babylon.quarks 0.17.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.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/dist/babylon.quarks.cjs +2 -0
  3. package/dist/babylon.quarks.cjs.map +1 -0
  4. package/dist/babylon.quarks.esm.js +2 -0
  5. package/dist/babylon.quarks.esm.js.map +1 -0
  6. package/dist/types/BatchedParticleRenderer.d.ts +2 -0
  7. package/dist/types/BatchedRenderer.d.ts +40 -0
  8. package/dist/types/MeshSurfaceEmitter.d.ts +19 -0
  9. package/dist/types/ParticleEmitter.d.ts +16 -0
  10. package/dist/types/ParticleSystem.d.ts +226 -0
  11. package/dist/types/QuarksLoader.d.ts +28 -0
  12. package/dist/types/QuarksPrefab.d.ts +48 -0
  13. package/dist/types/QuarksUtil.d.ts +14 -0
  14. package/dist/types/SpriteBatch.d.ts +32 -0
  15. package/dist/types/TrailBatch.d.ts +27 -0
  16. package/dist/types/VFXBatch.d.ts +51 -0
  17. package/dist/types/index.d.ts +19 -0
  18. package/dist/types/materials/ParticleMaterials.d.ts +12 -0
  19. package/dist/types/materials/index.d.ts +1 -0
  20. package/dist/types/shaders/chunks/index.d.ts +1 -0
  21. package/dist/types/shaders/chunks/register-shader-chunks.d.ts +3 -0
  22. package/dist/types/shaders/chunks/soft_fragment.glsl.d.ts +2 -0
  23. package/dist/types/shaders/chunks/soft_pars_fragment.glsl.d.ts +2 -0
  24. package/dist/types/shaders/chunks/soft_pars_vertex.glsl.d.ts +2 -0
  25. package/dist/types/shaders/chunks/soft_vertex.glsl.d.ts +2 -0
  26. package/dist/types/shaders/chunks/tile_fragment.glsl.d.ts +2 -0
  27. package/dist/types/shaders/chunks/tile_pars_fragment.glsl.d.ts +2 -0
  28. package/dist/types/shaders/chunks/tile_pars_vertex.glsl.d.ts +2 -0
  29. package/dist/types/shaders/chunks/tile_vertex.glsl.d.ts +2 -0
  30. package/dist/types/shaders/index.d.ts +9 -0
  31. package/dist/types/shaders/local_particle_physics_vert.glsl.d.ts +2 -0
  32. package/dist/types/shaders/local_particle_vert.glsl.d.ts +2 -0
  33. package/dist/types/shaders/particle_frag.glsl.d.ts +2 -0
  34. package/dist/types/shaders/particle_physics_frag.glsl.d.ts +2 -0
  35. package/dist/types/shaders/particle_vert.glsl.d.ts +2 -0
  36. package/dist/types/shaders/stretched_bb_particle_vert.glsl.d.ts +2 -0
  37. package/dist/types/shaders/trail_frag.glsl.d.ts +2 -0
  38. package/dist/types/shaders/trail_vert.glsl.d.ts +2 -0
  39. package/package.json +58 -0
  40. package/src/BatchedParticleRenderer.ts +3 -0
  41. package/src/BatchedRenderer.ts +135 -0
  42. package/src/MeshSurfaceEmitter.ts +137 -0
  43. package/src/ParticleEmitter.ts +86 -0
  44. package/src/ParticleSystem.ts +1162 -0
  45. package/src/QuarksLoader.ts +503 -0
  46. package/src/QuarksPrefab.ts +307 -0
  47. package/src/QuarksUtil.ts +66 -0
  48. package/src/SpriteBatch.ts +391 -0
  49. package/src/TrailBatch.ts +345 -0
  50. package/src/VFXBatch.ts +102 -0
  51. package/src/index.ts +54 -0
  52. package/src/materials/ParticleMaterials.ts +23 -0
  53. package/src/materials/index.ts +1 -0
  54. package/src/shaders/chunks/index.ts +1 -0
  55. package/src/shaders/chunks/register-shader-chunks.ts +32 -0
  56. package/src/shaders/chunks/soft_fragment.glsl.ts +13 -0
  57. package/src/shaders/chunks/soft_pars_fragment.glsl.ts +20 -0
  58. package/src/shaders/chunks/soft_pars_vertex.glsl.ts +6 -0
  59. package/src/shaders/chunks/soft_vertex.glsl.ts +6 -0
  60. package/src/shaders/chunks/tile_fragment.glsl.ts +9 -0
  61. package/src/shaders/chunks/tile_pars_fragment.glsl.ts +9 -0
  62. package/src/shaders/chunks/tile_pars_vertex.glsl.ts +28 -0
  63. package/src/shaders/chunks/tile_vertex.glsl.ts +18 -0
  64. package/src/shaders/index.ts +9 -0
  65. package/src/shaders/local_particle_physics_vert.glsl.ts +66 -0
  66. package/src/shaders/local_particle_vert.glsl.ts +50 -0
  67. package/src/shaders/particle_frag.glsl.ts +61 -0
  68. package/src/shaders/particle_physics_frag.glsl.ts +67 -0
  69. package/src/shaders/particle_vert.glsl.ts +85 -0
  70. package/src/shaders/stretched_bb_particle_vert.glsl.ts +74 -0
  71. package/src/shaders/trail_frag.glsl.ts +21 -0
  72. package/src/shaders/trail_vert.glsl.ts +58 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 soullnik
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("quarks.core"),t=require("@babylonjs/core/Buffers/buffer"),i=require("@babylonjs/core/Meshes/transformNode"),r=require("@babylonjs/core/Meshes/mesh"),s=require("@babylonjs/core/Materials/shaderMaterial"),n=require("@babylonjs/core/Meshes/mesh.vertexData"),a=require("@babylonjs/core/Materials/effect"),o=require("@babylonjs/core/Engines/constants"),l=require("@babylonjs/core/Maths/math.vector"),h=require("@babylonjs/core/Culling/boundingInfo"),d=require("@babylonjs/core/Materials/Textures/texture"),c=require("@babylonjs/core/Materials/standardMaterial"),u=require("@babylonjs/core/Materials/PBR/pbrMaterial");class f{get mesh(){return this._mesh}set mesh(i){if(this._mesh=i,!i)return;const r=i.getVerticesData(t.VertexBuffer.PositionKind),s=i.getIndices();if(!r||!s)return;this._positions=new Float32Array(r),this._indices=new Int32Array(s),this._triangleIndexToArea.length=0;let n=0;const a=s.length/3;this._triangleIndexToArea.push(0);const o=new e.Vector3,l=new e.Vector3,h=new e.Vector3;for(let t=0;t<a;t++){const i=s[3*t],a=s[3*t+1],d=s[3*t+2];o.set(r[3*i],r[3*i+1],r[3*i+2]),l.set(r[3*a],r[3*a+1],r[3*a+2]),h.set(r[3*d],r[3*d+1],r[3*d+2]),l.sub(o),h.sub(o);const c=new e.Vector3;c.crossVectors(l,h),n+=.5*c.length(),this._triangleIndexToArea.push(n)}}constructor(e,t){this.type="mesh_surface",this._triangleIndexToArea=[],this._meshReferenceId=t,e&&(this.mesh=e)}initialize(e){if(!this._positions||!this._indices)return e.position.set(0,0,0),void e.velocity.set(0,0,1).multiplyScalar(e.startSpeed);const t=this._triangleIndexToArea.length-1;let i=0,r=t;const s=Math.random()*this._triangleIndexToArea[t];for(;i+1<r;){const e=Math.floor((i+r)/2);s<this._triangleIndexToArea[e]?r=e:i=e}let n=Math.random(),a=Math.random();n+a>1&&(n=1-n,a=1-a);const o=this._indices[3*i],l=this._indices[3*i+1],h=this._indices[3*i+2],d=this._positions[3*o],c=this._positions[3*o+1],u=this._positions[3*o+2],f=this._positions[3*l]-d,p=this._positions[3*l+1]-c,m=this._positions[3*l+2]-u,v=this._positions[3*h]-d,g=this._positions[3*h+1]-c,y=this._positions[3*h+2]-u;e.position.set(d+f*n+v*a,c+p*n+g*a,u+m*n+y*a);const x=p*y-m*g,S=m*v-f*y,T=f*g-p*v,B=Math.sqrt(x*x+S*S+T*T)||1;e.velocity.set(x/B,S/B,T/B).multiplyScalar(e.startSpeed)}toJSON(){return{type:"mesh_surface",mesh:this._mesh?this._mesh.uniqueId?.toString():this._meshReferenceId??""}}static fromJSON(e){return new f(void 0,e?.mesh)}clone(){return new f(this._mesh,this._meshReferenceId)}update(e,t){}}const p={id:"babylon.quarks",initialize:()=>{},emitterShapes:[{type:"mesh_surface",params:[["mesh",["mesh"]]],constructor:f,loadJSON:e=>f.fromJSON(e)}],behaviors:[]};const m={};let v=!1;function g(){v||(m.tile_pars_vertex="\n#ifdef UV_TILE\n attribute float uvTile;\n uniform vec2 tileCount;\n\n mat3 makeTileTransform(float tileIndex) {\n float col = mod(tileIndex, tileCount.x);\n float row = (tileCount.y - floor(tileIndex / tileCount.x) - 1.0);\n return mat3(\n 1.0 / tileCount.x, 0.0, 0.0,\n 0.0, 1.0 / tileCount.y, 0.0,\n col / tileCount.x, row / tileCount.y, 1.0\n );\n }\n#else\n mat3 makeTileTransform(float tileIndex) {\n return mat3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);\n }\n#endif\n\n#if defined(USE_UV)\n varying vec2 vUv;\n #ifdef TILE_BLEND\n varying vec2 vUvNext;\n varying float vUvBlend;\n #endif\n#endif\n",m.tile_vertex="\n#ifdef UV_TILE\n mat3 tileTransform = makeTileTransform(floor(uvTile));\n #ifdef TILE_BLEND\n mat3 nextTileTransform = makeTileTransform(ceil(uvTile));\n vUvBlend = fract(uvTile);\n #endif\n#else\n mat3 tileTransform = makeTileTransform(0.0);\n#endif\n\n#if defined(USE_UV)\n vUv = (tileTransform * vec3(uv, 1.0)).xy;\n #if defined(TILE_BLEND) && defined(UV_TILE)\n vUvNext = (nextTileTransform * vec3(uv, 1.0)).xy;\n #endif\n#endif\n",m.tile_pars_fragment="\n#if defined(USE_UV)\n varying vec2 vUv;\n #ifdef TILE_BLEND\n varying vec2 vUvNext;\n varying float vUvBlend;\n #endif\n#endif\n",m.tile_fragment="\n#ifdef USE_MAP\n vec4 texelColor = texture2D(map, vUv);\n #ifdef TILE_BLEND\n texelColor = mix(texelColor, texture2D(map, vUvNext), vUvBlend);\n #endif\n diffuseColor *= texelColor;\n#endif\n",m.soft_pars_vertex="\n#ifdef SOFT_PARTICLES\n varying vec4 projPosition;\n varying float linearDepth;\n#endif\n",m.soft_vertex="\n#ifdef SOFT_PARTICLES\n projPosition = gl_Position;\n linearDepth = -mvPosition.z;\n#endif\n",m.soft_pars_fragment="\n#ifdef SOFT_PARTICLES\n uniform sampler2D depthTexture;\n uniform vec4 projParams;\n uniform vec2 softParams;\n\n varying vec4 projPosition;\n varying float linearDepth;\n\n #define SOFT_NEAR_FADE softParams.x\n #define SOFT_INV_FADE_DISTANCE softParams.y\n\n #define zNear projParams.x\n #define zFar projParams.y\n\n float linearize_depth(float d) {\n return (zFar * zNear) / (zFar - d * (zFar - zNear));\n }\n#endif\n",m.soft_fragment="\n#ifdef SOFT_PARTICLES\n\n vec2 p2 = projPosition.xy / projPosition.w;\n p2 = 0.5 * p2 + 0.5;\n\n float readDepth = texture2D(depthTexture, p2.xy).r;\n float viewDepth = linearize_depth(readDepth);\n float softParticlesFade = saturate(SOFT_INV_FADE_DISTANCE * ((viewDepth - SOFT_NEAR_FADE) - linearDepth));\n\n gl_FragColor *= softParticlesFade;\n#endif\n",v=!0)}var y,x="\n// Per-vertex attributes\nattribute vec3 position;\nattribute vec2 uv;\n\n// Per-instance attributes\nattribute vec3 offset;\nattribute vec4 color;\nattribute vec3 size;\nattribute float rotation;\nattribute float uvTile;\n\n// Uniforms\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 projection;\nuniform mat4 worldViewProjection;\n\n#ifdef UV_TILE\nuniform float tileCountX;\nuniform float tileCountY;\n#endif\n\n// Varyings\nvarying vec2 vUV;\nvarying vec4 vColor;\n#ifdef TILE_BLEND\nvarying vec2 vUV2;\nvarying float vTileBlend;\n#endif\n#ifdef SOFT_PARTICLES\nvarying vec4 projPosition;\nvarying float linearDepth;\n#endif\n\nvoid main() {\n float c = cos(rotation);\n float s = sin(rotation);\n\n vec2 alignedPosition = position.xy * size.xy;\n vec2 rotatedPosition;\n rotatedPosition.x = c * alignedPosition.x - s * alignedPosition.y;\n rotatedPosition.y = s * alignedPosition.x + c * alignedPosition.y;\n\n#ifdef HORIZONTAL\n vec4 mvPosition = world * vec4(offset, 1.0);\n mvPosition.x += rotatedPosition.x;\n mvPosition.z -= rotatedPosition.y;\n mvPosition = view * mvPosition;\n#elif defined(VERTICAL)\n vec4 mvPosition = world * vec4(offset, 1.0);\n mvPosition.y += rotatedPosition.y;\n mvPosition = view * mvPosition;\n mvPosition.x += rotatedPosition.x;\n#else\n vec4 mvPosition = view * world * vec4(offset, 1.0);\n mvPosition.xy += rotatedPosition;\n#endif\n\n gl_Position = projection * mvPosition;\n#ifdef SOFT_PARTICLES\n projPosition = gl_Position;\n linearDepth = -mvPosition.z;\n#endif\n\n #ifdef UV_TILE\n vec2 tc = vec2(tileCountX, tileCountY);\n float baseTile = floor(uvTile);\n float tileU = mod(baseTile, tc.x) / tc.x;\n float tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV = uv / tc + vec2(tileU, tileV);\n #ifdef TILE_BLEND\n float nextTile = ceil(uvTile);\n float nextU = mod(nextTile, tc.x) / tc.x;\n float nextV = 1.0 - floor(nextTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV2 = uv / tc + vec2(nextU, nextV);\n vTileBlend = fract(uvTile);\n #endif\n #else\n vUV = uv;\n #endif\n\n vColor = color;\n}\n",S="\nvarying vec2 vUV;\nvarying vec4 vColor;\n\n#ifdef TILE_BLEND\nvarying vec2 vUV2;\nvarying float vTileBlend;\n#endif\n\n#ifdef USE_MAP\nuniform sampler2D map;\n#endif\n\n#ifdef SOFT_PARTICLES\nuniform sampler2D depthTexture;\nuniform vec2 softParams;\nuniform vec4 projParams;\nvarying vec4 projPosition;\nvarying float linearDepth;\n#endif\n\n#ifdef USE_ALPHATEST\nuniform float alphaTest;\n#endif\n\nvoid main() {\n vec4 baseColor = vColor;\n\n#ifdef USE_MAP\n vec4 texColor = texture2D(map, vUV);\n #ifdef TILE_BLEND\n vec4 texColor2 = texture2D(map, vUV2);\n texColor = mix(texColor, texColor2, vTileBlend);\n #endif\n baseColor *= texColor;\n#endif\n\n#ifdef USE_COLOR_AS_ALPHA\n baseColor.a *= (baseColor.r + baseColor.g + baseColor.b) / 3.0;\n#endif\n\n#ifdef USE_ALPHATEST\n if (baseColor.a < alphaTest) discard;\n#else\n if (baseColor.a < 0.01) discard;\n#endif\n\n gl_FragColor = baseColor;\n\n#ifdef SOFT_PARTICLES\n vec2 p2 = projPosition.xy / projPosition.w;\n p2 = 0.5 * p2 + 0.5;\n float readDepth = texture2D(depthTexture, p2.xy).r;\n float zNear = projParams.x;\n float zFar = projParams.y;\n float viewDepth = (zFar * zNear) / (zFar - readDepth * (zFar - zNear));\n float fade = clamp(softParams.y * ((viewDepth - softParams.x) - linearDepth), 0.0, 1.0);\n gl_FragColor *= fade;\n#endif\n}\n",T="\nattribute vec3 position;\nattribute vec2 uv;\nattribute vec3 normal;\nattribute vec3 offset;\nattribute vec4 color;\nattribute vec3 size;\nattribute vec4 rotation;\nattribute float uvTile;\n\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 projection;\n\n#ifdef UV_TILE\nuniform float tileCountX;\nuniform float tileCountY;\n#endif\n\nvarying vec2 vUV;\nvarying vec4 vColor;\nvarying vec3 vNormal;\nvarying vec3 vWorldPos;\n\n#ifdef SOFT_PARTICLES\nvarying vec4 projPosition;\nvarying float linearDepth;\n#endif\n\nvec3 applyQuaternion(vec3 v, vec4 q) {\n vec3 qVec = q.xyz;\n float qW = q.w;\n vec3 t = 2.0 * cross(qVec, v);\n return v + qW * t + cross(qVec, t);\n}\n\nvoid main() {\n vec3 scaledPosition = position * size;\n vec3 rotatedPosition = applyQuaternion(scaledPosition, rotation);\n vec3 rotatedNormal = normalize(applyQuaternion(normal, rotation));\n vec3 localPos = rotatedPosition + offset;\n\n vec4 worldPos = world * vec4(localPos, 1.0);\n vec4 viewPos = view * worldPos;\n gl_Position = projection * viewPos;\n\n vWorldPos = worldPos.xyz;\n vNormal = normalize((world * vec4(rotatedNormal, 0.0)).xyz);\n\n#ifdef SOFT_PARTICLES\n projPosition = gl_Position;\n linearDepth = -viewPos.z;\n#endif\n\n#ifdef UV_TILE\n vec2 tc = vec2(tileCountX, tileCountY);\n float tileU = mod(uvTile, tc.x) / tc.x;\n float tileV = 1.0 - floor(uvTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV = uv / tc + vec2(tileU, tileV);\n#else\n vUV = uv;\n#endif\n\n vColor = color;\n}\n",B="\nvarying vec2 vUV;\nvarying vec4 vColor;\nvarying vec3 vNormal;\n\nuniform vec3 lightDirection;\nuniform vec3 lightColor;\nuniform vec3 ambientColor;\n\n#ifdef TILE_BLEND\nvarying vec2 vUV2;\nvarying float vTileBlend;\n#endif\n\n#ifdef USE_MAP\nuniform sampler2D map;\n#endif\n\n#ifdef SOFT_PARTICLES\nuniform sampler2D depthTexture;\nuniform vec2 softParams;\nuniform vec4 projParams;\nvarying vec4 projPosition;\nvarying float linearDepth;\n#endif\n\n#ifdef USE_ALPHATEST\nuniform float alphaTest;\n#endif\n\nvoid main() {\n vec4 baseColor = vColor;\n\n#ifdef USE_MAP\n vec4 texColor = texture2D(map, vUV);\n #ifdef TILE_BLEND\n vec4 texColor2 = texture2D(map, vUV2);\n texColor = mix(texColor, texColor2, vTileBlend);\n #endif\n baseColor *= texColor;\n#endif\n\n#ifdef USE_ALPHATEST\n if (baseColor.a < alphaTest) discard;\n#else\n if (baseColor.a < 0.01) discard;\n#endif\n\n vec3 N = normalize(vNormal);\n vec3 L = normalize(-lightDirection);\n float NdotL = max(dot(N, L), 0.0);\n vec3 litColor = ambientColor + lightColor * NdotL;\n\n gl_FragColor = vec4(baseColor.rgb * litColor, baseColor.a);\n\n#ifdef SOFT_PARTICLES\n vec2 p2 = projPosition.xy / projPosition.w;\n p2 = 0.5 * p2 + 0.5;\n float readDepth = texture2D(depthTexture, p2.xy).r;\n float zNear = projParams.x;\n float zFar = projParams.y;\n float viewDepth = (zFar * zNear) / (zFar - readDepth * (zFar - zNear));\n float fade = clamp(softParams.y * ((viewDepth - softParams.x) - linearDepth), 0.0, 1.0);\n gl_FragColor *= fade;\n#endif\n}\n",M="\n// Per-vertex attributes\nattribute vec3 position;\nattribute vec2 uv;\n\n// Per-instance attributes\nattribute vec3 offset;\nattribute vec4 color;\nattribute vec3 size;\nattribute float rotation;\nattribute float uvTile;\nattribute vec4 velocity;\n\n// Uniforms\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 projection;\nuniform float speedFactor;\n\n#ifdef UV_TILE\nuniform float tileCountX;\nuniform float tileCountY;\n#endif\n\n// Varyings\nvarying vec2 vUV;\nvarying vec4 vColor;\n#ifdef TILE_BLEND\nvarying vec2 vUV2;\nvarying float vTileBlend;\n#endif\n#ifdef SOFT_PARTICLES\nvarying vec4 projPosition;\nvarying float linearDepth;\n#endif\n\nvoid main() {\n float lengthFactor = velocity.w;\n float avgSize = (size.x + size.y) * 0.5;\n vec4 mvPosition = view * world * vec4(offset, 1.0);\n vec3 viewVelocity = mat3(view * world) * velocity.xyz;\n float vlength = length(viewVelocity);\n if (vlength < 0.0001) {\n vlength = 0.0001;\n viewVelocity = vec3(0.0, 0.0, 1.0);\n }\n mvPosition.xyz += position.y * normalize(cross(mvPosition.xyz, viewVelocity)) * avgSize;\n mvPosition.xyz -= (position.x + 0.5) * viewVelocity * (1.0 + lengthFactor / vlength) * avgSize;\n gl_Position = projection * mvPosition;\n#ifdef SOFT_PARTICLES\n projPosition = gl_Position;\n linearDepth = -mvPosition.z;\n#endif\n\n #ifdef UV_TILE\n vec2 tc = vec2(tileCountX, tileCountY);\n float baseTile = floor(uvTile);\n float tileU = mod(baseTile, tc.x) / tc.x;\n float tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV = uv / tc + vec2(tileU, tileV);\n #ifdef TILE_BLEND\n float nextTile = ceil(uvTile);\n float nextU = mod(nextTile, tc.x) / tc.x;\n float nextV = 1.0 - floor(nextTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV2 = uv / tc + vec2(nextU, nextV);\n vTileBlend = fract(uvTile);\n #endif\n #else\n vUV = uv;\n #endif\n\n vColor = color;\n}\n",b="\nattribute vec3 position;\nattribute vec3 previous;\nattribute vec3 next;\nattribute float side;\nattribute float width;\nattribute vec2 uv;\nattribute vec4 color;\n\nuniform mat4 view;\nuniform mat4 projection;\nuniform float lineWidth;\nuniform vec2 resolution;\nuniform float sizeAttenuation;\n\nvarying vec2 vUV;\nvarying vec4 vColor;\n\nvec2 fix(vec4 i, float aspect) {\n vec2 res = i.xy / i.w;\n res.x *= aspect;\n return res;\n}\n\nvoid main() {\n float aspect = resolution.x / resolution.y;\n vec4 finalPosition = projection * view * vec4(position, 1.0);\n vec4 prevPos = projection * view * vec4(previous, 1.0);\n vec4 nextPos = projection * view * vec4(next, 1.0);\n\n vec2 currentP = fix(finalPosition, aspect);\n vec2 prevP = fix(prevPos, aspect);\n vec2 nextP = fix(nextPos, aspect);\n\n float w = lineWidth * width;\n vec2 dir;\n if (distance(nextP, currentP) < 0.0001) {\n dir = normalize(currentP - prevP);\n } else if (distance(prevP, currentP) < 0.0001) {\n dir = normalize(nextP - currentP);\n } else {\n vec2 dir1 = normalize(currentP - prevP);\n vec2 dir2 = normalize(nextP - currentP);\n dir = normalize(dir1 + dir2);\n }\n vec4 normal = vec4(-dir.y, dir.x, 0.0, 1.0);\n normal.xy *= 0.5 * w;\n normal *= projection;\n if (sizeAttenuation == 0.0) {\n normal.xy *= finalPosition.w;\n normal.xy /= (vec4(resolution, 0.0, 1.0) * projection).xy;\n }\n finalPosition.xy += normal.xy * side;\n gl_Position = finalPosition;\n vUV = uv;\n vColor = color;\n}\n",P="\nvarying vec2 vUV;\nvarying vec4 vColor;\n\n#ifdef USE_MAP\nuniform sampler2D map;\n#endif\n\nvoid main() {\n vec4 baseColor = vColor;\n\n#ifdef USE_MAP\n vec4 texColor = texture2D(map, vUV);\n baseColor *= texColor;\n#endif\n\n if (baseColor.a < 0.01) discard;\n\n gl_FragColor = baseColor;\n}\n";exports.RenderMode=void 0,(y=exports.RenderMode||(exports.RenderMode={}))[y.BillBoard=0]="BillBoard",y[y.StretchedBillBoard=1]="StretchedBillBoard",y[y.Mesh=2]="Mesh",y[y.Trail=3]="Trail",y[y.HorizontalBillBoard=4]="HorizontalBillBoard",y[y.VerticalBillBoard=5]="VerticalBillBoard";class w{constructor(e,t){this.scene=t,this.maxParticles=1e3,this.systems=new Set,this.settings={instancingGeometry:e.instancingGeometry,instancingIndices:e.instancingIndices,instancingUVs:e.instancingUVs,instancingNormals:e.instancingNormals,renderMode:e.renderMode,renderOrder:e.renderOrder,uTileCount:e.uTileCount,vTileCount:e.vTileCount,blendTiles:e.blendTiles,softParticles:e.softParticles,softNearFade:e.softNearFade,softFarFade:e.softFarFade,materialBlendMode:e.materialBlendMode,materialTransparent:e.materialTransparent,materialDepthTest:e.materialDepthTest,materialDepthWrite:e.materialDepthWrite,materialAlphaTest:e.materialAlphaTest,texture:e.texture,layerMask:e.layerMask},this.mesh=new r.Mesh("vfxBatch",t),this.mesh.alwaysSelectAsActiveMesh=!0}addSystem(e){this.systems.add(e)}removeSystem(e){this.systems.delete(e)}getVisibleSystems(){return Array.from(this.systems).filter(e=>e.emitter.visible)}applyDepthTexture(e){const t=this.mesh.material;t&&t instanceof s.ShaderMaterial&&t.setTexture("depthTexture",e)}dispose(){this.mesh.dispose()}}class V extends w{constructor(t,i){super(t,i),this.vector_=new e.Vector3,this.vector2_=new e.Vector3,this.vector3_=new e.Vector3,this.quaternion_=new e.Quaternion,this.quaternion2_=new e.Quaternion,this.quaternion3_=new e.Quaternion,this.rotationMat_=new e.Matrix3,this.rotationMat2_=new e.Matrix3,this.maxParticles=1e3,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.mesh.dispose(),this.mesh=new r.Mesh("spriteBatch",this.scene),this.mesh.alwaysSelectAsActiveMesh=!0;const e=new n.VertexData;e.positions=Array.from(this.settings.instancingGeometry),e.indices=Array.from(this.settings.instancingIndices),this.settings.instancingUVs&&(e.uvs=Array.from(this.settings.instancingUVs)),this.settings.instancingNormals&&(e.normals=Array.from(this.settings.instancingNormals)),e.applyToMesh(this.mesh,!1),this.buildExpandableBuffers()}buildExpandableBuffers(){const e=this.scene.getEngine();this.offsetBuffer=new Float32Array(3*this.maxParticles),this.offsetVB=new t.VertexBuffer(e,this.offsetBuffer,"offset",!0,!1,3,!0),this.mesh.setVerticesBuffer(this.offsetVB),this.colorBuffer=new Float32Array(4*this.maxParticles),this.colorVB=new t.VertexBuffer(e,this.colorBuffer,"color",!0,!1,4,!0),this.mesh.setVerticesBuffer(this.colorVB),this.sizeBuffer=new Float32Array(3*this.maxParticles),this.sizeVB=new t.VertexBuffer(e,this.sizeBuffer,"size",!0,!1,3,!0),this.mesh.setVerticesBuffer(this.sizeVB),this.uvTileBuffer=new Float32Array(this.maxParticles),this.uvTileVB=new t.VertexBuffer(e,this.uvTileBuffer,"uvTile",!0,!1,1,!0),this.mesh.setVerticesBuffer(this.uvTileVB),this.settings.renderMode===exports.RenderMode.Mesh?(this.rotationBuffer=new Float32Array(4*this.maxParticles),this.rotationVB=new t.VertexBuffer(e,this.rotationBuffer,"rotation",!0,!1,4,!0)):(this.rotationBuffer=new Float32Array(this.maxParticles),this.rotationVB=new t.VertexBuffer(e,this.rotationBuffer,"rotation",!0,!1,1,!0)),this.mesh.setVerticesBuffer(this.rotationVB),this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&(this.velocityBuffer=new Float32Array(4*this.maxParticles),this.velocityVB=new t.VertexBuffer(e,this.velocityBuffer,"velocity",!0,!1,4,!0),this.mesh.setVerticesBuffer(this.velocityVB)),this.mesh.forcedInstanceCount=0,this.mesh.doNotSyncBoundingInfo=!0}expandBuffers(e){for(;e>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers(),this.rebuildMaterial()}rebuildMaterial(){const e=`quarksParticle_${this.settings.renderMode}_${Date.now()}`;let t,i;const r=[];this.settings.renderMode===exports.RenderMode.Mesh?(t=T,i=B):this.settings.renderMode===exports.RenderMode.StretchedBillBoard?(t=M,i=S):(t=x,i=S),this.settings.texture&&r.push("USE_MAP"),(this.settings.uTileCount>1||this.settings.vTileCount>1)&&r.push("UV_TILE"),this.settings.blendTiles&&r.push("TILE_BLEND"),this.settings.softParticles&&r.push("SOFT_PARTICLES"),this.settings.materialAlphaTest>0&&r.push("USE_ALPHATEST"),this.settings.renderMode===exports.RenderMode.VerticalBillBoard&&r.push("VERTICAL"),this.settings.renderMode===exports.RenderMode.HorizontalBillBoard&&r.push("HORIZONTAL"),a.Effect.ShadersStore[e+"VertexShader"]=t,a.Effect.ShadersStore[e+"FragmentShader"]=i;const n=["position","uv","offset","color","size","rotation","uvTile"];this.settings.renderMode===exports.RenderMode.Mesh&&n.push("normal"),this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&n.push("velocity");const h=["world","view","projection","worldView","worldViewProjection"],d=[];(this.settings.uTileCount>1||this.settings.vTileCount>1)&&(h.push("tileCountX"),h.push("tileCountY")),this.settings.texture&&d.push("map"),this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&h.push("speedFactor"),this.settings.softParticles&&(h.push("softParams"),h.push("projParams"),d.push("depthTexture")),this.settings.materialAlphaTest>0&&h.push("alphaTest"),this.settings.renderMode===exports.RenderMode.Mesh&&(h.push("lightDirection"),h.push("lightColor"),h.push("ambientColor"));const c=new s.ShaderMaterial(e,this.scene,{vertex:e,fragment:e},{attributes:n,uniforms:h,samplers:d,defines:r,needAlphaBlending:this.settings.materialTransparent});this.settings.texture&&c.setTexture("map",this.settings.texture),(this.settings.uTileCount>1||this.settings.vTileCount>1)&&(c.setFloat("tileCountX",this.settings.uTileCount),c.setFloat("tileCountY",this.settings.vTileCount)),this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&c.setFloat("speedFactor",this.settings.softNearFade>0?this.settings.softNearFade:1),this.settings.softParticles&&(c.setVector2("softParams",new l.Vector2(this.settings.softNearFade,1/Math.max(this.settings.softFarFade-this.settings.softNearFade,1e-4))),c.onBindObservable.add(()=>{const e=this.scene.activeCamera;e&&c.setVector4("projParams",new l.Vector4(e.minZ,e.maxZ,0,0))})),this.settings.materialAlphaTest>0&&c.setFloat("alphaTest",this.settings.materialAlphaTest),this.settings.renderMode===exports.RenderMode.Mesh&&(c.setVector3("lightDirection",new l.Vector3(.4,-1,.6)),c.setVector3("lightColor",new l.Vector3(1,1,1)),c.setVector3("ambientColor",new l.Vector3(.35,.35,.35))),c.backFaceCulling=!1,this.settings.materialTransparent?c.alphaMode=this.settings.materialBlendMode:c.alphaMode=o.Constants.ALPHA_DISABLE,c.needDepthPrePass=this.settings.materialDepthWrite,c.forceDepthWrite=this.settings.materialDepthWrite,c.disableDepthWrite=!this.settings.materialDepthWrite,this.mesh.material=c}update(){let e=0,t=0;const i=this.getVisibleSystems();for(const e of i)t+=e.particleNum;t>this.maxParticles&&this.expandBuffers(t);for(const t of i){const i=t.particles,r=t.particleNum,s=this.quaternion2_,n=this.vector2_,a=this.vector3_;t.emitter.matrixWorld.decompose(n,s,a),this.rotationMat_.setFromMatrix4(t.emitter.matrixWorld);for(let n=0;n<r;n++,e++){const r=i[n];if(this.settings.renderMode===exports.RenderMode.Mesh){let i;if(t.worldSpace)i=r.rotation;else{let e;e=r.parentMatrix?this.quaternion3_.setFromRotationMatrix(r.parentMatrix):s,i=this.quaternion_,i.copy(e).multiply(r.rotation)}const n=4*e;this.rotationBuffer[n]=i.x,this.rotationBuffer[n+1]=i.y,this.rotationBuffer[n+2]=i.z,this.rotationBuffer[n+3]=i.w}else this.rotationBuffer[e]=r.rotation;let o;t.worldSpace?o=r.position:(o=this.vector_,r.parentMatrix?o.copy(r.position).applyMatrix4(r.parentMatrix):o.copy(r.position).applyMatrix4(t.emitter.matrixWorld));const l=3*e;this.offsetBuffer[l]=o.x,this.offsetBuffer[l+1]=o.y,this.offsetBuffer[l+2]=o.z;const h=4*e;this.colorBuffer[h]=r.color.x,this.colorBuffer[h+1]=r.color.y,this.colorBuffer[h+2]=r.color.z,this.colorBuffer[h+3]=r.color.w;const d=3*e;if(t.worldSpace||r.parentMatrix?(this.sizeBuffer[d]=r.size.x,this.sizeBuffer[d+1]=r.size.y,this.sizeBuffer[d+2]=r.size.z):(this.sizeBuffer[d]=r.size.x*Math.abs(a.x),this.sizeBuffer[d+1]=r.size.y*Math.abs(a.y),this.sizeBuffer[d+2]=r.size.z*Math.abs(a.z)),this.uvTileBuffer[e]=r.uvTile,this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&this.velocityBuffer){let i=t.rendererEmitterSettings.speedFactor;0===i&&(i=.001);const s=t.rendererEmitterSettings.lengthFactor;let n;t.worldSpace?n=r.velocity:(n=this.vector_,r.parentMatrix?(this.rotationMat2_.setFromMatrix4(r.parentMatrix),n.copy(r.velocity).applyMatrix3(this.rotationMat2_)):n.copy(r.velocity).applyMatrix3(this.rotationMat_));const a=4*e;this.velocityBuffer[a]=n.x*i,this.velocityBuffer[a+1]=n.y*i,this.velocityBuffer[a+2]=n.z*i,this.velocityBuffer[a+3]=s}}}if(this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&this.mesh.material instanceof s.ShaderMaterial&&i.length>0){const e=i[0].rendererEmitterSettings.speedFactor??1;this.mesh.material.setFloat("speedFactor",0===e?.001:e)}this.mesh.forcedInstanceCount=e,this.mesh.setEnabled(e>0),e>0&&(this.offsetVB.update(this.offsetBuffer),this.sizeVB.update(this.sizeBuffer),this.colorVB.update(this.colorBuffer),this.uvTileVB.update(this.uvTileBuffer),this.rotationVB.update(this.rotationBuffer),this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&this.velocityVB&&this.velocityBuffer&&this.velocityVB.update(this.velocityBuffer))}dispose(){this.mesh.material&&this.mesh.material.dispose(),super.dispose()}}class C extends w{constructor(t,i){super(t,i),this.vector_=new e.Vector3,this.vector2_=new e.Vector3,this.vector3_=new e.Vector3,this.quaternion_=new e.Quaternion,this.maxParticles=1e4,this.setupBuffers(),this.rebuildMaterial(),this.mesh.setEnabled(!1)}setupBuffers(){this.mesh.dispose(),this.mesh=new r.Mesh("trailBatch",this.scene),this.mesh.alwaysSelectAsActiveMesh=!0,this.positionBuffer=new Float32Array(6*this.maxParticles),this.previousBuffer=new Float32Array(6*this.maxParticles),this.nextBuffer=new Float32Array(6*this.maxParticles),this.uvBuffer=new Float32Array(4*this.maxParticles),this.sideBuffer=new Float32Array(2*this.maxParticles),this.widthBuffer=new Float32Array(2*this.maxParticles),this.colorBuffer=new Float32Array(8*this.maxParticles),this.indexBuffer=new Uint32Array(6*this.maxParticles),this.positionBuffer[0]=0,this.positionBuffer[1]=0,this.positionBuffer[2]=0,this.positionBuffer[3]=1,this.positionBuffer[4]=0,this.positionBuffer[5]=0,this.positionBuffer[6]=0,this.positionBuffer[7]=1,this.positionBuffer[8]=0,this.positionBuffer[9]=1,this.positionBuffer[10]=1,this.positionBuffer[11]=0,this.indexBuffer[0]=0,this.indexBuffer[1]=1,this.indexBuffer[2]=2,this.indexBuffer[3]=1,this.indexBuffer[4]=3,this.indexBuffer[5]=2,this.mesh.setVerticesData(t.VertexBuffer.PositionKind,this.positionBuffer,!0),this.mesh.setVerticesData(t.VertexBuffer.UVKind,this.uvBuffer,!0),this.mesh.setVerticesData(t.VertexBuffer.ColorKind,this.colorBuffer,!0,4),this.mesh.setIndices(Array.from(this.indexBuffer.subarray(0,6)),null,!0);const e=this.scene.getEngine();this.previousVB=new t.VertexBuffer(e,this.previousBuffer,"previous",!0,!1,3,!1),this.nextVB=new t.VertexBuffer(e,this.nextBuffer,"next",!0,!1,3,!1),this.sideVB=new t.VertexBuffer(e,this.sideBuffer,"side",!0,!1,1,!1),this.widthVB=new t.VertexBuffer(e,this.widthBuffer,"width",!0,!1,1,!1),this.mesh.setVerticesBuffer(this.previousVB),this.mesh.setVerticesBuffer(this.nextVB),this.mesh.setVerticesBuffer(this.sideVB),this.mesh.setVerticesBuffer(this.widthVB),this.mesh.doNotSyncBoundingInfo=!0;const i=new l.Vector3(-1e4,-1e4,-1e4),s=new l.Vector3(1e4,1e4,1e4);if(this.mesh.setBoundingInfo(new h.BoundingInfo(i,s)),this.mesh.subMeshes)for(const e of this.mesh.subMeshes)e._boundingInfo=this.mesh.getBoundingInfo()}expandBuffers(e){for(;e>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers(),this.rebuildMaterial()}rebuildMaterial(){const e=`quarksTrail_${Date.now()}`,t=[];this.settings.texture&&t.push("USE_MAP"),a.Effect.ShadersStore[e+"VertexShader"]=b,a.Effect.ShadersStore[e+"FragmentShader"]=P;const i=[];this.settings.texture&&i.push("map");const r=new s.ShaderMaterial(e,this.scene,{vertex:e,fragment:e},{attributes:["position","previous","next","side","width","uv","color"],uniforms:["world","view","projection","worldViewProjection","lineWidth","resolution","sizeAttenuation"],samplers:i,defines:t,needAlphaBlending:this.settings.materialTransparent});this.settings.texture&&r.setTexture("map",this.settings.texture);const n=this.scene.getEngine();r.setFloat("lineWidth",1),r.setVector2("resolution",new l.Vector2(n.getRenderWidth(),n.getRenderHeight())),r.setFloat("sizeAttenuation",1),r.onBindObservable.add(()=>{const e=this.scene.getEngine();r.setVector2("resolution",new l.Vector2(e.getRenderWidth(),e.getRenderHeight()))}),r.backFaceCulling=!1,this.settings.materialTransparent?r.alphaMode=this.settings.materialBlendMode:r.alphaMode=o.Constants.ALPHA_DISABLE,r.needDepthPrePass=this.settings.materialDepthWrite,r.forceDepthWrite=this.settings.materialDepthWrite,r.disableDepthWrite=!this.settings.materialDepthWrite,this.mesh.material=r}update(){let e=0,i=0,r=0;const s=this.getVisibleSystems();for(const e of s)for(let t=0;t<e.particleNum;t++)r+=2*e.particles[t].previous.length;r>this.maxParticles&&this.expandBuffers(r);for(const t of s){t.emitter.computeWorldMatrix&&t.emitter.computeWorldMatrix(!0);const r=this.quaternion_,s=this.vector2_,n=this.vector3_;t.emitter.matrixWorld.decompose(s,r,n);const a=t.particles,o=t.particleNum,l=this.settings.uTileCount,h=this.settings.vTileCount,d=1/l,c=1/h;for(let r=0;r<o;r++){const s=a[r],o=s.uvTile%h,l=Math.floor(s.uvTile/h+.001),u=s.previous.values();let f,p=u.next(),m=p.value,v=m;p.done||(p=u.next()),f=void 0!==p.value?p.value:v;for(let r=0;r<s.previous.length;r++,e+=2){let a;t.worldSpace?a=v.position:(s.parentMatrix?this.vector_.copy(v.position).applyMatrix4(s.parentMatrix):this.vector_.copy(v.position).applyMatrix4(t.emitter.matrixWorld),a=this.vector_);const g=3*e;let y,x;if(this.positionBuffer[g]=a.x,this.positionBuffer[g+1]=a.y,this.positionBuffer[g+2]=a.z,this.positionBuffer[g+3]=a.x,this.positionBuffer[g+4]=a.y,this.positionBuffer[g+5]=a.z,t.worldSpace?y=m.position:(s.parentMatrix?this.vector_.copy(m.position).applyMatrix4(s.parentMatrix):this.vector_.copy(m.position).applyMatrix4(t.emitter.matrixWorld),y=this.vector_),this.previousBuffer[g]=y.x,this.previousBuffer[g+1]=y.y,this.previousBuffer[g+2]=y.z,this.previousBuffer[g+3]=y.x,this.previousBuffer[g+4]=y.y,this.previousBuffer[g+5]=y.z,t.worldSpace?x=f.position:(s.parentMatrix?this.vector_.copy(f.position).applyMatrix4(s.parentMatrix):this.vector_.copy(f.position).applyMatrix4(t.emitter.matrixWorld),x=this.vector_),this.nextBuffer[g]=x.x,this.nextBuffer[g+1]=x.y,this.nextBuffer[g+2]=x.z,this.nextBuffer[g+3]=x.x,this.nextBuffer[g+4]=x.y,this.nextBuffer[g+5]=x.z,this.sideBuffer[e]=1,this.sideBuffer[e+1]=-1,t.worldSpace||s.parentMatrix)this.widthBuffer[e]=v.size,this.widthBuffer[e+1]=v.size;else{const t=(Math.abs(n.x)+Math.abs(n.y)+Math.abs(n.z))/3;this.widthBuffer[e]=v.size*t,this.widthBuffer[e+1]=v.size*t}const S=2*e;this.uvBuffer[S]=(r/s.previous.length+o)*d,this.uvBuffer[S+1]=(h-l-1)*c,this.uvBuffer[S+2]=(r/s.previous.length+o)*d,this.uvBuffer[S+3]=(h-l)*c;const T=4*e;this.colorBuffer[T]=v.color.x,this.colorBuffer[T+1]=v.color.y,this.colorBuffer[T+2]=v.color.z,this.colorBuffer[T+3]=v.color.w,this.colorBuffer[T+4]=v.color.x,this.colorBuffer[T+5]=v.color.y,this.colorBuffer[T+6]=v.color.z,this.colorBuffer[T+7]=v.color.w,r+1<s.previous.length&&(this.indexBuffer[3*i]=e,this.indexBuffer[3*i+1]=e+1,this.indexBuffer[3*i+2]=e+2,i++,this.indexBuffer[3*i]=e+2,this.indexBuffer[3*i+1]=e+1,this.indexBuffer[3*i+2]=e+3,i++),m=v,v=f,p.done||(p=u.next(),void 0!==p.value&&(f=p.value))}}}if(e>0&&i>0){this.mesh.updateVerticesData(t.VertexBuffer.PositionKind,this.positionBuffer),this.mesh.updateVerticesData(t.VertexBuffer.UVKind,this.uvBuffer),this.mesh.updateIndices(Array.from(this.indexBuffer.subarray(0,3*i))),this.previousVB.update(this.previousBuffer),this.nextVB.update(this.nextBuffer),this.sideVB.update(this.sideBuffer),this.widthVB.update(this.widthBuffer);const r=this.mesh.getVertexBuffer(t.VertexBuffer.ColorKind);if(r&&r.update(this.colorBuffer),this.mesh.setEnabled(!0),this.mesh.subMeshes&&this.mesh.subMeshes.length>0){const t=this.mesh.getBoundingInfo();for(const e of this.mesh.subMeshes)e._boundingInfo=t;this.mesh.subMeshes[0].indexCount=3*i,this.mesh.subMeshes[0].verticesCount=e}}else this.mesh.setEnabled(!1)}dispose(){this.mesh.material&&this.mesh.material.dispose(),super.dispose()}}class A extends i.TransformNode{constructor(e,t){super(e,t),this.batches=[],this.systemToBatchIndex=new Map,this.depthTexture=null}static equals(e,t){return e.materialBlendMode===t.materialBlendMode&&e.materialTransparent===t.materialTransparent&&e.materialDepthTest===t.materialDepthTest&&e.materialDepthWrite===t.materialDepthWrite&&e.materialAlphaTest===t.materialAlphaTest&&e.texture===t.texture&&e.renderMode===t.renderMode&&e.blendTiles===t.blendTiles&&e.softParticles===t.softParticles&&e.softFarFade===t.softFarFade&&e.softNearFade===t.softNearFade&&e.uTileCount===t.uTileCount&&e.vTileCount===t.vTileCount&&e.instancingGeometry===t.instancingGeometry&&e.renderOrder===t.renderOrder&&e.layerMask===t.layerMask}addSystem(e){e._renderer=this;const t=e.getRendererSettings();for(let i=0;i<this.batches.length;i++)if(A.equals(this.batches[i].settings,t))return this.batches[i].addSystem(e),void this.systemToBatchIndex.set(e,i);let i;const r=this.getScene();switch(t.renderMode){case exports.RenderMode.Trail:i=new C(t,r);break;case exports.RenderMode.Mesh:case exports.RenderMode.BillBoard:case exports.RenderMode.VerticalBillBoard:case exports.RenderMode.HorizontalBillBoard:case exports.RenderMode.StretchedBillBoard:i=new V(t,r);break;default:throw new Error(`Unsupported render mode: ${t.renderMode}`)}i.mesh.parent=this,this.depthTexture&&i.applyDepthTexture(this.depthTexture),i.addSystem(e),this.batches.push(i),this.systemToBatchIndex.set(e,this.batches.length-1)}deleteSystem(e){const t=this.systemToBatchIndex.get(e);void 0!==t&&(this.batches[t].removeSystem(e),this.systemToBatchIndex.delete(e))}updateSystem(e){this.deleteSystem(e),this.addSystem(e)}setDepthTexture(e){this.depthTexture=e;for(const t of this.batches)t.applyDepthTexture(e)}update(e){this.systemToBatchIndex.forEach((t,i)=>{i.update(e)});for(let e=0;e<this.batches.length;e++)this.batches[e].update()}dispose(){for(const e of this.batches)e.dispose();this.batches=[],this.systemToBatchIndex.clear(),super.dispose()}}const _=A;class F extends i.TransformNode{get matrixWorld(){const e=this.getWorldMatrix(),t=this._matrixWorld.elements;return t[0]=e.m[0],t[1]=e.m[1],t[2]=e.m[2],t[3]=e.m[3],t[4]=e.m[4],t[5]=e.m[5],t[6]=e.m[6],t[7]=e.m[7],t[8]=e.m[8],t[9]=e.m[9],t[10]=e.m[10],t[11]=e.m[11],t[12]=e.m[12],t[13]=e.m[13],t[14]=e.m[14],t[15]=e.m[15],this._matrixWorld}get visible(){return this.isEnabled()}set visible(e){this.setEnabled(e)}get uuid(){return this.uniqueId.toString()}constructor(t,i){super("particleEmitter",i||void 0),this._matrixWorld=new e.Matrix4,this.system=t}dispose(){super.dispose()}extractFromCache(e){const t=[];for(const i in e){const r=e[i];r&&"object"==typeof r&&delete r.metadata,t.push(r)}return t}clone(e){const t=this.system.clone().emitter;return t.name=e??this.name,t.position.copyFrom(this.position),t.rotation.copyFrom(this.rotation),t.scaling.copyFrom(this.scaling),this.rotationQuaternion&&(t.rotationQuaternion=this.rotationQuaternion.clone()),t.setEnabled(this.isEnabled()),t}toJSON(e,t={}){return{uuid:this._quarksUUID??this.uniqueId.toString(),type:"ParticleEmitter",name:this.name,position:[this.position.x,this.position.y,this.position.z],rotation:[this.rotation.x,this.rotation.y,this.rotation.z],quaternion:this.rotationQuaternion?[this.rotationQuaternion.x,this.rotationQuaternion.y,this.rotationQuaternion.z,this.rotationQuaternion.w]:void 0,scale:[this.scaling.x,this.scaling.y,this.scaling.z],visible:this.isEnabled(),ps:this.system.toJSON(e,t)}}}const D=new e.Vector3(0,0,1),E=new e.Quaternion,U=new e.Vector3,I=new e.Vector3,O=new Float32Array([-.5,-.5,0,.5,-.5,0,.5,.5,0,-.5,.5,0]),N=new Float32Array([0,0,1,0,1,1,0,1]),R=new Uint32Array([0,1,2,0,2,3]);class z{set time(e){this.emissionState.time=e}get time(){return this.emissionState.time}get layers(){return this.layerMaskProxy}get texture(){return this.rendererSettings.texture}set texture(e){this.rendererSettings.texture=e,this.neededToUpdateRender=!0}get material(){return this.materialRef}set material(e){this.materialRef=e,this.applyMaterialSettings(e)}get uTileCount(){return this.rendererSettings.uTileCount}set uTileCount(e){this.rendererSettings.uTileCount=e,this.neededToUpdateRender=!0}get vTileCount(){return this.rendererSettings.vTileCount}set vTileCount(e){this.rendererSettings.vTileCount=e,this.neededToUpdateRender=!0}get blendTiles(){return this.rendererSettings.blendTiles}set blendTiles(e){this.rendererSettings.blendTiles=e,this.neededToUpdateRender=!0}get softParticles(){return this.rendererSettings.softParticles}set softParticles(e){this.rendererSettings.softParticles=e,this.neededToUpdateRender=!0}get softNearFade(){return this.rendererSettings.softNearFade}set softNearFade(e){this.rendererSettings.softNearFade=e,this.neededToUpdateRender=!0}get softFarFade(){return this.rendererSettings.softFarFade}set softFarFade(e){this.rendererSettings.softFarFade=e,this.neededToUpdateRender=!0}get instancingGeometry(){return this.rendererSettings.instancingGeometry}set instancingGeometry(e){this.restart(),this.particles.length=0,this.rendererSettings.instancingGeometry=e,this.neededToUpdateRender=!0}get blending(){return this.rendererSettings.materialBlendMode}set blending(e){this.rendererSettings.materialBlendMode=e,this.neededToUpdateRender=!0}get renderMode(){return this.rendererSettings.renderMode}set renderMode(t){if(this.rendererSettings.renderMode!==t){let i=!1;switch(this.rendererSettings.renderMode===exports.RenderMode.Trail&&(i=!0),this.rendererSettings.renderMode===exports.RenderMode.Mesh&&(this.startRotation=new e.ConstantValue(0)),t){case exports.RenderMode.Trail:this.rendererEmitterSettings={startLength:new e.ConstantValue(30),followLocalOrigin:!1},i=!0;break;case exports.RenderMode.Mesh:this.rendererEmitterSettings={},this.startRotation=new e.AxisAngleGenerator(new e.Vector3(0,1,0),new e.ConstantValue(0));break;case exports.RenderMode.StretchedBillBoard:this.rendererEmitterSettings={speedFactor:0,lengthFactor:2};break;case exports.RenderMode.BillBoard:case exports.RenderMode.VerticalBillBoard:case exports.RenderMode.HorizontalBillBoard:this.rendererEmitterSettings={}}this.rendererSettings.renderMode=t,i&&(this.restart(),this.particles.length=0),this.neededToUpdateRender=!0}}get renderOrder(){return this.rendererSettings.renderOrder}set renderOrder(e){this.rendererSettings.renderOrder=e,this.neededToUpdateRender=!0}constructor(t){if(this.temp=new e.Vector3,this.normalMatrix=new e.Matrix3,this.memory=[],this.listeners={},this.materialRef=null,this.firstTimeUpdate=!0,this.layerMaskProxy={mask:t.layerMask??268435455},Object.defineProperty(this.layerMaskProxy,"mask",{enumerable:!0,get:()=>this.rendererSettings.layerMask,set:e=>{this.rendererSettings.layerMask=e,this.neededToUpdateRender=!0}}),this.autoDestroy=t.autoDestroy??!1,this.duration=t.duration??1,this.looping=t.looping??!0,this.prewarm=t.prewarm??!1,this.startLife=t.startLife??new e.ConstantValue(5),this.startSpeed=t.startSpeed??new e.ConstantValue(0),this.startRotation=t.startRotation??new e.ConstantValue(0),this.startSize=t.startSize??new e.ConstantValue(1),this.startColor=t.startColor??new e.ConstantColor(new e.Vector4(1,1,1,1)),this.emissionOverTime=t.emissionOverTime??new e.ConstantValue(10),this.emissionOverDistance=t.emissionOverDistance??new e.ConstantValue(0),this.emissionBursts=t.emissionBursts??[],this.onlyUsedByOther=t.onlyUsedByOther??!1,this.emitterShape=t.shape??new e.SphereEmitter,this.behaviors=t.behaviors??[],this.worldSpace=t.worldSpace??!1,this.rendererEmitterSettings=t.rendererEmitterSettings??{},t.renderMode===exports.RenderMode.StretchedBillBoard){const e=this.rendererEmitterSettings;void 0!==t.speedFactor&&(e.speedFactor=t.speedFactor),e.speedFactor=e.speedFactor??0,e.lengthFactor=e.lengthFactor??0}this.rendererSettings={instancingGeometry:t.instancingGeometry??O,instancingIndices:t.instancingIndices??R,instancingUVs:t.instancingUVs??N,instancingNormals:t.instancingNormals,renderMode:t.renderMode??exports.RenderMode.BillBoard,renderOrder:t.renderOrder??0,uTileCount:t.uTileCount??1,vTileCount:t.vTileCount??1,blendTiles:t.blendTiles??!1,softParticles:t.softParticles??!1,softNearFade:t.softNearFade??0,softFarFade:t.softFarFade??0,materialBlendMode:t.blendMode??o.Constants.ALPHA_ADD,materialTransparent:t.transparent??!0,materialDepthTest:t.depthTest??!0,materialDepthWrite:t.depthWrite??!1,materialAlphaTest:t.alphaTest??0,texture:t.texture??null,layerMask:t.layerMask??268435455},this.rendererSettings.renderMode!==exports.RenderMode.Mesh||this.rendererSettings.instancingNormals||(this.rendererSettings.instancingNormals=z.createFallbackNormals(this.rendererSettings.instancingGeometry)),this.materialRef=t.material??null,this.applyMaterialSettings(this.materialRef,{blendMode:t.blendMode,transparent:t.transparent,depthTest:t.depthTest,depthWrite:t.depthWrite,alphaTest:t.alphaTest,texture:t.texture,layerMask:t.layerMask}),this.neededToUpdateRender=!0,this.particles=[],this.startTileIndex=t.startTileIndex||new e.ConstantValue(0),this.emitter=new F(this,t.scene),this.paused=!1,this.particleNum=0,this.emissionState={isBursting:!1,burstParticleIndex:0,burstParticleCount:0,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,travelDistance:0},this.emissionBursts.forEach(e=>e.count.startGen(this.memory)),this.emissionOverDistance.startGen(this.memory),this.emitEnded=!1,this.markForDestroy=!1,this.prewarmed=!1}applyMaterialSettings(e,t={}){if(!this.rendererSettings)return;const i=void 0!==t.texture?t.texture:e?.albedoTexture??e?.diffuseTexture??e?.emissiveTexture??e?.opacityTexture??e?.baseTexture??this.rendererSettings.texture??null,r=t.blendMode??("number"==typeof e?.alphaMode?e.alphaMode:this.rendererSettings.materialBlendMode),s=t.transparent??("function"==typeof e?.needAlphaBlending?e.needAlphaBlending():"number"==typeof e?.alpha?e.alpha<1:this.rendererSettings.materialTransparent),n=t.depthTest??("boolean"==typeof e?.disableDepthTest?!e.disableDepthTest:this.rendererSettings.materialDepthTest),a=t.depthWrite??("boolean"==typeof e?.disableDepthWrite?!e.disableDepthWrite:"boolean"==typeof e?.forceDepthWrite?e.forceDepthWrite:this.rendererSettings.materialDepthWrite),o=t.alphaTest??("number"==typeof e?.alphaCutOff?e.alphaCutOff:"number"==typeof e?.alphaCutOffValue?e.alphaCutOffValue:this.rendererSettings.materialAlphaTest);this.rendererSettings.texture=i,this.rendererSettings.materialBlendMode=r,this.rendererSettings.materialTransparent=s,this.rendererSettings.materialDepthTest=n,this.rendererSettings.materialDepthWrite=a,this.rendererSettings.materialAlphaTest=o,void 0!==t.layerMask&&(this.rendererSettings.layerMask=t.layerMask),this.neededToUpdateRender=!0}pause(){this.paused=!0}play(){this.paused=!1}stop(){this.restart(),this.pause()}spawn(t,i,r){E.setFromRotationMatrix(r);const s=U,n=I;r.decompose(s,E,n);for(let s=0;s<t;s++){for(i.burstParticleIndex=s,this.particleNum++;this.particles.length<this.particleNum;)this.rendererSettings.renderMode===exports.RenderMode.Trail?this.particles.push(new e.TrailParticle):this.particles.push(new e.SpriteParticle);const t=this.particles[this.particleNum-1];if(t.reset(),t.speedModifier=1,this.startColor.startGen(t.memory),this.startColor.genColor(t.memory,t.startColor,this.emissionState.time),t.color.copy(t.startColor),this.startSpeed.startGen(t.memory),t.startSpeed=this.startSpeed.genValue(t.memory,i.time/this.duration),this.startLife.startGen(t.memory),t.life=this.startLife.genValue(t.memory,i.time/this.duration),t.age=0,this.startSize.startGen(t.memory),"vec3function"===this.startSize.type)this.startSize.genValue(t.memory,t.startSize,i.time/this.duration);else{const e=this.startSize.genValue(t.memory,i.time/this.duration);t.startSize.set(e,e,e)}if(this.startTileIndex.startGen(t.memory),t.uvTile=this.startTileIndex.genValue(t.memory),t.size.copy(t.startSize),this.rendererSettings.renderMode===exports.RenderMode.Mesh||this.rendererSettings.renderMode===exports.RenderMode.BillBoard||this.rendererSettings.renderMode===exports.RenderMode.VerticalBillBoard||this.rendererSettings.renderMode===exports.RenderMode.HorizontalBillBoard||this.rendererSettings.renderMode===exports.RenderMode.StretchedBillBoard){const r=t;this.startRotation.startGen(t.memory),this.rendererSettings.renderMode===exports.RenderMode.Mesh?(r.rotation instanceof e.Quaternion||(r.rotation=new e.Quaternion),"rotation"===this.startRotation.type?this.startRotation.genValue(t.memory,r.rotation,1,i.time/this.duration):r.rotation.setFromAxisAngle(D,this.startRotation.genValue(r.memory,i.time/this.duration))):"rotation"===this.startRotation.type?r.rotation=0:r.rotation=this.startRotation.genValue(r.memory,i.time/this.duration)}else if(this.rendererSettings.renderMode===exports.RenderMode.Trail){const e=t;this.rendererEmitterSettings.startLength.startGen(e.memory),e.length=this.rendererEmitterSettings.startLength.genValue(e.memory,i.time/this.duration)}if(this.emitterShape.initialize(t,i),this.rendererSettings.renderMode===exports.RenderMode.Trail&&this.rendererEmitterSettings.followLocalOrigin){const i=t;i.localPosition=(new e.Vector3).copy(i.position)}this.worldSpace?(t.position.applyMatrix4(r),t.startSize.multiply(n).abs(),t.size.copy(t.startSize),t.velocity.multiply(n).applyMatrix3(this.normalMatrix),t.rotation&&t.rotation instanceof e.Quaternion&&t.rotation.multiplyQuaternions(E,t.rotation)):this.onlyUsedByOther&&(t.parentMatrix=r);for(let e=0;e<this.behaviors.length;e++)this.behaviors[e].initialize(t,this)}}endEmit(){this.emitEnded=!0,this.autoDestroy&&(this.markForDestroy=!0),this.fire({type:"emitEnd",particleSystem:this})}dispose(){this._renderer&&this._renderer.deleteSystem(this),this.emitter.dispose(),this.fire({type:"destroy",particleSystem:this})}restart(){this.memory.length=0,this.paused=!1,this.particleNum=0,this.emissionState.isBursting=!1,this.emissionState.burstIndex=0,this.emissionState.burstWaveIndex=0,this.emissionState.time=0,this.emissionState.waitEmiting=0,this.behaviors.forEach(e=>e.reset()),this.emitEnded=!1,this.markForDestroy=!1,this.prewarmed=!1,this.emissionBursts.forEach(e=>e.count.startGen(this.memory)),this.emissionOverDistance.startGen(this.memory)}update(t){if(!this.paused)if(this.firstTimeUpdate&&(this.firstTimeUpdate=!1,this.emitter.computeWorldMatrix(!0)),this.emitEnded&&0===this.particleNum)this.markForDestroy&&this.dispose();else{if(this.looping&&this.prewarm&&!this.prewarmed){this.prewarmed=!0;for(let e=0;e<60*this.duration;e++)this.update(1/60)}t>.1&&(t=.1),this.neededToUpdateRender&&(this._renderer&&this._renderer.updateSystem(this),this.neededToUpdateRender=!1),this.onlyUsedByOther||this.emit(t,this.emissionState,this.emitter.matrixWorld),this.emitterShape.update(this,t);for(let e=0;e<this.behaviors.length;e++){this.behaviors[e].frameUpdate(t);for(let i=0;i<this.particleNum;i++)this.particles[i].died||this.behaviors[e].update(this.particles[i],t)}for(let e=0;e<this.particleNum;e++)this.rendererEmitterSettings.followLocalOrigin&&this.particles[e].localPosition?(this.particles[e].position.copy(this.particles[e].localPosition),this.particles[e].parentMatrix?this.particles[e].position.applyMatrix4(this.particles[e].parentMatrix):this.particles[e].position.applyMatrix4(this.emitter.matrixWorld)):this.particles[e].position.addScaledVector(this.particles[e].velocity,t*this.particles[e].speedModifier),this.particles[e].age+=t;if(this.rendererSettings.renderMode===exports.RenderMode.Trail)for(let e=0;e<this.particleNum;e++)this.particles[e].update();for(let t=0;t<this.particleNum;t++){const i=this.particles[t];!i.died||i instanceof e.TrailParticle&&0!==i.previous.length||(this.particles[t]=this.particles[this.particleNum-1],this.particles[this.particleNum-1]=i,this.particleNum--,t--,this.fire({type:"particleDied",particleSystem:this,particle:i}))}}}emit(t,i,r){i.time>this.duration&&(this.looping?(i.time-=this.duration,i.burstIndex=0,this.behaviors.forEach(e=>e.reset())):this.emitEnded||this.onlyUsedByOther||this.endEmit()),this.normalMatrix.getNormalMatrix(r);const s=Math.ceil(i.waitEmiting);for(this.spawn(s,i,r),i.waitEmiting-=s;i.burstIndex<this.emissionBursts.length&&this.emissionBursts[i.burstIndex].time<=i.time;){if(Math.random()<this.emissionBursts[i.burstIndex].probability){const e=this.emissionBursts[i.burstIndex].count.genValue(this.memory,this.time);i.isBursting=!0,i.burstParticleCount=e,this.spawn(e,i,r),i.isBursting=!1}i.burstIndex++}if(!this.emitEnded&&(i.waitEmiting+=t*this.emissionOverTime.genValue(this.memory,i.time/this.duration),null!=i.previousWorldPos)){this.temp.set(r.elements[12],r.elements[13],r.elements[14]),i.travelDistance+=i.previousWorldPos.distanceTo(this.temp);const e=this.emissionOverDistance.genValue(this.memory,i.time/this.duration);if(i.travelDistance*e>0){const t=Math.floor(i.travelDistance*e);i.travelDistance-=t/e,i.waitEmiting+=t}}void 0===i.previousWorldPos&&(i.previousWorldPos=new e.Vector3),i.previousWorldPos.set(r.elements[12],r.elements[13],r.elements[14]),i.time+=t}toJSON(e,t={}){const i=void 0===e||"string"==typeof e?{geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}}:e,r=this.ensureGeometryMeta(i),s=this.ensureMaterialMeta(i),n=this.toRendererSettingsJSON();return{version:"3.0",autoDestroy:this.autoDestroy,looping:this.looping,prewarm:this.prewarm,duration:this.duration,shape:this.emitterShape.toJSON(),startLife:this.startLife.toJSON(),startSpeed:this.startSpeed.toJSON(),startRotation:this.startRotation.toJSON(),startSize:this.startSize.toJSON(),startColor:this.startColor.toJSON(),emissionOverTime:this.emissionOverTime.toJSON(),emissionOverDistance:this.emissionOverDistance.toJSON(),emissionBursts:this.emissionBursts.map(e=>({time:e.time,count:e.count.toJSON(),probability:e.probability,interval:e.interval,cycle:e.cycle})),onlyUsedByOther:this.onlyUsedByOther,instancingGeometry:r,renderMode:this.renderMode,renderOrder:this.renderOrder,rendererEmitterSettings:n,material:s,layers:this.rendererSettings.layerMask,startTileIndex:this.startTileIndex.toJSON(),uTileCount:this.rendererSettings.uTileCount,vTileCount:this.rendererSettings.vTileCount,blendTiles:this.rendererSettings.blendTiles,softParticles:this.rendererSettings.softParticles,softFarFade:this.rendererSettings.softFarFade,softNearFade:this.rendererSettings.softNearFade,blending:this.rendererSettings.materialBlendMode,transparent:this.rendererSettings.materialTransparent,depthTest:this.rendererSettings.materialDepthTest,depthWrite:this.rendererSettings.materialDepthWrite,alphaTest:this.rendererSettings.materialAlphaTest,behaviors:this.behaviors.map(e=>e.toJSON()),worldSpace:this.worldSpace}}static fromJSON(t,i,r={},s){const n=e.EmitterFromJSON(t.shape,i);let a;if(t.renderMode===exports.RenderMode.Trail){const i=t.rendererEmitterSettings;a={startLength:void 0!==i?.startLength?e.ValueGeneratorFromJSON(i.startLength):new e.ConstantValue(30),followLocalOrigin:i?.followLocalOrigin??!1}}else t.renderMode===exports.RenderMode.StretchedBillBoard?(a={...t.rendererEmitterSettings??{}},void 0!==t.speedFactor&&(a.speedFactor=t.speedFactor)):a={};const l=t.material?i.materials?.[t.material]:void 0,h=l?.texture??t.texture,d="string"==typeof h?i.textures?.[h]??null:h??null,c="string"==typeof t.instancingGeometry?i.geometries?.[t.instancingGeometry]:t.instancingGeometry,u=z.resolveGeometryData(c),f=new z({scene:s,autoDestroy:t.autoDestroy,looping:t.looping,prewarm:t.prewarm,duration:t.duration,shape:n,startLife:e.ValueGeneratorFromJSON(t.startLife),startSpeed:e.ValueGeneratorFromJSON(t.startSpeed),startRotation:e.GeneratorFromJSON(t.startRotation),startSize:e.GeneratorFromJSON(t.startSize),startColor:e.ColorGeneratorFromJSON(t.startColor),emissionOverTime:e.ValueGeneratorFromJSON(t.emissionOverTime),emissionOverDistance:e.ValueGeneratorFromJSON(t.emissionOverDistance),emissionBursts:t.emissionBursts?.map(t=>({time:t.time,count:"number"==typeof t.count?new e.ConstantValue(t.count):e.ValueGeneratorFromJSON(t.count),probability:t.probability??1,interval:t.interval??.1,cycle:t.cycle??t.cycleCount??1})),onlyUsedByOther:t.onlyUsedByOther,instancingGeometry:u.positions,instancingIndices:u.indices,instancingUVs:u.uvs,instancingNormals:u.normals,renderMode:t.renderMode,rendererEmitterSettings:a,renderOrder:t.renderOrder,texture:d,material:l?.sourceMaterial,blendMode:l?.alphaMode??t.blending??o.Constants.ALPHA_ADD,transparent:l?.transparent??t.transparent??!0,depthTest:l?.depthTest??t.depthTest??!0,depthWrite:l?.depthWrite??t.depthWrite??!1,alphaTest:l?.alphaTest??t.alphaTest??0,startTileIndex:"number"==typeof t.startTileIndex?new e.ConstantValue(t.startTileIndex):e.ValueGeneratorFromJSON(t.startTileIndex),uTileCount:t.uTileCount,vTileCount:t.vTileCount,blendTiles:t.blendTiles,softParticles:t.softParticles,softFarFade:t.softFarFade,softNearFade:t.softNearFade,behaviors:[],worldSpace:t.worldSpace,layerMask:t.layers});return f.behaviors=(t.behaviors??[]).map(t=>{const i=e.BehaviorFromJSON(t,f);return i&&"EmitSubParticleSystem"===i.type&&(r[t.subParticleSystem]=i),i}).filter(e=>null!==e),f}static nextSerializationId(e){return z.serializationCounter+=1,`${e}_${z.serializationCounter}`}static createFallbackNormals(e){const t=new Float32Array(e.length);for(let e=0;e<t.length;e+=3)t[e]=0,t[e+1]=0,t[e+2]=1;return t}toRendererSettingsJSON(){return this.renderMode===exports.RenderMode.Trail?{startLength:this.rendererEmitterSettings.startLength.toJSON(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin}:this.renderMode===exports.RenderMode.StretchedBillBoard?{speedFactor:this.rendererEmitterSettings.speedFactor,lengthFactor:this.rendererEmitterSettings.lengthFactor}:{}}ensureGeometryMeta(e){const t=z.nextSerializationId("quarks_geometry");return e.geometries[t]={uuid:t,type:"QuarksGeometry",positions:Array.from(this.rendererSettings.instancingGeometry),indices:Array.from(this.rendererSettings.instancingIndices),uvs:this.rendererSettings.instancingUVs?Array.from(this.rendererSettings.instancingUVs):void 0,normals:this.rendererSettings.instancingNormals?Array.from(this.rendererSettings.instancingNormals):void 0},t}ensureMaterialMeta(e){const t=this.rendererSettings.texture;let i;t&&(i=z.nextSerializationId("quarks_texture"),e.textures[i]=t);const r=z.nextSerializationId("quarks_material");return e.materials[r]={uuid:r,type:"QuarksMaterial",transparent:this.rendererSettings.materialTransparent,alphaMode:this.rendererSettings.materialBlendMode,depthTest:this.rendererSettings.materialDepthTest,depthWrite:this.rendererSettings.materialDepthWrite,alphaTest:this.rendererSettings.materialAlphaTest,texture:i,sourceMaterial:this.materialRef??void 0},r}static resolveGeometryData(e){if(e?.positions&&e?.indices)return{positions:e.positions instanceof Float32Array?e.positions:new Float32Array(e.positions),indices:e.indices instanceof Uint16Array||e.indices instanceof Uint32Array?e.indices:new Uint32Array(e.indices),uvs:e.uvs?e.uvs instanceof Float32Array?e.uvs:new Float32Array(e.uvs):void 0,normals:e.normals?e.normals instanceof Float32Array?e.normals:new Float32Array(e.normals):void 0};const t=e?.data??e;if(t?.attributes?.position?.array&&t?.index?.array){const e="Uint16Array"===t.index.type?Uint16Array:Uint32Array;return{positions:new Float32Array(t.attributes.position.array),indices:new e(t.index.array),uvs:t.attributes.uv?.array?new Float32Array(t.attributes.uv.array):void 0,normals:t.attributes.normal?.array?new Float32Array(t.attributes.normal.array):void 0}}return{positions:O,indices:R,uvs:N}}addBehavior(e){this.behaviors.push(e)}getRendererSettings(){return this.rendererSettings}addEventListener(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)}removeAllEventListeners(e){this.listeners[e]&&(this.listeners[e]=[])}removeEventListener(e,t){if(this.listeners[e]){const i=this.listeners[e].indexOf(t);-1!==i&&this.listeners[e].splice(i,1)}}fire(e){this.listeners[e.type]&&this.listeners[e.type].forEach(t=>t(e))}clone(){const e=this.behaviors.map(e=>e.clone());let t;return t=this.renderMode===exports.RenderMode.Trail?{startLength:this.rendererEmitterSettings.startLength.clone(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin}:this.renderMode===exports.RenderMode.StretchedBillBoard?{lengthFactor:this.rendererEmitterSettings.lengthFactor,speedFactor:this.rendererEmitterSettings.speedFactor}:{},new z({autoDestroy:this.autoDestroy,looping:this.looping,prewarm:this.prewarm,duration:this.duration,shape:this.emitterShape.clone(),startLife:this.startLife.clone(),startSpeed:this.startSpeed.clone(),startRotation:this.startRotation.clone(),startSize:this.startSize.clone(),startColor:this.startColor.clone(),emissionOverTime:this.emissionOverTime.clone(),emissionOverDistance:this.emissionOverDistance.clone(),emissionBursts:this.emissionBursts.map(e=>({...e})),onlyUsedByOther:this.onlyUsedByOther,instancingGeometry:this.rendererSettings.instancingGeometry,instancingIndices:this.rendererSettings.instancingIndices,instancingUVs:this.rendererSettings.instancingUVs,instancingNormals:this.rendererSettings.instancingNormals,renderMode:this.renderMode,renderOrder:this.renderOrder,rendererEmitterSettings:t,material:this.materialRef,texture:this.rendererSettings.texture,startTileIndex:this.startTileIndex,uTileCount:this.rendererSettings.uTileCount,vTileCount:this.rendererSettings.vTileCount,blendTiles:this.rendererSettings.blendTiles,softParticles:this.rendererSettings.softParticles,softFarFade:this.rendererSettings.softFarFade,softNearFade:this.rendererSettings.softNearFade,behaviors:e,worldSpace:this.worldSpace,blendMode:this.rendererSettings.materialBlendMode,transparent:this.rendererSettings.materialTransparent,depthTest:this.rendererSettings.materialDepthTest,depthWrite:this.rendererSettings.materialDepthWrite,alphaTest:this.rendererSettings.materialAlphaTest,layerMask:this.rendererSettings.layerMask,scene:this.emitter.getScene()})}}z.serializationCounter=0;class L{static runOnAllParticleEmitters(e,t){L.traverseNode(e,e=>{e instanceof F&&t(e)})}static addToBatchRenderer(e,t){L.runOnAllParticleEmitters(e,e=>{t.addSystem(e.system)})}static play(e){L.runOnAllParticleEmitters(e,e=>{e.system.play()})}static stop(e){L.runOnAllParticleEmitters(e,e=>{e.system.stop()})}static pause(e){L.runOnAllParticleEmitters(e,e=>{e.system.pause()})}static restart(e){L.runOnAllParticleEmitters(e,e=>{e.system.restart()})}static setAutoDestroy(e,t){L.runOnAllParticleEmitters(e,e=>{e.system.autoDestroy=t})}static endEmit(e){L.runOnAllParticleEmitters(e,e=>{e.system.endEmit()})}static traverseNode(e,t){t(e);const i=e.getChildren();for(const e of i)L.traverseNode(e,t)}}class k extends i.TransformNode{constructor(e="QuarksPrefab",t){super(e,t),this.type="QuarksPrefab",this.animationData=[],this.isPlaying=!1,this.currentTime=-1e-5,this.timeScale=1,this.duration=0,this._lastUpdateTimeMs=Date.now(),this._tempAnimationJSON=[]}registerBatchedRenderer(e){this._batchedRenderer=e}addParticleSystemAnimation(e,t=0,i=0,r=!1){const s={startTime:t,duration:i>0?i:e.system.duration,type:"ps",loop:r,target:e};return this.animationData.push(s),this.pause(),this.updateDuration(),s}addThreeAnimation(e,t,i=0,r=t?.duration??0,s=!1,n){const a={startTime:i,duration:r>0?r:t?.duration??0,type:"three",loop:s,target:e,clip:t,clipUUID:n??t?.uuid};return this.animationData.push(a),this.updateDuration(),a}removeAnimation(e){this.animationData.splice(e,1),this.updateDuration()}play(){this.isPlaying||(this.isPlaying=!0,this._lastUpdateTimeMs=Date.now())}pause(){this.isPlaying&&(this.isPlaying=!1,this.animationData.forEach(e=>{"ps"===e.type&&e.target instanceof F?e.target.system.pause():e.clip?.pause?.()}))}stop(){this.pause(),this.currentTime=-1e-5,this.animationData.forEach(e=>{"ps"===e.type&&e.target instanceof F?e.target.system.stop():e.clip?.stop?.()})}update(e){if(!this.isPlaying)return;const t=Date.now(),i=e??Math.max((t-this._lastUpdateTimeMs)/1e3,0);this._lastUpdateTimeMs=t;const r=this.currentTime;this.currentTime+=i*this.timeScale,this.currentTime>this.duration?this.stop():this.animationData.forEach(e=>{const t=e.startTime,i=e.startTime+e.duration,s=this.currentTime>=t&&this.currentTime<=i,n=r>=t&&r<=i;if(!s||n){if(!s&&n){if(e.loop&&"ps"===e.type&&e.target instanceof F)return void e.target.system.restart();"ps"===e.type&&e.target instanceof F?e.target.system.endEmit():e.loop?e.clip?.play?.():e.clip?.stop?.()}}else"ps"===e.type&&e.target instanceof F?(e.target.system.restart(),this._batchedRenderer&&this._batchedRenderer.addSystem(e.target.system)):e.clip?.play?.()})}setTime(e){const t=this.currentTime;this.currentTime=e,this.animationData.forEach(i=>{const r=i.startTime,s=i.startTime+i.duration,n=this.currentTime>=r&&this.currentTime<s,a=t>=r&&t<s;!n||a?n||!a?n&&"three"===i.type&&i.clip?.setTime?.(Math.max(e-r,0)):"ps"===i.type&&i.target instanceof F?i.target.system.endEmit():i.clip?.stop?.():"ps"===i.type&&i.target instanceof F?i.target.system.restart():i.clip?.play?.()})}getDuration(){return this.duration}resolveReferences(e){const t={},r=e=>{e._quarksUUID&&(t[e._quarksUUID]=e),t[e.uniqueId.toString()]=e;const s=e.getChildren();for(const e of s)e instanceof i.TransformNode&&r(e)};r(e),this._tempAnimationJSON.forEach(e=>{const i=t[e.targetUUID];if("ps"===e.type&&i instanceof F)this.addParticleSystemAnimation(i,e.startTime,e.duration,e.loop);else if("three"===e.type&&i){const t=this.resolveTimelineClip(i,e.clipUUID);this.addThreeAnimation(i,t,e.startTime,e.duration,e.loop,e.clipUUID)}}),this.updateDuration(),this._tempAnimationJSON=[]}toJSON(){return{type:this.type,name:this.name,animationData:this.animationData.map(e=>({startTime:e.startTime,duration:e.duration,type:e.type,targetUUID:e.target._quarksUUID??e.target.uniqueId.toString(),clipUUID:"three"===e.type?e.clipUUID??e.clip?.uuid:void 0,loop:e.loop}))}}static fromJSON(e,t){const i=new k(e.name||"QuarksPrefab",t);return Array.isArray(e.animationData)&&(i._tempAnimationJSON=e.animationData.filter(e=>"ps"===e?.type||"three"===e?.type)),i}resolveTimelineClip(e,t){const i=[e.animations,e.animationGroups,e.metadata?.animations,e.metadata?.animationGroups];for(const e of i){if(!Array.isArray(e))continue;if(!t)return e[0];const i=e.find(e=>e?.uuid===t);if(i)return i}}updateDuration(){let e=0;this.animationData.forEach(t=>{const i=t.startTime+t.duration;i>e&&(e=i)}),this.duration=e}}class W extends c.StandardMaterial{constructor(e,t,i={}){super(e,t),this.isParticleMeshStandardMaterial=!0,Object.assign(this,i)}}class j extends u.PBRMaterial{constructor(e,t,i={}){super(e,t),this.isParticleMeshPhysicsMaterial=!0,Object.assign(this,i)}}g(),e.loadPlugin(p),console.log("%c Particle system powered by babylon.quarks. https://quarks.art/","font-size: 14px; font-weight: bold;"),exports.BatchedParticleRenderer=_,exports.BatchedRenderer=A,exports.MeshSurfaceEmitter=f,exports.MeshSurfaceEmitterPlugin=p,exports.ParticleEmitter=F,exports.ParticleMeshPhysicsMaterial=j,exports.ParticleMeshStandardMaterial=W,exports.ParticleSystem=z,exports.QuarksLoader=class{constructor(e,t={}){this.scene=e,this.options=t}async load(e){const t=this.options.baseUrl||e.substring(0,e.lastIndexOf("/")+1),i=await fetch(e),r=await i.json();return this.parse(r,t)}parse(e,t=""){const i={textures:{},geometries:{},materials:{}};e.geometries&&this.parseGeometries(e.geometries,i),e.images&&this.parseImages(e.images,t,i),e.textures&&this.parseTextures(e.textures,i),e.materials&&this.parseMaterials(e.materials,i);const r=this.parseObject(e.object,i);return this.linkReferences(r),r}parseGeometries(e,t){for(const i of e)if("PlaneGeometry"===i.type){const e=(i.width||1)/2,r=(i.height||1)/2;t.geometries[i.uuid]={positions:new Float32Array([-e,-r,0,e,-r,0,e,r,0,-e,r,0]),indices:new Uint32Array([0,1,2,0,2,3]),uvs:new Float32Array([0,0,1,0,1,1,0,1]),normals:new Float32Array([0,0,1,0,0,1,0,0,1,0,0,1])}}else if("SphereGeometry"===i.type)t.geometries[i.uuid]=this.parseSphereGeometry(i);else if("BufferGeometry"===i.type&&i.data){const e=this.parseBufferGeometry(i.data);t.geometries[i.uuid]=e}}parseSphereGeometry(e){const t=e.radius??.5,i=Math.max(3,Math.floor(e.widthSegments??16)),r=Math.max(2,Math.floor(e.heightSegments??8)),s=e.phiStart??0,n=e.phiLength??2*Math.PI,a=e.thetaStart??0,o=e.thetaLength??Math.PI,l=[],h=[],d=[],c=[],u=[];let f=0;for(let e=0;e<=r;e++){const c=[],p=e/r,m=a+p*o;for(let e=0;e<=i;e++){const r=e/i,a=s+r*n,o=-t*Math.cos(a)*Math.sin(m),u=t*Math.cos(m),v=t*Math.sin(a)*Math.sin(m);l.push(o,u,v);const g=Math.hypot(o,u,v)||1;h.push(o/g,u/g,v/g),d.push(r,1-p),c.push(f++)}u.push(c)}const p=a<=0,m=a+o>=Math.PI;for(let e=0;e<r;e++)for(let t=0;t<i;t++){const i=u[e][t+1],s=u[e][t],n=u[e+1][t],a=u[e+1][t+1];0===e&&p||c.push(i,s,a),e===r-1&&m||c.push(s,n,a)}const v=l.length/3>65535?new Uint32Array(c):new Uint16Array(c);return{positions:new Float32Array(l),indices:v,uvs:new Float32Array(d),normals:new Float32Array(h)}}parseBufferGeometry(e){let t,i,r=new Float32Array(0),s=new Uint32Array(0);if(e.interleavedBuffers&&e.arrayBuffers){const s={};for(const[t,i]of Object.entries(e.interleavedBuffers)){const r=e.arrayBuffers[i.buffer];if(r){const e=new Float32Array(Array.isArray(r)?this.int32ArrayToFloat32(r):r);s[t]={data:e,stride:i.stride}}}if(e.attributes){if(e.attributes.position?.isInterleavedBufferAttribute){const t=e.attributes.position,i=s[t.data];i&&(r=this.extractInterleavedAttribute(i.data,i.stride,t.offset,t.itemSize))}if(e.attributes.uv?.isInterleavedBufferAttribute){const i=e.attributes.uv,r=s[i.data];r&&(t=this.extractInterleavedAttribute(r.data,r.stride,i.offset,i.itemSize))}if(e.attributes.normal?.isInterleavedBufferAttribute){const t=e.attributes.normal,r=s[t.data];r&&(i=this.extractInterleavedAttribute(r.data,r.stride,t.offset,t.itemSize))}}}else e.attributes&&(e.attributes.position?.array&&(r=new Float32Array(e.attributes.position.array)),e.attributes.uv?.array&&(t=new Float32Array(e.attributes.uv.array)),e.attributes.normal?.array&&(i=new Float32Array(e.attributes.normal.array)));return e.index&&(s="Uint16Array"===e.index.type?new Uint16Array(e.index.array):new Uint32Array(e.index.array)),{positions:r,indices:s,uvs:t,normals:i}}extractInterleavedAttribute(e,t,i,r){const s=Math.floor(e.length/t),n=new Float32Array(s*r);for(let a=0;a<s;a++)for(let s=0;s<r;s++)n[a*r+s]=e[a*t+i+s];return n}int32ArrayToFloat32(e){const t=new ArrayBuffer(4*e.length),i=new Int32Array(t);for(let t=0;t<e.length;t++)i[t]=e[t];return new Float32Array(t)}parseImages(e,t,i){this._images={};for(const i of e)this._images[i.uuid]=i.url?t+i.url:null}parseTextures(e,t){const i=this._images||{};for(const r of e){const e=i[r.image];if(e){const i=new d.Texture(e,this.scene);Array.isArray(r.wrap)&&(i.wrapU=this.mapWrapMode(r.wrap[0]),i.wrapV=this.mapWrapMode(r.wrap[1]??r.wrap[0])),Array.isArray(r.repeat)&&(i.uScale=r.repeat[0]??1,i.vScale=r.repeat[1]??1),Array.isArray(r.offset)&&(i.uOffset=r.offset[0]??0,i.vOffset=r.offset[1]??0),"number"==typeof r.rotation&&(i.wAng=r.rotation),t.textures[r.uuid]=i}else t.textures[r.uuid]=null}}mapWrapMode(e){switch(e){case 1001:return d.Texture.CLAMP_ADDRESSMODE;case 1002:return d.Texture.MIRROR_ADDRESSMODE;default:return d.Texture.WRAP_ADDRESSMODE}}parseMaterials(e,t){for(const i of e){const e={uuid:i.uuid,transparent:i.transparent??!0,blending:i.blending??1,side:i.side??2,depthTest:i.depthTest??!0,depthWrite:i.depthWrite??!1,alphaTest:i.alphaTest??0,texture:null};i.map&&(e.texture=t.textures[i.map]||null);const r={1:o.Constants.ALPHA_COMBINE,2:o.Constants.ALPHA_ADD,3:o.Constants.ALPHA_SUBTRACT,4:o.Constants.ALPHA_MULTIPLY};e.alphaMode=r[i.blending]||o.Constants.ALPHA_COMBINE,t.materials[i.uuid]=e}}getGeometry(e,t){if(t)return e.geometries[t]}getMaterial(e,t){if(!t)return;const i=Array.isArray(t)?t[0]:t;return e.materials[i]}createPlaceholderNode(e,t){const r=new i.TransformNode(t||e||"node",this.scene);return r.quarksOriginalType=e,r}createMeshNode(e,t){const i=new r.Mesh(e.name||e.type||"mesh",this.scene),s=this.getGeometry(t,e.geometry);if(s&&s.positions.length>0&&s.indices.length>0){const e=new n.VertexData;e.positions=Array.from(s.positions),e.indices=Array.from(s.indices),s.uvs&&s.uvs.length>0&&(e.uvs=Array.from(s.uvs)),s.normals&&s.normals.length>0&&(e.normals=Array.from(s.normals)),e.applyToMesh(i,!0)}const a=this.getMaterial(t,e.material);if(a){const e=new c.StandardMaterial(`quarks_loader_material_${a.uuid}`,this.scene);e.alphaMode=a.alphaMode??o.Constants.ALPHA_COMBINE,e.backFaceCulling=2!==a.side,e.alphaCutOff=a.alphaTest??0,e.disableDepthWrite=!a.depthWrite,a.texture&&(e.diffuseTexture=a.texture,e.opacityTexture=a.texture),i.material=e}return i}parseObject(e,t){let r;switch(e.type){case"QuarksPrefab":r=k.fromJSON(e,this.scene);break;case"ParticleEmitter":if(e.ps){r=this.parseParticleSystem(e.ps,t).emitter;break}r=this.createPlaceholderNode(e.type,e.name);break;case"Mesh":case"SkinnedMesh":case"InstancedMesh":case"BatchedMesh":r=this.createMeshNode(e,t);break;case"Scene":case"Group":case"Object3D":case"PerspectiveCamera":case"OrthographicCamera":case"AmbientLight":case"DirectionalLight":case"PointLight":case"RectAreaLight":case"SpotLight":case"HemisphereLight":case"LightProbe":case"LOD":case"Line":case"LineSegments":case"LineLoop":case"PointCloud":case"Points":case"Sprite":case"Bone":r=this.createPlaceholderNode(e.type,e.name);break;default:r=new i.TransformNode(e.name||e.type||"node",this.scene)}if(e.uuid&&(r._quarksUUID=e.uuid),e.name&&(r.name=e.name),e.matrix){const t=l.Matrix.FromArray(e.matrix),i=new l.Vector3(1,1,1),s=l.Quaternion.Identity(),n=new l.Vector3(0,0,0);t.decompose(i,s,n),r.position.copyFrom(n),r.scaling.copyFrom(i),r.rotationQuaternion=s}else e.position&&r.position.set(e.position[0],e.position[1],e.position[2]),e.scale&&r.scaling.set(e.scale[0],e.scale[1],e.scale[2]),e.quaternion?r.rotationQuaternion=new l.Quaternion(e.quaternion[0],e.quaternion[1],e.quaternion[2],e.quaternion[3]):e.rotation&&r.rotation.set(e.rotation[0],e.rotation[1],e.rotation[2]);if(void 0!==e.visible&&r.setEnabled(e.visible),e.children)for(const i of e.children){this.parseObject(i,t).parent=r}return r}parseParticleSystem(e,t){const i=z.fromJSON(e,t,{},this.scene);return i._meshSurfaceReferenceUUID="mesh_surface"===e?.shape?.type?e?.shape?.mesh:void 0,i}linkReferences(t){const s={},n=e=>{e._quarksUUID&&(s[e._quarksUUID]=e);for(const t of e.getChildren())t instanceof i.TransformNode&&n(t)};n(t);const a=n=>{if(n instanceof k&&n.resolveReferences(t),n instanceof F){const t=n.system,i=t._meshSurfaceReferenceUUID;if(i&&"mesh_surface"===t.emitterShape.type){const e=s[i];e instanceof r.Mesh&&(t.emitterShape.mesh=e)}for(let i=0;i<t.behaviors.length;i++)if(t.behaviors[i]instanceof e.EmitSubParticleSystem){const e=t.behaviors[i],r=e.subParticleSystem;"string"==typeof r&&s[r]&&(e.subParticleSystem=s[r])}}for(const e of n.getChildren())e instanceof i.TransformNode&&a(e)};a(t)}},exports.QuarksPrefab=k,exports.QuarksUtil=L,exports.SpriteBatch=V,exports.TrailBatch=C,exports.VFXBatch=w,exports.getRegisteredShaderChunks=function(){return m},exports.getShaderChunk=function(e){return m[e]},exports.localParticlePhysicsVertShader=T,exports.localParticleVertShader="\n// Per-vertex attributes\nattribute vec3 position;\nattribute vec2 uv;\n\n// Per-instance attributes\nattribute vec3 offset;\nattribute vec4 color;\nattribute vec3 size;\nattribute vec4 rotation;\nattribute float uvTile;\n\n// Uniforms\nuniform mat4 worldViewProjection;\n\n#ifdef UV_TILE\nuniform float tileCountX;\nuniform float tileCountY;\n#endif\n\n// Varyings\nvarying vec2 vUV;\nvarying vec4 vColor;\n\nvec3 applyQuaternion(vec3 v, vec4 q) {\n vec3 qVec = q.xyz;\n float qW = q.w;\n vec3 t = 2.0 * cross(qVec, v);\n return v + qW * t + cross(qVec, t);\n}\n\nvoid main() {\n vec3 rotatedPosition = applyQuaternion(position * size, rotation);\n vec3 worldPos = rotatedPosition + offset;\n\n gl_Position = worldViewProjection * vec4(worldPos, 1.0);\n\n #ifdef UV_TILE\n vec2 tc = vec2(tileCountX, tileCountY);\n float baseTile = floor(uvTile);\n float tileU = mod(baseTile, tc.x) / tc.x;\n float tileV = 1.0 - floor(baseTile / tc.x) / tc.y - 1.0 / tc.y;\n vUV = uv / tc + vec2(tileU, tileV);\n #else\n vUV = uv;\n #endif\n\n vColor = color;\n}\n",exports.particleFragShader=S,exports.particlePhysicsFragShader=B,exports.particleVertShader=x,exports.registerShaderChunks=g,exports.stretchedBillboardVertShader=M,exports.trailFragShader=P,exports.trailVertShader=b,Object.keys(e).forEach(function(t){"default"===t||Object.prototype.hasOwnProperty.call(exports,t)||Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})});
2
+ //# sourceMappingURL=babylon.quarks.cjs.map