@react-three/drei 9.83.9 → 9.84.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -2
- package/core/AccumulativeShadows.d.ts +3 -3
- package/core/AccumulativeShadows.js +30 -36
- package/core/AdaptiveDpr.js +4 -4
- package/core/ArcballControls.d.ts +1 -1
- package/core/ArcballControls.js +0 -1
- package/core/AsciiRenderer.d.ts +3 -3
- package/core/AsciiRenderer.js +12 -6
- package/core/BBAnchor.cjs.js +1 -1
- package/core/BBAnchor.d.ts +2 -2
- package/core/BBAnchor.js +5 -5
- package/core/Backdrop.d.ts +2 -2
- package/core/Backdrop.js +0 -3
- package/core/Billboard.d.ts +1 -1
- package/core/Billboard.js +6 -3
- package/core/Bounds.d.ts +5 -5
- package/core/Bounds.js +5 -32
- package/core/CameraControls.d.ts +2 -2
- package/core/CameraControls.js +0 -3
- package/core/CameraShake.js +0 -4
- package/core/CatmullRomLine.d.ts +1 -1
- package/core/CatmullRomLine.js +0 -2
- package/core/Caustics.d.ts +1 -1
- package/core/Caustics.js +31 -32
- package/core/Center.d.ts +2 -2
- package/core/Center.js +2 -1
- package/core/Clone.d.ts +1 -1
- package/core/Clone.js +10 -13
- package/core/Cloud.cjs.js +1 -1
- package/core/Cloud.d.ts +2 -2
- package/core/Cloud.js +1 -2
- package/core/ComputedAttribute.d.ts +2 -2
- package/core/ComputedAttribute.js +0 -1
- package/core/ContactShadows.d.ts +1 -1
- package/core/ContactShadows.js +6 -7
- package/core/CubeCamera.cjs.js +1 -1
- package/core/CubeCamera.d.ts +2 -2
- package/core/CubeCamera.js +1 -1
- package/core/CubicBezierLine.d.ts +1 -1
- package/core/CurveModifier.d.ts +1 -1
- package/core/CurveModifier.js +2 -4
- package/core/Decal.d.ts +1 -1
- package/core/Decal.js +8 -15
- package/core/Detailed.d.ts +1 -1
- package/core/Detailed.js +0 -1
- package/core/DeviceOrientationControls.d.ts +1 -1
- package/core/DeviceOrientationControls.js +3 -4
- package/core/Edges.d.ts +1 -1
- package/core/Edges.js +0 -2
- package/core/Effects.d.ts +1 -1
- package/core/Effects.js +5 -7
- package/core/Environment.d.ts +3 -3
- package/core/Environment.js +6 -12
- package/core/Example.d.ts +3 -3
- package/core/Example.js +2 -1
- package/core/FaceControls.cjs.js +1 -1
- package/core/FaceControls.d.ts +5 -5
- package/core/FaceControls.js +42 -39
- package/core/FaceLandmarker.d.ts +3 -2
- package/core/FaceLandmarker.js +1 -1
- package/core/Facemesh.d.ts +6 -6
- package/core/Facemesh.js +47 -53
- package/core/FirstPersonControls.d.ts +1 -1
- package/core/Float.d.ts +1 -1
- package/core/Float.js +0 -1
- package/core/FlyControls.d.ts +1 -1
- package/core/FlyControls.js +1 -2
- package/core/GizmoHelper.cjs.js +1 -1
- package/core/GizmoHelper.d.ts +2 -2
- package/core/GizmoHelper.js +18 -19
- package/core/GizmoViewcube.d.ts +3 -3
- package/core/GizmoViewcube.js +0 -14
- package/core/GizmoViewport.d.ts +3 -3
- package/core/GizmoViewport.js +0 -7
- package/core/Gltf.d.ts +1 -1
- package/core/GradientTexture.d.ts +3 -3
- package/core/GradientTexture.js +2 -5
- package/core/Grid.d.ts +2 -2
- package/core/Grid.js +2 -6
- package/core/Hud.d.ts +2 -2
- package/core/Hud.js +6 -9
- package/core/Image.d.ts +2 -2
- package/core/Image.js +4 -6
- package/core/Instances.d.ts +6 -6
- package/core/Instances.js +20 -35
- package/core/Lightformer.d.ts +1 -1
- package/core/Lightformer.js +4 -2
- package/core/Line.d.ts +1 -1
- package/core/Line.js +0 -3
- package/core/MapControls.d.ts +1 -1
- package/core/MapControls.js +0 -2
- package/core/MarchingCubes.d.ts +3 -3
- package/core/Mask.d.ts +1 -1
- package/core/MeshDistortMaterial.d.ts +2 -2
- package/core/MeshDistortMaterial.js +0 -9
- package/core/MeshPortalMaterial.d.ts +4 -4
- package/core/MeshPortalMaterial.js +22 -61
- package/core/MeshReflectorMaterial.d.ts +1 -1
- package/core/MeshReflectorMaterial.js +12 -14
- package/core/MeshRefractionMaterial.cjs.js +1 -1
- package/core/MeshRefractionMaterial.d.ts +3 -3
- package/core/MeshRefractionMaterial.js +9 -14
- package/core/MeshTransmissionMaterial.d.ts +2 -2
- package/core/MeshTransmissionMaterial.js +32 -33
- package/core/MeshWobbleMaterial.d.ts +2 -2
- package/core/MeshWobbleMaterial.js +0 -7
- package/core/MotionPathControls.cjs.js +1 -0
- package/core/MotionPathControls.d.ts +15 -0
- package/core/MotionPathControls.js +114 -0
- package/core/OrbitControls.d.ts +2 -2
- package/core/OrbitControls.js +0 -4
- package/core/OrthographicCamera.d.ts +1 -1
- package/core/OrthographicCamera.js +2 -3
- package/core/Outlines.cjs.js +1 -1
- package/core/Outlines.d.ts +3 -3
- package/core/Outlines.js +2 -7
- package/core/PerformanceMonitor.d.ts +4 -4
- package/core/PerformanceMonitor.js +8 -12
- package/core/PerspectiveCamera.d.ts +1 -1
- package/core/PerspectiveCamera.js +2 -3
- package/core/PointMaterial.d.ts +1 -1
- package/core/PointMaterial.js +0 -2
- package/core/PointerLockControls.d.ts +1 -1
- package/core/PointerLockControls.js +4 -6
- package/core/Points.d.ts +2 -2
- package/core/Points.js +6 -23
- package/core/PositionalAudio.d.ts +1 -1
- package/core/PositionalAudio.js +0 -5
- package/core/Preload.d.ts +1 -1
- package/core/Preload.js +8 -9
- package/core/QuadraticBezierLine.d.ts +2 -2
- package/core/QuadraticBezierLine.js +0 -2
- package/core/Reflector.d.ts +1 -1
- package/core/Reflector.js +11 -12
- package/core/RenderTexture.d.ts +1 -1
- package/core/RenderTexture.js +9 -11
- package/core/Resize.d.ts +2 -2
- package/core/RoundedBox.cjs.js +1 -1
- package/core/RoundedBox.d.ts +1 -1
- package/core/RoundedBox.js +1 -3
- package/core/Sampler.d.ts +5 -5
- package/core/Sampler.js +0 -10
- package/core/ScreenQuad.d.ts +1 -1
- package/core/ScreenQuad.js +0 -1
- package/core/ScreenSpace.d.ts +1 -1
- package/core/Segments.d.ts +2 -2
- package/core/Segments.js +0 -6
- package/core/Shadow.d.ts +1 -1
- package/core/Sky.d.ts +1 -1
- package/core/Sparkles.js +0 -10
- package/core/SpotLight.d.ts +2 -2
- package/core/SpotLight.js +3 -10
- package/core/SpriteAnimator.d.ts +1 -1
- package/core/SpriteAnimator.js +16 -34
- package/core/Stage.d.ts +4 -4
- package/core/Stage.js +2 -4
- package/core/Stars.d.ts +1 -1
- package/core/Stars.js +2 -11
- package/core/Stats.d.ts +1 -1
- package/core/Stats.js +2 -2
- package/core/StatsGl.d.ts +1 -1
- package/core/StatsGl.js +4 -3
- package/core/Svg.js +0 -2
- package/core/Text.d.ts +1 -1
- package/core/Text3D.d.ts +1 -1
- package/core/Text3D.js +1 -3
- package/core/TrackballControls.d.ts +1 -1
- package/core/TrackballControls.js +0 -1
- package/core/Trail.d.ts +3 -3
- package/core/Trail.js +6 -17
- package/core/TransformControls.d.ts +1 -1
- package/core/TransformControls.js +3 -9
- package/core/Wireframe.d.ts +1 -1
- package/core/Wireframe.js +0 -28
- package/core/index.cjs.js +1 -1
- package/core/index.d.ts +1 -0
- package/core/index.js +1 -0
- package/core/meshBounds.js +4 -14
- package/core/shaderMaterial.js +10 -9
- package/core/shapes.d.ts +2 -2
- package/core/shapes.js +3 -6
- package/core/softShadows.d.ts +1 -1
- package/core/softShadows.js +1 -4
- package/core/useAnimations.d.ts +1 -1
- package/core/useAnimations.js +2 -4
- package/core/useBVH.d.ts +1 -1
- package/core/useBVH.js +3 -4
- package/core/useBoxProjectedEnv.js +15 -22
- package/core/useCamera.js +0 -1
- package/core/useContextBridge.js +1 -2
- package/core/useCubeCamera.d.ts +1 -1
- package/core/useCubeTexture.d.ts +1 -1
- package/core/useCubeTexture.js +4 -3
- package/core/useEnvironment.cjs.js +1 -1
- package/core/useEnvironment.d.ts +2 -2
- package/core/useEnvironment.js +9 -11
- package/core/useFBO.d.ts +1 -1
- package/core/useFBO.js +3 -12
- package/core/useFBX.js +0 -2
- package/core/useFont.d.ts +2 -2
- package/core/useFont.js +0 -4
- package/core/useGLTF.d.ts +2 -2
- package/core/useGLTF.js +0 -8
- package/core/useHelper.d.ts +3 -3
- package/core/useHelper.js +2 -5
- package/core/useIntersect.js +5 -8
- package/core/useKTX2.js +3 -5
- package/core/useMatcapTexture.js +0 -6
- package/core/useNormalTexture.d.ts +1 -1
- package/core/useProgress.d.ts +1 -1
- package/core/useProgress.js +0 -5
- package/core/useTexture.js +4 -6
- package/core/useTrailTexture.d.ts +1 -1
- package/core/useTrailTexture.js +10 -21
- package/helpers/environment-assets.d.ts +1 -1
- package/helpers/ts-utils.d.ts +2 -2
- package/helpers/useEffectfulState.d.ts +1 -1
- package/helpers/useEffectfulState.js +0 -1
- package/index.cjs.js +1 -1
- package/index.js +1 -0
- package/materials/BlurPass.js +2 -5
- package/materials/ConvolutionMaterial.js +0 -3
- package/materials/MeshReflectorMaterial.d.ts +1 -1
- package/materials/MeshReflectorMaterial.js +0 -34
- package/materials/MeshRefractionMaterial.js +2 -6
- package/materials/SpotLightMaterial.js +2 -7
- package/materials/WireframeMaterial.js +7 -25
- package/native/index.cjs.js +1 -1
- package/native/index.js +1 -0
- package/package.json +2 -2
- package/react-three-drei-0.0.0-semantic-release.tgz +0 -0
- package/web/CycleRaycast.d.ts +1 -1
- package/web/CycleRaycast.js +20 -24
- package/web/Html.d.ts +2 -2
- package/web/Html.js +6 -50
- package/web/KeyboardControls.d.ts +10 -10
- package/web/KeyboardControls.js +9 -6
- package/web/Loader.d.ts +2 -2
- package/web/Loader.js +8 -5
- package/web/PresentationControls.d.ts +2 -2
- package/web/PresentationControls.js +2 -1
- package/web/ScrollControls.d.ts +4 -4
- package/web/ScrollControls.js +5 -16
- package/web/Select.d.ts +3 -3
- package/web/Select.js +6 -17
- package/web/View.d.ts +5 -5
- package/web/View.js +7 -20
- package/web/index.cjs.js +1 -1
- package/web/index.js +1 -0
- package/web/pivotControls/AxisArrow.js +6 -15
- package/web/pivotControls/AxisRotator.js +8 -23
- package/web/pivotControls/PlaneSlider.js +6 -16
- package/web/pivotControls/context.d.ts +2 -2
- package/web/pivotControls/index.d.ts +1 -1
- package/web/pivotControls/index.js +2 -9
|
@@ -2,11 +2,10 @@ import * as THREE from 'three';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { applyProps } from '@react-three/fiber';
|
|
4
4
|
|
|
5
|
+
// credits for the box-projecting shader code go to codercat (https://codercat.tk)
|
|
5
6
|
// and @0beqz https://gist.github.com/0beqz/8d51b4ae16d68021a09fb504af708fca
|
|
6
7
|
|
|
7
|
-
const worldposReplace =
|
|
8
|
-
/* glsl */
|
|
9
|
-
`
|
|
8
|
+
const worldposReplace = /* glsl */`
|
|
10
9
|
#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )
|
|
11
10
|
vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );
|
|
12
11
|
#ifdef BOX_PROJECTED_ENV_MAP
|
|
@@ -14,9 +13,7 @@ const worldposReplace =
|
|
|
14
13
|
#endif
|
|
15
14
|
#endif
|
|
16
15
|
`;
|
|
17
|
-
const boxProjectDefinitions =
|
|
18
|
-
/*glsl */
|
|
19
|
-
`
|
|
16
|
+
const boxProjectDefinitions = /*glsl */`
|
|
20
17
|
#ifdef BOX_PROJECTED_ENV_MAP
|
|
21
18
|
uniform vec3 envMapSize;
|
|
22
19
|
uniform vec3 envMapPosition;
|
|
@@ -35,38 +32,35 @@ const boxProjectDefinitions =
|
|
|
35
32
|
return boxIntersection - cubePos;
|
|
36
33
|
}
|
|
37
34
|
#endif
|
|
38
|
-
`;
|
|
35
|
+
`;
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
/* glsl
|
|
42
|
-
`
|
|
37
|
+
// will be inserted after "vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );"
|
|
38
|
+
const getIBLIrradiance_patch = /* glsl */`
|
|
43
39
|
#ifdef BOX_PROJECTED_ENV_MAP
|
|
44
40
|
worldNormal = parallaxCorrectNormal( worldNormal, envMapSize, envMapPosition );
|
|
45
41
|
#endif
|
|
46
|
-
`;
|
|
42
|
+
`;
|
|
47
43
|
|
|
48
|
-
|
|
49
|
-
/* glsl
|
|
50
|
-
`
|
|
44
|
+
// will be inserted after "reflectVec = inverseTransformDirection( reflectVec, viewMatrix );"
|
|
45
|
+
const getIBLRadiance_patch = /* glsl */`
|
|
51
46
|
#ifdef BOX_PROJECTED_ENV_MAP
|
|
52
47
|
reflectVec = parallaxCorrectNormal( reflectVec, envMapSize, envMapPosition );
|
|
53
48
|
#endif
|
|
54
49
|
`;
|
|
55
|
-
|
|
56
50
|
function boxProjectedEnvMap(shader, envMapPosition, envMapSize) {
|
|
57
|
-
shader.defines.BOX_PROJECTED_ENV_MAP = true;
|
|
58
|
-
|
|
51
|
+
shader.defines.BOX_PROJECTED_ENV_MAP = true;
|
|
52
|
+
// uniforms
|
|
59
53
|
shader.uniforms.envMapPosition = {
|
|
60
54
|
value: envMapPosition
|
|
61
55
|
};
|
|
62
56
|
shader.uniforms.envMapSize = {
|
|
63
57
|
value: envMapSize
|
|
64
|
-
};
|
|
65
|
-
|
|
58
|
+
};
|
|
59
|
+
// vertex shader
|
|
66
60
|
shader.vertexShader = `
|
|
67
61
|
varying vec3 vWorldPosition;
|
|
68
|
-
${shader.vertexShader.replace('#include <worldpos_vertex>', worldposReplace)}`;
|
|
69
|
-
|
|
62
|
+
${shader.vertexShader.replace('#include <worldpos_vertex>', worldposReplace)}`;
|
|
63
|
+
// fragment shader
|
|
70
64
|
shader.fragmentShader = `
|
|
71
65
|
${boxProjectDefinitions}
|
|
72
66
|
${shader.fragmentShader.replace('#include <envmap_physical_pars_fragment>', THREE.ShaderChunk.envmap_physical_pars_fragment).replace('vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );', `vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
|
|
@@ -75,7 +69,6 @@ function boxProjectedEnvMap(shader, envMapPosition, envMapSize) {
|
|
|
75
69
|
${getIBLRadiance_patch}
|
|
76
70
|
`)}`;
|
|
77
71
|
}
|
|
78
|
-
|
|
79
72
|
function useBoxProjectedEnv(position = new THREE.Vector3(), size = new THREE.Vector3()) {
|
|
80
73
|
const [config] = React.useState(() => ({
|
|
81
74
|
position: new THREE.Vector3(),
|
package/core/useCamera.js
CHANGED
|
@@ -13,7 +13,6 @@ function useCamera(camera, props) {
|
|
|
13
13
|
* so we have an expect error to mask this
|
|
14
14
|
*/
|
|
15
15
|
// @ts-expect-error
|
|
16
|
-
|
|
17
16
|
if (props) applyProps(raycaster, props, {});
|
|
18
17
|
return function (_, intersects) {
|
|
19
18
|
raycaster.setFromCamera(pointer, camera instanceof Camera ? camera : camera.current);
|
package/core/useContextBridge.js
CHANGED
|
@@ -14,8 +14,7 @@ function useContextBridge(...contexts) {
|
|
|
14
14
|
* done this way in reference to:
|
|
15
15
|
* https://github.com/DefinitelyTyped/DefinitelyTyped/issues/44572#issuecomment-625878049
|
|
16
16
|
* https://github.com/microsoft/TypeScript/issues/14729
|
|
17
|
-
*/
|
|
18
|
-
), []);
|
|
17
|
+
*/), []);
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
export { useContextBridge };
|
package/core/useCubeCamera.d.ts
CHANGED
package/core/useCubeTexture.d.ts
CHANGED
package/core/useCubeTexture.js
CHANGED
|
@@ -5,14 +5,15 @@ function useCubeTexture(files, {
|
|
|
5
5
|
path
|
|
6
6
|
}) {
|
|
7
7
|
// @ts-ignore
|
|
8
|
-
const [cubeTexture] = useLoader(
|
|
8
|
+
const [cubeTexture] = useLoader(
|
|
9
|
+
// @ts-ignore
|
|
9
10
|
CubeTextureLoader, [files], loader => loader.setPath(path));
|
|
10
11
|
return cubeTexture;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
13
|
useCubeTexture.preload = (files, {
|
|
14
14
|
path
|
|
15
|
-
}) => useLoader.preload(
|
|
15
|
+
}) => useLoader.preload(
|
|
16
|
+
// @ts-ignore
|
|
16
17
|
CubeTextureLoader, [files], loader => loader.setPath(path));
|
|
17
18
|
|
|
18
19
|
export { useCubeTexture };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@react-three/fiber"),r=require("three"),n=require("three-stdlib"),t=require("../helpers/environment-assets.cjs.js");const s=e=>Array.isArray(e);exports.useEnvironment=function({files:i=["/px.png","/nx.png","/py.png","/ny.png","/pz.png","/nz.png"],path:o="",preset:a,encoding:p,extensions:l}={}){var u
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@react-three/fiber"),r=require("three"),n=require("three-stdlib"),t=require("../helpers/environment-assets.cjs.js");const s=e=>Array.isArray(e);exports.useEnvironment=function({files:i=["/px.png","/nx.png","/py.png","/ny.png","/pz.png","/nz.png"],path:o="",preset:a,encoding:p,extensions:l}={}){var u;let c,d=null,b=!1;if(a){if(!(a in t.presetsObj))throw new Error("Preset must be one of: "+Object.keys(t.presetsObj).join(", "));i=t.presetsObj[a],o="https://raw.githack.com/pmndrs/drei-assets/456060a26bbeb8fdf79326f224b6d99b8bcce736/hdri/"}if(b=s(i),c=s(i)?"cube":i.startsWith("data:application/exr")?"exr":i.startsWith("data:application/hdr")?"hdr":null==(u=i.split(".").pop())||null==(u=u.split("?"))||null==(u=u.shift())?void 0:u.toLowerCase(),d=b?r.CubeTextureLoader:"hdr"===c?n.RGBELoader:"exr"===c?n.EXRLoader:null,!d)throw new Error("useEnvironment: Unrecognized file extension: "+i);const h=e.useLoader(d,b?[i]:i,(e=>{null==e.setPath||e.setPath(o),l&&l(e)})),g=b?h[0]:h;return g.mapping=b?r.CubeReflectionMapping:r.EquirectangularReflectionMapping,"colorSpace"in g?g.colorSpace=(null!=p?p:b)?"srgb":"srgb-linear":g.encoding=(null!=p?p:b)?3001:3e3,g};
|
package/core/useEnvironment.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Texture, Loader, CubeTexture, TextureEncoding } from 'three';
|
|
2
2
|
import { PresetsType } from '../helpers/environment-assets';
|
|
3
|
-
export
|
|
3
|
+
export type EnvironmentLoaderProps = {
|
|
4
4
|
files?: string | string[];
|
|
5
5
|
path?: string;
|
|
6
6
|
preset?: PresetsType;
|
|
7
7
|
extensions?: (loader: Loader) => void;
|
|
8
8
|
encoding?: TextureEncoding;
|
|
9
9
|
};
|
|
10
|
-
export declare function useEnvironment({ files, path, preset, encoding, extensions, }?: Partial<EnvironmentLoaderProps>): Texture | CubeTexture;
|
|
10
|
+
export declare function useEnvironment({ files, path, preset, encoding, extensions, }?: Partial<EnvironmentLoaderProps>): Texture | CubeTexture | (CubeTexture & Record<"colorSpace", unknown>);
|
package/core/useEnvironment.js
CHANGED
|
@@ -4,9 +4,7 @@ import { RGBELoader, EXRLoader } from 'three-stdlib';
|
|
|
4
4
|
import { presetsObj } from '../helpers/environment-assets.js';
|
|
5
5
|
|
|
6
6
|
const CUBEMAP_ROOT = 'https://raw.githack.com/pmndrs/drei-assets/456060a26bbeb8fdf79326f224b6d99b8bcce736/hdri/';
|
|
7
|
-
|
|
8
7
|
const isArray = arr => Array.isArray(arr);
|
|
9
|
-
|
|
10
8
|
function useEnvironment({
|
|
11
9
|
files = ['/px.png', '/nx.png', '/py.png', '/ny.png', '/pz.png', '/nz.png'],
|
|
12
10
|
path = '',
|
|
@@ -14,29 +12,29 @@ function useEnvironment({
|
|
|
14
12
|
encoding = undefined,
|
|
15
13
|
extensions
|
|
16
14
|
} = {}) {
|
|
17
|
-
var _files$split$pop
|
|
18
|
-
|
|
15
|
+
var _files$split$pop;
|
|
19
16
|
let loader = null;
|
|
20
17
|
let isCubeMap = false;
|
|
21
18
|
let extension;
|
|
22
|
-
|
|
23
19
|
if (preset) {
|
|
24
20
|
if (!(preset in presetsObj)) throw new Error('Preset must be one of: ' + Object.keys(presetsObj).join(', '));
|
|
25
21
|
files = presetsObj[preset];
|
|
26
22
|
path = CUBEMAP_ROOT;
|
|
27
|
-
}
|
|
28
|
-
|
|
23
|
+
}
|
|
29
24
|
|
|
25
|
+
// Everything else
|
|
30
26
|
isCubeMap = isArray(files);
|
|
31
|
-
extension = isArray(files) ? 'cube' : files.startsWith('data:application/exr') ? 'exr' : files.startsWith('data:application/hdr') ? 'hdr' : (_files$split$pop = files.split('.').pop()) == null
|
|
27
|
+
extension = isArray(files) ? 'cube' : files.startsWith('data:application/exr') ? 'exr' : files.startsWith('data:application/hdr') ? 'hdr' : (_files$split$pop = files.split('.').pop()) == null || (_files$split$pop = _files$split$pop.split('?')) == null || (_files$split$pop = _files$split$pop.shift()) == null ? void 0 : _files$split$pop.toLowerCase();
|
|
32
28
|
loader = isCubeMap ? CubeTextureLoader : extension === 'hdr' ? RGBELoader : extension === 'exr' ? EXRLoader : null;
|
|
33
29
|
if (!loader) throw new Error('useEnvironment: Unrecognized file extension: ' + files);
|
|
34
|
-
const loaderResult = useLoader(
|
|
30
|
+
const loaderResult = useLoader(
|
|
31
|
+
// @ts-expect-error
|
|
35
32
|
loader, isCubeMap ? [files] : files, loader => {
|
|
36
|
-
loader.setPath == null
|
|
33
|
+
loader.setPath == null || loader.setPath(path);
|
|
37
34
|
if (extensions) extensions(loader);
|
|
38
35
|
});
|
|
39
|
-
const texture = isCubeMap ?
|
|
36
|
+
const texture = isCubeMap ?
|
|
37
|
+
// @ts-ignore
|
|
40
38
|
loaderResult[0] : loaderResult;
|
|
41
39
|
texture.mapping = isCubeMap ? CubeReflectionMapping : EquirectangularReflectionMapping;
|
|
42
40
|
const sRGBEncoding = 3001;
|
package/core/useFBO.d.ts
CHANGED
package/core/useFBO.js
CHANGED
|
@@ -4,22 +4,15 @@ import { useThree } from '@react-three/fiber';
|
|
|
4
4
|
|
|
5
5
|
// 👇 uncomment when TS version supports function overloads
|
|
6
6
|
// export function useFBO(settings?: FBOSettings)
|
|
7
|
-
function useFBO(
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
/** Height in pixels */
|
|
11
|
-
height,
|
|
12
|
-
/**Settings */
|
|
7
|
+
function useFBO( /** Width in pixels, or settings (will render fullscreen by default) */
|
|
8
|
+
width, /** Height in pixels */
|
|
9
|
+
height, /**Settings */
|
|
13
10
|
settings) {
|
|
14
11
|
const size = useThree(state => state.size);
|
|
15
12
|
const viewport = useThree(state => state.viewport);
|
|
16
|
-
|
|
17
13
|
const _width = typeof width === 'number' ? width : size.width * viewport.dpr;
|
|
18
|
-
|
|
19
14
|
const _height = typeof height === 'number' ? height : size.height * viewport.dpr;
|
|
20
|
-
|
|
21
15
|
const _settings = (typeof width === 'number' ? settings : width) || {};
|
|
22
|
-
|
|
23
16
|
const {
|
|
24
17
|
samples = 0,
|
|
25
18
|
depth,
|
|
@@ -32,11 +25,9 @@ settings) {
|
|
|
32
25
|
type: THREE.HalfFloatType,
|
|
33
26
|
...targetSettings
|
|
34
27
|
});
|
|
35
|
-
|
|
36
28
|
if (depth) {
|
|
37
29
|
target.depthTexture = new THREE.DepthTexture(_width, _height, THREE.FloatType);
|
|
38
30
|
}
|
|
39
|
-
|
|
40
31
|
target.samples = samples;
|
|
41
32
|
return target;
|
|
42
33
|
}, []);
|
package/core/useFBX.js
CHANGED
|
@@ -4,9 +4,7 @@ import { useLoader } from '@react-three/fiber';
|
|
|
4
4
|
function useFBX(path) {
|
|
5
5
|
return useLoader(FBXLoader, path);
|
|
6
6
|
}
|
|
7
|
-
|
|
8
7
|
useFBX.preload = path => useLoader.preload(FBXLoader, path);
|
|
9
|
-
|
|
10
8
|
useFBX.clear = input => useLoader.clear(FBXLoader, input);
|
|
11
9
|
|
|
12
10
|
export { useFBX };
|
package/core/useFont.d.ts
CHANGED
package/core/useFont.js
CHANGED
|
@@ -2,19 +2,15 @@ import { FontLoader } from 'three-stdlib';
|
|
|
2
2
|
import { suspend, preload, clear } from 'suspend-react';
|
|
3
3
|
|
|
4
4
|
let fontLoader = null;
|
|
5
|
-
|
|
6
5
|
async function loader(font) {
|
|
7
6
|
if (!fontLoader) fontLoader = new FontLoader();
|
|
8
7
|
let data = typeof font === 'string' ? await (await fetch(font)).json() : font;
|
|
9
8
|
return fontLoader.parse(data);
|
|
10
9
|
}
|
|
11
|
-
|
|
12
10
|
function useFont(font) {
|
|
13
11
|
return suspend(loader, [font]);
|
|
14
12
|
}
|
|
15
|
-
|
|
16
13
|
useFont.preload = font => preload(loader, [font]);
|
|
17
|
-
|
|
18
14
|
useFont.clear = font => clear([font]);
|
|
19
15
|
|
|
20
16
|
export { useFont };
|
package/core/useGLTF.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GLTFLoader
|
|
2
|
-
export declare function useGLTF<T extends string | string[]>(path: T, useDraco?: boolean | string, useMeshOpt?: boolean, extendLoader?: (loader: GLTFLoader) => void): T extends any[] ? GLTF[] : GLTF;
|
|
1
|
+
import { GLTFLoader } from 'three-stdlib';
|
|
2
|
+
export declare function useGLTF<T extends string | string[]>(path: T, useDraco?: boolean | string, useMeshOpt?: boolean, extendLoader?: (loader: GLTFLoader) => void): T extends any[] ? import("three-stdlib").GLTF[] : import("three-stdlib").GLTF;
|
|
3
3
|
export declare namespace useGLTF {
|
|
4
4
|
var preload: (path: string | string[], useDraco?: string | boolean, useMeshOpt?: boolean, extendLoader?: ((loader: GLTFLoader) => void) | undefined) => undefined;
|
|
5
5
|
var clear: (input: string | string[]) => void;
|
package/core/useGLTF.js
CHANGED
|
@@ -4,37 +4,29 @@ import { useLoader } from '@react-three/fiber';
|
|
|
4
4
|
// @ts-ignore
|
|
5
5
|
let dracoLoader = null;
|
|
6
6
|
let decoderPath = 'https://www.gstatic.com/draco/versioned/decoders/1.5.5/';
|
|
7
|
-
|
|
8
7
|
function extensions(useDraco, useMeshopt, extendLoader) {
|
|
9
8
|
return loader => {
|
|
10
9
|
if (extendLoader) {
|
|
11
10
|
extendLoader(loader);
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
if (useDraco) {
|
|
15
13
|
if (!dracoLoader) {
|
|
16
14
|
dracoLoader = new DRACOLoader();
|
|
17
15
|
}
|
|
18
|
-
|
|
19
16
|
dracoLoader.setDecoderPath(typeof useDraco === 'string' ? useDraco : decoderPath);
|
|
20
17
|
loader.setDRACOLoader(dracoLoader);
|
|
21
18
|
}
|
|
22
|
-
|
|
23
19
|
if (useMeshopt) {
|
|
24
20
|
loader.setMeshoptDecoder(typeof MeshoptDecoder === 'function' ? MeshoptDecoder() : MeshoptDecoder);
|
|
25
21
|
}
|
|
26
22
|
};
|
|
27
23
|
}
|
|
28
|
-
|
|
29
24
|
function useGLTF(path, useDraco = true, useMeshOpt = true, extendLoader) {
|
|
30
25
|
const gltf = useLoader(GLTFLoader, path, extensions(useDraco, useMeshOpt, extendLoader));
|
|
31
26
|
return gltf;
|
|
32
27
|
}
|
|
33
|
-
|
|
34
28
|
useGLTF.preload = (path, useDraco = true, useMeshOpt = true, extendLoader) => useLoader.preload(GLTFLoader, path, extensions(useDraco, useMeshOpt, extendLoader));
|
|
35
|
-
|
|
36
29
|
useGLTF.clear = input => useLoader.clear(GLTFLoader, input);
|
|
37
|
-
|
|
38
30
|
useGLTF.setDecoderPath = path => {
|
|
39
31
|
decoderPath = path;
|
|
40
32
|
};
|
package/core/useHelper.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Object3D } from 'three';
|
|
3
3
|
import { Falsey } from 'utility-types';
|
|
4
|
-
|
|
4
|
+
type Helper = Object3D & {
|
|
5
5
|
update: () => void;
|
|
6
6
|
dispose: () => void;
|
|
7
7
|
};
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
type Constructor = new (...args: any[]) => any;
|
|
9
|
+
type Rest<T> = T extends [infer _, ...infer R] ? R : never;
|
|
10
10
|
export declare function useHelper<T extends Constructor>(object3D: React.MutableRefObject<Object3D> | Falsey, helperConstructor: T, ...args: Rest<ConstructorParameters<T>>): React.MutableRefObject<Helper | undefined>;
|
|
11
11
|
export {};
|
package/core/useHelper.js
CHANGED
|
@@ -6,11 +6,9 @@ function useHelper(object3D, helperConstructor, ...args) {
|
|
|
6
6
|
const scene = useThree(state => state.scene);
|
|
7
7
|
React.useLayoutEffect(() => {
|
|
8
8
|
let currentHelper = undefined;
|
|
9
|
-
|
|
10
9
|
if (object3D && object3D != null && object3D.current && helperConstructor) {
|
|
11
10
|
helper.current = currentHelper = new helperConstructor(object3D.current, ...args);
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
if (currentHelper) {
|
|
15
13
|
// Prevent the helpers from blocking rays
|
|
16
14
|
currentHelper.traverse(child => child.raycast = () => null);
|
|
@@ -18,14 +16,13 @@ function useHelper(object3D, helperConstructor, ...args) {
|
|
|
18
16
|
return () => {
|
|
19
17
|
helper.current = undefined;
|
|
20
18
|
scene.remove(currentHelper);
|
|
21
|
-
currentHelper.dispose == null
|
|
19
|
+
currentHelper.dispose == null || currentHelper.dispose();
|
|
22
20
|
};
|
|
23
21
|
}
|
|
24
22
|
}, [scene, helperConstructor, object3D, ...args]);
|
|
25
23
|
useFrame(() => {
|
|
26
24
|
var _helper$current;
|
|
27
|
-
|
|
28
|
-
return void ((_helper$current = helper.current) == null ? void 0 : _helper$current.update == null ? void 0 : _helper$current.update());
|
|
25
|
+
return void ((_helper$current = helper.current) == null || _helper$current.update == null ? void 0 : _helper$current.update());
|
|
29
26
|
});
|
|
30
27
|
return helper;
|
|
31
28
|
}
|
package/core/useIntersect.js
CHANGED
|
@@ -9,21 +9,18 @@ function useIntersect(onChange) {
|
|
|
9
9
|
React.useLayoutEffect(() => void (callback.current = onChange), [onChange]);
|
|
10
10
|
React.useEffect(() => {
|
|
11
11
|
const obj = ref.current;
|
|
12
|
-
|
|
13
12
|
if (obj) {
|
|
14
13
|
// Stamp out frustum check pre-emptively
|
|
15
14
|
const unsub1 = addEffect(() => {
|
|
16
15
|
check.current = false;
|
|
17
16
|
return true;
|
|
18
|
-
});
|
|
19
|
-
|
|
17
|
+
});
|
|
18
|
+
// If the object is inside the frustum three will call onRender
|
|
20
19
|
const oldOnRender = obj.onBeforeRender;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
obj.onBeforeRender = () => check.current = true;
|
|
21
|
+
// Compare the check value against the temp value, if it differs set state
|
|
25
22
|
const unsub2 = addAfterEffect(() => {
|
|
26
|
-
if (check.current !== temp.current) callback.current == null
|
|
23
|
+
if (check.current !== temp.current) callback.current == null || callback.current(temp.current = check.current);
|
|
27
24
|
return true;
|
|
28
25
|
});
|
|
29
26
|
return () => {
|
package/core/useKTX2.js
CHANGED
|
@@ -9,14 +9,14 @@ function useKTX2(input, basisPath = `${cdn}/basis/`) {
|
|
|
9
9
|
const textures = useLoader(KTX2Loader, IsObject(input) ? Object.values(input) : input, loader => {
|
|
10
10
|
loader.detectSupport(gl);
|
|
11
11
|
loader.setTranscoderPath(basisPath);
|
|
12
|
-
});
|
|
13
|
-
// Upload the texture to the GPU immediately instead of waiting for the first render
|
|
12
|
+
});
|
|
14
13
|
|
|
14
|
+
// https://github.com/mrdoob/three.js/issues/22696
|
|
15
|
+
// Upload the texture to the GPU immediately instead of waiting for the first render
|
|
15
16
|
useEffect(() => {
|
|
16
17
|
const array = Array.isArray(textures) ? textures : [textures];
|
|
17
18
|
array.forEach(gl.initTexture);
|
|
18
19
|
}, [gl, textures]);
|
|
19
|
-
|
|
20
20
|
if (IsObject(input)) {
|
|
21
21
|
const keys = Object.keys(input);
|
|
22
22
|
const keyed = {};
|
|
@@ -28,11 +28,9 @@ function useKTX2(input, basisPath = `${cdn}/basis/`) {
|
|
|
28
28
|
return textures;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
|
|
32
31
|
useKTX2.preload = (url, basisPath = `${cdn}/basis/`) => useLoader.preload(KTX2Loader, url, loader => {
|
|
33
32
|
loader.setTranscoderPath(basisPath);
|
|
34
33
|
});
|
|
35
|
-
|
|
36
34
|
useKTX2.clear = input => useLoader.clear(KTX2Loader, input);
|
|
37
35
|
|
|
38
36
|
export { useKTX2 };
|
package/core/useMatcapTexture.js
CHANGED
|
@@ -6,21 +6,16 @@ function getFormatString(format) {
|
|
|
6
6
|
switch (format) {
|
|
7
7
|
case 64:
|
|
8
8
|
return '-64px';
|
|
9
|
-
|
|
10
9
|
case 128:
|
|
11
10
|
return '-128px';
|
|
12
|
-
|
|
13
11
|
case 256:
|
|
14
12
|
return '-256px';
|
|
15
|
-
|
|
16
13
|
case 512:
|
|
17
14
|
return '-512px';
|
|
18
|
-
|
|
19
15
|
default:
|
|
20
16
|
return '';
|
|
21
17
|
}
|
|
22
18
|
}
|
|
23
|
-
|
|
24
19
|
const LIST_URL = 'https://cdn.jsdelivr.net/gh/pmndrs/drei-assets@master/matcaps.json';
|
|
25
20
|
const MATCAP_ROOT = 'https://rawcdn.githack.com/emmelleppi/matcaps/9b36ccaaf0a24881a39062d05566c9e92be4aa0d';
|
|
26
21
|
function useMatcapTexture(id = 0, format = 1024, onLoad) {
|
|
@@ -33,7 +28,6 @@ function useMatcapTexture(id = 0, format = 1024, onLoad) {
|
|
|
33
28
|
} else if (typeof id === 'number') {
|
|
34
29
|
return matcapList[id];
|
|
35
30
|
}
|
|
36
|
-
|
|
37
31
|
return null;
|
|
38
32
|
}, [id]);
|
|
39
33
|
const fileName = `${fileHash || DEFAULT_MATCAP}${getFormatString(format)}.png`;
|
package/core/useProgress.d.ts
CHANGED
package/core/useProgress.js
CHANGED
|
@@ -12,22 +12,18 @@ const useProgress = create(set => {
|
|
|
12
12
|
progress: (loaded - saveLastTotalLoaded) / (total - saveLastTotalLoaded) * 100
|
|
13
13
|
});
|
|
14
14
|
};
|
|
15
|
-
|
|
16
15
|
DefaultLoadingManager.onLoad = () => {
|
|
17
16
|
set({
|
|
18
17
|
active: false
|
|
19
18
|
});
|
|
20
19
|
};
|
|
21
|
-
|
|
22
20
|
DefaultLoadingManager.onError = item => set(state => ({
|
|
23
21
|
errors: [...state.errors, item]
|
|
24
22
|
}));
|
|
25
|
-
|
|
26
23
|
DefaultLoadingManager.onProgress = (item, loaded, total) => {
|
|
27
24
|
if (loaded === total) {
|
|
28
25
|
saveLastTotalLoaded = total;
|
|
29
26
|
}
|
|
30
|
-
|
|
31
27
|
set({
|
|
32
28
|
active: true,
|
|
33
29
|
item,
|
|
@@ -36,7 +32,6 @@ const useProgress = create(set => {
|
|
|
36
32
|
progress: (loaded - saveLastTotalLoaded) / (total - saveLastTotalLoaded) * 100 || 100
|
|
37
33
|
});
|
|
38
34
|
};
|
|
39
|
-
|
|
40
35
|
return {
|
|
41
36
|
errors: [],
|
|
42
37
|
active: false,
|
package/core/useTexture.js
CHANGED
|
@@ -7,15 +7,15 @@ function useTexture(input, onLoad) {
|
|
|
7
7
|
const gl = useThree(state => state.gl);
|
|
8
8
|
const textures = useLoader(TextureLoader, IsObject(input) ? Object.values(input) : input);
|
|
9
9
|
useLayoutEffect(() => {
|
|
10
|
-
onLoad == null
|
|
11
|
-
}, [onLoad]);
|
|
12
|
-
// Upload the texture to the GPU immediately instead of waiting for the first render
|
|
10
|
+
onLoad == null || onLoad(textures);
|
|
11
|
+
}, [onLoad]);
|
|
13
12
|
|
|
13
|
+
// https://github.com/mrdoob/three.js/issues/22696
|
|
14
|
+
// Upload the texture to the GPU immediately instead of waiting for the first render
|
|
14
15
|
useEffect(() => {
|
|
15
16
|
const array = Array.isArray(textures) ? textures : [textures];
|
|
16
17
|
array.forEach(gl.initTexture);
|
|
17
18
|
}, [gl, textures]);
|
|
18
|
-
|
|
19
19
|
if (IsObject(input)) {
|
|
20
20
|
const keys = Object.keys(input);
|
|
21
21
|
const keyed = {};
|
|
@@ -27,9 +27,7 @@ function useTexture(input, onLoad) {
|
|
|
27
27
|
return textures;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
|
|
31
30
|
useTexture.preload = url => useLoader.preload(TextureLoader, url);
|
|
32
|
-
|
|
33
31
|
useTexture.clear = input => useLoader.clear(TextureLoader, input);
|
|
34
32
|
|
|
35
33
|
export { IsObject, useTexture };
|