@react-three/drei 9.85.2 → 9.86.1
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 +4 -0
- package/core/Cloud.cjs.js +1 -1
- package/core/Cloud.d.ts +1 -0
- package/core/Cloud.js +5 -3
- package/index.cjs.js +1 -1
- package/package.json +1 -1
- package/react-three-drei-0.0.0-semantic-release.tgz +0 -0
package/README.md
CHANGED
|
@@ -4471,7 +4471,9 @@ attribute vec3 color;
|
|
|
4471
4471
|
[](https://drei.pmnd.rs/?path=/story/staging-cloud--cloud-st) 
|
|
4472
4472
|
|
|
4473
4473
|
<p>
|
|
4474
|
+
<a href="https://codesandbox.io/s/gwthnh"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/gwthnh/screenshot.png" alt="Demo"/></a>
|
|
4474
4475
|
<a href="https://codesandbox.io/s/mbfzf"><img width="20%" src="https://codesandbox.io/api/v1/sandboxes/mbfzf/screenshot.png" alt="Demo"/></a>
|
|
4476
|
+
|
|
4475
4477
|
</p>
|
|
4476
4478
|
|
|
4477
4479
|
Particle based cloud.
|
|
@@ -4495,6 +4497,8 @@ type CloudProps = JSX.IntrinsicElements['group'] & {
|
|
|
4495
4497
|
segments?: number
|
|
4496
4498
|
/** The box3 bounds of the cloud, default: [5, 1, 1] */
|
|
4497
4499
|
bounds?: ReactThreeFiber.Vector3
|
|
4500
|
+
/** How to arrange segments inside the bounds, default: inside (cloud are smaller are the edges) */
|
|
4501
|
+
concentrate?: 'inside' | 'outside'
|
|
4498
4502
|
/** The general scale of the segments */
|
|
4499
4503
|
scale?: ReactThreeFiber.Vector3
|
|
4500
4504
|
/** The volume/thickness of the segments, default: 6 */
|
package/core/Cloud.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("react"),r=require("three"),n=require("@react-three/fiber"),a=require("./useTexture.cjs.js"),o=require("uuid");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function c(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=u(e),s=c(t);const l=new r.Matrix4,d=new r.Vector3,f=new r.Quaternion,p=new r.Vector3,m=new r.Quaternion,g=new r.Vector3,h=s.createContext(null),y=s.forwardRef((({children:e,material:t=r.MeshLambertMaterial,texture:o="https://rawcdn.githack.com/pmndrs/drei-assets/9225a9f1fbd449d9411125c2f419b843d0308c9f/cloud.png",range:u,limit:c=200,...y},x)=>{var b,M;const v=s.useMemo((()=>class extends t{constructor(){super(),this.onBeforeCompile=e=>{e.vertexShader="attribute float opacity;\n varying float vOpacity;\n "+e.vertexShader.replace("#include <fog_vertex>","#include <fog_vertex>\n vOpacity = opacity;\n "),e.fragmentShader="varying float vOpacity;\n "+e.fragmentShader.replace("#include <opaque_fragment>","#include <opaque_fragment>\n gl_FragColor = vec4(outgoingLight, diffuseColor.a * vOpacity);\n ")}}}),[t]);n.extend({CloudMaterial:v});const w=s.useRef(null),C=s.useRef([]),E=s.useMemo((()=>new Float32Array(Array.from({length:c},(()=>1)))),[c]),A=s.useMemo((()=>new Float32Array(Array.from({length:c},(()=>[1,1,1])).flat())),[c]),O=a.useTexture(o);let j,R=0,_=0;const q=new r.Quaternion,F=new r.Vector3(0,0,1);n.useFrame(((e,t)=>{for(R=e.clock.getElapsedTime(),l.copy(w.current.matrixWorld).invert(),e.camera.matrixWorld.decompose(p,m,g),_=0;_<C.current.length;_++)j=C.current[_],j.ref.current.matrixWorld.decompose(d,f,g),d.add(j.position).applyQuaternion(f),f.copy(m).multiply(q.setFromAxisAngle(F,j.rotation+=t*j.rotationFactor)),g.addScalar(j.volume+(1+Math.sin(R*j.density*j.speed))/2*j.growth),j.matrix.compose(d,f,g).premultiply(l),j.dist=d.distanceTo(p);for(C.current.sort(((e,t)=>t.dist-e.dist)),_=0;_<C.current.length;_++)j=C.current[_],E[_]=j.opacity*(j.dist<j.fade-1?j.dist/j.fade:1),w.current.setMatrixAt(_,j.matrix),w.current.setColorAt(_,j.color);w.current.geometry.attributes.opacity.needsUpdate=!0,w.current.instanceMatrix.needsUpdate=!0,w.current.instanceColor&&(w.current.instanceColor.needsUpdate=!0)})),s.useLayoutEffect((()=>{const e=Math.min(c,void 0!==u?u:c,C.current.length);w.current.count=e,w.current.instanceMatrix.updateRange.count=16*e,w.current.instanceColor&&(w.current.instanceColor.updateRange.count=3*e),w.current.geometry.attributes.opacity.updateRange.count=e}));let P=[null!==(b=O.image.width)&&void 0!==b?b:1,null!==(M=O.image.height)&&void 0!==M?M:1],S=Math.max(P[0],P[1]);return P=[P[0]/S,P[1]/S],s.createElement("group",i.default({ref:x},y),s.createElement(h.Provider,{value:C},e,s.createElement("instancedMesh",{matrixAutoUpdate:!1,ref:w,args:[null,null,c]},s.createElement("instancedBufferAttribute",{usage:r.DynamicDrawUsage,attach:"instanceColor",args:[A,3]}),s.createElement("planeGeometry",{args:[...P]},s.createElement("instancedBufferAttribute",{usage:r.DynamicDrawUsage,attach:"attributes-opacity",args:[E,1]})),s.createElement("cloudMaterial",{key:t.name,map:O,transparent:!0,depthWrite:!1}))))})),x=s.forwardRef((({opacity:e=1,speed:t=0,bounds:a=[5,1,1],segments:u=20,color:c="#ffffff",fade:l=10,volume:d=6,growth:f=4,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("react"),r=require("three"),n=require("@react-three/fiber"),a=require("./useTexture.cjs.js"),o=require("uuid");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function c(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=u(e),s=c(t);const l=new r.Matrix4,d=new r.Vector3,f=new r.Quaternion,p=new r.Vector3,m=new r.Quaternion,g=new r.Vector3,h=s.createContext(null),y=s.forwardRef((({children:e,material:t=r.MeshLambertMaterial,texture:o="https://rawcdn.githack.com/pmndrs/drei-assets/9225a9f1fbd449d9411125c2f419b843d0308c9f/cloud.png",range:u,limit:c=200,...y},x)=>{var b,M;const v=s.useMemo((()=>class extends t{constructor(){super(),this.onBeforeCompile=e=>{e.vertexShader="attribute float opacity;\n varying float vOpacity;\n "+e.vertexShader.replace("#include <fog_vertex>","#include <fog_vertex>\n vOpacity = opacity;\n "),e.fragmentShader="varying float vOpacity;\n "+e.fragmentShader.replace("#include <opaque_fragment>","#include <opaque_fragment>\n gl_FragColor = vec4(outgoingLight, diffuseColor.a * vOpacity);\n ")}}}),[t]);n.extend({CloudMaterial:v});const w=s.useRef(null),C=s.useRef([]),E=s.useMemo((()=>new Float32Array(Array.from({length:c},(()=>1)))),[c]),A=s.useMemo((()=>new Float32Array(Array.from({length:c},(()=>[1,1,1])).flat())),[c]),O=a.useTexture(o);let j,R=0,_=0;const q=new r.Quaternion,F=new r.Vector3(0,0,1),V=new r.Vector3;n.useFrame(((e,t)=>{for(R=e.clock.getElapsedTime(),l.copy(w.current.matrixWorld).invert(),e.camera.matrixWorld.decompose(p,m,g),_=0;_<C.current.length;_++)j=C.current[_],j.ref.current.matrixWorld.decompose(d,f,g),d.add(V.copy(j.position).applyQuaternion(f)),f.copy(m).multiply(q.setFromAxisAngle(F,j.rotation+=t*j.rotationFactor)),g.addScalar(j.volume+(1+Math.sin(R*j.density*j.speed))/2*j.growth),j.matrix.compose(d,f,g).premultiply(l),j.dist=d.distanceTo(p);for(C.current.sort(((e,t)=>t.dist-e.dist)),_=0;_<C.current.length;_++)j=C.current[_],E[_]=j.opacity*(j.dist<j.fade-1?j.dist/j.fade:1),w.current.setMatrixAt(_,j.matrix),w.current.setColorAt(_,j.color);w.current.geometry.attributes.opacity.needsUpdate=!0,w.current.instanceMatrix.needsUpdate=!0,w.current.instanceColor&&(w.current.instanceColor.needsUpdate=!0)})),s.useLayoutEffect((()=>{const e=Math.min(c,void 0!==u?u:c,C.current.length);w.current.count=e,w.current.instanceMatrix.updateRange.count=16*e,w.current.instanceColor&&(w.current.instanceColor.updateRange.count=3*e),w.current.geometry.attributes.opacity.updateRange.count=e}));let P=[null!==(b=O.image.width)&&void 0!==b?b:1,null!==(M=O.image.height)&&void 0!==M?M:1],S=Math.max(P[0],P[1]);return P=[P[0]/S,P[1]/S],s.createElement("group",i.default({ref:x},y),s.createElement(h.Provider,{value:C},e,s.createElement("instancedMesh",{matrixAutoUpdate:!1,ref:w,args:[null,null,c]},s.createElement("instancedBufferAttribute",{usage:r.DynamicDrawUsage,attach:"instanceColor",args:[A,3]}),s.createElement("planeGeometry",{args:[...P]},s.createElement("instancedBufferAttribute",{usage:r.DynamicDrawUsage,attach:"attributes-opacity",args:[E,1]})),s.createElement("cloudMaterial",{key:t.name,map:O,transparent:!0,depthWrite:!1}))))})),x=s.forwardRef((({opacity:e=1,speed:t=0,bounds:a=[5,1,1],segments:u=20,color:c="#ffffff",fade:l=10,volume:d=6,growth:f=4,concentrate:p="inside",seed:m=Math.random(),...g},y)=>{function x(){const e=1e4*Math.sin(m++);return e-Math.floor(e)}const b=s.useContext(h),M=s.useRef(null),[v]=s.useState((()=>o.v4())),w=s.useMemo((()=>[...new Array(u)].map(((e,t)=>({segments:u,bounds:new r.Vector3(1,1,1),position:new r.Vector3,uuid:v,index:t,ref:M,dist:0,matrix:new r.Matrix4,color:new r.Color,rotation:t*(Math.PI/u)})))),[u,v]);return s.useLayoutEffect((()=>{w.forEach(((r,o)=>{n.applyProps(r,{color:c,speed:t,growth:f,opacity:e,fade:l,bounds:a,density:Math.max(.5,x()),rotationFactor:Math.max(.2,.5*x())*t}),u>1&&r.position.copy(r.bounds).multiply({x:2*x()-1,y:2*x()-1,z:2*x()-1});const i=Math.abs(r.position.x),s=Math.abs(r.position.y),m=Math.abs(r.position.z),g=Math.max(i,s,m);r.length="inside"===p?1:-1,i===g&&(r.length-=i/r.bounds.x),s===g&&(r.length-=s/r.bounds.y),m===g&&(r.length-=m/r.bounds.z),r.volume=Math.max(.25,r.length)*d}))}),[p,a,l,c,e,f,d,m,u,t]),s.useLayoutEffect((()=>{const e=w;return b.current=[...b.current,...e],()=>{b.current=b.current.filter((e=>e.uuid!==v))}}),[w]),s.useImperativeHandle(y,(()=>M.current),[]),s.createElement("group",i.default({ref:M},g))})),b=s.forwardRef(((e,t)=>s.useContext(h)?s.createElement(x,i.default({ref:t},e)):s.createElement(y,null,s.createElement(x,i.default({ref:t},e)))));exports.Cloud=b,exports.CloudInstance=x,exports.Clouds=y;
|
package/core/Cloud.d.ts
CHANGED
package/core/Cloud.js
CHANGED
|
@@ -75,6 +75,7 @@ const Clouds = /*@__PURE__*/React.forwardRef(({
|
|
|
75
75
|
let config;
|
|
76
76
|
const qat = new Quaternion();
|
|
77
77
|
const dir = new Vector3(0, 0, 1);
|
|
78
|
+
const pos = new Vector3();
|
|
78
79
|
useFrame((state, delta) => {
|
|
79
80
|
t = state.clock.getElapsedTime();
|
|
80
81
|
parentMatrix.copy(instance.current.matrixWorld).invert();
|
|
@@ -82,7 +83,7 @@ const Clouds = /*@__PURE__*/React.forwardRef(({
|
|
|
82
83
|
for (index = 0; index < clouds.current.length; index++) {
|
|
83
84
|
config = clouds.current[index];
|
|
84
85
|
config.ref.current.matrixWorld.decompose(translation, rotation, scale);
|
|
85
|
-
translation.add(config.position).applyQuaternion(rotation);
|
|
86
|
+
translation.add(pos.copy(config.position).applyQuaternion(rotation));
|
|
86
87
|
rotation.copy(cquat).multiply(qat.setFromAxisAngle(dir, config.rotation += delta * config.rotationFactor));
|
|
87
88
|
scale.addScalar(config.volume + (1 + Math.sin(t * config.density * config.speed)) / 2 * config.growth);
|
|
88
89
|
config.matrix.compose(translation, rotation, scale).premultiply(parentMatrix);
|
|
@@ -147,6 +148,7 @@ const CloudInstance = /*@__PURE__*/React.forwardRef(({
|
|
|
147
148
|
fade = 10,
|
|
148
149
|
volume = 6,
|
|
149
150
|
growth = 4,
|
|
151
|
+
concentrate = 'inside',
|
|
150
152
|
seed = Math.random(),
|
|
151
153
|
...props
|
|
152
154
|
}, fref) => {
|
|
@@ -193,13 +195,13 @@ const CloudInstance = /*@__PURE__*/React.forwardRef(({
|
|
|
193
195
|
const yDiff = Math.abs(cloud.position.y);
|
|
194
196
|
const zDiff = Math.abs(cloud.position.z);
|
|
195
197
|
const max = Math.max(xDiff, yDiff, zDiff);
|
|
196
|
-
cloud.length = 1;
|
|
198
|
+
cloud.length = concentrate === 'inside' ? 1 : -1;
|
|
197
199
|
if (xDiff === max) cloud.length -= xDiff / cloud.bounds.x;
|
|
198
200
|
if (yDiff === max) cloud.length -= yDiff / cloud.bounds.y;
|
|
199
201
|
if (zDiff === max) cloud.length -= zDiff / cloud.bounds.z;
|
|
200
202
|
cloud.volume = Math.max(0.25, cloud.length) * volume;
|
|
201
203
|
});
|
|
202
|
-
}, [bounds, fade, color, opacity, growth, volume, seed, segments, speed]);
|
|
204
|
+
}, [concentrate, bounds, fade, color, opacity, growth, volume, seed, segments, speed]);
|
|
203
205
|
React.useLayoutEffect(() => {
|
|
204
206
|
const temp = clouds;
|
|
205
207
|
parent.current = [...parent.current, ...temp];
|