@hology/core 0.0.233 → 0.0.234
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/gameplay/actors/builtin/components/character/character-movement.js +1 -1
- package/dist/rendering/motion-vector-node.d.ts +7 -0
- package/dist/rendering/motion-vector-node.js +4 -0
- package/dist/rendering/webgpu-experimental-backend.d.ts +23 -3
- package/dist/rendering/webgpu-experimental-backend.js +1 -1
- package/dist/rendering.d.ts +14 -2
- package/dist/rendering.js +1 -1
- package/dist/scene/materializer.js +1 -1
- package/dist/shader-nodes/depth.d.ts +1 -1
- package/dist/shader-nodes/glsl-node.js +1 -1
- package/dist/shader-nodes/material-flags.d.ts +1 -1
- package/dist/shader-nodes/material-flags.js +1 -1
- package/dist/shader-nodes/particle.d.ts +1 -1
- package/dist/shader-nodes/particle.js +1 -1
- package/dist/shader-nodes/pom.js +1 -1
- package/dist/shader-nodes/wgsl-node.js +1 -1
- package/dist/test/parameter-definition.test.js +1 -1
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WebGLRenderer } from "three";
|
|
2
2
|
import { FloatNode, Vec2Node, Vec3Node } from "three-shader-graph";
|
|
3
|
-
import type { Compiler } from "three-shader-graph
|
|
3
|
+
import type { Compiler } from "three-shader-graph";
|
|
4
4
|
export declare function supportsDepthTextureExtension(renderer: WebGLRenderer): boolean;
|
|
5
5
|
export declare const depthUniformName = "hology_depth_map";
|
|
6
6
|
export declare const resolutionUniformName = "hology_resolution";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{isWgslCompiler as e}from"three-shader-graph
|
|
1
|
+
import{isWgslCompiler as e}from"three-shader-graph";export function glslFunction(t,n,o){const r=t.typeName;return new class extends t{compile(t){if(e(t))throw new Error("WGSL cannot compile a glslFunction body. Replace it with shared nodes or provide a native WGSL node emitter.");const a=`customFunction_${t.variable()}`,i=Object.entries(n).map(([e,t])=>`${t.constructor.typeName} ${e}`).join(", "),c=Object.values(n).map(e=>t.get(e)).join(", ");return{pars:`${r} ${a}(${i}) {\n ${o}\n }`,out:`${a}(${c})`}}}}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BooleanNode } from 'three-shader-graph';
|
|
2
|
-
import { Compiler } from 'three-shader-graph
|
|
2
|
+
import { Compiler } from 'three-shader-graph';
|
|
3
3
|
export declare const MATERIAL_FLAG_ALPHA_TEST = 1;
|
|
4
4
|
export declare const MATERIAL_FLAG_RECEIVE_DECALS = 2;
|
|
5
5
|
declare class SampledSurfaceRejectsDecalsNode extends BooleanNode {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{BooleanNode as e}from"three-shader-graph";import{isWgslCompiler as
|
|
1
|
+
import{BooleanNode as e}from"three-shader-graph";import{isWgslCompiler as t}from"three-shader-graph";import{screenUV as r}from"./depth.js";import{sceneColorSampler as o}from"./scene-sample.js";export const MATERIAL_FLAG_ALPHA_TEST=1;export const MATERIAL_FLAG_RECEIVE_DECALS=2;const s=o.sample(r).a.lt(2);export const sampledSurfaceRejectsDecals=new class extends e{compile(e){return t(e)?{out:e.get(s)}:{out:"false"}}};/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FloatNode, Vec3Node } from 'three-shader-graph';
|
|
2
|
-
import { Compiler } from 'three-shader-graph
|
|
2
|
+
import { Compiler } from 'three-shader-graph';
|
|
3
3
|
export declare const particleEnergyUniformName = "hology_particle_energy";
|
|
4
4
|
export declare const particleTimeUniformName = "hology_particle_time";
|
|
5
5
|
export declare const particleVelcoityUniformName = "hology_particle_velocity";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Vector3 as e}from"three";import{attributeVec3 as t,FloatNode as o,ifDefApply as r,uniformFloat as n,Vec3Node as i,Vec3ExpressionNode as c,UniformVec3Node as a,autoVarying as
|
|
1
|
+
import{Vector3 as e}from"three";import{attributeVec3 as t,FloatNode as o,ifDefApply as r,uniformFloat as n,Vec3Node as i,Vec3ExpressionNode as c,UniformVec3Node as a,autoVarying as s}from"three-shader-graph";import{isWgslCompiler as l,isWgslFragmentCompiler as p}from"three-shader-graph";export const particleEnergyUniformName="hology_particle_energy";export const particleTimeUniformName="hology_particle_time";export const particleVelcoityUniformName="hology_particle_velocity";const m=new a("color",new e(1,1,1),void 0,!1);const h=s(new class extends i{compile(e){if(l(e))return p(e)?e.defineVarying("vec3",new c("instanceColor")):{out:"rendererObjectColor(input.instanceIndex).xyz"};return{chunk:`\n #ifdef USE_INSTANCING_COLOR\n vec3 instanceColor = instanceColor;\n #else\n vec3 instanceColor = ${e.get(m)};\n #endif\n `,out:"instanceColor"}}});class f extends o{constructor(e,o){super(),this.uniform=e,this.component=o,this.particleData=t("particleData")}compile(e){if(l(e)){const t=e.get(this.uniform),o=e.get(this.particleData);return{out:`select(${t}, ${o}.${this.component}, ${o}.z > 0.5)`}}return{out:e.get(r("USE_INSTANCING",this.uniform,()=>this.particleData[this.component]))}}}export const particleUniforms={energy:new f(n("hology_particle_energy",1),"y"),color:h,opacity:new f(n("opacity",1),"x"),time:n("hology_particle_time")};export const particleAttributes={};/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
package/dist/shader-nodes/pom.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{abs as e,attributes as t,cross as n,dFdx as r,dFdy as a,float as i,normalize as l,select as s,transformed as p,UniformSampler2dArraySlice as f,uniforms as $,varying as o,Vec2Node as v,vec3 as u,vec4 as m}from"three-shader-graph";import{isWgslCompiler as h,isWgslFragmentCompiler as d}from"three-shader-graph
|
|
1
|
+
import{abs as e,attributes as t,cross as n,dFdx as r,dFdy as a,float as i,normalize as l,select as s,transformed as p,UniformSampler2dArraySlice as f,uniforms as $,varying as o,Vec2Node as v,vec3 as u,vec4 as m}from"three-shader-graph";import{isWgslCompiler as h,isWgslFragmentCompiler as d}from"three-shader-graph";import{glslFunction as c}from"./glsl-node";export function computeTangent(e,t,i){const s=r(t),p=a(t),f=r(i),$=a(i),o=n(p,e),v=n(e,s),u=o.multiplyScalar(f.x).add(v.multiplyScalar($.x));return m(l(u),1)}export function fallbackTangent(t){const r=e(t.y),a=s(r.lt(i(.999)),u(0,1,0),u(1,0,0));return l(n(a,t))}const g=t.normal,S=o(l($.normalMatrix.multiplyVec(g))),x=o(p.mvPosition.xyz.multiplyScalar(-1));export function parallaxOcclusionMapping(e,t,n,r=8,a=24){return new y(e,t,n,r,a)}class y extends v{constructor(e,t,n,r,a){super(),this.uv=e,this.heightMap=t,this.heightScale=n,this.minLayers=r,this.maxLayers=a}compile(e){if(!h(e))return{out:e.get(this.compileGlsl())};if(!d(e))throw new Error("Parallax occlusion mapping requires fragment-stage derivatives in WGSL.");const t=`pom_${e.variable()}`,n=e.get(this.uv),r=e.get(this.heightMap),a=e.get(this.heightScale),l=e.get(S),s=e.get(x),p=e.get(i(this.minLayers)),f=e.get(i(this.maxLayers)),$=C(this.heightMap)?e.get(L(this.heightMap)):null;return{chunk:`\n let ${t}Uv = ${n};\n let ${t}Normal = normalize(${l});\n let ${t}ViewPosition = ${s};\n let ${t}ViewDirection = normalize(${t}ViewPosition);\n let ${t}Dp1 = dpdx(-${t}ViewPosition);\n // WGSL fragment coordinates have the opposite Y orientation from GLSL.\n // Negate both Y derivatives so the reconstructed cotangent frame keeps\n // the same handedness as the GLSL implementation.\n let ${t}Dp2 = -dpdy(-${t}ViewPosition);\n let ${t}Duv1 = dpdx(${t}Uv);\n let ${t}Duv2 = -dpdy(${t}Uv);\n let ${t}Dp2Perp = cross(${t}Dp2, ${t}Normal);\n let ${t}Dp1Perp = cross(${t}Normal, ${t}Dp1);\n let ${t}T = ${t}Dp2Perp * ${t}Duv1.x + ${t}Dp1Perp * ${t}Duv2.x;\n let ${t}B = ${t}Dp2Perp * ${t}Duv1.y + ${t}Dp1Perp * ${t}Duv2.y;\n let ${t}InvMax = inverseSqrt(max(dot(${t}T, ${t}T), dot(${t}B, ${t}B)));\n let ${t}Tbn = mat3x3<f32>(\n ${t}T * ${t}InvMax,\n ${t}B * ${t}InvMax,\n ${t}Normal\n );\n let ${t}Vv = -(transpose(${t}Tbn) * ${t}ViewDirection);\n let ${t}SafeVvZ = select(\n ${t}Vv.z,\n select(-0.0001, 0.0001, ${t}Vv.z >= 0.0),\n abs(${t}Vv.z) < 0.0001\n );\n let ${t}ParallaxLimit = (-length(${t}Vv.xy) / ${t}SafeVvZ) * ${a};\n let ${t}OffsetDirection = normalize(${t}Vv.xy);\n let ${t}MaxOffset = ${t}OffsetDirection * ${t}ParallaxLimit;\n let ${t}NumSamples = max(\n 1.0,\n mix(${f}, ${p}, dot(-${t}ViewDirection, ${t}Normal))\n );\n let ${t}StepSize = 1.0 / ${t}NumSamples;\n var ${t}CurrentRayHeight = 1.0;\n var ${t}CurrentOffset = vec2<f32>(0.0);\n var ${t}LastOffset = vec2<f32>(0.0);\n var ${t}LastSampledHeight = 1.0;\n var ${t}CurrentSampledHeight = 1.0;\n for (var ${t}SampleIndex: i32 = 0; ${t}SampleIndex < 24; ${t}SampleIndex = ${t}SampleIndex + 1) {\n if (f32(${t}SampleIndex) > ${t}NumSamples) {\n break;\n }\n ${t}CurrentSampledHeight = ${null==$?`textureSampleLevel(${r}Texture, ${r}Sampler, ${t}Uv + ${t}CurrentOffset, 0.0).r`:`textureSampleLevel(${r}Texture, ${r}Sampler, ${t}Uv + ${t}CurrentOffset, i32(${$}), 0.0).r`};\n if (${t}CurrentSampledHeight > ${t}CurrentRayHeight) {\n let ${t}Delta1 = ${t}CurrentSampledHeight - ${t}CurrentRayHeight;\n let ${t}Delta2 = (${t}CurrentRayHeight + ${t}StepSize) - ${t}LastSampledHeight;\n let ${t}Ratio = ${t}Delta1 / (${t}Delta1 + ${t}Delta2);\n ${t}CurrentOffset = ${t}Ratio * ${t}LastOffset + (1.0 - ${t}Ratio) * ${t}CurrentOffset;\n break;\n }\n ${t}CurrentRayHeight = ${t}CurrentRayHeight - ${t}StepSize;\n ${t}LastOffset = ${t}CurrentOffset;\n ${t}CurrentOffset = ${t}CurrentOffset + ${t}StepSize * ${t}MaxOffset;\n ${t}LastSampledHeight = ${t}CurrentSampledHeight;\n }\n let ${t}UvWithOffset = ${t}Uv + ${t}CurrentOffset;\n `,out:`${t}UvWithOffset`}}compileGlsl(){const e=C(this.heightMap)?L(this.heightMap):null,t=null==e?"texture2D(heightMap, uv + vCurrOffset).r":"texture(heightMap, vec3(uv + vCurrOffset, heightMapLayer)).r",n={uv:this.uv,heightScale:this.heightScale,heightMap:this.heightMap,minLayers:i(this.minLayers),maxLayers:i(this.maxLayers),vN:S,vViewPosition:x,...null==e?{}:{heightMapLayer:e}};return c(v,n,`\n vec3 N = normalize(vN);\n vec3 viewDir = normalize(vViewPosition);\n vec3 dp1 = dFdx(-vViewPosition);\n vec3 dp2 = dFdy(-vViewPosition);\n vec2 duv1 = dFdx(uv);\n vec2 duv2 = dFdy(uv);\n vec3 dp2perp = cross(dp2, N);\n vec3 dp1perp = cross(N, 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 tbn = mat3(T * invmax, B * invmax, N);\n vec3 vv = -viewDir * tbn;\n float parallaxLimit = -length(vv.xy) / vv.z;\n parallaxLimit *= heightScale;\n vec2 vOffsetDir = normalize(vv.xy);\n vec2 vMaxOffset = vOffsetDir * parallaxLimit;\n float nNumSamples = mix(float(maxLayers), float(minLayers), dot(-viewDir, N));\n float fStepSize = 1.0 / nNumSamples;\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 for (int nCurrSample = 0; nCurrSample < 24; nCurrSample++) {\n if (float(nCurrSample) > nNumSamples) break;\n fCurrSampledHeight = ${t};\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 return uv + vCurrOffset;\n `)}}function C(e){return e instanceof f||"sampler2DArray"===e.constructor.typeName}function L(e){return e.index??i(0)}/*
|
|
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{isWgslCompiler as e}from"three-shader-graph
|
|
1
|
+
import{isWgslCompiler as e}from"three-shader-graph";export function wgslFunction(n,t,o){const r=n.typeName;return new class extends n{compile(n){if(!e(n))throw new Error("GLSL cannot compile a wgslFunction body. Use glslFunction or shared nodes instead.");const s=`customFunction_${n.variable()}`,i=Object.entries(t).map(([e,t])=>`${e}: ${n.type(t.constructor.typeName)}`).join(", "),c=Object.values(t).map(e=>n.get(e)).join(", ");return n.addWgslDefinition(`fn ${s}(${i}) -> ${n.type(r)} {\n ${o}\n }`),{out:`${s}(${c})`}}}}/*
|
|
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{describe as a,expect as s,it as o,vi as i}from"vitest";i.hoisted(()=>{if("undefined"==typeof HTMLCanvasElement)return;const t=new Proxy({},{get:(t,e)=>(e in t||(t[e]=("string"!=typeof e||!e.startsWith("is"))&&i.fn()),t[e]),set:(t,e,a)=>(t[e]=a,!0)});Object.defineProperty(HTMLCanvasElement.prototype,"getContext",{configurable:!0,value:()=>t}),"undefined"==typeof AudioBuffer&&Object.defineProperty(globalThis,"AudioBuffer",{configurable:!0,value:class{}})}),i.mock("../gameplay/actors/builtin/index.js",()=>({default:{}})),i.mock("../effects/vfx/vfx-actor.js",()=>({VfxActor:class{}})),i.mock("../effects/vfx/vfx-param.js",()=>({VisualEffect:class{}})),i.mock("../rendering.js",()=>({RenderingView:class{},setRenderingPaused:i.fn()}));import{convertConfiguredParamValueToRuntimeType as r}from"../scene/custom-param-runtime-types.js";import{prepareClassParameters as n,prepareCustomParamsFromType as c}from"../scene/materializer.js";import{SerializedParamType as l}from"../scene/model.js";import{extractShaderParameters as u,getAssignableParameterDefinitions as p,isParameterDefinitionAbstract as m,Parameter as y,ParameterDefinition as d}from"../shader/parameter.js";let b=class{constructor(){this.damage=10,this.label="Slash"}kind(){return"attack"}};t([y({type:Number}),e("design:type",Object)],b.prototype,"damage",void 0),t([y({type:String}),e("design:type",Object)],b.prototype,"label",void 0),b=t([d("test.attack")],b);let g=class extends b{constructor(){super(...arguments),this.manaCost=5}kind(){return"magic"}};t([y({type:Number}),e("design:type",Object)],g.prototype,"manaCost",void 0),g=t([d("test.magicAttack")],g);let v=class{constructor(){this.amount=20}};t([y({type:Number}),e("design:type",Object)],v.prototype,"amount",void 0),v=t([d("test.heal")],v);class f{constructor(){this.attacks=[]}}t([y({type:()=>b,array:!0}),e("design:type",Array)],f.prototype,"attacks",void 0);class k{constructor(){this.attacks=[]}}t([y(),e("design:type",Array)],k.prototype,"attacks",void 0),Reflect.defineMetadata("design:type",Array,k.prototype,"attacks"),Reflect.defineMetadata("parameter:arrayElementType",b,k.prototype,"attacks");class B{constructor(){this.primaryAttack=new b}}t([y({type:()=>b}),e("design:type",Object)],B.prototype,"primaryAttack",void 0);let h=class{constructor(){this.cooldown=1}};t([y({type:Number}),e("design:type",Object)],h.prototype,"cooldown",void 0),h=t([d("test.ability",{abstract:!0})],h);let A=class extends h{constructor(){super(...arguments),this.manaCost=6}kind(){return"magicAbility"}};t([y({type:Number}),e("design:type",Object)],A.prototype,"manaCost",void 0),A=t([d("test.magicAbility")],A);class S{constructor(){this.ability=void 0}}t([y({type:()=>h}),e("design:type",h)],S.prototype,"ability",void 0);class j{constructor(){this.abilities=[]}}t([y({type:()=>h,array:!0}),e("design:type",Array)],j.prototype,"abilities",void 0);class w{constructor(){this.value=void 0}}var O,N;t([y({type:String}),e("design:type",Object)],w.prototype,"value",void 0),function(t){t[t.good=0]="good",t[t.bad=1]="bad"}(O||(O={})),function(t){t.good="good",t.bad="bad"}(N||(N={}));class C{constructor(){this.faction=O.bad,this.stringFaction=N.good}}t([y({enum:O}),e("design:type",Object)],C.prototype,"faction",void 0),t([y({enum:N}),e("design:type",Object)],C.prototype,"stringFaction",void 0);class E{}t([y({enum:N}),e("design:type",String)],E.prototype,"stringFaction",void 0);class z{constructor(){this.faction=O.good}}t([y(),e("design:type",Number)],z.prototype,"faction",void 0),Reflect.defineMetadata("parameter:enum",O,z.prototype,"faction"),a("parameter definitions",()=>{o("generates editor options from enum decorator options",()=>{const t=u(C),e=t.find(t=>"faction"===t.name),a=t.find(t=>"stringFaction"===t.name);s(e?.type).toBe(Number),s(e?.options.options).toEqual([{name:"Good",value:O.good},{name:"Bad",value:O.bad}]),s(a?.type).toBe(String),s(a?.options.options).toEqual([{name:"Good",value:N.good},{name:"Bad",value:N.bad}])}),o("prepares enum params as number or string custom values",()=>{const t=c(C,{});s(t.faction).toMatchObject({type:l.Number,value:O.bad}),s(t.stringFaction).toMatchObject({type:l.String,value:N.good})}),o("uses the first enum option as the default when no initializer is set",()=>{const t=c(E,{});s(t.stringFaction).toMatchObject({type:l.String,value:N.good})}),o("uses reflected enum metadata for direct enum parameter annotations",()=>{const[t]=u(z),e=c(z,{});s(t.type).toBe(Number),s(t.options.options).toEqual([{name:"Good",value:O.good},{name:"Bad",value:O.bad}]),s(e.faction).toMatchObject({type:l.Number,value:O.good})}),o("lists assignable parameter definitions with display labels",()=>{const t=p(b);s(t.map(t=>t.id)).toEqual(["test.attack","test.magicAttack"]),s(t.map(t=>t.label)).toEqual(["Attack","Magic Attack"]),s(t.some(t=>"test.heal"===t.id)).toBe(!1)}),o("lists concrete assignable definitions for abstract bases",()=>{const t=p(h);s(m(h)).toBe(!0),s(m("test.ability")).toBe(!0),s(t.map(t=>t.id)).toEqual(["test.magicAbility"]),s(t.map(t=>t.label)).toEqual(["Magic Ability"])}),o("serializes arrays of nested parameter definitions with stable definition ids",()=>{const t=c(f,{}).attacks;s(t.type).toBe(l.Array),s(t.element).toBe(l.Struct),s(t.elementStruct).toBe("test.attack"),s(t.value).toEqual([])}),o("uses reflected array element type metadata for parameter arrays",()=>{const[t]=u(k),e=c(k,{}).attacks;s(t.type).toBe(b),s(t.options.array).toBe(!0),s(e.type).toBe(l.Array),s(e.element).toBe(l.Struct),s(e.elementStruct).toBe("test.attack"),s(e.value).toEqual([])}),o("serializes nested parameter definition defaults",()=>{const t=c(B,{}).primaryAttack;s(t.type).toBe(l.Struct),s(t.struct).toBe("test.attack"),s(t.value.damage.value).toBe(10),s(t.value.label.value).toBe("Slash")}),o("uses an empty string for string parameters without explicit defaults",()=>{const t=c(w,{}).value;s(t.type).toBe(l.String),s(t.value).toBe("")}),o("serializes nested subclass defaults with concrete definition ids",()=>{class a{constructor(){this.primaryAttack=new g}}t([y({type:()=>b}),e("design:type",Object)],a.prototype,"primaryAttack",void 0);const o=c(a,{}).primaryAttack;s(o.type).toBe(l.Struct),s(o.struct).toBe("test.magicAttack"),s(o.value.damage.value).toBe(10),s(o.value.label.value).toBe("Slash"),s(o.value.manaCost.value).toBe(5)}),o("serializes abstract parameter definitions as unselected structs",()=>{const t=c(S,{}).ability;s(t.type).toBe(l.Struct),s(t.struct).toBe("test.ability"),s(t.value).toEqual({})}),o("serializes abstract base defaults with concrete subclass ids",()=>{class a{constructor(){this.ability=new A}}t([y({type:()=>h}),e("design:type",Object)],a.prototype,"ability",void 0);const o=c(a,{}).ability;s(o.type).toBe(l.Struct),s(o.struct).toBe("test.magicAbility"),s(o.value.cooldown.value).toBe(1),s(o.value.manaCost.value).toBe(6)}),o("preserves previously selected concrete definition ids when preparing params",()=>{const t=c(B,{primaryAttack:{type:l.Struct,struct:"test.magicAttack",value:{damage:{type:l.Number,value:22},manaCost:{type:l.Number,value:7}}}}).primaryAttack;s(t.struct).toBe("test.magicAttack"),s(t.value.damage.value).toBe(22),s(t.value.manaCost.value).toBe(7)}),o("materializes nested parameter definitions as class instances",async()=>{const t=await n({attacks:{type:l.Array,element:l.Struct,elementStruct:"test.attack",value:[{damage:{type:l.Number,value:25},label:{type:l.String,value:"Heavy Slash"}}]}},f,{},{});s(t.attacks).toHaveLength(1),s(t.attacks[0]).toBeInstanceOf(b),s(t.attacks[0].damage).toBe(25),s(t.attacks[0].label).toBe("Heavy Slash")}),o("materializes a selected subclass for a non-array base parameter",async()=>{const t=await n({primaryAttack:{type:l.Struct,struct:"test.magicAttack",value:{damage:{type:l.Number,value:30},label:{type:l.String,value:"Arcane Slash"},manaCost:{type:l.Number,value:12}}}},B,{},{});s(t.primaryAttack).toBeInstanceOf(g),s(t.primaryAttack.kind()).toBe("magic"),s(t.primaryAttack.damage).toBe(30),s(t.primaryAttack.manaCost).toBe(12)}),o("materializes a selected subclass for an abstract base parameter",async()=>{const t=await n({ability:{type:l.Struct,struct:"test.magicAbility",value:{cooldown:{type:l.Number,value:2},manaCost:{type:l.Number,value:9}}}},S,{},{});s(t.ability).toBeInstanceOf(A),s(t.ability.cooldown).toBe(2),s(t.ability.manaCost).toBe(9),s(t.ability.kind()).toBe("magicAbility")}),o("does not instantiate abstract parameter definitions",async()=>{const t=i.spyOn(console,"warn").mockImplementation(()=>{}),e=await n({ability:{type:l.Struct,struct:"test.ability",value:{}}},S,{},{});s(e.ability).toBeUndefined(),s(t).toHaveBeenCalledWith('Can not instantiate abstract parameter definition "test.ability"'),t.mockRestore()}),o("materializes compact and tagged struct array elements",async()=>{const t=await n({attacks:{type:l.Array,element:l.Struct,elementStruct:"test.attack",value:[{damage:{type:l.Number,value:15},label:{type:l.String,value:"Quick Slash"}},{struct:"test.magicAttack",value:{damage:{type:l.Number,value:45},label:{type:l.String,value:"Meteor"},manaCost:{type:l.Number,value:18}}}]}},f,{},{});s(t.attacks).toHaveLength(2),s(t.attacks[0]).toBeInstanceOf(b),s(t.attacks[0]).not.toBeInstanceOf(g),s(t.attacks[1]).toBeInstanceOf(g),s(t.attacks[1].damage).toBe(45),s(t.attacks[1].manaCost).toBe(18)}),o("materializes tagged struct array elements for abstract bases",async()=>{const t=await n({abilities:{type:l.Array,element:l.Struct,elementStruct:"test.ability",value:[{struct:"test.magicAbility",value:{cooldown:{type:l.Number,value:3},manaCost:{type:l.Number,value:11}}}]}},j,{},{});s(t.abilities).toHaveLength(1),s(t.abilities[0]).toBeInstanceOf(A),s(t.abilities[0].cooldown).toBe(3),s(t.abilities[0].manaCost).toBe(11)}),o("preserves compatible selected subclass ids during runtime normalization",()=>{const t=r({type:l.Struct,struct:"test.magicAttack",value:{manaCost:{type:l.Number,value:9}}},{type:l.Struct,struct:"test.attack"});s(t.struct).toBe("test.magicAttack")})});/*
|
|
1
|
+
import{__decorate as t,__metadata as e}from"tslib";import{describe as a,expect as s,it as o,vi as i}from"vitest";i.hoisted(()=>{if("undefined"==typeof HTMLCanvasElement)return;const t=new Proxy({},{get:(t,e)=>(e in t||(t[e]=("string"!=typeof e||!e.startsWith("is"))&&i.fn()),t[e]),set:(t,e,a)=>(t[e]=a,!0)});Object.defineProperty(HTMLCanvasElement.prototype,"getContext",{configurable:!0,value:()=>t}),"undefined"==typeof AudioBuffer&&Object.defineProperty(globalThis,"AudioBuffer",{configurable:!0,value:class{}})}),i.mock("../gameplay/actors/builtin/index.js",()=>({default:{}})),i.mock("../effects/vfx/vfx-actor.js",()=>({VfxActor:class{}})),i.mock("../effects/vfx/vfx-param.js",()=>({VisualEffect:class{}})),i.mock("../rendering.js",()=>({RenderingView:class{},setRenderingPaused:i.fn()}));import{convertConfiguredParamValueToRuntimeType as r}from"../scene/custom-param-runtime-types.js";import{prepareClassParameters as n,prepareCustomParamsFromType as c}from"../scene/materializer.js";import{SerializedParamType as l}from"../scene/model.js";import{extractShaderParameters as u,getAssignableParameterDefinitions as p,isParameterDefinitionAbstract as m,Parameter as y,ParameterDefinition as d}from"../shader/parameter.js";let b=class{constructor(){this.damage=10,this.label="Slash"}kind(){return"attack"}};t([y({type:Number}),e("design:type",Object)],b.prototype,"damage",void 0),t([y({type:String}),e("design:type",Object)],b.prototype,"label",void 0),b=t([d("test.attack")],b);let g=class extends b{constructor(){super(...arguments),this.manaCost=5}kind(){return"magic"}};t([y({type:Number}),e("design:type",Object)],g.prototype,"manaCost",void 0),g=t([d("test.magicAttack")],g);let v=class{constructor(){this.amount=20}};t([y({type:Number}),e("design:type",Object)],v.prototype,"amount",void 0),v=t([d("test.heal")],v);class f{constructor(){this.attacks=[]}}t([y({type:()=>b,array:!0}),e("design:type",Array)],f.prototype,"attacks",void 0);class k{constructor(){this.attacks=[]}}t([y(),e("design:type",Array)],k.prototype,"attacks",void 0),Reflect.defineMetadata("design:type",Array,k.prototype,"attacks"),Reflect.defineMetadata("parameter:arrayElementType",b,k.prototype,"attacks");class B{constructor(){this.primaryAttack=new b}}t([y({type:()=>b}),e("design:type",Object)],B.prototype,"primaryAttack",void 0);let h=class{constructor(){this.cooldown=1}};t([y({type:Number}),e("design:type",Object)],h.prototype,"cooldown",void 0),h=t([d("test.ability",{abstract:!0})],h);let A=class extends h{constructor(){super(...arguments),this.manaCost=6}kind(){return"magicAbility"}};t([y({type:Number}),e("design:type",Object)],A.prototype,"manaCost",void 0),A=t([d("test.magicAbility")],A);class S{constructor(){this.ability=void 0}}t([y({type:()=>h}),e("design:type",h)],S.prototype,"ability",void 0);class j{constructor(){this.abilities=[]}}t([y({type:()=>h,array:!0}),e("design:type",Array)],j.prototype,"abilities",void 0);class w{constructor(){this.value=void 0}}var O,N;t([y({type:String}),e("design:type",Object)],w.prototype,"value",void 0),function(t){t[t.good=0]="good",t[t.bad=1]="bad"}(O||(O={})),function(t){t.good="good",t.bad="bad"}(N||(N={}));class C{constructor(){this.faction=O.bad,this.stringFaction=N.good}}t([y({enum:O}),e("design:type",Object)],C.prototype,"faction",void 0),t([y({enum:N}),e("design:type",Object)],C.prototype,"stringFaction",void 0);class E{}t([y({enum:N}),e("design:type",String)],E.prototype,"stringFaction",void 0);class z{constructor(){this.faction=O.good}}t([y(),e("design:type",Number)],z.prototype,"faction",void 0),Reflect.defineMetadata("parameter:enum",O,z.prototype,"faction"),a("parameter definitions",()=>{o("generates editor options from enum decorator options",()=>{const t=u(C),e=t.find(t=>"faction"===t.name),a=t.find(t=>"stringFaction"===t.name);s(e?.type).toBe(Number),s(e?.options.options).toEqual([{name:"Good",value:O.good},{name:"Bad",value:O.bad}]),s(a?.type).toBe(String),s(a?.options.options).toEqual([{name:"Good",value:N.good},{name:"Bad",value:N.bad}])}),o("prepares enum params as number or string custom values",()=>{const t=c(C,{});s(t.faction).toMatchObject({type:l.Number,value:O.bad}),s(t.stringFaction).toMatchObject({type:l.String,value:N.good})}),o("uses the first enum option as the default when no initializer is set",()=>{const t=c(E,{});s(t.stringFaction).toMatchObject({type:l.String,value:N.good})}),o("uses reflected enum metadata for direct enum parameter annotations",()=>{const[t]=u(z),e=c(z,{});s(t.type).toBe(Number),s(t.options.options).toEqual([{name:"Good",value:O.good},{name:"Bad",value:O.bad}]),s(e.faction).toMatchObject({type:l.Number,value:O.good})}),o("lists assignable parameter definitions with display labels",()=>{const t=p(b);s(t.map(t=>t.id)).toEqual(["test.attack","test.magicAttack"]),s(t.map(t=>t.label)).toEqual(["Attack","Magic Attack"]),s(t.some(t=>"test.heal"===t.id)).toBe(!1)}),o("lists concrete assignable definitions for abstract bases",()=>{const t=p(h);s(m(h)).toBe(!0),s(m("test.ability")).toBe(!0),s(t.map(t=>t.id)).toEqual(["test.magicAbility"]),s(t.map(t=>t.label)).toEqual(["Magic Ability"])}),o("serializes arrays of nested parameter definitions with stable definition ids",()=>{const t=c(f,{}).attacks;s(t.type).toBe(l.Array),s(t.element).toBe(l.Struct),s(t.elementStruct).toBe("test.attack"),s(t.value).toEqual([])}),o("uses reflected array element type metadata for parameter arrays",()=>{const[t]=u(k),e=c(k,{}).attacks;s(t.type).toBe(b),s(t.options.array).toBe(!0),s(e.type).toBe(l.Array),s(e.element).toBe(l.Struct),s(e.elementStruct).toBe("test.attack"),s(e.value).toEqual([])}),o("serializes nested parameter definition defaults",()=>{const t=c(B,{}).primaryAttack;s(t.type).toBe(l.Struct),s(t.struct).toBe("test.attack"),s(t.value.damage.value).toBe(10),s(t.value.label.value).toBe("Slash")}),o("uses an empty string for string parameters without explicit defaults",()=>{const t=c(w,{}).value;s(t.type).toBe(l.String),s(t.value).toBe("")}),o("serializes nested subclass defaults with concrete definition ids",()=>{class a{constructor(){this.primaryAttack=new g}}t([y({type:()=>b}),e("design:type",Object)],a.prototype,"primaryAttack",void 0);const o=c(a,{}).primaryAttack;s(o.type).toBe(l.Struct),s(o.struct).toBe("test.magicAttack"),s(o.value.damage.value).toBe(10),s(o.value.label.value).toBe("Slash"),s(o.value.manaCost.value).toBe(5)}),o("serializes abstract parameter definitions as unselected structs",()=>{const t=c(S,{}).ability;s(t.type).toBe(l.Struct),s(t.struct).toBe("test.ability"),s(t.value).toEqual({})}),o("serializes abstract base defaults with concrete subclass ids",()=>{class a{constructor(){this.ability=new A}}t([y({type:()=>h}),e("design:type",Object)],a.prototype,"ability",void 0);const o=c(a,{}).ability;s(o.type).toBe(l.Struct),s(o.struct).toBe("test.magicAbility"),s(o.value.cooldown.value).toBe(1),s(o.value.manaCost.value).toBe(6)}),o("preserves previously selected concrete definition ids when preparing params",()=>{const t=c(B,{primaryAttack:{type:l.Struct,struct:"test.magicAttack",value:{damage:{type:l.Number,value:22},manaCost:{type:l.Number,value:7}}}}).primaryAttack;s(t.struct).toBe("test.magicAttack"),s(t.value.damage.value).toBe(22),s(t.value.label.value).toBe("Slash"),s(t.value.manaCost.value).toBe(7)}),o("backfills missing parameters in existing struct array elements",()=>{const t=c(f,{attacks:{type:l.Array,element:l.Struct,elementStruct:"test.attack",value:[{damage:{type:l.Number,value:25}}]}}).attacks.value[0];s(t.damage.value).toBe(25),s(t.label.value).toBe("Slash")}),o("materializes nested parameter definitions as class instances",async()=>{const t=await n({attacks:{type:l.Array,element:l.Struct,elementStruct:"test.attack",value:[{damage:{type:l.Number,value:25},label:{type:l.String,value:"Heavy Slash"}}]}},f,{},{});s(t.attacks).toHaveLength(1),s(t.attacks[0]).toBeInstanceOf(b),s(t.attacks[0].damage).toBe(25),s(t.attacks[0].label).toBe("Heavy Slash")}),o("materializes a selected subclass for a non-array base parameter",async()=>{const t=await n({primaryAttack:{type:l.Struct,struct:"test.magicAttack",value:{damage:{type:l.Number,value:30},label:{type:l.String,value:"Arcane Slash"},manaCost:{type:l.Number,value:12}}}},B,{},{});s(t.primaryAttack).toBeInstanceOf(g),s(t.primaryAttack.kind()).toBe("magic"),s(t.primaryAttack.damage).toBe(30),s(t.primaryAttack.manaCost).toBe(12)}),o("materializes a selected subclass for an abstract base parameter",async()=>{const t=await n({ability:{type:l.Struct,struct:"test.magicAbility",value:{cooldown:{type:l.Number,value:2},manaCost:{type:l.Number,value:9}}}},S,{},{});s(t.ability).toBeInstanceOf(A),s(t.ability.cooldown).toBe(2),s(t.ability.manaCost).toBe(9),s(t.ability.kind()).toBe("magicAbility")}),o("does not instantiate abstract parameter definitions",async()=>{const t=i.spyOn(console,"warn").mockImplementation(()=>{}),e=await n({ability:{type:l.Struct,struct:"test.ability",value:{}}},S,{},{});s(e.ability).toBeUndefined(),s(t).toHaveBeenCalledWith('Can not instantiate abstract parameter definition "test.ability"'),t.mockRestore()}),o("materializes compact and tagged struct array elements",async()=>{const t=await n({attacks:{type:l.Array,element:l.Struct,elementStruct:"test.attack",value:[{damage:{type:l.Number,value:15},label:{type:l.String,value:"Quick Slash"}},{struct:"test.magicAttack",value:{damage:{type:l.Number,value:45},label:{type:l.String,value:"Meteor"},manaCost:{type:l.Number,value:18}}}]}},f,{},{});s(t.attacks).toHaveLength(2),s(t.attacks[0]).toBeInstanceOf(b),s(t.attacks[0]).not.toBeInstanceOf(g),s(t.attacks[1]).toBeInstanceOf(g),s(t.attacks[1].damage).toBe(45),s(t.attacks[1].manaCost).toBe(18)}),o("materializes tagged struct array elements for abstract bases",async()=>{const t=await n({abilities:{type:l.Array,element:l.Struct,elementStruct:"test.ability",value:[{struct:"test.magicAbility",value:{cooldown:{type:l.Number,value:3},manaCost:{type:l.Number,value:11}}}]}},j,{},{});s(t.abilities).toHaveLength(1),s(t.abilities[0]).toBeInstanceOf(A),s(t.abilities[0].cooldown).toBe(3),s(t.abilities[0].manaCost).toBe(11)}),o("preserves compatible selected subclass ids during runtime normalization",()=>{const t=r({type:l.Struct,struct:"test.magicAttack",value:{manaCost:{type:l.Number,value:9}}},{type:l.Struct,struct:"test.attack"});s(t.struct).toBe("test.magicAttack")})});/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|