@react-three/drei 9.83.8 → 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 +4 -3
- package/core/Outlines.js +5 -8
- 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
package/core/Lightformer.js
CHANGED
|
@@ -25,12 +25,14 @@ const Lightformer = /*#__PURE__*/React.forwardRef(({
|
|
|
25
25
|
});
|
|
26
26
|
ref.current.material.color.multiplyScalar(intensity);
|
|
27
27
|
}
|
|
28
|
-
}, [color, intensity, children, props.material]);
|
|
28
|
+
}, [color, intensity, children, props.material]);
|
|
29
29
|
|
|
30
|
+
// Target light
|
|
30
31
|
React.useLayoutEffect(() => {
|
|
31
32
|
if (target) ref.current.lookAt(Array.isArray(target) ? new THREE.Vector3(...target) : target);
|
|
32
|
-
}, [target]);
|
|
33
|
+
}, [target]);
|
|
33
34
|
|
|
35
|
+
// Fix 2-dimensional scale
|
|
34
36
|
scale = Array.isArray(scale) && scale.length === 2 ? [scale[0], scale[1], 1] : scale;
|
|
35
37
|
return /*#__PURE__*/React.createElement("mesh", _extends({
|
|
36
38
|
ref: mergeRefs([ref, forwardRef]),
|
package/core/Line.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Vector2, Vector3, Color, ColorRepresentation } from 'three';
|
|
|
2
2
|
import { ReactThreeFiber } from '@react-three/fiber';
|
|
3
3
|
import { LineMaterial, LineMaterialParameters, Line2, LineSegments2 } from 'three-stdlib';
|
|
4
4
|
import { ForwardRefComponent } from '../helpers/ts-utils';
|
|
5
|
-
export
|
|
5
|
+
export type LineProps = {
|
|
6
6
|
points: Array<Vector3 | Vector2 | [number, number, number] | [number, number] | number>;
|
|
7
7
|
vertexColors?: Array<Color | [number, number, number]>;
|
|
8
8
|
lineWidth?: number;
|
package/core/Line.js
CHANGED
|
@@ -24,12 +24,10 @@ const Line = /*#__PURE__*/React.forwardRef(function Line({
|
|
|
24
24
|
return p instanceof Vector3 ? [p.x, p.y, p.z] : p instanceof Vector2 ? [p.x, p.y, 0] : isArray && p.length === 3 ? [p[0], p[1], p[2]] : isArray && p.length === 2 ? [p[0], p[1], 0] : p;
|
|
25
25
|
});
|
|
26
26
|
geom.setPositions(pValues.flat());
|
|
27
|
-
|
|
28
27
|
if (vertexColors) {
|
|
29
28
|
const cValues = vertexColors.map(c => c instanceof Color ? c.toArray() : c);
|
|
30
29
|
geom.setColors(cValues.flat());
|
|
31
30
|
}
|
|
32
|
-
|
|
33
31
|
return geom;
|
|
34
32
|
}, [points, segments, vertexColors]);
|
|
35
33
|
React.useLayoutEffect(() => {
|
|
@@ -42,7 +40,6 @@ const Line = /*#__PURE__*/React.forwardRef(function Line({
|
|
|
42
40
|
// Setting lineMaterial.defines.USE_DASH to undefined is apparently not sufficient.
|
|
43
41
|
delete lineMaterial.defines.USE_DASH;
|
|
44
42
|
}
|
|
45
|
-
|
|
46
43
|
lineMaterial.needsUpdate = true;
|
|
47
44
|
}, [dashed, lineMaterial]);
|
|
48
45
|
React.useEffect(() => {
|
package/core/MapControls.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ReactThreeFiber } from '@react-three/fiber';
|
|
|
2
2
|
import * as THREE from 'three';
|
|
3
3
|
import { MapControls as MapControlsImpl } from 'three-stdlib';
|
|
4
4
|
import { ForwardRefComponent } from '../helpers/ts-utils';
|
|
5
|
-
export
|
|
5
|
+
export type MapControlsProps = ReactThreeFiber.Overwrite<ReactThreeFiber.Object3DNode<MapControlsImpl, typeof MapControlsImpl>, {
|
|
6
6
|
target?: ReactThreeFiber.Vector3;
|
|
7
7
|
camera?: THREE.Camera;
|
|
8
8
|
makeDefault?: boolean;
|
package/core/MapControls.js
CHANGED
|
@@ -26,12 +26,10 @@ const MapControls = /*#__PURE__*/React.forwardRef((props = {
|
|
|
26
26
|
const controls = React.useMemo(() => new MapControls$1(explCamera), [explCamera]);
|
|
27
27
|
React.useEffect(() => {
|
|
28
28
|
controls.connect(explDomElement);
|
|
29
|
-
|
|
30
29
|
const callback = e => {
|
|
31
30
|
invalidate();
|
|
32
31
|
if (onChange) onChange(e);
|
|
33
32
|
};
|
|
34
|
-
|
|
35
33
|
controls.addEventListener('change', callback);
|
|
36
34
|
if (onStart) controls.addEventListener('start', onStart);
|
|
37
35
|
if (onEnd) controls.addEventListener('end', onEnd);
|
package/core/MarchingCubes.d.ts
CHANGED
|
@@ -2,20 +2,20 @@ import * as THREE from 'three';
|
|
|
2
2
|
import { Color } from 'three';
|
|
3
3
|
import { MarchingCubes as MarchingCubesImpl } from 'three-stdlib';
|
|
4
4
|
import { ForwardRefComponent } from '../helpers/ts-utils';
|
|
5
|
-
export
|
|
5
|
+
export type MarchingCubesProps = {
|
|
6
6
|
resolution?: number;
|
|
7
7
|
maxPolyCount?: number;
|
|
8
8
|
enableUvs?: boolean;
|
|
9
9
|
enableColors?: boolean;
|
|
10
10
|
} & JSX.IntrinsicElements['group'];
|
|
11
11
|
export declare const MarchingCubes: ForwardRefComponent<MarchingCubesProps, MarchingCubesImpl>;
|
|
12
|
-
|
|
12
|
+
type MarchingCubeProps = {
|
|
13
13
|
strength?: number;
|
|
14
14
|
subtract?: number;
|
|
15
15
|
color?: Color;
|
|
16
16
|
} & JSX.IntrinsicElements['group'];
|
|
17
17
|
export declare const MarchingCube: ForwardRefComponent<MarchingCubeProps, THREE.Group>;
|
|
18
|
-
|
|
18
|
+
type MarchingPlaneProps = {
|
|
19
19
|
planeType?: 'x' | 'y' | 'z';
|
|
20
20
|
strength?: number;
|
|
21
21
|
subtract?: number;
|
package/core/Mask.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import { ForwardRefComponent } from '../helpers/ts-utils';
|
|
3
|
-
|
|
3
|
+
type Props = Omit<JSX.IntrinsicElements['mesh'], 'id'> & {
|
|
4
4
|
id: number;
|
|
5
5
|
colorWrite?: boolean;
|
|
6
6
|
depthWrite?: boolean;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { MeshPhysicalMaterial, MeshPhysicalMaterialParameters, Shader } from 'three';
|
|
2
2
|
import { ForwardRefComponent } from '../helpers/ts-utils';
|
|
3
|
-
|
|
3
|
+
type DistortMaterialType = JSX.IntrinsicElements['meshPhysicalMaterial'] & {
|
|
4
4
|
time?: number;
|
|
5
5
|
distort?: number;
|
|
6
6
|
radius?: number;
|
|
7
7
|
};
|
|
8
|
-
|
|
8
|
+
type Props = DistortMaterialType & {
|
|
9
9
|
speed?: number;
|
|
10
10
|
factor?: number;
|
|
11
11
|
};
|
|
@@ -18,7 +18,6 @@ class DistortMaterialImpl extends MeshPhysicalMaterial {
|
|
|
18
18
|
value: 1
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
|
|
22
21
|
onBeforeCompile(shader) {
|
|
23
22
|
shader.uniforms.time = this._time;
|
|
24
23
|
shader.uniforms.radius = this._radius;
|
|
@@ -36,33 +35,25 @@ class DistortMaterialImpl extends MeshPhysicalMaterial {
|
|
|
36
35
|
vec3 transformed = vec3(position * (noise * pow(distort, 2.0) + radius));
|
|
37
36
|
`);
|
|
38
37
|
}
|
|
39
|
-
|
|
40
38
|
get time() {
|
|
41
39
|
return this._time.value;
|
|
42
40
|
}
|
|
43
|
-
|
|
44
41
|
set time(v) {
|
|
45
42
|
this._time.value = v;
|
|
46
43
|
}
|
|
47
|
-
|
|
48
44
|
get distort() {
|
|
49
45
|
return this._distort.value;
|
|
50
46
|
}
|
|
51
|
-
|
|
52
47
|
set distort(v) {
|
|
53
48
|
this._distort.value = v;
|
|
54
49
|
}
|
|
55
|
-
|
|
56
50
|
get radius() {
|
|
57
51
|
return this._radius.value;
|
|
58
52
|
}
|
|
59
|
-
|
|
60
53
|
set radius(v) {
|
|
61
54
|
this._radius.value = v;
|
|
62
55
|
}
|
|
63
|
-
|
|
64
56
|
}
|
|
65
|
-
|
|
66
57
|
const MeshDistortMaterial = /*#__PURE__*/React.forwardRef(({
|
|
67
58
|
speed = 1,
|
|
68
59
|
...props
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { ReactThreeFiber } from '@react-three/fiber';
|
|
4
|
-
export
|
|
4
|
+
export type PortalMaterialType = {
|
|
5
5
|
resolution: ReactThreeFiber.Vector2;
|
|
6
6
|
blur: number;
|
|
7
7
|
blend: number;
|
|
@@ -16,7 +16,7 @@ declare global {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
export
|
|
19
|
+
export type PortalProps = JSX.IntrinsicElements['shaderMaterial'] & {
|
|
20
20
|
blend?: number;
|
|
21
21
|
blur?: number;
|
|
22
22
|
resolution?: number;
|
|
@@ -25,7 +25,7 @@ export declare type PortalProps = JSX.IntrinsicElements['shaderMaterial'] & {
|
|
|
25
25
|
renderPriority?: number;
|
|
26
26
|
events?: boolean;
|
|
27
27
|
};
|
|
28
|
-
export declare const MeshPortalMaterial: React.ForwardRefExoticComponent<
|
|
28
|
+
export declare const MeshPortalMaterial: React.ForwardRefExoticComponent<Omit<ReactThreeFiber.ExtendedColors<ReactThreeFiber.Overwrite<Partial<THREE.ShaderMaterial>, ReactThreeFiber.NodeProps<THREE.ShaderMaterial, [THREE.ShaderMaterialParameters]>>> & {
|
|
29
29
|
blend?: number | undefined;
|
|
30
30
|
blur?: number | undefined;
|
|
31
31
|
resolution?: number | undefined;
|
|
@@ -33,4 +33,4 @@ export declare const MeshPortalMaterial: React.ForwardRefExoticComponent<Pick<Re
|
|
|
33
33
|
eventPriority?: number | undefined;
|
|
34
34
|
renderPriority?: number | undefined;
|
|
35
35
|
events?: boolean | undefined;
|
|
36
|
-
}, "
|
|
36
|
+
}, "ref"> & React.RefAttributes<PortalMaterialType>>;
|
|
@@ -70,19 +70,19 @@ const MeshPortalMaterial = /*#__PURE__*/React.forwardRef(({
|
|
|
70
70
|
enabled: !events
|
|
71
71
|
});
|
|
72
72
|
}, [events]);
|
|
73
|
-
const [visible, setVisible] = React.useState(true);
|
|
74
|
-
|
|
73
|
+
const [visible, setVisible] = React.useState(true);
|
|
74
|
+
// See if the parent mesh is in the camera frustum
|
|
75
75
|
const parent = useIntersect(setVisible);
|
|
76
76
|
React.useLayoutEffect(() => {
|
|
77
77
|
var _ref$current;
|
|
78
|
-
|
|
79
78
|
// Since the ref above is not tied to a mesh directly (we're inside a material),
|
|
80
79
|
// it has to be tied to the parent mesh here
|
|
81
80
|
parent.current = (_ref$current = ref.current) == null ? void 0 : _ref$current.__r3f.parent;
|
|
82
81
|
}, []);
|
|
83
82
|
React.useLayoutEffect(() => {
|
|
84
|
-
if (!parent.current) return;
|
|
83
|
+
if (!parent.current) return;
|
|
85
84
|
|
|
85
|
+
// Apply the SDF mask only once
|
|
86
86
|
if (blur && ref.current.sdf === null) {
|
|
87
87
|
const tempMesh = new THREE.Mesh(parent.current.geometry, new THREE.MeshBasicMaterial());
|
|
88
88
|
const boundingBox = new THREE.Box3().setFromBufferAttribute(tempMesh.geometry.attributes.position);
|
|
@@ -94,14 +94,12 @@ const MeshPortalMaterial = /*#__PURE__*/React.forwardRef(({
|
|
|
94
94
|
const sg = makeSDFGenerator(resolution, resolution, gl);
|
|
95
95
|
const sdf = sg(maskRenderTarget.texture);
|
|
96
96
|
const readSdf = new Float32Array(resolution * resolution);
|
|
97
|
-
gl.readRenderTargetPixels(sdf, 0, 0, resolution, resolution, readSdf);
|
|
98
|
-
|
|
97
|
+
gl.readRenderTargetPixels(sdf, 0, 0, resolution, resolution, readSdf);
|
|
98
|
+
// Get smallest value in sdf
|
|
99
99
|
let min = Infinity;
|
|
100
|
-
|
|
101
100
|
for (let i = 0; i < readSdf.length; i++) {
|
|
102
101
|
if (readSdf[i] < min) min = readSdf[i];
|
|
103
102
|
}
|
|
104
|
-
|
|
105
103
|
min = -min;
|
|
106
104
|
ref.current.size = min;
|
|
107
105
|
ref.current.sdf = sdf.texture;
|
|
@@ -111,15 +109,12 @@ const MeshPortalMaterial = /*#__PURE__*/React.forwardRef(({
|
|
|
111
109
|
React.useImperativeHandle(fref, () => ref.current);
|
|
112
110
|
const compute = React.useCallback((event, state, previous) => {
|
|
113
111
|
var _ref$current2;
|
|
114
|
-
|
|
115
112
|
if (!parent.current) return false;
|
|
116
113
|
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
117
114
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
118
|
-
|
|
119
115
|
if (((_ref$current2 = ref.current) == null ? void 0 : _ref$current2.blend) === 0) {
|
|
120
116
|
// We run a quick check against the parent, if it isn't hit there's no need to raycast at all
|
|
121
117
|
const [intersection] = state.raycaster.intersectObject(parent.current);
|
|
122
|
-
|
|
123
118
|
if (!intersection) {
|
|
124
119
|
// Cancel out the raycast camera if the parent mesh isn't hit
|
|
125
120
|
state.raycaster.camera = undefined;
|
|
@@ -148,7 +143,6 @@ const MeshPortalMaterial = /*#__PURE__*/React.forwardRef(({
|
|
|
148
143
|
worldUnits: worldUnits
|
|
149
144
|
})));
|
|
150
145
|
});
|
|
151
|
-
|
|
152
146
|
function ManagePortalScene({
|
|
153
147
|
events = undefined,
|
|
154
148
|
rootScene,
|
|
@@ -183,17 +177,13 @@ function ManagePortalScene({
|
|
|
183
177
|
},
|
|
184
178
|
blend
|
|
185
179
|
},
|
|
186
|
-
vertexShader:
|
|
187
|
-
/*glsl*/
|
|
188
|
-
`
|
|
180
|
+
vertexShader: /*glsl*/`
|
|
189
181
|
varying vec2 vUv;
|
|
190
182
|
void main() {
|
|
191
183
|
vUv = uv;
|
|
192
184
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
193
185
|
}`,
|
|
194
|
-
fragmentShader:
|
|
195
|
-
/*glsl*/
|
|
196
|
-
`
|
|
186
|
+
fragmentShader: /*glsl*/`
|
|
197
187
|
uniform sampler2D a;
|
|
198
188
|
uniform sampler2D b;
|
|
199
189
|
uniform float blend;
|
|
@@ -210,24 +200,20 @@ function ManagePortalScene({
|
|
|
210
200
|
}, []);
|
|
211
201
|
useFrame(state => {
|
|
212
202
|
var _material$current;
|
|
213
|
-
|
|
214
|
-
let parent = material == null ? void 0 : (_material$current = material.current) == null ? void 0 : _material$current.__r3f.parent;
|
|
215
|
-
|
|
203
|
+
let parent = material == null || (_material$current = material.current) == null ? void 0 : _material$current.__r3f.parent;
|
|
216
204
|
if (parent) {
|
|
217
205
|
// Move portal contents along with the parent if worldUnits is true
|
|
218
206
|
if (!worldUnits) {
|
|
219
207
|
var _material$current2;
|
|
220
|
-
|
|
221
208
|
// If the portal renders exclusively the original scene needs to be updated
|
|
222
209
|
if (priority && ((_material$current2 = material.current) == null ? void 0 : _material$current2.blend) === 1) parent.updateWorldMatrix(true, false);
|
|
223
210
|
scene.matrixWorld.copy(parent.matrixWorld);
|
|
224
|
-
} else scene.matrixWorld.identity();
|
|
225
|
-
// and will take over the render loop
|
|
226
|
-
|
|
211
|
+
} else scene.matrixWorld.identity();
|
|
227
212
|
|
|
213
|
+
// This bit is only necessary if the portal is blended, now it has a render-priority
|
|
214
|
+
// and will take over the render loop
|
|
228
215
|
if (priority) {
|
|
229
216
|
var _material$current3, _material$current4, _material$current5;
|
|
230
|
-
|
|
231
217
|
if (((_material$current3 = material.current) == null ? void 0 : _material$current3.blend) > 0 && ((_material$current4 = material.current) == null ? void 0 : _material$current4.blend) < 1) {
|
|
232
218
|
// If blend is ongoing (> 0 and < 1) then we need to render both the root scene
|
|
233
219
|
// and the portal scene, both will then be mixed in the quad from above
|
|
@@ -247,7 +233,6 @@ function ManagePortalScene({
|
|
|
247
233
|
}, priority);
|
|
248
234
|
return /*#__PURE__*/React.createElement(React.Fragment, null);
|
|
249
235
|
}
|
|
250
|
-
|
|
251
236
|
const makeSDFGenerator = (clientWidth, clientHeight, renderer) => {
|
|
252
237
|
let finalTarget = new THREE.WebGLRenderTarget(clientWidth, clientHeight, {
|
|
253
238
|
minFilter: THREE.LinearMipmapLinearFilter,
|
|
@@ -290,17 +275,13 @@ const makeSDFGenerator = (clientWidth, clientHeight, renderer) => {
|
|
|
290
275
|
value: null
|
|
291
276
|
}
|
|
292
277
|
},
|
|
293
|
-
vertexShader:
|
|
294
|
-
/*glsl*/
|
|
295
|
-
`
|
|
278
|
+
vertexShader: /*glsl*/`
|
|
296
279
|
varying vec2 vUv;
|
|
297
280
|
void main() {
|
|
298
281
|
vUv = uv;
|
|
299
282
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
300
283
|
}`,
|
|
301
|
-
fragmentShader:
|
|
302
|
-
/*glsl*/
|
|
303
|
-
`
|
|
284
|
+
fragmentShader: /*glsl*/`
|
|
304
285
|
uniform sampler2D tex;
|
|
305
286
|
varying vec2 vUv;
|
|
306
287
|
#include <packing>
|
|
@@ -314,17 +295,13 @@ const makeSDFGenerator = (clientWidth, clientHeight, renderer) => {
|
|
|
314
295
|
value: null
|
|
315
296
|
}
|
|
316
297
|
},
|
|
317
|
-
vertexShader:
|
|
318
|
-
/*glsl*/
|
|
319
|
-
`
|
|
298
|
+
vertexShader: /*glsl*/`
|
|
320
299
|
varying vec2 vUv;
|
|
321
300
|
void main() {
|
|
322
301
|
vUv = uv;
|
|
323
302
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
324
303
|
}`,
|
|
325
|
-
fragmentShader:
|
|
326
|
-
/*glsl*/
|
|
327
|
-
`
|
|
304
|
+
fragmentShader: /*glsl*/`
|
|
328
305
|
uniform sampler2D tex;
|
|
329
306
|
varying vec2 vUv;
|
|
330
307
|
#include <packing>
|
|
@@ -347,17 +324,13 @@ const makeSDFGenerator = (clientWidth, clientHeight, renderer) => {
|
|
|
347
324
|
value: 0.0
|
|
348
325
|
}
|
|
349
326
|
},
|
|
350
|
-
vertexShader:
|
|
351
|
-
/*glsl*/
|
|
352
|
-
`
|
|
327
|
+
vertexShader: /*glsl*/`
|
|
353
328
|
varying vec2 vUv;
|
|
354
329
|
void main() {
|
|
355
330
|
vUv = uv;
|
|
356
331
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
357
332
|
}`,
|
|
358
|
-
fragmentShader:
|
|
359
|
-
/*glsl*/
|
|
360
|
-
`
|
|
333
|
+
fragmentShader: /*glsl*/`
|
|
361
334
|
varying vec2 vUv;
|
|
362
335
|
uniform sampler2D tex;
|
|
363
336
|
uniform float offset;
|
|
@@ -391,17 +364,13 @@ const makeSDFGenerator = (clientWidth, clientHeight, renderer) => {
|
|
|
391
364
|
value: new THREE.Vector2(clientWidth, clientHeight)
|
|
392
365
|
}
|
|
393
366
|
},
|
|
394
|
-
vertexShader:
|
|
395
|
-
/*glsl*/
|
|
396
|
-
`
|
|
367
|
+
vertexShader: /*glsl*/`
|
|
397
368
|
varying vec2 vUv;
|
|
398
369
|
void main() {
|
|
399
370
|
vUv = uv;
|
|
400
371
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
401
372
|
}`,
|
|
402
|
-
fragmentShader:
|
|
403
|
-
/*glsl*/
|
|
404
|
-
`
|
|
373
|
+
fragmentShader: /*glsl*/`
|
|
405
374
|
varying vec2 vUv;
|
|
406
375
|
uniform sampler2D tex;
|
|
407
376
|
uniform vec2 size;
|
|
@@ -422,17 +391,13 @@ const makeSDFGenerator = (clientWidth, clientHeight, renderer) => {
|
|
|
422
391
|
value: null
|
|
423
392
|
}
|
|
424
393
|
},
|
|
425
|
-
vertexShader:
|
|
426
|
-
/*glsl*/
|
|
427
|
-
`
|
|
394
|
+
vertexShader: /*glsl*/`
|
|
428
395
|
varying vec2 vUv;
|
|
429
396
|
void main() {
|
|
430
397
|
vUv = uv;
|
|
431
398
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
432
399
|
}`,
|
|
433
|
-
fragmentShader:
|
|
434
|
-
/*glsl*/
|
|
435
|
-
`
|
|
400
|
+
fragmentShader: /*glsl*/`
|
|
436
401
|
varying vec2 vUv;
|
|
437
402
|
uniform sampler2D inside;
|
|
438
403
|
uniform sampler2D outside;
|
|
@@ -458,7 +423,6 @@ const makeSDFGenerator = (clientWidth, clientHeight, renderer) => {
|
|
|
458
423
|
const passes = Math.ceil(Math.log(Math.max(clientWidth, clientHeight)) / Math.log(2.0));
|
|
459
424
|
let lastTarget = outsideRenderTarget;
|
|
460
425
|
let target = null;
|
|
461
|
-
|
|
462
426
|
for (let i = 0; i < passes; i++) {
|
|
463
427
|
const offset = Math.pow(2, passes - i - 1);
|
|
464
428
|
target = lastTarget === outsideRenderTarget ? outsideRenderTarget2 : outsideRenderTarget;
|
|
@@ -470,7 +434,6 @@ const makeSDFGenerator = (clientWidth, clientHeight, renderer) => {
|
|
|
470
434
|
jumpFloodRender.render(renderer);
|
|
471
435
|
lastTarget = target;
|
|
472
436
|
}
|
|
473
|
-
|
|
474
437
|
renderer.setRenderTarget(outsideRenderTargetFinal);
|
|
475
438
|
distanceFieldRender.material.uniforms.tex.value = target.texture;
|
|
476
439
|
distanceFieldRender.render(renderer);
|
|
@@ -478,7 +441,6 @@ const makeSDFGenerator = (clientWidth, clientHeight, renderer) => {
|
|
|
478
441
|
renderer.setRenderTarget(insideRenderTarget);
|
|
479
442
|
uvRenderInside.render(renderer);
|
|
480
443
|
lastTarget = insideRenderTarget;
|
|
481
|
-
|
|
482
444
|
for (let i = 0; i < passes; i++) {
|
|
483
445
|
const offset = Math.pow(2, passes - i - 1);
|
|
484
446
|
target = lastTarget === insideRenderTarget ? insideRenderTarget2 : insideRenderTarget;
|
|
@@ -490,7 +452,6 @@ const makeSDFGenerator = (clientWidth, clientHeight, renderer) => {
|
|
|
490
452
|
jumpFloodRender.render(renderer);
|
|
491
453
|
lastTarget = target;
|
|
492
454
|
}
|
|
493
|
-
|
|
494
455
|
renderer.setRenderTarget(insideRenderTargetFinal);
|
|
495
456
|
distanceFieldRender.material.uniforms.tex.value = target.texture;
|
|
496
457
|
distanceFieldRender.render(renderer);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Texture } from 'three';
|
|
2
2
|
import { MeshReflectorMaterialProps, MeshReflectorMaterial as MeshReflectorMaterialImpl } from '../materials/MeshReflectorMaterial';
|
|
3
3
|
import { ForwardRefComponent } from '../helpers/ts-utils';
|
|
4
|
-
|
|
4
|
+
type Props = JSX.IntrinsicElements['meshStandardMaterial'] & {
|
|
5
5
|
resolution?: number;
|
|
6
6
|
mixBlur?: number;
|
|
7
7
|
mixStrength?: number;
|
|
@@ -51,7 +51,6 @@ const MeshReflectorMaterial = /*#__PURE__*/React.forwardRef(({
|
|
|
51
51
|
const [virtualCamera] = React.useState(() => new PerspectiveCamera());
|
|
52
52
|
const beforeRender = React.useCallback(() => {
|
|
53
53
|
var _materialRef$current;
|
|
54
|
-
|
|
55
54
|
// TODO: As of R3f 7-8 this should be __r3f.parent
|
|
56
55
|
const parent = materialRef.current.parent || ((_materialRef$current = materialRef.current) == null ? void 0 : _materialRef$current.__r3f.parent);
|
|
57
56
|
if (!parent) return;
|
|
@@ -61,8 +60,8 @@ const MeshReflectorMaterial = /*#__PURE__*/React.forwardRef(({
|
|
|
61
60
|
normal.set(0, 0, 1);
|
|
62
61
|
normal.applyMatrix4(rotationMatrix);
|
|
63
62
|
reflectorWorldPosition.addScaledVector(normal, reflectorOffset);
|
|
64
|
-
view.subVectors(reflectorWorldPosition, cameraWorldPosition);
|
|
65
|
-
|
|
63
|
+
view.subVectors(reflectorWorldPosition, cameraWorldPosition);
|
|
64
|
+
// Avoid rendering when reflector is facing away
|
|
66
65
|
if (view.dot(normal) > 0) return;
|
|
67
66
|
view.reflect(normal).negate();
|
|
68
67
|
view.add(reflectorWorldPosition);
|
|
@@ -79,16 +78,15 @@ const MeshReflectorMaterial = /*#__PURE__*/React.forwardRef(({
|
|
|
79
78
|
virtualCamera.up.reflect(normal);
|
|
80
79
|
virtualCamera.lookAt(target);
|
|
81
80
|
virtualCamera.far = camera.far; // Used in WebGLBackground
|
|
82
|
-
|
|
83
81
|
virtualCamera.updateMatrixWorld();
|
|
84
|
-
virtualCamera.projectionMatrix.copy(camera.projectionMatrix);
|
|
85
|
-
|
|
82
|
+
virtualCamera.projectionMatrix.copy(camera.projectionMatrix);
|
|
83
|
+
// Update the texture matrix
|
|
86
84
|
textureMatrix.set(0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0);
|
|
87
85
|
textureMatrix.multiply(virtualCamera.projectionMatrix);
|
|
88
86
|
textureMatrix.multiply(virtualCamera.matrixWorldInverse);
|
|
89
|
-
textureMatrix.multiply(parent.matrixWorld);
|
|
87
|
+
textureMatrix.multiply(parent.matrixWorld);
|
|
88
|
+
// Now update projection matrix with new clip plane, implementing code from: http://www.terathon.com/code/oblique.html
|
|
90
89
|
// Paper explaining this technique: http://www.terathon.com/lengyel/Lengyel-Oblique.pdf
|
|
91
|
-
|
|
92
90
|
reflectorPlane.setFromNormalAndCoplanarPoint(normal, reflectorWorldPosition);
|
|
93
91
|
reflectorPlane.applyMatrix4(virtualCamera.matrixWorldInverse);
|
|
94
92
|
clipPlane.set(reflectorPlane.normal.x, reflectorPlane.normal.y, reflectorPlane.normal.z, reflectorPlane.constant);
|
|
@@ -96,10 +94,10 @@ const MeshReflectorMaterial = /*#__PURE__*/React.forwardRef(({
|
|
|
96
94
|
q.x = (Math.sign(clipPlane.x) + projectionMatrix.elements[8]) / projectionMatrix.elements[0];
|
|
97
95
|
q.y = (Math.sign(clipPlane.y) + projectionMatrix.elements[9]) / projectionMatrix.elements[5];
|
|
98
96
|
q.z = -1.0;
|
|
99
|
-
q.w = (1.0 + projectionMatrix.elements[10]) / projectionMatrix.elements[14];
|
|
100
|
-
|
|
101
|
-
clipPlane.multiplyScalar(2.0 / clipPlane.dot(q));
|
|
102
|
-
|
|
97
|
+
q.w = (1.0 + projectionMatrix.elements[10]) / projectionMatrix.elements[14];
|
|
98
|
+
// Calculate the scaled plane vector
|
|
99
|
+
clipPlane.multiplyScalar(2.0 / clipPlane.dot(q));
|
|
100
|
+
// Replacing the third row of the projection matrix
|
|
103
101
|
projectionMatrix.elements[2] = clipPlane.x;
|
|
104
102
|
projectionMatrix.elements[6] = clipPlane.y;
|
|
105
103
|
projectionMatrix.elements[10] = clipPlane.z + 1.0;
|
|
@@ -151,7 +149,6 @@ const MeshReflectorMaterial = /*#__PURE__*/React.forwardRef(({
|
|
|
151
149
|
}, [gl, blur, textureMatrix, resolution, mirror, hasBlur, mixBlur, mixStrength, minDepthThreshold, maxDepthThreshold, depthScale, depthToBlurRatioBias, distortion, distortionMap, mixContrast]);
|
|
152
150
|
useFrame(() => {
|
|
153
151
|
var _materialRef$current2;
|
|
154
|
-
|
|
155
152
|
// TODO: As of R3f 7-8 this should be __r3f.parent
|
|
156
153
|
const parent = materialRef.current.parent || ((_materialRef$current2 = materialRef.current) == null ? void 0 : _materialRef$current2.__r3f.parent);
|
|
157
154
|
if (!parent) return;
|
|
@@ -172,7 +169,8 @@ const MeshReflectorMaterial = /*#__PURE__*/React.forwardRef(({
|
|
|
172
169
|
gl.setRenderTarget(null);
|
|
173
170
|
});
|
|
174
171
|
return /*#__PURE__*/React.createElement("meshReflectorMaterialImpl", _extends({
|
|
175
|
-
attach: "material"
|
|
172
|
+
attach: "material"
|
|
173
|
+
// Defines can't be updated dynamically, so we need to recreate the material
|
|
176
174
|
,
|
|
177
175
|
key: 'key' + reflectorProps['defines-USE_BLUR'] + reflectorProps['defines-USE_DEPTH'] + reflectorProps['defines-USE_DISTORTION'],
|
|
178
176
|
ref: mergeRefs([materialRef, ref])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),r=require("react"),t=require("@react-three/fiber"),a=require("three-mesh-bvh"),n=require("../materials/MeshRefractionMaterial.cjs.js");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function o(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var a=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,a.get?a:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}require("three"),require("./shaderMaterial.cjs.js");var u=i(e),s=o(r);exports.MeshRefractionMaterial=function({aberrationStrength:e=0,fastChroma:i=!0,envMap:o,...c}){t.extend({MeshRefractionMaterial:n.MeshRefractionMaterial});const l=r.useRef(),{size:f}=t.useThree(),h=r.useMemo((()=>{var r,t;const a={},n=(u=o)&&u.isCubeTexture;var u;const s=(null!==(r=n?null==(t=o.image[0])?void 0:t.width:o.image.width)&&void 0!==r?r:1024)/4,c=Math.floor(Math.log2(s)),l=Math.pow(2,c),f=3*Math.max(l,112),h=4*l;return n&&(a.ENVMAP_TYPE_CUBEM=""),a.CUBEUV_TEXEL_WIDTH=""+1/f,a.CUBEUV_TEXEL_HEIGHT=""+1/h,a.CUBEUV_MAX_MIP=`${c}.0`,e>0&&(a.CHROMATIC_ABERRATIONS=""),i&&(a.FAST_CHROMA=""),a}),[e,i]);return r.useLayoutEffect((()=>{var e
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),r=require("react"),t=require("@react-three/fiber"),a=require("three-mesh-bvh"),n=require("../materials/MeshRefractionMaterial.cjs.js");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function o(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var a=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,a.get?a:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}require("three"),require("./shaderMaterial.cjs.js");var u=i(e),s=o(r);exports.MeshRefractionMaterial=function({aberrationStrength:e=0,fastChroma:i=!0,envMap:o,...c}){t.extend({MeshRefractionMaterial:n.MeshRefractionMaterial});const l=r.useRef(),{size:f}=t.useThree(),h=r.useMemo((()=>{var r,t;const a={},n=(u=o)&&u.isCubeTexture;var u;const s=(null!==(r=n?null==(t=o.image[0])?void 0:t.width:o.image.width)&&void 0!==r?r:1024)/4,c=Math.floor(Math.log2(s)),l=Math.pow(2,c),f=3*Math.max(l,112),h=4*l;return n&&(a.ENVMAP_TYPE_CUBEM=""),a.CUBEUV_TEXEL_WIDTH=""+1/f,a.CUBEUV_TEXEL_HEIGHT=""+1/h,a.CUBEUV_MAX_MIP=`${c}.0`,e>0&&(a.CHROMATIC_ABERRATIONS=""),i&&(a.FAST_CHROMA=""),a}),[e,i]);return r.useLayoutEffect((()=>{var e;const r=null==(e=l.current)||null==(e=e.__r3f)||null==(e=e.parent)?void 0:e.geometry;r&&(l.current.bvh=new a.MeshBVHUniformStruct,l.current.bvh.updateFrom(new a.MeshBVH(r.clone().toNonIndexed(),{lazyGeneration:!1,strategy:a.SAH})))}),[]),t.useFrame((({camera:e})=>{l.current.viewMatrixInverse=e.matrixWorld,l.current.projectionMatrixInverse=e.projectionMatrixInverse})),s.createElement("meshRefractionMaterial",u.default({key:JSON.stringify(h),defines:h,ref:l,resolution:[f.width,f.height],aberrationStrength:e,envMap:o},c))};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import * as THREE from 'three';
|
|
2
|
+
import * as React from 'react';
|
|
3
3
|
import { ReactThreeFiber } from '@react-three/fiber';
|
|
4
4
|
import { MeshRefractionMaterial as MeshRefractionMaterial_ } from '../materials/MeshRefractionMaterial';
|
|
5
5
|
declare global {
|
|
@@ -9,7 +9,7 @@ declare global {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
type MeshRefractionMaterialProps = JSX.IntrinsicElements['shaderMaterial'] & {
|
|
13
13
|
envMap: THREE.CubeTexture | THREE.Texture;
|
|
14
14
|
bounces?: number;
|
|
15
15
|
ior?: number;
|
|
@@ -18,5 +18,5 @@ declare type MeshRefractionMaterialProps = JSX.IntrinsicElements['shaderMaterial
|
|
|
18
18
|
color?: ReactThreeFiber.Color;
|
|
19
19
|
fastChroma?: boolean;
|
|
20
20
|
};
|
|
21
|
-
export declare function MeshRefractionMaterial({ aberrationStrength, fastChroma, envMap, ...props }: MeshRefractionMaterialProps): JSX.Element;
|
|
21
|
+
export declare function MeshRefractionMaterial({ aberrationStrength, fastChroma, envMap, ...props }: MeshRefractionMaterialProps): React.JSX.Element;
|
|
22
22
|
export {};
|
|
@@ -6,7 +6,6 @@ import { MeshBVHUniformStruct, MeshBVH, SAH } from 'three-mesh-bvh';
|
|
|
6
6
|
import { MeshRefractionMaterial as MeshRefractionMaterial$1 } from '../materials/MeshRefractionMaterial.js';
|
|
7
7
|
|
|
8
8
|
const isCubeTexture = def => def && def.isCubeTexture;
|
|
9
|
-
|
|
10
9
|
function MeshRefractionMaterial({
|
|
11
10
|
aberrationStrength = 0,
|
|
12
11
|
fastChroma = true,
|
|
@@ -22,34 +21,29 @@ function MeshRefractionMaterial({
|
|
|
22
21
|
} = useThree();
|
|
23
22
|
const defines = useMemo(() => {
|
|
24
23
|
var _ref, _envMap$image$;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
const temp = {};
|
|
25
|
+
// Sampler2D and SamplerCube need different defines
|
|
28
26
|
const isCubeMap = isCubeTexture(envMap);
|
|
29
27
|
const w = (_ref = isCubeMap ? (_envMap$image$ = envMap.image[0]) == null ? void 0 : _envMap$image$.width : envMap.image.width) !== null && _ref !== void 0 ? _ref : 1024;
|
|
30
28
|
const cubeSize = w / 4;
|
|
31
|
-
|
|
32
29
|
const _lodMax = Math.floor(Math.log2(cubeSize));
|
|
33
|
-
|
|
34
30
|
const _cubeSize = Math.pow(2, _lodMax);
|
|
35
|
-
|
|
36
31
|
const width = 3 * Math.max(_cubeSize, 16 * 7);
|
|
37
32
|
const height = 4 * _cubeSize;
|
|
38
33
|
if (isCubeMap) temp.ENVMAP_TYPE_CUBEM = '';
|
|
39
34
|
temp.CUBEUV_TEXEL_WIDTH = `${1.0 / width}`;
|
|
40
35
|
temp.CUBEUV_TEXEL_HEIGHT = `${1.0 / height}`;
|
|
41
|
-
temp.CUBEUV_MAX_MIP = `${_lodMax}.0`;
|
|
42
|
-
|
|
36
|
+
temp.CUBEUV_MAX_MIP = `${_lodMax}.0`;
|
|
37
|
+
// Add defines from chromatic aberration
|
|
43
38
|
if (aberrationStrength > 0) temp.CHROMATIC_ABERRATIONS = '';
|
|
44
39
|
if (fastChroma) temp.FAST_CHROMA = '';
|
|
45
40
|
return temp;
|
|
46
41
|
}, [aberrationStrength, fastChroma]);
|
|
47
42
|
useLayoutEffect(() => {
|
|
48
|
-
var _material$current
|
|
49
|
-
|
|
43
|
+
var _material$current;
|
|
50
44
|
// Get the geometry of this materials parent
|
|
51
|
-
const geometry = (_material$current = material.current) == null
|
|
52
|
-
|
|
45
|
+
const geometry = (_material$current = material.current) == null || (_material$current = _material$current.__r3f) == null || (_material$current = _material$current.parent) == null ? void 0 : _material$current.geometry;
|
|
46
|
+
// Update the BVH
|
|
53
47
|
if (geometry) {
|
|
54
48
|
material.current.bvh = new MeshBVHUniformStruct();
|
|
55
49
|
material.current.bvh.updateFrom(new MeshBVH(geometry.clone().toNonIndexed(), {
|
|
@@ -66,7 +60,8 @@ function MeshRefractionMaterial({
|
|
|
66
60
|
});
|
|
67
61
|
return /*#__PURE__*/React.createElement("meshRefractionMaterial", _extends({
|
|
68
62
|
// @ts-ignore
|
|
69
|
-
key: JSON.stringify(defines)
|
|
63
|
+
key: JSON.stringify(defines)
|
|
64
|
+
// @ts-ignore
|
|
70
65
|
,
|
|
71
66
|
defines: defines,
|
|
72
67
|
ref: material,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import { ForwardRefComponent } from '../helpers/ts-utils';
|
|
3
|
-
|
|
3
|
+
type MeshTransmissionMaterialType = Omit<JSX.IntrinsicElements['meshPhysicalMaterial'], 'args' | 'roughness' | 'thickness' | 'transmission'> & {
|
|
4
4
|
transmission?: number;
|
|
5
5
|
thickness?: number;
|
|
6
6
|
roughness?: number;
|
|
@@ -14,7 +14,7 @@ declare type MeshTransmissionMaterialType = Omit<JSX.IntrinsicElements['meshPhys
|
|
|
14
14
|
time?: number;
|
|
15
15
|
args?: [samples: number, transmissionSampler: boolean];
|
|
16
16
|
};
|
|
17
|
-
|
|
17
|
+
type MeshTransmissionMaterialProps = Omit<MeshTransmissionMaterialType, 'args'> & {
|
|
18
18
|
transmissionSampler?: boolean;
|
|
19
19
|
backside?: boolean;
|
|
20
20
|
backsideThickness?: number;
|