mirror of
https://github.com/exogen/t2-mapper.git
synced 2026-03-15 02:10:55 +00:00
89 lines
34 KiB
JavaScript
89 lines
34 KiB
JavaScript
|
|
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,51295,e=>{"use strict";var t=e.i(43476),i=e.i(932),r=e.i(71645),a=e.i(71753),o=e.i(78140),n=e.i(90072),s=e.i(85557),l=e.i(12979),c=e.i(15080),u=e.i(75567);let d=Math.PI/180,m=Math.PI/18e4;function p(e,t,i){let r=e[t];return"number"==typeof r&&Number.isFinite(r)?r:i}function f(e,t,i){let r=e[t];return"boolean"==typeof r?r:"number"==typeof r?0!==r:i}function h(e,t){let i,r=e.particles;if(Array.isArray(r)){for(let e of r)if("number"==typeof e&&(i=t(e)))break}return i?{ejectionPeriodMS:p(e,"ejectionPeriodMS",100),periodVarianceMS:p(e,"periodVarianceMS",0),ejectionVelocity:.01*p(e,"ejectionVelocity",200),velocityVariance:.01*p(e,"velocityVariance",100),ejectionOffset:.01*p(e,"ejectionOffset",0),thetaMin:p(e,"thetaMin",0),thetaMax:p(e,"thetaMax",90),phiReferenceVel:p(e,"phiReferenceVel",0),phiVariance:p(e,"phiVariance",360),overrideAdvances:f(e,"overrideAdvances",!1),orientParticles:f(e,"orientParticles",!1),orientOnVelocity:f(e,"orientOnVelocity",!0),lifetimeMS:p(e,"lifetimeMS",0)<<5,lifetimeVarianceMS:p(e,"lifetimeVarianceMS",0)<<5,particles:function(e){let t=e.keys,i=[];if(Array.isArray(t)&&t.length>0)for(let e=0;e<t.length&&e<4;e++){let r=t[e];i.push({r:r.r??1,g:r.g??1,b:r.b??1,a:r.a??1,size:(r.size??.02)*50,time:0===e?0:r.time??1})}0===i.length&&i.push({r:1,g:1,b:1,a:1,size:1,time:0}),i.length<2&&i.push({...i[0],time:1});let r="";if("string"==typeof e.textureName&&e.textureName)r=e.textureName;else{let t=e.textures;Array.isArray(t)&&t.length>0&&t[0]&&(r=t[0])}return{dragCoefficient:5*p(e,"dragCoefficient",0),windCoefficient:p(e,"windCoefficient",1),gravityCoefficient:10*p(e,"gravityCoefficient",0),inheritedVelFactor:p(e,"inheritedVelFactor",0),constantAcceleration:p(e,"constantAcceleration",0),lifetimeMS:p(e,"lifetimeMS",31)<<5,lifetimeVarianceMS:p(e,"lifetimeVarianceMS",0)<<5,spinSpeed:p(e,"spinSpeed",0),spinRandomMin:p(e,"spinRandomMin",1e3)+-1e3,spinRandomMax:p(e,"spinRandomMax",1e3)+-1e3,useInvAlpha:f(e,"useInvAlpha",!1),keys:i,textureName:r}}(i)}:null}function g(e,t){return e+(2*Math.random()-1)*t}function y(e,t,i,r,a,o,n){let s=Math.cos(n),l=Math.sin(n),c=e*r+t*a+i*o;return[e*s+(a*i-o*t)*l+r*c*(1-s),t*s+(o*e-r*i)*l+a*c*(1-s),i*s+(r*t-a*e)*l+o*c*(1-s)]}class S{data;particles=[];maxParticles;internalClock=0;nextParticleTime=0;emitterAge=0;emitterLifetime;emitterDead=!1;constructor(e,t=256,i){this.data=e,this.maxParticles=t;let r=i??e.lifetimeMS;!i&&e.lifetimeVarianceMS>0&&(r+=Math.round(g(0,e.lifetimeVarianceMS))),this.emitterLifetime=r}emitBurst(e,t,i=[0,0,1]){for(let r=0;r<t&&this.particles.length<this.maxParticles;r++)this.addParticle(e,i)}emitPeriodic(e,t,i=[0,0,1]){if(this.emitterDead)return;let r=t;for(;r>0;){if(this.nextParticleTime>0){let e=Math.min(r,this.nextParticleTime);this.nextParticleTime-=e,r-=e,this.internalClock+=e;continue}if(this.particles.length<this.maxParticles&&(this.addParticle(e,i),!this.data.overrideAdvances&&r>0)){let e=this.particles[this.particles.length-1];e.currentAge+=r,e.currentAge>=e.totalLifetime&&this.particles.pop()}let t=this.data.ejectionPeriodMS;this.data.periodVarianceMS>0&&(t+=Math.round(g(0,this.data.periodVarianceMS))),this.nextParticleTime=Math.max(1,t)}}update(e){this.emitterAge+=e,this.emitterLifetime>0&&this.emitterAge>this.emitterLifetime&&(this.emitterDead=!0);let t=e/1e3,i=this.data.particles;for(let r=this.particles.length-1;r>=0;r--){let a=this.particles[r];if(a.currentAge+=e,a.currentAge>=a.totalLifetime){this.particles[r]=this.particles[this.particles.length-1],this.particles.pop();continue}let o=i.dragCoefficient,n=i.gravityCoefficient,s=a.acc[0]-a.vel[0]*o,l=a.acc[1]-a.vel[1]*o,c=a.acc[2]-a.vel[2]*o+-9.81*n;a.vel[0]+=s*t,a.vel[1]+=l*t,a.vel[2]+=c*t,a.pos[0]+=a.vel[0]*t,a.pos[1]+=a.vel[1]*t,a.pos[2]+=a.vel[2]*t;let u=a.currentAge/a.totalLifetime,d=function(e,t){for(let i=1;i<e.length;i++)if(e[i].time>=t){let r=e[i-1],a=e[i],o=a.time-r.time,n=o>0?(t-r.time)/o:0;return{r:r.r+(a.r-r.r)*n,g:r.g+(a.g-r.g)*n,b:r.b+(a.b-r.b)*n,a:r.a+(a.a-r.a)*n,size:r.size+(
|
||
|
|
// 'position' is auto-declared by Three.js for ShaderMaterial.
|
||
|
|
attribute vec4 particleColor;
|
||
|
|
attribute float particleSize;
|
||
|
|
attribute float particleSpin;
|
||
|
|
attribute vec2 quadCorner; // (-0.5,-0.5) to (0.5,0.5)
|
||
|
|
attribute vec3 orientDir;
|
||
|
|
|
||
|
|
uniform bool uOrientParticles;
|
||
|
|
// cameraPosition is a built-in Three.js uniform.
|
||
|
|
|
||
|
|
varying vec2 vUv;
|
||
|
|
varying vec4 vColor;
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
vUv = quadCorner + 0.5; // [0,1] range
|
||
|
|
vColor = particleColor;
|
||
|
|
|
||
|
|
if (uOrientParticles) {
|
||
|
|
if (length(orientDir) < 0.0001) {
|
||
|
|
// V12: don't render oriented particles with zero velocity.
|
||
|
|
gl_Position = vec4(0.0, 0.0, 0.0, 0.0);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
// V12 oriented particle: quad aligned along direction, facing camera.
|
||
|
|
vec3 worldPos = (modelMatrix * vec4(position, 1.0)).xyz;
|
||
|
|
vec3 dir = normalize(orientDir);
|
||
|
|
vec3 dirFromCam = worldPos - cameraPosition;
|
||
|
|
vec3 crossDir = normalize(cross(dirFromCam, dir));
|
||
|
|
|
||
|
|
// V12 maps U along dir (velocity) — match by using quadCorner.x for dir.
|
||
|
|
vec3 offset = dir * quadCorner.x + crossDir * quadCorner.y;
|
||
|
|
worldPos += offset * particleSize;
|
||
|
|
|
||
|
|
gl_Position = projectionMatrix * viewMatrix * vec4(worldPos, 1.0);
|
||
|
|
} else {
|
||
|
|
// Standard camera-facing billboard.
|
||
|
|
vec3 viewPos = (modelViewMatrix * vec4(position, 1.0)).xyz;
|
||
|
|
|
||
|
|
// Apply spin rotation to quad corner.
|
||
|
|
float c = cos(particleSpin);
|
||
|
|
float s = sin(particleSpin);
|
||
|
|
vec2 rotated = vec2(
|
||
|
|
c * quadCorner.x - s * quadCorner.y,
|
||
|
|
s * quadCorner.x + c * quadCorner.y
|
||
|
|
);
|
||
|
|
|
||
|
|
// Offset in view space (camera-facing billboard).
|
||
|
|
viewPos.xy += rotated * particleSize;
|
||
|
|
|
||
|
|
gl_Position = projectionMatrix * vec4(viewPos, 1.0);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
`,b=`
|
||
|
|
uniform sampler2D particleTexture;
|
||
|
|
uniform bool hasTexture;
|
||
|
|
uniform float debugOpacity;
|
||
|
|
|
||
|
|
varying vec2 vUv;
|
||
|
|
varying vec4 vColor;
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
if (hasTexture) {
|
||
|
|
vec4 texColor = texture2D(particleTexture, vUv);
|
||
|
|
gl_FragColor = texColor * vColor;
|
||
|
|
} else {
|
||
|
|
gl_FragColor = vColor;
|
||
|
|
}
|
||
|
|
gl_FragColor.a *= debugOpacity;
|
||
|
|
}
|
||
|
|
`;var M=e.i(25645),x=e.i(79123),w=e.i(51434),T=e.i(29055),A=e.i(58647);let P=(0,M.createLogger)("ParticleEffects"),k=new Float32Array([-.5,-.5,.5,-.5,.5,.5,-.5,.5]),C=new Map,D=new Set,I=new n.DataTexture(new Uint8Array([255,255,255,255]),1,1,n.RGBAFormat,n.UnsignedByteType);function B(e){if(!e)return I;let t=C.get(e);if(t)return t;try{let t=(0,l.textureToUrl)(e),i=(0,u.loadTexture)(t,e=>{(0,s.setupEffectTexture)(e),D.add(e)});return(0,s.setupEffectTexture)(i),C.set(e,i),i}catch{return I}}I.needsUpdate=!0;let N=new n.SphereGeometry(1,6,6),E=new n.MeshBasicMaterial({color:0xff0000,wireframe:!0}),R=new n.BoxGeometry(.3,.3,.3),V=new n.MeshBasicMaterial({color:65280,wireframe:!0}),F=new n.SphereGeometry(1,12,8),_=`
|
||
|
|
attribute vec4 vertexColor;
|
||
|
|
attribute vec2 texCoord;
|
||
|
|
varying vec4 vColor;
|
||
|
|
varying vec2 vUV;
|
||
|
|
void main() {
|
||
|
|
vColor = vertexColor;
|
||
|
|
vUV = texCoord;
|
||
|
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
||
|
|
}
|
||
|
|
`,O=`
|
||
|
|
uniform sampler2D uTexture;
|
||
|
|
varying vec4 vColor;
|
||
|
|
varying vec2 vUV;
|
||
|
|
void main() {
|
||
|
|
vec4 tex = texture2D(uTexture, vUV);
|
||
|
|
gl_FragColor = vec4(vColor.rgb * tex.rgb, vColor.a * tex.a);
|
||
|
|
}
|
||
|
|
`;function z(e){let t=(e+1)*2,i=new Float32Array(3*t),r=new Float32Array(2*t),a=new Float32Array(4*t),o=new Uint16Array(6*e);for(let t=0;t<e;t++){let e=2*t,i=6*t;o[i]=e,o[i+1]=e+1,o[i+2]=e+2,o[i+3]=e+1,o[i+4]=e+3,o[i+5]=e+2}let s=new n.BufferGeometry,l=new n.BufferAttribute(i,3);l.setUsage(35048),s.setAttribute("position",l);let c=new n.BufferAttribute(r,2);c.setUsage(35048),s.setAttribute("texCoord",c);let u=new n.BufferAttribute(a,4);return u.setUsage(35048),s.setAttribute("vertexColor",u),s.setIndex(new n.BufferAttribute(o,1)),s}function U(e,t,i,r,a){let o=e.getAttribute("position").array,n=e.getAttribute("texCoord").array,s=e.getAttribute("vertexColor").array,l=Math.max(i-.5*t.width,0),c=i+.5*t.width,u=t.numSegments,d=r[0],m=r[1],p=r[2],f=r[3];for(let e=0;e<=u;e++){let i=e/u*Math.PI*2,r=Math.cos(i),h=Math.sin(i),g=2*e,y=g+1,S=3*g;o[S]=r*c,o[S+1]=a?0:t.height,o[S+2]=h*c;let v=3*y;o[v]=r*l,o[v+1]=0,o[v+2]=h*l;let b=e/u*t.texWrap,M=2*g;n[M]=b,n[M+1]=.05;let x=2*y;n[x]=b,n[x+1]=.95;let w=4*g;s[w]=d,s[w+1]=m,s[w+2]=p,s[w+3]=f;let T=4*y;s[T]=d,s[T+1]=m,s[T+2]=p,s[T+3]=f}e.getAttribute("position").needsUpdate=!0,e.getAttribute("texCoord").needsUpdate=!0,e.getAttribute("vertexColor").needsUpdate=!0,e.computeBoundingSphere()}function j(e){let t=new n.BufferGeometry,i=4*e,r=new Float32Array(2*i);for(let t=0;t<e;t++)r.set(k,8*t);let a=new Uint16Array(6*e);for(let t=0;t<e;t++){let e=4*t,i=6*t;a[i]=e,a[i+1]=e+1,a[i+2]=e+2,a[i+3]=e,a[i+4]=e+2,a[i+5]=e+3}let o=new Float32Array(3*i),s=new Float32Array(4*i),l=new Float32Array(i),c=new Float32Array(i),u=new Float32Array(3*i);return t.setIndex(new n.Uint16BufferAttribute(a,1)),t.setAttribute("quadCorner",new n.Float32BufferAttribute(r,2)),t.setAttribute("position",new n.Float32BufferAttribute(o,3)),t.setAttribute("particleColor",new n.Float32BufferAttribute(s,4)),t.setAttribute("particleSize",new n.Float32BufferAttribute(l,1)),t.setAttribute("particleSpin",new n.Float32BufferAttribute(c,1)),t.setAttribute("orientDir",new n.Float32BufferAttribute(u,3)),t.setDrawRange(0,0),t}function q(e,t,i=!1){let r=D.has(e);return new n.ShaderMaterial({vertexShader:v,fragmentShader:b,uniforms:{particleTexture:{value:r?e:I},hasTexture:{value:!0},debugOpacity:{value:1},uOrientParticles:{value:i}},transparent:!0,depthWrite:!1,depthTest:!0,side:n.DoubleSide,blending:t?n.NormalBlending:n.AdditiveBlending})}function L(e){let o,s,u,d,m,p,f,g,y,v,b,M=(0,i.c)(18),{playback:k,snapshotRef:C}=e,{debugMode:I}=(0,x.useDebug)(),{audioEnabled:L}=(0,x.useSettings)(),{audioLoader:K,audioListener:$}=(0,w.useAudio)(),Y=(0,c.useThree)(H),Q=(0,r.useRef)(null);M[0]===Symbol.for("react.memo_cache_sentinel")?(o=[],M[0]=o):o=M[0];let J=(0,r.useRef)(o);M[1]===Symbol.for("react.memo_cache_sentinel")?(s=new Set,M[1]=s):s=M[1];let X=(0,r.useRef)(s);M[2]===Symbol.for("react.memo_cache_sentinel")?(u=new Set,M[2]=u):u=M[2];let Z=(0,r.useRef)(u);M[3]===Symbol.for("react.memo_cache_sentinel")?(d=new Map,M[3]=d):d=M[3];let ee=(0,r.useRef)(d);M[4]===Symbol.for("react.memo_cache_sentinel")?(m=new Set,M[4]=m):m=M[4];let et=(0,r.useRef)(m);M[5]===Symbol.for("react.memo_cache_sentinel")?(p=[],M[5]=p):p=M[5];let ei=(0,r.useRef)(p);M[6]===Symbol.for("react.memo_cache_sentinel")?(f=[],M[6]=f):f=M[6];let er=(0,r.useRef)(f);return M[7]!==L||M[8]!==$||M[9]!==K||M[10]!==I||M[11]!==Y||M[12]!==k||M[13]!==C?(g=(e,t)=>{let i=Q.current,r=C.current;if(!i||!r)return;let a=A.engineStore.getState().playback,o="playing"===a.status,s=o?t*a.rate:0,c=1e3*s,u=k.getDataBlockData.bind(k);for(let e of r.entities){if("Explosion"!==e.type||!e.explosionDataBlockId||!e.position||X.current.has(e.id))continue;X.current.add(e.id);let t=function(e,t){let i=t(e);if(!i)return null;let r=[],a=[],o=i.particleEmitter;if("number"==typeof o){let e=t(o);if(e){let a=h(e,t);if(a){let e=i.particleDensity??10;r.push({data:a,density:e})}}}let n=i.emitters;if(Array.isArray(n))for(let e of n){if("number"!=typeof e)continue;let i=t(e);if(!i)continue;let r=h(i,t);r&&a.push(r)}return 0===r.length&&0===a.length?null:{burstEmitters:r,streamingEmitters:a,lifetimeMS:32*(i.lifetimeMS??31)}}(e.e
|