@hology/core 0.0.153 → 0.0.155
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/effects/vfx/vfx-materializer.d.ts.map +1 -1
- package/dist/effects/vfx/vfx-materializer.js +1 -1
- package/dist/gameplay/services/physics/physics-system.d.ts +1 -0
- package/dist/gameplay/services/physics/physics-system.d.ts.map +1 -1
- package/dist/gameplay/services/physics/physics-system.js +1 -1
- package/dist/rendering/bloom/LuminosityHighPassShader.d.ts +28 -0
- package/dist/rendering/bloom/LuminosityHighPassShader.d.ts.map +1 -0
- package/dist/rendering/bloom/LuminosityHighPassShader.js +4 -0
- package/dist/rendering/bloom/UnrealBloomPass.d.ts +89 -0
- package/dist/rendering/bloom/UnrealBloomPass.d.ts.map +1 -0
- package/dist/rendering/bloom/UnrealBloomPass.js +4 -0
- package/dist/rendering/bloom/types.d.ts +14 -0
- package/dist/rendering/bloom/types.d.ts.map +1 -0
- package/dist/rendering/bloom/types.js +4 -0
- package/dist/rendering/outline-effect.js +1 -1
- package/dist/rendering/ssr/SSRPass.d.ts +9 -2
- package/dist/rendering/ssr/SSRPass.d.ts.map +1 -1
- package/dist/rendering/ssr/SSRPass.js +1 -1
- package/dist/rendering/ssr/SSRShader.d.ts.map +1 -1
- package/dist/rendering/ssr/SSRShader.js +1 -1
- package/dist/rendering.d.ts +4 -0
- package/dist/rendering.d.ts.map +1 -1
- package/dist/rendering.js +1 -1
- package/dist/scene/asset-resource-loader.d.ts.map +1 -1
- package/dist/scene/asset-resource-loader.js +1 -1
- package/dist/scene/batched-mesh-2.d.ts +10 -0
- package/dist/scene/batched-mesh-2.d.ts.map +1 -0
- package/dist/scene/batched-mesh-2.js +4 -0
- package/dist/scene/landscape/landscape-manager.d.ts.map +1 -1
- package/dist/scene/landscape/landscape-manager.js +1 -1
- package/dist/scene/materializer.d.ts +5 -0
- package/dist/scene/materializer.d.ts.map +1 -1
- package/dist/scene/materializer.js +1 -1
- package/dist/shader/builtin/decal-standard-shader.d.ts +2 -0
- package/dist/shader/builtin/decal-standard-shader.d.ts.map +1 -1
- package/dist/shader/builtin/decal-standard-shader.js +1 -1
- package/dist/shader/builtin/decal-unlit-shader.d.ts +2 -1
- package/dist/shader/builtin/decal-unlit-shader.d.ts.map +1 -1
- package/dist/shader/builtin/decal-unlit-shader.js +1 -1
- package/dist/shader/builtin/lambert-shader.d.ts +3 -1
- package/dist/shader/builtin/lambert-shader.d.ts.map +1 -1
- package/dist/shader/builtin/lambert-shader.js +1 -1
- package/dist/shader/builtin/landscape-composite-shader.d.ts.map +1 -1
- package/dist/shader/builtin/landscape-composite-shader.js +1 -1
- package/dist/shader/builtin/standard-shader.d.ts.map +1 -1
- package/dist/shader/builtin/standard-shader.js +1 -1
- package/dist/shader/shader.d.ts +1 -0
- package/dist/shader/shader.d.ts.map +1 -1
- package/dist/shader-nodes/curve-sample.d.ts +11 -0
- package/dist/shader-nodes/curve-sample.d.ts.map +1 -0
- package/dist/shader-nodes/curve-sample.js +4 -0
- package/dist/shader-nodes/depth.d.ts +3 -0
- package/dist/shader-nodes/depth.d.ts.map +1 -1
- package/dist/shader-nodes/depth.js +1 -1
- package/dist/shader-nodes/index.d.ts +1 -0
- package/dist/shader-nodes/index.d.ts.map +1 -1
- package/dist/shader-nodes/index.js +1 -1
- package/dist/shader-nodes/pom.d.ts +7 -0
- package/dist/shader-nodes/pom.d.ts.map +1 -0
- package/dist/shader-nodes/pom.js +4 -0
- package/dist/utils/three/traverse.d.ts +2 -1
- package/dist/utils/three/traverse.d.ts.map +1 -1
- package/dist/utils/three/traverse.js +1 -1
- package/package.json +3 -3
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vfx-materializer.d.ts","sourceRoot":"","sources":["../../../src/effects/vfx/vfx-materializer.ts"],"names":[],"mappings":"AAAA,OAAO,MAAiE,MAAM,gBAAgB,CAAC;AAC/F,OAAO,KAAK,KAAK,MA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AM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAA;IACzC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACnD,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IACjD,WAAW,CAAC,OAAO,EAAE,MAAM,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;;;;GA2DpL;AA+0BD,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 a,Emitter as n,Rate as s}from"@hology/nebula";import*as r from"three";import{Object3D as i}from"three";import{AttributeVec3Node as o,AttributeVec4Node as l,NodeShaderMaterial as c,RgbNode as u,UniformFloatNode as p,UniformVec3Node as m,Vec3ExpressionNode as h,Vec4Node as d,attributeFloat as f,attributeVec3 as y,attributeVec4 as w,attributes as g,clamp as b,float as v,glslFunction as A,lambertMaterial as E,log as M,pow as x,rgb as I,rgba as T,smoothstep as P,standardMaterial as B,textureSampler2d as C,uniformFloat as S,uniforms as R,varying as k,varyingAttributes as j,varyingVec3 as D,varyingVec4 as z}from"three-shader-graph";import{prepareClassParameters as V,prepareShapeParameters as F}from"../../scene/materializer.js";import{SerializedParamType as L}from"../../scene/model.js";import{ShapeLibrary as O}from"../../scene/objects/shapes.js";import{fragmentLinearEyeDepth as Q,linearEyeDepth as W}from"../../shader-nodes/depth.js";import{particleEnergyUniformName as H,particleTimeUniformName as U,particleUniforms as q,particleVelcoityUniformName as G}from"../../shader-nodes/particle.js";import{sampleFlipbook as J}from"../../shader-nodes/texture-sequence.js";import{DefaultInitializer as N}from"./initializsers.js";import{DelayRate as K,OnceRate as Y}from"./rates.js";import{StretchedSprite as X}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{getSpritePosition as ae,SpriteNodeShaderMaterial as ne}from"../../shader/sprite-shader.js";import{DecalUnlitShader as se}from"../../shader/builtin/decal-unlit-shader.js";import{DecalStandardShader as re}from"../../shader/builtin/decal-standard-shader.js";export async function materializeVfx(t,a,n,s,o,l){let c=a;for(;null!=c.parent;)c=c.parent;const u=new i;u.name="particle system local",a.add(u);const p=new i;p.name="particle system world";const m=new ee(p,u,r,s),h=new e;return(await Promise.all(t.vfx.emitters.slice().sort((e,t)=>(t.output.renderOrder??0)-(e.output.renderOrder??0)).map(async e=>{const t=await ie(e,n,h,o,l);return t.setParentRecursive(h),t.emit()}))).forEach(e=>h.addEmitter(e)),h.addRenderer(m).emit({onEnd:()=>{}}),{container:p,system:h,dispose:()=>{p.removeFromParent(),u.removeFromParent(),m.dispose()}}}async function ie(e,t,n,u,v){const x=function(e){let t;switch(e.rate.type){case"continuous":t=new K(e.rate.delay??0,e.rate.count,e.rate.time,e.rate.duration);break;case"once":t=new Y(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 I;switch(e.output.type){case"decal":I=new a(await async function(e,t){const a=!1!==e.unlit?new se:new re;a.color=new r.Color(e.color),a instanceof se?a.intensity=e.intensity??1:a.emissiveIntensity=e.intensity??1;if(e.colorMap){const n=await t.getTexture(e.colorMap);a.colorMap=n}if(e.alphaMap){const n=await t.getTexture(e.alphaMap);a.alphaMap=n}const n=a.build();n.blending=Z[e.blendingMode]??r.NormalBlending,n.transparent=!0,n.side=r.BackSide,n.depthTest=!1,null!=n&&!0===e.bloom&&(n.userData.hasBloom=!0);n.defines.IS_PARTICLE="";const s=new r.BoxGeometry(1,1,1),i=new r.Mesh(s,n);null!=e.renderOrder&&(i.renderOrder=e.renderOrder);return i}(e.output,t));break;case"sprite":I=new a(await async function(e,t,a){let n=null;n=null!=e.shader?await le(e,t,a):await async function(e,t){const a=null!=e.texture?await t.getTexture(e.texture):oe,n=C(a);let s=n.sample(j.uv);e.flipbook?.enabled&&(s=J(n,g.uv,e.flipbook.columns,e.flipbook.rows,q.time,e.flipbook.fps,e.flipbook.mode));const i=new p("rotation",0),o=new m("color").rgb,l=S("opacity",1),c=W.subtract(Q).divide(W);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=b(c,0,1e3);u=u.multiply(P(0,.2*e.softness,t))}const h=ae(i);var d=new ne({color:T(o.multiply(s.rgb).multiplyScalar(e.intensity??1),u),transparent:!0,position:h,alphaTest:1e-4,uniforms:{color:{value:new r.Color(e.color)}}});d.alphaHash=!0,null!=d&&!0===e.bloom&&(d.userData.hasBloom=!0);return d.blending=Z[e.blendingMode]??r.NormalBlending,d}(e,t);n instanceof r.ShaderMaterial&&!0===e.lockY&&(n.defines.LOCK_Y_AXIS="");const s=new r.Mesh(new r.PlaneGeometry(1,1),n);return s.name="sprite",s}(e.output,t,v));break;case"stretchedSprite":I=new a(await async function(e,t){const a=null!=e.texture?await t.getTexture(e.texture):oe,n=C(a).sample(j.uv),s=z(new l("color")),i=s.rgb.multiply(n.rgb);let o=s.w;switch(e.opacityChannel??"red"){case"none":break;case"red":o=o.multiply(n.r);break;case"alpha":o=o.multiply(n.a)}if("number"==typeof e.softness&&e.softness>0){const t=W.subtract(Q).divide(M(W)),a=b(t,0,1e3);o=o.multiply(P(0,.2*e.softness,a))}const c=A(d,{position:g.position,offset:y("offset"),modelViewMatrix:R.modelViewMatrix,velocity:w("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 ne({color:T(i.multiplyScalar(e.intensity??1),o),alphaTest:.1,transparent:!0,position:c,uniforms:{color:{value:new r.Color(e.color)}}});null!=u&&!0===e.bloom&&(u.userData.hasBloom=!0);u.blending=Z[e.blendingMode]??r.NormalBlending;const p=new X(new r.PlaneGeometry(1,1),u);return p.scaleFactor=e.scale,p}(e.output,t));break;case"shape":I=new a(await async function(e,t,a){if(null==e.shape)return console.log("Shape is null"),new i;const n=O[e.shape];if(null==n)return console.error(`No shape with type ${e.shape}`),new i;const s=F(e.params??{}),l=n.geometry(s);let u=null;u=null!=e.shader?await le(e,t,a):null!=e.material?ce(await t.getMaterial(e.material)):function(){const e=k(new h("instanceColor")).rgb,t=k(new o("particleData")).x;return new c({color:E({color:e}).rgb.rgba(t),transparent:!0})}();null!=u&&!0===e.bloom&&(u.userData.hasBloom=!0);return new r.Mesh(l,u)}(e.output,t,v));break;case"mesh":I=new a(await async function(e,t,a){if(null==e.assetId)return console.warn("Can't use mesh as particle without asset id"),new i;const n=await t.getMesh(e.assetId),s=await t.getAsset(e.assetId);if(null!=e.shader||null!=e.material){let s;s=null!=e.shader?await le(e,t,a):ce(await t.getMaterial(e.material)),null!=s&&!0===e.bloom&&(s.userData.hasBloom=!0),null!=s&&!0===e.bloom&&(s.userData.hasBloom=!0),n.traverse(e=>{e instanceof r.Mesh&&(e.material=s)})}else{const e=[];if(null!=s.materialAssignments)for(const a of s.materialAssignments)n.traverse(n=>{n instanceof r.Mesh&&n.material instanceof r.Material&&n.material.color instanceof r.Color&&(n.material.name!=a.name&&null!=a.name||"#"+n.material.color.getHexString()!==a.color||e.push(t.getMaterial(a.materialId).then(e=>n.material=e)))});await Promise.all(e)}const o=[];if(n.traverse(e=>{e instanceof r.Mesh&&o.push(e)}),1===o.length){const e=o[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,v));break;case"trail":I=new a({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 B=new pe;B.parent=n,B.setRate(x),B._space=e.output.space;const D=await Promise.all(e.initializers.filter(e=>!1!==e.enabled).filter(e=>null!=$[e.type]).map(async e=>{const t=$[e.type],a=await F(e.params??{});return t.build(a)}));D.push(I,new N),B.addInitializers(D);const V=await Promise.all(e.behaviours.filter(e=>!1!==e.enabled).filter(e=>null!=_[e.type]).map(async e=>{const t=_[e.type];for(const[a,n]of Object.entries(e.params))t.parameters&&null!=t.parameters[a]&&"curve"===t.parameters[a].type&&n.type!==L.Curve&&(n.type=L.Curve);const a=await F(e.params??{});return t.build(a)}).sort((e,t)=>e instanceof te?1:0));V.push(new ue);for(const e of V)e instanceof te&&(e.physics=u);B.addBehaviours(V);for(const a of e.children){const e=await ie(a,t,n,u,v),s=new EmitterPool(()=>{const t=e.clone();return t.onExpired=()=>{const e=B.childEmitters.findIndex(e=>e.id===t.id);-1!=e&&B.childEmitters.splice(e,1),s.release(t)},t}),r=B.eventDispatcher,i=new Map;B.bindEmitterEvent=!0,r.addEventListener("PARTICLE_DEAD",e=>{const t=i.get(e.id);if(null!=t){const e=B.childEmitters.findIndex(e=>e.id===t.id);null!=e&&(t.stopEmit(),B.childEmitters.splice(e,1))}});let o="PARTICLE_CREATED";if("spawnEvent"in a)switch(a.spawnEvent){case"collision":o="PARTICLE_COLLISION";break;case"start":o="PARTICLE_CREATED"}r.addEventListener(o,e=>{const t=s.get();t.age=0,t.totalEmitTimes=-1,t.particles.length=0,t.currentEmitTime=0,t.cID=0,t.eventDispatcher.removeAllEventListeners(),B.childEmitters.push(t),i.set(e.id,t),t.parentParticle=e,t.system=B.system,t.emit()})}return B}const oe=(new r.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 le(e,t,a){const n=a.get(e.shader);if(null==n)return console.error("No shader exists with name "+e.shader),new r.Material;const s=new n.type,i=await V(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,i),s.build()}function ce(e){const t=k(new h("instanceColor")).rgb;let a,n=k(new o("particleData")).x;if(e instanceof r.MeshStandardMaterial||e instanceof r.MeshLambertMaterial||e instanceof r.MeshBasicMaterial){let s=t.multiply(I(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 r.MeshStandardMaterial?a=new c({color:B({color:s,emissive:I(e.emissive),emissiveIntensity:v(e.emissiveIntensity),roughness:e.roughness,metalness:e.metalness}).rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}):e instanceof r.MeshLambertMaterial?a=new c({color:E({color:s}).rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}):e instanceof r.MeshBasicMaterial&&(a=new c({color:s.rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}))}else e instanceof c&&(a=e.clone(),a.defines.IS_PARTICLE="");return null!=a&&(!0===e.userData?.hasBloom&&null!=a&&(a.userData.hasBloom=!0),a.side=e.side,a.transparent=e.transparent),a??e}class ue extends t{initialize(e){e.body instanceof r.Object3D&&e.body.traverse(e=>{if(e instanceof r.Mesh){const t=e.material;t instanceof c&&(null!=t.uniforms[H]||null!=t.uniforms[U]||t.uniforms[G])}})}mutate(e,t,a){this.energize(e,t),e.target instanceof i&&e.target.traverse(t=>{if(t instanceof r.Mesh){const a=t.material;a instanceof c&&(null!=a.uniforms[H]&&(a.uniforms[H].value=this.energy),null!=a.uniforms[U]&&(a.uniforms[U].value=e.age),null!=a.uniforms[G]&&(a.uniforms[G].value=e.velocity))}})}}class pe 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 pe;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 s,Emitter as a,Rate as n}from"@hology/nebula";import*as i from"three";import{Object3D as r}from"three";import{AttributeVec3Node as o,AttributeVec4Node as l,NodeShaderMaterial as c,RgbNode as u,UniformFloatNode as p,UniformVec3Node as m,Vec3ExpressionNode as h,Vec4Node as d,attributeFloat as f,attributeVec3 as y,attributeVec4 as w,attributes as g,clamp as b,float as v,glslFunction as A,lambertMaterial as E,log as M,pow as x,rgb as I,rgba as T,smoothstep as P,standardMaterial as S,textureSampler2d as B,uniformFloat as C,uniforms as R,varying as k,varyingAttributes as j,varyingVec3 as D,varyingVec4 as z}from"three-shader-graph";import{prepareClassParameters as V,prepareShapeParameters as F}from"../../scene/materializer.js";import{SerializedParamType as L}from"../../scene/model.js";import{ShapeLibrary as O}from"../../scene/objects/shapes.js";import{fragmentLinearEyeDepth as Q,linearEyeDepth as W}from"../../shader-nodes/depth.js";import{particleEnergyUniformName as H,particleTimeUniformName as U,particleUniforms as q,particleVelcoityUniformName as G}from"../../shader-nodes/particle.js";import{sampleFlipbook as J}from"../../shader-nodes/texture-sequence.js";import{DefaultInitializer as N}from"./initializsers.js";import{DelayRate as K,OnceRate as Y}from"./rates.js";import{StretchedSprite as X}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{getSpritePosition as se,SpriteNodeShaderMaterial as ae}from"../../shader/sprite-shader.js";import{DecalUnlitShader as ne}from"../../shader/builtin/decal-unlit-shader.js";import{DecalStandardShader as ie}from"../../shader/builtin/decal-standard-shader.js";export async function materializeVfx(t,s,a,n,o,l){let c=s;for(;null!=c.parent;)c=c.parent;const u=new r;u.name="particle system local",s.add(u);const p=new r;p.name="particle system world";const m=new ee(p,u,i,n),h=new e;return(await Promise.all(t.vfx.emitters.slice().sort((e,t)=>(t.output.renderOrder??0)-(e.output.renderOrder??0)).map(async e=>{const t=await re(e,a,h,o,l);return t.setParentRecursive(h),t.emit()}))).forEach(e=>h.addEmitter(e)),h.addRenderer(m).emit({onEnd:()=>{}}),{container:p,system:h,dispose:()=>{p.removeFromParent(),u.removeFromParent(),m.dispose()}}}async function re(e,t,a,u,v){const x=function(e){let t;switch(e.rate.type){case"continuous":t=new K(e.rate.delay??0,e.rate.count,e.rate.time,e.rate.duration);break;case"once":t=new Y(e.rate.delay??0,e.rate.count);break;default:console.warn(`Failed to configure rate for emitter: ${JSON.stringify(e)}`),t=new n(0,1/0)}return t}(e);let I;switch(e.output.type){case"decal":I=new s(await async function(e,t){const s=!1!==e.unlit?new ne:new ie;s.color=new i.Color(e.color),s instanceof ne?s.intensity=e.intensity??1:s.emissiveIntensity=e.intensity??1;if(e.colorMap){const a=await t.getTexture(e.colorMap);s.colorMap=a}if(e.alphaMap){const a=await t.getTexture(e.alphaMap);s.alphaMap=a}const a=s.build();a.blending=Z[e.blendingMode]??i.NormalBlending,a.transparent=!0,a.side=i.BackSide,a.depthTest=!1,null!=a&&!0===e.bloom&&(a.userData.hasBloom=!0);a.defines.IS_PARTICLE="";const n=new i.BoxGeometry(1,1,1),r=new i.Mesh(n,a);null!=e.renderOrder&&(r.renderOrder=e.renderOrder);return r}(e.output,t));break;case"sprite":I=new s(await async function(e,t,s){let a=null;a=null!=e.shader?await le(e,t,s):await async function(e,t){const s=null!=e.texture?await t.getTexture(e.texture):oe,a=B(s);let n=a.sample(j.uv);e.flipbook?.enabled&&(n=J(a,g.uv,e.flipbook.columns,e.flipbook.rows,q.time,e.flipbook.fps,e.flipbook.mode));const r=new p("rotation",0),o=new m("color").rgb,l=C("opacity",1),c=W.subtract(Q).divide(W);let u=l;switch(e.opacityChannel??"red"){case"none":break;case"red":u=u.multiply(n.r);break;case"alpha":u=u.multiply(n.a)}if("number"==typeof e.softness&&e.softness>0){const t=b(c,0,1e3);u=u.multiply(P(0,.2*e.softness,t))}const h=se(r),d=T(o.multiply(n.rgb).multiplyScalar(e.intensity??1),u);var f=new ae({color:d,emissive:d.rgb.multiplyScalar(u),transparent:!0,position:h,alphaTest:1e-4,uniforms:{color:{value:new i.Color(e.color)}}});f.alphaHash=!0,null!=f&&!0===e.bloom&&(f.userData.hasBloom=!0);return f.blending=Z[e.blendingMode]??i.NormalBlending,f}(e,t);a instanceof i.ShaderMaterial&&!0===e.lockY&&(a.defines.LOCK_Y_AXIS="");const n=new i.Mesh(new i.PlaneGeometry(1,1),a);return n.name="sprite",n}(e.output,t,v));break;case"stretchedSprite":I=new s(await async function(e,t){const s=null!=e.texture?await t.getTexture(e.texture):oe,a=B(s).sample(j.uv),n=z(new l("color")),r=n.rgb.multiply(a.rgb);let o=n.w;switch(e.opacityChannel??"red"){case"none":break;case"red":o=o.multiply(a.r);break;case"alpha":o=o.multiply(a.a)}if("number"==typeof e.softness&&e.softness>0){const t=W.subtract(Q).divide(M(W)),s=b(t,0,1e3);o=o.multiply(P(0,.2*e.softness,s))}const c=A(d,{position:g.position,offset:y("offset"),modelViewMatrix:R.modelViewMatrix,velocity:w("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 ae({color:T(r.multiplyScalar(e.intensity??1),o),alphaTest:.1,transparent:!0,position:c,uniforms:{color:{value:new i.Color(e.color)}}});null!=u&&!0===e.bloom&&(u.userData.hasBloom=!0);u.blending=Z[e.blendingMode]??i.NormalBlending;const p=new X(new i.PlaneGeometry(1,1),u);return p.scaleFactor=e.scale,p}(e.output,t));break;case"shape":I=new s(await async function(e,t,s){if(null==e.shape)return console.log("Shape is null"),new r;const a=O[e.shape];if(null==a)return console.error(`No shape with type ${e.shape}`),new r;const n=F(e.params??{}),l=a.geometry(n);let u=null;u=null!=e.shader?await le(e,t,s):null!=e.material?ce(await t.getMaterial(e.material)):function(){const e=k(new h("instanceColor")).rgb,t=k(new o("particleData")).x;return new c({color:E({color:e}).rgb.rgba(t),transparent:!0})}();null!=u&&!0===e.bloom&&(u.userData.hasBloom=!0);return new i.Mesh(l,u)}(e.output,t,v));break;case"mesh":I=new s(await async function(e,t,s){if(null==e.assetId)return console.warn("Can't use mesh as particle without asset id"),new r;const a=await t.getMesh(e.assetId),n=await t.getAsset(e.assetId);if(null!=e.shader||null!=e.material){let n;n=null!=e.shader?await le(e,t,s):ce(await t.getMaterial(e.material)),null!=n&&!0===e.bloom&&(n.userData.hasBloom=!0),null!=n&&!0===e.bloom&&(n.userData.hasBloom=!0),a.traverse(e=>{e instanceof i.Mesh&&(e.material=n)})}else{const e=[];if(null!=n.materialAssignments)for(const s of n.materialAssignments)a.traverse(a=>{a instanceof i.Mesh&&a.material instanceof i.Material&&a.material.color instanceof i.Color&&(a.material.name!=s.name&&null!=s.name||"#"+a.material.color.getHexString()!==s.color||e.push(t.getMaterial(s.materialId).then(e=>a.material=e)))});await Promise.all(e)}const o=[];if(a.traverse(e=>{e instanceof i.Mesh&&o.push(e)}),1===o.length){const e=o[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 a}(e.output,t,v));break;case"trail":I=new s({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 S=new pe;S.parent=a,S.setRate(x),S._space=e.output.space;const D=await Promise.all(e.initializers.filter(e=>!1!==e.enabled).filter(e=>null!=$[e.type]).map(async e=>{const t=$[e.type],s=await F(e.params??{});return t.build(s)}));D.push(I,new N),S.addInitializers(D);const V=await Promise.all(e.behaviours.filter(e=>!1!==e.enabled).filter(e=>null!=_[e.type]).map(async e=>{const t=_[e.type];for(const[s,a]of Object.entries(e.params))t.parameters&&null!=t.parameters[s]&&"curve"===t.parameters[s].type&&a.type!==L.Curve&&(a.type=L.Curve);const s=await F(e.params??{});return t.build(s)}).sort((e,t)=>e instanceof te?1:0));V.push(new ue);for(const e of V)e instanceof te&&(e.physics=u);S.addBehaviours(V);for(const s of e.children){const e=await re(s,t,a,u,v),n=new EmitterPool(()=>{const t=e.clone();return t.onExpired=()=>{const e=S.childEmitters.findIndex(e=>e.id===t.id);-1!=e&&S.childEmitters.splice(e,1),n.release(t)},t}),i=S.eventDispatcher,r=new Map;S.bindEmitterEvent=!0,i.addEventListener("PARTICLE_DEAD",e=>{const t=r.get(e.id);if(null!=t){const e=S.childEmitters.findIndex(e=>e.id===t.id);null!=e&&(t.stopEmit(),S.childEmitters.splice(e,1))}});let o="PARTICLE_CREATED";if("spawnEvent"in s)switch(s.spawnEvent){case"collision":o="PARTICLE_COLLISION";break;case"start":o="PARTICLE_CREATED"}i.addEventListener(o,e=>{const t=n.get();t.age=0,t.totalEmitTimes=-1,t.particles.length=0,t.currentEmitTime=0,t.cID=0,t.eventDispatcher.removeAllEventListeners(),S.childEmitters.push(t),r.set(e.id,t),t.parentParticle=e,t.system=S.system,t.emit()})}return S}const oe=(new i.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 le(e,t,s){const a=s.get(e.shader);if(null==a)return console.error("No shader exists with name "+e.shader),new i.Material;const n=new a.type,r=await V(e.shaderParams,a.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(n,r),n.build()}function ce(e){const t=k(new h("instanceColor")).rgb;let s,a=k(new o("particleData")).x;if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshBasicMaterial){let n=t.multiply(I(e.color));null!=e.map&&(n=n.multiply(B(e.map).sample(j.uv).rgb)),null!=e.alphaMap&&(a=a.multiply(B(e.alphaMap).sample(j.uv).r)),e instanceof i.MeshStandardMaterial?s=new c({color:S({color:n,emissive:I(e.emissive),emissiveIntensity:v(e.emissiveIntensity),roughness:e.roughness,metalness:e.metalness}).rgb.rgba(a),emissive:I(e.emissive).multiplyScalar(e.emissiveIntensity),transparent:e.transparent,alphaTest:e.alphaTest}):e instanceof i.MeshLambertMaterial?s=new c({color:E({color:n}).rgb.rgba(a),emissive:I(e.emissive).multiplyScalar(e.emissiveIntensity),transparent:e.transparent,alphaTest:e.alphaTest}):e instanceof i.MeshBasicMaterial&&(s=new c({color:n.rgb.rgba(a),emissive:n.rgb,transparent:e.transparent,alphaTest:e.alphaTest}))}else e instanceof c&&(s=e.clone(),s.defines.IS_PARTICLE="");return null!=s&&(!0===e.userData?.hasBloom&&null!=s&&(s.userData.hasBloom=!0),s.side=e.side,s.transparent=e.transparent),s??e}class ue extends t{initialize(e){e.body instanceof i.Object3D&&e.body.traverse(e=>{if(e instanceof i.Mesh){const t=e.material;t instanceof c&&(null!=t.uniforms[H]||null!=t.uniforms[U]||t.uniforms[G])}})}mutate(e,t,s){this.energize(e,t),e.target instanceof r&&e.target.traverse(t=>{if(t instanceof i.Mesh){const s=t.material;s instanceof c&&(null!=s.uniforms[H]&&(s.uniforms[H].value=this.energy),null!=s.uniforms[U]&&(s.uniforms[U].value=e.age),null!=s.uniforms[G]&&(s.uniforms[G].value=e.velocity))}})}}class pe extends a{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 pe;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 (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -194,6 +194,7 @@ export declare class PhysicsSystem extends AbstractPhysicsSystem {
|
|
|
194
194
|
* @private
|
|
195
195
|
*/
|
|
196
196
|
private createForInstancedMesh;
|
|
197
|
+
private instancedShapeReset;
|
|
197
198
|
private readonly controlledActors;
|
|
198
199
|
/**
|
|
199
200
|
* Creates a character controller for physics-based character movement.
|
|
@@ -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,EACxE,UAAU,EAG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AC,UAAU;IA8DlB;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAKpB;;;;OAIG;IACH,OAAO,CAAC,aAAa;IASrB;;;;;;OAMG;IACH,OAAO,CAAC,UAAU,CAAkB;IAC7B,iBAAiB,CACtB,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,aAAa,EACtB,OAAO,CAAC,EAAE,cAAc;IAS1B,OAAO,CAAC,eAAe,CAAsB;IAC7C,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,iBAAiB,CAAgB;IACzC;;;;;;;OAOG;IACI,OAAO,CACZ,IAAI,EAAE,OAAO,EACb,EAAE,EAAE,OAAO,EACX,MAAM,CAAC,EAAE,aAAa,EACtB,OAAO,CAAC,EAAE,cAAc;IAiE1B;;;;;OAKG;IACI,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAMjD;;;OAGG;IACI,UAAU,IAAI,OAAO;IAQ5B;;;OAGG;IACI,YAAY,CAAC,MAAM,EAAE,QAAQ;IAQpC;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAiCtB;;;;;OAKG;IACH,OAAO,CAAC,sBAAsB;
|
|
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,EACxE,UAAU,EAGV,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,uBAA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AAC,GAAG,EAAE,UAAU;IAI3B,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO;IAM3C,iBAAiB,CAAC,GAAG,EAAE,OAAO;IAI9B,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO;IAM5C,kBAAkB,CAAC,GAAG,EAAE,OAAO;IAI/B,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,GAAE,OAAc;IAIrD,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,GAAE,OAAc;IAI1D,wBAAwB,CAAC,GAAG,EAAE,OAAO;IAIrC,wBAAwB,CAAC,GAAG,EAAE,UAAU;IAIxC,OAAO,CAAC,IAAI,EAAE,eAAe;IAI7B,eAAe,CAAC,KAAK,EAAE,MAAM;IAI7B,eAAe;IAIf,SAAS,IAAI,OAAO;IAIpB,WAAW,IAAI,OAAO;IAItB,QAAQ,IAAI,OAAO;IAInB;;;;;;OAMG;IACH,KAAK;IAIL,MAAM;CAGP"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as t,__metadata as e}from"tslib";import*as i from"@dimforge/rapier3d-compat";import{QueryFilterFlags as s}from"@dimforge/rapier3d-compat";import{BehaviorSubject as o,distinctUntilChanged as n,filter as r,map as a,Subject as l,takeUntil as c}from"rxjs";import*as d from"three";import{ArrowHelper as h,BufferAttribute as y,BufferGeometry as u,Group as p,LineSegments as g,Matrix4 as m,Object3D as f,Quaternion as w,Raycaster as B,Scene as x,Vector3 as b}from"three";import{Service as v}from"typedi";import{AssetMeshInstance as C}from"../../../scene/asset-resource-loader.js";import{BoxCollisionShape as A,CapsuleCollisionShape as S,CollisionShapeSource as z,ConeCollisionShape as D,ConvexPolyhedronCollisionShape as R,CylinderCollisionShape as T,PhysicalShapeMesh as M,PlaneCollisionShape as E,SphereCollisionShape as P,TrimeshCollisionShape as V}from"../../../index.js";import{LandscapeGroup as _}from"../../../scene/landscape/landscape.js";import{ViewController as k}from"../render.js";import{World as F}from"../world.js";import*as I from"three/examples/jsm/utils/BufferGeometryUtils.js";import{calculateEffectiveScale as W}from"../../../utils/three/traverse.js";import{AbstractPhysicsSystem as N}from"./abstract-physics-system.js";import{ActorComponent as j,Component as L}from"../../../gameplay/actors/component.js";import{inject as O}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 class ShapeCastResult{constructor(){this.hasHit=!1,this.hitPoint=new b,this.normal=new b}reset(){this.actor=void 0,this.hasHit=!1,this.distance=0,this.hitPoint.set(0,0,0),this.normal.set(0,0,0)}}ShapeCastResult.shared=new ShapeCastResult;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,K=new b,q=new w,U=new w,H=(new w,[]);let Q=class extends N{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.colliders=new Map,this.collisionEvents=new l,this.beforeStep=new l,this.afterStep=new l,this.shouldRenderDebug=!1,this.shapeCacheBox=new Map,this.shapeCacheBall=new Map,this._raycaster=new B,this._reusableResult=new RayTestResult,this._raytestDiff=new b,this._raytestDirection=new b,this.controlledActors=new Set,this.ready=this.setup()}getBallShape(t){let e=this.shapeCacheBall.get(t);return null==e&&(e=new i.Ball(t),this.shapeCacheBall.set(t,e)),e}getBoxShape(t,e,s){const o=t+1e6*e+1e12*s;let n=this.shapeCacheBox.get(o);return null==n&&(n=new i.Cuboid(t,e,s),this.shapeCacheBox.set(o,n)),n}hasBoxIntersection(t){const e=t.getCenter(G),i=t.getSize(K),s=this.getBoxShape(i.x/2,i.y/2,i.z/2);return null!=this.world.intersectionWithShape(e,q,s)}hasSphereIntersection(t){const e=this.getBallShape(t.radius);return null!=this.world.intersectionWithShape(t.center,q,e)}createDebugMesh(){return new g(new u,new d.LineBasicMaterial({color:255}))}async start(){return await this.ready,this.handleTick(),this.handleCollisionEvents(),this.ready}handleCollisionEvents(){this.collisionSub=this.collisionEvents.subscribe(t=>{const e=this.colliders.get(t.handle1);if(null==e)return;const i=this.world.getCollider(t.handle2);if(null==i||null==i.parent())return;const s=this.bodyActors.get(i.parent());null!=s&&(t.started?e.onBeginOverlapActor.next({actor:s}):e.onEndOverlapActor.next({actor:s}))})}renderDebug(){if(null==this.scene)return;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 y(t.vertices,3))}async setup(){if(null!=this.rapier)throw new Error("Rapier is already estup");this.rapier=await rt(),this.eventQueue=new i.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;null!=e&&e.parent instanceof x&&(ct(e.position,t.translation()),(t.isDynamic()||t.isKinematic()&&!this.controlledActors.has(this.bodyActors.get(t)?.id))&&dt(e.quaternion,t.rotation()),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,i)=>{this.collisionEvents.next({handle1:t,handle2:e,started:i}),this.collisionEvents.next({handle1:e,handle2:t,started:i})})}rayTestFromCamera(t,e,i){this._raycaster.setFromCamera(st,this.viewController.getCamera());const s=this._raycaster.ray.origin,o=this._raycaster.ray.direction.multiplyScalar(t).add(s);return this.rayTest(s,o,e,i)}rayTest(t,e,i,s){null==i&&(i=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"),i;at(mt.origin,t),at(mt.dir,n);const r=o.length(),a=this.world.castRayAndGetNormal(mt,r,!1,void 0,s?.collisionFilter,void 0,null!=s?.excludeActor?this.actorBodies.get(s.excludeActor.id):void 0,s?.excludeTriggers?t=>!t.isSensor():void 0);if(i.hasHit=null!=a,i.hasHit){const e=mt.pointAt(a.timeOfImpact);i._internal=a,ct(i.hitNormal,a.normal),ct(i.hitPoint,e),i.distance=yt.subVectors(i.hitPoint,t).length();const s=this.world.bodies.getAll().find(t=>function(t,e){for(let i=0,s=t.numColliders();i<s;i++){const s=t.collider(i);if(e(s))return s}}(t,t=>t===a.collider));i.actor=null!=s?this.bodyActors.get(s):null}if(this.showDebug){let e;H.length>0?(e=H.pop(),e.setDirection(n),e.position.copy(t),e.setLength(r,.2,.1),e.setColor(s?.debugColor??255)):e=new h(n,t,r,s?.debugColor??255),this.scene?.add(e),setTimeout(()=>{this.scene?.remove(e),H.push(e)},s?.debugLifetime??200)}return i}setGravity(t,e,i){this.world.gravity.x=t,this.world.gravity.y=e,this.world.gravity.z=i}getGravity(){return J.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())ht(t,t=>t.setActiveEvents(i.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 M&&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||t.children[0].isBatchedMesh))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 _?this.addLandscapeGroup(t):(t instanceof p||t instanceof x)&&t.children.forEach(t=>this.addRecursively(t))}createForInstancedMesh(t,e){const i=new m,s=e.filter(t=>null!=t).map(t=>t.source===z.rendered?t.withOffset(wt):t);if(t instanceof d.BatchedMesh){const e=t._instanceInfo??t._drawInfo;for(let o=0;o<e.length;o++){if(null!=t.userData.hasCollision&&!t.userData.hasCollision[o])continue;const e=new f;e.matrix.identity(),t.getMatrixAt(o,i),e.applyMatrix4(i);this.createStaticBody(e,s)}}else 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(),i.fromArray(t.instanceMatrix.array,16*e),o.applyMatrix4(i);this.createStaticBody(o,s)}}getCharacterController(t){return this.world?.createCharacterController(t)}getActorComputedMovement(t,e,i,o=null){const n=this.actorBodies.get(t.id);this.controlledActors.add(t.id);const r=n.collider(0);e.computeColliderMovement(r,i,s.EXCLUDE_SENSORS,o,pt);const a=e.computedMovement();return ct(ut,a),ut}createCollider(t,e){const i=this.addShape(e?.body,t),s=new PhysicsCollider(i,this.world);return this.colliders.set(i.handle,s),s.disposed.subscribe(()=>{this.colliders.delete(i.handle)}),s}createBody(t=PhysicsBodyType.dynamic,e={}){const s=(()=>{switch(t){case PhysicsBodyType.dynamic:return i.RigidBodyDesc.dynamic();case PhysicsBodyType.static:return i.RigidBodyDesc.fixed();case PhysicsBodyType.kinematic:return i.RigidBodyDesc.kinematicPositionBased();case PhysicsBodyType.kinematicVelocityBased:return i.RigidBodyDesc.kinematicVelocityBased();default:return i.RigidBodyDesc.dynamic()}})();e.position&&s.setTranslation(e.position.x,e.position.y,e.position.z),e.rotation&&s.setRotation({x:e.rotation.x,y:e.rotation.y,z:e.rotation.z,w:e.rotation.w}),"boolean"==typeof e.canSleep&&s.setCanSleep(e.canSleep),"boolean"==typeof e.ccdEnabled&&s.setCcdEnabled(e.ccdEnabled),"number"==typeof e.gravityScale&&s.setGravityScale(e.gravityScale),"number"==typeof e.mass&&s.setAdditionalMass(e.mass),void 0!==e.userData&&(s.userData=e.userData);const o=this.world.createRigidBody(s);return new PhysicsBody(o,this.world)}getCharacterComputedMovement(t,e,i,o=null){const n=t.collider;e.computeColliderMovement(n,i,s.EXCLUDE_SENSORS,o,pt);const r=e.computedMovement();return ct(ut,r),ut}setNextKinematicTranslation(t,e){const i=this.actorBodies.get(t.id),s=i.translation();s.x+=e.x,s.y+=e.y,s.z+=e.z,i?.setNextKinematicTranslation(s)}setNextKinematicPosition(t,e){this.actorBodies.get(t.id).setNextKinematicTranslation(e)}setNextKinematicRotation(t,e){this.actorBodies.get(t.id).setNextKinematicRotation(e)}setNextKinematicTransform(t){!function(t,e){const i=e.getWorldPosition(X),s=e.getWorldQuaternion(Y);t.setNextKinematicTranslation(ot(i)),t.setNextKinematicRotation(nt(s))}(this.actorBodies.get(t.id),t.object)}setAngularVelocity(t,e){const i=this.actorBodies.get(t.id);tt.x=e.x,tt.y=e.y,tt.z=e.z,i?.setAngvel(tt,!0)}setLinearVelocity(t,e){const i=this.actorBodies.get(t.id);tt.x=e.x,tt.y=e.y,tt.z=e.z,i?.setLinvel(tt,!0)}getLinearVelocity(t,e=new b){const i=this.actorBodies.get(t.id).linvel();return e.x=i.x,e.y=i.y,e.z=i.z,e}getAngularVelocity(t,e=new b){const i=this.actorBodies.get(t.id).angvel();return e.x=i.x,e.y=i.y,e.z=i.z,e}setLinearDamping(t,e){const i=this.actorBodies.get(t.id);i?.setLinearDamping(e)}getLienarDamping(t){const e=this.actorBodies.get(t.id);return e?.linearDamping()??0}setAngularDamping(t,e){const i=this.actorBodies.get(t.id);i?.setAngularDamping(e)}getAngularDamping(t){const e=this.actorBodies.get(t.id);e?.angularDamping()}setPosition(t,e){const i=this.actorBodies.get(t.id);i?.setTranslation(ot(e),!1)}getPosition(t,e=new b){const i=this.actorBodies.get(t.id);i&&ct(e,i.translation())}setRotation(t,e){const i=this.actorBodies.get(t.id);i?.setTranslation(nt(e),!1)}getRotation(t,e=new w){const i=this.actorBodies.get(t.id);i&&dt(e,i.rotation())}lockTranslations(t,e){const i=this.actorBodies.get(t.id);i?.lockTranslations(e,!1)}lockRotations(t,e){const i=this.actorBodies.get(t.id);i?.lockRotations(e,!1)}setEnabledTranslations(t,e,i,s){const o=this.actorBodies.get(t.id);o?.setEnabledTranslations(e,i,s,!1)}setEnabledRotations(t,e,i,s){const o=this.actorBodies.get(t.id);o?.setEnabledRotations(e,i,s,!1)}addLandscapeGroup(t){const e=t.userData.src,s=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(),s=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]*=s.x,a[t+1]*=s.y,a[t+2]*=s.z;const l=t.index;for(let t=0;t<l.count;t+=3){const e=r.getX(l.getX(t)),i=r.getX(l.getY(t)),s=r.getX(l.getZ(t));(e>.5||i>.5||s>.5)&&(l.setX(t,0),l.setY(t,0),l.setZ(t,0))}const c=i.ColliderDesc.trimesh(a,new Uint32Array(t.getIndex().array));if(!1!==e.collisionDetection){const t=this.world.createRigidBody(i.RigidBodyDesc.fixed()),e=new i.Vector3(0,0,0);at(e,o),t.setTranslation(e,!1),this.world.createCollider(c,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 l=s.find(t=>t.x===n.x&&t.y==n.y);if(null!=l)for(const e of l.points){if(null==a[e.i%t])continue;const i=t-1-Math.floor(e.i/t);i in a[e.i%t]?a[e.i%t][i]=e.y/r:console.warn("wrong index",{points:a,point:e,i:e.i%t,k:i,heightMap:l})}const c=e.landscape.options.density,d=a.flatMap(t=>t.reverse()),h=i.ColliderDesc.heightfield(c,c,new Float32Array(d),new i.Vector3(r,r,r));if(!1!==e.collisionDetection){const t=this.world.createRigidBody(i.RigidBodyDesc.fixed()),e=new i.Vector3(0,0,0);at(e,o),t.setTranslation(e,!1),this.world.createCollider(h,t),this.staticBodies.set(n,t)}}}setEnabled(t,e){const i=this.actorBodies.get(t.id);i?.setEnabled(e)}addActor(t,e,s={}){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(s.type??PhysicsBodyType.static){case PhysicsBodyType.dynamic:n=i.RigidBodyDesc.dynamic(),n.mass=s.mass??1;break;case PhysicsBodyType.kinematic:n=i.RigidBodyDesc.kinematicPositionBased();break;case PhysicsBodyType.kinematicVelocityBased:n=i.RigidBodyDesc.kinematicVelocityBased();break;default:n=s.isTrigger?i.RigidBodyDesc.kinematicVelocityBased():i.RigidBodyDesc.fixed()}const r=this.world.createRigidBody(n);r.enableCcd(1==s.continousCollisionDetection);for(const t of e)this.addShape(r,t,o);return ht(r,t=>{null!=s.isTrigger&&(t.setSensor(s.isTrigger),t.setActiveCollisionTypes(i.ActiveCollisionTypes.ALL),t.setActiveEvents(i.ActiveEvents.COLLISION_EVENTS)),null!=s.friction&&t.setFriction(s.friction),null!=s.density&&t.setDensity(s.density),null!=s.mass&&t.setMass(s.mass),null!=s.restitution&&t.setRestitution(s.restitution)}),Z(r,o),!0===s.ignoreForNavMesh&&(r.userData={ignoreForNavMesh:!0}),this.actorBodies.set(t.id,r),this.bodyActors.set(r,t),new PhysicsBody(r,this.world)}applyTorque(t,e){const i=this.actorBodies.get(t.id);tt.x=e.x,tt.y=e.y,tt.z=e.z,i?.addTorque(tt,!0)}applyTorqueImpulse(t,e){const i=this.actorBodies.get(t.id);tt.x=e.x,tt.y=e.y,tt.z=e.z,i?.applyTorqueImpulse(tt,!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 i=this.actorBodies.get(t.id);tt.x=e.x,tt.y=e.y,tt.z=e.z,i?.addForce(tt,!0)}applyImpulse(t,e){const i=this.actorBodies.get(t.id);tt.x=e.x,tt.y=e.y,tt.z=e.z,i?.applyImpulse(tt,!0)}applyLocalForce(t,e,i){const s=this.actorBodies.get(t.id);at(tt,e),null==i?s?.addForce(tt,!0):(at(et,i),s?.addForceAtPoint(tt,et,!0))}applyLocalImpulse(t,e,i){const s=this.actorBodies.get(t.id);at(tt,e),null==i?s.applyImpulse(tt,!0):(at(et,i),s.applyImpulseAtPoint(tt,et,!0))}applyRadiusImpulse(t,e,s){this.world.bodies.forEach(o=>{if(o.collider(0)?.isSensor())return;if(o.bodyType()!==i.RigidBodyType.Dynamic)return;const n=it;ct(n,o.translation());const r=n.clone().sub(t);if(r.length()>e)return;const a=r.clone().normalize().multiplyScalar(s);tt.x=a.x,tt.y=a.y,tt.z=a.z,o.applyImpulse(tt,!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,i]of this.staticBodies.entries())!e.has(t.uuid)&&this.world.getRigidBody(i.handle)&&(this.staticBodies.delete(t),this.world.removeRigidBody(i))}removeSceneObject(t){if(t instanceof _){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,i){return this.activateActorEvents(t),this.collisionEvents.pipe(c(t.disposed),r(({started:t})=>t===i),a(({handle1:t,handle2:e,started:i})=>({a1:this.bodyActors.get(this.world.getCollider(t)?.parent()),a2:this.bodyActors.get(this.world.getCollider(e)?.parent()),started:i})),r(({a1:i,a2:s})=>null!=i&&null!=s&&i.id===t.id&&e(i,s)),a(({a2:t})=>t))}onBeginContact(t){return this.activateActorEvents(t),this.collisionEvents.pipe(c(t.disposed),r(t=>t.started),r(({handle1:e})=>{const i=this.bodyActors.get(this.world.getCollider(e)?.parent());return null!=i&&i.id===t.id}),a(t=>t.handle2))}onEndContact(t){return this.activateActorEvents(t),this.collisionEvents.pipe(c(t.disposed),r(t=>!t.started),r(({handle1:e})=>{const i=this.bodyActors.get(this.world.getCollider(e)?.parent());return null!=i&&i.id===t.id}),a(t=>t.handle2))}onHasContactChanged(t){const e=new Set,i=new o(!1);return this.onBeginContact(t).subscribe(t=>{e.add(t),i.next(e.size>0)}),this.onEndContact(t).subscribe(t=>{e.delete(t),i.next(e.size>0)}),i.pipe(n())}onBeginOverlapWithActorType(t,e){return this._onCollisionWithActorEvent(t,(t,i)=>i instanceof e,!0)}onEndOverlapWithActorType(t,e){return this._onCollisionWithActorEvent(t,(t,i)=>i instanceof e,!1)}onBeginOverlapWithActor(t,e){return this._onCollisionWithActorEvent(t,(t,i)=>e.id===i.id,!0)}onEndOverlapWithActor(t,e){return this._onCollisionWithActorEvent(t,(t,i)=>e.id===i.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&&Z(e,t.object)}setupWorld(){const t=new i.World({x:0,y:-9.81,z:0});this.world=t}sphereCast(t,e,i,s,o=ShapeCastResult.shared,n=void 0){o.reset();const r=this.getBallShape(e);this.shapeCacheBall.get;const a={x:t.x,y:t.y,z:t.z},l={x:i.x,y:i.y,z:i.z},c=this.world.castShape(a,{x:0,y:0,z:0,w:1},l,r,.01,s,!0,null,n,null,void 0,void 0);if(null!=c){ct(o.hitPoint,c.witness1),o.normal.set(c.normal1.x,c.normal1.y,c.normal1.z),o.distance=c.time_of_impact,o.hasHit=!0;const t=c.collider.parent();if(t){const e=this.bodyActors.get(t);e&&(o.actor=e)}}return o}castActorShape(t,e,i,s=ShapeCastResult.shared,o=void 0){s.reset();const n=this.actorBodies.get(t.id);if(n&&n.numColliders()>0){for(let t=0;t<n.numColliders();t++){const r=n.collider(t);let a=r.shape,l=r.translation(),c=r.rotation(),d=e,h=i;const y=this.world.castShape(l,c,d,a,.01,h,!0,null,o,null,n,void 0);if(null!=y){y.collider;const t=r;return ct(s.hitPoint,y.witness1),Bt(t.rotation(),y.normal1,s.normal,U),s.distance=y.time_of_impact,s.actor=this.bodyActors.get(y.collider.parent()),s.hasHit=!0,s}}return s}return console.warn("Actor is not added to the physics system"),s}stop(){this.world?.bodies.forEach(t=>this.world.removeRigidBody(t)),this.world?.free(),this.fixedupdateSub?.unsubscribe(),this.collisionSub?.unsubscribe(),H.length=0}createStaticBody(t,e,s){const o=s?.type===PhysicsBodyType.dynamic?i.RigidBodyDesc.dynamic():i.RigidBodyDesc.fixed(),n=this.world.createRigidBody(o);for(const i of e){if(null==i){console.warn("Collision shape is missing for object",t);continue}const o=this.addShape(n,i,t);null!=s?.friction&&o.setFriction(s.friction),null!=s?.density&&o.setDensity(s.density),null!=s?.mass&&o.setMass(s.mass/e.length),null!=s?.restitution&&o.setRestitution(s.restitution)}return Z(n,t),n.userData=t.uuid,n}addShape(t=void 0,e,i){const s=i?.getWorldScale(gt)??$,o=this.createShape(e,s);this.applyShapeSettings(o,e);const n=e.offset.clone().multiply(s);at(o.translation,n);const r=(new w).setFromEuler(e.rotation);e instanceof R&&e.mesh instanceof d.Mesh&&r.multiply(e.mesh.getWorldQuaternion(Y)),lt(o.rotation,r);return this.world.createCollider(o,t)}applyShapeSettings(t,e){null!=e.collisionGroup&&t.setCollisionGroups(e.collisionGroup),t.friction=e.friction??.1,null!=e.restitution&&(t.restitution=e.restitution),null!=e.density&&(t.density=e.density,t.massPropsMode=i.MassPropsMode.Density),null!=e.mass&&(t.mass=e.mass,t.massPropsMode=i.MassPropsMode.Mass)}createShape(t,e){if(t instanceof A)return i.ColliderDesc.cuboid(t.dimensions.x*e.x/2,t.dimensions.y*e.y/2,t.dimensions.z*e.z/2);if(t instanceof S){return i.ColliderDesc.capsule(t.length/2*e.y,t.radius*Math.max(e.z,e.x))}if(t instanceof V){const s=null!=t.geometry.getIndex()?t.geometry:I.mergeVertices(t.geometry),o=extractFloat32Array(s.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 i.ColliderDesc.trimesh(o,new Uint32Array(s.getIndex().array))}if(t instanceof R){let s;t.mesh instanceof d.Mesh?s=t.mesh.geometry:t.mesh instanceof d.BufferGeometry?s=t.mesh:console.log("Unknownd shape",{shapeInfo:t});const o=extractFloat32Array(s.getAttribute("position"));if(t.mesh instanceof d.Mesh){const e=W(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 i.ColliderDesc.convexHull(n)}if(t instanceof P){const s=2*e.x-e.y-e.z;return Math.abs(s)>.01?this.createShape(new R(new d.SphereGeometry(t.radius).scale(e.x,e.y,e.z)),new b(1,1,1)):i.ColliderDesc.ball(t.radius*Math.max(e.x,e.y,e.z))}return t instanceof T?i.ColliderDesc.cylinder(t.height/2*e.y,t.radiusTop*Math.max(e.z,e.x)):t instanceof D?i.ColliderDesc.cone(t.height*e.y,t.radiusBottom/2*Math.max(e.z,e.x)):t instanceof E?i.ColliderDesc.cuboid(t.width/2*e.x,t.height/2*e.y,.001):(console.error("Unsupported shape",t),i.ColliderDesc.cuboid(1,1,1))}createCharacterCollision(){return new i.CharacterCollision}};Q=t([v(),e("design:paramtypes",[k])],Q);export{Q as PhysicsSystem};const X=new b,Y=new d.Quaternion;function Z(t,e){const i=e.getWorldPosition(X),s=e.getWorldQuaternion(Y);t.setTranslation(ot(i),!1),t.setRotation(nt(s),!1)}const J=new b,$=new b(1,1,1),tt=new i.Vector3(0,0,0),et=new i.Vector3(0,0,0),it=new b,st=new d.Vector2;function ot(t){return at(tt,t),tt}function nt(t){return lt(U,t),U}const rt=async()=>{let t=await import("@dimforge/rapier3d-compat");return await t.init(),t};function at(t,e){t.x=e.x,t.y=e.y,t.z=e.z}function lt(t,e){t.x=e.x,t.y=e.y,t.z=e.z,t.w=e.w}function ct(t,e){t.x=e.x,t.y=e.y,t.z=e.z}function dt(t,e){t.x=e.x,t.y=e.y,t.z=e.z,t.w=e.w}function ht(t,e){for(let i=0,s=t.numColliders();i<s;i++){e(t.collider(i))}}const yt=new b,ut=new b,pt=t=>!t.isSensor(),gt=new b;const mt=new i.Ray(new i.Vector3(0,0,0),new i.Vector3(0,1,0));let ft=class extends j{constructor(){super(...arguments),this._active=!0,this.physics=O(Q),this.world=O(F)}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}};ft=t([L()],ft);export function extractFloat32Array(t){const e=t.itemSize,i=t.count,s=new Float32Array(i*e);for(let o=0;o<i;o++)for(let i=0;i<e;i++)s[o*e+i]=t.getComponent(o,i);return s}const wt=new b;function Bt(t,e,i,s){return s.set(t.x,t.y,t.z,t.w),i.set(e.x,e.y,e.z),i.applyQuaternion(s),i}export class PhysicsCollider{constructor(t,e){this.collider=t,this.world=e,this.disposed=new l,this.onBeginOverlapActor=new l,this.onEndOverlapActor=new l}dispose(){this.world.removeCollider(this.collider,!1),this.disposed.next(!0),this.disposed.complete(),this.onBeginOverlapActor.complete(),this.onEndOverlapActor.complete()}set mass(t){this.collider.setMass(t)}get mass(){return this.collider.mass()}set friction(t){this.collider.setFriction(t)}get friction(){return this.collider.friction()}set restitution(t){this.collider.setRestitution(t)}get restitution(){return this.collider.restitution()}set density(t){this.collider.setDensity(t)}get density(){return this.collider.density()}set isTrigger(t){this.collider.setSensor(t)}get isTrigger(){return this.collider.isSensor()}set collisionGroups(t){this.collider.setCollisionGroups(t)}get collisionGroups(){return this.collider.collisionGroups()}set enabled(t){this.collider.setEnabled(t)}get enabled(){return this.collider.isEnabled()}}export class PhysicsBody{constructor(t,e){this.body=t,this.world=e}dispose(){this.world.removeRigidBody(this.body)}setEnabled(t){this.body.setEnabled(t)}isEnabled(){return this.body.isEnabled()}getPosition(t){const e=this.body.translation();return t.set(e.x,e.y,e.z),t}setPosition(t){this.body.setTranslation({x:t.x,y:t.y,z:t.z},!0)}getRotation(t){const e=this.body.rotation();return t.set(e.x,e.y,e.z,e.w),t}setRotation(t){this.body.setRotation({x:t.x,y:t.y,z:t.z,w:t.w},!0)}getLinearVelocity(t){const e=this.body.linvel();return t.set(e.x,e.y,e.z),t}setLinearVelocity(t){this.body.setLinvel({x:t.x,y:t.y,z:t.z},!0)}getAngularVelocity(t){const e=this.body.angvel();return t.set(e.x,e.y,e.z),t}setAngularVelocity(t){this.body.setAngvel({x:t.x,y:t.y,z:t.z},!0)}applyImpulse(t,e=!0){this.body.applyImpulse({x:t.x,y:t.y,z:t.z},e)}applyTorqueImpulse(t,e=!0){this.body.applyTorqueImpulse({x:t.x,y:t.y,z:t.z},e)}setNextKinematicPosition(t){this.body.setNextKinematicTranslation(t)}setNextKinematicRotation(t){this.body.setNextKinematicRotation(t)}setType(t){this.body.setBodyType(function(t){switch(t){case PhysicsBodyType.dynamic:return i.RigidBodyType.Dynamic;case PhysicsBodyType.static:return i.RigidBodyType.Fixed;case PhysicsBodyType.kinematic:return i.RigidBodyType.KinematicPositionBased;case PhysicsBodyType.kinematicVelocityBased:return i.RigidBodyType.KinematicVelocityBased}}(t),t!==PhysicsBodyType.static)}setGravityScale(t){this.body.setGravityScale(t,!1)}getGravityScale(){return this.body.gravityScale()}isDynamic(){return this.body.isDynamic()}isKinematic(){return this.body.isKinematic()}isStatic(){return this.body.isFixed()}sleep(){this.body.sleep()}wakeUp(){this.body.wakeUp()}}/*
|
|
1
|
+
import{__decorate as t,__metadata as e}from"tslib";import*as i from"@dimforge/rapier3d-compat";import{QueryFilterFlags as s}from"@dimforge/rapier3d-compat";import{BehaviorSubject as o,distinctUntilChanged as n,filter as r,map as a,Subject as l,takeUntil as c}from"rxjs";import*as d from"three";import{ArrowHelper as h,BufferAttribute as y,BufferGeometry as u,Group as p,LineSegments as g,Matrix4 as m,Object3D as f,Quaternion as w,Raycaster as B,Scene as x,Vector3 as b}from"three";import{Service as v}from"typedi";import{AssetMeshInstance as C}from"../../../scene/asset-resource-loader.js";import{BoxCollisionShape as A,CapsuleCollisionShape as S,CollisionShapeSource as R,ConeCollisionShape as D,ConvexPolyhedronCollisionShape as z,CylinderCollisionShape as T,PhysicalShapeMesh as M,PlaneCollisionShape as E,SphereCollisionShape as P,TrimeshCollisionShape as V}from"../../../index.js";import{LandscapeGroup as _}from"../../../scene/landscape/landscape.js";import{ViewController as k}from"../render.js";import{World as F}from"../world.js";import*as I from"three/examples/jsm/utils/BufferGeometryUtils.js";import{calculateEffectiveScale as W}from"../../../utils/three/traverse.js";import{AbstractPhysicsSystem as N}from"./abstract-physics-system.js";import{ActorComponent as j,Component as L}from"../../../gameplay/actors/component.js";import{inject as O}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 class ShapeCastResult{constructor(){this.hasHit=!1,this.hitPoint=new b,this.normal=new b}reset(){this.actor=void 0,this.hasHit=!1,this.distance=0,this.hitPoint.set(0,0,0),this.normal.set(0,0,0)}}ShapeCastResult.shared=new ShapeCastResult;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,K=new b,q=new w,U=new w,H=(new w,[]);let Q=class extends N{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.colliders=new Map,this.collisionEvents=new l,this.beforeStep=new l,this.afterStep=new l,this.shouldRenderDebug=!1,this.shapeCacheBox=new Map,this.shapeCacheBall=new Map,this._raycaster=new B,this._reusableResult=new RayTestResult,this._raytestDiff=new b,this._raytestDirection=new b,this.controlledActors=new Set,this.ready=this.setup()}getBallShape(t){let e=this.shapeCacheBall.get(t);return null==e&&(e=new i.Ball(t),this.shapeCacheBall.set(t,e)),e}getBoxShape(t,e,s){const o=t+1e6*e+1e12*s;let n=this.shapeCacheBox.get(o);return null==n&&(n=new i.Cuboid(t,e,s),this.shapeCacheBox.set(o,n)),n}hasBoxIntersection(t){const e=t.getCenter(G),i=t.getSize(K),s=this.getBoxShape(i.x/2,i.y/2,i.z/2);return null!=this.world.intersectionWithShape(e,q,s)}hasSphereIntersection(t){const e=this.getBallShape(t.radius);return null!=this.world.intersectionWithShape(t.center,q,e)}createDebugMesh(){return new g(new u,new d.LineBasicMaterial({color:255}))}async start(){return await this.ready,this.handleTick(),this.handleCollisionEvents(),this.ready}handleCollisionEvents(){this.collisionSub=this.collisionEvents.subscribe(t=>{const e=this.colliders.get(t.handle1);if(null==e)return;const i=this.world.getCollider(t.handle2);if(null==i||null==i.parent())return;const s=this.bodyActors.get(i.parent());null!=s&&(t.started?e.onBeginOverlapActor.next({actor:s}):e.onEndOverlapActor.next({actor:s}))})}renderDebug(){if(null==this.scene)return;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 y(t.vertices,3))}async setup(){if(null!=this.rapier)throw new Error("Rapier is already estup");this.rapier=await rt(),this.eventQueue=new i.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;null!=e&&e.parent instanceof x&&(ct(e.position,t.translation()),(t.isDynamic()||t.isKinematic()&&!this.controlledActors.has(this.bodyActors.get(t)?.id))&&dt(e.quaternion,t.rotation()),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,i)=>{this.collisionEvents.next({handle1:t,handle2:e,started:i}),this.collisionEvents.next({handle1:e,handle2:t,started:i})})}rayTestFromCamera(t,e,i){this._raycaster.setFromCamera(st,this.viewController.getCamera());const s=this._raycaster.ray.origin,o=this._raycaster.ray.direction.multiplyScalar(t).add(s);return this.rayTest(s,o,e,i)}rayTest(t,e,i,s){null==i&&(i=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"),i;at(mt.origin,t),at(mt.dir,n);const r=o.length(),a=this.world.castRayAndGetNormal(mt,r,!1,void 0,s?.collisionFilter,void 0,null!=s?.excludeActor?this.actorBodies.get(s.excludeActor.id):void 0,s?.excludeTriggers?t=>!t.isSensor():void 0);if(i.hasHit=null!=a,i.hasHit){const e=mt.pointAt(a.timeOfImpact);i._internal=a,ct(i.hitNormal,a.normal),ct(i.hitPoint,e),i.distance=yt.subVectors(i.hitPoint,t).length();const s=this.world.bodies.getAll().find(t=>function(t,e){for(let i=0,s=t.numColliders();i<s;i++){const s=t.collider(i);if(e(s))return s}}(t,t=>t===a.collider));i.actor=null!=s?this.bodyActors.get(s):null}if(this.showDebug){let e;H.length>0?(e=H.pop(),e.setDirection(n),e.position.copy(t),e.setLength(r,.2,.1),e.setColor(s?.debugColor??255)):e=new h(n,t,r,s?.debugColor??255),this.scene?.add(e),setTimeout(()=>{this.scene?.remove(e),H.push(e)},s?.debugLifetime??200)}return i}setGravity(t,e,i){this.world.gravity.x=t,this.world.gravity.y=e,this.world.gravity.z=i}getGravity(){return J.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())ht(t,t=>t.setActiveEvents(i.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 M&&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||t.children[0].isBatchedMesh))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 _?this.addLandscapeGroup(t):(t instanceof p||t instanceof x)&&t.children.forEach(t=>this.addRecursively(t))}createForInstancedMesh(t,e){const i=new m;if(t instanceof d.BatchedMesh){const e=t._instanceInfo??t._drawInfo,s=new Map;for(let o=0;o<e.length;o++){if(null!=t.userData.hasCollision&&!t.userData.hasCollision[o])continue;const e=t.userData.collisionShapes?.[o];if(null==e){console.warn("Missing collision shapes for batched instance");continue}let n=s.get(e);null==n&&(n=this.instancedShapeReset(e),s.set(e,n));const r=new f;r.matrix.identity(),t.getMatrixAt(o,i),r.applyMatrix4(i);this.createStaticBody(r,n)}}else{const s=this.instancedShapeReset(e);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(),i.fromArray(t.instanceMatrix.array,16*e),o.applyMatrix4(i);this.createStaticBody(o,s)}}}instancedShapeReset(t){return t.filter(t=>null!=t).map(t=>t.source===R.rendered?t.withOffset(wt):t)}getCharacterController(t){return this.world?.createCharacterController(t)}getActorComputedMovement(t,e,i,o=null){const n=this.actorBodies.get(t.id);this.controlledActors.add(t.id);const r=n.collider(0);e.computeColliderMovement(r,i,s.EXCLUDE_SENSORS,o,pt);const a=e.computedMovement();return ct(ut,a),ut}createCollider(t,e){const i=this.addShape(e?.body,t),s=new PhysicsCollider(i,this.world);return this.colliders.set(i.handle,s),s.disposed.subscribe(()=>{this.colliders.delete(i.handle)}),s}createBody(t=PhysicsBodyType.dynamic,e={}){const s=(()=>{switch(t){case PhysicsBodyType.dynamic:return i.RigidBodyDesc.dynamic();case PhysicsBodyType.static:return i.RigidBodyDesc.fixed();case PhysicsBodyType.kinematic:return i.RigidBodyDesc.kinematicPositionBased();case PhysicsBodyType.kinematicVelocityBased:return i.RigidBodyDesc.kinematicVelocityBased();default:return i.RigidBodyDesc.dynamic()}})();e.position&&s.setTranslation(e.position.x,e.position.y,e.position.z),e.rotation&&s.setRotation({x:e.rotation.x,y:e.rotation.y,z:e.rotation.z,w:e.rotation.w}),"boolean"==typeof e.canSleep&&s.setCanSleep(e.canSleep),"boolean"==typeof e.ccdEnabled&&s.setCcdEnabled(e.ccdEnabled),"number"==typeof e.gravityScale&&s.setGravityScale(e.gravityScale),"number"==typeof e.mass&&s.setAdditionalMass(e.mass),void 0!==e.userData&&(s.userData=e.userData);const o=this.world.createRigidBody(s);return new PhysicsBody(o,this.world)}getCharacterComputedMovement(t,e,i,o=null){const n=t.collider;e.computeColliderMovement(n,i,s.EXCLUDE_SENSORS,o,pt);const r=e.computedMovement();return ct(ut,r),ut}setNextKinematicTranslation(t,e){const i=this.actorBodies.get(t.id),s=i.translation();s.x+=e.x,s.y+=e.y,s.z+=e.z,i?.setNextKinematicTranslation(s)}setNextKinematicPosition(t,e){this.actorBodies.get(t.id).setNextKinematicTranslation(e)}setNextKinematicRotation(t,e){this.actorBodies.get(t.id).setNextKinematicRotation(e)}setNextKinematicTransform(t){!function(t,e){const i=e.getWorldPosition(X),s=e.getWorldQuaternion(Y);t.setNextKinematicTranslation(ot(i)),t.setNextKinematicRotation(nt(s))}(this.actorBodies.get(t.id),t.object)}setAngularVelocity(t,e){const i=this.actorBodies.get(t.id);tt.x=e.x,tt.y=e.y,tt.z=e.z,i?.setAngvel(tt,!0)}setLinearVelocity(t,e){const i=this.actorBodies.get(t.id);tt.x=e.x,tt.y=e.y,tt.z=e.z,i?.setLinvel(tt,!0)}getLinearVelocity(t,e=new b){const i=this.actorBodies.get(t.id).linvel();return e.x=i.x,e.y=i.y,e.z=i.z,e}getAngularVelocity(t,e=new b){const i=this.actorBodies.get(t.id).angvel();return e.x=i.x,e.y=i.y,e.z=i.z,e}setLinearDamping(t,e){const i=this.actorBodies.get(t.id);i?.setLinearDamping(e)}getLienarDamping(t){const e=this.actorBodies.get(t.id);return e?.linearDamping()??0}setAngularDamping(t,e){const i=this.actorBodies.get(t.id);i?.setAngularDamping(e)}getAngularDamping(t){const e=this.actorBodies.get(t.id);e?.angularDamping()}setPosition(t,e){const i=this.actorBodies.get(t.id);i?.setTranslation(ot(e),!1)}getPosition(t,e=new b){const i=this.actorBodies.get(t.id);i&&ct(e,i.translation())}setRotation(t,e){const i=this.actorBodies.get(t.id);i?.setTranslation(nt(e),!1)}getRotation(t,e=new w){const i=this.actorBodies.get(t.id);i&&dt(e,i.rotation())}lockTranslations(t,e){const i=this.actorBodies.get(t.id);i?.lockTranslations(e,!1)}lockRotations(t,e){const i=this.actorBodies.get(t.id);i?.lockRotations(e,!1)}setEnabledTranslations(t,e,i,s){const o=this.actorBodies.get(t.id);o?.setEnabledTranslations(e,i,s,!1)}setEnabledRotations(t,e,i,s){const o=this.actorBodies.get(t.id);o?.setEnabledRotations(e,i,s,!1)}addLandscapeGroup(t){const e=t.userData.src,s=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(),s=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]*=s.x,a[t+1]*=s.y,a[t+2]*=s.z;const l=t.index;for(let t=0;t<l.count;t+=3){const e=r.getX(l.getX(t)),i=r.getX(l.getY(t)),s=r.getX(l.getZ(t));(e>.5||i>.5||s>.5)&&(l.setX(t,0),l.setY(t,0),l.setZ(t,0))}const c=i.ColliderDesc.trimesh(a,new Uint32Array(t.getIndex().array));if(!1!==e.collisionDetection){const t=this.world.createRigidBody(i.RigidBodyDesc.fixed()),e=new i.Vector3(0,0,0);at(e,o),t.setTranslation(e,!1),this.world.createCollider(c,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 l=s.find(t=>t.x===n.x&&t.y==n.y);if(null!=l)for(const e of l.points){if(null==a[e.i%t])continue;const i=t-1-Math.floor(e.i/t);i in a[e.i%t]?a[e.i%t][i]=e.y/r:console.warn("wrong index",{points:a,point:e,i:e.i%t,k:i,heightMap:l})}const c=e.landscape.options.density,d=a.flatMap(t=>t.reverse()),h=i.ColliderDesc.heightfield(c,c,new Float32Array(d),new i.Vector3(r,r,r));if(!1!==e.collisionDetection){const t=this.world.createRigidBody(i.RigidBodyDesc.fixed()),e=new i.Vector3(0,0,0);at(e,o),t.setTranslation(e,!1),this.world.createCollider(h,t),this.staticBodies.set(n,t)}}}setEnabled(t,e){const i=this.actorBodies.get(t.id);i?.setEnabled(e)}addActor(t,e,s={}){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(s.type??PhysicsBodyType.static){case PhysicsBodyType.dynamic:n=i.RigidBodyDesc.dynamic(),n.mass=s.mass??1;break;case PhysicsBodyType.kinematic:n=i.RigidBodyDesc.kinematicPositionBased();break;case PhysicsBodyType.kinematicVelocityBased:n=i.RigidBodyDesc.kinematicVelocityBased();break;default:n=s.isTrigger?i.RigidBodyDesc.kinematicVelocityBased():i.RigidBodyDesc.fixed()}const r=this.world.createRigidBody(n);r.enableCcd(1==s.continousCollisionDetection);for(const t of e)this.addShape(r,t,o);return ht(r,t=>{null!=s.isTrigger&&(t.setSensor(s.isTrigger),t.setActiveCollisionTypes(i.ActiveCollisionTypes.ALL),t.setActiveEvents(i.ActiveEvents.COLLISION_EVENTS)),null!=s.friction&&t.setFriction(s.friction),null!=s.density&&t.setDensity(s.density),null!=s.mass&&t.setMass(s.mass),null!=s.restitution&&t.setRestitution(s.restitution)}),Z(r,o),!0===s.ignoreForNavMesh&&(r.userData={ignoreForNavMesh:!0}),this.actorBodies.set(t.id,r),this.bodyActors.set(r,t),new PhysicsBody(r,this.world)}applyTorque(t,e){const i=this.actorBodies.get(t.id);tt.x=e.x,tt.y=e.y,tt.z=e.z,i?.addTorque(tt,!0)}applyTorqueImpulse(t,e){const i=this.actorBodies.get(t.id);tt.x=e.x,tt.y=e.y,tt.z=e.z,i?.applyTorqueImpulse(tt,!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 i=this.actorBodies.get(t.id);tt.x=e.x,tt.y=e.y,tt.z=e.z,i?.addForce(tt,!0)}applyImpulse(t,e){const i=this.actorBodies.get(t.id);tt.x=e.x,tt.y=e.y,tt.z=e.z,i?.applyImpulse(tt,!0)}applyLocalForce(t,e,i){const s=this.actorBodies.get(t.id);at(tt,e),null==i?s?.addForce(tt,!0):(at(et,i),s?.addForceAtPoint(tt,et,!0))}applyLocalImpulse(t,e,i){const s=this.actorBodies.get(t.id);at(tt,e),null==i?s.applyImpulse(tt,!0):(at(et,i),s.applyImpulseAtPoint(tt,et,!0))}applyRadiusImpulse(t,e,s){this.world.bodies.forEach(o=>{if(o.collider(0)?.isSensor())return;if(o.bodyType()!==i.RigidBodyType.Dynamic)return;const n=it;ct(n,o.translation());const r=n.clone().sub(t);if(r.length()>e)return;const a=r.clone().normalize().multiplyScalar(s);tt.x=a.x,tt.y=a.y,tt.z=a.z,o.applyImpulse(tt,!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,i]of this.staticBodies.entries())!e.has(t.uuid)&&this.world.getRigidBody(i.handle)&&(this.staticBodies.delete(t),this.world.removeRigidBody(i))}removeSceneObject(t){if(t instanceof _){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,i){return this.activateActorEvents(t),this.collisionEvents.pipe(c(t.disposed),r(({started:t})=>t===i),a(({handle1:t,handle2:e,started:i})=>({a1:this.bodyActors.get(this.world.getCollider(t)?.parent()),a2:this.bodyActors.get(this.world.getCollider(e)?.parent()),started:i})),r(({a1:i,a2:s})=>null!=i&&null!=s&&i.id===t.id&&e(i,s)),a(({a2:t})=>t))}onBeginContact(t){return this.activateActorEvents(t),this.collisionEvents.pipe(c(t.disposed),r(t=>t.started),r(({handle1:e})=>{const i=this.bodyActors.get(this.world.getCollider(e)?.parent());return null!=i&&i.id===t.id}),a(t=>t.handle2))}onEndContact(t){return this.activateActorEvents(t),this.collisionEvents.pipe(c(t.disposed),r(t=>!t.started),r(({handle1:e})=>{const i=this.bodyActors.get(this.world.getCollider(e)?.parent());return null!=i&&i.id===t.id}),a(t=>t.handle2))}onHasContactChanged(t){const e=new Set,i=new o(!1);return this.onBeginContact(t).subscribe(t=>{e.add(t),i.next(e.size>0)}),this.onEndContact(t).subscribe(t=>{e.delete(t),i.next(e.size>0)}),i.pipe(n())}onBeginOverlapWithActorType(t,e){return this._onCollisionWithActorEvent(t,(t,i)=>i instanceof e,!0)}onEndOverlapWithActorType(t,e){return this._onCollisionWithActorEvent(t,(t,i)=>i instanceof e,!1)}onBeginOverlapWithActor(t,e){return this._onCollisionWithActorEvent(t,(t,i)=>e.id===i.id,!0)}onEndOverlapWithActor(t,e){return this._onCollisionWithActorEvent(t,(t,i)=>e.id===i.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&&Z(e,t.object)}setupWorld(){const t=new i.World({x:0,y:-9.81,z:0});this.world=t}sphereCast(t,e,i,s,o=ShapeCastResult.shared,n=void 0){o.reset();const r=this.getBallShape(e);this.shapeCacheBall.get;const a={x:t.x,y:t.y,z:t.z},l={x:i.x,y:i.y,z:i.z},c=this.world.castShape(a,{x:0,y:0,z:0,w:1},l,r,.01,s,!0,null,n,null,void 0,void 0);if(null!=c){ct(o.hitPoint,c.witness1),o.normal.set(c.normal1.x,c.normal1.y,c.normal1.z),o.distance=c.time_of_impact,o.hasHit=!0;const t=c.collider.parent();if(t){const e=this.bodyActors.get(t);e&&(o.actor=e)}}return o}castActorShape(t,e,i,s=ShapeCastResult.shared,o=void 0){s.reset();const n=this.actorBodies.get(t.id);if(n&&n.numColliders()>0){for(let t=0;t<n.numColliders();t++){const r=n.collider(t);let a=r.shape,l=r.translation(),c=r.rotation(),d=e,h=i;const y=this.world.castShape(l,c,d,a,.01,h,!0,null,o,null,n,void 0);if(null!=y){y.collider;const t=r;return ct(s.hitPoint,y.witness1),Bt(t.rotation(),y.normal1,s.normal,U),s.distance=y.time_of_impact,s.actor=this.bodyActors.get(y.collider.parent()),s.hasHit=!0,s}}return s}return console.warn("Actor is not added to the physics system"),s}stop(){this.world?.bodies.forEach(t=>this.world.removeRigidBody(t)),this.world?.free(),this.fixedupdateSub?.unsubscribe(),this.collisionSub?.unsubscribe(),H.length=0}createStaticBody(t,e,s){const o=s?.type===PhysicsBodyType.dynamic?i.RigidBodyDesc.dynamic():i.RigidBodyDesc.fixed(),n=this.world.createRigidBody(o);for(const i of e){if(null==i){console.warn("Collision shape is missing for object",t);continue}const o=this.addShape(n,i,t);null!=s?.friction&&o.setFriction(s.friction),null!=s?.density&&o.setDensity(s.density),null!=s?.mass&&o.setMass(s.mass/e.length),null!=s?.restitution&&o.setRestitution(s.restitution)}return Z(n,t),n.userData=t.uuid,n}addShape(t=void 0,e,i){const s=i?.getWorldScale(gt)??$,o=this.createShape(e,s);this.applyShapeSettings(o,e);const n=e.offset.clone().multiply(s);at(o.translation,n);const r=(new w).setFromEuler(e.rotation);e instanceof z&&e.mesh instanceof d.Mesh&&r.multiply(e.mesh.getWorldQuaternion(Y)),lt(o.rotation,r);return this.world.createCollider(o,t)}applyShapeSettings(t,e){null!=e.collisionGroup&&t.setCollisionGroups(e.collisionGroup),t.friction=e.friction??.1,null!=e.restitution&&(t.restitution=e.restitution),null!=e.density&&(t.density=e.density,t.massPropsMode=i.MassPropsMode.Density),null!=e.mass&&(t.mass=e.mass,t.massPropsMode=i.MassPropsMode.Mass)}createShape(t,e){if(t instanceof A)return i.ColliderDesc.cuboid(t.dimensions.x*e.x/2,t.dimensions.y*e.y/2,t.dimensions.z*e.z/2);if(t instanceof S){return i.ColliderDesc.capsule(t.length/2*e.y,t.radius*Math.max(e.z,e.x))}if(t instanceof V){const s=null!=t.geometry.getIndex()?t.geometry:I.mergeVertices(t.geometry),o=extractFloat32Array(s.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 i.ColliderDesc.trimesh(o,new Uint32Array(s.getIndex().array))}if(t instanceof z){let s;t.mesh instanceof d.Mesh?s=t.mesh.geometry:t.mesh instanceof d.BufferGeometry?s=t.mesh:console.log("Unknownd shape",{shapeInfo:t});const o=extractFloat32Array(s.getAttribute("position"));if(t.mesh instanceof d.Mesh){const e=W(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 i.ColliderDesc.convexHull(n)}if(t instanceof P){const s=2*e.x-e.y-e.z;return Math.abs(s)>.01?this.createShape(new z(new d.SphereGeometry(t.radius).scale(e.x,e.y,e.z)),new b(1,1,1)):i.ColliderDesc.ball(t.radius*Math.max(e.x,e.y,e.z))}return t instanceof T?i.ColliderDesc.cylinder(t.height/2*e.y,t.radiusTop*Math.max(e.z,e.x)):t instanceof D?i.ColliderDesc.cone(t.height*e.y,t.radiusBottom/2*Math.max(e.z,e.x)):t instanceof E?i.ColliderDesc.cuboid(t.width/2*e.x,t.height/2*e.y,.001):(console.error("Unsupported shape",t),i.ColliderDesc.cuboid(1,1,1))}createCharacterCollision(){return new i.CharacterCollision}};Q=t([v(),e("design:paramtypes",[k])],Q);export{Q as PhysicsSystem};const X=new b,Y=new d.Quaternion;function Z(t,e){const i=e.getWorldPosition(X),s=e.getWorldQuaternion(Y);t.setTranslation(ot(i),!1),t.setRotation(nt(s),!1)}const J=new b,$=new b(1,1,1),tt=new i.Vector3(0,0,0),et=new i.Vector3(0,0,0),it=new b,st=new d.Vector2;function ot(t){return at(tt,t),tt}function nt(t){return lt(U,t),U}const rt=async()=>{let t=await import("@dimforge/rapier3d-compat");return await t.init(),t};function at(t,e){t.x=e.x,t.y=e.y,t.z=e.z}function lt(t,e){t.x=e.x,t.y=e.y,t.z=e.z,t.w=e.w}function ct(t,e){t.x=e.x,t.y=e.y,t.z=e.z}function dt(t,e){t.x=e.x,t.y=e.y,t.z=e.z,t.w=e.w}function ht(t,e){for(let i=0,s=t.numColliders();i<s;i++){e(t.collider(i))}}const yt=new b,ut=new b,pt=t=>!t.isSensor(),gt=new b;const mt=new i.Ray(new i.Vector3(0,0,0),new i.Vector3(0,1,0));let ft=class extends j{constructor(){super(...arguments),this._active=!0,this.physics=O(Q),this.world=O(F)}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}};ft=t([L()],ft);export function extractFloat32Array(t){const e=t.itemSize,i=t.count,s=new Float32Array(i*e);for(let o=0;o<i;o++)for(let i=0;i<e;i++)s[o*e+i]=t.getComponent(o,i);return s}const wt=new b;function Bt(t,e,i,s){return s.set(t.x,t.y,t.z,t.w),i.set(e.x,e.y,e.z),i.applyQuaternion(s),i}export class PhysicsCollider{constructor(t,e){this.collider=t,this.world=e,this.disposed=new l,this.onBeginOverlapActor=new l,this.onEndOverlapActor=new l}dispose(){this.world.removeCollider(this.collider,!1),this.disposed.next(!0),this.disposed.complete(),this.onBeginOverlapActor.complete(),this.onEndOverlapActor.complete()}set mass(t){this.collider.setMass(t)}get mass(){return this.collider.mass()}set friction(t){this.collider.setFriction(t)}get friction(){return this.collider.friction()}set restitution(t){this.collider.setRestitution(t)}get restitution(){return this.collider.restitution()}set density(t){this.collider.setDensity(t)}get density(){return this.collider.density()}set isTrigger(t){this.collider.setSensor(t)}get isTrigger(){return this.collider.isSensor()}set collisionGroups(t){this.collider.setCollisionGroups(t)}get collisionGroups(){return this.collider.collisionGroups()}set enabled(t){this.collider.setEnabled(t)}get enabled(){return this.collider.isEnabled()}}export class PhysicsBody{constructor(t,e){this.body=t,this.world=e}dispose(){this.world.removeRigidBody(this.body)}setEnabled(t){this.body.setEnabled(t)}isEnabled(){return this.body.isEnabled()}getPosition(t){const e=this.body.translation();return t.set(e.x,e.y,e.z),t}setPosition(t){this.body.setTranslation({x:t.x,y:t.y,z:t.z},!0)}getRotation(t){const e=this.body.rotation();return t.set(e.x,e.y,e.z,e.w),t}setRotation(t){this.body.setRotation({x:t.x,y:t.y,z:t.z,w:t.w},!0)}getLinearVelocity(t){const e=this.body.linvel();return t.set(e.x,e.y,e.z),t}setLinearVelocity(t){this.body.setLinvel({x:t.x,y:t.y,z:t.z},!0)}getAngularVelocity(t){const e=this.body.angvel();return t.set(e.x,e.y,e.z),t}setAngularVelocity(t){this.body.setAngvel({x:t.x,y:t.y,z:t.z},!0)}applyImpulse(t,e=!0){this.body.applyImpulse({x:t.x,y:t.y,z:t.z},e)}applyTorqueImpulse(t,e=!0){this.body.applyTorqueImpulse({x:t.x,y:t.y,z:t.z},e)}setNextKinematicPosition(t){this.body.setNextKinematicTranslation(t)}setNextKinematicRotation(t){this.body.setNextKinematicRotation(t)}setType(t){this.body.setBodyType(function(t){switch(t){case PhysicsBodyType.dynamic:return i.RigidBodyType.Dynamic;case PhysicsBodyType.static:return i.RigidBodyType.Fixed;case PhysicsBodyType.kinematic:return i.RigidBodyType.KinematicPositionBased;case PhysicsBodyType.kinematicVelocityBased:return i.RigidBodyType.KinematicVelocityBased}}(t),t!==PhysicsBodyType.static)}setGravityScale(t){this.body.setGravityScale(t,!1)}getGravityScale(){return this.body.gravityScale()}isDynamic(){return this.body.isDynamic()}isKinematic(){return this.body.isKinematic()}isStatic(){return this.body.isFixed()}sleep(){this.body.sleep()}wakeUp(){this.body.wakeUp()}}/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Color } from 'three';
|
|
2
|
+
/**
|
|
3
|
+
* Luminosity
|
|
4
|
+
* http://en.wikipedia.org/wiki/Luminosity
|
|
5
|
+
*/
|
|
6
|
+
export declare const LuminosityHighPassShader: {
|
|
7
|
+
shaderID: string;
|
|
8
|
+
uniforms: {
|
|
9
|
+
tDiffuse: {
|
|
10
|
+
value: any;
|
|
11
|
+
};
|
|
12
|
+
luminosityThreshold: {
|
|
13
|
+
value: number;
|
|
14
|
+
};
|
|
15
|
+
smoothWidth: {
|
|
16
|
+
value: number;
|
|
17
|
+
};
|
|
18
|
+
defaultColor: {
|
|
19
|
+
value: Color;
|
|
20
|
+
};
|
|
21
|
+
defaultOpacity: {
|
|
22
|
+
value: number;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
vertexShader: string;
|
|
26
|
+
fragmentShader: string;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=LuminosityHighPassShader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LuminosityHighPassShader.d.ts","sourceRoot":"","sources":["../../../src/rendering/bloom/LuminosityHighPassShader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAE7B;;;GAGG;AAEH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;CAgDpC,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{Color as t}from"three";export const LuminosityHighPassShader={shaderID:"luminosityHighPass",uniforms:{tDiffuse:{value:null},luminosityThreshold:{value:1},smoothWidth:{value:1},defaultColor:{value:new t(0)},defaultOpacity:{value:0}},vertexShader:"\n varying vec2 vUv;\n\n void main() {\n\n \tvUv = uv;\n\n \tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n }\n ",fragmentShader:"\n uniform sampler2D tDiffuse;\n uniform vec3 defaultColor;\n uniform float defaultOpacity;\n uniform float luminosityThreshold;\n uniform float smoothWidth;\n\n varying vec2 vUv;\n\n void main() {\n\n \tvec4 texel = texture2D( tDiffuse, vUv );\n\n \tvec3 luma = vec3( 0.299, 0.587, 0.114 );\n\n \tfloat v = dot( texel.xyz, luma );\n\n \tvec4 outputColor = vec4( defaultColor.rgb, defaultOpacity );\n\n \tfloat alpha = smoothstep( luminosityThreshold, luminosityThreshold + smoothWidth, v );\n\n \tgl_FragColor = mix( outputColor, texel, alpha );\n\n }\n "};/*
|
|
2
|
+
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
|
+
* See the LICENSE.md file for details.
|
|
4
|
+
*/
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export namespace LuminosityHighPassShader {
|
|
2
|
+
let shaderID: string;
|
|
3
|
+
namespace uniforms {
|
|
4
|
+
namespace tDiffuse {
|
|
5
|
+
let value: any;
|
|
6
|
+
}
|
|
7
|
+
namespace luminosityThreshold {
|
|
8
|
+
let value_1: number;
|
|
9
|
+
export { value_1 as value };
|
|
10
|
+
}
|
|
11
|
+
namespace smoothWidth {
|
|
12
|
+
let value_2: number;
|
|
13
|
+
export { value_2 as value };
|
|
14
|
+
}
|
|
15
|
+
namespace defaultColor {
|
|
16
|
+
let value_3: Color;
|
|
17
|
+
export { value_3 as value };
|
|
18
|
+
}
|
|
19
|
+
namespace defaultOpacity {
|
|
20
|
+
let value_4: number;
|
|
21
|
+
export { value_4 as value };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
let vertexShader: string;
|
|
25
|
+
let fragmentShader: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* UnrealBloomPass is inspired by the bloom pass of Unreal Engine. It creates a
|
|
29
|
+
* mip map chain of bloom textures and blurs them with different radii. Because
|
|
30
|
+
* of the weighted combination of mips, and because larger blurs are done on
|
|
31
|
+
* higher mips, this effect provides good quality and performance.
|
|
32
|
+
*
|
|
33
|
+
* Reference:
|
|
34
|
+
* - https://docs.unrealengine.com/latest/INT/Engine/Rendering/PostProcessEffects/Bloom/
|
|
35
|
+
*/
|
|
36
|
+
export class UnrealBloomPass extends Pass {
|
|
37
|
+
static BlurDirectionX: Vector2;
|
|
38
|
+
static BlurDirectionY: Vector2;
|
|
39
|
+
constructor(resolution: any, strength: any, radius: any, threshold: any);
|
|
40
|
+
strength: any;
|
|
41
|
+
radius: any;
|
|
42
|
+
threshold: any;
|
|
43
|
+
resolution: Vector2;
|
|
44
|
+
clearColor: Color;
|
|
45
|
+
renderTargetsHorizontal: WebGLRenderTarget<import("three").Texture>[];
|
|
46
|
+
renderTargetsVertical: WebGLRenderTarget<import("three").Texture>[];
|
|
47
|
+
nMips: number;
|
|
48
|
+
renderTargetBright: WebGLRenderTarget<import("three").Texture>;
|
|
49
|
+
highPassUniforms: {
|
|
50
|
+
tDiffuse: {
|
|
51
|
+
value: any;
|
|
52
|
+
};
|
|
53
|
+
luminosityThreshold: {
|
|
54
|
+
value: number;
|
|
55
|
+
};
|
|
56
|
+
smoothWidth: {
|
|
57
|
+
value: number;
|
|
58
|
+
};
|
|
59
|
+
defaultColor: {
|
|
60
|
+
value: Color;
|
|
61
|
+
};
|
|
62
|
+
defaultOpacity: {
|
|
63
|
+
value: number;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
materialHighPassFilter: ShaderMaterial;
|
|
67
|
+
separableBlurMaterials: ShaderMaterial[];
|
|
68
|
+
compositeMaterial: ShaderMaterial;
|
|
69
|
+
bloomTintColors: Vector3[];
|
|
70
|
+
copyUniforms: import("three-stdlib").CopyShaderUniforms;
|
|
71
|
+
materialCopy: ShaderMaterial;
|
|
72
|
+
_oldClearColor: Color;
|
|
73
|
+
oldClearAlpha: number;
|
|
74
|
+
basic: MeshBasicMaterial;
|
|
75
|
+
fsQuad: FullScreenQuad;
|
|
76
|
+
setSize(width: any, height: any): void;
|
|
77
|
+
render(renderer: any, writeBuffer: any, readBuffer: any, deltaTime: any, maskActive: any): void;
|
|
78
|
+
getSeperableBlurMaterial(kernelRadius: any): ShaderMaterial;
|
|
79
|
+
getCompositeMaterial(nMips: any): ShaderMaterial;
|
|
80
|
+
}
|
|
81
|
+
import { Color } from 'three';
|
|
82
|
+
import { Pass } from 'three/examples/jsm/Addons.js';
|
|
83
|
+
import { Vector2 } from 'three';
|
|
84
|
+
import { WebGLRenderTarget } from 'three';
|
|
85
|
+
import { ShaderMaterial } from 'three';
|
|
86
|
+
import { Vector3 } from 'three';
|
|
87
|
+
import { MeshBasicMaterial } from 'three';
|
|
88
|
+
import { FullScreenQuad } from 'three/examples/jsm/Addons.js';
|
|
89
|
+
//# sourceMappingURL=UnrealBloomPass.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnrealBloomPass.d.ts","sourceRoot":"","sources":["../../../src/rendering/bloom/UnrealBloomPass.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAcA;;;;;;;;GAQG;AACH;IACE,+BAA6C;IAC7C,+BAA6C;IAK7C,yEAyHC;IAtHC,cAAqD;IACrD,YAAoB;IACpB,eAA0B;IAC1B,oBAA4G;IAG5G,kBAAoC;IAGpC,sEAAiC;IACjC,oEAA+B;IAC/B,cAAc;IAId,+DAAoF;IA2BpF;;;;;;;;;;;;;;;;MAAoE;IAKpE,uCAKE;IAGF,yCAAgC;IAgBhC,kCAA8D;IAY9D,2BAMC;IAOD,wDAA4D;IAG5D,6BAQE;IAKF,sBAAiC;IACjC,sBAAsB;IAEtB,yBAAoC;IAEpC,uBAAsC;IA6BxC,uCAeC;IAED,gGAmFC;IAED,4DA6CC;IAED,iDAgDC;CACF;sBA/WM,OAAO;qBAEuB,8BAA8B;wBAF5D,OAAO;kCAAP,OAAO;+BAAP,OAAO;wBAAP,OAAO;kCAAP,OAAO;+BAEuB,8BAA8B"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{AdditiveBlending as e,Color as t,HalfFloatType as r,MeshBasicMaterial as i,ShaderMaterial as o,UniformsUtils as s,Vector2 as a,Vector3 as l,WebGLRenderTarget as n}from"three";import{CopyShader as u}from"three-stdlib";import{FullScreenQuad as h,Pass as m}from"three/examples/jsm/Addons.js";class d extends m{constructor(m,d,f,v){super(),this.strength=void 0!==d?d:1,this.radius=f,this.threshold=v,this.resolution=void 0!==m?new a(m.x,m.y):new a(256,256),this.clearColor=new t(0,0,0),this.renderTargetsHorizontal=[],this.renderTargetsVertical=[],this.nMips=5;let c=Math.round(this.resolution.x/2),p=Math.round(this.resolution.y/2);this.renderTargetBright=new n(c,p,{type:r}),this.renderTargetBright.texture.name="UnrealBloomPass.bright",this.renderTargetBright.texture.generateMipmaps=!1;for(let e=0;e<this.nMips;e++){const t=new n(c,p,{type:r});t.texture.name="UnrealBloomPass.h"+e,t.texture.generateMipmaps=!1,this.renderTargetsHorizontal.push(t);const i=new n(c,p,{type:r});i.texture.name="UnrealBloomPass.v"+e,i.texture.generateMipmaps=!1,this.renderTargetsVertical.push(i),c=Math.round(c/2),p=Math.round(p/2)}const g=LuminosityHighPassShader;this.highPassUniforms=s.clone(g.uniforms),this.highPassUniforms.luminosityThreshold.value=v,this.highPassUniforms.smoothWidth.value=.01,this.materialHighPassFilter=new o({uniforms:this.highPassUniforms,vertexShader:g.vertexShader,fragmentShader:g.fragmentShader,defines:{}}),this.separableBlurMaterials=[];const x=[3,5,7,9,11];c=Math.round(this.resolution.x/2),p=Math.round(this.resolution.y/2);for(let e=0;e<this.nMips;e++)this.separableBlurMaterials.push(this.getSeperableBlurMaterial(x[e])),this.separableBlurMaterials[e].uniforms.texSize.value=new a(c,p),c=Math.round(c/2),p=Math.round(p/2);this.compositeMaterial=this.getCompositeMaterial(this.nMips),this.compositeMaterial.uniforms.blurTexture1.value=this.renderTargetsVertical[0].texture,this.compositeMaterial.uniforms.blurTexture2.value=this.renderTargetsVertical[1].texture,this.compositeMaterial.uniforms.blurTexture3.value=this.renderTargetsVertical[2].texture,this.compositeMaterial.uniforms.blurTexture4.value=this.renderTargetsVertical[3].texture,this.compositeMaterial.uniforms.blurTexture5.value=this.renderTargetsVertical[4].texture,this.compositeMaterial.uniforms.bloomStrength.value=d,this.compositeMaterial.uniforms.bloomRadius.value=.1,this.compositeMaterial.needsUpdate=!0;this.compositeMaterial.uniforms.bloomFactors.value=[1,.8,.6,.4,.2],this.bloomTintColors=[new l(1,1,1),new l(1,1,1),new l(1,1,1),new l(1,1,1),new l(1,1,1)],this.compositeMaterial.uniforms.bloomTintColors.value=this.bloomTintColors;const T=u;this.copyUniforms=s.clone(T.uniforms),this.copyUniforms.opacity.value=1,this.materialCopy=new o({uniforms:this.copyUniforms,vertexShader:T.vertexShader,fragmentShader:T.fragmentShader,blending:e,depthTest:!1,depthWrite:!1,transparent:!0}),this.enabled=!0,this.needsSwap=!1,this._oldClearColor=new t,this.oldClearAlpha=1,this.basic=new i,this.fsQuad=new h(null)}dispose(){for(let e=0;e<this.renderTargetsHorizontal.length;e++)this.renderTargetsHorizontal[e].dispose();for(let e=0;e<this.renderTargetsVertical.length;e++)this.renderTargetsVertical[e].dispose();this.renderTargetBright.dispose();for(let e=0;e<this.separableBlurMaterials.length;e++)this.separableBlurMaterials[e].dispose();this.compositeMaterial.dispose(),this.materialCopy.dispose(),this.basic.dispose(),this.fsQuad.dispose()}setSize(e,t){let r=Math.round(e/2),i=Math.round(t/2);this.renderTargetBright.setSize(r,i);for(let e=0;e<this.nMips;e++)this.renderTargetsHorizontal[e].setSize(r,i),this.renderTargetsVertical[e].setSize(r,i),this.separableBlurMaterials[e].uniforms.texSize.value=new a(r,i),r=Math.round(r/2),i=Math.round(i/2)}render(e,t,r,i,o){e.getClearColor(this._oldClearColor),this.oldClearAlpha=e.getClearAlpha();const s=e.autoClear;e.autoClear=!1,e.setClearColor(this.clearColor,0),o&&e.state.buffers.stencil.setTest(!1),this.renderToScreen&&(this.fsQuad.material=this.basic,this.basic.map=r.texture,e.setRenderTarget(null),e.clear(),this.fsQuad.render(e)),this.highPassUniforms.tDiffuse.value=this.emissiveTexture??r.texture,this.highPassUniforms.luminosityThreshold.value=this.threshold,this.fsQuad.material=this.materialHighPassFilter,e.setRenderTarget(this.renderTargetBright),e.clear(),this.fsQuad.render(e);let a=this.renderTargetBright;for(let t=0;t<this.nMips;t++)this.fsQuad.material=this.separableBlurMaterials[t],this.separableBlurMaterials[t].uniforms.colorTexture.value=a.texture,this.separableBlurMaterials[t].uniforms.direction.value=d.BlurDirectionX,e.setRenderTarget(this.renderTargetsHorizontal[t]),e.clear(),this.fsQuad.render(e),this.separableBlurMaterials[t].uniforms.colorTexture.value=this.renderTargetsHorizontal[t].texture,this.separableBlurMaterials[t].uniforms.direction.value=d.BlurDirectionY,e.setRenderTarget(this.renderTargetsVertical[t]),e.clear(),this.fsQuad.render(e),a=this.renderTargetsVertical[t];this.fsQuad.material=this.compositeMaterial,this.compositeMaterial.uniforms.bloomStrength.value=this.strength,this.compositeMaterial.uniforms.bloomRadius.value=this.radius,this.compositeMaterial.uniforms.bloomTintColors.value=this.bloomTintColors,e.setRenderTarget(this.renderTargetsHorizontal[0]),e.clear(),this.fsQuad.render(e),this.fsQuad.material=this.materialCopy,this.copyUniforms.tDiffuse.value=this.renderTargetsHorizontal[0].texture,o&&e.state.buffers.stencil.setTest(!0),this.renderToScreen?(e.setRenderTarget(null),this.fsQuad.render(e)):(e.setRenderTarget(r),this.fsQuad.render(e)),e.setClearColor(this._oldClearColor,this.oldClearAlpha),e.autoClear=s}getSeperableBlurMaterial(e){return new o({defines:{KERNEL_RADIUS:e,SIGMA:e},uniforms:{colorTexture:{value:null},texSize:{value:new a(.5,.5)},direction:{value:new a(.5,.5)}},vertexShader:"varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }",fragmentShader:"#include <common>\n varying vec2 vUv;\n uniform sampler2D colorTexture;\n uniform vec2 texSize;\n uniform vec2 direction;\n\n float gaussianPdf(in float x, in float sigma) {\n return 0.39894 * exp( -0.5 * x * x/( sigma * sigma))/sigma;\n }\n void main() {\n vec2 invSize = 1.0 / texSize;\n float fSigma = float(SIGMA);\n float weightSum = gaussianPdf(0.0, fSigma);\n vec3 diffuseSum = texture2D( colorTexture, vUv).rgb * weightSum;\n for( int i = 1; i < KERNEL_RADIUS; i ++ ) {\n float x = float(i);\n float w = gaussianPdf(x, fSigma);\n vec2 uvOffset = direction * invSize * x;\n vec3 sample1 = texture2D( colorTexture, vUv + uvOffset).rgb;\n vec3 sample2 = texture2D( colorTexture, vUv - uvOffset).rgb;\n diffuseSum += (sample1 + sample2) * w;\n weightSum += 2.0 * w;\n }\n gl_FragColor = vec4(diffuseSum/weightSum, 1.0);\n }"})}getCompositeMaterial(e){return new o({defines:{NUM_MIPS:e},uniforms:{blurTexture1:{value:null},blurTexture2:{value:null},blurTexture3:{value:null},blurTexture4:{value:null},blurTexture5:{value:null},bloomStrength:{value:1},bloomFactors:{value:null},bloomTintColors:{value:null},bloomRadius:{value:0}},vertexShader:"varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }",fragmentShader:"varying vec2 vUv;\n uniform sampler2D blurTexture1;\n uniform sampler2D blurTexture2;\n uniform sampler2D blurTexture3;\n uniform sampler2D blurTexture4;\n uniform sampler2D blurTexture5;\n uniform float bloomStrength;\n uniform float bloomRadius;\n uniform float bloomFactors[NUM_MIPS];\n uniform vec3 bloomTintColors[NUM_MIPS];\n\n float lerpBloomFactor(const in float factor) {\n float mirrorFactor = 1.2 - factor;\n return mix(factor, mirrorFactor, bloomRadius);\n }\n\n void main() {\n gl_FragColor = bloomStrength * ( lerpBloomFactor(bloomFactors[0]) * vec4(bloomTintColors[0], 1.0) * texture2D(blurTexture1, vUv) +\n lerpBloomFactor(bloomFactors[1]) * vec4(bloomTintColors[1], 1.0) * texture2D(blurTexture2, vUv) +\n lerpBloomFactor(bloomFactors[2]) * vec4(bloomTintColors[2], 1.0) * texture2D(blurTexture3, vUv) +\n lerpBloomFactor(bloomFactors[3]) * vec4(bloomTintColors[3], 1.0) * texture2D(blurTexture4, vUv) +\n lerpBloomFactor(bloomFactors[4]) * vec4(bloomTintColors[4], 1.0) * texture2D(blurTexture5, vUv) );\n }"})}}d.BlurDirectionX=new a(1,0),d.BlurDirectionY=new a(0,1);export{d as UnrealBloomPass};export const LuminosityHighPassShader={shaderID:"luminosityHighPass",uniforms:{tDiffuse:{value:null},luminosityThreshold:{value:1},smoothWidth:{value:1},defaultColor:{value:new t(0)},defaultOpacity:{value:0}},vertexShader:"\n varying vec2 vUv;\n\n void main() {\n\n \tvUv = uv;\n\n \tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n }\n ",fragmentShader:"\n uniform sampler2D tDiffuse;\n uniform vec3 defaultColor;\n uniform float defaultOpacity;\n uniform float luminosityThreshold;\n uniform float smoothWidth;\n\n varying vec2 vUv;\n\n void main() {\n\n \tvec4 texel = texture2D( tDiffuse, vUv );\n\n \tvec3 luma = vec3( 0.299, 0.587, 0.114 );\n\n \tfloat v = dot( texel.xyz, luma );\n\n \tvec4 outputColor = vec4( defaultColor.rgb, defaultOpacity );\n\n \tfloat alpha = smoothstep( luminosityThreshold, luminosityThreshold + smoothWidth, v );\n\n \tgl_FragColor = mix( outputColor, texel, alpha );\n\n }\n "};/*
|
|
2
|
+
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
|
+
* See the LICENSE.md file for details.
|
|
4
|
+
*/
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IUniform } from 'three';
|
|
2
|
+
export type Defines = {
|
|
3
|
+
[key: string]: boolean | number | string;
|
|
4
|
+
};
|
|
5
|
+
export type Uniforms = {
|
|
6
|
+
[key: string]: IUniform;
|
|
7
|
+
};
|
|
8
|
+
export interface IShader<U extends Uniforms, D extends Defines | undefined = undefined> {
|
|
9
|
+
defines?: D;
|
|
10
|
+
fragmentShader: string;
|
|
11
|
+
uniforms: U;
|
|
12
|
+
vertexShader: string;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/rendering/bloom/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAErC,MAAM,MAAM,OAAO,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;CAAE,CAAA;AAClE,MAAM,MAAM,QAAQ,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAA;AAElD,MAAM,WAAW,OAAO,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,OAAO,GAAG,SAAS,GAAG,SAAS;IACpF,OAAO,CAAC,EAAE,CAAC,CAAA;IACX,cAAc,EAAE,MAAM,CAAA;IACtB,QAAQ,EAAE,CAAC,CAAA;IACX,YAAY,EAAE,MAAM,CAAA;CACrB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{BackSide as e,Color as i,ShaderMaterial as t,UniformsLib as n,UniformsUtils as a,Object3D as l,Mesh as r,InstancedMesh as o,BatchedMesh as s}from"three";export class OutlineEffect{constructor(l,r={}){this.applied=new WeakSet,this.enabled=!0;const o=void 0!==r.defaultThickness?r.defaultThickness:.003,s=(new i).fromArray(void 0!==r.defaultColor?r.defaultColor:[0,0,0]),u=void 0!==r.defaultAlpha?r.defaultAlpha:1,p=void 0!==r.defaultKeepAlive&&r.defaultKeepAlive,c={},d={},m={outlineThickness:{value:o},outlineColor:{value:s},outlineAlpha:{value:u}},v=["#include <common>","#include <uv_pars_vertex>","#include <displacementmap_pars_vertex>","#include <fog_pars_vertex>","#include <morphtarget_pars_vertex>","#include <skinning_pars_vertex>","#include <logdepthbuf_pars_vertex>","#include <clipping_planes_pars_vertex>","uniform float outlineThickness;","vec4 calculateOutline( vec4 pos, vec3 normal, vec4 skinned ) {","\tfloat thickness = outlineThickness;","\tconst float ratio = 1.0;","\tvec4 pos2 = projectionMatrix * modelViewMatrix * vec4( skinned.xyz + normal, 1.0 );"," float viewDistance = length((modelViewMatrix * vec4(skinned.xyz, 1.0)).xyz);"," float scale = pow(viewDistance, 0.5); // sqrt, or any exponent","\tvec4 norm = normalize( pos - pos2 );","\treturn pos + norm * thickness * scale * ratio;","}","void main() {","\t#include <uv_vertex>","\t#include <beginnormal_vertex>","\t#include <morphnormal_vertex>","\t#include <skinbase_vertex>","\t#include <skinnormal_vertex>","\t#include <begin_vertex>","\t#include <morphtarget_vertex>","\t#include <skinning_vertex>","\t#include <displacementmap_vertex>","\t#include <project_vertex>","\tvec3 outlineNormal = - objectNormal;","\tgl_Position = calculateOutline( gl_Position, outlineNormal, vec4( transformed, 1.0 ) );","\t#include <logdepthbuf_vertex>","\t#include <clipping_planes_vertex>","\t#include <fog_vertex>","}"].join("\n"),f=["#include <common>","#include <fog_pars_fragment>","#include <logdepthbuf_pars_fragment>","#include <clipping_planes_pars_fragment>","uniform vec3 outlineColor;","uniform float outlineAlpha;","void main() {","\t#include <clipping_planes_fragment>","\t#include <logdepthbuf_fragment>","\tgl_FragColor = vec4( outlineColor, outlineAlpha );","\t#include <tonemapping_fragment>","\t#include <colorspace_fragment>","\t#include <fog_fragment>","\t#include <premultiplied_alpha_fragment>","}"].join("\n");function h(){return new t({type:"OutlineEffect",uniforms:a.merge([n.fog,n.displacementmap,m]),vertexShader:v,fragmentShader:f,side:e,depthTest:!0,depthWrite:!
|
|
1
|
+
import{BackSide as e,Color as i,ShaderMaterial as t,UniformsLib as n,UniformsUtils as a,Object3D as l,Mesh as r,InstancedMesh as o,BatchedMesh as s}from"three";export class OutlineEffect{constructor(l,r={}){this.applied=new WeakSet,this.enabled=!0;const o=void 0!==r.defaultThickness?r.defaultThickness:.003,s=(new i).fromArray(void 0!==r.defaultColor?r.defaultColor:[0,0,0]),u=void 0!==r.defaultAlpha?r.defaultAlpha:1,p=void 0!==r.defaultKeepAlive&&r.defaultKeepAlive,c={},d={},m={outlineThickness:{value:o},outlineColor:{value:s},outlineAlpha:{value:u}},v=["#include <common>","#include <uv_pars_vertex>","#include <displacementmap_pars_vertex>","#include <fog_pars_vertex>","#include <morphtarget_pars_vertex>","#include <skinning_pars_vertex>","#include <logdepthbuf_pars_vertex>","#include <clipping_planes_pars_vertex>","uniform float outlineThickness;","vec4 calculateOutline( vec4 pos, vec3 normal, vec4 skinned ) {","\tfloat thickness = outlineThickness;","\tconst float ratio = 1.0;","\tvec4 pos2 = projectionMatrix * modelViewMatrix * vec4( skinned.xyz + normal, 1.0 );"," float viewDistance = length((modelViewMatrix * vec4(skinned.xyz, 1.0)).xyz);"," float scale = pow(viewDistance, 0.5); // sqrt, or any exponent","\tvec4 norm = normalize( pos - pos2 );","\treturn pos + norm * thickness * scale * ratio;","}","void main() {","\t#include <uv_vertex>","\t#include <beginnormal_vertex>","\t#include <morphnormal_vertex>","\t#include <skinbase_vertex>","\t#include <skinnormal_vertex>","\t#include <begin_vertex>","\t#include <morphtarget_vertex>","\t#include <skinning_vertex>","\t#include <displacementmap_vertex>","\t#include <project_vertex>","\tvec3 outlineNormal = - objectNormal;","\tgl_Position = calculateOutline( gl_Position, outlineNormal, vec4( transformed, 1.0 ) );","\t#include <logdepthbuf_vertex>","\t#include <clipping_planes_vertex>","\t#include <fog_vertex>","}"].join("\n"),f=["#include <common>","#include <fog_pars_fragment>","#include <logdepthbuf_pars_fragment>","#include <clipping_planes_pars_fragment>","uniform vec3 outlineColor;","uniform float outlineAlpha;","void main() {","\t#include <clipping_planes_fragment>","\t#include <logdepthbuf_fragment>","\tgl_FragColor = vec4( outlineColor, outlineAlpha );","\t#include <tonemapping_fragment>","\t#include <colorspace_fragment>","\t#include <fog_fragment>","\t#include <premultiplied_alpha_fragment>","}"].join("\n");function h(){return new t({type:"OutlineEffect",uniforms:a.merge([n.fog,n.displacementmap,m]),vertexShader:v,fragmentShader:f,side:e,depthTest:!0,depthWrite:!0,transparent:!0})}this.createMaterial=h,this.getOutlineMaterial=function(e){const i=function(e){let i=c[e.uuid];return void 0===i&&(i={material:h(),used:!0,keepAlive:p,count:0},c[e.uuid]=i),i.used=!0,i.material}(e);return d[i.uuid]=e,function(e,i){Array.isArray(i)&&(i=i[0]);if("invisible"===e.name)return;const t=i.userData.outlineParameters;e.fog=i.fog,e.toneMapped=i.toneMapped,e.premultipliedAlpha=i.premultipliedAlpha,e.displacementMap=i.displacementMap,void 0!==t?(!1===i.visible?e.visible=!1:e.visible=void 0===t.visible||t.visible,e.transparent=void 0!==t.alpha&&t.alpha<1||i.transparent,void 0!==t.keepAlive&&(c[i.uuid].keepAlive=t.keepAlive)):(e.transparent=i.transparent,e.visible=i.visible);!0!==i.wireframe&&!1!==i.depthTest||(e.visible=!1);i.clippingPlanes&&(e.clipping=!0,e.clippingPlanes=i.clippingPlanes,e.clipIntersection=i.clipIntersection,e.clipShadows=i.clipShadows);e.version=i.version}(i,e),i},this.updateUniforms=function(e,i){const t=i.userData.outlineParameters;e.uniforms.outlineAlpha.value=i.opacity,void 0!==t&&(void 0!==t.thickness&&(e.uniforms.outlineThickness.value=t.thickness),void 0!==t.color&&e.uniforms.outlineColor.value.fromArray(t.color),void 0!==t.alpha&&(e.uniforms.outlineAlpha.value=t.alpha)),i.displacementMap&&(e.uniforms.displacementMap.value=i.displacementMap,e.uniforms.displacementScale.value=i.displacementScale,e.uniforms.displacementBias.value=i.displacementBias)}}apply(e){if(!(e instanceof r)||e instanceof s||e instanceof o)return;if(this.applied.has(e))return;this.applied.add(e);const i=e.onAfterRender;e.onAfterRender=(t,n,a,l,r,o)=>{i(t,n,a,l,r);let s=!1;if(Array.isArray(r)?s=r.some(e=>e&&e.userData&&e.userData.outlineParameters):r&&r.userData&&r.userData.outlineParameters&&(s=!0),!s)return;const u=e.material,p=this.getOutlineMaterial(u);e.material=p,this.updateUniforms(p,r),t.renderBufferDirect(a,n,l,p,e,o),e.material=u}}}/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -57,7 +57,7 @@ export class SSRPass extends Pass {
|
|
|
57
57
|
*
|
|
58
58
|
* @param {SSRPass~Options} options - The pass options.
|
|
59
59
|
*/
|
|
60
|
-
constructor({ renderer, scene, camera, width, height, selects, bouncing, groundReflector }: SSRPass);
|
|
60
|
+
constructor({ renderer, scene, camera, width, height, selects, bouncing, groundReflector, normalTexture, depthTexture }: SSRPass);
|
|
61
61
|
/**
|
|
62
62
|
* Elapsed time used for custom shaders
|
|
63
63
|
*/
|
|
@@ -139,6 +139,13 @@ export class SSRPass extends Pass {
|
|
|
139
139
|
* @default false
|
|
140
140
|
*/
|
|
141
141
|
selective: boolean;
|
|
142
|
+
renderNormals: boolean;
|
|
143
|
+
/**
|
|
144
|
+
* How much to divide the resolution. Native resolution (1) is usually not necessary.
|
|
145
|
+
* @type {number}
|
|
146
|
+
* @default 2
|
|
147
|
+
*/
|
|
148
|
+
resolutionDownscale: number;
|
|
142
149
|
_bouncing: any;
|
|
143
150
|
/**
|
|
144
151
|
* Whether to blur reflections or not.
|
|
@@ -178,7 +185,7 @@ export class SSRPass extends Pass {
|
|
|
178
185
|
* @param {number} deltaTime - The delta time in seconds.
|
|
179
186
|
* @param {boolean} maskActive - Whether masking is active or not.
|
|
180
187
|
*/
|
|
181
|
-
render(renderer: WebGLRenderer, writeBuffer: WebGLRenderTarget): void;
|
|
188
|
+
render(renderer: WebGLRenderer, writeBuffer: WebGLRenderTarget, readBuffer: WebGLRenderTarget): void;
|
|
182
189
|
_renderPass(renderer: any, passMaterial: any, renderTarget: any, clearColor: any, clearAlpha: any): void;
|
|
183
190
|
_renderOverride(renderer: any, overrideMaterial: any, renderTarget: any, clearColor: any, clearAlpha: any): void;
|
|
184
191
|
_renderMetalness(renderer: any, overrideMaterial: any, renderTarget: any, clearColor: any, clearAlpha: any): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SSRPass.d.ts","sourceRoot":"","sources":["../../../src/rendering/ssr/SSRPass.js"],"names":[],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"SSRPass.d.ts","sourceRoot":"","sources":["../../../src/rendering/ssr/SSRPass.js"],"names":[],"mappings":";;;;;;;cA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CD,yGA2BC;IAID,iHAoEC;IAED,kHAiGC;CAED;;;;;;;;;;;qBA36BgD,8BAA8B;sBAFxE,OAAO;kCAAP,OAAO;+BAAP,OAAO;mCAAP,OAAO;kCAAP,OAAO;+BAEmC,8BAA8B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{AddEquation as e,Color as t,DepthTexture as r,HalfFloatType as s,Mesh as i,MeshBasicMaterial as a,MeshLambertMaterial as n,MeshNormalMaterial as l,MeshStandardMaterial as h,NearestFilter as o,NoBlending as u,NormalBlending as d,OneMinusSrcAlphaFactor as c,ShaderMaterial as m,SrcAlphaFactor as f,UniformsUtils as p,UnsignedShortType as g,WebGLRenderTarget as M}from"three";import{NodeShaderMaterial as T,float as b,rgb as R,vec3 as v}from"three-shader-graph";import{CopyShader as y,FullScreenQuad as C,Pass as S}from"three/examples/jsm/Addons.js";import{oneMinus as _}from"../../shader-nodes/math.js";import{traverseVisibleStop as x}from"../../utils/three/traverse.js";import{elapsedTimeUniformName as w}from"../../shader-nodes/time.js";import{SSRBlurShader as P,SSRDepthShader as A,SSRShader as D}from"./SSRShader.js";const k=new WeakMap,O=new WeakMap;class U extends S{constructor({renderer:i,scene:n,camera:h,width:d=512,height:T=512,selects:b=null,bouncing:R=!1,groundReflector:v=null}){super(),this.elapsedTime=0,this.width=d,this.height=T,this.clear=!0,this.renderer=i,this.scene=n,this.camera=h,this.groundReflector=v,this.opacity=D.uniforms.opacity.value,this.output=0,this.maxDistance=D.uniforms.maxDistance.value,this.thickness=D.uniforms.thickness.value,this.tempColor=new t,this._selects=b,this.selective=Array.isArray(this._selects),Object.defineProperty(this,"selects",{get(){return this._selects},set(e){this._selects!==e&&(this._selects=e,Array.isArray(e)?(this.selective=!0,this.ssrMaterial.defines.SELECTIVE=!0,this.ssrMaterial.needsUpdate=!0):(this.selective=!1,this.ssrMaterial.defines.SELECTIVE=!1,this.ssrMaterial.needsUpdate=!0))}}),this._bouncing=R,Object.defineProperty(this,"bouncing",{get(){return this._bouncing},set(e){this._bouncing!==e&&(this._bouncing=e,this.ssrMaterial.uniforms.tDiffuse.value=e?this.prevRenderTarget.texture:this.beautyRenderTarget.texture)}}),this.blur=!0,this._distanceAttenuation=D.defines.DISTANCE_ATTENUATION,Object.defineProperty(this,"distanceAttenuation",{get(){return this._distanceAttenuation},set(e){this._distanceAttenuation!==e&&(this._distanceAttenuation=e,this.ssrMaterial.defines.DISTANCE_ATTENUATION=e,this.ssrMaterial.needsUpdate=!0)}}),this._fresnel=D.defines.FRESNEL,Object.defineProperty(this,"fresnel",{get(){return this._fresnel},set(e){this._fresnel!==e&&(this._fresnel=e,this.ssrMaterial.defines.FRESNEL=e,this.ssrMaterial.needsUpdate=!0)}}),this._infiniteThick=D.defines.INFINITE_THICK,Object.defineProperty(this,"infiniteThick",{get(){return this._infiniteThick},set(e){this._infiniteThick!==e&&(this._infiniteThick=e,this.ssrMaterial.defines.INFINITE_THICK=e,this.ssrMaterial.needsUpdate=!0)}});const S=new r;S.type=g,S.minFilter=o,S.magFilter=o,this.beautyRenderTarget=new M(this.width,this.height,{minFilter:o,magFilter:o,type:s,depthTexture:S,depthBuffer:!0}),this.prevRenderTarget=new M(this.width,this.height,{minFilter:o,magFilter:o}),this.normalRenderTarget=new M(this.width,this.height,{minFilter:o,magFilter:o,type:s}),this.metalnessRenderTarget=new M(this.width,this.height,{minFilter:o,magFilter:o,type:s}),this.ssrRenderTarget=new M(this.width,this.height,{minFilter:o,magFilter:o}),this.blurRenderTarget=this.ssrRenderTarget.clone(),this.blurRenderTarget2=this.ssrRenderTarget.clone(),this.ssrMaterial=new m({defines:Object.assign({},D.defines,{MAX_STEP:Math.sqrt(this.width*this.width+this.height*this.height)}),uniforms:p.clone(D.uniforms),vertexShader:D.vertexShader,fragmentShader:D.fragmentShader,blending:u}),this.ssrMaterial.uniforms.tDiffuse.value=this.beautyRenderTarget.texture,this.ssrMaterial.uniforms.tNormal.value=this.normalRenderTarget.texture,this.ssrMaterial.defines.SELECTIVE=this.selective,this.ssrMaterial.needsUpdate=!0,this.ssrMaterial.uniforms.tMetalness.value=this.metalnessRenderTarget.texture,this.ssrMaterial.uniforms.tDepth.value=this.beautyRenderTarget.depthTexture,this.ssrMaterial.uniforms.cameraNear.value=this.camera.near,this.ssrMaterial.uniforms.cameraFar.value=this.camera.far,this.ssrMaterial.uniforms.thickness.value=this.thickness,this.ssrMaterial.uniforms.resolution.value.set(this.width,this.height),this.ssrMaterial.uniforms.cameraProjectionMatrix.value.copy(this.camera.projectionMatrix),this.ssrMaterial.uniforms.cameraInverseProjectionMatrix.value.copy(this.camera.projectionMatrixInverse),this.normalMaterial=new l,this.normalMaterial.blending=u,this.metalnessOnMaterial=new a({color:"white"}),this.metalnessOffMaterial=new a({color:"black"}),this.blurMaterial=new m({defines:Object.assign({},P.defines),uniforms:p.clone(P.uniforms),vertexShader:P.vertexShader,fragmentShader:P.fragmentShader}),this.blurMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.blurMaterial.uniforms.resolution.value.set(this.width,this.height),this.blurMaterial2=new m({defines:Object.assign({},P.defines),uniforms:p.clone(P.uniforms),vertexShader:P.vertexShader,fragmentShader:P.fragmentShader}),this.blurMaterial2.uniforms.tDiffuse.value=this.blurRenderTarget.texture,this.blurMaterial2.uniforms.resolution.value.set(this.width,this.height),this.depthRenderMaterial=new m({defines:Object.assign({},A.defines),uniforms:p.clone(A.uniforms),vertexShader:A.vertexShader,fragmentShader:A.fragmentShader,blending:u}),this.depthRenderMaterial.uniforms.tDepth.value=this.beautyRenderTarget.depthTexture,this.depthRenderMaterial.uniforms.cameraNear.value=this.camera.near,this.depthRenderMaterial.uniforms.cameraFar.value=this.camera.far,this.copyMaterial=new m({uniforms:p.clone(y.uniforms),vertexShader:y.vertexShader,fragmentShader:y.fragmentShader,transparent:!0,depthTest:!1,depthWrite:!1,blendSrc:f,blendDst:c,blendEquation:e,blendSrcAlpha:f,blendDstAlpha:c,blendEquationAlpha:e}),this.fsQuad=new C(null),this.originalClearColor=new t}dispose(){this.beautyRenderTarget.dispose(),this.prevRenderTarget.dispose(),this.normalRenderTarget.dispose(),this.metalnessRenderTarget.dispose(),this.ssrRenderTarget.dispose(),this.blurRenderTarget.dispose(),this.blurRenderTarget2.dispose(),this.normalMaterial.dispose(),this.metalnessOnMaterial.dispose(),this.metalnessOffMaterial.dispose(),this.blurMaterial.dispose(),this.blurMaterial2.dispose(),this.copyMaterial.dispose(),this.depthRenderMaterial.dispose(),this.fsQuad.dispose()}render(e,t){const r=this.scene.matrixWorldAutoUpdate;switch(this.scene.matrixWorldAutoUpdate=!1,e.setRenderTarget(this.beautyRenderTarget),e.clear(),this.groundReflector&&(this.groundReflector.visible=!1,this.groundReflector.doRender(this.renderer,this.scene,this.camera),this.groundReflector.visible=!0),e.render(this.scene,this.camera),this.groundReflector&&(this.groundReflector.visible=!1),this._renderOverride(e,this.normalMaterial,this.normalRenderTarget,0,0),this.selective&&this._renderMetalness(e,this.metalnessOnMaterial,this.metalnessRenderTarget,0,0),this.ssrMaterial.uniforms.opacity.value=this.opacity,this.ssrMaterial.uniforms.maxDistance.value=this.maxDistance,this.ssrMaterial.uniforms.thickness.value=this.thickness,this._renderPass(e,this.ssrMaterial,this.ssrRenderTarget),this.blur&&(this._renderPass(e,this.blurMaterial,this.blurRenderTarget),this._renderPass(e,this.blurMaterial2,this.blurRenderTarget2)),this.output){case U.OUTPUT.Default:this.bouncing?(this.copyMaterial.uniforms.tDiffuse.value=this.beautyRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.prevRenderTarget),this.blur?this.copyMaterial.uniforms.tDiffuse.value=this.blurRenderTarget2.texture:this.copyMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.copyMaterial.blending=d,this._renderPass(e,this.copyMaterial,this.prevRenderTarget),this.copyMaterial.uniforms.tDiffuse.value=this.prevRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t)):(this.copyMaterial.uniforms.tDiffuse.value=this.beautyRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t),this.blur?this.copyMaterial.uniforms.tDiffuse.value=this.blurRenderTarget2.texture:this.copyMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.copyMaterial.blending=d,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t));break;case U.OUTPUT.SSR:this.blur?this.copyMaterial.uniforms.tDiffuse.value=this.blurRenderTarget2.texture:this.copyMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t),this.bouncing&&(this.blur?this.copyMaterial.uniforms.tDiffuse.value=this.blurRenderTarget2.texture:this.copyMaterial.uniforms.tDiffuse.value=this.beautyRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.prevRenderTarget),this.copyMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.copyMaterial.blending=d,this._renderPass(e,this.copyMaterial,this.prevRenderTarget));break;case U.OUTPUT.Beauty:this.copyMaterial.uniforms.tDiffuse.value=this.beautyRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t);break;case U.OUTPUT.Depth:this._renderPass(e,this.depthRenderMaterial,this.renderToScreen?null:t);break;case U.OUTPUT.Normal:this.copyMaterial.uniforms.tDiffuse.value=this.normalRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t);break;case U.OUTPUT.Metalness:this.copyMaterial.uniforms.tDiffuse.value=this.metalnessRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t);break;default:console.warn("THREE.SSRPass: Unknown output type.")}this.scene.matrixWorldAutoUpdate=r}setSize(e,t){this.width=e,this.height=t,this.ssrMaterial.defines.MAX_STEP=Math.sqrt(e*e+t*t),this.ssrMaterial.needsUpdate=!0,this.beautyRenderTarget.setSize(e,t),this.prevRenderTarget.setSize(e,t),this.ssrRenderTarget.setSize(e,t),this.normalRenderTarget.setSize(e,t),this.metalnessRenderTarget.setSize(e,t),this.blurRenderTarget.setSize(e,t),this.blurRenderTarget2.setSize(e,t),this.ssrMaterial.uniforms.resolution.value.set(e,t),this.ssrMaterial.uniforms.cameraProjectionMatrix.value.copy(this.camera.projectionMatrix),this.ssrMaterial.uniforms.cameraInverseProjectionMatrix.value.copy(this.camera.projectionMatrixInverse),this.blurMaterial.uniforms.resolution.value.set(e,t),this.blurMaterial2.uniforms.resolution.value.set(e,t)}_renderPass(e,t,r,s,i){this.originalClearColor.copy(e.getClearColor(this.tempColor));const a=e.getClearAlpha(this.tempColor),n=e.autoClear;e.setRenderTarget(r),e.autoClear=!1,null!=s&&(e.setClearColor(s),e.setClearAlpha(i||0),e.clear()),this.fsQuad.material=t,this.fsQuad.render(e),e.autoClear=n,e.setClearColor(this.originalClearColor),e.setClearAlpha(a)}_renderOverride(e,t,r,s,a){this.originalClearColor.copy(e.getClearColor(this.tempColor));const n=e.getClearAlpha(this.tempColor),o=e.autoClear;e.setRenderTarget(r),e.autoClear=!1,s=t.clearColor||s,a=t.clearAlpha||a,null!=s&&(e.setClearColor(s),e.setClearAlpha(a||0),e.clear()),x(this.scene,e=>{if(e.isTransformControlsGizmo)return!1;if(e instanceof i)if(e._SSRPassBackupMaterial=e.material,e.material instanceof h&&this._selects.includes(e)){let t=k.get(e.material);t||(t=new l({normalMap:e.material.normalMap,normalScale:e.material.normalScale}),k.set(e.material,t)),e.material=t}else e.material=t}),e.render(this.scene,this.camera),this.scene.traverseVisible(e=>{e._SSRPassBackupMaterial&&(e.material=e._SSRPassBackupMaterial)}),e.autoClear=o,e.setClearColor(this.originalClearColor),e.setClearAlpha(n)}_renderMetalness(e,t,r,s,i){this.originalClearColor.copy(e.getClearColor(this.tempColor));const l=e.getClearAlpha(this.tempColor),o=e.autoClear,u=this.scene.background,d=this.scene.fog;e.setRenderTarget(r),e.autoClear=!1,this.scene.background=null,this.scene.fog=null,s=t.clearColor||s,i=t.clearAlpha||i,null!=s&&(e.setClearColor(s),e.setClearAlpha(i||0),e.clear()),this.scene.traverseVisible(e=>{if(e._SSRPassBackupMaterial=e.material,this._selects.includes(e))if((e.material instanceof h||e.material instanceof n)&&null!=e.material.alphaMap){let t=O.get(e.material);t||(t=new a({color:"white",alphaMap:e.material.alphaMap,alphaTest:.5}),O.set(e.material,t)),e.material=t}else if(e.material instanceof T){let t=O.get(e.material);if(!t){const r=e.material,s=r.outputRoughness??b(0),i=r.outputColor.a.multiply(_(s));t=new T({color:R("white").rgba(i),transparent:!0,fog:!1,outputEncoding:!1}),t.lights=!1,O.set(e.material,t)}e.material=t,null!=t.uniforms[w]&&(t.uniforms[w].value=this.elapsedTime)}else e.material=this.metalnessOnMaterial;else e.material=this.metalnessOffMaterial}),e.render(this.scene,this.camera),this.scene.traverseVisible(e=>{e.material=e._SSRPassBackupMaterial}),e.autoClear=o,e.setClearColor(this.originalClearColor),e.setClearAlpha(l),this.scene.background=u,this.scene.fog=d}}U.OUTPUT={Default:0,SSR:1,Beauty:3,Depth:4,Normal:5,Metalness:7};export{U as SSRPass};/*
|
|
1
|
+
import{AddEquation as e,Color as t,DepthTexture as s,HalfFloatType as r,Mesh as i,MeshBasicMaterial as a,MeshLambertMaterial as l,MeshNormalMaterial as n,MeshStandardMaterial as h,NearestFilter as o,NoBlending as u,NormalBlending as d,OneMinusSrcAlphaFactor as c,ShaderMaterial as m,SrcAlphaFactor as f,UniformsUtils as p,UnsignedShortType as g,WebGLRenderTarget as M}from"three";import{NodeShaderMaterial as T,float as b,rgb as R,vec3 as v}from"three-shader-graph";import{CopyShader as y,FullScreenQuad as C,Pass as S}from"three/examples/jsm/Addons.js";import{oneMinus as x}from"../../shader-nodes/math.js";import{traverseVisibleStop as _}from"../../utils/three/traverse.js";import{elapsedTimeUniformName as w}from"../../shader-nodes/time.js";import{SSRBlurShader as D,SSRDepthShader as P,SSRShader as A}from"./SSRShader.js";const k=new WeakMap,O=new WeakMap;class U extends S{constructor({renderer:i,scene:l,camera:h,width:d=512,height:T=512,selects:b=null,bouncing:R=!1,groundReflector:v=null,normalTexture:S=null,depthTexture:x=null}){super(),this.elapsedTime=0,this.width=d,this.height=T,this.clear=!0,this.renderer=i,this.scene=l,this.camera=h,this.groundReflector=v,this.opacity=A.uniforms.opacity.value,this.output=0,this.maxDistance=A.uniforms.maxDistance.value,this.thickness=A.uniforms.thickness.value,this.tempColor=new t,this._selects=b,this.selective=Array.isArray(this._selects),this.renderNormals=null==S,this.resolutionDownscale=4,Object.defineProperty(this,"selects",{get(){return this._selects},set(e){this._selects!==e&&(this._selects=e,Array.isArray(e)?(this.selective=!0,this.ssrMaterial.defines.SELECTIVE=!0,this.ssrMaterial.needsUpdate=!0):(this.selective=!1,this.ssrMaterial.defines.SELECTIVE=!1,this.ssrMaterial.needsUpdate=!0))}}),this._bouncing=R,Object.defineProperty(this,"bouncing",{get(){return this._bouncing},set(e){this._bouncing!==e&&(this._bouncing=e,this.ssrMaterial.uniforms.tDiffuse.value=e?this.prevRenderTarget.texture:this.beautyRenderTarget.texture)}}),this.blur=!0,this._distanceAttenuation=A.defines.DISTANCE_ATTENUATION,Object.defineProperty(this,"distanceAttenuation",{get(){return this._distanceAttenuation},set(e){this._distanceAttenuation!==e&&(this._distanceAttenuation=e,this.ssrMaterial.defines.DISTANCE_ATTENUATION=e,this.ssrMaterial.needsUpdate=!0)}}),this._fresnel=A.defines.FRESNEL,Object.defineProperty(this,"fresnel",{get(){return this._fresnel},set(e){this._fresnel!==e&&(this._fresnel=e,this.ssrMaterial.defines.FRESNEL=e,this.ssrMaterial.needsUpdate=!0)}}),this._infiniteThick=A.defines.INFINITE_THICK,Object.defineProperty(this,"infiniteThick",{get(){return this._infiniteThick},set(e){this._infiniteThick!==e&&(this._infiniteThick=e,this.ssrMaterial.defines.INFINITE_THICK=e,this.ssrMaterial.needsUpdate=!0)}});const _=null==x;null==x&&((x=new s).type=g,x.minFilter=o,x.magFilter=o),this.beautyRenderTarget=new M(this.width,this.height,{minFilter:o,magFilter:o,type:r,depthTexture:_?x:void 0,depthBuffer:!0}),this.prevRenderTarget=new M(this.width,this.height,{minFilter:o,magFilter:o}),this.renderNormals&&(this.normalRenderTarget=new M(this.width,this.height,{minFilter:o,magFilter:o,type:r}),this.metalnessRenderTarget=new M(this.width,this.height,{minFilter:o,magFilter:o,type:r})),this.ssrRenderTarget=new M(this.width/this.resolutionDownscale,this.height/this.resolutionDownscale,{minFilter:o,magFilter:o}),this.blurRenderTarget=this.ssrRenderTarget.clone(),this.blurRenderTarget2=this.ssrRenderTarget.clone(),this.ssrMaterial=new m({defines:Object.assign({},A.defines,{MAX_STEP:Math.sqrt(this.width*this.width+this.height*this.height)}),uniforms:p.clone(A.uniforms),vertexShader:A.vertexShader,fragmentShader:A.fragmentShader,blending:u}),this.ssrMaterial.uniforms.tNormal.value=this.renderNormals?this.normalRenderTarget.texture:S,this.ssrMaterial.defines.SELECTIVE=this.selective,this.ssrMaterial.needsUpdate=!0,this.renderNormals&&(this.ssrMaterial.uniforms.tMetalness.value=this.metalnessRenderTarget.texture),this.ssrMaterial.uniforms.tDepth.value=null!=x?x:this.beautyRenderTarget.depthTexture,this.ssrMaterial.uniforms.cameraNear.value=this.camera.near,this.ssrMaterial.uniforms.cameraFar.value=this.camera.far,this.ssrMaterial.uniforms.thickness.value=this.thickness,this.ssrMaterial.uniforms.resolution.value.set(this.width/this.resolutionDownscale,this.height/this.resolutionDownscale),this.ssrMaterial.uniforms.cameraProjectionMatrix.value.copy(this.camera.projectionMatrix),this.ssrMaterial.uniforms.cameraInverseProjectionMatrix.value.copy(this.camera.projectionMatrixInverse),this.normalMaterial=new n,this.normalMaterial.blending=u,this.metalnessOnMaterial=new a({color:"white"}),this.metalnessOffMaterial=new a({color:"black"}),this.blurMaterial=new m({defines:Object.assign({},D.defines),uniforms:p.clone(D.uniforms),vertexShader:D.vertexShader,fragmentShader:D.fragmentShader}),this.blurMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.blurMaterial.uniforms.resolution.value.set(this.width,this.height),this.blurMaterial2=new m({defines:Object.assign({},D.defines),uniforms:p.clone(D.uniforms),vertexShader:D.vertexShader,fragmentShader:D.fragmentShader}),this.blurMaterial2.uniforms.tDiffuse.value=this.blurRenderTarget.texture,this.blurMaterial2.uniforms.resolution.value.set(this.width,this.height),_&&(this.depthRenderMaterial=new m({defines:Object.assign({},P.defines),uniforms:p.clone(P.uniforms),vertexShader:P.vertexShader,fragmentShader:P.fragmentShader,blending:u}),this.depthRenderMaterial.uniforms.tDepth.value=this.beautyRenderTarget.depthTexture,this.depthRenderMaterial.uniforms.cameraNear.value=this.camera.near,this.depthRenderMaterial.uniforms.cameraFar.value=this.camera.far),this.copyMaterial=new m({uniforms:p.clone(y.uniforms),vertexShader:y.vertexShader,fragmentShader:y.fragmentShader,transparent:!0,depthTest:!1,depthWrite:!1,blendSrc:f,blendDst:c,blendEquation:e,blendSrcAlpha:f,blendDstAlpha:c,blendEquationAlpha:e}),this.fsQuad=new C(null),this.originalClearColor=new t,this.needsSwap=!1}dispose(){this.beautyRenderTarget&&this.beautyRenderTarget.dispose(),this.prevRenderTarget.dispose(),this.normalRenderTarget&&this.normalRenderTarget.dispose(),this.metalnessRenderTarget&&this.metalnessRenderTarget.dispose(),this.ssrRenderTarget.dispose(),this.blurRenderTarget.dispose(),this.blurRenderTarget2.dispose(),this.normalMaterial.dispose(),this.metalnessOnMaterial.dispose(),this.metalnessOffMaterial.dispose(),this.blurMaterial.dispose(),this.blurMaterial2.dispose(),this.copyMaterial.dispose(),this.depthRenderMaterial&&this.depthRenderMaterial.dispose(),this.fsQuad.dispose()}render(e,t,s){const r=this.scene.matrixWorldAutoUpdate;switch(this.scene.matrixWorldAutoUpdate=!1,this.ssrMaterial.uniforms.tDiffuse.value=s.texture,this.groundReflector&&(this.groundReflector.visible=!1,this.groundReflector.visible=!0),this.groundReflector&&(this.groundReflector.visible=!1),this.renderNormals&&this._renderOverride(e,this.normalMaterial,this.normalRenderTarget,0,0),this.selective&&this.renderNormals&&this._renderMetalness(e,this.metalnessOnMaterial,this.metalnessRenderTarget,0,0),this.ssrMaterial.uniforms.opacity.value=this.opacity,this.ssrMaterial.uniforms.maxDistance.value=this.maxDistance,this.ssrMaterial.uniforms.thickness.value=this.thickness,this._renderPass(e,this.ssrMaterial,this.ssrRenderTarget),this.blur&&(this._renderPass(e,this.blurMaterial,this.blurRenderTarget),this._renderPass(e,this.blurMaterial2,this.blurRenderTarget2)),this.output){case U.OUTPUT.Default:this.bouncing?(this.copyMaterial.uniforms.tDiffuse.value=s.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.prevRenderTarget),this.blur?this.copyMaterial.uniforms.tDiffuse.value=this.blurRenderTarget2.texture:this.copyMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.copyMaterial.blending=d,this._renderPass(e,this.copyMaterial,this.prevRenderTarget),this.copyMaterial.uniforms.tDiffuse.value=this.prevRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t)):(this.blur?this.copyMaterial.uniforms.tDiffuse.value=this.blurRenderTarget2.texture:this.copyMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.copyMaterial.blending=d,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:s));break;case U.OUTPUT.SSR:this.blur?this.copyMaterial.uniforms.tDiffuse.value=this.blurRenderTarget2.texture:this.copyMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t),this.bouncing&&(this.blur?this.copyMaterial.uniforms.tDiffuse.value=this.blurRenderTarget2.texture:this.copyMaterial.uniforms.tDiffuse.value=this.beautyRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.prevRenderTarget),this.copyMaterial.uniforms.tDiffuse.value=this.ssrRenderTarget.texture,this.copyMaterial.blending=d,this._renderPass(e,this.copyMaterial,this.prevRenderTarget));break;case U.OUTPUT.Beauty:this.copyMaterial.uniforms.tDiffuse.value=this.beautyRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t);break;case U.OUTPUT.Depth:this._renderPass(e,this.depthRenderMaterial,this.renderToScreen?null:t);break;case U.OUTPUT.Normal:this.copyMaterial.uniforms.tDiffuse.value=this.normalRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t);break;case U.OUTPUT.Metalness:this.copyMaterial.uniforms.tDiffuse.value=this.metalnessRenderTarget.texture,this.copyMaterial.blending=u,this._renderPass(e,this.copyMaterial,this.renderToScreen?null:t);break;default:console.warn("THREE.SSRPass: Unknown output type.")}this.scene.matrixWorldAutoUpdate=r}setSize(e,t){this.width=e,this.height=t,this.ssrMaterial.defines.MAX_STEP=Math.sqrt(e*e+t*t),this.ssrMaterial.needsUpdate=!0,this.beautyRenderTarget.setSize(e,t),this.prevRenderTarget.setSize(e,t),this.ssrRenderTarget.setSize(e/this.resolutionDownscale,t/this.resolutionDownscale),null!=this.normalRenderTarget&&this.normalRenderTarget.setSize(e,t),null!=this.metalnessRenderTarget&&this.metalnessRenderTarget.setSize(e,t),this.blurRenderTarget.setSize(e,t),this.blurRenderTarget2.setSize(e,t),this.ssrMaterial.uniforms.resolution.value.set(e/this.resolutionDownscale,t/this.resolutionDownscale),this.ssrMaterial.uniforms.cameraProjectionMatrix.value.copy(this.camera.projectionMatrix),this.ssrMaterial.uniforms.cameraInverseProjectionMatrix.value.copy(this.camera.projectionMatrixInverse),this.blurMaterial.uniforms.resolution.value.set(e,t),this.blurMaterial2.uniforms.resolution.value.set(e,t)}_renderPass(e,t,s,r,i){this.originalClearColor.copy(e.getClearColor(this.tempColor));const a=e.getClearAlpha(this.tempColor),l=e.autoClear;e.setRenderTarget(s),e.autoClear=!1,null!=r&&(e.setClearColor(r),e.setClearAlpha(i||0),e.clear()),this.fsQuad.material=t,this.fsQuad.render(e),e.autoClear=l,e.setClearColor(this.originalClearColor),e.setClearAlpha(a)}_renderOverride(e,t,s,r,a){this.originalClearColor.copy(e.getClearColor(this.tempColor));const l=e.getClearAlpha(this.tempColor),o=e.autoClear;e.setRenderTarget(s),e.autoClear=!1,r=t.clearColor||r,a=t.clearAlpha||a,null!=r&&(e.setClearColor(r),e.setClearAlpha(a||0),e.clear()),_(this.scene,e=>{if(e.isTransformControlsGizmo)return!1;if(e instanceof i)if(e._SSRPassBackupMaterial=e.material,e.material instanceof h&&this._selects.includes(e)){let t=k.get(e.material);t||(t=new n({normalMap:e.material.normalMap,normalScale:e.material.normalScale}),k.set(e.material,t)),e.material=t}else e.material=t}),e.render(this.scene,this.camera),this.scene.traverseVisible(e=>{e._SSRPassBackupMaterial&&(e.material=e._SSRPassBackupMaterial)}),e.autoClear=o,e.setClearColor(this.originalClearColor),e.setClearAlpha(l)}_renderMetalness(e,t,s,r,i){this.originalClearColor.copy(e.getClearColor(this.tempColor));const n=e.getClearAlpha(this.tempColor),o=e.autoClear,u=this.scene.background,d=this.scene.fog;e.setRenderTarget(s),e.autoClear=!1,this.scene.background=null,this.scene.fog=null,r=t.clearColor||r,i=t.clearAlpha||i,null!=r&&(e.setClearColor(r),e.setClearAlpha(i||0),e.clear()),this.scene.traverseVisible(e=>{if(e._SSRPassBackupMaterial=e.material,this._selects.includes(e))if((e.material instanceof h||e.material instanceof l)&&null!=e.material.alphaMap){let t=O.get(e.material);t||(t=new a({color:"white",alphaMap:e.material.alphaMap,alphaTest:.5}),O.set(e.material,t)),e.material=t}else if(e.material instanceof T){let t=O.get(e.material);if(!t){const s=e.material,r=s.outputRoughness??b(0),i=s.outputColor.a.multiply(x(r));t=new T({color:R("white").rgba(i),transparent:!0,fog:!1,outputEncoding:!1}),t.lights=!1,O.set(e.material,t)}e.material=t,null!=t.uniforms[w]&&(t.uniforms[w].value=this.elapsedTime)}else e.material=this.metalnessOnMaterial;else e.material=this.metalnessOffMaterial}),e.render(this.scene,this.camera),this.scene.traverseVisible(e=>{e.material=e._SSRPassBackupMaterial}),e.autoClear=o,e.setClearColor(this.originalClearColor),e.setClearAlpha(n),this.scene.background=u,this.scene.fog=d}}U.OUTPUT={Default:0,SSR:1,Beauty:3,Depth:4,Normal:5,Metalness:7};export{U as SSRPass};/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SSRShader.d.ts","sourceRoot":"","sources":["../../../src/rendering/ssr/SSRShader.js"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,
|
|
1
|
+
{"version":3,"file":"SSRShader.d.ts","sourceRoot":"","sources":["../../../src/rendering/ssr/SSRShader.js"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,4BAsOE;AAEF;;;;;GAKG;AACH,iCAmEE;AAEF;;;;;GAKG;AACH,gCA+DE"}
|