@react-three/drei 9.19.5 → 9.20.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 +63 -13
- package/core/AccumulativeShadows.cjs.js +1 -1
- package/core/AccumulativeShadows.d.ts +6 -2
- package/core/AccumulativeShadows.js +114 -93
- package/core/Decal.cjs.js +1 -0
- package/core/Decal.d.ts +12 -0
- package/core/Decal.js +56 -0
- package/core/Reflector.d.ts +1 -1
- package/core/Sampler.cjs.js +1 -1
- package/core/Sampler.d.ts +9 -2
- package/core/Sampler.js +48 -28
- package/core/index.cjs.js +1 -1
- package/core/index.d.ts +1 -0
- package/core/index.js +2 -1
- package/index.cjs.js +1 -1
- package/index.js +2 -1
- package/native/index.cjs.js +1 -1
- package/native/index.js +2 -1
- package/package.json +1 -1
- package/web/index.cjs.js +1 -1
- package/web/index.js +2 -1
package/README.md
CHANGED
|
@@ -73,6 +73,7 @@ The `native` route of the library **does not** export `Html` or `Loader`. The de
|
|
|
73
73
|
<li><a href="#clone">Clone</a></li>
|
|
74
74
|
<li><a href="#useanimations">useAnimations</a></li>
|
|
75
75
|
<li><a href="#marchingcubes">MarchingCubes</a></li>
|
|
76
|
+
<li><a href="#decal">Decal</a></li>
|
|
76
77
|
</ul>
|
|
77
78
|
<li><a href="#shaders">Shaders</a></li>
|
|
78
79
|
<ul>
|
|
@@ -108,6 +109,7 @@ The `native` route of the library **does not** export `Html` or `Loader`. The de
|
|
|
108
109
|
<li><a href="#useintersect">useIntersect</a></li>
|
|
109
110
|
<li><a href="#useboxprojectedenv">useBoxProjectedEnv</a></li>
|
|
110
111
|
<li><a href="#useTrail">useTrail</a></li>
|
|
112
|
+
<li><a href="#useSurfaceSampler">useSurfaceSampler</a></li>
|
|
111
113
|
<li><a href="#BBAnchor">BBAnchor</a></li>
|
|
112
114
|
</ul>
|
|
113
115
|
<li><a href="#loading">Loaders</a></li>
|
|
@@ -767,6 +769,7 @@ You can either pass a Mesh and InstancedMesh as children:
|
|
|
767
769
|
<Sampler
|
|
768
770
|
weight={"normal"} // the name of the attribute to be used as sampling weight
|
|
769
771
|
transform={transformPoint} // a function that transforms each instance given a sample. See the examples for more.
|
|
772
|
+
count={16} // Number of samples
|
|
770
773
|
>
|
|
771
774
|
<mesh>
|
|
772
775
|
<sphereGeometry args={[2]} />
|
|
@@ -912,6 +915,37 @@ An abstraction for threes [MarchingCubes](https://threejs.org/examples/#webgl_ma
|
|
|
912
915
|
</MarchingCubes>
|
|
913
916
|
```
|
|
914
917
|
|
|
918
|
+
#### Decal
|
|
919
|
+
|
|
920
|
+
[](https://drei.pmnd.rs/?path=/story/misc-decal--decal-st)
|
|
921
|
+
|
|
922
|
+
Abstraction around Three's `DecalGeometry`. It will use the its parent `mesh` as the decal surface by default.
|
|
923
|
+
|
|
924
|
+
```js
|
|
925
|
+
<mesh>
|
|
926
|
+
<sphereGeometry />
|
|
927
|
+
<meshBasicMaterial />
|
|
928
|
+
|
|
929
|
+
<Decal
|
|
930
|
+
debug={undefined} // Makes "bounding box" of the decal visible
|
|
931
|
+
position={[0, 0, 0]} // Position of the decal
|
|
932
|
+
rotation={[0, 0, 0]} // Rotation of the decal
|
|
933
|
+
scale={[1, 1, 1]} // Scale of the decal
|
|
934
|
+
>
|
|
935
|
+
// Include your decal material here
|
|
936
|
+
<meshBasicMaterial alpaMap={map} />
|
|
937
|
+
</Decal>
|
|
938
|
+
</mesh>
|
|
939
|
+
```
|
|
940
|
+
|
|
941
|
+
If declarative composition is not possible, use the `mesh` prop to define the surface the decal must attach to.
|
|
942
|
+
|
|
943
|
+
```js
|
|
944
|
+
<Decal mesh={ref}>
|
|
945
|
+
<meshBasicMaterial alpaMap={map} />
|
|
946
|
+
</Decal>
|
|
947
|
+
```
|
|
948
|
+
|
|
915
949
|
# Shaders
|
|
916
950
|
|
|
917
951
|
#### MeshReflectorMaterial
|
|
@@ -1423,6 +1457,22 @@ useFrame(() => {
|
|
|
1423
1457
|
})
|
|
1424
1458
|
```
|
|
1425
1459
|
|
|
1460
|
+
#### useSurfaceSampler
|
|
1461
|
+
|
|
1462
|
+
[](https://drei.vercel.app/?path=/story/misc-decal--decal-st)
|
|
1463
|
+
|
|
1464
|
+
A hook to obtain the result of the [`<Sampler />`](#sampler) as a buffer. Useful for driving anything other than `InstancedMesh` via the Sampler.
|
|
1465
|
+
|
|
1466
|
+
```js
|
|
1467
|
+
const buffer = useSurfaceSampler(
|
|
1468
|
+
mesh, // Mesh to sample
|
|
1469
|
+
count, // [Optional] Number of samples (default: 16)
|
|
1470
|
+
transform, // [Optional] Transformation function. Same as in `<Sampler />`
|
|
1471
|
+
weight, // [Optional] Same as in `<Sampler />`
|
|
1472
|
+
instancedMesh // [Optional] Instanced mesh to scatter
|
|
1473
|
+
)
|
|
1474
|
+
```
|
|
1475
|
+
|
|
1426
1476
|
#### BBAnchor
|
|
1427
1477
|
|
|
1428
1478
|
[](https://drei.vercel.app/?path=/story/misc-bbanchor--bb-anchor-with-html)
|
|
@@ -2177,7 +2227,11 @@ type RandomizedLightProps = JSX.IntrinsicElements['group'] & {
|
|
|
2177
2227
|
}
|
|
2178
2228
|
```
|
|
2179
2229
|
|
|
2180
|
-
|
|
2230
|
+
```jsx
|
|
2231
|
+
<RandomizedLight castShadow amount={8} frames={100} position={[5, 5, -10]} />
|
|
2232
|
+
```
|
|
2233
|
+
|
|
2234
|
+
#### Refernce api
|
|
2181
2235
|
|
|
2182
2236
|
```jsx
|
|
2183
2237
|
interface AccumulativeLightContext {
|
|
@@ -2186,17 +2240,13 @@ interface AccumulativeLightContext {
|
|
|
2186
2240
|
}
|
|
2187
2241
|
```
|
|
2188
2242
|
|
|
2189
|
-
```jsx
|
|
2190
|
-
<RandomizedLight castShadow amount={8} frames={100} position={[5, 5, -10]} />
|
|
2191
|
-
```
|
|
2192
|
-
|
|
2193
2243
|
### AccumulativeShadows
|
|
2194
2244
|
|
|
2195
2245
|
<p>
|
|
2196
2246
|
<a href="https://codesandbox.io/s/hxcc1x"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/hxcc1x/screenshot.png" alt="Demo"/></a>
|
|
2197
2247
|
</p>
|
|
2198
2248
|
|
|
2199
|
-
A planar, Y-up oriented shadow-catcher that can accumulate into soft shadows and has zero performance impact after all frames have accumulated. It can be temporal, it will accumulate over time, or instantaneous, which might expensive depending on how many frames you render.
|
|
2249
|
+
A planar, Y-up oriented shadow-catcher that can accumulate into soft shadows and has zero performance impact after all frames have accumulated. It can be temporal, it will accumulate over time, or instantaneous, which might be expensive depending on how many frames you render.
|
|
2200
2250
|
|
|
2201
2251
|
You must pair it with lightsources (and scene objects!) that cast shadows, which go into the children slot. Best use it with the `RandomizedLight` component, which jiggles a set of lights around, creating realistic raycast-like shadows and ambient occlusion.
|
|
2202
2252
|
|
|
@@ -2223,7 +2273,13 @@ type AccumulativeShadowsProps = JSX.IntrinsicElements['group'] & {
|
|
|
2223
2273
|
}
|
|
2224
2274
|
```
|
|
2225
2275
|
|
|
2226
|
-
|
|
2276
|
+
```jsx
|
|
2277
|
+
<AccumulativeShadows temporal frames={100} scale={10}>
|
|
2278
|
+
<RandomizedLight amount={8} position={[5, 5, -10]} />
|
|
2279
|
+
</AccumulativeShadows>
|
|
2280
|
+
```
|
|
2281
|
+
|
|
2282
|
+
##### Reference api
|
|
2227
2283
|
|
|
2228
2284
|
```tsx
|
|
2229
2285
|
interface AccumulativeContext {
|
|
@@ -2236,12 +2292,6 @@ interface AccumulativeContext {
|
|
|
2236
2292
|
}
|
|
2237
2293
|
```
|
|
2238
2294
|
|
|
2239
|
-
```jsx
|
|
2240
|
-
<AccumulativeShadows temporal frames={100} scale={10}>
|
|
2241
|
-
<RandomizedLight castShadow amount={8} position={[5, 5, -10]} />
|
|
2242
|
-
</AccumulativeShadows>
|
|
2243
|
-
```
|
|
2244
|
-
|
|
2245
2295
|
#### SpotLight
|
|
2246
2296
|
|
|
2247
2297
|
<p>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("three"),r=require("react"),a=require("@react-three/fiber");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("three"),r=require("react"),a=require("@react-three/fiber");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var a=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,a.get?a:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var n=i(e),o=s(t),h=s(r);const l=h.createContext(null),u=h.forwardRef((({children:e,temporal:t,frames:r=40,blend:i=20,scale:s=10,opacity:n=1,alphaTest:u=.65,color:c="black",resolution:d=1024,...g},f)=>{const m=a.useThree((e=>e.gl)),v=a.useThree((e=>e.scene)),M=a.useThree((e=>e.camera)),b=h.useRef(null),w=h.useRef(null),[y]=h.useState((()=>new p(m,v,d)));h.useLayoutEffect((()=>{y.configure(b.current)}),[]);const S=h.useMemo((()=>{const e=Object.assign(new o.MeshBasicMaterial({opacity:0,transparent:!0,dithering:!0,depthWrite:!1,map:y.progressiveLightMap2.texture}),{uniforms:{ucolor:{value:new o.Color(c)},alphaTest:{value:0}}});return e.onBeforeCompile=t=>{e.uniforms=t.uniforms={...t.uniforms,...e.uniforms},t.fragmentShader=t.fragmentShader.replace("void main() {","uniform vec3 ucolor;\n uniform float alphaTest;\n void main() {"),t.fragmentShader=t.fragmentShader.replace("#include <dithering_fragment>","#include <dithering_fragment>\n gl_FragColor = vec4(ucolor * gl_FragColor.r * 2.0, max(0.0, (1.0 - gl_FragColor.r / alphaTest)) * opacity);")},e}),[c]),x=h.useMemo((()=>({lights:new Map,temporal:!!t,frames:Math.max(2,r),blend:Math.max(2,r===1/0?i:r),count:0,reset:()=>{y.clear(),S.opacity=0,S.uniforms.alphaTest.value=0,x.count=0},update:(e=1)=>{x.temporal?(S.opacity=Math.min(n,S.opacity+n/x.blend),S.uniforms.alphaTest.value=Math.min(u,S.uniforms.alphaTest.value+u/x.blend)):(S.opacity=n,S.uniforms.alphaTest.value=u),w.current.visible=!0,y.prepare();for(let t=0;t<e;t++)x.lights.forEach((e=>e.update())),y.update(M,x.blend);w.current.visible=!1,y.finish()}})),[y,S,M,v,t,r,i,n,u]);return h.useLayoutEffect((()=>{x.reset(),x.temporal||x.frames===1/0||x.update(x.blend)})),h.useImperativeHandle(f,(()=>x),[]),a.useFrame((()=>{(x.temporal||x.frames===1/0)&&x.count<x.frames&&(x.update(),x.count++)})),h.createElement("group",g,h.createElement("group",{traverse:()=>null,ref:w},h.createElement(l.Provider,{value:x},e)),h.createElement("mesh",{receiveShadow:!0,ref:b,material:S,scale:s,rotation:[-Math.PI/2,0,0]},h.createElement("planeGeometry",null)))})),c=h.forwardRef((({castShadow:e=!0,bias:t=0,mapSize:r=512,size:a=5,near:i=.5,far:s=500,frames:u=1,position:c=[0,0,0],radius:d=1,amount:p=8,intensity:g=1,ambient:f=.5,...m},v)=>{const M=h.useRef(null),b=new o.Vector3(...c).length(),w=h.useContext(l),y=h.useCallback((()=>{let e;if(M.current)for(let t=0;t<M.current.children.length;t++)if(e=M.current.children[t],Math.random()>f)e.position.set(c[0]+o.MathUtils.randFloatSpread(d),c[1]+o.MathUtils.randFloatSpread(d),c[2]+o.MathUtils.randFloatSpread(d));else{let t=Math.acos(2*Math.random()-1)-Math.PI/2,r=2*Math.PI*Math.random();e.position.set(Math.cos(t)*Math.cos(r)*b,Math.abs(Math.cos(t)*Math.sin(r)*b),Math.sin(t)*b)}}),[d,f,b,...c]),S=h.useMemo((()=>({update:y})),[y]);return h.useImperativeHandle(v,(()=>S),[S]),h.useLayoutEffect((()=>{const e=M.current;return w&&w.lights.set(e.uuid,S),()=>{w.lights.delete(e.uuid)}}),[w,S]),h.createElement("group",n.default({ref:M},m),Array.from({length:p},((n,o)=>h.createElement("directionalLight",{key:o,castShadow:e,"shadow-bias":t,"shadow-mapSize":[r,r],intensity:g/p},h.createElement("orthographicCamera",{attach:"shadow-camera",args:[-a,a,a,-a,i,s]})))))}));class d extends o.ShaderMaterial{constructor(){super({vertexShader:"void main() { gl_Position = vec4((uv - 0.5) * 2.0, 1.0, 1.0); }",fragmentShader:"void main() { discard; }"})}}class p{constructor(e,t,r=1024){this.renderer=e,this.res=r,this.scene=t,this.scene.background=null,this.buffer1Active=!1,this.lights=[],this.meshes=[],this.object=null;const a=/(Android|iPad|iPhone|iPod)/g.test(navigator.userAgent)?o.HalfFloatType:o.FloatType;this.progressiveLightMap1=new o.WebGLRenderTarget(this.res,this.res,{type:a}),this.progressiveLightMap2=new o.WebGLRenderTarget(this.res,this.res,{type:a}),this.uvMat=new d,this.targetMat=new o.MeshPhongMaterial({shininess:0}),this.previousShadowMap={value:this.progressiveLightMap1.texture},this.averagingWindow={value:100},this.targetMat.onBeforeCompile=e=>{e.vertexShader="varying vec2 vUv;\n"+e.vertexShader.slice(0,-1)+"vUv = uv; gl_Position = vec4((uv - 0.5) * 2.0, 1.0, 1.0); }";const t=e.fragmentShader.indexOf("void main() {");e.fragmentShader=e.fragmentShader.replace("#include <clipping_planes_pars_fragment>","#include <clipping_planes_pars_fragment>\n#include <shadowmask_pars_fragment>\n"),e.fragmentShader="varying vec2 vUv;\n"+e.fragmentShader.slice(0,t)+"\tuniform sampler2D previousShadowMap;\n\tuniform float averagingWindow;\n"+e.fragmentShader.slice(t-1,-1)+"\nvec3 texelOld = texture2D(previousShadowMap, vUv).rgb;\n gl_FragColor.rgb = mix(texelOld, gl_FragColor.rgb, 1.0/averagingWindow);\n }",e.uniforms.previousShadowMap=this.previousShadowMap,e.uniforms.averagingWindow=this.averagingWindow}}clear(){this.renderer.setRenderTarget(this.progressiveLightMap1),this.renderer.clear(),this.renderer.setRenderTarget(this.progressiveLightMap2),this.renderer.clear(),this.lights=[],this.meshes=[],this.scene.traverse((e=>{!function(e){return!!e.geometry}(e)?function(e){return e.isLight}(e)&&this.lights.push({object:e,intensity:e.intensity}):this.meshes.push({object:e,material:e.material})}))}prepare(){this.lights.forEach((e=>e.object.intensity=0)),this.meshes.forEach((e=>e.object.material=this.uvMat))}finish(){this.lights.forEach((e=>e.object.intensity=e.intensity)),this.meshes.forEach((e=>e.object.material=e.material))}configure(e){this.object=e}update(e,t=100){if(!this.object)return;this.averagingWindow.value=t,this.object.material=this.targetMat;const r=this.buffer1Active?this.progressiveLightMap1:this.progressiveLightMap2,a=this.buffer1Active?this.progressiveLightMap2:this.progressiveLightMap1;this.renderer.setRenderTarget(r),this.previousShadowMap.value=a.texture,this.buffer1Active=!this.buffer1Active,this.renderer.render(this.scene,e),this.renderer.setRenderTarget(null)}}exports.AccumulativeShadows=u,exports.RandomizedLight=c,exports.accumulativeContext=l;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
interface AccumulativeContext {
|
|
4
|
+
lights: Map<any, any>;
|
|
5
|
+
temporal: boolean;
|
|
6
|
+
frames: number;
|
|
7
|
+
blend: number;
|
|
8
|
+
count: number;
|
|
4
9
|
reset: () => void;
|
|
5
10
|
update: (frames?: number) => void;
|
|
6
|
-
setLights: React.Dispatch<React.SetStateAction<AccumulativeLightContext[]>>;
|
|
7
11
|
}
|
|
8
12
|
interface AccumulativeLightContext {
|
|
9
13
|
update: () => void;
|
|
@@ -36,7 +40,7 @@ export declare const AccumulativeShadows: React.ForwardRefExoticComponent<Pick<O
|
|
|
36
40
|
alphaTest?: number | undefined;
|
|
37
41
|
color?: string | undefined;
|
|
38
42
|
resolution?: number | undefined;
|
|
39
|
-
}, "visible" | "attach" | "args" | "children" | "key" | "onUpdate" | "position" | "up" | "scale" | "rotation" | "matrix" | "quaternion" | "layers" | "dispose" | "type" | "isGroup" | "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 | "opacity" | "alphaTest" | "resolution" | "frames" | "
|
|
43
|
+
}, "visible" | "attach" | "args" | "children" | "key" | "onUpdate" | "position" | "up" | "scale" | "rotation" | "matrix" | "quaternion" | "layers" | "dispose" | "type" | "isGroup" | "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 | "opacity" | "alphaTest" | "resolution" | "frames" | "temporal" | "blend"> & React.RefAttributes<AccumulativeContext>>;
|
|
40
44
|
export declare const RandomizedLight: React.ForwardRefExoticComponent<Pick<Omit<import("@react-three/fiber").ExtendedColors<import("@react-three/fiber").Overwrite<Partial<THREE.Group>, import("@react-three/fiber").NodeProps<THREE.Group, typeof THREE.Group>>>, import("@react-three/fiber").NonFunctionKeys<{
|
|
41
45
|
position?: import("@react-three/fiber").Vector3 | undefined;
|
|
42
46
|
up?: import("@react-three/fiber").Vector3 | undefined;
|
|
@@ -7,13 +7,17 @@ function isLight(object) {
|
|
|
7
7
|
return object.isLight;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
function isGeometry(object) {
|
|
11
|
+
return !!object.geometry;
|
|
12
|
+
}
|
|
13
|
+
|
|
10
14
|
const accumulativeContext = /*#__PURE__*/React.createContext(null);
|
|
11
15
|
const AccumulativeShadows = /*#__PURE__*/React.forwardRef(({
|
|
12
16
|
children,
|
|
13
|
-
|
|
17
|
+
temporal,
|
|
14
18
|
frames = 40,
|
|
19
|
+
blend = 20,
|
|
15
20
|
scale = 10,
|
|
16
|
-
temporal = false,
|
|
17
21
|
opacity = 1,
|
|
18
22
|
alphaTest = 0.65,
|
|
19
23
|
color = 'black',
|
|
@@ -22,17 +26,14 @@ const AccumulativeShadows = /*#__PURE__*/React.forwardRef(({
|
|
|
22
26
|
}, forwardRef) => {
|
|
23
27
|
const gl = useThree(state => state.gl);
|
|
24
28
|
const scene = useThree(state => state.scene);
|
|
25
|
-
const
|
|
29
|
+
const camera = useThree(state => state.camera);
|
|
26
30
|
const gPlane = React.useRef(null);
|
|
27
31
|
const gLights = React.useRef(null);
|
|
28
|
-
const count = React.useRef(0);
|
|
29
32
|
const [plm] = React.useState(() => new ProgressiveLightMap(gl, scene, resolution));
|
|
30
33
|
React.useLayoutEffect(() => {
|
|
31
|
-
plm.
|
|
32
|
-
}, []); //
|
|
34
|
+
plm.configure(gPlane.current);
|
|
35
|
+
}, []); //const [lights, setLights] = React.useState<AccumulativeLightContext[]>([])
|
|
33
36
|
|
|
34
|
-
if (frames <= 1) frames = 2;
|
|
35
|
-
let blendFrames = blend === undefined ? frames === Infinity ? 100 : frames : frames;
|
|
36
37
|
const material = React.useMemo(() => {
|
|
37
38
|
const mat = Object.assign(new THREE.MeshBasicMaterial({
|
|
38
39
|
opacity: 0,
|
|
@@ -64,73 +65,59 @@ const AccumulativeShadows = /*#__PURE__*/React.forwardRef(({
|
|
|
64
65
|
|
|
65
66
|
return mat;
|
|
66
67
|
}, [color]);
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
material.
|
|
77
|
-
|
|
68
|
+
const api = React.useMemo(() => ({
|
|
69
|
+
lights: new Map(),
|
|
70
|
+
temporal: !!temporal,
|
|
71
|
+
frames: Math.max(2, frames),
|
|
72
|
+
blend: Math.max(2, frames === Infinity ? blend : frames),
|
|
73
|
+
count: 0,
|
|
74
|
+
reset: () => {
|
|
75
|
+
// Clear buffers, reset opacities, set frame count to 0
|
|
76
|
+
plm.clear();
|
|
77
|
+
material.opacity = 0;
|
|
78
|
+
material.uniforms.alphaTest.value = 0;
|
|
79
|
+
api.count = 0;
|
|
80
|
+
},
|
|
81
|
+
update: (frames = 1) => {
|
|
82
|
+
// Adapt the opacity-blend ratio to the number of frames
|
|
83
|
+
if (!api.temporal) {
|
|
84
|
+
material.opacity = opacity;
|
|
85
|
+
material.uniforms.alphaTest.value = alphaTest;
|
|
86
|
+
} else {
|
|
87
|
+
material.opacity = Math.min(opacity, material.opacity + opacity / api.blend);
|
|
88
|
+
material.uniforms.alphaTest.value = Math.min(alphaTest, material.uniforms.alphaTest.value + alphaTest / api.blend);
|
|
89
|
+
} // Switch accumulative lights on
|
|
78
90
|
|
|
79
91
|
|
|
80
|
-
|
|
92
|
+
gLights.current.visible = true; // Collect scene lights and meshes
|
|
81
93
|
|
|
82
|
-
|
|
83
|
-
scene.traverse(object => {
|
|
84
|
-
if (isLight(object)) {
|
|
85
|
-
intensities.push({
|
|
86
|
-
object,
|
|
87
|
-
intensity: object.intensity
|
|
88
|
-
});
|
|
89
|
-
object.intensity = 0;
|
|
90
|
-
}
|
|
91
|
-
}); // Update the lightmap and the accumulative lights
|
|
94
|
+
plm.prepare(); // Update the lightmap and the accumulative lights
|
|
92
95
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
for (let i = 0; i < frames; i++) {
|
|
97
|
+
api.lights.forEach(light => light.update());
|
|
98
|
+
plm.update(camera, api.blend);
|
|
99
|
+
} // Switch lights off
|
|
97
100
|
|
|
98
101
|
|
|
99
|
-
|
|
102
|
+
gLights.current.visible = false; // Restore lights and meshes
|
|
100
103
|
|
|
101
|
-
|
|
102
|
-
object,
|
|
103
|
-
intensity
|
|
104
|
-
}) => object.intensity = intensity);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function reset() {
|
|
108
|
-
if (frames !== Infinity) {
|
|
109
|
-
plm.clear();
|
|
110
|
-
material.opacity = 0;
|
|
111
|
-
material.uniforms.alphaTest.value = 0;
|
|
112
|
-
count.current = 0;
|
|
113
|
-
update();
|
|
104
|
+
plm.finish();
|
|
114
105
|
}
|
|
115
|
-
}
|
|
106
|
+
}), [plm, material, camera, scene, temporal, frames, blend, opacity, alphaTest]);
|
|
107
|
+
React.useLayoutEffect(() => {
|
|
108
|
+
// Reset internals, buffers, ...
|
|
109
|
+
api.reset(); // Update lightmap
|
|
116
110
|
|
|
111
|
+
if (!api.temporal && api.frames !== Infinity) api.update(api.blend);
|
|
112
|
+
}); // Expose api, allow children to set itself as the main light source
|
|
117
113
|
|
|
118
|
-
|
|
119
|
-
reset,
|
|
120
|
-
update,
|
|
121
|
-
setLights
|
|
122
|
-
}), []);
|
|
123
|
-
React.useImperativeHandle(forwardRef, () => api, [api]);
|
|
114
|
+
React.useImperativeHandle(forwardRef, () => api, []);
|
|
124
115
|
useFrame(() => {
|
|
125
|
-
if (temporal && count
|
|
126
|
-
update();
|
|
127
|
-
count
|
|
116
|
+
if ((api.temporal || api.frames === Infinity) && api.count < api.frames) {
|
|
117
|
+
api.update();
|
|
118
|
+
api.count++;
|
|
128
119
|
}
|
|
129
120
|
});
|
|
130
|
-
React.useLayoutEffect(() => {
|
|
131
|
-
reset();
|
|
132
|
-
if (!temporal) update(blendFrames);
|
|
133
|
-
});
|
|
134
121
|
return /*#__PURE__*/React.createElement("group", props, /*#__PURE__*/React.createElement("group", {
|
|
135
122
|
traverse: () => null,
|
|
136
123
|
ref: gLights
|
|
@@ -184,8 +171,9 @@ const RandomizedLight = /*#__PURE__*/React.forwardRef(({
|
|
|
184
171
|
}), [update]);
|
|
185
172
|
React.useImperativeHandle(forwardRef, () => api, [api]);
|
|
186
173
|
React.useLayoutEffect(() => {
|
|
187
|
-
|
|
188
|
-
|
|
174
|
+
const group = gLights.current;
|
|
175
|
+
if (parent) parent.lights.set(group.uuid, api);
|
|
176
|
+
return () => void parent.lights.delete(group.uuid);
|
|
189
177
|
}, [parent, api]);
|
|
190
178
|
return /*#__PURE__*/React.createElement("group", _extends({
|
|
191
179
|
ref: gLights
|
|
@@ -201,7 +189,18 @@ const RandomizedLight = /*#__PURE__*/React.forwardRef(({
|
|
|
201
189
|
attach: "shadow-camera",
|
|
202
190
|
args: [-size, size, size, -size, near, far]
|
|
203
191
|
}))));
|
|
204
|
-
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
class UVMaterial extends THREE.ShaderMaterial {
|
|
195
|
+
constructor() {
|
|
196
|
+
super({
|
|
197
|
+
vertexShader: 'void main() { gl_Position = vec4((uv - 0.5) * 2.0, 1.0, 1.0); }',
|
|
198
|
+
fragmentShader: 'void main() { discard; }'
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
} // Based on "Progressive Light Map Accumulator", by [zalo](https://github.com/zalo/)
|
|
203
|
+
|
|
205
204
|
|
|
206
205
|
class ProgressiveLightMap {
|
|
207
206
|
constructor(renderer, scene, res = 1024) {
|
|
@@ -209,7 +208,10 @@ class ProgressiveLightMap {
|
|
|
209
208
|
this.res = res;
|
|
210
209
|
this.scene = scene;
|
|
211
210
|
this.scene.background = null;
|
|
212
|
-
this.buffer1Active = false;
|
|
211
|
+
this.buffer1Active = false;
|
|
212
|
+
this.lights = [];
|
|
213
|
+
this.meshes = [];
|
|
214
|
+
this.object = null; // Create the Progressive LightMap Texture
|
|
213
215
|
|
|
214
216
|
const format = /(Android|iPad|iPhone|iPod)/g.test(navigator.userAgent) ? THREE.HalfFloatType : THREE.FloatType;
|
|
215
217
|
this.progressiveLightMap1 = new THREE.WebGLRenderTarget(this.res, this.res, {
|
|
@@ -219,29 +221,29 @@ class ProgressiveLightMap {
|
|
|
219
221
|
type: format
|
|
220
222
|
}); // Inject some spicy new logic into a standard phong material
|
|
221
223
|
|
|
222
|
-
this.uvMat = new
|
|
223
|
-
|
|
224
|
-
|
|
224
|
+
this.uvMat = new UVMaterial();
|
|
225
|
+
this.targetMat = new THREE.MeshPhongMaterial({
|
|
226
|
+
shininess: 0
|
|
225
227
|
});
|
|
226
|
-
this.
|
|
228
|
+
this.previousShadowMap = {
|
|
229
|
+
value: this.progressiveLightMap1.texture
|
|
230
|
+
};
|
|
231
|
+
this.averagingWindow = {
|
|
232
|
+
value: 100
|
|
233
|
+
};
|
|
227
234
|
|
|
228
|
-
this.
|
|
235
|
+
this.targetMat.onBeforeCompile = shader => {
|
|
229
236
|
// Vertex Shader: Set Vertex Positions to the Unwrapped UV Positions
|
|
230
|
-
shader.vertexShader = '
|
|
237
|
+
shader.vertexShader = 'varying vec2 vUv;\n' + shader.vertexShader.slice(0, -1) + 'vUv = uv; gl_Position = vec4((uv - 0.5) * 2.0, 1.0, 1.0); }'; // Fragment Shader: Set Pixels to average in the Previous frame's Shadows
|
|
231
238
|
|
|
232
239
|
const bodyStart = shader.fragmentShader.indexOf('void main() {');
|
|
233
240
|
shader.fragmentShader = shader.fragmentShader.replace('#include <clipping_planes_pars_fragment>', '#include <clipping_planes_pars_fragment>\n#include <shadowmask_pars_fragment>\n');
|
|
234
|
-
shader.fragmentShader = 'varying vec2
|
|
241
|
+
shader.fragmentShader = 'varying vec2 vUv;\n' + shader.fragmentShader.slice(0, bodyStart) + ' uniform sampler2D previousShadowMap;\n uniform float averagingWindow;\n' + shader.fragmentShader.slice(bodyStart - 1, -1) + `\nvec3 texelOld = texture2D(previousShadowMap, vUv).rgb;
|
|
235
242
|
gl_FragColor.rgb = mix(texelOld, gl_FragColor.rgb, 1.0/averagingWindow);
|
|
236
243
|
}`; // Set the Previous Frame's Texture Buffer and Averaging Window
|
|
237
244
|
|
|
238
|
-
shader.uniforms.previousShadowMap =
|
|
239
|
-
|
|
240
|
-
};
|
|
241
|
-
shader.uniforms.averagingWindow = {
|
|
242
|
-
value: 100
|
|
243
|
-
};
|
|
244
|
-
this.uniforms = shader.uniforms;
|
|
245
|
+
shader.uniforms.previousShadowMap = this.previousShadowMap;
|
|
246
|
+
shader.uniforms.averagingWindow = this.averagingWindow;
|
|
245
247
|
};
|
|
246
248
|
}
|
|
247
249
|
|
|
@@ -250,31 +252,50 @@ class ProgressiveLightMap {
|
|
|
250
252
|
this.renderer.clear();
|
|
251
253
|
this.renderer.setRenderTarget(this.progressiveLightMap2);
|
|
252
254
|
this.renderer.clear();
|
|
255
|
+
this.lights = [];
|
|
256
|
+
this.meshes = [];
|
|
257
|
+
this.scene.traverse(object => {
|
|
258
|
+
if (isGeometry(object)) {
|
|
259
|
+
this.meshes.push({
|
|
260
|
+
object,
|
|
261
|
+
material: object.material
|
|
262
|
+
});
|
|
263
|
+
} else if (isLight(object)) {
|
|
264
|
+
this.lights.push({
|
|
265
|
+
object,
|
|
266
|
+
intensity: object.intensity
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
prepare() {
|
|
273
|
+
this.lights.forEach(light => light.object.intensity = 0);
|
|
274
|
+
this.meshes.forEach(mesh => mesh.object.material = this.uvMat);
|
|
253
275
|
}
|
|
254
276
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
277
|
+
finish() {
|
|
278
|
+
this.lights.forEach(light => light.object.intensity = light.intensity);
|
|
279
|
+
this.meshes.forEach(mesh => mesh.object.material = mesh.material);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
configure(object) {
|
|
283
|
+
this.object = object;
|
|
259
284
|
}
|
|
260
285
|
|
|
261
286
|
update(camera, blendWindow = 100) {
|
|
262
|
-
// Set each object's material to the UV Unwrapped Surface Mapping Version
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
this.scene.overrideMaterial = this.uvMat; // Ping-pong two surface buffers for reading/writing
|
|
287
|
+
if (!this.object) return; // Set each object's material to the UV Unwrapped Surface Mapping Version
|
|
288
|
+
|
|
289
|
+
this.averagingWindow.value = blendWindow;
|
|
290
|
+
this.object.material = this.targetMat; // Ping-pong two surface buffers for reading/writing
|
|
267
291
|
|
|
268
292
|
const activeMap = this.buffer1Active ? this.progressiveLightMap1 : this.progressiveLightMap2;
|
|
269
293
|
const inactiveMap = this.buffer1Active ? this.progressiveLightMap2 : this.progressiveLightMap1; // Render the object's surface maps
|
|
270
294
|
|
|
271
295
|
this.renderer.setRenderTarget(activeMap);
|
|
272
|
-
this.
|
|
273
|
-
value: inactiveMap.texture
|
|
274
|
-
};
|
|
296
|
+
this.previousShadowMap.value = inactiveMap.texture;
|
|
275
297
|
this.buffer1Active = !this.buffer1Active;
|
|
276
298
|
this.renderer.render(this.scene, camera);
|
|
277
|
-
this.scene.overrideMaterial = null;
|
|
278
299
|
this.renderer.setRenderTarget(null);
|
|
279
300
|
}
|
|
280
301
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("three"),t=require("three-stdlib");function n(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var a=n(e),o=n(r);function c(e,r){Array.isArray(e)?r.fromArray?r.fromArray(e):r.set(...e):r.copy(e)}exports.Decal=function({debug:e,mesh:r,children:n,position:s,rotation:l,scale:u}){const i=a.useRef(null),[[f,m,p]]=a.useState((()=>[new o.Vector3,new o.Euler,new o.Vector3(1,1,1)]));return a.useLayoutEffect((()=>{const e=(null==r?void 0:r.current)||i.current.parent;if(!(e instanceof o.Mesh))throw new Error('Decal must have a Mesh as parent or specify its "mesh" prop');e&&(c(s,f),c(l,m),c(u,p),i.current.geometry=new t.DecalGeometry(e,f,m,p))}),[r,s,u,l,f,m,p]),a.createElement("mesh",{ref:i},n||a.createElement("meshNormalMaterial",{transparent:!0,depthTest:!0,depthWrite:!1,polygonOffset:!0,polygonOffsetFactor:-4}),e&&a.createElement("mesh",{position:s,rotation:l,scale:u},a.createElement("boxGeometry",null),a.createElement("meshNormalMaterial",{wireframe:!0}),a.createElement("axesHelper",null)))};
|
package/core/Decal.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
import * as FIBER from '@react-three/fiber';
|
|
4
|
+
interface DecalProps {
|
|
5
|
+
debug: boolean;
|
|
6
|
+
mesh: React.MutableRefObject<THREE.Mesh>;
|
|
7
|
+
position: FIBER.Vector3;
|
|
8
|
+
rotation: FIBER.Euler;
|
|
9
|
+
scale: FIBER.Vector3;
|
|
10
|
+
}
|
|
11
|
+
export declare function Decal({ debug, mesh, children, position, rotation, scale, }: React.PropsWithChildren<Partial<DecalProps>>): JSX.Element;
|
|
12
|
+
export {};
|
package/core/Decal.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
import { DecalGeometry } from 'three-stdlib';
|
|
4
|
+
|
|
5
|
+
function setProp(value, targetProp) {
|
|
6
|
+
if (Array.isArray(value)) {
|
|
7
|
+
if (targetProp.fromArray) targetProp.fromArray(value);else targetProp.set(...value);
|
|
8
|
+
} else {
|
|
9
|
+
targetProp.copy(value);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function Decal({
|
|
14
|
+
debug,
|
|
15
|
+
mesh,
|
|
16
|
+
children,
|
|
17
|
+
position,
|
|
18
|
+
rotation,
|
|
19
|
+
scale
|
|
20
|
+
}) {
|
|
21
|
+
const ref = React.useRef(null);
|
|
22
|
+
const [[p, r, s]] = React.useState(() => {
|
|
23
|
+
return [new THREE.Vector3(), new THREE.Euler(), new THREE.Vector3(1, 1, 1)];
|
|
24
|
+
});
|
|
25
|
+
React.useLayoutEffect(() => {
|
|
26
|
+
const parent = (mesh == null ? void 0 : mesh.current) || ref.current.parent;
|
|
27
|
+
|
|
28
|
+
if (!(parent instanceof THREE.Mesh)) {
|
|
29
|
+
throw new Error('Decal must have a Mesh as parent or specify its "mesh" prop');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (parent) {
|
|
33
|
+
setProp(position, p);
|
|
34
|
+
setProp(rotation, r);
|
|
35
|
+
setProp(scale, s);
|
|
36
|
+
ref.current.geometry = new DecalGeometry(parent, p, r, s);
|
|
37
|
+
}
|
|
38
|
+
}, [mesh, position, scale, rotation, p, r, s]);
|
|
39
|
+
return /*#__PURE__*/React.createElement("mesh", {
|
|
40
|
+
ref: ref
|
|
41
|
+
}, children || /*#__PURE__*/React.createElement("meshNormalMaterial", {
|
|
42
|
+
transparent: true,
|
|
43
|
+
depthTest: true,
|
|
44
|
+
depthWrite: false,
|
|
45
|
+
polygonOffset: true,
|
|
46
|
+
polygonOffsetFactor: -4
|
|
47
|
+
}), debug && /*#__PURE__*/React.createElement("mesh", {
|
|
48
|
+
position: position,
|
|
49
|
+
rotation: rotation,
|
|
50
|
+
scale: scale
|
|
51
|
+
}, /*#__PURE__*/React.createElement("boxGeometry", null), /*#__PURE__*/React.createElement("meshNormalMaterial", {
|
|
52
|
+
wireframe: true
|
|
53
|
+
}), /*#__PURE__*/React.createElement("axesHelper", null)));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { Decal };
|
package/core/Reflector.d.ts
CHANGED
|
@@ -26,4 +26,4 @@ declare global {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
export declare const Reflector: React.ForwardRefExoticComponent<Pick<ReflectorProps, "visible" | "attach" | "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" | "blur" | "resolution" | "geometry" | "morphTargetInfluences" | "morphTargetDictionary" | "isMesh" | "updateMorphTargets" | "minDepthThreshold" | "maxDepthThreshold" | "depthScale" | "depthToBlurRatioBias" | "mixBlur" | "mixStrength" | "mirror" | "distortion" | "mixContrast" | "distortionMap"
|
|
29
|
+
export declare const Reflector: React.ForwardRefExoticComponent<Pick<ReflectorProps, "visible" | "attach" | "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" | "blur" | "resolution" | "geometry" | "morphTargetInfluences" | "morphTargetDictionary" | "isMesh" | "updateMorphTargets" | "debug" | "minDepthThreshold" | "maxDepthThreshold" | "depthScale" | "depthToBlurRatioBias" | "mixBlur" | "mixStrength" | "mirror" | "distortion" | "mixContrast" | "distortionMap"> & React.RefAttributes<Mesh<import("three").BufferGeometry, import("three").Material | import("three").Material[]>>>;
|
package/core/Sampler.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),r=require("react"),t=require("three-stdlib"),n=require("three");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function c(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),r=require("react"),t=require("three-stdlib"),n=require("three");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function c(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var l=u(e),o=c(r);function i(e,r=16,u,c,l){const[i,a]=o.useState((()=>{const e=Array.from({length:r},(()=>[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])).flat();return new n.InstancedBufferAttribute(Float32Array.from(e),16)}));return o.useEffect((()=>{if(void 0===e.current)return;const o=new t.MeshSurfaceSampler(e.current);c&&o.setWeightAttribute(c),o.build();const s=new n.Vector3,f=new n.Vector3,d=new n.Color,p=new n.Object3D;e.current.updateMatrixWorld(!0);for(let t=0;t<r;t++)o.sample(s,f,d),"function"==typeof u?u({dummy:p,sampledMesh:e.current,position:s,normal:f,color:d},t):p.position.copy(s),p.updateMatrix(),null!=l&&l.current&&l.current.setMatrixAt(t,p.matrix),p.matrix.toArray(i.array,16*t);null!=l&&l.current&&(l.current.instanceMatrix.needsUpdate=!0),i.needsUpdate=!0,a(i.clone())}),[e,l,c,r,u]),i}exports.Sampler=function({children:e,weight:r,transform:t,instances:n,mesh:u,count:c=16,...a}){const s=o.useRef(null),f=o.useRef(null),d=o.useRef(null);return o.useEffect((()=>{var e,r;f.current=null!==(e=null==n?void 0:n.current)&&void 0!==e?e:s.current.children.find((e=>e.hasOwnProperty("instanceMatrix"))),d.current=null!==(r=null==u?void 0:u.current)&&void 0!==r?r:s.current.children.find((e=>"Mesh"===e.type))}),[e,null==u?void 0:u.current,null==n?void 0:n.current]),i(d,c,t,r,f),o.createElement("group",l.default({ref:s},a),e)},exports.useSurfaceSampler=i;
|