@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,52 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Shape } from 'three';
|
|
4
|
+
import { toCreasedNormals } from 'three-stdlib';
|
|
5
|
+
|
|
6
|
+
const eps = 0.00001;
|
|
7
|
+
|
|
8
|
+
function createShape(width, height, radius0) {
|
|
9
|
+
const shape = new Shape();
|
|
10
|
+
const radius = radius0 - eps;
|
|
11
|
+
shape.absarc(eps, eps, eps, -Math.PI / 2, -Math.PI, true);
|
|
12
|
+
shape.absarc(eps, height - radius * 2, eps, Math.PI, Math.PI / 2, true);
|
|
13
|
+
shape.absarc(width - radius * 2, height - radius * 2, eps, Math.PI / 2, 0, true);
|
|
14
|
+
shape.absarc(width - radius * 2, eps, eps, 0, -Math.PI / 2, true);
|
|
15
|
+
return shape;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const RoundedBox = /*#__PURE__*/React.forwardRef(function RoundedBox({
|
|
19
|
+
args: [width = 1, height = 1, depth = 1] = [],
|
|
20
|
+
radius = 0.05,
|
|
21
|
+
steps = 1,
|
|
22
|
+
smoothness = 4,
|
|
23
|
+
creaseAngle = 0.4,
|
|
24
|
+
children,
|
|
25
|
+
...rest
|
|
26
|
+
}, ref) {
|
|
27
|
+
const shape = React.useMemo(() => createShape(width, height, radius), [width, height, radius]);
|
|
28
|
+
const params = React.useMemo(() => ({
|
|
29
|
+
depth: depth - radius * 2,
|
|
30
|
+
bevelEnabled: true,
|
|
31
|
+
bevelSegments: smoothness * 2,
|
|
32
|
+
steps,
|
|
33
|
+
bevelSize: radius - eps,
|
|
34
|
+
bevelThickness: radius,
|
|
35
|
+
curveSegments: smoothness
|
|
36
|
+
}), [depth, radius, smoothness]);
|
|
37
|
+
const geomRef = React.useRef();
|
|
38
|
+
React.useLayoutEffect(() => {
|
|
39
|
+
if (geomRef.current) {
|
|
40
|
+
geomRef.current.center();
|
|
41
|
+
toCreasedNormals(geomRef.current, creaseAngle);
|
|
42
|
+
}
|
|
43
|
+
}, [shape, params]);
|
|
44
|
+
return /*#__PURE__*/React.createElement("mesh", _extends({
|
|
45
|
+
ref: ref
|
|
46
|
+
}, rest), /*#__PURE__*/React.createElement("extrudeGeometry", {
|
|
47
|
+
ref: geomRef,
|
|
48
|
+
args: [shape, params]
|
|
49
|
+
}), children);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export { RoundedBox };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { MeshSurfaceSampler } from 'three-stdlib';
|
|
4
|
+
import { InstancedBufferAttribute, Vector3, Color, Object3D } from 'three';
|
|
5
|
+
|
|
6
|
+
function useSurfaceSampler(mesh, count = 16, transform, weight, instanceMesh) {
|
|
7
|
+
const [buffer, setBuffer] = React.useState(() => {
|
|
8
|
+
const arr = Array.from({
|
|
9
|
+
length: count
|
|
10
|
+
}, () => [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]).flat();
|
|
11
|
+
return new InstancedBufferAttribute(Float32Array.from(arr), 16);
|
|
12
|
+
});
|
|
13
|
+
React.useLayoutEffect(() => {
|
|
14
|
+
if (typeof mesh.current === 'undefined') return;
|
|
15
|
+
const sampler = new MeshSurfaceSampler(mesh.current);
|
|
16
|
+
|
|
17
|
+
if (weight) {
|
|
18
|
+
sampler.setWeightAttribute(weight);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
sampler.build();
|
|
22
|
+
const position = new Vector3();
|
|
23
|
+
const normal = new Vector3();
|
|
24
|
+
const color = new Color();
|
|
25
|
+
const dummy = new Object3D();
|
|
26
|
+
mesh.current.updateMatrixWorld(true);
|
|
27
|
+
|
|
28
|
+
for (let i = 0; i < count; i++) {
|
|
29
|
+
sampler.sample(position, normal, color);
|
|
30
|
+
|
|
31
|
+
if (typeof transform === 'function') {
|
|
32
|
+
transform({
|
|
33
|
+
dummy,
|
|
34
|
+
sampledMesh: mesh.current,
|
|
35
|
+
position,
|
|
36
|
+
normal,
|
|
37
|
+
color
|
|
38
|
+
}, i);
|
|
39
|
+
} else {
|
|
40
|
+
dummy.position.copy(position);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
dummy.updateMatrix();
|
|
44
|
+
|
|
45
|
+
if (instanceMesh != null && instanceMesh.current) {
|
|
46
|
+
instanceMesh.current.setMatrixAt(i, dummy.matrix);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
dummy.matrix.toArray(buffer.array, i * 16);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (instanceMesh != null && instanceMesh.current) {
|
|
53
|
+
instanceMesh.current.instanceMatrix.needsUpdate = true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
buffer.needsUpdate = true;
|
|
57
|
+
setBuffer(buffer.clone());
|
|
58
|
+
}, [mesh, instanceMesh, weight, count, transform]);
|
|
59
|
+
return buffer;
|
|
60
|
+
}
|
|
61
|
+
function Sampler({
|
|
62
|
+
children,
|
|
63
|
+
weight,
|
|
64
|
+
transform,
|
|
65
|
+
instances,
|
|
66
|
+
mesh,
|
|
67
|
+
count = 16,
|
|
68
|
+
...props
|
|
69
|
+
}) {
|
|
70
|
+
const group = React.useRef(null);
|
|
71
|
+
const instancedRef = React.useRef(null);
|
|
72
|
+
const meshToSampleRef = React.useRef(null);
|
|
73
|
+
React.useLayoutEffect(() => {
|
|
74
|
+
var _instances$current, _mesh$current;
|
|
75
|
+
|
|
76
|
+
instancedRef.current = (_instances$current = instances == null ? void 0 : instances.current) !== null && _instances$current !== void 0 ? _instances$current : group.current.children.find(c => c.hasOwnProperty('instanceMatrix'));
|
|
77
|
+
meshToSampleRef.current = (_mesh$current = mesh == null ? void 0 : mesh.current) !== null && _mesh$current !== void 0 ? _mesh$current : group.current.children.find(c => c.type === 'Mesh');
|
|
78
|
+
}, [children, mesh == null ? void 0 : mesh.current, instances == null ? void 0 : instances.current]);
|
|
79
|
+
useSurfaceSampler(meshToSampleRef, count, transform, weight, instancedRef);
|
|
80
|
+
return /*#__PURE__*/React.createElement("group", _extends({
|
|
81
|
+
ref: group
|
|
82
|
+
}, props), children);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { Sampler, useSurfaceSampler };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
|
|
5
|
+
function createScreenQuadGeometry() {
|
|
6
|
+
const geometry = new THREE.BufferGeometry();
|
|
7
|
+
const vertices = new Float32Array([-1, -1, 3, -1, -1, 3]);
|
|
8
|
+
geometry.setAttribute('position', new THREE.BufferAttribute(vertices, 2));
|
|
9
|
+
return geometry;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const ScreenQuad = /*#__PURE__*/React.forwardRef(function ScreenQuad({
|
|
13
|
+
children,
|
|
14
|
+
...restProps
|
|
15
|
+
}, ref) {
|
|
16
|
+
const geometry = React.useMemo(createScreenQuadGeometry, []);
|
|
17
|
+
return /*#__PURE__*/React.createElement("mesh", _extends({
|
|
18
|
+
ref: ref,
|
|
19
|
+
geometry: geometry,
|
|
20
|
+
frustumCulled: false
|
|
21
|
+
}, restProps), children);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export { ScreenQuad };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import mergeRefs from 'react-merge-refs';
|
|
4
|
+
import { useFrame } from '@react-three/fiber';
|
|
5
|
+
|
|
6
|
+
const ScreenSpace = /*#__PURE__*/React.forwardRef(({
|
|
7
|
+
children,
|
|
8
|
+
depth = -1,
|
|
9
|
+
...rest
|
|
10
|
+
}, ref) => {
|
|
11
|
+
const localRef = React.useRef(null);
|
|
12
|
+
useFrame(({
|
|
13
|
+
camera
|
|
14
|
+
}) => {
|
|
15
|
+
localRef.current.quaternion.copy(camera.quaternion);
|
|
16
|
+
localRef.current.position.copy(camera.position);
|
|
17
|
+
});
|
|
18
|
+
return /*#__PURE__*/React.createElement("group", _extends({
|
|
19
|
+
ref: mergeRefs([ref, localRef])
|
|
20
|
+
}, rest), /*#__PURE__*/React.createElement("group", {
|
|
21
|
+
"position-z": -depth
|
|
22
|
+
}, children));
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export { ScreenSpace };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import mergeRefs from 'react-merge-refs';
|
|
5
|
+
import { extend, useFrame } from '@react-three/fiber';
|
|
6
|
+
import { Line2, LineMaterial, LineSegmentsGeometry } from 'three-stdlib';
|
|
7
|
+
|
|
8
|
+
const context = /*#__PURE__*/React.createContext(null);
|
|
9
|
+
const Segments = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
|
|
10
|
+
React.useMemo(() => extend({
|
|
11
|
+
SegmentObject
|
|
12
|
+
}), []);
|
|
13
|
+
const {
|
|
14
|
+
limit = 1000,
|
|
15
|
+
lineWidth = 1.0,
|
|
16
|
+
children,
|
|
17
|
+
...rest
|
|
18
|
+
} = props;
|
|
19
|
+
const [segments, setSegments] = React.useState([]);
|
|
20
|
+
const [line] = React.useState(() => new Line2());
|
|
21
|
+
const [material] = React.useState(() => new LineMaterial());
|
|
22
|
+
const [geometry] = React.useState(() => new LineSegmentsGeometry());
|
|
23
|
+
const [resolution] = React.useState(() => new THREE.Vector2(512, 512));
|
|
24
|
+
const [positions] = React.useState(() => Array(limit * 6).fill(0));
|
|
25
|
+
const [colors] = React.useState(() => Array(limit * 6).fill(0));
|
|
26
|
+
const api = React.useMemo(() => ({
|
|
27
|
+
subscribe: ref => {
|
|
28
|
+
setSegments(segments => [...segments, ref]);
|
|
29
|
+
return () => setSegments(segments => segments.filter(item => item.current !== ref.current));
|
|
30
|
+
}
|
|
31
|
+
}), []);
|
|
32
|
+
useFrame(() => {
|
|
33
|
+
for (let i = 0; i < limit; i++) {
|
|
34
|
+
var _segments$i;
|
|
35
|
+
|
|
36
|
+
const segment = (_segments$i = segments[i]) == null ? void 0 : _segments$i.current;
|
|
37
|
+
|
|
38
|
+
if (segment) {
|
|
39
|
+
positions[i * 6 + 0] = segment.start.x;
|
|
40
|
+
positions[i * 6 + 1] = segment.start.y;
|
|
41
|
+
positions[i * 6 + 2] = segment.start.z;
|
|
42
|
+
positions[i * 6 + 3] = segment.end.x;
|
|
43
|
+
positions[i * 6 + 4] = segment.end.y;
|
|
44
|
+
positions[i * 6 + 5] = segment.end.z;
|
|
45
|
+
colors[i * 6 + 0] = segment.color.r;
|
|
46
|
+
colors[i * 6 + 1] = segment.color.g;
|
|
47
|
+
colors[i * 6 + 2] = segment.color.b;
|
|
48
|
+
colors[i * 6 + 3] = segment.color.r;
|
|
49
|
+
colors[i * 6 + 4] = segment.color.g;
|
|
50
|
+
colors[i * 6 + 5] = segment.color.b;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
geometry.setColors(colors);
|
|
55
|
+
geometry.setPositions(positions);
|
|
56
|
+
line.computeLineDistances();
|
|
57
|
+
});
|
|
58
|
+
return /*#__PURE__*/React.createElement("primitive", {
|
|
59
|
+
object: line,
|
|
60
|
+
ref: forwardedRef
|
|
61
|
+
}, /*#__PURE__*/React.createElement("primitive", {
|
|
62
|
+
object: geometry,
|
|
63
|
+
attach: "geometry"
|
|
64
|
+
}), /*#__PURE__*/React.createElement("primitive", _extends({
|
|
65
|
+
object: material,
|
|
66
|
+
attach: "material",
|
|
67
|
+
vertexColors: true,
|
|
68
|
+
resolution: resolution,
|
|
69
|
+
linewidth: lineWidth
|
|
70
|
+
}, rest)), /*#__PURE__*/React.createElement(context.Provider, {
|
|
71
|
+
value: api
|
|
72
|
+
}, children));
|
|
73
|
+
});
|
|
74
|
+
class SegmentObject {
|
|
75
|
+
constructor() {
|
|
76
|
+
this.color = new THREE.Color('white');
|
|
77
|
+
this.start = new THREE.Vector3(0, 0, 0);
|
|
78
|
+
this.end = new THREE.Vector3(0, 0, 0);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const normPos = pos => pos instanceof THREE.Vector3 ? pos : new THREE.Vector3(...(typeof pos === 'number' ? [pos, pos, pos] : pos));
|
|
84
|
+
|
|
85
|
+
const Segment = /*#__PURE__*/React.forwardRef(({
|
|
86
|
+
color,
|
|
87
|
+
start,
|
|
88
|
+
end
|
|
89
|
+
}, forwardedRef) => {
|
|
90
|
+
const api = React.useContext(context);
|
|
91
|
+
if (!api) throw 'Segment must used inside Segments component.';
|
|
92
|
+
const ref = React.useRef(null);
|
|
93
|
+
React.useLayoutEffect(() => api.subscribe(ref), []);
|
|
94
|
+
return /*#__PURE__*/React.createElement("segmentObject", {
|
|
95
|
+
ref: mergeRefs([ref, forwardedRef]),
|
|
96
|
+
color: color,
|
|
97
|
+
start: normPos(start),
|
|
98
|
+
end: normPos(end)
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
export { Segment, SegmentObject, Segments };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Color, DoubleSide } from 'three';
|
|
4
|
+
|
|
5
|
+
const Shadow = /*#__PURE__*/React.forwardRef(({
|
|
6
|
+
fog = false,
|
|
7
|
+
renderOrder,
|
|
8
|
+
depthWrite = false,
|
|
9
|
+
colorStop = 0.0,
|
|
10
|
+
color = 'black',
|
|
11
|
+
opacity = 0.5,
|
|
12
|
+
...props
|
|
13
|
+
}, ref) => {
|
|
14
|
+
const canvas = React.useMemo(() => {
|
|
15
|
+
const canvas = document.createElement('canvas');
|
|
16
|
+
canvas.width = 128;
|
|
17
|
+
canvas.height = 128;
|
|
18
|
+
const context = canvas.getContext('2d');
|
|
19
|
+
const gradient = context.createRadialGradient(canvas.width / 2, canvas.height / 2, 0, canvas.width / 2, canvas.height / 2, canvas.width / 2);
|
|
20
|
+
gradient.addColorStop(colorStop, new Color(color).getStyle());
|
|
21
|
+
gradient.addColorStop(1, 'rgba(0,0,0,0)');
|
|
22
|
+
context.fillStyle = gradient;
|
|
23
|
+
context.fillRect(0, 0, canvas.width, canvas.height);
|
|
24
|
+
return canvas;
|
|
25
|
+
}, [color, colorStop]);
|
|
26
|
+
return /*#__PURE__*/React.createElement("mesh", _extends({
|
|
27
|
+
renderOrder: renderOrder,
|
|
28
|
+
ref: ref,
|
|
29
|
+
"rotation-x": -Math.PI / 2
|
|
30
|
+
}, props), /*#__PURE__*/React.createElement("planeGeometry", null), /*#__PURE__*/React.createElement("meshBasicMaterial", {
|
|
31
|
+
transparent: true,
|
|
32
|
+
opacity: opacity,
|
|
33
|
+
fog: fog,
|
|
34
|
+
depthWrite: depthWrite,
|
|
35
|
+
side: DoubleSide
|
|
36
|
+
}, /*#__PURE__*/React.createElement("canvasTexture", {
|
|
37
|
+
attach: "map",
|
|
38
|
+
args: [canvas]
|
|
39
|
+
})));
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export { Shadow };
|
package/src/core/Sky.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Sky as Sky$1 } from 'three-stdlib';
|
|
4
|
+
import { Vector3 } from 'three';
|
|
5
|
+
|
|
6
|
+
function calcPosFromAngles(inclination, azimuth, vector = new Vector3()) {
|
|
7
|
+
const theta = Math.PI * (inclination - 0.5);
|
|
8
|
+
const phi = 2 * Math.PI * (azimuth - 0.5);
|
|
9
|
+
vector.x = Math.cos(phi);
|
|
10
|
+
vector.y = Math.sin(theta);
|
|
11
|
+
vector.z = Math.sin(phi);
|
|
12
|
+
return vector;
|
|
13
|
+
}
|
|
14
|
+
const Sky = /*#__PURE__*/React.forwardRef(({
|
|
15
|
+
inclination = 0.6,
|
|
16
|
+
azimuth = 0.1,
|
|
17
|
+
distance = 1000,
|
|
18
|
+
mieCoefficient = 0.005,
|
|
19
|
+
mieDirectionalG = 0.8,
|
|
20
|
+
rayleigh = 0.5,
|
|
21
|
+
turbidity = 10,
|
|
22
|
+
sunPosition = calcPosFromAngles(inclination, azimuth),
|
|
23
|
+
...props
|
|
24
|
+
}, ref) => {
|
|
25
|
+
const scale = React.useMemo(() => new Vector3().setScalar(distance), [distance]);
|
|
26
|
+
const [sky] = React.useState(() => new Sky$1());
|
|
27
|
+
return /*#__PURE__*/React.createElement("primitive", _extends({
|
|
28
|
+
object: sky,
|
|
29
|
+
ref: ref,
|
|
30
|
+
"material-uniforms-mieCoefficient-value": mieCoefficient,
|
|
31
|
+
"material-uniforms-mieDirectionalG-value": mieDirectionalG,
|
|
32
|
+
"material-uniforms-rayleigh-value": rayleigh,
|
|
33
|
+
"material-uniforms-sunPosition-value": sunPosition,
|
|
34
|
+
"material-uniforms-turbidity-value": turbidity,
|
|
35
|
+
scale: scale
|
|
36
|
+
}, props));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export { Sky, calcPosFromAngles };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import * as THREE from 'three';
|
|
4
|
+
import { extend, useThree, useFrame } from '@react-three/fiber';
|
|
5
|
+
import { shaderMaterial } from './shaderMaterial.js';
|
|
6
|
+
|
|
7
|
+
const SparklesImplMaterial = shaderMaterial({
|
|
8
|
+
time: 0,
|
|
9
|
+
pixelRatio: 1
|
|
10
|
+
}, ` uniform float pixelRatio;
|
|
11
|
+
uniform float time;
|
|
12
|
+
attribute float size;
|
|
13
|
+
attribute float speed;
|
|
14
|
+
attribute float opacity;
|
|
15
|
+
attribute vec3 noise;
|
|
16
|
+
attribute vec3 color;
|
|
17
|
+
varying vec3 vColor;
|
|
18
|
+
varying float vOpacity;
|
|
19
|
+
void main() {
|
|
20
|
+
vec4 modelPosition = modelMatrix * vec4(position, 1.0);
|
|
21
|
+
modelPosition.y += sin(time * speed + modelPosition.x * noise.x * 100.0) * 0.2;
|
|
22
|
+
modelPosition.z += cos(time * speed + modelPosition.x * noise.y * 100.0) * 0.2;
|
|
23
|
+
modelPosition.x += cos(time * speed + modelPosition.x * noise.z * 100.0) * 0.2;
|
|
24
|
+
vec4 viewPosition = viewMatrix * modelPosition;
|
|
25
|
+
vec4 projectionPostion = projectionMatrix * viewPosition;
|
|
26
|
+
gl_Position = projectionPostion;
|
|
27
|
+
gl_PointSize = size * 25. * pixelRatio;
|
|
28
|
+
gl_PointSize *= (1.0 / - viewPosition.z);
|
|
29
|
+
vColor = color;
|
|
30
|
+
vOpacity = opacity;
|
|
31
|
+
}`, ` varying vec3 vColor;
|
|
32
|
+
varying float vOpacity;
|
|
33
|
+
void main() {
|
|
34
|
+
float distanceToCenter = distance(gl_PointCoord, vec2(0.5));
|
|
35
|
+
float strength = 0.05 / distanceToCenter - 0.1;
|
|
36
|
+
gl_FragColor = vec4(vColor, strength * vOpacity);
|
|
37
|
+
#include <tonemapping_fragment>
|
|
38
|
+
#include <encodings_fragment>
|
|
39
|
+
}`);
|
|
40
|
+
|
|
41
|
+
const isFloat32Array = def => def && def.constructor === Float32Array;
|
|
42
|
+
|
|
43
|
+
const expandColor = v => [v.r, v.g, v.b];
|
|
44
|
+
|
|
45
|
+
const isVector = v => v instanceof THREE.Vector2 || v instanceof THREE.Vector3 || v instanceof THREE.Vector4;
|
|
46
|
+
|
|
47
|
+
const normalizeVector = v => {
|
|
48
|
+
if (Array.isArray(v)) return v;else if (isVector(v)) return v.toArray();
|
|
49
|
+
return [v, v, v];
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
function usePropAsIsOrAsAttribute(count, prop, setDefault) {
|
|
53
|
+
return React.useMemo(() => {
|
|
54
|
+
if (prop !== undefined) {
|
|
55
|
+
if (isFloat32Array(prop)) {
|
|
56
|
+
return prop;
|
|
57
|
+
} else {
|
|
58
|
+
if (prop instanceof THREE.Color) {
|
|
59
|
+
const a = Array.from({
|
|
60
|
+
length: count * 3
|
|
61
|
+
}, () => expandColor(prop)).flat();
|
|
62
|
+
return Float32Array.from(a);
|
|
63
|
+
} else if (isVector(prop) || Array.isArray(prop)) {
|
|
64
|
+
const a = Array.from({
|
|
65
|
+
length: count * 3
|
|
66
|
+
}, () => normalizeVector(prop)).flat();
|
|
67
|
+
return Float32Array.from(a);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return Float32Array.from({
|
|
71
|
+
length: count
|
|
72
|
+
}, () => prop);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return Float32Array.from({
|
|
77
|
+
length: count
|
|
78
|
+
}, setDefault);
|
|
79
|
+
}, [prop]);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const Sparkles = /*#__PURE__*/React.forwardRef(({
|
|
83
|
+
noise = 1,
|
|
84
|
+
count = 100,
|
|
85
|
+
speed = 1,
|
|
86
|
+
opacity = 1,
|
|
87
|
+
scale = 1,
|
|
88
|
+
size,
|
|
89
|
+
color,
|
|
90
|
+
children,
|
|
91
|
+
...props
|
|
92
|
+
}, forwardRef) => {
|
|
93
|
+
React.useMemo(() => extend({
|
|
94
|
+
SparklesImplMaterial
|
|
95
|
+
}), []);
|
|
96
|
+
const ref = React.useRef(null);
|
|
97
|
+
const dpr = useThree(state => state.viewport.dpr);
|
|
98
|
+
const positions = React.useMemo(() => Float32Array.from(Array.from({
|
|
99
|
+
length: count
|
|
100
|
+
}, () => normalizeVector(scale).map(THREE.MathUtils.randFloatSpread)).flat()), [count, scale]);
|
|
101
|
+
const sizes = usePropAsIsOrAsAttribute(count, size, Math.random);
|
|
102
|
+
const opacities = usePropAsIsOrAsAttribute(count, opacity);
|
|
103
|
+
const speeds = usePropAsIsOrAsAttribute(count, speed);
|
|
104
|
+
const noises = usePropAsIsOrAsAttribute(count * 3, noise);
|
|
105
|
+
const colors = usePropAsIsOrAsAttribute(color === undefined ? count * 3 : count, !isFloat32Array(color) ? new THREE.Color(color) : color, () => 1);
|
|
106
|
+
useFrame(state => {
|
|
107
|
+
if (ref.current && ref.current.material) ref.current.material.time = state.clock.elapsedTime;
|
|
108
|
+
});
|
|
109
|
+
React.useImperativeHandle(forwardRef, () => ref.current, []);
|
|
110
|
+
return /*#__PURE__*/React.createElement("points", _extends({
|
|
111
|
+
key: `particle-${count}-${JSON.stringify(scale)}`
|
|
112
|
+
}, props, {
|
|
113
|
+
ref: ref
|
|
114
|
+
}), /*#__PURE__*/React.createElement("bufferGeometry", null, /*#__PURE__*/React.createElement("bufferAttribute", {
|
|
115
|
+
attach: "attributes-position",
|
|
116
|
+
args: [positions, 3]
|
|
117
|
+
}), /*#__PURE__*/React.createElement("bufferAttribute", {
|
|
118
|
+
attach: "attributes-size",
|
|
119
|
+
args: [sizes, 1]
|
|
120
|
+
}), /*#__PURE__*/React.createElement("bufferAttribute", {
|
|
121
|
+
attach: "attributes-opacity",
|
|
122
|
+
args: [opacities, 1]
|
|
123
|
+
}), /*#__PURE__*/React.createElement("bufferAttribute", {
|
|
124
|
+
attach: "attributes-speed",
|
|
125
|
+
args: [speeds, 1]
|
|
126
|
+
}), /*#__PURE__*/React.createElement("bufferAttribute", {
|
|
127
|
+
attach: "attributes-color",
|
|
128
|
+
args: [colors, 3]
|
|
129
|
+
}), /*#__PURE__*/React.createElement("bufferAttribute", {
|
|
130
|
+
attach: "attributes-noise",
|
|
131
|
+
args: [noises, 3]
|
|
132
|
+
})), children ? children : /*#__PURE__*/React.createElement("sparklesImplMaterial", {
|
|
133
|
+
transparent: true,
|
|
134
|
+
pixelRatio: dpr,
|
|
135
|
+
depthWrite: false
|
|
136
|
+
}));
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
export { Sparkles };
|