@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 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://img.shields.io/badge/-storybook-%23ff69b4)](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://img.shields.io/badge/-storybook-%23ff69b4)](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://img.shields.io/badge/-storybook-%23ff69b4)](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
- It exposes its api via reference, where `update` will jiggle the lights.
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
- It exposes its api via reference. Mostly `setLights` is interesting for internal
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 n(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 s=i(e),o=n(t),u=n(r);const l=u.createContext(null),c=u.forwardRef((({children:e,blend:t,frames:r=40,scale:i=10,temporal:n=!1,opacity:s=1,alphaTest:c=.65,color:h="black",resolution:f=1024,...g},p)=>{const m=a.useThree((e=>e.gl)),v=a.useThree((e=>e.scene)),M=a.useThree((e=>e.camera)),b=u.useRef(null),y=u.useRef(null),S=u.useRef(0),[w]=u.useState((()=>new d(m,v,f)));u.useLayoutEffect((()=>{w.configureObject(b.current)}),[]),r<=1&&(r=2);let L=void 0===t&&r===1/0?100:r;const _=u.useMemo((()=>{const e=Object.assign(new o.MeshBasicMaterial({opacity:0,transparent:!0,dithering:!0,depthWrite:!1,map:w.progressiveLightMap2.texture}),{uniforms:{ucolor:{value:new o.Color(h)},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}),[h]),[T,x]=u.useState([]);function E(e=1){n?(_.opacity=Math.min(s,_.opacity+s/L),_.uniforms.alphaTest.value=Math.min(c,_.uniforms.alphaTest.value+c/L)):(_.opacity=s,_.uniforms.alphaTest.value=c),y.current.visible=!0;const t=[];v.traverse((e=>{(function(e){return e.isLight})(e)&&(t.push({object:e,intensity:e.intensity}),e.intensity=0)}));for(let t=0;t<e;t++)w.update(M,L),T&&T.forEach((e=>e.update()));y.current.visible=!1,t.forEach((({object:e,intensity:t})=>e.intensity=t))}function C(){r!==1/0&&(w.clear(),_.opacity=0,_.uniforms.alphaTest.value=0,S.current=0,E())}const A=u.useMemo((()=>({reset:C,update:E,setLights:x})),[]);return u.useImperativeHandle(p,(()=>A),[A]),a.useFrame((()=>{n&&S.current<r&&(E(),S.current++)})),u.useLayoutEffect((()=>{C(),n||E(L)})),u.createElement("group",g,u.createElement("group",{traverse:()=>null,ref:y},u.createElement(l.Provider,{value:A},e)),u.createElement("mesh",{receiveShadow:!0,ref:b,material:_,scale:i,rotation:[-Math.PI/2,0,0]},u.createElement("planeGeometry",null)))})),h=u.forwardRef((({castShadow:e=!0,bias:t=0,mapSize:r=512,size:a=5,near:i=.5,far:n=500,frames:c=1,position:h=[0,0,0],radius:d=1,amount:f=8,intensity:g=1,ambient:p=.5,...m},v)=>{const M=u.useRef(null),b=new o.Vector3(...h).length(),y=u.useContext(l),S=u.useCallback((()=>{let e;if(M.current)for(let t=0;t<M.current.children.length;t++)if(e=M.current.children[t],Math.random()>p)e.position.set(h[0]+o.MathUtils.randFloatSpread(d),h[1]+o.MathUtils.randFloatSpread(d),h[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,p,b,...h]),w=u.useMemo((()=>({update:S})),[S]);return u.useImperativeHandle(v,(()=>w),[w]),u.useLayoutEffect((()=>(y&&y.setLights((e=>[...e,w])),()=>y.setLights((e=>e.filter((e=>e!==w)))))),[y,w]),u.createElement("group",s.default({ref:M},m),Array.from({length:f},((s,o)=>u.createElement("directionalLight",{key:o,castShadow:e,"shadow-bias":t,"shadow-mapSize":[r,r],intensity:g/f},u.createElement("orthographicCamera",{attach:"shadow-camera",args:[-a,a,a,-a,i,n]})))))}));class d{constructor(e,t,r=1024){this.renderer=e,this.res=r,this.scene=t,this.scene.background=null,this.buffer1Active=!1;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 o.MeshPhongMaterial({shininess:0,specular:new o.Color("black")}),this.uniforms={},this.uvMat.onBeforeCompile=e=>{e.vertexShader="#define USE_LIGHTMAP\n"+e.vertexShader.slice(0,-1)+"\tgl_Position = vec4((uv2 - 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 vUv2;\n"+e.fragmentShader.slice(0,t)+"\tuniform sampler2D previousShadowMap;\n\tuniform float averagingWindow;\n"+e.fragmentShader.slice(t-1,-1)+"\nvec3 texelOld = texture2D(previousShadowMap, vUv2).rgb;\n gl_FragColor.rgb = mix(texelOld, gl_FragColor.rgb, 1.0/averagingWindow);\n }",e.uniforms.previousShadowMap={value:this.progressiveLightMap1.texture},e.uniforms.averagingWindow={value:100},this.uniforms=e.uniforms}}clear(){this.renderer.setRenderTarget(this.progressiveLightMap1),this.renderer.clear(),this.renderer.setRenderTarget(this.progressiveLightMap2),this.renderer.clear()}configureObject(e){const t=e.geometry.getAttribute("uv").clone();e.geometry.setAttribute("uv2",t),e.geometry.getAttribute("uv2").needsUpdate=!0}update(e,t=100){this.uniforms.averagingWindow={value:t},this.scene.overrideMaterial=this.uvMat;const r=this.buffer1Active?this.progressiveLightMap1:this.progressiveLightMap2,a=this.buffer1Active?this.progressiveLightMap2:this.progressiveLightMap1;this.renderer.setRenderTarget(r),this.uniforms.previousShadowMap={value:a.texture},this.buffer1Active=!this.buffer1Active,this.renderer.render(this.scene,e),this.scene.overrideMaterial=null,this.renderer.setRenderTarget(null)}}exports.AccumulativeShadows=c,exports.RandomizedLight=h,exports.accumulativeContext=l;
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" | "blend" | "temporal"> & React.RefAttributes<AccumulativeContext>>;
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
- blend,
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 defaultCamera = useThree(state => state.camera);
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.configureObject(gPlane.current);
32
- }, []); // Actual number of frames to render, it must be at least 2 due to the ping/ponging in the lightmap
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 [lights, setLights] = React.useState([]);
68
-
69
- function update(frames = 1) {
70
- // Adapt the opacity-blend ratio to the number of frames
71
- if (!temporal) {
72
- material.opacity = opacity;
73
- material.uniforms.alphaTest.value = alphaTest;
74
- } else {
75
- material.opacity = Math.min(opacity, material.opacity + opacity / blendFrames);
76
- material.uniforms.alphaTest.value = Math.min(alphaTest, material.uniforms.alphaTest.value + alphaTest / blendFrames);
77
- } // Switch accumulative lights on
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
- gLights.current.visible = true; // Switch off all other scene lights off, collect their intensities
92
+ gLights.current.visible = true; // Collect scene lights and meshes
81
93
 
82
- const intensities = [];
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
- for (let i = 0; i < frames; i++) {
94
- plm.update(defaultCamera, blendFrames);
95
- if (lights) lights.forEach(light => light.update());
96
- } // Switch lights off
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
- gLights.current.visible = false; // Switch scene lights on and restore their intensities
102
+ gLights.current.visible = false; // Restore lights and meshes
100
103
 
101
- intensities.forEach(({
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
- } // Expose api, allow children to set itself as the main light source
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
- const api = React.useMemo(() => ({
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.current < frames) {
126
- update();
127
- count.current++;
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
- if (parent) parent.setLights(state => [...state, api]);
188
- return () => parent.setLights(state => state.filter(a => a !== api));
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
- }); // Based on "Progressive Light Map Accumulator", by [zalo](https://github.com/zalo/)
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; // Create the Progressive LightMap Texture
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 THREE.MeshPhongMaterial({
223
- shininess: 0,
224
- specular: new THREE.Color('black')
224
+ this.uvMat = new UVMaterial();
225
+ this.targetMat = new THREE.MeshPhongMaterial({
226
+ shininess: 0
225
227
  });
226
- this.uniforms = {};
228
+ this.previousShadowMap = {
229
+ value: this.progressiveLightMap1.texture
230
+ };
231
+ this.averagingWindow = {
232
+ value: 100
233
+ };
227
234
 
228
- this.uvMat.onBeforeCompile = shader => {
235
+ this.targetMat.onBeforeCompile = shader => {
229
236
  // Vertex Shader: Set Vertex Positions to the Unwrapped UV Positions
230
- shader.vertexShader = '#define USE_LIGHTMAP\n' + shader.vertexShader.slice(0, -1) + ' gl_Position = vec4((uv2 - 0.5) * 2.0, 1.0, 1.0); }'; // Fragment Shader: Set Pixels to average in the Previous frame's Shadows
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 vUv2;\n' + shader.fragmentShader.slice(0, bodyStart) + ' uniform sampler2D previousShadowMap;\n uniform float averagingWindow;\n' + shader.fragmentShader.slice(bodyStart - 1, -1) + `\nvec3 texelOld = texture2D(previousShadowMap, vUv2).rgb;
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
- value: this.progressiveLightMap1.texture
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
- configureObject(object) {
256
- const uv2 = object.geometry.getAttribute('uv').clone();
257
- object.geometry.setAttribute('uv2', uv2);
258
- object.geometry.getAttribute('uv2').needsUpdate = true;
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
- this.uniforms.averagingWindow = {
264
- value: blendWindow
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.uniforms.previousShadowMap = {
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)))};
@@ -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 };
@@ -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" | "debug"> & React.RefAttributes<Mesh<import("three").BufferGeometry, import("three").Material | import("three").Material[]>>>;
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[]>>>;
@@ -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 i=u(e),l=c(r);exports.Sampler=({children:e,weight:r,transform:u,instances:c,mesh:o,...a})=>{const s=l.useRef(null),d=l.useRef(null),f=l.useRef(null);return l.useEffect((()=>{var e,r;d.current=null!==(e=null==c?void 0:c.current)&&void 0!==e?e:s.current.children.find((e=>e.hasOwnProperty("instanceMatrix"))),f.current=null!==(r=null==o?void 0:o.current)&&void 0!==r?r:s.current.children.find((e=>"Mesh"===e.type))}),[e,null==o?void 0:o.current,null==c?void 0:c.current]),l.useEffect((()=>{if(void 0===f.current)return;if(void 0===d.current)return;const e=new t.MeshSurfaceSampler(f.current);r&&e.setWeightAttribute(r),e.build();const c=new n.Vector3,i=new n.Vector3,l=new n.Color,o=new n.Object3D;f.current.updateMatrixWorld(!0);for(let r=0;r<d.current.count;r++)e.sample(c,i,l),"function"==typeof u?u({dummy:o,sampledMesh:f.current,position:c,normal:i,color:l},r):o.position.copy(c),o.updateMatrix(),d.current.setMatrixAt(r,o.matrix);d.current.instanceMatrix.needsUpdate=!0}),[e,null==o?void 0:o.current,null==c?void 0:c.current]),l.createElement("group",i.default({ref:s},a),e)};
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;