@react-three/drei 10.8.0-alpha.1 → 11.0.0-alpha.1
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/_chunks/libs/tunnel-rat.mjs +11 -11
- package/core/_chunks/libs/zustand.mjs +3 -3
- package/core/core/index.d.mts +150 -150
- package/core/core/index.mjs +646 -646
- package/index.d.mts +5 -5
- package/native/_chunks/libs/tunnel-rat.mjs +11 -11
- package/native/_chunks/libs/zustand.mjs +3 -3
- package/native/native/index.d.mts +164 -164
- package/native/native/index.mjs +765 -765
- package/package.json +1 -1
- package/webgpu/webgpu/index.d.mts +1 -1
package/core/core/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import { t as require_stats_min } from "../_chunks/libs/stats.js.mjs";
|
|
|
10
10
|
import { t as Stats$1 } from "../_chunks/libs/stats-gl.mjs";
|
|
11
11
|
import { t as require_index_cjs$1 } from "../_chunks/libs/tunnel-rat.mjs";
|
|
12
12
|
import { n as HDRJPGLoader, t as GainMapLoader } from "../_chunks/libs/@monogrid/gainmap-js.mjs";
|
|
13
|
-
import * as React
|
|
13
|
+
import * as React from "react";
|
|
14
14
|
import { Fragment, createContext, forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
15
15
|
import { addAfterEffect, addEffect, applyProps, context, createPortal, extend, useFrame, useInstanceHandle, useLoader, useThree } from "@react-three/fiber";
|
|
16
16
|
import { HorizontalBlurShader } from "three/examples/jsm/shaders/HorizontalBlurShader";
|
|
@@ -75,14 +75,14 @@ import { SelectionBox } from "three/examples/jsm/interactive/SelectionBox";
|
|
|
75
75
|
* <ContactShadows frames={1} />
|
|
76
76
|
* ```
|
|
77
77
|
*/
|
|
78
|
-
const ContactShadows = /* @__PURE__ */ React
|
|
79
|
-
const ref = React
|
|
78
|
+
const ContactShadows = /* @__PURE__ */ React.forwardRef(({ scale: scale$2 = 10, frames = Infinity, opacity = 1, width = 1, height = 1, blur = 1, near = 0, far = 10, resolution = 512, smooth = true, color = "#000000", depthWrite = false, renderOrder, ...props }, fref) => {
|
|
79
|
+
const ref = React.useRef(null);
|
|
80
80
|
const scene = useThree((state) => state.scene);
|
|
81
81
|
const gl = useThree((state) => state.gl);
|
|
82
|
-
const shadowCamera = React
|
|
82
|
+
const shadowCamera = React.useRef(null);
|
|
83
83
|
width = width * (Array.isArray(scale$2) ? scale$2[0] : scale$2 || 1);
|
|
84
84
|
height = height * (Array.isArray(scale$2) ? scale$2[1] : scale$2 || 1);
|
|
85
|
-
const [renderTarget, planeGeometry, depthMaterial, blurPlane, horizontalBlurMaterial, verticalBlurMaterial, renderTargetBlur] = React
|
|
85
|
+
const [renderTarget, planeGeometry, depthMaterial, blurPlane, horizontalBlurMaterial, verticalBlurMaterial, renderTargetBlur] = React.useMemo(() => {
|
|
86
86
|
const renderTarget$1 = new WebGLRenderTarget$1(resolution, resolution);
|
|
87
87
|
const renderTargetBlur$1 = new WebGLRenderTarget$1(resolution, resolution);
|
|
88
88
|
renderTargetBlur$1.texture.generateMipmaps = renderTarget$1.texture.generateMipmaps = false;
|
|
@@ -154,7 +154,7 @@ const ContactShadows = /* @__PURE__ */ React$1.forwardRef(({ scale: scale$2 = 10
|
|
|
154
154
|
scene.background = initialBackground;
|
|
155
155
|
}
|
|
156
156
|
});
|
|
157
|
-
React
|
|
157
|
+
React.useImperativeHandle(fref, () => ref.current, []);
|
|
158
158
|
return /* @__PURE__ */ jsxs("group", {
|
|
159
159
|
"rotation-x": Math.PI / 2,
|
|
160
160
|
...props,
|
|
@@ -257,7 +257,7 @@ function isLight(object) {
|
|
|
257
257
|
function isGeometry$1(object) {
|
|
258
258
|
return !!object.geometry;
|
|
259
259
|
}
|
|
260
|
-
const accumulativeContext = /* @__PURE__ */ React
|
|
260
|
+
const accumulativeContext = /* @__PURE__ */ React.createContext(null);
|
|
261
261
|
const SoftShadowMaterial = /* @__PURE__ */ shaderMaterial({
|
|
262
262
|
color: /* @__PURE__ */ new Color$2(),
|
|
263
263
|
blend: 2,
|
|
@@ -280,19 +280,19 @@ const SoftShadowMaterial = /* @__PURE__ */ shaderMaterial({
|
|
|
280
280
|
#include <tonemapping_fragment>
|
|
281
281
|
#include <${version >= 154 ? "colorspace_fragment" : "encodings_fragment"}>
|
|
282
282
|
}`);
|
|
283
|
-
const AccumulativeShadows = /* @__PURE__ */ React
|
|
283
|
+
const AccumulativeShadows = /* @__PURE__ */ React.forwardRef(({ children, temporal, frames = 40, limit = Infinity, blend = 20, scale: scale$2 = 10, opacity = 1, alphaTest = .75, color = "black", colorBlend = 2, resolution = 1024, toneMapped = true, ...props }, forwardRef$1) => {
|
|
284
284
|
extend({ SoftShadowMaterial });
|
|
285
285
|
const gl = useThree((state) => state.gl);
|
|
286
286
|
const scene = useThree((state) => state.scene);
|
|
287
287
|
const camera = useThree((state) => state.camera);
|
|
288
288
|
const invalidate = useThree((state) => state.invalidate);
|
|
289
|
-
const gPlane = React
|
|
290
|
-
const gLights = React
|
|
291
|
-
const [plm] = React
|
|
292
|
-
React
|
|
289
|
+
const gPlane = React.useRef(null);
|
|
290
|
+
const gLights = React.useRef(null);
|
|
291
|
+
const [plm] = React.useState(() => new ProgressiveLightMap(gl, scene, resolution));
|
|
292
|
+
React.useLayoutEffect(() => {
|
|
293
293
|
plm.configure(gPlane.current);
|
|
294
294
|
}, []);
|
|
295
|
-
const api = React
|
|
295
|
+
const api = React.useMemo(() => ({
|
|
296
296
|
lights: /* @__PURE__ */ new Map(),
|
|
297
297
|
temporal: !!temporal,
|
|
298
298
|
frames: Math.max(2, frames),
|
|
@@ -334,11 +334,11 @@ const AccumulativeShadows = /* @__PURE__ */ React$1.forwardRef(({ children, temp
|
|
|
334
334
|
opacity,
|
|
335
335
|
alphaTest
|
|
336
336
|
]);
|
|
337
|
-
React
|
|
337
|
+
React.useLayoutEffect(() => {
|
|
338
338
|
api.reset();
|
|
339
339
|
if (!api.temporal && api.frames !== Infinity) api.update(api.blend);
|
|
340
340
|
});
|
|
341
|
-
React
|
|
341
|
+
React.useImperativeHandle(forwardRef$1, () => api, [api]);
|
|
342
342
|
useFrame(() => {
|
|
343
343
|
if ((api.temporal || api.frames === Infinity) && api.count < api.frames && api.count < limit) {
|
|
344
344
|
invalidate();
|
|
@@ -375,15 +375,15 @@ const AccumulativeShadows = /* @__PURE__ */ React$1.forwardRef(({ children, temp
|
|
|
375
375
|
})]
|
|
376
376
|
});
|
|
377
377
|
});
|
|
378
|
-
const RandomizedLight = /* @__PURE__ */ React
|
|
378
|
+
const RandomizedLight = /* @__PURE__ */ React.forwardRef(({ castShadow = true, bias = .001, mapSize = 512, size = 5, near = .5, far = 500, frames = 1, position: position$1 = [
|
|
379
379
|
0,
|
|
380
380
|
0,
|
|
381
381
|
0
|
|
382
382
|
], radius = 1, amount = 8, intensity = version >= 155 ? Math.PI : 1, ambient = .5, ...props }, forwardRef$1) => {
|
|
383
|
-
const gLights = React
|
|
383
|
+
const gLights = React.useRef(null);
|
|
384
384
|
const length = new Vector3$2(...position$1).length();
|
|
385
|
-
const parent = React
|
|
386
|
-
const update = React
|
|
385
|
+
const parent = React.useContext(accumulativeContext);
|
|
386
|
+
const update = React.useCallback(() => {
|
|
387
387
|
let light;
|
|
388
388
|
if (gLights.current) for (let l = 0; l < gLights.current.children.length; l++) {
|
|
389
389
|
light = gLights.current.children[l];
|
|
@@ -400,9 +400,9 @@ const RandomizedLight = /* @__PURE__ */ React$1.forwardRef(({ castShadow = true,
|
|
|
400
400
|
length,
|
|
401
401
|
...position$1
|
|
402
402
|
]);
|
|
403
|
-
const api = React
|
|
404
|
-
React
|
|
405
|
-
React
|
|
403
|
+
const api = React.useMemo(() => ({ update }), [update]);
|
|
404
|
+
React.useImperativeHandle(forwardRef$1, () => api, [api]);
|
|
405
|
+
React.useLayoutEffect(() => {
|
|
406
406
|
const group = gLights.current;
|
|
407
407
|
if (parent) parent.lights?.set(group.uuid, api);
|
|
408
408
|
return () => void parent?.lights?.delete(group.uuid);
|
|
@@ -551,7 +551,7 @@ function useFBO(width, height, settings) {
|
|
|
551
551
|
const _settings = (typeof width === "number" ? settings : width) || {};
|
|
552
552
|
const { samples = 0, depth, ...targetSettings } = _settings;
|
|
553
553
|
const depthBuffer = depth ?? _settings.depthBuffer;
|
|
554
|
-
const target$1 = React
|
|
554
|
+
const target$1 = React.useMemo(() => {
|
|
555
555
|
const target$2 = new RenderTarget(_width, _height, {
|
|
556
556
|
minFilter: LinearFilter$1,
|
|
557
557
|
magFilter: LinearFilter$1,
|
|
@@ -562,7 +562,7 @@ function useFBO(width, height, settings) {
|
|
|
562
562
|
target$2.samples = samples;
|
|
563
563
|
return target$2;
|
|
564
564
|
}, []);
|
|
565
|
-
React
|
|
565
|
+
React.useLayoutEffect(() => {
|
|
566
566
|
target$1.setSize(_width, _height);
|
|
567
567
|
if (samples) target$1.samples = samples;
|
|
568
568
|
}, [
|
|
@@ -571,7 +571,7 @@ function useFBO(width, height, settings) {
|
|
|
571
571
|
_width,
|
|
572
572
|
_height
|
|
573
573
|
]);
|
|
574
|
-
React
|
|
574
|
+
React.useEffect(() => {
|
|
575
575
|
return () => target$1.dispose();
|
|
576
576
|
}, []);
|
|
577
577
|
return target$1;
|
|
@@ -615,9 +615,9 @@ const Fbo = /* @__PURE__ */ forwardRef(({ children, width, height, ...settings }
|
|
|
615
615
|
* ```
|
|
616
616
|
*/
|
|
617
617
|
function useHelper(object3D, helperConstructor, ...args) {
|
|
618
|
-
const helper = React
|
|
618
|
+
const helper = React.useRef(null);
|
|
619
619
|
const scene = useThree((state) => state.scene);
|
|
620
|
-
React
|
|
620
|
+
React.useLayoutEffect(() => {
|
|
621
621
|
let currentHelper = void 0;
|
|
622
622
|
if (object3D && object3D?.current && helperConstructor) helper.current = currentHelper = new helperConstructor(object3D.current, ...args);
|
|
623
623
|
if (currentHelper) {
|
|
@@ -650,9 +650,9 @@ function useHelper(object3D, helperConstructor, ...args) {
|
|
|
650
650
|
* ```
|
|
651
651
|
*/
|
|
652
652
|
const Helper = ({ type: helperConstructor, args = [] }) => {
|
|
653
|
-
const thisRef = React
|
|
654
|
-
const parentRef = React
|
|
655
|
-
React
|
|
653
|
+
const thisRef = React.useRef(null);
|
|
654
|
+
const parentRef = React.useRef(null);
|
|
655
|
+
React.useLayoutEffect(() => {
|
|
656
656
|
parentRef.current = thisRef.current.parent;
|
|
657
657
|
});
|
|
658
658
|
useHelper(parentRef, helperConstructor, ...args);
|
|
@@ -681,11 +681,11 @@ const Helper = ({ type: helperConstructor, args = [] }) => {
|
|
|
681
681
|
* </mesh>
|
|
682
682
|
* ```
|
|
683
683
|
*/
|
|
684
|
-
const Edges = /* @__PURE__ */ React
|
|
684
|
+
const Edges = /* @__PURE__ */ React.forwardRef(({ threshold = 15, geometry: explicitGeometry, LineComponent, ...props }, fref) => {
|
|
685
685
|
const LineComp = LineComponent ?? Line;
|
|
686
|
-
const ref = React
|
|
687
|
-
React
|
|
688
|
-
const tmpPoints = React
|
|
686
|
+
const ref = React.useRef(null);
|
|
687
|
+
React.useImperativeHandle(fref, () => ref.current, []);
|
|
688
|
+
const tmpPoints = React.useMemo(() => [
|
|
689
689
|
0,
|
|
690
690
|
0,
|
|
691
691
|
0,
|
|
@@ -693,9 +693,9 @@ const Edges = /* @__PURE__ */ React$1.forwardRef(({ threshold = 15, geometry: ex
|
|
|
693
693
|
0,
|
|
694
694
|
0
|
|
695
695
|
], []);
|
|
696
|
-
const memoizedGeometry = React
|
|
697
|
-
const memoizedThreshold = React
|
|
698
|
-
React
|
|
696
|
+
const memoizedGeometry = React.useRef(null);
|
|
697
|
+
const memoizedThreshold = React.useRef(null);
|
|
698
|
+
React.useLayoutEffect(() => {
|
|
699
699
|
const parent = ref.current.parent;
|
|
700
700
|
const geometry$1 = explicitGeometry ?? parent?.geometry;
|
|
701
701
|
if (!geometry$1) return;
|
|
@@ -731,17 +731,17 @@ const Edges = /* @__PURE__ */ React$1.forwardRef(({ threshold = 15, geometry: ex
|
|
|
731
731
|
*/
|
|
732
732
|
function useIntersect(onChange) {
|
|
733
733
|
const { isLegacy } = useThree();
|
|
734
|
-
const ref = React
|
|
735
|
-
const currentStatus = React
|
|
736
|
-
const previousStatus = React
|
|
737
|
-
const callback = React
|
|
738
|
-
const { frustum, projScreenMatrix } = React
|
|
734
|
+
const ref = React.useRef(null);
|
|
735
|
+
const currentStatus = React.useRef(false);
|
|
736
|
+
const previousStatus = React.useRef(false);
|
|
737
|
+
const callback = React.useRef(onChange);
|
|
738
|
+
const { frustum, projScreenMatrix } = React.useMemo(() => {
|
|
739
739
|
return {
|
|
740
740
|
frustum: new Frustum(),
|
|
741
741
|
projScreenMatrix: new Matrix4()
|
|
742
742
|
};
|
|
743
743
|
}, []);
|
|
744
|
-
React
|
|
744
|
+
React.useLayoutEffect(() => void (callback.current = onChange), [onChange]);
|
|
745
745
|
useFrame(() => {
|
|
746
746
|
if (ref.current) currentStatus.current = false;
|
|
747
747
|
}, { phase: "start" });
|
|
@@ -759,7 +759,7 @@ function useIntersect(onChange) {
|
|
|
759
759
|
previousStatus.current = visibleNow;
|
|
760
760
|
callback.current?.(visibleNow);
|
|
761
761
|
}, { phase: "end" });
|
|
762
|
-
React
|
|
762
|
+
React.useEffect(() => {
|
|
763
763
|
const obj = ref.current;
|
|
764
764
|
if (obj && isLegacy) {
|
|
765
765
|
const oldOnRender = obj.onBeforeRender;
|
|
@@ -774,11 +774,11 @@ function useIntersect(onChange) {
|
|
|
774
774
|
|
|
775
775
|
//#endregion
|
|
776
776
|
//#region src/core/Portal/RenderTexture/RenderTexture.tsx
|
|
777
|
-
const RenderTexture = /* @__PURE__ */ React
|
|
777
|
+
const RenderTexture = /* @__PURE__ */ React.forwardRef(({ children, compute, width, height, samples = 4, renderPriority = 0, eventPriority = 0, frames = Infinity, stencilBuffer = false, depthBuffer = true, generateMipmaps = false, ...props }, forwardRef$1) => {
|
|
778
778
|
const { size, viewport, isLegacy } = useThree();
|
|
779
779
|
const fboWidth = (width || size.width) * viewport.dpr;
|
|
780
780
|
const fboHeight = (height || size.height) * viewport.dpr;
|
|
781
|
-
const fboRef = React
|
|
781
|
+
const fboRef = React.useRef(null);
|
|
782
782
|
if (!fboRef.current) {
|
|
783
783
|
const settings = {
|
|
784
784
|
minFilter: LinearFilter$1,
|
|
@@ -796,7 +796,7 @@ const RenderTexture = /* @__PURE__ */ React$1.forwardRef(({ children, compute, w
|
|
|
796
796
|
}
|
|
797
797
|
const fboA = fboRef.current.a;
|
|
798
798
|
const fboB = fboRef.current.b;
|
|
799
|
-
React
|
|
799
|
+
React.useLayoutEffect(() => {
|
|
800
800
|
const needsFlip = !isLegacy;
|
|
801
801
|
fboA.texture.flipY = !needsFlip;
|
|
802
802
|
fboB.texture.flipY = !needsFlip;
|
|
@@ -805,7 +805,7 @@ const RenderTexture = /* @__PURE__ */ React$1.forwardRef(({ children, compute, w
|
|
|
805
805
|
fboB,
|
|
806
806
|
isLegacy
|
|
807
807
|
]);
|
|
808
|
-
React
|
|
808
|
+
React.useLayoutEffect(() => {
|
|
809
809
|
fboA.setSize(fboWidth, fboHeight);
|
|
810
810
|
fboB.setSize(fboWidth, fboHeight);
|
|
811
811
|
}, [
|
|
@@ -814,7 +814,7 @@ const RenderTexture = /* @__PURE__ */ React$1.forwardRef(({ children, compute, w
|
|
|
814
814
|
fboWidth,
|
|
815
815
|
fboHeight
|
|
816
816
|
]);
|
|
817
|
-
React
|
|
817
|
+
React.useEffect(() => {
|
|
818
818
|
return () => {
|
|
819
819
|
if (fboRef.current) {
|
|
820
820
|
fboRef.current.a.dispose();
|
|
@@ -823,10 +823,10 @@ const RenderTexture = /* @__PURE__ */ React$1.forwardRef(({ children, compute, w
|
|
|
823
823
|
}
|
|
824
824
|
};
|
|
825
825
|
}, []);
|
|
826
|
-
const readBufferIndex = React
|
|
827
|
-
const displayTextureRef = React
|
|
828
|
-
const [vScene] = React
|
|
829
|
-
const uvCompute = React
|
|
826
|
+
const readBufferIndex = React.useRef(0);
|
|
827
|
+
const displayTextureRef = React.useRef(fboA.texture);
|
|
828
|
+
const [vScene] = React.useState(() => new Scene$1());
|
|
829
|
+
const uvCompute = React.useCallback((event, state, previous) => {
|
|
830
830
|
let parent = fboA.texture?.__r3f?.parent?.object;
|
|
831
831
|
while (parent && !(parent instanceof Object3D)) parent = parent.__r3f?.parent?.object;
|
|
832
832
|
if (!parent) return false;
|
|
@@ -837,7 +837,7 @@ const RenderTexture = /* @__PURE__ */ React$1.forwardRef(({ children, compute, w
|
|
|
837
837
|
if (!uv) return false;
|
|
838
838
|
state.raycaster.setFromCamera(state.pointer.set(uv.x * 2 - 1, uv.y * 2 - 1), state.camera);
|
|
839
839
|
}, [fboA]);
|
|
840
|
-
React
|
|
840
|
+
React.useImperativeHandle(forwardRef$1, () => displayTextureRef.current, []);
|
|
841
841
|
return /* @__PURE__ */ jsxs(Fragment$1, { children: [createPortal(/* @__PURE__ */ jsxs(Container$2, {
|
|
842
842
|
renderPriority,
|
|
843
843
|
frames,
|
|
@@ -926,7 +926,7 @@ function RenderHud$1({ defaultScene, defaultCamera, renderPriority = 1 }) {
|
|
|
926
926
|
}
|
|
927
927
|
function Hud$1({ children, renderPriority = 1 }) {
|
|
928
928
|
const { scene: defaultScene, camera: defaultCamera } = useThree();
|
|
929
|
-
const [hudScene] = React
|
|
929
|
+
const [hudScene] = React.useState(() => new Scene$1());
|
|
930
930
|
return /* @__PURE__ */ jsx(Fragment$1, { children: createPortal(/* @__PURE__ */ jsxs(Fragment$1, { children: [children, /* @__PURE__ */ jsx(RenderHud$1, {
|
|
931
931
|
defaultScene,
|
|
932
932
|
defaultCamera,
|
|
@@ -952,12 +952,12 @@ function Hud$1({ children, renderPriority = 1 }) {
|
|
|
952
952
|
* />
|
|
953
953
|
* ```
|
|
954
954
|
*/
|
|
955
|
-
const Line = /* @__PURE__ */ React
|
|
955
|
+
const Line = /* @__PURE__ */ React.forwardRef(function Line$1({ points, color = 16777215, vertexColors, linewidth, lineWidth, segments, dashed, ...rest }, ref) {
|
|
956
956
|
const size = useThree((state) => state.size);
|
|
957
|
-
const line2 = React
|
|
958
|
-
const lineMaterial = React
|
|
957
|
+
const line2 = React.useMemo(() => segments ? new LineSegments2() : new Line2(), [segments]);
|
|
958
|
+
const lineMaterial = React.useMemo(() => new LineMaterial(), []);
|
|
959
959
|
const itemSize = (vertexColors?.[0])?.length === 4 ? 4 : 3;
|
|
960
|
-
const lineGeom = React
|
|
960
|
+
const lineGeom = React.useMemo(() => {
|
|
961
961
|
const geom = segments ? new LineSegmentsGeometry() : new LineGeometry();
|
|
962
962
|
const pValues = points.map((p) => {
|
|
963
963
|
const isArray$1 = Array.isArray(p);
|
|
@@ -1005,15 +1005,15 @@ const Line = /* @__PURE__ */ React$1.forwardRef(function Line$1({ points, color
|
|
|
1005
1005
|
vertexColors,
|
|
1006
1006
|
itemSize
|
|
1007
1007
|
]);
|
|
1008
|
-
React
|
|
1008
|
+
React.useLayoutEffect(() => {
|
|
1009
1009
|
line2.computeLineDistances();
|
|
1010
1010
|
}, [points, line2]);
|
|
1011
|
-
React
|
|
1011
|
+
React.useLayoutEffect(() => {
|
|
1012
1012
|
if (dashed) lineMaterial.dashed = true;
|
|
1013
1013
|
else lineMaterial.dashed = false;
|
|
1014
1014
|
lineMaterial.needsUpdate = true;
|
|
1015
1015
|
}, [dashed, lineMaterial]);
|
|
1016
|
-
React
|
|
1016
|
+
React.useEffect(() => {
|
|
1017
1017
|
const geom = lineGeom;
|
|
1018
1018
|
const mat = lineMaterial;
|
|
1019
1019
|
return () => {
|
|
@@ -1173,21 +1173,21 @@ const isFunction$1 = (node) => typeof node === "function";
|
|
|
1173
1173
|
* </OrthographicCamera>
|
|
1174
1174
|
* ```
|
|
1175
1175
|
*/
|
|
1176
|
-
const OrthographicCamera = /* @__PURE__ */ React
|
|
1176
|
+
const OrthographicCamera = /* @__PURE__ */ React.forwardRef(({ envMap, resolution = 256, frames = Infinity, children, makeDefault, ...props }, ref) => {
|
|
1177
1177
|
const set = useThree(({ set: set$1 }) => set$1);
|
|
1178
1178
|
const camera = useThree(({ camera: camera$1 }) => camera$1);
|
|
1179
1179
|
const size = useThree(({ size: size$1 }) => size$1);
|
|
1180
|
-
const cameraRef = React
|
|
1181
|
-
React
|
|
1182
|
-
const groupRef = React
|
|
1180
|
+
const cameraRef = React.useRef(null);
|
|
1181
|
+
React.useImperativeHandle(ref, () => cameraRef.current, []);
|
|
1182
|
+
const groupRef = React.useRef(null);
|
|
1183
1183
|
const fbo = useFBO(resolution);
|
|
1184
|
-
React
|
|
1184
|
+
React.useLayoutEffect(() => {
|
|
1185
1185
|
if (!props.manual) cameraRef.current.updateProjectionMatrix();
|
|
1186
1186
|
}, [size, props]);
|
|
1187
|
-
React
|
|
1187
|
+
React.useLayoutEffect(() => {
|
|
1188
1188
|
cameraRef.current.updateProjectionMatrix();
|
|
1189
1189
|
});
|
|
1190
|
-
React
|
|
1190
|
+
React.useLayoutEffect(() => {
|
|
1191
1191
|
if (makeDefault) {
|
|
1192
1192
|
const oldCam = camera;
|
|
1193
1193
|
set(() => ({ camera: cameraRef.current }));
|
|
@@ -1259,18 +1259,18 @@ const isFunction = (node) => typeof node === "function";
|
|
|
1259
1259
|
* </PerspectiveCamera>
|
|
1260
1260
|
* ```
|
|
1261
1261
|
*/
|
|
1262
|
-
const PerspectiveCamera = /* @__PURE__ */ React
|
|
1262
|
+
const PerspectiveCamera = /* @__PURE__ */ React.forwardRef(({ envMap, resolution = 256, frames = Infinity, makeDefault, children, ...props }, ref) => {
|
|
1263
1263
|
const set = useThree(({ set: set$1 }) => set$1);
|
|
1264
1264
|
const camera = useThree(({ camera: camera$1 }) => camera$1);
|
|
1265
1265
|
const size = useThree(({ size: size$1 }) => size$1);
|
|
1266
|
-
const cameraRef = React
|
|
1267
|
-
React
|
|
1268
|
-
const groupRef = React
|
|
1266
|
+
const cameraRef = React.useRef(null);
|
|
1267
|
+
React.useImperativeHandle(ref, () => cameraRef.current, []);
|
|
1268
|
+
const groupRef = React.useRef(null);
|
|
1269
1269
|
const fbo = useFBO(resolution);
|
|
1270
|
-
React
|
|
1270
|
+
React.useLayoutEffect(() => {
|
|
1271
1271
|
if (!props.manual) cameraRef.current.aspect = size.width / size.height;
|
|
1272
1272
|
}, [size, props]);
|
|
1273
|
-
React
|
|
1273
|
+
React.useLayoutEffect(() => {
|
|
1274
1274
|
cameraRef.current.updateProjectionMatrix();
|
|
1275
1275
|
});
|
|
1276
1276
|
let count = 0;
|
|
@@ -1289,7 +1289,7 @@ const PerspectiveCamera = /* @__PURE__ */ React$1.forwardRef(({ envMap, resoluti
|
|
|
1289
1289
|
count++;
|
|
1290
1290
|
}
|
|
1291
1291
|
});
|
|
1292
|
-
React
|
|
1292
|
+
React.useLayoutEffect(() => {
|
|
1293
1293
|
if (makeDefault) {
|
|
1294
1294
|
const oldCam = camera;
|
|
1295
1295
|
set(() => ({ camera: cameraRef.current }));
|
|
@@ -1388,15 +1388,15 @@ const ArcballControls = /* @__PURE__ */ forwardRef(({ camera, makeDefault, regre
|
|
|
1388
1388
|
* <DeviceOrientationControls />
|
|
1389
1389
|
* ```
|
|
1390
1390
|
*/
|
|
1391
|
-
const DeviceOrientationControls = /* @__PURE__ */ React
|
|
1391
|
+
const DeviceOrientationControls = /* @__PURE__ */ React.forwardRef((props, ref) => {
|
|
1392
1392
|
const { camera, onChange, makeDefault, ...rest } = props;
|
|
1393
1393
|
const defaultCamera = useThree((state) => state.camera);
|
|
1394
1394
|
const invalidate = useThree((state) => state.invalidate);
|
|
1395
1395
|
const get = useThree((state) => state.get);
|
|
1396
1396
|
const set = useThree((state) => state.set);
|
|
1397
1397
|
const explCamera = camera || defaultCamera;
|
|
1398
|
-
const controls = React
|
|
1399
|
-
React
|
|
1398
|
+
const controls = React.useMemo(() => new DeviceOrientationControls$1(explCamera), [explCamera]);
|
|
1399
|
+
React.useEffect(() => {
|
|
1400
1400
|
const callback = (e) => {
|
|
1401
1401
|
invalidate();
|
|
1402
1402
|
if (onChange) onChange(e);
|
|
@@ -1409,12 +1409,12 @@ const DeviceOrientationControls = /* @__PURE__ */ React$1.forwardRef((props, ref
|
|
|
1409
1409
|
invalidate
|
|
1410
1410
|
]);
|
|
1411
1411
|
useFrame(() => controls?.update(), -1);
|
|
1412
|
-
React
|
|
1412
|
+
React.useEffect(() => {
|
|
1413
1413
|
const current = controls;
|
|
1414
1414
|
current?.connect();
|
|
1415
1415
|
return () => current?.dispose();
|
|
1416
1416
|
}, [controls]);
|
|
1417
|
-
React
|
|
1417
|
+
React.useEffect(() => {
|
|
1418
1418
|
if (makeDefault) {
|
|
1419
1419
|
const old = get().controls;
|
|
1420
1420
|
set({ controls });
|
|
@@ -1458,10 +1458,10 @@ const dragPlane = /* @__PURE__ */ new Plane$1();
|
|
|
1458
1458
|
* />
|
|
1459
1459
|
* ```
|
|
1460
1460
|
*/
|
|
1461
|
-
const DragControls = React
|
|
1461
|
+
const DragControls = React.forwardRef(({ autoTransform = true, matrix: matrix$1, axisLock, dragLimits, onHover, onDragStart, onDrag, onDragEnd, children, dragConfig, ...props }, fRef) => {
|
|
1462
1462
|
const defaultControls = useThree((state) => state.controls);
|
|
1463
1463
|
const { camera, size, raycaster, invalidate } = useThree();
|
|
1464
|
-
const ref = React
|
|
1464
|
+
const ref = React.useRef(null);
|
|
1465
1465
|
const bind = (0, import_use_gesture_react_cjs.useGesture)({
|
|
1466
1466
|
onHover: ({ hovering }) => onHover && onHover(hovering ?? false),
|
|
1467
1467
|
onDragStart: ({ event }) => {
|
|
@@ -1525,8 +1525,8 @@ const DragControls = React$1.forwardRef(({ autoTransform = true, matrix: matrix$
|
|
|
1525
1525
|
threshold: 1,
|
|
1526
1526
|
...typeof dragConfig === "object" ? dragConfig : {}
|
|
1527
1527
|
} });
|
|
1528
|
-
React
|
|
1529
|
-
React
|
|
1528
|
+
React.useImperativeHandle(fRef, () => ref.current, []);
|
|
1529
|
+
React.useLayoutEffect(() => {
|
|
1530
1530
|
if (!matrix$1) return;
|
|
1531
1531
|
ref.current.matrix = matrix$1;
|
|
1532
1532
|
}, [matrix$1]);
|
|
@@ -1551,15 +1551,15 @@ const DragControls = React$1.forwardRef(({ autoTransform = true, matrix: matrix$
|
|
|
1551
1551
|
* <FirstPersonControls />
|
|
1552
1552
|
* ```
|
|
1553
1553
|
*/
|
|
1554
|
-
const FirstPersonControls = /* @__PURE__ */ React
|
|
1554
|
+
const FirstPersonControls = /* @__PURE__ */ React.forwardRef(({ domElement, makeDefault, ...props }, ref) => {
|
|
1555
1555
|
const camera = useThree((state) => state.camera);
|
|
1556
1556
|
const gl = useThree((state) => state.gl);
|
|
1557
1557
|
const events = useThree((state) => state.events);
|
|
1558
1558
|
const get = useThree((state) => state.get);
|
|
1559
1559
|
const set = useThree((state) => state.set);
|
|
1560
1560
|
const explDomElement = domElement || events.connected || gl.domElement;
|
|
1561
|
-
const [controls] = React
|
|
1562
|
-
React
|
|
1561
|
+
const [controls] = React.useState(() => new FirstPersonControls$1(camera, explDomElement));
|
|
1562
|
+
React.useEffect(() => {
|
|
1563
1563
|
if (makeDefault) {
|
|
1564
1564
|
const old = get().controls;
|
|
1565
1565
|
set({ controls });
|
|
@@ -1587,7 +1587,7 @@ const FirstPersonControls = /* @__PURE__ */ React$1.forwardRef(({ domElement, ma
|
|
|
1587
1587
|
* <FlyControls movementSpeed={2} rollSpeed={Math.PI / 6} />
|
|
1588
1588
|
* ```
|
|
1589
1589
|
*/
|
|
1590
|
-
const FlyControls = /* @__PURE__ */ React
|
|
1590
|
+
const FlyControls = /* @__PURE__ */ React.forwardRef(({ domElement, ...props }, fref) => {
|
|
1591
1591
|
const { onChange, makeDefault, ...rest } = props;
|
|
1592
1592
|
const invalidate = useThree((state) => state.invalidate);
|
|
1593
1593
|
const camera = useThree((state) => state.camera);
|
|
@@ -1596,8 +1596,8 @@ const FlyControls = /* @__PURE__ */ React$1.forwardRef(({ domElement, ...props }
|
|
|
1596
1596
|
const get = useThree((state) => state.get);
|
|
1597
1597
|
const set = useThree((state) => state.set);
|
|
1598
1598
|
const explDomElement = domElement || events.connected || gl.domElement;
|
|
1599
|
-
const controls = React
|
|
1600
|
-
React
|
|
1599
|
+
const controls = React.useMemo(() => new FlyControls$1(camera), [camera]);
|
|
1600
|
+
React.useEffect(() => {
|
|
1601
1601
|
controls.connect(explDomElement);
|
|
1602
1602
|
return () => void controls.dispose();
|
|
1603
1603
|
}, [
|
|
@@ -1605,7 +1605,7 @@ const FlyControls = /* @__PURE__ */ React$1.forwardRef(({ domElement, ...props }
|
|
|
1605
1605
|
controls,
|
|
1606
1606
|
invalidate
|
|
1607
1607
|
]);
|
|
1608
|
-
React
|
|
1608
|
+
React.useEffect(() => {
|
|
1609
1609
|
const callback = (e) => {
|
|
1610
1610
|
invalidate();
|
|
1611
1611
|
if (onChange) onChange(e);
|
|
@@ -1613,7 +1613,7 @@ const FlyControls = /* @__PURE__ */ React$1.forwardRef(({ domElement, ...props }
|
|
|
1613
1613
|
controls.addEventListener?.("change", callback);
|
|
1614
1614
|
return () => controls.removeEventListener?.("change", callback);
|
|
1615
1615
|
}, [onChange, invalidate]);
|
|
1616
|
-
React
|
|
1616
|
+
React.useEffect(() => {
|
|
1617
1617
|
if (makeDefault) {
|
|
1618
1618
|
const old = get().controls;
|
|
1619
1619
|
set({ controls });
|
|
@@ -1631,7 +1631,7 @@ const FlyControls = /* @__PURE__ */ React$1.forwardRef(({ domElement, ...props }
|
|
|
1631
1631
|
|
|
1632
1632
|
//#endregion
|
|
1633
1633
|
//#region src/core/Controls/KeyboardControls/KeyboardControls.tsx
|
|
1634
|
-
const context$9 = /* @__PURE__ */ React
|
|
1634
|
+
const context$9 = /* @__PURE__ */ React.createContext(null);
|
|
1635
1635
|
/**
|
|
1636
1636
|
* A rudimentary keyboard controller which distributes your defined data-model
|
|
1637
1637
|
* to the `useKeyboardControls` hook. It's a rather simple way to get started with keyboard input.
|
|
@@ -1672,19 +1672,19 @@ const context$9 = /* @__PURE__ */ React$1.createContext(null);
|
|
|
1672
1672
|
*/
|
|
1673
1673
|
function KeyboardControls({ map, children, onChange, domElement }) {
|
|
1674
1674
|
const key = map.map((item) => item.name + item.keys).join("-");
|
|
1675
|
-
const useControls = React
|
|
1675
|
+
const useControls = React.useMemo(() => {
|
|
1676
1676
|
return create$1(subscribeWithSelector(() => map.reduce((prev, cur) => ({
|
|
1677
1677
|
...prev,
|
|
1678
1678
|
[cur.name]: false
|
|
1679
1679
|
}), {})));
|
|
1680
1680
|
}, [key]);
|
|
1681
|
-
const api = React
|
|
1681
|
+
const api = React.useMemo(() => [
|
|
1682
1682
|
useControls.subscribe,
|
|
1683
1683
|
useControls.getState,
|
|
1684
1684
|
useControls
|
|
1685
1685
|
], [key]);
|
|
1686
1686
|
const set = useControls.setState;
|
|
1687
|
-
React
|
|
1687
|
+
React.useEffect(() => {
|
|
1688
1688
|
const keyMap = map.map(({ name, keys, up }) => ({
|
|
1689
1689
|
keys,
|
|
1690
1690
|
up,
|
|
@@ -1728,7 +1728,7 @@ function KeyboardControls({ map, children, onChange, domElement }) {
|
|
|
1728
1728
|
});
|
|
1729
1729
|
}
|
|
1730
1730
|
function useKeyboardControls(sel) {
|
|
1731
|
-
const [sub, get, store] = React
|
|
1731
|
+
const [sub, get, store] = React.useContext(context$9);
|
|
1732
1732
|
if (sel) return store(sel);
|
|
1733
1733
|
else return [sub, get];
|
|
1734
1734
|
}
|
|
@@ -1744,7 +1744,7 @@ function useKeyboardControls(sel) {
|
|
|
1744
1744
|
* <MapControls enableDamping dampingFactor={0.05} />
|
|
1745
1745
|
* ```
|
|
1746
1746
|
*/
|
|
1747
|
-
const MapControls = /* @__PURE__ */ React
|
|
1747
|
+
const MapControls = /* @__PURE__ */ React.forwardRef((props = { enableDamping: true }, ref) => {
|
|
1748
1748
|
const { domElement, camera, makeDefault, onChange, onStart, onEnd, ...rest } = props;
|
|
1749
1749
|
const invalidate = useThree((state) => state.invalidate);
|
|
1750
1750
|
const defaultCamera = useThree((state) => state.camera);
|
|
@@ -1754,8 +1754,8 @@ const MapControls = /* @__PURE__ */ React$1.forwardRef((props = { enableDamping:
|
|
|
1754
1754
|
const get = useThree((state) => state.get);
|
|
1755
1755
|
const explDomElement = domElement || events.connected || gl.domElement;
|
|
1756
1756
|
const explCamera = camera || defaultCamera;
|
|
1757
|
-
const controls = React
|
|
1758
|
-
React
|
|
1757
|
+
const controls = React.useMemo(() => new MapControls$1(explCamera), [explCamera]);
|
|
1758
|
+
React.useEffect(() => {
|
|
1759
1759
|
controls.connect(explDomElement);
|
|
1760
1760
|
const callback = (e) => {
|
|
1761
1761
|
invalidate();
|
|
@@ -1778,7 +1778,7 @@ const MapControls = /* @__PURE__ */ React$1.forwardRef((props = { enableDamping:
|
|
|
1778
1778
|
invalidate,
|
|
1779
1779
|
explDomElement
|
|
1780
1780
|
]);
|
|
1781
|
-
React
|
|
1781
|
+
React.useEffect(() => {
|
|
1782
1782
|
if (makeDefault) {
|
|
1783
1783
|
const old = get().controls;
|
|
1784
1784
|
set({ controls });
|
|
@@ -1798,19 +1798,19 @@ const MapControls = /* @__PURE__ */ React$1.forwardRef((props = { enableDamping:
|
|
|
1798
1798
|
//#region src/core/Controls/MotionPathControls/MotionPathControls.tsx
|
|
1799
1799
|
var import_maath_cjs = require_maath_cjs();
|
|
1800
1800
|
const isObject3DRef = (ref) => ref?.current instanceof Object3D;
|
|
1801
|
-
const MotionContext = /* @__PURE__ */ React
|
|
1801
|
+
const MotionContext = /* @__PURE__ */ React.createContext(null);
|
|
1802
1802
|
function useMotion() {
|
|
1803
|
-
const context$10 = React
|
|
1803
|
+
const context$10 = React.useContext(MotionContext);
|
|
1804
1804
|
if (!context$10) throw new Error("useMotion hook must be used in a MotionPathControls component.");
|
|
1805
1805
|
return context$10;
|
|
1806
1806
|
}
|
|
1807
1807
|
function Debug({ points = 50, color = "black" }) {
|
|
1808
1808
|
const { path } = useMotion();
|
|
1809
|
-
const [dots, setDots] = React
|
|
1810
|
-
const material = React
|
|
1811
|
-
const geometry$1 = React
|
|
1812
|
-
const last = React
|
|
1813
|
-
React
|
|
1809
|
+
const [dots, setDots] = React.useState([]);
|
|
1810
|
+
const material = React.useMemo(() => new MeshBasicMaterial$1({ color }), [color]);
|
|
1811
|
+
const geometry$1 = React.useMemo(() => new SphereGeometry(.025, 16, 16), []);
|
|
1812
|
+
const last = React.useRef([]);
|
|
1813
|
+
React.useEffect(() => {
|
|
1814
1814
|
if (path.curves !== last.current) {
|
|
1815
1815
|
setDots(path.getPoints(points));
|
|
1816
1816
|
last.current = path.curves;
|
|
@@ -1853,12 +1853,12 @@ function Debug({ points = 50, color = "black" }) {
|
|
|
1853
1853
|
* }
|
|
1854
1854
|
* ```
|
|
1855
1855
|
*/
|
|
1856
|
-
const MotionPathControls = /* @__PURE__ */ React
|
|
1856
|
+
const MotionPathControls = /* @__PURE__ */ React.forwardRef(({ children, curves = [], debug = false, debugColor = "black", object, focus, loop = true, offset = void 0, smooth = false, eps: eps$1 = 1e-5, damping = .1, focusDamping = .1, maxSpeed = Infinity, ...props }, fref) => {
|
|
1857
1857
|
const { camera } = useThree();
|
|
1858
|
-
const ref = React
|
|
1859
|
-
const pos = React
|
|
1860
|
-
const path = React
|
|
1861
|
-
const state = React
|
|
1858
|
+
const ref = React.useRef(null);
|
|
1859
|
+
const pos = React.useRef(offset ?? 0);
|
|
1860
|
+
const path = React.useMemo(() => new CurvePath(), []);
|
|
1861
|
+
const state = React.useMemo(() => ({
|
|
1862
1862
|
focus,
|
|
1863
1863
|
object: object?.current instanceof Object3D ? object : { current: camera },
|
|
1864
1864
|
path,
|
|
@@ -1869,7 +1869,7 @@ const MotionPathControls = /* @__PURE__ */ React$1.forwardRef(({ children, curve
|
|
|
1869
1869
|
next: new Vector3$2()
|
|
1870
1870
|
}), [focus, object]);
|
|
1871
1871
|
const instanceRef = useInstanceHandle(ref);
|
|
1872
|
-
React
|
|
1872
|
+
React.useLayoutEffect(() => {
|
|
1873
1873
|
const instance = instanceRef.current;
|
|
1874
1874
|
path.curves = [];
|
|
1875
1875
|
const _curves = curves.length > 0 ? curves : instance.children.map((instance$1) => instance$1.object);
|
|
@@ -1880,11 +1880,11 @@ const MotionPathControls = /* @__PURE__ */ React$1.forwardRef(({ children, curve
|
|
|
1880
1880
|
}
|
|
1881
1881
|
path.updateArcLengths();
|
|
1882
1882
|
});
|
|
1883
|
-
React
|
|
1884
|
-
React
|
|
1883
|
+
React.useImperativeHandle(fref, () => Object.assign(ref.current, { motion: state }), [state]);
|
|
1884
|
+
React.useLayoutEffect(() => {
|
|
1885
1885
|
pos.current = import_maath_cjs.misc.repeat(pos.current, 1);
|
|
1886
1886
|
}, [offset]);
|
|
1887
|
-
const vec = React
|
|
1887
|
+
const vec = React.useMemo(() => new Vector3$2(), []);
|
|
1888
1888
|
useFrame((_state, delta) => {
|
|
1889
1889
|
const lastOffset = state.offset;
|
|
1890
1890
|
import_maath_cjs.easing.damp(pos, "current", offset !== void 0 ? offset : state.current, damping, delta, maxSpeed, void 0, eps$1);
|
|
@@ -1924,7 +1924,7 @@ const MotionPathControls = /* @__PURE__ */ React$1.forwardRef(({ children, curve
|
|
|
1924
1924
|
* <OrbitControls makeDefault enableDamping dampingFactor={0.05} />
|
|
1925
1925
|
* ```
|
|
1926
1926
|
*/
|
|
1927
|
-
const OrbitControls = /* @__PURE__ */ React
|
|
1927
|
+
const OrbitControls = /* @__PURE__ */ React.forwardRef(({ makeDefault, camera, regress, domElement, enableDamping = true, keyEvents = false, onChange, onStart, onEnd, ...restProps }, ref) => {
|
|
1928
1928
|
const invalidate = useThree((state) => state.invalidate);
|
|
1929
1929
|
const defaultCamera = useThree((state) => state.camera);
|
|
1930
1930
|
const gl = useThree((state) => state.gl);
|
|
@@ -1935,11 +1935,11 @@ const OrbitControls = /* @__PURE__ */ React$1.forwardRef(({ makeDefault, camera,
|
|
|
1935
1935
|
const performance$1 = useThree((state) => state.performance);
|
|
1936
1936
|
const explCamera = camera || defaultCamera;
|
|
1937
1937
|
const explDomElement = domElement || events.connected || gl.domElement;
|
|
1938
|
-
const controls = React
|
|
1938
|
+
const controls = React.useMemo(() => new OrbitControls$1(explCamera), [explCamera]);
|
|
1939
1939
|
useFrame(() => {
|
|
1940
1940
|
if (controls.enabled) controls.update();
|
|
1941
1941
|
}, -1);
|
|
1942
|
-
React
|
|
1942
|
+
React.useEffect(() => {
|
|
1943
1943
|
if (keyEvents) controls.connect(keyEvents === true ? explDomElement : keyEvents);
|
|
1944
1944
|
controls.connect(explDomElement);
|
|
1945
1945
|
return () => void controls.dispose();
|
|
@@ -1950,7 +1950,7 @@ const OrbitControls = /* @__PURE__ */ React$1.forwardRef(({ makeDefault, camera,
|
|
|
1950
1950
|
controls,
|
|
1951
1951
|
invalidate
|
|
1952
1952
|
]);
|
|
1953
|
-
React
|
|
1953
|
+
React.useEffect(() => {
|
|
1954
1954
|
const callback = (e) => {
|
|
1955
1955
|
invalidate();
|
|
1956
1956
|
if (regress) performance$1.regress();
|
|
@@ -1978,7 +1978,7 @@ const OrbitControls = /* @__PURE__ */ React$1.forwardRef(({ makeDefault, camera,
|
|
|
1978
1978
|
invalidate,
|
|
1979
1979
|
setEvents
|
|
1980
1980
|
]);
|
|
1981
|
-
React
|
|
1981
|
+
React.useEffect(() => {
|
|
1982
1982
|
if (makeDefault) {
|
|
1983
1983
|
const old = get().controls;
|
|
1984
1984
|
set({ controls });
|
|
@@ -2004,7 +2004,7 @@ const OrbitControls = /* @__PURE__ */ React$1.forwardRef(({ makeDefault, camera,
|
|
|
2004
2004
|
* <PointerLockControls selector="#button" />
|
|
2005
2005
|
* ```
|
|
2006
2006
|
*/
|
|
2007
|
-
const PointerLockControls = /* @__PURE__ */ React
|
|
2007
|
+
const PointerLockControls = /* @__PURE__ */ React.forwardRef(({ domElement, selector, onChange, onLock, onUnlock, enabled = true, makeDefault, ...props }, ref) => {
|
|
2008
2008
|
const { camera, ...rest } = props;
|
|
2009
2009
|
const setEvents = useThree((state) => state.setEvents);
|
|
2010
2010
|
const gl = useThree((state) => state.gl);
|
|
@@ -2015,8 +2015,8 @@ const PointerLockControls = /* @__PURE__ */ React$1.forwardRef(({ domElement, se
|
|
|
2015
2015
|
const set = useThree((state) => state.set);
|
|
2016
2016
|
const explCamera = camera || defaultCamera;
|
|
2017
2017
|
const explDomElement = domElement || events.connected || gl.domElement;
|
|
2018
|
-
const controls = React
|
|
2019
|
-
React
|
|
2018
|
+
const controls = React.useMemo(() => new PointerLockControls$1(explCamera), [explCamera]);
|
|
2019
|
+
React.useEffect(() => {
|
|
2020
2020
|
if (enabled) {
|
|
2021
2021
|
controls.connect(explDomElement);
|
|
2022
2022
|
const oldComputeOffsets = get().events.compute;
|
|
@@ -2032,7 +2032,7 @@ const PointerLockControls = /* @__PURE__ */ React$1.forwardRef(({ domElement, se
|
|
|
2032
2032
|
};
|
|
2033
2033
|
}
|
|
2034
2034
|
}, [enabled, controls]);
|
|
2035
|
-
React
|
|
2035
|
+
React.useEffect(() => {
|
|
2036
2036
|
const callback = (e) => {
|
|
2037
2037
|
invalidate();
|
|
2038
2038
|
if (onChange) onChange(e);
|
|
@@ -2057,7 +2057,7 @@ const PointerLockControls = /* @__PURE__ */ React$1.forwardRef(({ domElement, se
|
|
|
2057
2057
|
controls,
|
|
2058
2058
|
invalidate
|
|
2059
2059
|
]);
|
|
2060
|
-
React
|
|
2060
|
+
React.useEffect(() => {
|
|
2061
2061
|
if (makeDefault) {
|
|
2062
2062
|
const old = get().controls;
|
|
2063
2063
|
set({ controls });
|
|
@@ -2105,17 +2105,17 @@ function PresentationControls({ enabled = true, snap, global, domElement, cursor
|
|
|
2105
2105
|
const gl = useThree((state) => state.gl);
|
|
2106
2106
|
const explDomElement = domElement || events.connected || gl.domElement;
|
|
2107
2107
|
const { size } = useThree();
|
|
2108
|
-
const rPolar = React
|
|
2108
|
+
const rPolar = React.useMemo(() => [rotation$2[0] + polar[0], rotation$2[0] + polar[1]], [
|
|
2109
2109
|
rotation$2[0],
|
|
2110
2110
|
polar[0],
|
|
2111
2111
|
polar[1]
|
|
2112
2112
|
]);
|
|
2113
|
-
const rAzimuth = React
|
|
2113
|
+
const rAzimuth = React.useMemo(() => [rotation$2[1] + azimuth[0], rotation$2[1] + azimuth[1]], [
|
|
2114
2114
|
rotation$2[1],
|
|
2115
2115
|
azimuth[0],
|
|
2116
2116
|
azimuth[1]
|
|
2117
2117
|
]);
|
|
2118
|
-
const rInitial = React
|
|
2118
|
+
const rInitial = React.useMemo(() => [
|
|
2119
2119
|
MathUtils.clamp(rotation$2[0], ...rPolar),
|
|
2120
2120
|
MathUtils.clamp(rotation$2[1], ...rAzimuth),
|
|
2121
2121
|
rotation$2[2]
|
|
@@ -2126,7 +2126,7 @@ function PresentationControls({ enabled = true, snap, global, domElement, cursor
|
|
|
2126
2126
|
rPolar,
|
|
2127
2127
|
rAzimuth
|
|
2128
2128
|
]);
|
|
2129
|
-
React
|
|
2129
|
+
React.useEffect(() => {
|
|
2130
2130
|
if (global && cursor && enabled) {
|
|
2131
2131
|
explDomElement.style.cursor = "grab";
|
|
2132
2132
|
gl.domElement.style.cursor = "";
|
|
@@ -2141,12 +2141,12 @@ function PresentationControls({ enabled = true, snap, global, domElement, cursor
|
|
|
2141
2141
|
explDomElement,
|
|
2142
2142
|
enabled
|
|
2143
2143
|
]);
|
|
2144
|
-
const [animation] = React
|
|
2144
|
+
const [animation] = React.useState({
|
|
2145
2145
|
scale: 1,
|
|
2146
2146
|
rotation: rInitial,
|
|
2147
2147
|
damping
|
|
2148
2148
|
});
|
|
2149
|
-
const ref = React
|
|
2149
|
+
const ref = React.useRef(null);
|
|
2150
2150
|
useFrame((state, delta) => {
|
|
2151
2151
|
import_maath_cjs.easing.damp3(ref.current.scale, animation.scale, animation.damping, delta);
|
|
2152
2152
|
import_maath_cjs.easing.dampE(ref.current.rotation, animation.rotation, animation.damping, delta);
|
|
@@ -2178,12 +2178,12 @@ function PresentationControls({ enabled = true, snap, global, domElement, cursor
|
|
|
2178
2178
|
|
|
2179
2179
|
//#endregion
|
|
2180
2180
|
//#region src/core/Controls/ScrollControls/ScrollControls.tsx
|
|
2181
|
-
const context$8 = /* @__PURE__ */ React
|
|
2181
|
+
const context$8 = /* @__PURE__ */ React.createContext(null);
|
|
2182
2182
|
/**
|
|
2183
2183
|
* Hook to access scroll state: offset (0-1), delta, range(), curve(), visible().
|
|
2184
2184
|
*/
|
|
2185
2185
|
function useScroll() {
|
|
2186
|
-
return React
|
|
2186
|
+
return React.useContext(context$8);
|
|
2187
2187
|
}
|
|
2188
2188
|
/**
|
|
2189
2189
|
* Scroll controls create an HTML scroll container in front of the canvas.
|
|
@@ -2210,12 +2210,12 @@ function useScroll() {
|
|
|
2210
2210
|
*/
|
|
2211
2211
|
function ScrollControls({ eps: eps$1 = 1e-5, enabled = true, infinite, horizontal, pages = 1, distance = 1, damping = .25, maxSpeed = Infinity, prepend = false, style = {}, children }) {
|
|
2212
2212
|
const { get, setEvents, gl, size, invalidate, events } = useThree();
|
|
2213
|
-
const [el] = React
|
|
2214
|
-
const [fill] = React
|
|
2215
|
-
const [fixed] = React
|
|
2213
|
+
const [el] = React.useState(() => document.createElement("div"));
|
|
2214
|
+
const [fill] = React.useState(() => document.createElement("div"));
|
|
2215
|
+
const [fixed] = React.useState(() => document.createElement("div"));
|
|
2216
2216
|
const target$1 = gl.domElement.parentNode;
|
|
2217
|
-
const scroll = React
|
|
2218
|
-
const state = React
|
|
2217
|
+
const scroll = React.useRef(0);
|
|
2218
|
+
const state = React.useMemo(() => {
|
|
2219
2219
|
return {
|
|
2220
2220
|
el,
|
|
2221
2221
|
eps: eps$1,
|
|
@@ -2247,7 +2247,7 @@ function ScrollControls({ eps: eps$1 = 1e-5, enabled = true, infinite, horizonta
|
|
|
2247
2247
|
horizontal,
|
|
2248
2248
|
pages
|
|
2249
2249
|
]);
|
|
2250
|
-
React
|
|
2250
|
+
React.useEffect(() => {
|
|
2251
2251
|
el.style.position = "absolute";
|
|
2252
2252
|
el.style.width = "100%";
|
|
2253
2253
|
el.style.height = "100%";
|
|
@@ -2294,7 +2294,7 @@ function ScrollControls({ eps: eps$1 = 1e-5, enabled = true, infinite, horizonta
|
|
|
2294
2294
|
fixed,
|
|
2295
2295
|
target$1
|
|
2296
2296
|
]);
|
|
2297
|
-
React
|
|
2297
|
+
React.useEffect(() => {
|
|
2298
2298
|
if (events.connected === el) {
|
|
2299
2299
|
const containerLength = size[horizontal ? "width" : "height"];
|
|
2300
2300
|
const scrollLength = el[horizontal ? "scrollWidth" : "scrollHeight"];
|
|
@@ -2355,9 +2355,9 @@ function ScrollControls({ eps: eps$1 = 1e-5, enabled = true, infinite, horizonta
|
|
|
2355
2355
|
children
|
|
2356
2356
|
});
|
|
2357
2357
|
}
|
|
2358
|
-
const ScrollCanvas = /* @__PURE__ */ React
|
|
2359
|
-
const group = React
|
|
2360
|
-
React
|
|
2358
|
+
const ScrollCanvas = /* @__PURE__ */ React.forwardRef(({ children }, ref) => {
|
|
2359
|
+
const group = React.useRef(null);
|
|
2360
|
+
React.useImperativeHandle(ref, () => group.current, []);
|
|
2361
2361
|
const state = useScroll();
|
|
2362
2362
|
const { width, height } = useThree((state$1) => state$1.viewport);
|
|
2363
2363
|
useFrame(() => {
|
|
@@ -2369,13 +2369,13 @@ const ScrollCanvas = /* @__PURE__ */ React$1.forwardRef(({ children }, ref) => {
|
|
|
2369
2369
|
children
|
|
2370
2370
|
});
|
|
2371
2371
|
});
|
|
2372
|
-
const ScrollHtml = React
|
|
2372
|
+
const ScrollHtml = React.forwardRef(({ children, style, ...props }, ref) => {
|
|
2373
2373
|
const state = useScroll();
|
|
2374
|
-
const group = React
|
|
2375
|
-
React
|
|
2374
|
+
const group = React.useRef(null);
|
|
2375
|
+
React.useImperativeHandle(ref, () => group.current, []);
|
|
2376
2376
|
const { width, height } = useThree((state$1) => state$1.size);
|
|
2377
|
-
const fiberState = React
|
|
2378
|
-
const root = React
|
|
2377
|
+
const fiberState = React.useContext(context);
|
|
2378
|
+
const root = React.useMemo(() => ReactDOM.createRoot(state.fixed), [state.fixed]);
|
|
2379
2379
|
useFrame(() => {
|
|
2380
2380
|
if (state.delta > state.eps) group.current.style.transform = `translate3d(${state.horizontal ? -width * (state.pages - 1) * state.offset : 0}px,${state.horizontal ? 0 : height * (state.pages - 1) * -state.offset}px,0)`;
|
|
2381
2381
|
});
|
|
@@ -2399,7 +2399,7 @@ const ScrollHtml = React$1.forwardRef(({ children, style, ...props }, ref) => {
|
|
|
2399
2399
|
}));
|
|
2400
2400
|
return null;
|
|
2401
2401
|
});
|
|
2402
|
-
const Scroll = /* @__PURE__ */ React
|
|
2402
|
+
const Scroll = /* @__PURE__ */ React.forwardRef(({ html, ...props }, ref) => {
|
|
2403
2403
|
return /* @__PURE__ */ jsx(html ? ScrollHtml : ScrollCanvas, {
|
|
2404
2404
|
ref,
|
|
2405
2405
|
...props
|
|
@@ -2417,15 +2417,15 @@ const Scroll = /* @__PURE__ */ React$1.forwardRef(({ html, ...props }, ref) => {
|
|
|
2417
2417
|
* <TrackballControls />
|
|
2418
2418
|
* ```
|
|
2419
2419
|
*/
|
|
2420
|
-
const TrackballControls = /* @__PURE__ */ React
|
|
2420
|
+
const TrackballControls = /* @__PURE__ */ React.forwardRef(({ makeDefault, camera, domElement, regress, onChange, onStart, onEnd, ...restProps }, ref) => {
|
|
2421
2421
|
const { invalidate, camera: defaultCamera, gl, events, set, get, performance: performance$1, viewport } = useThree();
|
|
2422
2422
|
const explCamera = camera || defaultCamera;
|
|
2423
2423
|
const explDomElement = domElement || events.connected || gl.domElement;
|
|
2424
|
-
const controls = React
|
|
2424
|
+
const controls = React.useMemo(() => new TrackballControls$1(explCamera), [explCamera]);
|
|
2425
2425
|
useFrame(() => {
|
|
2426
2426
|
if (controls.enabled) controls.update();
|
|
2427
2427
|
}, -1);
|
|
2428
|
-
React
|
|
2428
|
+
React.useEffect(() => {
|
|
2429
2429
|
controls.connect(explDomElement);
|
|
2430
2430
|
return () => void controls.dispose();
|
|
2431
2431
|
}, [
|
|
@@ -2434,7 +2434,7 @@ const TrackballControls = /* @__PURE__ */ React$1.forwardRef(({ makeDefault, cam
|
|
|
2434
2434
|
controls,
|
|
2435
2435
|
invalidate
|
|
2436
2436
|
]);
|
|
2437
|
-
React
|
|
2437
|
+
React.useEffect(() => {
|
|
2438
2438
|
const callback = (e) => {
|
|
2439
2439
|
invalidate();
|
|
2440
2440
|
if (regress) performance$1.regress();
|
|
@@ -2455,10 +2455,10 @@ const TrackballControls = /* @__PURE__ */ React$1.forwardRef(({ makeDefault, cam
|
|
|
2455
2455
|
controls,
|
|
2456
2456
|
invalidate
|
|
2457
2457
|
]);
|
|
2458
|
-
React
|
|
2458
|
+
React.useEffect(() => {
|
|
2459
2459
|
controls.handleResize();
|
|
2460
2460
|
}, [viewport]);
|
|
2461
|
-
React
|
|
2461
|
+
React.useEffect(() => {
|
|
2462
2462
|
if (makeDefault) {
|
|
2463
2463
|
const old = get().controls;
|
|
2464
2464
|
set({ controls });
|
|
@@ -2493,25 +2493,25 @@ const TrackballControls = /* @__PURE__ */ React$1.forwardRef(({ makeDefault, cam
|
|
|
2493
2493
|
* <CameraShake ref={shakeRef} decay decayRate={0.65} intensity={0} />
|
|
2494
2494
|
* ```
|
|
2495
2495
|
*/
|
|
2496
|
-
const CameraShake = /* @__PURE__ */ React
|
|
2496
|
+
const CameraShake = /* @__PURE__ */ React.forwardRef(({ intensity = 1, decay, decayRate = .65, maxYaw = .1, maxPitch = .1, maxRoll = .1, yawFrequency = .1, pitchFrequency = .1, rollFrequency = .1 }, ref) => {
|
|
2497
2497
|
const camera = useThree((state) => state.camera);
|
|
2498
2498
|
const defaultControls = useThree((state) => state.controls);
|
|
2499
|
-
const intensityRef = React
|
|
2500
|
-
const initialRotation = React
|
|
2501
|
-
const [yawNoise] = React
|
|
2502
|
-
const [pitchNoise] = React
|
|
2503
|
-
const [rollNoise] = React
|
|
2499
|
+
const intensityRef = React.useRef(intensity);
|
|
2500
|
+
const initialRotation = React.useRef(camera.rotation.clone());
|
|
2501
|
+
const [yawNoise] = React.useState(() => new SimplexNoise());
|
|
2502
|
+
const [pitchNoise] = React.useState(() => new SimplexNoise());
|
|
2503
|
+
const [rollNoise] = React.useState(() => new SimplexNoise());
|
|
2504
2504
|
const constrainIntensity = () => {
|
|
2505
2505
|
if (intensityRef.current < 0 || intensityRef.current > 1) intensityRef.current = intensityRef.current < 0 ? 0 : 1;
|
|
2506
2506
|
};
|
|
2507
|
-
React
|
|
2507
|
+
React.useImperativeHandle(ref, () => ({
|
|
2508
2508
|
getIntensity: () => intensityRef.current,
|
|
2509
2509
|
setIntensity: (val) => {
|
|
2510
2510
|
intensityRef.current = val;
|
|
2511
2511
|
constrainIntensity();
|
|
2512
2512
|
}
|
|
2513
2513
|
}), []);
|
|
2514
|
-
React
|
|
2514
|
+
React.useEffect(() => {
|
|
2515
2515
|
if (defaultControls) {
|
|
2516
2516
|
const callback = () => void (initialRotation.current = camera.rotation.clone());
|
|
2517
2517
|
defaultControls.addEventListener("change", callback);
|
|
@@ -2600,7 +2600,7 @@ const rotation$1 = /* @__PURE__ */ new Quaternion();
|
|
|
2600
2600
|
const cpos = /* @__PURE__ */ new Vector3$2();
|
|
2601
2601
|
const cquat = /* @__PURE__ */ new Quaternion();
|
|
2602
2602
|
const scale$1 = /* @__PURE__ */ new Vector3$2();
|
|
2603
|
-
const context$7 = /* @__PURE__ */ React
|
|
2603
|
+
const context$7 = /* @__PURE__ */ React.createContext(null);
|
|
2604
2604
|
/**
|
|
2605
2605
|
* Provider component that groups all Cloud children into a single instanced draw call.
|
|
2606
2606
|
* Wrap your Cloud components with this for better performance.
|
|
@@ -2613,18 +2613,18 @@ const context$7 = /* @__PURE__ */ React$1.createContext(null);
|
|
|
2613
2613
|
* </Clouds>
|
|
2614
2614
|
* ```
|
|
2615
2615
|
*/
|
|
2616
|
-
const Clouds = /* @__PURE__ */ React
|
|
2617
|
-
const instance = React
|
|
2618
|
-
const clouds = React
|
|
2619
|
-
const opacities = React
|
|
2620
|
-
const colors$1 = React
|
|
2616
|
+
const Clouds = /* @__PURE__ */ React.forwardRef(({ children, material = MeshLambertMaterial, materialFactory, texture = CLOUD_URL, range, limit = 200, frustumCulled, ...props }, fref) => {
|
|
2617
|
+
const instance = React.useRef(null);
|
|
2618
|
+
const clouds = React.useRef([]);
|
|
2619
|
+
const opacities = React.useMemo(() => new Float32Array(Array.from({ length: limit }, () => 1)), [limit]);
|
|
2620
|
+
const colors$1 = React.useMemo(() => new Float32Array(Array.from({ length: limit }, () => [
|
|
2621
2621
|
1,
|
|
2622
2622
|
1,
|
|
2623
2623
|
1
|
|
2624
2624
|
]).flat()), [limit]);
|
|
2625
2625
|
const cloudTexture = useTexture(texture);
|
|
2626
2626
|
const MaterialFn = materialFactory ?? CloudMaterial;
|
|
2627
|
-
const cloudMaterial = React
|
|
2627
|
+
const cloudMaterial = React.useMemo(() => {
|
|
2628
2628
|
const cloudMat = MaterialFn(material);
|
|
2629
2629
|
cloudMat.map = cloudTexture;
|
|
2630
2630
|
cloudMat.transparent = true;
|
|
@@ -2665,7 +2665,7 @@ const Clouds = /* @__PURE__ */ React$1.forwardRef(({ children, material = MeshLa
|
|
|
2665
2665
|
instance.current.instanceMatrix.needsUpdate = true;
|
|
2666
2666
|
if (instance.current.instanceColor) instance.current.instanceColor.needsUpdate = true;
|
|
2667
2667
|
});
|
|
2668
|
-
React
|
|
2668
|
+
React.useLayoutEffect(() => {
|
|
2669
2669
|
const count = Math.min(limit, range !== void 0 ? range : limit, clouds.current.length);
|
|
2670
2670
|
instance.current.count = count;
|
|
2671
2671
|
setUpdateRange(instance.current.instanceMatrix, {
|
|
@@ -2716,7 +2716,7 @@ const Clouds = /* @__PURE__ */ React$1.forwardRef(({ children, material = MeshLa
|
|
|
2716
2716
|
})
|
|
2717
2717
|
});
|
|
2718
2718
|
});
|
|
2719
|
-
const CloudInstance = /* @__PURE__ */ React
|
|
2719
|
+
const CloudInstance = /* @__PURE__ */ React.forwardRef(({ opacity = 1, speed = 0, bounds = [
|
|
2720
2720
|
5,
|
|
2721
2721
|
1,
|
|
2722
2722
|
1
|
|
@@ -2725,10 +2725,10 @@ const CloudInstance = /* @__PURE__ */ React$1.forwardRef(({ opacity = 1, speed =
|
|
|
2725
2725
|
const x = Math.sin(seed++) * 1e4;
|
|
2726
2726
|
return x - Math.floor(x);
|
|
2727
2727
|
}
|
|
2728
|
-
const parent = React
|
|
2729
|
-
const ref = React
|
|
2730
|
-
const uuid = React
|
|
2731
|
-
const clouds = React
|
|
2728
|
+
const parent = React.useContext(context$7);
|
|
2729
|
+
const ref = React.useRef(null);
|
|
2730
|
+
const uuid = React.useId();
|
|
2731
|
+
const clouds = React.useMemo(() => {
|
|
2732
2732
|
return [...new Array(segments)].map((_, index) => ({
|
|
2733
2733
|
segments,
|
|
2734
2734
|
bounds: new Vector3$2(1, 1, 1),
|
|
@@ -2742,7 +2742,7 @@ const CloudInstance = /* @__PURE__ */ React$1.forwardRef(({ opacity = 1, speed =
|
|
|
2742
2742
|
rotation: index * (Math.PI / segments)
|
|
2743
2743
|
}));
|
|
2744
2744
|
}, [segments, uuid]);
|
|
2745
|
-
React
|
|
2745
|
+
React.useLayoutEffect(() => {
|
|
2746
2746
|
clouds.forEach((cloud, index) => {
|
|
2747
2747
|
applyProps(cloud, {
|
|
2748
2748
|
volume,
|
|
@@ -2783,14 +2783,14 @@ const CloudInstance = /* @__PURE__ */ React$1.forwardRef(({ opacity = 1, speed =
|
|
|
2783
2783
|
segments,
|
|
2784
2784
|
speed
|
|
2785
2785
|
]);
|
|
2786
|
-
React
|
|
2786
|
+
React.useLayoutEffect(() => {
|
|
2787
2787
|
const temp = clouds;
|
|
2788
2788
|
parent.current = [...parent.current, ...temp];
|
|
2789
2789
|
return () => {
|
|
2790
2790
|
parent.current = parent.current.filter((item) => item.uuid !== uuid);
|
|
2791
2791
|
};
|
|
2792
2792
|
}, [clouds]);
|
|
2793
|
-
React
|
|
2793
|
+
React.useImperativeHandle(fref, () => ref.current, []);
|
|
2794
2794
|
return /* @__PURE__ */ jsx("group", {
|
|
2795
2795
|
ref,
|
|
2796
2796
|
...props
|
|
@@ -2807,8 +2807,8 @@ const CloudInstance = /* @__PURE__ */ React$1.forwardRef(({ opacity = 1, speed =
|
|
|
2807
2807
|
* <Cloud segments={40} bounds={[10, 2, 2]} volume={10} color="white" />
|
|
2808
2808
|
* ```
|
|
2809
2809
|
*/
|
|
2810
|
-
const Cloud = /* @__PURE__ */ React
|
|
2811
|
-
if (React
|
|
2810
|
+
const Cloud = /* @__PURE__ */ React.forwardRef((props, fref) => {
|
|
2811
|
+
if (React.useContext(context$7)) return /* @__PURE__ */ jsx(CloudInstance, {
|
|
2812
2812
|
ref: fref,
|
|
2813
2813
|
...props
|
|
2814
2814
|
});
|
|
@@ -2835,9 +2835,9 @@ const Cloud = /* @__PURE__ */ React$1.forwardRef((props, fref) => {
|
|
|
2835
2835
|
* />
|
|
2836
2836
|
* ```
|
|
2837
2837
|
*/
|
|
2838
|
-
const CatmullRomLine = /* @__PURE__ */ React
|
|
2838
|
+
const CatmullRomLine = /* @__PURE__ */ React.forwardRef(function CatmullRomLine$1({ points, closed = false, curveType = "centripetal", tension = .5, segments = 20, vertexColors, LineComponent, ...rest }, ref) {
|
|
2839
2839
|
const LineComp = LineComponent ?? Line;
|
|
2840
|
-
const curve = React
|
|
2840
|
+
const curve = React.useMemo(() => {
|
|
2841
2841
|
return new CatmullRomCurve3(points.map((pt) => pt instanceof Vector3$2 ? pt : new Vector3$2(...pt)), closed, curveType, tension);
|
|
2842
2842
|
}, [
|
|
2843
2843
|
points,
|
|
@@ -2847,8 +2847,8 @@ const CatmullRomLine = /* @__PURE__ */ React$1.forwardRef(function CatmullRomLin
|
|
|
2847
2847
|
]);
|
|
2848
2848
|
return /* @__PURE__ */ jsx(LineComp, {
|
|
2849
2849
|
ref,
|
|
2850
|
-
points: React
|
|
2851
|
-
vertexColors: React
|
|
2850
|
+
points: React.useMemo(() => curve.getPoints(segments), [curve, segments]),
|
|
2851
|
+
vertexColors: React.useMemo(() => {
|
|
2852
2852
|
if (!vertexColors || vertexColors.length < 2) return void 0;
|
|
2853
2853
|
if (vertexColors.length === segments + 1) return vertexColors;
|
|
2854
2854
|
const mappedColors = vertexColors.map((color) => color instanceof Color$2 ? color : new Color$2(...color));
|
|
@@ -2883,10 +2883,10 @@ const CatmullRomLine = /* @__PURE__ */ React$1.forwardRef(function CatmullRomLin
|
|
|
2883
2883
|
* />
|
|
2884
2884
|
* ```
|
|
2885
2885
|
*/
|
|
2886
|
-
const CubicBezierLine = /* @__PURE__ */ React
|
|
2886
|
+
const CubicBezierLine = /* @__PURE__ */ React.forwardRef(function CubicBezierLine$1({ start, end, midA, midB, segments = 20, LineComponent, ...rest }, ref) {
|
|
2887
2887
|
return /* @__PURE__ */ jsx(LineComponent ?? Line, {
|
|
2888
2888
|
ref,
|
|
2889
|
-
points: React
|
|
2889
|
+
points: React.useMemo(() => {
|
|
2890
2890
|
const startV = start instanceof Vector3$2 ? start : new Vector3$2(...start);
|
|
2891
2891
|
const endV = end instanceof Vector3$2 ? end : new Vector3$2(...end);
|
|
2892
2892
|
return new CubicBezierCurve3(startV, midA instanceof Vector3$2 ? midA : new Vector3$2(...midA), midB instanceof Vector3$2 ? midB : new Vector3$2(...midB), endV).getPoints(segments);
|
|
@@ -2935,18 +2935,18 @@ const CubicBezierLine = /* @__PURE__ */ React$1.forwardRef(function CubicBezierL
|
|
|
2935
2935
|
* </CurveModifier>
|
|
2936
2936
|
* ```
|
|
2937
2937
|
*/
|
|
2938
|
-
const CurveModifier = /* @__PURE__ */ React
|
|
2939
|
-
const [scene] = React
|
|
2940
|
-
const [obj, set] = React
|
|
2941
|
-
const modifier = React
|
|
2942
|
-
React
|
|
2938
|
+
const CurveModifier = /* @__PURE__ */ React.forwardRef(({ children, curve }, ref) => {
|
|
2939
|
+
const [scene] = React.useState(() => new Scene$1());
|
|
2940
|
+
const [obj, set] = React.useState();
|
|
2941
|
+
const modifier = React.useRef(null);
|
|
2942
|
+
React.useLayoutEffect(() => {
|
|
2943
2943
|
modifier.current = new Flow(scene.children[0]);
|
|
2944
2944
|
set(modifier.current.object3D);
|
|
2945
2945
|
}, [children]);
|
|
2946
|
-
React
|
|
2946
|
+
React.useEffect(() => {
|
|
2947
2947
|
if (curve) modifier.current?.updateCurve(0, curve);
|
|
2948
2948
|
}, [curve]);
|
|
2949
|
-
React
|
|
2949
|
+
React.useImperativeHandle(ref, () => modifier.current);
|
|
2950
2950
|
return /* @__PURE__ */ jsxs(Fragment$1, { children: [createPortal(children, scene), obj && /* @__PURE__ */ jsx("primitive", { object: obj })] });
|
|
2951
2951
|
});
|
|
2952
2952
|
|
|
@@ -3007,16 +3007,16 @@ function vecToArray(vec = [
|
|
|
3007
3007
|
* </Decal>
|
|
3008
3008
|
* ```
|
|
3009
3009
|
*/
|
|
3010
|
-
const Decal = /* @__PURE__ */ React
|
|
3011
|
-
const ref = React
|
|
3012
|
-
React
|
|
3013
|
-
const helper = React
|
|
3014
|
-
const state = React
|
|
3010
|
+
const Decal = /* @__PURE__ */ React.forwardRef(function Decal$1({ debug, depthTest = false, polygonOffsetFactor = -10, map, mesh, children, position: position$1, rotation: rotation$2, scale: scale$2, ...props }, forwardRef$1) {
|
|
3011
|
+
const ref = React.useRef(null);
|
|
3012
|
+
React.useImperativeHandle(forwardRef$1, () => ref.current);
|
|
3013
|
+
const helper = React.useRef(null);
|
|
3014
|
+
const state = React.useRef({
|
|
3015
3015
|
position: new Vector3$2(),
|
|
3016
3016
|
rotation: new Euler$1(),
|
|
3017
3017
|
scale: new Vector3$2(1, 1, 1)
|
|
3018
3018
|
});
|
|
3019
|
-
React
|
|
3019
|
+
React.useLayoutEffect(() => {
|
|
3020
3020
|
const parent = mesh?.current || ref.current.parent;
|
|
3021
3021
|
const target$1 = ref.current;
|
|
3022
3022
|
if (!(parent instanceof Mesh$1)) throw new Error("Decal must have a Mesh as parent or specify its \"mesh\" prop");
|
|
@@ -3073,7 +3073,7 @@ const Decal = /* @__PURE__ */ React$1.forwardRef(function Decal$1({ debug, depth
|
|
|
3073
3073
|
...vecToArray(scale$2),
|
|
3074
3074
|
...vecToArray(rotation$2)
|
|
3075
3075
|
]);
|
|
3076
|
-
React
|
|
3076
|
+
React.useLayoutEffect(() => {
|
|
3077
3077
|
if (helper.current) helper.current.traverse((child) => child.raycast = () => null);
|
|
3078
3078
|
}, [debug]);
|
|
3079
3079
|
return /* @__PURE__ */ jsxs("mesh", {
|
|
@@ -3110,10 +3110,10 @@ const Decal = /* @__PURE__ */ React$1.forwardRef(function Decal$1({ debug, depth
|
|
|
3110
3110
|
* </Detailed>
|
|
3111
3111
|
* ```
|
|
3112
3112
|
*/
|
|
3113
|
-
const Detailed = /* @__PURE__ */ React
|
|
3114
|
-
const lodRef = React
|
|
3115
|
-
React
|
|
3116
|
-
React
|
|
3113
|
+
const Detailed = /* @__PURE__ */ React.forwardRef(({ children, hysteresis = 0, distances, ...props }, ref) => {
|
|
3114
|
+
const lodRef = React.useRef(null);
|
|
3115
|
+
React.useImperativeHandle(ref, () => lodRef.current, []);
|
|
3116
|
+
React.useLayoutEffect(() => {
|
|
3117
3117
|
const { current: lod } = lodRef;
|
|
3118
3118
|
lod.levels.length = 0;
|
|
3119
3119
|
lod.children.forEach((object, index) => lod.levels.push({
|
|
@@ -3183,22 +3183,22 @@ var PositionPoint = class extends Group {
|
|
|
3183
3183
|
}
|
|
3184
3184
|
};
|
|
3185
3185
|
let i, positionRef;
|
|
3186
|
-
const context$6 = /* @__PURE__ */ React
|
|
3186
|
+
const context$6 = /* @__PURE__ */ React.createContext(null);
|
|
3187
3187
|
const parentMatrix$1 = /* @__PURE__ */ new Matrix4();
|
|
3188
3188
|
const position = /* @__PURE__ */ new Vector3$2();
|
|
3189
3189
|
/**
|
|
3190
3190
|
* Instance implementation, relies on react + context to update the attributes based on the children of this component
|
|
3191
3191
|
*/
|
|
3192
|
-
const PointsInstances = /* @__PURE__ */ React
|
|
3193
|
-
const parentRef = React
|
|
3194
|
-
React
|
|
3195
|
-
const [refs, setRefs] = React
|
|
3196
|
-
const [[positions, colors$1, sizes]] = React
|
|
3192
|
+
const PointsInstances = /* @__PURE__ */ React.forwardRef(({ children, range, limit = 1e3, ...props }, ref) => {
|
|
3193
|
+
const parentRef = React.useRef(null);
|
|
3194
|
+
React.useImperativeHandle(ref, () => parentRef.current, []);
|
|
3195
|
+
const [refs, setRefs] = React.useState([]);
|
|
3196
|
+
const [[positions, colors$1, sizes]] = React.useState(() => [
|
|
3197
3197
|
new Float32Array(limit * 3),
|
|
3198
3198
|
Float32Array.from({ length: limit * 3 }, () => 1),
|
|
3199
3199
|
Float32Array.from({ length: limit }, () => 1)
|
|
3200
3200
|
]);
|
|
3201
|
-
React
|
|
3201
|
+
React.useEffect(() => {
|
|
3202
3202
|
parentRef.current.geometry.attributes.position.needsUpdate = true;
|
|
3203
3203
|
});
|
|
3204
3204
|
useFrame(() => {
|
|
@@ -3218,7 +3218,7 @@ const PointsInstances = /* @__PURE__ */ React$1.forwardRef(({ children, range, l
|
|
|
3218
3218
|
parentRef.current.geometry.attributes.size.needsUpdate = true;
|
|
3219
3219
|
}
|
|
3220
3220
|
});
|
|
3221
|
-
const api = React
|
|
3221
|
+
const api = React.useMemo(() => ({
|
|
3222
3222
|
getParent: () => parentRef,
|
|
3223
3223
|
subscribe: (ref$1) => {
|
|
3224
3224
|
setRefs((refs$1) => [...refs$1, ref$1]);
|
|
@@ -3264,12 +3264,12 @@ const PointsInstances = /* @__PURE__ */ React$1.forwardRef(({ children, range, l
|
|
|
3264
3264
|
* </Points>
|
|
3265
3265
|
* ```
|
|
3266
3266
|
*/
|
|
3267
|
-
const Point = /* @__PURE__ */ React
|
|
3268
|
-
React
|
|
3269
|
-
const group = React
|
|
3270
|
-
React
|
|
3271
|
-
const { subscribe, getParent } = React
|
|
3272
|
-
React
|
|
3267
|
+
const Point = /* @__PURE__ */ React.forwardRef(({ children, ...props }, ref) => {
|
|
3268
|
+
React.useMemo(() => extend({ PositionPoint }), []);
|
|
3269
|
+
const group = React.useRef(null);
|
|
3270
|
+
React.useImperativeHandle(ref, () => group.current, []);
|
|
3271
|
+
const { subscribe, getParent } = React.useContext(context$6);
|
|
3272
|
+
React.useLayoutEffect(() => subscribe(group), []);
|
|
3273
3273
|
return /* @__PURE__ */ jsx("positionPoint", {
|
|
3274
3274
|
instance: getParent(),
|
|
3275
3275
|
instanceKey: group,
|
|
@@ -3278,9 +3278,9 @@ const Point = /* @__PURE__ */ React$1.forwardRef(({ children, ...props }, ref) =
|
|
|
3278
3278
|
children
|
|
3279
3279
|
});
|
|
3280
3280
|
});
|
|
3281
|
-
const PointsBuffer = /* @__PURE__ */ React
|
|
3282
|
-
const pointsRef = React
|
|
3283
|
-
React
|
|
3281
|
+
const PointsBuffer = /* @__PURE__ */ React.forwardRef(({ children, positions, colors: colors$1, sizes, stride = 3, ...props }, forwardedRef) => {
|
|
3282
|
+
const pointsRef = React.useRef(null);
|
|
3283
|
+
React.useImperativeHandle(forwardedRef, () => pointsRef.current, []);
|
|
3284
3284
|
useFrame(() => {
|
|
3285
3285
|
const attr = pointsRef.current.geometry.attributes;
|
|
3286
3286
|
attr.position.needsUpdate = true;
|
|
@@ -3327,7 +3327,7 @@ const PointsBuffer = /* @__PURE__ */ React$1.forwardRef(({ children, positions,
|
|
|
3327
3327
|
* </Points>
|
|
3328
3328
|
* ```
|
|
3329
3329
|
*/
|
|
3330
|
-
const Points = /* @__PURE__ */ React
|
|
3330
|
+
const Points = /* @__PURE__ */ React.forwardRef((props, forwardedRef) => {
|
|
3331
3331
|
if (props.positions instanceof Float32Array) return /* @__PURE__ */ jsx(PointsBuffer, {
|
|
3332
3332
|
...props,
|
|
3333
3333
|
ref: forwardedRef
|
|
@@ -3354,7 +3354,7 @@ const v = /* @__PURE__ */ new Vector3$2();
|
|
|
3354
3354
|
* />
|
|
3355
3355
|
* ```
|
|
3356
3356
|
*/
|
|
3357
|
-
const QuadraticBezierLine = /* @__PURE__ */ React
|
|
3357
|
+
const QuadraticBezierLine = /* @__PURE__ */ React.forwardRef(function QuadraticBezierLine$1({ start = [
|
|
3358
3358
|
0,
|
|
3359
3359
|
0,
|
|
3360
3360
|
0
|
|
@@ -3364,10 +3364,10 @@ const QuadraticBezierLine = /* @__PURE__ */ React$1.forwardRef(function Quadrati
|
|
|
3364
3364
|
0
|
|
3365
3365
|
], mid, segments = 20, LineComponent, ...rest }, forwardref) {
|
|
3366
3366
|
const LineComp = LineComponent ?? Line;
|
|
3367
|
-
const ref = React
|
|
3368
|
-
React
|
|
3369
|
-
const [curve] = React
|
|
3370
|
-
const getPoints = React
|
|
3367
|
+
const ref = React.useRef(null);
|
|
3368
|
+
React.useImperativeHandle(forwardref, () => ref.current);
|
|
3369
|
+
const [curve] = React.useState(() => new QuadraticBezierCurve3(void 0, void 0, void 0));
|
|
3370
|
+
const getPoints = React.useCallback((start$1, end$1, mid$1, segments$1 = 20) => {
|
|
3371
3371
|
if (start$1 instanceof Vector3$2) curve.v0.copy(start$1);
|
|
3372
3372
|
else curve.v0.set(...start$1);
|
|
3373
3373
|
if (end$1 instanceof Vector3$2) curve.v2.copy(end$1);
|
|
@@ -3377,7 +3377,7 @@ const QuadraticBezierLine = /* @__PURE__ */ React$1.forwardRef(function Quadrati
|
|
|
3377
3377
|
else curve.v1.copy(curve.v0.clone().add(curve.v2.clone().sub(curve.v0)).add(v.set(0, curve.v0.y - curve.v2.y, 0)));
|
|
3378
3378
|
return curve.getPoints(segments$1);
|
|
3379
3379
|
}, []);
|
|
3380
|
-
React
|
|
3380
|
+
React.useLayoutEffect(() => {
|
|
3381
3381
|
ref.current.setPoints = (start$1, end$1, mid$1) => {
|
|
3382
3382
|
const points = getPoints(start$1, end$1, mid$1);
|
|
3383
3383
|
if (ref.current.geometry) ref.current.geometry.setPositions(points.map((p) => p.toArray()).flat());
|
|
@@ -3385,7 +3385,7 @@ const QuadraticBezierLine = /* @__PURE__ */ React$1.forwardRef(function Quadrati
|
|
|
3385
3385
|
}, []);
|
|
3386
3386
|
return /* @__PURE__ */ jsx(LineComp, {
|
|
3387
3387
|
ref,
|
|
3388
|
-
points: React
|
|
3388
|
+
points: React.useMemo(() => getPoints(start, end, mid, segments), [
|
|
3389
3389
|
start,
|
|
3390
3390
|
end,
|
|
3391
3391
|
mid,
|
|
@@ -3429,7 +3429,7 @@ function createShape(width, height, radius0) {
|
|
|
3429
3429
|
* </RoundedBox>
|
|
3430
3430
|
* ```
|
|
3431
3431
|
*/
|
|
3432
|
-
const RoundedBox = /* @__PURE__ */ React
|
|
3432
|
+
const RoundedBox = /* @__PURE__ */ React.forwardRef(function RoundedBox$1({ args: [width = 1, height = 1, depth = 1] = [], radius = .05, steps = 1, smoothness = 4, bevelSegments = 4, creaseAngle = .4, children, ...rest }, ref) {
|
|
3433
3433
|
return /* @__PURE__ */ jsxs("mesh", {
|
|
3434
3434
|
ref,
|
|
3435
3435
|
...rest,
|
|
@@ -3447,13 +3447,13 @@ const RoundedBox = /* @__PURE__ */ React$1.forwardRef(function RoundedBox$1({ ar
|
|
|
3447
3447
|
}), children]
|
|
3448
3448
|
});
|
|
3449
3449
|
});
|
|
3450
|
-
const RoundedBoxGeometry = /* @__PURE__ */ React
|
|
3451
|
-
const shape = React
|
|
3450
|
+
const RoundedBoxGeometry = /* @__PURE__ */ React.forwardRef(function RoundedBoxGeometry$1({ args: [width = 1, height = 1, depth = 1] = [], radius = .05, steps = 1, smoothness = 4, bevelSegments = 4, creaseAngle = .4, ...rest }, ref) {
|
|
3451
|
+
const shape = React.useMemo(() => createShape(width, height, radius), [
|
|
3452
3452
|
width,
|
|
3453
3453
|
height,
|
|
3454
3454
|
radius
|
|
3455
3455
|
]);
|
|
3456
|
-
const params = React
|
|
3456
|
+
const params = React.useMemo(() => ({
|
|
3457
3457
|
depth: depth - radius * 2,
|
|
3458
3458
|
bevelEnabled: true,
|
|
3459
3459
|
bevelSegments: bevelSegments * 2,
|
|
@@ -3468,8 +3468,8 @@ const RoundedBoxGeometry = /* @__PURE__ */ React$1.forwardRef(function RoundedBo
|
|
|
3468
3468
|
bevelSegments,
|
|
3469
3469
|
steps
|
|
3470
3470
|
]);
|
|
3471
|
-
const geomRef = React
|
|
3472
|
-
React
|
|
3471
|
+
const geomRef = React.useRef(null);
|
|
3472
|
+
React.useLayoutEffect(() => {
|
|
3473
3473
|
if (geomRef.current) {
|
|
3474
3474
|
geomRef.current.center();
|
|
3475
3475
|
toCreasedNormals(geomRef.current, creaseAngle);
|
|
@@ -3479,7 +3479,7 @@ const RoundedBoxGeometry = /* @__PURE__ */ React$1.forwardRef(function RoundedBo
|
|
|
3479
3479
|
params,
|
|
3480
3480
|
creaseAngle
|
|
3481
3481
|
]);
|
|
3482
|
-
React
|
|
3482
|
+
React.useImperativeHandle(ref, () => geomRef.current);
|
|
3483
3483
|
return /* @__PURE__ */ jsx("extrudeGeometry", {
|
|
3484
3484
|
ref: geomRef,
|
|
3485
3485
|
args: [shape, params],
|
|
@@ -3514,10 +3514,10 @@ function createScreenQuadGeometry() {
|
|
|
3514
3514
|
* </ScreenQuad>
|
|
3515
3515
|
* ```
|
|
3516
3516
|
*/
|
|
3517
|
-
const ScreenQuad = /* @__PURE__ */ React
|
|
3517
|
+
const ScreenQuad = /* @__PURE__ */ React.forwardRef(function ScreenQuad$1({ children, ...restProps }, ref) {
|
|
3518
3518
|
return /* @__PURE__ */ jsx("mesh", {
|
|
3519
3519
|
ref,
|
|
3520
|
-
geometry: React
|
|
3520
|
+
geometry: React.useMemo(createScreenQuadGeometry, []),
|
|
3521
3521
|
frustumCulled: false,
|
|
3522
3522
|
...restProps,
|
|
3523
3523
|
children
|
|
@@ -3538,10 +3538,10 @@ const ScreenQuad = /* @__PURE__ */ React$1.forwardRef(function ScreenQuad$1({ ch
|
|
|
3538
3538
|
*/
|
|
3539
3539
|
function create(type, effect) {
|
|
3540
3540
|
const El = type + "Geometry";
|
|
3541
|
-
return React
|
|
3542
|
-
const ref = React
|
|
3543
|
-
React
|
|
3544
|
-
React
|
|
3541
|
+
return React.forwardRef(({ args, children, ...props }, fref) => {
|
|
3542
|
+
const ref = React.useRef(null);
|
|
3543
|
+
React.useImperativeHandle(fref, () => ref.current);
|
|
3544
|
+
React.useLayoutEffect(() => void effect?.(ref.current));
|
|
3545
3545
|
return /* @__PURE__ */ jsxs("mesh", {
|
|
3546
3546
|
ref,
|
|
3547
3547
|
...props,
|
|
@@ -3621,7 +3621,7 @@ const types = ["string", "number"];
|
|
|
3621
3621
|
const getTextFromChildren = (children) => {
|
|
3622
3622
|
let label = "";
|
|
3623
3623
|
const rest = [];
|
|
3624
|
-
React
|
|
3624
|
+
React.Children.forEach(children, (child) => {
|
|
3625
3625
|
if (types.includes(typeof child)) label += child + "";
|
|
3626
3626
|
else rest.push(child);
|
|
3627
3627
|
});
|
|
@@ -3660,9 +3660,9 @@ const getTextFromChildren = (children) => {
|
|
|
3660
3660
|
* <Text3D smooth={1} lineHeight={0.5} letterSpacing={-0.025}>{`hello\nworld`}</Text3D>
|
|
3661
3661
|
* ```
|
|
3662
3662
|
*/
|
|
3663
|
-
const Text3D = /* @__PURE__ */ React
|
|
3664
|
-
React
|
|
3665
|
-
const ref = React
|
|
3663
|
+
const Text3D = /* @__PURE__ */ React.forwardRef(({ font: _font, letterSpacing = 0, lineHeight = 1, size = 1, height = .2, bevelThickness = .1, bevelSize = .01, bevelEnabled = false, bevelOffset = 0, bevelSegments = 4, curveSegments = 8, smooth, children, ...props }, fref) => {
|
|
3664
|
+
React.useMemo(() => extend({ RenamedTextGeometry: TextGeometry }), []);
|
|
3665
|
+
const ref = React.useRef(null);
|
|
3666
3666
|
const font = useFont(_font);
|
|
3667
3667
|
const opts = useMemo(() => {
|
|
3668
3668
|
return {
|
|
@@ -3696,14 +3696,14 @@ const Text3D = /* @__PURE__ */ React$1.forwardRef(({ font: _font, letterSpacing
|
|
|
3696
3696
|
* need to be able to do `<Text3d>{state}</Text3d>`.
|
|
3697
3697
|
*/
|
|
3698
3698
|
const [label, ...rest] = useMemo(() => getTextFromChildren(children), [children]);
|
|
3699
|
-
const args = React
|
|
3700
|
-
React
|
|
3699
|
+
const args = React.useMemo(() => [label, opts], [label, opts]);
|
|
3700
|
+
React.useLayoutEffect(() => {
|
|
3701
3701
|
if (smooth) {
|
|
3702
3702
|
ref.current.geometry = mergeVertices(ref.current.geometry, smooth);
|
|
3703
3703
|
ref.current.geometry.computeVertexNormals();
|
|
3704
3704
|
}
|
|
3705
3705
|
}, [args, smooth]);
|
|
3706
|
-
React
|
|
3706
|
+
React.useImperativeHandle(fref, () => ref.current, []);
|
|
3707
3707
|
return /* @__PURE__ */ jsxs("mesh", {
|
|
3708
3708
|
...props,
|
|
3709
3709
|
ref,
|
|
@@ -3884,21 +3884,21 @@ function setWireframeOverride(material, uniforms) {
|
|
|
3884
3884
|
material.transparent = true;
|
|
3885
3885
|
}
|
|
3886
3886
|
function useWireframeUniforms(uniforms, props) {
|
|
3887
|
-
React
|
|
3888
|
-
React
|
|
3889
|
-
React
|
|
3890
|
-
React
|
|
3891
|
-
React
|
|
3892
|
-
React
|
|
3893
|
-
React
|
|
3894
|
-
React
|
|
3895
|
-
React
|
|
3896
|
-
React
|
|
3897
|
-
React
|
|
3898
|
-
React
|
|
3899
|
-
React
|
|
3900
|
-
React
|
|
3901
|
-
React
|
|
3887
|
+
React.useEffect(() => void (uniforms.fillOpacity.value = props.fillOpacity ?? uniforms.fillOpacity.value), [props.fillOpacity]);
|
|
3888
|
+
React.useEffect(() => void (uniforms.fillMix.value = props.fillMix ?? uniforms.fillMix.value), [props.fillMix]);
|
|
3889
|
+
React.useEffect(() => void (uniforms.strokeOpacity.value = props.strokeOpacity ?? uniforms.strokeOpacity.value), [props.strokeOpacity]);
|
|
3890
|
+
React.useEffect(() => void (uniforms.thickness.value = props.thickness ?? uniforms.thickness.value), [props.thickness]);
|
|
3891
|
+
React.useEffect(() => void (uniforms.colorBackfaces.value = !!props.colorBackfaces), [props.colorBackfaces]);
|
|
3892
|
+
React.useEffect(() => void (uniforms.dash.value = !!props.dash), [props.dash]);
|
|
3893
|
+
React.useEffect(() => void (uniforms.dashInvert.value = !!props.dashInvert), [props.dashInvert]);
|
|
3894
|
+
React.useEffect(() => void (uniforms.dashRepeats.value = props.dashRepeats ?? uniforms.dashRepeats.value), [props.dashRepeats]);
|
|
3895
|
+
React.useEffect(() => void (uniforms.dashLength.value = props.dashLength ?? uniforms.dashLength.value), [props.dashLength]);
|
|
3896
|
+
React.useEffect(() => void (uniforms.squeeze.value = !!props.squeeze), [props.squeeze]);
|
|
3897
|
+
React.useEffect(() => void (uniforms.squeezeMin.value = props.squeezeMin ?? uniforms.squeezeMin.value), [props.squeezeMin]);
|
|
3898
|
+
React.useEffect(() => void (uniforms.squeezeMax.value = props.squeezeMax ?? uniforms.squeezeMax.value), [props.squeezeMax]);
|
|
3899
|
+
React.useEffect(() => void (uniforms.stroke.value = props.stroke ? new Color$2(props.stroke) : uniforms.stroke.value), [props.stroke]);
|
|
3900
|
+
React.useEffect(() => void (uniforms.fill.value = props.fill ? new Color$2(props.fill) : uniforms.fill.value), [props.fill]);
|
|
3901
|
+
React.useEffect(() => void (uniforms.backfaceStroke.value = props.backfaceStroke ? new Color$2(props.backfaceStroke) : uniforms.backfaceStroke.value), [props.backfaceStroke]);
|
|
3902
3902
|
}
|
|
3903
3903
|
|
|
3904
3904
|
//#endregion
|
|
@@ -3957,8 +3957,8 @@ function setBarycentricCoordinates(geometry$1, simplify) {
|
|
|
3957
3957
|
}
|
|
3958
3958
|
function WireframeWithCustomGeo({ geometry: customGeometry, simplify = false, ...props }) {
|
|
3959
3959
|
extend({ MeshWireframeMaterial: WireframeMaterial });
|
|
3960
|
-
const [geometry$1, setGeometry] = React
|
|
3961
|
-
React
|
|
3960
|
+
const [geometry$1, setGeometry] = React.useState(null);
|
|
3961
|
+
React.useLayoutEffect(() => {
|
|
3962
3962
|
const geom = getInputGeometry(customGeometry);
|
|
3963
3963
|
if (!geom) throw new Error("Wireframe: geometry prop must be a BufferGeometry or a ref to a BufferGeometry.");
|
|
3964
3964
|
setBarycentricCoordinates(geom, simplify);
|
|
@@ -3978,10 +3978,10 @@ function WireframeWithCustomGeo({ geometry: customGeometry, simplify = false, ..
|
|
|
3978
3978
|
}) });
|
|
3979
3979
|
}
|
|
3980
3980
|
function WireframeWithoutCustomGeo({ simplify = false, ...props }) {
|
|
3981
|
-
const objectRef = React
|
|
3982
|
-
const uniforms = React
|
|
3981
|
+
const objectRef = React.useRef(null);
|
|
3982
|
+
const uniforms = React.useMemo(() => getUniforms(), [WireframeMaterialShaders.uniforms]);
|
|
3983
3983
|
useWireframeUniforms(uniforms, props);
|
|
3984
|
-
React
|
|
3984
|
+
React.useLayoutEffect(() => {
|
|
3985
3985
|
const geom = getInputGeometry(objectRef);
|
|
3986
3986
|
if (!geom) throw new Error("Wireframe: Must be a child of a Mesh, Line or Points object or specify a geometry prop.");
|
|
3987
3987
|
const og = geom.clone();
|
|
@@ -3991,7 +3991,7 @@ function WireframeWithoutCustomGeo({ simplify = false, ...props }) {
|
|
|
3991
3991
|
og.dispose();
|
|
3992
3992
|
};
|
|
3993
3993
|
}, [simplify]);
|
|
3994
|
-
React
|
|
3994
|
+
React.useLayoutEffect(() => {
|
|
3995
3995
|
const parentMesh = objectRef.current.parent;
|
|
3996
3996
|
const og = parentMesh.material.clone();
|
|
3997
3997
|
setWireframeOverride(parentMesh.material, uniforms);
|
|
@@ -4024,13 +4024,13 @@ function Wireframe({ geometry: customGeometry, ...props }) {
|
|
|
4024
4024
|
|
|
4025
4025
|
//#endregion
|
|
4026
4026
|
//#region src/core/Gizmos/gizmo/GizmoHelper.tsx
|
|
4027
|
-
const Context = /* @__PURE__ */ React
|
|
4027
|
+
const Context = /* @__PURE__ */ React.createContext({});
|
|
4028
4028
|
/**
|
|
4029
4029
|
* Hook to access the GizmoHelper context for creating custom gizmos.
|
|
4030
4030
|
* Provides `tweenCamera(direction)` to animate camera rotation.
|
|
4031
4031
|
*/
|
|
4032
4032
|
const useGizmoContext = () => {
|
|
4033
|
-
return React
|
|
4033
|
+
return React.useContext(Context);
|
|
4034
4034
|
};
|
|
4035
4035
|
const turnRate = 2 * Math.PI;
|
|
4036
4036
|
const dummy = /* @__PURE__ */ new Object3D();
|
|
@@ -4061,17 +4061,17 @@ const GizmoHelper = ({ alignment = "bottom-right", margin = [80, 80], renderPrio
|
|
|
4061
4061
|
const mainCamera = useThree((state) => state.camera);
|
|
4062
4062
|
const defaultControls = useThree((state) => state.controls);
|
|
4063
4063
|
const invalidate = useThree((state) => state.invalidate);
|
|
4064
|
-
const gizmoRef = React
|
|
4065
|
-
const virtualCam = React
|
|
4066
|
-
const animating = React
|
|
4067
|
-
const radius = React
|
|
4068
|
-
const focusPoint = React
|
|
4069
|
-
const defaultUp = React
|
|
4070
|
-
React
|
|
4064
|
+
const gizmoRef = React.useRef(null);
|
|
4065
|
+
const virtualCam = React.useRef(null);
|
|
4066
|
+
const animating = React.useRef(false);
|
|
4067
|
+
const radius = React.useRef(0);
|
|
4068
|
+
const focusPoint = React.useRef(new Vector3$2(0, 0, 0));
|
|
4069
|
+
const defaultUp = React.useRef(new Vector3$2(0, 0, 0));
|
|
4070
|
+
React.useEffect(() => {
|
|
4071
4071
|
defaultUp.current.copy(mainCamera.up);
|
|
4072
4072
|
dummy.up.copy(mainCamera.up);
|
|
4073
4073
|
}, [mainCamera]);
|
|
4074
|
-
const tweenCamera = React
|
|
4074
|
+
const tweenCamera = React.useCallback((direction) => {
|
|
4075
4075
|
animating.current = true;
|
|
4076
4076
|
if (defaultControls || onTarget) focusPoint.current = onTarget?.() || (isCameraControls(defaultControls) ? defaultControls.getTarget(focusPoint.current) : defaultControls?.target);
|
|
4077
4077
|
radius.current = mainCamera.position.distanceTo(target);
|
|
@@ -4106,7 +4106,7 @@ const GizmoHelper = ({ alignment = "bottom-right", margin = [80, 80], renderPrio
|
|
|
4106
4106
|
gizmoRef.current?.quaternion.setFromRotationMatrix(matrix);
|
|
4107
4107
|
}
|
|
4108
4108
|
});
|
|
4109
|
-
const gizmoHelperContext = React
|
|
4109
|
+
const gizmoHelperContext = React.useMemo(() => ({ tweenCamera }), [tweenCamera]);
|
|
4110
4110
|
const [marginX, marginY] = margin;
|
|
4111
4111
|
const x = alignment.endsWith("-center") ? 0 : alignment.endsWith("-left") ? -size.width / 2 + marginX : size.width / 2 - marginX;
|
|
4112
4112
|
const y = alignment.startsWith("center-") ? 0 : alignment.startsWith("top-") ? size.height / 2 - marginY : -size.height / 2 + marginY;
|
|
@@ -4265,7 +4265,7 @@ const edgeDimensions = /* @__PURE__ */ edges.map((edge) => edge.toArray().map((a
|
|
|
4265
4265
|
const FaceMaterial = ({ hover, index, font = "20px Inter var, Arial, sans-serif", faces = defaultFaces, color = colors.bg, hoverColor = colors.hover, textColor = colors.text, strokeColor = colors.stroke, opacity = 1 }) => {
|
|
4266
4266
|
const renderer = useThree((state) => state.renderer);
|
|
4267
4267
|
return /* @__PURE__ */ jsx("meshBasicMaterial", {
|
|
4268
|
-
map: React
|
|
4268
|
+
map: React.useMemo(() => {
|
|
4269
4269
|
const canvas = document.createElement("canvas");
|
|
4270
4270
|
canvas.width = 128;
|
|
4271
4271
|
canvas.height = 128;
|
|
@@ -4296,7 +4296,7 @@ const FaceMaterial = ({ hover, index, font = "20px Inter var, Arial, sans-serif"
|
|
|
4296
4296
|
};
|
|
4297
4297
|
const FaceCube = (props) => {
|
|
4298
4298
|
const { tweenCamera } = useGizmoContext();
|
|
4299
|
-
const [hover, setHover] = React
|
|
4299
|
+
const [hover, setHover] = React.useState(null);
|
|
4300
4300
|
const handlePointerOut = (e) => {
|
|
4301
4301
|
e.stopPropagation();
|
|
4302
4302
|
setHover(null);
|
|
@@ -4322,7 +4322,7 @@ const FaceCube = (props) => {
|
|
|
4322
4322
|
};
|
|
4323
4323
|
const EdgeCube = ({ onClick, dimensions, position: position$1, hoverColor = colors.hover }) => {
|
|
4324
4324
|
const { tweenCamera } = useGizmoContext();
|
|
4325
|
-
const [hover, setHover] = React
|
|
4325
|
+
const [hover, setHover] = React.useState(false);
|
|
4326
4326
|
const handlePointerOut = (e) => {
|
|
4327
4327
|
e.stopPropagation();
|
|
4328
4328
|
setHover(false);
|
|
@@ -4407,7 +4407,7 @@ function Axis({ scale: scale$2 = [
|
|
|
4407
4407
|
}
|
|
4408
4408
|
function AxisHead({ onClick, font, disabled, arcStyle, label, labelColor, axisHeadScale = 1, ...props }) {
|
|
4409
4409
|
const renderer = useThree((state) => state.renderer);
|
|
4410
|
-
const texture = React
|
|
4410
|
+
const texture = React.useMemo(() => {
|
|
4411
4411
|
const canvas = document.createElement("canvas");
|
|
4412
4412
|
canvas.width = 64;
|
|
4413
4413
|
canvas.height = 64;
|
|
@@ -4430,7 +4430,7 @@ function AxisHead({ onClick, font, disabled, arcStyle, label, labelColor, axisHe
|
|
|
4430
4430
|
labelColor,
|
|
4431
4431
|
font
|
|
4432
4432
|
]);
|
|
4433
|
-
const [active, setActive] = React
|
|
4433
|
+
const [active, setActive] = React.useState(false);
|
|
4434
4434
|
const scale$2 = (label ? 1 : .75) * (active ? 1.2 : 1) * axisHeadScale;
|
|
4435
4435
|
const handlePointerOver = (e) => {
|
|
4436
4436
|
e.stopPropagation();
|
|
@@ -4703,22 +4703,22 @@ function isRefObject(ref) {
|
|
|
4703
4703
|
* </Html>
|
|
4704
4704
|
* ```
|
|
4705
4705
|
*/
|
|
4706
|
-
const Html = /* @__PURE__ */ React
|
|
4706
|
+
const Html = /* @__PURE__ */ React.forwardRef(({ children, eps: eps$1 = .001, style, className, prepend, center, fullscreen, portal, distanceFactor, sprite = false, transform = false, occlude, onOcclude, castShadow, receiveShadow, material, geometry: geometry$1, zIndexRange = [16777271, 0], calculatePosition = defaultCalculatePosition, as = "div", wrapperClass, pointerEvents = "auto", ...props }, ref) => {
|
|
4707
4707
|
const { gl, camera, scene, size, raycaster, events, viewport } = useThree();
|
|
4708
|
-
const [el] = React
|
|
4709
|
-
const root = React
|
|
4710
|
-
const group = React
|
|
4711
|
-
const oldZoom = React
|
|
4712
|
-
const oldPosition = React
|
|
4713
|
-
const transformOuterRef = React
|
|
4714
|
-
const transformInnerRef = React
|
|
4708
|
+
const [el] = React.useState(() => document.createElement(as));
|
|
4709
|
+
const root = React.useRef(null);
|
|
4710
|
+
const group = React.useRef(null);
|
|
4711
|
+
const oldZoom = React.useRef(0);
|
|
4712
|
+
const oldPosition = React.useRef([0, 0]);
|
|
4713
|
+
const transformOuterRef = React.useRef(null);
|
|
4714
|
+
const transformInnerRef = React.useRef(null);
|
|
4715
4715
|
const target$1 = portal?.current || events.connected || gl.domElement.parentNode;
|
|
4716
|
-
const occlusionMeshRef = React
|
|
4717
|
-
const isMeshSizeSet = React
|
|
4718
|
-
const isRayCastOcclusion = React
|
|
4716
|
+
const occlusionMeshRef = React.useRef(null);
|
|
4717
|
+
const isMeshSizeSet = React.useRef(false);
|
|
4718
|
+
const isRayCastOcclusion = React.useMemo(() => {
|
|
4719
4719
|
return occlude && occlude !== "blending" || Array.isArray(occlude) && occlude.length && isRefObject(occlude[0]);
|
|
4720
4720
|
}, [occlude]);
|
|
4721
|
-
React
|
|
4721
|
+
React.useLayoutEffect(() => {
|
|
4722
4722
|
const el$1 = gl.domElement;
|
|
4723
4723
|
if (occlude && occlude === "blending") {
|
|
4724
4724
|
el$1.style.zIndex = `${Math.floor(zIndexRange[0] / 2)}`;
|
|
@@ -4730,7 +4730,7 @@ const Html = /* @__PURE__ */ React$1.forwardRef(({ children, eps: eps$1 = .001,
|
|
|
4730
4730
|
el$1.style.pointerEvents = null;
|
|
4731
4731
|
}
|
|
4732
4732
|
}, [occlude]);
|
|
4733
|
-
React
|
|
4733
|
+
React.useLayoutEffect(() => {
|
|
4734
4734
|
if (group.current) {
|
|
4735
4735
|
const currentRoot = root.current = ReactDOM.createRoot(el);
|
|
4736
4736
|
scene.updateMatrixWorld();
|
|
@@ -4747,10 +4747,10 @@ const Html = /* @__PURE__ */ React$1.forwardRef(({ children, eps: eps$1 = .001,
|
|
|
4747
4747
|
};
|
|
4748
4748
|
}
|
|
4749
4749
|
}, [target$1, transform]);
|
|
4750
|
-
React
|
|
4750
|
+
React.useLayoutEffect(() => {
|
|
4751
4751
|
if (wrapperClass) el.className = wrapperClass;
|
|
4752
4752
|
}, [wrapperClass]);
|
|
4753
|
-
const styles$1 = React
|
|
4753
|
+
const styles$1 = React.useMemo(() => {
|
|
4754
4754
|
if (transform) return {
|
|
4755
4755
|
position: "absolute",
|
|
4756
4756
|
top: 0,
|
|
@@ -4778,11 +4778,11 @@ const Html = /* @__PURE__ */ React$1.forwardRef(({ children, eps: eps$1 = .001,
|
|
|
4778
4778
|
size,
|
|
4779
4779
|
transform
|
|
4780
4780
|
]);
|
|
4781
|
-
const transformInnerStyles = React
|
|
4781
|
+
const transformInnerStyles = React.useMemo(() => ({
|
|
4782
4782
|
position: "absolute",
|
|
4783
4783
|
pointerEvents
|
|
4784
4784
|
}), [pointerEvents]);
|
|
4785
|
-
React
|
|
4785
|
+
React.useLayoutEffect(() => {
|
|
4786
4786
|
isMeshSizeSet.current = false;
|
|
4787
4787
|
if (transform) root.current?.render(/* @__PURE__ */ jsx("div", {
|
|
4788
4788
|
ref: transformOuterRef,
|
|
@@ -4805,7 +4805,7 @@ const Html = /* @__PURE__ */ React$1.forwardRef(({ children, eps: eps$1 = .001,
|
|
|
4805
4805
|
children
|
|
4806
4806
|
}));
|
|
4807
4807
|
});
|
|
4808
|
-
const visible = React
|
|
4808
|
+
const visible = React.useRef(true);
|
|
4809
4809
|
useFrame((gl$1) => {
|
|
4810
4810
|
if (group.current) {
|
|
4811
4811
|
camera.updateMatrixWorld();
|
|
@@ -4883,7 +4883,7 @@ const Html = /* @__PURE__ */ React$1.forwardRef(({ children, eps: eps$1 = .001,
|
|
|
4883
4883
|
occlusionMeshRef.current.lookAt(gl$1.camera.position);
|
|
4884
4884
|
}
|
|
4885
4885
|
});
|
|
4886
|
-
const shaders = React
|
|
4886
|
+
const shaders = React.useMemo(() => ({
|
|
4887
4887
|
vertexShader: !transform ? `
|
|
4888
4888
|
/*
|
|
4889
4889
|
This shader is from the THREE's SpriteMaterial.
|
|
@@ -4942,7 +4942,7 @@ const Html = /* @__PURE__ */ React$1.forwardRef(({ children, eps: eps$1 = .001,
|
|
|
4942
4942
|
|
|
4943
4943
|
//#endregion
|
|
4944
4944
|
//#region src/core/Gizmos/PivotControls/context.ts
|
|
4945
|
-
const context$5 = /* @__PURE__ */ React
|
|
4945
|
+
const context$5 = /* @__PURE__ */ React.createContext(null);
|
|
4946
4946
|
|
|
4947
4947
|
//#endregion
|
|
4948
4948
|
//#region src/core/Gizmos/PivotControls/AxisArrow.tsx
|
|
@@ -4960,14 +4960,14 @@ const calculateOffset$1 = (clickPoint, normal, rayStart, rayDir) => {
|
|
|
4960
4960
|
const upV$1 = /* @__PURE__ */ new Vector3$2(0, 1, 0);
|
|
4961
4961
|
const offsetMatrix$1 = /* @__PURE__ */ new Matrix4();
|
|
4962
4962
|
const AxisArrow = ({ direction, axis }) => {
|
|
4963
|
-
const { translation: translation$2, translationLimits, annotations, annotationsClass, depthTest, scale: scale$2, lineWidth, fixed, axisColors, hoveredColor, opacity, renderOrder, onDragStart, onDrag, onDragEnd, userData, LineComponent: Line$1 } = React
|
|
4963
|
+
const { translation: translation$2, translationLimits, annotations, annotationsClass, depthTest, scale: scale$2, lineWidth, fixed, axisColors, hoveredColor, opacity, renderOrder, onDragStart, onDrag, onDragEnd, userData, LineComponent: Line$1 } = React.useContext(context$5);
|
|
4964
4964
|
const camControls = useThree((state) => state.controls);
|
|
4965
|
-
const divRef = React
|
|
4966
|
-
const objRef = React
|
|
4967
|
-
const clickInfo = React
|
|
4968
|
-
const offset0 = React
|
|
4969
|
-
const [isHovered, setIsHovered] = React
|
|
4970
|
-
const onPointerDown = React
|
|
4965
|
+
const divRef = React.useRef(null);
|
|
4966
|
+
const objRef = React.useRef(null);
|
|
4967
|
+
const clickInfo = React.useRef(null);
|
|
4968
|
+
const offset0 = React.useRef(0);
|
|
4969
|
+
const [isHovered, setIsHovered] = React.useState(false);
|
|
4970
|
+
const onPointerDown = React.useCallback((e) => {
|
|
4971
4971
|
if (annotations) {
|
|
4972
4972
|
divRef.current.innerText = `${translation$2.current[axis].toFixed(2)}`;
|
|
4973
4973
|
divRef.current.style.display = "block";
|
|
@@ -4998,7 +4998,7 @@ const AxisArrow = ({ direction, axis }) => {
|
|
|
4998
4998
|
translation$2,
|
|
4999
4999
|
axis
|
|
5000
5000
|
]);
|
|
5001
|
-
const onPointerMove = React
|
|
5001
|
+
const onPointerMove = React.useCallback((e) => {
|
|
5002
5002
|
e.stopPropagation();
|
|
5003
5003
|
if (!isHovered) setIsHovered(true);
|
|
5004
5004
|
if (clickInfo.current) {
|
|
@@ -5020,7 +5020,7 @@ const AxisArrow = ({ direction, axis }) => {
|
|
|
5020
5020
|
translationLimits,
|
|
5021
5021
|
axis
|
|
5022
5022
|
]);
|
|
5023
|
-
const onPointerUp = React
|
|
5023
|
+
const onPointerUp = React.useCallback((e) => {
|
|
5024
5024
|
if (annotations) divRef.current.style.display = "none";
|
|
5025
5025
|
e.stopPropagation();
|
|
5026
5026
|
clickInfo.current = null;
|
|
@@ -5032,11 +5032,11 @@ const AxisArrow = ({ direction, axis }) => {
|
|
|
5032
5032
|
camControls,
|
|
5033
5033
|
onDragEnd
|
|
5034
5034
|
]);
|
|
5035
|
-
const onPointerOut = React
|
|
5035
|
+
const onPointerOut = React.useCallback((e) => {
|
|
5036
5036
|
e.stopPropagation();
|
|
5037
5037
|
setIsHovered(false);
|
|
5038
5038
|
}, []);
|
|
5039
|
-
const { cylinderLength, coneWidth, coneLength, matrixL } = React
|
|
5039
|
+
const { cylinderLength, coneWidth, coneLength, matrixL } = React.useMemo(() => {
|
|
5040
5040
|
const coneWidth$1 = fixed ? lineWidth / scale$2 * 1.6 : scale$2 / 20;
|
|
5041
5041
|
const coneLength$1 = fixed ? .2 : scale$2 / 5;
|
|
5042
5042
|
const cylinderLength$1 = fixed ? 1 - coneLength$1 : scale$2 - coneLength$1;
|
|
@@ -5182,15 +5182,15 @@ const posNew = /* @__PURE__ */ new Vector3$2();
|
|
|
5182
5182
|
const ray$1 = /* @__PURE__ */ new Ray();
|
|
5183
5183
|
const intersection$1 = /* @__PURE__ */ new Vector3$2();
|
|
5184
5184
|
const AxisRotator = ({ dir1, dir2, axis }) => {
|
|
5185
|
-
const { rotationLimits, annotations, annotationsClass, depthTest, scale: scale$2, lineWidth, fixed, axisColors, hoveredColor, renderOrder, opacity, onDragStart, onDrag, onDragEnd, userData, LineComponent: Line$1 } = React
|
|
5185
|
+
const { rotationLimits, annotations, annotationsClass, depthTest, scale: scale$2, lineWidth, fixed, axisColors, hoveredColor, renderOrder, opacity, onDragStart, onDrag, onDragEnd, userData, LineComponent: Line$1 } = React.useContext(context$5);
|
|
5186
5186
|
const camControls = useThree((state) => state.controls);
|
|
5187
|
-
const divRef = React
|
|
5188
|
-
const objRef = React
|
|
5189
|
-
const angle0 = React
|
|
5190
|
-
const angle = React
|
|
5191
|
-
const clickInfo = React
|
|
5192
|
-
const [isHovered, setIsHovered] = React
|
|
5193
|
-
const onPointerDown = React
|
|
5187
|
+
const divRef = React.useRef(null);
|
|
5188
|
+
const objRef = React.useRef(null);
|
|
5189
|
+
const angle0 = React.useRef(0);
|
|
5190
|
+
const angle = React.useRef(0);
|
|
5191
|
+
const clickInfo = React.useRef(null);
|
|
5192
|
+
const [isHovered, setIsHovered] = React.useState(false);
|
|
5193
|
+
const onPointerDown = React.useCallback((e) => {
|
|
5194
5194
|
if (annotations) {
|
|
5195
5195
|
divRef.current.innerText = `${toDegrees(angle.current).toFixed(0)}º`;
|
|
5196
5196
|
divRef.current.style.display = "block";
|
|
@@ -5227,7 +5227,7 @@ const AxisRotator = ({ dir1, dir2, axis }) => {
|
|
|
5227
5227
|
onDragStart,
|
|
5228
5228
|
axis
|
|
5229
5229
|
]);
|
|
5230
|
-
const onPointerMove = React
|
|
5230
|
+
const onPointerMove = React.useCallback((e) => {
|
|
5231
5231
|
e.stopPropagation();
|
|
5232
5232
|
if (!isHovered) setIsHovered(true);
|
|
5233
5233
|
if (clickInfo.current) {
|
|
@@ -5268,7 +5268,7 @@ const AxisRotator = ({ dir1, dir2, axis }) => {
|
|
|
5268
5268
|
rotationLimits,
|
|
5269
5269
|
axis
|
|
5270
5270
|
]);
|
|
5271
|
-
const onPointerUp = React
|
|
5271
|
+
const onPointerUp = React.useCallback((e) => {
|
|
5272
5272
|
if (annotations) divRef.current.style.display = "none";
|
|
5273
5273
|
e.stopPropagation();
|
|
5274
5274
|
angle0.current = angle.current;
|
|
@@ -5281,17 +5281,17 @@ const AxisRotator = ({ dir1, dir2, axis }) => {
|
|
|
5281
5281
|
camControls,
|
|
5282
5282
|
onDragEnd
|
|
5283
5283
|
]);
|
|
5284
|
-
const onPointerOut = React
|
|
5284
|
+
const onPointerOut = React.useCallback((e) => {
|
|
5285
5285
|
e.stopPropagation();
|
|
5286
5286
|
setIsHovered(false);
|
|
5287
5287
|
}, []);
|
|
5288
|
-
const matrixL = React
|
|
5288
|
+
const matrixL = React.useMemo(() => {
|
|
5289
5289
|
const dir1N = dir1.clone().normalize();
|
|
5290
5290
|
const dir2N = dir2.clone().normalize();
|
|
5291
5291
|
return new Matrix4().makeBasis(dir1N, dir2N, dir1N.clone().cross(dir2N));
|
|
5292
5292
|
}, [dir1, dir2]);
|
|
5293
5293
|
const r = fixed ? .65 : scale$2 * .65;
|
|
5294
|
-
const arc = React
|
|
5294
|
+
const arc = React.useMemo(() => {
|
|
5295
5295
|
const segments = 32;
|
|
5296
5296
|
const points = [];
|
|
5297
5297
|
for (let j = 0; j <= segments; j++) {
|
|
@@ -5374,15 +5374,15 @@ const ray = /* @__PURE__ */ new Ray();
|
|
|
5374
5374
|
const intersection = /* @__PURE__ */ new Vector3$2();
|
|
5375
5375
|
const offsetMatrix = /* @__PURE__ */ new Matrix4();
|
|
5376
5376
|
const PlaneSlider = ({ dir1, dir2, axis }) => {
|
|
5377
|
-
const { translation: translation$2, translationLimits, annotations, annotationsClass, depthTest, scale: scale$2, lineWidth, fixed, axisColors, hoveredColor, opacity, renderOrder, onDragStart, onDrag, onDragEnd, userData, LineComponent: Line$1 } = React
|
|
5377
|
+
const { translation: translation$2, translationLimits, annotations, annotationsClass, depthTest, scale: scale$2, lineWidth, fixed, axisColors, hoveredColor, opacity, renderOrder, onDragStart, onDrag, onDragEnd, userData, LineComponent: Line$1 } = React.useContext(context$5);
|
|
5378
5378
|
const camControls = useThree((state) => state.controls);
|
|
5379
|
-
const divRef = React
|
|
5380
|
-
const objRef = React
|
|
5381
|
-
const clickInfo = React
|
|
5382
|
-
const offsetX0 = React
|
|
5383
|
-
const offsetY0 = React
|
|
5384
|
-
const [isHovered, setIsHovered] = React
|
|
5385
|
-
const onPointerDown = React
|
|
5379
|
+
const divRef = React.useRef(null);
|
|
5380
|
+
const objRef = React.useRef(null);
|
|
5381
|
+
const clickInfo = React.useRef(null);
|
|
5382
|
+
const offsetX0 = React.useRef(0);
|
|
5383
|
+
const offsetY0 = React.useRef(0);
|
|
5384
|
+
const [isHovered, setIsHovered] = React.useState(false);
|
|
5385
|
+
const onPointerDown = React.useCallback((e) => {
|
|
5386
5386
|
if (annotations) {
|
|
5387
5387
|
divRef.current.innerText = `${translation$2.current[(axis + 1) % 3].toFixed(2)}, ${translation$2.current[(axis + 2) % 3].toFixed(2)}`;
|
|
5388
5388
|
divRef.current.style.display = "block";
|
|
@@ -5419,7 +5419,7 @@ const PlaneSlider = ({ dir1, dir2, axis }) => {
|
|
|
5419
5419
|
onDragStart,
|
|
5420
5420
|
axis
|
|
5421
5421
|
]);
|
|
5422
|
-
const onPointerMove = React
|
|
5422
|
+
const onPointerMove = React.useCallback((e) => {
|
|
5423
5423
|
e.stopPropagation();
|
|
5424
5424
|
if (!isHovered) setIsHovered(true);
|
|
5425
5425
|
if (clickInfo.current) {
|
|
@@ -5450,7 +5450,7 @@ const PlaneSlider = ({ dir1, dir2, axis }) => {
|
|
|
5450
5450
|
translationLimits,
|
|
5451
5451
|
axis
|
|
5452
5452
|
]);
|
|
5453
|
-
const onPointerUp = React
|
|
5453
|
+
const onPointerUp = React.useCallback((e) => {
|
|
5454
5454
|
if (annotations) divRef.current.style.display = "none";
|
|
5455
5455
|
e.stopPropagation();
|
|
5456
5456
|
clickInfo.current = null;
|
|
@@ -5462,11 +5462,11 @@ const PlaneSlider = ({ dir1, dir2, axis }) => {
|
|
|
5462
5462
|
camControls,
|
|
5463
5463
|
onDragEnd
|
|
5464
5464
|
]);
|
|
5465
|
-
const onPointerOut = React
|
|
5465
|
+
const onPointerOut = React.useCallback((e) => {
|
|
5466
5466
|
e.stopPropagation();
|
|
5467
5467
|
setIsHovered(false);
|
|
5468
5468
|
}, []);
|
|
5469
|
-
const matrixL = React
|
|
5469
|
+
const matrixL = React.useMemo(() => {
|
|
5470
5470
|
const dir1N = dir1.clone().normalize();
|
|
5471
5471
|
const dir2N = dir2.clone().normalize();
|
|
5472
5472
|
return new Matrix4().makeBasis(dir1N, dir2N, dir1N.clone().cross(dir2N));
|
|
@@ -5474,7 +5474,7 @@ const PlaneSlider = ({ dir1, dir2, axis }) => {
|
|
|
5474
5474
|
const pos1 = fixed ? 1 / 7 : scale$2 / 7;
|
|
5475
5475
|
const length = fixed ? .225 : scale$2 * .225;
|
|
5476
5476
|
const color = isHovered ? hoveredColor : axisColors[axis];
|
|
5477
|
-
const points = React
|
|
5477
|
+
const points = React.useMemo(() => [
|
|
5478
5478
|
new Vector3$2(0, 0, 0),
|
|
5479
5479
|
new Vector3$2(0, length, 0),
|
|
5480
5480
|
new Vector3$2(length, length, 0),
|
|
@@ -5596,18 +5596,18 @@ const upV = /* @__PURE__ */ new Vector3$2(0, 1, 0);
|
|
|
5596
5596
|
const scaleV = /* @__PURE__ */ new Vector3$2();
|
|
5597
5597
|
const scaleMatrix = /* @__PURE__ */ new Matrix4();
|
|
5598
5598
|
const ScalingSphere = ({ direction, axis }) => {
|
|
5599
|
-
const { scaleLimits, annotations, annotationsClass, depthTest, scale: scale$2, lineWidth, fixed, axisColors, hoveredColor, opacity, renderOrder, onDragStart, onDrag, onDragEnd, userData } = React
|
|
5599
|
+
const { scaleLimits, annotations, annotationsClass, depthTest, scale: scale$2, lineWidth, fixed, axisColors, hoveredColor, opacity, renderOrder, onDragStart, onDrag, onDragEnd, userData } = React.useContext(context$5);
|
|
5600
5600
|
const size = useThree((state) => state.size);
|
|
5601
5601
|
const camControls = useThree((state) => state.controls);
|
|
5602
|
-
const divRef = React
|
|
5603
|
-
const objRef = React
|
|
5604
|
-
const meshRef = React
|
|
5605
|
-
const scale0 = React
|
|
5606
|
-
const scaleCur = React
|
|
5607
|
-
const clickInfo = React
|
|
5608
|
-
const [isHovered, setIsHovered] = React
|
|
5602
|
+
const divRef = React.useRef(null);
|
|
5603
|
+
const objRef = React.useRef(null);
|
|
5604
|
+
const meshRef = React.useRef(null);
|
|
5605
|
+
const scale0 = React.useRef(1);
|
|
5606
|
+
const scaleCur = React.useRef(1);
|
|
5607
|
+
const clickInfo = React.useRef(null);
|
|
5608
|
+
const [isHovered, setIsHovered] = React.useState(false);
|
|
5609
5609
|
const position$1 = fixed ? 1.2 : 1.2 * scale$2;
|
|
5610
|
-
const onPointerDown = React
|
|
5610
|
+
const onPointerDown = React.useCallback((e) => {
|
|
5611
5611
|
if (annotations) {
|
|
5612
5612
|
divRef.current.innerText = `${scaleCur.current.toFixed(2)}`;
|
|
5613
5613
|
divRef.current.style.display = "block";
|
|
@@ -5643,7 +5643,7 @@ const ScalingSphere = ({ direction, axis }) => {
|
|
|
5643
5643
|
scale$2,
|
|
5644
5644
|
size
|
|
5645
5645
|
]);
|
|
5646
|
-
const onPointerMove = React
|
|
5646
|
+
const onPointerMove = React.useCallback((e) => {
|
|
5647
5647
|
e.stopPropagation();
|
|
5648
5648
|
if (!isHovered) setIsHovered(true);
|
|
5649
5649
|
if (clickInfo.current) {
|
|
@@ -5671,7 +5671,7 @@ const ScalingSphere = ({ direction, axis }) => {
|
|
|
5671
5671
|
scaleLimits,
|
|
5672
5672
|
axis
|
|
5673
5673
|
]);
|
|
5674
|
-
const onPointerUp = React
|
|
5674
|
+
const onPointerUp = React.useCallback((e) => {
|
|
5675
5675
|
if (annotations) divRef.current.style.display = "none";
|
|
5676
5676
|
e.stopPropagation();
|
|
5677
5677
|
scale0.current = scaleCur.current;
|
|
@@ -5686,11 +5686,11 @@ const ScalingSphere = ({ direction, axis }) => {
|
|
|
5686
5686
|
onDragEnd,
|
|
5687
5687
|
position$1
|
|
5688
5688
|
]);
|
|
5689
|
-
const onPointerOut = React
|
|
5689
|
+
const onPointerOut = React.useCallback((e) => {
|
|
5690
5690
|
e.stopPropagation();
|
|
5691
5691
|
setIsHovered(false);
|
|
5692
5692
|
}, []);
|
|
5693
|
-
const { radius, matrixL } = React
|
|
5693
|
+
const { radius, matrixL } = React.useMemo(() => {
|
|
5694
5694
|
const radius$1 = fixed ? lineWidth / scale$2 * 1.8 : scale$2 / 22.5;
|
|
5695
5695
|
const quaternion = new Quaternion().setFromUnitVectors(upV, direction.clone().normalize());
|
|
5696
5696
|
return {
|
|
@@ -5800,7 +5800,7 @@ const zDir = /* @__PURE__ */ new Vector3$2(0, 0, 1);
|
|
|
5800
5800
|
* />
|
|
5801
5801
|
* ```
|
|
5802
5802
|
*/
|
|
5803
|
-
const PivotControls = /* @__PURE__ */ React
|
|
5803
|
+
const PivotControls = /* @__PURE__ */ React.forwardRef(({ enabled = true, matrix: matrix$1, onDragStart, onDrag, onDragEnd, autoTransform = true, anchor, disableAxes = false, disableSliders = false, disableRotations = false, disableScaling = false, activeAxes = [
|
|
5804
5804
|
true,
|
|
5805
5805
|
true,
|
|
5806
5806
|
true
|
|
@@ -5819,18 +5819,18 @@ const PivotControls = /* @__PURE__ */ React$1.forwardRef(({ enabled = true, matr
|
|
|
5819
5819
|
], hoveredColor = "#ffff40", annotations = false, annotationsClass, opacity = 1, visible = true, userData, children, LineComponent, ...props }, fRef) => {
|
|
5820
5820
|
const LineComp = LineComponent ?? Line;
|
|
5821
5821
|
const invalidate = useThree((state) => state.invalidate);
|
|
5822
|
-
const parentRef = React
|
|
5823
|
-
const ref = React
|
|
5824
|
-
const gizmoRef = React
|
|
5825
|
-
const childrenRef = React
|
|
5826
|
-
const translation$2 = React
|
|
5822
|
+
const parentRef = React.useRef(null);
|
|
5823
|
+
const ref = React.useRef(null);
|
|
5824
|
+
const gizmoRef = React.useRef(null);
|
|
5825
|
+
const childrenRef = React.useRef(null);
|
|
5826
|
+
const translation$2 = React.useRef([
|
|
5827
5827
|
0,
|
|
5828
5828
|
0,
|
|
5829
5829
|
0
|
|
5830
5830
|
]);
|
|
5831
|
-
const cameraScale = React
|
|
5832
|
-
const gizmoScale = React
|
|
5833
|
-
React
|
|
5831
|
+
const cameraScale = React.useRef(new Vector3$2(1, 1, 1));
|
|
5832
|
+
const gizmoScale = React.useRef(new Vector3$2(1, 1, 1));
|
|
5833
|
+
React.useLayoutEffect(() => {
|
|
5834
5834
|
if (!anchor) return;
|
|
5835
5835
|
childrenRef.current.updateWorldMatrix(true, true);
|
|
5836
5836
|
mPInv.copy(childrenRef.current.matrixWorld).invert();
|
|
@@ -5850,7 +5850,7 @@ const PivotControls = /* @__PURE__ */ React$1.forwardRef(({ enabled = true, matr
|
|
|
5850
5850
|
gizmoRef.current.position.copy(vPosition);
|
|
5851
5851
|
invalidate();
|
|
5852
5852
|
});
|
|
5853
|
-
const config = React
|
|
5853
|
+
const config = React.useMemo(() => ({
|
|
5854
5854
|
onDragStart: (props$1) => {
|
|
5855
5855
|
mL0.copy(ref.current.matrix);
|
|
5856
5856
|
mW0.copy(ref.current.matrixWorld);
|
|
@@ -5924,7 +5924,7 @@ const PivotControls = /* @__PURE__ */ React$1.forwardRef(({ enabled = true, matr
|
|
|
5924
5924
|
state.invalidate();
|
|
5925
5925
|
}
|
|
5926
5926
|
});
|
|
5927
|
-
React
|
|
5927
|
+
React.useImperativeHandle(fRef, () => ref.current, []);
|
|
5928
5928
|
return /* @__PURE__ */ jsx(context$5.Provider, {
|
|
5929
5929
|
value: config,
|
|
5930
5930
|
children: /* @__PURE__ */ jsx("group", {
|
|
@@ -6024,7 +6024,7 @@ const PivotControls = /* @__PURE__ */ React$1.forwardRef(({ enabled = true, matr
|
|
|
6024
6024
|
* <mesh ref={meshRef} />
|
|
6025
6025
|
* ```
|
|
6026
6026
|
*/
|
|
6027
|
-
const TransformControls = /* @__PURE__ */ React
|
|
6027
|
+
const TransformControls = /* @__PURE__ */ React.forwardRef(({ children, domElement, onChange, onMouseDown, onMouseUp, onObjectChange, object, makeDefault, camera, enabled, axis, mode, translationSnap, rotationSnap, scaleSnap, space, size, showX, showY, showZ, ...props }, ref) => {
|
|
6028
6028
|
const defaultControls = useThree((state) => state.controls);
|
|
6029
6029
|
const gl = useThree((state) => state.gl);
|
|
6030
6030
|
const events = useThree((state) => state.events);
|
|
@@ -6034,9 +6034,9 @@ const TransformControls = /* @__PURE__ */ React$1.forwardRef(({ children, domEle
|
|
|
6034
6034
|
const set = useThree((state) => state.set);
|
|
6035
6035
|
const explCamera = camera || defaultCamera;
|
|
6036
6036
|
const explDomElement = domElement || events.connected || gl.domElement;
|
|
6037
|
-
const controls = React
|
|
6038
|
-
const group = React
|
|
6039
|
-
React
|
|
6037
|
+
const controls = React.useMemo(() => new TransformControls$1(explCamera, explDomElement), [explCamera, explDomElement]);
|
|
6038
|
+
const group = React.useRef(null);
|
|
6039
|
+
React.useLayoutEffect(() => {
|
|
6040
6040
|
if (object) controls.attach(object instanceof Object3D ? object : object.current);
|
|
6041
6041
|
else if (group.current instanceof Object3D) controls.attach(group.current);
|
|
6042
6042
|
return () => void controls.detach();
|
|
@@ -6045,22 +6045,22 @@ const TransformControls = /* @__PURE__ */ React$1.forwardRef(({ children, domEle
|
|
|
6045
6045
|
children,
|
|
6046
6046
|
controls
|
|
6047
6047
|
]);
|
|
6048
|
-
React
|
|
6048
|
+
React.useEffect(() => {
|
|
6049
6049
|
if (defaultControls) {
|
|
6050
6050
|
const callback = (event) => defaultControls.enabled = !event.value;
|
|
6051
6051
|
controls.addEventListener("dragging-changed", callback);
|
|
6052
6052
|
return () => controls.removeEventListener("dragging-changed", callback);
|
|
6053
6053
|
}
|
|
6054
6054
|
}, [controls, defaultControls]);
|
|
6055
|
-
const onChangeRef = React
|
|
6056
|
-
const onMouseDownRef = React
|
|
6057
|
-
const onMouseUpRef = React
|
|
6058
|
-
const onObjectChangeRef = React
|
|
6059
|
-
React
|
|
6060
|
-
React
|
|
6061
|
-
React
|
|
6062
|
-
React
|
|
6063
|
-
React
|
|
6055
|
+
const onChangeRef = React.useRef(void 0);
|
|
6056
|
+
const onMouseDownRef = React.useRef(void 0);
|
|
6057
|
+
const onMouseUpRef = React.useRef(void 0);
|
|
6058
|
+
const onObjectChangeRef = React.useRef(void 0);
|
|
6059
|
+
React.useLayoutEffect(() => void (onChangeRef.current = onChange), [onChange]);
|
|
6060
|
+
React.useLayoutEffect(() => void (onMouseDownRef.current = onMouseDown), [onMouseDown]);
|
|
6061
|
+
React.useLayoutEffect(() => void (onMouseUpRef.current = onMouseUp), [onMouseUp]);
|
|
6062
|
+
React.useLayoutEffect(() => void (onObjectChangeRef.current = onObjectChange), [onObjectChange]);
|
|
6063
|
+
React.useEffect(() => {
|
|
6064
6064
|
const onChange$1 = (e) => {
|
|
6065
6065
|
invalidate();
|
|
6066
6066
|
onChangeRef.current?.(e);
|
|
@@ -6079,7 +6079,7 @@ const TransformControls = /* @__PURE__ */ React$1.forwardRef(({ children, domEle
|
|
|
6079
6079
|
controls.removeEventListener("objectChange", onObjectChange$1);
|
|
6080
6080
|
};
|
|
6081
6081
|
}, [invalidate, controls]);
|
|
6082
|
-
React
|
|
6082
|
+
React.useEffect(() => {
|
|
6083
6083
|
if (makeDefault) {
|
|
6084
6084
|
const old = get().controls;
|
|
6085
6085
|
set({ controls });
|
|
@@ -6140,8 +6140,8 @@ var PointMaterialImpl = class extends PointsMaterial {
|
|
|
6140
6140
|
* </points>
|
|
6141
6141
|
* ```
|
|
6142
6142
|
*/
|
|
6143
|
-
const PointMaterial = /* @__PURE__ */ React
|
|
6144
|
-
const [material] = React
|
|
6143
|
+
const PointMaterial = /* @__PURE__ */ React.forwardRef((props, ref) => {
|
|
6144
|
+
const [material] = React.useState(() => new PointMaterialImpl(null));
|
|
6145
6145
|
return /* @__PURE__ */ jsx("primitive", {
|
|
6146
6146
|
...props,
|
|
6147
6147
|
object: material,
|
|
@@ -6166,13 +6166,13 @@ const PointMaterial = /* @__PURE__ */ React$1.forwardRef((props, ref) => {
|
|
|
6166
6166
|
* />
|
|
6167
6167
|
* ```
|
|
6168
6168
|
*/
|
|
6169
|
-
const PositionalAudio = /* @__PURE__ */ React
|
|
6170
|
-
const sound = React
|
|
6171
|
-
React
|
|
6169
|
+
const PositionalAudio = /* @__PURE__ */ React.forwardRef(({ url, distance = 1, loop = true, autoplay, ...props }, ref) => {
|
|
6170
|
+
const sound = React.useRef(null);
|
|
6171
|
+
React.useImperativeHandle(ref, () => sound.current, []);
|
|
6172
6172
|
const camera = useThree(({ camera: camera$1 }) => camera$1);
|
|
6173
|
-
const [listener] = React
|
|
6173
|
+
const [listener] = React.useState(() => new AudioListener());
|
|
6174
6174
|
const buffer = useLoader(AudioLoader, url);
|
|
6175
|
-
React
|
|
6175
|
+
React.useEffect(() => {
|
|
6176
6176
|
const _sound = sound.current;
|
|
6177
6177
|
if (_sound) {
|
|
6178
6178
|
_sound.setBuffer(Array.isArray(buffer) ? buffer[0] : buffer);
|
|
@@ -6186,7 +6186,7 @@ const PositionalAudio = /* @__PURE__ */ React$1.forwardRef(({ url, distance = 1,
|
|
|
6186
6186
|
distance,
|
|
6187
6187
|
loop
|
|
6188
6188
|
]);
|
|
6189
|
-
React
|
|
6189
|
+
React.useEffect(() => {
|
|
6190
6190
|
const _sound = sound.current;
|
|
6191
6191
|
camera.add(listener);
|
|
6192
6192
|
return () => {
|
|
@@ -6249,7 +6249,7 @@ var PositionMesh = class extends Group {
|
|
|
6249
6249
|
_instanceIntersects.length = 0;
|
|
6250
6250
|
}
|
|
6251
6251
|
};
|
|
6252
|
-
const globalContext = /* @__PURE__ */ React
|
|
6252
|
+
const globalContext = /* @__PURE__ */ React.createContext(null);
|
|
6253
6253
|
const parentMatrix = /* @__PURE__ */ new Matrix4();
|
|
6254
6254
|
const instanceMatrix = /* @__PURE__ */ new Matrix4();
|
|
6255
6255
|
const tempMatrix = /* @__PURE__ */ new Matrix4();
|
|
@@ -6261,12 +6261,12 @@ const isInstancedBufferAttribute = (attr) => attr.isInstancedBufferAttribute;
|
|
|
6261
6261
|
* A single instance within an Instances container.
|
|
6262
6262
|
* Supports transform props, colors, and events.
|
|
6263
6263
|
*/
|
|
6264
|
-
const Instance = /* @__PURE__ */ React
|
|
6265
|
-
React
|
|
6266
|
-
const group = React
|
|
6267
|
-
React
|
|
6268
|
-
const { subscribe, getParent } = React
|
|
6269
|
-
React
|
|
6264
|
+
const Instance = /* @__PURE__ */ React.forwardRef(({ context: context$10, children, ...props }, ref) => {
|
|
6265
|
+
React.useMemo(() => extend({ PositionMesh }), []);
|
|
6266
|
+
const group = React.useRef(null);
|
|
6267
|
+
React.useImperativeHandle(ref, () => group.current, []);
|
|
6268
|
+
const { subscribe, getParent } = React.useContext(context$10 || globalContext);
|
|
6269
|
+
React.useLayoutEffect(() => subscribe(group), []);
|
|
6270
6270
|
return /* @__PURE__ */ jsx("positionMesh", {
|
|
6271
6271
|
instance: getParent(),
|
|
6272
6272
|
instanceKey: group,
|
|
@@ -6289,33 +6289,33 @@ const Instance = /* @__PURE__ */ React$1.forwardRef(({ context: context$10, chil
|
|
|
6289
6289
|
* </Instances>
|
|
6290
6290
|
* ```
|
|
6291
6291
|
*/
|
|
6292
|
-
const Instances = /* @__PURE__ */ React
|
|
6293
|
-
const [{ localContext, instance }] = React
|
|
6294
|
-
const localContext$1 = React
|
|
6292
|
+
const Instances = /* @__PURE__ */ React.forwardRef(({ context: context$10, children, range, limit = 1e3, frames = Infinity, ...props }, ref) => {
|
|
6293
|
+
const [{ localContext, instance }] = React.useState(() => {
|
|
6294
|
+
const localContext$1 = React.createContext(null);
|
|
6295
6295
|
return {
|
|
6296
6296
|
localContext: localContext$1,
|
|
6297
|
-
instance: React
|
|
6297
|
+
instance: React.forwardRef((props$1, ref$1) => /* @__PURE__ */ jsx(Instance, {
|
|
6298
6298
|
context: localContext$1,
|
|
6299
6299
|
...props$1,
|
|
6300
6300
|
ref: ref$1
|
|
6301
6301
|
}))
|
|
6302
6302
|
};
|
|
6303
6303
|
});
|
|
6304
|
-
const parentRef = React
|
|
6305
|
-
React
|
|
6306
|
-
const [instances, setInstances] = React
|
|
6307
|
-
const [[matrices, colors$1]] = React
|
|
6304
|
+
const parentRef = React.useRef(null);
|
|
6305
|
+
React.useImperativeHandle(ref, () => parentRef.current, []);
|
|
6306
|
+
const [instances, setInstances] = React.useState([]);
|
|
6307
|
+
const [[matrices, colors$1]] = React.useState(() => {
|
|
6308
6308
|
const mArray = new Float32Array(limit * 16);
|
|
6309
6309
|
for (let i$1 = 0; i$1 < limit; i$1++) tempMatrix.identity().toArray(mArray, i$1 * 16);
|
|
6310
6310
|
return [mArray, new Float32Array([...new Array(limit * 3)].map(() => 1))];
|
|
6311
6311
|
});
|
|
6312
|
-
React
|
|
6312
|
+
React.useEffect(() => {
|
|
6313
6313
|
parentRef.current.instanceMatrix.needsUpdate = true;
|
|
6314
6314
|
});
|
|
6315
6315
|
let iterations = 0;
|
|
6316
6316
|
let count = 0;
|
|
6317
|
-
const attributes = React
|
|
6318
|
-
React
|
|
6317
|
+
const attributes = React.useRef([]);
|
|
6318
|
+
React.useLayoutEffect(() => {
|
|
6319
6319
|
attributes.current = Object.entries(parentRef.current.geometry.attributes).filter(([_name, value]) => isInstancedBufferAttribute(value));
|
|
6320
6320
|
});
|
|
6321
6321
|
useFrame(() => {
|
|
@@ -6346,7 +6346,7 @@ const Instances = /* @__PURE__ */ React$1.forwardRef(({ context: context$10, chi
|
|
|
6346
6346
|
iterations++;
|
|
6347
6347
|
}
|
|
6348
6348
|
});
|
|
6349
|
-
const api = React
|
|
6349
|
+
const api = React.useMemo(() => ({
|
|
6350
6350
|
getParent: () => parentRef,
|
|
6351
6351
|
subscribe: (ref$1) => {
|
|
6352
6352
|
setInstances((instances$1) => [...instances$1, ref$1]);
|
|
@@ -6392,7 +6392,7 @@ const Instances = /* @__PURE__ */ React$1.forwardRef(({ context: context$10, chi
|
|
|
6392
6392
|
]
|
|
6393
6393
|
});
|
|
6394
6394
|
});
|
|
6395
|
-
const Merged = /* @__PURE__ */ React
|
|
6395
|
+
const Merged = /* @__PURE__ */ React.forwardRef(function Merged$1({ meshes, children, ...props }, ref) {
|
|
6396
6396
|
const isArray$1 = Array.isArray(meshes);
|
|
6397
6397
|
if (!isArray$1) {
|
|
6398
6398
|
for (const key of Object.keys(meshes)) if (!meshes[key].isMesh) delete meshes[key];
|
|
@@ -6418,7 +6418,7 @@ function renderRecursive(render, components, results = []) {
|
|
|
6418
6418
|
return typeof components[0] === "function" ? components[0]({
|
|
6419
6419
|
results,
|
|
6420
6420
|
render: nextRender
|
|
6421
|
-
}) : React
|
|
6421
|
+
}) : React.cloneElement(components[0], { children: nextRender });
|
|
6422
6422
|
}
|
|
6423
6423
|
/** Idea and implementation for global instances and instanced attributes by
|
|
6424
6424
|
/* Matias Gonzalez Fernandez https://x.com/matiNotFound
|
|
@@ -6441,12 +6441,12 @@ function renderRecursive(render, components, results = []) {
|
|
|
6441
6441
|
* ```
|
|
6442
6442
|
*/
|
|
6443
6443
|
function createInstances() {
|
|
6444
|
-
const context$10 = React
|
|
6445
|
-
return [React
|
|
6444
|
+
const context$10 = React.createContext(null);
|
|
6445
|
+
return [React.forwardRef((props, fref) => /* @__PURE__ */ jsx(Instances, {
|
|
6446
6446
|
ref: fref,
|
|
6447
6447
|
context: context$10,
|
|
6448
6448
|
...props
|
|
6449
|
-
})), React
|
|
6449
|
+
})), React.forwardRef((props, fref) => /* @__PURE__ */ jsx(Instance, {
|
|
6450
6450
|
ref: fref,
|
|
6451
6451
|
context: context$10,
|
|
6452
6452
|
...props
|
|
@@ -6466,10 +6466,10 @@ function createInstances() {
|
|
|
6466
6466
|
* </Instances>
|
|
6467
6467
|
* ```
|
|
6468
6468
|
*/
|
|
6469
|
-
const InstancedAttribute = React
|
|
6470
|
-
const ref = React
|
|
6471
|
-
React
|
|
6472
|
-
React
|
|
6469
|
+
const InstancedAttribute = React.forwardRef(({ name, defaultValue, normalized, usage = DynamicDrawUsage }, fref) => {
|
|
6470
|
+
const ref = React.useRef(null);
|
|
6471
|
+
React.useImperativeHandle(fref, () => ref.current, []);
|
|
6472
|
+
React.useLayoutEffect(() => {
|
|
6473
6473
|
const parent = ref.current.__r3f.parent.object;
|
|
6474
6474
|
parent.geometry.attributes[name] = ref.current;
|
|
6475
6475
|
const value = Array.isArray(defaultValue) ? defaultValue : [defaultValue];
|
|
@@ -6532,9 +6532,9 @@ const InstancedAttribute = React$1.forwardRef(({ name, defaultValue, normalized,
|
|
|
6532
6532
|
* </group>
|
|
6533
6533
|
* ```
|
|
6534
6534
|
*/
|
|
6535
|
-
const Billboard = /* @__PURE__ */ React
|
|
6536
|
-
const inner = React
|
|
6537
|
-
const localRef = React
|
|
6535
|
+
const Billboard = /* @__PURE__ */ React.forwardRef(function Billboard$1({ children, follow = true, lockX = false, lockY = false, lockZ = false, ...props }, fref) {
|
|
6536
|
+
const inner = React.useRef(null);
|
|
6537
|
+
const localRef = React.useRef(null);
|
|
6538
6538
|
const q = new Quaternion();
|
|
6539
6539
|
useFrame(({ camera }) => {
|
|
6540
6540
|
if (!follow || !localRef.current) return;
|
|
@@ -6547,7 +6547,7 @@ const Billboard = /* @__PURE__ */ React$1.forwardRef(function Billboard$1({ chil
|
|
|
6547
6547
|
if (lockY) inner.current.rotation.y = prevRotation.y;
|
|
6548
6548
|
if (lockZ) inner.current.rotation.z = prevRotation.z;
|
|
6549
6549
|
});
|
|
6550
|
-
React
|
|
6550
|
+
React.useImperativeHandle(fref, () => localRef.current, []);
|
|
6551
6551
|
return /* @__PURE__ */ jsx("group", {
|
|
6552
6552
|
ref: localRef,
|
|
6553
6553
|
...props,
|
|
@@ -6577,18 +6577,18 @@ const checkIfFrameIsEmpty = (frameData) => {
|
|
|
6577
6577
|
* ```
|
|
6578
6578
|
*/
|
|
6579
6579
|
function useSpriteLoader(input, json, animationNames, numberOfFrames, onLoad, canvasRenderingContext2DSettings) {
|
|
6580
|
-
const viewportRef = React
|
|
6581
|
-
const spriteDataRef = React
|
|
6582
|
-
const totalFrames = React
|
|
6580
|
+
const viewportRef = React.useRef(useThree((state) => state.viewport));
|
|
6581
|
+
const spriteDataRef = React.useRef(null);
|
|
6582
|
+
const totalFrames = React.useRef(0);
|
|
6583
6583
|
const aspectFactor = .1;
|
|
6584
|
-
const inputRef = React
|
|
6585
|
-
const jsonRef = React
|
|
6586
|
-
const animationFramesRef = React
|
|
6584
|
+
const inputRef = React.useRef(input);
|
|
6585
|
+
const jsonRef = React.useRef(json);
|
|
6586
|
+
const animationFramesRef = React.useRef(animationNames);
|
|
6587
6587
|
const [spriteData, setSpriteData] = useState(null);
|
|
6588
|
-
const [spriteTexture, setSpriteTexture] = React
|
|
6589
|
-
const textureLoader = React
|
|
6588
|
+
const [spriteTexture, setSpriteTexture] = React.useState(new Texture$2());
|
|
6589
|
+
const textureLoader = React.useMemo(() => new TextureLoader(), []);
|
|
6590
6590
|
const [spriteObj, setSpriteObj] = useState(null);
|
|
6591
|
-
const calculateAspectRatio = React
|
|
6591
|
+
const calculateAspectRatio = React.useCallback((width, height, factor) => {
|
|
6592
6592
|
const adaptedHeight = height * (viewportRef.current.aspect > width / height ? viewportRef.current.width / width : viewportRef.current.height / height);
|
|
6593
6593
|
const scaleX = width * (viewportRef.current.aspect > width / height ? viewportRef.current.width / width : viewportRef.current.height / height) * factor;
|
|
6594
6594
|
const scaleY = adaptedHeight * factor;
|
|
@@ -6601,7 +6601,7 @@ function useSpriteLoader(input, json, animationNames, numberOfFrames, onLoad, ca
|
|
|
6601
6601
|
}
|
|
6602
6602
|
return new Vector3$2(finalMaxScaleW, finalMaxScaleH, 1);
|
|
6603
6603
|
}, []);
|
|
6604
|
-
const getRowsAndColumns = React
|
|
6604
|
+
const getRowsAndColumns = React.useCallback((texture, totalFrames$1) => {
|
|
6605
6605
|
if (texture.image) {
|
|
6606
6606
|
const canvas = document.createElement("canvas");
|
|
6607
6607
|
const ctx = canvas.getContext("2d", canvasRenderingContext2DSettings);
|
|
@@ -6646,7 +6646,7 @@ function useSpriteLoader(input, json, animationNames, numberOfFrames, onLoad, ca
|
|
|
6646
6646
|
emptyFrames: []
|
|
6647
6647
|
};
|
|
6648
6648
|
}, [canvasRenderingContext2DSettings]);
|
|
6649
|
-
const calculateScaleRatio = React
|
|
6649
|
+
const calculateScaleRatio = React.useCallback((frames) => {
|
|
6650
6650
|
const processFrameArray = (frameArray) => {
|
|
6651
6651
|
let largestFrame = null;
|
|
6652
6652
|
for (const frame of frameArray) {
|
|
@@ -6675,7 +6675,7 @@ function useSpriteLoader(input, json, animationNames, numberOfFrames, onLoad, ca
|
|
|
6675
6675
|
return result;
|
|
6676
6676
|
}
|
|
6677
6677
|
}, []);
|
|
6678
|
-
const parseFrames = React
|
|
6678
|
+
const parseFrames = React.useCallback(() => {
|
|
6679
6679
|
const sprites = {};
|
|
6680
6680
|
const data = spriteDataRef.current;
|
|
6681
6681
|
const delimiters = animationFramesRef.current;
|
|
@@ -6744,7 +6744,7 @@ function useSpriteLoader(input, json, animationNames, numberOfFrames, onLoad, ca
|
|
|
6744
6744
|
}
|
|
6745
6745
|
return [];
|
|
6746
6746
|
}, [calculateScaleRatio, spriteDataRef]);
|
|
6747
|
-
const parseSpriteData = React
|
|
6747
|
+
const parseSpriteData = React.useCallback((json$1, _spriteTexture) => {
|
|
6748
6748
|
let aspect = new Vector3$2(1, 1, 1);
|
|
6749
6749
|
if (json$1 === null) {
|
|
6750
6750
|
if (_spriteTexture && numberOfFrames) {
|
|
@@ -6822,7 +6822,7 @@ function useSpriteLoader(input, json, animationNames, numberOfFrames, onLoad, ca
|
|
|
6822
6822
|
/**
|
|
6823
6823
|
*
|
|
6824
6824
|
*/
|
|
6825
|
-
const loadJsonAndTextureAndExecuteCallback = React
|
|
6825
|
+
const loadJsonAndTextureAndExecuteCallback = React.useCallback((jsonUrl, textureUrl, callback) => {
|
|
6826
6826
|
const jsonPromise = fetch(jsonUrl).then((response) => response.json());
|
|
6827
6827
|
const texturePromise = new Promise((resolve) => {
|
|
6828
6828
|
textureLoader.load(textureUrl, resolve);
|
|
@@ -6831,13 +6831,13 @@ function useSpriteLoader(input, json, animationNames, numberOfFrames, onLoad, ca
|
|
|
6831
6831
|
callback(response[0], response[1]);
|
|
6832
6832
|
});
|
|
6833
6833
|
}, [textureLoader]);
|
|
6834
|
-
const loadStandaloneSprite = React
|
|
6834
|
+
const loadStandaloneSprite = React.useCallback((textureUrl) => {
|
|
6835
6835
|
if (!textureUrl && !inputRef.current) throw new Error("Either textureUrl or input must be provided");
|
|
6836
6836
|
const validUrl = textureUrl ?? inputRef.current;
|
|
6837
6837
|
if (!validUrl) throw new Error("A valid texture URL must be provided");
|
|
6838
6838
|
textureLoader.load(validUrl, (texture) => parseSpriteData(null, texture));
|
|
6839
6839
|
}, [textureLoader, parseSpriteData]);
|
|
6840
|
-
const loadJsonAndTexture = React
|
|
6840
|
+
const loadJsonAndTexture = React.useCallback((textureUrl, jsonUrl) => {
|
|
6841
6841
|
if (jsonUrl && textureUrl) loadJsonAndTextureAndExecuteCallback(jsonUrl, textureUrl, parseSpriteData);
|
|
6842
6842
|
else loadStandaloneSprite(textureUrl);
|
|
6843
6843
|
}, [
|
|
@@ -6845,7 +6845,7 @@ function useSpriteLoader(input, json, animationNames, numberOfFrames, onLoad, ca
|
|
|
6845
6845
|
loadStandaloneSprite,
|
|
6846
6846
|
parseSpriteData
|
|
6847
6847
|
]);
|
|
6848
|
-
React
|
|
6848
|
+
React.useLayoutEffect(() => {
|
|
6849
6849
|
if (jsonRef.current && inputRef.current) loadJsonAndTextureAndExecuteCallback(jsonRef.current, inputRef.current, parseSpriteData);
|
|
6850
6850
|
else if (inputRef.current) loadStandaloneSprite();
|
|
6851
6851
|
const _inputRef = inputRef.current;
|
|
@@ -6857,7 +6857,7 @@ function useSpriteLoader(input, json, animationNames, numberOfFrames, onLoad, ca
|
|
|
6857
6857
|
loadStandaloneSprite,
|
|
6858
6858
|
parseSpriteData
|
|
6859
6859
|
]);
|
|
6860
|
-
React
|
|
6860
|
+
React.useLayoutEffect(() => {
|
|
6861
6861
|
onLoad?.(spriteTexture, spriteData ?? null);
|
|
6862
6862
|
}, [
|
|
6863
6863
|
spriteTexture,
|
|
@@ -6874,9 +6874,9 @@ useSpriteLoader.clear = (input) => useLoader.clear(TextureLoader, input);
|
|
|
6874
6874
|
|
|
6875
6875
|
//#endregion
|
|
6876
6876
|
//#region src/core/Helpers/SpriteAnimator/SpriteAnimator.tsx
|
|
6877
|
-
const context$4 = React
|
|
6877
|
+
const context$4 = React.createContext(null);
|
|
6878
6878
|
function useSpriteAnimator() {
|
|
6879
|
-
return React
|
|
6879
|
+
return React.useContext(context$4);
|
|
6880
6880
|
}
|
|
6881
6881
|
function isSpriteData(data) {
|
|
6882
6882
|
return data !== null && "meta" in data && "frames" in data;
|
|
@@ -6897,29 +6897,29 @@ const geometry = /* @__PURE__ */ new PlaneGeometry$1(1, 1);
|
|
|
6897
6897
|
* />
|
|
6898
6898
|
* ```
|
|
6899
6899
|
*/
|
|
6900
|
-
const SpriteAnimator = /* @__PURE__ */ React
|
|
6900
|
+
const SpriteAnimator = /* @__PURE__ */ React.forwardRef(({ startFrame = 0, endFrame, fps = 30, frameName = "", textureDataURL, textureImageURL, loop = false, numberOfFrames = 1, autoPlay = true, animationNames, onStart, onEnd, onLoopEnd, onFrame, play, pause = false, flipX = false, alphaTest = 0, children, asSprite = false, offset, playBackwards = false, resetOnEnd = false, maxItems = 1, instanceItems = [[
|
|
6901
6901
|
0,
|
|
6902
6902
|
0,
|
|
6903
6903
|
0
|
|
6904
6904
|
]], spriteDataset, canvasRenderingContext2DSettings, roundFramePosition = false, meshProps = {}, ...props }, fref) => {
|
|
6905
|
-
const ref = React
|
|
6906
|
-
const spriteData = React
|
|
6907
|
-
const matRef = React
|
|
6908
|
-
const spriteRef = React
|
|
6909
|
-
const timerOffset = React
|
|
6910
|
-
const currentFrame = React
|
|
6911
|
-
const currentFrameName = React
|
|
6905
|
+
const ref = React.useRef(new Group());
|
|
6906
|
+
const spriteData = React.useRef(null);
|
|
6907
|
+
const matRef = React.useRef(null);
|
|
6908
|
+
const spriteRef = React.useRef(null);
|
|
6909
|
+
const timerOffset = React.useRef(window.performance.now());
|
|
6910
|
+
const currentFrame = React.useRef(startFrame);
|
|
6911
|
+
const currentFrameName = React.useRef(frameName);
|
|
6912
6912
|
const fpsInterval = fps > 0 ? 1e3 / fps : 0;
|
|
6913
|
-
const [spriteTexture, setSpriteTexture] = React
|
|
6914
|
-
const totalFrames = React
|
|
6915
|
-
const [aspect, setAspect] = React
|
|
6913
|
+
const [spriteTexture, setSpriteTexture] = React.useState(new Texture$2());
|
|
6914
|
+
const totalFrames = React.useRef(0);
|
|
6915
|
+
const [aspect, setAspect] = React.useState(new Vector3$2(1, 1, 1));
|
|
6916
6916
|
const flipOffset = flipX ? -1 : 1;
|
|
6917
|
-
const pauseRef = React
|
|
6918
|
-
const pos = React
|
|
6919
|
-
const softEnd = React
|
|
6917
|
+
const pauseRef = React.useRef(pause);
|
|
6918
|
+
const pos = React.useRef(offset);
|
|
6919
|
+
const softEnd = React.useRef(false);
|
|
6920
6920
|
const { spriteObj, loadJsonAndTexture } = useSpriteLoader(null, null, animationNames, numberOfFrames, void 0, canvasRenderingContext2DSettings);
|
|
6921
|
-
const frameNameRef = React
|
|
6922
|
-
const parseSpriteDataLite = React
|
|
6921
|
+
const frameNameRef = React.useRef(frameName);
|
|
6922
|
+
const parseSpriteDataLite = React.useCallback((textureData, data) => {
|
|
6923
6923
|
if (data === null) {
|
|
6924
6924
|
if (numberOfFrames) {
|
|
6925
6925
|
totalFrames.current = numberOfFrames;
|
|
@@ -6938,7 +6938,7 @@ const SpriteAnimator = /* @__PURE__ */ React$1.forwardRef(({ startFrame = 0, end
|
|
|
6938
6938
|
}
|
|
6939
6939
|
setSpriteTexture(textureData);
|
|
6940
6940
|
}, [numberOfFrames, playBackwards]);
|
|
6941
|
-
const modifySpritePosition = React
|
|
6941
|
+
const modifySpritePosition = React.useCallback(() => {
|
|
6942
6942
|
if (!spriteData.current) return;
|
|
6943
6943
|
const { meta: { size: metaInfo }, frames } = spriteData.current;
|
|
6944
6944
|
const { w: frameW, h: frameH } = Array.isArray(frames) ? frames[0].sourceSize : frameName ? frames[frameName] ? frames[frameName][0].sourceSize : {
|
|
@@ -6967,15 +6967,15 @@ const SpriteAnimator = /* @__PURE__ */ React$1.forwardRef(({ startFrame = 0, end
|
|
|
6967
6967
|
frameName,
|
|
6968
6968
|
onStart
|
|
6969
6969
|
]);
|
|
6970
|
-
const state = React
|
|
6970
|
+
const state = React.useMemo(() => ({
|
|
6971
6971
|
current: pos.current,
|
|
6972
6972
|
offset: pos.current,
|
|
6973
6973
|
imageUrl: textureImageURL,
|
|
6974
6974
|
hasEnded: false,
|
|
6975
6975
|
ref: fref
|
|
6976
6976
|
}), [textureImageURL, fref]);
|
|
6977
|
-
React
|
|
6978
|
-
React
|
|
6977
|
+
React.useImperativeHandle(fref, () => ref.current, []);
|
|
6978
|
+
React.useLayoutEffect(() => {
|
|
6979
6979
|
pos.current = offset;
|
|
6980
6980
|
}, [offset]);
|
|
6981
6981
|
const calculateAspectRatio = (width, height) => {
|
|
@@ -6985,7 +6985,7 @@ const SpriteAnimator = /* @__PURE__ */ React$1.forwardRef(({ startFrame = 0, end
|
|
|
6985
6985
|
spriteRef.current?.scale.copy(ret);
|
|
6986
6986
|
return ret;
|
|
6987
6987
|
};
|
|
6988
|
-
React
|
|
6988
|
+
React.useEffect(() => {
|
|
6989
6989
|
if (spriteDataset) parseSpriteDataLite(spriteDataset?.spriteTexture?.clone(), spriteDataset.spriteData);
|
|
6990
6990
|
else if (textureImageURL && textureDataURL) loadJsonAndTexture(textureImageURL, textureDataURL);
|
|
6991
6991
|
}, [
|
|
@@ -6995,25 +6995,25 @@ const SpriteAnimator = /* @__PURE__ */ React$1.forwardRef(({ startFrame = 0, end
|
|
|
6995
6995
|
textureImageURL,
|
|
6996
6996
|
parseSpriteDataLite
|
|
6997
6997
|
]);
|
|
6998
|
-
React
|
|
6998
|
+
React.useEffect(() => {
|
|
6999
6999
|
if (spriteObj) parseSpriteDataLite(spriteObj?.spriteTexture?.clone(), spriteObj?.spriteData);
|
|
7000
7000
|
}, [spriteObj, parseSpriteDataLite]);
|
|
7001
|
-
React
|
|
7001
|
+
React.useEffect(() => {
|
|
7002
7002
|
state.hasEnded = false;
|
|
7003
7003
|
if (spriteData.current && playBackwards === true) currentFrame.current = (spriteData.current.frames.length ?? 0) - 1;
|
|
7004
7004
|
else currentFrame.current = 0;
|
|
7005
7005
|
}, [playBackwards, state]);
|
|
7006
|
-
React
|
|
7006
|
+
React.useLayoutEffect(() => {
|
|
7007
7007
|
modifySpritePosition();
|
|
7008
7008
|
}, [
|
|
7009
7009
|
spriteTexture,
|
|
7010
7010
|
flipX,
|
|
7011
7011
|
modifySpritePosition
|
|
7012
7012
|
]);
|
|
7013
|
-
React
|
|
7013
|
+
React.useEffect(() => {
|
|
7014
7014
|
if (autoPlay) pauseRef.current = false;
|
|
7015
7015
|
}, [autoPlay]);
|
|
7016
|
-
React
|
|
7016
|
+
React.useLayoutEffect(() => {
|
|
7017
7017
|
if (currentFrameName.current !== frameName && frameName) {
|
|
7018
7018
|
currentFrame.current = 0;
|
|
7019
7019
|
currentFrameName.current = frameName;
|
|
@@ -7194,15 +7194,15 @@ const SpriteAnimator = /* @__PURE__ */ React$1.forwardRef(({ startFrame = 0, end
|
|
|
7194
7194
|
* ```
|
|
7195
7195
|
*/
|
|
7196
7196
|
function useAnimations(clips, root) {
|
|
7197
|
-
const ref = React
|
|
7198
|
-
const [actualRef] = React
|
|
7199
|
-
const [mixer] = React
|
|
7200
|
-
React
|
|
7197
|
+
const ref = React.useRef(null);
|
|
7198
|
+
const [actualRef] = React.useState(() => root ? root instanceof Object3D ? { current: root } : root : ref);
|
|
7199
|
+
const [mixer] = React.useState(() => new AnimationMixer(void 0));
|
|
7200
|
+
React.useLayoutEffect(() => {
|
|
7201
7201
|
if (root) actualRef.current = root instanceof Object3D ? root : root.current;
|
|
7202
7202
|
mixer._root = actualRef.current;
|
|
7203
7203
|
});
|
|
7204
|
-
const lazyActions = React
|
|
7205
|
-
const api = React
|
|
7204
|
+
const lazyActions = React.useRef({});
|
|
7205
|
+
const api = React.useMemo(() => {
|
|
7206
7206
|
const actions = {};
|
|
7207
7207
|
clips.forEach((clip) => Object.defineProperty(actions, clip.name, {
|
|
7208
7208
|
enumerable: true,
|
|
@@ -7220,7 +7220,7 @@ function useAnimations(clips, root) {
|
|
|
7220
7220
|
};
|
|
7221
7221
|
}, [clips]);
|
|
7222
7222
|
useFrame((state, delta) => mixer.update(delta));
|
|
7223
|
-
React
|
|
7223
|
+
React.useEffect(() => {
|
|
7224
7224
|
const currentRoot = actualRef.current;
|
|
7225
7225
|
return () => {
|
|
7226
7226
|
lazyActions.current = {};
|
|
@@ -7253,9 +7253,9 @@ function useAnimations(clips, root) {
|
|
|
7253
7253
|
* ```
|
|
7254
7254
|
*/
|
|
7255
7255
|
function useContextBridge(...contexts) {
|
|
7256
|
-
const cRef = React
|
|
7257
|
-
cRef.current = contexts.map((context$10) => React
|
|
7258
|
-
return React
|
|
7256
|
+
const cRef = React.useRef([]);
|
|
7257
|
+
cRef.current = contexts.map((context$10) => React.useContext(context$10));
|
|
7258
|
+
return React.useMemo(() => ({ children }) => contexts.reduceRight((acc, Context$1, i$1) => /* @__PURE__ */ jsx(Context$1.Provider, {
|
|
7259
7259
|
value: cRef.current[i$1],
|
|
7260
7260
|
children: acc
|
|
7261
7261
|
}), children), []);
|
|
@@ -7301,7 +7301,7 @@ function createSpread(child, { keys = [
|
|
|
7301
7301
|
...spread,
|
|
7302
7302
|
children: inject(child)
|
|
7303
7303
|
};
|
|
7304
|
-
else if (React
|
|
7304
|
+
else if (React.isValidElement(inject)) spread = {
|
|
7305
7305
|
...spread,
|
|
7306
7306
|
children: inject
|
|
7307
7307
|
};
|
|
@@ -7344,7 +7344,7 @@ function createSpread(child, { keys = [
|
|
|
7344
7344
|
* } />
|
|
7345
7345
|
* ```
|
|
7346
7346
|
*/
|
|
7347
|
-
const Clone = /* @__PURE__ */ React
|
|
7347
|
+
const Clone = /* @__PURE__ */ React.forwardRef(({ isChild = false, object, children, deep, castShadow, receiveShadow, inject, keys, ...props }, forwardRef$1) => {
|
|
7348
7348
|
const config = {
|
|
7349
7349
|
keys,
|
|
7350
7350
|
deep,
|
|
@@ -7352,7 +7352,7 @@ const Clone = /* @__PURE__ */ React$1.forwardRef(({ isChild = false, object, chi
|
|
|
7352
7352
|
castShadow,
|
|
7353
7353
|
receiveShadow
|
|
7354
7354
|
};
|
|
7355
|
-
object = React
|
|
7355
|
+
object = React.useMemo(() => {
|
|
7356
7356
|
if (isChild === false && !Array.isArray(object)) {
|
|
7357
7357
|
let isSkinned = false;
|
|
7358
7358
|
object.traverse((object$1) => {
|
|
@@ -7414,9 +7414,9 @@ const Clone = /* @__PURE__ */ React$1.forwardRef(({ isChild = false, object, chi
|
|
|
7414
7414
|
* ```
|
|
7415
7415
|
*/
|
|
7416
7416
|
const ComputedAttribute = ({ compute, name, ...props }) => {
|
|
7417
|
-
const [bufferAttribute] = React
|
|
7418
|
-
const primitive = React
|
|
7419
|
-
React
|
|
7417
|
+
const [bufferAttribute] = React.useState(() => new BufferAttribute(new Float32Array(0), 1));
|
|
7418
|
+
const primitive = React.useRef(null);
|
|
7419
|
+
React.useLayoutEffect(() => {
|
|
7420
7420
|
if (primitive.current) {
|
|
7421
7421
|
const prim = primitive.current;
|
|
7422
7422
|
const attr = compute(prim.parent ?? prim.__r3f?.parent?.object);
|
|
@@ -7451,14 +7451,14 @@ const ComputedAttribute = ({ compute, name, ...props }) => {
|
|
|
7451
7451
|
* </Center>
|
|
7452
7452
|
* ```
|
|
7453
7453
|
*/
|
|
7454
|
-
const Center = /* @__PURE__ */ React
|
|
7455
|
-
const ref = React
|
|
7456
|
-
const outer = React
|
|
7457
|
-
const inner = React
|
|
7458
|
-
const [box3] = React
|
|
7459
|
-
const [center] = React
|
|
7460
|
-
const [sphere] = React
|
|
7461
|
-
React
|
|
7454
|
+
const Center = /* @__PURE__ */ React.forwardRef(function Center$1({ children, object, disable, disableX, disableY, disableZ, left, right, top, bottom, front, back, onCentered, precise = true, cacheKey = 0, ...props }, fRef) {
|
|
7455
|
+
const ref = React.useRef(null);
|
|
7456
|
+
const outer = React.useRef(null);
|
|
7457
|
+
const inner = React.useRef(null);
|
|
7458
|
+
const [box3] = React.useState(() => new Box3());
|
|
7459
|
+
const [center] = React.useState(() => new Vector3$2());
|
|
7460
|
+
const [sphere] = React.useState(() => new Sphere$1());
|
|
7461
|
+
React.useLayoutEffect(() => {
|
|
7462
7462
|
outer.current.matrixWorld.identity();
|
|
7463
7463
|
box3.setFromObject(object ?? inner.current, precise);
|
|
7464
7464
|
const width = box3.max.x - box3.min.x;
|
|
@@ -7502,7 +7502,7 @@ const Center = /* @__PURE__ */ React$1.forwardRef(function Center$1({ children,
|
|
|
7502
7502
|
center,
|
|
7503
7503
|
sphere
|
|
7504
7504
|
]);
|
|
7505
|
-
React
|
|
7505
|
+
React.useImperativeHandle(fRef, () => ref.current, []);
|
|
7506
7506
|
return /* @__PURE__ */ jsx("group", {
|
|
7507
7507
|
ref,
|
|
7508
7508
|
...props,
|
|
@@ -7521,18 +7521,18 @@ const Center = /* @__PURE__ */ React$1.forwardRef(function Center$1({ children,
|
|
|
7521
7521
|
/**
|
|
7522
7522
|
* A simple counter example component. Click to increment, meta-click to decrement.
|
|
7523
7523
|
*/
|
|
7524
|
-
const Example = /* @__PURE__ */ React
|
|
7525
|
-
const [counter, setCounter] = React
|
|
7526
|
-
const incr = React
|
|
7527
|
-
const decr = React
|
|
7528
|
-
const api = React
|
|
7524
|
+
const Example = /* @__PURE__ */ React.forwardRef(({ font, color = "#cbcbcb", bevelSize = .04, debug = false, children, ...props }, fref) => {
|
|
7525
|
+
const [counter, setCounter] = React.useState(0);
|
|
7526
|
+
const incr = React.useCallback((x = 1) => setCounter(counter + x), [counter]);
|
|
7527
|
+
const decr = React.useCallback((x = 1) => setCounter(counter - x), [counter]);
|
|
7528
|
+
const api = React.useMemo(() => ({
|
|
7529
7529
|
incr,
|
|
7530
7530
|
decr
|
|
7531
7531
|
}), [incr, decr]);
|
|
7532
|
-
React
|
|
7532
|
+
React.useImperativeHandle(fref, () => api, [api]);
|
|
7533
7533
|
return /* @__PURE__ */ jsxs("group", {
|
|
7534
7534
|
...props,
|
|
7535
|
-
children: [/* @__PURE__ */ jsx(React
|
|
7535
|
+
children: [/* @__PURE__ */ jsx(React.Suspense, {
|
|
7536
7536
|
fallback: null,
|
|
7537
7537
|
children: /* @__PURE__ */ jsx(Center, {
|
|
7538
7538
|
top: true,
|
|
@@ -7554,7 +7554,7 @@ const Example = /* @__PURE__ */ React$1.forwardRef(({ font, color = "#cbcbcb", b
|
|
|
7554
7554
|
//#endregion
|
|
7555
7555
|
//#region src/core/Helpers/Sampler/Sampler.tsx
|
|
7556
7556
|
function useSurfaceSampler(mesh, count = 16, transform, weight, instanceMesh) {
|
|
7557
|
-
const [buffer, setBuffer] = React
|
|
7557
|
+
const [buffer, setBuffer] = React.useState(() => {
|
|
7558
7558
|
const arr = Array.from({ length: count }, () => [
|
|
7559
7559
|
1,
|
|
7560
7560
|
0,
|
|
@@ -7575,7 +7575,7 @@ function useSurfaceSampler(mesh, count = 16, transform, weight, instanceMesh) {
|
|
|
7575
7575
|
]).flat();
|
|
7576
7576
|
return new InstancedBufferAttribute(Float32Array.from(arr), 16);
|
|
7577
7577
|
});
|
|
7578
|
-
React
|
|
7578
|
+
React.useLayoutEffect(() => {
|
|
7579
7579
|
if (typeof mesh.current === "undefined") return;
|
|
7580
7580
|
const sampler = new MeshSurfaceSampler(mesh.current);
|
|
7581
7581
|
if (weight) sampler.setWeightAttribute(weight);
|
|
@@ -7648,10 +7648,10 @@ function useSurfaceSampler(mesh, count = 16, transform, weight, instanceMesh) {
|
|
|
7648
7648
|
* ```
|
|
7649
7649
|
*/
|
|
7650
7650
|
function Sampler({ children, weight, transform, instances, mesh, count = 16, ...props }) {
|
|
7651
|
-
const group = React
|
|
7652
|
-
const instancedRef = React
|
|
7653
|
-
const meshToSampleRef = React
|
|
7654
|
-
React
|
|
7651
|
+
const group = React.useRef(null);
|
|
7652
|
+
const instancedRef = React.useRef(null);
|
|
7653
|
+
const meshToSampleRef = React.useRef(null);
|
|
7654
|
+
React.useLayoutEffect(() => {
|
|
7655
7655
|
instancedRef.current = instances?.current ?? group.current.children.find((c) => c.hasOwnProperty("instanceMatrix"));
|
|
7656
7656
|
meshToSampleRef.current = mesh?.current ?? group.current.children.find((c) => c.type === "Mesh");
|
|
7657
7657
|
}, [
|
|
@@ -7729,7 +7729,7 @@ function useDepthBuffer({ size = 256, frames = Infinity } = {}) {
|
|
|
7729
7729
|
const { width, height } = useThree((state) => state.size);
|
|
7730
7730
|
const w = size || width * dpr;
|
|
7731
7731
|
const h = size || height * dpr;
|
|
7732
|
-
const depthConfig = React
|
|
7732
|
+
const depthConfig = React.useMemo(() => {
|
|
7733
7733
|
const depthTexture = new DepthTexture(w, h);
|
|
7734
7734
|
depthTexture.format = DepthFormat;
|
|
7735
7735
|
depthTexture.type = UnsignedShortType;
|
|
@@ -7835,23 +7835,23 @@ const defaultDataInterpolation = (p) => `Loading ${p.toFixed(2)}%`;
|
|
|
7835
7835
|
*/
|
|
7836
7836
|
function Loader({ containerStyles, innerStyles, barStyles, dataStyles, dataInterpolation = defaultDataInterpolation, initialState = (active$1) => active$1 }) {
|
|
7837
7837
|
const { active, progress } = useProgress();
|
|
7838
|
-
const progressRef = React
|
|
7839
|
-
const rafRef = React
|
|
7840
|
-
const progressSpanRef = React
|
|
7841
|
-
const [shown, setShown] = React
|
|
7842
|
-
React
|
|
7838
|
+
const progressRef = React.useRef(0);
|
|
7839
|
+
const rafRef = React.useRef(0);
|
|
7840
|
+
const progressSpanRef = React.useRef(null);
|
|
7841
|
+
const [shown, setShown] = React.useState(initialState(active));
|
|
7842
|
+
React.useEffect(() => {
|
|
7843
7843
|
let t;
|
|
7844
7844
|
if (active !== shown) t = setTimeout(() => setShown(active), 300);
|
|
7845
7845
|
return () => clearTimeout(t);
|
|
7846
7846
|
}, [shown, active]);
|
|
7847
|
-
const updateProgress = React
|
|
7847
|
+
const updateProgress = React.useCallback(() => {
|
|
7848
7848
|
if (!progressSpanRef.current) return;
|
|
7849
7849
|
progressRef.current += (progress - progressRef.current) / 2;
|
|
7850
7850
|
if (progressRef.current > .95 * progress || progress === 100) progressRef.current = progress;
|
|
7851
7851
|
progressSpanRef.current.innerText = dataInterpolation(progressRef.current);
|
|
7852
7852
|
if (progressRef.current < progress) rafRef.current = requestAnimationFrame(updateProgress);
|
|
7853
7853
|
}, [dataInterpolation, progress]);
|
|
7854
|
-
React
|
|
7854
|
+
React.useEffect(() => {
|
|
7855
7855
|
updateProgress();
|
|
7856
7856
|
return () => cancelAnimationFrame(rafRef.current);
|
|
7857
7857
|
}, [updateProgress]);
|
|
@@ -7937,7 +7937,7 @@ function Preload({ all, scene, camera }) {
|
|
|
7937
7937
|
const gl = useThree(({ gl: gl$1 }) => gl$1);
|
|
7938
7938
|
const dCamera = useThree(({ camera: camera$1 }) => camera$1);
|
|
7939
7939
|
const dScene = useThree(({ scene: scene$1 }) => scene$1);
|
|
7940
|
-
React
|
|
7940
|
+
React.useLayoutEffect(() => {
|
|
7941
7941
|
const invisible = [];
|
|
7942
7942
|
if (all) (scene || dScene).traverse((object) => {
|
|
7943
7943
|
if (object.visible === false) {
|
|
@@ -8306,7 +8306,7 @@ useGLTF.setDecoderPath = (path) => {
|
|
|
8306
8306
|
* <Gltf src="/model.glb" />
|
|
8307
8307
|
* ```
|
|
8308
8308
|
*/
|
|
8309
|
-
const Gltf = /* @__PURE__ */ React
|
|
8309
|
+
const Gltf = /* @__PURE__ */ React.forwardRef(({ src, useDraco, useMeshOpt, extendLoader, ...props }, ref) => {
|
|
8310
8310
|
const { scene } = useGLTF(src, useDraco, useMeshOpt, extendLoader);
|
|
8311
8311
|
return /* @__PURE__ */ jsx(Clone, {
|
|
8312
8312
|
ref,
|
|
@@ -8411,14 +8411,14 @@ function AdaptiveDpr({ pixelated }) {
|
|
|
8411
8411
|
const current = useThree((state) => state.performance.current);
|
|
8412
8412
|
const initialDpr = useThree((state) => state.viewport.initialDpr);
|
|
8413
8413
|
const setDpr = useThree((state) => state.setDpr);
|
|
8414
|
-
React
|
|
8414
|
+
React.useEffect(() => {
|
|
8415
8415
|
const domElement = gl.domElement;
|
|
8416
8416
|
return () => {
|
|
8417
8417
|
if (active) setDpr(initialDpr);
|
|
8418
8418
|
if (pixelated && domElement) domElement.style.imageRendering = "auto";
|
|
8419
8419
|
};
|
|
8420
8420
|
}, []);
|
|
8421
|
-
React
|
|
8421
|
+
React.useEffect(() => {
|
|
8422
8422
|
setDpr(current * initialDpr);
|
|
8423
8423
|
if (pixelated && gl.domElement) gl.domElement.style.imageRendering = current === 1 ? "auto" : "pixelated";
|
|
8424
8424
|
}, [current]);
|
|
@@ -8440,11 +8440,11 @@ function AdaptiveEvents() {
|
|
|
8440
8440
|
const get = useThree((state) => state.get);
|
|
8441
8441
|
const setEvents = useThree((state) => state.setEvents);
|
|
8442
8442
|
const current = useThree((state) => state.performance.current);
|
|
8443
|
-
React
|
|
8443
|
+
React.useEffect(() => {
|
|
8444
8444
|
const enabled = get().events.enabled;
|
|
8445
8445
|
return () => setEvents({ enabled });
|
|
8446
8446
|
}, []);
|
|
8447
|
-
React
|
|
8447
|
+
React.useEffect(() => setEvents({ enabled: current === 1 }), [current]);
|
|
8448
8448
|
return null;
|
|
8449
8449
|
}
|
|
8450
8450
|
|
|
@@ -8620,8 +8620,8 @@ function call(ref, value) {
|
|
|
8620
8620
|
else if (ref != null) ref.current = value;
|
|
8621
8621
|
}
|
|
8622
8622
|
function useEffectfulState(fn, deps = [], cb) {
|
|
8623
|
-
const [state, set] = React
|
|
8624
|
-
React
|
|
8623
|
+
const [state, set] = React.useState();
|
|
8624
|
+
React.useLayoutEffect(() => {
|
|
8625
8625
|
const value = fn();
|
|
8626
8626
|
set(value);
|
|
8627
8627
|
call(cb, value);
|
|
@@ -8643,7 +8643,7 @@ var import_stats_min = /* @__PURE__ */ __toESM(require_stats_min());
|
|
|
8643
8643
|
*/
|
|
8644
8644
|
function Stats({ showPanel = 0, className, parent }) {
|
|
8645
8645
|
const stats = useEffectfulState(() => new import_stats_min.default(), []);
|
|
8646
|
-
React
|
|
8646
|
+
React.useEffect(() => {
|
|
8647
8647
|
if (stats) {
|
|
8648
8648
|
const node = parent && parent.current || document.body;
|
|
8649
8649
|
stats.showPanel(showPanel);
|
|
@@ -8678,13 +8678,13 @@ function Stats({ showPanel = 0, className, parent }) {
|
|
|
8678
8678
|
* <Canvas><StatsGl /></Canvas>
|
|
8679
8679
|
* ```
|
|
8680
8680
|
*/
|
|
8681
|
-
const StatsGl = /* @__PURE__ */ React
|
|
8681
|
+
const StatsGl = /* @__PURE__ */ React.forwardRef(function StatsGl$1({ className, parent, id, clearStatsGlStyle, ...props }, fref) {
|
|
8682
8682
|
const { renderer } = useThree();
|
|
8683
|
-
const stats = React
|
|
8683
|
+
const stats = React.useMemo(() => {
|
|
8684
8684
|
return new Stats$1({ ...props });
|
|
8685
8685
|
}, [renderer]);
|
|
8686
|
-
React
|
|
8687
|
-
React
|
|
8686
|
+
React.useImperativeHandle(fref, () => stats.domElement, [stats]);
|
|
8687
|
+
React.useEffect(() => {
|
|
8688
8688
|
if (stats) {
|
|
8689
8689
|
const node = parent && parent.current || document.body;
|
|
8690
8690
|
node?.appendChild(stats.domElement);
|
|
@@ -8738,11 +8738,11 @@ const StatsGl = /* @__PURE__ */ React$1.forwardRef(function StatsGl$1({ classNam
|
|
|
8738
8738
|
* </mesh>
|
|
8739
8739
|
* ```
|
|
8740
8740
|
*/
|
|
8741
|
-
const RenderCubeTexture = /* @__PURE__ */ React
|
|
8741
|
+
const RenderCubeTexture = /* @__PURE__ */ React.forwardRef(({ children, compute, renderPriority = -1, eventPriority = 0, frames = Infinity, stencilBuffer = false, depthBuffer = true, generateMipmaps = false, resolution = 896, near = .1, far = 1e3, flip = false, position: position$1, rotation: rotation$2, scale: scale$2, quaternion, matrix: matrix$1, matrixAutoUpdate, ...props }, forwardRef$1) => {
|
|
8742
8742
|
const { size, viewport } = useThree();
|
|
8743
8743
|
const fboSize = Math.max((resolution || size.width) * viewport.dpr, (resolution || size.height) * viewport.dpr);
|
|
8744
|
-
const fboRef = React
|
|
8745
|
-
const cameraRef = React
|
|
8744
|
+
const fboRef = React.useRef(null);
|
|
8745
|
+
const cameraRef = React.useRef(null);
|
|
8746
8746
|
if (!fboRef.current) {
|
|
8747
8747
|
const settings = {
|
|
8748
8748
|
stencilBuffer,
|
|
@@ -8766,9 +8766,9 @@ const RenderCubeTexture = /* @__PURE__ */ React$1.forwardRef(({ children, comput
|
|
|
8766
8766
|
const fboA = fboRef.current.a;
|
|
8767
8767
|
const fboB = fboRef.current.b;
|
|
8768
8768
|
const camera = cameraRef.current;
|
|
8769
|
-
const readBufferIndex = React
|
|
8770
|
-
const displayTextureRef = React
|
|
8771
|
-
React
|
|
8769
|
+
const readBufferIndex = React.useRef(0);
|
|
8770
|
+
const displayTextureRef = React.useRef(fboA.texture);
|
|
8771
|
+
React.useLayoutEffect(() => {
|
|
8772
8772
|
if (position$1) {
|
|
8773
8773
|
if (Array.isArray(position$1)) camera.position.set(...position$1);
|
|
8774
8774
|
else if (position$1 instanceof Vector3$2) camera.position.copy(position$1);
|
|
@@ -8797,7 +8797,7 @@ const RenderCubeTexture = /* @__PURE__ */ React$1.forwardRef(({ children, comput
|
|
|
8797
8797
|
matrix$1,
|
|
8798
8798
|
matrixAutoUpdate
|
|
8799
8799
|
]);
|
|
8800
|
-
React
|
|
8800
|
+
React.useEffect(() => {
|
|
8801
8801
|
return () => {
|
|
8802
8802
|
if (fboRef.current) {
|
|
8803
8803
|
fboRef.current.a.dispose();
|
|
@@ -8807,8 +8807,8 @@ const RenderCubeTexture = /* @__PURE__ */ React$1.forwardRef(({ children, comput
|
|
|
8807
8807
|
cameraRef.current = null;
|
|
8808
8808
|
};
|
|
8809
8809
|
}, []);
|
|
8810
|
-
const [vScene] = React
|
|
8811
|
-
React
|
|
8810
|
+
const [vScene] = React.useState(() => new Scene$1());
|
|
8811
|
+
React.useImperativeHandle(forwardRef$1, () => ({
|
|
8812
8812
|
scene: vScene,
|
|
8813
8813
|
get fbo() {
|
|
8814
8814
|
return readBufferIndex.current === 0 ? fboA : fboB;
|
|
@@ -8841,9 +8841,9 @@ const RenderCubeTexture = /* @__PURE__ */ React$1.forwardRef(({ children, comput
|
|
|
8841
8841
|
})] });
|
|
8842
8842
|
});
|
|
8843
8843
|
function DynamicTexture({ displayTextureRef, fboA, fboB, readBufferIndex, ...props }) {
|
|
8844
|
-
const materialRef = React
|
|
8844
|
+
const materialRef = React.useRef(null);
|
|
8845
8845
|
const attachKey = typeof props.attach === "string" ? props.attach : "envMap";
|
|
8846
|
-
const customAttach = React
|
|
8846
|
+
const customAttach = React.useCallback((parent, self) => {
|
|
8847
8847
|
const material = parent?.isMaterial ? parent : parent?.object;
|
|
8848
8848
|
if (!material) {
|
|
8849
8849
|
console.warn("RenderCubeTexture: Could not find parent material for attach");
|
|
@@ -8911,11 +8911,11 @@ function Container$1({ frames, renderPriority, children, camera, fboA, fboB, rea
|
|
|
8911
8911
|
* ```
|
|
8912
8912
|
*/
|
|
8913
8913
|
function Fisheye({ renderPriority = 1, zoom = 0, segments = 64, children, resolution = 896, ...props }) {
|
|
8914
|
-
const sphere = React
|
|
8915
|
-
const cubeApi = React
|
|
8914
|
+
const sphere = React.useRef(null);
|
|
8915
|
+
const cubeApi = React.useRef(null);
|
|
8916
8916
|
const { width, height } = useThree((state) => state.size);
|
|
8917
|
-
const [orthoC] = React
|
|
8918
|
-
React
|
|
8917
|
+
const [orthoC] = React.useState(() => new OrthographicCamera$2());
|
|
8918
|
+
React.useLayoutEffect(() => {
|
|
8919
8919
|
orthoC.position.set(0, 0, 100);
|
|
8920
8920
|
orthoC.zoom = 100;
|
|
8921
8921
|
orthoC.left = width / -2;
|
|
@@ -8928,7 +8928,7 @@ function Fisheye({ renderPriority = 1, zoom = 0, segments = 64, children, resolu
|
|
|
8928
8928
|
const normal = new Vector3$2();
|
|
8929
8929
|
const sph = new Sphere$1(new Vector3$2(), radius);
|
|
8930
8930
|
const normalMatrix = new Matrix3();
|
|
8931
|
-
const compute = React
|
|
8931
|
+
const compute = React.useCallback((event, state, prev) => {
|
|
8932
8932
|
state.pointer.set(event.offsetX / state.size.width * 2 - 1, -(event.offsetY / state.size.height) * 2 + 1);
|
|
8933
8933
|
state.raycaster.setFromCamera(state.pointer, orthoC);
|
|
8934
8934
|
if (!state.raycaster.ray.intersectSphere(sph, normal)) return;
|
|
@@ -9016,7 +9016,7 @@ function RenderHud({ defaultScene, defaultCamera, renderPriority = 1 }) {
|
|
|
9016
9016
|
*/
|
|
9017
9017
|
function Hud({ children, renderPriority = 1 }) {
|
|
9018
9018
|
const { scene: defaultScene, camera: defaultCamera } = useThree();
|
|
9019
|
-
const [hudScene] = React
|
|
9019
|
+
const [hudScene] = React.useState(() => new Scene$1());
|
|
9020
9020
|
return /* @__PURE__ */ jsx(Fragment$1, { children: createPortal(/* @__PURE__ */ jsxs(Fragment$1, { children: [children, /* @__PURE__ */ jsx(RenderHud, {
|
|
9021
9021
|
defaultScene,
|
|
9022
9022
|
defaultCamera,
|
|
@@ -9049,13 +9049,13 @@ function Hud({ children, renderPriority = 1 }) {
|
|
|
9049
9049
|
* <Mask id={1} position={[1, 0, 0]}><circleGeometry /></Mask>
|
|
9050
9050
|
* ```
|
|
9051
9051
|
*/
|
|
9052
|
-
const Mask = /* @__PURE__ */ React
|
|
9053
|
-
const ref = React
|
|
9052
|
+
const Mask = /* @__PURE__ */ React.forwardRef(({ id = 1, colorWrite = false, depthWrite = false, children, ...props }, fref) => {
|
|
9053
|
+
const ref = React.useRef(null);
|
|
9054
9054
|
const renderer = useThree((state) => state.renderer);
|
|
9055
|
-
const stencilReady = React
|
|
9056
|
-
const [ready, setReady] = React
|
|
9057
|
-
React
|
|
9058
|
-
React
|
|
9055
|
+
const stencilReady = React.useRef(false);
|
|
9056
|
+
const [ready, setReady] = React.useState(false);
|
|
9057
|
+
React.useImperativeHandle(fref, () => ref.current, []);
|
|
9058
|
+
React.useLayoutEffect(() => {
|
|
9059
9059
|
if (stencilReady.current) return;
|
|
9060
9060
|
if ("backend" in renderer) {
|
|
9061
9061
|
renderer.stencil = true;
|
|
@@ -9132,7 +9132,7 @@ function useMask(id, inverse = false) {
|
|
|
9132
9132
|
*/
|
|
9133
9133
|
function useCustomRaycast(camera, props) {
|
|
9134
9134
|
const pointer = useThree((state) => state.pointer);
|
|
9135
|
-
const [raycast] = React
|
|
9135
|
+
const [raycast] = React.useState(() => {
|
|
9136
9136
|
const raycaster = new Raycaster();
|
|
9137
9137
|
if (props) applyProps(raycaster, props);
|
|
9138
9138
|
return function(_, intersects) {
|
|
@@ -9201,9 +9201,9 @@ function clear(renderer) {
|
|
|
9201
9201
|
}
|
|
9202
9202
|
function Container({ visible = true, canvasSize, scene, index, children, frames, rect, track }) {
|
|
9203
9203
|
const { scene: portalScene, camera: portalCamera, renderer, get, setEvents } = useThree();
|
|
9204
|
-
const [isOffscreen, setOffscreen] = React
|
|
9205
|
-
const mountedRef = React
|
|
9206
|
-
React
|
|
9204
|
+
const [isOffscreen, setOffscreen] = React.useState(false);
|
|
9205
|
+
const mountedRef = React.useRef(true);
|
|
9206
|
+
React.useEffect(() => {
|
|
9207
9207
|
mountedRef.current = true;
|
|
9208
9208
|
return () => {
|
|
9209
9209
|
mountedRef.current = false;
|
|
@@ -9235,7 +9235,7 @@ function Container({ visible = true, canvasSize, scene, index, children, frames,
|
|
|
9235
9235
|
after: "render",
|
|
9236
9236
|
priority: index
|
|
9237
9237
|
});
|
|
9238
|
-
React
|
|
9238
|
+
React.useLayoutEffect(() => {
|
|
9239
9239
|
const curRect = rect.current;
|
|
9240
9240
|
if (curRect && (!visible || !isOffscreen)) {
|
|
9241
9241
|
const { position: position$1, isOffscreen: _isOffscreen } = computeContainerPosition(canvasSize, curRect);
|
|
@@ -9252,7 +9252,7 @@ function Container({ visible = true, canvasSize, scene, index, children, frames,
|
|
|
9252
9252
|
portalCamera,
|
|
9253
9253
|
canvasSize
|
|
9254
9254
|
]);
|
|
9255
|
-
React
|
|
9255
|
+
React.useEffect(() => {
|
|
9256
9256
|
if (!track) return;
|
|
9257
9257
|
const curRect = rect.current;
|
|
9258
9258
|
const old = get().events.connected;
|
|
@@ -9278,12 +9278,12 @@ function Container({ visible = true, canvasSize, scene, index, children, frames,
|
|
|
9278
9278
|
]);
|
|
9279
9279
|
return /* @__PURE__ */ jsxs(Fragment$1, { children: [children, /* @__PURE__ */ jsx("group", { onPointerOver: () => null })] });
|
|
9280
9280
|
}
|
|
9281
|
-
const CanvasView = /* @__PURE__ */ React
|
|
9282
|
-
const rect = React
|
|
9281
|
+
const CanvasView = /* @__PURE__ */ React.forwardRef(({ track, visible = true, index = 1, id, style, className, frames = Infinity, children, ...props }, fref) => {
|
|
9282
|
+
const rect = React.useRef(null);
|
|
9283
9283
|
const { size, scene } = useThree();
|
|
9284
|
-
const [virtualScene] = React
|
|
9285
|
-
const [ready, toggle] = React
|
|
9286
|
-
const compute = React
|
|
9284
|
+
const [virtualScene] = React.useState(() => new Scene$1());
|
|
9285
|
+
const [ready, toggle] = React.useReducer(() => true, false);
|
|
9286
|
+
const compute = React.useCallback((event, state) => {
|
|
9287
9287
|
if (rect.current && track && track.current && event.target === track.current) {
|
|
9288
9288
|
const { width, height, left, top } = rect.current;
|
|
9289
9289
|
const x = event.clientX - left;
|
|
@@ -9292,7 +9292,7 @@ const CanvasView = /* @__PURE__ */ React$1.forwardRef(({ track, visible = true,
|
|
|
9292
9292
|
state.raycaster.setFromCamera(state.pointer, state.camera);
|
|
9293
9293
|
}
|
|
9294
9294
|
}, [rect, track]);
|
|
9295
|
-
React
|
|
9295
|
+
React.useEffect(() => {
|
|
9296
9296
|
if (track) rect.current = track.current?.getBoundingClientRect();
|
|
9297
9297
|
toggle();
|
|
9298
9298
|
}, [track]);
|
|
@@ -9322,10 +9322,10 @@ const CanvasView = /* @__PURE__ */ React$1.forwardRef(({ track, visible = true,
|
|
|
9322
9322
|
})
|
|
9323
9323
|
});
|
|
9324
9324
|
});
|
|
9325
|
-
const HtmlView = /* @__PURE__ */ React
|
|
9326
|
-
const uuid = React
|
|
9327
|
-
const ref = React
|
|
9328
|
-
React
|
|
9325
|
+
const HtmlView = /* @__PURE__ */ React.forwardRef(({ as: El = "div", id, visible, className, style, index = 1, track, frames = Infinity, children, ...props }, fref) => {
|
|
9326
|
+
const uuid = React.useId();
|
|
9327
|
+
const ref = React.useRef(null);
|
|
9328
|
+
React.useImperativeHandle(fref, () => ref.current);
|
|
9329
9329
|
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(El, {
|
|
9330
9330
|
ref,
|
|
9331
9331
|
id,
|
|
@@ -9361,8 +9361,8 @@ const HtmlView = /* @__PURE__ */ React$1.forwardRef(({ as: El = "div", id, visib
|
|
|
9361
9361
|
* ```
|
|
9362
9362
|
*/
|
|
9363
9363
|
const View = /* @__PURE__ */ (() => {
|
|
9364
|
-
const _View = React
|
|
9365
|
-
if (!React
|
|
9364
|
+
const _View = React.forwardRef((props, fref) => {
|
|
9365
|
+
if (!React.useContext(context)) return /* @__PURE__ */ jsx(HtmlView, {
|
|
9366
9366
|
ref: fref,
|
|
9367
9367
|
...props
|
|
9368
9368
|
});
|
|
@@ -9389,8 +9389,8 @@ const easeInExpo = (x) => x === 0 ? 0 : Math.pow(2, 10 * x - 10);
|
|
|
9389
9389
|
* ```
|
|
9390
9390
|
*/
|
|
9391
9391
|
function Backdrop({ children, floor = .25, segments = 20, receiveShadow, ...props }) {
|
|
9392
|
-
const ref = React
|
|
9393
|
-
React
|
|
9392
|
+
const ref = React.useRef(null);
|
|
9393
|
+
React.useLayoutEffect(() => {
|
|
9394
9394
|
let i$1 = 0;
|
|
9395
9395
|
const offset = segments / segments / 2;
|
|
9396
9396
|
const position$1 = ref.current.attributes.position;
|
|
@@ -9438,9 +9438,9 @@ const boundingBoxSize = /* @__PURE__ */ new Vector3$2();
|
|
|
9438
9438
|
* ```
|
|
9439
9439
|
*/
|
|
9440
9440
|
const BBAnchor = ({ anchor, ...props }) => {
|
|
9441
|
-
const ref = React
|
|
9442
|
-
const parentRef = React
|
|
9443
|
-
React
|
|
9441
|
+
const ref = React.useRef(null);
|
|
9442
|
+
const parentRef = React.useRef(null);
|
|
9443
|
+
React.useEffect(() => {
|
|
9444
9444
|
if (ref.current?.parent?.parent) {
|
|
9445
9445
|
parentRef.current = ref.current.parent;
|
|
9446
9446
|
ref.current.parent.parent.add(ref.current);
|
|
@@ -9472,7 +9472,7 @@ const isBox3 = (def) => def && def.isBox3;
|
|
|
9472
9472
|
const interpolateFuncDefault = (t) => {
|
|
9473
9473
|
return 1 - Math.exp(-5 * t) + .007 * t;
|
|
9474
9474
|
};
|
|
9475
|
-
const context$2 = React
|
|
9475
|
+
const context$2 = React.createContext(null);
|
|
9476
9476
|
/**
|
|
9477
9477
|
* Calculates and provides the bounding box of children.
|
|
9478
9478
|
* Useful for camera framing and object positioning.
|
|
@@ -9485,27 +9485,27 @@ const context$2 = React$1.createContext(null);
|
|
|
9485
9485
|
* ```
|
|
9486
9486
|
*/
|
|
9487
9487
|
function Bounds({ children, maxDuration = 1, margin = 1.2, observe, fit, clip, interpolateFunc = interpolateFuncDefault, onFit }) {
|
|
9488
|
-
const ref = React
|
|
9488
|
+
const ref = React.useRef(null);
|
|
9489
9489
|
const { camera, size, invalidate } = useThree();
|
|
9490
9490
|
const controls = useThree((state) => state.controls);
|
|
9491
|
-
const onFitRef = React
|
|
9491
|
+
const onFitRef = React.useRef(onFit);
|
|
9492
9492
|
onFitRef.current = onFit;
|
|
9493
|
-
const origin = React
|
|
9493
|
+
const origin = React.useRef({
|
|
9494
9494
|
camPos: new Vector3$2(),
|
|
9495
9495
|
camRot: new Quaternion(),
|
|
9496
9496
|
camZoom: 1
|
|
9497
9497
|
});
|
|
9498
|
-
const goal = React
|
|
9498
|
+
const goal = React.useRef({
|
|
9499
9499
|
camPos: void 0,
|
|
9500
9500
|
camRot: void 0,
|
|
9501
9501
|
camZoom: void 0,
|
|
9502
9502
|
camUp: void 0,
|
|
9503
9503
|
target: void 0
|
|
9504
9504
|
});
|
|
9505
|
-
const animationState = React
|
|
9506
|
-
const t = React
|
|
9507
|
-
const [box] = React
|
|
9508
|
-
const api = React
|
|
9505
|
+
const animationState = React.useRef(AnimationState.NONE);
|
|
9506
|
+
const t = React.useRef(0);
|
|
9507
|
+
const [box] = React.useState(() => new Box3());
|
|
9508
|
+
const api = React.useMemo(() => {
|
|
9509
9509
|
function getSize() {
|
|
9510
9510
|
const boxSize = box.getSize(new Vector3$2());
|
|
9511
9511
|
const center = box.getCenter(new Vector3$2());
|
|
@@ -9627,7 +9627,7 @@ function Bounds({ children, maxDuration = 1, margin = 1.2, observe, fit, clip, i
|
|
|
9627
9627
|
margin,
|
|
9628
9628
|
invalidate
|
|
9629
9629
|
]);
|
|
9630
|
-
React
|
|
9630
|
+
React.useLayoutEffect(() => {
|
|
9631
9631
|
if (controls) {
|
|
9632
9632
|
const callback = () => {
|
|
9633
9633
|
if (controls && goal.current.target && animationState.current !== AnimationState.NONE) {
|
|
@@ -9644,8 +9644,8 @@ function Bounds({ children, maxDuration = 1, margin = 1.2, observe, fit, clip, i
|
|
|
9644
9644
|
return () => controls.removeEventListener("start", callback);
|
|
9645
9645
|
}
|
|
9646
9646
|
}, [controls]);
|
|
9647
|
-
const count = React
|
|
9648
|
-
React
|
|
9647
|
+
const count = React.useRef(0);
|
|
9648
|
+
React.useLayoutEffect(() => {
|
|
9649
9649
|
if (observe || count.current++ === 0) {
|
|
9650
9650
|
api.refresh();
|
|
9651
9651
|
if (fit) api.reset().fit();
|
|
@@ -9698,7 +9698,7 @@ function Bounds({ children, maxDuration = 1, margin = 1.2, observe, fit, clip, i
|
|
|
9698
9698
|
});
|
|
9699
9699
|
}
|
|
9700
9700
|
function useBounds() {
|
|
9701
|
-
return React
|
|
9701
|
+
return React.useContext(context$2);
|
|
9702
9702
|
}
|
|
9703
9703
|
|
|
9704
9704
|
//#endregion
|
|
@@ -9907,7 +9907,7 @@ function setEnvProps(background, scene, defaultScene, texture, sceneProps = {})
|
|
|
9907
9907
|
*/
|
|
9908
9908
|
function EnvironmentMap({ scene, background = false, map, ...config }) {
|
|
9909
9909
|
const defaultScene = useThree((state) => state.scene);
|
|
9910
|
-
React
|
|
9910
|
+
React.useLayoutEffect(() => {
|
|
9911
9911
|
if (map) return setEnvProps(background, scene, defaultScene, map, config);
|
|
9912
9912
|
});
|
|
9913
9913
|
return null;
|
|
@@ -9940,7 +9940,7 @@ function EnvironmentMap({ scene, background = false, map, ...config }) {
|
|
|
9940
9940
|
function EnvironmentCube({ background = false, scene, blur, backgroundBlurriness, backgroundIntensity, backgroundRotation, environmentIntensity, environmentRotation, ...rest }) {
|
|
9941
9941
|
const texture = useEnvironment(rest);
|
|
9942
9942
|
const defaultScene = useThree((state) => state.scene);
|
|
9943
|
-
React
|
|
9943
|
+
React.useLayoutEffect(() => {
|
|
9944
9944
|
return setEnvProps(background, scene, defaultScene, texture, {
|
|
9945
9945
|
backgroundBlurriness: blur ?? backgroundBlurriness,
|
|
9946
9946
|
backgroundIntensity,
|
|
@@ -9949,7 +9949,7 @@ function EnvironmentCube({ background = false, scene, blur, backgroundBlurriness
|
|
|
9949
9949
|
environmentRotation
|
|
9950
9950
|
});
|
|
9951
9951
|
});
|
|
9952
|
-
React
|
|
9952
|
+
React.useEffect(() => {
|
|
9953
9953
|
return () => {
|
|
9954
9954
|
texture.dispose();
|
|
9955
9955
|
};
|
|
@@ -9990,19 +9990,19 @@ function EnvironmentCube({ background = false, scene, blur, backgroundBlurriness
|
|
|
9990
9990
|
function EnvironmentPortal({ children, near = .1, far = 1e3, resolution = 256, frames = 1, map, background = false, blur, backgroundBlurriness, backgroundIntensity, backgroundRotation, environmentIntensity, environmentRotation, scene, files, path, preset = void 0, extensions: extensions$1 }) {
|
|
9991
9991
|
const gl = useThree((state) => state.gl);
|
|
9992
9992
|
const defaultScene = useThree((state) => state.scene);
|
|
9993
|
-
const camera = React
|
|
9994
|
-
const [virtualScene] = React
|
|
9995
|
-
const fbo = React
|
|
9993
|
+
const camera = React.useRef(null);
|
|
9994
|
+
const [virtualScene] = React.useState(() => new Scene$1());
|
|
9995
|
+
const fbo = React.useMemo(() => {
|
|
9996
9996
|
const fbo$1 = new WebGLCubeRenderTarget(resolution);
|
|
9997
9997
|
fbo$1.texture.type = HalfFloatType$1;
|
|
9998
9998
|
return fbo$1;
|
|
9999
9999
|
}, [resolution]);
|
|
10000
|
-
React
|
|
10000
|
+
React.useEffect(() => {
|
|
10001
10001
|
return () => {
|
|
10002
10002
|
fbo.dispose();
|
|
10003
10003
|
};
|
|
10004
10004
|
}, [fbo]);
|
|
10005
|
-
React
|
|
10005
|
+
React.useLayoutEffect(() => {
|
|
10006
10006
|
if (frames === 1) {
|
|
10007
10007
|
const autoClear = gl.autoClear;
|
|
10008
10008
|
gl.autoClear = true;
|
|
@@ -10083,8 +10083,8 @@ function EnvironmentPortal({ children, near = .1, far = 1e3, resolution = 256, f
|
|
|
10083
10083
|
function EnvironmentGround(props) {
|
|
10084
10084
|
const textureDefault = useEnvironment(props);
|
|
10085
10085
|
const texture = props.map || textureDefault;
|
|
10086
|
-
React
|
|
10087
|
-
React
|
|
10086
|
+
React.useMemo(() => extend({ GroundProjectedEnvImpl: GroundedSkybox }), []);
|
|
10087
|
+
React.useEffect(() => {
|
|
10088
10088
|
return () => {
|
|
10089
10089
|
textureDefault.dispose();
|
|
10090
10090
|
};
|
|
@@ -10092,7 +10092,7 @@ function EnvironmentGround(props) {
|
|
|
10092
10092
|
const height = props.ground?.height ?? 15;
|
|
10093
10093
|
const radius = props.ground?.radius ?? 60;
|
|
10094
10094
|
const scale$2 = props.ground?.scale ?? 1e3;
|
|
10095
|
-
const args = React
|
|
10095
|
+
const args = React.useMemo(() => [
|
|
10096
10096
|
texture,
|
|
10097
10097
|
height,
|
|
10098
10098
|
radius
|
|
@@ -10220,10 +10220,10 @@ function Environment(props) {
|
|
|
10220
10220
|
* </Float>
|
|
10221
10221
|
* ```
|
|
10222
10222
|
*/
|
|
10223
|
-
const Float = /* @__PURE__ */ React
|
|
10224
|
-
const ref = React
|
|
10225
|
-
React
|
|
10226
|
-
const offset = React
|
|
10223
|
+
const Float = /* @__PURE__ */ React.forwardRef(({ children, enabled = true, speed = 1, rotationIntensity = 1, floatIntensity = 1, floatingRange = [-.1, .1], autoInvalidate = false, ...props }, forwardRef$1) => {
|
|
10224
|
+
const ref = React.useRef(null);
|
|
10225
|
+
React.useImperativeHandle(forwardRef$1, () => ref.current, []);
|
|
10226
|
+
const offset = React.useRef(Math.random() * 1e4);
|
|
10227
10227
|
useFrame((state) => {
|
|
10228
10228
|
if (!enabled || speed === 0) return;
|
|
10229
10229
|
if (autoInvalidate) state.invalidate();
|
|
@@ -10257,14 +10257,14 @@ const Float = /* @__PURE__ */ React$1.forwardRef(({ children, enabled = true, sp
|
|
|
10257
10257
|
* <Lightformer form="circle" intensity={2} position={[0, 5, -2]} />
|
|
10258
10258
|
* ```
|
|
10259
10259
|
*/
|
|
10260
|
-
const Lightformer = /* @__PURE__ */ React
|
|
10260
|
+
const Lightformer = /* @__PURE__ */ React.forwardRef(({ light, args, map, toneMapped = false, color = "white", form: Form = "rect", intensity = 1, scale: scale$2 = 1, target: target$1 = [
|
|
10261
10261
|
0,
|
|
10262
10262
|
0,
|
|
10263
10263
|
0
|
|
10264
10264
|
], children, ...props }, forwardRef$1) => {
|
|
10265
|
-
const ref = React
|
|
10266
|
-
React
|
|
10267
|
-
React
|
|
10265
|
+
const ref = React.useRef(null);
|
|
10266
|
+
React.useImperativeHandle(forwardRef$1, () => ref.current, []);
|
|
10267
|
+
React.useLayoutEffect(() => {
|
|
10268
10268
|
if (!children && !props.material) {
|
|
10269
10269
|
applyProps(ref.current.material, { color });
|
|
10270
10270
|
ref.current.material.color.multiplyScalar(intensity);
|
|
@@ -10275,7 +10275,7 @@ const Lightformer = /* @__PURE__ */ React$1.forwardRef(({ light, args, map, tone
|
|
|
10275
10275
|
children,
|
|
10276
10276
|
props.material
|
|
10277
10277
|
]);
|
|
10278
|
-
React
|
|
10278
|
+
React.useLayoutEffect(() => {
|
|
10279
10279
|
if (!props.rotation) ref.current.quaternion.identity();
|
|
10280
10280
|
if (target$1 && !props.rotation) "boolean" === typeof target$1 ? ref.current.lookAt(0, 0, 0) : ref.current.lookAt(Array.isArray(target$1) ? new Vector3$2(...target$1) : target$1);
|
|
10281
10281
|
}, [target$1, props.rotation]);
|
|
@@ -10327,11 +10327,11 @@ const Lightformer = /* @__PURE__ */ React$1.forwardRef(({ light, args, map, tone
|
|
|
10327
10327
|
* </Resize>
|
|
10328
10328
|
* ```
|
|
10329
10329
|
*/
|
|
10330
|
-
const Resize = /* @__PURE__ */ React
|
|
10331
|
-
const ref = React
|
|
10332
|
-
const outer = React
|
|
10333
|
-
const inner = React
|
|
10334
|
-
React
|
|
10330
|
+
const Resize = /* @__PURE__ */ React.forwardRef(({ children, width, height, depth, box3, precise = true, ...props }, fRef) => {
|
|
10331
|
+
const ref = React.useRef(null);
|
|
10332
|
+
const outer = React.useRef(null);
|
|
10333
|
+
const inner = React.useRef(null);
|
|
10334
|
+
React.useLayoutEffect(() => {
|
|
10335
10335
|
outer.current.matrixWorld.identity();
|
|
10336
10336
|
let box = box3 || new Box3().setFromObject(inner.current, precise);
|
|
10337
10337
|
const w = box.max.x - box.min.x;
|
|
@@ -10349,7 +10349,7 @@ const Resize = /* @__PURE__ */ React$1.forwardRef(({ children, width, height, de
|
|
|
10349
10349
|
box3,
|
|
10350
10350
|
precise
|
|
10351
10351
|
]);
|
|
10352
|
-
React
|
|
10352
|
+
React.useImperativeHandle(fRef, () => ref.current, []);
|
|
10353
10353
|
return /* @__PURE__ */ jsx("group", {
|
|
10354
10354
|
ref,
|
|
10355
10355
|
...props,
|
|
@@ -10378,7 +10378,7 @@ const worldPos = /* @__PURE__ */ new Vector3$2();
|
|
|
10378
10378
|
*/
|
|
10379
10379
|
const ScreenSizer = /* @__PURE__ */ forwardRef(({ scale: scale$2 = 1, ...props }, ref) => {
|
|
10380
10380
|
const container = useRef(null);
|
|
10381
|
-
React
|
|
10381
|
+
React.useImperativeHandle(ref, () => container.current, []);
|
|
10382
10382
|
useFrame((state) => {
|
|
10383
10383
|
const obj = container.current;
|
|
10384
10384
|
if (!obj) return;
|
|
@@ -10401,8 +10401,8 @@ const ScreenSizer = /* @__PURE__ */ forwardRef(({ scale: scale$2 = 1, ...props }
|
|
|
10401
10401
|
* <Shadow color="black" opacity={0.5} position={[0, 0, 0]} />
|
|
10402
10402
|
* ```
|
|
10403
10403
|
*/
|
|
10404
|
-
const Shadow = /* @__PURE__ */ React
|
|
10405
|
-
const canvas = React
|
|
10404
|
+
const Shadow = /* @__PURE__ */ React.forwardRef(({ fog = false, renderOrder, depthWrite = false, colorStop = 0, color = "black", opacity = .5, ...props }, ref) => {
|
|
10405
|
+
const canvas = React.useMemo(() => {
|
|
10406
10406
|
const canvas$1 = document.createElement("canvas");
|
|
10407
10407
|
canvas$1.width = 128;
|
|
10408
10408
|
canvas$1.height = 128;
|
|
@@ -10457,9 +10457,9 @@ function toVector3(value) {
|
|
|
10457
10457
|
* <Sky sunPosition={[0, 1, 0]} />
|
|
10458
10458
|
* ```
|
|
10459
10459
|
*/
|
|
10460
|
-
const Sky = /* @__PURE__ */ React
|
|
10460
|
+
const Sky = /* @__PURE__ */ React.forwardRef(({ inclination = .6, azimuth = .1, distance = 1e3, mieCoefficient = .005, mieDirectionalG = .8, rayleigh = .5, turbidity = 10, sunPosition = calcPosFromAngles(inclination, azimuth), ...props }, ref) => {
|
|
10461
10461
|
const { isLegacy } = useThree();
|
|
10462
|
-
const sky = React
|
|
10462
|
+
const sky = React.useMemo(() => {
|
|
10463
10463
|
if (isLegacy) {
|
|
10464
10464
|
const skyInstance = new Sky$1();
|
|
10465
10465
|
skyInstance.scale.setScalar(distance);
|
|
@@ -10470,10 +10470,10 @@ const Sky = /* @__PURE__ */ React$1.forwardRef(({ inclination = .6, azimuth = .1
|
|
|
10470
10470
|
return skyInstance;
|
|
10471
10471
|
}
|
|
10472
10472
|
}, [isLegacy, distance]);
|
|
10473
|
-
React
|
|
10473
|
+
React.useLayoutEffect(() => {
|
|
10474
10474
|
sky.scale.setScalar(distance);
|
|
10475
10475
|
}, [sky, distance]);
|
|
10476
|
-
React
|
|
10476
|
+
React.useLayoutEffect(() => {
|
|
10477
10477
|
if (!sky) return;
|
|
10478
10478
|
if (isLegacy) applyProps(sky.material, {
|
|
10479
10479
|
mieCoefficient,
|
|
@@ -10571,7 +10571,7 @@ const presets = {
|
|
|
10571
10571
|
};
|
|
10572
10572
|
function Refit({ radius, adjustCamera }) {
|
|
10573
10573
|
const api = useBounds();
|
|
10574
|
-
React
|
|
10574
|
+
React.useEffect(() => {
|
|
10575
10575
|
if (adjustCamera) api.refresh().clip().fit();
|
|
10576
10576
|
}, [radius, adjustCamera]);
|
|
10577
10577
|
return null;
|
|
@@ -10589,7 +10589,7 @@ function Refit({ radius, adjustCamera }) {
|
|
|
10589
10589
|
*/
|
|
10590
10590
|
function Stage({ children, center, adjustCamera = true, intensity = .5, shadows = "contact", environment = "city", preset = "rembrandt", ...props }) {
|
|
10591
10591
|
const config = typeof preset === "string" ? presets[preset] : preset;
|
|
10592
|
-
const [{ radius, height }, set] = React
|
|
10592
|
+
const [{ radius, height }, set] = React.useState({
|
|
10593
10593
|
radius: 0,
|
|
10594
10594
|
width: 0,
|
|
10595
10595
|
height: 0,
|
|
@@ -10603,7 +10603,7 @@ function Stage({ children, center, adjustCamera = true, intensity = .5, shadows
|
|
|
10603
10603
|
const accumulativeShadow = shadows === "accumulative" || shadows?.type === "accumulative";
|
|
10604
10604
|
const shadowSpread = { ...typeof shadows === "object" ? shadows : {} };
|
|
10605
10605
|
const environmentProps = !environment ? null : typeof environment === "string" ? { preset: environment } : environment;
|
|
10606
|
-
const onCentered = React
|
|
10606
|
+
const onCentered = React.useCallback((props$1) => {
|
|
10607
10607
|
const { width, height: height$1, depth, boundingSphere } = props$1;
|
|
10608
10608
|
set({
|
|
10609
10609
|
radius: boundingSphere.radius,
|
|
@@ -10710,8 +10710,8 @@ const MATCAP_ROOT = "https://rawcdn.githack.com/emmelleppi/matcaps/9b36ccaaf0a24
|
|
|
10710
10710
|
function useMatcapTexture(id = 0, format = 1024, onLoad) {
|
|
10711
10711
|
const matcapList = (0, import_index_cjs$1.suspend)(() => fetch(LIST_URL$1).then((res) => res.json()), ["matcapList"]);
|
|
10712
10712
|
const DEFAULT_MATCAP = matcapList[0];
|
|
10713
|
-
const numTot = React
|
|
10714
|
-
const url = `${MATCAP_ROOT}/${format}/${`${React
|
|
10713
|
+
const numTot = React.useMemo(() => Object.keys(matcapList).length, []);
|
|
10714
|
+
const url = `${MATCAP_ROOT}/${format}/${`${React.useMemo(() => {
|
|
10715
10715
|
if (typeof id === "string") return id;
|
|
10716
10716
|
else if (typeof id === "number") return matcapList[id];
|
|
10717
10717
|
return null;
|
|
@@ -10744,11 +10744,11 @@ const LIST_URL = "https://cdn.jsdelivr.net/gh/pmndrs/drei-assets@master/normals/
|
|
|
10744
10744
|
function useNormalTexture(id = 0, settings = {}, onLoad) {
|
|
10745
10745
|
const { repeat = [1, 1], anisotropy = 1, offset = [0, 0] } = settings;
|
|
10746
10746
|
const normalsList = (0, import_index_cjs$1.suspend)(() => fetch(LIST_URL).then((res) => res.json()), ["normalsList"]);
|
|
10747
|
-
const numTot = React
|
|
10747
|
+
const numTot = React.useMemo(() => Object.keys(normalsList).length, []);
|
|
10748
10748
|
const DEFAULT_NORMAL = normalsList[0];
|
|
10749
10749
|
const url = `${NORMAL_ROOT}/normals/${normalsList[id] || DEFAULT_NORMAL}`;
|
|
10750
10750
|
const normalTexture = useTexture(url, onLoad);
|
|
10751
|
-
React
|
|
10751
|
+
React.useLayoutEffect(() => {
|
|
10752
10752
|
if (!normalTexture) return;
|
|
10753
10753
|
normalTexture.wrapS = normalTexture.wrapT = RepeatWrapping;
|
|
10754
10754
|
normalTexture.repeat = new Vector2$2(repeat[0], repeat[1]);
|
|
@@ -10793,11 +10793,11 @@ const NormalTexture = ({ children, id, onLoad, ...settings }) => {
|
|
|
10793
10793
|
* ```
|
|
10794
10794
|
*/
|
|
10795
10795
|
function CycleRaycast({ onChanged, portal, preventDefault = true, scroll = true, keyCode = 9 }) {
|
|
10796
|
-
const cycle = React
|
|
10796
|
+
const cycle = React.useRef(0);
|
|
10797
10797
|
const setEvents = useThree((state) => state.setEvents);
|
|
10798
10798
|
const get = useThree((state) => state.get);
|
|
10799
10799
|
const gl = useThree((state) => state.gl);
|
|
10800
|
-
React
|
|
10800
|
+
React.useEffect(() => {
|
|
10801
10801
|
let hits = [];
|
|
10802
10802
|
let lastEvent = void 0;
|
|
10803
10803
|
const prev = get().events.filter;
|
|
@@ -10892,7 +10892,7 @@ function useAspect(width, height, factor = 1) {
|
|
|
10892
10892
|
* ```
|
|
10893
10893
|
*/
|
|
10894
10894
|
function useCursor(hovered, onPointerOver = "pointer", onPointerOut = "auto", container = document.body) {
|
|
10895
|
-
React
|
|
10895
|
+
React.useEffect(() => {
|
|
10896
10896
|
if (hovered) {
|
|
10897
10897
|
container.style.cursor = onPointerOver;
|
|
10898
10898
|
return () => void (container.style.cursor = onPointerOut);
|
|
@@ -10912,9 +10912,9 @@ function useCursor(hovered, onPointerOver = "pointer", onPointerOut = "auto", co
|
|
|
10912
10912
|
* </ScreenSpace>
|
|
10913
10913
|
* ```
|
|
10914
10914
|
*/
|
|
10915
|
-
const ScreenSpace = /* @__PURE__ */ React
|
|
10916
|
-
const localRef = React
|
|
10917
|
-
React
|
|
10915
|
+
const ScreenSpace = /* @__PURE__ */ React.forwardRef(({ children, depth = -1, ...rest }, ref) => {
|
|
10916
|
+
const localRef = React.useRef(null);
|
|
10917
|
+
React.useImperativeHandle(ref, () => localRef.current, []);
|
|
10918
10918
|
useFrame(({ camera }) => {
|
|
10919
10919
|
localRef.current.quaternion.copy(camera.quaternion);
|
|
10920
10920
|
localRef.current.position.copy(camera.position);
|
|
@@ -10931,7 +10931,7 @@ const ScreenSpace = /* @__PURE__ */ React$1.forwardRef(({ children, depth = -1,
|
|
|
10931
10931
|
|
|
10932
10932
|
//#endregion
|
|
10933
10933
|
//#region src/core/UI/Select/Select.tsx
|
|
10934
|
-
const context$1 = /* @__PURE__ */ React
|
|
10934
|
+
const context$1 = /* @__PURE__ */ React.createContext([]);
|
|
10935
10935
|
/**
|
|
10936
10936
|
* Allows selecting/unselecting objects by clicking on them.
|
|
10937
10937
|
* Supports multi-select (shift key) and box selection.
|
|
@@ -10949,30 +10949,30 @@ const context$1 = /* @__PURE__ */ React$1.createContext([]);
|
|
|
10949
10949
|
* ```
|
|
10950
10950
|
*/
|
|
10951
10951
|
function Select({ box, multiple, children, onChange, onChangePointerUp, border = "1px solid #55aaff", backgroundColor = "rgba(75, 160, 255, 0.1)", filter: customFilter = (item) => item, ...props }) {
|
|
10952
|
-
const [downed, down] = React
|
|
10952
|
+
const [downed, down] = React.useState(false);
|
|
10953
10953
|
const { setEvents, camera, raycaster, gl, controls, size, get } = useThree();
|
|
10954
|
-
const [hovered, hover] = React
|
|
10955
|
-
const [active, dispatch] = React
|
|
10954
|
+
const [hovered, hover] = React.useState(false);
|
|
10955
|
+
const [active, dispatch] = React.useReducer((state, { object, shift }) => {
|
|
10956
10956
|
if (object === void 0) return [];
|
|
10957
10957
|
else if (Array.isArray(object)) return object;
|
|
10958
10958
|
else if (!shift) return state[0] === object ? [] : [object];
|
|
10959
10959
|
else if (state.includes(object)) return state.filter((o) => o !== object);
|
|
10960
10960
|
else return [object, ...state];
|
|
10961
10961
|
}, []);
|
|
10962
|
-
React
|
|
10962
|
+
React.useEffect(() => {
|
|
10963
10963
|
if (downed) onChange?.(active);
|
|
10964
10964
|
else onChangePointerUp?.(active);
|
|
10965
10965
|
}, [active, downed]);
|
|
10966
|
-
const onClick = React
|
|
10966
|
+
const onClick = React.useCallback((e) => {
|
|
10967
10967
|
e.stopPropagation();
|
|
10968
10968
|
dispatch({
|
|
10969
10969
|
object: customFilter([e.object])[0],
|
|
10970
10970
|
shift: multiple && e.shiftKey
|
|
10971
10971
|
});
|
|
10972
10972
|
}, []);
|
|
10973
|
-
const onPointerMissed = React
|
|
10974
|
-
const ref = React
|
|
10975
|
-
React
|
|
10973
|
+
const onPointerMissed = React.useCallback((e) => !hovered && dispatch({}), [hovered]);
|
|
10974
|
+
const ref = React.useRef(null);
|
|
10975
|
+
React.useEffect(() => {
|
|
10976
10976
|
if (!box || !multiple) return;
|
|
10977
10977
|
const selBox = new SelectionBox(camera, ref.current);
|
|
10978
10978
|
const element = document.createElement("div");
|
|
@@ -11075,7 +11075,7 @@ function Select({ box, multiple, children, onChange, onChangePointerUp, border =
|
|
|
11075
11075
|
});
|
|
11076
11076
|
}
|
|
11077
11077
|
function useSelect() {
|
|
11078
|
-
return React
|
|
11078
|
+
return React.useContext(context$1);
|
|
11079
11079
|
}
|
|
11080
11080
|
|
|
11081
11081
|
//#endregion
|