@react-three/drei 9.74.11 → 9.74.13
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/core/CatmullRomLine.js +2 -0
- package/core/Cloud.js +3 -0
- package/core/CubeCamera.js +1 -0
- package/core/CubicBezierLine.js +2 -0
- package/core/Environment.js +1 -0
- package/core/Example.js +6 -0
- package/core/FaceControls.cjs.js +1 -1
- package/core/FaceControls.js +2 -0
- package/core/FaceLandmarker.cjs.js +1 -1
- package/core/FaceLandmarker.js +3 -2
- package/core/Facemesh.js +2 -0
- package/core/GizmoHelper.js +3 -0
- package/core/GizmoViewcube.js +4 -0
- package/core/GizmoViewport.js +4 -0
- package/core/Gltf.js +4 -0
- package/core/MeshDiscardMaterial.js +2 -0
- package/core/MeshDistortMaterial.js +2 -1
- package/core/MeshReflectorMaterial.js +1 -0
- package/core/MeshRefractionMaterial.js +2 -0
- package/core/MeshTransmissionMaterial.js +1 -0
- package/core/OrthographicCamera.js +1 -0
- package/core/PerspectiveCamera.js +1 -0
- package/core/QuadraticBezierLine.js +2 -0
- package/core/Reflector.js +1 -0
- package/core/SpotLight.js +2 -1
- package/core/Stage.js +7 -0
- package/core/Text3D.js +1 -0
- package/core/Wireframe.js +1 -0
- package/core/index.cjs.js +1 -1
- package/core/index.js +0 -1
- package/core/useKTX2.js +1 -0
- package/core/useMatcapTexture.js +2 -0
- package/core/useNormalTexture.js +1 -0
- package/index.cjs.js +1 -1
- package/materials/DiscardMaterial.js +1 -0
- package/materials/MeshRefractionMaterial.js +1 -1
- package/native/index.cjs.js +1 -1
- package/native/index.js +0 -1
- package/package.json +9 -9
- package/src/core/AccumulativeShadows.js +311 -0
- package/src/core/AdaptiveDpr.js +28 -0
- package/src/core/AdaptiveEvents.js +20 -0
- package/src/core/ArcballControls.js +67 -0
- package/src/core/AsciiRenderer.js +60 -0
- package/src/core/BBAnchor.js +37 -0
- package/src/core/Backdrop.js +36 -0
- package/src/core/BakeShadows.js +16 -0
- package/src/core/Billboard.js +41 -0
- package/src/core/Bounds.js +245 -0
- package/src/core/CameraControls.js +92 -0
- package/src/core/CameraShake.js +61 -0
- package/src/core/CatmullRomLine.js +44 -0
- package/src/core/Caustics.js +375 -0
- package/src/core/Center.js +66 -0
- package/src/core/Clone.js +102 -0
- package/src/core/Cloud.js +59 -0
- package/src/core/ComputedAttribute.js +34 -0
- package/src/core/ContactShadows.js +114 -0
- package/src/core/CubeCamera.js +43 -0
- package/src/core/CubicBezierLine.js +28 -0
- package/src/core/CurveModifier.js +34 -0
- package/src/core/Decal.js +92 -0
- package/src/core/Detailed.js +34 -0
- package/src/core/DeviceOrientationControls.js +51 -0
- package/src/core/Edges.js +36 -0
- package/src/core/Effects.js +93 -0
- package/src/core/Environment.js +132 -0
- package/src/core/Example.js +42 -0
- package/src/core/FaceControls.js +315 -0
- package/src/core/FaceLandmarker.js +43 -0
- package/src/core/Facemesh.js +4545 -0
- package/src/core/FirstPersonControls.js +38 -0
- package/src/core/Float.js +36 -0
- package/src/core/FlyControls.js +55 -0
- package/src/core/GizmoHelper.js +111 -0
- package/src/core/GizmoViewcube.js +152 -0
- package/src/core/GizmoViewport.js +152 -0
- package/src/core/Gltf.js +20 -0
- package/src/core/GradientTexture.js +33 -0
- package/src/core/Grid.js +112 -0
- package/src/core/Hud.js +58 -0
- package/src/core/Image.js +119 -0
- package/src/core/Instances.js +215 -0
- package/src/core/Lightformer.js +51 -0
- package/src/core/Line.js +68 -0
- package/src/core/MapControls.js +64 -0
- package/src/core/MarchingCubes.js +76 -0
- package/src/core/Mask.js +42 -0
- package/src/core/MeshDiscardMaterial.js +15 -0
- package/src/core/MeshDistortMaterial.js +79 -0
- package/src/core/MeshPortalMaterial.js +381 -0
- package/src/core/MeshReflectorMaterial.js +182 -0
- package/src/core/MeshRefractionMaterial.js +79 -0
- package/src/core/MeshTransmissionMaterial.js +395 -0
- package/src/core/MeshWobbleMaterial.js +65 -0
- package/src/core/OrbitControls.js +82 -0
- package/src/core/OrthographicCamera.js +77 -0
- package/src/core/PerformanceMonitor.js +121 -0
- package/src/core/PerspectiveCamera.js +73 -0
- package/src/core/PointMaterial.js +36 -0
- package/src/core/PointerLockControls.js +90 -0
- package/src/core/Points.js +227 -0
- package/src/core/PositionalAudio.js +51 -0
- package/src/core/Preload.js +45 -0
- package/src/core/QuadraticBezierLine.js +44 -0
- package/src/core/Reflector.js +182 -0
- package/src/core/RenderTexture.js +96 -0
- package/src/core/Resize.js +39 -0
- package/src/core/RoundedBox.js +52 -0
- package/src/core/Sampler.js +85 -0
- package/src/core/ScreenQuad.js +24 -0
- package/src/core/ScreenSpace.js +25 -0
- package/src/core/Segments.js +102 -0
- package/src/core/Shadow.js +42 -0
- package/src/core/Sky.js +39 -0
- package/src/core/Sparkles.js +139 -0
- package/src/core/SpotLight.js +231 -0
- package/src/core/SpriteAnimator.js +342 -0
- package/src/core/Stage.js +135 -0
- package/src/core/Stars.js +108 -0
- package/src/core/Stats.js +30 -0
- package/src/core/Svg.js +59 -0
- package/src/core/Text.js +58 -0
- package/src/core/Text3D.js +76 -0
- package/src/core/TrackballControls.js +72 -0
- package/src/core/Trail.js +161 -0
- package/src/core/TransformControls.js +106 -0
- package/src/core/Wireframe.js +185 -0
- package/src/core/meshBounds.js +38 -0
- package/src/core/shaderMaterial.js +39 -0
- package/src/core/shapes.js +68 -0
- package/src/core/softShadows.js +161 -0
- package/src/core/useAnimations.js +56 -0
- package/src/core/useAspect.js +10 -0
- package/src/core/useBVH.js +90 -0
- package/src/core/useBoxProjectedEnv.js +98 -0
- package/src/core/useCamera.js +27 -0
- package/src/core/useContextBridge.js +21 -0
- package/src/core/useCubeCamera.js +49 -0
- package/src/core/useCubeTexture.js +18 -0
- package/src/core/useDepthBuffer.js +38 -0
- package/src/core/useDetectGPU.js +6 -0
- package/src/core/useEnvironment.js +48 -0
- package/src/core/useFBO.js +53 -0
- package/src/core/useFBX.js +12 -0
- package/src/core/useFont.js +20 -0
- package/src/core/useGLTF.js +37 -0
- package/src/core/useHelper.js +31 -0
- package/src/core/useIntersect.js +39 -0
- package/src/core/useKTX2.js +38 -0
- package/src/core/useMatcapTexture.js +45 -0
- package/src/core/useNormalTexture.js +30 -0
- package/src/core/useProgress.js +50 -0
- package/src/core/useTexture.js +35 -0
- package/src/core/useTrailTexture.js +164 -0
- package/src/core/useVideoTexture.js +41 -0
- package/src/helpers/environment-assets.js +14 -0
- package/src/helpers/useEffectfulState.js +18 -0
- package/src/materials/BlurPass.js +75 -0
- package/src/materials/ConvolutionMaterial.js +99 -0
- package/src/materials/DiscardMaterial.js +5 -0
- package/src/materials/MeshReflectorMaterial.js +290 -0
- package/src/materials/MeshRefractionMaterial.js +171 -0
- package/src/materials/SpotLightMaterial.js +111 -0
- package/src/materials/WireframeMaterial.js +235 -0
- package/src/web/CycleRaycast.js +97 -0
- package/src/web/Html.js +417 -0
- package/src/web/KeyboardControls.js +101 -0
- package/src/web/Loader.js +98 -0
- package/src/web/PresentationControls.js +86 -0
- package/src/web/ScrollControls.js +246 -0
- package/src/web/Select.js +175 -0
- package/src/web/View.js +206 -0
- package/src/web/pivotControls/AxisArrow.js +202 -0
- package/src/web/pivotControls/AxisRotator.js +235 -0
- package/src/web/pivotControls/PlaneSlider.js +211 -0
- package/src/web/pivotControls/context.js +5 -0
- package/src/web/pivotControls/index.js +223 -0
- package/src/web/useCursor.js +12 -0
- package/web/Loader.js +2 -0
- package/web/index.cjs.js +1 -1
- package/web/index.js +0 -1
- package/web/pivotControls/AxisArrow.js +3 -0
- package/web/pivotControls/AxisRotator.js +3 -0
- package/web/pivotControls/PlaneSlider.js +3 -0
- package/web/pivotControls/index.js +5 -0
- /package/{helpers → src/helpers}/glsl/DefaultSpotlightShadowShadows.glsl.js +0 -0
- /package/{helpers → src/helpers}/glsl/distort.vert.glsl.js +0 -0
- /package/{index.js → src/index.js} +0 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { extend, useFrame } from '@react-three/fiber';
|
|
5
|
+
import mergeRefs from 'react-merge-refs';
|
|
6
|
+
|
|
7
|
+
const _inverseMatrix = /*@__PURE__*/new THREE.Matrix4();
|
|
8
|
+
|
|
9
|
+
const _ray = /*@__PURE__*/new THREE.Ray();
|
|
10
|
+
|
|
11
|
+
const _sphere = /*@__PURE__*/new THREE.Sphere();
|
|
12
|
+
|
|
13
|
+
const _position = /*@__PURE__*/new THREE.Vector3();
|
|
14
|
+
|
|
15
|
+
class PositionPoint extends THREE.Group {
|
|
16
|
+
constructor() {
|
|
17
|
+
super();
|
|
18
|
+
this.size = 0;
|
|
19
|
+
this.color = new THREE.Color('white');
|
|
20
|
+
this.instance = {
|
|
21
|
+
current: undefined
|
|
22
|
+
};
|
|
23
|
+
this.instanceKey = {
|
|
24
|
+
current: undefined
|
|
25
|
+
};
|
|
26
|
+
} // This will allow the virtual instance have bounds
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
get geometry() {
|
|
30
|
+
var _this$instance$curren;
|
|
31
|
+
|
|
32
|
+
return (_this$instance$curren = this.instance.current) == null ? void 0 : _this$instance$curren.geometry;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
raycast(raycaster, intersects) {
|
|
36
|
+
var _raycaster$params$Poi, _raycaster$params$Poi2;
|
|
37
|
+
|
|
38
|
+
const parent = this.instance.current;
|
|
39
|
+
if (!parent || !parent.geometry) return;
|
|
40
|
+
const instanceId = parent.userData.instances.indexOf(this.instanceKey); // If the instance wasn't found or exceeds the parents draw range, bail out
|
|
41
|
+
|
|
42
|
+
if (instanceId === -1 || instanceId > parent.geometry.drawRange.count) return;
|
|
43
|
+
const threshold = (_raycaster$params$Poi = (_raycaster$params$Poi2 = raycaster.params.Points) == null ? void 0 : _raycaster$params$Poi2.threshold) !== null && _raycaster$params$Poi !== void 0 ? _raycaster$params$Poi : 1;
|
|
44
|
+
|
|
45
|
+
_sphere.set(this.getWorldPosition(_position), threshold);
|
|
46
|
+
|
|
47
|
+
if (raycaster.ray.intersectsSphere(_sphere) === false) return;
|
|
48
|
+
|
|
49
|
+
_inverseMatrix.copy(parent.matrixWorld).invert();
|
|
50
|
+
|
|
51
|
+
_ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix);
|
|
52
|
+
|
|
53
|
+
const localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3);
|
|
54
|
+
const localThresholdSq = localThreshold * localThreshold;
|
|
55
|
+
|
|
56
|
+
const rayPointDistanceSq = _ray.distanceSqToPoint(this.position);
|
|
57
|
+
|
|
58
|
+
if (rayPointDistanceSq < localThresholdSq) {
|
|
59
|
+
const intersectPoint = new THREE.Vector3();
|
|
60
|
+
|
|
61
|
+
_ray.closestPointToPoint(this.position, intersectPoint);
|
|
62
|
+
|
|
63
|
+
intersectPoint.applyMatrix4(this.matrixWorld);
|
|
64
|
+
const distance = raycaster.ray.origin.distanceTo(intersectPoint);
|
|
65
|
+
if (distance < raycaster.near || distance > raycaster.far) return;
|
|
66
|
+
intersects.push({
|
|
67
|
+
distance: distance,
|
|
68
|
+
distanceToRay: Math.sqrt(rayPointDistanceSq),
|
|
69
|
+
point: intersectPoint,
|
|
70
|
+
index: instanceId,
|
|
71
|
+
face: null,
|
|
72
|
+
object: this
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
let i, positionRef;
|
|
79
|
+
const context = /*@__PURE__*/React.createContext(null);
|
|
80
|
+
const parentMatrix = /*@__PURE__*/new THREE.Matrix4();
|
|
81
|
+
const position = /*@__PURE__*/new THREE.Vector3();
|
|
82
|
+
/**
|
|
83
|
+
* Instance implementation, relies on react + context to update the attributes based on the children of this component
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
const PointsInstances = /*#__PURE__*/React.forwardRef(({
|
|
87
|
+
children,
|
|
88
|
+
range,
|
|
89
|
+
limit = 1000,
|
|
90
|
+
...props
|
|
91
|
+
}, ref) => {
|
|
92
|
+
const parentRef = React.useRef(null);
|
|
93
|
+
const [refs, setRefs] = React.useState([]);
|
|
94
|
+
const [[positions, colors, sizes]] = React.useState(() => [new Float32Array(limit * 3), Float32Array.from({
|
|
95
|
+
length: limit * 3
|
|
96
|
+
}, () => 1), Float32Array.from({
|
|
97
|
+
length: limit
|
|
98
|
+
}, () => 1)]);
|
|
99
|
+
React.useEffect(() => {
|
|
100
|
+
// We might be a frame too late? 🤷♂️
|
|
101
|
+
parentRef.current.geometry.attributes.position.needsUpdate = true;
|
|
102
|
+
});
|
|
103
|
+
useFrame(() => {
|
|
104
|
+
parentRef.current.updateMatrix();
|
|
105
|
+
parentRef.current.updateMatrixWorld();
|
|
106
|
+
parentMatrix.copy(parentRef.current.matrixWorld).invert();
|
|
107
|
+
parentRef.current.geometry.drawRange.count = Math.min(limit, range !== undefined ? range : limit, refs.length);
|
|
108
|
+
|
|
109
|
+
for (i = 0; i < refs.length; i++) {
|
|
110
|
+
positionRef = refs[i].current;
|
|
111
|
+
positionRef.getWorldPosition(position).applyMatrix4(parentMatrix);
|
|
112
|
+
position.toArray(positions, i * 3);
|
|
113
|
+
parentRef.current.geometry.attributes.position.needsUpdate = true;
|
|
114
|
+
positionRef.matrixWorldNeedsUpdate = true;
|
|
115
|
+
positionRef.color.toArray(colors, i * 3);
|
|
116
|
+
parentRef.current.geometry.attributes.color.needsUpdate = true;
|
|
117
|
+
sizes.set([positionRef.size], i);
|
|
118
|
+
parentRef.current.geometry.attributes.size.needsUpdate = true;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
const api = React.useMemo(() => ({
|
|
122
|
+
getParent: () => parentRef,
|
|
123
|
+
subscribe: ref => {
|
|
124
|
+
setRefs(refs => [...refs, ref]);
|
|
125
|
+
return () => setRefs(refs => refs.filter(item => item.current !== ref.current));
|
|
126
|
+
}
|
|
127
|
+
}), []);
|
|
128
|
+
return /*#__PURE__*/React.createElement("points", _extends({
|
|
129
|
+
userData: {
|
|
130
|
+
instances: refs
|
|
131
|
+
},
|
|
132
|
+
matrixAutoUpdate: false,
|
|
133
|
+
ref: mergeRefs([ref, parentRef]),
|
|
134
|
+
raycast: () => null
|
|
135
|
+
}, props), /*#__PURE__*/React.createElement("bufferGeometry", null, /*#__PURE__*/React.createElement("bufferAttribute", {
|
|
136
|
+
attach: "attributes-position",
|
|
137
|
+
count: positions.length / 3,
|
|
138
|
+
array: positions,
|
|
139
|
+
itemSize: 3,
|
|
140
|
+
usage: THREE.DynamicDrawUsage
|
|
141
|
+
}), /*#__PURE__*/React.createElement("bufferAttribute", {
|
|
142
|
+
attach: "attributes-color",
|
|
143
|
+
count: colors.length / 3,
|
|
144
|
+
array: colors,
|
|
145
|
+
itemSize: 3,
|
|
146
|
+
usage: THREE.DynamicDrawUsage
|
|
147
|
+
}), /*#__PURE__*/React.createElement("bufferAttribute", {
|
|
148
|
+
attach: "attributes-size",
|
|
149
|
+
count: sizes.length,
|
|
150
|
+
array: sizes,
|
|
151
|
+
itemSize: 1,
|
|
152
|
+
usage: THREE.DynamicDrawUsage
|
|
153
|
+
})), /*#__PURE__*/React.createElement(context.Provider, {
|
|
154
|
+
value: api
|
|
155
|
+
}, children));
|
|
156
|
+
});
|
|
157
|
+
const Point = /*#__PURE__*/React.forwardRef(({
|
|
158
|
+
children,
|
|
159
|
+
...props
|
|
160
|
+
}, ref) => {
|
|
161
|
+
React.useMemo(() => extend({
|
|
162
|
+
PositionPoint
|
|
163
|
+
}), []);
|
|
164
|
+
const group = React.useRef();
|
|
165
|
+
const {
|
|
166
|
+
subscribe,
|
|
167
|
+
getParent
|
|
168
|
+
} = React.useContext(context);
|
|
169
|
+
React.useLayoutEffect(() => subscribe(group), []);
|
|
170
|
+
return /*#__PURE__*/React.createElement("positionPoint", _extends({
|
|
171
|
+
instance: getParent(),
|
|
172
|
+
instanceKey: group,
|
|
173
|
+
ref: mergeRefs([ref, group])
|
|
174
|
+
}, props), children);
|
|
175
|
+
});
|
|
176
|
+
/**
|
|
177
|
+
* Buffer implementation, relies on complete buffers of the correct number, leaves it to the user to update them
|
|
178
|
+
*/
|
|
179
|
+
|
|
180
|
+
const PointsBuffer = /*#__PURE__*/React.forwardRef(({
|
|
181
|
+
children,
|
|
182
|
+
positions,
|
|
183
|
+
colors,
|
|
184
|
+
sizes,
|
|
185
|
+
stride = 3,
|
|
186
|
+
...props
|
|
187
|
+
}, forwardedRef) => {
|
|
188
|
+
const pointsRef = React.useRef(null);
|
|
189
|
+
useFrame(() => {
|
|
190
|
+
const attr = pointsRef.current.geometry.attributes;
|
|
191
|
+
attr.position.needsUpdate = true;
|
|
192
|
+
if (colors) attr.color.needsUpdate = true;
|
|
193
|
+
if (sizes) attr.size.needsUpdate = true;
|
|
194
|
+
});
|
|
195
|
+
return /*#__PURE__*/React.createElement("points", _extends({
|
|
196
|
+
ref: mergeRefs([forwardedRef, pointsRef])
|
|
197
|
+
}, props), /*#__PURE__*/React.createElement("bufferGeometry", null, /*#__PURE__*/React.createElement("bufferAttribute", {
|
|
198
|
+
attach: "attributes-position",
|
|
199
|
+
count: positions.length / stride,
|
|
200
|
+
array: positions,
|
|
201
|
+
itemSize: stride,
|
|
202
|
+
usage: THREE.DynamicDrawUsage
|
|
203
|
+
}), colors && /*#__PURE__*/React.createElement("bufferAttribute", {
|
|
204
|
+
attach: "attributes-color",
|
|
205
|
+
count: colors.length / stride,
|
|
206
|
+
array: colors,
|
|
207
|
+
itemSize: 3,
|
|
208
|
+
usage: THREE.DynamicDrawUsage
|
|
209
|
+
}), sizes && /*#__PURE__*/React.createElement("bufferAttribute", {
|
|
210
|
+
attach: "attributes-size",
|
|
211
|
+
count: sizes.length / stride,
|
|
212
|
+
array: sizes,
|
|
213
|
+
itemSize: 1,
|
|
214
|
+
usage: THREE.DynamicDrawUsage
|
|
215
|
+
})), children);
|
|
216
|
+
});
|
|
217
|
+
const Points = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
|
218
|
+
if (props.positions instanceof Float32Array) {
|
|
219
|
+
return /*#__PURE__*/React.createElement(PointsBuffer, _extends({}, props, {
|
|
220
|
+
ref: forwardedRef
|
|
221
|
+
}));
|
|
222
|
+
} else return /*#__PURE__*/React.createElement(PointsInstances, _extends({}, props, {
|
|
223
|
+
ref: forwardedRef
|
|
224
|
+
}));
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
export { Point, Points, PointsBuffer, PositionPoint };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { AudioListener, AudioLoader } from 'three';
|
|
4
|
+
import { useThree, useLoader } from '@react-three/fiber';
|
|
5
|
+
import mergeRefs from 'react-merge-refs';
|
|
6
|
+
|
|
7
|
+
const PositionalAudio = /*#__PURE__*/React.forwardRef(({
|
|
8
|
+
url,
|
|
9
|
+
distance = 1,
|
|
10
|
+
loop = true,
|
|
11
|
+
autoplay,
|
|
12
|
+
...props
|
|
13
|
+
}, ref) => {
|
|
14
|
+
const sound = React.useRef();
|
|
15
|
+
const camera = useThree(({
|
|
16
|
+
camera
|
|
17
|
+
}) => camera);
|
|
18
|
+
const [listener] = React.useState(() => new AudioListener());
|
|
19
|
+
const buffer = useLoader(AudioLoader, url);
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
const _sound = sound.current;
|
|
22
|
+
|
|
23
|
+
if (_sound) {
|
|
24
|
+
_sound.setBuffer(buffer);
|
|
25
|
+
|
|
26
|
+
_sound.setRefDistance(distance);
|
|
27
|
+
|
|
28
|
+
_sound.setLoop(loop);
|
|
29
|
+
|
|
30
|
+
if (autoplay && !_sound.isPlaying) _sound.play();
|
|
31
|
+
}
|
|
32
|
+
}, [buffer, camera, distance, loop]);
|
|
33
|
+
React.useEffect(() => {
|
|
34
|
+
const _sound = sound.current;
|
|
35
|
+
camera.add(listener);
|
|
36
|
+
return () => {
|
|
37
|
+
camera.remove(listener);
|
|
38
|
+
|
|
39
|
+
if (_sound) {
|
|
40
|
+
if (_sound.isPlaying) _sound.stop();
|
|
41
|
+
if (_sound.source && _sound.source._connected) _sound.disconnect();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}, []);
|
|
45
|
+
return /*#__PURE__*/React.createElement("positionalAudio", _extends({
|
|
46
|
+
ref: mergeRefs([sound, ref]),
|
|
47
|
+
args: [listener]
|
|
48
|
+
}, props));
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export { PositionalAudio };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { WebGLCubeRenderTarget, CubeCamera } from 'three';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useThree } from '@react-three/fiber';
|
|
4
|
+
|
|
5
|
+
function Preload({
|
|
6
|
+
all,
|
|
7
|
+
scene,
|
|
8
|
+
camera
|
|
9
|
+
}) {
|
|
10
|
+
const gl = useThree(({
|
|
11
|
+
gl
|
|
12
|
+
}) => gl);
|
|
13
|
+
const dCamera = useThree(({
|
|
14
|
+
camera
|
|
15
|
+
}) => camera);
|
|
16
|
+
const dScene = useThree(({
|
|
17
|
+
scene
|
|
18
|
+
}) => scene); // Layout effect because it must run before React commits
|
|
19
|
+
|
|
20
|
+
React.useLayoutEffect(() => {
|
|
21
|
+
const invisible = [];
|
|
22
|
+
|
|
23
|
+
if (all) {
|
|
24
|
+
(scene || dScene).traverse(object => {
|
|
25
|
+
if (object.visible === false) {
|
|
26
|
+
invisible.push(object);
|
|
27
|
+
object.visible = true;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
} // Now compile the scene
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
gl.compile(scene || dScene, camera || dCamera); // And for good measure, hit it with a cube camera
|
|
34
|
+
|
|
35
|
+
const cubeRenderTarget = new WebGLCubeRenderTarget(128);
|
|
36
|
+
const cubeCamera = new CubeCamera(0.01, 100000, cubeRenderTarget);
|
|
37
|
+
cubeCamera.update(gl, scene || dScene);
|
|
38
|
+
cubeRenderTarget.dispose(); // Flips these objects back
|
|
39
|
+
|
|
40
|
+
invisible.forEach(object => object.visible = false);
|
|
41
|
+
}, []);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { Preload };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Vector3, QuadraticBezierCurve3 } from 'three';
|
|
4
|
+
import mergeRefs from 'react-merge-refs';
|
|
5
|
+
import { Line } from './Line.js';
|
|
6
|
+
|
|
7
|
+
const v = new Vector3();
|
|
8
|
+
const QuadraticBezierLine = /*#__PURE__*/React.forwardRef(function QuadraticBezierLine({
|
|
9
|
+
start = [0, 0, 0],
|
|
10
|
+
end = [0, 0, 0],
|
|
11
|
+
mid,
|
|
12
|
+
segments = 20,
|
|
13
|
+
...rest
|
|
14
|
+
}, forwardref) {
|
|
15
|
+
const ref = React.useRef(null);
|
|
16
|
+
const [curve] = React.useState(() => new QuadraticBezierCurve3(undefined, undefined, undefined));
|
|
17
|
+
const getPoints = React.useCallback((start, end, mid, segments = 20) => {
|
|
18
|
+
if (start instanceof Vector3) curve.v0.copy(start);else curve.v0.set(...start);
|
|
19
|
+
if (end instanceof Vector3) curve.v2.copy(end);else curve.v2.set(...end);
|
|
20
|
+
|
|
21
|
+
if (mid instanceof Vector3) {
|
|
22
|
+
curve.v1.copy(mid);
|
|
23
|
+
} else if (Array.isArray(mid)) {
|
|
24
|
+
curve.v1.set(...mid);
|
|
25
|
+
} else {
|
|
26
|
+
curve.v1.copy(curve.v0.clone().add(curve.v2.clone().sub(curve.v0)).add(v.set(0, curve.v0.y - curve.v2.y, 0)));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return curve.getPoints(segments);
|
|
30
|
+
}, []);
|
|
31
|
+
React.useLayoutEffect(() => {
|
|
32
|
+
ref.current.setPoints = (start, end, mid) => {
|
|
33
|
+
const points = getPoints(start, end, mid);
|
|
34
|
+
if (ref.current.geometry) ref.current.geometry.setPositions(points.map(p => p.toArray()).flat());
|
|
35
|
+
};
|
|
36
|
+
}, []);
|
|
37
|
+
const points = React.useMemo(() => getPoints(start, end, mid, segments), [start, end, mid, segments]);
|
|
38
|
+
return /*#__PURE__*/React.createElement(Line, _extends({
|
|
39
|
+
ref: mergeRefs([ref, forwardref]),
|
|
40
|
+
points: points
|
|
41
|
+
}, rest));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export { QuadraticBezierLine };
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Plane, Vector3, Matrix4, Vector4, PerspectiveCamera, WebGLRenderTarget, DepthTexture, DepthFormat, UnsignedShortType, HalfFloatType, LinearFilter } from 'three';
|
|
4
|
+
import { extend, useThree, useFrame } from '@react-three/fiber';
|
|
5
|
+
import mergeRefs from 'react-merge-refs';
|
|
6
|
+
import { BlurPass } from '../materials/BlurPass.js';
|
|
7
|
+
import { MeshReflectorMaterial } from '../materials/MeshReflectorMaterial.js';
|
|
8
|
+
|
|
9
|
+
extend({
|
|
10
|
+
MeshReflectorMaterial
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use MeshReflectorMaterial instead
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const Reflector = /*#__PURE__*/React.forwardRef(({
|
|
17
|
+
mixBlur = 0,
|
|
18
|
+
mixStrength = 0.5,
|
|
19
|
+
resolution = 256,
|
|
20
|
+
blur = [0, 0],
|
|
21
|
+
args = [1, 1],
|
|
22
|
+
minDepthThreshold = 0.9,
|
|
23
|
+
maxDepthThreshold = 1,
|
|
24
|
+
depthScale = 0,
|
|
25
|
+
depthToBlurRatioBias = 0.25,
|
|
26
|
+
mirror = 0,
|
|
27
|
+
children,
|
|
28
|
+
debug = 0,
|
|
29
|
+
distortion = 1,
|
|
30
|
+
mixContrast = 1,
|
|
31
|
+
distortionMap,
|
|
32
|
+
...props
|
|
33
|
+
}, ref) => {
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
console.warn('Reflector has been deprecated and will be removed next major. Replace it with <MeshReflectorMaterial />!');
|
|
36
|
+
}, []);
|
|
37
|
+
const gl = useThree(({
|
|
38
|
+
gl
|
|
39
|
+
}) => gl);
|
|
40
|
+
const camera = useThree(({
|
|
41
|
+
camera
|
|
42
|
+
}) => camera);
|
|
43
|
+
const scene = useThree(({
|
|
44
|
+
scene
|
|
45
|
+
}) => scene);
|
|
46
|
+
blur = Array.isArray(blur) ? blur : [blur, blur];
|
|
47
|
+
const hasBlur = blur[0] + blur[1] > 0;
|
|
48
|
+
const meshRef = React.useRef(null);
|
|
49
|
+
const [reflectorPlane] = React.useState(() => new Plane());
|
|
50
|
+
const [normal] = React.useState(() => new Vector3());
|
|
51
|
+
const [reflectorWorldPosition] = React.useState(() => new Vector3());
|
|
52
|
+
const [cameraWorldPosition] = React.useState(() => new Vector3());
|
|
53
|
+
const [rotationMatrix] = React.useState(() => new Matrix4());
|
|
54
|
+
const [lookAtPosition] = React.useState(() => new Vector3(0, 0, -1));
|
|
55
|
+
const [clipPlane] = React.useState(() => new Vector4());
|
|
56
|
+
const [view] = React.useState(() => new Vector3());
|
|
57
|
+
const [target] = React.useState(() => new Vector3());
|
|
58
|
+
const [q] = React.useState(() => new Vector4());
|
|
59
|
+
const [textureMatrix] = React.useState(() => new Matrix4());
|
|
60
|
+
const [virtualCamera] = React.useState(() => new PerspectiveCamera());
|
|
61
|
+
const beforeRender = React.useCallback(() => {
|
|
62
|
+
reflectorWorldPosition.setFromMatrixPosition(meshRef.current.matrixWorld);
|
|
63
|
+
cameraWorldPosition.setFromMatrixPosition(camera.matrixWorld);
|
|
64
|
+
rotationMatrix.extractRotation(meshRef.current.matrixWorld);
|
|
65
|
+
normal.set(0, 0, 1);
|
|
66
|
+
normal.applyMatrix4(rotationMatrix);
|
|
67
|
+
view.subVectors(reflectorWorldPosition, cameraWorldPosition); // Avoid rendering when reflector is facing away
|
|
68
|
+
|
|
69
|
+
if (view.dot(normal) > 0) return;
|
|
70
|
+
view.reflect(normal).negate();
|
|
71
|
+
view.add(reflectorWorldPosition);
|
|
72
|
+
rotationMatrix.extractRotation(camera.matrixWorld);
|
|
73
|
+
lookAtPosition.set(0, 0, -1);
|
|
74
|
+
lookAtPosition.applyMatrix4(rotationMatrix);
|
|
75
|
+
lookAtPosition.add(cameraWorldPosition);
|
|
76
|
+
target.subVectors(reflectorWorldPosition, lookAtPosition);
|
|
77
|
+
target.reflect(normal).negate();
|
|
78
|
+
target.add(reflectorWorldPosition);
|
|
79
|
+
virtualCamera.position.copy(view);
|
|
80
|
+
virtualCamera.up.set(0, 1, 0);
|
|
81
|
+
virtualCamera.up.applyMatrix4(rotationMatrix);
|
|
82
|
+
virtualCamera.up.reflect(normal);
|
|
83
|
+
virtualCamera.lookAt(target);
|
|
84
|
+
virtualCamera.far = camera.far; // Used in WebGLBackground
|
|
85
|
+
|
|
86
|
+
virtualCamera.updateMatrixWorld();
|
|
87
|
+
virtualCamera.projectionMatrix.copy(camera.projectionMatrix); // Update the texture matrix
|
|
88
|
+
|
|
89
|
+
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);
|
|
90
|
+
textureMatrix.multiply(virtualCamera.projectionMatrix);
|
|
91
|
+
textureMatrix.multiply(virtualCamera.matrixWorldInverse);
|
|
92
|
+
textureMatrix.multiply(meshRef.current.matrixWorld); // Now update projection matrix with new clip plane, implementing code from: http://www.terathon.com/code/oblique.html
|
|
93
|
+
// Paper explaining this technique: http://www.terathon.com/lengyel/Lengyel-Oblique.pdf
|
|
94
|
+
|
|
95
|
+
reflectorPlane.setFromNormalAndCoplanarPoint(normal, reflectorWorldPosition);
|
|
96
|
+
reflectorPlane.applyMatrix4(virtualCamera.matrixWorldInverse);
|
|
97
|
+
clipPlane.set(reflectorPlane.normal.x, reflectorPlane.normal.y, reflectorPlane.normal.z, reflectorPlane.constant);
|
|
98
|
+
const projectionMatrix = virtualCamera.projectionMatrix;
|
|
99
|
+
q.x = (Math.sign(clipPlane.x) + projectionMatrix.elements[8]) / projectionMatrix.elements[0];
|
|
100
|
+
q.y = (Math.sign(clipPlane.y) + projectionMatrix.elements[9]) / projectionMatrix.elements[5];
|
|
101
|
+
q.z = -1.0;
|
|
102
|
+
q.w = (1.0 + projectionMatrix.elements[10]) / projectionMatrix.elements[14]; // Calculate the scaled plane vector
|
|
103
|
+
|
|
104
|
+
clipPlane.multiplyScalar(2.0 / clipPlane.dot(q)); // Replacing the third row of the projection matrix
|
|
105
|
+
|
|
106
|
+
projectionMatrix.elements[2] = clipPlane.x;
|
|
107
|
+
projectionMatrix.elements[6] = clipPlane.y;
|
|
108
|
+
projectionMatrix.elements[10] = clipPlane.z + 1.0;
|
|
109
|
+
projectionMatrix.elements[14] = clipPlane.w;
|
|
110
|
+
}, []);
|
|
111
|
+
const [fbo1, fbo2, blurpass, reflectorProps] = React.useMemo(() => {
|
|
112
|
+
const parameters = {
|
|
113
|
+
type: HalfFloatType,
|
|
114
|
+
minFilter: LinearFilter,
|
|
115
|
+
magFilter: LinearFilter
|
|
116
|
+
};
|
|
117
|
+
const fbo1 = new WebGLRenderTarget(resolution, resolution, parameters);
|
|
118
|
+
fbo1.depthBuffer = true;
|
|
119
|
+
fbo1.depthTexture = new DepthTexture(resolution, resolution);
|
|
120
|
+
fbo1.depthTexture.format = DepthFormat;
|
|
121
|
+
fbo1.depthTexture.type = UnsignedShortType;
|
|
122
|
+
const fbo2 = new WebGLRenderTarget(resolution, resolution, parameters);
|
|
123
|
+
const blurpass = new BlurPass({
|
|
124
|
+
gl,
|
|
125
|
+
resolution,
|
|
126
|
+
width: blur[0],
|
|
127
|
+
height: blur[1],
|
|
128
|
+
minDepthThreshold,
|
|
129
|
+
maxDepthThreshold,
|
|
130
|
+
depthScale,
|
|
131
|
+
depthToBlurRatioBias
|
|
132
|
+
});
|
|
133
|
+
const reflectorProps = {
|
|
134
|
+
mirror,
|
|
135
|
+
textureMatrix,
|
|
136
|
+
mixBlur,
|
|
137
|
+
tDiffuse: fbo1.texture,
|
|
138
|
+
tDepth: fbo1.depthTexture,
|
|
139
|
+
tDiffuseBlur: fbo2.texture,
|
|
140
|
+
hasBlur,
|
|
141
|
+
mixStrength,
|
|
142
|
+
minDepthThreshold,
|
|
143
|
+
maxDepthThreshold,
|
|
144
|
+
depthScale,
|
|
145
|
+
depthToBlurRatioBias,
|
|
146
|
+
transparent: true,
|
|
147
|
+
debug,
|
|
148
|
+
distortion,
|
|
149
|
+
distortionMap,
|
|
150
|
+
mixContrast,
|
|
151
|
+
'defines-USE_BLUR': hasBlur ? '' : undefined,
|
|
152
|
+
'defines-USE_DEPTH': depthScale > 0 ? '' : undefined,
|
|
153
|
+
'defines-USE_DISTORTION': distortionMap ? '' : undefined
|
|
154
|
+
};
|
|
155
|
+
return [fbo1, fbo2, blurpass, reflectorProps];
|
|
156
|
+
}, [gl, blur, textureMatrix, resolution, mirror, hasBlur, mixBlur, mixStrength, minDepthThreshold, maxDepthThreshold, depthScale, depthToBlurRatioBias, debug, distortion, distortionMap, mixContrast]);
|
|
157
|
+
useFrame(() => {
|
|
158
|
+
if (!(meshRef != null && meshRef.current)) return;
|
|
159
|
+
meshRef.current.visible = false;
|
|
160
|
+
const currentXrEnabled = gl.xr.enabled;
|
|
161
|
+
const currentShadowAutoUpdate = gl.shadowMap.autoUpdate;
|
|
162
|
+
beforeRender();
|
|
163
|
+
gl.xr.enabled = false;
|
|
164
|
+
gl.shadowMap.autoUpdate = false;
|
|
165
|
+
gl.setRenderTarget(fbo1);
|
|
166
|
+
gl.state.buffers.depth.setMask(true);
|
|
167
|
+
if (!gl.autoClear) gl.clear();
|
|
168
|
+
gl.render(scene, virtualCamera);
|
|
169
|
+
if (hasBlur) blurpass.render(gl, fbo1, fbo2);
|
|
170
|
+
gl.xr.enabled = currentXrEnabled;
|
|
171
|
+
gl.shadowMap.autoUpdate = currentShadowAutoUpdate;
|
|
172
|
+
meshRef.current.visible = true;
|
|
173
|
+
gl.setRenderTarget(null);
|
|
174
|
+
});
|
|
175
|
+
return /*#__PURE__*/React.createElement("mesh", _extends({
|
|
176
|
+
ref: mergeRefs([meshRef, ref])
|
|
177
|
+
}, props), /*#__PURE__*/React.createElement("planeGeometry", {
|
|
178
|
+
args: args
|
|
179
|
+
}), children ? children('meshReflectorMaterial', reflectorProps) : /*#__PURE__*/React.createElement("meshReflectorMaterial", reflectorProps));
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
export { Reflector };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { useThree, createPortal, useFrame } from '@react-three/fiber';
|
|
5
|
+
import { useFBO } from './useFBO.js';
|
|
6
|
+
|
|
7
|
+
const RenderTexture = /*#__PURE__*/React.forwardRef(({
|
|
8
|
+
children,
|
|
9
|
+
compute,
|
|
10
|
+
width,
|
|
11
|
+
height,
|
|
12
|
+
samples = 8,
|
|
13
|
+
renderPriority = 0,
|
|
14
|
+
eventPriority = 0,
|
|
15
|
+
frames = Infinity,
|
|
16
|
+
stencilBuffer = false,
|
|
17
|
+
depthBuffer = true,
|
|
18
|
+
generateMipmaps = false,
|
|
19
|
+
...props
|
|
20
|
+
}, forwardRef) => {
|
|
21
|
+
const {
|
|
22
|
+
size,
|
|
23
|
+
viewport
|
|
24
|
+
} = useThree();
|
|
25
|
+
const fbo = useFBO((width || size.width) * viewport.dpr, (height || size.height) * viewport.dpr, {
|
|
26
|
+
samples,
|
|
27
|
+
stencilBuffer,
|
|
28
|
+
depthBuffer,
|
|
29
|
+
generateMipmaps
|
|
30
|
+
});
|
|
31
|
+
const [vScene] = React.useState(() => new THREE.Scene());
|
|
32
|
+
const uvCompute = React.useCallback((event, state, previous) => {
|
|
33
|
+
var _fbo$texture, _previous$previousRoo;
|
|
34
|
+
|
|
35
|
+
// Since this is only a texture it does not have an easy way to obtain the parent, which we
|
|
36
|
+
// need to transform event coordinates to local coordinates. We use r3f internals to find the
|
|
37
|
+
// next Object3D.
|
|
38
|
+
let parent = (_fbo$texture = fbo.texture) == null ? void 0 : _fbo$texture.__r3f.parent;
|
|
39
|
+
|
|
40
|
+
while (parent && !(parent instanceof THREE.Object3D)) {
|
|
41
|
+
parent = parent.__r3f.parent;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!parent) return false; // First we call the previous state-onion-layers compute, this is what makes it possible to nest portals
|
|
45
|
+
|
|
46
|
+
if (!previous.raycaster.camera) previous.events.compute(event, previous, (_previous$previousRoo = previous.previousRoot) == null ? void 0 : _previous$previousRoo.getState()); // We run a quick check against the parent, if it isn't hit there's no need to raycast at all
|
|
47
|
+
|
|
48
|
+
const [intersection] = previous.raycaster.intersectObject(parent);
|
|
49
|
+
if (!intersection) return false; // We take that hits uv coords, set up this layers raycaster, et voilà, we have raycasting on arbitrary surfaces
|
|
50
|
+
|
|
51
|
+
const uv = intersection.uv;
|
|
52
|
+
if (!uv) return false;
|
|
53
|
+
state.raycaster.setFromCamera(state.pointer.set(uv.x * 2 - 1, uv.y * 2 - 1), state.camera);
|
|
54
|
+
}, []);
|
|
55
|
+
React.useImperativeHandle(forwardRef, () => fbo.texture, [fbo]);
|
|
56
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, createPortal( /*#__PURE__*/React.createElement(Container, {
|
|
57
|
+
renderPriority: renderPriority,
|
|
58
|
+
frames: frames,
|
|
59
|
+
fbo: fbo
|
|
60
|
+
}, children, /*#__PURE__*/React.createElement("group", {
|
|
61
|
+
onPointerOver: () => null
|
|
62
|
+
})), vScene, {
|
|
63
|
+
events: {
|
|
64
|
+
compute: compute || uvCompute,
|
|
65
|
+
priority: eventPriority
|
|
66
|
+
}
|
|
67
|
+
}), /*#__PURE__*/React.createElement("primitive", _extends({
|
|
68
|
+
object: fbo.texture
|
|
69
|
+
}, props)));
|
|
70
|
+
}); // The container component has to be separate, it can not be inlined because "useFrame(state" when run inside createPortal will return
|
|
71
|
+
// the portals own state which includes user-land overrides (custom cameras etc), but if it is executed in <RenderTexture>'s render function
|
|
72
|
+
// it would return the default state.
|
|
73
|
+
|
|
74
|
+
function Container({
|
|
75
|
+
frames,
|
|
76
|
+
renderPriority,
|
|
77
|
+
children,
|
|
78
|
+
fbo
|
|
79
|
+
}) {
|
|
80
|
+
let count = 0;
|
|
81
|
+
let oldAutoClear;
|
|
82
|
+
useFrame(state => {
|
|
83
|
+
if (frames === Infinity || count < frames) {
|
|
84
|
+
oldAutoClear = state.gl.autoClear;
|
|
85
|
+
state.gl.autoClear = true;
|
|
86
|
+
state.gl.setRenderTarget(fbo);
|
|
87
|
+
state.gl.render(state.scene, state.camera);
|
|
88
|
+
state.gl.setRenderTarget(null);
|
|
89
|
+
state.gl.autoClear = oldAutoClear;
|
|
90
|
+
count++;
|
|
91
|
+
}
|
|
92
|
+
}, renderPriority);
|
|
93
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export { RenderTexture };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
const Resize = /*#__PURE__*/React.forwardRef(({
|
|
6
|
+
children,
|
|
7
|
+
width,
|
|
8
|
+
height,
|
|
9
|
+
depth,
|
|
10
|
+
box3,
|
|
11
|
+
precise = true,
|
|
12
|
+
...props
|
|
13
|
+
}, fRef) => {
|
|
14
|
+
const ref = React.useRef(null);
|
|
15
|
+
const outer = React.useRef(null);
|
|
16
|
+
const inner = React.useRef(null);
|
|
17
|
+
React.useLayoutEffect(() => {
|
|
18
|
+
outer.current.matrixWorld.identity();
|
|
19
|
+
let box = box3 || new THREE.Box3().setFromObject(inner.current, precise);
|
|
20
|
+
const w = box.max.x - box.min.x;
|
|
21
|
+
const h = box.max.y - box.min.y;
|
|
22
|
+
const d = box.max.z - box.min.z;
|
|
23
|
+
let dimension = Math.max(w, h, d);
|
|
24
|
+
if (width) dimension = w;
|
|
25
|
+
if (height) dimension = h;
|
|
26
|
+
if (depth) dimension = d;
|
|
27
|
+
outer.current.scale.setScalar(1 / dimension);
|
|
28
|
+
}, [width, height, depth, box3, precise]);
|
|
29
|
+
React.useImperativeHandle(fRef, () => ref.current, []);
|
|
30
|
+
return /*#__PURE__*/React.createElement("group", _extends({
|
|
31
|
+
ref: ref
|
|
32
|
+
}, props), /*#__PURE__*/React.createElement("group", {
|
|
33
|
+
ref: outer
|
|
34
|
+
}, /*#__PURE__*/React.createElement("group", {
|
|
35
|
+
ref: inner
|
|
36
|
+
}, children)));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export { Resize };
|