@hology/core 0.0.102 → 0.0.105

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.
@@ -1,11 +1,12 @@
1
1
  import * as THREE from "three";
2
- import { NodeShaderMaterial } from "three-shader-graph";
2
+ import { NodeShaderMaterial } from 'three-shader-graph';
3
3
  import { OutputTextureSetting } from '../../gameplay';
4
4
  export declare const trailUV: import("three-shader-graph").Vec2Node;
5
5
  export declare const trailDragUV: import("three-shader-graph").Vec2Node;
6
6
  export declare class Trail extends THREE.Object3D {
7
7
  active: boolean;
8
8
  orientToMovement: boolean;
9
+ billboard: boolean;
9
10
  scene: any;
10
11
  geometry: THREE.BufferGeometry | null;
11
12
  mesh: THREE.Mesh | null;
@@ -34,7 +35,7 @@ export declare class Trail extends THREE.Object3D {
34
35
  faceCount: number;
35
36
  constructor(scene: THREE.Object3D, orientToMovement: boolean);
36
37
  setAdvanceFrequency(advanceFrequency: any): void;
37
- initialize(material: THREE.ShaderMaterial, length: number, dragTexture: boolean, localHeadWidth: number, localHeadGeometry: THREE.BufferGeometry, targetObject: THREE.Object3D): void;
38
+ initialize(material: THREE.ShaderMaterial, length: number, dragTexture: boolean, localHeadWidth: number, localHeadGeometry: THREE.BufferGeometry, targetObject: THREE.Object3D, billboard?: boolean): void;
38
39
  initializeLocalHeadGeometry(localHeadWidth: number, localHeadGeometry: any): void;
39
40
  initializeGeometry(): void;
40
41
  zeroVertices(): void;
@@ -69,13 +70,13 @@ export declare class Trail extends THREE.Object3D {
69
70
  };
70
71
  deactivate(): void;
71
72
  activate(): void;
72
- static getTrailShaderNodes(): {
73
+ static getTrailShaderNodes(billboard: boolean): {
73
74
  position: import("three-shader-graph").Vec4Node;
74
75
  color: import("three-shader-graph").Vec4Node;
75
76
  fraction: import("three-shader-graph").FloatDivNode;
76
77
  };
77
78
  static applyTrailShaderParameters(nodeShader: THREE.ShaderMaterial): void;
78
- static createBaseMaterial(texture?: THREE.Texture, scrollSpeed?: number, opacityChannel?: OutputTextureSetting['opacityChannel']): NodeShaderMaterial;
79
+ static createBaseMaterial(texture?: THREE.Texture, scrollSpeed?: number, opacityChannel?: OutputTextureSetting['opacityChannel'], billboard?: boolean): NodeShaderMaterial;
79
80
  static get MaxHeadVertices(): number;
80
81
  static _LocalOrientationTangent: THREE.Vector3;
81
82
  static get LocalOrientationTangent(): THREE.Vector3;
@@ -1 +1 @@
1
- {"version":3,"file":"trail-renderer.d.ts","sourceRoot":"","sources":["../../../src/effects/vfx/trail-renderer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAkL,MAAM,oBAAoB,CAAA;AACvO,OAAO,EAAC,oBAAoB,EAAC,MAAM,gBAAgB,CAAC;AAyBpD,eAAO,MAAM,OAAO,uCAMlB,CAAA;AAEF,eAAO,MAAM,WAAW,uCAGtB,CAAA;AAEF,qBAAa,KAAM,SAAQ,KAAK,CAAC,QAAQ;IACvC,MAAM,EAAE,OAAO,CAAA;IACf,gBAAgB,EAAE,OAAO,CAAA;IACzB,KAAK,EAAE,GAAG,CAAA;IACV,QAAQ,EAAE,KAAK,CAAC,cAAc,GAAG,IAAI,CAAA;IACrC,IAAI,EAAE,KAAK,CAAC,IAAI,GAAG,IAAI,CAAA;IACvB,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAK;IACtC,cAAc,EAAE,KAAK,CAAC,OAAO,GAAG,IAAI,CAAA;IACpC,iBAAiB,EAAE,KAAK,CAAC,OAAO,GAAG,IAAI,CAAA;IACvC,kBAAkB,EAAE,KAAK,CAAC,OAAO,GAAG,IAAI,CAAA;IACxC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAK;IAC3B,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;IACrB,gBAAgB,EAAE,MAAM,CAAA;IACxB,aAAa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AK,gBAAgB,WAE1B;IAED,MAAM,KAAK,cAAc,WAExB;IAED,MAAM,KAAK,YAAY,WAEtB;IAED,MAAM,CAAC,MAAM;;;;;;;;;;MAsGZ;CACF"}
@@ -1,4 +1,4 @@
1
- import{timeUniforms as e}from"../../shader-nodes";import*as t from"three";import{NodeShaderMaterial as r,uniformBool as i,uniformFloat as a,uniformVec2 as n,mix as s,uniformVec4 as o,attributeFloat as h,attributeVec3 as c,select as l,float as d,textureSampler2d as u,attributes as m,uniforms as g,rgba as p,vec4 as y,varying as f,vec2 as x}from"three-shader-graph";a("trailLength");const v=a("verticesPerNode"),T=a("minID"),V=a("maxID"),P=(a("dragTexture"),a("maxTrailLength")),C=n("textureTileFactor",new t.Vector2(1,1)),N=o("headColor",new t.Vector4),D=o("tailColor",new t.Vector4),F=i("taper",!1),w=(a("scale",1),h("nodeID")),I=h("nodeVertexID"),b=c("nodeCenter"),U=V.subtract(w).divide(V.subtract(T)),A=l(F,U,d(0)),L=f(d(1).subtract(U).multiplyVec4(N).add(U.multiplyVec4(D))),M=y(d(1).subtract(A).multiplyVec3(m.position).add(A.multiplyVec3(b)),1),H=g.projectionMatrix.multiply(g.viewMatrix).multiplyVec(M);export const trailUV=f(x(U.multiply(C.x),I.divide(v).multiply(C.y).multiply(2)));export const trailDragUV=f(x(w.divide(P).multiply(C.x),I.divide(v).multiply(C.y).multiply(2)));export class Trail extends t.Object3D{constructor(e,r){super(),this.nodeCenters=[],this.nodeIDs=[],this.advance=function(){const e=new t.Matrix4;return function(){this.targetObject.updateMatrixWorld(),e.copy(this.targetObject.matrixWorld),this.advanceWithTransform(e),this.updateUniforms()}}(),this.advanceGeometry=function(e,t){const r=this.currentEnd+1>=this.length?0:this.currentEnd+1;if(t?this.updateNodePositionsFromTransformMatrix(r,t):this.updateNodePositionsFromOrientationTangent(r,e.position,e.tangent),this.currentLength>=1&&(this.connectNodes(this.currentEnd,r),this.currentLength>=this.length)){const e=this.currentEnd+1>=this.length?0:this.currentEnd+1;this.disconnectNodes(e)}this.currentLength<this.length&&this.currentLength++,this.currentEnd++,this.currentEnd>=this.length&&(this.currentEnd=0),this.currentLength>=1&&(this.currentLength<this.length?this.geometry.setDrawRange(0,(this.currentLength-1)*this.FaceIndicesPerNode):this.geometry.setDrawRange(0,this.currentLength*this.FaceIndicesPerNode)),this.updateNodeID(this.currentEnd,this.currentNodeID),this.currentNodeID++},this.updateHead=function(){const e=new t.Matrix4;return function(){this.currentEnd<0||(this.targetObject.updateMatrixWorld(),e.copy(this.targetObject.matrixWorld),this.updateNodePositionsFromTransformMatrix(this.currentEnd,e))}}(),this.updateNodePositionsFromOrientationTangent=function(){const e=new t.Quaternion,r=new t.Vector3,i=[];for(let e=0;e<Trail.MaxHeadVertices;e++){const e=new t.Vector3;i.push(e)}return function(t,a,n){const s=this.geometry.getAttribute("position");this.updateNodeCenter(t,a),r.copy(a),r.sub(Trail.LocalHeadOrigin),e.setFromUnitVectors(Trail.LocalOrientationTangent,n);for(let t=0;t<this.localHeadGeometry.length;t++){const a=i[t];a.copy(this.localHeadGeometry[t]),a.applyQuaternion(e),a.add(r)}for(let e=0;e<this.localHeadGeometry.length;e++){const r=(this.VerticesPerNode*t+e)*Trail.PositionComponentCount,a=i[e];s.array[r]=a.x,s.array[r+1]=a.y,s.array[r+2]=a.z}s.needsUpdate=!0}}(),this.updateNodePositionsFromTransformMatrix=function(){const e=new t.Matrix3,r=new t.Quaternion,i=new t.Vector3,a=new t.Vector3,n=new t.Vector3,s=new t.Vector3,o=new t.Box3,h=new t.Vector3,c=[];for(let e=0;e<Trail.MaxHeadVertices;e++){const e=new t.Vector3;c.push(e)}return function(l,d){const u=this.geometry.getAttribute("position");i.set(0,0,0),i.applyMatrix4(d),this.updateNodeCenter(l,i);for(let e=0;e<this.localHeadGeometry.length;e++){c[e].copy(this.localHeadGeometry[e])}for(let e=0;e<this.localHeadGeometry.length;e++){c[e].applyMatrix4(d)}if(this.lastNodeCenter&&this.orientToMovement&&(function(e,t){const r=t.elements;e.set(r[0],r[1],r[2],r[4],r[5],r[6],r[8],r[9],r[10])}(e,d),n.set(0,0,-1),n.applyMatrix3(e),s.copy(this.currentNodeCenter),s.sub(this.lastNodeCenter),s.normalize(),s.lengthSq()<=1e-4&&this.lastOrientationDir&&s.copy(this.lastOrientationDir),s.lengthSq()>1e-4)){this.lastOrientationDir||(this.lastOrientationDir=new t.Vector3),r.setFromUnitVectors(n,s),a.copy(this.currentNodeCenter);for(let e=0;e<this.localHeadGeometry.length;e++){const t=c[e];t.sub(a),t.applyQuaternion(r),t.add(a)}}for(let e=0;e<this.localHeadGeometry.length;e++){const t=(this.VerticesPerNode*l+e)*Trail.PositionComponentCount,r=c[e];u.array[t]=r.x,u.array[t+1]=r.y,u.array[t+2]=r.z}u.needsUpdate=!0,u.addUpdateRange(l*this.VerticesPerNode*Trail.PositionComponentCount,this.VerticesPerNode*Trail.PositionComponentCount),o.makeEmpty();for(let e=0;e<this.currentLength*this.VerticesPerNode;e++){const t=3*e;h.set(u.array[t],u.array[t+1],u.array[t+2]),o.expandByPoint(h)}this.geometry.boundingBox=o,null==this.geometry.boundingSphere&&(this.geometry.boundingSphere=new t.Sphere),this.geometry.boundingBox.getBoundingSphere(this.geometry.boundingSphere)}}(),this.connectNodes=(()=>{const e={attribute:null,offset:0,count:-1};return(t,r)=>{const i=this.geometry.getIndex();for(let e=0;e<this.localHeadGeometry.length-1;e++){const a=this.VerticesPerNode*t+e,n=this.VerticesPerNode*r+e,s=(t*this.FacesPerNode+e*Trail.FacesPerQuad)*Trail.IndicesPerFace;i.array[s]=a,i.array[s+1]=n,i.array[s+2]=a+1,i.array[s+3]=n,i.array[s+4]=n+1,i.array[s+5]=a+1}return i.needsUpdate=!0,i.clearUpdateRanges(),e.attribute=i,e.offset=t*this.FacesPerNode*Trail.IndicesPerFace,e.count=this.FacesPerNode*Trail.IndicesPerFace,e}})(),this.disconnectNodes=(()=>{const e={attribute:null,offset:0,count:-1};return t=>{const r=this.geometry.getIndex();for(let e=0;e<this.localHeadGeometry.length-1;e++){const i=(t*this.FacesPerNode+e*Trail.FacesPerQuad)*Trail.IndicesPerFace;r.array[i]=0,r.array[i+1]=0,r.array[i+2]=0,r.array[i+3]=0,r.array[i+4]=0,r.array[i+5]=0}return r.needsUpdate=!0,r.clearUpdateRanges(),e.attribute=r,e.offset=t*this.FacesPerNode*Trail.IndicesPerFace,e.count=this.FacesPerNode*Trail.IndicesPerFace,e}})(),this.active=!1,this.orientToMovement=!1,r&&(this.orientToMovement=!0),this.scene=e,this.geometry=null,this.mesh=null,this.nodeCenters=[],this.lastNodeCenter=null,this.currentNodeCenter=null,this.lastOrientationDir=null,this.nodeIDs=[],this.currentLength=0,this.currentEnd=0,this.currentNodeID=0,this.advanceFrequency=60,this.advancePeriod=1/this.advanceFrequency,this.lastAdvanceTime=0,this.paused=!1,this.pauseAdvanceUpdateTimeDiff=0}setAdvanceFrequency(e){this.advanceFrequency=e,this.advancePeriod=1/this.advanceFrequency}initialize(e,r,i,a,n,s){this.deactivate(),this.destroyMesh(),this.length=r>0?r+1:0,this.dragTexture=i?1:0,this.targetObject=s,this.initializeLocalHeadGeometry(a,n),this.nodeIDs=[],this.nodeCenters=[];for(let e=0;e<this.length;e++)this.nodeIDs[e]=-1,this.nodeCenters[e]=new t.Vector3;this.material=e,this.initializeGeometry(),this.initializeMesh(),this.material.uniforms.dragTexture&&(this.material.uniforms.trailLength.value=0),this.material.uniforms.minID.value=0,this.material.uniforms.maxID.value=0,this.material.uniforms.dragTexture&&(this.material.uniforms.dragTexture.value=this.dragTexture),this.material.uniforms.maxTrailLength&&(this.material.uniforms.maxTrailLength.value=this.length),this.material.uniforms.verticesPerNode&&(this.material.uniforms.verticesPerNode.value=this.VerticesPerNode),this.material.uniforms.textureTileFactor&&(this.material.uniforms.textureTileFactor.value=new t.Vector2(1,1)),this.material.uniforms.scale&&(this.material.uniforms.scale.value=1),this.reset()}initializeLocalHeadGeometry(e,r){if(this.localHeadGeometry=[],r){this.VerticesPerNode=0;for(let e=0;e<r.length&&e<Trail.MaxHeadVertices;e++){const i=r[e];if(i&&i instanceof t.Vector3){const e=new t.Vector3;e.copy(i),this.localHeadGeometry.push(e),this.VerticesPerNode++}}}else{const r=(e||1)/2;this.localHeadGeometry.push(new t.Vector3(-r,0,0)),this.localHeadGeometry.push(new t.Vector3(r,0,0)),this.VerticesPerNode=2}this.FacesPerNode=2*(this.VerticesPerNode-1),this.FaceIndicesPerNode=3*this.FacesPerNode}initializeGeometry(){this.vertexCount=this.length*this.VerticesPerNode,this.faceCount=this.length*this.FacesPerNode;const e=new t.BufferGeometry,r=new Float32Array(this.vertexCount),i=new Float32Array(this.vertexCount*this.VerticesPerNode),a=new Float32Array(this.vertexCount*Trail.PositionComponentCount),n=new Float32Array(this.vertexCount*Trail.PositionComponentCount),s=new Float32Array(this.vertexCount*Trail.UVComponentCount),o=new Uint32Array(this.faceCount*Trail.IndicesPerFace),h=new t.BufferAttribute(r,1);h.setUsage(t.DynamicDrawUsage),e.setAttribute("nodeID",h);const c=new t.BufferAttribute(i,1);c.setUsage(t.DynamicDrawUsage),e.setAttribute("nodeVertexID",c);const l=new t.BufferAttribute(n,Trail.PositionComponentCount);l.setUsage(t.DynamicDrawUsage),e.setAttribute("nodeCenter",l);const d=new t.BufferAttribute(a,Trail.PositionComponentCount);d.setUsage(t.DynamicDrawUsage),e.setAttribute("position",d);const u=new t.BufferAttribute(s,Trail.UVComponentCount);u.setUsage(t.DynamicDrawUsage),e.setAttribute("uv",u);const m=new t.BufferAttribute(o,1);m.setUsage(t.DynamicDrawUsage),e.setIndex(m),this.geometry=e}zeroVertices(){const e=this.geometry.getAttribute("position");for(let t=0;t<this.vertexCount;t++){const r=3*t;e.array[r]=0,e.array[r+1]=0,e.array[r+2]=0}e.needsUpdate=!0}zeroIndices(){if(null==this.geometry)throw"Geometry not initialized";const e=this.geometry.getIndex();for(let t=0;t<this.faceCount;t++){const r=3*t;e.array[r]=0,e.array[r+1]=0,e.array[r+2]=0}e.needsUpdate=!0,e.clearUpdateRanges()}formInitialFaces(){this.zeroIndices();const e=this.geometry.getIndex();for(let e=0;e<this.length-1;e++)this.connectNodes(e,e+1);e.needsUpdate=!0,e.clearUpdateRanges()}initializeMesh(){if(null==this.geometry)throw"Geometry not initialized";this.mesh=new t.Mesh(this.geometry,this.material),this.mesh.matrixAutoUpdate=!1}destroyMesh(){this.mesh&&(this.scene.remove(this.mesh),this.mesh=null)}reset(){this.currentLength=0,this.currentEnd=-1,this.lastNodeCenter=null,this.currentNodeCenter=null,this.lastOrientationDir=null,this.currentNodeID=0,this.formInitialFaces(),this.zeroVertices(),this.geometry.setDrawRange(0,0)}updateUniforms(){this.currentLength<this.length?this.material.uniforms.minID.value=0:this.material.uniforms.minID.value=this.currentNodeID-this.length,this.material.uniforms.maxID.value=this.currentNodeID,this.material.uniforms.trailLength&&(this.material.uniforms.trailLength.value=this.currentLength),this.material.uniforms.maxTrailLength&&(this.material.uniforms.maxTrailLength.value=this.length),this.material.uniforms.verticesPerNod&&(this.material.uniforms.verticesPerNode.value=this.VerticesPerNode)}advanceWithPositionAndOrientation(e,t){this.advanceGeometry({position:e,tangent:t},null)}advanceWithTransform(e){this.advanceGeometry(null,e)}currentTime(){return performance.now()/1e3}pause(){this.paused||(this.paused=!0,this.pauseAdvanceUpdateTimeDiff=this.currentTime()-this.lastAdvanceTime)}resume(){this.paused&&(this.paused=!1,this.lastAdvanceTime=this.currentTime()-this.pauseAdvanceUpdateTimeDiff)}update(){if(!this.paused){const e=this.currentTime();this.lastAdvanceTime||(this.lastAdvanceTime=e),e-this.lastAdvanceTime>this.advancePeriod?(this.advance(),this.lastAdvanceTime=e):this.updateHead()}}updateNodeID(e,t){this.nodeIDs[e]=t;const r=this.geometry.getAttribute("nodeID"),i=this.geometry.getAttribute("nodeVertexID");for(let a=0;a<this.VerticesPerNode;a++){const n=e*this.VerticesPerNode+a;r.array[n]=t,i.array[n]=a}r.needsUpdate=!0,i.needsUpdate=!0,r.addUpdateRange(e*this.VerticesPerNode,this.VerticesPerNode),i.addUpdateRange(e*this.VerticesPerNode,this.VerticesPerNode)}updateNodeCenter(e,t){this.lastNodeCenter=this.currentNodeCenter,this.currentNodeCenter=this.nodeCenters[e],this.currentNodeCenter.copy(t);const r=this.geometry.getAttribute("nodeCenter");for(let i=0;i<this.VerticesPerNode;i++){const a=3*(e*this.VerticesPerNode+i);r.array[a]=t.x,r.array[a+1]=t.y,r.array[a+2]=t.z}r.needsUpdate=!0,r.updateRanges=[{start:e*this.VerticesPerNode*Trail.PositionComponentCount,count:this.VerticesPerNode*Trail.PositionComponentCount}]}deactivate(){this.active&&(this.scene.remove(this.mesh),this.active=!1)}activate(){this.active||(this.scene.add(this.mesh),this.active=!0)}static getTrailShaderNodes(){return{position:H,color:L,fraction:U}}static applyTrailShaderParameters(e){e.transparent=!0,e.alphaTest=.5,e.blending=t.CustomBlending,e.blendSrc=t.SrcAlphaFactor,e.blendDst=t.OneMinusSrcAlphaFactor,e.blendEquation=t.AddEquation,e.depthTest=!0,e.depthWrite=!1,e.side=t.DoubleSide}static createBaseMaterial(t,i,a){let{position:n}=Trail.getTrailShaderNodes(),o=s(N,D,U).rgba;if(null!=t){let r=trailUV;null!=i&&(r=r.add(x(e.elapsed.multiply(-i),0)));const n=u(t).sample(r);let s=o.a;switch(a??"red"){case"none":break;case"red":s=s.multiply(n.r);break;case"alpha":s=s.multiply(n.a)}o=p(o.rgb.multiply(n.rgb),s)}const h=new r({position:n,color:o});return Trail.applyTrailShaderParameters(h),h}static get MaxHeadVertices(){return 128}static get LocalOrientationTangent(){return Trail._LocalOrientationTangent}static get LocalHeadOrigin(){return Trail._LocalHeadOrigin}static get PositionComponentCount(){return 3}static get UVComponentCount(){return 2}static get IndicesPerFace(){return 3}static get FacesPerQuad(){return 2}}Trail._LocalOrientationTangent=new t.Vector3(1,0,0),Trail._LocalHeadOrigin=new t.Vector3(0,0,0),Trail.Shader={get BaseVertexVars(){return["attribute float nodeID;","attribute float nodeVertexID;","attribute vec3 nodeCenter;","uniform float minID;","uniform float maxID;","uniform float trailLength;","uniform float maxTrailLength;","uniform float verticesPerNode;","uniform vec2 textureTileFactor;","uniform bool taper;","uniform vec4 headColor;","uniform vec4 tailColor;","varying vec4 vColor;"].join("\n")},get TexturedVertexVars(){return[this.BaseVertexVars,"varying vec2 vUV;","uniform float dragTexture;"].join("\n")},BaseFragmentVars:["varying vec4 vColor;","uniform sampler2D trailTexture;"].join("\n"),get TexturedFragmentVars(){return[this.BaseFragmentVars,"varying vec2 vUV;"].join("\n")},get VertexShaderCore(){return["float fraction = (maxID - nodeID) / (maxID - minID);","float fractionSize = taper ? fraction : 0.0;","vColor = (1.0 - fraction) * headColor + fraction * tailColor;","vec4 realPosition = vec4((1.0 - fractionSize) * position.xyz + fractionSize * nodeCenter.xyz, 1.0); "].join("\n")},get BaseVertexShader(){return[this.BaseVertexVars,"void main() { ",this.VertexShaderCore,"gl_Position = projectionMatrix * viewMatrix * realPosition;","}"].join("\n")},get BaseFragmentShader(){return[this.BaseFragmentVars,"void main() { ","gl_FragColor = vColor;","}"].join("\n")},get TexturedVertexShader(){return[this.TexturedVertexVars,"void main() { ",this.VertexShaderCore,"float s = 0.0;","float t = 0.0;","if (dragTexture == 1.0) { "," s = fraction * textureTileFactor.s; "," t = (nodeVertexID / verticesPerNode) * textureTileFactor.t;","} else { "," s = nodeID / maxTrailLength * textureTileFactor.s;"," t = (nodeVertexID / verticesPerNode) * textureTileFactor.t;","}","vUV = vec2(s, t); ","gl_Position = projectionMatrix * viewMatrix * realPosition;","}"].join("\n")},get TexturedFragmentShader(){return[this.TexturedFragmentVars,"void main() { ","vec4 textureColor = texture2D(trailTexture, vUV);","gl_FragColor = vColor * textureColor;","}"].join("\n")}};/*
1
+ import{timeUniforms as e}from"../../shader-nodes";import*as t from"three";import{NodeShaderMaterial as r,uniformBool as i,uniformFloat as a,uniformVec2 as n,mix as s,uniformVec4 as o,attributeFloat as h,attributeVec3 as c,select as l,float as d,textureSampler2d as u,attributes as m,uniforms as g,rgba as p,vec4 as y,varying as f,vec2 as x,normalize as v,cross as T,max as V}from"three-shader-graph";a("trailLength");const C=a("verticesPerNode"),N=a("minID"),P=a("maxID"),b=(a("dragTexture"),a("maxTrailLength")),D=n("textureTileFactor",new t.Vector2(1,1)),w=o("headColor",new t.Vector4),F=o("tailColor",new t.Vector4),I=i("taper",!1),U=(a("scale",1),h("nodeID")),A=h("nodeVertexID"),L=c("nodeCenter"),M=P.subtract(U).divide(P.subtract(N)),S=l(I,M,d(0)),B=f(d(1).subtract(M).multiplyVec4(w).add(M.multiplyVec4(F))),H=v(g.cameraPosition.subtract(L)),z=v(c("nodeTangent")),G=a("width",1),O=v(T(z,H)).multiplyScalar(A.subtract(d(.5))).multiplyScalar(G),j=y(d(1).subtract(S).multiplyVec3(O).add(V(S,d(1)).multiplyVec3(L)),1),E=y(d(1).subtract(S).multiplyVec3(m.position).add(S.multiplyVec3(L)),1),R=g.projectionMatrix.multiply(g.viewMatrix).multiplyVec(j),q=g.projectionMatrix.multiply(g.viewMatrix).multiplyVec(E);export const trailUV=f(x(M.multiply(D.x),A.divide(C).multiply(D.y).multiply(2)));export const trailDragUV=f(x(U.divide(b).multiply(D.x),A.divide(C).multiply(D.y).multiply(2)));export class Trail extends t.Object3D{constructor(e,r){super(),this.nodeCenters=[],this.nodeIDs=[],this.advance=function(){const e=new t.Matrix4;return function(){this.targetObject.updateMatrixWorld(),e.copy(this.targetObject.matrixWorld),this.advanceWithTransform(e),this.updateUniforms()}}(),this.advanceGeometry=function(e,t){const r=this.currentEnd+1>=this.length?0:this.currentEnd+1;if(t?this.updateNodePositionsFromTransformMatrix(r,t):this.updateNodePositionsFromOrientationTangent(r,e.position,e.tangent),this.currentLength>=1&&(this.connectNodes(this.currentEnd,r),this.currentLength>=this.length)){const e=this.currentEnd+1>=this.length?0:this.currentEnd+1;this.disconnectNodes(e)}this.currentLength<this.length&&this.currentLength++,this.currentEnd++,this.currentEnd>=this.length&&(this.currentEnd=0),this.currentLength>=1&&(this.currentLength<this.length?this.geometry.setDrawRange(0,(this.currentLength-1)*this.FaceIndicesPerNode):this.geometry.setDrawRange(0,this.currentLength*this.FaceIndicesPerNode)),this.updateNodeID(this.currentEnd,this.currentNodeID),this.currentNodeID++},this.updateHead=function(){const e=new t.Matrix4;return function(){this.currentEnd<0||(this.targetObject.updateMatrixWorld(),e.copy(this.targetObject.matrixWorld),this.updateNodePositionsFromTransformMatrix(this.currentEnd,e))}}(),this.updateNodePositionsFromOrientationTangent=function(){const e=new t.Quaternion,r=new t.Vector3,i=[];for(let e=0;e<Trail.MaxHeadVertices;e++){const e=new t.Vector3;i.push(e)}return function(t,a,n){const s=this.geometry.getAttribute("position");this.updateNodeCenter(t,a),r.copy(a),r.sub(Trail.LocalHeadOrigin),e.setFromUnitVectors(Trail.LocalOrientationTangent,n);for(let t=0;t<this.localHeadGeometry.length;t++){const a=i[t];a.copy(this.localHeadGeometry[t]),a.applyQuaternion(e),a.add(r)}for(let e=0;e<this.localHeadGeometry.length;e++){const r=(this.VerticesPerNode*t+e)*Trail.PositionComponentCount,a=i[e];s.array[r]=a.x,s.array[r+1]=a.y,s.array[r+2]=a.z}s.needsUpdate=!0}}(),this.updateNodePositionsFromTransformMatrix=function(){const e=new t.Matrix3,r=new t.Quaternion,i=new t.Vector3,a=new t.Vector3,n=new t.Vector3,s=new t.Vector3,o=new t.Box3,h=new t.Vector3,c=[];for(let e=0;e<Trail.MaxHeadVertices;e++){const e=new t.Vector3;c.push(e)}const l=new t.Vector3(1,0,0);return function(d,u){const m=this.geometry.getAttribute("position");i.set(0,0,0),i.applyMatrix4(u),this.updateNodeCenter(d,i);for(let e=0;e<this.localHeadGeometry.length;e++){c[e].copy(this.localHeadGeometry[e])}for(let e=0;e<this.localHeadGeometry.length;e++){c[e].applyMatrix4(u)}if(this.lastNodeCenter&&this.orientToMovement&&(function(e,t){const r=t.elements;e.set(r[0],r[1],r[2],r[4],r[5],r[6],r[8],r[9],r[10])}(e,u),n.set(0,0,-1),n.applyMatrix3(e),s.copy(this.currentNodeCenter),s.sub(this.lastNodeCenter),s.normalize(),s.lengthSq()<=1e-4&&this.lastOrientationDir&&s.copy(this.lastOrientationDir),s.lengthSq()>1e-4)){this.lastOrientationDir||(this.lastOrientationDir=new t.Vector3),r.setFromUnitVectors(n,s),a.copy(this.currentNodeCenter);for(let e=0;e<this.localHeadGeometry.length;e++){const t=c[e];t.sub(a),t.applyQuaternion(r),t.add(a)}}this.lastNodeCenter&&this.currentNodeCenter&&this.billboard&&!this.currentNodeCenter.equals(this.lastNodeCenter)&&(l.copy(this.currentNodeCenter).sub(this.lastNodeCenter),l.normalize());const g=this.geometry.getAttribute("nodeTangent");for(let e=0;e<this.localHeadGeometry.length;e++){const t=(this.VerticesPerNode*d+e)*Trail.PositionComponentCount,r=c[e];this.billboard?(g.array[t]=l.x,g.array[t+1]=l.y,g.array[t+2]=l.z):(m.array[t]=r.x,m.array[t+1]=r.y,m.array[t+2]=r.z)}this.billboard?(this.mesh.frustumCulled=!1,g.needsUpdate=!0,g.updateRange={offset:d*this.VerticesPerNode*3,count:3*this.VerticesPerNode}):(m.needsUpdate=!0,m.addUpdateRange(d*this.VerticesPerNode*Trail.PositionComponentCount,this.VerticesPerNode*Trail.PositionComponentCount)),o.makeEmpty();for(let e=0;e<this.currentLength*this.VerticesPerNode;e++){const t=3*e;h.set(m.array[t],m.array[t+1],m.array[t+2]),o.expandByPoint(h)}this.mesh.visible=!o.isEmpty(),null==this.geometry.boundingBox&&(this.geometry.boundingBox=new t.Box3),this.geometry.boundingBox.copy(o),null==this.geometry.boundingSphere&&(this.geometry.boundingSphere=new t.Sphere),this.geometry.boundingBox.getBoundingSphere(this.geometry.boundingSphere)}}(),this.connectNodes=(()=>{const e={attribute:null,offset:0,count:-1};return(t,r)=>{const i=this.geometry.getIndex();for(let e=0;e<this.localHeadGeometry.length-1;e++){const a=this.VerticesPerNode*t+e,n=this.VerticesPerNode*r+e,s=(t*this.FacesPerNode+e*Trail.FacesPerQuad)*Trail.IndicesPerFace;i.array[s]=a,i.array[s+1]=n,i.array[s+2]=a+1,i.array[s+3]=n,i.array[s+4]=n+1,i.array[s+5]=a+1}return i.needsUpdate=!0,i.clearUpdateRanges(),e.attribute=i,e.offset=t*this.FacesPerNode*Trail.IndicesPerFace,e.count=this.FacesPerNode*Trail.IndicesPerFace,e}})(),this.disconnectNodes=(()=>{const e={attribute:null,offset:0,count:-1};return t=>{const r=this.geometry.getIndex();for(let e=0;e<this.localHeadGeometry.length-1;e++){const i=(t*this.FacesPerNode+e*Trail.FacesPerQuad)*Trail.IndicesPerFace;r.array[i]=0,r.array[i+1]=0,r.array[i+2]=0,r.array[i+3]=0,r.array[i+4]=0,r.array[i+5]=0}return r.needsUpdate=!0,r.clearUpdateRanges(),e.attribute=r,e.offset=t*this.FacesPerNode*Trail.IndicesPerFace,e.count=this.FacesPerNode*Trail.IndicesPerFace,e}})(),this.active=!1,this.orientToMovement=!1,r&&(this.orientToMovement=!0),this.scene=e,this.geometry=null,this.mesh=null,this.nodeCenters=[],this.lastNodeCenter=null,this.currentNodeCenter=null,this.lastOrientationDir=null,this.nodeIDs=[],this.currentLength=0,this.currentEnd=0,this.currentNodeID=0,this.advanceFrequency=60,this.advancePeriod=1/this.advanceFrequency,this.lastAdvanceTime=0,this.paused=!1,this.pauseAdvanceUpdateTimeDiff=0}setAdvanceFrequency(e){this.advanceFrequency=e,this.advancePeriod=1/this.advanceFrequency}initialize(e,r,i,a,n,s,o=!1){this.deactivate(),this.destroyMesh(),this.length=r>0?r+1:0,this.dragTexture=i?1:0,this.targetObject=s,this.billboard=o,this.initializeLocalHeadGeometry(a,n),null!=e.uniforms.width&&(e.uniforms.width.value=a),this.nodeIDs=[],this.nodeCenters=[];for(let e=0;e<this.length;e++)this.nodeIDs[e]=-1,this.nodeCenters[e]=new t.Vector3;this.material=e,this.initializeGeometry(),this.initializeMesh(),this.material.uniforms.dragTexture&&(this.material.uniforms.trailLength.value=0),this.material.uniforms.minID.value=0,this.material.uniforms.maxID.value=0,this.material.uniforms.dragTexture&&(this.material.uniforms.dragTexture.value=this.dragTexture),this.material.uniforms.maxTrailLength&&(this.material.uniforms.maxTrailLength.value=this.length),this.material.uniforms.verticesPerNode&&(this.material.uniforms.verticesPerNode.value=this.VerticesPerNode),this.material.uniforms.textureTileFactor&&(this.material.uniforms.textureTileFactor.value=new t.Vector2(1,1)),this.material.uniforms.scale&&(this.material.uniforms.scale.value=1),this.reset()}initializeLocalHeadGeometry(e,r){if(this.localHeadGeometry=[],r){this.VerticesPerNode=0;for(let e=0;e<r.length&&e<Trail.MaxHeadVertices;e++){const i=r[e];if(i&&i instanceof t.Vector3){const e=new t.Vector3;e.copy(i),this.localHeadGeometry.push(e),this.VerticesPerNode++}}}else{const r=(e||1)/2;this.localHeadGeometry.push(new t.Vector3(-r,0,0)),this.localHeadGeometry.push(new t.Vector3(r,0,0)),this.VerticesPerNode=2}this.FacesPerNode=2*(this.VerticesPerNode-1),this.FaceIndicesPerNode=3*this.FacesPerNode}initializeGeometry(){this.vertexCount=this.length*this.VerticesPerNode,this.faceCount=this.length*this.FacesPerNode;const e=new t.BufferGeometry,r=new Float32Array(this.vertexCount),i=new Float32Array(this.vertexCount*this.VerticesPerNode),a=new Float32Array(this.vertexCount*Trail.PositionComponentCount),n=new Float32Array(this.vertexCount*Trail.PositionComponentCount),s=new Float32Array(this.vertexCount*Trail.UVComponentCount),o=new Uint32Array(this.faceCount*Trail.IndicesPerFace),h=new Float32Array(3*this.vertexCount),c=new t.BufferAttribute(h,3);c.setUsage(t.DynamicDrawUsage),e.setAttribute("nodeTangent",c);const l=new t.BufferAttribute(r,1);l.setUsage(t.DynamicDrawUsage),e.setAttribute("nodeID",l);const d=new t.BufferAttribute(i,1);d.setUsage(t.DynamicDrawUsage),e.setAttribute("nodeVertexID",d);const u=new t.BufferAttribute(n,Trail.PositionComponentCount);u.setUsage(t.DynamicDrawUsage),e.setAttribute("nodeCenter",u);const m=new t.BufferAttribute(a,Trail.PositionComponentCount);m.setUsage(t.DynamicDrawUsage),e.setAttribute("position",m);const g=new t.BufferAttribute(s,Trail.UVComponentCount);g.setUsage(t.DynamicDrawUsage),e.setAttribute("uv",g);const p=new t.BufferAttribute(o,1);p.setUsage(t.DynamicDrawUsage),e.setIndex(p),this.geometry=e}zeroVertices(){const e=this.geometry.getAttribute("position");for(let t=0;t<this.vertexCount;t++){const r=3*t;e.array[r]=0,e.array[r+1]=0,e.array[r+2]=0}e.needsUpdate=!0}zeroIndices(){if(null==this.geometry)throw"Geometry not initialized";const e=this.geometry.getIndex();for(let t=0;t<this.faceCount;t++){const r=3*t;e.array[r]=0,e.array[r+1]=0,e.array[r+2]=0}e.needsUpdate=!0,e.clearUpdateRanges()}formInitialFaces(){this.zeroIndices();const e=this.geometry.getIndex();for(let e=0;e<this.length-1;e++)this.connectNodes(e,e+1);e.needsUpdate=!0,e.clearUpdateRanges()}initializeMesh(){if(null==this.geometry)throw"Geometry not initialized";this.mesh=new t.Mesh(this.geometry,this.material),this.mesh.matrixAutoUpdate=!1}destroyMesh(){this.mesh&&(this.scene.remove(this.mesh),this.mesh=null)}reset(){this.currentLength=0,this.currentEnd=-1,this.lastNodeCenter=null,this.currentNodeCenter=null,this.lastOrientationDir=null,this.currentNodeID=0,this.formInitialFaces(),this.zeroVertices(),this.geometry.setDrawRange(0,0)}updateUniforms(){this.currentLength<this.length?this.material.uniforms.minID.value=0:this.material.uniforms.minID.value=this.currentNodeID-this.length,this.material.uniforms.maxID.value=this.currentNodeID,this.material.uniforms.trailLength&&(this.material.uniforms.trailLength.value=this.currentLength),this.material.uniforms.maxTrailLength&&(this.material.uniforms.maxTrailLength.value=this.length),this.material.uniforms.verticesPerNod&&(this.material.uniforms.verticesPerNode.value=this.VerticesPerNode)}advanceWithPositionAndOrientation(e,t){this.advanceGeometry({position:e,tangent:t},null)}advanceWithTransform(e){this.advanceGeometry(null,e)}currentTime(){return performance.now()/1e3}pause(){this.paused||(this.paused=!0,this.pauseAdvanceUpdateTimeDiff=this.currentTime()-this.lastAdvanceTime)}resume(){this.paused&&(this.paused=!1,this.lastAdvanceTime=this.currentTime()-this.pauseAdvanceUpdateTimeDiff)}update(){if(!this.paused){const e=this.currentTime();this.lastAdvanceTime||(this.lastAdvanceTime=e),e-this.lastAdvanceTime>this.advancePeriod?(this.advance(),this.lastAdvanceTime=e):this.updateHead()}}updateNodeID(e,t){this.nodeIDs[e]=t;const r=this.geometry.getAttribute("nodeID"),i=this.geometry.getAttribute("nodeVertexID");for(let a=0;a<this.VerticesPerNode;a++){const n=e*this.VerticesPerNode+a;r.array[n]=t,i.array[n]=a}r.needsUpdate=!0,i.needsUpdate=!0,r.addUpdateRange(e*this.VerticesPerNode,this.VerticesPerNode),i.addUpdateRange(e*this.VerticesPerNode,this.VerticesPerNode)}updateNodeCenter(e,t){this.lastNodeCenter=this.currentNodeCenter,this.currentNodeCenter=this.nodeCenters[e],this.currentNodeCenter.copy(t);const r=this.geometry.getAttribute("nodeCenter");for(let i=0;i<this.VerticesPerNode;i++){const a=3*(e*this.VerticesPerNode+i);r.array[a]=t.x,r.array[a+1]=t.y,r.array[a+2]=t.z}r.needsUpdate=!0,r.updateRanges=[{start:e*this.VerticesPerNode*Trail.PositionComponentCount,count:this.VerticesPerNode*Trail.PositionComponentCount}]}deactivate(){this.active&&(this.scene.remove(this.mesh),this.active=!1)}activate(){this.active||(this.scene.add(this.mesh),this.active=!0)}static getTrailShaderNodes(e){return{position:e?R:q,color:B,fraction:M}}static applyTrailShaderParameters(e){e.transparent=!0,e.alphaTest=.5,e.blending=t.CustomBlending,e.blendSrc=t.SrcAlphaFactor,e.blendDst=t.OneMinusSrcAlphaFactor,e.blendEquation=t.AddEquation,e.depthTest=!0,e.depthWrite=!1,e.side=t.DoubleSide}static createBaseMaterial(t,i,a,n=!1){let{position:o}=Trail.getTrailShaderNodes(n),h=s(w,F,M).rgba;if(null!=t){let r=trailUV;null!=i&&(r=r.add(x(e.elapsed.multiply(-i),0)));const n=u(t).sample(r);let s=h.a;switch(a??"red"){case"none":break;case"red":s=s.multiply(n.r);break;case"alpha":s=s.multiply(n.a)}h=p(h.rgb.multiply(n.rgb),s)}const c=new r({position:o,color:h});return Trail.applyTrailShaderParameters(c),c}static get MaxHeadVertices(){return 128}static get LocalOrientationTangent(){return Trail._LocalOrientationTangent}static get LocalHeadOrigin(){return Trail._LocalHeadOrigin}static get PositionComponentCount(){return 3}static get UVComponentCount(){return 2}static get IndicesPerFace(){return 3}static get FacesPerQuad(){return 2}}Trail._LocalOrientationTangent=new t.Vector3(1,0,0),Trail._LocalHeadOrigin=new t.Vector3(0,0,0),Trail.Shader={get BaseVertexVars(){return["attribute float nodeID;","attribute float nodeVertexID;","attribute vec3 nodeCenter;","uniform float minID;","uniform float maxID;","uniform float trailLength;","uniform float maxTrailLength;","uniform float verticesPerNode;","uniform vec2 textureTileFactor;","uniform bool taper;","uniform vec4 headColor;","uniform vec4 tailColor;","varying vec4 vColor;"].join("\n")},get TexturedVertexVars(){return[this.BaseVertexVars,"varying vec2 vUV;","uniform float dragTexture;"].join("\n")},BaseFragmentVars:["varying vec4 vColor;","uniform sampler2D trailTexture;"].join("\n"),get TexturedFragmentVars(){return[this.BaseFragmentVars,"varying vec2 vUV;"].join("\n")},get VertexShaderCore(){return["float fraction = (maxID - nodeID) / (maxID - minID);","float fractionSize = taper ? fraction : 0.0;","vColor = (1.0 - fraction) * headColor + fraction * tailColor;","vec4 realPosition = vec4((1.0 - fractionSize) * position.xyz + fractionSize * nodeCenter.xyz, 1.0); "].join("\n")},get BaseVertexShader(){return[this.BaseVertexVars,"void main() { ",this.VertexShaderCore,"gl_Position = projectionMatrix * viewMatrix * realPosition;","}"].join("\n")},get BaseFragmentShader(){return[this.BaseFragmentVars,"void main() { ","gl_FragColor = vColor;","}"].join("\n")},get TexturedVertexShader(){return[this.TexturedVertexVars,"void main() { ",this.VertexShaderCore,"float s = 0.0;","float t = 0.0;","if (dragTexture == 1.0) { "," s = fraction * textureTileFactor.s; "," t = (nodeVertexID / verticesPerNode) * textureTileFactor.t;","} else { "," s = nodeID / maxTrailLength * textureTileFactor.s;"," t = (nodeVertexID / verticesPerNode) * textureTileFactor.t;","}","vUV = vec2(s, t); ","gl_Position = projectionMatrix * viewMatrix * realPosition;","}"].join("\n")},get TexturedFragmentShader(){return[this.TexturedFragmentVars,"void main() { ","vec4 textureColor = texture2D(trailTexture, vUV);","gl_FragColor = vColor * textureColor;","}"].join("\n")}};/*
2
2
  * Copyright (©) 2023. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -90,6 +90,7 @@ export type TrailOutput = {
90
90
  bloom: boolean;
91
91
  scrollSpeed?: number;
92
92
  width?: number;
93
+ billboard?: boolean;
93
94
  } & CommonOutput & Partial<OutputCustomShader> & OutputTextureSetting;
94
95
  export type ShapeOutput = {
95
96
  type: 'shape';
@@ -1 +1 @@
1
- {"version":3,"file":"vfx-asset.d.ts","sourceRoot":"","sources":["../../../src/effects/vfx/vfx-asset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAA0B,MAAM,eAAe,CAAC;AAM1G,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAA;IAEZ,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AACD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,YAAY,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AACD,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAC,kBAAkB,CAAA;AAEtD,MAAM,MAAM,eAAe,GAAG;IAC5B,E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AAM,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;CACtD,CAAA;AAGD,wBAAsB,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,gBAAgB,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc;;;;GAyDpL;AAgxBD,qBAAa,WAAW,CAAC,CAAC;IAIZ,OAAO,CAAC,OAAO;IAF3B,SAAS,EAAE,CAAC,EAAE,CAAK;gBAEC,OAAO,EAAE,MAAM,CAAC;IAEpC;;;OAGG;IACH,GAAG,IAAI,CAAC;IAQR;;;OAGG;IACH,OAAO,CAAC,QAAQ,EAAE,CAAC;IAMnB,OAAO;CAGR"}
@@ -1,4 +1,4 @@
1
- import e,{Behaviour as t,Body as i,Emitter as n,Rate as s}from"@hology/nebula";import*as a from"three";import{Object3D as o}from"three";import{AttributeVec3Node as r,AttributeVec4Node as l,NodeShaderMaterial as c,RgbNode as m,UniformFloatNode as u,UniformVec3Node as p,Vec3ExpressionNode as h,Vec4Node as d,attributeFloat as f,attributeVec3 as y,attributeVec4 as g,attributes as w,float as v,glslFunction as b,lambertMaterial as x,log as A,pow as E,rgb as M,rgba as P,saturate as T,standardMaterial as I,textureSampler2d as C,transformed as B,uniformFloat as R,uniforms as k,varying as S,varyingAttributes as j,varyingVec3 as z,varyingVec4 as V}from"three-shader-graph";import{prepareClassParameters as D,prepareShapeParameters as F}from"../../scene/materializer.js";import{SerializedParamType as Q}from"../../scene/model.js";import{ShapeLibrary as U}from"../../scene/objects/shapes.js";import{fragmentLinearEyeDepth as W,linearEyeDepth as L}from"../../shader-nodes/depth.js";import{particleEnergyUniformName as q,particleTimeUniformName as H,particleUniforms as G,particleVelcoityUniformName as J}from"../../shader-nodes/particle.js";import{sampleFlipbook as O}from"../../shader-nodes/texture-sequence.js";import{DefaultInitializer as N}from"./initializsers.js";import{DelayRate as K,OnceRate as X}from"./rates.js";import{StretchedSprite as Y}from"./stretched-sprite.js";import{ThreeBlendingMode as Z}from"./vfx-asset.js";import{VfxBehaviourLibrary as _,VfxInitializserLibrary as $}from"./vfx-defs.js";import{MultiRenderer as ee}from"./vfx-renderers.js";import{WorldCollisionBehaviour as te}from"./vfx-collision-behaviour.js";import{SpriteNodeShaderMaterial as ie}from"../../shader/sprite-shader.js";export async function materializeVfx(t,i,n,s,r,l){let c=i;for(;null!=c.parent;)c=c.parent;const m=new o;m.name="particle system local",i.add(m);const u=new o;u.name="particle system world",c.add(u);const p=new ee(u,m,a,s),h=new e;return(await Promise.all(t.vfx.emitters.map((async e=>{const t=await ne(e,n,h,r,l);return t.setParentRecursive(h),t.emit()})))).forEach((e=>h.addEmitter(e))),h.addRenderer(p).emit({onEnd:()=>{}}),{container:u,system:h,dispose:()=>{u.removeFromParent(),m.removeFromParent(),p.dispose()}}}async function ne(e,t,n,m,z){const D=function(e){let t;switch(e.rate.type){case"continuous":t=new K(e.rate.delay??0,e.rate.count,e.rate.time);break;case"once":t=new X(e.rate.delay??0,e.rate.count);break;default:console.warn(`Failed to configure rate for emitter: ${JSON.stringify(e)}`),t=new s(0,1/0)}return t}(e);let q;switch(e.output.type){case"sprite":q=new i(await async function(e,t,i){let n=null;n=null!=e.shader?await ae(e,t,i):await async function(e,t){const i=null!=e.texture?await t.getTexture(e.texture):se,n=C(i);let s=n.sample(j.uv);e.flipbook?.enabled&&(s=O(n,w.uv,e.flipbook.columns,e.flipbook.rows,G.time,e.flipbook.fps,e.flipbook.mode));const o=new u("rotation",0),r=new p("color").rgb,l=R("opacity",1),c=L.subtract(W).divide(L);let m=l;switch(e.opacityChannel??"red"){case"none":break;case"red":m=m.multiply(s.r);break;case"alpha":m=m.multiply(s.a)}if("number"==typeof e.softness&&e.softness>0){const t=E(c,v(e.softness));m=m.multiply(t)}const h=b(d,{position:B.position,modelViewMatrix:k.modelViewMatrix,rotation:o},"\n vec2 center = vec2(0.5, 0.5);\n vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n // Using scale form instance matrix instead of modelMatrix\n vec2 scale;\n scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\n // This times 2 on scale seem to make it appear like when using regular sprites. \n // Not sure if this is correct though.\n vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * (scale);\n\n vec2 rotatedPosition;\n rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\n mvPosition.xy += rotatedPosition;\n return projectionMatrix * mvPosition;\n ");var f=new ie({color:P(r.multiply(s.rgb).multiplyScalar(e.intensity??1),m),transparent:!0,position:h,uniforms:{color:{value:new a.Color(e.color)}}});null!=f&&!0===e.bloom&&(f.userData.hasBloom=!0);return f.blending=Z[e.blendingMode]??a.NormalBlending,f}(e,t);const s=new a.Mesh(new a.PlaneGeometry(1,1),n);return s.name="sprite",s}(e.output,t,z));break;case"stretchedSprite":q=new i(await async function(e,t){const i=null!=e.texture?await t.getTexture(e.texture):se,n=C(i).sample(j.uv),s=V(new l("color")),o=s.rgb.multiply(n.rgb);let r=s.w;switch(e.opacityChannel??"red"){case"none":break;case"red":r=r.multiply(n.r);break;case"alpha":r=r.multiply(n.a)}if("number"==typeof e.softness&&e.softness>0){const t=L.subtract(W).divide(A(L)),i=E(t,v(e.softness));r=T(r.multiply(i))}const c=b(d,{position:w.position,offset:y("offset"),modelViewMatrix:k.modelViewMatrix,velocity:g("velocity"),size:y("size"),rotation:f("rotation")},"\n float lengthFactor = velocity.w;\n float avgSize = (size.x + size.y) * 0.5;\n\n vec4 mvPosition = modelViewMatrix * vec4( offset , 1.0 );\n vec3 viewVelocity = normalMatrix * velocity.xyz;\n float vlength = length(viewVelocity); \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 return projectionMatrix * mvPosition;\n ");var m=new ie({color:P(o.multiplyScalar(e.intensity??1),r),alphaTest:.1,transparent:!0,position:c,uniforms:{color:{value:new a.Color(e.color)}}});null!=m&&!0===e.bloom&&(m.userData.hasBloom=!0);m.blending=Z[e.blendingMode]??a.NormalBlending;const u=new Y(new a.PlaneGeometry(1,1),m);return u.scaleFactor=e.scale,u}(e.output,t));break;case"shape":q=new i(await async function(e,t,i){if(null==e.shape)return console.log("Shape is null"),new o;const n=U[e.shape];if(null==n)return console.error(`No shape with type ${e.shape}`),new o;const s=F(e.params??{}),l=n.geometry(s);let m=null;m=null!=e.shader?await ae(e,t,i):null!=e.material?function(e){const t=S(new h("instanceColor")).rgb;let i,n=S(new r("particleData")).x;if(e instanceof a.MeshStandardMaterial||e instanceof a.MeshLambertMaterial||e instanceof a.MeshBasicMaterial){let s=t.multiply(M(e.color));null!=e.map&&(s=s.multiply(C(e.map).sample(j.uv).rgb)),null!=e.alphaMap&&(n=n.multiply(C(e.alphaMap).sample(j.uv).r)),e instanceof a.MeshStandardMaterial?i=new c({color:I({color:s,emissive:M(e.emissive),emissiveIntensity:v(e.emissiveIntensity),roughness:e.roughness,metalness:e.metalness}).rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}):e instanceof a.MeshLambertMaterial?i=new c({color:x({color:s}).rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}):e instanceof a.MeshBasicMaterial&&(i=new c({color:s.rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}))}null!=i&&(!0===e.userData?.hasBloom&&null!=i&&(i.userData.hasBloom=!0),i.side=e.side,i.transparent=e.transparent);return i??e}(await t.getMaterial(e.material)):function(){const e=S(new h("instanceColor")).rgb,t=S(new r("particleData")).x;return new c({color:x({color:e}).rgb.rgba(t),transparent:!0})}();null!=m&&!0===e.bloom&&(m.userData.hasBloom=!0);return new a.Mesh(l,m)}(e.output,t,z));break;case"mesh":q=new i(await async function(e,t,i){if(null==e.assetId)return console.warn("Can't use mesh as particle without asset id"),new o;const n=await t.getMesh(e.assetId),s=await t.getAsset(e.assetId);if(null!=e.shader){const s=await ae(e,t,i);null!=s&&!0===e.bloom&&(s.userData.hasBloom=!0),n.traverse((e=>{e instanceof a.Mesh&&(e.material=s)}))}else{const e=[];if(null!=s.materialAssignments)for(const i of s.materialAssignments)n.traverse((n=>{n instanceof a.Mesh&&n.material instanceof a.Material&&n.material.color instanceof a.Color&&(n.material.name!=i.name&&null!=i.name||"#"+n.material.color.getHexString()!==i.color||e.push(t.getMaterial(i.materialId).then((e=>n.material=e))))}));await Promise.all(e)}const r=[];if(n.traverse((e=>{e instanceof a.Mesh&&r.push(e)})),1===r.length){const e=r[0];return e.updateWorldMatrix(!0,!0),e.updateMatrixWorld(),e.matrix.copy(e.matrixWorld),e.matrixWorld.decompose(e.position,e.quaternion,e.scale),e.removeFromParent(),e}return n}(e.output,t,z));break;case"trail":q=new i({type:"trail",taper:e.output.taper,headGeometry:null,dragTexture:!1,texture:null!=e.output.texture?await t.getTexture(e.output.texture):null,opacityChannel:e.output.opacityChannel,color:e.output.color,colorEnd:e.output.colorEnd,intensity:e.output.intensity??1,intensityEnd:e.output.intensityEnd??1,length:e.output.length,opacityStart:e.output.opacityStart,opacityEnd:e.output.opacityEnd,bloom:e.output.bloom,scrollSpeed:e.output.scrollSpeed,width:e.output.width});break;default:console.error("Failed to create particly system body: "+JSON.stringify(e))}const H=new re;H.parent=n,H.setRate(D),H._space=e.output.space;const J=await Promise.all(e.initializers.filter((e=>null!=$[e.type])).map((async e=>{const t=$[e.type],i=await F(e.params??{});return t.build(i)})));J.push(q,new N),H.addInitializers(J);const ee=await Promise.all(e.behaviours.filter((e=>null!=_[e.type])).map((async e=>{const t=_[e.type];for(const[i,n]of Object.entries(e.params))t.parameters&&null!=t.parameters[i]&&"curve"===t.parameters[i].type&&n.type!==Q.Curve&&(n.type=Q.Curve);const i=await F(e.params??{});return t.build(i)})).sort(((e,t)=>e instanceof te?1:0)));ee.push(new oe);for(const e of ee)e instanceof te&&(e.physics=m);H.addBehaviours(ee);for(const i of e.children){const e=await ne(i,t,n,m,z),s=new EmitterPool((()=>{const t=e.clone();return t.onExpired=()=>{const e=H.childEmitters.findIndex((e=>e.id===t.id));-1!=e&&H.childEmitters.splice(e,1),s.release(t)},t})),a=H.eventDispatcher,o=new Map;H.bindEmitterEvent=!0,a.addEventListener("PARTICLE_DEAD",(e=>{const t=o.get(e.id);if(null!=t){const e=H.childEmitters.findIndex((e=>e.id===t.id));null!=e&&(t.stopEmit(),H.childEmitters.splice(e,1))}}));let r="PARTICLE_CREATED";if("spawnEvent"in i)switch(i.spawnEvent){case"collision":r="PARTICLE_COLLISION";break;case"start":r="PARTICLE_CREATED"}a.addEventListener(r,(e=>{const t=s.get();t.age=0,t.totalEmitTimes=-1,t.particles.length=0,t.currentEmitTime=0,t.cID=0,t.eventDispatcher.removeAllEventListeners(),H.childEmitters.push(t),o.set(e.id,t),t.parentParticle=e,t.system=H.system,t.emit()}))}return H}const se=(new a.TextureLoader).load("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJkSURBVHjaxJeJbusgEEW94S1L//83X18M2MSuLd2pbqc4wZGqRLrKBsyZhQHny7Jk73xVL8xpVhWrcmiB5lX+6GJ5YgQ2owbAm8oIwH1VgKZUmGcRqKGGPgtEQQAzGR8hQ59fAmhJHSAagigJ4E7GPWRXOYC6owAd1JM6wDQPADyMWUqZRMqmAojHp1Vn6EQQEgUNMJLnUjMyJsM49wygBkAPw9dVFwXRkncCIIW3GRgoTQUZn6HxCMAFEFd8TwEQ78X4rHbILoAUmeT+RFG4UhQ6MiIAE4W/UsYFjuVjAIa2nIY4q1R0GFtQWG3E84lqw2GO2QOoCKBVu0BAPgDSU0eUDjjQenNkV/AW/pWChhpMTelo1a64AOKM30vk18GzTHXCNtI/Knz3DFBgsUqBGIjTInXRY1yA9xkVoqW5tVq3pDR9A0hfF5BSARmVnh7RMDCaIdcNgbPBkgzn1Bu+SfIEFSpSBmkxyrMicb0fAEuCZrWnN89veA/4XcakrPcjBWzkTuLjlbfTQPOlBhz+HwkqqPXmPQDdrQItxE1moGof1S74j/8txk8EHhTQrAE8qlwfqS5yukm1x/rAJ9Jiaa6nyATqD78aUVBhFo8b1V4DdTXdCW+IxA1zB4JhiOhZMEWO1HqnvdoHZ4FAMIhV9REF8FiUm0jsYPEJx/Fm/N8OhH90HI9YRHesWbXXZwAShU8qThe7H8YAuJmw5yOd989uRINKRTJAhoF8jbqrHKfeCYdIISZfSq26bk/K+yO3YvfKrVgiwQBHnwt8ynPB25+M8hceTt/ybPhnryJ78+tLgAEAuCFyiQgQB30AAAAASUVORK5CYII=");async function ae(e,t,i){const n=i.get(e.shader);if(null==n)return console.error("No shader exists with name "+e.shader),new a.Material;const s=new n.type,o=await D(e.shaderParams,n.type,t,{getTexture:e=>t.getTexture(e.id),getMaterial:e=>t.getMaterial(e.id),getMesh:e=>t.getMesh(e.id)},void 0,void 0,void 0,void 0);return Object.assign(s,o),s.build()}class oe extends t{initialize(e){e.body instanceof a.Object3D&&e.body.traverse((e=>{if(e instanceof a.Mesh){const t=e.material;t instanceof c&&(null!=t.uniforms[q]||null!=t.uniforms[H]||t.uniforms[J])}}))}mutate(e,t,i){this.energize(e,t),e.target instanceof o&&e.target.traverse((t=>{if(t instanceof a.Mesh){const i=t.material;i instanceof c&&(null!=i.uniforms[q]&&(i.uniforms[q].value=this.energy),null!=i.uniforms[H]&&(i.uniforms[H].value=e.age),null!=i.uniforms[J]&&(i.uniforms[J].value=e.velocity))}}))}}class re extends n{constructor(){super(...arguments),this.childEmitters=[],this.bindEmitterEvent=!1,this.onExpired=()=>{}}update(e){if(!this.isEmitting&&0===this.particles.length)return;this.age+=e,(this.dead||this.age>=this.life)&&this.destroy(),this.generate(e),this.integrate(e);let t=this.particles.length;for(;t--;){const e=this.particles[t];e.dead&&(this.system&&this.system.dispatch("PARTICLE_DEAD",e),this.bindEmitterEvent&&this.dispatch("PARTICLE_DEAD",e),this.system.pool.expire(e.reset()),this.particles.splice(t,1))}this.updateEmitterBehaviours(e),this.updateChildren(e),this.isEmitting||0!==this.particles.length||this.onExpired()}updateChildren(e){for(const t of this.childEmitters)null!=t.parentParticle?t.position.copy(t.parentParticle.position):t.setPosition(this.position),t.update(e)}clone(){const e=new re;return e.setRate(this.rate.clone()),e.behaviours=this.behaviours,e.initializers=this.initializers,e._space=this._space,e.body=this.body,e.parent=this.parent,e.system=this.system,e}setParentRecursive(e){this.system=e,this.childEmitters.forEach((t=>t.setParentRecursive(e)))}}export class EmitterPool{constructor(e){this.creator=e,this.instances=[]}get(){0==this.instances.length&&this.instances.push(this.creator());return this.instances.pop()}release(e){this.instances.push(e)}dispose(){this.instances.length=0}}/*
1
+ import e,{Behaviour as t,Body as i,Emitter as n,Rate as s}from"@hology/nebula";import*as a from"three";import{Object3D as o}from"three";import{AttributeVec3Node as r,AttributeVec4Node as l,NodeShaderMaterial as c,RgbNode as u,UniformFloatNode as m,UniformVec3Node as p,Vec3ExpressionNode as h,Vec4Node as d,attributeFloat as f,attributeVec3 as y,attributeVec4 as g,attributes as w,float as v,glslFunction as b,lambertMaterial as x,log as A,pow as E,rgb as M,rgba as P,saturate as T,standardMaterial as I,textureSampler2d as C,transformed as B,uniformFloat as R,uniforms as k,varying as S,varyingAttributes as j,varyingVec3 as z,varyingVec4 as V}from"three-shader-graph";import{prepareClassParameters as D,prepareShapeParameters as F}from"../../scene/materializer.js";import{SerializedParamType as Q}from"../../scene/model.js";import{ShapeLibrary as U}from"../../scene/objects/shapes.js";import{fragmentLinearEyeDepth as W,linearEyeDepth as L}from"../../shader-nodes/depth.js";import{particleEnergyUniformName as q,particleTimeUniformName as H,particleUniforms as G,particleVelcoityUniformName as J}from"../../shader-nodes/particle.js";import{sampleFlipbook as O}from"../../shader-nodes/texture-sequence.js";import{DefaultInitializer as N}from"./initializsers.js";import{DelayRate as K,OnceRate as X}from"./rates.js";import{StretchedSprite as Y}from"./stretched-sprite.js";import{ThreeBlendingMode as Z}from"./vfx-asset.js";import{VfxBehaviourLibrary as _,VfxInitializserLibrary as $}from"./vfx-defs.js";import{MultiRenderer as ee}from"./vfx-renderers.js";import{WorldCollisionBehaviour as te}from"./vfx-collision-behaviour.js";import{SpriteNodeShaderMaterial as ie}from"../../shader/sprite-shader.js";export async function materializeVfx(t,i,n,s,r,l){let c=i;for(;null!=c.parent;)c=c.parent;const u=new o;u.name="particle system local",i.add(u);const m=new o;m.name="particle system world",c.add(m);const p=new ee(m,u,a,s),h=new e;return(await Promise.all(t.vfx.emitters.map((async e=>{const t=await ne(e,n,h,r,l);return t.setParentRecursive(h),t.emit()})))).forEach((e=>h.addEmitter(e))),h.addRenderer(p).emit({onEnd:()=>{}}),{container:m,system:h,dispose:()=>{m.removeFromParent(),u.removeFromParent(),p.dispose()}}}async function ne(e,t,n,u,z){const D=function(e){let t;switch(e.rate.type){case"continuous":t=new K(e.rate.delay??0,e.rate.count,e.rate.time);break;case"once":t=new X(e.rate.delay??0,e.rate.count);break;default:console.warn(`Failed to configure rate for emitter: ${JSON.stringify(e)}`),t=new s(0,1/0)}return t}(e);let q;switch(e.output.type){case"sprite":q=new i(await async function(e,t,i){let n=null;n=null!=e.shader?await ae(e,t,i):await async function(e,t){const i=null!=e.texture?await t.getTexture(e.texture):se,n=C(i);let s=n.sample(j.uv);e.flipbook?.enabled&&(s=O(n,w.uv,e.flipbook.columns,e.flipbook.rows,G.time,e.flipbook.fps,e.flipbook.mode));const o=new m("rotation",0),r=new p("color").rgb,l=R("opacity",1),c=L.subtract(W).divide(L);let u=l;switch(e.opacityChannel??"red"){case"none":break;case"red":u=u.multiply(s.r);break;case"alpha":u=u.multiply(s.a)}if("number"==typeof e.softness&&e.softness>0){const t=E(c,v(e.softness));u=u.multiply(t)}const h=b(d,{position:B.position,modelViewMatrix:k.modelViewMatrix,rotation:o},"\n vec2 center = vec2(0.5, 0.5);\n vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n // Using scale form instance matrix instead of modelMatrix\n vec2 scale;\n scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\n // This times 2 on scale seem to make it appear like when using regular sprites. \n // Not sure if this is correct though.\n vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * (scale);\n\n vec2 rotatedPosition;\n rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\n mvPosition.xy += rotatedPosition;\n return projectionMatrix * mvPosition;\n ");var f=new ie({color:P(r.multiply(s.rgb).multiplyScalar(e.intensity??1),u),transparent:!0,position:h,uniforms:{color:{value:new a.Color(e.color)}}});null!=f&&!0===e.bloom&&(f.userData.hasBloom=!0);return f.blending=Z[e.blendingMode]??a.NormalBlending,f}(e,t);const s=new a.Mesh(new a.PlaneGeometry(1,1),n);return s.name="sprite",s}(e.output,t,z));break;case"stretchedSprite":q=new i(await async function(e,t){const i=null!=e.texture?await t.getTexture(e.texture):se,n=C(i).sample(j.uv),s=V(new l("color")),o=s.rgb.multiply(n.rgb);let r=s.w;switch(e.opacityChannel??"red"){case"none":break;case"red":r=r.multiply(n.r);break;case"alpha":r=r.multiply(n.a)}if("number"==typeof e.softness&&e.softness>0){const t=L.subtract(W).divide(A(L)),i=E(t,v(e.softness));r=T(r.multiply(i))}const c=b(d,{position:w.position,offset:y("offset"),modelViewMatrix:k.modelViewMatrix,velocity:g("velocity"),size:y("size"),rotation:f("rotation")},"\n float lengthFactor = velocity.w;\n float avgSize = (size.x + size.y) * 0.5;\n\n vec4 mvPosition = modelViewMatrix * vec4( offset , 1.0 );\n vec3 viewVelocity = normalMatrix * velocity.xyz;\n float vlength = length(viewVelocity); \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 return projectionMatrix * mvPosition;\n ");var u=new ie({color:P(o.multiplyScalar(e.intensity??1),r),alphaTest:.1,transparent:!0,position:c,uniforms:{color:{value:new a.Color(e.color)}}});null!=u&&!0===e.bloom&&(u.userData.hasBloom=!0);u.blending=Z[e.blendingMode]??a.NormalBlending;const m=new Y(new a.PlaneGeometry(1,1),u);return m.scaleFactor=e.scale,m}(e.output,t));break;case"shape":q=new i(await async function(e,t,i){if(null==e.shape)return console.log("Shape is null"),new o;const n=U[e.shape];if(null==n)return console.error(`No shape with type ${e.shape}`),new o;const s=F(e.params??{}),l=n.geometry(s);let u=null;u=null!=e.shader?await ae(e,t,i):null!=e.material?function(e){const t=S(new h("instanceColor")).rgb;let i,n=S(new r("particleData")).x;if(e instanceof a.MeshStandardMaterial||e instanceof a.MeshLambertMaterial||e instanceof a.MeshBasicMaterial){let s=t.multiply(M(e.color));null!=e.map&&(s=s.multiply(C(e.map).sample(j.uv).rgb)),null!=e.alphaMap&&(n=n.multiply(C(e.alphaMap).sample(j.uv).r)),e instanceof a.MeshStandardMaterial?i=new c({color:I({color:s,emissive:M(e.emissive),emissiveIntensity:v(e.emissiveIntensity),roughness:e.roughness,metalness:e.metalness}).rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}):e instanceof a.MeshLambertMaterial?i=new c({color:x({color:s}).rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}):e instanceof a.MeshBasicMaterial&&(i=new c({color:s.rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}))}null!=i&&(!0===e.userData?.hasBloom&&null!=i&&(i.userData.hasBloom=!0),i.side=e.side,i.transparent=e.transparent);return i??e}(await t.getMaterial(e.material)):function(){const e=S(new h("instanceColor")).rgb,t=S(new r("particleData")).x;return new c({color:x({color:e}).rgb.rgba(t),transparent:!0})}();null!=u&&!0===e.bloom&&(u.userData.hasBloom=!0);return new a.Mesh(l,u)}(e.output,t,z));break;case"mesh":q=new i(await async function(e,t,i){if(null==e.assetId)return console.warn("Can't use mesh as particle without asset id"),new o;const n=await t.getMesh(e.assetId),s=await t.getAsset(e.assetId);if(null!=e.shader){const s=await ae(e,t,i);null!=s&&!0===e.bloom&&(s.userData.hasBloom=!0),n.traverse((e=>{e instanceof a.Mesh&&(e.material=s)}))}else{const e=[];if(null!=s.materialAssignments)for(const i of s.materialAssignments)n.traverse((n=>{n instanceof a.Mesh&&n.material instanceof a.Material&&n.material.color instanceof a.Color&&(n.material.name!=i.name&&null!=i.name||"#"+n.material.color.getHexString()!==i.color||e.push(t.getMaterial(i.materialId).then((e=>n.material=e))))}));await Promise.all(e)}const r=[];if(n.traverse((e=>{e instanceof a.Mesh&&r.push(e)})),1===r.length){const e=r[0];return e.updateWorldMatrix(!0,!0),e.updateMatrixWorld(),e.matrix.copy(e.matrixWorld),e.matrixWorld.decompose(e.position,e.quaternion,e.scale),e.removeFromParent(),e}return n}(e.output,t,z));break;case"trail":q=new i({type:"trail",taper:e.output.taper,headGeometry:null,dragTexture:!1,texture:null!=e.output.texture?await t.getTexture(e.output.texture):null,opacityChannel:e.output.opacityChannel,color:e.output.color,colorEnd:e.output.colorEnd,intensity:e.output.intensity??1,intensityEnd:e.output.intensityEnd??1,length:e.output.length,opacityStart:e.output.opacityStart,opacityEnd:e.output.opacityEnd,bloom:e.output.bloom,scrollSpeed:e.output.scrollSpeed,width:e.output.width,billboard:e.output.billboard??!1});break;default:console.error("Failed to create particly system body: "+JSON.stringify(e))}const H=new re;H.parent=n,H.setRate(D),H._space=e.output.space;const J=await Promise.all(e.initializers.filter((e=>null!=$[e.type])).map((async e=>{const t=$[e.type],i=await F(e.params??{});return t.build(i)})));J.push(q,new N),H.addInitializers(J);const ee=await Promise.all(e.behaviours.filter((e=>null!=_[e.type])).map((async e=>{const t=_[e.type];for(const[i,n]of Object.entries(e.params))t.parameters&&null!=t.parameters[i]&&"curve"===t.parameters[i].type&&n.type!==Q.Curve&&(n.type=Q.Curve);const i=await F(e.params??{});return t.build(i)})).sort(((e,t)=>e instanceof te?1:0)));ee.push(new oe);for(const e of ee)e instanceof te&&(e.physics=u);H.addBehaviours(ee);for(const i of e.children){const e=await ne(i,t,n,u,z),s=new EmitterPool((()=>{const t=e.clone();return t.onExpired=()=>{const e=H.childEmitters.findIndex((e=>e.id===t.id));-1!=e&&H.childEmitters.splice(e,1),s.release(t)},t})),a=H.eventDispatcher,o=new Map;H.bindEmitterEvent=!0,a.addEventListener("PARTICLE_DEAD",(e=>{const t=o.get(e.id);if(null!=t){const e=H.childEmitters.findIndex((e=>e.id===t.id));null!=e&&(t.stopEmit(),H.childEmitters.splice(e,1))}}));let r="PARTICLE_CREATED";if("spawnEvent"in i)switch(i.spawnEvent){case"collision":r="PARTICLE_COLLISION";break;case"start":r="PARTICLE_CREATED"}a.addEventListener(r,(e=>{const t=s.get();t.age=0,t.totalEmitTimes=-1,t.particles.length=0,t.currentEmitTime=0,t.cID=0,t.eventDispatcher.removeAllEventListeners(),H.childEmitters.push(t),o.set(e.id,t),t.parentParticle=e,t.system=H.system,t.emit()}))}return H}const se=(new a.TextureLoader).load("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJkSURBVHjaxJeJbusgEEW94S1L//83X18M2MSuLd2pbqc4wZGqRLrKBsyZhQHny7Jk73xVL8xpVhWrcmiB5lX+6GJ5YgQ2owbAm8oIwH1VgKZUmGcRqKGGPgtEQQAzGR8hQ59fAmhJHSAagigJ4E7GPWRXOYC6owAd1JM6wDQPADyMWUqZRMqmAojHp1Vn6EQQEgUNMJLnUjMyJsM49wygBkAPw9dVFwXRkncCIIW3GRgoTQUZn6HxCMAFEFd8TwEQ78X4rHbILoAUmeT+RFG4UhQ6MiIAE4W/UsYFjuVjAIa2nIY4q1R0GFtQWG3E84lqw2GO2QOoCKBVu0BAPgDSU0eUDjjQenNkV/AW/pWChhpMTelo1a64AOKM30vk18GzTHXCNtI/Knz3DFBgsUqBGIjTInXRY1yA9xkVoqW5tVq3pDR9A0hfF5BSARmVnh7RMDCaIdcNgbPBkgzn1Bu+SfIEFSpSBmkxyrMicb0fAEuCZrWnN89veA/4XcakrPcjBWzkTuLjlbfTQPOlBhz+HwkqqPXmPQDdrQItxE1moGof1S74j/8txk8EHhTQrAE8qlwfqS5yukm1x/rAJ9Jiaa6nyATqD78aUVBhFo8b1V4DdTXdCW+IxA1zB4JhiOhZMEWO1HqnvdoHZ4FAMIhV9REF8FiUm0jsYPEJx/Fm/N8OhH90HI9YRHesWbXXZwAShU8qThe7H8YAuJmw5yOd989uRINKRTJAhoF8jbqrHKfeCYdIISZfSq26bk/K+yO3YvfKrVgiwQBHnwt8ynPB25+M8hceTt/ybPhnryJ78+tLgAEAuCFyiQgQB30AAAAASUVORK5CYII=");async function ae(e,t,i){const n=i.get(e.shader);if(null==n)return console.error("No shader exists with name "+e.shader),new a.Material;const s=new n.type,o=await D(e.shaderParams,n.type,t,{getTexture:e=>t.getTexture(e.id),getMaterial:e=>t.getMaterial(e.id),getMesh:e=>t.getMesh(e.id)},void 0,void 0,void 0,void 0);return Object.assign(s,o),s.build()}class oe extends t{initialize(e){e.body instanceof a.Object3D&&e.body.traverse((e=>{if(e instanceof a.Mesh){const t=e.material;t instanceof c&&(null!=t.uniforms[q]||null!=t.uniforms[H]||t.uniforms[J])}}))}mutate(e,t,i){this.energize(e,t),e.target instanceof o&&e.target.traverse((t=>{if(t instanceof a.Mesh){const i=t.material;i instanceof c&&(null!=i.uniforms[q]&&(i.uniforms[q].value=this.energy),null!=i.uniforms[H]&&(i.uniforms[H].value=e.age),null!=i.uniforms[J]&&(i.uniforms[J].value=e.velocity))}}))}}class re extends n{constructor(){super(...arguments),this.childEmitters=[],this.bindEmitterEvent=!1,this.onExpired=()=>{}}update(e){if(!this.isEmitting&&0===this.particles.length)return;this.age+=e,(this.dead||this.age>=this.life)&&this.destroy(),this.generate(e),this.integrate(e);let t=this.particles.length;for(;t--;){const e=this.particles[t];e.dead&&(this.system&&this.system.dispatch("PARTICLE_DEAD",e),this.bindEmitterEvent&&this.dispatch("PARTICLE_DEAD",e),this.system.pool.expire(e.reset()),this.particles.splice(t,1))}this.updateEmitterBehaviours(e),this.updateChildren(e),this.isEmitting||0!==this.particles.length||this.onExpired()}updateChildren(e){for(const t of this.childEmitters)null!=t.parentParticle?t.position.copy(t.parentParticle.position):t.setPosition(this.position),t.update(e)}clone(){const e=new re;return e.setRate(this.rate.clone()),e.behaviours=this.behaviours,e.initializers=this.initializers,e._space=this._space,e.body=this.body,e.parent=this.parent,e.system=this.system,e}setParentRecursive(e){this.system=e,this.childEmitters.forEach((t=>t.setParentRecursive(e)))}}export class EmitterPool{constructor(e){this.creator=e,this.instances=[]}get(){0==this.instances.length&&this.instances.push(this.creator());return this.instances.pop()}release(e){this.instances.push(e)}dispose(){this.instances.length=0}}/*
2
2
  * Copyright (©) 2023. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -32,6 +32,7 @@ export type TrailTemplate = {
32
32
  intensity: number;
33
33
  intensityEnd?: number;
34
34
  width?: number;
35
+ billboard?: boolean;
35
36
  scrollSpeed?: number;
36
37
  opacityStart: number;
37
38
  opacityEnd: number;
@@ -1 +1 @@
1
- {"version":3,"file":"vfx-renderers.d.ts","sourceRoot":"","sources":["../../../src/effects/vfx/vfx-renderers.ts"],"names":[],"mappings":"AAAA,OAAO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,CAAC,IAAI;gBAA5D,SAAS,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,KAAK,EAAU,IAAI,EAAE,cAAc;IAGxF,OAAO;IAIP,cAAc;IAUd,OAAO,CAAC,MAAM,CAA0B;IAExC,OAAO,CAAC,YAAY;IAWpB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG;QAAC,IAAI,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;QAAC,MAAM,EAAE,GAAG,CAAA;KAAC;IAsElF,gBAAgB,CAAC,QAAQ,KAAA;IA0CzB,cAAc,CAAC,QAAQ,KAAA;CAiBxB;AAgDD;;;;;GAKG;AACH,iBAAS,2BAA2B,CAAC,IAAI,EAAE,iBAAiB,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,CAqExF;AAED,OAAO,EAAE,2BAA2B,EAAE,CAAA"}
@@ -1,4 +1,4 @@
1
- import{CustomRenderer as e,MeshRenderer as t,PUID as r}from"@hology/nebula";import*as a from"three";import{InstancedBufferAttribute as i,Object3D as o}from"three";import{NodeShaderMaterial as s}from"three-shader-graph";import{StretchedSprite as n}from"./stretched-sprite.js";import{Trail as l}from"./trail-renderer.js";import{SpriteNodeShaderMaterial as c}from"../../shader/sprite-shader";var d;!function(e){e[e.mesh=0]="mesh",e[e.instanced=1]="instanced",e[e.sprite=2]="sprite",e[e.stretchedBillboard=3]="stretchedBillboard",e[e.trail=4]="trail"}(d||(d={}));export class MultiRenderer extends e{constructor(e,t,r,a){super(),this.worldContainer=e,this.localContainer=t,this.three=r,this.view=a,this.localRenderers=[],this.worldRenderers=[]}onSystemUpdate(){for(const e of this.worldRenderers)e?.onSystemUpdate();for(const e of this.localRenderers)e?.onSystemUpdate()}onParticleCreated(e){this.getRenderer(e)?.onParticleCreated(e)}onParticleUpdate(e){this.getRenderer(e)?.onParticleUpdate(e)}onParticleDead(e){this.getRenderer(e)?.onParticleDead(e),e._renderer=null}getRenderer(e){if(e._renderer)return e._renderer;const t=(null!=e?.parent?e?.parent._space:null)??"world",r="world"===t?this.worldContainer:this.localContainer,i="world"===t?this.worldRenderers:this.localRenderers;return"trail"===e.body.type?(null==i[d.trail]&&(i[d.trail]=new TrailRenderer(r,this.three)),e._renderer=i[d.trail]):e.body instanceof n?(null==i[d.stretchedBillboard]&&(i[d.stretchedBillboard]=new StretchedSpriteInstancedRenderer(r,this.three,this.view)),e._renderer=i[d.stretchedBillboard]):e.body instanceof a.Sprite||e.body instanceof a.Mesh&&"sprite"===e.body.name?(null==i[d.sprite]&&(i[d.sprite]=new CombinedRenderer(r,this.three)),e._renderer=i[d.sprite]):e.body instanceof a.Mesh&&0==e.body.children.length&&e.body.material instanceof s?(null==i[d.instanced]&&(i[d.instanced]=new InstancedRenderer(r,this.three,this.view)),e._renderer=i[d.instanced]):e.body instanceof a.Object3D?(null==i[d.mesh]&&(i[d.mesh]=new CombinedRenderer(r,this.three)),e._renderer=i[d.mesh]):void 0}dispose(){this.localRenderers.forEach((e=>{e instanceof InstancedRenderer&&e.dispose()})),this.worldRenderers.forEach((e=>{e instanceof InstancedRenderer&&e.dispose()}))}}export class TrailRenderer extends t{constructor(){super(...arguments),this.trails=[]}dispose(){}onSystemUpdate(){for(const e of this.trails)e.update()}onParticleCreated(e){const t=e.body,r=new l(this.container,!0),i=new o,s=l.createBaseMaterial(t.texture,t.scrollSpeed,t.opacityChannel);s.uniforms.taper.value=t.taper??!1;const n=new a.Color(t.color??0).multiplyScalar(t.intensity),c=new a.Color(t.colorEnd??0).multiplyScalar(t.intensityEnd??t.intensity??1);s.uniforms.headColor&&s.uniforms.tailColor&&(s.uniforms.headColor.value=new a.Vector4(n.r,n.g,n.b,t.opacityStart??1),s.uniforms.tailColor.value=new a.Vector4(c.r,c.g,c.b,t.opacityEnd??1)),t.bloom&&(s.userData.hasBloom=!0),r.initialize(s,Math.round(t.length??10),!1,t.width,null,i);const d=e.rotation;i.rotation.set(d.x,d.y,d.z);e.scale;r.activate(),this.trails.push(r),e.target=i}onParticleUpdate(e){const t=e.target;t.position.copy(e.position);const r=e.body;let a=x;e.old&&e.old.position?a.set(e.position.x-e.old.position.x,e.position.y-e.old.position.y,e.position.z-e.old.position.z).normalize():a.copy(e.velocity).normalize();const i=w;i.setFromUnitVectors(a,y),t.rotation.set(0,0,0),t.applyQuaternion(i);const o=this.trails.findIndex((e=>e.targetObject.id===t.id));if(-1!=o){const t=this.trails[o];if(e.useAlpha&&t.material.uniforms.headColor&&t.material.uniforms.tailColor){t.material.uniforms.headColor.value.setW(r.opacityStart*e.alpha);t.material.uniforms.tailColor.value.setW(r.opacityEnd*e.alpha)}}}onParticleDead(e){const t=e.target,r=this.trails.findIndex((e=>e.targetObject.id===t.id));if(-1!=r){const e=this.trails[r];e.removeFromParent(),e.mesh.removeFromParent(),t.removeFromParent(),this.trails.splice(r,1)}}}export class CombinedRenderer extends t{dispose(){}scale(e){const t=e.transform.initialScale;e.target instanceof a.Sprite?null!=t?e.target.scale.set(t.x*e.scale*e.radius,t.y*e.scale*e.radius,1):e.target.scale.set(e.scale*e.radius,e.scale*e.radius,1):null!=t?e.target.scale.set(t.x*e.scale,t.y*e.scale,t.z*e.scale):super.scale(e)}rotate(e){e.target.material.rotation=e.rotation.z}onParticleCreated(e){e.target||(e.target=this._targetPool.get(e.body),(e.useAlpha||e.useColor)&&(e.target instanceof a.Mesh||e.target instanceof a.Sprite&&e.target.material instanceof a.Material)&&(e.target.material.__puid=r.id(e.body.material),e.target.material=this._materialPool.get(e.target.material))),e.target&&e.target instanceof o&&(e.target.position.set(e.position.x,e.position.y,e.position.z),this.container.add(e.target))}onParticleUpdate(e){const{target:t,useAlpha:r,useColor:i,rotation:s}=e;if(t){if(t.position.copy(e.position),this.isThreeSprite(e)||(t instanceof a.Mesh&&t.material instanceof c?e.target.material.rotation=e.rotation.z:t.rotation.set(s.x,s.y,s.z)),this.scale(e),e.transform&&e.transform.orientAlongVelocity&&t instanceof o){const r=m.set(e.velocity.x,e.velocity.y,e.velocity.z).normalize(),a=t.getWorldDirection(h);a.applyAxisAngle(p,Math.PI/-2),u.setFromUnitVectors(a,r),t.quaternion.copy(u)}t.material instanceof a.Material&&(r&&(t.material instanceof c&&null!=t.material.uniforms.opacity&&(t.material.uniforms.opacity.value=e.alpha,t.material.uniformsNeedUpdate=!0),t.material.opacity=e.alpha,t.material.transparent=!0),i&&(null!=t.material.color?t.material.color.copy(e.color):t.material instanceof a.ShaderMaterial&&null!=t.material.uniforms.color&&(t.material.uniforms.color.value=e.color,t.material.uniformsNeedUpdate=!0)))}}onParticleDead(e){e.target&&(e.target.material&&(e.useAlpha||e.useColor)&&this._materialPool.expire(e.target.material),this._targetPool.expire(e.target),this.container.remove(e.target),e.target=null)}}export class StretchedSpriteInstancedRenderer extends t{constructor(e,t,r){super(e,t),this.view=r,this.meshes=[]}dispose(){this.meshes.forEach((e=>e.mesh.geometry.dispose()))}onSystemUpdate(){for(const e of this.meshes){const t=e.mesh.geometry.getAttribute("offset"),r=e.mesh.geometry.getAttribute("size"),i=e.mesh.geometry.getAttribute("velocity"),o=e.mesh.geometry.getAttribute("rotation"),s=e.mesh.geometry.getAttribute("color");let n=0;for(const l of e.particles){if(null==l||l.dead)continue;if(l.useColor||l.color instanceof a.Color){const e=C.copy(l.color).getRGB(M);s.setXYZW(n,e.r,e.g,e.b,1),s.needsUpdate=!0}l.useAlpha&&(s.setW(n,l.alpha),s.needsUpdate=!0),"number"==typeof l.rotation?o.setX(n,l.rotation):o.setX(n,l.rotation.x);const e=l.position;if(t.setXYZ(n,e.x,e.y,e.z),"number"!=typeof l.scale)throw new Error("Particle scale is not a number");r.setXYZ(n,l.scale,l.scale,l.scale);let c=l.body.scaleFactor;0===c&&(c=.001);const d=1,m=l.velocity;i.setXYZW(n,m.x*c,m.y*c,m.z*c,d),n++}n>0&&(t.clearUpdateRanges(),t.addUpdateRange(0,3*n),t.needsUpdate=!0,r.clearUpdateRanges(),r.addUpdateRange(0,3*n),r.needsUpdate=!0,s.clearUpdateRanges(),s.addUpdateRange(0,4*n),s.needsUpdate=!0,i.clearUpdateRanges(),i.addUpdateRange(0,4*n),i.needsUpdate=!0,o.clearUpdateRanges(),o.addUpdateRange(0,n),o.needsUpdate=!0)}}calcMaxCount(e){if(null==e)return 1;const t=e.parent.rate;return Math.min(t.numPan.b*Math.ceil(e.life/Math.min(Math.max(t.timePan.a,.01),1)),1e5)*this.calcMaxCount(e.parent.parentParticle)}onParticleCreated(e){if(e.body instanceof n&&null==e.target){const t=e.body;let r=this.meshes.find((e=>e.mesh.material.uuid===t.material.uuid));if(null==r){const o=this.calcMaxCount(e),s=new a.InstancedBufferGeometry;s.setIndex(t.geometry.getIndex()),s.setAttribute("position",t.geometry.getAttribute("position")),t.geometry.hasAttribute("normal")&&s.setAttribute("normal",t.geometry.getAttribute("normal")),s.setAttribute("uv",t.geometry.getAttribute("uv"));const n=new i(new Float32Array(3*o),3);n.setUsage(a.DynamicDrawUsage),s.setAttribute("offset",n);const l=new i(new Float32Array(4*o),4);if(l.setUsage(a.DynamicDrawUsage),s.setAttribute("color",l),t.material instanceof c){const e=new a.Color(t.material.color);for(let t=0;t<l.count;t++)l.setXYZW(t,e.r,e.g,e.b,1)}const d=new i(new Float32Array(3*o),3);d.setUsage(a.DynamicDrawUsage),s.setAttribute("size",d);const m=new i(new Float32Array(4*o),4);m.setUsage(a.DynamicDrawUsage),s.setAttribute("velocity",m);const h=new i(new Float32Array(4*o),1);h.setUsage(a.DynamicDrawUsage),s.setAttribute("rotation",h),r={mesh:new a.Mesh(s,t.material),indices:new Float32Array(o),particles:[]},this.meshes.push(r),this.container.add(r.mesh)}let o=r.indices.findIndex((e=>0===e));o<0&&(o=function(e){let t=e[0],r=0;for(let a=1;a<e.length;a++)e[a]<t&&(t=e[a],r=a);return r}(r.indices)),r.indices[o]=performance.now(),e.target=o,r.particles[o]=e}}onParticleUpdate(e){}onParticleDead(e){const t=e.body;let r=this.meshes.find((e=>e.mesh.material.uuid===t.material.uuid));if(r){const t=r.mesh.geometry.getAttribute("size");t.setXYZ(e.target,0,0,0),t.needsUpdate=!0,r.particles[e.target]=null,r.indices[e.target]=0}e.target=null}}const m=new a.Vector3,h=new a.Vector3,u=new a.Quaternion,p=new a.Vector3(1,0,0);export class InstancedRenderer extends t{constructor(e,t,r){super(e,t),this.view=r,this.meshes=[]}dispose(){this.meshes.forEach((e=>e.mesh.dispose()))}onSystemUpdate(){for(const e of this.meshes);}calcMaxCount(e){if(null==e)return 1;const t=e.parent.rate;return Math.min(t.numPan.b*Math.ceil(e.life/Math.min(Math.max(t.timePan.a,.01),1)),1e5)*this.calcMaxCount(e.parent.parentParticle)}onParticleCreated(e){if(!(e.body instanceof a.Sprite)){if(null==e.target){const t=e.body;let r=this.meshes.find((e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid));if(null==r){const i=this.calcMaxCount(e);r={mesh:new a.InstancedMesh(t.geometry,t.material,i),indices:new Array(i).fill(null),particles:[]},r.mesh.setColorAt(0,C.setScalar(1)),r.mesh.instanceColor.needsUpdate=!0,r.mesh.material.defines.USE_INSTANCING="";const o=new Float32Array(3*i);b.makeScale(0,0,0);for(let e=0;e<i;e++)o[3*e+0]=1,o[3*e+1]=1,r.mesh.setMatrixAt(e,b);r.mesh.instanceMatrix.needsUpdate=!0,r.mesh.geometry.setAttribute("particleData",new a.InstancedBufferAttribute(o,3)),this.meshes.push(r),this.container.add(r.mesh)}let i=r.indices.findIndex((e=>null==e));i<0&&(i=r.indices.indexOf(Math.min(...r.indices))),r.indices[i]=performance.now(),e.target=i,r.particles[i]=e}if("number"==typeof e.target){e.transform.initialScale;const t=e.body;let r=this.meshes.find((e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid));f(e,r.mesh),e.useAlpha&&(r.mesh.material.transparent=!0)}}}onParticleUpdate(e){const{target:t,useAlpha:r,useColor:a,rotation:i}=e;if(null==t)return;const o=e.body,s=this.meshes.find((e=>e.mesh.geometry.uuid===o.geometry.uuid&&e.mesh.material.uuid===o.material.uuid));if(null==s)return;f(e,s.mesh),a&&(s.mesh.setColorAt(e.target,C.copy(e.color)),s.mesh.instanceColor.needsUpdate=!0);const n=s.mesh.geometry.getAttribute("particleData");r&&n.setX(e.target,e.alpha),n.setY(e.target,e.energy),n.needsUpdate=!0}onParticleDead(e){if(null!=e.target){const t=e.body,r=this.meshes.find((e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid));if(null==r)return;r.indices[e.target]=null,e.scale=0,f(e,r.mesh),r.mesh.instanceMatrix.needsUpdate=!0,e.target=null}}}const g=new o;function f(e,t){if(x.set(e.position.x,e.position.y,e.position.z),e.transform&&e.transform.orientAlongVelocity){const r=m.set(e.position.x-e.old.position.x,e.position.y-e.old.position.y,e.position.z-e.old.position.z).normalize();t.getMatrixAt(e.target,g.matrix);const a=g.getWorldDirection(A);a.applyAxisAngle(p,Math.PI/-2),w.setFromUnitVectors(a,r)}else U.set(e.rotation.x,e.rotation.y,e.rotation.z),w.setFromEuler(U);const r=e.transform.initialScale;null!=r?A.set(r.x*e.scale,r.y*e.scale,r.z*e.scale):A.set(e.scale,e.scale,e.scale),b.compose(x,w,A),t.setMatrixAt(e.target,b),t.instanceMatrix.needsUpdate=!0}const y=new a.Vector3(0,0,-1),b=new a.Matrix4,w=new a.Quaternion,x=new a.Vector3,A=new a.Vector3,U=new a.Euler,C=new a.Color(0),M={r:0,g:0,b:0};function P(e,t){const r=e.mesh,i=r.count,o=[],s=r.geometry.getAttribute("particleData"),n=new a.Vector3;for(let l=0;l<i;l++){const i=new a.Matrix4,c=new a.Color;r.getMatrixAt(l,i),r.getColorAt(l,c);const d=s.getX(l);n.setFromMatrixPosition(i);const m=n.distanceTo(t.position);o.push({index:l,distance:m,matrix:i,particle:e.particles[l],color:c,pdx:d})}o.sort(((e,t)=>t.distance-e.distance));for(let e=0;e<i;e++){const t=o[e].matrix;null==o[e].particle&&t.makeScale(0,0,0),r.setMatrixAt(e,t),r.setColorAt(e,o[e].color),s.setX(e,o[e].pdx)}r.instanceMatrix.needsUpdate=!0}export{P as sortInstancedMeshByDistance};/*
1
+ import{CustomRenderer as e,MeshRenderer as t,PUID as r}from"@hology/nebula";import*as a from"three";import{InstancedBufferAttribute as o,Object3D as i}from"three";import{NodeShaderMaterial as n}from"three-shader-graph";import{StretchedSprite as s}from"./stretched-sprite.js";import{Trail as l}from"./trail-renderer.js";import{SpriteNodeShaderMaterial as c}from"../../shader/sprite-shader";var d;!function(e){e[e.mesh=0]="mesh",e[e.instanced=1]="instanced",e[e.sprite=2]="sprite",e[e.stretchedBillboard=3]="stretchedBillboard",e[e.trail=4]="trail"}(d||(d={}));export class MultiRenderer extends e{constructor(e,t,r,a){super(),this.worldContainer=e,this.localContainer=t,this.three=r,this.view=a,this.localRenderers=[],this.worldRenderers=[]}onSystemUpdate(){for(const e of this.worldRenderers)e?.onSystemUpdate();for(const e of this.localRenderers)e?.onSystemUpdate()}onParticleCreated(e){e.target=null,this.getRenderer(e)?.onParticleCreated(e)}onParticleUpdate(e){this.getRenderer(e)?.onParticleUpdate(e)}onParticleDead(e){this.getRenderer(e)?.onParticleDead(e),e._renderer=null}getRenderer(e){if(e._renderer)return e._renderer;const t=(null!=e?.parent?e?.parent._space:null)??"world",r="world"===t?this.worldContainer:this.localContainer,o="world"===t?this.worldRenderers:this.localRenderers;return"trail"===e.body.type?(null==o[d.trail]&&(o[d.trail]=new TrailRenderer(r,this.three)),e._renderer=o[d.trail]):e.body instanceof s?(null==o[d.stretchedBillboard]&&(o[d.stretchedBillboard]=new StretchedSpriteInstancedRenderer(r,this.three,this.view)),e._renderer=o[d.stretchedBillboard]):e.body instanceof a.Sprite||e.body instanceof a.Mesh&&"sprite"===e.body.name?(null==o[d.sprite]&&(o[d.sprite]=new CombinedRenderer(r,this.three)),e._renderer=o[d.sprite]):e.body instanceof a.Mesh&&0==e.body.children.length&&e.body.material instanceof n?(null==o[d.instanced]&&(o[d.instanced]=new InstancedRenderer(r,this.three,this.view)),e._renderer=o[d.instanced]):e.body instanceof a.Object3D?(null==o[d.mesh]&&(o[d.mesh]=new CombinedRenderer(r,this.three)),e._renderer=o[d.mesh]):void 0}dispose(){this.localRenderers.forEach((e=>{e instanceof InstancedRenderer&&e.dispose()})),this.worldRenderers.forEach((e=>{e instanceof InstancedRenderer&&e.dispose()}))}}export class TrailRenderer extends t{constructor(){super(...arguments),this.trails=[]}dispose(){}onSystemUpdate(){for(const e of this.trails)e.update()}onParticleCreated(e){const t=e.body,r=new l(this.container,!1),o=new i,n=l.createBaseMaterial(t.texture,t.scrollSpeed,t.opacityChannel,t.billboard??!1);n.uniforms.taper.value=t.taper??!1;const s=new a.Color(t.color??0).multiplyScalar(t.intensity),c=new a.Color(t.colorEnd??0).multiplyScalar(t.intensityEnd??t.intensity??1);n.uniforms.headColor&&n.uniforms.tailColor&&(n.uniforms.headColor.value=new a.Vector4(s.r,s.g,s.b,t.opacityStart??1),n.uniforms.tailColor.value=new a.Vector4(c.r,c.g,c.b,t.opacityEnd??1)),t.bloom&&(n.userData.hasBloom=!0),r.initialize(n,Math.round(t.length??10),!1,t.width,null,o,t.billboard??!1);const d=e.rotation;o.rotation.set(d.x,d.y,d.z);e.scale;r.activate(),this.trails.push(r),e.target=o}onParticleUpdate(e){const t=e.target;t.position.copy(e.position);const r=e.body;let a=x;e.old&&e.old.position?a.set(e.position.x-e.old.position.x,e.position.y-e.old.position.y,e.position.z-e.old.position.z).normalize():a.copy(e.velocity).normalize();const o=w;o.setFromUnitVectors(a,y),t.rotation.set(0,0,0),t.rotation.set(e.rotation.x,e.rotation.y,e.rotation.z),t.applyQuaternion(o);const i=this.trails.findIndex((e=>e.targetObject.id===t.id));if(-1!=i){const t=this.trails[i];if(e.useAlpha&&t.material.uniforms.headColor&&t.material.uniforms.tailColor){t.material.uniforms.headColor.value.setW(r.opacityStart*e.alpha);t.material.uniforms.tailColor.value.setW(r.opacityEnd*e.alpha)}}}onParticleDead(e){const t=e.target,r=this.trails.findIndex((e=>e.targetObject.id===t.id));if(-1!=r){const e=this.trails[r];e.removeFromParent(),e.mesh.removeFromParent(),t.removeFromParent(),this.trails.splice(r,1)}}}export class CombinedRenderer extends t{dispose(){}scale(e){const t=e.transform.initialScale;e.target instanceof a.Sprite?null!=t?e.target.scale.set(t.x*e.scale*e.radius,t.y*e.scale*e.radius,1):e.target.scale.set(e.scale*e.radius,e.scale*e.radius,1):null!=t?e.target.scale.set(t.x*e.scale,t.y*e.scale,t.z*e.scale):super.scale(e)}rotate(e){e.target.material.rotation=e.rotation.z}onParticleCreated(e){e.target||(e.target=this._targetPool.get(e.body),(e.useAlpha||e.useColor)&&(e.target instanceof a.Mesh||e.target instanceof a.Sprite&&e.target.material instanceof a.Material)&&(e.target.material.__puid=r.id(e.body.material),e.target.material=this._materialPool.get(e.target.material))),e.target&&e.target instanceof i&&(e.target.position.set(e.position.x,e.position.y,e.position.z),this.container.add(e.target))}onParticleUpdate(e){const{target:t,useAlpha:r,useColor:o,rotation:n}=e;if(t){if(t.position.copy(e.position),this.isThreeSprite(e)||(t instanceof a.Mesh&&t.material instanceof c?e.target.material.rotation=e.rotation.z:t.rotation.set(n.x,n.y,n.z)),this.scale(e),e.transform&&e.transform.orientAlongVelocity&&t instanceof i){const r=m.set(e.velocity.x,e.velocity.y,e.velocity.z).normalize(),a=t.getWorldDirection(u);a.applyAxisAngle(p,Math.PI/-2),h.setFromUnitVectors(a,r),t.quaternion.copy(h)}t.material instanceof a.Material&&(r&&(t.material instanceof c&&null!=t.material.uniforms.opacity&&(t.material.uniforms.opacity.value=e.alpha,t.material.uniformsNeedUpdate=!0),t.material.opacity=e.alpha,t.material.transparent=!0),o&&(null!=t.material.color?t.material.color.copy(e.color):t.material instanceof a.ShaderMaterial&&null!=t.material.uniforms.color&&(t.material.uniforms.color.value=e.color,t.material.uniformsNeedUpdate=!0)))}}onParticleDead(e){e.target&&(e.target.material&&(e.useAlpha||e.useColor)&&this._materialPool.expire(e.target.material),this._targetPool.expire(e.target),this.container.remove(e.target),e.target=null)}}export class StretchedSpriteInstancedRenderer extends t{constructor(e,t,r){super(e,t),this.view=r,this.meshes=[]}dispose(){this.meshes.forEach((e=>e.mesh.geometry.dispose()))}onSystemUpdate(){for(const e of this.meshes){const t=e.mesh.geometry.getAttribute("offset"),r=e.mesh.geometry.getAttribute("size"),o=e.mesh.geometry.getAttribute("velocity"),i=e.mesh.geometry.getAttribute("rotation"),n=e.mesh.geometry.getAttribute("color");let s=0;for(const l of e.particles){if(null==l||l.dead)continue;if(l.useColor||l.color instanceof a.Color){const e=C.copy(l.color).getRGB(M);n.setXYZW(s,e.r,e.g,e.b,1),n.needsUpdate=!0}l.useAlpha&&(n.setW(s,l.alpha),n.needsUpdate=!0),"number"==typeof l.rotation?i.setX(s,l.rotation):i.setX(s,l.rotation.x);const e=l.position;if(t.setXYZ(s,e.x,e.y,e.z),"number"!=typeof l.scale)throw new Error("Particle scale is not a number");r.setXYZ(s,l.scale,l.scale,l.scale);let c=l.body.scaleFactor;0===c&&(c=.001);const d=1,m=l.velocity;o.setXYZW(s,m.x*c,m.y*c,m.z*c,d),s++}s>0&&(t.clearUpdateRanges(),t.addUpdateRange(0,3*s),t.needsUpdate=!0,r.clearUpdateRanges(),r.addUpdateRange(0,3*s),r.needsUpdate=!0,n.clearUpdateRanges(),n.addUpdateRange(0,4*s),n.needsUpdate=!0,o.clearUpdateRanges(),o.addUpdateRange(0,4*s),o.needsUpdate=!0,i.clearUpdateRanges(),i.addUpdateRange(0,s),i.needsUpdate=!0)}}calcMaxCount(e){if(null==e)return 1;const t=e.parent.rate;return Math.min(t.numPan.b*Math.ceil(e.life/Math.min(Math.max(t.timePan.a,.01),1)),1e5)*this.calcMaxCount(e.parent.parentParticle)}onParticleCreated(e){if(e.body instanceof s&&null==e.target){const t=e.body;let r=this.meshes.find((e=>e.mesh.material.uuid===t.material.uuid));if(null==r){const i=this.calcMaxCount(e),n=new a.InstancedBufferGeometry;n.setIndex(t.geometry.getIndex()),n.setAttribute("position",t.geometry.getAttribute("position")),t.geometry.hasAttribute("normal")&&n.setAttribute("normal",t.geometry.getAttribute("normal")),n.setAttribute("uv",t.geometry.getAttribute("uv"));const s=new o(new Float32Array(3*i),3);s.setUsage(a.DynamicDrawUsage),n.setAttribute("offset",s);const l=new o(new Float32Array(4*i),4);if(l.setUsage(a.DynamicDrawUsage),n.setAttribute("color",l),t.material instanceof c){const e=new a.Color(t.material.color);for(let t=0;t<l.count;t++)l.setXYZW(t,e.r,e.g,e.b,1)}const d=new o(new Float32Array(3*i),3);d.setUsage(a.DynamicDrawUsage),n.setAttribute("size",d);const m=new o(new Float32Array(4*i),4);m.setUsage(a.DynamicDrawUsage),n.setAttribute("velocity",m);const u=new o(new Float32Array(4*i),1);u.setUsage(a.DynamicDrawUsage),n.setAttribute("rotation",u),r={mesh:new a.Mesh(n,t.material),indices:new Float32Array(i),particles:[]},this.meshes.push(r),this.container.add(r.mesh)}let i=r.indices.findIndex((e=>0===e));i<0&&(i=function(e){let t=e[0],r=0;for(let a=1;a<e.length;a++)e[a]<t&&(t=e[a],r=a);return r}(r.indices)),r.indices[i]=performance.now(),e.target=i,r.particles[i]=e}}onParticleUpdate(e){}onParticleDead(e){const t=e.body;let r=this.meshes.find((e=>e.mesh.material.uuid===t.material.uuid));if(r){const t=r.mesh.geometry.getAttribute("size");t.setXYZ(e.target,0,0,0),t.needsUpdate=!0,r.particles[e.target]=null,r.indices[e.target]=0}e.target=null}}const m=new a.Vector3,u=new a.Vector3,h=new a.Quaternion,p=new a.Vector3(1,0,0);export class InstancedRenderer extends t{constructor(e,t,r){super(e,t),this.view=r,this.meshes=[]}dispose(){this.meshes.forEach((e=>e.mesh.dispose()))}onSystemUpdate(){for(const e of this.meshes);}calcMaxCount(e){if(null==e)return 1;const t=e.parent.rate;return Math.min(t.numPan.b*Math.ceil(e.life/Math.min(Math.max(t.timePan.a,.01),1)),1e5)*this.calcMaxCount(e.parent.parentParticle)}onParticleCreated(e){if(e.body instanceof a.Sprite)return;const t=e.body;let r=this.meshes.find((e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid));if(null==r){const o=this.calcMaxCount(e);r={mesh:new a.InstancedMesh(t.geometry,t.material,o),indices:new Array(o).fill(null),particles:[]},r.mesh.setColorAt(0,C.setScalar(1)),r.mesh.instanceColor.needsUpdate=!0,r.mesh.material.defines.USE_INSTANCING="";const i=new Float32Array(3*o);b.makeScale(0,0,0);for(let e=0;e<o;e++)i[3*e+0]=1,i[3*e+1]=1,r.mesh.setMatrixAt(e,b);r.mesh.instanceMatrix.needsUpdate=!0,r.mesh.geometry.setAttribute("particleData",new a.InstancedBufferAttribute(i,3)),this.meshes.push(r),this.container.add(r.mesh)}let o=r.indices.findIndex((e=>null==e));if(o<0&&(o=r.indices.indexOf(Math.min(...r.indices))),r.indices[o]=performance.now(),e.target=o,r.particles[o]=e,"number"==typeof e.target){e.transform.initialScale;const t=e.body;let r=this.meshes.find((e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid));f(e,r.mesh),e.useAlpha&&(r.mesh.material.transparent=!0)}}onParticleUpdate(e){const{target:t,useAlpha:r,useColor:a,rotation:o}=e;if(null==t)return;const i=e.body,n=this.meshes.find((e=>e.mesh.geometry.uuid===i.geometry.uuid&&e.mesh.material.uuid===i.material.uuid));if(null==n)return;n.mesh.frustumCulled=!1,f(e,n.mesh),a&&(n.mesh.setColorAt(e.target,C.copy(e.color)),n.mesh.instanceColor.needsUpdate=!0);const s=n.mesh.geometry.getAttribute("particleData");r&&s.setX(e.target,e.alpha),s.setY(e.target,e.energy),s.needsUpdate=!0}onParticleDead(e){if(null!=e.target){const t=e.body,r=this.meshes.find((e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid));if(null==r)return;r.indices[e.target]=null,e.scale=0,f(e,r.mesh),r.mesh.instanceMatrix.needsUpdate=!0,e.target=null}}}const g=new i;function f(e,t){if(x.set(e.position.x,e.position.y,e.position.z),e.transform&&e.transform.orientAlongVelocity){const r=m.set(e.position.x-e.old.position.x,e.position.y-e.old.position.y,e.position.z-e.old.position.z).normalize();t.getMatrixAt(e.target,g.matrix);const a=g.getWorldDirection(A);a.applyAxisAngle(p,Math.PI/-2),w.setFromUnitVectors(a,r)}else U.set(e.rotation.x,e.rotation.y,e.rotation.z),w.setFromEuler(U);const r=e.transform.initialScale;null!=r?A.set(r.x*e.scale,r.y*e.scale,r.z*e.scale):A.set(e.scale,e.scale,e.scale),b.compose(x,w,A),t.setMatrixAt(e.target,b),t.instanceMatrix.needsUpdate=!0}const y=new a.Vector3(0,0,-1),b=new a.Matrix4,w=new a.Quaternion,x=new a.Vector3,A=new a.Vector3,U=new a.Euler,C=new a.Color(0),M={r:0,g:0,b:0};function P(e,t){const r=e.mesh,o=r.count,i=[],n=r.geometry.getAttribute("particleData"),s=new a.Vector3;for(let l=0;l<o;l++){const o=new a.Matrix4,c=new a.Color;r.getMatrixAt(l,o),r.getColorAt(l,c);const d=n.getX(l);s.setFromMatrixPosition(o);const m=s.distanceTo(t.position);i.push({index:l,distance:m,matrix:o,particle:e.particles[l],color:c,pdx:d})}i.sort(((e,t)=>t.distance-e.distance));for(let e=0;e<o;e++){const t=i[e].matrix;null==i[e].particle&&t.makeScale(0,0,0),r.setMatrixAt(e,t),r.setColorAt(e,i[e].color),n.setX(e,i[e].pdx)}r.instanceMatrix.needsUpdate=!0}export{P as sortInstancedMeshByDistance};/*
2
2
  * Copyright (©) 2023. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -51,7 +51,25 @@ export declare class PhysicsSystem extends AbstractPhysicsSystem {
51
51
  get showDebug(): boolean;
52
52
  constructor(viewController: ViewController);
53
53
  private shapeCacheBox;
54
+ private shapeCacheBall;
55
+ /**
56
+ * Check if there is any objects in the physics world currently that
57
+ * intersects with this box.
58
+ * Note that this doesn't work for heightfields. To support heightfields,
59
+ * use hasSphereIntersection instead.
60
+ * @param box
61
+ * @returns
62
+ */
54
63
  hasBoxIntersection(box: THREE.Box3): boolean;
64
+ /**
65
+ * Check if there is any objects in the physics world currently that
66
+ * intersects with this sphere.
67
+ * Note that this doesn't work for heightfields. To support heightfields,
68
+ * use hasSphereIntersection instead.
69
+ * @param sphere
70
+ * @returns
71
+ */
72
+ hasSphereIntersection(sphere: THREE.Sphere): boolean;
55
73
  private debugMesh;
56
74
  private createDebugMesh;
57
75
  /**
@@ -197,6 +215,38 @@ export declare class PhysicsSystem extends AbstractPhysicsSystem {
197
215
  * @param factor - The damping factor to apply
198
216
  */
199
217
  setAngularDamping(actor: BaseActor, factor: number): void;
218
+ /**
219
+ * Locks or unlocks the ability of this rigid-body to translate.
220
+ *
221
+ * @param actor - The actor which body's rotation should be locked
222
+ * @param locked - If `true`, this rigid-body will no longer translate due to forces and impulses
223
+ */
224
+ lockTranslations(actor: BaseActor, locked: boolean): void;
225
+ /**
226
+ * Locks or unlocks the ability of this rigid-body to rotate.
227
+ *
228
+ * @param actor - The actor which body's rotation should be locked
229
+ * @param locked - If `true`, this rigid-body will no longer rotate due to torques and impulses.
230
+ */
231
+ lockRotations(actor: BaseActor, locked: boolean): void;
232
+ /**
233
+ * Locks or unlocks the ability of this rigid-body to translate along individual coordinate axes.
234
+ *
235
+ * @param actor - The actor which body's translations should be enabled
236
+ * @param enableX - If `false`, this rigid-body will no longer translate due to torques and impulses, along the X coordinate axis.
237
+ * @param enableY - If `false`, this rigid-body will no longer translate due to torques and impulses, along the Y coordinate axis.
238
+ * @param enableZ - If `false`, this rigid-body will no longer translate due to torques and impulses, along the Z coordinate axis.
239
+ */
240
+ setEnabledTranslations(actor: BaseActor, enableX: boolean, enableY: boolean, enableZ: boolean): void;
241
+ /**
242
+ * Locks or unlocks the ability of this rigid-body to rotate along individual coordinate axes.
243
+ *
244
+ * @param actor - The actor which body's rotations should be enabled
245
+ * @param enableX - If `false`, this rigid-body will no longer rotate due to torques and impulses, along the X coordinate axis.
246
+ * @param enableY - If `false`, this rigid-body will no longer rotate due to torques and impulses, along the Y coordinate axis.
247
+ * @param enableZ - If `false`, this rigid-body will no longer rotate due to torques and impulses, along the Z coordinate axis.
248
+ */
249
+ setEnabledRotations(actor: BaseActor, enableX: boolean, enableY: boolean, enableZ: boolean): void;
200
250
  /**
201
251
  * Adds physics bodies for a landscape group.
202
252
  * @param object - The landscape group to add physics for
@@ -1 +1 @@
1
- {"version":3,"file":"physics-system.d.ts","sourceRoot":"","sources":["../../../../src/gameplay/services/physics/physics-system.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,2BAA2B,CAAA;AAEnD,OAAO,EAAgE,UAAU,EAAE,OAAO,EAA2B,MAAM,MAAM,CAAA;AACjI,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAGL,mBAAmB,EAE6C,QAAQ,EAIxE,OAAO,EACR,MAAM,OAAO,CAAA;AAGd,OAAO,EAGL,cAAc,EASf,MAAM,mBAAmB,CAAA;AAM1B,OAAO,EAAE,YAAY,EAAQ,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAW,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAM7C,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AAGzF,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,KAAK,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAG7G,qBAAa,aAAa;IAGxB,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,MAAM,EAAE,OAAO,CAAQ;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,OAAO,CAAgB;IACjC,SAAS,EAAE,OAAO,CAAgB;CACnC;AAED,UAAU,cAAc;IACtB,UAAU,CAAC,EAAE,mBAAmB,CAAA;IAChC,aAAa,CAAC,EAAE,M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,EAAE,EAAE,OAAO,CAAC;QACZ,EAAE,EAAE,OAAO,CAAC;QACZ,EAAE,EAAE,OAAO,CAAA;KACZ,EAAE;IA8BH;;OAEG;IACI,IAAI;IAMX;;;;;;;OAOG;IACH,OAAO,CAAC,gBAAgB;IA2BxB;;;;;;;OAOG;IACH,OAAO,CAAC,QAAQ;IAoChB;;;;;;OAMG;IACH,OAAO,CAAC,WAAW;IAqFnB;;;OAGG;IACI,wBAAwB,IAAI,MAAM,CAAC,kBAAkB;CAG7D;AA4LD;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,KAAK,CAAC,eAAe,GAAG,KAAK,CAAC,0BAA0B,GAC7D,YAAY,CAcd"}
@@ -1,4 +1,4 @@
1
- import{__decorate as t,__metadata as e}from"tslib";import*as s from"@dimforge/rapier3d-compat";import{QueryFilterFlags as i}from"@dimforge/rapier3d-compat";import{BehaviorSubject as o,distinctUntilChanged as n,filter as r,map as a,Subject as c,takeUntil as l}from"rxjs";import*as d from"three";import{ArrowHelper as h,BufferAttribute as u,BufferGeometry as y,Group as p,LineSegments as g,Matrix4 as m,Object3D as f,Quaternion as w,Raycaster as x,Scene as v,Vector3 as B}from"three";import{Service as b}from"typedi";import{AssetMeshInstance as A}from"../../../scene/asset-resource-loader.js";import{BoxCollisionShape as C,CapsuleCollisionShape as D,CollisionShapeSource as z,ConeCollisionShape as M,ConvexPolyhedronCollisionShape as S,CylinderCollisionShape as R,PhysicalShapeMesh as T,PlaneCollisionShape as E,SphereCollisionShape as F,TrimeshCollisionShape as j}from"../../../index.js";import{LandscapeGroup as W}from"../../../scene/landscape/landscape.js";import{ViewController as V}from"../render.js";import{World as _}from"../world.js";import*as P from"three/examples/jsm/utils/BufferGeometryUtils.js";import{calculateEffectiveScale as I}from"../../../utils/three/traverse.js";import{AbstractPhysicsSystem as L}from"./abstract-physics-system.js";import{ActorComponent as k,Component as O}from"../../../gameplay/actors/component.js";import{inject as N}from"../../../gameplay/inject.js";export{Component,ActorComponent,attach,Attach}from"../../actors/component.js";export class RayTestResult{constructor(){this.hasHit=!1,this.hitPoint=new B,this.hitNormal=new B}}export var PhysicsBodyType;!function(t){t[t.dynamic=1]="dynamic",t[t.static=2]="static",t[t.kinematic=4]="kinematic",t[t.kinematicVelocityBased=8]="kinematicVelocityBased"}(PhysicsBodyType||(PhysicsBodyType={}));const G=new B,q=new B,Q=new w;let U=class extends L{set showDebug(t){this.shouldRenderDebug=t,this.debugMesh&&(this.debugMesh.visible=t)}get showDebug(){return this.shouldRenderDebug}constructor(t){super(),this.viewController=t,this.staticMeshes=new Map,this.staticBodies=new Map,this.actorBodies=new Map,this.bodyActors=new Map,this.collisionEvents=new c,this.beforeStep=new c,this.afterStep=new c,this.shouldRenderDebug=!1,this.shapeCacheBox=new Map,this._raycaster=new x,this._reusableResult=new RayTestResult,this._raytestDiff=new B,this._raytestDirection=new B,this.controlledActors=new Set,this.ready=this.setup()}hasBoxIntersection(t){const e=t.getCenter(G),i=t.getSize(q),o=i.x+1e6*i.y+1e12*i.z;if(!this.shapeCacheBox.has(o)){const t=new s.Cuboid(i.x/2,i.y/2,i.z/2);this.shapeCacheBox.set(o,t)}const n=this.shapeCacheBox.get(o);return null!=this.world.intersectionWithShape(e,Q,n)}createDebugMesh(){return new g(new y,new d.LineBasicMaterial({color:255}))}async start(){return await this.ready,this.handleTick(),this.ready}renderDebug(){null==this.debugMesh&&(this.debugMesh=this.createDebugMesh(),this.debugMesh.visible=this.shouldRenderDebug,this.debugMesh.raycast=function(){},this.scene.add(this.debugMesh));const t=this.world.debugRender();this.debugMesh.geometry.setAttribute("position",new u(t.vertices,3))}async setup(){if(null!=this.rapier)throw new Error("Rapier is already estup");this.rapier=await et(),this.eventQueue=new s.EventQueue(!0),this.setupWorld()}handleTick(){this.fixedupdateSub=this.viewController.onUpdate().subscribe((t=>{t=Math.min(.1,t),this.beforeStep.next(t),this.updatePhysics(t),this.showDebug&&this.renderDebug(),this.world.bodies.forEach((t=>{if(t.isFixed())return;const e=this.staticMeshes.get(t)??this.bodyActors.get(t)?.object;var s,i;null!=e&&(e.parent instanceof v&&(it(e.position,t.translation()),(t.isDynamic()||t.isKinematic()&&!this.controlledActors.has(this.bodyActors.get(t)?.id))&&(s=e.quaternion,i=t.rotation(),s.x=i.x,s.y=i.y,s.z=i.z,s.w=i.w),e.updateMatrix(),e.updateWorldMatrix(!1,!1)))})),this.afterStep.next(t)}))}_updateWorld(){this.world.timestep=0,this.world.step()}updatePhysics(t){this.world.timestep=t,this.world.step(this.eventQueue),this.eventQueue.drainCollisionEvents(((t,e,s)=>{this.collisionEvents.next({handle1:t,handle2:e,started:s}),this.collisionEvents.next({handle1:e,handle2:t,started:s})}))}rayTestFromCamera(t,e,s){this._raycaster.setFromCamera(tt,this.viewController.getCamera());const i=this._raycaster.ray.origin,o=this._raycaster.ray.direction.multiplyScalar(t).add(i);return this.rayTest(i,o,e,s)}rayTest(t,e,s,i){null==s&&(s=this._reusableResult);const o=this._raytestDiff,n=this._raytestDirection;if(o.subVectors(e,t),n.copy(o).normalize(),0===n.length())return console.warn("Ray test called with to and from being equal"),s;st(lt.origin,t),st(lt.dir,n);const r=o.length(),a=this.world.castRayAndGetNormal(lt,r,!1,void 0,void 0,void 0,null!=i?.excludeActor?this.actorBodies.get(i.excludeActor.id):void 0,i?.excludeTriggers?t=>!t.isSensor():void 0);if(s.hasHit=null!=a,s.hasHit){const e=lt.pointAt(a.timeOfImpact);s._internal=a,it(s.hitNormal,a.normal),it(s.hitPoint,e),s.distance=nt.subVectors(s.hitPoint,t).length();const i=this.world.bodies.getAll().find((t=>function(t,e){for(let s=0,i=t.numColliders();s<i;s++){const i=t.collider(s);if(e(i))return i}}(t,(t=>t===a.collider))));s.actor=null!=i?this.bodyActors.get(i):null}if(this.showDebug){const e=new h(n,t,r,i?.debugColor??255);this.scene.add(e),setTimeout((()=>this.scene.remove(e)),i?.debugLifetime??200)}return s}setGravity(t,e,s){this.world.gravity.x=t,this.world.gravity.y=e,this.world.gravity.z=s}getGravity(){return Y.set(this.world.gravity.x,this.world.gravity.y,this.world.gravity.z)}addFromScene(t){this.addRecursively(t);for(const t of this.staticBodies.values())ot(t,(t=>t.setActiveEvents(s.ActiveEvents.COLLISION_EVENTS)))}addRecursively(t){if(this.removeSceneObject(t),!function(t){if(null!=t.userData?.src){const e=t.userData?.src;return"actor"===e.type}return!1}(t))if(t instanceof T&&null!=t.collisionShape){const e=this.createStaticBody(t,[t.collisionShape],t.physics);this.staticMeshes.set(e,t),this.staticBodies.set(t,e)}else if(t instanceof A&&!1!==t.userData?.src?.collisionDetection)if(t.children[0]&&t.children[0].instanceMatrix)this.createForInstancedMesh(t.children[0],t.collisionShapes);else{const e=this.createStaticBody(t,t.collisionShapes,t.physics);this.staticMeshes.set(e,t),this.staticBodies.set(t,e)}else t instanceof W?this.addLandscapeGroup(t):(t instanceof p||t instanceof v)&&t.children.forEach((t=>this.addRecursively(t)))}createForInstancedMesh(t,e){const s=new m,i=e.filter((t=>null!=t)).map((t=>t.source===z.rendered?t.withOffset(ht):t));for(let e=0;e<t.count;e++){if(null!=t.userData.hasCollision&&!t.userData.hasCollision[e])continue;const o=new f;o.matrix.identity(),s.fromArray(t.instanceMatrix.array,16*e),o.applyMatrix4(s);this.createStaticBody(o,i)}}getCharacterController(t){return this.world?.createCharacterController(t)}getActorComputedMovement(t,e,s,o=null){const n=this.actorBodies.get(t.id);this.controlledActors.add(t.id);const r=n.collider(0);e.computeColliderMovement(r,s,i.EXCLUDE_SENSORS,o,at);const a=e.computedMovement();return it(rt,a),rt}setNextKinematicTranslation(t,e){const s=this.actorBodies.get(t.id),i=s.translation();i.x+=e.x,i.y+=e.y,i.z+=e.z,s?.setNextKinematicTranslation(i)}setAngularVelocity(t,e){const s=this.actorBodies.get(t.id);Z.x=e.x,Z.y=e.y,Z.z=e.z,s?.setAngvel(Z,!0)}setLinearVelocity(t,e){const s=this.actorBodies.get(t.id);Z.x=e.x,Z.y=e.y,Z.z=e.z,s?.setLinvel(Z,!0)}getLinearVelocity(t,e=new B){const s=this.actorBodies.get(t.id).linvel();return e.x=s.x,e.y=s.y,e.z=s.z,e}getAngularVelocity(t,e=new B){const s=this.actorBodies.get(t.id).angvel();return e.x=s.x,e.y=s.y,e.z=s.z,e}setLinearDamping(t,e){const s=this.actorBodies.get(t.id);s?.setLinearDamping(e)}setAngularDamping(t,e){const s=this.actorBodies.get(t.id);s?.setAngularDamping(e)}addLandscapeGroup(t){const e=t.userData.src,i=e.landscape.heightMaps;for(const n of t.sections){this.staticBodies.has(n)&&this.world.removeRigidBody(this.staticBodies.get(n));var o=n.getWorldPosition(new B);if(e.landscape.holes&&e.landscape.holes.some((t=>t.m===n.name&&0!==t.w[0]))){const t=n.geometry.clone(),i=n.scale,r=n.geometry.getAttribute("hole"),a=new Float32Array(t.getAttribute("position").array);for(let t=0;t<a.length;t+=3)a[t]*=i.x,a[t+1]*=i.y,a[t+2]*=i.z;const c=t.index;for(let t=0;t<c.count;t+=3){const e=r.getX(c.getX(t)),s=r.getX(c.getY(t)),i=r.getX(c.getZ(t));(e>.5||s>.5||i>.5)&&(c.setX(t,0),c.setY(t,0),c.setZ(t,0))}const l=s.ColliderDesc.trimesh(a,new Uint32Array(t.getIndex().array));if(!1!==e.collisionDetection){const t=this.world.createRigidBody(s.RigidBodyDesc.fixed()),e=new s.Vector3(0,0,0);st(e,o),t.setTranslation(e,!1),this.world.createCollider(l,t),this.staticBodies.set(n,t)}continue}const t=e.landscape.options.density+1,r=e.landscape.options.sectionSize,a=new Array(t);for(let e=0;e<t;e++)a[e]=new Array(t).fill(0);const c=i.find((t=>t.x===n.x&&t.y==n.y));if(null!=c)for(const e of c.points){if(null==a[e.i%t])continue;const s=t-1-Math.floor(e.i/t);s in a[e.i%t]?a[e.i%t][s]=e.y/r:console.warn("wrong index",{points:a,point:e,i:e.i%t,k:s,heightMap:c})}const l=e.landscape.options.density,d=a.flatMap((t=>t.reverse())),h=s.ColliderDesc.heightfield(l,l,new Float32Array(d),new s.Vector3(r,r,r));if(!1!==e.collisionDetection){const t=this.world.createRigidBody(s.RigidBodyDesc.fixed()),e=new s.Vector3(0,0,0);st(e,o),t.setTranslation(e,!1),this.world.createCollider(h,t),this.staticBodies.set(n,t)}}}setEnabled(t,e){const s=this.actorBodies.get(t.id);s?.setEnabled(e)}addActor(t,e,i={}){if(0==e.length)return void console.error("No collision shapes were defined when adding actor to the physics system.");this.removeActor(t);const o=t.object;let n;switch(i.type??PhysicsBodyType.static){case PhysicsBodyType.dynamic:n=s.RigidBodyDesc.dynamic(),n.mass=i.mass??1;break;case PhysicsBodyType.kinematic:n=s.RigidBodyDesc.kinematicPositionBased();break;case PhysicsBodyType.kinematicVelocityBased:n=s.RigidBodyDesc.kinematicVelocityBased();break;default:n=i.isTrigger?s.RigidBodyDesc.kinematicVelocityBased():s.RigidBodyDesc.fixed()}const r=this.world.createRigidBody(n);r.enableCcd(1==i.continousCollisionDetection);for(const t of e)this.addShape(r,t,o);ot(r,(t=>{null!=i.isTrigger&&(t.setSensor(i.isTrigger),t.setActiveCollisionTypes(s.ActiveCollisionTypes.ALL),t.setActiveEvents(s.ActiveEvents.COLLISION_EVENTS)),null!=i.friction&&t.setFriction(i.friction),null!=i.density&&t.setDensity(i.density),null!=i.mass&&t.setMass(i.mass),null!=i.restitution&&t.setRestitution(i.restitution)})),K(r,o),!0===i.ignoreForNavMesh&&(r.userData={ignoreForNavMesh:!0}),this.actorBodies.set(t.id,r),this.bodyActors.set(r,t)}applyTorque(t,e){const s=this.actorBodies.get(t.id);Z.x=e.x,Z.y=e.y,Z.z=e.z,s?.addTorque(Z,!0)}applyTorqueImpulse(t,e){const s=this.actorBodies.get(t.id);Z.x=e.x,Z.y=e.y,Z.z=e.z,s?.applyTorqueImpulse(Z,!0)}resetForces(t){const e=this.actorBodies.get(t.id);e?.resetForces(!1)}resetTorques(t){const e=this.actorBodies.get(t.id);e?.resetTorques(!1)}applyForce(t,e){const s=this.actorBodies.get(t.id);Z.x=e.x,Z.y=e.y,Z.z=e.z,s?.addForce(Z,!0)}applyImpulse(t,e){const s=this.actorBodies.get(t.id);Z.x=e.x,Z.y=e.y,Z.z=e.z,s?.applyImpulse(Z,!0)}applyLocalForce(t,e,s){const i=this.actorBodies.get(t.id);st(Z,e),null==s?i?.addForce(Z,!0):(st(J,s),i?.addForceAtPoint(Z,J,!0))}applyLocalImpulse(t,e,s){const i=this.actorBodies.get(t.id);st(Z,e),null==s?i.applyImpulse(Z,!0):(st(J,s),i.applyImpulseAtPoint(Z,J,!0))}applyRadiusImpulse(t,e,i){this.world.bodies.forEach((o=>{if(o.collider(0)?.isSensor())return;if(o.bodyType()!==s.RigidBodyType.Dynamic)return;const n=$;it(n,o.translation());const r=n.clone().sub(t);if(r.length()>e)return;const a=r.clone().normalize().multiplyScalar(i);Z.x=a.x,Z.y=a.y,Z.z=a.z,o.applyImpulse(Z,!0)}))}removeActor(t){if(null==t)return;this.controlledActors.delete(t.id);const e=this.actorBodies.get(t.id);null!=e&&(this.bodyActors.delete(e),this.world.removeRigidBody(e)),this.actorBodies.delete(t.id)}removeRemoved(t){if(null==t)return;const e=new Set;t.traverse((t=>{e.add(t.uuid)}));for(const[t,s]of this.staticBodies.entries())!e.has(t.uuid)&&this.world.getRigidBody(s.handle)&&(this.staticBodies.delete(t),this.world.removeRigidBody(s))}removeSceneObject(t){if(t instanceof W){for(const e of t.sections)this.removeSceneObject(e);return}let e=this.staticBodies.get(t);null!=e&&this.world.getRigidBody(e.handle)&&this.world.removeRigidBody(e),this.staticBodies.delete(t)}activateActorEvents(t){this.actorBodies.get(t.id)}_onCollisionWithActorEvent(t,e,s){return this.activateActorEvents(t),this.collisionEvents.pipe(l(t.disposed),r((({started:t})=>t===s)),a((({handle1:t,handle2:e,started:s})=>({a1:this.bodyActors.get(this.world.getCollider(t)?.parent()),a2:this.bodyActors.get(this.world.getCollider(e)?.parent()),started:s}))),r((({a1:s,a2:i})=>null!=s&&null!=i&&s.id===t.id&&e(s,i))),a((({a2:t})=>t)))}onBeginContact(t){return this.activateActorEvents(t),this.collisionEvents.pipe(l(t.disposed),r((t=>t.started)),r((({handle1:e})=>{const s=this.bodyActors.get(this.world.getCollider(e)?.parent());return null!=s&&s.id===t.id})),a((t=>t.handle2)))}onEndContact(t){return this.activateActorEvents(t),this.collisionEvents.pipe(l(t.disposed),r((t=>!t.started)),r((({handle1:e})=>{const s=this.bodyActors.get(this.world.getCollider(e)?.parent());return null!=s&&s.id===t.id})),a((t=>t.handle2)))}onHasContactChanged(t){const e=new Set,s=new o(!1);return this.onBeginContact(t).subscribe((t=>{e.add(t),s.next(e.size>0)})),this.onEndContact(t).subscribe((t=>{e.delete(t),s.next(e.size>0)})),s.pipe(n())}onBeginOverlapWithActorType(t,e){return this._onCollisionWithActorEvent(t,((t,s)=>s instanceof e),!0)}onEndOverlapWithActorType(t,e){return this._onCollisionWithActorEvent(t,((t,s)=>s instanceof e),!1)}onBeginOverlapWithActor(t,e){return this._onCollisionWithActorEvent(t,((t,s)=>e.id===s.id),!0)}onEndOverlapWithActor(t,e){return this._onCollisionWithActorEvent(t,((t,s)=>e.id===s.id),!1)}onCollisionWithActor(t,e){return this.onBeginOverlapWithActor(t,e)}onCollisionWithActorType(t,e){return this.onBeginOverlapWithActorType(t,e)}updateActorTransform(t){const e=this.actorBodies.get(t.id);null!=e?K(e,t.object):console.warn("Actor has not been added to physics world",t)}setupWorld(){const t=new s.World({x:0,y:-9.81,z:0});this.world=t}getActorContacts(t,e){const i=this.actorBodies.get(t.id);if(i&&i.numColliders()>0){const o=i.collider(0);let n=o.shape,r=o.translation(),a=o.rotation(),c=e,l=.3;const d=this.world.castShape(r,a,c,n,.1,l,!0,null,null,null,this.actorBodies.get(t.id),(t=>t.shape.type!=s.ShapeType.HeightField));if(null!=d){const t=new B,e=new B,s=new B;return it(t,d.witness2),it(e,d.witness1),it(s,d.normal1),s.negate(),[{ri:t,rj:e,ni:s}]}return[]}return console.warn("Actor is not added to the physics system"),[]}stop(){this.world?.bodies.forEach((t=>this.world.removeRigidBody(t))),this.world?.free(),this.fixedupdateSub?.unsubscribe()}createStaticBody(t,e,i){const o=i?.type===PhysicsBodyType.dynamic?s.RigidBodyDesc.dynamic():s.RigidBodyDesc.fixed(),n=this.world.createRigidBody(o);for(const s of e){if(null==s){console.warn("Collision shape is missing for object",t);continue}const o=this.addShape(n,s,t);null!=i?.friction&&o.setFriction(i.friction),null!=i?.density&&o.setDensity(i.density),null!=i?.mass&&o.setMass(i.mass/e.length),null!=i?.restitution&&o.setRestitution(i.restitution)}return K(n,t),n.userData=t.uuid,n}addShape(t,e,i){const o=i.getWorldScale(ct),n=this.createShape(e,o);null!=e.collisionGroup&&n.setCollisionGroups(e.collisionGroup),n.friction=e.friction??.1,null!=e.restitution&&(n.restitution=e.restitution),null!=e.density&&(n.density=e.density,n.massPropsMode=s.MassPropsMode.Density),null!=e.mass&&(n.mass=e.mass,n.massPropsMode=s.MassPropsMode.Mass);const r=e.offset.clone().multiply(o);st(n.translation,r);const a=(new w).setFromEuler(e.rotation);var c,l;e instanceof S&&e.mesh instanceof d.Mesh&&a.multiply(e.mesh.getWorldQuaternion(X)),c=n.rotation,l=a,c.x=l.x,c.y=l.y,c.z=l.z,c.w=l.w;return this.world.createCollider(n,t)}createShape(t,e){if(t instanceof C)return s.ColliderDesc.cuboid(t.dimensions.x*e.x/2,t.dimensions.y*e.y/2,t.dimensions.z*e.z/2);if(t instanceof D){return s.ColliderDesc.capsule(t.length/2*e.y,t.radius*Math.max(e.z,e.x))}if(t instanceof j){const i=null!=t.geometry.getIndex()?t.geometry:P.mergeVertices(t.geometry),o=extractFloat32Array(i.getAttribute("position"));for(let t=0;t<o.length;t+=3)o[t]*=e.x,o[t+1]*=e.y,o[t+2]*=e.z;return s.ColliderDesc.trimesh(o,new Uint32Array(i.getIndex().array))}if(t instanceof S){let i;t.mesh instanceof d.Mesh?i=t.mesh.geometry:t.mesh instanceof d.BufferGeometry?i=t.mesh:console.log("Unknownd shape",{shapeInfo:t});const o=extractFloat32Array(i.getAttribute("position"));if(t.mesh instanceof d.Mesh){const e=I(t.mesh);for(let t=0;t<o.length;t+=3)o[t]*=e.x,o[t+1]*=e.y,o[t+2]*=e.z}for(let t=0;t<o.length;t+=3)o[t]*=e.x,o[t+1]*=e.y,o[t+2]*=e.z;const n=o;n.length;return s.ColliderDesc.convexHull(n)}if(t instanceof F){const i=2*e.x-e.y-e.z;return Math.abs(i)>.01?this.createShape(new S(new d.SphereGeometry(t.radius).scale(e.x,e.y,e.z)),new B(1,1,1)):s.ColliderDesc.ball(t.radius*Math.max(e.x,e.y,e.z))}return t instanceof R?s.ColliderDesc.cylinder(t.height/2*e.y,t.radiusTop*Math.max(e.z,e.x)):t instanceof M?s.ColliderDesc.cone(t.height*e.y,t.radiusBottom/2*Math.max(e.z,e.x)):t instanceof E?s.ColliderDesc.cuboid(t.width/2*e.x,t.height/2*e.y,.001):(console.error("Unsupported shape",t),s.ColliderDesc.cuboid(1,1,1))}createCharacterCollision(){return new s.CharacterCollision}};U=t([b(),e("design:paramtypes",[V])],U);export{U as PhysicsSystem};const H=new B,X=new d.Quaternion;function K(t,e){const i=e.getWorldPosition(H),o=e.getWorldQuaternion(X);t.setTranslation(new s.Vector3(i.x,i.y,i.z),!1),t.setRotation(new s.Quaternion(o.x,o.y,o.z,o.w),!1)}const Y=new B,Z=new s.Vector3(0,0,0),J=new s.Vector3(0,0,0),$=new B,tt=new d.Vector2,et=async()=>{let t=await import("@dimforge/rapier3d-compat");return await t.init(),t};function st(t,e){t.x=e.x,t.y=e.y,t.z=e.z}function it(t,e){t.x=e.x,t.y=e.y,t.z=e.z}function ot(t,e){for(let s=0,i=t.numColliders();s<i;s++){e(t.collider(s))}}const nt=new B,rt=new B,at=t=>!t.isSensor(),ct=new B;const lt=new s.Ray(new s.Vector3(0,0,0),new s.Vector3(0,1,0));let dt=class extends k{constructor(){super(...arguments),this._active=!0,this.physics=N(U),this.world=N(_)}set active(t){this._active=t,t?(this.world.scene.remove(this.actor.object),this.physics.setEnabled(this.actor,t)):(this.world.scene.add(this.actor.object),this.physics.setEnabled(this.actor,t))}get active(){return this._active}};dt=t([O()],dt);export function extractFloat32Array(t){const e=t.itemSize,s=t.count,i=new Float32Array(s*e);for(let o=0;o<s;o++)for(let s=0;s<e;s++)i[o*e+s]=t.getComponent(o,s);return i}const ht=new B;/*
1
+ import{__decorate as t,__metadata as e}from"tslib";import*as s from"@dimforge/rapier3d-compat";import{QueryFilterFlags as i}from"@dimforge/rapier3d-compat";import{BehaviorSubject as o,distinctUntilChanged as n,filter as r,map as a,Subject as c,takeUntil as l}from"rxjs";import*as d from"three";import{ArrowHelper as h,BufferAttribute as u,BufferGeometry as y,Group as p,LineSegments as g,Matrix4 as m,Object3D as f,Quaternion as w,Raycaster as x,Scene as B,Vector3 as v}from"three";import{Service as b}from"typedi";import{AssetMeshInstance as C}from"../../../scene/asset-resource-loader.js";import{BoxCollisionShape as A,CapsuleCollisionShape as D,CollisionShapeSource as M,ConeCollisionShape as z,ConvexPolyhedronCollisionShape as S,CylinderCollisionShape as R,PhysicalShapeMesh as T,PlaneCollisionShape as E,SphereCollisionShape as F,TrimeshCollisionShape as W}from"../../../index.js";import{LandscapeGroup as j}from"../../../scene/landscape/landscape.js";import{ViewController as V}from"../render.js";import{World as _}from"../world.js";import*as I from"three/examples/jsm/utils/BufferGeometryUtils.js";import{calculateEffectiveScale as P}from"../../../utils/three/traverse.js";import{AbstractPhysicsSystem as k}from"./abstract-physics-system.js";import{ActorComponent as L,Component as O}from"../../../gameplay/actors/component.js";import{inject as N}from"../../../gameplay/inject.js";export{Component,ActorComponent,attach,Attach}from"../../actors/component.js";export class RayTestResult{constructor(){this.hasHit=!1,this.hitPoint=new v,this.hitNormal=new v}}export var PhysicsBodyType;!function(t){t[t.dynamic=1]="dynamic",t[t.static=2]="static",t[t.kinematic=4]="kinematic",t[t.kinematicVelocityBased=8]="kinematicVelocityBased"}(PhysicsBodyType||(PhysicsBodyType={}));const G=new v,q=new v,Q=new w;let U=class extends k{set showDebug(t){this.shouldRenderDebug=t,this.debugMesh&&(this.debugMesh.visible=t)}get showDebug(){return this.shouldRenderDebug}constructor(t){super(),this.viewController=t,this.staticMeshes=new Map,this.staticBodies=new Map,this.actorBodies=new Map,this.bodyActors=new Map,this.collisionEvents=new c,this.beforeStep=new c,this.afterStep=new c,this.shouldRenderDebug=!1,this.shapeCacheBox=new Map,this.shapeCacheBall=new Map,this._raycaster=new x,this._reusableResult=new RayTestResult,this._raytestDiff=new v,this._raytestDirection=new v,this.controlledActors=new Set,this.ready=this.setup()}hasBoxIntersection(t){const e=t.getCenter(G),i=t.getSize(q),o=i.x+1e6*i.y+1e12*i.z;if(!this.shapeCacheBox.has(o)){const t=new s.Cuboid(i.x/2,i.y/2,i.z/2);this.shapeCacheBox.set(o,t)}const n=this.shapeCacheBox.get(o);return null!=this.world.intersectionWithShape(e,Q,n)}hasSphereIntersection(t){const e=t.radius;if(!this.shapeCacheBox.has(e)){const i=new s.Ball(t.radius);this.shapeCacheBall.set(e,i)}const i=this.shapeCacheBall.get(e);return null!=this.world.intersectionWithShape(t.center,Q,i)}createDebugMesh(){return new g(new y,new d.LineBasicMaterial({color:255}))}async start(){return await this.ready,this.handleTick(),this.ready}renderDebug(){null==this.debugMesh&&(this.debugMesh=this.createDebugMesh(),this.debugMesh.visible=this.shouldRenderDebug,this.debugMesh.raycast=function(){},this.scene.add(this.debugMesh));const t=this.world.debugRender();this.debugMesh.geometry.setAttribute("position",new u(t.vertices,3))}async setup(){if(null!=this.rapier)throw new Error("Rapier is already estup");this.rapier=await et(),this.eventQueue=new s.EventQueue(!0),this.setupWorld()}handleTick(){this.fixedupdateSub=this.viewController.onUpdate().subscribe((t=>{t=Math.min(.1,t),this.beforeStep.next(t),this.updatePhysics(t),this.showDebug&&this.renderDebug(),this.world.bodies.forEach((t=>{if(t.isFixed())return;const e=this.staticMeshes.get(t)??this.bodyActors.get(t)?.object;var s,i;null!=e&&(e.parent instanceof B&&(it(e.position,t.translation()),(t.isDynamic()||t.isKinematic()&&!this.controlledActors.has(this.bodyActors.get(t)?.id))&&(s=e.quaternion,i=t.rotation(),s.x=i.x,s.y=i.y,s.z=i.z,s.w=i.w),e.updateMatrix(),e.updateWorldMatrix(!1,!1)))})),this.afterStep.next(t)}))}_updateWorld(){this.world.timestep=0,this.world.step()}updatePhysics(t){this.world.timestep=t,this.world.step(this.eventQueue),this.eventQueue.drainCollisionEvents(((t,e,s)=>{this.collisionEvents.next({handle1:t,handle2:e,started:s}),this.collisionEvents.next({handle1:e,handle2:t,started:s})}))}rayTestFromCamera(t,e,s){this._raycaster.setFromCamera(tt,this.viewController.getCamera());const i=this._raycaster.ray.origin,o=this._raycaster.ray.direction.multiplyScalar(t).add(i);return this.rayTest(i,o,e,s)}rayTest(t,e,s,i){null==s&&(s=this._reusableResult);const o=this._raytestDiff,n=this._raytestDirection;if(o.subVectors(e,t),n.copy(o).normalize(),0===n.length())return console.warn("Ray test called with to and from being equal"),s;st(lt.origin,t),st(lt.dir,n);const r=o.length(),a=this.world.castRayAndGetNormal(lt,r,!1,void 0,void 0,void 0,null!=i?.excludeActor?this.actorBodies.get(i.excludeActor.id):void 0,i?.excludeTriggers?t=>!t.isSensor():void 0);if(s.hasHit=null!=a,s.hasHit){const e=lt.pointAt(a.timeOfImpact);s._internal=a,it(s.hitNormal,a.normal),it(s.hitPoint,e),s.distance=nt.subVectors(s.hitPoint,t).length();const i=this.world.bodies.getAll().find((t=>function(t,e){for(let s=0,i=t.numColliders();s<i;s++){const i=t.collider(s);if(e(i))return i}}(t,(t=>t===a.collider))));s.actor=null!=i?this.bodyActors.get(i):null}if(this.showDebug){const e=new h(n,t,r,i?.debugColor??255);this.scene.add(e),setTimeout((()=>this.scene.remove(e)),i?.debugLifetime??200)}return s}setGravity(t,e,s){this.world.gravity.x=t,this.world.gravity.y=e,this.world.gravity.z=s}getGravity(){return Y.set(this.world.gravity.x,this.world.gravity.y,this.world.gravity.z)}addFromScene(t){this.addRecursively(t);for(const t of this.staticBodies.values())ot(t,(t=>t.setActiveEvents(s.ActiveEvents.COLLISION_EVENTS)))}addRecursively(t){if(this.removeSceneObject(t),!function(t){if(null!=t.userData?.src){const e=t.userData?.src;return"actor"===e.type}return!1}(t))if(t instanceof T&&null!=t.collisionShape){const e=this.createStaticBody(t,[t.collisionShape],t.physics);this.staticMeshes.set(e,t),this.staticBodies.set(t,e)}else if(t instanceof C&&!1!==t.userData?.src?.collisionDetection)if(t.children[0]&&t.children[0].instanceMatrix)this.createForInstancedMesh(t.children[0],t.collisionShapes);else{const e=this.createStaticBody(t,t.collisionShapes,t.physics);this.staticMeshes.set(e,t),this.staticBodies.set(t,e)}else t instanceof j?this.addLandscapeGroup(t):(t instanceof p||t instanceof B)&&t.children.forEach((t=>this.addRecursively(t)))}createForInstancedMesh(t,e){const s=new m,i=e.filter((t=>null!=t)).map((t=>t.source===M.rendered?t.withOffset(ht):t));for(let e=0;e<t.count;e++){if(null!=t.userData.hasCollision&&!t.userData.hasCollision[e])continue;const o=new f;o.matrix.identity(),s.fromArray(t.instanceMatrix.array,16*e),o.applyMatrix4(s);this.createStaticBody(o,i)}}getCharacterController(t){return this.world?.createCharacterController(t)}getActorComputedMovement(t,e,s,o=null){const n=this.actorBodies.get(t.id);this.controlledActors.add(t.id);const r=n.collider(0);e.computeColliderMovement(r,s,i.EXCLUDE_SENSORS,o,at);const a=e.computedMovement();return it(rt,a),rt}setNextKinematicTranslation(t,e){const s=this.actorBodies.get(t.id),i=s.translation();i.x+=e.x,i.y+=e.y,i.z+=e.z,s?.setNextKinematicTranslation(i)}setAngularVelocity(t,e){const s=this.actorBodies.get(t.id);Z.x=e.x,Z.y=e.y,Z.z=e.z,s?.setAngvel(Z,!0)}setLinearVelocity(t,e){const s=this.actorBodies.get(t.id);Z.x=e.x,Z.y=e.y,Z.z=e.z,s?.setLinvel(Z,!0)}getLinearVelocity(t,e=new v){const s=this.actorBodies.get(t.id).linvel();return e.x=s.x,e.y=s.y,e.z=s.z,e}getAngularVelocity(t,e=new v){const s=this.actorBodies.get(t.id).angvel();return e.x=s.x,e.y=s.y,e.z=s.z,e}setLinearDamping(t,e){const s=this.actorBodies.get(t.id);s?.setLinearDamping(e)}setAngularDamping(t,e){const s=this.actorBodies.get(t.id);s?.setAngularDamping(e)}lockTranslations(t,e){const s=this.actorBodies.get(t.id);s?.lockTranslations(e,!1)}lockRotations(t,e){const s=this.actorBodies.get(t.id);s?.lockRotations(e,!1)}setEnabledTranslations(t,e,s,i){const o=this.actorBodies.get(t.id);o?.setEnabledTranslations(e,s,i,!1)}setEnabledRotations(t,e,s,i){const o=this.actorBodies.get(t.id);o?.setEnabledRotations(e,s,i,!1)}addLandscapeGroup(t){const e=t.userData.src,i=e.landscape.heightMaps;for(const n of t.sections){this.staticBodies.has(n)&&this.world.removeRigidBody(this.staticBodies.get(n));var o=n.getWorldPosition(new v);if(e.landscape.holes&&e.landscape.holes.some((t=>t.m===n.name&&0!==t.w[0]))){const t=n.geometry.clone(),i=n.scale,r=n.geometry.getAttribute("hole"),a=new Float32Array(t.getAttribute("position").array);for(let t=0;t<a.length;t+=3)a[t]*=i.x,a[t+1]*=i.y,a[t+2]*=i.z;const c=t.index;for(let t=0;t<c.count;t+=3){const e=r.getX(c.getX(t)),s=r.getX(c.getY(t)),i=r.getX(c.getZ(t));(e>.5||s>.5||i>.5)&&(c.setX(t,0),c.setY(t,0),c.setZ(t,0))}const l=s.ColliderDesc.trimesh(a,new Uint32Array(t.getIndex().array));if(!1!==e.collisionDetection){const t=this.world.createRigidBody(s.RigidBodyDesc.fixed()),e=new s.Vector3(0,0,0);st(e,o),t.setTranslation(e,!1),this.world.createCollider(l,t),this.staticBodies.set(n,t)}continue}const t=e.landscape.options.density+1,r=e.landscape.options.sectionSize,a=new Array(t);for(let e=0;e<t;e++)a[e]=new Array(t).fill(0);const c=i.find((t=>t.x===n.x&&t.y==n.y));if(null!=c)for(const e of c.points){if(null==a[e.i%t])continue;const s=t-1-Math.floor(e.i/t);s in a[e.i%t]?a[e.i%t][s]=e.y/r:console.warn("wrong index",{points:a,point:e,i:e.i%t,k:s,heightMap:c})}const l=e.landscape.options.density,d=a.flatMap((t=>t.reverse())),h=s.ColliderDesc.heightfield(l,l,new Float32Array(d),new s.Vector3(r,r,r));if(!1!==e.collisionDetection){const t=this.world.createRigidBody(s.RigidBodyDesc.fixed()),e=new s.Vector3(0,0,0);st(e,o),t.setTranslation(e,!1),this.world.createCollider(h,t),this.staticBodies.set(n,t)}}}setEnabled(t,e){const s=this.actorBodies.get(t.id);s?.setEnabled(e)}addActor(t,e,i={}){if(0==e.length)return void console.error("No collision shapes were defined when adding actor to the physics system.");this.removeActor(t);const o=t.object;let n;switch(i.type??PhysicsBodyType.static){case PhysicsBodyType.dynamic:n=s.RigidBodyDesc.dynamic(),n.mass=i.mass??1;break;case PhysicsBodyType.kinematic:n=s.RigidBodyDesc.kinematicPositionBased();break;case PhysicsBodyType.kinematicVelocityBased:n=s.RigidBodyDesc.kinematicVelocityBased();break;default:n=i.isTrigger?s.RigidBodyDesc.kinematicVelocityBased():s.RigidBodyDesc.fixed()}const r=this.world.createRigidBody(n);r.enableCcd(1==i.continousCollisionDetection);for(const t of e)this.addShape(r,t,o);ot(r,(t=>{null!=i.isTrigger&&(t.setSensor(i.isTrigger),t.setActiveCollisionTypes(s.ActiveCollisionTypes.ALL),t.setActiveEvents(s.ActiveEvents.COLLISION_EVENTS)),null!=i.friction&&t.setFriction(i.friction),null!=i.density&&t.setDensity(i.density),null!=i.mass&&t.setMass(i.mass),null!=i.restitution&&t.setRestitution(i.restitution)})),K(r,o),!0===i.ignoreForNavMesh&&(r.userData={ignoreForNavMesh:!0}),this.actorBodies.set(t.id,r),this.bodyActors.set(r,t)}applyTorque(t,e){const s=this.actorBodies.get(t.id);Z.x=e.x,Z.y=e.y,Z.z=e.z,s?.addTorque(Z,!0)}applyTorqueImpulse(t,e){const s=this.actorBodies.get(t.id);Z.x=e.x,Z.y=e.y,Z.z=e.z,s?.applyTorqueImpulse(Z,!0)}resetForces(t){const e=this.actorBodies.get(t.id);e?.resetForces(!1)}resetTorques(t){const e=this.actorBodies.get(t.id);e?.resetTorques(!1)}applyForce(t,e){const s=this.actorBodies.get(t.id);Z.x=e.x,Z.y=e.y,Z.z=e.z,s?.addForce(Z,!0)}applyImpulse(t,e){const s=this.actorBodies.get(t.id);Z.x=e.x,Z.y=e.y,Z.z=e.z,s?.applyImpulse(Z,!0)}applyLocalForce(t,e,s){const i=this.actorBodies.get(t.id);st(Z,e),null==s?i?.addForce(Z,!0):(st(J,s),i?.addForceAtPoint(Z,J,!0))}applyLocalImpulse(t,e,s){const i=this.actorBodies.get(t.id);st(Z,e),null==s?i.applyImpulse(Z,!0):(st(J,s),i.applyImpulseAtPoint(Z,J,!0))}applyRadiusImpulse(t,e,i){this.world.bodies.forEach((o=>{if(o.collider(0)?.isSensor())return;if(o.bodyType()!==s.RigidBodyType.Dynamic)return;const n=$;it(n,o.translation());const r=n.clone().sub(t);if(r.length()>e)return;const a=r.clone().normalize().multiplyScalar(i);Z.x=a.x,Z.y=a.y,Z.z=a.z,o.applyImpulse(Z,!0)}))}removeActor(t){if(null==t)return;this.controlledActors.delete(t.id);const e=this.actorBodies.get(t.id);null!=e&&(this.bodyActors.delete(e),this.world.removeRigidBody(e)),this.actorBodies.delete(t.id)}removeRemoved(t){if(null==t)return;const e=new Set;t.traverse((t=>{e.add(t.uuid)}));for(const[t,s]of this.staticBodies.entries())!e.has(t.uuid)&&this.world.getRigidBody(s.handle)&&(this.staticBodies.delete(t),this.world.removeRigidBody(s))}removeSceneObject(t){if(t instanceof j){for(const e of t.sections)this.removeSceneObject(e);return}let e=this.staticBodies.get(t);null!=e&&this.world.getRigidBody(e.handle)&&this.world.removeRigidBody(e),this.staticBodies.delete(t)}activateActorEvents(t){this.actorBodies.get(t.id)}_onCollisionWithActorEvent(t,e,s){return this.activateActorEvents(t),this.collisionEvents.pipe(l(t.disposed),r((({started:t})=>t===s)),a((({handle1:t,handle2:e,started:s})=>({a1:this.bodyActors.get(this.world.getCollider(t)?.parent()),a2:this.bodyActors.get(this.world.getCollider(e)?.parent()),started:s}))),r((({a1:s,a2:i})=>null!=s&&null!=i&&s.id===t.id&&e(s,i))),a((({a2:t})=>t)))}onBeginContact(t){return this.activateActorEvents(t),this.collisionEvents.pipe(l(t.disposed),r((t=>t.started)),r((({handle1:e})=>{const s=this.bodyActors.get(this.world.getCollider(e)?.parent());return null!=s&&s.id===t.id})),a((t=>t.handle2)))}onEndContact(t){return this.activateActorEvents(t),this.collisionEvents.pipe(l(t.disposed),r((t=>!t.started)),r((({handle1:e})=>{const s=this.bodyActors.get(this.world.getCollider(e)?.parent());return null!=s&&s.id===t.id})),a((t=>t.handle2)))}onHasContactChanged(t){const e=new Set,s=new o(!1);return this.onBeginContact(t).subscribe((t=>{e.add(t),s.next(e.size>0)})),this.onEndContact(t).subscribe((t=>{e.delete(t),s.next(e.size>0)})),s.pipe(n())}onBeginOverlapWithActorType(t,e){return this._onCollisionWithActorEvent(t,((t,s)=>s instanceof e),!0)}onEndOverlapWithActorType(t,e){return this._onCollisionWithActorEvent(t,((t,s)=>s instanceof e),!1)}onBeginOverlapWithActor(t,e){return this._onCollisionWithActorEvent(t,((t,s)=>e.id===s.id),!0)}onEndOverlapWithActor(t,e){return this._onCollisionWithActorEvent(t,((t,s)=>e.id===s.id),!1)}onCollisionWithActor(t,e){return this.onBeginOverlapWithActor(t,e)}onCollisionWithActorType(t,e){return this.onBeginOverlapWithActorType(t,e)}updateActorTransform(t){const e=this.actorBodies.get(t.id);null!=e?K(e,t.object):console.warn("Actor has not been added to physics world",t)}setupWorld(){const t=new s.World({x:0,y:-9.81,z:0});this.world=t}getActorContacts(t,e){const i=this.actorBodies.get(t.id);if(i&&i.numColliders()>0){const o=i.collider(0);let n=o.shape,r=o.translation(),a=o.rotation(),c=e,l=.3;const d=this.world.castShape(r,a,c,n,.1,l,!0,null,null,null,this.actorBodies.get(t.id),(t=>t.shape.type!=s.ShapeType.HeightField));if(null!=d){const t=new v,e=new v,s=new v;return it(t,d.witness2),it(e,d.witness1),it(s,d.normal1),s.negate(),[{ri:t,rj:e,ni:s}]}return[]}return console.warn("Actor is not added to the physics system"),[]}stop(){this.world?.bodies.forEach((t=>this.world.removeRigidBody(t))),this.world?.free(),this.fixedupdateSub?.unsubscribe()}createStaticBody(t,e,i){const o=i?.type===PhysicsBodyType.dynamic?s.RigidBodyDesc.dynamic():s.RigidBodyDesc.fixed(),n=this.world.createRigidBody(o);for(const s of e){if(null==s){console.warn("Collision shape is missing for object",t);continue}const o=this.addShape(n,s,t);null!=i?.friction&&o.setFriction(i.friction),null!=i?.density&&o.setDensity(i.density),null!=i?.mass&&o.setMass(i.mass/e.length),null!=i?.restitution&&o.setRestitution(i.restitution)}return K(n,t),n.userData=t.uuid,n}addShape(t,e,i){const o=i.getWorldScale(ct),n=this.createShape(e,o);null!=e.collisionGroup&&n.setCollisionGroups(e.collisionGroup),n.friction=e.friction??.1,null!=e.restitution&&(n.restitution=e.restitution),null!=e.density&&(n.density=e.density,n.massPropsMode=s.MassPropsMode.Density),null!=e.mass&&(n.mass=e.mass,n.massPropsMode=s.MassPropsMode.Mass);const r=e.offset.clone().multiply(o);st(n.translation,r);const a=(new w).setFromEuler(e.rotation);var c,l;e instanceof S&&e.mesh instanceof d.Mesh&&a.multiply(e.mesh.getWorldQuaternion(X)),c=n.rotation,l=a,c.x=l.x,c.y=l.y,c.z=l.z,c.w=l.w;return this.world.createCollider(n,t)}createShape(t,e){if(t instanceof A)return s.ColliderDesc.cuboid(t.dimensions.x*e.x/2,t.dimensions.y*e.y/2,t.dimensions.z*e.z/2);if(t instanceof D){return s.ColliderDesc.capsule(t.length/2*e.y,t.radius*Math.max(e.z,e.x))}if(t instanceof W){const i=null!=t.geometry.getIndex()?t.geometry:I.mergeVertices(t.geometry),o=extractFloat32Array(i.getAttribute("position"));for(let t=0;t<o.length;t+=3)o[t]*=e.x,o[t+1]*=e.y,o[t+2]*=e.z;return s.ColliderDesc.trimesh(o,new Uint32Array(i.getIndex().array))}if(t instanceof S){let i;t.mesh instanceof d.Mesh?i=t.mesh.geometry:t.mesh instanceof d.BufferGeometry?i=t.mesh:console.log("Unknownd shape",{shapeInfo:t});const o=extractFloat32Array(i.getAttribute("position"));if(t.mesh instanceof d.Mesh){const e=P(t.mesh);for(let t=0;t<o.length;t+=3)o[t]*=e.x,o[t+1]*=e.y,o[t+2]*=e.z}for(let t=0;t<o.length;t+=3)o[t]*=e.x,o[t+1]*=e.y,o[t+2]*=e.z;const n=o;n.length;return s.ColliderDesc.convexHull(n)}if(t instanceof F){const i=2*e.x-e.y-e.z;return Math.abs(i)>.01?this.createShape(new S(new d.SphereGeometry(t.radius).scale(e.x,e.y,e.z)),new v(1,1,1)):s.ColliderDesc.ball(t.radius*Math.max(e.x,e.y,e.z))}return t instanceof R?s.ColliderDesc.cylinder(t.height/2*e.y,t.radiusTop*Math.max(e.z,e.x)):t instanceof z?s.ColliderDesc.cone(t.height*e.y,t.radiusBottom/2*Math.max(e.z,e.x)):t instanceof E?s.ColliderDesc.cuboid(t.width/2*e.x,t.height/2*e.y,.001):(console.error("Unsupported shape",t),s.ColliderDesc.cuboid(1,1,1))}createCharacterCollision(){return new s.CharacterCollision}};U=t([b(),e("design:paramtypes",[V])],U);export{U as PhysicsSystem};const H=new v,X=new d.Quaternion;function K(t,e){const i=e.getWorldPosition(H),o=e.getWorldQuaternion(X);t.setTranslation(new s.Vector3(i.x,i.y,i.z),!1),t.setRotation(new s.Quaternion(o.x,o.y,o.z,o.w),!1)}const Y=new v,Z=new s.Vector3(0,0,0),J=new s.Vector3(0,0,0),$=new v,tt=new d.Vector2,et=async()=>{let t=await import("@dimforge/rapier3d-compat");return await t.init(),t};function st(t,e){t.x=e.x,t.y=e.y,t.z=e.z}function it(t,e){t.x=e.x,t.y=e.y,t.z=e.z}function ot(t,e){for(let s=0,i=t.numColliders();s<i;s++){e(t.collider(s))}}const nt=new v,rt=new v,at=t=>!t.isSensor(),ct=new v;const lt=new s.Ray(new s.Vector3(0,0,0),new s.Vector3(0,1,0));let dt=class extends L{constructor(){super(...arguments),this._active=!0,this.physics=N(U),this.world=N(_)}set active(t){this._active=t,t?(this.world.scene.remove(this.actor.object),this.physics.setEnabled(this.actor,t)):(this.world.scene.add(this.actor.object),this.physics.setEnabled(this.actor,t))}get active(){return this._active}};dt=t([O()],dt);export function extractFloat32Array(t){const e=t.itemSize,s=t.count,i=new Float32Array(s*e);for(let o=0;o<s;o++)for(let s=0;s<e;s++)i[o*e+s]=t.getComponent(o,s);return i}const ht=new v;/*
2
2
  * Copyright (©) 2023. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -25,4 +25,5 @@ export interface PropertyParameter {
25
25
  }
26
26
  export declare function Parameter(options?: ParameterOptions): (target: Object, propertyName: string | symbol, index?: unknown) => void;
27
27
  export declare function extractShaderParameters(shaderType: Type<any>): PropertyParameter[];
28
+ export declare function ParameterCategory(name: string): void;
28
29
  //# sourceMappingURL=parameter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parameter.d.ts","sourceRoot":"","sources":["../../src/shader/parameter.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAA;AAEzB,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC7F,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAExH,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MA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AC,OAAO,CAAC,EAAE,gBAAgB,IACjC,QAAQ,MAAM,EAAE,cAAc,MAAM,GAAG,MAAM,EAAE,QAAQ,OAAO,KAAG,IAAI,CAevF;AAYD,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,iBAAiB,EAAE,CAyBlF;AAID,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,QAK7C"}
@@ -1,4 +1,4 @@
1
- import"reflect-metadata";import{reflect as t,decorateProperty as e}from"@plumier/reflect";import{ArrayMap as r}from"../utils/collections.js";Symbol("format");class o{constructor(t){this.options=t,this.isParameterDecorator=!0}}const a=new r;export function Parameter(t){return function(r,n,c){if(null!=r){a.push(r.constructor,{name:n,options:t??{}});try{e(new o(t))(r,n,c)}catch(t){console.warn("Failed to decorate method ",r,n,c)}}}}export function extractShaderParameters(t){return a.get(t).map((({name:e,options:r})=>{const o=Reflect.getMetadata("design:type",t.prototype,e),a=r.type??o;return r.array=o===Array,{name:e,type:a,options:r}}))}/*
1
+ import"reflect-metadata";import{reflect as t,decorateProperty as e}from"@plumier/reflect";import{ArrayMap as r}from"../utils/collections.js";Symbol("format");class o{constructor(t){this.options=t,this.isParameterDecorator=!0}}new Map;const a=new r;export function Parameter(t){return function(r,n,c){if(null!=r){a.push(r.constructor,{name:n,options:t??{}});try{e(new o(t))(r,n,c)}catch(t){console.warn("Failed to decorate method ",r,n,c)}}}}export function extractShaderParameters(t){return a.get(t).map((({name:e,options:r})=>{const o=Reflect.getMetadata("design:type",t.prototype,e),a=r.type??o;return r.array=o===Array,{name:e,type:a,options:r}}))}export function ParameterCategory(t){}/*
2
2
  * Copyright (©) 2023. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -1 +1 @@
1
- {"version":3,"file":"trail-shader.d.ts","sourceRoot":"","sources":["../../src/shader/trail-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAI9C,8BAAsB,eAAe;IACnC,KAAK,IAAI,QAAQ;IAgBjB,QAAQ,CAAC,MAAM,IAAI,gBAAgB;CACpC"}
1
+ {"version":3,"file":"trail-shader.d.ts","sourceRoot":"","sources":["../../src/shader/trail-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAI9C,8BAAsB,eAAe;IACnC,KAAK,IAAI,QAAQ;IAkBjB,QAAQ,CAAC,MAAM,IAAI,gBAAgB;CACpC"}
@@ -1,4 +1,4 @@
1
- import{NodeShaderMaterial as r}from"three-shader-graph";import{Trail as e}from"../effects/vfx/trail-renderer";export class TrailNodeShader{build(){const o=this.output(),{position:t}=e.getTrailShaderNodes(),a=new r({position:t,color:o.color});return e.applyTrailShaderParameters(a),a}}/*
1
+ import{NodeShaderMaterial as r}from"three-shader-graph";import{Trail as e}from"../effects/vfx/trail-renderer";export class TrailNodeShader{build(){const o=this.output(),{position:t}=e.getTrailShaderNodes(!1),a=new r({position:t,color:o.color});return e.applyTrailShaderParameters(a),a}}/*
2
2
  * Copyright (©) 2023. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */