@hology/core 0.0.214 → 0.0.215
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/config/project-config.d.ts +1 -0
- package/dist/effects/sequence/sequence-action.d.ts +4 -0
- package/dist/effects/sequence/sequence-actor.js +1 -1
- package/dist/effects/sequence/sequence-animation-retiming.d.ts +2 -1
- package/dist/effects/sequence/sequence-animation-retiming.js +1 -1
- package/dist/effects/sequence/sequence-data.d.ts +6 -0
- package/dist/effects/sequence/sequence-data.js +1 -1
- package/dist/effects/sequence/sequence-player.d.ts +11 -0
- package/dist/effects/sequence/sequence-player.js +1 -1
- package/dist/effects/vfx/vfx-collision-behaviour.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-animation.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-movement-like.d.ts +3 -0
- package/dist/gameplay/actors/builtin/components/character/character-movement.d.ts +22 -0
- package/dist/gameplay/actors/builtin/components/character/character-movement.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-slide.d.ts +7 -0
- package/dist/gameplay/actors/builtin/components/character/character-slide.js +4 -0
- package/dist/gameplay/actors/builtin/components/character/modes.d.ts +2 -1
- package/dist/gameplay/actors/builtin/components/character/modes.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/net-character-movement-protocol.d.ts +3 -1
- package/dist/gameplay/actors/builtin/components/character/net-character-movement-protocol.js +1 -1
- package/dist/gameplay/actors/builtin/navmesh-actor.js +1 -1
- package/dist/gameplay/actors/camera/third-person-camera-component.d.ts +1 -0
- package/dist/gameplay/actors/camera/third-person-camera-component.js +1 -1
- package/dist/gameplay/ai/behavior-tree/move.js +1 -1
- package/dist/gameplay/ai/dynamic-tiled-navmesh.d.ts +20 -2
- package/dist/gameplay/ai/dynamic-tiled-navmesh.js +1 -1
- package/dist/gameplay/animation/animation-action.d.ts +3 -0
- package/dist/gameplay/animation/animation-action.js +4 -0
- package/dist/gameplay/services/physics/physics-system.d.ts +56 -3
- package/dist/gameplay/services/physics/physics-system.js +1 -1
- package/dist/scene/asset-resource-loader.d.ts +2 -0
- package/dist/scene/asset-resource-loader.js +1 -1
- package/dist/scene/collision/collision-shape.d.ts +1 -1
- package/dist/scene/materializer.js +1 -1
- package/dist/scene/storage/storage.js +1 -1
- package/dist/shader/builtin/standard-shader.js +1 -1
- package/dist/shader/builtin/unlit-shader.js +1 -1
- package/dist/shader/decal-shader.d.ts +2 -2
- package/dist/shader/decal-shader.js +1 -1
- package/dist/shader/shader.d.ts +2 -1
- package/dist/shader/shader.js +1 -1
- package/dist/shader/sprite-shader.d.ts +2 -2
- package/dist/shader/sprite-shader.js +1 -1
- package/dist/shader/trail-shader.d.ts +2 -2
- package/dist/shader/trail-shader.js +1 -1
- package/dist/test/asset-resource-loader-texture-array.test.d.ts +2 -0
- package/dist/test/asset-resource-loader-texture-array.test.js +4 -0
- package/dist/test/character-animation-transition.test.d.ts +2 -0
- package/dist/test/character-animation-transition.test.js +4 -0
- package/dist/test/character-slide.test.d.ts +2 -0
- package/dist/test/character-slide.test.js +4 -0
- package/dist/test/navmesh-worker-pool.test.d.ts +2 -0
- package/dist/test/navmesh-worker-pool.test.js +4 -0
- package/dist/test/net-character-movement.test.js +1 -1
- package/dist/test/sequence-animation-retiming.test.js +1 -1
- package/dist/test/sequence-root-motion-axis-mask.test.d.ts +2 -0
- package/dist/test/sequence-root-motion-axis-mask.test.js +4 -0
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as e,__metadata as a}from"tslib";import{Color as t,MeshStandardMaterial as n,Texture as r,Vector2 as i}from"three";import{Shader as s}from"../shader.js";import{Parameter as o}from"../parameter.js";import*as p from"three";import{attributes as l,AttributeVec3Node as d,colorToNormal as h,ifDefApply as m,NodeShaderMaterial as u,normalize as v,Sampler2DNode as c,standardMaterial as y,UniformSampler2d as S,uniformFloat as g,uniformVec2 as f,uniformVec3 as M,varying as x,varyingAttributes as C,varyingTransformed as b,vec2 as w,UniformVec3Node as O,UniformFloatNode as R}from"three-shader-graph";import{parallaxOcclusionMapping as L}from"../../shader-nodes/pom.js";import{createPlaceholderTexture as T}from"../../utils/three/placeholder-texture.js";const N=T(),B=new i(1,1);export class StandardShader extends s{constructor(){super(...arguments),this.color=new t("#FFFFFF"),this.map=new S("map",N),this.opacity=1,this.alphaMap=new S("alphaMap",N),this.roughness=1,this.roughnessMap=new S("roughnessMap",N),this.metalness=0,this.metalnessMap=new S("metalnessMap",N),this.lightMap=new S("lightMap",N),this.aoMap=new S("aoMap",N),this.emissiveMap=new S("emissiveMap",N),this.normalMap=new S("normalMap",N),this.normalScale=new i(1,1),this.sheen=0,this.sheenColor=new t("#FFFFFF"),this.sheenColorMap=new S("sheenColorMap",N),this.sheenRoughness=.5,this.sheenRoughnessMap=new S("sheenRoughnessMap",N),this.anisotropyMap=new S("anisotropyMap",N),this.anisotropy=0,this.heightMap=new S("heightMap",N),this.vertexColor=!1,this.uvScale=B}build(){P(this.map,p.SRGBColorSpace),P(this.alphaMap,p.LinearSRGBColorSpace),P(this.roughnessMap,p.LinearSRGBColorSpace),P(this.metalnessMap,p.LinearSRGBColorSpace),P(this.aoMap,p.LinearSRGBColorSpace),P(this.emissiveMap,p.SRGBColorSpace),P(this.normalMap,p.LinearSRGBColorSpace),P(this.sheenColorMap,p.LinearSRGBColorSpace),P(this.sheenRoughnessMap,p.LinearSRGBColorSpace),P(this.anisotropyMap,p.LinearSRGBColorSpace);let e=!1;const a=f("uvScale",this.uvScale??B);let n=C.uv.multiply(a);F(this.heightMap)&&0!==(this.heightScale??.05)&&(n=L(n,this.heightMap,g("heightScale",this.heightScale??.05)));const r=x(new d("particleData"));let s=m("IS_PARTICLE",new R("opacity",this.opacity,void 0,!1),e=>e.multiply(r.x)),o=new O("color",(new p.Vector3).setFromColor(this.color),void 0,!1).rgb;if(F(this.map)){const e=this.map.sample(n);o=o.multiply(e.rgb),s=s.multiply(e.a)}F(this.alphaMap)&&(s=s.multiply(this.alphaMap.sample(n).r)),!0===this.vertexColor&&(o=o.multiply(x(l.color.rgb)));let c=null,S=null;F(this.aoMap)&&(S=g("aoMapIntensity",this.aoMapIntensity??1),c=this.aoMap.sample(n).r);let T=g("roughness",this.roughness??1);F(this.roughnessMap)&&(T=T.multiply(this.roughnessMap.sample(n).g),e=!0);let N=g("metalness",this.metalness??0);F(this.metalnessMap)&&(N=N.multiply(this.metalnessMap.sample(n).b),e=!0);let D=null;F(this.lightMap)&&(D=this.lightMap.sample(n).rgb.multiplyScalar(g("lightMapIntensity",this.lightMapIntensity??1)));let _=M("emissive",(new p.Vector3).setFromColor(this.emissive??new t(0))).rgb;F(this.emissiveMap)&&(_=_.multiply(this.emissiveMap.sample(n).rgb));const I=g("emissiveIntensity",this.emissiveIntensity??1);let E=b.normal;if(F(this.normalMap)){const e=g("normalScale",this.normalScale?.x??1);E=h(this.normalMap.sample(n),e)}let V=null,G=null;if((this.sheen??0)>0){const e=g("sheen",this.sheen??0);V=M("sheenColor",(new p.Vector3).setFromColor(this.sheenColor??new t(16777215))).rgb.multiplyScalar(e),F(this.sheenColorMap)&&(V=V.multiply(this.sheenColorMap.sample(n).rgb)),G=g("sheenRoughness",this.sheenRoughness??.5),F(this.sheenRoughnessMap)&&(G=G.multiply(this.sheenRoughnessMap.sample(n).a))}(this.roughness<1||this.metalness>0)&&(e=!0);let H=null,A=null;if((this.anisotropy??0)>0&&(H=g("anisotropy",this.anisotropy??0),A=f("anisotropyDirection",(U=this.anisotropyRotation??0,new i(Math.cos(U),Math.sin(U)))),F(this.anisotropyMap))){const e=this.anisotropyMap.sample(n),a=v(w(e.r,e.g).multiplyScalar(2).subtract(w(1,1)));A=w(A.x.multiply(a.x).subtract(A.y.multiply(a.y)),A.y.multiply(a.x).add(A.x.multiply(a.y))),H=H.multiply(e.b)}var U;const z=new u({color:y({color:o.rgba(s),roughness:T,metalness:N,ambientOcclusion:c,ambientOcclusionIntensity:S,emissive:_,emissiveIntensity:I,normal:E,bakedLight:D,sheenColor:V,sheenRoughness:G,anisotropy:H,anisotropyDirection:A,specular:e}),opacity:s,roughness:T,normal:E,emissive:_.multiplyScalar(I),envMap:this.envMap});return null!=this.envMap&&(z.uniforms.envMapIntensity={value:this.envMapIntensity??1}),z.vertexColors=!0===this.vertexColor,z}}function F(e){return null!=e&&(!(e instanceof S)||null!=e.value&&e.value!==N)}e([o(),a("design:type",t)],StandardShader.prototype,"color",void 0),e([o({label:"Color Map"}),a("design:type",c)],StandardShader.prototype,"map",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"opacity",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"alphaMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"roughness",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"roughnessMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"metalness",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"metalnessMap",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"lightMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"lightMapIntensity",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"aoMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"aoMapIntensity",void 0),e([o(),a("design:type",t)],StandardShader.prototype,"emissive",void 0),e([o({range:[0,10]}),a("design:type",Number)],StandardShader.prototype,"emissiveIntensity",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"emissiveMap",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"normalMap",void 0),e([o(),a("design:type",i)],StandardShader.prototype,"normalScale",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"sheen",void 0),e([o(),a("design:type",t)],StandardShader.prototype,"sheenColor",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"sheenColorMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"sheenRoughness",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"sheenRoughnessMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"anisotropyRotation",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"anisotropyMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"anisotropy",void 0),e([o(),a("design:type",r)],StandardShader.prototype,"envMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"envMapIntensity",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"heightMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"heightScale",void 0),e([o(),a("design:type",Boolean)],StandardShader.prototype,"vertexColor",void 0),e([o(),a("design:type",i)],StandardShader.prototype,"uvScale",void 0);export var ParallaxType;!function(e){e[e.none=0]="none",e[e.offset=1]="offset",e[e.pom=2]="pom"}(ParallaxType||(ParallaxType={}));export class ParallaxStandardMaterial extends n{constructor(e={}){super(e),e.heightMap&&(this.heightMap=e.heightMap),this.heightScale=e.heightScale??.05,this.parallaxType=e.parallaxType??ParallaxType.pom,this.minLayers=e.minLayers??10,this.maxLayers=e.maxLayers??32}onBeforeCompile(e){e.uniforms.heightMap={value:this.heightMap},e.uniforms.heightScale={value:this.heightScale},e.uniforms.minLayers={value:this.minLayers},e.uniforms.maxLayers={value:this.maxLayers},e.uniforms.parallaxType={value:this.parallaxType},e.vertexTangents=!0,e.vertexShader=e.vertexShader.replace("#include <uv_pars_vertex>","\n #include <uv_pars_vertex>\n "),e.vertexShader=e.vertexShader.replace("#include <begin_vertex>","\n #include <begin_vertex>\n "),e.fragmentShader=e.fragmentShader.replace("#include <uv_pars_fragment>","\n #include <uv_pars_fragment>\n uniform sampler2D heightMap;\n uniform float heightScale;\n uniform int minLayers;\n uniform int maxLayers;\n uniform int parallaxType;\n\n vec2 parallaxOffset(vec2 uv, vec3 viewDir, vec3 normal) {\n // Compute TBN in fragment shader using screen-space derivatives\n vec3 dp1 = dFdx(-vViewPosition);\n vec3 dp2 = dFdy(-vViewPosition);\n vec2 duv1 = dFdx(uv);\n vec2 duv2 = dFdy(uv);\n \n vec3 dp2perp = cross(dp2, normal);\n vec3 dp1perp = cross(normal, dp1);\n vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;\n vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;\n \n float invmax = inversesqrt(max(dot(T,T), dot(B,B)));\n mat3 tbn = mat3(T * invmax, B * invmax, normal);\n vec3 viewDirTS = -viewDir * tbn;\n\n float h = texture(heightMap, uv).r;\n return uv - (viewDirTS.xy / viewDirTS.z) * (h * heightScale);\n }\n\n vec2 parallaxOcclusion2(vec2 uv, vec3 viewDir, vec3 normal) {\n // Compute TBN in fragment shader using screen-space derivatives\n vec3 dp1 = dFdx(-vViewPosition);\n vec3 dp2 = dFdy(-vViewPosition);\n vec2 duv1 = dFdx(uv);\n vec2 duv2 = dFdy(uv);\n \n vec3 dp2perp = cross(dp2, normal);\n vec3 dp1perp = cross(normal, dp1);\n vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;\n vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;\n \n float invmax = inversesqrt(max(dot(T,T), dot(B,B)));\n mat3 tbn = mat3(T * invmax, B * invmax, normal);\n vec3 vv = -viewDir * tbn;\n\n float parallaxLimit = -length(vv.xy) / vv.z;\n parallaxLimit *= heightScale;\n\n vec2 vOffsetDir = normalize(vv.xy);\n vec2 vMaxOffset = vOffsetDir * parallaxLimit;\n\n float factor = pow(1.0 - abs(vv.z), 2.0);\n float nNumSamples = mix(float(minLayers), float(maxLayers), factor);\n float fStepSize = 1.0 / nNumSamples;\n\n float fCurrRayHeight = 1.0;\n vec2 vCurrOffset = vec2(0.0);\n vec2 vLastOffset = vec2(0.0);\n float fLastSampledHeight = 1.0;\n float fCurrSampledHeight = 1.0;\n\n for (int nCurrSample = 0; nCurrSample < 128; nCurrSample++) {\n if (float(nCurrSample) > nNumSamples) break;\n\n fCurrSampledHeight = texture2D(heightMap, uv + vCurrOffset).r;\n if (fCurrSampledHeight > fCurrRayHeight) {\n float delta1 = fCurrSampledHeight - fCurrRayHeight;\n float delta2 = (fCurrRayHeight + fStepSize) - fLastSampledHeight;\n float ratio = delta1 / (delta1 + delta2);\n vCurrOffset = ratio * vLastOffset + (1.0 - ratio) * vCurrOffset;\n break;\n } else {\n fCurrRayHeight -= fStepSize;\n vLastOffset = vCurrOffset;\n vCurrOffset += fStepSize * vMaxOffset;\n fLastSampledHeight = fCurrSampledHeight;\n }\n }\n\n return uv + vCurrOffset;\n }\n "),e.fragmentShader=e.fragmentShader.replace("#include <map_fragment>","\n vec3 pomViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n vec2 uvPOM = vMapUv ;\n if (parallaxType == 1) {\n uvPOM = parallaxOffset(vMapUv, pomViewDir, vNormal);\n } else if (parallaxType == 2) {\n uvPOM = parallaxOcclusion2(vMapUv, pomViewDir, vNormal);\n }\n\n vec4 texelColor = texture2D(map, uvPOM);\n diffuseColor *= texelColor;\n "),e.fragmentShader=e.fragmentShader.replace("#include <normal_fragment_maps>","\n #ifdef USE_NORMALMAP\n // RE-COMPUTE TBN for normal mapping consistency\n vec3 dp1 = dFdx(-vViewPosition);\n vec3 dp2 = dFdy(-vViewPosition);\n vec2 duv1 = dFdx(uvPOM);\n vec2 duv2 = dFdy(uvPOM);\n vec3 dp2perp = cross(dp2, vNormal);\n vec3 dp1perp = cross(vNormal, dp1);\n vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;\n vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;\n float invmax = inversesqrt(max(dot(T,T), dot(B,B)));\n mat3 localTBN = mat3(T * invmax, B * invmax, vNormal);\n\n vec3 mapN = texture2D(normalMap, uvPOM).xyz * 2.0 - 1.0;\n mapN.xy *= normalScale;\n normal = normalize( localTBN * mapN );\n #endif\n "),e.fragmentShader=e.fragmentShader.replace("#include <roughnessmap_fragment>","\n float roughnessFactor = roughness;\n #ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, uvPOM );\n // reads channel G, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\n roughnessFactor *= texelRoughness.g;\n #endif\n "),e.fragmentShader=e.fragmentShader.replace("#include <metalnesssmap_fragment>","\n float metalnessFactor = metalness;\n #ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, uvPOM );\n // reads channel B, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\n metalnessFactor *= texelMetalness.b;\n #endif\n "),e.fragmentShader=e.fragmentShader.replace("#include <aomap_fragment>","\n #ifdef USE_AOMAP\n\n // reads channel R, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\n float ambientOcclusion = ( texture2D( aoMap, uvPOM ).r - 1.0 ) * aoMapIntensity + 1.0;\n\n reflectedLight.indirectDiffuse *= ambientOcclusion;\n\n #if defined( USE_CLEARCOAT ) \n clearcoatSpecularIndirect *= ambientOcclusion;\n #endif\n\n #if defined( USE_SHEEN ) \n sheenSpecularIndirect *= ambientOcclusion;\n #endif\n\n #if defined( USE_ENVMAP ) && defined( STANDARD )\n\n float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );\n\n reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );\n\n #endif\n\n #endif\n "),this.userData.shader=e}clone(){const e=super.clone();return e.heightMap=this.heightMap,e.heightScale=this.heightScale,e.parallaxType=this.parallaxType,e.minLayers=this.minLayers,e.maxLayers=this.maxLayers,e}}export function applyTiling(e,a){if(null==e||null==a)return e;if(1===a.x&&1===a.y)return e;const t=e.clone();return t.repeat.copy(a),t.needsUpdate=!0,t}function P(e,a){null!=e&&(e instanceof r?e.colorSpace=a:e instanceof S&&null!=e.value&&(e.value.colorSpace=a))}/*
|
|
1
|
+
import{__decorate as e,__metadata as a}from"tslib";import{Color as t,MeshStandardMaterial as n,Texture as r,Vector2 as i}from"three";import{Shader as s}from"../shader.js";import{Parameter as o}from"../parameter.js";import*as p from"three";import{attributes as l,AttributeVec3Node as d,colorToNormal as h,ifDefApply as m,NodeShaderMaterial as u,normalize as v,Sampler2DNode as c,standardMaterial as y,UniformSampler2d as S,uniformFloat as g,uniformVec2 as f,uniformVec3 as M,varying as x,varyingAttributes as C,varyingTransformed as b,vec2 as w,UniformVec3Node as O,UniformFloatNode as R}from"three-shader-graph";import{parallaxOcclusionMapping as T}from"../../shader-nodes/pom.js";import{createPlaceholderTexture as L}from"../../utils/three/placeholder-texture.js";const N=L(),B=new i(1,1);export class StandardShader extends s{constructor(){super(...arguments),this.color=new t("#FFFFFF"),this.map=new S("map",N),this.opacity=1,this.alphaMap=new S("alphaMap",N),this.roughness=1,this.roughnessMap=new S("roughnessMap",N),this.metalness=0,this.metalnessMap=new S("metalnessMap",N),this.lightMap=new S("lightMap",N),this.aoMap=new S("aoMap",N),this.emissiveMap=new S("emissiveMap",N),this.normalMap=new S("normalMap",N),this.normalScale=new i(1,1),this.sheen=0,this.sheenColor=new t("#FFFFFF"),this.sheenColorMap=new S("sheenColorMap",N),this.sheenRoughness=.5,this.sheenRoughnessMap=new S("sheenRoughnessMap",N),this.anisotropyMap=new S("anisotropyMap",N),this.anisotropy=0,this.heightMap=new S("heightMap",N),this.vertexColor=!1,this.uvScale=B}build(){P(this.map,p.SRGBColorSpace),P(this.alphaMap,p.LinearSRGBColorSpace),P(this.roughnessMap,p.LinearSRGBColorSpace),P(this.metalnessMap,p.LinearSRGBColorSpace),P(this.aoMap,p.LinearSRGBColorSpace),P(this.emissiveMap,p.SRGBColorSpace),P(this.normalMap,p.LinearSRGBColorSpace),P(this.sheenColorMap,p.LinearSRGBColorSpace),P(this.sheenRoughnessMap,p.LinearSRGBColorSpace),P(this.anisotropyMap,p.LinearSRGBColorSpace);let e=!1;const a=f("uvScale",this.uvScale??B);let n=C.uv.multiply(a);F(this.heightMap)&&0!==(this.heightScale??.05)&&(n=T(n,this.heightMap,g("heightScale",this.heightScale??.05)));const r=x(new d("particleData"));let s=m("IS_PARTICLE",new R("opacity",this.opacity,void 0,!1),e=>e.multiply(r.x)),o=new O("color",(new p.Vector3).setFromColor(this.color),void 0,!1).rgb;if(F(this.map)){const e=this.map.sample(n);o=o.multiply(e.rgb),s=s.multiply(e.a)}F(this.alphaMap)&&(s=s.multiply(this.alphaMap.sample(n).r)),!0===this.vertexColor&&(o=o.multiply(x(l.color.rgb)));let c=null,S=null;F(this.aoMap)&&(S=g("aoMapIntensity",this.aoMapIntensity??1),c=this.aoMap.sample(n).r);let L=g("roughness",this.roughness??1);F(this.roughnessMap)&&(L=L.multiply(this.roughnessMap.sample(n).g),e=!0);let N=g("metalness",this.metalness??0);F(this.metalnessMap)&&(N=N.multiply(this.metalnessMap.sample(n).b),e=!0);let D=null;F(this.lightMap)&&(D=this.lightMap.sample(n).rgb.multiplyScalar(g("lightMapIntensity",this.lightMapIntensity??1)));let _=M("emissive",(new p.Vector3).setFromColor(this.emissive??new t(0))).rgb;F(this.emissiveMap)&&(_=_.multiply(this.emissiveMap.sample(n).rgb));const I=g("emissiveIntensity",this.emissiveIntensity??1);let E=b.normal;if(F(this.normalMap)){const e=g("normalScale",this.normalScale?.x??1);E=h(this.normalMap.sample(n),e)}let V=null,G=null;if((this.sheen??0)>0){const e=g("sheen",this.sheen??0);V=M("sheenColor",(new p.Vector3).setFromColor(this.sheenColor??new t(16777215))).rgb.multiplyScalar(e),F(this.sheenColorMap)&&(V=V.multiply(this.sheenColorMap.sample(n).rgb)),G=g("sheenRoughness",this.sheenRoughness??.5),F(this.sheenRoughnessMap)&&(G=G.multiply(this.sheenRoughnessMap.sample(n).a))}(this.roughness<1||this.metalness>0)&&(e=!0);let H=null,A=null;if((this.anisotropy??0)>0&&(H=g("anisotropy",this.anisotropy??0),A=f("anisotropyDirection",(U=this.anisotropyRotation??0,new i(Math.cos(U),Math.sin(U)))),F(this.anisotropyMap))){const e=this.anisotropyMap.sample(n),a=v(w(e.r,e.g).multiplyScalar(2).subtract(w(1,1)));A=w(A.x.multiply(a.x).subtract(A.y.multiply(a.y)),A.y.multiply(a.x).add(A.x.multiply(a.y))),H=H.multiply(e.b)}var U;const z=new u({color:y({color:o.rgba(s),roughness:L,metalness:N,ambientOcclusion:c,ambientOcclusionIntensity:S,emissive:_,emissiveIntensity:I,normal:E,bakedLight:D,sheenColor:V,sheenRoughness:G,anisotropy:H,anisotropyDirection:A,specular:e}),opacity:s,roughness:L,normal:E,emissive:_.multiplyScalar(I),envMap:this.envMap,alphaTest:this.alphaTest});return null!=this.envMap&&(z.uniforms.envMapIntensity={value:this.envMapIntensity??1}),z.vertexColors=!0===this.vertexColor,z}}function F(e){return null!=e&&(!(e instanceof S)||null!=e.value&&e.value!==N)}e([o(),a("design:type",t)],StandardShader.prototype,"color",void 0),e([o({label:"Color Map"}),a("design:type",c)],StandardShader.prototype,"map",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"opacity",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"alphaMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"roughness",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"roughnessMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"metalness",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"metalnessMap",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"lightMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"lightMapIntensity",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"aoMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"aoMapIntensity",void 0),e([o(),a("design:type",t)],StandardShader.prototype,"emissive",void 0),e([o({range:[0,10]}),a("design:type",Number)],StandardShader.prototype,"emissiveIntensity",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"emissiveMap",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"normalMap",void 0),e([o(),a("design:type",i)],StandardShader.prototype,"normalScale",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"sheen",void 0),e([o(),a("design:type",t)],StandardShader.prototype,"sheenColor",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"sheenColorMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"sheenRoughness",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"sheenRoughnessMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"anisotropyRotation",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"anisotropyMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"anisotropy",void 0),e([o(),a("design:type",r)],StandardShader.prototype,"envMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"envMapIntensity",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"heightMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"heightScale",void 0),e([o(),a("design:type",Boolean)],StandardShader.prototype,"vertexColor",void 0),e([o(),a("design:type",i)],StandardShader.prototype,"uvScale",void 0);export var ParallaxType;!function(e){e[e.none=0]="none",e[e.offset=1]="offset",e[e.pom=2]="pom"}(ParallaxType||(ParallaxType={}));export class ParallaxStandardMaterial extends n{constructor(e={}){super(e),e.heightMap&&(this.heightMap=e.heightMap),this.heightScale=e.heightScale??.05,this.parallaxType=e.parallaxType??ParallaxType.pom,this.minLayers=e.minLayers??10,this.maxLayers=e.maxLayers??32}onBeforeCompile(e){e.uniforms.heightMap={value:this.heightMap},e.uniforms.heightScale={value:this.heightScale},e.uniforms.minLayers={value:this.minLayers},e.uniforms.maxLayers={value:this.maxLayers},e.uniforms.parallaxType={value:this.parallaxType},e.vertexTangents=!0,e.vertexShader=e.vertexShader.replace("#include <uv_pars_vertex>","\n #include <uv_pars_vertex>\n "),e.vertexShader=e.vertexShader.replace("#include <begin_vertex>","\n #include <begin_vertex>\n "),e.fragmentShader=e.fragmentShader.replace("#include <uv_pars_fragment>","\n #include <uv_pars_fragment>\n uniform sampler2D heightMap;\n uniform float heightScale;\n uniform int minLayers;\n uniform int maxLayers;\n uniform int parallaxType;\n\n vec2 parallaxOffset(vec2 uv, vec3 viewDir, vec3 normal) {\n // Compute TBN in fragment shader using screen-space derivatives\n vec3 dp1 = dFdx(-vViewPosition);\n vec3 dp2 = dFdy(-vViewPosition);\n vec2 duv1 = dFdx(uv);\n vec2 duv2 = dFdy(uv);\n \n vec3 dp2perp = cross(dp2, normal);\n vec3 dp1perp = cross(normal, dp1);\n vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;\n vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;\n \n float invmax = inversesqrt(max(dot(T,T), dot(B,B)));\n mat3 tbn = mat3(T * invmax, B * invmax, normal);\n vec3 viewDirTS = -viewDir * tbn;\n\n float h = texture(heightMap, uv).r;\n return uv - (viewDirTS.xy / viewDirTS.z) * (h * heightScale);\n }\n\n vec2 parallaxOcclusion2(vec2 uv, vec3 viewDir, vec3 normal) {\n // Compute TBN in fragment shader using screen-space derivatives\n vec3 dp1 = dFdx(-vViewPosition);\n vec3 dp2 = dFdy(-vViewPosition);\n vec2 duv1 = dFdx(uv);\n vec2 duv2 = dFdy(uv);\n \n vec3 dp2perp = cross(dp2, normal);\n vec3 dp1perp = cross(normal, dp1);\n vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;\n vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;\n \n float invmax = inversesqrt(max(dot(T,T), dot(B,B)));\n mat3 tbn = mat3(T * invmax, B * invmax, normal);\n vec3 vv = -viewDir * tbn;\n\n float parallaxLimit = -length(vv.xy) / vv.z;\n parallaxLimit *= heightScale;\n\n vec2 vOffsetDir = normalize(vv.xy);\n vec2 vMaxOffset = vOffsetDir * parallaxLimit;\n\n float factor = pow(1.0 - abs(vv.z), 2.0);\n float nNumSamples = mix(float(minLayers), float(maxLayers), factor);\n float fStepSize = 1.0 / nNumSamples;\n\n float fCurrRayHeight = 1.0;\n vec2 vCurrOffset = vec2(0.0);\n vec2 vLastOffset = vec2(0.0);\n float fLastSampledHeight = 1.0;\n float fCurrSampledHeight = 1.0;\n\n for (int nCurrSample = 0; nCurrSample < 128; nCurrSample++) {\n if (float(nCurrSample) > nNumSamples) break;\n\n fCurrSampledHeight = texture2D(heightMap, uv + vCurrOffset).r;\n if (fCurrSampledHeight > fCurrRayHeight) {\n float delta1 = fCurrSampledHeight - fCurrRayHeight;\n float delta2 = (fCurrRayHeight + fStepSize) - fLastSampledHeight;\n float ratio = delta1 / (delta1 + delta2);\n vCurrOffset = ratio * vLastOffset + (1.0 - ratio) * vCurrOffset;\n break;\n } else {\n fCurrRayHeight -= fStepSize;\n vLastOffset = vCurrOffset;\n vCurrOffset += fStepSize * vMaxOffset;\n fLastSampledHeight = fCurrSampledHeight;\n }\n }\n\n return uv + vCurrOffset;\n }\n "),e.fragmentShader=e.fragmentShader.replace("#include <map_fragment>","\n vec3 pomViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n vec2 uvPOM = vMapUv ;\n if (parallaxType == 1) {\n uvPOM = parallaxOffset(vMapUv, pomViewDir, vNormal);\n } else if (parallaxType == 2) {\n uvPOM = parallaxOcclusion2(vMapUv, pomViewDir, vNormal);\n }\n\n vec4 texelColor = texture2D(map, uvPOM);\n diffuseColor *= texelColor;\n "),e.fragmentShader=e.fragmentShader.replace("#include <normal_fragment_maps>","\n #ifdef USE_NORMALMAP\n // RE-COMPUTE TBN for normal mapping consistency\n vec3 dp1 = dFdx(-vViewPosition);\n vec3 dp2 = dFdy(-vViewPosition);\n vec2 duv1 = dFdx(uvPOM);\n vec2 duv2 = dFdy(uvPOM);\n vec3 dp2perp = cross(dp2, vNormal);\n vec3 dp1perp = cross(vNormal, dp1);\n vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;\n vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;\n float invmax = inversesqrt(max(dot(T,T), dot(B,B)));\n mat3 localTBN = mat3(T * invmax, B * invmax, vNormal);\n\n vec3 mapN = texture2D(normalMap, uvPOM).xyz * 2.0 - 1.0;\n mapN.xy *= normalScale;\n normal = normalize( localTBN * mapN );\n #endif\n "),e.fragmentShader=e.fragmentShader.replace("#include <roughnessmap_fragment>","\n float roughnessFactor = roughness;\n #ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, uvPOM );\n // reads channel G, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\n roughnessFactor *= texelRoughness.g;\n #endif\n "),e.fragmentShader=e.fragmentShader.replace("#include <metalnesssmap_fragment>","\n float metalnessFactor = metalness;\n #ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, uvPOM );\n // reads channel B, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\n metalnessFactor *= texelMetalness.b;\n #endif\n "),e.fragmentShader=e.fragmentShader.replace("#include <aomap_fragment>","\n #ifdef USE_AOMAP\n\n // reads channel R, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\n float ambientOcclusion = ( texture2D( aoMap, uvPOM ).r - 1.0 ) * aoMapIntensity + 1.0;\n\n reflectedLight.indirectDiffuse *= ambientOcclusion;\n\n #if defined( USE_CLEARCOAT ) \n clearcoatSpecularIndirect *= ambientOcclusion;\n #endif\n\n #if defined( USE_SHEEN ) \n sheenSpecularIndirect *= ambientOcclusion;\n #endif\n\n #if defined( USE_ENVMAP ) && defined( STANDARD )\n\n float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );\n\n reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );\n\n #endif\n\n #endif\n "),this.userData.shader=e}clone(){const e=super.clone();return e.heightMap=this.heightMap,e.heightScale=this.heightScale,e.parallaxType=this.parallaxType,e.minLayers=this.minLayers,e.maxLayers=this.maxLayers,e}}export function applyTiling(e,a){if(null==e||null==a)return e;if(1===a.x&&1===a.y)return e;const t=e.clone();return t.repeat.copy(a),t.needsUpdate=!0,t}function P(e,a){null!=e&&(e instanceof r?e.colorSpace=a:e instanceof S&&null!=e.value&&(e.value.colorSpace=a))}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as t,__metadata as e}from"tslib";import{Color as i,Texture as o,Vector2 as p}from"three";import{Shader as
|
|
1
|
+
import{__decorate as t,__metadata as e}from"tslib";import{Color as i,Texture as o,Vector2 as p}from"three";import{Shader as a}from"../shader.js";import{Parameter as r}from"../parameter.js";import{attributes as l,NodeShaderMaterial as n,rgba as s,Sampler2DNode as h,UniformSampler2d as y,uniformFloat as d,uniformVec3 as m,varying as u,varyingAttributes as c,vec2 as g}from"three-shader-graph";import*as v from"three";import{createPlaceholderTexture as M}from"../../utils/three/placeholder-texture.js";const S=M();export class UnlitShader extends a{constructor(){super(...arguments),this.color=new i("#FFFFFF"),this.opacity=1,this.intensity=1,this.map=new y("map",S),this.lightMap=new y("lightMap",S),this.aoMap=new y("aoMap",S),this.alphaMap=new y("alphaMap",S),this.vertexColor=!1,this.uvScale=new p(1,1)}build(){const t=function(t,e){if(null==e||1===e.x&&1===e.y)return t;return t.multiply(g(e))}(c.uv,this.uvScale);let e=d("opacity",this.opacity),i=m("color",(new v.Vector3).setFromColor(this.color)).rgb.multiplyScalar(d("intensity",this.intensity));if(f(this.map)){const o=this.map.sample(t);i=i.multiply(o.rgb),e=e.multiply(o.a)}if(f(this.alphaMap)&&(e=e.multiply(this.alphaMap.sample(t).r)),!0===this.vertexColor&&(i=i.multiply(u(l.color.rgb))),f(this.lightMap)&&(i=i.add(this.lightMap.sample(t).rgb.multiplyScalar(d("lightMapIntensity",this.lightMapIntensity??1)))),f(this.aoMap)){const e=this.aoMap.sample(t).r,o=d("aoMapIntensity",this.aoMapIntensity??1);i=i.multiplyScalar(e.subtract(1).multiply(o).add(1))}const o=new n({color:s(i,e),opacity:e,emissive:i,envMap:this.envMap,alphaTest:this.alphaTest});return o.vertexColors=!0===this.vertexColor,o}}function f(t){return null!=t&&(!(t instanceof y)||null!=t.value&&t.value!==S)}t([r(),e("design:type",i)],UnlitShader.prototype,"color",void 0),t([r({range:[0,1]}),e("design:type",Number)],UnlitShader.prototype,"opacity",void 0),t([r({range:[0,10]}),e("design:type",Number)],UnlitShader.prototype,"intensity",void 0),t([r(),e("design:type",h)],UnlitShader.prototype,"map",void 0),t([r(),e("design:type",h)],UnlitShader.prototype,"lightMap",void 0),t([r(),e("design:type",Number)],UnlitShader.prototype,"lightMapIntensity",void 0),t([r(),e("design:type",h)],UnlitShader.prototype,"aoMap",void 0),t([r(),e("design:type",Number)],UnlitShader.prototype,"aoMapIntensity",void 0),t([r(),e("design:type",h)],UnlitShader.prototype,"alphaMap",void 0),t([r(),e("design:type",o)],UnlitShader.prototype,"envMap",void 0),t([r(),e("design:type",Boolean)],UnlitShader.prototype,"vertexColor",void 0),t([r(),e("design:type",p)],UnlitShader.prototype,"uvScale",void 0);/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Material } from "three";
|
|
2
|
-
import { NodeShaderOutput } from "./shader.js";
|
|
3
|
-
export declare abstract class DecalNodeShader {
|
|
2
|
+
import { NodeShaderOutput, Shader } from "./shader.js";
|
|
3
|
+
export declare abstract class DecalNodeShader extends Shader {
|
|
4
4
|
build(): Material;
|
|
5
5
|
abstract output(): NodeShaderOutput;
|
|
6
6
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{NodeShaderMaterial as r}from"../shader-nodes/index.js";import{decalDiscard as s}from"../shader-nodes/decal.js";export class DecalNodeShader{build(){const e=this.output();let d=s;null!=e.discard&&(d=d.or(e.discard));const a=new r({transparent:!1,...e,discard:d});return a.userData.isDecal=!0,a}}/*
|
|
1
|
+
import{NodeShaderMaterial as r}from"../shader-nodes/index.js";import{decalDiscard as s}from"../shader-nodes/decal.js";import{Shader as e}from"./shader.js";export class DecalNodeShader extends e{build(){const e=this.output();let d=s;null!=e.discard&&(d=d.or(e.discard));const a=new r({transparent:!1,...e,discard:d});return a.userData.isDecal=!0,a}}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
package/dist/shader/shader.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { Mat4Node, BooleanNode, Vec4Node, Vec3Node, FloatNode, Vec2Node } from '
|
|
|
5
5
|
import { Type } from '../utils/type.js';
|
|
6
6
|
export * from './parameter.js';
|
|
7
7
|
export declare abstract class Shader {
|
|
8
|
+
alphaTest: number;
|
|
8
9
|
abstract build(): Material;
|
|
9
10
|
}
|
|
10
11
|
export type ShaderType = Type<Shader>;
|
|
@@ -29,7 +30,7 @@ export type NodeShaderOutput = {
|
|
|
29
30
|
opacity?: FloatNode;
|
|
30
31
|
emissive?: Vec3Node;
|
|
31
32
|
};
|
|
32
|
-
export declare abstract class NodeShader {
|
|
33
|
+
export declare abstract class NodeShader extends Shader {
|
|
33
34
|
build(): Material;
|
|
34
35
|
abstract output(): NodeShaderOutput;
|
|
35
36
|
}
|
package/dist/shader/shader.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{NodeShaderMaterial as r,BooleanNode as s,attributeFloat as e}from"../shader-nodes/index.js";export*from"./parameter.js";export class Shader{}const
|
|
1
|
+
import{NodeShaderMaterial as r,BooleanNode as s,attributeFloat as e}from"../shader-nodes/index.js";export*from"./parameter.js";export class Shader{constructor(){this.alphaTest=0}}const t=e("hole").gt(.5);export class NodeShader extends Shader{build(){const e=this.output();return new r({transparent:!1,...e,...!0===e.landscape?{discard:null!=e.discard&&e.discard instanceof s?e.discard.or(t):t}:{}})}}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -2,9 +2,9 @@ import * as THREE from 'three';
|
|
|
2
2
|
import { Material } from "three";
|
|
3
3
|
import { ConstantMat4Node, FloatNode, Vec4Node } from 'three-shader-graph';
|
|
4
4
|
import { NodeShaderMaterial } from "../shader-nodes/index.js";
|
|
5
|
-
import { NodeShaderOutput } from "./shader.js";
|
|
5
|
+
import { NodeShaderOutput, Shader } from "./shader.js";
|
|
6
6
|
export declare const identityTransform: ConstantMat4Node;
|
|
7
|
-
export declare abstract class SpriteNodeShader {
|
|
7
|
+
export declare abstract class SpriteNodeShader extends Shader {
|
|
8
8
|
build(): Material;
|
|
9
9
|
abstract output(): NodeShaderOutput;
|
|
10
10
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import*as i from"three";import{batchingMatrix as r,ConstantMat4Node as o,float as a,glslFunction as n,ifDefApply as s,rgba as l,step as c,textureSampler2d as p,UniformFloatNode as d,uniforms as u,varying as h,varyingAttributes as S,vec3 as m,vec4 as x,Vec4Node as y}from"three-shader-graph";import{depthSampler as v,NodeShaderMaterial as f}from"../shader-nodes/index.js";import{Parameter as M}from"./shader.js";export const identityTransform=new o((new i.Matrix4).identity());const
|
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import*as i from"three";import{batchingMatrix as r,ConstantMat4Node as o,float as a,glslFunction as n,ifDefApply as s,rgba as l,step as c,textureSampler2d as p,UniformFloatNode as d,uniforms as u,varying as h,varyingAttributes as S,vec3 as m,vec4 as x,Vec4Node as y}from"three-shader-graph";import{depthSampler as v,NodeShaderMaterial as f}from"../shader-nodes/index.js";import{Parameter as M,Shader as g}from"./shader.js";export const identityTransform=new o((new i.Matrix4).identity());const P=s("USE_BATCHING",identityTransform,e=>r);export class SpriteNodeShader extends g{build(){const e=this.output(),t=getSpritePosition(new d("rotation",0),new d("screenSpaceSize",0));return new SpriteNodeShaderMaterial({color:e.color,discard:e.discard,alphaTest:e.alphaTest,transparent:e.transparent??!0,position:t,uniforms:{color:{value:new i.Color(0)}}})}}export class SpriteShader extends SpriteNodeShader{constructor(){super(...arguments),this.color=new i.Color("#FFFFFF"),this.opacity=1,this.intensity=1,this.lockY=!1,this.screenSpaceSize=0,this.lenseFlare=!1,this.occlusionRadius=.2}output(){let e=a(this.opacity);this.alphaMap&&(e=e.multiply(p(this.alphaMap).sample(S.uv).r));let t=l(this.color,e);if(this.map&&(t=t.multiply(p(this.map).sample(S.uv))),null!=this.intensity&&1!==this.intensity&&(t=l(t.rgb.multiplyScalar(this.intensity),t.a)),this.lenseFlare){const e=a(this.occlusionRadius),i=b(w(m(0,0,0))),r=b(w(m(e.multiply(-1),0,0))),o=b(w(m(e,0,0))),n=b(w(m(0,e,0))),s=b(w(m(0,e.multiply(-1),0))),c=i.add(r).add(o).add(n).add(s).divide(5),p=h(c);return{color:l(t.rgb,t.a.multiply(p))}}return{color:t}}build(){const e=super.build();return this.lenseFlare&&(e.depthTest=!1,e.depthWrite=!1),this.lockY&&(e.defines.LOCK_Y_AXIS=""),null!=this.screenSpaceSize&&this.screenSpaceSize>0&&(e.defines.SCREEN_SPACE_SIZE=""),e.uniforms.screenSpaceSize.value=this.screenSpaceSize,e}}function w(e){let t=u.instanceMatrix.multiplyVec(x(e,1));return t=s("USE_BATCHING",t,e=>r.multiplyVec(e)),u.modelMatrix.multiplyVec(t)}function b(e){const t=u.projectionMatrix.multiplyVec(u.viewMatrix.multiplyVec(e)),i=t.xyz.divideScalar(t.w),r=i.xy.multiplyScalar(.5).addScalar(.5),o=v.sample(r).x,n=i.z.multiply(.5).add(.5),s=c(n,o.add(a(1e-4))),l=c(a(0),t.w);return s.multiply(l)}e([M(),t("design:type",i.Color)],SpriteShader.prototype,"color",void 0),e([M({range:[0,1]}),t("design:type",Number)],SpriteShader.prototype,"opacity",void 0),e([M({range:[0,10]}),t("design:type",Number)],SpriteShader.prototype,"intensity",void 0),e([M(),t("design:type",i.Texture)],SpriteShader.prototype,"map",void 0),e([M(),t("design:type",i.Texture)],SpriteShader.prototype,"alphaMap",void 0),e([M({help:"Sprite will rotate around Y axis to face camera"}),t("design:type",Boolean)],SpriteShader.prototype,"lockY",void 0),e([M({range:[0,1],help:"0 = Perspective (gets smaller with distance), 1 = Screen Space (constant size)"}),t("design:type",Number)],SpriteShader.prototype,"screenSpaceSize",void 0),e([M({help:"Make the sprite behave as a lense flare that appear in front of geometry if center is visible.",label:"Lens Flare"}),t("design:type",Boolean)],SpriteShader.prototype,"lenseFlare",void 0),e([M({range:[0,2],help:"The radius of the occlusion check. Larger radius will make the sprite fade out more gradually.",requires:{lenseFlare:!0}}),t("design:type",Number)],SpriteShader.prototype,"occlusionRadius",void 0);export function getSpritePosition(e,t=a(0)){return n(y,{cameraPosition:u.cameraPosition,viewMatrix:u.viewMatrix,modelViewMatrix:u.modelViewMatrix,rotation:e,screenSpaceSize:t,batchingMatrix:P,instanceMatrix:u.instanceMatrix},"\n mat4 finalModelMatrix = modelMatrix * batchingMatrix * instanceMatrix;\n\n // Scale from your model matrix\n vec2 scale;\n scale.x = length(vec3(finalModelMatrix[0].x, finalModelMatrix[0].y, finalModelMatrix[0].z));\n scale.y = length(vec3(finalModelMatrix[1].x, finalModelMatrix[1].y, finalModelMatrix[1].z));\n\n vec3 right, up;\n vec3 objectPos = (finalModelMatrix * vec4(0.0, 0.0, 0.0, 1.0)).xyz;\n\n #ifdef SCREEN_SPACE_SIZE\n float distanceToCamera = length(objectPos - cameraPosition);\n float screenScaleFactor = mix(1.0, distanceToCamera, screenSpaceSize);\n scale *= screenScaleFactor;\n #endif\n\n\n #ifdef LOCK_Y_AXIS\n vec3 cameraPos = cameraPosition;\n vec3 lookDir = normalize(vec3(cameraPos.x - objectPos.x, 0.0, cameraPos.z - objectPos.z));\n right = normalize(vec3(lookDir.z, 0.0, -lookDir.x));\n up = vec3(0.0, 1.0, 0.0);\n #else\n right = vec3(viewMatrix[0][0], viewMatrix[1][0], viewMatrix[2][0]);\n up = vec3(viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1]);\n #endif\n\n // then your shared code:\n vec2 center = vec2(0.5, 0.5);\n vec2 alignedPosition = (position.xy - (center - vec2(0.5))) * scale;\n\n vec2 rotatedPosition;\n rotatedPosition.x = cos(rotation) * alignedPosition.x - sin(rotation) * alignedPosition.y;\n rotatedPosition.y = sin(rotation) * alignedPosition.x + cos(rotation) * alignedPosition.y;\n\n vec3 billboardPos = objectPos + right * rotatedPosition.x + up * rotatedPosition.y;\n\n // This can be used just to test outputting without sprite functionality\n // return projectionMatrix * viewMatrix * finalModelMatrix * vec4(position, 1.0);\n return projectionMatrix * viewMatrix * vec4(billboardPos, 1.0);\n ")}export class SpriteNodeShaderMaterial extends f{get color(){return this.uniforms.color.value}set color(e){this.uniforms.color.value=new i.Color(e)}get rotation(){return this.uniforms.rotation.value}set rotation(e){this.uniforms.rotation.value=e}get screenSpaceSize(){return this.uniforms.screenSpaceSize.value}set screenSpaceSize(e){this.uniforms.screenSpaceSize.value=e}get occlusionRadius(){return this.uniforms.occlusionRadius.value}set occlusionRadius(e){this.uniforms.occlusionRadius.value=e}}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Material } from "three";
|
|
2
|
-
import { NodeShaderOutput } from "./shader.js";
|
|
3
|
-
export declare abstract class TrailNodeShader {
|
|
2
|
+
import { NodeShaderOutput, Shader } from "./shader.js";
|
|
3
|
+
export declare abstract class TrailNodeShader extends Shader {
|
|
4
4
|
build(): Material;
|
|
5
5
|
abstract output(): NodeShaderOutput;
|
|
6
6
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Shader as r}from"./shader.js";import{NodeShaderMaterial as e}from"three-shader-graph";import{Trail as o}from"../effects/vfx/trail-renderer";export class TrailNodeShader extends r{build(){const r=this.output(),{position:t}=o.getTrailShaderNodes(!1),a=new e({position:t,color:r.color});return o.applyTrailShaderParameters(a),a}}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{describe as e,expect as t,it as r,vi as a}from"vitest";import{Texture as o}from"three";import{AssetResourceLoader as n}from"../scene/asset-resource-loader.js";function s(e,t){return{id:e,name:e,type:"texture",fileKey:`${e}.ktx2`,fileFormat:"ktx2",texture:{textureArrayFileKey:"shared-array.ktx2",textureArrayLayer:t}}}a.mock("../scene/materializer.js",()=>({applyMaterial:a.fn(),getConvertedFbxToGlbAssignedMaterialTextureFlipY:a.fn()})),a.hoisted(()=>{if("undefined"==typeof HTMLCanvasElement)return;const e=new Proxy({},{get:(e,t)=>(t in e||(e[t]=("string"!=typeof t||!t.startsWith("is"))&&a.fn()),e[t]),set:(e,t,r)=>(e[t]=r,!0)});Object.defineProperty(HTMLCanvasElement.prototype,"getContext",{configurable:!0,value:()=>e}),"undefined"==typeof AudioBuffer&&Object.defineProperty(globalThis,"AudioBuffer",{configurable:!0,value:class{}})}),e("AssetResourceLoader texture arrays",()=>{r("deduplicates concurrent loads by texture array file key",async()=>{const e=new n;let r;const l=new Promise(e=>{r=e}),i=a.fn(()=>l);e._getTextureLoader=()=>({loadAsync:i}),e.getUri=e=>e;const u=e.getTextureArray(s("texture-a",0)),d=e.getTextureArray(s("texture-b",1));t(i).toHaveBeenCalledTimes(1);const c=new o;r(c);const[y,f]=await Promise.all([u,d]);t(y.texture).toBe(c),t(f.texture).toBe(c),t(y.layerIndex).toBe(0),t(f.layerIndex).toBe(1)}),r("allows a failed texture array load to be retried",async()=>{const e=new n,r=new o,l=a.fn().mockRejectedValueOnce(new Error("load failed")).mockResolvedValueOnce(r);e._getTextureLoader=()=>({loadAsync:l}),e.getUri=e=>e;const i=s("texture-a",0);await t(e.getTextureArray(i)).rejects.toThrow("load failed"),await t(e.getTextureArray(i)).resolves.toEqual({texture:r,layerIndex:0}),t(l).toHaveBeenCalledTimes(2)})});/*
|
|
2
|
+
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
|
+
* See the LICENSE.md file for details.
|
|
4
|
+
*/
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{expect as e,test as t}from"vitest";import{AnimationClip as i,AnimationMixer as o,LoopOnce as n,Object3D as a,VectorKeyframeTrack as s}from"three";import{canCrossFadeFromAnimationAction as p}from"../gameplay/animation/animation-action.js";t("crossfades away from a finished clamped animation",()=>{const t=new a,d=new o(t),c=new i("slide",.5,[new s(".position",[0,.5],[0,0,0,0,0,1])]),r=new i("idle",1,[new s(".position",[0,1],[0,0,0,0,0,0])]),m=d.clipAction(c);m.setLoop(n,1),m.clampWhenFinished=!0,m.play(),d.update(c.duration+.1),e(m.isRunning()).toBe(!1),e(m.isScheduled()).toBe(!0),e(m.enabled).toBe(!0),e(p(m)).toBe(!0);const l=d.clipAction(r);l.reset().play(),m.crossFadeTo(l,.2,!0),d.update(.1),e(m.getEffectiveWeight()).toBeLessThan(1),e(l.getEffectiveWeight()).toBeGreaterThan(0),d.update(.11),e(m.enabled).toBe(!1)});/*
|
|
2
|
+
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
|
+
* See the LICENSE.md file for details.
|
|
4
|
+
*/
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{describe as e,expect as t,test as o}from"vitest";import{Vector3 as n}from"three";import{setSlideJumpVelocity as s,shouldContinueSlide as a,shouldStartSlide as r,updateSlideVelocity as c,updateSlideVelocityFromDisplacement as l}from"../gameplay/actors/builtin/components/character/character-slide.js";const h=new n(0,1,0),i=new n;e("character slide movement",()=>{o("decelerates at a constant rate on flat ground",()=>{const e=new n(0,0,10),o=c(e,e,h,i,-9.81,1,3,1,2);t(o).toBeCloseTo(7),t(e.z).toBeCloseTo(7)}),o("uses the surface angle to accelerate downhill and slow uphill",()=>{const e=Math.PI/6,o=new n(0,Math.cos(e),Math.sin(e)),s=new n(0,Math.cos(e),-Math.sin(e)),a=new n(0,0,10),r=new n(0,0,10),l=new n(0,0,10),w=c(a,a,o,i,-9.81,.5,3,1,0),d=c(l,l,h,i,-9.81,.5,3,1,0),B=c(r,r,s,i,-9.81,.5,3,1,0);t(w).toBeGreaterThan(d),t(B).toBeLessThan(d)}),o("steers gradually without changing the computed speed",()=>{const e=new n(0,0,10),o=new n(1,0,0),s=c(e,e,h,o,0,.1,0,1,2);t(s).toBeCloseTo(10),t(e.length()).toBeCloseTo(10),t(e.x).toBeGreaterThan(0),t(e.z).toBeGreaterThan(0)}),o("turns predictably when steering opposite the slide direction",()=>{const e=new n(0,0,10);c(e,e,h,new n(0,0,-1),0,.1,0,1,2),t(e.length()).toBeCloseTo(10),t(e.z).toBeGreaterThan(0),t(Math.abs(e.x)).toBeGreaterThan(0)}),o("derives speed from collision-corrected displacement",()=>{const e=new n,o=l(e,new n(0,0,.08),new n,h,.016),s=l(e,new n,new n,h,.016);t(o).toBeCloseTo(5),t(s).toBe(0)}),o("requires a start edge and uses exit-speed hysteresis",()=>{t(r(!0,!0,!0,!0,!1,8,8)).toBe(!0),t(r(!0,!1,!0,!0,!1,12,8)).toBe(!1),t(r(!0,!0,!0,!0,!0,12,8)).toBe(!1),t(a(!0,!0,!0,!0,!1,4,4)).toBe(!0),t(a(!0,!0,!0,!0,!1,3.99,4)).toBe(!1),t(a(!0,!1,!0,!0,!1,12,4)).toBe(!1)}),o("preserves horizontal momentum when jumping",()=>{const e=s(new n,new n(3,-2,5),7);t(e.toArray()).toEqual([3,7,5])})});/*
|
|
2
|
+
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
|
+
* See the LICENSE.md file for details.
|
|
4
|
+
*/
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{describe as e,expect as t,it as s,vi as a}from"vitest";import{NavMeshWorkerPool as n}from"../gameplay/ai/dynamic-tiled-navmesh.js";e("NavMeshWorkerPool",()=>{s("creates workers lazily and caps concurrent work",()=>{const e=[],s=new n(()=>{const t=new o;return e.push(t),t}),l={},r=a.fn();t(e).toHaveLength(0);for(let e=0;e<8;e++)s.schedule(l,{tileX:e},void 0,r,24);t(e).toHaveLength(4),t(e.flatMap(e=>e.messages)).toHaveLength(4),e[0].complete(0),t(e).toHaveLength(4),t(e.flatMap(e=>e.messages)).toHaveLength(5),t(r).toHaveBeenCalledTimes(1)}),s("does not deliver queued or active results after an owner is cancelled",()=>{const e=[],s=new n(()=>{const t=new o;return e.push(t),t}),l={},r=a.fn();s.schedule(l,{tileX:0},void 0,r,1),s.schedule(l,{tileX:1},void 0,r,1),s.cancel(l),e[0].complete(0),t(r).not.toHaveBeenCalled(),t(e[0].messages).toHaveLength(1)})});class o{constructor(){this.onmessage=null,this.onerror=null,this.messages=[],this.terminate=a.fn()}postMessage(e){this.messages.push(e)}complete(e){this.onmessage?.({data:{tileX:e,tileY:0,navMeshData:new Uint8Array}})}}/*
|
|
2
|
+
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
|
+
* See the LICENSE.md file for details.
|
|
4
|
+
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{beforeAll as e,describe as t,expect as o,test as a}from"vitest";import{CharacterMovementMode as n}from"../gameplay/actors/builtin/components/character/modes.js";let c,
|
|
1
|
+
import{beforeAll as e,describe as t,expect as o,test as a}from"vitest";import{CharacterMovementMode as n}from"../gameplay/actors/builtin/components/character/modes.js";let c,s;function r(e={}){return{sequence:1,clientTime:.016,dt:.016,inputX:0,inputY:0,yaw:0,flags:0,clientX:0,clientY:0,clientZ:0,rootMotionX:0,rootMotionY:0,rootMotionZ:0,...e}}function i(e={}){return{sequence:0,x:0,y:0,z:0,velocityX:0,velocityY:0,velocityZ:0,yaw:0,mode:n.walking,flags:0,horizontalSpeed:0,...e}}function l(e){return{directionInput:{},jumpInput:{},sprintInput:{},rotationInput:{},setRootMotionAction(){},applyImpulse(){},...e}}e(async()=>{"undefined"!=typeof HTMLCanvasElement&&Object.defineProperty(HTMLCanvasElement.prototype,"getContext",{configurable:!0,value:()=>({fillStyle:"",fillRect(){},clearRect(){},getImageData:()=>({data:new Uint8ClampedArray(4)}),putImageData(){},createImageData:()=>({data:new Uint8ClampedArray(4)}),setTransform(){},drawImage(){},save(){},restore(){},beginPath(){},moveTo(){},lineTo(){},closePath(){},stroke(){},translate(){},scale(){},rotate(){},arc(){},fill(){},measureText:()=>({width:0}),transform(){},rect(){},clip(){}})}),c=await import("../gameplay/actors/builtin/components/character/net-character-movement-protocol.js"),s=(await import("../gameplay/actors/builtin/components/character/character-movement-like.js")).getCharacterMovementLike}),t("net character movement packets",()=>{a("round trips batched saved moves",()=>{const e=[r({sequence:1,dt:.016,inputX:.25,inputY:1,yaw:.5,flags:c.MOVE_FLAG_CROUCH|c.MOVE_FLAG_SLIDE_START,clientX:1,clientY:2,clientZ:3}),r({sequence:2,dt:.033,inputX:-.5,inputY:.5,yaw:-1,flags:1,clientX:4,clientY:5,clientZ:6,rootMotionZ:.2})],t=c.decodeNetCharacterMoveBatch(c.encodeNetCharacterMoveBatch(e));o(t.ok).toBe(!0),t.ok&&(o(t.value.moves).toHaveLength(2),o(t.value.moves[0].sequence).toBe(1),o(t.value.moves[0].clientTime).toBeCloseTo(.016,3),o(t.value.moves[0].dt).toBeCloseTo(.016,3),o(t.value.moves[0].inputX).toBeCloseTo(.25,4),o(t.value.moves[0].flags).toBe(c.MOVE_FLAG_CROUCH|c.MOVE_FLAG_SLIDE_START),o(t.value.moves[1].rootMotionZ).toBeCloseTo(.2))}),a("round trips owner ack, correction, and simulated state packets",()=>{const e=c.SNAPSHOT_FLAG_CROUCHING|c.SNAPSHOT_FLAG_CROUCH_SUPPRESSED,t=i({sequence:42,x:10,y:2,z:-3,velocityX:1,yaw:1.25,mode:n.sliding,flags:e,horizontalSpeed:7}),a=c.decodeNetCharacterOwnerAck(c.encodeNetCharacterOwnerAck(42)),s=c.decodeNetCharacterOwnerCorrection(c.encodeNetCharacterOwnerCorrection(t)),r=c.decodeNetCharacterSimulatedState(c.encodeNetCharacterSimulatedState(t));o(a.ok&&a.value.sequence).toBe(42),o(s.ok&&s.value.snapshot.sequence).toBe(42),o(s.ok&&s.value.snapshot.flags).toBe(e),o(r.ok&&r.value.mode).toBe(n.sliding),o(r.ok&&r.value.flags).toBe(e),o(r.ok&&r.value.horizontalSpeed).toBeCloseTo(7)}),a("rejects malformed, unsupported version, and wrong-kind packets",()=>{const e=c.encodeNetCharacterMoveBatch([r({sequence:1})]),t=e.slice();t[0]=99;const a=e.slice();a[1]=99,o(c.decodeNetCharacterMoveBatch(new Uint8Array([1,1,0]))).toMatchObject({ok:!1,reason:"malformed"}),o(c.decodeNetCharacterMoveBatch(t)).toMatchObject({ok:!1,reason:"unsupported-version"}),o(c.decodeNetCharacterMoveBatch(a)).toMatchObject({ok:!1,reason:"wrong-kind"}),o(c.NET_CHARACTER_MOVEMENT_VERSION).toBe(4)})}),t("net character prediction helpers",()=>{a("combines adjacent equivalent saved moves by default",()=>{const e=new c.NetCharacterSavedMoveBuffer(4);e.push(r({sequence:1,clientTime:.016,dt:.016,inputY:1,clientZ:.1})),e.push(r({sequence:2,clientTime:.032,dt:.016,inputY:1,clientZ:.3}));const t=e.getMovesForSend(4);o(t).toHaveLength(1),o(t[0].sequence).toBe(2),o(t[0].dt).toBeCloseTo(.032),o(t[0].clientZ).toBeCloseTo(.3)}),a("keeps adjacent saved moves separate when combining is disabled",()=>{const e=new c.NetCharacterSavedMoveBuffer(4,-1);e.push(r({sequence:1,clientTime:.016,dt:.016,inputY:1,clientZ:.1})),e.push(r({sequence:2,clientTime:.032,dt:.016,inputY:1,clientZ:.3}));const t=e.getMovesForSend(4);o(t.map(e=>e.sequence)).toEqual([1,2]),o(t.map(e=>e.dt)).toEqual([.016,.016])}),a("preserves a sprint start move for server simulation and replay",()=>{const e=new c.NetCharacterSavedMoveBuffer(4),t=c.MOVE_FLAG_SPRINT|c.MOVE_FLAG_SPRINT_START;e.push(r({sequence:1,clientTime:.016,dt:.016,inputY:1,flags:t})),e.push(r({sequence:2,clientTime:.032,dt:.016,inputY:1,flags:c.MOVE_FLAG_SPRINT}));const a=c.encodeNetCharacterMoveBatch(e.getMovesForSend(4)),n=c.decodeNetCharacterMoveBatch(a);o(n.ok).toBe(!0),n.ok&&(o(n.value.moves.map(e=>e.sequence)).toEqual([1,2]),o(n.value.moves[0].flags).toBe(t))}),a("preserves a slide start move for server simulation and replay",()=>{const e=new c.NetCharacterSavedMoveBuffer(4),t=c.MOVE_FLAG_CROUCH|c.MOVE_FLAG_SLIDE_START;e.push(r({sequence:1,clientTime:.016,dt:.016,inputY:1,flags:t})),e.push(r({sequence:2,clientTime:.032,dt:.016,inputY:1,flags:c.MOVE_FLAG_CROUCH}));const a=c.encodeNetCharacterMoveBatch(e.getMovesForSend(4)),n=c.decodeNetCharacterMoveBatch(a);o(n.ok).toBe(!0),n.ok&&(o(n.value.moves.map(e=>e.sequence)).toEqual([1,2]),o(n.value.moves[0].flags).toBe(t))}),a("does not combine saved moves across crouch changes",()=>{const e=new c.NetCharacterSavedMoveBuffer(4);e.push(r({sequence:1,clientTime:.016,dt:.016,inputY:1})),e.push(r({sequence:2,clientTime:.032,dt:.016,inputY:1,flags:c.MOVE_FLAG_CROUCH}));const t=e.getMovesForSend(4);o(t.map(e=>e.sequence)).toEqual([1,2]),o(t.map(e=>e.flags)).toEqual([0,c.MOVE_FLAG_CROUCH])}),a("combines adjacent crouched saved moves",()=>{const e=new c.NetCharacterSavedMoveBuffer(4);e.push(r({sequence:1,clientTime:.016,dt:.016,inputY:1,flags:c.MOVE_FLAG_CROUCH})),e.push(r({sequence:2,clientTime:.032,dt:.016,inputY:1,flags:c.MOVE_FLAG_CROUCH}));const t=e.getMovesForSend(4);o(t).toHaveLength(1),o(t[0].sequence).toBe(2),o(t[0].flags).toBe(c.MOVE_FLAG_CROUCH)}),a("respects saved move max combined delta time",()=>{const e=new c.NetCharacterSavedMoveBuffer(4,.02);e.push(r({sequence:1,clientTime:.016,dt:.016,inputY:1})),e.push(r({sequence:2,clientTime:.032,dt:.016,inputY:1})),o(e.getMovesForSend(4).map(e=>e.sequence)).toEqual([1,2])}),a("does not combine a move after it has been selected for sending",()=>{const e=new c.NetCharacterSavedMoveBuffer(4,.1);e.push(r({sequence:1,clientTime:.016,dt:.016,inputY:1})),o(e.getMovesForSend(4).map(e=>e.sequence)).toEqual([1]),e.push(r({sequence:2,clientTime:.032,dt:.016,inputY:1}));const t=e.getMovesForSend(4);o(t.map(e=>e.sequence)).toEqual([1,2]),o(t.map(e=>e.dt)).toEqual([.016,.016])}),a("selects the oldest unacked move and newest moves for send packets",()=>{const e=new c.NetCharacterSavedMoveBuffer(8);for(let t=1;t<=5;t++)e.push(r({sequence:t,clientTime:.02*t,dt:.02,inputX:t%2==0?.25:-.25}));o(e.getMovesForSend(3).map(e=>e.sequence)).toEqual([1,4,5])}),a("replays saved moves with a deterministic simulator",()=>{const e=c.replayNetCharacterSavedMoves({x:0},[r({sequence:1,dt:.1,inputY:1}),r({sequence:2,dt:.2,inputY:1})],(e,t)=>({x:e.x+t.inputY*t.dt*10}));o(e.x).toBeCloseTo(3)}),a("validates move sequence, dt, and normalized input",()=>{o(c.validateNetCharacterMove(r({sequence:2,dt:.016}),1)).toBe(!0),o(c.validateNetCharacterMove(r({sequence:1,dt:.016}),1)).toBe(!1),o(c.validateNetCharacterMove(r({sequence:2,clientTime:0}),1)).toBe(!1),o(c.validateNetCharacterMove(r({sequence:2,dt:.5}),1,.1)).toBe(!1),o(c.validateNetCharacterMove(r({sequence:2,inputX:1,inputY:1}),1)).toBe(!1),o(c.validateNetCharacterMove(r({sequence:2,flags:128}),1)).toBe(!1)}),a("derives server move dt from client timestamps",()=>{const e=c.createNetCharacterServerMoveTimingState();c.accrueNetCharacterServerMoveTime(e,.05);const t=c.consumeNetCharacterServerMoveTime(e,r({sequence:1,clientTime:.016}),{maxMoveDeltaTime:.1}),a=c.consumeNetCharacterServerMoveTime(e,r({sequence:2,clientTime:.05}),{maxMoveDeltaTime:.1});o(t).toBeCloseTo(.016),o(a).toBeCloseTo(.034),o(e.lastClientTime).toBeCloseTo(.05)}),a("clamps server move dt and rejects clients too far ahead of server time",()=>{const e=c.createNetCharacterServerMoveTimingState();c.accrueNetCharacterServerMoveTime(e,.02);const t=c.consumeNetCharacterServerMoveTime(e,r({sequence:1,clientTime:.5}),{maxMoveDeltaTime:.05,maxServerMoveDeltaTimeScalar:2,maxClientTimeAhead:.1}),a=c.consumeNetCharacterServerMoveTime(e,r({sequence:2,clientTime:.7}),{maxMoveDeltaTime:.05,maxServerMoveDeltaTimeScalar:2,maxClientTimeAhead:.01});o(t).toBeCloseTo(.1),o(a).toBe(-1)})}),t("net character simulated proxy smoothing",()=>{a("interpolates delayed snapshots",()=>{const e=new c.NetCharacterProxySmoother(.1,20),t=i();e.push(i({sequence:1,x:0}),0),e.push(i({sequence:2,x:10}),1),o(e.sample(.6,t)).toBe(!0),o(t.x).toBeCloseTo(5)}),a("snaps instead of interpolating large gaps",()=>{const e=new c.NetCharacterProxySmoother(0,1),t=i();e.push(i({sequence:1,x:0}),0),e.push(i({sequence:2,x:10}),1),o(e.sample(.5,t)).toBe(!0),o(t.x).toBe(10)})}),t("character movement compatibility",()=>{a("prefers the default movement component when present",()=>{const e=l({horizontalSpeed:2}),t=l({horizontalSpeed:5,isDefaultCharacterMovementComponent:!0});o(s({oldMovement:e,defaultMovement:t,attachedComponents:[]})).toBe(t)})});/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{expect as
|
|
1
|
+
import{expect as e,test as t,vi as o}from"vitest";import*as i from"three";import{BaseActor as n}from"../gameplay/actors/actor.js";import{CharacterAnimationComponent as s,OldCharacterMovementComponent as r}from"../gameplay/actors/index.js";import{RootMotionClip as a}from"../gameplay/animation/root-motion.js";import{createAnimationClipInstance as c,createAnimationSubTrack as l}from"../effects/sequence/sequence-data.js";import{evaluateAnimationClipOutputProgress as m,evaluateAnimationClipSourceProgress as p,normalizeAnimationClipRetiming as u,buildRetimedAnimationClip as f}from"../effects/sequence/sequence-animation-retiming.js";import{SequencePlayer as d}from"../effects/sequence/sequence-player.js";function g(e){return Array.from(e).map(e=>Math.round(1e3*e)/1e3)}o.mock("../gameplay/actors/builtin/index.js",()=>({builtInActors:{},default:{}})),o.mock("../gameplay/actors/index.js",()=>({CharacterAnimationComponent:class{},OldCharacterMovementComponent:class{},getCharacterMovementLike:e=>e.movement??void 0})),o.mock("../effects/vfx/vfx-actor.js",()=>({VfxActor:class{}})),o.mock("../effects/vfx/vfx-param.js",()=>({VisualEffect:class{}})),o.mock("../effects/vfx/vfx-service.js",()=>({VfxService:class{}})),o.hoisted(()=>{if("undefined"==typeof AudioBuffer&&Object.defineProperty(globalThis,"AudioBuffer",{configurable:!0,value:class{}}),"undefined"==typeof HTMLCanvasElement)return;const e=new Proxy({},{get:(e,t)=>(t in e||(e[t]=("string"!=typeof t||!t.startsWith("is"))&&o.fn()),e[t]),set:(e,t,o)=>(e[t]=o,!0)});Object.defineProperty(HTMLCanvasElement.prototype,"getContext",{configurable:!0,value:()=>e})}),t("uniform retiming mapping stays linear",()=>{e(p(void 0,.25)).toBeCloseTo(.25),e(m(void 0,.75)).toBeCloseTo(.75),e(p({mode:"uniform",points:[]},.6)).toBeCloseTo(.6)}),t("impact retiming redistributes time around the impact marker",()=>{const t={mode:"impact",points:[{id:"impact",clipProgress:.35,sourceProgress:.55}]};e(p(t,.35)).toBeCloseTo(.55),e(m(t,.55)).toBeCloseTo(.35),e(p(t,.7)).toBeGreaterThan(.7)}),t("advanced retiming sanitization stays monotonic and bounded",()=>{const t=u({mode:"advanced",points:[{id:"a",clipProgress:.9,sourceProgress:.2},{id:"b",clipProgress:-4,sourceProgress:.8},{id:"c",clipProgress:.9,sourceProgress:2},{id:"d",clipProgress:.4,sourceProgress:.1}]});e(t.points).toHaveLength(3);for(let o=1;o<t.points.length;o++)e(t.points[o].clipProgress).toBeGreaterThan(t.points[o-1].clipProgress),e(t.points[o].sourceProgress).toBeGreaterThan(t.points[o-1].sourceProgress);e(t.points[0].clipProgress).toBeGreaterThan(0),e(t.points[t.points.length-1].sourceProgress).toBeLessThan(1)}),t("retimed clip baking preserves trim boundary poses and remaps track times to clip duration",()=>{const t=new i.AnimationClip("trim-test",2,[new i.NumberKeyframeTrack("weight",[0,1,2],[0,10,20])]),o=c("anim",0,1);o.clipStartOffset=.5,o.clipEndOffset=.25,o.retiming={mode:"advanced",points:[]};const n=f(t,o),s=n.tracks[0];e(n.duration).toBeCloseTo(1),e(g(s.times)).toEqual([0,.4,1]),e(g(s.values)).toEqual([5,10,17.5])}),t("root motion track baking stays aligned with the retimed visual clip",()=>{const t=new i.AnimationClip("root-motion-test",2,[new i.VectorKeyframeTrack("hips.position",[0,1,2],[0,0,0,1,0,0,2,0,0])]),o=c("anim",0,1);o.retiming={mode:"impact",points:[{id:"impact",clipProgress:.25,sourceProgress:.5}]};const n=f(t,o),s=n.tracks[0],r=a.fromClip(n,!1);e(g(s.times)).toEqual([0,.25,1]),e(g(r.motionTrack.times)).toEqual([0,.25,1]),e(g(r.motionTrack.values)).toEqual([0,0,0,1,0,0,2,0,0])}),t("sequence player keeps uniform clips on the existing playback path",()=>{const t=new d,o=l(),n=c("anim",0,1);n.playbackRate=1.75,n.clipStartOffset=.25,o.clips.push(n);const s=new i.AnimationClip("uniform-test",2,[new i.NumberKeyframeTrack("weight",[0,1,2],[0,1,2])]);t.animationClips.set("anim",s);const r=new i.Object3D,a={target:r,mixer:new i.AnimationMixer(r),activeActions:new Map};t.evaluateAnimationSubTrack(o,a,.1);const m=a.activeActions.get(`${o.id}-${n.id}`);e(m).toBeDefined(),e(m.getClip()).toBe(s),e(m.timeScale).toBeCloseTo(1.75),e(m.time).toBeCloseTo(.25)}),t("sequence player uses baked retimed clips and still wires root motion through the action",()=>{const t=new d,o=l(),n=c("anim",0,1.5);n.rootMotion=!0,n.playbackRate=2,n.retiming={mode:"impact",points:[{id:"impact",clipProgress:.3,sourceProgress:.55}]},o.clips.push(n);const s=new i.AnimationClip("retimed-root",2,[new i.VectorKeyframeTrack("hips.position",[0,1,2],[0,0,0,1,0,0,2,0,0]),new i.NumberKeyframeTrack("weight",[0,1,2],[0,1,2])]);t.animationClips.set("anim",s);const r=new h,m=new y(r.object),p=new v;r.charAnim=m,r.movement=p;const u={target:r,activeActions:new Map};t.evaluateAnimationSubTrack(o,u,.1);const f=u.activeActions.get(`${o.id}-${n.id}`);e(f).toBeDefined(),e(f.timeScale).toBeCloseTo(1),e(f.getClip()).toBeInstanceOf(a),e(f.getClip().duration).toBeCloseTo(1.5),e(p.lastRootMotionAction).toBe(f),e(t.retimedAnimationClips.size).toBe(1)}),t("external sequence control previews root motion deterministically while scrubbing",()=>{const t=new d;t.externalTimeControl=!0;const o=l(),n=c("anim",0,2);n.rootMotion=!0,o.clips.push(n);const s=new i.AnimationClip("root-motion-preview",2,[new i.VectorKeyframeTrack("hips.position",[0,1,2],[0,0,0,1,1,0,2,2,0])]);t.animationClips.set("anim",s);const r=new h;r.object.position.set(10,3,0),r.object.scale.setScalar(2);const a=new i.Bone;a.name="hips",r.object.add(a),r.charAnim=new y(r.object);const m={target:r,activeActions:new Map};t.evaluateSubTracks([o],m,.25),e(r.object.position.x).toBeCloseTo(10.5),e(r.object.position.y).toBeCloseTo(3),t.evaluateSubTracks([o],m,1.5),e(r.object.position.x).toBeCloseTo(13),e(r.object.position.y).toBeCloseTo(3),t.evaluateSubTracks([o],m,.5),e(r.object.position.x).toBeCloseTo(11),e(r.object.position.y).toBeCloseTo(3)});class h extends n{constructor(){super(...arguments),this.charAnim=null,this.movement=null}getComponent(e){return e===s?this.charAnim:e===r?this.movement:void 0}}class y{constructor(e){this.fullBodyAction=null,this.mixer=new i.AnimationMixer(e)}play(e,t={}){this.fullBodyAction=this.mixer.clipAction(e),this.fullBodyAction.setLoop(i.LoopOnce,1),this.fullBodyAction.clampWhenFinished=!0,this.fullBodyAction.timeScale=t.timeScale??1,null!=t.offset&&(this.fullBodyAction.time=t.offset),this.fullBodyAction.play()}beginExternalAnimationControl(e,t={}){return this.play(e,t),this.getFullBodyAction()}getFullBodyAction(){if(null==this.fullBodyAction)throw new Error("No full body action is active");return this.fullBodyAction}getMixer(){return this.mixer}beginExternalControl(){}endExternalControl(){}stopSequenceAnimation(){}}class v{constructor(){this.lastRootMotionAction=null}setRootMotionAction(e){this.lastRootMotionAction=e}}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{expect as o,test as e}from"vitest";import*as t from"three";import{createAnimationClipInstance as n}from"../effects/sequence/sequence-data.js";import{applyAnimationClipRootMotionAxisMask as i}from"../effects/sequence/sequence-animation-retiming.js";function a(o){return Array.from(o).map(o=>Math.round(1e3*o)/1e3)}e("root motion axis masking removes disabled translation without changing the source clip",()=>{const e=new t.AnimationClip("root-motion-mask",1,[new t.VectorKeyframeTrack("hips.position",[0,.5,1],[2,3,4,3,5,7,1,8,10])]),r=n("anim",0,1);r.rootMotion=!0,r.rootMotionX=!1;const s=i(e,r),m=s.tracks[0],c=e.tracks[0];o(s).not.toBe(e),o(a(m.values)).toEqual([2,3,4,2,5,7,2,8,10]),o(a(c.values)).toEqual([2,3,4,3,5,7,1,8,10])}),e("root motion axis masking keeps the original clip when all axes are enabled",()=>{const e=new t.AnimationClip("root-motion-unmasked",1,[new t.VectorKeyframeTrack("hips.position",[0,1],[0,0,0,1,2,3])]),a=n("anim",0,1);o(i(e,a)).toBe(e)});/*
|
|
2
|
+
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
|
+
* See the LICENSE.md file for details.
|
|
4
|
+
*/
|