@quake2ts/engine 0.0.769 → 0.0.771
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.
- package/dist/browser/index.global.js +1 -1
- package/dist/browser/index.global.js.map +1 -1
- package/dist/cjs/index.cjs +4 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +4 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/render/particleSystem.d.ts +6 -0
- package/dist/types/render/particleSystem.d.ts.map +1 -1
- package/dist/types/render/webgpu/pipelines/particleSystem.d.ts +25 -9
- package/dist/types/render/webgpu/pipelines/particleSystem.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -551,7 +551,7 @@ void main() {
|
|
|
551
551
|
}
|
|
552
552
|
|
|
553
553
|
o_color = finalColor;
|
|
554
|
-
}`,Do=class{constructor(e,r,n,i){this.gl=e,this.geometry=hc(r),this.vertexBuffer=new Se(e,e.STATIC_DRAW),this.indexBuffer=new Te(e,e.STATIC_DRAW),this.vertexArray=new Ce(e),this.indexCount=this.geometry.indices.length,this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:48,offset:0},{index:1,size:3,type:e.FLOAT,stride:48,offset:12},{index:2,size:2,type:e.FLOAT,stride:48,offset:24},{index:3,size:4,type:e.FLOAT,stride:48,offset:32}],this.vertexBuffer),this.vertexArray.bind(),this.indexBuffer.bind(),this.indexBuffer.upload(this.geometry.indices,e.STATIC_DRAW),this.update(r,n,i)}update(e,r,n){let i=mc(e,this.geometry,r,n);this.vertexBuffer.upload(i,this.gl.STATIC_DRAW)}bind(){this.vertexArray.bind(),this.indexBuffer.bind()}dispose(){this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose(),this.wireframeIndexBuffer?.dispose()}},Es=class{constructor(e,r,n,i){this.surfaces=new Map;this.gl=e,this.model=r,this.blend=n,this.lighting=i,r.surfaces.forEach(o=>{this.surfaces.set(o.name,new Do(e,o,n,i))})}update(e,r){this.blend=e,this.lighting=r??this.lighting;for(let n of this.model.surfaces)this.surfaces.get(n.name)?.update(n,e,this.lighting)}dispose(){for(let e of this.surfaces.values())e.dispose();this.surfaces.clear()}},Ls=class{constructor(e){this.gl=e,this.program=ve.create(e,{vertex:pc,fragment:gc},{a_position:0,a_normal:1,a_texCoord:2,a_color:3}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformTint=this.program.getUniformLocation("u_tint"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformRenderMode=this.program.getUniformLocation("u_renderMode"),this.uniformSolidColor=this.program.getUniformLocation("u_solidColor"),this.uniformBrightness=this.program.getUniformLocation("u_brightness"),this.uniformGamma=this.program.getUniformLocation("u_gamma"),this.uniformFullbright=this.program.getUniformLocation("u_fullbright"),this.uniformGlobalAmbient=this.program.getUniformLocation("u_globalAmbient")}get shaderSize(){return this.program.sourceSize}bind(e,r=[1,1,1,1],n=0){this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,e),this.gl.uniform4fv(this.uniformTint,new Float32Array(r)),this.gl.uniform1i(this.uniformDiffuse,n),this.gl.uniform1i(this.uniformRenderMode,0),this.gl.uniform4f(this.uniformSolidColor,1,1,1,1)}drawSurface(e,r){let n=r?.diffuseSampler??0,i=r?.tint??[1,1,1,1],o=r?.renderMode,a=r?.brightness??1,s=r?.gamma??1,d=r?.fullbright??!1,l=r?.globalAmbient??0;this.gl.uniform4fv(this.uniformTint,new Float32Array(i)),this.gl.uniform1i(this.uniformDiffuse,n);let c=0,f=[1,1,1,1];if(o&&(o.mode==="solid"||o.mode==="wireframe"?c=1:o.mode==="solid-faceted"&&(c=2),o.color&&(f=[...o.color])),this.gl.uniform1i(this.uniformRenderMode,c),this.gl.uniform4f(this.uniformSolidColor,f[0],f[1],f[2],f[3]),this.gl.uniform1f(this.uniformBrightness,a),this.gl.uniform1f(this.uniformGamma,s),this.gl.uniform1i(this.uniformFullbright,d?1:0),this.gl.uniform1f(this.uniformGlobalAmbient,l),e.vertexArray.bind(),o&&o.mode==="wireframe"){if(!e.wireframeIndexBuffer){e.wireframeIndexBuffer=new Te(this.gl,this.gl.STATIC_DRAW);let u=li(e.geometry.indices);e.wireframeIndexBuffer.upload(u),e.wireframeIndexCount=u.length}e.wireframeIndexBuffer.bind(),this.gl.drawElements(this.gl.LINES,e.wireframeIndexCount,this.gl.UNSIGNED_SHORT,0)}else e.indexBuffer.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};var f1=[1,1,1,1],Ts=class{constructor(e,r){this.maxParticles=e,this.rng=r,this.alive=new Uint8Array(e),this.positionX=new Float32Array(e),this.positionY=new Float32Array(e),this.positionZ=new Float32Array(e),this.velocityX=new Float32Array(e),this.velocityY=new Float32Array(e),this.velocityZ=new Float32Array(e),this.colorR=new Float32Array(e),this.colorG=new Float32Array(e),this.colorB=new Float32Array(e),this.colorA=new Float32Array(e),this.size=new Float32Array(e),this.lifetime=new Float32Array(e),this.remaining=new Float32Array(e),this.gravity=new Float32Array(e),this.damping=new Float32Array(e),this.bounce=new Float32Array(e),this.fade=new Uint8Array(e),this.blendMode=new Uint8Array(e)}spawn(e){let r=this.findFreeSlot();if(r===-1)return null;let n=e.color??f1,i=e.velocity??{x:0,y:0,z:0};return this.alive[r]=1,this.positionX[r]=e.position.x,this.positionY[r]=e.position.y,this.positionZ[r]=e.position.z,this.velocityX[r]=i.x,this.velocityY[r]=i.y,this.velocityZ[r]=i.z,this.colorR[r]=n[0],this.colorG[r]=n[1],this.colorB[r]=n[2],this.colorA[r]=n[3],this.size[r]=e.size??2.5,this.lifetime[r]=e.lifetime,this.remaining[r]=e.lifetime,this.gravity[r]=e.gravity??800,this.damping[r]=e.damping??0,this.bounce[r]=e.bounce??.25,this.fade[r]=e.fade?1:0,this.blendMode[r]=e.blendMode==="additive"?1:0,r}update(e,r={}){let n=r.floorZ??-1/0;for(let i=0;i<this.maxParticles;i+=1){if(!this.alive[i])continue;if(this.remaining[i]-=e,this.remaining[i]<=0){this.alive[i]=0;continue}let o=Math.max(0,1-this.damping[i]*e);this.velocityX[i]*=o,this.velocityY[i]*=o,this.velocityZ[i]=this.velocityZ[i]*o-this.gravity[i]*e,this.positionX[i]+=this.velocityX[i]*e,this.positionY[i]+=this.velocityY[i]*e,this.positionZ[i]+=this.velocityZ[i]*e,this.positionZ[i]<n&&(this.positionZ[i]=n,this.velocityZ[i]=-this.velocityZ[i]*this.bounce[i],this.velocityX[i]*=.7,this.velocityY[i]*=.7)}}killAll(){this.alive.fill(0)}aliveCount(){let e=0;for(let r=0;r<this.maxParticles;r+=1)this.alive[r]&&(e+=1);return e}getState(e){return{alive:this.alive[e]===1,position:{x:this.positionX[e],y:this.positionY[e],z:this.positionZ[e]},velocity:{x:this.velocityX[e],y:this.velocityY[e],z:this.velocityZ[e]},remaining:this.remaining[e],color:[this.colorR[e],this.colorG[e],this.colorB[e],this.colorA[e]],size:this.size[e],blendMode:this.blendMode[e]===1?"additive":"alpha"}}buildMesh(e,r){let n=[],i=[],o=[],a=s=>{let d=i.length,l=0;for(let c=0;c<this.maxParticles;c+=1){if(!this.alive[c]||(s==="additive"?1:0)!==this.blendMode[c])continue;l+=1;let f=n.length/9,u=this.size[c]*.5,h=this.fade[c]?Math.max(this.remaining[c]/this.lifetime[c],0):1,m=this.blendMode[c]===1?1.2:1,g=this.colorR[c]*m,p=this.colorG[c]*m,y=this.colorB[c]*m,_=this.colorA[c]*h,x=this.positionX[c],b=this.positionY[c],v=this.positionZ[c],w=e.x*u,S=e.y*u,E=e.z*u,T=r.x*u,A=r.y*u,C=r.z*u,P=[{x:x-w-T,y:b-S-A,z:v-E-C},{x:x+w-T,y:b+S-A,z:v+E-C},{x:x-w+T,y:b-S+A,z:v-E+C},{x:x+w+T,y:b+S+A,z:v+E+C}],O=[[0,1],[1,1],[0,0],[1,0]];P.forEach((k,V)=>{n.push(k.x,k.y,k.z,O[V]?.[0]??0,O[V]?.[1]??0,g,p,y,_)}),i.push(f,f+1,f+2,f+2,f+1,f+3)}l>0&&o.push({blendMode:s,start:d,count:i.length-d})};return a("alpha"),a("additive"),{vertices:new Float32Array(n),indices:new Uint16Array(i),batches:o}}findFreeSlot(){for(let e=0;e<this.maxParticles;e+=1)if(!this.alive[e])return e;return-1}},yc=`#version 300 es
|
|
554
|
+
}`,Do=class{constructor(e,r,n,i){this.gl=e,this.geometry=hc(r),this.vertexBuffer=new Se(e,e.STATIC_DRAW),this.indexBuffer=new Te(e,e.STATIC_DRAW),this.vertexArray=new Ce(e),this.indexCount=this.geometry.indices.length,this.vertexArray.configureAttributes([{index:0,size:3,type:e.FLOAT,stride:48,offset:0},{index:1,size:3,type:e.FLOAT,stride:48,offset:12},{index:2,size:2,type:e.FLOAT,stride:48,offset:24},{index:3,size:4,type:e.FLOAT,stride:48,offset:32}],this.vertexBuffer),this.vertexArray.bind(),this.indexBuffer.bind(),this.indexBuffer.upload(this.geometry.indices,e.STATIC_DRAW),this.update(r,n,i)}update(e,r,n){let i=mc(e,this.geometry,r,n);this.vertexBuffer.upload(i,this.gl.STATIC_DRAW)}bind(){this.vertexArray.bind(),this.indexBuffer.bind()}dispose(){this.vertexBuffer.dispose(),this.indexBuffer.dispose(),this.vertexArray.dispose(),this.wireframeIndexBuffer?.dispose()}},Es=class{constructor(e,r,n,i){this.surfaces=new Map;this.gl=e,this.model=r,this.blend=n,this.lighting=i,r.surfaces.forEach(o=>{this.surfaces.set(o.name,new Do(e,o,n,i))})}update(e,r){this.blend=e,this.lighting=r??this.lighting;for(let n of this.model.surfaces)this.surfaces.get(n.name)?.update(n,e,this.lighting)}dispose(){for(let e of this.surfaces.values())e.dispose();this.surfaces.clear()}},Ls=class{constructor(e){this.gl=e,this.program=ve.create(e,{vertex:pc,fragment:gc},{a_position:0,a_normal:1,a_texCoord:2,a_color:3}),this.uniformMvp=this.program.getUniformLocation("u_modelViewProjection"),this.uniformTint=this.program.getUniformLocation("u_tint"),this.uniformDiffuse=this.program.getUniformLocation("u_diffuseMap"),this.uniformRenderMode=this.program.getUniformLocation("u_renderMode"),this.uniformSolidColor=this.program.getUniformLocation("u_solidColor"),this.uniformBrightness=this.program.getUniformLocation("u_brightness"),this.uniformGamma=this.program.getUniformLocation("u_gamma"),this.uniformFullbright=this.program.getUniformLocation("u_fullbright"),this.uniformGlobalAmbient=this.program.getUniformLocation("u_globalAmbient")}get shaderSize(){return this.program.sourceSize}bind(e,r=[1,1,1,1],n=0){this.program.use(),this.gl.uniformMatrix4fv(this.uniformMvp,!1,e),this.gl.uniform4fv(this.uniformTint,new Float32Array(r)),this.gl.uniform1i(this.uniformDiffuse,n),this.gl.uniform1i(this.uniformRenderMode,0),this.gl.uniform4f(this.uniformSolidColor,1,1,1,1)}drawSurface(e,r){let n=r?.diffuseSampler??0,i=r?.tint??[1,1,1,1],o=r?.renderMode,a=r?.brightness??1,s=r?.gamma??1,d=r?.fullbright??!1,l=r?.globalAmbient??0;this.gl.uniform4fv(this.uniformTint,new Float32Array(i)),this.gl.uniform1i(this.uniformDiffuse,n);let c=0,f=[1,1,1,1];if(o&&(o.mode==="solid"||o.mode==="wireframe"?c=1:o.mode==="solid-faceted"&&(c=2),o.color&&(f=[...o.color])),this.gl.uniform1i(this.uniformRenderMode,c),this.gl.uniform4f(this.uniformSolidColor,f[0],f[1],f[2],f[3]),this.gl.uniform1f(this.uniformBrightness,a),this.gl.uniform1f(this.uniformGamma,s),this.gl.uniform1i(this.uniformFullbright,d?1:0),this.gl.uniform1f(this.uniformGlobalAmbient,l),e.vertexArray.bind(),o&&o.mode==="wireframe"){if(!e.wireframeIndexBuffer){e.wireframeIndexBuffer=new Te(this.gl,this.gl.STATIC_DRAW);let u=li(e.geometry.indices);e.wireframeIndexBuffer.upload(u),e.wireframeIndexCount=u.length}e.wireframeIndexBuffer.bind(),this.gl.drawElements(this.gl.LINES,e.wireframeIndexCount,this.gl.UNSIGNED_SHORT,0)}else e.indexBuffer.bind(),this.gl.drawElements(this.gl.TRIANGLES,e.indexCount,this.gl.UNSIGNED_SHORT,0)}dispose(){this.program.dispose()}};var f1=[1,1,1,1],Ts=class{constructor(e,r){this.maxParticles=e,this.rng=r,this.alive=new Uint8Array(e),this.positionX=new Float32Array(e),this.positionY=new Float32Array(e),this.positionZ=new Float32Array(e),this.velocityX=new Float32Array(e),this.velocityY=new Float32Array(e),this.velocityZ=new Float32Array(e),this.colorR=new Float32Array(e),this.colorG=new Float32Array(e),this.colorB=new Float32Array(e),this.colorA=new Float32Array(e),this.size=new Float32Array(e),this.lifetime=new Float32Array(e),this.remaining=new Float32Array(e),this.gravity=new Float32Array(e),this.damping=new Float32Array(e),this.bounce=new Float32Array(e),this.fade=new Uint8Array(e),this.blendMode=new Uint8Array(e),this.textureIndex=new Int16Array(e)}spawn(e){let r=this.findFreeSlot();if(r===-1)return null;let n=e.color??f1,i=e.velocity??{x:0,y:0,z:0};return this.alive[r]=1,this.positionX[r]=e.position.x,this.positionY[r]=e.position.y,this.positionZ[r]=e.position.z,this.velocityX[r]=i.x,this.velocityY[r]=i.y,this.velocityZ[r]=i.z,this.colorR[r]=n[0],this.colorG[r]=n[1],this.colorB[r]=n[2],this.colorA[r]=n[3],this.size[r]=e.size??2.5,this.lifetime[r]=e.lifetime,this.remaining[r]=e.lifetime,this.gravity[r]=e.gravity??800,this.damping[r]=e.damping??0,this.bounce[r]=e.bounce??.25,this.fade[r]=e.fade?1:0,this.blendMode[r]=e.blendMode==="additive"?1:0,this.textureIndex[r]=e.textureIndex??0,r}update(e,r={}){let n=r.floorZ??-1/0;for(let i=0;i<this.maxParticles;i+=1){if(!this.alive[i])continue;if(this.remaining[i]-=e,this.remaining[i]<=0){this.alive[i]=0;continue}let o=Math.max(0,1-this.damping[i]*e);this.velocityX[i]*=o,this.velocityY[i]*=o,this.velocityZ[i]=this.velocityZ[i]*o-this.gravity[i]*e,this.positionX[i]+=this.velocityX[i]*e,this.positionY[i]+=this.velocityY[i]*e,this.positionZ[i]+=this.velocityZ[i]*e,this.positionZ[i]<n&&(this.positionZ[i]=n,this.velocityZ[i]=-this.velocityZ[i]*this.bounce[i],this.velocityX[i]*=.7,this.velocityY[i]*=.7)}}killAll(){this.alive.fill(0)}aliveCount(){let e=0;for(let r=0;r<this.maxParticles;r+=1)this.alive[r]&&(e+=1);return e}getState(e){return{alive:this.alive[e]===1,position:{x:this.positionX[e],y:this.positionY[e],z:this.positionZ[e]},velocity:{x:this.velocityX[e],y:this.velocityY[e],z:this.velocityZ[e]},remaining:this.remaining[e],color:[this.colorR[e],this.colorG[e],this.colorB[e],this.colorA[e]],size:this.size[e],blendMode:this.blendMode[e]===1?"additive":"alpha",textureIndex:this.textureIndex[e]}}buildMesh(e,r){let n=[],i=[],o=[],a=s=>{let d=i.length,l=0;for(let c=0;c<this.maxParticles;c+=1){if(!this.alive[c]||(s==="additive"?1:0)!==this.blendMode[c])continue;l+=1;let f=n.length/9,u=this.size[c]*.5,h=this.fade[c]?Math.max(this.remaining[c]/this.lifetime[c],0):1,m=this.blendMode[c]===1?1.2:1,g=this.colorR[c]*m,p=this.colorG[c]*m,y=this.colorB[c]*m,_=this.colorA[c]*h,x=this.positionX[c],b=this.positionY[c],v=this.positionZ[c],w=e.x*u,S=e.y*u,E=e.z*u,T=r.x*u,A=r.y*u,C=r.z*u,P=[{x:x-w-T,y:b-S-A,z:v-E-C},{x:x+w-T,y:b+S-A,z:v+E-C},{x:x-w+T,y:b-S+A,z:v-E+C},{x:x+w+T,y:b+S+A,z:v+E+C}],O=[[0,1],[1,1],[0,0],[1,0]];P.forEach((k,V)=>{n.push(k.x,k.y,k.z,O[V]?.[0]??0,O[V]?.[1]??0,g,p,y,_)}),i.push(f,f+1,f+2,f+2,f+1,f+3)}l>0&&o.push({blendMode:s,start:d,count:i.length-d})};return a("alpha"),a("additive"),{vertices:new Float32Array(n),indices:new Uint16Array(i),batches:o}}findFreeSlot(){for(let e=0;e<this.maxParticles;e+=1)if(!this.alive[e])return e;return-1}},yc=`#version 300 es
|
|
555
555
|
precision highp float;
|
|
556
556
|
|
|
557
557
|
layout(location = 0) in vec3 a_position;
|