@react-three/drei 9.74.11 → 9.74.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/CatmullRomLine.js +2 -0
- package/core/Cloud.js +3 -0
- package/core/CubeCamera.js +1 -0
- package/core/CubicBezierLine.js +2 -0
- package/core/Environment.js +1 -0
- package/core/Example.js +6 -0
- package/core/FaceControls.cjs.js +1 -1
- package/core/FaceControls.js +2 -0
- package/core/FaceLandmarker.cjs.js +1 -1
- package/core/FaceLandmarker.js +3 -2
- package/core/Facemesh.js +2 -0
- package/core/GizmoHelper.js +3 -0
- package/core/GizmoViewcube.js +4 -0
- package/core/GizmoViewport.js +4 -0
- package/core/Gltf.js +4 -0
- package/core/MeshDiscardMaterial.js +2 -0
- package/core/MeshDistortMaterial.js +2 -1
- package/core/MeshReflectorMaterial.js +1 -0
- package/core/MeshRefractionMaterial.js +2 -0
- package/core/MeshTransmissionMaterial.js +1 -0
- package/core/OrthographicCamera.js +1 -0
- package/core/PerspectiveCamera.js +1 -0
- package/core/QuadraticBezierLine.js +2 -0
- package/core/Reflector.js +1 -0
- package/core/SpotLight.js +2 -1
- package/core/Stage.js +7 -0
- package/core/Text3D.js +1 -0
- package/core/Wireframe.js +1 -0
- package/core/index.cjs.js +1 -1
- package/core/index.js +0 -1
- package/core/useKTX2.js +1 -0
- package/core/useMatcapTexture.js +2 -0
- package/core/useNormalTexture.js +1 -0
- package/index.cjs.js +1 -1
- package/materials/DiscardMaterial.js +1 -0
- package/materials/MeshRefractionMaterial.js +1 -1
- package/native/index.cjs.js +1 -1
- package/native/index.js +0 -1
- package/package.json +9 -9
- package/src/core/AccumulativeShadows.js +311 -0
- package/src/core/AdaptiveDpr.js +28 -0
- package/src/core/AdaptiveEvents.js +20 -0
- package/src/core/ArcballControls.js +67 -0
- package/src/core/AsciiRenderer.js +60 -0
- package/src/core/BBAnchor.js +37 -0
- package/src/core/Backdrop.js +36 -0
- package/src/core/BakeShadows.js +16 -0
- package/src/core/Billboard.js +41 -0
- package/src/core/Bounds.js +245 -0
- package/src/core/CameraControls.js +92 -0
- package/src/core/CameraShake.js +61 -0
- package/src/core/CatmullRomLine.js +44 -0
- package/src/core/Caustics.js +375 -0
- package/src/core/Center.js +66 -0
- package/src/core/Clone.js +102 -0
- package/src/core/Cloud.js +59 -0
- package/src/core/ComputedAttribute.js +34 -0
- package/src/core/ContactShadows.js +114 -0
- package/src/core/CubeCamera.js +43 -0
- package/src/core/CubicBezierLine.js +28 -0
- package/src/core/CurveModifier.js +34 -0
- package/src/core/Decal.js +92 -0
- package/src/core/Detailed.js +34 -0
- package/src/core/DeviceOrientationControls.js +51 -0
- package/src/core/Edges.js +36 -0
- package/src/core/Effects.js +93 -0
- package/src/core/Environment.js +132 -0
- package/src/core/Example.js +42 -0
- package/src/core/FaceControls.js +315 -0
- package/src/core/FaceLandmarker.js +43 -0
- package/src/core/Facemesh.js +4545 -0
- package/src/core/FirstPersonControls.js +38 -0
- package/src/core/Float.js +36 -0
- package/src/core/FlyControls.js +55 -0
- package/src/core/GizmoHelper.js +111 -0
- package/src/core/GizmoViewcube.js +152 -0
- package/src/core/GizmoViewport.js +152 -0
- package/src/core/Gltf.js +20 -0
- package/src/core/GradientTexture.js +33 -0
- package/src/core/Grid.js +112 -0
- package/src/core/Hud.js +58 -0
- package/src/core/Image.js +119 -0
- package/src/core/Instances.js +215 -0
- package/src/core/Lightformer.js +51 -0
- package/src/core/Line.js +68 -0
- package/src/core/MapControls.js +64 -0
- package/src/core/MarchingCubes.js +76 -0
- package/src/core/Mask.js +42 -0
- package/src/core/MeshDiscardMaterial.js +15 -0
- package/src/core/MeshDistortMaterial.js +79 -0
- package/src/core/MeshPortalMaterial.js +381 -0
- package/src/core/MeshReflectorMaterial.js +182 -0
- package/src/core/MeshRefractionMaterial.js +79 -0
- package/src/core/MeshTransmissionMaterial.js +395 -0
- package/src/core/MeshWobbleMaterial.js +65 -0
- package/src/core/OrbitControls.js +82 -0
- package/src/core/OrthographicCamera.js +77 -0
- package/src/core/PerformanceMonitor.js +121 -0
- package/src/core/PerspectiveCamera.js +73 -0
- package/src/core/PointMaterial.js +36 -0
- package/src/core/PointerLockControls.js +90 -0
- package/src/core/Points.js +227 -0
- package/src/core/PositionalAudio.js +51 -0
- package/src/core/Preload.js +45 -0
- package/src/core/QuadraticBezierLine.js +44 -0
- package/src/core/Reflector.js +182 -0
- package/src/core/RenderTexture.js +96 -0
- package/src/core/Resize.js +39 -0
- package/src/core/RoundedBox.js +52 -0
- package/src/core/Sampler.js +85 -0
- package/src/core/ScreenQuad.js +24 -0
- package/src/core/ScreenSpace.js +25 -0
- package/src/core/Segments.js +102 -0
- package/src/core/Shadow.js +42 -0
- package/src/core/Sky.js +39 -0
- package/src/core/Sparkles.js +139 -0
- package/src/core/SpotLight.js +231 -0
- package/src/core/SpriteAnimator.js +342 -0
- package/src/core/Stage.js +135 -0
- package/src/core/Stars.js +108 -0
- package/src/core/Stats.js +30 -0
- package/src/core/Svg.js +59 -0
- package/src/core/Text.js +58 -0
- package/src/core/Text3D.js +76 -0
- package/src/core/TrackballControls.js +72 -0
- package/src/core/Trail.js +161 -0
- package/src/core/TransformControls.js +106 -0
- package/src/core/Wireframe.js +185 -0
- package/src/core/meshBounds.js +38 -0
- package/src/core/shaderMaterial.js +39 -0
- package/src/core/shapes.js +68 -0
- package/src/core/softShadows.js +161 -0
- package/src/core/useAnimations.js +56 -0
- package/src/core/useAspect.js +10 -0
- package/src/core/useBVH.js +90 -0
- package/src/core/useBoxProjectedEnv.js +98 -0
- package/src/core/useCamera.js +27 -0
- package/src/core/useContextBridge.js +21 -0
- package/src/core/useCubeCamera.js +49 -0
- package/src/core/useCubeTexture.js +18 -0
- package/src/core/useDepthBuffer.js +38 -0
- package/src/core/useDetectGPU.js +6 -0
- package/src/core/useEnvironment.js +48 -0
- package/src/core/useFBO.js +53 -0
- package/src/core/useFBX.js +12 -0
- package/src/core/useFont.js +20 -0
- package/src/core/useGLTF.js +37 -0
- package/src/core/useHelper.js +31 -0
- package/src/core/useIntersect.js +39 -0
- package/src/core/useKTX2.js +38 -0
- package/src/core/useMatcapTexture.js +45 -0
- package/src/core/useNormalTexture.js +30 -0
- package/src/core/useProgress.js +50 -0
- package/src/core/useTexture.js +35 -0
- package/src/core/useTrailTexture.js +164 -0
- package/src/core/useVideoTexture.js +41 -0
- package/src/helpers/environment-assets.js +14 -0
- package/src/helpers/useEffectfulState.js +18 -0
- package/src/materials/BlurPass.js +75 -0
- package/src/materials/ConvolutionMaterial.js +99 -0
- package/src/materials/DiscardMaterial.js +5 -0
- package/src/materials/MeshReflectorMaterial.js +290 -0
- package/src/materials/MeshRefractionMaterial.js +171 -0
- package/src/materials/SpotLightMaterial.js +111 -0
- package/src/materials/WireframeMaterial.js +235 -0
- package/src/web/CycleRaycast.js +97 -0
- package/src/web/Html.js +417 -0
- package/src/web/KeyboardControls.js +101 -0
- package/src/web/Loader.js +98 -0
- package/src/web/PresentationControls.js +86 -0
- package/src/web/ScrollControls.js +246 -0
- package/src/web/Select.js +175 -0
- package/src/web/View.js +206 -0
- package/src/web/pivotControls/AxisArrow.js +202 -0
- package/src/web/pivotControls/AxisRotator.js +235 -0
- package/src/web/pivotControls/PlaneSlider.js +211 -0
- package/src/web/pivotControls/context.js +5 -0
- package/src/web/pivotControls/index.js +223 -0
- package/src/web/useCursor.js +12 -0
- package/web/Loader.js +2 -0
- package/web/index.cjs.js +1 -1
- package/web/index.js +0 -1
- package/web/pivotControls/AxisArrow.js +3 -0
- package/web/pivotControls/AxisRotator.js +3 -0
- package/web/pivotControls/PlaneSlider.js +3 -0
- package/web/pivotControls/index.js +5 -0
- /package/{helpers → src/helpers}/glsl/DefaultSpotlightShadowShadows.glsl.js +0 -0
- /package/{helpers → src/helpers}/glsl/distort.vert.glsl.js +0 -0
- /package/{index.js → src/index.js} +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useThree, useFrame } from '@react-three/fiber';
|
|
4
|
+
import { FirstPersonControls as FirstPersonControls$1 } from 'three-stdlib';
|
|
5
|
+
|
|
6
|
+
const FirstPersonControls = /*#__PURE__*/React.forwardRef(({
|
|
7
|
+
domElement,
|
|
8
|
+
makeDefault,
|
|
9
|
+
...props
|
|
10
|
+
}, ref) => {
|
|
11
|
+
const camera = useThree(state => state.camera);
|
|
12
|
+
const gl = useThree(state => state.gl);
|
|
13
|
+
const events = useThree(state => state.events);
|
|
14
|
+
const get = useThree(state => state.get);
|
|
15
|
+
const set = useThree(state => state.set);
|
|
16
|
+
const explDomElement = domElement || events.connected || gl.domElement;
|
|
17
|
+
const [controls] = React.useState(() => new FirstPersonControls$1(camera, explDomElement));
|
|
18
|
+
React.useEffect(() => {
|
|
19
|
+
if (makeDefault) {
|
|
20
|
+
const old = get().controls;
|
|
21
|
+
set({
|
|
22
|
+
controls
|
|
23
|
+
});
|
|
24
|
+
return () => set({
|
|
25
|
+
controls: old
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}, [makeDefault, controls]);
|
|
29
|
+
useFrame((_, delta) => {
|
|
30
|
+
controls.update(delta);
|
|
31
|
+
}, -1);
|
|
32
|
+
return controls ? /*#__PURE__*/React.createElement("primitive", _extends({
|
|
33
|
+
ref: ref,
|
|
34
|
+
object: controls
|
|
35
|
+
}, props)) : null;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export { FirstPersonControls };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useFrame } from '@react-three/fiber';
|
|
3
|
+
import mergeRefs from 'react-merge-refs';
|
|
4
|
+
import * as THREE from 'three';
|
|
5
|
+
|
|
6
|
+
const Float = /*#__PURE__*/React.forwardRef(({
|
|
7
|
+
children,
|
|
8
|
+
enabled = true,
|
|
9
|
+
speed = 1,
|
|
10
|
+
rotationIntensity = 1,
|
|
11
|
+
floatIntensity = 1,
|
|
12
|
+
floatingRange = [-0.1, 0.1],
|
|
13
|
+
...props
|
|
14
|
+
}, forwardRef) => {
|
|
15
|
+
const ref = React.useRef(null);
|
|
16
|
+
const offset = React.useRef(Math.random() * 10000);
|
|
17
|
+
useFrame(state => {
|
|
18
|
+
var _floatingRange$, _floatingRange$2;
|
|
19
|
+
|
|
20
|
+
if (!enabled || speed === 0) return;
|
|
21
|
+
const t = offset.current + state.clock.getElapsedTime();
|
|
22
|
+
ref.current.rotation.x = Math.cos(t / 4 * speed) / 8 * rotationIntensity;
|
|
23
|
+
ref.current.rotation.y = Math.sin(t / 4 * speed) / 8 * rotationIntensity;
|
|
24
|
+
ref.current.rotation.z = Math.sin(t / 4 * speed) / 20 * rotationIntensity;
|
|
25
|
+
let yPosition = Math.sin(t / 4 * speed) / 10;
|
|
26
|
+
yPosition = THREE.MathUtils.mapLinear(yPosition, -0.1, 0.1, (_floatingRange$ = floatingRange == null ? void 0 : floatingRange[0]) !== null && _floatingRange$ !== void 0 ? _floatingRange$ : -0.1, (_floatingRange$2 = floatingRange == null ? void 0 : floatingRange[1]) !== null && _floatingRange$2 !== void 0 ? _floatingRange$2 : 0.1);
|
|
27
|
+
ref.current.position.y = yPosition * floatIntensity;
|
|
28
|
+
ref.current.updateMatrix();
|
|
29
|
+
});
|
|
30
|
+
return /*#__PURE__*/React.createElement("group", props, /*#__PURE__*/React.createElement("group", {
|
|
31
|
+
ref: mergeRefs([ref, forwardRef]),
|
|
32
|
+
matrixAutoUpdate: false
|
|
33
|
+
}, children));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export { Float };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import { useThree, useFrame } from '@react-three/fiber';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { FlyControls as FlyControls$1 } from 'three-stdlib';
|
|
5
|
+
|
|
6
|
+
const FlyControls = /*#__PURE__*/React.forwardRef(({
|
|
7
|
+
domElement,
|
|
8
|
+
...props
|
|
9
|
+
}, fref) => {
|
|
10
|
+
const {
|
|
11
|
+
onChange,
|
|
12
|
+
makeDefault,
|
|
13
|
+
...rest
|
|
14
|
+
} = props;
|
|
15
|
+
const invalidate = useThree(state => state.invalidate);
|
|
16
|
+
const camera = useThree(state => state.camera);
|
|
17
|
+
const gl = useThree(state => state.gl);
|
|
18
|
+
const events = useThree(state => state.events);
|
|
19
|
+
const get = useThree(state => state.get);
|
|
20
|
+
const set = useThree(state => state.set);
|
|
21
|
+
const explDomElement = domElement || events.connected || gl.domElement;
|
|
22
|
+
const controls = React.useMemo(() => new FlyControls$1(camera), [camera]);
|
|
23
|
+
React.useEffect(() => {
|
|
24
|
+
controls.connect(explDomElement);
|
|
25
|
+
return () => void controls.dispose();
|
|
26
|
+
}, [explDomElement, controls, invalidate]);
|
|
27
|
+
React.useEffect(() => {
|
|
28
|
+
const callback = e => {
|
|
29
|
+
invalidate();
|
|
30
|
+
if (onChange) onChange(e);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
controls.addEventListener == null ? void 0 : controls.addEventListener('change', callback);
|
|
34
|
+
return () => controls.removeEventListener == null ? void 0 : controls.removeEventListener('change', callback);
|
|
35
|
+
}, [onChange, invalidate]);
|
|
36
|
+
React.useEffect(() => {
|
|
37
|
+
if (makeDefault) {
|
|
38
|
+
const old = get().controls;
|
|
39
|
+
set({
|
|
40
|
+
controls
|
|
41
|
+
});
|
|
42
|
+
return () => set({
|
|
43
|
+
controls: old
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}, [makeDefault, controls]);
|
|
47
|
+
useFrame((_, delta) => controls.update(delta));
|
|
48
|
+
return /*#__PURE__*/React.createElement("primitive", _extends({
|
|
49
|
+
ref: fref,
|
|
50
|
+
object: controls,
|
|
51
|
+
args: [camera, explDomElement]
|
|
52
|
+
}, rest));
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export { FlyControls };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useThree, useFrame } from '@react-three/fiber';
|
|
3
|
+
import { Object3D, Matrix4, Quaternion, Vector3 } from 'three';
|
|
4
|
+
import { OrthographicCamera } from './OrthographicCamera.js';
|
|
5
|
+
import { Hud } from './Hud.js';
|
|
6
|
+
|
|
7
|
+
const Context = /*#__PURE__*/React.createContext({});
|
|
8
|
+
const useGizmoContext = () => {
|
|
9
|
+
return React.useContext(Context);
|
|
10
|
+
};
|
|
11
|
+
const turnRate = 2 * Math.PI; // turn rate in angles per second
|
|
12
|
+
|
|
13
|
+
const dummy = new Object3D();
|
|
14
|
+
const matrix = new Matrix4();
|
|
15
|
+
const [q1, q2] = [new Quaternion(), new Quaternion()];
|
|
16
|
+
const target = new Vector3();
|
|
17
|
+
const targetPosition = new Vector3();
|
|
18
|
+
|
|
19
|
+
const isOrbitControls = controls => {
|
|
20
|
+
return 'minPolarAngle' in controls;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const GizmoHelper = ({
|
|
24
|
+
alignment = 'bottom-right',
|
|
25
|
+
margin = [80, 80],
|
|
26
|
+
renderPriority = 1,
|
|
27
|
+
onUpdate,
|
|
28
|
+
onTarget,
|
|
29
|
+
children
|
|
30
|
+
}) => {
|
|
31
|
+
const size = useThree(state => state.size);
|
|
32
|
+
const mainCamera = useThree(state => state.camera); // @ts-ignore
|
|
33
|
+
|
|
34
|
+
const defaultControls = useThree(state => state.controls);
|
|
35
|
+
const invalidate = useThree(state => state.invalidate);
|
|
36
|
+
const gizmoRef = React.useRef();
|
|
37
|
+
const virtualCam = React.useRef(null);
|
|
38
|
+
const animating = React.useRef(false);
|
|
39
|
+
const radius = React.useRef(0);
|
|
40
|
+
const focusPoint = React.useRef(new Vector3(0, 0, 0));
|
|
41
|
+
const defaultUp = React.useRef(new Vector3(0, 0, 0));
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
defaultUp.current.copy(mainCamera.up);
|
|
44
|
+
}, [mainCamera]);
|
|
45
|
+
const tweenCamera = React.useCallback(direction => {
|
|
46
|
+
animating.current = true;
|
|
47
|
+
if (defaultControls || onTarget) focusPoint.current = (defaultControls == null ? void 0 : defaultControls.target) || (onTarget == null ? void 0 : onTarget());
|
|
48
|
+
radius.current = mainCamera.position.distanceTo(target); // Rotate from current camera orientation
|
|
49
|
+
|
|
50
|
+
q1.copy(mainCamera.quaternion); // To new current camera orientation
|
|
51
|
+
|
|
52
|
+
targetPosition.copy(direction).multiplyScalar(radius.current).add(target);
|
|
53
|
+
dummy.lookAt(targetPosition);
|
|
54
|
+
dummy.up.copy(mainCamera.up);
|
|
55
|
+
q2.copy(dummy.quaternion);
|
|
56
|
+
invalidate();
|
|
57
|
+
}, [defaultControls, mainCamera, onTarget, invalidate]);
|
|
58
|
+
useFrame((_, delta) => {
|
|
59
|
+
if (virtualCam.current && gizmoRef.current) {
|
|
60
|
+
var _gizmoRef$current;
|
|
61
|
+
|
|
62
|
+
// Animate step
|
|
63
|
+
if (animating.current) {
|
|
64
|
+
if (q1.angleTo(q2) < 0.01) {
|
|
65
|
+
animating.current = false; // Orbit controls uses UP vector as the orbit axes,
|
|
66
|
+
// so we need to reset it after the animation is done
|
|
67
|
+
// moving it around for the controls to work correctly
|
|
68
|
+
|
|
69
|
+
if (isOrbitControls(defaultControls)) {
|
|
70
|
+
mainCamera.up.copy(defaultUp.current);
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
const step = delta * turnRate; // animate position by doing a slerp and then scaling the position on the unit sphere
|
|
74
|
+
|
|
75
|
+
q1.rotateTowards(q2, step); // animate orientation
|
|
76
|
+
|
|
77
|
+
mainCamera.position.set(0, 0, 1).applyQuaternion(q1).multiplyScalar(radius.current).add(focusPoint.current);
|
|
78
|
+
mainCamera.up.set(0, 1, 0).applyQuaternion(q1).normalize();
|
|
79
|
+
mainCamera.quaternion.copy(q1);
|
|
80
|
+
if (onUpdate) onUpdate();else if (defaultControls) defaultControls.update();
|
|
81
|
+
invalidate();
|
|
82
|
+
}
|
|
83
|
+
} // Sync Gizmo with main camera orientation
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
matrix.copy(mainCamera.matrix).invert();
|
|
87
|
+
(_gizmoRef$current = gizmoRef.current) == null ? void 0 : _gizmoRef$current.quaternion.setFromRotationMatrix(matrix);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const gizmoHelperContext = React.useMemo(() => ({
|
|
91
|
+
tweenCamera
|
|
92
|
+
}), [tweenCamera]); // Position gizmo component within scene
|
|
93
|
+
|
|
94
|
+
const [marginX, marginY] = margin;
|
|
95
|
+
const x = alignment.endsWith('-center') ? 0 : alignment.endsWith('-left') ? -size.width / 2 + marginX : size.width / 2 - marginX;
|
|
96
|
+
const y = alignment.startsWith('center-') ? 0 : alignment.startsWith('top-') ? size.height / 2 - marginY : -size.height / 2 + marginY;
|
|
97
|
+
return /*#__PURE__*/React.createElement(Hud, {
|
|
98
|
+
renderPriority: renderPriority
|
|
99
|
+
}, /*#__PURE__*/React.createElement(Context.Provider, {
|
|
100
|
+
value: gizmoHelperContext
|
|
101
|
+
}, /*#__PURE__*/React.createElement(OrthographicCamera, {
|
|
102
|
+
makeDefault: true,
|
|
103
|
+
ref: virtualCam,
|
|
104
|
+
position: [0, 0, 200]
|
|
105
|
+
}), /*#__PURE__*/React.createElement("group", {
|
|
106
|
+
ref: gizmoRef,
|
|
107
|
+
position: [x, y, 0]
|
|
108
|
+
}, children)));
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export { GizmoHelper, useGizmoContext };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useThree } from '@react-three/fiber';
|
|
4
|
+
import { useGizmoContext } from './GizmoHelper.js';
|
|
5
|
+
import { Vector3, CanvasTexture } from 'three';
|
|
6
|
+
|
|
7
|
+
const colors = {
|
|
8
|
+
bg: '#f0f0f0',
|
|
9
|
+
hover: '#999',
|
|
10
|
+
text: 'black',
|
|
11
|
+
stroke: 'black'
|
|
12
|
+
};
|
|
13
|
+
const defaultFaces = ['Right', 'Left', 'Top', 'Bottom', 'Front', 'Back'];
|
|
14
|
+
|
|
15
|
+
const makePositionVector = xyz => new Vector3(...xyz).multiplyScalar(0.38);
|
|
16
|
+
|
|
17
|
+
const corners = [[1, 1, 1], [1, 1, -1], [1, -1, 1], [1, -1, -1], [-1, 1, 1], [-1, 1, -1], [-1, -1, 1], [-1, -1, -1]].map(makePositionVector);
|
|
18
|
+
const cornerDimensions = [0.25, 0.25, 0.25];
|
|
19
|
+
const edges = [[1, 1, 0], [1, 0, 1], [1, 0, -1], [1, -1, 0], [0, 1, 1], [0, 1, -1], [0, -1, 1], [0, -1, -1], [-1, 1, 0], [-1, 0, 1], [-1, 0, -1], [-1, -1, 0]].map(makePositionVector);
|
|
20
|
+
const edgeDimensions = edges.map(edge => edge.toArray().map(axis => axis == 0 ? 0.5 : 0.25));
|
|
21
|
+
|
|
22
|
+
const FaceMaterial = ({
|
|
23
|
+
hover,
|
|
24
|
+
index,
|
|
25
|
+
font = '20px Inter var, Arial, sans-serif',
|
|
26
|
+
faces = defaultFaces,
|
|
27
|
+
color = colors.bg,
|
|
28
|
+
hoverColor = colors.hover,
|
|
29
|
+
textColor = colors.text,
|
|
30
|
+
strokeColor = colors.stroke,
|
|
31
|
+
opacity = 1
|
|
32
|
+
}) => {
|
|
33
|
+
const gl = useThree(state => state.gl);
|
|
34
|
+
const texture = React.useMemo(() => {
|
|
35
|
+
const canvas = document.createElement('canvas');
|
|
36
|
+
canvas.width = 128;
|
|
37
|
+
canvas.height = 128;
|
|
38
|
+
const context = canvas.getContext('2d');
|
|
39
|
+
context.fillStyle = color;
|
|
40
|
+
context.fillRect(0, 0, canvas.width, canvas.height);
|
|
41
|
+
context.strokeStyle = strokeColor;
|
|
42
|
+
context.strokeRect(0, 0, canvas.width, canvas.height);
|
|
43
|
+
context.font = font;
|
|
44
|
+
context.textAlign = 'center';
|
|
45
|
+
context.fillStyle = textColor;
|
|
46
|
+
context.fillText(faces[index].toUpperCase(), 64, 76);
|
|
47
|
+
return new CanvasTexture(canvas);
|
|
48
|
+
}, [index, faces, font, color, textColor, strokeColor]);
|
|
49
|
+
return /*#__PURE__*/React.createElement("meshLambertMaterial", {
|
|
50
|
+
map: texture,
|
|
51
|
+
"map-anisotropy": gl.capabilities.getMaxAnisotropy() || 1,
|
|
52
|
+
attach: `material-${index}`,
|
|
53
|
+
color: hover ? hoverColor : 'white',
|
|
54
|
+
transparent: true,
|
|
55
|
+
opacity: opacity
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const FaceCube = props => {
|
|
60
|
+
const {
|
|
61
|
+
tweenCamera
|
|
62
|
+
} = useGizmoContext();
|
|
63
|
+
const [hover, setHover] = React.useState(null);
|
|
64
|
+
|
|
65
|
+
const handlePointerOut = e => {
|
|
66
|
+
e.stopPropagation();
|
|
67
|
+
setHover(null);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const handleClick = e => {
|
|
71
|
+
e.stopPropagation();
|
|
72
|
+
tweenCamera(e.face.normal);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const handlePointerMove = e => {
|
|
76
|
+
e.stopPropagation();
|
|
77
|
+
setHover(Math.floor(e.faceIndex / 2));
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return /*#__PURE__*/React.createElement("mesh", {
|
|
81
|
+
onPointerOut: handlePointerOut,
|
|
82
|
+
onPointerMove: handlePointerMove,
|
|
83
|
+
onClick: props.onClick || handleClick
|
|
84
|
+
}, [...Array(6)].map((_, index) => /*#__PURE__*/React.createElement(FaceMaterial, _extends({
|
|
85
|
+
key: index,
|
|
86
|
+
index: index,
|
|
87
|
+
hover: hover === index
|
|
88
|
+
}, props))), /*#__PURE__*/React.createElement("boxGeometry", null));
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const EdgeCube = ({
|
|
92
|
+
onClick,
|
|
93
|
+
dimensions,
|
|
94
|
+
position,
|
|
95
|
+
hoverColor = colors.hover
|
|
96
|
+
}) => {
|
|
97
|
+
const {
|
|
98
|
+
tweenCamera
|
|
99
|
+
} = useGizmoContext();
|
|
100
|
+
const [hover, setHover] = React.useState(false);
|
|
101
|
+
|
|
102
|
+
const handlePointerOut = e => {
|
|
103
|
+
e.stopPropagation();
|
|
104
|
+
setHover(false);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const handlePointerOver = e => {
|
|
108
|
+
e.stopPropagation();
|
|
109
|
+
setHover(true);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const handleClick = e => {
|
|
113
|
+
e.stopPropagation();
|
|
114
|
+
tweenCamera(position);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
return /*#__PURE__*/React.createElement("mesh", {
|
|
118
|
+
scale: 1.01,
|
|
119
|
+
position: position,
|
|
120
|
+
onPointerOver: handlePointerOver,
|
|
121
|
+
onPointerOut: handlePointerOut,
|
|
122
|
+
onClick: onClick || handleClick
|
|
123
|
+
}, /*#__PURE__*/React.createElement("meshBasicMaterial", {
|
|
124
|
+
color: hover ? hoverColor : 'white',
|
|
125
|
+
transparent: true,
|
|
126
|
+
opacity: 0.6,
|
|
127
|
+
visible: hover
|
|
128
|
+
}), /*#__PURE__*/React.createElement("boxGeometry", {
|
|
129
|
+
args: dimensions
|
|
130
|
+
}));
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const GizmoViewcube = props => {
|
|
134
|
+
return /*#__PURE__*/React.createElement("group", {
|
|
135
|
+
scale: [60, 60, 60]
|
|
136
|
+
}, /*#__PURE__*/React.createElement(FaceCube, props), edges.map((edge, index) => /*#__PURE__*/React.createElement(EdgeCube, _extends({
|
|
137
|
+
key: index,
|
|
138
|
+
position: edge,
|
|
139
|
+
dimensions: edgeDimensions[index]
|
|
140
|
+
}, props))), corners.map((corner, index) => /*#__PURE__*/React.createElement(EdgeCube, _extends({
|
|
141
|
+
key: index,
|
|
142
|
+
position: corner,
|
|
143
|
+
dimensions: cornerDimensions
|
|
144
|
+
}, props))), /*#__PURE__*/React.createElement("ambientLight", {
|
|
145
|
+
intensity: 0.5
|
|
146
|
+
}), /*#__PURE__*/React.createElement("pointLight", {
|
|
147
|
+
position: [10, 10, 10],
|
|
148
|
+
intensity: 0.5
|
|
149
|
+
}));
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export { GizmoViewcube };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useThree } from '@react-three/fiber';
|
|
4
|
+
import { CanvasTexture } from 'three';
|
|
5
|
+
import { useGizmoContext } from './GizmoHelper.js';
|
|
6
|
+
|
|
7
|
+
function Axis({
|
|
8
|
+
scale = [0.8, 0.05, 0.05],
|
|
9
|
+
color,
|
|
10
|
+
rotation
|
|
11
|
+
}) {
|
|
12
|
+
return /*#__PURE__*/React.createElement("group", {
|
|
13
|
+
rotation: rotation
|
|
14
|
+
}, /*#__PURE__*/React.createElement("mesh", {
|
|
15
|
+
position: [0.4, 0, 0]
|
|
16
|
+
}, /*#__PURE__*/React.createElement("boxGeometry", {
|
|
17
|
+
args: scale
|
|
18
|
+
}), /*#__PURE__*/React.createElement("meshBasicMaterial", {
|
|
19
|
+
color: color,
|
|
20
|
+
toneMapped: false
|
|
21
|
+
})));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function AxisHead({
|
|
25
|
+
onClick,
|
|
26
|
+
font,
|
|
27
|
+
disabled,
|
|
28
|
+
arcStyle,
|
|
29
|
+
label,
|
|
30
|
+
labelColor,
|
|
31
|
+
axisHeadScale = 1,
|
|
32
|
+
...props
|
|
33
|
+
}) {
|
|
34
|
+
const gl = useThree(state => state.gl);
|
|
35
|
+
const texture = React.useMemo(() => {
|
|
36
|
+
const canvas = document.createElement('canvas');
|
|
37
|
+
canvas.width = 64;
|
|
38
|
+
canvas.height = 64;
|
|
39
|
+
const context = canvas.getContext('2d');
|
|
40
|
+
context.beginPath();
|
|
41
|
+
context.arc(32, 32, 16, 0, 2 * Math.PI);
|
|
42
|
+
context.closePath();
|
|
43
|
+
context.fillStyle = arcStyle;
|
|
44
|
+
context.fill();
|
|
45
|
+
|
|
46
|
+
if (label) {
|
|
47
|
+
context.font = font;
|
|
48
|
+
context.textAlign = 'center';
|
|
49
|
+
context.fillStyle = labelColor;
|
|
50
|
+
context.fillText(label, 32, 41);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return new CanvasTexture(canvas);
|
|
54
|
+
}, [arcStyle, label, labelColor, font]);
|
|
55
|
+
const [active, setActive] = React.useState(false);
|
|
56
|
+
const scale = (label ? 1 : 0.75) * (active ? 1.2 : 1) * axisHeadScale;
|
|
57
|
+
|
|
58
|
+
const handlePointerOver = e => {
|
|
59
|
+
e.stopPropagation();
|
|
60
|
+
setActive(true);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const handlePointerOut = e => {
|
|
64
|
+
e.stopPropagation();
|
|
65
|
+
setActive(false);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return /*#__PURE__*/React.createElement("sprite", _extends({
|
|
69
|
+
scale: scale,
|
|
70
|
+
onPointerOver: !disabled ? handlePointerOver : undefined,
|
|
71
|
+
onPointerOut: !disabled ? onClick || handlePointerOut : undefined
|
|
72
|
+
}, props), /*#__PURE__*/React.createElement("spriteMaterial", {
|
|
73
|
+
map: texture,
|
|
74
|
+
"map-anisotropy": gl.capabilities.getMaxAnisotropy() || 1,
|
|
75
|
+
alphaTest: 0.3,
|
|
76
|
+
opacity: label ? 1 : 0.75,
|
|
77
|
+
toneMapped: false
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const GizmoViewport = ({
|
|
82
|
+
hideNegativeAxes,
|
|
83
|
+
hideAxisHeads,
|
|
84
|
+
disabled,
|
|
85
|
+
font = '18px Inter var, Arial, sans-serif',
|
|
86
|
+
axisColors = ['#ff2060', '#20df80', '#2080ff'],
|
|
87
|
+
axisHeadScale = 1,
|
|
88
|
+
axisScale,
|
|
89
|
+
labels = ['X', 'Y', 'Z'],
|
|
90
|
+
labelColor = '#000',
|
|
91
|
+
onClick,
|
|
92
|
+
...props
|
|
93
|
+
}) => {
|
|
94
|
+
const [colorX, colorY, colorZ] = axisColors;
|
|
95
|
+
const {
|
|
96
|
+
tweenCamera
|
|
97
|
+
} = useGizmoContext();
|
|
98
|
+
const axisHeadProps = {
|
|
99
|
+
font,
|
|
100
|
+
disabled,
|
|
101
|
+
labelColor,
|
|
102
|
+
onClick,
|
|
103
|
+
axisHeadScale,
|
|
104
|
+
onPointerDown: !disabled ? e => {
|
|
105
|
+
tweenCamera(e.object.position);
|
|
106
|
+
e.stopPropagation();
|
|
107
|
+
} : undefined
|
|
108
|
+
};
|
|
109
|
+
return /*#__PURE__*/React.createElement("group", _extends({
|
|
110
|
+
scale: 40
|
|
111
|
+
}, props), /*#__PURE__*/React.createElement(Axis, {
|
|
112
|
+
color: colorX,
|
|
113
|
+
rotation: [0, 0, 0],
|
|
114
|
+
scale: axisScale
|
|
115
|
+
}), /*#__PURE__*/React.createElement(Axis, {
|
|
116
|
+
color: colorY,
|
|
117
|
+
rotation: [0, 0, Math.PI / 2],
|
|
118
|
+
scale: axisScale
|
|
119
|
+
}), /*#__PURE__*/React.createElement(Axis, {
|
|
120
|
+
color: colorZ,
|
|
121
|
+
rotation: [0, -Math.PI / 2, 0],
|
|
122
|
+
scale: axisScale
|
|
123
|
+
}), !hideAxisHeads && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(AxisHead, _extends({
|
|
124
|
+
arcStyle: colorX,
|
|
125
|
+
position: [1, 0, 0],
|
|
126
|
+
label: labels[0]
|
|
127
|
+
}, axisHeadProps)), /*#__PURE__*/React.createElement(AxisHead, _extends({
|
|
128
|
+
arcStyle: colorY,
|
|
129
|
+
position: [0, 1, 0],
|
|
130
|
+
label: labels[1]
|
|
131
|
+
}, axisHeadProps)), /*#__PURE__*/React.createElement(AxisHead, _extends({
|
|
132
|
+
arcStyle: colorZ,
|
|
133
|
+
position: [0, 0, 1],
|
|
134
|
+
label: labels[2]
|
|
135
|
+
}, axisHeadProps)), !hideNegativeAxes && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(AxisHead, _extends({
|
|
136
|
+
arcStyle: colorX,
|
|
137
|
+
position: [-1, 0, 0]
|
|
138
|
+
}, axisHeadProps)), /*#__PURE__*/React.createElement(AxisHead, _extends({
|
|
139
|
+
arcStyle: colorY,
|
|
140
|
+
position: [0, -1, 0]
|
|
141
|
+
}, axisHeadProps)), /*#__PURE__*/React.createElement(AxisHead, _extends({
|
|
142
|
+
arcStyle: colorZ,
|
|
143
|
+
position: [0, 0, -1]
|
|
144
|
+
}, axisHeadProps)))), /*#__PURE__*/React.createElement("ambientLight", {
|
|
145
|
+
intensity: 0.5
|
|
146
|
+
}), /*#__PURE__*/React.createElement("pointLight", {
|
|
147
|
+
position: [10, 10, 10],
|
|
148
|
+
intensity: 0.5
|
|
149
|
+
}));
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export { GizmoViewport };
|
package/src/core/Gltf.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useGLTF } from './useGLTF.js';
|
|
4
|
+
import { Clone } from './Clone.js';
|
|
5
|
+
|
|
6
|
+
const Gltf = /*#__PURE__*/React.forwardRef(({
|
|
7
|
+
src,
|
|
8
|
+
...props
|
|
9
|
+
}, ref) => {
|
|
10
|
+
const {
|
|
11
|
+
scene
|
|
12
|
+
} = useGLTF(src);
|
|
13
|
+
return /*#__PURE__*/React.createElement(Clone, _extends({
|
|
14
|
+
ref: ref
|
|
15
|
+
}, props, {
|
|
16
|
+
object: scene
|
|
17
|
+
}));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export { Gltf };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
function GradientTexture({
|
|
5
|
+
stops,
|
|
6
|
+
colors,
|
|
7
|
+
size = 1024,
|
|
8
|
+
...props
|
|
9
|
+
}) {
|
|
10
|
+
const canvas = React.useMemo(() => {
|
|
11
|
+
const canvas = document.createElement('canvas');
|
|
12
|
+
const context = canvas.getContext('2d');
|
|
13
|
+
canvas.width = 16;
|
|
14
|
+
canvas.height = size;
|
|
15
|
+
const gradient = context.createLinearGradient(0, 0, 0, size);
|
|
16
|
+
let i = stops.length;
|
|
17
|
+
|
|
18
|
+
while (i--) {
|
|
19
|
+
gradient.addColorStop(stops[i], colors[i]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
context.fillStyle = gradient;
|
|
23
|
+
context.fillRect(0, 0, 16, size);
|
|
24
|
+
return canvas;
|
|
25
|
+
}, [stops]); // @ts-ignore ????
|
|
26
|
+
|
|
27
|
+
return /*#__PURE__*/React.createElement("canvasTexture", _extends({
|
|
28
|
+
args: [canvas],
|
|
29
|
+
attach: "map"
|
|
30
|
+
}, props));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { GradientTexture };
|