@hology/core 0.0.206 → 0.0.208
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/effects/sequence/sequence-data.d.ts +8 -3
- package/dist/effects/sequence/sequence-data.js +1 -1
- package/dist/effects/sequence/sequence-definitions.js +1 -1
- package/dist/effects/sequence/sequence-player.d.ts +4 -0
- package/dist/effects/sequence/sequence-player.js +1 -1
- package/dist/effects/sequence/sequence-value-lane.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-animation.js +1 -1
- package/dist/gameplay/actors/factory.d.ts +1 -0
- package/dist/gameplay/actors/factory.js +1 -1
- package/dist/gameplay/actors/internal/component-init.d.ts +1 -0
- package/dist/gameplay/actors/internal/component-init.js +1 -1
- package/dist/gameplay/animation/anim-sm.d.ts +2 -0
- package/dist/gameplay/animation/anim-sm.js +1 -1
- package/dist/gameplay/initiate.d.ts +3 -0
- package/dist/gameplay/initiate.js +1 -1
- package/dist/gameplay/services/world.js +1 -1
- package/dist/rendering/upscaling-pass.d.ts +95 -0
- package/dist/rendering/upscaling-pass.js +4 -0
- package/dist/rendering.d.ts +77 -1
- package/dist/rendering.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/materializer.d.ts +2 -0
- package/dist/scene/materializer.js +1 -1
- package/dist/scene/materials/water.js +1 -1
- package/dist/scene/runtime-asset-service.d.ts +2 -0
- package/dist/scene/runtime-asset-service.js +1 -1
- package/dist/scene/storage/storage.d.ts +3 -0
- package/dist/scene/storage/storage.js +1 -1
- package/dist/shader/builtin/landscape-composite-shader.d.ts +0 -1
- package/dist/shader/builtin/landscape-composite-shader.js +1 -1
- package/dist/shader/builtin/standard-shader.d.ts +13 -12
- package/dist/shader/builtin/standard-shader.js +1 -1
- package/dist/shader/builtin/toon-shader.d.ts +9 -7
- package/dist/shader/builtin/toon-shader.js +1 -1
- package/dist/shader/builtin/unlit-shader.d.ts +5 -4
- package/dist/shader/builtin/unlit-shader.js +1 -1
- package/dist/shader/graph/compiler.js +1 -1
- package/dist/shader/parameter.js +1 -1
- package/dist/shader-nodes/pom.js +1 -1
- package/dist/test/data-asset-definition.test.js +1 -1
- package/dist/test/parameter-definition.test.js +1 -1
- package/dist/test/runtime-asset-service.test.d.ts +2 -0
- package/dist/test/runtime-asset-service.test.js +4 -0
- package/dist/test/runtime-param-type-inference.test.js +1 -1
- package/dist/test/sequence-post-process.test.js +1 -1
- package/dist/test/sequence-property-parameters.test.js +1 -1
- package/dist/test/sequence-vfx.test.d.ts +2 -0
- package/dist/test/sequence-vfx.test.js +4 -0
- package/dist/test/shader-graph.test.js +1 -1
- package/dist/test/storage-case-collision.test.js +1 -1
- package/dist/test/world-lifecycle.test.d.ts +2 -0
- package/dist/test/world-lifecycle.test.js +4 -0
- package/package.json +2 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -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.primaryAttack=new b}}t([y({type:()=>b}),e("design:type",Object)],k.prototype,"primaryAttack",void 0);let B=class{constructor(){this.cooldown=1}};t([y({type:Number}),e("design:type",Object)],B.prototype,"cooldown",void 0),B=t([d("test.ability",{abstract:!0})],B);let h=class extends B{constructor(){super(...arguments),this.manaCost=6}kind(){return"magicAbility"}};t([y({type:Number}),e("design:type",Object)],h.prototype,"manaCost",void 0),h=t([d("test.magicAbility")],h);class A{constructor(){this.ability=void 0}}t([y({type:()=>B}),e("design:type",B)],A.prototype,"ability",void 0);class S{constructor(){this.abilities=[]}}t([y({type:()=>B,array:!0}),e("design:type",Array)],S.prototype,"abilities",void 0);class j{constructor(){this.value=void 0}}var w,O;t([y({type:String}),e("design:type",Object)],j.prototype,"value",void 0),function(t){t[t.good=0]="good",t[t.bad=1]="bad"}(w||(w={})),function(t){t.good="good",t.bad="bad"}(O||(O={}));class N{constructor(){this.faction=w.bad,this.stringFaction=O.good}}t([y({enum:w}),e("design:type",Object)],N.prototype,"faction",void 0),t([y({enum:O}),e("design:type",Object)],N.prototype,"stringFaction",void 0);class C{}t([y({enum:O}),e("design:type",String)],C.prototype,"stringFaction",void 0);class z{constructor(){this.faction=w.good}}t([y(),e("design:type",Number)],z.prototype,"faction",void 0),Reflect.defineMetadata("parameter:enum",w,z.prototype,"faction"),a("parameter definitions",()=>{o("generates editor options from enum decorator options",()=>{const t=u(N),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:w.good},{name:"Bad",value:w.bad}]),s(a?.type).toBe(String),s(a?.options.options).toEqual([{name:"Good",value:O.good},{name:"Bad",value:O.bad}])}),o("prepares enum params as number or string custom values",()=>{const t=c(N,{});s(t.faction).toMatchObject({type:l.Number,value:w.bad}),s(t.stringFaction).toMatchObject({type:l.String,value:O.good})}),o("uses the first enum option as the default when no initializer is set",()=>{const t=c(C,{});s(t.stringFaction).toMatchObject({type:l.String,value:O.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:w.good},{name:"Bad",value:w.bad}]),s(e.faction).toMatchObject({type:l.Number,value:w.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(B);s(m(B)).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("serializes nested parameter definition defaults",()=>{const t=c(k,{}).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(j,{}).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(A,{}).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 h}}t([y({type:()=>B}),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(k,{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}}}},k,{},{});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}}}},A,{},{});s(t.ability).toBeInstanceOf(h),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:{}}},A,{},{});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}}}]}},S,{},{});s(t.abilities).toHaveLength(1),s(t.abilities[0]).toBeInstanceOf(h),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.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")})});/*
|
|
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 s,it as t,vi as a}from"vitest";import{RuntimeAssetsService as n}from"../scene/runtime-asset-service.js";e("RuntimeAssetsService",()=>{t("shares concurrent asset list loads and reuses the loaded cache",async()=>{const e=[{id:"mesh-a",name:"Mesh A",type:"mesh"},{id:"material-a",name:"Material A",type:"material"}],t={getAssets:a.fn(async()=>(await new Promise(e=>setTimeout(e,5)),e)),getAsset:a.fn(),getScenes:a.fn(),getScene:a.fn(),getSceneData:a.fn()},i=new n(t);await Promise.all([i.getAssets(),i.getAssets()]),await i.getAssets(),s(t.getAssets).toHaveBeenCalledTimes(1)})});/*
|
|
2
|
+
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
|
+
* See the LICENSE.md file for details.
|
|
4
|
+
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{expect as e,test as t,vi as
|
|
1
|
+
import{expect as e,test as t,vi as a}from"vitest";import{Vector3 as r}from"three";import{rgb as o,UniformSampler2d as p}from"three-shader-graph";a.mock("three/examples/jsm/Addons.js",()=>({BufferGeometryUtils:{},ConvexHull:class{},SkeletonUtils:{clone:e=>e}}));import{convertConfiguredParamsToRuntimeTypes as n,convertConfiguredParamValueToRuntimeType as s,inferRuntimeSerializedParamTypeHint as i}from"../scene/custom-param-runtime-types.js";import{SerializedParamType as c}from"../scene/model.js";class m{constructor(){this.tint=o("white"),this.direction=new r(1,1,1),this.map=new p("map")}}t("runtime parameter type inference uses class instance default values",()=>{e(i((new m).tint)?.type).toBe(c.RgbNode),e(i((new m).direction)?.type).toBe(c.Vector3),e(i((new m).map)?.type).toBe(c.Sampler2DNode)}),t("configured params can be retargeted to inferred runtime types",()=>{const t=new m,{params:a,skipped:r}=n({tint:{type:c.Color,value:"#336699"},direction:{type:c.Number,value:.5}},{parameterTarget:t});e(r).toEqual([]),e(a.tint).toMatchObject({type:c.RgbNode,value:"#336699"}),e(a.direction).toMatchObject({type:c.Vector3,value:[.5,.5,.5]})}),t("stored texture params can be retargeted to sampler node params",()=>{const{params:t,skipped:a}=n({map:{type:c.Texture,value:"texture-asset-id"}},{parameterTarget:new m});e(a).toEqual([]),e(t.map).toMatchObject({type:c.Sampler2DNode,value:"texture-asset-id"})}),t("configured params are normalized when stored type changed but value shape did not",()=>{const t=s({type:c.Vector3,value:.5},{type:c.Vector3});e(t).toMatchObject({type:c.Vector3,value:[.5,.5,.5]})}),t("configured params that cannot be safely coerced are skipped",()=>{const t=new m,a=s({type:c.Texture,value:"texture-asset-id"},i(t.direction));e(a).toBeNull()}),t("runtime type conversion caches extracted parameter metadata",()=>{const t=a.fn(()=>[{name:"direction",type:r,options:{}}]),o=a.fn(()=>c.Vector3),p={direction:{type:c.Number,value:.5}};n(p,{parameterType:m,extractPropertyParameters:t,toSerializedParamType:o}),n(p,{parameterType:m,extractPropertyParameters:t,toSerializedParamType:o}),e(t).toHaveBeenCalledTimes(1),e(o).toHaveBeenCalledTimes(1)}),t("runtime type conversion can be disabled",()=>{const t={direction:{type:c.Number,value:.5}},{params:a,skipped:r}=n(t,{parameterTarget:new m,applyRuntimeParamTypeInference:!1});e(a).toBe(t),e(a.direction).toMatchObject({type:c.Number,value:.5}),e(r).toEqual([])});/*
|
|
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{describe as e,expect as s,it as
|
|
1
|
+
import{describe as e,expect as s,it as a,vi as t}from"vitest";import*as r from"three";import{createMaterialSubTrack as o,createPostProcessClipInstance as n,createPostProcessTrack as i,createPropertyKeyframe as c,createSequenceData as l}from"../effects/sequence/sequence-data.js";import{createDefaultPostProcessShaderGraphDocument as p,shaderGraphPostProcessWeightUniformName as d}from"../shader/graph/index.js";import{shaderParameterUniformName as u}from"../shader/parameter.js";import{UniformFloatNode as f}from"../shader-nodes/index.js";import{SerializedParamType as m}from"../scene/model.js";async function h(e,s){const{SequencePlayer:a}=await import("../effects/sequence/sequence-player.js"),t=new a;return t.setWorld({scene:new r.Scene}),t.setViewController(e),t.setAssetLoader(s),t}function y(e,s,a){const t=l();t.duration=Math.max(2,s+a+.25);const r=i(),o=n(s,a);return o.shaderGraphAssetId=e,r.clips.push(o),t.tracks.push(r),{sequence:t,track:r,clip:o}}function v(e,s={}){return{clearCacheById:t.fn(),getShaderGraphByAssetId:t.fn().mockResolvedValue(e),prepareShaderGraphParameters:t.fn().mockResolvedValue(s)}}function w(){const e=[],s=t.fn((s,a={})=>{const r={material:s,enabled:a.enabled??!0,priority:a.priority??0,stage:a.stage??"beforeOutput",dispose:t.fn()};return e.push(r),r});return{handles:e,addPostProcessEffect:s,clearCameraShakeContributionsForOwner:t.fn(),releaseCameraOverridesForOwner:t.fn(),pushCameraOverride:t.fn(),setCameraShakeContribution:t.fn()}}function C(e){return e.material.uniforms[d].value}async function g(e=6){for(let s=0;s<e;s++)await Promise.resolve()}t.mock("../gameplay/actors/builtin/index.js",()=>({builtInActors:{},default:{}})),t.mock("../gameplay/actors/index.js",()=>({CharacterAnimationComponent:class{},CharacterMovementComponent:class{}})),t.mock("../effects/vfx/vfx-actor.js",()=>({VfxActor:class{}})),t.mock("../effects/vfx/vfx-param.js",()=>({VisualEffect:class{}})),t.mock("../effects/vfx/vfx-service.js",()=>({VfxService:class{}})),t.hoisted(()=>{if("undefined"==typeof HTMLCanvasElement)return;const e=new Proxy({},{get:(e,s)=>(s in e||(e[s]=("string"!=typeof s||!s.startsWith("is"))&&t.fn()),e[s]),set:(e,s,a)=>(e[s]=a,!0)});Object.defineProperty(HTMLCanvasElement.prototype,"getContext",{configurable:!0,value:()=>e})}),e("sequence post-process tracks",()=>{a("registers active post-process clips with the view controller",async()=>{const e=p(),a=w(),t=await h(a,v(e)),{clip:r,sequence:o}=y("graph-asset",0,1);t.load(o),t.play(),await g(),s(a.addPostProcessEffect).toHaveBeenCalledTimes(1),s(a.addPostProcessEffect).toHaveBeenCalledWith(s.anything(),s.objectContaining({stage:"beforeOutput",priority:0,enabled:!0})),s(a.handles[0].material.uniforms[d]).toBeTruthy(),s(r.shaderGraphAssetId).toBe("graph-asset")}),a("updates post-process blend weight from clip fades",async()=>{const e=p(),a=w(),t=await h(a,v(e)),{clip:r,sequence:o}=y("graph-asset",0,2);r.fadeInDuration=.5,r.fadeOutDuration=.5,t.load(o),t.play(),await g(),t.seek(.25),s(C(a.handles[0])).toBeCloseTo(.5),t.seek(1),s(C(a.handles[0])).toBeCloseTo(1),t.seek(1.75),s(C(a.handles[0])).toBeCloseTo(.5)}),a("animates shader graph parameters on active post-process clips",async()=>{const e=(a="intensity",{...p(),parameters:[{id:a,name:a,type:"float",defaultValue:0}],nodes:[{id:a,kind:"input.parameter",label:"Parameter",params:{parameter:a}}],edges:[],outputs:{color:{input:{nodeId:a,port:"value"}}}});var a;const t=u("intensity"),r=w(),n=await h(r,v(e,{intensity:new f(t,0,void 0,!1)})),{sequence:i,track:l}=y("graph-asset",0,1),d=o({materialMatchMode:"parameterName",materialAssetId:null,parameterName:"intensity",uniformName:t,uniformType:m.FloatNode,valueType:m.Number});d.keyframes.push(c(0,{type:m.Number,value:0}),c(1,{type:m.Number,value:1})),l.subTracks.push(d),n.load(i),n.play(),await g(),n.seek(.5),s(r.handles[0].material.uniforms[t].value).toBeCloseTo(.5)}),a("disposes post-process handles when clips exit and when stopped",async()=>{const e=p(),a=w(),t=await h(a,v(e)),{sequence:r}=y("graph-asset",0,1);t.load(r),t.play(),await g();const o=a.handles[0];t.seek(1.1),s(o.dispose).toHaveBeenCalledTimes(1),t.seek(.1),await g();const n=a.handles[1];t.stop(),s(n.dispose).toHaveBeenCalledTimes(1)}),a("does not register stale async post-process loads after stop",async()=>{const e=function(){let e;return{promise:new Promise(s=>{e=s}),resolve:e}}(),a=w(),t=await h(a,v(e.promise)),{sequence:r}=y("graph-asset",0,1);t.load(r),t.play(),t.stop(),e.resolve(p()),await g(),s(a.addPostProcessEffect).not.toHaveBeenCalled()})});/*
|
|
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{beforeAll as e,describe as
|
|
1
|
+
import{beforeAll as e,describe as a,expect as t,it as o,vi as r}from"vitest";import{BoxGeometry as s,Color as l,Euler as n,Mesh as i,Object3D as m,ShaderMaterial as u,Vector3 as p}from"three";import{createMaterialSubTrack as c,createPropertyKeyframe as f,createPropertySubTrack as y,createSpawnTrack as v}from"../effects/sequence/sequence-data.js";import{canTrackAddSubTrack as d}from"../effects/sequence/sequence-definitions.js";import{evaluateCustomParamValueKeyframes as b}from"../effects/sequence/sequence-value-lane.js";import{SerializedParamType as g}from"../scene/model.js";import{shaderParameterUniformName as w}from"../shader/parameter.js";let B;function N(){return new B}r.mock("../gameplay/actors/builtin/index.js",()=>({builtInActors:{},default:{}})),r.mock("../gameplay/actors/index.js",()=>({CharacterAnimationComponent:class{},CharacterMovementComponent:class{}})),r.mock("../effects/vfx/vfx-actor.js",()=>({VfxActor:class{}})),r.mock("../effects/vfx/vfx-param.js",()=>({VisualEffect:class{}})),r.mock("../effects/vfx/vfx-service.js",()=>({VfxService:class{}})),r.mock("../gameplay/services/render.js",()=>({})),r.hoisted(()=>{if("undefined"==typeof HTMLCanvasElement)return;const e=new Proxy({},{get:(e,a)=>(a in e||(e[a]=r.fn()),e[a]),set:(e,a,t)=>(e[a]=t,!0)});Object.defineProperty(HTMLCanvasElement.prototype,"getContext",{configurable:!0,value:()=>e})}),e(async()=>{const e=await import("../effects/sequence/sequence-player.js");B=e.SequencePlayer},1e4),a("sequence property parameter tracks",()=>{o("allows multiple property sub-tracks on spawn tracks but rejects duplicate property paths",()=>{const e=v(),a=y({propertyPath:"settings.globalGain",propertyType:g.Vector3});t(d(e,"property",{propertyPath:"settings.globalGain"})).toBe(!0),e.subTracks.push(a),t(d(e,"property",{propertyPath:"settings.globalGain"})).toBe(!1),t(d(e,"property",{propertyPath:"settings.globalGamma"})).toBe(!0)}),o("creates material sub-tracks for uniform-backed parameters and rejects duplicates",()=>{const e=v(),a={materialAssetId:"mat-1",parameterName:"dissolveAmount",uniformName:w("dissolveAmount"),uniformType:g.FloatNode,valueType:g.Number,label:"Dissolve Amount",defaultValue:{type:g.Number,value:0}},o=c(a);t(o).toMatchObject({type:"material",materialMatchMode:"asset",materialAssetId:"mat-1",parameterName:"dissolveAmount",uniformName:"pu_dissolveAmount",uniformType:g.FloatNode,valueType:g.Number,label:"Dissolve Amount"}),t(d(e,"material",{material:a})).toBe(!0),e.subTracks.push(o),t(d(e,"material",{material:a})).toBe(!1),t(d(e,"material",{material:{...a,parameterName:"rimPower",uniformName:w("rimPower")}})).toBe(!0)}),o("allows name-matched material sub-tracks as an alternative to asset-specific material tracks",()=>{const e=v(),a={materialAssetId:"mat-1",parameterName:"hitGlow",uniformName:w("hitGlow"),uniformType:g.FloatNode,valueType:g.Number},o={...a,materialAssetId:null,materialMatchMode:"parameterName"},r=c(o);t(r).toMatchObject({type:"material",materialMatchMode:"parameterName",materialAssetId:null,parameterName:"hitGlow"}),t(d(e,"material",{material:o})).toBe(!0),e.subTracks.push(r),t(d(e,"material",{material:a})).toBe(!1),t(d(e,"material",{material:{...a,parameterName:"rimPower",uniformName:w("rimPower")}})).toBe(!0);const s=v();s.subTracks.push(c(a)),t(d(s,"material",{material:{...a,materialAssetId:"mat-2"}})).toBe(!0),t(d(s,"material",{material:o})).toBe(!1)}),o("interpolates number, vector, color, and Euler property keyframes",()=>{const e=b([f(0,{type:g.Number,value:0}),f(1,{type:g.Number,value:10})],.5);t(e?.value).toBeCloseTo(5);const a=b([f(0,{type:g.Vector3,value:[0,0,0]}),f(1,{type:g.Vector3,value:[2,4,6]})],.5,{min:0,max:3});t(a?.value).toEqual([1,2,3]);const o=b([f(0,{type:g.Color,value:"#000000"}),f(1,{type:g.Color,value:"#ffffff"})],.5);t(o?.value).toBe(`#${new l("#000000").lerp(new l("#ffffff"),.5).getHexString()}`);const r=b([f(0,{type:g.Euler,value:[0,0,0,"XYZ"]}),f(1,{type:g.Euler,value:[1,2,3,"XYZ"]})],.5);t(r?.value).toEqual([.5,1,1.5,"XYZ"])}),o("uses step evaluation for booleans and options-backed values",()=>{const e=b([f(0,{type:g.Boolean,value:!1}),f(1,{type:g.Boolean,value:!0})],.5,{stepOnly:!0});t(e?.value).toBe(!1);const a=b([f(0,{type:g.Number,value:1}),f(1,{type:g.Number,value:2})],.5,{stepOnly:!0});t(a?.value).toBe(1)}),o("applies nested property paths and restores an original undefined value",async()=>{const e={settings:{globalGain:void 0}},a=y({propertyPath:"settings.globalGain",propertyType:g.Vector3}),o=await N();o.applyResolvedPropertyValue(a,e,{type:g.Vector3,value:[1,2,3]}),t(e.settings.globalGain).toBeInstanceOf(p),t(e.settings.globalGain?.toArray()).toEqual([1,2,3]),o.stop(),t(Object.prototype.hasOwnProperty.call(e.settings,"globalGain")).toBe(!0),t(e.settings.globalGain).toBeUndefined()}),o("mutates existing mutable values and restores their original value",async()=>{const e=new p(9,8,7),a=new l("#112233"),o=new n(.1,.2,.3,"XYZ"),r={settings:{globalGain:e,colorTint:a,rotation:o}},s=await N();s.applyResolvedPropertyValue(y({propertyPath:"settings.globalGain",propertyType:g.Vector3}),r,{type:g.Vector3,value:[1,2,3]}),s.applyResolvedPropertyValue(y({propertyPath:"settings.colorTint",propertyType:g.Color}),r,{type:g.Color,value:"#ffffff"}),s.applyResolvedPropertyValue(y({propertyPath:"settings.rotation",propertyType:g.Euler}),r,{type:g.Euler,value:[1,2,3,"XYZ"]}),t(r.settings.globalGain).toBe(e),t(r.settings.globalGain.toArray()).toEqual([1,2,3]),t(r.settings.colorTint).toBe(a),t(r.settings.colorTint.getHexString()).toBe("ffffff"),t(r.settings.rotation).toBe(o),t(r.settings.rotation.toArray()).toEqual([1,2,3,"XYZ"]),s.stop(),t(r.settings.globalGain).toBe(e),t(r.settings.globalGain.toArray()).toEqual([9,8,7]),t(r.settings.colorTint).toBe(a),t(r.settings.colorTint.getHexString()).toBe("112233"),t(r.settings.rotation).toBe(o),t(r.settings.rotation.toArray()).toEqual([.1,.2,.3,"XYZ"])}),o("clones matched materials before animating uniforms and restores originals",async()=>{const e=w("dissolveAmount"),a=new u({uniforms:{[e]:{value:0}}});a.userData.assetId="mat-1";const o=new i(new s,a),r=c({materialAssetId:"mat-1",parameterName:"dissolveAmount",uniformName:e,uniformType:g.FloatNode,valueType:g.Number});r.keyframes=[f(0,{type:g.Number,value:0}),f(1,{type:g.Number,value:1})];const l=await N();l.evaluateParameterSubTrack(r,o,.5),t(o.material).not.toBe(a),t(a.uniforms[e].value).toBe(0),t(o.material.uniforms[e].value).toBeCloseTo(.5),l.stop(),t(o.material).toBe(a)}),o("can match material tracks by parameter name across different material assets",async()=>{const e=w("hitGlow"),a=new u({uniforms:{[e]:{value:0}}});a.userData.assetId="mat-1";const o=new u({uniforms:{[e]:{value:0}}});o.userData.assetId="mat-2";const r=new u({uniforms:{[w("otherGlow")]:{value:0}}});r.userData.assetId="mat-3";const l=new i(new s,a),n=new i(new s,o),p=new i(new s,r),f=new m;f.add(l,n,p);const y=c({materialMatchMode:"parameterName",parameterName:"hitGlow",uniformName:e,uniformType:g.FloatNode,valueType:g.Number}),v=await N();v.applyResolvedMaterialValue(y,f,{type:g.Number,value:.75}),t(l.material).not.toBe(a),t(n.material).not.toBe(o),t(p.material).toBe(r),t(a.uniforms[e].value).toBe(0),t(o.uniforms[e].value).toBe(0),t(l.material.uniforms[e].value).toBeCloseTo(.75),t(n.material.uniforms[e].value).toBeCloseTo(.75),v.stop(),t(l.material).toBe(a),t(n.material).toBe(o)}),o("interpolates string-backed number material keyframes before applying uniforms",async()=>{const e=w("dissolveAmount"),a=new u({uniforms:{[e]:{value:0}}});a.userData.assetId="mat-1";const o=new i(new s,a),r=c({materialAssetId:"mat-1",parameterName:"dissolveAmount",uniformName:e,uniformType:g.FloatNode,valueType:g.Number});r.keyframes=[f(0,{type:g.Number,value:"0"}),f(1,{type:g.Number,value:"1"})];(await N()).evaluateParameterSubTrack(r,o,.5),t(o.material.uniforms[e].value).toBeCloseTo(.5)}),o("applies color material keyframes to vec3 uniform storage",async()=>{const e=w("rimColor"),a=new u({uniforms:{[e]:{value:new p(0,0,0)}}});a.userData.assetId="mat-1";const o=new i(new s,a),r=c({materialAssetId:"mat-1",parameterName:"rimColor",uniformName:e,uniformType:g.RgbNode,valueType:g.Color});(await N()).applyResolvedMaterialValue(r,o,{type:g.Color,value:"#336699"});const n=o.material.uniforms[e].value,m=new l("#336699");t(n.x).toBeCloseTo(m.r),t(n.y).toBeCloseTo(m.g),t(n.z).toBeCloseTo(m.b)}),o("step-evaluates boolean material keyframes",async()=>{const e=w("enabled"),a=new u({uniforms:{[e]:{value:!1}}});a.userData.assetId="mat-1";const o=new i(new s,a),r=c({materialAssetId:"mat-1",parameterName:"enabled",uniformName:e,uniformType:g.BooleanNode,valueType:g.Boolean});r.keyframes=[f(0,{type:g.Boolean,value:!1}),f(1,{type:g.Boolean,value:!0})];(await N()).evaluateParameterSubTrack(r,o,.5),t(o.material.uniforms[e].value).toBe(!1)})});/*
|
|
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*as e from"three";import{describe as s,expect as t,it as a,vi as n}from"vitest";import{createSequenceData as c,createVfxClipInstance as r,createVfxTrack as o}from"../effects/sequence/sequence-data.js";import{SequencePlayer as l}from"../effects/sequence/sequence-player.js";function i(){return{object:new e.Object3D,restart:n.fn(),play:n.fn(),pause:n.fn(),stop:n.fn(),getParticleCount:n.fn(()=>0)}}async function f(){await Promise.resolve(),await Promise.resolve()}n.mock("../gameplay/actors/builtin/index.js",()=>({builtInActors:{},default:{}})),n.mock("../gameplay/actors/index.js",()=>({CharacterAnimationComponent:class{},CharacterMovementComponent:class{}})),n.mock("../effects/vfx/vfx-actor.js",()=>({VfxActor:class{}})),n.mock("../effects/vfx/vfx-param.js",()=>({VisualEffect:class{}})),n.mock("../effects/vfx/vfx-service.js",()=>({VfxService:class{}})),n.hoisted(()=>{if("undefined"==typeof HTMLCanvasElement)return;const e=new Proxy({},{get:(e,s)=>(s in e||(e[s]=("string"!=typeof s||!s.startsWith("is"))&&n.fn()),e[s]),set:(e,s,t)=>(e[s]=t,!0)});Object.defineProperty(HTMLCanvasElement.prototype,"getContext",{configurable:!0,value:()=>e})}),s("sequence VFX tracks",()=>{a("restarts an already-active VFX clip when seeking backwards within the clip",async()=>{const s=i(),a=new l;a.setWorld({scene:new e.Scene}),a.setVfxService({createFromAssetId:n.fn(async()=>s)});const p=c();p.duration=2;const m=o(),d=r("vfx-asset",0,1.5);m.clips.push(d),p.tracks.push(m),a.load(p),a.play(),await f(),a.seek(1),s.restart.mockClear(),s.play.mockClear(),a.seek(.25),t(s.restart).toHaveBeenCalledTimes(1),t(s.play).toHaveBeenCalledTimes(1)}),a("restarts active VFX clips when a looping sequence wraps to the start",async()=>{const s=i(),a=new l;a.setWorld({scene:new e.Scene}),a.setVfxService({createFromAssetId:n.fn(async()=>s)});const p=c();p.duration=1,p.loop=!0;const m=o(),d=r("vfx-asset",0,1);m.clips.push(d),p.tracks.push(m),a.load(p),a.play(),await f(),s.restart.mockClear(),s.play.mockClear(),a.update(1.1),t(s.restart).toHaveBeenCalledTimes(1),t(s.play).toHaveBeenCalledTimes(1)}),a("clears VFX particles when seeking backwards before the clip starts",async()=>{const s=i(),a=new l;a.setWorld({scene:new e.Scene}),a.setVfxService({createFromAssetId:n.fn(async()=>s)});const p=c();p.duration=2;const m=o(),d=r("vfx-asset",.5,1);m.clips.push(d),p.tracks.push(m),a.load(p),a.play(),a.seek(.75),await f(),s.restart.mockClear(),s.stop.mockClear(),s.pause.mockClear(),a.seek(.25),t(s.restart).toHaveBeenCalledTimes(1),t(s.stop).toHaveBeenCalled(),t(s.pause).toHaveBeenCalledTimes(1)})});/*
|
|
2
|
+
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
|
+
* See the LICENSE.md file for details.
|
|
4
|
+
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{expect as e,test as t,vi as o}from"vitest";import{DoubleSide as a,FrontSide as r,Texture as n}from"three";o.hoisted(()=>{if("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}),"undefined"==typeof AudioBuffer&&Object.defineProperty(globalThis,"AudioBuffer",{configurable:!0,value:class{}})}),o.mock("three/examples/jsm/Addons.js",async e=>({...await e(),ConvexHull:class{},SkeletonUtils:{clone:e=>e},RectAreaLightHelper:class{}})),o.mock("three-shader-graph",async e=>{const t=await e();return{...t,rgb:(e,o,a)=>null==o&&null==a&&!0===e?.isColor&&"function"==typeof e.getHexString?t.rgb("#"+e.getHexString()):t.rgb(e,o,a)}}),o.mock("../rendering.js",()=>({RenderingView:class{constructor(){this._id="test",this.csm={setupMaterial:o.fn()}}getEnvTexture(e){return e}},setRenderingPaused:o.fn()}));import{materialFromAsset as s,prepareCustomParamsFromShaderGraph as d,prepareShaderGraphParameters as p}from"../scene/materializer.js";import{SerializedParamType as u}from"../scene/model.js";import{AssetsProvider as l}from"../scene/assets-provider.js";import{AssetResourceLoader as i}from"../scene/asset-resource-loader.js";import{buildShaderGraphMaterial as c,buildShaderGraphPostProcessMaterial as m,compileShaderGraph as v,compileShaderGraphPreview as f,createDefaultPostProcessShaderGraphDocument as h,createDefaultShaderGraphDocument as y,createDefaultVfxShaderGraphDocument as g,shaderGraphPostProcessWeightUniformName as I,shaderGraphParametersToPropertyParameters as b}from"../shader/graph/index.js";import{NodeShaderMaterial as B,textureSampler2d as k}from"../shader-nodes/index.js";import{sceneMapUniformName as x}from"../shader-nodes/scene-sample.js";function T(e,t,o){return{version:1,target:"surface",parameters:[],nodes:e,edges:t,outputs:o}}function w(e,t){return{id:e,name:e,type:"material",material:{type:"shaderGraph",side:r,params:{},shaderParams:{},shaderGraph:t}}}t("graph validation rejects missing nodes, invalid ports, and incompatible edges",()=>{const t=y();t.outputs.color={input:{nodeId:"missing",port:"value"}},e(()=>v(t)).toThrow(/Missing shader graph node/);const o=y();o.outputs.color={input:{nodeId:"base-color",port:"missing"}},e(()=>v(o)).toThrow(/does not have output/);const a=T([{id:"a",kind:"constant.vec2",params:{value:[1,1]}},{id:"b",kind:"constant.vec3",params:{value:[1,1,1]}},{id:"add",kind:"math.add"}],[{from:{nodeId:"a",port:"value"},to:{nodeId:"add",port:"a"}},{from:{nodeId:"b",port:"value"},to:{nodeId:"add",port:"b"}}],{color:{input:{nodeId:"add",port:"value"}}});e(()=>v(a)).toThrow(/Cannot add vec2 and vec3/)}),t("surface graph compiles to NodeShaderOutput",()=>{const t=v(y("surface"));e(t.output.color).toBeTruthy(),e(t.output.transparent).toBe(!1)}),t("inline literal inputs compile without separate constant nodes",()=>{const t=T([{id:"uv",kind:"builtin.uv"},{id:"scale-uv",kind:"math.multiply",inputs:{b:{value:2,valueType:"float"}}},{id:"rotate",kind:"uv.rotate",inputs:{angle:{value:.5,valueType:"float"},center:{value:[.25,.75],valueType:"vec2"}}},{id:"translate",kind:"transform.translate",inputs:{offset:{value:[0,1,0],valueType:"vec3"}}}],[{from:{nodeId:"uv",port:"value"},to:{nodeId:"scale-uv",port:"a"}},{from:{nodeId:"scale-uv",port:"value"},to:{nodeId:"rotate",port:"uv"}}],{color:{input:{nodeId:"rotate",port:"value"}},transform:{input:{nodeId:"translate",port:"value"}}}),o=v(t);e(o.nodes.get("scale-uv")?.outputs.value.type).toBe("vec2"),e(o.nodes.get("rotate")?.outputs.value.type).toBe("vec2"),e(o.nodes.get("translate")?.outputs.value.type).toBe("mat4"),e(o.output.color).toBeTruthy(),e(o.output.transform).toBeTruthy()}),t("sprite graph compiles with sprite-compatible material output",()=>{const t=y("sprite"),o=v(t);e(o.output.color).toBeTruthy(),e(o.output.transparent).toBe(!0)}),t("default VFX shader graphs compile mapped targets and build non-sprite materials",()=>{for(const t of["sprite","surface","decal","trail"]){const o=g(t);if(e(v(o).output.color).toBeTruthy(),"sprite"===t)continue;const a=c(o,{trailBillboard:"trail"===t});e(a.isMaterial).toBe(!0)}}),t("graph material options apply to supported material targets",()=>{const t=y("surface");t.materialOptions={side:"double",transparent:!0};const o=c(t);e(o.side).toBe(a),e(o.transparent).toBe(!0);const r=y("decal");r.materialOptions={transparent:!0};const n=c(r);e(n.transparent).toBe(!0)}),t("standard graph compiles extended material outputs and vertex transform",()=>{const t=T([{id:"metalness",kind:"constant.float",params:{value:.8}},{id:"ao",kind:"constant.float",params:{value:.5}},{id:"sheen",kind:"constant.vec3",params:{value:[.1,.2,.3]}},{id:"offset",kind:"constant.vec3",params:{value:[0,1,0]}},{id:"translate",kind:"transform.translate"}],[{from:{nodeId:"offset",port:"value"},to:{nodeId:"translate",port:"offset"}}],{metalness:{input:{nodeId:"metalness",port:"value"}},ambientOcclusion:{input:{nodeId:"ao",port:"value"}},sheenColor:{input:{nodeId:"sheen",port:"value"}},transform:{input:{nodeId:"translate",port:"value"}}}),o=v(t);e(o.output.metalness).toBeTruthy(),e(o.output.ambientOcclusion).toBeTruthy(),e(o.output.sheenColor).toBeTruthy(),e(o.output.transform).toBeTruthy();const a=c(t);e(a.outputMetalness).toBeTruthy(),e(a.outputAmbientOcclusion).toBeTruthy(),e(a.outputTransform).toBeTruthy()}),t("math multiply composes transform matrices",()=>{const t=T([{id:"translate",kind:"transform.translate",inputs:{offset:{value:[0,1,0],valueType:"vec3"}}},{id:"scale",kind:"transform.scale",inputs:{scale:{value:[2,2,2],valueType:"vec3"}}},{id:"compose",kind:"math.multiply"}],[{from:{nodeId:"translate",port:"value"},to:{nodeId:"compose",port:"a"}},{from:{nodeId:"scale",port:"value"},to:{nodeId:"compose",port:"b"}}],{transform:{input:{nodeId:"compose",port:"value"}}}),o=v(t);e(o.nodes.get("compose")?.outputs.value.type).toBe("mat4"),e(o.output.transform).toBeTruthy(),e(c(t).outputTransform).toBeTruthy()}),t("matrix input nodes compile as mat4 uniforms",()=>{for(const t of["builtin.viewMatrix","builtin.projectionMatrix","builtin.modelViewMatrix"]){const o=T([{id:"matrix",kind:t}],[],{transform:{input:{nodeId:"matrix",port:"value"}}}),a=v(o);e(a.nodes.get("matrix")?.outputs.value.type).toBe("mat4"),e(a.output.transform).toBeTruthy()}}),t("compose vec4 node compiles from float components",()=>{const t=T([{id:"compose",kind:"compose.vec4",inputs:{x:{value:.1},y:{value:.2},z:{value:.3},w:{value:1}}}],[],{color:{input:{nodeId:"compose",port:"value"}}}),o=v(t);e(o.nodes.get("compose")?.outputs.value.type).toBe("vec4"),e(o.output.color).toBeTruthy()}),t("atan2 node compiles from y and x inputs",()=>{const t=T([{id:"atan2",kind:"math.atan2",inputs:{y:{value:1},x:{value:0}}}],[],{color:{input:{nodeId:"atan2",port:"value"}}}),o=v(t);e(o.nodes.get("atan2")?.outputs.value.type).toBe("float"),e(o.output.color).toBeTruthy()}),t("built-in attribute nodes compile for fragment and transform outputs",()=>{const t=T([{id:"color",kind:"builtin.color"},{id:"normal",kind:"builtin.normal"},{id:"position",kind:"builtin.position"},{id:"worldPosition",kind:"builtin.worldPosition"},{id:"objectPosition",kind:"builtin.objectPosition"},{id:"translate",kind:"transform.translate"}],[{from:{nodeId:"objectPosition",port:"value"},to:{nodeId:"translate",port:"offset"}}],{color:{input:{nodeId:"color",port:"value"}},normal:{input:{nodeId:"normal",port:"value"}},roughness:{input:{nodeId:"position",port:"x"}},transform:{input:{nodeId:"translate",port:"value"}}}),o=v(t);e(o.nodes.get("color")?.outputs.value.type).toBe("rgba"),e(o.nodes.get("normal")?.outputs.value.type).toBe("vec3"),e(o.nodes.get("position")?.outputs.value.type).toBe("vec3"),e(o.nodes.get("worldPosition")?.outputs.value.type).toBe("vec3"),e(o.nodes.get("objectPosition")?.outputs.value.type).toBe("vec3"),e(o.output.color).toBeTruthy(),e(o.output.normal).toBeTruthy(),e(o.output.transform).toBeTruthy(),e(c(t).outputTransform).toBeTruthy()}),t("painted layer mix node compiles color layers and builds a material",()=>{const t=T([{id:"base",kind:"constant.rgba",params:{value:"#224422",alpha:1}},{id:"grass",kind:"constant.rgba",params:{value:"#55aa33",alpha:1}},{id:"stone",kind:"constant.rgba",params:{value:"#777777",alpha:1}},{id:"mix",kind:"layer.mixPainted",params:{mode:"soft",enableNoise:!0,softness:.25,noiseScale:.2,noiseAmount:.4}}],[{from:{nodeId:"base",port:"value"},to:{nodeId:"mix",port:"base"}},{from:{nodeId:"grass",port:"value"},to:{nodeId:"mix",port:"layer1"}},{from:{nodeId:"stone",port:"value"},to:{nodeId:"mix",port:"layer3"}}],{color:{input:{nodeId:"mix",port:"value"}}}),o=v(t);e(o.nodes.get("mix")?.outputs.value.type).toBe("rgba"),e(o.output.color).toBeTruthy(),e(c(t).isMaterial).toBe(!0)}),t("painted layer mix node compiles sparse float layers in hard and soft modes",()=>{for(const t of["hard","soft"]){const o=T([{id:"base",kind:"constant.float",params:{value:.8}},{id:"mud",kind:"constant.float",params:{value:1}},{id:"wet",kind:"constant.float",params:{value:.25}},{id:"mix",kind:"layer.mixPainted",params:{mode:t,enableNoise:!1,softness:.3,noiseScale:.1,noiseAmount:.5}}],[{from:{nodeId:"base",port:"value"},to:{nodeId:"mix",port:"base"}},{from:{nodeId:"mud",port:"value"},to:{nodeId:"mix",port:"layer2"}},{from:{nodeId:"wet",port:"value"},to:{nodeId:"mix",port:"layer8"}}],{roughness:{input:{nodeId:"mix",port:"value"}}}),a=v(o);e(a.nodes.get("mix")?.outputs.value.type).toBe("float"),e(a.output.roughness).toBeTruthy()}}),t("painted layer mix node rejects incompatible layer types",()=>{const t=T([{id:"base",kind:"constant.vec2",params:{value:[0,1]}},{id:"layer",kind:"constant.vec3",params:{value:[1,0,0]}},{id:"mix",kind:"layer.mixPainted"}],[{from:{nodeId:"base",port:"value"},to:{nodeId:"mix",port:"base"}},{from:{nodeId:"layer",port:"value"},to:{nodeId:"mix",port:"layer1"}}],{color:{input:{nodeId:"mix",port:"value"}}});e(()=>v(t)).toThrow(/Cannot mix vec2 and vec3/)}),t("additional math, uv, shape, noise, and effect nodes compile",()=>{const t=T([{id:"uv",kind:"builtin.uv"},{id:"angle",kind:"constant.float",params:{value:.5}},{id:"scale",kind:"constant.float",params:{value:4}},{id:"half",kind:"constant.float",params:{value:.5}},{id:"axis",kind:"constant.vec3",params:{value:[0,1,0]}},{id:"rotatedUv",kind:"uv.rotate"},{id:"twirl",kind:"uv.twirl"},{id:"bulge",kind:"uv.bulge"},{id:"radial",kind:"uv.radial"},{id:"flipbook",kind:"uv.flipbook"},{id:"shape",kind:"shape.roundedRectangle"},{id:"noise",kind:"noise.simplex"},{id:"voronoi",kind:"noise.voronoi2d"},{id:"fresnel",kind:"effect.fresnel"},{id:"sin",kind:"math.sin"},{id:"pow",kind:"math.pow"},{id:"mix",kind:"math.mix"},{id:"rotateAxis",kind:"transform.rotateAxis"}],[{from:{nodeId:"uv",port:"value"},to:{nodeId:"rotatedUv",port:"uv"}},{from:{nodeId:"angle",port:"value"},to:{nodeId:"rotatedUv",port:"angle"}},{from:{nodeId:"rotatedUv",port:"value"},to:{nodeId:"twirl",port:"uv"}},{from:{nodeId:"scale",port:"value"},to:{nodeId:"twirl",port:"strength"}},{from:{nodeId:"twirl",port:"value"},to:{nodeId:"bulge",port:"uv"}},{from:{nodeId:"half",port:"value"},to:{nodeId:"bulge",port:"power"}},{from:{nodeId:"bulge",port:"value"},to:{nodeId:"radial",port:"uv"}},{from:{nodeId:"twirl",port:"value"},to:{nodeId:"flipbook",port:"uv"}},{from:{nodeId:"twirl",port:"value"},to:{nodeId:"shape",port:"uv"}},{from:{nodeId:"half",port:"value"},to:{nodeId:"shape",port:"width"}},{from:{nodeId:"half",port:"value"},to:{nodeId:"shape",port:"height"}},{from:{nodeId:"half",port:"value"},to:{nodeId:"shape",port:"radius"}},{from:{nodeId:"twirl",port:"value"},to:{nodeId:"noise",port:"uv"}},{from:{nodeId:"scale",port:"value"},to:{nodeId:"noise",port:"scale"}},{from:{nodeId:"twirl",port:"value"},to:{nodeId:"voronoi",port:"uv"}},{from:{nodeId:"scale",port:"value"},to:{nodeId:"voronoi",port:"scale"}},{from:{nodeId:"scale",port:"value"},to:{nodeId:"fresnel",port:"power"}},{from:{nodeId:"radial",port:"angle"},to:{nodeId:"sin",port:"value"}},{from:{nodeId:"noise",port:"value"},to:{nodeId:"pow",port:"a"}},{from:{nodeId:"half",port:"value"},to:{nodeId:"pow",port:"b"}},{from:{nodeId:"shape",port:"value"},to:{nodeId:"mix",port:"a"}},{from:{nodeId:"voronoi",port:"value"},to:{nodeId:"mix",port:"b"}},{from:{nodeId:"fresnel",port:"value"},to:{nodeId:"mix",port:"t"}},{from:{nodeId:"axis",port:"value"},to:{nodeId:"rotateAxis",port:"axis"}},{from:{nodeId:"angle",port:"value"},to:{nodeId:"rotateAxis",port:"angle"}}],{color:{input:{nodeId:"mix",port:"value"}},opacity:{input:{nodeId:"sin",port:"value"}},anisotropyDirection:{input:{nodeId:"flipbook",port:"value"}},transform:{input:{nodeId:"rotateAxis",port:"value"}}}),o=v(t);e(o.nodes.get("mix")?.outputs.value.type).toBe("float"),e(o.nodes.get("twirl")?.outputs.value.type).toBe("vec2"),e(o.nodes.get("bulge")?.outputs.value.type).toBe("vec2"),e(o.nodes.get("radial")?.outputs.coords.type).toBe("vec2"),e(o.nodes.get("flipbook")?.outputs.value.type).toBe("vec2"),e(o.nodes.get("rotateAxis")?.outputs.value.type).toBe("mat4"),e(o.output.color).toBeTruthy(),e(o.output.opacity).toBeTruthy(),e(o.output.transform).toBeTruthy()}),t("slider input node outputs a clamped float value",()=>{const t=T([{id:"slider",kind:"input.slider",params:{value:1.25}}],[],{roughness:{input:{nodeId:"slider",port:"value"}}}),o=v(t);e(o.nodes.get("slider")?.outputs.value.type).toBe("float"),e(o.output.roughness).toBeTruthy()}),t("comparison and boolean graph nodes compile to boolean outputs",()=>{const t=T([{id:"a",kind:"constant.float",params:{value:.75}},{id:"b",kind:"constant.float",params:{value:.5}},{id:"greater",kind:"compare.greaterThan"},{id:"lessEqual",kind:"compare.lessThanOrEqual"},{id:"not",kind:"boolean.not"},{id:"and",kind:"boolean.and"},{id:"or",kind:"boolean.or"}],[{from:{nodeId:"a",port:"value"},to:{nodeId:"greater",port:"a"}},{from:{nodeId:"b",port:"value"},to:{nodeId:"greater",port:"b"}},{from:{nodeId:"a",port:"value"},to:{nodeId:"lessEqual",port:"a"}},{from:{nodeId:"b",port:"value"},to:{nodeId:"lessEqual",port:"b"}},{from:{nodeId:"lessEqual",port:"value"},to:{nodeId:"not",port:"value"}},{from:{nodeId:"greater",port:"value"},to:{nodeId:"and",port:"a"}},{from:{nodeId:"not",port:"value"},to:{nodeId:"and",port:"b"}},{from:{nodeId:"and",port:"value"},to:{nodeId:"or",port:"a"}},{from:{nodeId:"lessEqual",port:"value"},to:{nodeId:"or",port:"b"}}],{discard:{input:{nodeId:"or",port:"value"}}}),o=v(t);e(o.nodes.get("greater")?.outputs.value.type).toBe("boolean"),e(o.nodes.get("lessEqual")?.outputs.value.type).toBe("boolean"),e(o.nodes.get("not")?.outputs.value.type).toBe("boolean"),e(o.nodes.get("and")?.outputs.value.type).toBe("boolean"),e(o.nodes.get("or")?.outputs.value.type).toBe("boolean"),e(o.output.discard).toBeTruthy()}),t("split component node exposes vector and color channels as separate outputs",()=>{const t=T([{id:"vec",kind:"constant.vec3",params:{value:[.2,.4,.6]}},{id:"color",kind:"constant.rgba",params:{value:"#336699",alpha:.75}},{id:"splitVec",kind:"decompose.split"},{id:"splitColor",kind:"decompose.split"},{id:"sum",kind:"math.add"}],[{from:{nodeId:"vec",port:"value"},to:{nodeId:"splitVec",port:"value"}},{from:{nodeId:"color",port:"value"},to:{nodeId:"splitColor",port:"value"}},{from:{nodeId:"splitVec",port:"z"},to:{nodeId:"sum",port:"a"}},{from:{nodeId:"splitColor",port:"a"},to:{nodeId:"sum",port:"b"}}],{roughness:{input:{nodeId:"sum",port:"value"}}}),o=v(t);e(Object.keys(o.nodes.get("splitVec")?.outputs??{})).toEqual(["x","y","z"]),e(Object.keys(o.nodes.get("splitColor")?.outputs??{})).toEqual(["r","g","b","a","x","y","z","w"]),e(o.nodes.get("splitVec")?.outputs.z.type).toBe("float"),e(o.nodes.get("splitColor")?.outputs.a.type).toBe("float"),e(o.output.roughness).toBeTruthy()}),t("color gradient node compiles editable stops to a sampled color",()=>{const t=T([{id:"threshold",kind:"constant.float",params:{value:.75}},{id:"gradient",kind:"color.gradient",params:{stops:[{position:0,color:"#000000",alpha:1},{position:.5,color:"#ff0000",alpha:1},{position:1,color:"#ffffff",alpha:1}]}}],[{from:{nodeId:"threshold",port:"value"},to:{nodeId:"gradient",port:"t"}}],{color:{input:{nodeId:"gradient",port:"value"}}}),o=v(t);e(o.nodes.get("gradient")?.outputs.value.type).toBe("rgba"),e(o.output.color).toBeTruthy(),e(f(t,"gradient").color).toBeTruthy()}),t("curve node compiles editable curve to a sampled float",()=>{const t=T([{id:"t",kind:"constant.float",params:{value:.75}},{id:"curve",kind:"utility.curve",params:{curve:"InOutQuad"}}],[{from:{nodeId:"t",port:"value"},to:{nodeId:"curve",port:"t"}}],{roughness:{input:{nodeId:"curve",port:"value"}}}),o=v(t);e(o.nodes.get("curve")?.outputs.value.type).toBe("float"),e(o.output.roughness).toBeTruthy(),e(f(t,"curve").color).toBeTruthy()}),t("graph parameters convert to property params and custom defaults",()=>{const t=y();t.parameters.push({name:"opacity",type:"float",defaultValue:.5});const o=b(t);e(o.map(e=>e.name)).toEqual(["baseColor","opacity"]),e(o.every(e=>!0===e.options.optional)).toBe(!0);const a=d(t);e(a.baseColor).toMatchObject({type:u.RgbNode,value:"#ffffff",override:!1}),e(a.opacity).toMatchObject({type:u.FloatNode,value:.5,override:!1})}),t("existing shader graph param values keep overriding unless explicitly disabled",()=>{const t=y(),o=d(t,{baseColor:{type:u.RgbNode,value:"#ff0000"}});e(o.baseColor).toMatchObject({type:u.RgbNode,value:"#ff0000",override:!0});const a=d(t,{baseColor:{type:u.RgbNode,value:"#00ff00",override:!1}});e(a.baseColor).toMatchObject({type:u.RgbNode,value:"#ffffff",override:!1})}),t("texture graph parameter defaults serialize as sampler parameters",()=>{const t=T([],[],{});t.parameters.push({name:"map",type:"texture",defaultValue:"texture-asset-id"});const o=d(t);e(o.map).toMatchObject({type:u.Sampler2DNode,value:"texture-asset-id"})}),t("shader graph params keep graph-declared serialized types over previous string params",()=>{const t=y();t.parameters.push({name:"map",type:"texture",defaultValue:null});const o=d(t,{baseColor:{type:u.String,value:"#ff0000"},map:{type:u.String,value:"texture-asset-id"}});e(o.baseColor).toMatchObject({type:u.RgbNode,value:"#ff0000"}),e(o.map).toMatchObject({type:u.Sampler2DNode,value:"texture-asset-id"})}),t("shader graph texture params resolve asset ids before compile",async()=>{const t=T([{id:"texture",kind:"input.parameter",params:{parameter:"map"}}],[],{color:{input:{nodeId:"texture",port:"value"}}});t.parameters.push({name:"map",type:"texture",defaultValue:"texture-asset-id"});const o=await p({},t,new j([{id:"texture-asset-id",name:"Map",type:"texture",fileKey:"map.png",fileFormat:"png"}]),new C);e(o.map).toBeTruthy(),e(typeof o.map).not.toBe("string"),e(v(t,{parameters:o}).output.color).toBeTruthy()}),t("material graph asset reference and local embedded graph both build materials",async()=>{const t={id:"graph-asset",name:"Reusable Graph",type:"shaderGraph",shaderGraph:y()},o=w("referenced",{source:"asset",assetId:t.id}),a=w("local",{source:"local",graph:y()}),r=new j([t,o,a]),n=new i;e((await s(o,null,r,n,[],!1)).isMaterial).toBe(!0),e((await s(a,null,r,n,[],!1)).isMaterial).toBe(!0)}),t("selected-node preview compiles scalar, vector, color, rgba, and boolean outputs",()=>{const t=[{id:"float",kind:"constant.float",params:{value:.25}},{id:"slider",kind:"input.slider",params:{value:.5}},{id:"vec2",kind:"constant.vec2",params:{value:[1,0]}},{id:"rgb",kind:"constant.vec3",params:{value:[1,.5,0]}},{id:"rgba",kind:"constant.rgba",params:{value:"#ff8800",alpha:.75}},{id:"boolean",kind:"constant.boolean",params:{value:!0}}];for(const o of t){const t=T([o],[],{color:{input:{nodeId:o.id,port:"value"}}});e(f(t,o.id).color).toBeTruthy()}}),t("post-process shader graph builds a fullscreen-safe material",()=>{const t=h(),o=m(t);e(o).toBeInstanceOf(B),e(o.depthWrite).toBe(!1),e(o.depthTest).toBe(!1),e(o.toneMapped).toBe(!1),e(o.transparent).toBe(!1),e(o.userData.isPostProcessShaderGraph).toBe(!0),e(o.uniforms[x]).toBeTruthy(),e(o.uniforms[I]).toBeTruthy()}),t("empty post-process shader graph defaults to identity scene color",()=>{const t=h();t.nodes=[],t.edges=[],t.outputs={};const o=v(t),a=m(t);e(o.output.color).toBeTruthy(),e(o.output.transparent).toBe(!1),e(a.uniforms[x]).toBeTruthy(),e(a.uniforms[I]).toBeTruthy()}),t("post-process color and opacity outputs expose blend weight uniform",()=>{const t=T([{id:"color",kind:"constant.rgba",params:{value:"#ff0044",alpha:1}},{id:"opacity",kind:"constant.float",params:{value:.35}}],[],{color:{input:{nodeId:"color",port:"value"}},opacity:{input:{nodeId:"opacity",port:"value"}},roughness:{value:.8}});t.target="postProcess";const o=v(t),a=m(t);e(o.output.color).toBeTruthy(),e(o.output.opacity).toBeTruthy(),e(o.output.roughness).toBeUndefined(),e(a.uniforms[I]).toBeTruthy()}),t("selected-node preview builds through post-process fullscreen path",()=>{const t=T([{id:"float",kind:"constant.float",params:{value:.25}}],[],{color:{input:{nodeId:"float",port:"value"}}});t.target="postProcess";const o=m(t,{previewNodeId:"float"});e(o).toBeInstanceOf(B),e(o.userData.isPostProcessShaderGraph).toBe(!0),e(o.uniforms[x]).toBeTruthy(),e(o.uniforms[I]).toBeTruthy()}),t("texture parameter nodes expose sampled value and channel outputs",()=>{const t=T([{id:"texture",kind:"input.parameter",params:{parameter:"albedo"}}],[],{color:{input:{nodeId:"texture",port:"value"}}});t.parameters.push({name:"albedo",type:"texture",defaultValue:null});const o=v(t,{parameters:{albedo:new n}}),a=o.nodes.get("texture")?.outputs??{};e(Object.keys(a)).toEqual(["value","rgb","r","g","b","a","sampler"]),e(a.value.type).toBe("rgba"),e(a.rgb.type).toBe("rgb"),e(a.r.type).toBe("float"),e(a.g.type).toBe("float"),e(a.b.type).toBe("float"),e(a.a.type).toBe("float"),e(a.sampler.type).toBe("sampler2d"),e(o.output.color).toBeTruthy()}),t("texture parameter nodes accept resolved sampler values",()=>{const t=T([{id:"texture",kind:"input.parameter",params:{parameter:"map"}}],[],{color:{input:{nodeId:"texture",port:"value"}}});t.parameters.push({name:"map",type:"texture",defaultValue:"texture-asset-id"});const o=v(t,{parameters:{map:k(new n)}});e(o.output.color).toBeTruthy()}),t("scene depth graph nodes expose sampled and fragment linear eye depth",()=>{const t=T([{id:"uv",kind:"builtin.screenUv"},{id:"sceneDepth",kind:"scene.sampleDepth"},{id:"fragmentDepth",kind:"scene.fragmentDepth"},{id:"depthFade",kind:"math.subtract"}],[{from:{nodeId:"uv",port:"value"},to:{nodeId:"sceneDepth",port:"uv"}},{from:{nodeId:"sceneDepth",port:"linearEyeDepth"},to:{nodeId:"depthFade",port:"a"}},{from:{nodeId:"fragmentDepth",port:"linearEyeDepth"},to:{nodeId:"depthFade",port:"b"}}],{opacity:{input:{nodeId:"depthFade",port:"value"}}}),o=v(t);e(o.nodes.get("sceneDepth")?.outputs.depth.type).toBe("float"),e(o.nodes.get("sceneDepth")?.outputs.linearEyeDepth.type).toBe("float"),e(o.nodes.get("fragmentDepth")?.outputs.linearEyeDepth.type).toBe("float"),e(o.output.opacity).toBeTruthy()}),t("unpack normal node compiles with various input combinations",()=>{const t=T([{id:"sample",kind:"constant.vec3",params:{value:[.5,.5,1]}},{id:"scale",kind:"constant.float",params:{value:1}},{id:"normal",kind:"builtin.normal"},{id:"toNormal",kind:"color.unpackNormal"}],[{from:{nodeId:"sample",port:"value"},to:{nodeId:"toNormal",port:"color"}},{from:{nodeId:"scale",port:"value"},to:{nodeId:"toNormal",port:"scale"}},{from:{nodeId:"normal",port:"value"},to:{nodeId:"toNormal",port:"normal"}}],{normal:{input:{nodeId:"toNormal",port:"value"}}}),o=v(t);e(o.nodes.get("toNormal")?.outputs.value.type).toBe("vec3"),e(o.output.normal).toBeTruthy()});class j extends l{constructor(e){super(),this.onCreate=null,this.onDelete=null,this.onUpdate=null,this.assets=new Map(e.map(e=>[e.id,e]))}async getAsset(e){return this.assets.get(e)}async getAssets(){return Array.from(this.assets.values())}}class C extends i{async getTexture(){return new n}async getTextureArray(){return{texture:null,layerIndex:null}}}/*
|
|
1
|
+
import{expect as e,test as t,vi as o}from"vitest";import{DoubleSide as a,FrontSide as r,Texture as n}from"three";o.hoisted(()=>{if("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}),"undefined"==typeof AudioBuffer&&Object.defineProperty(globalThis,"AudioBuffer",{configurable:!0,value:class{}})}),o.mock("three/examples/jsm/Addons.js",async e=>({...await e(),ConvexHull:class{},SkeletonUtils:{clone:e=>e},RectAreaLightHelper:class{}})),o.mock("three-shader-graph",async e=>{const t=await e();return{...t,rgb:(e,o,a)=>null==o&&null==a&&!0===e?.isColor&&"function"==typeof e.getHexString?t.rgb("#"+e.getHexString()):t.rgb(e,o,a)}}),o.mock("../rendering.js",()=>({RenderingView:class{constructor(){this._id="test",this.csm={setupMaterial:o.fn()}}getEnvTexture(e){return e}},setRenderingPaused:o.fn()}));import{materialFromAsset as s,prepareCustomParamsFromShaderGraph as d,prepareShaderGraphParameters as p}from"../scene/materializer.js";import{SerializedParamType as u}from"../scene/model.js";import{AssetsProvider as l}from"../scene/assets-provider.js";import{AssetResourceLoader as i}from"../scene/asset-resource-loader.js";import{buildShaderGraphMaterial as m,buildShaderGraphPostProcessMaterial as c,compileShaderGraph as v,compileShaderGraphPreview as f,createDefaultPostProcessShaderGraphDocument as h,createDefaultShaderGraphDocument as y,createDefaultVfxShaderGraphDocument as g,shaderGraphPostProcessWeightUniformName as I,shaderGraphParametersToPropertyParameters as b}from"../shader/graph/index.js";import{NodeShaderMaterial as x,textureSampler2d as B,UniformFloatNode as k,UniformSampler2dArraySlice as T}from"../shader-nodes/index.js";import{StandardShader as w}from"../shader/builtin/standard-shader.js";import{sceneMapUniformName as j}from"../shader-nodes/scene-sample.js";function M(e,t,o){return{version:1,target:"surface",parameters:[],nodes:e,edges:t,outputs:o}}function C(e,t){return{id:e,name:e,type:"material",material:{type:"shaderGraph",side:r,params:{},shaderParams:{},shaderGraph:t}}}t("graph validation rejects missing nodes, invalid ports, and incompatible edges",()=>{const t=y();t.outputs.color={input:{nodeId:"missing",port:"value"}},e(()=>v(t)).toThrow(/Missing shader graph node/);const o=y();o.outputs.color={input:{nodeId:"base-color",port:"missing"}},e(()=>v(o)).toThrow(/does not have output/);const a=M([{id:"a",kind:"constant.vec2",params:{value:[1,1]}},{id:"b",kind:"constant.vec3",params:{value:[1,1,1]}},{id:"add",kind:"math.add"}],[{from:{nodeId:"a",port:"value"},to:{nodeId:"add",port:"a"}},{from:{nodeId:"b",port:"value"},to:{nodeId:"add",port:"b"}}],{color:{input:{nodeId:"add",port:"value"}}});e(()=>v(a)).toThrow(/Cannot add vec2 and vec3/)}),t("surface graph compiles to NodeShaderOutput",()=>{const t=v(y("surface"));e(t.output.color).toBeTruthy(),e(t.output.transparent).toBe(!1)}),t("inline literal inputs compile without separate constant nodes",()=>{const t=M([{id:"uv",kind:"builtin.uv"},{id:"scale-uv",kind:"math.multiply",inputs:{b:{value:2,valueType:"float"}}},{id:"rotate",kind:"uv.rotate",inputs:{angle:{value:.5,valueType:"float"},center:{value:[.25,.75],valueType:"vec2"}}},{id:"translate",kind:"transform.translate",inputs:{offset:{value:[0,1,0],valueType:"vec3"}}}],[{from:{nodeId:"uv",port:"value"},to:{nodeId:"scale-uv",port:"a"}},{from:{nodeId:"scale-uv",port:"value"},to:{nodeId:"rotate",port:"uv"}}],{color:{input:{nodeId:"rotate",port:"value"}},transform:{input:{nodeId:"translate",port:"value"}}}),o=v(t);e(o.nodes.get("scale-uv")?.outputs.value.type).toBe("vec2"),e(o.nodes.get("rotate")?.outputs.value.type).toBe("vec2"),e(o.nodes.get("translate")?.outputs.value.type).toBe("mat4"),e(o.output.color).toBeTruthy(),e(o.output.transform).toBeTruthy()}),t("sprite graph compiles with sprite-compatible material output",()=>{const t=y("sprite"),o=v(t);e(o.output.color).toBeTruthy(),e(o.output.transparent).toBe(!0)}),t("default VFX shader graphs compile mapped targets and build non-sprite materials",()=>{for(const t of["sprite","surface","decal","trail"]){const o=g(t);if(e(v(o).output.color).toBeTruthy(),"sprite"===t)continue;const a=m(o,{trailBillboard:"trail"===t});e(a.isMaterial).toBe(!0)}}),t("graph material options apply to supported material targets",()=>{const t=y("surface");t.materialOptions={side:"double",transparent:!0};const o=m(t);e(o.side).toBe(a),e(o.transparent).toBe(!0);const r=y("decal");r.materialOptions={transparent:!0};const n=m(r);e(n.transparent).toBe(!0)}),t("standard graph compiles extended material outputs and vertex transform",()=>{const t=M([{id:"metalness",kind:"constant.float",params:{value:.8}},{id:"ao",kind:"constant.float",params:{value:.5}},{id:"sheen",kind:"constant.vec3",params:{value:[.1,.2,.3]}},{id:"offset",kind:"constant.vec3",params:{value:[0,1,0]}},{id:"translate",kind:"transform.translate"}],[{from:{nodeId:"offset",port:"value"},to:{nodeId:"translate",port:"offset"}}],{metalness:{input:{nodeId:"metalness",port:"value"}},ambientOcclusion:{input:{nodeId:"ao",port:"value"}},sheenColor:{input:{nodeId:"sheen",port:"value"}},transform:{input:{nodeId:"translate",port:"value"}}}),o=v(t);e(o.output.metalness).toBeTruthy(),e(o.output.ambientOcclusion).toBeTruthy(),e(o.output.sheenColor).toBeTruthy(),e(o.output.transform).toBeTruthy();const a=m(t);e(a.outputMetalness).toBeTruthy(),e(a.outputAmbientOcclusion).toBeTruthy(),e(a.outputTransform).toBeTruthy()}),t("math multiply composes transform matrices",()=>{const t=M([{id:"translate",kind:"transform.translate",inputs:{offset:{value:[0,1,0],valueType:"vec3"}}},{id:"scale",kind:"transform.scale",inputs:{scale:{value:[2,2,2],valueType:"vec3"}}},{id:"compose",kind:"math.multiply"}],[{from:{nodeId:"translate",port:"value"},to:{nodeId:"compose",port:"a"}},{from:{nodeId:"scale",port:"value"},to:{nodeId:"compose",port:"b"}}],{transform:{input:{nodeId:"compose",port:"value"}}}),o=v(t);e(o.nodes.get("compose")?.outputs.value.type).toBe("mat4"),e(o.output.transform).toBeTruthy(),e(m(t).outputTransform).toBeTruthy()}),t("matrix input nodes compile as mat4 uniforms",()=>{for(const t of["builtin.viewMatrix","builtin.projectionMatrix","builtin.modelViewMatrix"]){const o=M([{id:"matrix",kind:t}],[],{transform:{input:{nodeId:"matrix",port:"value"}}}),a=v(o);e(a.nodes.get("matrix")?.outputs.value.type).toBe("mat4"),e(a.output.transform).toBeTruthy()}}),t("compose vec4 node compiles from float components",()=>{const t=M([{id:"compose",kind:"compose.vec4",inputs:{x:{value:.1},y:{value:.2},z:{value:.3},w:{value:1}}}],[],{color:{input:{nodeId:"compose",port:"value"}}}),o=v(t);e(o.nodes.get("compose")?.outputs.value.type).toBe("vec4"),e(o.output.color).toBeTruthy()}),t("atan2 node compiles from y and x inputs",()=>{const t=M([{id:"atan2",kind:"math.atan2",inputs:{y:{value:1},x:{value:0}}}],[],{color:{input:{nodeId:"atan2",port:"value"}}}),o=v(t);e(o.nodes.get("atan2")?.outputs.value.type).toBe("float"),e(o.output.color).toBeTruthy()}),t("built-in attribute nodes compile for fragment and transform outputs",()=>{const t=M([{id:"color",kind:"builtin.color"},{id:"normal",kind:"builtin.normal"},{id:"position",kind:"builtin.position"},{id:"worldPosition",kind:"builtin.worldPosition"},{id:"objectPosition",kind:"builtin.objectPosition"},{id:"translate",kind:"transform.translate"}],[{from:{nodeId:"objectPosition",port:"value"},to:{nodeId:"translate",port:"offset"}}],{color:{input:{nodeId:"color",port:"value"}},normal:{input:{nodeId:"normal",port:"value"}},roughness:{input:{nodeId:"position",port:"x"}},metalness:{input:{nodeId:"worldPosition",port:"x"}},transform:{input:{nodeId:"translate",port:"value"}}}),o=v(t);e(o.nodes.get("color")?.outputs.value.type).toBe("rgba"),e(o.nodes.get("normal")?.outputs.value.type).toBe("vec3"),e(o.nodes.get("position")?.outputs.value.type).toBe("vec3"),e(o.nodes.get("worldPosition")?.outputs.value.type).toBe("vec3"),e(o.nodes.get("objectPosition")?.outputs.value.type).toBe("vec3"),e(o.output.color).toBeTruthy(),e(o.output.normal).toBeTruthy(),e(o.output.transform).toBeTruthy(),e(m(t).outputTransform).toBeTruthy()}),t("painted layer mix node compiles color layers and builds a material",()=>{const t=M([{id:"base",kind:"constant.rgba",params:{value:"#224422",alpha:1}},{id:"grass",kind:"constant.rgba",params:{value:"#55aa33",alpha:1}},{id:"stone",kind:"constant.rgba",params:{value:"#777777",alpha:1}},{id:"mix",kind:"layer.mixPainted",params:{mode:"soft",enableNoise:!0,softness:.25,noiseScale:.2,noiseAmount:.4}}],[{from:{nodeId:"base",port:"value"},to:{nodeId:"mix",port:"base"}},{from:{nodeId:"grass",port:"value"},to:{nodeId:"mix",port:"layer1"}},{from:{nodeId:"stone",port:"value"},to:{nodeId:"mix",port:"layer3"}}],{color:{input:{nodeId:"mix",port:"value"}}}),o=v(t);e(o.nodes.get("mix")?.outputs.value.type).toBe("rgba"),e(o.output.color).toBeTruthy(),e(m(t).isMaterial).toBe(!0)}),t("painted layer mix node compiles sparse float layers in hard and soft modes",()=>{for(const t of["hard","soft"]){const o=M([{id:"base",kind:"constant.float",params:{value:.8}},{id:"mud",kind:"constant.float",params:{value:1}},{id:"wet",kind:"constant.float",params:{value:.25}},{id:"mix",kind:"layer.mixPainted",params:{mode:t,enableNoise:!1,softness:.3,noiseScale:.1,noiseAmount:.5}}],[{from:{nodeId:"base",port:"value"},to:{nodeId:"mix",port:"base"}},{from:{nodeId:"mud",port:"value"},to:{nodeId:"mix",port:"layer2"}},{from:{nodeId:"wet",port:"value"},to:{nodeId:"mix",port:"layer8"}}],{roughness:{input:{nodeId:"mix",port:"value"}}}),a=v(o);e(a.nodes.get("mix")?.outputs.value.type).toBe("float"),e(a.output.roughness).toBeTruthy()}}),t("painted layer mix node rejects incompatible layer types",()=>{const t=M([{id:"base",kind:"constant.vec2",params:{value:[0,1]}},{id:"layer",kind:"constant.vec3",params:{value:[1,0,0]}},{id:"mix",kind:"layer.mixPainted"}],[{from:{nodeId:"base",port:"value"},to:{nodeId:"mix",port:"base"}},{from:{nodeId:"layer",port:"value"},to:{nodeId:"mix",port:"layer1"}}],{color:{input:{nodeId:"mix",port:"value"}}});e(()=>v(t)).toThrow(/Cannot mix vec2 and vec3/)}),t("additional math, uv, shape, noise, and effect nodes compile",()=>{const t=M([{id:"uv",kind:"builtin.uv"},{id:"angle",kind:"constant.float",params:{value:.5}},{id:"scale",kind:"constant.float",params:{value:4}},{id:"half",kind:"constant.float",params:{value:.5}},{id:"axis",kind:"constant.vec3",params:{value:[0,1,0]}},{id:"rotatedUv",kind:"uv.rotate"},{id:"twirl",kind:"uv.twirl"},{id:"bulge",kind:"uv.bulge"},{id:"radial",kind:"uv.radial"},{id:"flipbook",kind:"uv.flipbook"},{id:"shape",kind:"shape.roundedRectangle"},{id:"noise",kind:"noise.simplex"},{id:"voronoi",kind:"noise.voronoi2d"},{id:"fresnel",kind:"effect.fresnel"},{id:"sin",kind:"math.sin"},{id:"pow",kind:"math.pow"},{id:"mix",kind:"math.mix"},{id:"rotateAxis",kind:"transform.rotateAxis"}],[{from:{nodeId:"uv",port:"value"},to:{nodeId:"rotatedUv",port:"uv"}},{from:{nodeId:"angle",port:"value"},to:{nodeId:"rotatedUv",port:"angle"}},{from:{nodeId:"rotatedUv",port:"value"},to:{nodeId:"twirl",port:"uv"}},{from:{nodeId:"scale",port:"value"},to:{nodeId:"twirl",port:"strength"}},{from:{nodeId:"twirl",port:"value"},to:{nodeId:"bulge",port:"uv"}},{from:{nodeId:"half",port:"value"},to:{nodeId:"bulge",port:"power"}},{from:{nodeId:"bulge",port:"value"},to:{nodeId:"radial",port:"uv"}},{from:{nodeId:"twirl",port:"value"},to:{nodeId:"flipbook",port:"uv"}},{from:{nodeId:"twirl",port:"value"},to:{nodeId:"shape",port:"uv"}},{from:{nodeId:"half",port:"value"},to:{nodeId:"shape",port:"width"}},{from:{nodeId:"half",port:"value"},to:{nodeId:"shape",port:"height"}},{from:{nodeId:"half",port:"value"},to:{nodeId:"shape",port:"radius"}},{from:{nodeId:"twirl",port:"value"},to:{nodeId:"noise",port:"uv"}},{from:{nodeId:"scale",port:"value"},to:{nodeId:"noise",port:"scale"}},{from:{nodeId:"twirl",port:"value"},to:{nodeId:"voronoi",port:"uv"}},{from:{nodeId:"scale",port:"value"},to:{nodeId:"voronoi",port:"scale"}},{from:{nodeId:"scale",port:"value"},to:{nodeId:"fresnel",port:"power"}},{from:{nodeId:"radial",port:"angle"},to:{nodeId:"sin",port:"value"}},{from:{nodeId:"noise",port:"value"},to:{nodeId:"pow",port:"a"}},{from:{nodeId:"half",port:"value"},to:{nodeId:"pow",port:"b"}},{from:{nodeId:"shape",port:"value"},to:{nodeId:"mix",port:"a"}},{from:{nodeId:"voronoi",port:"value"},to:{nodeId:"mix",port:"b"}},{from:{nodeId:"fresnel",port:"value"},to:{nodeId:"mix",port:"t"}},{from:{nodeId:"axis",port:"value"},to:{nodeId:"rotateAxis",port:"axis"}},{from:{nodeId:"angle",port:"value"},to:{nodeId:"rotateAxis",port:"angle"}}],{color:{input:{nodeId:"mix",port:"value"}},opacity:{input:{nodeId:"sin",port:"value"}},anisotropyDirection:{input:{nodeId:"flipbook",port:"value"}},transform:{input:{nodeId:"rotateAxis",port:"value"}}}),o=v(t);e(o.nodes.get("mix")?.outputs.value.type).toBe("float"),e(o.nodes.get("twirl")?.outputs.value.type).toBe("vec2"),e(o.nodes.get("bulge")?.outputs.value.type).toBe("vec2"),e(o.nodes.get("radial")?.outputs.coords.type).toBe("vec2"),e(o.nodes.get("flipbook")?.outputs.value.type).toBe("vec2"),e(o.nodes.get("rotateAxis")?.outputs.value.type).toBe("mat4"),e(o.output.color).toBeTruthy(),e(o.output.opacity).toBeTruthy(),e(o.output.transform).toBeTruthy()}),t("slider input node outputs a clamped float value",()=>{const t=M([{id:"slider",kind:"input.slider",params:{value:1.25}}],[],{roughness:{input:{nodeId:"slider",port:"value"}}}),o=v(t);e(o.nodes.get("slider")?.outputs.value.type).toBe("float"),e(o.output.roughness).toBeTruthy()}),t("comparison and boolean graph nodes compile to boolean outputs",()=>{const t=M([{id:"a",kind:"constant.float",params:{value:.75}},{id:"b",kind:"constant.float",params:{value:.5}},{id:"greater",kind:"compare.greaterThan"},{id:"lessEqual",kind:"compare.lessThanOrEqual"},{id:"not",kind:"boolean.not"},{id:"and",kind:"boolean.and"},{id:"or",kind:"boolean.or"}],[{from:{nodeId:"a",port:"value"},to:{nodeId:"greater",port:"a"}},{from:{nodeId:"b",port:"value"},to:{nodeId:"greater",port:"b"}},{from:{nodeId:"a",port:"value"},to:{nodeId:"lessEqual",port:"a"}},{from:{nodeId:"b",port:"value"},to:{nodeId:"lessEqual",port:"b"}},{from:{nodeId:"lessEqual",port:"value"},to:{nodeId:"not",port:"value"}},{from:{nodeId:"greater",port:"value"},to:{nodeId:"and",port:"a"}},{from:{nodeId:"not",port:"value"},to:{nodeId:"and",port:"b"}},{from:{nodeId:"and",port:"value"},to:{nodeId:"or",port:"a"}},{from:{nodeId:"lessEqual",port:"value"},to:{nodeId:"or",port:"b"}}],{discard:{input:{nodeId:"or",port:"value"}}}),o=v(t);e(o.nodes.get("greater")?.outputs.value.type).toBe("boolean"),e(o.nodes.get("lessEqual")?.outputs.value.type).toBe("boolean"),e(o.nodes.get("not")?.outputs.value.type).toBe("boolean"),e(o.nodes.get("and")?.outputs.value.type).toBe("boolean"),e(o.nodes.get("or")?.outputs.value.type).toBe("boolean"),e(o.output.discard).toBeTruthy()}),t("split component node exposes vector and color channels as separate outputs",()=>{const t=M([{id:"vec",kind:"constant.vec3",params:{value:[.2,.4,.6]}},{id:"color",kind:"constant.rgba",params:{value:"#336699",alpha:.75}},{id:"splitVec",kind:"decompose.split"},{id:"splitColor",kind:"decompose.split"},{id:"sum",kind:"math.add"}],[{from:{nodeId:"vec",port:"value"},to:{nodeId:"splitVec",port:"value"}},{from:{nodeId:"color",port:"value"},to:{nodeId:"splitColor",port:"value"}},{from:{nodeId:"splitVec",port:"z"},to:{nodeId:"sum",port:"a"}},{from:{nodeId:"splitColor",port:"a"},to:{nodeId:"sum",port:"b"}}],{roughness:{input:{nodeId:"sum",port:"value"}}}),o=v(t);e(Object.keys(o.nodes.get("splitVec")?.outputs??{})).toEqual(["x","y","z"]),e(Object.keys(o.nodes.get("splitColor")?.outputs??{})).toEqual(["r","g","b","a","x","y","z","w"]),e(o.nodes.get("splitVec")?.outputs.z.type).toBe("float"),e(o.nodes.get("splitColor")?.outputs.a.type).toBe("float"),e(o.output.roughness).toBeTruthy()}),t("color gradient node compiles editable stops to a sampled color",()=>{const t=M([{id:"threshold",kind:"constant.float",params:{value:.75}},{id:"gradient",kind:"color.gradient",params:{stops:[{position:0,color:"#000000",alpha:1},{position:.5,color:"#ff0000",alpha:1},{position:1,color:"#ffffff",alpha:1}]}}],[{from:{nodeId:"threshold",port:"value"},to:{nodeId:"gradient",port:"t"}}],{color:{input:{nodeId:"gradient",port:"value"}}}),o=v(t);e(o.nodes.get("gradient")?.outputs.value.type).toBe("rgba"),e(o.output.color).toBeTruthy(),e(f(t,"gradient").color).toBeTruthy()}),t("curve node compiles editable curve to a sampled float",()=>{const t=M([{id:"t",kind:"constant.float",params:{value:.75}},{id:"curve",kind:"utility.curve",params:{curve:"InOutQuad"}}],[{from:{nodeId:"t",port:"value"},to:{nodeId:"curve",port:"t"}}],{roughness:{input:{nodeId:"curve",port:"value"}}}),o=v(t);e(o.nodes.get("curve")?.outputs.value.type).toBe("float"),e(o.output.roughness).toBeTruthy(),e(f(t,"curve").color).toBeTruthy()}),t("graph parameters convert to property params and custom defaults",()=>{const t=y();t.parameters.push({name:"opacity",type:"float",defaultValue:.5});const o=b(t);e(o.map(e=>e.name)).toEqual(["baseColor","opacity"]),e(o.every(e=>!0===e.options.optional)).toBe(!0);const a=d(t);e(a.baseColor).toMatchObject({type:u.RgbNode,value:"#ffffff",override:!1}),e(a.opacity).toMatchObject({type:u.FloatNode,value:.5,override:!1})}),t("existing shader graph param values keep overriding unless explicitly disabled",()=>{const t=y(),o=d(t,{baseColor:{type:u.RgbNode,value:"#ff0000"}});e(o.baseColor).toMatchObject({type:u.RgbNode,value:"#ff0000",override:!0});const a=d(t,{baseColor:{type:u.RgbNode,value:"#00ff00",override:!1}});e(a.baseColor).toMatchObject({type:u.RgbNode,value:"#ffffff",override:!1})}),t("texture graph parameter defaults serialize as sampler parameters",()=>{const t=M([],[],{});t.parameters.push({name:"map",type:"texture",defaultValue:"texture-asset-id"});const o=d(t);e(o.map).toMatchObject({type:u.Sampler2DNode,value:"texture-asset-id"})}),t("shader graph params keep graph-declared serialized types over previous string params",()=>{const t=y();t.parameters.push({name:"map",type:"texture",defaultValue:null});const o=d(t,{baseColor:{type:u.String,value:"#ff0000"},map:{type:u.String,value:"texture-asset-id"}});e(o.baseColor).toMatchObject({type:u.RgbNode,value:"#ff0000"}),e(o.map).toMatchObject({type:u.Sampler2DNode,value:"texture-asset-id"})}),t("shader graph texture params resolve asset ids before compile",async()=>{const t=M([{id:"texture",kind:"input.parameter",params:{parameter:"map"}}],[],{color:{input:{nodeId:"texture",port:"value"}}});t.parameters.push({name:"map",type:"texture",defaultValue:"texture-asset-id"});const o=await p({},t,new A([{id:"texture-asset-id",name:"Map",type:"texture",fileKey:"map.png",fileFormat:"png"}]),new O);e(o.map).toBeTruthy(),e(typeof o.map).not.toBe("string"),e(v(t,{parameters:o}).output.color).toBeTruthy()}),t("shader graph texture array params expose named slice uniforms",async()=>{const t=M([{id:"texture",kind:"input.parameter",params:{parameter:"map"}}],[],{color:{input:{nodeId:"texture",port:"value"}}});t.parameters.push({name:"map",type:"texture",defaultValue:"texture-array-layer"});const o=await p({},t,new A([{id:"texture-array-layer",name:"Map Layer",type:"texture",fileKey:"map.png",fileFormat:"png",texture:{textureArrayFileKey:"textures/packed.ktx2",textureArrayLayer:5}}]),new P(new n,5)),a=m(t,{parameters:o});e(a.uniforms.pu_map_i?.value).toBe(5),e(a.fragmentShader).toContain("uniform float pu_map_i")}),t("standard shader height maps support texture array slices",()=>{const t=new w;t.heightMap=new T("heightMap",new n,new k("heightMap_i",3,void 0,!1)),t.map=B(new n),t.heightScale=.05;const o=t.build();e(o.fragmentShader).toContain("uniform sampler2DArray heightMap"),e(o.fragmentShader).toContain("uniform float heightMap_i"),e(o.fragmentShader).toContain("texture(heightMap, vec3(uv + vCurrOffset, heightMapLayer)).r")}),t("material graph asset reference and local embedded graph both build materials",async()=>{const t={id:"graph-asset",name:"Reusable Graph",type:"shaderGraph",shaderGraph:y()},o=C("referenced",{source:"asset",assetId:t.id}),a=C("local",{source:"local",graph:y()}),r=new A([t,o,a]),n=new i;e((await s(o,null,r,n,[],!1)).isMaterial).toBe(!0),e((await s(a,null,r,n,[],!1)).isMaterial).toBe(!0)}),t("selected-node preview compiles scalar, vector, color, rgba, and boolean outputs",()=>{const t=[{id:"float",kind:"constant.float",params:{value:.25}},{id:"slider",kind:"input.slider",params:{value:.5}},{id:"vec2",kind:"constant.vec2",params:{value:[1,0]}},{id:"rgb",kind:"constant.vec3",params:{value:[1,.5,0]}},{id:"rgba",kind:"constant.rgba",params:{value:"#ff8800",alpha:.75}},{id:"boolean",kind:"constant.boolean",params:{value:!0}}];for(const o of t){const t=M([o],[],{color:{input:{nodeId:o.id,port:"value"}}});e(f(t,o.id).color).toBeTruthy()}}),t("post-process shader graph builds a fullscreen-safe material",()=>{const t=h(),o=c(t);e(o).toBeInstanceOf(x),e(o.depthWrite).toBe(!1),e(o.depthTest).toBe(!1),e(o.toneMapped).toBe(!1),e(o.transparent).toBe(!1),e(o.userData.isPostProcessShaderGraph).toBe(!0),e(o.uniforms[j]).toBeTruthy(),e(o.uniforms[I]).toBeTruthy()}),t("empty post-process shader graph defaults to identity scene color",()=>{const t=h();t.nodes=[],t.edges=[],t.outputs={};const o=v(t),a=c(t);e(o.output.color).toBeTruthy(),e(o.output.transparent).toBe(!1),e(a.uniforms[j]).toBeTruthy(),e(a.uniforms[I]).toBeTruthy()}),t("post-process color and opacity outputs expose blend weight uniform",()=>{const t=M([{id:"color",kind:"constant.rgba",params:{value:"#ff0044",alpha:1}},{id:"opacity",kind:"constant.float",params:{value:.35}}],[],{color:{input:{nodeId:"color",port:"value"}},opacity:{input:{nodeId:"opacity",port:"value"}},roughness:{value:.8}});t.target="postProcess";const o=v(t),a=c(t);e(o.output.color).toBeTruthy(),e(o.output.opacity).toBeTruthy(),e(o.output.roughness).toBeUndefined(),e(a.uniforms[I]).toBeTruthy()}),t("selected-node preview builds through post-process fullscreen path",()=>{const t=M([{id:"float",kind:"constant.float",params:{value:.25}}],[],{color:{input:{nodeId:"float",port:"value"}}});t.target="postProcess";const o=c(t,{previewNodeId:"float"});e(o).toBeInstanceOf(x),e(o.userData.isPostProcessShaderGraph).toBe(!0),e(o.uniforms[j]).toBeTruthy(),e(o.uniforms[I]).toBeTruthy()}),t("texture parameter nodes expose sampled value and channel outputs",()=>{const t=M([{id:"texture",kind:"input.parameter",params:{parameter:"albedo"}}],[],{color:{input:{nodeId:"texture",port:"value"}}});t.parameters.push({name:"albedo",type:"texture",defaultValue:null});const o=v(t,{parameters:{albedo:new n}}),a=o.nodes.get("texture")?.outputs??{};e(Object.keys(a)).toEqual(["value","rgb","r","g","b","a","sampler"]),e(a.value.type).toBe("rgba"),e(a.rgb.type).toBe("rgb"),e(a.r.type).toBe("float"),e(a.g.type).toBe("float"),e(a.b.type).toBe("float"),e(a.a.type).toBe("float"),e(a.sampler.type).toBe("sampler2d"),e(o.output.color).toBeTruthy()}),t("texture parameter nodes accept resolved sampler values",()=>{const t=M([{id:"texture",kind:"input.parameter",params:{parameter:"map"}}],[],{color:{input:{nodeId:"texture",port:"value"}}});t.parameters.push({name:"map",type:"texture",defaultValue:"texture-asset-id"});const o=v(t,{parameters:{map:B(new n)}});e(o.output.color).toBeTruthy()}),t("scene depth graph nodes expose sampled and fragment linear eye depth",()=>{const t=M([{id:"uv",kind:"builtin.screenUv"},{id:"sceneDepth",kind:"scene.sampleDepth"},{id:"fragmentDepth",kind:"scene.fragmentDepth"},{id:"depthFade",kind:"math.subtract"}],[{from:{nodeId:"uv",port:"value"},to:{nodeId:"sceneDepth",port:"uv"}},{from:{nodeId:"sceneDepth",port:"linearEyeDepth"},to:{nodeId:"depthFade",port:"a"}},{from:{nodeId:"fragmentDepth",port:"linearEyeDepth"},to:{nodeId:"depthFade",port:"b"}}],{opacity:{input:{nodeId:"depthFade",port:"value"}}}),o=v(t);e(o.nodes.get("sceneDepth")?.outputs.depth.type).toBe("float"),e(o.nodes.get("sceneDepth")?.outputs.linearEyeDepth.type).toBe("float"),e(o.nodes.get("fragmentDepth")?.outputs.linearEyeDepth.type).toBe("float"),e(o.output.opacity).toBeTruthy()}),t("unpack normal node compiles with various input combinations",()=>{const t=M([{id:"sample",kind:"constant.vec3",params:{value:[.5,.5,1]}},{id:"scale",kind:"constant.float",params:{value:1}},{id:"normal",kind:"builtin.normal"},{id:"toNormal",kind:"color.unpackNormal"}],[{from:{nodeId:"sample",port:"value"},to:{nodeId:"toNormal",port:"color"}},{from:{nodeId:"scale",port:"value"},to:{nodeId:"toNormal",port:"scale"}},{from:{nodeId:"normal",port:"value"},to:{nodeId:"toNormal",port:"normal"}}],{normal:{input:{nodeId:"toNormal",port:"value"}}}),o=v(t);e(o.nodes.get("toNormal")?.outputs.value.type).toBe("vec3"),e(o.output.normal).toBeTruthy()});class A extends l{constructor(e){super(),this.onCreate=null,this.onDelete=null,this.onUpdate=null,this.assets=new Map(e.map(e=>[e.id,e]))}async getAsset(e){return this.assets.get(e)}async getAssets(){return Array.from(this.assets.values())}}class O extends i{async getTexture(){return new n}async getTextureArray(){return{texture:null,layerIndex:null}}}class P extends O{constructor(e,t){super(),this.textureArray=e,this.layerIndex=t}async getTextureArray(){return{texture:this.textureArray,layerIndex:this.layerIndex}}}/*
|
|
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{afterEach as e,beforeEach as t,describe as a,expect as
|
|
1
|
+
import{afterEach as e,beforeEach as t,describe as a,expect as s,it as r,vi as i}from"vitest";import{createRequire as o}from"node:module";import*as n from"node:fs/promises";import*as c from"node:os";import*as l from"node:path";import{firstValueFrom as d}from"rxjs";const w=o(import.meta.url);let m,f,g;async function p(){const{ObjectStorage:e}=await import("../scene/storage/storage.js"),t=new e("asset");return t.setBasePath("data"),t}a("ObjectStorage case-insensitive file collisions",()=>{t(async()=>{i.resetModules(),f=window.require,g=window.process,m=await n.mkdtemp(l.join(c.tmpdir(),"hology-storage-")),await n.writeFile(l.join(m,"vite.config.ts"),"hologyBuild()"),Object.defineProperty(window,"require",{configurable:!0,value:e=>"chokidar"===e?{watch:()=>({on:()=>{},close:()=>{}})}:w(e)}),Object.defineProperty(window,"process",{configurable:!0,value:{argv:[`--path=${m}`]}})}),e(async()=>{await n.rm(m,{recursive:!0,force:!0}),Object.defineProperty(window,"require",{configurable:!0,value:f}),Object.defineProperty(window,"process",{configurable:!0,value:g})}),r("rejects create names that only differ by case",async()=>{const e=await p();await e.create({name:"dirt"}),await s(e.create({name:"Dirt"})).rejects.toThrow(/differs beyond letter casing/),await s(e.getAll()).resolves.toHaveLength(1)}),r("rejects prepared saves that only differ by case",async()=>{const e=await p();await e.create({name:"dirt"});const t=e.prepareCreate({name:"Dirt"});await s(e.save(t)).rejects.toThrow(/differs beyond letter casing/),await s(e.getAll()).resolves.toHaveLength(1)}),r("rejects renames that only differ by case from another object",async()=>{const e=await p();await e.create({name:"dirt"});const t=await e.create({name:"sand"});await s(e.rename(t,"Dirt")).rejects.toThrow(/differs beyond letter casing/),await s(e.get(t.id)).resolves.toMatchObject({name:"sand"})}),r("waits for the base path before watching folders",async()=>{const{ObjectStorage:e}=await import("../scene/storage/storage.js"),t=new e("asset"),a=d(t.watchFolders());t.setBasePath("data"),await s(a).resolves.toEqual([])}),r("loads pre-existing nested assets into the index",async()=>{const e=l.join(m,"data","asset");await n.mkdir(l.join(e,"weapons","swords"),{recursive:!0}),await n.mkdir(l.join(e,"materials"),{recursive:!0}),await n.writeFile(l.join(e,"weapons","swords","Iron_Sword.json"),JSON.stringify({id:"iron-sword",name:"Iron Sword"})),await n.writeFile(l.join(e,"materials","Steel.json"),JSON.stringify({id:"steel",name:"Steel"}));const t=await p();await s(t.get("iron-sword")).resolves.toMatchObject({id:"iron-sword",path:l.join("weapons","swords")}),await s(t.get("steel")).resolves.toMatchObject({id:"steel",path:"materials"})}),r("limits concurrent storage file reads across overlapping scans",async()=>{const e=l.join(m,"data","asset");await n.mkdir(e,{recursive:!0}),await Promise.all(Array.from({length:64},(t,a)=>n.writeFile(l.join(e,`Asset_${a}.json`),JSON.stringify({id:`asset-${a}`,name:`Asset ${a}`}))));const t=w("fs"),a=t.promises.readFile.bind(t.promises);let r=0,o=0;const c=i.spyOn(t.promises,"readFile").mockImplementation(async(...e)=>{if(!(e[0]?.toString()??"").endsWith(".json"))return a(...e);r++,o=Math.max(o,r);try{return await new Promise(e=>setTimeout(e,5)),await a(...e)}finally{r--}});try{const e=await p();await Promise.all([e.getAll(),e.getAll()])}finally{c.mockRestore()}s(o).toBeLessThanOrEqual(32)}),r("shares cold index loading across concurrent gets",async()=>{const e=l.join(m,"data","asset");await n.mkdir(e,{recursive:!0}),await Promise.all(Array.from({length:48},(t,a)=>n.writeFile(l.join(e,`Asset_${a}.json`),JSON.stringify({id:`asset-${a}`,name:`Asset ${a}`}))));const t=w("fs"),a=t.promises.readFile.bind(t.promises);let r=0;const o=i.spyOn(t.promises,"readFile").mockImplementation(async(...e)=>((e[0]?.toString()??"").endsWith(".json")&&r++,a(...e)));try{const e=await p(),t=await Promise.all(Array.from({length:16},(t,a)=>e.get(`asset-${a}`)));s(t).toHaveLength(16),s(t.every(e=>null!=e)).toBe(!0)}finally{o.mockRestore()}s(r).toBeLessThanOrEqual(64)})});/*
|
|
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{__decorate as t}from"tslib";import"reflect-metadata";import{expect as e,test as o,vi as n}from"vitest";n.mock("../gameplay/services/render.js",()=>({ViewController:class{}})),n.mock("../gameplay/services/physics/physics-system.js",()=>({PhysicsSystem:class{}})),n.mock("../rendering.js",()=>({RenderingView:class{}}));import{Scene as i}from"three";import{Subject as r}from"rxjs";import{Container as s}from"typedi";import{Actor as d,BaseActor as a}from"../gameplay/actors/actor.js";import{ActorComponent as c,Component as l}from"../gameplay/actors/component.js";import{ActorFactory as m}from"../gameplay/actors/factory.js";import{World as y}from"../gameplay/services/world.js";function u(t){const e=Object.create(y.prototype);return e.actorFactory=t,e.physics={removeActor(){}},e.actors=[],e.actorAdded=new r,e.actorRemoved=new r,e.scene=new i,e}o("world begin and end play skip runtime-only components in editor",async()=>{const t=new m(s.of("world-lifecycle-editor"),{inEditor:!0}),o=await t.create(p),n=u(t);n.addActor(o),n.removeActor(o),e(o.beginCount).toBe(1),e(o.endCount).toBe(1),e(o.runtimeOnly.beginCount).toBe(0),e(o.runtimeOnly.endCount).toBe(0),e(o.runtimeOnly.actor).toBeUndefined(),e(o.inEditor.beginCount).toBe(1),e(o.inEditor.endCount).toBe(1),e(o.inEditor.actor).toBe(o),e(o.editorOnly.beginCount).toBe(1),e(o.editorOnly.endCount).toBe(1),e(o.editorOnly.actor).toBe(o)}),o("world begin and end play skip editor-only components at runtime",async()=>{const t=new m(s.of("world-lifecycle-runtime"),{inEditor:!1}),o=await t.create(p),n=u(t);n.addActor(o),n.removeActor(o),e(o.beginCount).toBe(1),e(o.endCount).toBe(1),e(o.runtimeOnly.beginCount).toBe(1),e(o.runtimeOnly.endCount).toBe(1),e(o.runtimeOnly.actor).toBe(o),e(o.inEditor.beginCount).toBe(1),e(o.inEditor.endCount).toBe(1),e(o.inEditor.actor).toBe(o),e(o.editorOnly.beginCount).toBe(0),e(o.editorOnly.endCount).toBe(0),e(o.editorOnly.actor).toBeUndefined()});let p=class extends a{constructor(){super(...arguments),this.beginCount=0,this.endCount=0,this.runtimeOnly=this.attach(g),this.inEditor=this.attach(B),this.editorOnly=this.attach(h)}onBeginPlay(){this.beginCount++}onEndPlay(){this.endCount++}};p=t([d()],p);class C extends c{constructor(){super(...arguments),this.beginCount=0,this.endCount=0}onBeginPlay(){this.beginCount++}onEndPlay(){this.endCount++}}let g=class extends C{};g=t([l()],g);let B=class extends C{};B=t([l({inEditor:!0})],B);let h=class extends C{};h=t([l({inEditor:!0,editorOnly:!0})],h);/*
|
|
2
|
+
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
|
+
* See the LICENSE.md file for details.
|
|
4
|
+
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hology/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.208",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -181,7 +181,7 @@
|
|
|
181
181
|
"recast-navigation": "0.39.0",
|
|
182
182
|
"rxjs": "7.8.1",
|
|
183
183
|
"three-mesh-bvh": "^0.7.5",
|
|
184
|
-
"three-shader-graph": "^0.2.
|
|
184
|
+
"three-shader-graph": "^0.2.52",
|
|
185
185
|
"three-stdlib": "2.34.0",
|
|
186
186
|
"ts-key-enum": "^2.0.12",
|
|
187
187
|
"typedi": "^0.10.0"
|