@hology/core 0.0.86 → 0.0.88

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.
@@ -53,12 +53,12 @@ export declare class Trail extends THREE.Object3D {
53
53
  updateNodeCenter(nodeIndex: any, nodeCenter: any): void;
54
54
  updateNodePositionsFromOrientationTangent: (nodeIndex: any, nodeCenter: any, orientationTangent: any) => void;
55
55
  updateNodePositionsFromTransformMatrix: (nodeIndex: any, transformMatrix: any) => void;
56
- connectNodes: (srcNodeIndex: any, destNodeIndex: any) => {
56
+ connectNodes: (srcNodeIndex: number, destNodeIndex: number) => {
57
57
  attribute: any;
58
58
  offset: number;
59
59
  count: number;
60
60
  };
61
- disconnectNodes: (srcNodeIndex: any) => {
61
+ disconnectNodes: (srcNodeIndex: number) => {
62
62
  attribute: any;
63
63
  offset: number;
64
64
  count: number;
@@ -1,4 +1,4 @@
1
- import*as e from"three";export class Trail extends e.Object3D{constructor(t,r){super(),this.nodeCenters=[],this.nodeIDs=[],this.advance=function(){const t=new e.Matrix4;return function(){this.targetObject.updateMatrixWorld(),t.copy(this.targetObject.matrixWorld),this.advanceWithTransform(t),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 t=new e.Matrix4;return function(){this.currentEnd<0||(this.targetObject.updateMatrixWorld(),t.copy(this.targetObject.matrixWorld),this.updateNodePositionsFromTransformMatrix(this.currentEnd,t))}}(),this.updateNodePositionsFromOrientationTangent=function(){const t=new e.Quaternion,r=new e.Vector3,i=[];for(let t=0;t<Trail.MaxHeadVertices;t++){const t=new e.Vector3;i.push(t)}return function(e,a,n){const s=this.geometry.getAttribute("position");this.updateNodeCenter(e,a),r.copy(a),r.sub(Trail.LocalHeadOrigin),t.setFromUnitVectors(Trail.LocalOrientationTangent,n);for(let e=0;e<this.localHeadGeometry.length;e++){const a=i[e];a.copy(this.localHeadGeometry[e]),a.applyQuaternion(t),a.add(r)}for(let t=0;t<this.localHeadGeometry.length;t++){const r=(this.VerticesPerNode*e+t)*Trail.PositionComponentCount,a=i[t];s.array[r]=a.x,s.array[r+1]=a.y,s.array[r+2]=a.z}s.needsUpdate=!0}}(),this.updateNodePositionsFromTransformMatrix=function(){const t=new e.Matrix3,r=new e.Quaternion,i=new e.Vector3,a=new e.Vector3,n=new e.Vector3,s=new e.Vector3,o=[];for(let t=0;t<Trail.MaxHeadVertices;t++){const t=new e.Vector3;o.push(t)}return function(h,c){const l=this.geometry.getAttribute("position");i.set(0,0,0),i.applyMatrix4(c),this.updateNodeCenter(h,i);for(let e=0;e<this.localHeadGeometry.length;e++){o[e].copy(this.localHeadGeometry[e])}for(let e=0;e<this.localHeadGeometry.length;e++){o[e].applyMatrix4(c)}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])}(t,c),n.set(0,0,-1),n.applyMatrix3(t),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 e.Vector3),r.setFromUnitVectors(n,s),a.copy(this.currentNodeCenter);for(let e=0;e<this.localHeadGeometry.length;e++){const t=o[e];t.sub(a),t.applyQuaternion(r),t.add(a)}}for(let e=0;e<this.localHeadGeometry.length;e++){const t=(this.VerticesPerNode*h+e)*Trail.PositionComponentCount,r=o[e];l.array[t]=r.x,l.array[t+1]=r.y,l.array[t+2]=r.z}l.needsUpdate=!0,l.addUpdateRange(h*this.VerticesPerNode*Trail.PositionComponentCount,this.VerticesPerNode*Trail.PositionComponentCount)}}(),this.connectNodes=function(){const e={attribute:null,offset:0,count:-1};return function(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.updateRange.count=-1,e.attribute=i,e.offset=t*this.FacesPerNode*Trail.IndicesPerFace,e.count=this.FacesPerNode*Trail.IndicesPerFace,e}}(),this.disconnectNodes=function(){const e={attribute:null,offset:0,count:-1};return function(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.updateRange.count=-1,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=t,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(t,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 t=0;t<this.length;t++)this.nodeIDs[t]=-1,this.nodeCenters[t]=new e.Vector3;this.material=t,this.initializeGeometry(),this.initializeMesh(),this.material.uniforms.trailLength.value=0,this.material.uniforms.minID.value=0,this.material.uniforms.maxID.value=0,this.material.uniforms.dragTexture.value=this.dragTexture,this.material.uniforms.maxTrailLength.value=this.length,this.material.uniforms.verticesPerNode.value=this.VerticesPerNode,this.material.uniforms.textureTileFactor.value=new e.Vector2(1,1),this.material.uniforms.scale.value=1,this.reset()}initializeLocalHeadGeometry(t,r){if(this.localHeadGeometry=[],r){this.VerticesPerNode=0;for(let t=0;t<r.length&&t<Trail.MaxHeadVertices;t++){const i=r[t];if(i&&i instanceof e.Vector3){const t=new e.Vector3;t.copy(i),this.localHeadGeometry.push(t),this.VerticesPerNode++}}}else{const r=(t||1)/2;this.localHeadGeometry.push(new e.Vector3(-r,0,0)),this.localHeadGeometry.push(new e.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 t=new e.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 e.BufferAttribute(r,1);h.setUsage(e.DynamicDrawUsage),t.setAttribute("nodeID",h);const c=new e.BufferAttribute(i,1);c.setUsage(e.DynamicDrawUsage),t.setAttribute("nodeVertexID",c);const l=new e.BufferAttribute(n,Trail.PositionComponentCount);l.setUsage(e.DynamicDrawUsage),t.setAttribute("nodeCenter",l);const d=new e.BufferAttribute(a,Trail.PositionComponentCount);d.setUsage(e.DynamicDrawUsage),t.setAttribute("position",d);const u=new e.BufferAttribute(s,Trail.UVComponentCount);u.setUsage(e.DynamicDrawUsage),t.setAttribute("uv",u);const m=new e.BufferAttribute(o,1);m.setUsage(e.DynamicDrawUsage),t.setIndex(m),this.geometry=t}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.addUpdateRange(0,-1)}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.addUpdateRange(0,-1)}initializeMesh(){if(null==this.geometry)throw"Geometry not initialized";this.mesh=new e.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.value=this.currentLength,this.material.uniforms.maxTrailLength.value=this.length,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 createMaterial(t,r,i){return(i=i||{}).trailLength={type:"f",value:null},i.verticesPerNode={type:"f",value:null},i.minID={type:"f",value:null},i.maxID={type:"f",value:null},i.dragTexture={type:"f",value:null},i.maxTrailLength={type:"f",value:null},i.textureTileFactor={type:"v2",value:null},i.headColor={type:"v4",value:new e.Vector4},i.tailColor={type:"v4",value:new e.Vector4},i.taper={type:"bool",value:!1},i.scale={type:"f",value:1},t=t||Trail.Shader.BaseVertexShader,r=r||Trail.Shader.BaseFragmentShader,new e.ShaderMaterial({uniforms:i,vertexShader:t,fragmentShader:r,transparent:!0,alphaTest:.5,blending:e.CustomBlending,blendSrc:e.SrcAlphaFactor,blendDst:e.OneMinusSrcAlphaFactor,blendEquation:e.AddEquation,depthTest:!0,depthWrite:!1,side:e.DoubleSide})}static createBaseMaterial(e={}){return Trail.createMaterial(Trail.Shader.BaseVertexShader,Trail.Shader.BaseFragmentShader,e)}static createTexturedMaterial(e){return(e={}).trailTexture={type:"t",value:null},Trail.createMaterial(Trail.Shader.TexturedVertexShader,Trail.Shader.TexturedFragmentShader,e)}static get MaxHeadVertices(){return 128}static{this._LocalOrientationTangent=new e.Vector3(1,0,0)}static get LocalOrientationTangent(){return Trail._LocalOrientationTangent}static{this._LocalHeadOrigin=new e.Vector3(0,0,0)}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}static{this.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*as e from"three";export class Trail extends e.Object3D{constructor(t,r){super(),this.nodeCenters=[],this.nodeIDs=[],this.advance=function(){const t=new e.Matrix4;return function(){this.targetObject.updateMatrixWorld(),t.copy(this.targetObject.matrixWorld),this.advanceWithTransform(t),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 t=new e.Matrix4;return function(){this.currentEnd<0||(this.targetObject.updateMatrixWorld(),t.copy(this.targetObject.matrixWorld),this.updateNodePositionsFromTransformMatrix(this.currentEnd,t))}}(),this.updateNodePositionsFromOrientationTangent=function(){const t=new e.Quaternion,r=new e.Vector3,i=[];for(let t=0;t<Trail.MaxHeadVertices;t++){const t=new e.Vector3;i.push(t)}return function(e,a,n){const s=this.geometry.getAttribute("position");this.updateNodeCenter(e,a),r.copy(a),r.sub(Trail.LocalHeadOrigin),t.setFromUnitVectors(Trail.LocalOrientationTangent,n);for(let e=0;e<this.localHeadGeometry.length;e++){const a=i[e];a.copy(this.localHeadGeometry[e]),a.applyQuaternion(t),a.add(r)}for(let t=0;t<this.localHeadGeometry.length;t++){const r=(this.VerticesPerNode*e+t)*Trail.PositionComponentCount,a=i[t];s.array[r]=a.x,s.array[r+1]=a.y,s.array[r+2]=a.z}s.needsUpdate=!0}}(),this.updateNodePositionsFromTransformMatrix=function(){const t=new e.Matrix3,r=new e.Quaternion,i=new e.Vector3,a=new e.Vector3,n=new e.Vector3,s=new e.Vector3,o=[];for(let t=0;t<Trail.MaxHeadVertices;t++){const t=new e.Vector3;o.push(t)}return function(h,c){const l=this.geometry.getAttribute("position");i.set(0,0,0),i.applyMatrix4(c),this.updateNodeCenter(h,i);for(let e=0;e<this.localHeadGeometry.length;e++){o[e].copy(this.localHeadGeometry[e])}for(let e=0;e<this.localHeadGeometry.length;e++){o[e].applyMatrix4(c)}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])}(t,c),n.set(0,0,-1),n.applyMatrix3(t),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 e.Vector3),r.setFromUnitVectors(n,s),a.copy(this.currentNodeCenter);for(let e=0;e<this.localHeadGeometry.length;e++){const t=o[e];t.sub(a),t.applyQuaternion(r),t.add(a)}}for(let e=0;e<this.localHeadGeometry.length;e++){const t=(this.VerticesPerNode*h+e)*Trail.PositionComponentCount,r=o[e];l.array[t]=r.x,l.array[t+1]=r.y,l.array[t+2]=r.z}l.needsUpdate=!0,l.addUpdateRange(h*this.VerticesPerNode*Trail.PositionComponentCount,this.VerticesPerNode*Trail.PositionComponentCount)}}(),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=t,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(t,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 t=0;t<this.length;t++)this.nodeIDs[t]=-1,this.nodeCenters[t]=new e.Vector3;this.material=t,this.initializeGeometry(),this.initializeMesh(),this.material.uniforms.trailLength.value=0,this.material.uniforms.minID.value=0,this.material.uniforms.maxID.value=0,this.material.uniforms.dragTexture.value=this.dragTexture,this.material.uniforms.maxTrailLength.value=this.length,this.material.uniforms.verticesPerNode.value=this.VerticesPerNode,this.material.uniforms.textureTileFactor.value=new e.Vector2(1,1),this.material.uniforms.scale.value=1,this.reset()}initializeLocalHeadGeometry(t,r){if(this.localHeadGeometry=[],r){this.VerticesPerNode=0;for(let t=0;t<r.length&&t<Trail.MaxHeadVertices;t++){const i=r[t];if(i&&i instanceof e.Vector3){const t=new e.Vector3;t.copy(i),this.localHeadGeometry.push(t),this.VerticesPerNode++}}}else{const r=(t||1)/2;this.localHeadGeometry.push(new e.Vector3(-r,0,0)),this.localHeadGeometry.push(new e.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 t=new e.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 e.BufferAttribute(r,1);h.setUsage(e.DynamicDrawUsage),t.setAttribute("nodeID",h);const c=new e.BufferAttribute(i,1);c.setUsage(e.DynamicDrawUsage),t.setAttribute("nodeVertexID",c);const l=new e.BufferAttribute(n,Trail.PositionComponentCount);l.setUsage(e.DynamicDrawUsage),t.setAttribute("nodeCenter",l);const d=new e.BufferAttribute(a,Trail.PositionComponentCount);d.setUsage(e.DynamicDrawUsage),t.setAttribute("position",d);const u=new e.BufferAttribute(s,Trail.UVComponentCount);u.setUsage(e.DynamicDrawUsage),t.setAttribute("uv",u);const m=new e.BufferAttribute(o,1);m.setUsage(e.DynamicDrawUsage),t.setIndex(m),this.geometry=t}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 e.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.value=this.currentLength,this.material.uniforms.maxTrailLength.value=this.length,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 createMaterial(t,r,i){return(i=i||{}).trailLength={type:"f",value:null},i.verticesPerNode={type:"f",value:null},i.minID={type:"f",value:null},i.maxID={type:"f",value:null},i.dragTexture={type:"f",value:null},i.maxTrailLength={type:"f",value:null},i.textureTileFactor={type:"v2",value:null},i.headColor={type:"v4",value:new e.Vector4},i.tailColor={type:"v4",value:new e.Vector4},i.taper={type:"bool",value:!1},i.scale={type:"f",value:1},t=t||Trail.Shader.BaseVertexShader,r=r||Trail.Shader.BaseFragmentShader,new e.ShaderMaterial({uniforms:i,vertexShader:t,fragmentShader:r,transparent:!0,alphaTest:.5,blending:e.CustomBlending,blendSrc:e.SrcAlphaFactor,blendDst:e.OneMinusSrcAlphaFactor,blendEquation:e.AddEquation,depthTest:!0,depthWrite:!1,side:e.DoubleSide})}static createBaseMaterial(e={}){return Trail.createMaterial(Trail.Shader.BaseVertexShader,Trail.Shader.BaseFragmentShader,e)}static createTexturedMaterial(e){return(e={}).trailTexture={type:"t",value:null},Trail.createMaterial(Trail.Shader.TexturedVertexShader,Trail.Shader.TexturedFragmentShader,e)}static get MaxHeadVertices(){return 128}static{this._LocalOrientationTangent=new e.Vector3(1,0,0)}static get LocalOrientationTangent(){return Trail._LocalOrientationTangent}static{this._LocalHeadOrigin=new e.Vector3(0,0,0)}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}static{this.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
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -0,0 +1,5 @@
1
+ import{__decorate as t,__metadata as e}from"tslib";import{ActorComponent as i,Component as s}from"../component.js";import{Vector3 as o,MathUtils as n,PerspectiveCamera as a}from"three";import{ViewController as r}from"../../services/render.js";import{DecimalInput as h,RestrictedRotationInput as c}from"../../input/index.js";import{PhysicsSystem as d,RayTestResult as m}from"../../services/physics/physics-system.js";import{Parameter as l}from"../../../shader/parameter.js";import{World as p}from"../../services/world.js";import{inject as u}from"../../inject.js";const f=void 0!==window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let w=class extends i{constructor(t,e){super(),this.viewController=t,this.physicsSystem=e,this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.near=.5,this.far=500,this.viewAngle=f?30:45,this.camera=new a(this.viewAngle,this.aspect,this.near,this.far),this.distance=9,this.minDistance=1.5,this.maxDistance=this.distance,this.height=3,this.offsetX=-1,this.offsetZ=1.5,this.autoActivate=!0,this.bounceBackSpeed=5,this.collisionCheckRadius=.5,this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.rotationInput=new c(-Math.PI/4,Math.PI/2-.7),this.zoomInput=new h(1,0,1),this.offset=new o,this.lookAtOffset=new o(this.offsetX,0,this.offsetZ),this.fixedBehind=!0,this.world=u(p),this.isMouseLocked=!1,this.canvas=null,this.pointerLockInactivatedAt=null,this.onMouseDown=t=>{this.isMouseLocked||this.hideCursor()},this.onKeyDown=t=>{"Escape"===t.key&&this.showCursor()},this.onPointerLockChange=()=>{null!=document.pointerLockElement||null!=document.mozPointerLockElement||this.showCursor()}}async onInit(){this.world.scene.add(this.camera),this.rotationInput.rotation.copy(this.actor.rotation),this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.autoActivate&&this.activate()}activate(){this.viewController.setCamera(this.camera);const t=this.element;null!=document.body.requestPointerLock&&(t.addEventListener("mousedown",this.onMouseDown),t.addEventListener("keydown",this.onKeyDown),document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),this.disposed.subscribe((()=>{t.removeEventListener("mousedown",this.onMouseDown),t.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("pointerlockchange",this.onPointerLockChange,!1)})))}onLateUpdate(t){this.setFromRotation(t)}get element(){return this.viewController.htmlElement}hideCursor(){"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0||null!=this.pointerLockInactivatedAt&&performance.now()-this.pointerLockInactivatedAt<1600||(this.element.style.cursor="none",null==this.canvas&&(this.canvas=this.element.getElementsByTagName("canvas")[0]),this.canvas&&(this.canvas.requestPointerLock(),this.isMouseLocked=!0))}showCursor(){this.pointerLockInactivatedAt=performance.now(),this.element.style.cursor="default",window.document.exitPointerLock(),this.isMouseLocked=!1}setFromRotation(t){this.checkForCollision(t);const e=n.clamp(Math.min(this.restrictedDistance,this.distance),Math.min(this.minDistance,this.restrictedDistance),Math.max(this.distance*this.zoomInput.value,this.minDistance)),i=Math.cos(this.rotationInput.rotation.x)*e,s=this.fixedBehind?0:this.rotationInput.rotation.y;this.offset.x=Math.sin(-s)*i,this.offset.y=Math.sin(this.rotationInput.rotation.x)*e+2,this.offset.z=Math.cos(-s)*-i,this.offset.add(this.lookAtOffset),this.updateCameraPosition()}checkForCollision(t){const e=this.getLookAtPosition(),i=y;let s=!1,o=this.distance;const a=new m,r=this.camera.getWorldPosition(g);for(let t=-1;t<=1;t++){const n=k.subVectors(r,e);i.copy(r).add(n.multiplyScalar(1.2)),i.x+=t*this.collisionCheckRadius,this.physicsSystem.rayTest(e,i,a,{debugLifetime:0,excludeActor:this.actor,excludeTriggers:!0}),a.hasHit&&a.distance<this.distance&&(o=Math.min(a.distance,o),s||=a.hasHit)}s||(this.restrictedDistance=n.lerp(this.restrictedDistance,this.distance,n.clamp(this.bounceBackSpeed*t,0,1)))}getLookAtPosition(){const t=v;return t.set(0,0,0),t.y=this.height,t.add(this.lookAtOffset),t.applyMatrix4(this.actor.object.matrixWorld),t}updateCameraPosition(){this.fixedBehind?(this.actor.object.updateWorldMatrix(!0,!1),this.camera.position.set(this.offset.x,this.offset.y,this.offset.z),this.camera.rotation.set(0,0,0),this.camera.scale.set(1,1,1),this.camera.applyMatrix4(this.actor.object.matrix)):this.camera.position.copy(this.actor.position).add(this.offset);const t=this.getLookAtPosition();this.camera.lookAt(t)}};t([l(),e("design:type",Number)],w.prototype,"near",void 0),t([l(),e("design:type",Number)],w.prototype,"far",void 0),t([l(),e("design:type",Number)],w.prototype,"viewAngle",void 0),w=t([s(),e("design:paramtypes",[r,d])],w);export{w as ThirdPersonCameraComponent};const v=new o,y=new o,k=(new o,new o),g=new o;export class ThirdPartyCameraComponent extends w{}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -1,6 +1,6 @@
1
1
  export { CameraActor } from './builtin/camera-actor.js';
2
2
  export { CameraComponent } from './camera/camera-component.js';
3
- export { ThirdPersonCameraComponent, ThirdPartyCameraComponent } from './camera/third-party-camera-component.js';
3
+ export { ThirdPersonCameraComponent, ThirdPartyCameraComponent } from './camera/third-person-camera-component.js';
4
4
  export { SpawnPoint } from './builtin/spawn-point.js';
5
5
  export { TriggerVolume, TriggerVolumeComponent } from './builtin/trigger-volume.js';
6
6
  export { PositionalAudioActor, PositionalAudioComponent } from './builtin/positional-audio-actor.js';
@@ -1,4 +1,4 @@
1
- export{CameraActor}from"./builtin/camera-actor.js";export{CameraComponent}from"./camera/camera-component.js";export{ThirdPersonCameraComponent,ThirdPartyCameraComponent}from"./camera/third-party-camera-component.js";export{SpawnPoint}from"./builtin/spawn-point.js";export{TriggerVolume,TriggerVolumeComponent}from"./builtin/trigger-volume.js";export{PositionalAudioActor,PositionalAudioComponent}from"./builtin/positional-audio-actor.js";export*from"./builtin/components/mesh-component.js";export*from"./builtin/components/character/character-movement.js";export*from"./builtin/components/character/modes.js";export*from"./builtin/components/character/character-animation.js";
1
+ export{CameraActor}from"./builtin/camera-actor.js";export{CameraComponent}from"./camera/camera-component.js";export{ThirdPersonCameraComponent,ThirdPartyCameraComponent}from"./camera/third-person-camera-component.js";export{SpawnPoint}from"./builtin/spawn-point.js";export{TriggerVolume,TriggerVolumeComponent}from"./builtin/trigger-volume.js";export{PositionalAudioActor,PositionalAudioComponent}from"./builtin/positional-audio-actor.js";export*from"./builtin/components/mesh-component.js";export*from"./builtin/components/character/character-movement.js";export*from"./builtin/components/character/modes.js";export*from"./builtin/components/character/character-animation.js";
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
package/dist/rendering.js CHANGED
@@ -1,4 +1,4 @@
1
- var e;import{__decorate as t,__metadata as i}from"tslib";import*as s from"three";import{Color as r,Material as n,Matrix4 as a,Mesh as o,PerspectiveCamera as h,ShaderChunk as l,ShaderMaterial as d}from"three";import{EffectComposer as c,FXAAShader as m,GammaCorrectionShader as p,RenderPass as u,ShaderPass as f,UnrealBloomPass as g,VRButton as v}from"three-stdlib";import{CSMShader as x,CSMUtil as w}from"./csm.js";import{NodeShaderMaterial as b}from"three-shader-graph";import{Reflector as T}from"three-stdlib";import{OutputPass as y}from"three/examples/jsm/Addons.js";import{CSM as M}from"three/examples/jsm/csm/CSM.js";import C from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as P}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as R}from"typedi";import{depthUniformName as S,farUniformName as D,nearUniformName as F,resolutionUniformName as W,supportsDepthTextureExtension as A}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as H}from"./shader-nodes/time.js";import{DepthPass as L}from"./utils/three/depth-pass.js";import{GPUStatsPanel as k}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as O}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as j}from"./utils/three/traverse.js";(new s.Layers).set(9);const E=new s.MeshBasicMaterial({color:"black"}),B=new s.MeshDepthMaterial;B.depthPacking=s.RGBADepthPacking,B.blending=s.NoBlending,B.side=s.DoubleSide;const U=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let V=e=class{setPaused(e){this.paused=e}resizeRender(){this.previousClientWith===this.container.clientWidth&&this.previousClientHeight===this.container.clientHeight||(this.previousClientWith=this.container.clientWidth,this.previousClientHeight=this.container.clientHeight,this.camera instanceof h&&(this.camera.aspect=this.container.clientWidth/this.container.clientHeight,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(this.container.clientWidth,this.container.clientHeight),this.composer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.aoMaskDepthRenderTarget.dispose(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.aoPass.blendMaterial.uniforms.tDepth.value=this.aoMaskDepthRenderTarget.depthTexture)}constructor(t,i={}){this.container=t,this.options=i,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.resolutionScale=U?.5:1,this.maxPixelRatio=U?1:window.devicePixelRatio,this.onResize=()=>{this.resizeRender(),this.paused||this.render()},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!1,this.onLoopCallbacks=[],this.stats=new C,this._showStats=!0,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this.prevClearColor=new r,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],null!=i.maxPixelRatio&&(this.maxPixelRatio=i.maxPixelRatio),window.renderer=this.renderer=new s.WebGLRenderer({antialias:!0,powerPreference:"high-performance"}),this.scene=new s.Scene,this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(v.createButton(this.renderer)),this.composer=new c(this.renderer);var n=t.clientWidth/t.clientHeight;const a=new s.PerspectiveCamera(45,n,.5,800);a.layers.enable(19),this.setCamera(a),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=s.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=i.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=s.SRGBColorSpace,this.renderer.toneMapping=s.NoToneMapping,this.renderer.toneMappingExposure=1,this.renderer.gammaFactor=1.4,w.renderingView=this,w.patchThreeAdd(),this.isDepthTextureExtensionSupported=A(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container);const o=new u(this.scene,this.camera);this.composer.addPass(o);const h=new g(new s.Vector2(t.clientWidth,t.clientHeight),1.5,.4,.85);h.threshold=0,h.strength=.9,h.radius=1;const l=new P(this.scene,this.camera,t.clientWidth,t.clientWidth);l.blendMaterial.uniforms.tDepth={value:this.aoMaskDepthRenderTarget.depthTexture},l.blendMaterial.uniforms.tAODepth={value:l.depthTexture},l.blendMaterial.fragmentShader="\n uniform float intensity;\n uniform sampler2D tDiffuse;\n uniform sampler2D tDepth;\n uniform sampler2D tAODepth;\n varying vec2 vUv;\n\n void main() {\n vec4 texel = texture2D( tDiffuse, vUv );\n float d = textureLod(tDepth, vUv.xy, 0.0).x;\n float d2 = textureLod(tAODepth, vUv.xy, 0.0).x;\n\n float depth = 2.0 * 1.0 * 500.0 / (500.0 + 1.0 - (2.0 * d - 1.0) * (500.0 - 1.0));\n gl_FragColor = vec4(mix(vec3(1.), texel.rgb, d2 > d ? 0.0 : intensity), texel.a);\n }\n ",l.output=P.OUTPUT.Default,l.enabled=!1,this.aoPass=l,!1!==this.options.ao?.enabled&&this.composer.addPass(l),this.renderer.info.autoReset=!1;const d=new c(this.renderer);d.renderToScreen=!1,d.addPass(o),d.addPass(h),this.bloomComposer=d;const x=new f(new s.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:d.renderTarget2.texture}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }",fragmentShader:"\n uniform sampler2D baseTexture;\n uniform sampler2D bloomTexture;\n varying vec2 vUv;\n void main() {\n gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0 ) * texture2D( bloomTexture, vUv ) );\n }",defines:{}}),"baseTexture");if(x.needsSwap=!0,this.composer.addPass(x),this.outlinePass=new O(new s.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),!0===i.enableOutlines){this.outlinePass.edgeThickness=0,this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.composer.addPass(this.outlinePass);const e=new f(m);e.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(e)}new f(p).clear=!1,this.fixStatsStyle();const b=new y;this.composer.addPass(b)}fixStatsStyle(){const e=this.stats.dom;e.style.position="absolute";const t=e.getElementsByTagName("canvas");for(let e=0;e<t.length;e++)t.item(e).style.display="inline-block"}setCamera(e){this.camera=e,this.composer.passes.forEach((t=>{t instanceof u?t.camera=e:t instanceof O?t.renderCamera=e:(t instanceof L||t instanceof P)&&(t.camera=e)})),null==this.csm?(this.csm=new M({maxFar:500,lightFar:250,lightMargin:20,cascades:4,shadowMapSize:2048,lightDirection:new s.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene}),l.lights_fragment_begin=x.lights_fragment_begin):(this.csm.camera=this.camera,this.camera instanceof h&&(this.csm.maxFar=this.camera.far)),this.csm.updateFrustums()}setSelectedObjects(e){const t=new Map;for(const i of e)t.set(i.uuid,i);for(const i of e)i.traverse((e=>{e.uuid!==i.uuid&&t.has(e.uuid)&&t.delete(e.uuid)}));this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t){var i=!!e.extensions.get("WEBGL_depth_texture");const r=new s.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio());return r.texture.minFilter=s.NearestFilter,r.texture.magFilter=s.NearestFilter,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,!0===i&&(r.depthTexture=new s.DepthTexture(128,128),r.depthTexture.type=s.UnsignedShortType,r.depthTexture.minFilter=s.NearestFilter,r.depthTexture.magFilter=s.NearestFilter),r}static createAOMaskDepthRenderTarget(e,t){const i=new s.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio(),{type:s.HalfFloatType});return i.texture.minFilter=s.NearestFilter,i.texture.magFilter=s.NearestFilter,i.texture.generateMipmaps=!1,i.stencilBuffer=!1,i.depthTexture=new s.DepthTexture(128,128),i.depthTexture.type=s.UnsignedInt248Type,i.depthTexture.minFilter=s.NearestFilter,i.depthTexture.magFilter=s.NearestFilter,i}setupEventListeners(){window.addEventListener("resize",this.onResize),window.addEventListener("orientationchange",this.onResize),document.addEventListener("visibilitychange",this.onVisiblityChane)}stop(){this.running=!1,window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],this.renderer.dispose(),this.depthRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.csm.dispose(),this.container.replaceChildren()}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.find(e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&!this.container.contains(this.stats.dom)?this.container.appendChild(this.stats.dom):!this._showStats&&this.container.contains(this.stats.dom)&&this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}applyEnvMap(e){null!=this.scene.environment&&e instanceof b&&(null==e.uniforms.envMap&&(e.uniforms.envMap={value:this.scene.environment}),null==e.uniforms.envMapIntensity&&(e.uniforms.envMapIntensity={value:1}),e.uniforms.envMap.value=this.scene.environment,e.uniforms.envMapIntensity.value=this.scene.environmentIntensity,e.envMap=this.scene.environment)}loop(e,t=!1){const i=this.stats,r=i.addPanel(new C.Panel("Calls","#83f","#002")),h=i.addPanel(new C.Panel("Triangles","#c32","#002"));let l;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(l=new k(this.renderer.getContext()),i.addPanel(l)),this.showStats=t;let d=10,c=1e3;const m=()=>{const e=this.renderer.info.render.calls;e>d&&(d=e,setTimeout((()=>d=10),5e3)),r.update(e,d);const t=this.renderer.info.render.triangles;t>c&&(c=t,setTimeout((()=>c=1e3),5e3)),h.update(t,c)};performance.now();s.Ray.prototype.intersectTriangle;const p=[],u=[];let f=0;const g=new a,v=new a,x=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return void setTimeout((()=>x(t)),500);this.renderer.autoClear=!1,this.renderer.clear(),this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),this.camera,i.begin();let a=(t*=.001)-f;if(f=t,g.copy(this.camera.matrixWorld),a>1){let t=a;for(;t>.05;)e(z),t-=z;e(t)}else e(a);this.onLoopCallbacks.forEach((e=>e(a))),this.camera?.updateMatrixWorld(),v.copy(this.camera.matrixWorld),v.equals(g)||(this.renderer.shadowMap.needsUpdate=!0),this.resizeRender(),p.length=0,u.length=0;const h=_;if(this.camera.updateMatrixWorld(),N.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),h.setFromProjectionMatrix(N),this.scene.traverseVisible((e=>{if(null!=this.scene.environment&&(e instanceof o||e instanceof s.Sprite)&&function(e,t){if(Array.isArray(e.material))for(const i of e.material)t(i);else null!=e.material&&t(e.material)}(e,(e=>this.applyEnvMap(e))),(e instanceof o||e instanceof s.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[S])&&isObjectInFrustum(e,h)?(e.visible=!1,p.push(e),this.initDepthUniform(e.material),e.renderOrder=100):(e instanceof T||(e instanceof o||e instanceof s.Sprite)&&function(e){if(e.material instanceof n)return e.material.transparent||e.material.alphaTest>0;if(Array.isArray(e.material))for(const t of e.material)if(t.transparent||t.alphaTest>0)return!0}(e))&&(e.visible=!1,u.push(e)),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[H])e.material.uniforms[H].value=t;else if(e instanceof o&&Array.isArray(e.material))for(const i of e.material)i.uniforms&&null!=i.uniforms[H]&&(i.uniforms[H].value=t)})),p.length>0){if(this.scene.overrideMaterial=B,this.renderer.setRenderTarget(this.depthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}if(p.forEach((e=>e.visible=!0)),u.forEach((e=>e.visible=!0)),this.aoPass.enabled){if(this.scene.overrideMaterial=B,this.renderer.setRenderTarget(this.aoMaskDepthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}try{!this.paused&&this.running&&(this.showStats&&l?.startQuery(),this.render(a),this.showStats&&l?.endQuery(),this.showStats&&m(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}i.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout((()=>{requestAnimationFrame(x)}),1e3/this.fpsCap):requestAnimationFrame(x))};!0===this.options.enableXR?this.renderer.setAnimationLoop(x):requestAnimationFrame(x)}renderOverlay(){const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.container.clientWidth/2,i=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let s=0;s<e.length;s++)this.renderer.clearDepth(),this.renderer.setViewport(t-i/2+this.insetWidth*s+this.insetMargin*s,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[s])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){const t=this.hasBloom();if(t||this.hadBloom){const e=this.scene.fog;this.scene.fog=null;const t=this.renderer.getClearColor(this.prevClearColor);this.renderer.setClearColor(0),this.scene.traverseVisible((e=>this.darkenNonBloomed(e))),this.bloomComposer.render(),this.scene.traverse((e=>this.restoreMaterial(e))),this.bloomHidden.forEach((e=>e.visible=!0)),this.bloomHidden.length=0,this.renderer.setClearColor(t),this.scene.fog=e}this.hadBloom=t,this.composer.render(e)}hasBloom(){return null!=j(this.scene,(e=>e instanceof o&&!0===e.material?.userData?.hasBloom))}darkenNonBloomed(e){(e instanceof o||e instanceof s.Sprite||e instanceof s.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)?(this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=E:e.visible=!1):"TransformControlsPlane"!==e.type&&"TransformControlsGizmo"!==e.type||(e.visible=!1,this.bloomHidden.push(e))}restoreMaterial(e){this.bloomStoredMaterials[e.uuid]&&(e.material=this.bloomStoredMaterials[e.uuid],delete this.bloomStoredMaterials[e.uuid],e.visible=!0)}initDepthUniform(e){e instanceof d&&(e.uniforms[S].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,null!=e.uniforms[W]&&e.uniforms[W].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio()),this.camera instanceof h&&(e.uniforms[F].value=this.camera.near,e.uniforms[D].value=this.camera.far))}};V=e=t([R(),i("design:paramtypes",[HTMLElement,Object])],V);export{V as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const z=.05;P.prototype.overrideVisibility=function(){const e=this.scene,t=this._visibilityCache;e.traverse((function(e){if(t.set(e,e.visible),(e.isPoints||e.isLine)&&(e.visible=!1),null!=e.material){let t=!1;if(Array.isArray(e.material)){for(const i of e.material)if(null!=i.alphaTest&&i.alphaTest>0){t=!0;break}}else null!=e.material.alphaTest&&e.material.alphaTest>0&&(t=!0);t&&(e.visible=!1)}}))};const _=new s.Frustum,I=new s.Box3,N=new s.Matrix4;export function isObjectInFrustum(e,t){const i=I.setFromObject(e);return t.intersectsBox(i)}
1
+ var e;import{__decorate as t,__metadata as i}from"tslib";import*as s from"three";import{Color as r,Material as n,Matrix4 as a,Mesh as o,PerspectiveCamera as h,ShaderChunk as l,ShaderMaterial as d}from"three";import{EffectComposer as c,FXAAShader as m,GammaCorrectionShader as p,RenderPass as u,ShaderPass as f,UnrealBloomPass as g,VRButton as v}from"three-stdlib";import{CSMShader as x,CSMUtil as w}from"./csm.js";import{NodeShaderMaterial as b}from"three-shader-graph";import{Reflector as T}from"three-stdlib";import{OutputPass as y}from"three/examples/jsm/Addons.js";import{CSM as M}from"three/examples/jsm/csm/CSM.js";import C from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as P}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as R}from"typedi";import{depthUniformName as S,farUniformName as D,nearUniformName as F,resolutionUniformName as W,supportsDepthTextureExtension as A}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as H}from"./shader-nodes/time.js";import{DepthPass as L}from"./utils/three/depth-pass.js";import{GPUStatsPanel as k}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as O}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as j}from"./utils/three/traverse.js";(new s.Layers).set(9);const E=new s.MeshBasicMaterial({color:"black"}),B=new s.MeshDepthMaterial;B.depthPacking=s.RGBADepthPacking,B.blending=s.NoBlending,B.side=s.DoubleSide;const U=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let V=e=class{setPaused(e){this.paused=e}resizeRender(){this.previousClientWith===this.container.clientWidth&&this.previousClientHeight===this.container.clientHeight||(this.previousClientWith=this.container.clientWidth,this.previousClientHeight=this.container.clientHeight,this.camera instanceof h&&(this.camera.aspect=this.container.clientWidth/this.container.clientHeight,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(this.container.clientWidth,this.container.clientHeight),this.composer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.aoMaskDepthRenderTarget.dispose(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.aoPass.blendMaterial.uniforms.tDepth.value=this.aoMaskDepthRenderTarget.depthTexture)}constructor(t,i={}){this.container=t,this.options=i,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.resolutionScale=U?.5:1,this.maxPixelRatio=U?1:window.devicePixelRatio,this.onResize=()=>{this.resizeRender(),this.paused||this.render()},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!1,this.onLoopCallbacks=[],this.stats=new C,this._showStats=!0,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this.prevClearColor=new r,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],null!=i.maxPixelRatio&&(this.maxPixelRatio=i.maxPixelRatio),window.renderer=this.renderer=new s.WebGLRenderer({antialias:!0,powerPreference:"high-performance"}),this.scene=new s.Scene,this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(v.createButton(this.renderer)),this.composer=new c(this.renderer);var n=t.clientWidth/t.clientHeight;const a=new s.PerspectiveCamera(45,n,.5,800);a.layers.enable(19),this.setCamera(a),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=s.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=i.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=s.SRGBColorSpace,this.renderer.toneMapping=s.NoToneMapping,this.renderer.toneMappingExposure=1,this.renderer.gammaFactor=1.4,w.renderingView=this,w.patchThreeAdd(),this.isDepthTextureExtensionSupported=A(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container);const o=new u(this.scene,this.camera);this.composer.addPass(o);const h=new g(new s.Vector2(t.clientWidth,t.clientHeight),1.5,.4,.85);h.threshold=0,h.strength=.9,h.radius=1;const l=new P(this.scene,this.camera,t.clientWidth,t.clientWidth);l.blendMaterial.uniforms.tDepth={value:this.aoMaskDepthRenderTarget.depthTexture},l.blendMaterial.uniforms.tAODepth={value:l.depthTexture},l.blendMaterial.fragmentShader="\n uniform float intensity;\n uniform sampler2D tDiffuse;\n uniform sampler2D tDepth;\n uniform sampler2D tAODepth;\n varying vec2 vUv;\n\n void main() {\n vec4 texel = texture2D( tDiffuse, vUv );\n float d = textureLod(tDepth, vUv.xy, 0.0).x;\n float d2 = textureLod(tAODepth, vUv.xy, 0.0).x;\n\n float depth = 2.0 * 1.0 * 500.0 / (500.0 + 1.0 - (2.0 * d - 1.0) * (500.0 - 1.0));\n gl_FragColor = vec4(mix(vec3(1.), texel.rgb, d2 > d ? 0.0 : intensity), texel.a);\n }\n ",l.output=P.OUTPUT.Default,l.enabled=!1,this.aoPass=l,!1!==this.options.ao?.enabled&&this.composer.addPass(l),this.renderer.info.autoReset=!1;const d=new c(this.renderer);d.renderToScreen=!1,d.addPass(o),d.addPass(h),this.bloomComposer=d;const x=new f(new s.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:d.renderTarget2.texture}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }",fragmentShader:"\n uniform sampler2D baseTexture;\n uniform sampler2D bloomTexture;\n varying vec2 vUv;\n void main() {\n gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0 ) * texture2D( bloomTexture, vUv ) );\n }",defines:{}}),"baseTexture");if(x.needsSwap=!0,this.composer.addPass(x),this.outlinePass=new O(new s.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),!0===i.enableOutlines){this.outlinePass.edgeThickness=0,this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.composer.addPass(this.outlinePass);const e=new f(m);e.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(e)}new f(p).clear=!1,this.fixStatsStyle();const b=new y;this.composer.addPass(b)}fixStatsStyle(){const e=this.stats.dom;e.style.position="absolute";const t=e.getElementsByTagName("canvas");for(let e=0;e<t.length;e++)t.item(e).style.display="inline-block"}setCamera(e){this.camera=e,this.composer.passes.forEach((t=>{t instanceof u?t.camera=e:t instanceof O?t.renderCamera=e:(t instanceof L||t instanceof P)&&(t.camera=e)})),null==this.csm?(this.csm=new M({maxFar:500,lightFar:250,lightMargin:20,cascades:4,shadowMapSize:2048,lightDirection:new s.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene}),l.lights_fragment_begin=x.lights_fragment_begin):(this.csm.camera=this.camera,this.camera instanceof h&&(this.csm.maxFar=this.camera.far)),this.csm.updateFrustums()}setSelectedObjects(e){const t=new Map;for(const i of e)t.set(i.uuid,i);for(const i of e)i.traverse((e=>{e.uuid!==i.uuid&&t.has(e.uuid)&&t.delete(e.uuid)}));this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t){var i=!!e.extensions.get("WEBGL_depth_texture");const r=new s.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio());return r.texture.minFilter=s.NearestFilter,r.texture.magFilter=s.NearestFilter,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,!0===i&&(r.depthTexture=new s.DepthTexture(128,128),r.depthTexture.type=s.UnsignedShortType,r.depthTexture.minFilter=s.NearestFilter,r.depthTexture.magFilter=s.NearestFilter),r}static createAOMaskDepthRenderTarget(e,t){const i=new s.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio(),{type:s.HalfFloatType});return i.texture.minFilter=s.NearestFilter,i.texture.magFilter=s.NearestFilter,i.texture.generateMipmaps=!1,i.stencilBuffer=!1,i.depthTexture=new s.DepthTexture(128,128),i.depthTexture.type=s.UnsignedInt248Type,i.depthTexture.minFilter=s.NearestFilter,i.depthTexture.magFilter=s.NearestFilter,i}setupEventListeners(){window.addEventListener("resize",this.onResize),window.addEventListener("orientationchange",this.onResize),document.addEventListener("visibilitychange",this.onVisiblityChane)}stop(){this.running=!1,window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],this.renderer.dispose(),this.depthRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.csm.dispose(),this.container.replaceChildren()}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.find(e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&!this.container.contains(this.stats.dom)?this.container.appendChild(this.stats.dom):!this._showStats&&this.container.contains(this.stats.dom)&&this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}applyEnvMap(e){null!=this.scene.environment&&e instanceof b&&(null==e.uniforms.envMap&&(e.uniforms.envMap={value:this.scene.environment}),null==e.uniforms.envMapIntensity&&(e.uniforms.envMapIntensity={value:1}),e.uniforms.envMap.value=this.scene.environment,e.uniforms.envMapIntensity.value=this.scene.environmentIntensity,e.envMap=this.scene.environment)}loop(e,t=!1){const i=this.stats,r=i.addPanel(new C.Panel("Calls","#83f","#002")),h=i.addPanel(new C.Panel("Triangles","#c32","#002"));let l;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(l=new k(this.renderer.getContext()),i.addPanel(l)),this.showStats=t;let d=10,c=1e3;const m=()=>{const e=this.renderer.info.render.calls;e>d&&(d=e,setTimeout((()=>d=10),5e3)),r.update(e,d);const t=this.renderer.info.render.triangles;t>c&&(c=t,setTimeout((()=>c=1e3),5e3)),h.update(t,c)};performance.now();s.Ray.prototype.intersectTriangle;const p=[],u=[];let f=0;const g=new a,v=new a,x=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return void setTimeout((()=>x(t)),500);this.renderer.autoClear=!1,this.renderer.clear(),this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),this.camera,i.begin();let a=(t*=.001)-f;if(f=t,g.copy(this.camera.matrixWorld),a>1){let t=a;for(;t>.05;)e(z),t-=z;e(t)}else e(a);this.onLoopCallbacks.forEach((e=>e(a))),this.camera?.updateMatrixWorld(),v.copy(this.camera.matrixWorld),v.equals(g)||(this.renderer.shadowMap.needsUpdate=!0),this.resizeRender(),p.length=0,u.length=0;const h=_;if(this.camera.updateMatrixWorld(),N.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),h.setFromProjectionMatrix(N),this.scene.traverseVisible((e=>{if(null!=this.scene.environment&&(e instanceof o||e instanceof s.Sprite)&&function(e,t){if(Array.isArray(e.material))for(const i of e.material)t(i);else null!=e.material&&t(e.material)}(e,(e=>this.applyEnvMap(e))),(e instanceof o||e instanceof s.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[S])&&isObjectInFrustum(e,h)?(e.visible=!1,p.push(e),this.initDepthUniform(e.material),e.renderOrder=100):(e instanceof T||(e instanceof o||e instanceof s.Sprite)&&function(e){if(e.material instanceof n)return e.material.transparent||e.material.alphaTest>0;if(Array.isArray(e.material))for(const t of e.material)if(t.transparent||t.alphaTest>0)return!0}(e))&&(e.visible=!1,u.push(e)),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[H])e.material.uniforms[H].value=t;else if(e instanceof o&&Array.isArray(e.material))for(const i of e.material)i.uniforms&&null!=i.uniforms[H]&&(i.uniforms[H].value=t)})),p.length>0){if(this.scene.overrideMaterial=B,this.renderer.setRenderTarget(this.depthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}if(p.forEach((e=>e.visible=!0)),u.forEach((e=>e.visible=!0)),this.aoPass.enabled){if(this.scene.overrideMaterial=B,this.renderer.setRenderTarget(this.aoMaskDepthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}try{!this.paused&&this.running&&(this.showStats&&l?.startQuery(),this.render(a),this.showStats&&l?.endQuery(),this.showStats&&m(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}i.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout((()=>{requestAnimationFrame(x)}),1e3/this.fpsCap):requestAnimationFrame(x))};!0===this.options.enableXR?this.renderer.setAnimationLoop(x):requestAnimationFrame(x)}renderOverlay(){const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.container.clientWidth/2,i=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let s=0;s<e.length;s++)this.renderer.clearDepth(),this.renderer.setViewport(t-i/2+this.insetWidth*s+this.insetMargin*s,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[s])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){const t=this.hasBloom();if(t||this.hadBloom){const e=this.scene.fog;this.scene.fog=null;const t=this.renderer.getClearColor(this.prevClearColor);this.renderer.setClearColor(0),this.scene.traverseVisible((e=>this.darkenNonBloomed(e))),this.bloomComposer.render(),this.scene.traverse((e=>this.restoreMaterial(e))),this.bloomHidden.forEach((e=>e.visible=!0)),this.bloomHidden.length=0,this.renderer.setClearColor(t),this.scene.fog=e}this.hadBloom=t,this.composer.render(e)}hasBloom(){return null!=j(this.scene,(e=>e instanceof o&&!0===e.material?.userData?.hasBloom))}darkenNonBloomed(e){(e instanceof o||e instanceof s.Sprite||e instanceof s.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)?(this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=E:e.visible=!1):"TransformControlsPlane"!==e.type&&"TransformControlsGizmo"!==e.type||(e.visible=!1,this.bloomHidden.push(e))}restoreMaterial(e){this.bloomStoredMaterials[e.uuid]&&(e.material=this.bloomStoredMaterials[e.uuid],delete this.bloomStoredMaterials[e.uuid],e.visible=!0)}initDepthUniform(e){e instanceof d&&(e.uniforms[S].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,null!=e.uniforms[W]&&e.uniforms[W].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio()),this.camera instanceof h&&(e.uniforms[F].value=this.camera.near,e.uniforms[D].value=this.camera.far))}};V=e=t([R(),i("design:paramtypes",[HTMLElement,Object])],V);export{V as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const z=.05;P.prototype.overrideVisibility=function(){const e=this.scene,t=this._visibilityCache;e.traverse((function(e){if(t.set(e,e.visible),(e.isPoints||e.isLine||e.isTransformControls)&&(e.visible=!1),null!=e.material){let t=!1;if(Array.isArray(e.material)){for(const i of e.material)if(null!=i.alphaTest&&i.alphaTest>0){t=!0;break}}else null!=e.material.alphaTest&&e.material.alphaTest>0&&(t=!0);t&&(e.visible=!1)}}))};const _=new s.Frustum,I=new s.Box3,N=new s.Matrix4;export function isObjectInFrustum(e,t){const i=I.setFromObject(e);return t.intersectsBox(i)}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -0,0 +1,2 @@
1
+ import { FloatNode, Sampler2DNode, Vec2Node } from "three-shader-graph";
2
+ export declare function textureSequence(sampler: Sampler2DNode, uv: Vec2Node, alpha: FloatNode, columns: number, rows: number, frames?: number): import("three-shader-graph").RgbaNode;
@@ -0,0 +1,5 @@
1
+ import{float as i,floor as e,mod as d,textureSize as t,vec2 as l}from"three-shader-graph";export function textureSequence(r,p,u,m,v,n=m*v){const{x:o,y:y}=t(r,0),a=o.divide(m),c=y.divide(v),h=m*v,s=e(i(h).multiply(u.multiply(i(n).divide(h)))),x=d(s,i(m)).multiply(i(a)).divide(i(o)),f=e(s.divide(i(m))).multiply(i(c)).divide(i(y)),g=l(x,f);return r.sample(g.add(p))}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hology/core",
3
- "version": "0.0.86",
3
+ "version": "0.0.88",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -100,7 +100,7 @@
100
100
  "three-csm": "^4.2.1",
101
101
  "three-mesh-bvh": "^0.7.5",
102
102
  "three-nebula": "^10.0.3",
103
- "three-shader-graph": "0.2.11",
103
+ "three-shader-graph": "0.2.12",
104
104
  "three-stdlib": "2.34.0",
105
105
  "ts-key-enum": "^2.0.12",
106
106
  "typedi": "^0.10.0"