@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
package/core/Bounds.js
CHANGED
|
@@ -3,9 +3,7 @@ import * as THREE from 'three';
|
|
|
3
3
|
import { useThree, useFrame } from '@react-three/fiber';
|
|
4
4
|
|
|
5
5
|
const isOrthographic = def => def && def.isOrthographicCamera;
|
|
6
|
-
|
|
7
6
|
const isBox3 = def => def && def.isBox3;
|
|
8
|
-
|
|
9
7
|
const context = /*#__PURE__*/React.createContext(null);
|
|
10
8
|
function Bounds({
|
|
11
9
|
children,
|
|
@@ -27,17 +25,14 @@ function Bounds({
|
|
|
27
25
|
const controls = controlsImpl;
|
|
28
26
|
const onFitRef = React.useRef(onFit);
|
|
29
27
|
onFitRef.current = onFit;
|
|
30
|
-
|
|
31
28
|
function equals(a, b) {
|
|
32
29
|
return Math.abs(a.x - b.x) < eps && Math.abs(a.y - b.y) < eps && Math.abs(a.z - b.z) < eps;
|
|
33
30
|
}
|
|
34
|
-
|
|
35
31
|
function damp(v, t, lambda, delta) {
|
|
36
32
|
v.x = THREE.MathUtils.damp(v.x, t.x, lambda, delta);
|
|
37
33
|
v.y = THREE.MathUtils.damp(v.y, t.y, lambda, delta);
|
|
38
34
|
v.z = THREE.MathUtils.damp(v.z, t.z, lambda, delta);
|
|
39
35
|
}
|
|
40
|
-
|
|
41
36
|
const [current] = React.useState(() => ({
|
|
42
37
|
animating: false,
|
|
43
38
|
focus: new THREE.Vector3(),
|
|
@@ -65,10 +60,8 @@ function Bounds({
|
|
|
65
60
|
distance
|
|
66
61
|
};
|
|
67
62
|
}
|
|
68
|
-
|
|
69
63
|
return {
|
|
70
64
|
getSize,
|
|
71
|
-
|
|
72
65
|
refresh(object) {
|
|
73
66
|
if (isBox3(object)) box.copy(object);else {
|
|
74
67
|
const target = object || ref.current;
|
|
@@ -76,12 +69,10 @@ function Bounds({
|
|
|
76
69
|
target.updateWorldMatrix(true, true);
|
|
77
70
|
box.setFromObject(target);
|
|
78
71
|
}
|
|
79
|
-
|
|
80
72
|
if (box.isEmpty()) {
|
|
81
73
|
const max = camera.position.length() || 10;
|
|
82
74
|
box.setFromCenterAndSize(new THREE.Vector3(), new THREE.Vector3(max, max, max));
|
|
83
75
|
}
|
|
84
|
-
|
|
85
76
|
if ((controls == null ? void 0 : controls.constructor.name) === 'OrthographicTrackballControls') {
|
|
86
77
|
// Put camera on a sphere along which it should move
|
|
87
78
|
const {
|
|
@@ -91,10 +82,8 @@ function Bounds({
|
|
|
91
82
|
const newPos = controls.target.clone().add(direction);
|
|
92
83
|
camera.position.copy(newPos);
|
|
93
84
|
}
|
|
94
|
-
|
|
95
85
|
return this;
|
|
96
86
|
},
|
|
97
|
-
|
|
98
87
|
clip() {
|
|
99
88
|
const {
|
|
100
89
|
distance
|
|
@@ -107,7 +96,6 @@ function Bounds({
|
|
|
107
96
|
invalidate();
|
|
108
97
|
return this;
|
|
109
98
|
},
|
|
110
|
-
|
|
111
99
|
to({
|
|
112
100
|
position,
|
|
113
101
|
target
|
|
@@ -117,22 +105,18 @@ function Bounds({
|
|
|
117
105
|
center
|
|
118
106
|
} = getSize();
|
|
119
107
|
goal.camera.set(...position);
|
|
120
|
-
|
|
121
108
|
if (target) {
|
|
122
109
|
goal.focus.set(...target);
|
|
123
110
|
} else {
|
|
124
111
|
goal.focus.copy(center);
|
|
125
112
|
}
|
|
126
|
-
|
|
127
113
|
if (damping) {
|
|
128
114
|
current.animating = true;
|
|
129
115
|
} else {
|
|
130
116
|
camera.position.set(...position);
|
|
131
117
|
}
|
|
132
|
-
|
|
133
118
|
return this;
|
|
134
119
|
},
|
|
135
|
-
|
|
136
120
|
fit() {
|
|
137
121
|
current.camera.copy(camera.position);
|
|
138
122
|
if (controls) current.focus.copy(controls.target);
|
|
@@ -143,62 +127,54 @@ function Bounds({
|
|
|
143
127
|
const direction = center.clone().sub(camera.position).normalize().multiplyScalar(distance);
|
|
144
128
|
goal.camera.copy(center).sub(direction);
|
|
145
129
|
goal.focus.copy(center);
|
|
146
|
-
|
|
147
130
|
if (isOrthographic(camera)) {
|
|
148
131
|
current.zoom = camera.zoom;
|
|
149
132
|
let maxHeight = 0,
|
|
150
|
-
|
|
151
|
-
const vertices = [new THREE.Vector3(box.min.x, box.min.y, box.min.z), new THREE.Vector3(box.min.x, box.max.y, box.min.z), new THREE.Vector3(box.min.x, box.min.y, box.max.z), new THREE.Vector3(box.min.x, box.max.y, box.max.z), new THREE.Vector3(box.max.x, box.max.y, box.max.z), new THREE.Vector3(box.max.x, box.max.y, box.min.z), new THREE.Vector3(box.max.x, box.min.y, box.max.z), new THREE.Vector3(box.max.x, box.min.y, box.min.z)];
|
|
152
|
-
|
|
133
|
+
maxWidth = 0;
|
|
134
|
+
const vertices = [new THREE.Vector3(box.min.x, box.min.y, box.min.z), new THREE.Vector3(box.min.x, box.max.y, box.min.z), new THREE.Vector3(box.min.x, box.min.y, box.max.z), new THREE.Vector3(box.min.x, box.max.y, box.max.z), new THREE.Vector3(box.max.x, box.max.y, box.max.z), new THREE.Vector3(box.max.x, box.max.y, box.min.z), new THREE.Vector3(box.max.x, box.min.y, box.max.z), new THREE.Vector3(box.max.x, box.min.y, box.min.z)];
|
|
135
|
+
// Transform the center and each corner to camera space
|
|
153
136
|
center.applyMatrix4(camera.matrixWorldInverse);
|
|
154
|
-
|
|
155
137
|
for (const v of vertices) {
|
|
156
138
|
v.applyMatrix4(camera.matrixWorldInverse);
|
|
157
139
|
maxHeight = Math.max(maxHeight, Math.abs(v.y - center.y));
|
|
158
140
|
maxWidth = Math.max(maxWidth, Math.abs(v.x - center.x));
|
|
159
141
|
}
|
|
160
|
-
|
|
161
142
|
maxHeight *= 2;
|
|
162
143
|
maxWidth *= 2;
|
|
163
144
|
const zoomForHeight = (camera.top - camera.bottom) / maxHeight;
|
|
164
145
|
const zoomForWidth = (camera.right - camera.left) / maxWidth;
|
|
165
146
|
goal.zoom = Math.min(zoomForHeight, zoomForWidth) / margin;
|
|
166
|
-
|
|
167
147
|
if (!damping) {
|
|
168
148
|
camera.zoom = goal.zoom;
|
|
169
149
|
camera.updateProjectionMatrix();
|
|
170
150
|
}
|
|
171
151
|
}
|
|
172
|
-
|
|
173
152
|
if (damping) {
|
|
174
153
|
current.animating = true;
|
|
175
154
|
} else {
|
|
176
155
|
camera.position.copy(goal.camera);
|
|
177
156
|
camera.lookAt(goal.focus);
|
|
178
|
-
|
|
179
157
|
if (controls) {
|
|
180
158
|
controls.target.copy(goal.focus);
|
|
181
159
|
controls.update();
|
|
182
160
|
}
|
|
183
161
|
}
|
|
184
|
-
|
|
185
162
|
if (onFitRef.current) onFitRef.current(this.getSize());
|
|
186
163
|
invalidate();
|
|
187
164
|
return this;
|
|
188
165
|
}
|
|
189
|
-
|
|
190
166
|
};
|
|
191
167
|
}, [box, camera, controls, margin, damping, invalidate]);
|
|
192
168
|
React.useLayoutEffect(() => {
|
|
193
169
|
if (controls) {
|
|
194
170
|
// Try to prevent drag hijacking
|
|
195
171
|
const callback = () => current.animating = false;
|
|
196
|
-
|
|
197
172
|
controls.addEventListener('start', callback);
|
|
198
173
|
return () => controls.removeEventListener('start', callback);
|
|
199
174
|
}
|
|
200
|
-
}, [controls]);
|
|
175
|
+
}, [controls]);
|
|
201
176
|
|
|
177
|
+
// Scale pointer on window resize
|
|
202
178
|
const count = React.useRef(0);
|
|
203
179
|
React.useLayoutEffect(() => {
|
|
204
180
|
if (observe || count.current++ === 0) {
|
|
@@ -213,19 +189,16 @@ function Bounds({
|
|
|
213
189
|
damp(current.camera, goal.camera, damping, delta);
|
|
214
190
|
current.zoom = THREE.MathUtils.damp(current.zoom, goal.zoom, damping, delta);
|
|
215
191
|
camera.position.copy(current.camera);
|
|
216
|
-
|
|
217
192
|
if (isOrthographic(camera)) {
|
|
218
193
|
camera.zoom = current.zoom;
|
|
219
194
|
camera.updateProjectionMatrix();
|
|
220
195
|
}
|
|
221
|
-
|
|
222
196
|
if (!controls) {
|
|
223
197
|
camera.lookAt(current.focus);
|
|
224
198
|
} else {
|
|
225
199
|
controls.target.copy(current.focus);
|
|
226
200
|
controls.update();
|
|
227
201
|
}
|
|
228
|
-
|
|
229
202
|
invalidate();
|
|
230
203
|
if (isOrthographic(camera) && !(Math.abs(current.zoom - goal.zoom) < eps)) return;
|
|
231
204
|
if (!isOrthographic(camera) && !equals(current.camera, goal.camera)) return;
|
package/core/CameraControls.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { OrthographicCamera, PerspectiveCamera } from 'three';
|
|
|
2
2
|
import { ReactThreeFiber } from '@react-three/fiber';
|
|
3
3
|
import CameraControlsImpl from 'camera-controls';
|
|
4
4
|
import { ForwardRefComponent } from '../helpers/ts-utils';
|
|
5
|
-
export
|
|
5
|
+
export type CameraControlsProps = Omit<ReactThreeFiber.Overwrite<ReactThreeFiber.Node<CameraControlsImpl, typeof CameraControlsImpl>, {
|
|
6
6
|
camera?: PerspectiveCamera | OrthographicCamera;
|
|
7
7
|
domElement?: HTMLElement;
|
|
8
8
|
makeDefault?: boolean;
|
|
@@ -19,4 +19,4 @@ export declare type CameraControlsProps = Omit<ReactThreeFiber.Overwrite<ReactTh
|
|
|
19
19
|
regress?: boolean;
|
|
20
20
|
}>, 'ref'>;
|
|
21
21
|
export declare const CameraControls: ForwardRefComponent<CameraControlsProps, CameraControlsImpl>;
|
|
22
|
-
export
|
|
22
|
+
export type CameraControls = CameraControlsImpl;
|
package/core/CameraControls.js
CHANGED
|
@@ -65,15 +65,12 @@ const CameraControls = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
65
65
|
if (regress) performance.regress();
|
|
66
66
|
if (onChange) onChange(e);
|
|
67
67
|
};
|
|
68
|
-
|
|
69
68
|
const onStartCb = e => {
|
|
70
69
|
if (onStart) onStart(e);
|
|
71
70
|
};
|
|
72
|
-
|
|
73
71
|
const onEndCb = e => {
|
|
74
72
|
if (onEnd) onEnd(e);
|
|
75
73
|
};
|
|
76
|
-
|
|
77
74
|
controls.addEventListener('update', callback);
|
|
78
75
|
controls.addEventListener('controlstart', onStartCb);
|
|
79
76
|
controls.addEventListener('controlend', onEndCb);
|
package/core/CameraShake.js
CHANGED
|
@@ -20,13 +20,11 @@ const CameraShake = /*#__PURE__*/React.forwardRef(({
|
|
|
20
20
|
const [yawNoise] = React.useState(() => new SimplexNoise());
|
|
21
21
|
const [pitchNoise] = React.useState(() => new SimplexNoise());
|
|
22
22
|
const [rollNoise] = React.useState(() => new SimplexNoise());
|
|
23
|
-
|
|
24
23
|
const constrainIntensity = () => {
|
|
25
24
|
if (intensityRef.current < 0 || intensityRef.current > 1) {
|
|
26
25
|
intensityRef.current = intensityRef.current < 0 ? 0 : 1;
|
|
27
26
|
}
|
|
28
27
|
};
|
|
29
|
-
|
|
30
28
|
React.useImperativeHandle(ref, () => ({
|
|
31
29
|
getIntensity: () => intensityRef.current,
|
|
32
30
|
setIntensity: val => {
|
|
@@ -37,7 +35,6 @@ const CameraShake = /*#__PURE__*/React.forwardRef(({
|
|
|
37
35
|
React.useEffect(() => {
|
|
38
36
|
if (defaultControls) {
|
|
39
37
|
const callback = () => void (initialRotation.current = camera.rotation.clone());
|
|
40
|
-
|
|
41
38
|
defaultControls.addEventListener('change', callback);
|
|
42
39
|
callback();
|
|
43
40
|
return () => void defaultControls.removeEventListener('change', callback);
|
|
@@ -49,7 +46,6 @@ const CameraShake = /*#__PURE__*/React.forwardRef(({
|
|
|
49
46
|
const pitch = maxPitch * shake * pitchNoise.noise(state.clock.elapsedTime * pitchFrequency, 1);
|
|
50
47
|
const roll = maxRoll * shake * rollNoise.noise(state.clock.elapsedTime * rollFrequency, 1);
|
|
51
48
|
camera.rotation.set(initialRotation.current.x + pitch, initialRotation.current.y + yaw, initialRotation.current.z + roll);
|
|
52
|
-
|
|
53
49
|
if (decay && intensityRef.current > 0) {
|
|
54
50
|
intensityRef.current -= decayRate * delta;
|
|
55
51
|
constrainIntensity();
|
package/core/CatmullRomLine.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Line2 } from 'three-stdlib';
|
|
2
2
|
import { LineProps } from './Line';
|
|
3
3
|
import { ForwardRefComponent } from '../helpers/ts-utils';
|
|
4
|
-
|
|
4
|
+
type Props = Omit<LineProps, 'ref'> & {
|
|
5
5
|
closed?: boolean;
|
|
6
6
|
curveType?: 'centripetal' | 'chordal' | 'catmullrom';
|
|
7
7
|
tension?: number;
|
package/core/CatmullRomLine.js
CHANGED
|
@@ -24,13 +24,11 @@ const CatmullRomLine = /*#__PURE__*/React.forwardRef(function CatmullRomLine({
|
|
|
24
24
|
if (closed) mappedColors.push(mappedColors[0].clone());
|
|
25
25
|
const iColors = [mappedColors[0]];
|
|
26
26
|
const divisions = segments / (mappedColors.length - 1);
|
|
27
|
-
|
|
28
27
|
for (let i = 1; i < segments; i++) {
|
|
29
28
|
const alpha = i % divisions / divisions;
|
|
30
29
|
const colorIndex = Math.floor(i / divisions);
|
|
31
30
|
iColors.push(mappedColors[colorIndex].clone().lerp(mappedColors[colorIndex + 1], alpha));
|
|
32
31
|
}
|
|
33
|
-
|
|
34
32
|
iColors.push(mappedColors[mappedColors.length - 1]);
|
|
35
33
|
return iColors;
|
|
36
34
|
}, [vertexColors, segments]);
|
package/core/Caustics.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as THREE from 'three';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { ReactThreeFiber } from '@react-three/fiber';
|
|
4
4
|
import { ForwardRefComponent } from '../helpers/ts-utils';
|
|
5
|
-
|
|
5
|
+
type CausticsProps = JSX.IntrinsicElements['group'] & {
|
|
6
6
|
frames?: number;
|
|
7
7
|
debug?: boolean;
|
|
8
8
|
causticsOnly: boolean;
|
package/core/Caustics.js
CHANGED
|
@@ -25,7 +25,6 @@ function createNormalMaterial(side = THREE.FrontSide) {
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
-
|
|
29
28
|
const CausticsProjectionMaterial = shaderMaterial({
|
|
30
29
|
causticsTexture: null,
|
|
31
30
|
causticsTextureB: null,
|
|
@@ -71,16 +70,12 @@ const CausticsMaterial = shaderMaterial({
|
|
|
71
70
|
resolution: 1024,
|
|
72
71
|
size: 10,
|
|
73
72
|
intensity: 0.5
|
|
74
|
-
},
|
|
75
|
-
/* glsl */
|
|
76
|
-
`
|
|
73
|
+
}, /* glsl */`
|
|
77
74
|
varying vec2 vUv;
|
|
78
75
|
void main() {
|
|
79
76
|
vUv = uv;
|
|
80
77
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
81
|
-
}`,
|
|
82
|
-
/* glsl */
|
|
83
|
-
`
|
|
78
|
+
}`, /* glsl */`
|
|
84
79
|
uniform mat4 cameraMatrixWorld;
|
|
85
80
|
uniform mat4 cameraProjectionMatrixInv;
|
|
86
81
|
uniform vec3 lightDir;
|
|
@@ -218,16 +213,17 @@ const Caustics = /*#__PURE__*/React.forwardRef(({
|
|
|
218
213
|
const scene = React.useRef(null);
|
|
219
214
|
const plane = React.useRef(null);
|
|
220
215
|
const gl = useThree(state => state.gl);
|
|
221
|
-
const helper = useHelper(debug && camera, THREE.CameraHelper);
|
|
216
|
+
const helper = useHelper(debug && camera, THREE.CameraHelper);
|
|
222
217
|
|
|
218
|
+
// Buffers for front and back faces
|
|
223
219
|
const normalTarget = useFBO(resolution, resolution, NORMALPROPS);
|
|
224
220
|
const normalTargetB = useFBO(resolution, resolution, NORMALPROPS);
|
|
225
221
|
const causticsTarget = useFBO(resolution, resolution, CAUSTICPROPS);
|
|
226
|
-
const causticsTargetB = useFBO(resolution, resolution, CAUSTICPROPS);
|
|
227
|
-
|
|
222
|
+
const causticsTargetB = useFBO(resolution, resolution, CAUSTICPROPS);
|
|
223
|
+
// Normal materials for front and back faces
|
|
228
224
|
const [normalMat] = React.useState(() => createNormalMaterial());
|
|
229
|
-
const [normalMatB] = React.useState(() => createNormalMaterial(THREE.BackSide));
|
|
230
|
-
|
|
225
|
+
const [normalMatB] = React.useState(() => createNormalMaterial(THREE.BackSide));
|
|
226
|
+
// The quad that catches the caustics
|
|
231
227
|
const [causticsMaterial] = React.useState(() => new CausticsMaterial());
|
|
232
228
|
const [causticsQuad] = React.useState(() => new FullScreenQuad(causticsMaterial));
|
|
233
229
|
React.useLayoutEffect(() => {
|
|
@@ -247,21 +243,18 @@ const Caustics = /*#__PURE__*/React.forwardRef(({
|
|
|
247
243
|
const projectedVerts = [];
|
|
248
244
|
const lightDirs = [];
|
|
249
245
|
const cameraPos = new THREE.Vector3();
|
|
250
|
-
|
|
251
246
|
for (let i = 0; i < 8; i++) {
|
|
252
247
|
boundsVertices.push(new THREE.Vector3());
|
|
253
248
|
worldVerts.push(new THREE.Vector3());
|
|
254
249
|
projectedVerts.push(new THREE.Vector3());
|
|
255
250
|
lightDirs.push(new THREE.Vector3());
|
|
256
251
|
}
|
|
257
|
-
|
|
258
252
|
useFrame(() => {
|
|
259
253
|
if (frames === Infinity || count++ < frames) {
|
|
260
254
|
var _scene$current$parent, _helper$current;
|
|
261
|
-
|
|
262
255
|
if (Array.isArray(lightSource)) lightDir.fromArray(lightSource).normalize();else lightDir.copy(ref.current.worldToLocal(lightSource.current.getWorldPosition(v)).normalize());
|
|
263
256
|
lightDirInv.copy(lightDir).multiplyScalar(-1);
|
|
264
|
-
(_scene$current$parent = scene.current.parent) == null
|
|
257
|
+
(_scene$current$parent = scene.current.parent) == null || _scene$current$parent.matrixWorld.identity();
|
|
265
258
|
bounds.setFromObject(scene.current, true);
|
|
266
259
|
boundsVertices[0].set(bounds.min.x, bounds.min.y, bounds.min.z);
|
|
267
260
|
boundsVertices[1].set(bounds.min.x, bounds.min.y, bounds.max.z);
|
|
@@ -271,19 +264,17 @@ const Caustics = /*#__PURE__*/React.forwardRef(({
|
|
|
271
264
|
boundsVertices[5].set(bounds.max.x, bounds.min.y, bounds.max.z);
|
|
272
265
|
boundsVertices[6].set(bounds.max.x, bounds.max.y, bounds.min.z);
|
|
273
266
|
boundsVertices[7].set(bounds.max.x, bounds.max.y, bounds.max.z);
|
|
274
|
-
|
|
275
267
|
for (let i = 0; i < 8; i++) {
|
|
276
268
|
worldVerts[i].copy(boundsVertices[i]);
|
|
277
269
|
}
|
|
278
|
-
|
|
279
270
|
bounds.getCenter(focusPos);
|
|
280
271
|
boundsVertices.map(v => v.sub(focusPos));
|
|
281
272
|
const lightPlane = lpP.set(lightDirInv, 0);
|
|
282
273
|
boundsVertices.map((v, i) => lightPlane.projectPoint(v, projectedVerts[i]));
|
|
283
274
|
const centralVert = projectedVerts.reduce((a, b) => a.add(b), v.set(0, 0, 0)).divideScalar(projectedVerts.length);
|
|
284
275
|
const radius = projectedVerts.map(v => v.distanceTo(centralVert)).reduce((a, b) => Math.max(a, b));
|
|
285
|
-
const dirLength = boundsVertices.map(x => x.dot(lightDir)).reduce((a, b) => Math.max(a, b));
|
|
286
|
-
|
|
276
|
+
const dirLength = boundsVertices.map(x => x.dot(lightDir)).reduce((a, b) => Math.max(a, b));
|
|
277
|
+
// Shadows
|
|
287
278
|
camera.current.position.copy(cameraPos.copy(lightDir).multiplyScalar(dirLength).add(focusPos));
|
|
288
279
|
camera.current.lookAt(scene.current.localToWorld(focusPos));
|
|
289
280
|
const dirMatrix = lpM.lookAt(camera.current.position, focusPos, v.set(0, 1, 0));
|
|
@@ -296,15 +287,17 @@ const Caustics = /*#__PURE__*/React.forwardRef(({
|
|
|
296
287
|
camera.current.near = 0.1;
|
|
297
288
|
camera.current.far = yTime;
|
|
298
289
|
camera.current.updateProjectionMatrix();
|
|
299
|
-
camera.current.updateMatrixWorld();
|
|
290
|
+
camera.current.updateMatrixWorld();
|
|
300
291
|
|
|
292
|
+
// Now find size of ground plane
|
|
301
293
|
const groundProjectedCoords = worldVerts.map((v, i) => v.add(lightDirs[i].copy(lightDir).multiplyScalar(-v.y / lightDir.y)));
|
|
302
294
|
const centerPos = groundProjectedCoords.reduce((a, b) => a.add(b), v.set(0, 0, 0)).divideScalar(groundProjectedCoords.length);
|
|
303
295
|
const maxSize = 2 * groundProjectedCoords.map(v => Math.hypot(v.x - centerPos.x, v.z - centerPos.z)).reduce((a, b) => Math.max(a, b));
|
|
304
296
|
plane.current.scale.setScalar(maxSize);
|
|
305
297
|
plane.current.position.copy(centerPos);
|
|
306
|
-
if (debug) (_helper$current = helper.current) == null
|
|
298
|
+
if (debug) (_helper$current = helper.current) == null || _helper$current.update();
|
|
307
299
|
|
|
300
|
+
// Inject uniforms
|
|
308
301
|
normalMatB.viewMatrix.value = normalMat.viewMatrix.value = camera.current.matrixWorldInverse;
|
|
309
302
|
const dirLightNearPlane = lpF.setFromProjectionMatrix(lpM.multiplyMatrices(camera.current.projectionMatrix, camera.current.matrixWorldInverse)).planes[4];
|
|
310
303
|
causticsMaterial.cameraMatrixWorld = camera.current.matrixWorld;
|
|
@@ -317,26 +310,29 @@ const Caustics = /*#__PURE__*/React.forwardRef(({
|
|
|
317
310
|
causticsMaterial.resolution = resolution;
|
|
318
311
|
causticsMaterial.size = radius;
|
|
319
312
|
causticsMaterial.intensity = intensity;
|
|
320
|
-
causticsMaterial.worldRadius = worldRadius;
|
|
313
|
+
causticsMaterial.worldRadius = worldRadius;
|
|
321
314
|
|
|
322
|
-
|
|
315
|
+
// Switch the scene on
|
|
316
|
+
scene.current.visible = true;
|
|
323
317
|
|
|
318
|
+
// Render front face normals
|
|
324
319
|
gl.setRenderTarget(normalTarget);
|
|
325
320
|
gl.clear();
|
|
326
321
|
scene.current.overrideMaterial = normalMat;
|
|
327
|
-
gl.render(scene.current, camera.current);
|
|
322
|
+
gl.render(scene.current, camera.current);
|
|
328
323
|
|
|
324
|
+
// Render back face normals, if enabled
|
|
329
325
|
gl.setRenderTarget(normalTargetB);
|
|
330
326
|
gl.clear();
|
|
331
|
-
|
|
332
327
|
if (backside) {
|
|
333
328
|
scene.current.overrideMaterial = normalMatB;
|
|
334
329
|
gl.render(scene.current, camera.current);
|
|
335
|
-
}
|
|
336
|
-
|
|
330
|
+
}
|
|
337
331
|
|
|
338
|
-
|
|
332
|
+
// Remove the override material
|
|
333
|
+
scene.current.overrideMaterial = null;
|
|
339
334
|
|
|
335
|
+
// Render front face caustics
|
|
340
336
|
causticsMaterial.ior = ior;
|
|
341
337
|
plane.current.material.lightProjMatrix = camera.current.projectionMatrix;
|
|
342
338
|
plane.current.material.lightViewMatrix = camera.current.matrixWorldInverse;
|
|
@@ -344,17 +340,20 @@ const Caustics = /*#__PURE__*/React.forwardRef(({
|
|
|
344
340
|
causticsMaterial.depthTexture = normalTarget.depthTexture;
|
|
345
341
|
gl.setRenderTarget(causticsTarget);
|
|
346
342
|
gl.clear();
|
|
347
|
-
causticsQuad.render(gl);
|
|
343
|
+
causticsQuad.render(gl);
|
|
348
344
|
|
|
345
|
+
// Render back face caustics, if enabled
|
|
349
346
|
causticsMaterial.ior = backsideIOR;
|
|
350
347
|
causticsMaterial.normalTexture = normalTargetB.texture;
|
|
351
348
|
causticsMaterial.depthTexture = normalTargetB.depthTexture;
|
|
352
349
|
gl.setRenderTarget(causticsTargetB);
|
|
353
350
|
gl.clear();
|
|
354
|
-
if (backside) causticsQuad.render(gl);
|
|
351
|
+
if (backside) causticsQuad.render(gl);
|
|
355
352
|
|
|
356
|
-
|
|
353
|
+
// Reset render target
|
|
354
|
+
gl.setRenderTarget(null);
|
|
357
355
|
|
|
356
|
+
// Switch the scene off if caustics is all that's wanted
|
|
358
357
|
if (causticsOnly) scene.current.visible = false;
|
|
359
358
|
}
|
|
360
359
|
});
|
package/core/Center.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Group } from 'three';
|
|
2
2
|
import { ForwardRefComponent } from '../helpers/ts-utils';
|
|
3
|
-
export
|
|
3
|
+
export type OnCenterCallbackProps = {
|
|
4
4
|
parent: THREE.Object3D;
|
|
5
5
|
container: THREE.Object3D;
|
|
6
6
|
width: number;
|
|
@@ -13,7 +13,7 @@ export declare type OnCenterCallbackProps = {
|
|
|
13
13
|
horizontalAlignment: number;
|
|
14
14
|
depthAlignment: number;
|
|
15
15
|
};
|
|
16
|
-
export
|
|
16
|
+
export type CenterProps = {
|
|
17
17
|
top?: boolean;
|
|
18
18
|
right?: boolean;
|
|
19
19
|
bottom?: boolean;
|
package/core/Center.js
CHANGED
|
@@ -35,8 +35,9 @@ const Center = /*#__PURE__*/React.forwardRef(function Center({
|
|
|
35
35
|
const vAlign = top ? height / 2 : bottom ? -height / 2 : 0;
|
|
36
36
|
const hAlign = left ? -width / 2 : right ? width / 2 : 0;
|
|
37
37
|
const dAlign = front ? depth / 2 : back ? -depth / 2 : 0;
|
|
38
|
-
outer.current.position.set(disable || disableX ? 0 : -center.x + hAlign, disable || disableY ? 0 : -center.y + vAlign, disable || disableZ ? 0 : -center.z + dAlign);
|
|
38
|
+
outer.current.position.set(disable || disableX ? 0 : -center.x + hAlign, disable || disableY ? 0 : -center.y + vAlign, disable || disableZ ? 0 : -center.z + dAlign);
|
|
39
39
|
|
|
40
|
+
// Only fire onCentered if the bounding box has changed
|
|
40
41
|
if (typeof onCentered !== 'undefined') {
|
|
41
42
|
onCentered({
|
|
42
43
|
parent: ref.current.parent,
|
package/core/Clone.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as THREE from 'three';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { MeshProps } from '@react-three/fiber';
|
|
4
4
|
import { ForwardRefComponent } from '../helpers/ts-utils';
|
|
5
|
-
export
|
|
5
|
+
export type CloneProps = {
|
|
6
6
|
object: THREE.Object3D | THREE.Object3D[];
|
|
7
7
|
children?: React.ReactNode;
|
|
8
8
|
deep?: boolean | 'materialsOnly' | 'geometriesOnly';
|
package/core/Clone.js
CHANGED
|
@@ -12,30 +12,28 @@ function createSpread(child, {
|
|
|
12
12
|
receiveShadow
|
|
13
13
|
}) {
|
|
14
14
|
let spread = pick(child, keys);
|
|
15
|
-
|
|
16
15
|
if (deep) {
|
|
17
16
|
if (spread.geometry && deep !== 'materialsOnly') spread.geometry = spread.geometry.clone();
|
|
18
17
|
if (spread.material && deep !== 'geometriesOnly') spread.material = spread.material.clone();
|
|
19
18
|
}
|
|
20
|
-
|
|
21
19
|
if (inject) {
|
|
22
|
-
if (typeof inject === 'function') spread = {
|
|
20
|
+
if (typeof inject === 'function') spread = {
|
|
21
|
+
...spread,
|
|
23
22
|
children: inject(child)
|
|
24
|
-
};else if ( /*#__PURE__*/React.isValidElement(inject)) spread = {
|
|
23
|
+
};else if ( /*#__PURE__*/React.isValidElement(inject)) spread = {
|
|
24
|
+
...spread,
|
|
25
25
|
children: inject
|
|
26
|
-
};else spread = {
|
|
26
|
+
};else spread = {
|
|
27
|
+
...spread,
|
|
27
28
|
...inject
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
|
-
|
|
31
31
|
if (child instanceof THREE.Mesh) {
|
|
32
32
|
if (castShadow) spread.castShadow = true;
|
|
33
33
|
if (receiveShadow) spread.receiveShadow = true;
|
|
34
34
|
}
|
|
35
|
-
|
|
36
35
|
return spread;
|
|
37
36
|
}
|
|
38
|
-
|
|
39
37
|
const Clone = /*#__PURE__*/React.forwardRef(({
|
|
40
38
|
isChild = false,
|
|
41
39
|
object,
|
|
@@ -48,7 +46,6 @@ const Clone = /*#__PURE__*/React.forwardRef(({
|
|
|
48
46
|
...props
|
|
49
47
|
}, forwardRef) => {
|
|
50
48
|
var _object;
|
|
51
|
-
|
|
52
49
|
const config = {
|
|
53
50
|
keys,
|
|
54
51
|
deep,
|
|
@@ -64,10 +61,10 @@ const Clone = /*#__PURE__*/React.forwardRef(({
|
|
|
64
61
|
});
|
|
65
62
|
if (isSkinned) return SkeletonUtils.clone(object);
|
|
66
63
|
}
|
|
67
|
-
|
|
68
64
|
return object;
|
|
69
|
-
}, [object, isChild]);
|
|
65
|
+
}, [object, isChild]);
|
|
70
66
|
|
|
67
|
+
// Deal with arrayed clones
|
|
71
68
|
if (Array.isArray(object)) {
|
|
72
69
|
return /*#__PURE__*/React.createElement("group", _extends({}, props, {
|
|
73
70
|
ref: forwardRef
|
|
@@ -75,9 +72,9 @@ const Clone = /*#__PURE__*/React.forwardRef(({
|
|
|
75
72
|
key: o.uuid,
|
|
76
73
|
object: o
|
|
77
74
|
}, config))), children);
|
|
78
|
-
}
|
|
79
|
-
|
|
75
|
+
}
|
|
80
76
|
|
|
77
|
+
// Singleton clones
|
|
81
78
|
const {
|
|
82
79
|
children: injectChildren,
|
|
83
80
|
...spread
|
package/core/Cloud.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("@react-three/fiber"),t=require("./Billboard.cjs.js"),a=require("./shapes.cjs.js"),n=require("./useTexture.cjs.js");function s(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("@babel/runtime/helpers/extends"),require("react-merge-refs"),require("three");var c=s(e);exports.Cloud=function({opacity:e=.5,speed:s=.4,width:o=10,depth:i=1.5,segments:u=20,texture:l="https://rawcdn.githack.com/pmndrs/drei-assets/9225a9f1fbd449d9411125c2f419b843d0308c9f/cloud.png",color:d="#ffffff",depthTest:f=!0,...h}){const p=c.useRef(),m=n.useTexture(l),b=c.useMemo((()=>[...new Array(u)].map(((e,r)=>({x:o/2-Math.random()*o,y:o/2-Math.random()*o,scale:.4+Math.sin((r+1)/u*Math.PI)*(10*(.2+Math.random())),density:Math.max(.2,Math.random()),rotation:Math.max(.002,.005*Math.random())*s})))),[o,u,s]);return r.useFrame((e=>{var r;return null==(r=p.current)?void 0:r.children.forEach(((r,t)=>{r.children[0].rotation.z+=b[t].rotation,r.children[0].scale.setScalar(b[t].scale+(1+Math.sin(e.clock.getElapsedTime()/10))/2*t/10)}))})),c.createElement("group",h,c.createElement("group",{position:[0,0,u/2*i],ref:p},b.map((({x:r,y:n,scale:s,density:o},u)=>c.createElement(t.Billboard,{key:u,position:[r,n,-u*i]},c.createElement(a.Plane,{scale:s,rotation:[0,0,0]},c.createElement("meshStandardMaterial",{map:m,transparent:!0,opacity:s/6*o*e,depthTest:f,color:d})))))))};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("@react-three/fiber"),t=require("./Billboard.cjs.js"),a=require("./shapes.cjs.js"),n=require("./useTexture.cjs.js");function s(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("@babel/runtime/helpers/extends"),require("react-merge-refs"),require("three");var c=s(e);exports.Cloud=function({opacity:e=.5,speed:s=.4,width:o=10,depth:i=1.5,segments:u=20,texture:l="https://rawcdn.githack.com/pmndrs/drei-assets/9225a9f1fbd449d9411125c2f419b843d0308c9f/cloud.png",color:d="#ffffff",depthTest:f=!0,...h}){const p=c.useRef(null),m=n.useTexture(l),b=c.useMemo((()=>[...new Array(u)].map(((e,r)=>({x:o/2-Math.random()*o,y:o/2-Math.random()*o,scale:.4+Math.sin((r+1)/u*Math.PI)*(10*(.2+Math.random())),density:Math.max(.2,Math.random()),rotation:Math.max(.002,.005*Math.random())*s})))),[o,u,s]);return r.useFrame((e=>{var r;return null==(r=p.current)?void 0:r.children.forEach(((r,t)=>{r.children[0].rotation.z+=b[t].rotation,r.children[0].scale.setScalar(b[t].scale+(1+Math.sin(e.clock.getElapsedTime()/10))/2*t/10)}))})),c.createElement("group",h,c.createElement("group",{position:[0,0,u/2*i],ref:p},b.map((({x:r,y:n,scale:s,density:o},u)=>c.createElement(t.Billboard,{key:u,position:[r,n,-u*i]},c.createElement(a.Plane,{scale:s,rotation:[0,0,0]},c.createElement("meshStandardMaterial",{map:m,transparent:!0,opacity:s/6*o*e,depthTest:f,color:d})))))))};
|
package/core/Cloud.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
2
|
export declare function Cloud({ opacity, speed, width, depth, segments, texture, color, depthTest, ...props }: {
|
|
3
3
|
[x: string]: any;
|
|
4
4
|
opacity?: number | undefined;
|
|
@@ -9,4 +9,4 @@ export declare function Cloud({ opacity, speed, width, depth, segments, texture,
|
|
|
9
9
|
texture?: string | undefined;
|
|
10
10
|
color?: string | undefined;
|
|
11
11
|
depthTest?: boolean | undefined;
|
|
12
|
-
}): JSX.Element;
|
|
12
|
+
}): React.JSX.Element;
|
package/core/Cloud.js
CHANGED
|
@@ -16,7 +16,7 @@ function Cloud({
|
|
|
16
16
|
depthTest = true,
|
|
17
17
|
...props
|
|
18
18
|
}) {
|
|
19
|
-
const group = React.useRef();
|
|
19
|
+
const group = React.useRef(null);
|
|
20
20
|
const cloudTexture = useTexture(texture);
|
|
21
21
|
const clouds = React.useMemo(() => [...new Array(segments)].map((_, index) => ({
|
|
22
22
|
x: width / 2 - Math.random() * width,
|
|
@@ -27,7 +27,6 @@ function Cloud({
|
|
|
27
27
|
})), [width, segments, speed]);
|
|
28
28
|
useFrame(state => {
|
|
29
29
|
var _group$current;
|
|
30
|
-
|
|
31
30
|
return (_group$current = group.current) == null ? void 0 : _group$current.children.forEach((cloud, index) => {
|
|
32
31
|
cloud.children[0].rotation.z += clouds[index].rotation;
|
|
33
32
|
cloud.children[0].scale.setScalar(clouds[index].scale + (1 + Math.sin(state.clock.getElapsedTime() / 10)) / 2 * index / 10);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BufferAttributeProps } from '@react-three/fiber';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { BufferAttribute, BufferGeometry } from 'three';
|
|
4
|
-
|
|
4
|
+
type Props = {
|
|
5
5
|
compute: (geometry: BufferGeometry) => BufferAttribute;
|
|
6
6
|
name: string;
|
|
7
7
|
};
|
|
8
|
-
export declare const ComputedAttribute: ({ compute, name, ...props }: React.PropsWithChildren<Props & BufferAttributeProps>) => JSX.Element;
|
|
8
|
+
export declare const ComputedAttribute: ({ compute, name, ...props }: React.PropsWithChildren<Props & BufferAttributeProps>) => React.JSX.Element;
|
|
9
9
|
export {};
|
|
@@ -17,7 +17,6 @@ const ComputedAttribute = ({
|
|
|
17
17
|
React.useLayoutEffect(() => {
|
|
18
18
|
if (primitive.current) {
|
|
19
19
|
var _ref;
|
|
20
|
-
|
|
21
20
|
// @ts-expect-error brittle
|
|
22
21
|
const parent = (_ref = primitive.current.parent) !== null && _ref !== void 0 ? _ref : primitive.current.__r3f.parent;
|
|
23
22
|
const attr = compute(parent);
|
package/core/ContactShadows.d.ts
CHANGED