@react-three/drei 8.16.7 → 8.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -0
- package/core/Clone.cjs.js +1 -0
- package/core/Clone.d.ts +8 -0
- package/core/Clone.js +34 -0
- package/core/Points.d.ts +1 -1
- package/core/SpotLight.d.ts +1 -1
- package/core/Trail.cjs.js +1 -0
- package/core/Trail.d.ts +20 -0
- package/core/Trail.js +158 -0
- package/core/index.cjs.js +1 -1
- package/core/index.d.ts +2 -0
- package/core/index.js +4 -1
- package/index.cjs.js +1 -1
- package/index.js +2 -0
- package/native/index.cjs.js +1 -1
- package/native/index.js +4 -1
- package/package.json +2 -1
- package/web/index.cjs.js +1 -1
- package/web/index.js +4 -1
package/README.md
CHANGED
|
@@ -65,6 +65,8 @@ The `native` route of the library **does not** export `Html` or `Loader`. The de
|
|
|
65
65
|
<li><a href="#effects">Effects</a></li>
|
|
66
66
|
<li><a href="#gradienttexture">GradientTexture</a></li>
|
|
67
67
|
<li><a href="#edges">Edges</a></li>
|
|
68
|
+
<li><a href="#trail">Trail</a></li>
|
|
69
|
+
<li><a href="#clone">Clone</a></li>
|
|
68
70
|
<li><a href="#useanimations">useAnimations</a></li>
|
|
69
71
|
</ul>
|
|
70
72
|
<li><a href="#shaders">Shaders</a></li>
|
|
@@ -100,6 +102,7 @@ The `native` route of the library **does not** export `Html` or `Loader`. The de
|
|
|
100
102
|
<li><a href="#usecursor">useCursor</a></li>
|
|
101
103
|
<li><a href="#useintersect">useIntersect</a></li>
|
|
102
104
|
<li><a href="#useboxprojectedenv">useBoxProjectedEnv</a></li>
|
|
105
|
+
<li><a href="#useTrail">useTrail</a></li>
|
|
103
106
|
</ul>
|
|
104
107
|
<li><a href="#loading">Loaders</a></li>
|
|
105
108
|
<ul>
|
|
@@ -641,6 +644,62 @@ Abstracts [THREE.EdgesGeometry](https://threejs.org/docs/index.html?q=EdgesGeome
|
|
|
641
644
|
</mesh>
|
|
642
645
|
```
|
|
643
646
|
|
|
647
|
+
#### Trail
|
|
648
|
+
|
|
649
|
+
[](https://drei.vercel.app/?path=/story/misc-trail--use-trail-st)
|
|
650
|
+
|
|
651
|
+
A declarative, `three.MeshLine` based Trails implementation. You can attach it to any mesh and it will give it a beautiful trail.
|
|
652
|
+
|
|
653
|
+
Props defined bellow with their default values.
|
|
654
|
+
|
|
655
|
+
```jsx
|
|
656
|
+
<Trail
|
|
657
|
+
width={0.2} // Width of the line
|
|
658
|
+
color={'hotpink'} // Color of the line
|
|
659
|
+
length={1} // Length of the line
|
|
660
|
+
decay={1} // How fast the line fades away
|
|
661
|
+
target={undefined} // Optional target. This object will produce the trail.
|
|
662
|
+
attenuation={(width) => width} // A function to define the width in each point along it.
|
|
663
|
+
>
|
|
664
|
+
{/* If `target` is not defined, Trail will use the first `Object3D` child as the target. */}
|
|
665
|
+
<mesh>
|
|
666
|
+
<sphereGeometry />
|
|
667
|
+
<meshBasicMaterial />
|
|
668
|
+
</mesh>
|
|
669
|
+
|
|
670
|
+
{/* You can optionally define a custom meshLineMaterial to use. */}
|
|
671
|
+
{/* <meshLineMaterial color={"red"} /> */}
|
|
672
|
+
</Trail>
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
👉 Inspired by [TheSpite's Codevember 2021 #9](https://spite.github.io/codevember-2021/9/)
|
|
676
|
+
|
|
677
|
+
#### Clone
|
|
678
|
+
|
|
679
|
+
Declarative abstraction around THREE.Object3D.clone. This is useful when you want to create a shallow copy of an existing fragment (and Object3D, Groups, etc) into your scene, for instance a group from a loaded GLTF. This clone is now re-usable, but it will still refer to the original geometries and materials. You can also deeply clone, down to geometries and materials using the `deep` prop.
|
|
680
|
+
|
|
681
|
+
```jsx
|
|
682
|
+
<Clone object={nodes.table} />
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
You can dynamically insert objects, these will apply to anything that isn't a group or a plain object3d (meshes, lines, etc):
|
|
686
|
+
|
|
687
|
+
```jsx
|
|
688
|
+
const { nodes } = useGLTF(url)
|
|
689
|
+
return (
|
|
690
|
+
<Clone object={nodes.table}>
|
|
691
|
+
<meshStandardMaterial color="green" />
|
|
692
|
+
</Clone>
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
Or make inserts conditional:
|
|
696
|
+
|
|
697
|
+
```jsx
|
|
698
|
+
<Clone object={nodes.table}>
|
|
699
|
+
{(object) => (object.name === 'table' ? <meshStandardMaterial color="green" /> : null)}
|
|
700
|
+
</Clone>
|
|
701
|
+
```
|
|
702
|
+
|
|
644
703
|
#### useAnimations
|
|
645
704
|
|
|
646
705
|
[](https://drei.pmnd.rs/?path=/story/abstractions-useanimations--use-animations-st)
|
|
@@ -1137,6 +1196,27 @@ const projection = useBoxProjectedEnv(
|
|
|
1137
1196
|
</CubeCamera>
|
|
1138
1197
|
```
|
|
1139
1198
|
|
|
1199
|
+
#### useTrail
|
|
1200
|
+
|
|
1201
|
+
[](https://drei.vercel.app/?path=/story/misc-trail--use-trail-st)
|
|
1202
|
+
|
|
1203
|
+
A hook to obtain an array of points that make up a [Trail](#trail). You can use this array to drive your own `MeshLine` or make a trail out of anything you please.
|
|
1204
|
+
|
|
1205
|
+
Note: The hook returns a ref (`MutableRefObject<Vector3[]>`) this means updates to it will not trigger a re-draw, thus keeping this cheap.
|
|
1206
|
+
|
|
1207
|
+
```js
|
|
1208
|
+
const points = useTrail(
|
|
1209
|
+
target, // Required target object. This object will produce the trail.
|
|
1210
|
+
length, // Length of the line
|
|
1211
|
+
decay // How fast the line fades away
|
|
1212
|
+
)
|
|
1213
|
+
|
|
1214
|
+
// To use...
|
|
1215
|
+
useFrame(() => {
|
|
1216
|
+
meshLineRef.current.position.setPoints(points.current)
|
|
1217
|
+
})
|
|
1218
|
+
```
|
|
1219
|
+
|
|
1140
1220
|
# Loading
|
|
1141
1221
|
|
|
1142
1222
|
#### Loader
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("react"),r=require("lodash.pick");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function a(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var o=n(e),c=a(t),l=n(r);exports.Clone=function e({object:t,deep:r=!1,children:n,keys:a=["near","far","color","distance","decay","penumbra","angle","intensity","skeleton","visible","castShadow","receiveShadow","morphTargetDictionary","morphTargetInfluences","name","geometry","material","position","rotation","scale","up","userData"],...u}){const i=l.default(t,a);return c.createElement("group",u,c.createElement("group",i,null==t?void 0:t.children.map((t=>{let u=l.default(t,a);r&&(u.geometry&&(u.geometry=u.geometry.clone()),u.material&&(u.material=u.material.clone()));let i=t.type[0].toLowerCase()+t.type.slice(1);return"group"!==i&&"object3D"!==i||(i=e,u.object=t),c.createElement(i,o.default({key:t.uuid},u),"function"==typeof n?n(t):n)}))))};
|
package/core/Clone.d.ts
ADDED
package/core/Clone.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import pick from 'lodash.pick';
|
|
4
|
+
|
|
5
|
+
function Clone({
|
|
6
|
+
object,
|
|
7
|
+
deep = false,
|
|
8
|
+
children,
|
|
9
|
+
keys = ['near', 'far', 'color', 'distance', 'decay', 'penumbra', 'angle', 'intensity', 'skeleton', 'visible', 'castShadow', 'receiveShadow', 'morphTargetDictionary', 'morphTargetInfluences', 'name', 'geometry', 'material', 'position', 'rotation', 'scale', 'up', 'userData'],
|
|
10
|
+
...props
|
|
11
|
+
}) {
|
|
12
|
+
const spread = pick(object, keys);
|
|
13
|
+
return /*#__PURE__*/React.createElement("group", props, /*#__PURE__*/React.createElement("group", spread, object == null ? void 0 : object.children.map(child => {
|
|
14
|
+
let spread = pick(child, keys);
|
|
15
|
+
|
|
16
|
+
if (deep) {
|
|
17
|
+
if (spread.geometry) spread.geometry = spread.geometry.clone();
|
|
18
|
+
if (spread.material) spread.material = spread.material.clone();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let Element = child.type[0].toLowerCase() + child.type.slice(1);
|
|
22
|
+
|
|
23
|
+
if (Element === 'group' || Element === 'object3D') {
|
|
24
|
+
Element = Clone;
|
|
25
|
+
spread.object = child;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return /*#__PURE__*/React.createElement(Element, _extends({
|
|
29
|
+
key: child.uuid
|
|
30
|
+
}, spread), typeof children === 'function' ? children(child) : children);
|
|
31
|
+
})));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { Clone };
|
package/core/Points.d.ts
CHANGED
|
@@ -11,6 +11,6 @@ declare type PointsBuffersProps = JSX.IntrinsicElements['points'] & {
|
|
|
11
11
|
sizes?: Float32Array;
|
|
12
12
|
stride?: 2 | 3;
|
|
13
13
|
};
|
|
14
|
-
export declare const PointsBuffer: React.ForwardRefExoticComponent<Pick<PointsBuffersProps, "visible" | "attach" | "attachArray" | "attachObject" | "args" | "children" | "key" | "onUpdate" | "position" | "up" | "scale" | "rotation" | "matrix" | "quaternion" | "layers" | "dispose" | "type" | "id" | "uuid" | "name" | "parent" | "modelViewMatrix" | "normalMatrix" | "matrixWorld" | "matrixAutoUpdate" | "matrixWorldNeedsUpdate" | "castShadow" | "receiveShadow" | "frustumCulled" | "renderOrder" | "animations" | "userData" | "customDepthMaterial" | "customDistanceMaterial" | "isObject3D" | "onBeforeRender" | "onAfterRender" | "applyMatrix4" | "applyQuaternion" | "setRotationFromAxisAngle" | "setRotationFromEuler" | "setRotationFromMatrix" | "setRotationFromQuaternion" | "rotateOnAxis" | "rotateOnWorldAxis" | "rotateX" | "rotateY" | "rotateZ" | "translateOnAxis" | "translateX" | "translateY" | "translateZ" | "localToWorld" | "worldToLocal" | "lookAt" | "add" | "remove" | "removeFromParent" | "clear" | "getObjectById" | "getObjectByName" | "getObjectByProperty" | "getWorldPosition" | "getWorldQuaternion" | "getWorldScale" | "getWorldDirection" | "raycast" | "traverse" | "traverseVisible" | "traverseAncestors" | "updateMatrix" | "updateMatrixWorld" | "updateWorldMatrix" | "toJSON" | "clone" | "copy" | "addEventListener" | "hasEventListener" | "removeEventListener" | "dispatchEvent" | keyof import("@react-three/fiber/dist/declarations/src/core/events").EventHandlers | "material" | "geometry" | "morphTargetInfluences" | "morphTargetDictionary" | "updateMorphTargets" | "colors" | "
|
|
14
|
+
export declare const PointsBuffer: React.ForwardRefExoticComponent<Pick<PointsBuffersProps, "visible" | "attach" | "attachArray" | "attachObject" | "args" | "children" | "key" | "onUpdate" | "position" | "up" | "scale" | "rotation" | "matrix" | "quaternion" | "layers" | "dispose" | "type" | "id" | "uuid" | "name" | "parent" | "modelViewMatrix" | "normalMatrix" | "matrixWorld" | "matrixAutoUpdate" | "matrixWorldNeedsUpdate" | "castShadow" | "receiveShadow" | "frustumCulled" | "renderOrder" | "animations" | "userData" | "customDepthMaterial" | "customDistanceMaterial" | "isObject3D" | "onBeforeRender" | "onAfterRender" | "applyMatrix4" | "applyQuaternion" | "setRotationFromAxisAngle" | "setRotationFromEuler" | "setRotationFromMatrix" | "setRotationFromQuaternion" | "rotateOnAxis" | "rotateOnWorldAxis" | "rotateX" | "rotateY" | "rotateZ" | "translateOnAxis" | "translateX" | "translateY" | "translateZ" | "localToWorld" | "worldToLocal" | "lookAt" | "add" | "remove" | "removeFromParent" | "clear" | "getObjectById" | "getObjectByName" | "getObjectByProperty" | "getWorldPosition" | "getWorldQuaternion" | "getWorldScale" | "getWorldDirection" | "raycast" | "traverse" | "traverseVisible" | "traverseAncestors" | "updateMatrix" | "updateMatrixWorld" | "updateWorldMatrix" | "toJSON" | "clone" | "copy" | "addEventListener" | "hasEventListener" | "removeEventListener" | "dispatchEvent" | keyof import("@react-three/fiber/dist/declarations/src/core/events").EventHandlers | "material" | "geometry" | "morphTargetInfluences" | "morphTargetDictionary" | "updateMorphTargets" | "colors" | "stride" | "isPoints" | "positions" | "sizes"> & React.RefAttributes<THREE.Points<THREE.BufferGeometry, THREE.Material | THREE.Material[]>>>;
|
|
15
15
|
export declare const Points: React.ForwardRefExoticComponent<Pick<PointsInstancesProps | PointsBuffersProps, "visible" | "attach" | "attachArray" | "attachObject" | "args" | "children" | "key" | "onUpdate" | "position" | "up" | "scale" | "rotation" | "matrix" | "quaternion" | "layers" | "dispose" | "type" | "id" | "uuid" | "name" | "parent" | "modelViewMatrix" | "normalMatrix" | "matrixWorld" | "matrixAutoUpdate" | "matrixWorldNeedsUpdate" | "castShadow" | "receiveShadow" | "frustumCulled" | "renderOrder" | "animations" | "userData" | "customDepthMaterial" | "customDistanceMaterial" | "isObject3D" | "onBeforeRender" | "onAfterRender" | "applyMatrix4" | "applyQuaternion" | "setRotationFromAxisAngle" | "setRotationFromEuler" | "setRotationFromMatrix" | "setRotationFromQuaternion" | "rotateOnAxis" | "rotateOnWorldAxis" | "rotateX" | "rotateY" | "rotateZ" | "translateOnAxis" | "translateX" | "translateY" | "translateZ" | "localToWorld" | "worldToLocal" | "lookAt" | "add" | "remove" | "removeFromParent" | "clear" | "getObjectById" | "getObjectByName" | "getObjectByProperty" | "getWorldPosition" | "getWorldQuaternion" | "getWorldScale" | "getWorldDirection" | "raycast" | "traverse" | "traverseVisible" | "traverseAncestors" | "updateMatrix" | "updateMatrixWorld" | "updateWorldMatrix" | "toJSON" | "clone" | "copy" | "addEventListener" | "hasEventListener" | "removeEventListener" | "dispatchEvent" | "onClick" | "onContextMenu" | "onDoubleClick" | "onPointerDown" | "onPointerMove" | "onPointerUp" | "onPointerCancel" | "onPointerEnter" | "onPointerLeave" | "onPointerOver" | "onPointerOut" | "onWheel" | "onPointerMissed" | "material" | "geometry" | "morphTargetInfluences" | "morphTargetDictionary" | "updateMorphTargets" | "isPoints"> & React.RefAttributes<THREE.Points<THREE.BufferGeometry, THREE.Material | THREE.Material[]>>>;
|
|
16
16
|
export {};
|
package/core/SpotLight.d.ts
CHANGED
|
@@ -10,5 +10,5 @@ declare const SpotLight: React.ForwardRefExoticComponent<Pick<Omit<import("@reac
|
|
|
10
10
|
radiusBottom?: number | undefined;
|
|
11
11
|
opacity?: number | undefined;
|
|
12
12
|
color?: string | number | undefined;
|
|
13
|
-
}, "visible" | "attach" | "attachArray" | "attachObject" | "args" | "children" | "key" | "onUpdate" | "position" | "up" | "scale" | "rotation" | "matrix" | "quaternion" | "layers" | "dispose" | "type" | "id" | "uuid" | "name" | "parent" | "modelViewMatrix" | "normalMatrix" | "matrixWorld" | "matrixAutoUpdate" | "matrixWorldNeedsUpdate" | "castShadow" | "receiveShadow" | "frustumCulled" | "renderOrder" | "animations" | "userData" | "customDepthMaterial" | "customDistanceMaterial" | "isObject3D" | "onBeforeRender" | "onAfterRender" | "applyMatrix4" | "applyQuaternion" | "setRotationFromAxisAngle" | "setRotationFromEuler" | "setRotationFromMatrix" | "setRotationFromQuaternion" | "rotateOnAxis" | "rotateOnWorldAxis" | "rotateX" | "rotateY" | "rotateZ" | "translateOnAxis" | "translateX" | "translateY" | "translateZ" | "localToWorld" | "worldToLocal" | "lookAt" | "add" | "remove" | "removeFromParent" | "clear" | "getObjectById" | "getObjectByName" | "getObjectByProperty" | "getWorldPosition" | "getWorldQuaternion" | "getWorldScale" | "getWorldDirection" | "raycast" | "traverse" | "traverseVisible" | "traverseAncestors" | "updateMatrix" | "updateMatrixWorld" | "updateWorldMatrix" | "toJSON" | "clone" | "copy" | "addEventListener" | "hasEventListener" | "removeEventListener" | "dispatchEvent" | "color" | keyof import("@react-three/fiber/dist/declarations/src/core/events").EventHandlers | "distance" | "opacity" | "decay" | "target" | "angle" | "intensity" | "isLight" | "shadow" | "shadowCameraFov" | "shadowCameraLeft" | "shadowCameraRight" | "shadowCameraTop" | "shadowCameraBottom" | "shadowCameraNear" | "shadowCameraFar" | "shadowBias" | "shadowMapWidth" | "shadowMapHeight" | "power" | "depthBuffer" | "
|
|
13
|
+
}, "visible" | "attach" | "attachArray" | "attachObject" | "args" | "children" | "key" | "onUpdate" | "position" | "up" | "scale" | "rotation" | "matrix" | "quaternion" | "layers" | "dispose" | "type" | "id" | "uuid" | "name" | "parent" | "modelViewMatrix" | "normalMatrix" | "matrixWorld" | "matrixAutoUpdate" | "matrixWorldNeedsUpdate" | "castShadow" | "receiveShadow" | "frustumCulled" | "renderOrder" | "animations" | "userData" | "customDepthMaterial" | "customDistanceMaterial" | "isObject3D" | "onBeforeRender" | "onAfterRender" | "applyMatrix4" | "applyQuaternion" | "setRotationFromAxisAngle" | "setRotationFromEuler" | "setRotationFromMatrix" | "setRotationFromQuaternion" | "rotateOnAxis" | "rotateOnWorldAxis" | "rotateX" | "rotateY" | "rotateZ" | "translateOnAxis" | "translateX" | "translateY" | "translateZ" | "localToWorld" | "worldToLocal" | "lookAt" | "add" | "remove" | "removeFromParent" | "clear" | "getObjectById" | "getObjectByName" | "getObjectByProperty" | "getWorldPosition" | "getWorldQuaternion" | "getWorldScale" | "getWorldDirection" | "raycast" | "traverse" | "traverseVisible" | "traverseAncestors" | "updateMatrix" | "updateMatrixWorld" | "updateWorldMatrix" | "toJSON" | "clone" | "copy" | "addEventListener" | "hasEventListener" | "removeEventListener" | "dispatchEvent" | "color" | keyof import("@react-three/fiber/dist/declarations/src/core/events").EventHandlers | "distance" | "opacity" | "decay" | "target" | "angle" | "attenuation" | "penumbra" | "intensity" | "isLight" | "shadow" | "shadowCameraFov" | "shadowCameraLeft" | "shadowCameraRight" | "shadowCameraTop" | "shadowCameraBottom" | "shadowCameraNear" | "shadowCameraFar" | "shadowBias" | "shadowMapWidth" | "shadowMapHeight" | "power" | "depthBuffer" | "isSpotLight" | "anglePower" | "radiusTop" | "radiusBottom"> & React.RefAttributes<SpotLightImpl>>;
|
|
14
14
|
export { SpotLight };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@react-three/fiber"),t=require("react"),r=require("three"),n=require("meshline");function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var i=o(t);const s={width:.2,length:1,decay:1,local:!1,stride:0,interval:1},u=(e,t=1)=>(e.set(e.subarray(t)),e.fill(-1/0,-t),e);function c(t,n){const{length:o,local:c,decay:l,interval:a,stride:f}={...s,...n},d=i.useRef(),[h]=i.useState((()=>new r.Vector3));i.useLayoutEffect((()=>{t&&(d.current=Float32Array.from({length:1e3*o*3},((e,r)=>t.position.getComponent(r%3))))}),[o,t]);const p=i.useRef(new r.Vector3),y=i.useRef(0);return e.useFrame((()=>{if(t&&d.current){if(0===y.current){let e;c?e=t.position:(t.getWorldPosition(h),e=h);const r=100*l;for(let t=0;t<r;t++)e.distanceTo(p.current)<f||(u(d.current,3),d.current.set(e.toArray(),d.current.length-3));p.current.copy(e)}y.current++,y.current=y.current%a}})),d}const l=i.forwardRef(((t,o)=>{const{children:u}=t,{width:l,length:a,decay:f,local:d,stride:h,interval:p}={...s,...t},{color:y="hotpink",attenuation:g,target:m}=t,v=e.useThree((e=>e.size)),b=i.useRef(null),[w,M]=i.useState(null),j=c(w,{length:a,decay:f,local:d,stride:h,interval:p});i.useEffect((()=>{const e=(null==m?void 0:m.current)||b.current.children.find((e=>e instanceof r.Object3D));e&&M(e)}),[j,m]);const O=i.useMemo((()=>new n.MeshLine),[]),E=i.useMemo((()=>{var e;const t=new n.MeshLineMaterial({lineWidth:.1*l,color:y,sizeAttenuation:1,resolution:new r.Vector2(v.width,v.height)});let o;if(Array.isArray(u))o=u.find((e=>{const t=e;return"string"==typeof t.type&&"meshLineMaterial"===t.type}));else{const e=u;"string"==typeof e.type&&"meshLineMaterial"===e.type&&(o=e)}return"object"==typeof(null==(e=o)?void 0:e.props)&&t.setValues(o.props),t}),[l,y,v,u]);return i.useEffect((()=>{E.uniforms.resolution.value.set(v.width,v.height)}),[v]),e.useFrame((()=>{j.current&&O.setPoints(j.current,g)})),i.createElement("group",null,i.createElement("mesh",{ref:o,geometry:O,material:E}),i.createElement("group",{ref:b},u))}));exports.Trail=l,exports.useTrail=c;
|
package/core/Trail.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ColorRepresentation, Object3D } from 'three';
|
|
3
|
+
import { MeshLine } from 'meshline';
|
|
4
|
+
declare type Settings = {
|
|
5
|
+
width: number;
|
|
6
|
+
length: number;
|
|
7
|
+
decay: number;
|
|
8
|
+
local: boolean;
|
|
9
|
+
stride: number;
|
|
10
|
+
interval: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function useTrail(target: Object3D, settings: Partial<Settings>): React.MutableRefObject<Float32Array | undefined>;
|
|
13
|
+
export declare const Trail: React.ForwardRefExoticComponent<{
|
|
14
|
+
color?: ColorRepresentation | undefined;
|
|
15
|
+
attenuation?: ((width: number) => number) | undefined;
|
|
16
|
+
target?: React.MutableRefObject<Object3D<import("three").Event>> | undefined;
|
|
17
|
+
} & Partial<Settings> & {
|
|
18
|
+
children?: React.ReactNode;
|
|
19
|
+
} & React.RefAttributes<MeshLine>>;
|
|
20
|
+
export {};
|
package/core/Trail.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { useFrame, useThree } from '@react-three/fiber';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { Vector3, Object3D, Vector2 } from 'three';
|
|
4
|
+
import { MeshLine, MeshLineMaterial } from 'meshline';
|
|
5
|
+
|
|
6
|
+
const defaults = {
|
|
7
|
+
width: 0.2,
|
|
8
|
+
length: 1,
|
|
9
|
+
decay: 1,
|
|
10
|
+
local: false,
|
|
11
|
+
stride: 0,
|
|
12
|
+
interval: 1
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const shiftLeft = (collection, steps = 1) => {
|
|
16
|
+
collection.set(collection.subarray(steps));
|
|
17
|
+
collection.fill(-Infinity, -steps);
|
|
18
|
+
return collection;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function useTrail(target, settings) {
|
|
22
|
+
const {
|
|
23
|
+
length,
|
|
24
|
+
local,
|
|
25
|
+
decay,
|
|
26
|
+
interval,
|
|
27
|
+
stride
|
|
28
|
+
} = { ...defaults,
|
|
29
|
+
...settings
|
|
30
|
+
};
|
|
31
|
+
const points = React.useRef();
|
|
32
|
+
const [worldPosition] = React.useState(() => new Vector3());
|
|
33
|
+
React.useLayoutEffect(() => {
|
|
34
|
+
if (target) {
|
|
35
|
+
points.current = Float32Array.from({
|
|
36
|
+
length: length * 1000 * 3
|
|
37
|
+
}, (_, i) => target.position.getComponent(i % 3));
|
|
38
|
+
}
|
|
39
|
+
}, [length, target]);
|
|
40
|
+
const prevPosition = React.useRef(new Vector3());
|
|
41
|
+
const frameCount = React.useRef(0);
|
|
42
|
+
useFrame(() => {
|
|
43
|
+
if (!target) return;
|
|
44
|
+
if (!points.current) return;
|
|
45
|
+
|
|
46
|
+
if (frameCount.current === 0) {
|
|
47
|
+
let newPosition;
|
|
48
|
+
|
|
49
|
+
if (local) {
|
|
50
|
+
newPosition = target.position;
|
|
51
|
+
} else {
|
|
52
|
+
target.getWorldPosition(worldPosition);
|
|
53
|
+
newPosition = worldPosition;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const steps = 100 * decay;
|
|
57
|
+
|
|
58
|
+
for (let i = 0; i < steps; i++) {
|
|
59
|
+
if (newPosition.distanceTo(prevPosition.current) < stride) continue;
|
|
60
|
+
shiftLeft(points.current, 3);
|
|
61
|
+
points.current.set(newPosition.toArray(), points.current.length - 3);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
prevPosition.current.copy(newPosition);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
frameCount.current++;
|
|
68
|
+
frameCount.current = frameCount.current % interval;
|
|
69
|
+
});
|
|
70
|
+
return points;
|
|
71
|
+
}
|
|
72
|
+
const Trail = /*#__PURE__*/React.forwardRef((props, forwardRef) => {
|
|
73
|
+
const {
|
|
74
|
+
children
|
|
75
|
+
} = props;
|
|
76
|
+
const {
|
|
77
|
+
width,
|
|
78
|
+
length,
|
|
79
|
+
decay,
|
|
80
|
+
local,
|
|
81
|
+
stride,
|
|
82
|
+
interval
|
|
83
|
+
} = { ...defaults,
|
|
84
|
+
...props
|
|
85
|
+
};
|
|
86
|
+
const {
|
|
87
|
+
color = 'hotpink',
|
|
88
|
+
attenuation,
|
|
89
|
+
target
|
|
90
|
+
} = props;
|
|
91
|
+
const size = useThree(s => s.size);
|
|
92
|
+
const ref = React.useRef(null);
|
|
93
|
+
const [anchor, setAnchor] = React.useState(null);
|
|
94
|
+
const points = useTrail(anchor, {
|
|
95
|
+
length,
|
|
96
|
+
decay,
|
|
97
|
+
local,
|
|
98
|
+
stride,
|
|
99
|
+
interval
|
|
100
|
+
});
|
|
101
|
+
React.useEffect(() => {
|
|
102
|
+
const t = (target == null ? void 0 : target.current) || ref.current.children.find(o => {
|
|
103
|
+
return o instanceof Object3D;
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
if (t) {
|
|
107
|
+
setAnchor(t);
|
|
108
|
+
}
|
|
109
|
+
}, [points, target]);
|
|
110
|
+
const geo = React.useMemo(() => new MeshLine(), []);
|
|
111
|
+
const mat = React.useMemo(() => {
|
|
112
|
+
var _matOverride;
|
|
113
|
+
|
|
114
|
+
const m = new MeshLineMaterial({
|
|
115
|
+
lineWidth: 0.1 * width,
|
|
116
|
+
color: color,
|
|
117
|
+
sizeAttenuation: 1,
|
|
118
|
+
resolution: new Vector2(size.width, size.height)
|
|
119
|
+
}); // Get and apply first <meshLineMaterial /> from children
|
|
120
|
+
|
|
121
|
+
let matOverride;
|
|
122
|
+
|
|
123
|
+
if (Array.isArray(children)) {
|
|
124
|
+
matOverride = children.find(child => {
|
|
125
|
+
const c = child;
|
|
126
|
+
return typeof c.type === 'string' && c.type === 'meshLineMaterial';
|
|
127
|
+
});
|
|
128
|
+
} else {
|
|
129
|
+
const c = children;
|
|
130
|
+
|
|
131
|
+
if (typeof c.type === 'string' && c.type === 'meshLineMaterial') {
|
|
132
|
+
matOverride = c;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (typeof ((_matOverride = matOverride) == null ? void 0 : _matOverride.props) === 'object') {
|
|
137
|
+
m.setValues(matOverride.props);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return m;
|
|
141
|
+
}, [width, color, size, children]);
|
|
142
|
+
React.useEffect(() => {
|
|
143
|
+
mat.uniforms.resolution.value.set(size.width, size.height);
|
|
144
|
+
}, [size]);
|
|
145
|
+
useFrame(() => {
|
|
146
|
+
if (!points.current) return;
|
|
147
|
+
geo.setPoints(points.current, attenuation);
|
|
148
|
+
});
|
|
149
|
+
return /*#__PURE__*/React.createElement("group", null, /*#__PURE__*/React.createElement("mesh", {
|
|
150
|
+
ref: forwardRef,
|
|
151
|
+
geometry: geo,
|
|
152
|
+
material: mat
|
|
153
|
+
}), /*#__PURE__*/React.createElement("group", {
|
|
154
|
+
ref: ref
|
|
155
|
+
}, children));
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
export { Trail, useTrail };
|
package/core/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./Billboard.cjs.js"),r=require("./QuadraticBezierLine.cjs.js"),s=require("./CubicBezierLine.cjs.js"),t=require("./Line.cjs.js"),o=require("./PositionalAudio.cjs.js"),i=require("./Text.cjs.js"),u=require("./Effects.cjs.js"),a=require("./GradientTexture.cjs.js"),n=require("./Image.cjs.js"),j=require("./Edges.cjs.js"),c=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./Billboard.cjs.js"),r=require("./QuadraticBezierLine.cjs.js"),s=require("./CubicBezierLine.cjs.js"),t=require("./Line.cjs.js"),o=require("./PositionalAudio.cjs.js"),i=require("./Text.cjs.js"),u=require("./Effects.cjs.js"),a=require("./GradientTexture.cjs.js"),n=require("./Image.cjs.js"),j=require("./Edges.cjs.js"),c=require("./Trail.cjs.js"),p=require("./Clone.cjs.js"),l=require("./OrthographicCamera.cjs.js"),x=require("./PerspectiveCamera.cjs.js"),q=require("./CubeCamera.cjs.js"),d=require("./DeviceOrientationControls.cjs.js"),C=require("./FlyControls.cjs.js"),h=require("./MapControls.cjs.js"),m=require("./OrbitControls.cjs.js"),B=require("./TrackballControls.cjs.js"),P=require("./ArcballControls.cjs.js"),b=require("./TransformControls.cjs.js"),M=require("./PointerLockControls.cjs.js"),T=require("./FirstPersonControls.cjs.js"),S=require("./GizmoHelper.cjs.js"),f=require("./GizmoViewcube.cjs.js"),g=require("./GizmoViewport.cjs.js"),v=require("./useCubeTexture.cjs.js"),L=require("./useFBX.cjs.js"),E=require("./useGLTF.cjs.js"),A=require("./useProgress.cjs.js"),G=require("./useTexture.cjs.js"),k=require("./useKTX2.cjs.js"),D=require("./Stats.cjs.js"),F=require("./useDepthBuffer.cjs.js"),w=require("./useAspect.cjs.js"),z=require("./useCamera.cjs.js"),I=require("./useDetectGPU.cjs.js"),O=require("./useHelper.cjs.js"),R=require("./useBVH.cjs.js"),y=require("./useContextBridge.cjs.js"),H=require("./useAnimations.cjs.js"),V=require("./useFBO.cjs.js"),Q=require("./useIntersect.cjs.js"),X=require("./useBoxProjectedEnv.cjs.js"),K=require("./CurveModifier.cjs.js"),W=require("./MeshDistortMaterial.cjs.js"),N=require("./MeshWobbleMaterial.cjs.js"),U=require("./MeshReflectorMaterial.cjs.js"),_=require("./PointMaterial.cjs.js"),J=require("./shaderMaterial.cjs.js"),Y=require("./softShadows.cjs.js"),Z=require("./shapes.cjs.js"),$=require("./RoundedBox.cjs.js"),ee=require("./ScreenQuad.cjs.js"),re=require("./Center.cjs.js"),se=require("./Bounds.cjs.js"),te=require("./CameraShake.cjs.js"),oe=require("./Float.cjs.js"),ie=require("./Stage.cjs.js"),ue=require("./Backdrop.cjs.js"),ae=require("./Shadow.cjs.js"),ne=require("./ContactShadows.cjs.js"),je=require("./Reflector.cjs.js"),ce=require("./SpotLight.cjs.js"),pe=require("./Environment.cjs.js"),le=require("./Lightformer.cjs.js"),xe=require("./Sky.cjs.js"),qe=require("./Stars.cjs.js"),de=require("./Cloud.cjs.js"),Ce=require("./useMatcapTexture.cjs.js"),he=require("./useNormalTexture.cjs.js"),me=require("./Points.cjs.js"),Be=require("./Instances.cjs.js"),Pe=require("./Segments.cjs.js"),be=require("./Detailed.cjs.js"),Me=require("./Preload.cjs.js"),Te=require("./BakeShadows.cjs.js"),Se=require("./meshBounds.cjs.js"),fe=require("./AdaptiveDpr.cjs.js"),ge=require("./AdaptiveEvents.cjs.js");require("@babel/runtime/helpers/extends"),require("react"),require("@react-three/fiber"),require("react-merge-refs"),require("three"),require("three-stdlib"),require("troika-three-text"),require("suspend-react"),require("meshline"),require("lodash.pick"),require("lodash.omit"),require("zustand"),require("stats.js"),require("../helpers/useEffectfulState.cjs.js"),require("detect-gpu"),require("three-mesh-bvh"),require("../materials/BlurPass.cjs.js"),require("../materials/ConvolutionMaterial.cjs.js"),require("../materials/MeshReflectorMaterial.cjs.js"),require("../helpers/environment-assets.cjs.js"),require("../materials/SpotLightMaterial.cjs.js"),require("../helpers/Position.cjs.js"),require("react-composer"),exports.Billboard=e.Billboard,exports.QuadraticBezierLine=r.QuadraticBezierLine,exports.CubicBezierLine=s.CubicBezierLine,exports.Line=t.Line,exports.PositionalAudio=o.PositionalAudio,exports.Text=i.Text,exports.Effects=u.Effects,exports.isWebGL2Available=u.isWebGL2Available,exports.GradientTexture=a.GradientTexture,exports.Image=n.Image,exports.Edges=j.Edges,exports.Trail=c.Trail,exports.useTrail=c.useTrail,exports.Clone=p.Clone,exports.OrthographicCamera=l.OrthographicCamera,exports.PerspectiveCamera=x.PerspectiveCamera,exports.CubeCamera=q.CubeCamera,exports.DeviceOrientationControls=d.DeviceOrientationControls,exports.FlyControls=C.FlyControls,exports.MapControls=h.MapControls,exports.OrbitControls=m.OrbitControls,exports.TrackballControls=B.TrackballControls,exports.ArcballControls=P.ArcballControls,exports.TransformControls=b.TransformControls,exports.PointerLockControls=M.PointerLockControls,exports.FirstPersonControls=T.FirstPersonControls,exports.GizmoHelper=S.GizmoHelper,exports.useGizmoContext=S.useGizmoContext,exports.GizmoViewcube=f.GizmoViewcube,exports.GizmoViewport=g.GizmoViewport,exports.useCubeTexture=v.useCubeTexture,exports.useFBX=L.useFBX,exports.useGLTF=E.useGLTF,exports.useProgress=A.useProgress,exports.IsObject=G.IsObject,exports.useTexture=G.useTexture,exports.useKTX2=k.useKTX2,exports.Stats=D.Stats,exports.useDepthBuffer=F.useDepthBuffer,exports.useAspect=w.useAspect,exports.useCamera=z.useCamera,exports.useDetectGPU=I.useDetectGPU,exports.useHelper=O.useHelper,exports.useBVH=R.useBVH,exports.useContextBridge=y.useContextBridge,exports.useAnimations=H.useAnimations,exports.useFBO=V.useFBO,exports.useIntersect=Q.useIntersect,exports.useBoxProjectedEnv=X.useBoxProjectedEnv,exports.CurveModifier=K.CurveModifier,exports.MeshDistortMaterial=W.MeshDistortMaterial,exports.MeshWobbleMaterial=N.MeshWobbleMaterial,exports.MeshReflectorMaterial=U.MeshReflectorMaterial,exports.PointMaterial=_.PointMaterial,exports.PointMaterialImpl=_.PointMaterialImpl,exports.shaderMaterial=J.shaderMaterial,exports.softShadows=Y.softShadows,exports.Box=Z.Box,exports.Circle=Z.Circle,exports.Cone=Z.Cone,exports.Cylinder=Z.Cylinder,exports.Dodecahedron=Z.Dodecahedron,exports.Extrude=Z.Extrude,exports.Icosahedron=Z.Icosahedron,exports.Lathe=Z.Lathe,exports.Octahedron=Z.Octahedron,exports.Plane=Z.Plane,exports.Polyhedron=Z.Polyhedron,exports.Ring=Z.Ring,exports.Sphere=Z.Sphere,exports.Tetrahedron=Z.Tetrahedron,exports.Torus=Z.Torus,exports.TorusKnot=Z.TorusKnot,exports.Tube=Z.Tube,exports.RoundedBox=$.RoundedBox,exports.ScreenQuad=ee.ScreenQuad,exports.Center=re.Center,exports.Bounds=se.Bounds,exports.useBounds=se.useBounds,exports.CameraShake=te.CameraShake,exports.Float=oe.Float,exports.Stage=ie.Stage,exports.Backdrop=ue.Backdrop,exports.Shadow=ae.Shadow,exports.ContactShadows=ne.ContactShadows,exports.Reflector=je.Reflector,exports.SpotLight=ce.SpotLight,exports.Environment=pe.Environment,exports.EnvironmentCube=pe.EnvironmentCube,exports.EnvironmentMap=pe.EnvironmentMap,exports.EnvironmentPortal=pe.EnvironmentPortal,exports.Lightformer=le.Lightformer,exports.Sky=xe.Sky,exports.calcPosFromAngles=xe.calcPosFromAngles,exports.Stars=qe.Stars,exports.Cloud=de.Cloud,exports.useMatcapTexture=Ce.useMatcapTexture,exports.useNormalTexture=he.useNormalTexture,exports.Point=me.Point,exports.Points=me.Points,exports.PointsBuffer=me.PointsBuffer,exports.Instance=Be.Instance,exports.Instances=Be.Instances,exports.Merged=Be.Merged,exports.Segment=Pe.Segment,exports.Segments=Pe.Segments,exports.Detailed=be.Detailed,exports.Preload=Me.Preload,exports.BakeShadows=Te.BakeShadows,exports.meshBounds=Se.meshBounds,exports.AdaptiveDpr=fe.AdaptiveDpr,exports.AdaptiveEvents=ge.AdaptiveEvents;
|
package/core/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export * from './Effects';
|
|
|
8
8
|
export * from './GradientTexture';
|
|
9
9
|
export * from './Image';
|
|
10
10
|
export * from './Edges';
|
|
11
|
+
export * from './Trail';
|
|
12
|
+
export * from './Clone';
|
|
11
13
|
export * from './OrthographicCamera';
|
|
12
14
|
export * from './PerspectiveCamera';
|
|
13
15
|
export * from './CubeCamera';
|
package/core/index.js
CHANGED
|
@@ -8,6 +8,8 @@ export { Effects, isWebGL2Available } from './Effects.js';
|
|
|
8
8
|
export { GradientTexture } from './GradientTexture.js';
|
|
9
9
|
export { Image } from './Image.js';
|
|
10
10
|
export { Edges } from './Edges.js';
|
|
11
|
+
export { Trail, useTrail } from './Trail.js';
|
|
12
|
+
export { Clone } from './Clone.js';
|
|
11
13
|
export { OrthographicCamera } from './OrthographicCamera.js';
|
|
12
14
|
export { PerspectiveCamera } from './PerspectiveCamera.js';
|
|
13
15
|
export { CubeCamera } from './CubeCamera.js';
|
|
@@ -85,8 +87,9 @@ import 'three';
|
|
|
85
87
|
import 'three-stdlib';
|
|
86
88
|
import 'troika-three-text';
|
|
87
89
|
import 'suspend-react';
|
|
88
|
-
import '
|
|
90
|
+
import 'meshline';
|
|
89
91
|
import 'lodash.pick';
|
|
92
|
+
import 'lodash.omit';
|
|
90
93
|
import 'zustand';
|
|
91
94
|
import 'stats.js';
|
|
92
95
|
import '../helpers/useEffectfulState.js';
|