u-space 0.0.26 → 0.0.28

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.
Files changed (42) hide show
  1. package/dist/index.cjs +3 -3
  2. package/dist/index.js +411 -373
  3. package/dist/plugins/atmosphere/index.cjs +1 -1
  4. package/dist/plugins/atmosphere/index.js +3255 -129
  5. package/dist/plugins/atmosphere/threeR185Compat.d.ts +2 -0
  6. package/dist/plugins/fire/FireEffect.d.ts +90 -0
  7. package/dist/plugins/fire/index.cjs +1 -0
  8. package/dist/plugins/fire/index.d.ts +1 -0
  9. package/dist/plugins/fire/index.js +433 -0
  10. package/dist/plugins/u-manager/index.cjs +60 -60
  11. package/dist/plugins/u-manager/index.d.ts +3 -0
  12. package/dist/plugins/u-manager/index.js +10070 -9660
  13. package/dist/plugins/u-manager/instances/SemanticInstanceObject.d.ts +37 -0
  14. package/dist/plugins/u-manager/instances/SemanticModelInstancedLayer.d.ts +33 -0
  15. package/dist/plugins/u-manager/instances/index.d.ts +2 -0
  16. package/dist/plugins/u-manager/loaders/SceneInstancedLayer.d.ts +13 -0
  17. package/dist/plugins/u-manager/loaders/SceneLoader.d.ts +5 -5
  18. package/dist/plugins/u-manager/loaders/UManagerLoader.d.ts +24 -0
  19. package/dist/plugins/u-manager/semantics/SemanticLoader.d.ts +2 -2
  20. package/dist/plugins/u-manager/semantics/SemanticParser.d.ts +3 -3
  21. package/dist/plugins/u-manager/semantics/index.d.ts +1 -1
  22. package/dist/plugins/u-manager/semantics/objects/BuildingGroup.d.ts +4 -10
  23. package/dist/plugins/u-manager/semantics/objects/FacilityInstancedLayer.d.ts +5 -24
  24. package/dist/plugins/u-manager/semantics/objects/FloorMesh.d.ts +30 -15
  25. package/dist/plugins/u-manager/semantics/objects/SemanticGroup.d.ts +26 -0
  26. package/dist/plugins/u-manager/semantics/types.d.ts +1 -0
  27. package/dist/src/effects/MaterialEffects.d.ts +1 -0
  28. package/dist/src/tools/AnnotationManager.d.ts +4 -1
  29. package/dist/src/viewers/RenderPipeline.d.ts +6 -5
  30. package/docs/api-effects.md +3 -0
  31. package/docs/api-interactions.md +1 -0
  32. package/docs/api-managers.md +1 -1
  33. package/docs/api-plugin-fire.md +174 -0
  34. package/docs/api-plugin-u-manager.md +249 -57
  35. package/docs/api-tools.md +1 -1
  36. package/docs/changelog.md +41 -8
  37. package/docs/examples-guide.md +39 -13
  38. package/docs/getting-started.md +1 -1
  39. package/docs/index.md +1 -0
  40. package/docs/mcp.md +34 -1
  41. package/package.json +4 -4
  42. package/dist/plugins/u-manager/semantics/objects/SemanticSceneGroup.d.ts +0 -31
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare function threeR185Compat(): Plugin;
@@ -0,0 +1,90 @@
1
+ import { BoxGeometry, Mesh, Object3D, PointLight, SpotLight, Vector3, VolumeNodeMaterial, type BufferGeometry, type ColorRepresentation, type Node } from 'three/webgpu';
2
+ import type { Viewer } from 'u-space';
3
+ export interface FireEffectGridSize {
4
+ x: number;
5
+ y: number;
6
+ z: number;
7
+ }
8
+ export interface FireEffectOptions {
9
+ /** Bottom-center of the official volume box in world units. */
10
+ position?: Vector3;
11
+ /** Official volume world size. Default: (12, 12, 24). */
12
+ size?: Vector3;
13
+ /** Official simulation grid. Default: 100 x 100 x 200. */
14
+ gridSize?: Partial<FireEffectGridSize>;
15
+ /** Layer used by the isolated volumetric pass. Default: 10. */
16
+ volumeLayer?: number;
17
+ /** Geometry sampled by the official emitter pass. Defaults to TeapotGeometry(0.8, 28). */
18
+ emitterGeometry?: BufferGeometry | null;
19
+ /** Object whose matrix drives the official emitter. Defaults to an internal Object3D at position. */
20
+ emitter?: Object3D | null;
21
+ /** Official wind interaction radius. Default: 1. */
22
+ emitterRadius?: number;
23
+ simulate?: boolean;
24
+ simSpeed?: number;
25
+ /** Jacobi projection iterations. Rounded up to a positive even number. Default: 2. */
26
+ pressureIterations?: number;
27
+ raymarchSteps?: number;
28
+ renderResolution?: number;
29
+ denoise?: boolean;
30
+ denoiseStrength?: number;
31
+ bloom?: boolean;
32
+ bloomStrength?: number;
33
+ bloomRadius?: number;
34
+ bloomThreshold?: number;
35
+ smokeLifespan?: number;
36
+ /** Smoke scattering visibility multiplier. Default: 1, matching the official example. */
37
+ smokeIntensity?: number;
38
+ /** Smoke scattering tint. Default: white, matching the official example. */
39
+ smokeColor?: ColorRepresentation;
40
+ fireLifespan?: number;
41
+ turbulence?: number;
42
+ turbulenceDecay?: number;
43
+ turbulenceFrequency?: number;
44
+ buoyancy?: number;
45
+ velocityDamping?: number;
46
+ emitDensity?: number;
47
+ emitTemperature?: number;
48
+ motionBoost?: number;
49
+ windStrength?: number;
50
+ fireIntensity?: number;
51
+ glowSpread?: number;
52
+ fireHue?: number;
53
+ saturation?: number;
54
+ fireStartColor?: ColorRepresentation;
55
+ fireMidColor?: ColorRepresentation;
56
+ fireEndColor?: ColorRepresentation;
57
+ phaseAsymmetry?: number;
58
+ powderStrength?: number;
59
+ multiScattering?: number;
60
+ shadowAbsorption?: number;
61
+ shadowAmbient?: number;
62
+ keyLight?: boolean;
63
+ pointLight?: boolean;
64
+ pointLightIntensity?: number;
65
+ pointLightDistance?: number;
66
+ }
67
+ interface VolumeFireMaterial extends VolumeNodeMaterial {
68
+ scatteringEmissiveNode?: (params: {
69
+ positionRay: Node<'vec3'>;
70
+ }) => Node | null;
71
+ }
72
+ declare class FireEffect {
73
+ #private;
74
+ viewer: Viewer;
75
+ mesh: Mesh<BoxGeometry, VolumeFireMaterial> | null;
76
+ shadowMesh: Mesh<BoxGeometry, VolumeNodeMaterial> | null;
77
+ keyLight: SpotLight | null;
78
+ pointLight: PointLight | null;
79
+ constructor(viewer: Viewer, options?: FireEffectOptions);
80
+ get enabled(): boolean;
81
+ get emitter(): Object3D<import("three").Object3DEventMap>;
82
+ enable(options?: FireEffectOptions): this;
83
+ update(options?: FireEffectOptions): this;
84
+ setPosition(position: Vector3): this;
85
+ setEmitter(emitter: Object3D | null, geometry?: BufferGeometry<import("three").NormalBufferAttributes, import("three").BufferGeometryEventMap> | null): this;
86
+ reset(): this;
87
+ disable(): this;
88
+ dispose(): this;
89
+ }
90
+ export { FireEffect };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("three/webgpu"),t=require("three/tsl"),st=require("three/addons/tsl/display/BloomNode.js"),it=require("three/addons/tsl/display/GaussianBlurNode.js"),ot=require("three/addons/math/ImprovedNoise.js"),nt=require("three/addons/geometries/TeapotGeometry.js"),B=require("three/addons/tsl/math/curlNoise.js"),rt={x:100,y:100,z:200},$=new i.Vector3(12,12,24),ht=new i.Vector3;function at(c){const s=Math.max(2,Math.floor(Number.isFinite(c)?c:2));return s%2===0?s:s+1}function Q(c={},s){const e=s??{position:ht.clone(),size:$.clone(),gridSize:{...rt},volumeLayer:10,emitterGeometry:null,emitter:null,emitterRadius:1,simulate:!0,simSpeed:1.2,pressureIterations:2,raymarchSteps:16,renderResolution:.5,denoise:!0,denoiseStrength:.5,bloom:!0,bloomStrength:.1,bloomRadius:1,bloomThreshold:.5,smokeLifespan:3.5,smokeIntensity:1,smokeColor:16777215,fireLifespan:1.3,turbulence:3.2,turbulenceDecay:.1,turbulenceFrequency:10,buoyancy:3,velocityDamping:.25,emitDensity:7,emitTemperature:5.5,motionBoost:.25,windStrength:6.5,fireIntensity:40,glowSpread:5,fireHue:0,saturation:1.1,fireStartColor:16770700,fireMidColor:16741125,fireEndColor:16711680,phaseAsymmetry:0,powderStrength:.59,multiScattering:1,shadowAbsorption:2,shadowAmbient:.5,keyLight:!0,pointLight:!0,pointLightIntensity:1,pointLightDistance:40};return{...e,...c,position:c.position?.clone()??e.position.clone(),size:c.size?.clone()??e.size.clone(),gridSize:{x:Math.max(2,Math.floor(c.gridSize?.x??e.gridSize.x)),y:Math.max(2,Math.floor(c.gridSize?.y??e.gridSize.y)),z:Math.max(2,Math.floor(c.gridSize?.z??e.gridSize.z))},volumeLayer:Math.max(0,Math.min(31,Math.floor(c.volumeLayer??e.volumeLayer))),emitter:c.emitter===void 0?e.emitter:c.emitter,emitterGeometry:c.emitterGeometry===void 0?e.emitterGeometry:c.emitterGeometry,emitterRadius:Math.max(.01,c.emitterRadius??e.emitterRadius),pressureIterations:at(c.pressureIterations??e.pressureIterations),raymarchSteps:Math.max(4,Math.floor(c.raymarchSteps??e.raymarchSteps)),renderResolution:Math.min(1,Math.max(.1,c.renderResolution??e.renderResolution)),smokeIntensity:Math.max(0,c.smokeIntensity??e.smokeIntensity)}}function I(c,s){const e=new i.Storage3DTexture(s.x,s.y,s.z);return e.name=c,e.format=i.RGBAFormat,e.type=i.HalfFloatType,e.minFilter=i.LinearFilter,e.magFilter=i.LinearFilter,e.wrapS=i.ClampToEdgeWrapping,e.wrapT=i.ClampToEdgeWrapping,e.wrapR=i.ClampToEdgeWrapping,e}function G(c,s,e){return t.textureStore(c,s,e).toWriteOnly()}class lt{viewer;mesh=null;shadowMesh=null;keyLight=null;pointLight=null;#o=!1;#t;#it="demand";#ot=new i.Object3D;#m=new i.Vector3;#q=new i.Vector3;#d=new i.Vector3;#a=null;#p=null;#R=0;#f=null;#b=null;#L=null;#S=null;#z=null;#T=null;#F=null;#h=null;#v=null;#D=null;#P=!1;#B=null;#G=null;#W=null;#j=null;#O=null;#_=null;#U=null;#Z=null;#i=null;#M=new i.Layers;#H;#N=[];#y=0;#l=0;#u=new ot.ImprovedNoise;#n=t.uniform(.016);#r=t.uniform(0);#s=t.uniform($.clone());#g=t.uniform(new i.Vector3);#nt=t.uniform(new i.Matrix4);#X=t.uniform(0);#rt=t.uniform(new i.Vector3);#x=t.uniform(new i.Vector3);#Y=t.uniform(1);#V=t.uniform(new i.Vector3);#ht=t.uniform(3);#kt=t.uniform(.15);#E=t.uniform(3.2);#at=t.uniform(.1);#w=t.uniform(10);#lt=t.uniform(.25);#ut=t.uniform(1);#ct=t.uniform(.4);#A=t.uniform(7);#c=t.uniform(5.5);#mt=t.uniform(.25);#dt=t.uniform(6.5);#k=t.uniform(40);#pt=t.uniform(5);#K=t.uniform(2);#ft=t.uniform(.5);#J=t.uniform(new i.Color(16770700));#Q=t.uniform(new i.Color(16741125));#$=t.uniform(new i.Color(16711680));#vt=t.uniform(1);#yt=t.uniform(new i.Color(16777215));#C=t.uniform(0);#I=t.uniform(1.1);#gt=t.uniform(0);#xt=t.uniform(.59);#wt=t.uniform(1);#Ct=t.uniform(2);#It=t.uniform(10);#qt=t.uniform(10);#Rt=t.uniform(15);#Bt=t.uniform(10);#Gt=t.uniform(20);#Wt=t.uniform(.2);#jt=t.uniform(17);#Ot=t.uniform(3.25);#bt=t.uniform(3.5);#Lt=t.uniform(new i.Vector3);#St=t.uniform(1);#zt=t.uniform(0);constructor(s,e={}){this.viewer=s,this.#t=Q(e),this.#Tt(),this.#H=this.#Xt()}get enabled(){return this.#o}get emitter(){return this.#t.emitter??this.#ot}enable(s={}){return this.#o?this.update(s):(this.#t=Q(s,this.#t),this.#et(),this.#tt(),this.#it=this.viewer.frameloop,this.viewer.frameloop="always",this.viewer.renderPipeline.addOutputEffect(this.#H),this.viewer.addEventListener("beforeRender",this.#Et),this.viewer.addEventListener("cameraChange",this.#Pt),this.#o=!0,this.viewer.render(),this)}update(s={}){const e=this.#t;this.#t=Q(s,this.#t);const n=!e.size.equals(this.#t.size),a=e.gridSize.x!==this.#t.gridSize.x||e.gridSize.y!==this.#t.gridSize.y||e.gridSize.z!==this.#t.gridSize.z||e.emitterGeometry!==this.#t.emitterGeometry||e.volumeLayer!==this.#t.volumeLayer||e.raymarchSteps!==this.#t.raymarchSteps;return this.#o&&a&&(this.#st(),this.#et()),this.#o&&n&&!a&&(this.#P=!1),this.#tt(),this.viewer.renderPipeline.needsUpdateOutputNode=!0,this.viewer.render(),this}setPosition(s){return this.update({position:s})}setEmitter(s,e=this.#t.emitterGeometry){return this.update({emitter:s,emitterGeometry:e})}reset(){return this.#o?(this.#st(),this.#et(),this.#tt(),this.viewer.render(),this):this}disable(){return this.#o?(this.viewer.removeEventListener("beforeRender",this.#Et),this.viewer.removeEventListener("cameraChange",this.#Pt),this.viewer.renderPipeline.removeOutputEffect(this.#H),this.viewer.frameloop=this.#it,this.#o=!1,this.#st(),this.viewer.render(),this):this}dispose(){return this.disable(),this.#a?.dispose(),this.#a=null,this}#tt(){const{position:s,size:e}=this.#t,n=new i.Vector3(s.x,s.y+e.y*.5,s.z);this.#Tt(),this.#g.value.copy(n),this.#s.value.copy(e),this.#V.value.set(s.x-3*(e.x/8),s.y+6*(e.y/8)+e.y*.5+.4,s.z+3*(e.z/8)),this.#A.value=this.#t.emitDensity,this.#c.value=this.#t.emitTemperature,this.#mt.value=this.#t.motionBoost,this.#dt.value=this.#t.windStrength,this.#Y.value=this.#t.emitterRadius,this.#ht.value=this.#t.buoyancy,this.#lt.value=this.#t.velocityDamping,this.#at.value=this.#t.turbulenceDecay,this.#w.value=this.#t.turbulenceFrequency,this.#k.value=this.#t.fireIntensity,this.#pt.value=this.#t.glowSpread,this.#K.value=this.#t.shadowAbsorption,this.#ft.value=this.#t.shadowAmbient,this.#gt.value=this.#t.phaseAsymmetry,this.#xt.value=this.#t.powderStrength,this.#wt.value=this.#t.multiScattering,this.#I.value=this.#t.saturation,this.#J.value.set(this.#t.fireStartColor),this.#Q.value.set(this.#t.fireMidColor),this.#$.value.set(this.#t.fireEndColor),this.#vt.value=this.#t.smokeIntensity,this.#yt.value.set(this.#t.smokeColor),this.#C.value=this.#t.fireHue*Math.PI/180,this.mesh&&(this.mesh.position.copy(n),this.mesh.geometry.dispose(),this.mesh.geometry=new i.BoxGeometry(e.x,e.y,e.z),this.mesh.material.steps=this.#t.raymarchSteps,this.mesh.layers.disableAll(),this.mesh.layers.enable(this.#t.volumeLayer)),this.shadowMesh&&(this.shadowMesh.position.copy(n),this.shadowMesh.geometry.dispose(),this.shadowMesh.geometry=new i.BoxGeometry(e.x,e.y,e.z),this.shadowMesh.material.steps=this.#t.raymarchSteps),this.#i&&(this.#Ft(),this.#i.setLayers(this.#M),this.#i.setResolutionScale(this.#t.renderResolution)),this.#o&&this.#t.keyLight&&!this.keyLight&&this.#Nt(),this.keyLight&&(this.keyLight.visible=this.#t.keyLight,this.keyLight.position.copy(this.#V.value),this.keyLight.layers.enable(this.#t.volumeLayer),this.keyLight.target.position.set(s.x+1,s.y,s.z)),this.#o&&this.#t.pointLight&&!this.pointLight&&this.#Vt(),this.pointLight&&(this.pointLight.visible=this.#t.pointLight,this.pointLight.intensity=this.#t.pointLightIntensity,this.pointLight.layers.enable(this.#t.volumeLayer))}#Tt(){this.#t.emitter||this.#ot.position.copy(this.#t.position)}#Ft(){this.#M.disableAll(),this.#M.enable(this.#t.volumeLayer)}#et(){this.#y=0,this.#l=0,this.#P=!1,this.#_t(),this.#Ut(),this.#Zt(),this.#Ht(),this.#Nt(),this.#Dt(),this.#Vt(),this.emitter.updateMatrixWorld(),this.emitter.getWorldPosition(this.#d),this.#x.value.copy(this.#d)}#_t(){const s=this.#t.gridSize;this.#f=I("fire velocity A",s),this.#b=I("fire velocity B",s),this.#L=I("fire dye A",s),this.#S=I("fire dye B",s),this.#z=I("fire divergence",s),this.#T=I("fire pressure A",s),this.#F=I("fire pressure B",s),this.#h=I("fire curl noise",s),this.#h.wrapS=i.RepeatWrapping,this.#h.wrapT=i.RepeatWrapping,this.#h.wrapR=i.RepeatWrapping,this.#v=t.texture3D(this.#L),this.#D=t.storageTexture(this.#S).toWriteOnly()}#Ut(){this.#a?.dispose(),this.#a=null,this.#p=this.#t.emitterGeometry,this.#p||(this.#a=new nt.TeapotGeometry(.8,28),this.#p=this.#a);const s=this.#p.getAttribute("position");if(!s)throw new Error("FireEffect: emitterGeometry requires a position attribute.");this.#R=s.count}#Zt(){const s=this.#e(this.#f),e=this.#e(this.#b),n=this.#e(this.#v),a=this.#e(this.#D),p=this.#e(this.#z),f=this.#e(this.#T),N=this.#e(this.#F),d=this.#e(this.#h),v=t.texture3D(d),m=this.#e(this.#p).getAttribute("position"),T=t.storage(m,"vec3",this.#R).toReadOnly(),r=this.#t.gridSize,b=r.x*r.y*r.z,x=1/r.x,L=1/r.y,F=1/r.z,D=l=>{const o=l.mod(r.x),h=l.div(r.x).mod(r.y),y=l.div(r.x*r.y);return t.uvec3(o,h,y)},P=l=>t.vec3(l).add(.5).div(t.vec3(r.x,r.y,r.z)),W=t.Fn(()=>{const l=D(t.instanceIndex),o=P(l),h=this.#w,y=t.float(.1).div(h),u=t.vec3(y,0,0),z=t.vec3(0,y,0),S=t.vec3(0,0,y),g=o.mul(t.vec3(this.#s.x.div(this.#s.y),1,this.#s.z.div(this.#s.y))),w=B.snoiseVec3(g.sub(u).mul(h)),M=B.snoiseVec3(g.add(u).mul(h)),V=B.snoiseVec3(g.sub(z).mul(h)),E=B.snoiseVec3(g.add(z).mul(h)),k=B.snoiseVec3(g.sub(S).mul(h)),C=B.snoiseVec3(g.add(S).mul(h)),Z=E.z.sub(V.z).sub(C.y).add(k.y),X=C.x.sub(k.x).sub(M.z).add(w.z),O=M.y.sub(w.y).sub(E.x).add(V.x);G(d,l,t.vec4(t.vec3(Z,X,O).mul(5),0))})().compute(b).setName("fire.computeCurlNoise"),q=t.Fn(()=>{const l=D(t.instanceIndex),o=P(l),h=t.texture3D(s,o,0).xyz,y=o.sub(h.div(this.#s).mul(this.#n)),u=t.texture3D(s,y,0).xyz.toVar(),z=n.sample(o).level(t.float(0)),S=z.r,g=z.g,w=z.b,M=g.mul(this.#ht).sub(S.mul(this.#kt)).mul(this.#s.y);u.addAssign(t.vec3(0,M,0).mul(this.#n));const V=o.add(t.vec3(0,w.negate().mul(.6),w.mul(.13)).div(this.#w)),E=w.mul(this.#at.negate()).exp(),k=v.sample(V).level(t.float(0)).xyz.mul(this.#E).mul(g).mul(E),C=o.mul(.5).add(t.vec3(0,this.#r.mul(.25),this.#r.mul(.06)).div(this.#w)),Z=v.sample(C).level(t.float(0)).xyz.mul(this.#E.mul(.2)).mul(S);u.addAssign(k.add(Z).mul(this.#s.y).mul(this.#n)),u.mulAssign(t.max(t.float(1).sub(this.#lt.mul(this.#n)),t.float(0)));const O=o.sub(.5).mul(this.#s).add(this.#g).distance(this.#x);t.If(O.lessThan(this.#Y),()=>{const K=t.smoothstep(t.float(0),t.float(1),t.float(1).sub(O.div(this.#Y))),J=o.add(t.vec3(0,this.#r.mul(.5),0).div(this.#w)),tt=v.sample(J).level(t.float(0)).xyz.mul(this.#E).mul(this.#X),et=this.#rt.mul(this.#dt).add(tt).mul(this.#n).mul(K);u.addAssign(et)});const H=t.min(o,t.vec3(1).sub(o)),Y=t.smoothstep(t.float(0),t.float(.08),t.min(H.x,t.min(H.y,H.z)));u.mulAssign(Y),G(e,l,t.vec4(u,0))})().compute(b).setName("fire.advectVelocity"),_=t.Fn(()=>{const l=D(t.instanceIndex),o=P(l),h=t.texture3D(e,o.add(t.vec3(x,0,0)),0).x,y=t.texture3D(e,o.sub(t.vec3(x,0,0)),0).x,u=t.texture3D(e,o.add(t.vec3(0,L,0)),0).y,z=t.texture3D(e,o.sub(t.vec3(0,L,0)),0).y,S=t.texture3D(e,o.add(t.vec3(0,0,F)),0).z,g=t.texture3D(e,o.sub(t.vec3(0,0,F)),0).z,w=h.sub(y).add(u.sub(z)).add(S.sub(g)).mul(.5);G(p,l,t.vec4(w,0,0,0))})().compute(b).setName("fire.divergence"),j=(l,o,h)=>t.Fn(()=>{const y=D(t.instanceIndex),u=P(y),z=t.texture3D(l,u.add(t.vec3(x,0,0)),0).x,S=t.texture3D(l,u.sub(t.vec3(x,0,0)),0).x,g=t.texture3D(l,u.add(t.vec3(0,L,0)),0).x,w=t.texture3D(l,u.sub(t.vec3(0,L,0)),0).x,M=t.texture3D(l,u.add(t.vec3(0,0,F)),0).x,V=t.texture3D(l,u.sub(t.vec3(0,0,F)),0).x,E=t.texture3D(p,u,0).x,k=z.add(S).add(g).add(w).add(M).add(V).sub(E).div(6);G(o,y,t.vec4(k,0,0,0))})().compute(b).setName(h),A=t.Fn(()=>{const l=D(t.instanceIndex),o=P(l),h=t.texture3D(f,o.add(t.vec3(x,0,0)),0).x,y=t.texture3D(f,o.sub(t.vec3(x,0,0)),0).x,u=t.texture3D(f,o.add(t.vec3(0,L,0)),0).x,z=t.texture3D(f,o.sub(t.vec3(0,L,0)),0).x,S=t.texture3D(f,o.add(t.vec3(0,0,F)),0).x,g=t.texture3D(f,o.sub(t.vec3(0,0,F)),0).x,w=t.vec3(h.sub(y),u.sub(z),S.sub(g)).mul(.5),M=t.texture3D(e,o,0).xyz.sub(w);G(s,l,t.vec4(M,0))})().compute(b).setName("fire.project"),R=t.Fn(()=>{const l=D(t.instanceIndex),o=P(l),h=t.texture3D(s,o,0).xyz,y=o.sub(h.div(this.#s).mul(this.#n)),u=n.sample(y).level(t.float(0)),z=u.r.mul(t.max(t.float(1).sub(this.#ct.mul(this.#n)),t.float(0))).toVar(),S=u.g.mul(t.max(t.float(1).sub(this.#ut.mul(this.#n)),t.float(0))).toVar(),g=t.vec3(r.x,r.y,r.z),w=t.floor(y.mul(g)).add(.5).div(g),M=n.sample(w).level(t.float(0)).b.add(this.#n).toVar();S.assign(S.clamp(0,12)),t.If(z.lessThanEqual(.01),()=>{M.assign(0)}),G(a,l,t.vec4(z,S,M,1))})().compute(b).setName("fire.advectDye"),U=t.Fn(()=>{const l=T.element(t.instanceIndex),h=this.#nt.mul(t.vec4(l,1)).xyz.sub(this.#g).div(this.#s).add(.5);t.If(h.x.greaterThanEqual(0).and(h.x.lessThanEqual(1)).and(h.y.greaterThanEqual(0)).and(h.y.lessThanEqual(1)).and(h.z.greaterThanEqual(0)).and(h.z.lessThanEqual(1)),()=>{const y=t.uvec3(h.mul(t.vec3(r.x,r.y,r.z))),u=t.mx_noise_float(l.mul(9).add(t.vec3(0,this.#r.negate().mul(2.5),this.#r.mul(.7)))).mul(.5).add(.5),z=this.#c.greaterThan(0).select(t.float(1),t.float(0)),S=this.#X.mul(this.#mt),g=z.add(S),w=this.#A.mul(t.float(1/120)).mul(u.mul(.85).add(.15)).mul(g);t.If(w.greaterThan(0),()=>{const M=this.#c.mul(t.float(.008333333333333333)).mul(u.mul(.85).add(.15)).mul(g),V=n.sample(h).level(t.float(0)),E=V.r.add(w),k=V.g.add(M).clamp(0,12),C=t.mix(V.b,t.float(0),w.div(t.max(E,t.float(.001))));G(a,y,t.vec4(E,k,C,1))})})})().compute(this.#R).setName("fire.emit");this.#B=W,this.#G=q,this.#W=_,this.#j=j(f,N,"fire.jacobiAB"),this.#O=j(N,f,"fire.jacobiBA"),this.#_=A,this.#U=R,this.#Z=U}#Ht(){const s=this.#e(this.#v),e=this.#e(this.#f),n=new i.VolumeNodeMaterial;n.steps=this.#t.raymarchSteps,n.transparent=!0,n.blending=i.AdditiveBlending,n.depthWrite=!1,n.offsetNode=t.fract(t.interleavedGradientNoise(t.screenCoordinate).add(t.float(t.frameId).mul(.618033988749895)));const a=t.Fn(([v])=>{const m=t.vec3(0).toVar();return m.assign(t.mix(t.vec3(0,0,0),this.#$,t.smoothstep(t.float(.05),t.float(.35),v))),m.assign(t.mix(m,this.#Q,t.smoothstep(t.float(.35),t.float(.65),v))),m.assign(t.mix(m,this.#J,t.smoothstep(t.float(.65),t.float(1),v))),m}),p=t.Fn(([v,m])=>{const T=m.mul(m),r=t.float(1).add(T).sub(t.float(2).mul(m).mul(v));return t.float(1).sub(T).div(r.pow(1.5)).mul(.079577)}),f=({positionRay:v})=>{const m=v.sub(this.#g).div(this.#s).add(.5).toVar(),T=t.texture3D(e,m,0).xyz.div(this.#s).mul(.15),r=m.add(T).clamp(0,1).toVar(),b=s.sample(r).level(t.float(0)),x=b.r.toVar(),L=b.b,F=b.g,D=B.snoise(v.mul(5.5).add(t.vec3(0,L.mul(.8).negate(),0)));x.mulAssign(D.mul(.35).add(.85));const P=t.min(r,t.vec3(1).sub(r));return x.mulAssign(t.smoothstep(t.float(0),t.float(.06),t.min(P.x,t.min(P.y,P.z)))),{density:x,temperature:F}};n.scatteringNode=t.Fn(({positionRay:v})=>{const{density:m}=f({positionRay:v}),T=this.#V.sub(v).normalize(),r=t.float(0).toVar(),b=.35;for(let R=0;R<2;R++){const U=(R+.5)*b,o=v.add(T.mul(U)).sub(this.#g).div(this.#s).add(.5),h=t.min(o,t.vec3(1).sub(o)),y=t.smoothstep(t.float(0),t.float(.06),t.min(h.x,t.min(h.y,h.z)));r.addAssign(s.sample(o).level(t.float(0)).r.mul(y))}const x=r.mul(b).mul(this.#K),L=x.negate().exp(),F=x.mul(.25).negate().exp().mul(.5),D=t.mix(L,L.add(F),this.#wt),P=t.float(1).sub(x.mul(2).negate().exp()),q=t.mix(D,D.mul(P),this.#xt).add(this.#ft).clamp(0,1),j=t.cameraPosition.sub(v).normalize().dot(T).clamp(-1,1),A=p(j,this.#gt);return this.#yt.mul(m).mul(q).mul(A.mul(12.56637)).mul(this.#vt)}),n.scatteringEmissiveNode=t.Fn(({positionRay:v})=>{const{density:m,temperature:T}=f({positionRay:v}),r=t.float(6).sub(this.#pt),b=a(T.clamp(0,1)).mul(T.pow(r)).mul(this.#k),x=t.hue(b,this.#C),L=v.sub(this.#V).length(),F=t.float(400).div(L.pow(2));return x.mul(m.add(.15)).mul(F)});const N=t.Fn(()=>{const v=t.positionWorld,m=t.positionWorld.sub(t.cameraPosition).normalize(),T=this.#t.raymarchSteps,r=this.#s.length().div(T).toVar(),b=m.toVar(),x=t.float(0).toVar(),L=t.float(1).toVar();return t.Loop(T,()=>{const F=v.add(b.mul(x)),{density:D}=f({positionRay:F}),W=D.mul(this.#K).mul(.01).negate().mul(r).exp();L.mulAssign(W),x.addAssign(r)}),L.greaterThanEqual(.99).discard(),t.vec4(t.vec3(0),L.oneMinus().mul(5))});this.mesh=new i.Mesh(new i.BoxGeometry(this.#t.size.x,this.#t.size.y,this.#t.size.z),n),this.mesh.name="FireEffect.volume",this.mesh.frustumCulled=!1,this.mesh.receiveShadow=!0,this.mesh.layers.disableAll(),this.mesh.layers.enable(this.#t.volumeLayer),this.viewer.scene.add(this.mesh);const d=new i.VolumeNodeMaterial;d.steps=n.steps,d.offsetNode=n.offsetNode,d.castShadowNode=N(),d.shadowSide=i.FrontSide,d.colorWrite=!1,d.depthWrite=!1,d.blending=i.CustomBlending,d.blendEquation=i.AddEquation,d.blendSrc=i.ZeroFactor,d.blendDst=i.OneMinusSrcAlphaFactor,d.blendEquationAlpha=i.AddEquation,d.blendSrcAlpha=i.OneFactor,d.blendDstAlpha=i.OneMinusSrcAlphaFactor,this.shadowMesh=new i.Mesh(new i.BoxGeometry(this.#t.size.x,this.#t.size.y,this.#t.size.z),d),this.shadowMesh.name="FireEffect.shadow",this.shadowMesh.position.copy(this.mesh.position),this.shadowMesh.castShadow=!0,this.viewer.scene.add(this.shadowMesh)}#Dt(){this.#Ft(),this.#i=t.pass(this.viewer.scene,this.viewer.camera),this.#i.name="FireEffect Volumetric Pass",this.#i.setLayers(this.#M),this.#i.setResolutionScale(this.#t.renderResolution)}#Pt=()=>{this.#o&&(this.#i?.dispose(),this.#Dt(),this.viewer.renderPipeline.needsUpdateOutputNode=!0,this.viewer.render())};#Xt(){return((s,e)=>{if(this.#Mt(),!this.#i)return e;let n=this.#i;if(this.#t.denoise){const d=it.gaussianBlur(this.#i,this.#t.denoiseStrength,1);this.#N.push(d),n=d}const a=n.rgb,p=t.saturation(a,this.#I),f=t.vec4(p,n.a).mul(.5);let N=e.max(f).add(f);if(this.#t.bloom){const d=st.bloom(N,this.#t.bloomStrength,this.#t.bloomRadius,this.#t.bloomThreshold);this.#N.push(d),N=N.add(d)}return N})}#Mt(){for(const s of this.#N)s.dispose();this.#N=[]}#Nt(){!this.#t.keyLight||this.keyLight||(this.keyLight=new i.SpotLight(16777215,1e3),this.keyLight.name="FireEffect.keyLight",this.keyLight.angle=Math.PI/5,this.keyLight.penumbra=1,this.keyLight.decay=2,this.keyLight.distance=0,this.keyLight.castShadow=!0,this.keyLight.shadow.intensity=.98,this.keyLight.shadow.mapSize.width=1024,this.keyLight.shadow.mapSize.height=1024,this.keyLight.shadow.camera.near=1,this.keyLight.shadow.camera.far=20*(Math.max(this.#t.size.x,this.#t.size.y,this.#t.size.z)/8),this.keyLight.shadow.bias=-.001,this.keyLight.shadow.focus=1,this.keyLight.layers.enable(this.#t.volumeLayer),this.viewer.scene.add(this.keyLight),this.viewer.scene.add(this.keyLight.target))}#Vt(){if(!this.#t.pointLight||this.pointLight)return;const s=t.Fn(([a])=>{const p=t.vec3(0).toVar();return p.assign(t.mix(t.vec3(0,0,0),this.#$,t.smoothstep(t.float(.05),t.float(.35),a))),p.assign(t.mix(p,this.#Q,t.smoothstep(t.float(.35),t.float(.65),a))),p.assign(t.mix(p,this.#J,t.smoothstep(t.float(.65),t.float(1),a))),p}),e=t.Fn(({material:a})=>{const p=a&&a.isVolumeNodeMaterial;return t.float(p?1:0)})(),n=t.Fn(()=>{const a=t.positionWorld,p=this.#x,f=t.vec3(0,this.#bt,0),d=a.sub(p).dot(f).div(f.dot(f)).clamp(0,1),v=p.add(this.#Lt).add(f.mul(d)),m=a.sub(v).length(),T=t.float(1.2),r=t.float(1).div(m.pow(2).add(T.pow(2))),x=a.sub(p).length().pow(2).max(.01).reciprocal(),L=e.equal(1).select(r.div(x),t.float(1)),F=e.equal(1).select(this.#Ct,this.#It),D=this.#c.div(8.34).mul(.5).add(.2).add(this.#zt).clamp(0,1),P=s(D),W=t.hue(t.saturation(P,this.#I),this.#C),q=a.xz.sub(p.xz),_=t.atan(q.y,q.x),j=q.length(),A=this.#Wt,R=t.mx_noise_float(t.vec3(t.cos(_).mul(t.float(1.5).mul(A)),t.sin(_).mul(t.float(1.5).mul(A)),this.#r.mul(.6))).mul(.5).add(.5),U=t.smoothstep(t.float(0),this.#Ot,j),l=t.mix(t.float(1),R,U),o=t.vec3(a.x.mul(t.float(.6).mul(A)),this.#r.mul(1.2),a.z.mul(t.float(.6).mul(A))),h=t.mx_noise_float(o).mul(.5).add(.5),y=t.vec3(a.x.mul(t.float(1.5).mul(A)),this.#r.mul(2.5),a.z.mul(t.float(1.5).mul(A))),u=t.mx_noise_float(y).mul(.5).add(.5),S=h.mul(.65).add(u.mul(.35)).mul(l.mul(.5).add(.5)),g=m.div(this.#jt).clamp(0,1),w=t.mix(S,t.float(1),g),V=t.float(1).sub(m.div(this.#Gt)).clamp(0,1).mul(w).clamp(0,1),E=s(V),k=t.hue(t.saturation(E,this.#I),this.#C),C=e.equal(1).select(W,k),Z=this.#c.div(8.34).max(0).pow(4),X=this.#A.div(11.02).max(0),O=t.smoothstep(t.float(0),t.float(3),this.#r),H=C.mul(Z).mul(X).mul(this.#k).mul(F).mul(this.#St).mul(O),Y=m.div(this.#Bt).clamp(0,1),K=t.mix(this.#qt,this.#Rt,t.smoothstep(t.float(0),t.float(1),Y)),J=e.equal(1).select(K,t.float(1));return H.mul(L).mul(J)})();this.pointLight=new i.PointLight(16777215,this.#t.pointLightIntensity,this.#t.pointLightDistance,2),this.pointLight.name="FireEffect.pointLight",this.pointLight.colorNode=n,this.pointLight.layers.enable(this.#t.volumeLayer),this.viewer.scene.add(this.pointLight)}#Et=({delta:s})=>{if(!this.#o)return;const e=this.viewer.renderer;if(this.#P||(e.compute(this.#e(this.#B)),this.#P=!0),this.#Yt(s),this.#At(this.#y),this.#t.simulate&&this.#t.simSpeed>0){const n=.008333333333333333*this.#t.simSpeed;for(this.#l+=Math.min(s,1/30)*this.#t.simSpeed,this.#l=Math.min(this.#l,n*8),this.#n.value=n,this.#E.value=this.#t.turbulence/Math.sqrt(this.#t.simSpeed),this.#ct.value=this.#t.smokeLifespan>=100?0:1/this.#t.smokeLifespan,this.#ut.value=1/this.#t.fireLifespan;this.#l>=n;){this.#y+=n,this.#At(this.#y),e.compute(this.#e(this.#G)),e.compute(this.#e(this.#W));for(let a=0;a<this.#t.pressureIterations;a++)e.compute(this.#e(a%2===0?this.#j:this.#O));e.compute(this.#e(this.#_)),e.compute(this.#e(this.#U)),e.compute(this.#e(this.#Z)),this.#Kt(),this.#l-=n}}if(this.pointLight){const n=this.#c.value/8.34,a=this.#A.value/11.02,p=this.#k.value/5.63,f=Math.sqrt(Math.max(.01,n*a*p)),N=ut(Math.min(Math.max(this.#y/3,0),1));this.pointLight.position.copy(this.#x.value),this.pointLight.distance=Math.max(.01,this.#t.pointLightDistance*Math.max(.2,f)*N),this.pointLight.intensity=this.#t.pointLightIntensity}};#Yt(s){const e=this.emitter;e.updateMatrixWorld(),this.#nt.value.copy(e.matrixWorld),e.getWorldPosition(this.#m),this.#q.set(0,0,0),s>0&&this.#q.subVectors(this.#m,this.#d).multiplyScalar(1/s),this.#X.value=s>0?this.#m.distanceTo(this.#d)/s:0,this.#rt.value.copy(this.#q),this.#x.value.copy(this.#m),this.#d.copy(this.#m)}#At(s){this.#r.value=s%1e3;const e=this.#u.noise(0,s*2.5,0);this.#bt.value=3.5+e*.8;const n=this.#u.noise(s*3.5,0,0)*.4,a=this.#u.noise(0,0,s*3.5)*.4;this.#Lt.value.set(n,0,a);const p=this.#u.noise(0,s*.8,0),f=this.#u.noise(0,s*15,0);this.#St.value=p*.12+f*.06+.82,this.#zt.value=this.#u.noise(s*5,s*5,0)*.08}#Kt(){const s=this.#e(this.#v),e=this.#e(this.#D),n=s.value;s.value=e.value,e.value=n}#st(){this.mesh&&(this.viewer.scene.remove(this.mesh),this.mesh.geometry.dispose(),this.mesh.material.dispose(),this.mesh=null),this.shadowMesh&&(this.viewer.scene.remove(this.shadowMesh),this.shadowMesh.geometry.dispose(),this.shadowMesh.material.dispose(),this.shadowMesh=null),this.keyLight&&(this.viewer.scene.remove(this.keyLight.target),this.viewer.scene.remove(this.keyLight),this.keyLight.dispose(),this.keyLight=null),this.pointLight&&(this.viewer.scene.remove(this.pointLight),this.pointLight.dispose(),this.pointLight=null),this.#i?.dispose(),this.#i=null,this.#f?.dispose(),this.#b?.dispose(),this.#L?.dispose(),this.#S?.dispose(),this.#z?.dispose(),this.#T?.dispose(),this.#F?.dispose(),this.#h?.dispose(),this.#f=null,this.#b=null,this.#L=null,this.#S=null,this.#z=null,this.#T=null,this.#F=null,this.#h=null,this.#v=null,this.#D=null,this.#B=null,this.#G=null,this.#W=null,this.#j=null,this.#O=null,this.#_=null,this.#U=null,this.#Z=null,this.#Mt()}#e(s){if(s===null)throw new Error("FireEffect: resource is not initialized.");return s}}function ut(c){return c*c*(3-2*c)}exports.FireEffect=lt;
@@ -0,0 +1 @@
1
+ export * from './FireEffect';
@@ -0,0 +1,433 @@
1
+ import { Vector3 as B, Object3D as Et, Layers as Nt, Matrix4 as Ft, Color as ot, BoxGeometry as nt, RepeatWrapping as dt, VolumeNodeMaterial as ft, AdditiveBlending as At, Mesh as wt, FrontSide as kt, CustomBlending as Vt, AddEquation as bt, ZeroFactor as Ct, OneMinusSrcAlphaFactor as xt, OneFactor as Dt, SpotLight as It, PointLight as Rt, Storage3DTexture as Bt, RGBAFormat as qt, HalfFloatType as Gt, LinearFilter as Lt, ClampToEdgeWrapping as mt } from "three/webgpu";
2
+ import { uniform as i, texture3D as p, storageTexture as Wt, storage as jt, Fn as A, float as s, vec3 as o, vec4 as W, max as ht, If as rt, smoothstep as V, min as j, floor as Ot, instanceIndex as H, uvec3 as St, mx_noise_float as at, mix as I, fract as Ut, interleavedGradientNoise as Zt, screenCoordinate as _t, frameId as Ht, cameraPosition as zt, hue as pt, positionWorld as yt, Loop as Xt, pass as Yt, saturation as gt, atan as Kt, cos as Jt, sin as Qt, textureStore as $t } from "three/tsl";
3
+ import { bloom as te } from "three/addons/tsl/display/BloomNode.js";
4
+ import { gaussianBlur as ee } from "three/addons/tsl/display/GaussianBlurNode.js";
5
+ import { ImprovedNoise as se } from "three/addons/math/ImprovedNoise.js";
6
+ import { TeapotGeometry as ie } from "three/addons/geometries/TeapotGeometry.js";
7
+ import { snoiseVec3 as Q, snoise as oe } from "three/addons/tsl/math/curlNoise.js";
8
+ const ne = { x: 100, y: 100, z: 200 }, Tt = new B(12, 12, 24), he = new B();
9
+ function re(d) {
10
+ const e = Math.max(2, Math.floor(Number.isFinite(d) ? d : 2));
11
+ return e % 2 === 0 ? e : e + 1;
12
+ }
13
+ function vt(d = {}, e) {
14
+ const t = e ?? {
15
+ position: he.clone(),
16
+ size: Tt.clone(),
17
+ gridSize: { ...ne },
18
+ volumeLayer: 10,
19
+ emitterGeometry: null,
20
+ emitter: null,
21
+ emitterRadius: 1,
22
+ simulate: !0,
23
+ simSpeed: 1.2,
24
+ pressureIterations: 2,
25
+ raymarchSteps: 16,
26
+ renderResolution: 0.5,
27
+ denoise: !0,
28
+ denoiseStrength: 0.5,
29
+ bloom: !0,
30
+ bloomStrength: 0.1,
31
+ bloomRadius: 1,
32
+ bloomThreshold: 0.5,
33
+ smokeLifespan: 3.5,
34
+ smokeIntensity: 1,
35
+ smokeColor: 16777215,
36
+ fireLifespan: 1.3,
37
+ turbulence: 3.2,
38
+ turbulenceDecay: 0.1,
39
+ turbulenceFrequency: 10,
40
+ buoyancy: 3,
41
+ velocityDamping: 0.25,
42
+ emitDensity: 7,
43
+ emitTemperature: 5.5,
44
+ motionBoost: 0.25,
45
+ windStrength: 6.5,
46
+ fireIntensity: 40,
47
+ glowSpread: 5,
48
+ fireHue: 0,
49
+ saturation: 1.1,
50
+ fireStartColor: 16770700,
51
+ fireMidColor: 16741125,
52
+ fireEndColor: 16711680,
53
+ phaseAsymmetry: 0,
54
+ powderStrength: 0.59,
55
+ multiScattering: 1,
56
+ shadowAbsorption: 2,
57
+ shadowAmbient: 0.5,
58
+ keyLight: !0,
59
+ pointLight: !0,
60
+ pointLightIntensity: 1,
61
+ pointLightDistance: 40
62
+ };
63
+ return {
64
+ ...t,
65
+ ...d,
66
+ position: d.position?.clone() ?? t.position.clone(),
67
+ size: d.size?.clone() ?? t.size.clone(),
68
+ gridSize: {
69
+ x: Math.max(2, Math.floor(d.gridSize?.x ?? t.gridSize.x)),
70
+ y: Math.max(2, Math.floor(d.gridSize?.y ?? t.gridSize.y)),
71
+ z: Math.max(2, Math.floor(d.gridSize?.z ?? t.gridSize.z))
72
+ },
73
+ volumeLayer: Math.max(0, Math.min(31, Math.floor(d.volumeLayer ?? t.volumeLayer))),
74
+ emitter: d.emitter === void 0 ? t.emitter : d.emitter,
75
+ emitterGeometry: d.emitterGeometry === void 0 ? t.emitterGeometry : d.emitterGeometry,
76
+ emitterRadius: Math.max(0.01, d.emitterRadius ?? t.emitterRadius),
77
+ pressureIterations: re(d.pressureIterations ?? t.pressureIterations),
78
+ raymarchSteps: Math.max(4, Math.floor(d.raymarchSteps ?? t.raymarchSteps)),
79
+ renderResolution: Math.min(1, Math.max(0.1, d.renderResolution ?? t.renderResolution)),
80
+ smokeIntensity: Math.max(0, d.smokeIntensity ?? t.smokeIntensity)
81
+ };
82
+ }
83
+ function U(d, e) {
84
+ const t = new Bt(e.x, e.y, e.z);
85
+ return t.name = d, t.format = qt, t.type = Gt, t.minFilter = Lt, t.magFilter = Lt, t.wrapS = mt, t.wrapT = mt, t.wrapR = mt, t;
86
+ }
87
+ function X(d, e, t) {
88
+ return $t(
89
+ d,
90
+ e,
91
+ t
92
+ ).toWriteOnly();
93
+ }
94
+ class ge {
95
+ viewer;
96
+ mesh = null;
97
+ shadowMesh = null;
98
+ keyLight = null;
99
+ pointLight = null;
100
+ #o = !1;
101
+ #t;
102
+ #it = "demand";
103
+ #ot = new Et();
104
+ #d = new B();
105
+ #R = new B();
106
+ #m = new B();
107
+ #a = null;
108
+ #p = null;
109
+ #B = 0;
110
+ #y = null;
111
+ #x = null;
112
+ #L = null;
113
+ #S = null;
114
+ #z = null;
115
+ #T = null;
116
+ #P = null;
117
+ #r = null;
118
+ #g = null;
119
+ #M = null;
120
+ #E = !1;
121
+ #q = null;
122
+ #G = null;
123
+ #W = null;
124
+ #j = null;
125
+ #O = null;
126
+ #U = null;
127
+ #Z = null;
128
+ #_ = null;
129
+ #i = null;
130
+ #N = new Nt();
131
+ #H;
132
+ #F = [];
133
+ #v = 0;
134
+ #l = 0;
135
+ #u = new se();
136
+ #n = i(0.016);
137
+ #h = i(0);
138
+ #s = i(Tt.clone());
139
+ #f = i(new B());
140
+ #nt = i(new Ft());
141
+ #X = i(0);
142
+ #ht = i(new B());
143
+ #w = i(new B());
144
+ #Y = i(1);
145
+ #A = i(new B());
146
+ #rt = i(3);
147
+ #Ct = i(0.15);
148
+ #k = i(3.2);
149
+ #at = i(0.1);
150
+ #b = i(10);
151
+ #lt = i(0.25);
152
+ #ut = i(1);
153
+ #ct = i(0.4);
154
+ #V = i(7);
155
+ #c = i(5.5);
156
+ #dt = i(0.25);
157
+ #mt = i(6.5);
158
+ #C = i(40);
159
+ #pt = i(5);
160
+ #K = i(2);
161
+ #yt = i(0.5);
162
+ #J = i(new ot(16770700));
163
+ #Q = i(new ot(16741125));
164
+ #$ = i(new ot(16711680));
165
+ #gt = i(1);
166
+ #vt = i(new ot(16777215));
167
+ #D = i(0);
168
+ #I = i(1.1);
169
+ #ft = i(0);
170
+ #wt = i(0.59);
171
+ #bt = i(1);
172
+ #Dt = i(2);
173
+ #It = i(10);
174
+ #Rt = i(10);
175
+ #Bt = i(15);
176
+ #qt = i(10);
177
+ #Gt = i(20);
178
+ #Wt = i(0.2);
179
+ #jt = i(17);
180
+ #Ot = i(3.25);
181
+ #xt = i(3.5);
182
+ #Lt = i(new B());
183
+ #St = i(1);
184
+ #zt = i(0);
185
+ constructor(e, t = {}) {
186
+ this.viewer = e, this.#t = vt(t), this.#Tt(), this.#H = this.#Xt();
187
+ }
188
+ get enabled() {
189
+ return this.#o;
190
+ }
191
+ get emitter() {
192
+ return this.#t.emitter ?? this.#ot;
193
+ }
194
+ enable(e = {}) {
195
+ return this.#o ? this.update(e) : (this.#t = vt(e, this.#t), this.#et(), this.#tt(), this.#it = this.viewer.frameloop, this.viewer.frameloop = "always", this.viewer.renderPipeline.addOutputEffect(this.#H), this.viewer.addEventListener("beforeRender", this.#kt), this.viewer.addEventListener("cameraChange", this.#Et), this.#o = !0, this.viewer.render(), this);
196
+ }
197
+ update(e = {}) {
198
+ const t = this.#t;
199
+ this.#t = vt(e, this.#t);
200
+ const h = !t.size.equals(this.#t.size), l = t.gridSize.x !== this.#t.gridSize.x || t.gridSize.y !== this.#t.gridSize.y || t.gridSize.z !== this.#t.gridSize.z || t.emitterGeometry !== this.#t.emitterGeometry || t.volumeLayer !== this.#t.volumeLayer || t.raymarchSteps !== this.#t.raymarchSteps;
201
+ return this.#o && l && (this.#st(), this.#et()), this.#o && h && !l && (this.#E = !1), this.#tt(), this.viewer.renderPipeline.needsUpdateOutputNode = !0, this.viewer.render(), this;
202
+ }
203
+ setPosition(e) {
204
+ return this.update({ position: e });
205
+ }
206
+ setEmitter(e, t = this.#t.emitterGeometry) {
207
+ return this.update({ emitter: e, emitterGeometry: t });
208
+ }
209
+ reset() {
210
+ return this.#o ? (this.#st(), this.#et(), this.#tt(), this.viewer.render(), this) : this;
211
+ }
212
+ disable() {
213
+ return this.#o ? (this.viewer.removeEventListener("beforeRender", this.#kt), this.viewer.removeEventListener("cameraChange", this.#Et), this.viewer.renderPipeline.removeOutputEffect(this.#H), this.viewer.frameloop = this.#it, this.#o = !1, this.#st(), this.viewer.render(), this) : this;
214
+ }
215
+ dispose() {
216
+ return this.disable(), this.#a?.dispose(), this.#a = null, this;
217
+ }
218
+ #tt() {
219
+ const { position: e, size: t } = this.#t, h = new B(e.x, e.y + t.y * 0.5, e.z);
220
+ this.#Tt(), this.#f.value.copy(h), this.#s.value.copy(t), this.#A.value.set(
221
+ e.x - 3 * (t.x / 8),
222
+ e.y + 6 * (t.y / 8) + t.y * 0.5 + 0.4,
223
+ e.z + 3 * (t.z / 8)
224
+ ), this.#V.value = this.#t.emitDensity, this.#c.value = this.#t.emitTemperature, this.#dt.value = this.#t.motionBoost, this.#mt.value = this.#t.windStrength, this.#Y.value = this.#t.emitterRadius, this.#rt.value = this.#t.buoyancy, this.#lt.value = this.#t.velocityDamping, this.#at.value = this.#t.turbulenceDecay, this.#b.value = this.#t.turbulenceFrequency, this.#C.value = this.#t.fireIntensity, this.#pt.value = this.#t.glowSpread, this.#K.value = this.#t.shadowAbsorption, this.#yt.value = this.#t.shadowAmbient, this.#ft.value = this.#t.phaseAsymmetry, this.#wt.value = this.#t.powderStrength, this.#bt.value = this.#t.multiScattering, this.#I.value = this.#t.saturation, this.#J.value.set(this.#t.fireStartColor), this.#Q.value.set(this.#t.fireMidColor), this.#$.value.set(this.#t.fireEndColor), this.#gt.value = this.#t.smokeIntensity, this.#vt.value.set(this.#t.smokeColor), this.#D.value = this.#t.fireHue * Math.PI / 180, this.mesh && (this.mesh.position.copy(h), this.mesh.geometry.dispose(), this.mesh.geometry = new nt(t.x, t.y, t.z), this.mesh.material.steps = this.#t.raymarchSteps, this.mesh.layers.disableAll(), this.mesh.layers.enable(this.#t.volumeLayer)), this.shadowMesh && (this.shadowMesh.position.copy(h), this.shadowMesh.geometry.dispose(), this.shadowMesh.geometry = new nt(t.x, t.y, t.z), this.shadowMesh.material.steps = this.#t.raymarchSteps), this.#i && (this.#Pt(), this.#i.setLayers(this.#N), this.#i.setResolutionScale(this.#t.renderResolution)), this.#o && this.#t.keyLight && !this.keyLight && this.#Ft(), this.keyLight && (this.keyLight.visible = this.#t.keyLight, this.keyLight.position.copy(this.#A.value), this.keyLight.layers.enable(this.#t.volumeLayer), this.keyLight.target.position.set(e.x + 1, e.y, e.z)), this.#o && this.#t.pointLight && !this.pointLight && this.#At(), this.pointLight && (this.pointLight.visible = this.#t.pointLight, this.pointLight.intensity = this.#t.pointLightIntensity, this.pointLight.layers.enable(this.#t.volumeLayer));
225
+ }
226
+ #Tt() {
227
+ this.#t.emitter || this.#ot.position.copy(this.#t.position);
228
+ }
229
+ #Pt() {
230
+ this.#N.disableAll(), this.#N.enable(this.#t.volumeLayer);
231
+ }
232
+ #et() {
233
+ this.#v = 0, this.#l = 0, this.#E = !1, this.#Ut(), this.#Zt(), this.#_t(), this.#Ht(), this.#Ft(), this.#Mt(), this.#At(), this.emitter.updateMatrixWorld(), this.emitter.getWorldPosition(this.#m), this.#w.value.copy(this.#m);
234
+ }
235
+ #Ut() {
236
+ const e = this.#t.gridSize;
237
+ this.#y = U("fire velocity A", e), this.#x = U("fire velocity B", e), this.#L = U("fire dye A", e), this.#S = U("fire dye B", e), this.#z = U("fire divergence", e), this.#T = U("fire pressure A", e), this.#P = U("fire pressure B", e), this.#r = U("fire curl noise", e), this.#r.wrapS = dt, this.#r.wrapT = dt, this.#r.wrapR = dt, this.#g = p(this.#L), this.#M = Wt(this.#S).toWriteOnly();
238
+ }
239
+ #Zt() {
240
+ this.#a?.dispose(), this.#a = null, this.#p = this.#t.emitterGeometry, this.#p || (this.#a = new ie(0.8, 28), this.#p = this.#a);
241
+ const e = this.#p.getAttribute("position");
242
+ if (!e)
243
+ throw new Error("FireEffect: emitterGeometry requires a position attribute.");
244
+ this.#B = e.count;
245
+ }
246
+ #_t() {
247
+ const e = this.#e(this.#y), t = this.#e(this.#x), h = this.#e(this.#g), l = this.#e(this.#M), g = this.#e(this.#z), v = this.#e(this.#T), C = this.#e(this.#P), y = this.#e(this.#r), f = p(y), m = this.#e(this.#p).getAttribute("position"), M = jt(m, "vec3", this.#B).toReadOnly(), r = this.#t.gridSize, S = r.x * r.y * r.z, x = 1 / r.x, z = 1 / r.y, E = 1 / r.z, N = (u) => {
248
+ const n = u.mod(r.x), a = u.div(r.x).mod(r.y), w = u.div(r.x * r.y);
249
+ return St(n, a, w);
250
+ }, F = (u) => o(u).add(0.5).div(o(r.x, r.y, r.z)), Y = A(() => {
251
+ const u = N(H), n = F(u), a = this.#b, w = s(0.1).div(a), c = o(w, 0, 0), P = o(0, w, 0), T = o(0, 0, w), b = n.mul(o(this.#s.x.div(this.#s.y), 1, this.#s.z.div(this.#s.y))), L = Q(b.sub(c).mul(a)), k = Q(b.add(c).mul(a)), D = Q(b.sub(P).mul(a)), R = Q(b.add(P).mul(a)), G = Q(b.sub(T).mul(a)), O = Q(b.add(T).mul(a)), et = R.z.sub(D.z).sub(O.y).add(G.y), it = O.x.sub(G.x).sub(k.z).add(L.z), J = k.y.sub(L.y).sub(R.x).add(D.x);
252
+ X(y, u, W(o(et, it, J).mul(5), 0));
253
+ })().compute(S).setName("fire.computeCurlNoise"), Z = A(() => {
254
+ const u = N(H), n = F(u), a = p(e, n, 0).xyz, w = n.sub(a.div(this.#s).mul(this.#n)), c = p(e, w, 0).xyz.toVar(), P = h.sample(n).level(s(0)), T = P.r, b = P.g, L = P.b, k = b.mul(this.#rt).sub(T.mul(this.#Ct)).mul(this.#s.y);
255
+ c.addAssign(o(0, k, 0).mul(this.#n));
256
+ const D = n.add(o(0, L.negate().mul(0.6), L.mul(0.13)).div(this.#b)), R = L.mul(this.#at.negate()).exp(), G = f.sample(D).level(s(0)).xyz.mul(this.#k).mul(b).mul(R), O = n.mul(0.5).add(o(0, this.#h.mul(0.25), this.#h.mul(0.06)).div(this.#b)), et = f.sample(O).level(s(0)).xyz.mul(this.#k.mul(0.2)).mul(T);
257
+ c.addAssign(G.add(et).mul(this.#s.y).mul(this.#n)), c.mulAssign(ht(s(1).sub(this.#lt.mul(this.#n)), s(0)));
258
+ const J = n.sub(0.5).mul(this.#s).add(this.#f).distance(this.#w);
259
+ rt(J.lessThan(this.#Y), () => {
260
+ const ut = V(s(0), s(1), s(1).sub(J.div(this.#Y))), ct = n.add(o(0, this.#h.mul(0.5), 0).div(this.#b)), Pt = f.sample(ct).level(s(0)).xyz.mul(this.#k).mul(this.#X), Mt = this.#ht.mul(this.#mt).add(Pt).mul(this.#n).mul(ut);
261
+ c.addAssign(Mt);
262
+ });
263
+ const st = j(n, o(1).sub(n)), lt = V(s(0), s(0.08), j(st.x, j(st.y, st.z)));
264
+ c.mulAssign(lt), X(t, u, W(c, 0));
265
+ })().compute(S).setName("fire.advectVelocity"), $ = A(() => {
266
+ const u = N(H), n = F(u), a = p(t, n.add(o(x, 0, 0)), 0).x, w = p(t, n.sub(o(x, 0, 0)), 0).x, c = p(t, n.add(o(0, z, 0)), 0).y, P = p(t, n.sub(o(0, z, 0)), 0).y, T = p(t, n.add(o(0, 0, E)), 0).z, b = p(t, n.sub(o(0, 0, E)), 0).z, L = a.sub(w).add(c.sub(P)).add(T.sub(b)).mul(0.5);
267
+ X(g, u, W(L, 0, 0, 0));
268
+ })().compute(S).setName("fire.divergence"), K = (u, n, a) => A(() => {
269
+ const w = N(H), c = F(w), P = p(u, c.add(o(x, 0, 0)), 0).x, T = p(u, c.sub(o(x, 0, 0)), 0).x, b = p(u, c.add(o(0, z, 0)), 0).x, L = p(u, c.sub(o(0, z, 0)), 0).x, k = p(u, c.add(o(0, 0, E)), 0).x, D = p(u, c.sub(o(0, 0, E)), 0).x, R = p(g, c, 0).x, G = P.add(T).add(b).add(L).add(k).add(D).sub(R).div(6);
270
+ X(n, w, W(G, 0, 0, 0));
271
+ })().compute(S).setName(a), q = A(() => {
272
+ const u = N(H), n = F(u), a = p(v, n.add(o(x, 0, 0)), 0).x, w = p(v, n.sub(o(x, 0, 0)), 0).x, c = p(v, n.add(o(0, z, 0)), 0).x, P = p(v, n.sub(o(0, z, 0)), 0).x, T = p(v, n.add(o(0, 0, E)), 0).x, b = p(v, n.sub(o(0, 0, E)), 0).x, L = o(a.sub(w), c.sub(P), T.sub(b)).mul(0.5), k = p(t, n, 0).xyz.sub(L);
273
+ X(e, u, W(k, 0));
274
+ })().compute(S).setName("fire.project"), _ = A(() => {
275
+ const u = N(H), n = F(u), a = p(e, n, 0).xyz, w = n.sub(a.div(this.#s).mul(this.#n)), c = h.sample(w).level(s(0)), P = c.r.mul(ht(s(1).sub(this.#ct.mul(this.#n)), s(0))).toVar(), T = c.g.mul(ht(s(1).sub(this.#ut.mul(this.#n)), s(0))).toVar(), b = o(r.x, r.y, r.z), L = Ot(w.mul(b)).add(0.5).div(b), k = h.sample(L).level(s(0)).b.add(this.#n).toVar();
276
+ T.assign(T.clamp(0, 12)), rt(P.lessThanEqual(0.01), () => {
277
+ k.assign(0);
278
+ }), X(l, u, W(P, T, k, 1));
279
+ })().compute(S).setName("fire.advectDye"), tt = A(() => {
280
+ const u = M.element(H), a = this.#nt.mul(W(u, 1)).xyz.sub(this.#f).div(this.#s).add(0.5);
281
+ rt(
282
+ a.x.greaterThanEqual(0).and(a.x.lessThanEqual(1)).and(a.y.greaterThanEqual(0)).and(a.y.lessThanEqual(1)).and(a.z.greaterThanEqual(0)).and(a.z.lessThanEqual(1)),
283
+ () => {
284
+ const w = St(a.mul(o(r.x, r.y, r.z))), c = at(u.mul(9).add(o(0, this.#h.negate().mul(2.5), this.#h.mul(0.7)))).mul(0.5).add(0.5), P = this.#c.greaterThan(0).select(s(1), s(0)), T = this.#X.mul(this.#dt), b = P.add(T), L = this.#V.mul(s(1 / 120)).mul(c.mul(0.85).add(0.15)).mul(b);
285
+ rt(L.greaterThan(0), () => {
286
+ const k = this.#c.mul(s(0.008333333333333333)).mul(c.mul(0.85).add(0.15)).mul(b), D = h.sample(a).level(s(0)), R = D.r.add(L), G = D.g.add(k).clamp(0, 12), O = I(D.b, s(0), L.div(ht(R, s(1e-3))));
287
+ X(l, w, W(R, G, O, 1));
288
+ });
289
+ }
290
+ );
291
+ })().compute(this.#B).setName("fire.emit");
292
+ this.#q = Y, this.#G = Z, this.#W = $, this.#j = K(v, C, "fire.jacobiAB"), this.#O = K(C, v, "fire.jacobiBA"), this.#U = q, this.#Z = _, this.#_ = tt;
293
+ }
294
+ #Ht() {
295
+ const e = this.#e(this.#g), t = this.#e(this.#y), h = new ft();
296
+ h.steps = this.#t.raymarchSteps, h.transparent = !0, h.blending = At, h.depthWrite = !1, h.offsetNode = Ut(Zt(_t).add(s(Ht).mul(0.618033988749895)));
297
+ const l = A(([f]) => {
298
+ const m = o(0).toVar();
299
+ return m.assign(I(o(0, 0, 0), this.#$, V(s(0.05), s(0.35), f))), m.assign(I(m, this.#Q, V(s(0.35), s(0.65), f))), m.assign(I(m, this.#J, V(s(0.65), s(1), f))), m;
300
+ }), g = A(([f, m]) => {
301
+ const M = m.mul(m), r = s(1).add(M).sub(s(2).mul(m).mul(f));
302
+ return s(1).sub(M).div(r.pow(1.5)).mul(0.079577);
303
+ }), v = ({ positionRay: f }) => {
304
+ const m = f.sub(this.#f).div(this.#s).add(0.5).toVar(), M = p(t, m, 0).xyz.div(this.#s).mul(0.15), r = m.add(M).clamp(0, 1).toVar(), S = e.sample(r).level(s(0)), x = S.r.toVar(), z = S.b, E = S.g, N = oe(f.mul(5.5).add(o(0, z.mul(0.8).negate(), 0)));
305
+ x.mulAssign(N.mul(0.35).add(0.85));
306
+ const F = j(r, o(1).sub(r));
307
+ return x.mulAssign(V(s(0), s(0.06), j(F.x, j(F.y, F.z)))), { density: x, temperature: E };
308
+ };
309
+ h.scatteringNode = A(({ positionRay: f }) => {
310
+ const { density: m } = v({ positionRay: f }), M = this.#A.sub(f).normalize(), r = s(0).toVar(), S = 0.35;
311
+ for (let _ = 0; _ < 2; _++) {
312
+ const tt = (_ + 0.5) * S, n = f.add(M.mul(tt)).sub(this.#f).div(this.#s).add(0.5), a = j(n, o(1).sub(n)), w = V(s(0), s(0.06), j(a.x, j(a.y, a.z)));
313
+ r.addAssign(e.sample(n).level(s(0)).r.mul(w));
314
+ }
315
+ const x = r.mul(S).mul(this.#K), z = x.negate().exp(), E = x.mul(0.25).negate().exp().mul(0.5), N = I(z, z.add(E), this.#bt), F = s(1).sub(x.mul(2).negate().exp()), Z = I(N, N.mul(F), this.#wt).add(this.#yt).clamp(0, 1), K = zt.sub(f).normalize().dot(M).clamp(-1, 1), q = g(K, this.#ft);
316
+ return this.#vt.mul(m).mul(Z).mul(q.mul(12.56637)).mul(this.#gt);
317
+ }), h.scatteringEmissiveNode = A(({ positionRay: f }) => {
318
+ const { density: m, temperature: M } = v({ positionRay: f }), r = s(6).sub(this.#pt), S = l(M.clamp(0, 1)).mul(M.pow(r)).mul(this.#C), x = pt(S, this.#D), z = f.sub(this.#A).length(), E = s(400).div(z.pow(2));
319
+ return x.mul(m.add(0.15)).mul(E);
320
+ });
321
+ const C = A(() => {
322
+ const f = yt, m = yt.sub(zt).normalize(), M = this.#t.raymarchSteps, r = this.#s.length().div(M).toVar(), S = m.toVar(), x = s(0).toVar(), z = s(1).toVar();
323
+ return Xt(M, () => {
324
+ const E = f.add(S.mul(x)), { density: N } = v({ positionRay: E }), Y = N.mul(this.#K).mul(0.01).negate().mul(r).exp();
325
+ z.mulAssign(Y), x.addAssign(r);
326
+ }), z.greaterThanEqual(0.99).discard(), W(o(0), z.oneMinus().mul(5));
327
+ });
328
+ this.mesh = new wt(new nt(this.#t.size.x, this.#t.size.y, this.#t.size.z), h), this.mesh.name = "FireEffect.volume", this.mesh.frustumCulled = !1, this.mesh.receiveShadow = !0, this.mesh.layers.disableAll(), this.mesh.layers.enable(this.#t.volumeLayer), this.viewer.scene.add(this.mesh);
329
+ const y = new ft();
330
+ y.steps = h.steps, y.offsetNode = h.offsetNode, y.castShadowNode = C(), y.shadowSide = kt, y.colorWrite = !1, y.depthWrite = !1, y.blending = Vt, y.blendEquation = bt, y.blendSrc = Ct, y.blendDst = xt, y.blendEquationAlpha = bt, y.blendSrcAlpha = Dt, y.blendDstAlpha = xt, this.shadowMesh = new wt(new nt(this.#t.size.x, this.#t.size.y, this.#t.size.z), y), this.shadowMesh.name = "FireEffect.shadow", this.shadowMesh.position.copy(this.mesh.position), this.shadowMesh.castShadow = !0, this.viewer.scene.add(this.shadowMesh);
331
+ }
332
+ #Mt() {
333
+ this.#Pt(), this.#i = Yt(this.viewer.scene, this.viewer.camera), this.#i.name = "FireEffect Volumetric Pass", this.#i.setLayers(this.#N), this.#i.setResolutionScale(this.#t.renderResolution);
334
+ }
335
+ #Et = () => {
336
+ this.#o && (this.#i?.dispose(), this.#Mt(), this.viewer.renderPipeline.needsUpdateOutputNode = !0, this.viewer.render());
337
+ };
338
+ #Xt() {
339
+ return ((e, t) => {
340
+ if (this.#Nt(), !this.#i)
341
+ return t;
342
+ let h = this.#i;
343
+ if (this.#t.denoise) {
344
+ const y = ee(this.#i, this.#t.denoiseStrength, 1);
345
+ this.#F.push(y), h = y;
346
+ }
347
+ const l = h.rgb, g = gt(l, this.#I), v = W(g, h.a).mul(0.5);
348
+ let C = t.max(v).add(v);
349
+ if (this.#t.bloom) {
350
+ const y = te(
351
+ C,
352
+ this.#t.bloomStrength,
353
+ this.#t.bloomRadius,
354
+ this.#t.bloomThreshold
355
+ );
356
+ this.#F.push(y), C = C.add(y);
357
+ }
358
+ return C;
359
+ });
360
+ }
361
+ #Nt() {
362
+ for (const e of this.#F)
363
+ e.dispose();
364
+ this.#F = [];
365
+ }
366
+ #Ft() {
367
+ !this.#t.keyLight || this.keyLight || (this.keyLight = new It(16777215, 1e3), this.keyLight.name = "FireEffect.keyLight", this.keyLight.angle = Math.PI / 5, this.keyLight.penumbra = 1, this.keyLight.decay = 2, this.keyLight.distance = 0, this.keyLight.castShadow = !0, this.keyLight.shadow.intensity = 0.98, this.keyLight.shadow.mapSize.width = 1024, this.keyLight.shadow.mapSize.height = 1024, this.keyLight.shadow.camera.near = 1, this.keyLight.shadow.camera.far = 20 * (Math.max(this.#t.size.x, this.#t.size.y, this.#t.size.z) / 8), this.keyLight.shadow.bias = -1e-3, this.keyLight.shadow.focus = 1, this.keyLight.layers.enable(this.#t.volumeLayer), this.viewer.scene.add(this.keyLight), this.viewer.scene.add(this.keyLight.target));
368
+ }
369
+ #At() {
370
+ if (!this.#t.pointLight || this.pointLight)
371
+ return;
372
+ const e = A(([l]) => {
373
+ const g = o(0).toVar();
374
+ return g.assign(I(o(0, 0, 0), this.#$, V(s(0.05), s(0.35), l))), g.assign(I(g, this.#Q, V(s(0.35), s(0.65), l))), g.assign(I(g, this.#J, V(s(0.65), s(1), l))), g;
375
+ }), t = A(({ material: l }) => {
376
+ const g = l && l.isVolumeNodeMaterial;
377
+ return s(g ? 1 : 0);
378
+ })(), h = A(() => {
379
+ const l = yt, g = this.#w, v = o(0, this.#xt, 0), y = l.sub(g).dot(v).div(v.dot(v)).clamp(0, 1), f = g.add(this.#Lt).add(v.mul(y)), m = l.sub(f).length(), M = s(1.2), r = s(1).div(m.pow(2).add(M.pow(2))), x = l.sub(g).length().pow(2).max(0.01).reciprocal(), z = t.equal(1).select(r.div(x), s(1)), E = t.equal(1).select(this.#Dt, this.#It), N = this.#c.div(8.34).mul(0.5).add(0.2).add(this.#zt).clamp(0, 1), F = e(N), Y = pt(gt(F, this.#I), this.#D), Z = l.xz.sub(g.xz), $ = Kt(Z.y, Z.x), K = Z.length(), q = this.#Wt, _ = at(o(Jt($).mul(s(1.5).mul(q)), Qt($).mul(s(1.5).mul(q)), this.#h.mul(0.6))).mul(0.5).add(0.5), tt = V(s(0), this.#Ot, K), u = I(s(1), _, tt), n = o(l.x.mul(s(0.6).mul(q)), this.#h.mul(1.2), l.z.mul(s(0.6).mul(q))), a = at(n).mul(0.5).add(0.5), w = o(l.x.mul(s(1.5).mul(q)), this.#h.mul(2.5), l.z.mul(s(1.5).mul(q))), c = at(w).mul(0.5).add(0.5), T = a.mul(0.65).add(c.mul(0.35)).mul(u.mul(0.5).add(0.5)), b = m.div(this.#jt).clamp(0, 1), L = I(T, s(1), b), D = s(1).sub(m.div(this.#Gt)).clamp(0, 1).mul(L).clamp(0, 1), R = e(D), G = pt(gt(R, this.#I), this.#D), O = t.equal(1).select(Y, G), et = this.#c.div(8.34).max(0).pow(4), it = this.#V.div(11.02).max(0), J = V(s(0), s(3), this.#h), st = O.mul(et).mul(it).mul(this.#C).mul(E).mul(this.#St).mul(J), lt = m.div(this.#qt).clamp(0, 1), ut = I(this.#Rt, this.#Bt, V(s(0), s(1), lt)), ct = t.equal(1).select(ut, s(1));
380
+ return st.mul(z).mul(ct);
381
+ })();
382
+ this.pointLight = new Rt(16777215, this.#t.pointLightIntensity, this.#t.pointLightDistance, 2), this.pointLight.name = "FireEffect.pointLight", this.pointLight.colorNode = h, this.pointLight.layers.enable(this.#t.volumeLayer), this.viewer.scene.add(this.pointLight);
383
+ }
384
+ #kt = ({ delta: e }) => {
385
+ if (!this.#o)
386
+ return;
387
+ const t = this.viewer.renderer;
388
+ if (this.#E || (t.compute(this.#e(this.#q)), this.#E = !0), this.#Yt(e), this.#Vt(this.#v), this.#t.simulate && this.#t.simSpeed > 0) {
389
+ const h = 0.008333333333333333 * this.#t.simSpeed;
390
+ for (this.#l += Math.min(e, 1 / 30) * this.#t.simSpeed, this.#l = Math.min(this.#l, h * 8), this.#n.value = h, this.#k.value = this.#t.turbulence / Math.sqrt(this.#t.simSpeed), this.#ct.value = this.#t.smokeLifespan >= 100 ? 0 : 1 / this.#t.smokeLifespan, this.#ut.value = 1 / this.#t.fireLifespan; this.#l >= h; ) {
391
+ this.#v += h, this.#Vt(this.#v), t.compute(this.#e(this.#G)), t.compute(this.#e(this.#W));
392
+ for (let l = 0; l < this.#t.pressureIterations; l++)
393
+ t.compute(this.#e(l % 2 === 0 ? this.#j : this.#O));
394
+ t.compute(this.#e(this.#U)), t.compute(this.#e(this.#Z)), t.compute(this.#e(this.#_)), this.#Kt(), this.#l -= h;
395
+ }
396
+ }
397
+ if (this.pointLight) {
398
+ const h = this.#c.value / 8.34, l = this.#V.value / 11.02, g = this.#C.value / 5.63, v = Math.sqrt(Math.max(0.01, h * l * g)), C = ae(Math.min(Math.max(this.#v / 3, 0), 1));
399
+ this.pointLight.position.copy(this.#w.value), this.pointLight.distance = Math.max(0.01, this.#t.pointLightDistance * Math.max(0.2, v) * C), this.pointLight.intensity = this.#t.pointLightIntensity;
400
+ }
401
+ };
402
+ #Yt(e) {
403
+ const t = this.emitter;
404
+ t.updateMatrixWorld(), this.#nt.value.copy(t.matrixWorld), t.getWorldPosition(this.#d), this.#R.set(0, 0, 0), e > 0 && this.#R.subVectors(this.#d, this.#m).multiplyScalar(1 / e), this.#X.value = e > 0 ? this.#d.distanceTo(this.#m) / e : 0, this.#ht.value.copy(this.#R), this.#w.value.copy(this.#d), this.#m.copy(this.#d);
405
+ }
406
+ #Vt(e) {
407
+ this.#h.value = e % 1e3;
408
+ const t = this.#u.noise(0, e * 2.5, 0);
409
+ this.#xt.value = 3.5 + t * 0.8;
410
+ const h = this.#u.noise(e * 3.5, 0, 0) * 0.4, l = this.#u.noise(0, 0, e * 3.5) * 0.4;
411
+ this.#Lt.value.set(h, 0, l);
412
+ const g = this.#u.noise(0, e * 0.8, 0), v = this.#u.noise(0, e * 15, 0);
413
+ this.#St.value = g * 0.12 + v * 0.06 + 0.82, this.#zt.value = this.#u.noise(e * 5, e * 5, 0) * 0.08;
414
+ }
415
+ #Kt() {
416
+ const e = this.#e(this.#g), t = this.#e(this.#M), h = e.value;
417
+ e.value = t.value, t.value = h;
418
+ }
419
+ #st() {
420
+ this.mesh && (this.viewer.scene.remove(this.mesh), this.mesh.geometry.dispose(), this.mesh.material.dispose(), this.mesh = null), this.shadowMesh && (this.viewer.scene.remove(this.shadowMesh), this.shadowMesh.geometry.dispose(), this.shadowMesh.material.dispose(), this.shadowMesh = null), this.keyLight && (this.viewer.scene.remove(this.keyLight.target), this.viewer.scene.remove(this.keyLight), this.keyLight.dispose(), this.keyLight = null), this.pointLight && (this.viewer.scene.remove(this.pointLight), this.pointLight.dispose(), this.pointLight = null), this.#i?.dispose(), this.#i = null, this.#y?.dispose(), this.#x?.dispose(), this.#L?.dispose(), this.#S?.dispose(), this.#z?.dispose(), this.#T?.dispose(), this.#P?.dispose(), this.#r?.dispose(), this.#y = null, this.#x = null, this.#L = null, this.#S = null, this.#z = null, this.#T = null, this.#P = null, this.#r = null, this.#g = null, this.#M = null, this.#q = null, this.#G = null, this.#W = null, this.#j = null, this.#O = null, this.#U = null, this.#Z = null, this.#_ = null, this.#Nt();
421
+ }
422
+ #e(e) {
423
+ if (e === null)
424
+ throw new Error("FireEffect: resource is not initialized.");
425
+ return e;
426
+ }
427
+ }
428
+ function ae(d) {
429
+ return d * d * (3 - 2 * d);
430
+ }
431
+ export {
432
+ ge as FireEffect
433
+ };