@hology/core 0.0.29 → 0.0.31

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,16 @@ export declare class Rotation extends Initializer {
5
5
  constructor(rotation: Vector3);
6
6
  init(emitter: Emitter, particle: Particle): void;
7
7
  }
8
+ export declare class InitialScale extends Initializer {
9
+ private scale;
10
+ constructor(scale: number);
11
+ init(emitter: Emitter, particle: Particle): void;
12
+ }
13
+ export declare class AdditiveVelocity extends Initializer {
14
+ private velocity;
15
+ constructor(velocity: Vector3);
16
+ init(emitter: Emitter, particle: Particle): void;
17
+ }
8
18
  export declare class RandomDirection extends Initializer {
9
19
  private speed;
10
20
  constructor(speed: number);
@@ -1,4 +1,4 @@
1
- import{Vector3 as t}from"three";import i,{Span as e}from"three-nebula";export class Rotation extends i{constructor(t){super(),this.rotation=t}init(t,i){"number"!=typeof i.rotation&&i.rotation.copy(this.rotation)}}export class RandomDirection extends i{constructor(t){super(),this.speed=t}init(t,i){s.set(2*Math.random()-1,2*Math.random()-1,2*Math.random()-1).normalize().multiplyScalar(this.speed),i.velocity.x+=s.x,i.velocity.y+=s.y,i.velocity.z+=s.z}}export class RandomComponentsDirection extends i{constructor(t,i,s){super(),this.speed=t,this.min=i,this.max=s,this.x=new e(this.min.x,this.max.x),this.y=new e(this.min.y,this.max.y),this.z=new e(this.min.z,this.max.z)}init(t,i){s.set(this.x.getValue(),this.y.getValue(),this.z.getValue()).normalize().multiplyScalar(this.speed),i.velocity.x+=s.x,i.velocity.y+=s.y,i.velocity.z+=s.z}}export class RandomVelocity extends i{constructor(t,i){super(),this.min=t,this.max=i,this.x=new e(this.min.x,this.max.x),this.y=new e(this.min.y,this.max.y),this.z=new e(this.min.z,this.max.z)}init(t,i){i.velocity.x+=this.x.getValue(),i.velocity.y+=this.y.getValue(),i.velocity.z+=this.z.getValue()}}const s=new t;
1
+ import{Vector3 as t}from"three";import i,{Span as e}from"three-nebula";export class Rotation extends i{constructor(t){super(),this.rotation=t}init(t,i){"number"!=typeof i.rotation&&i.rotation.copy(this.rotation)}}export class InitialScale extends i{constructor(t){super(),this.scale=t}init(t,i){i.scale=this.scale}}export class AdditiveVelocity extends i{constructor(t){super(),this.velocity=t}init(t,i){i.velocity.x+=this.velocity.x,i.velocity.y+=this.velocity.y,i.velocity.z+=this.velocity.z}}export class RandomDirection extends i{constructor(t){super(),this.speed=t}init(t,i){s.set(2*Math.random()-1,2*Math.random()-1,2*Math.random()-1).normalize().multiplyScalar(this.speed),i.velocity.x+=s.x,i.velocity.y+=s.y,i.velocity.z+=s.z}}export class RandomComponentsDirection extends i{constructor(t,i,s){super(),this.speed=t,this.min=i,this.max=s,this.x=new e(this.min.x,this.max.x),this.y=new e(this.min.y,this.max.y),this.z=new e(this.min.z,this.max.z)}init(t,i){s.set(this.x.getValue(),this.y.getValue(),this.z.getValue()).normalize().multiplyScalar(this.speed),i.velocity.x+=s.x,i.velocity.y+=s.y,i.velocity.z+=s.z}}export class RandomVelocity extends i{constructor(t,i){super(),this.min=t,this.max=i,this.x=new e(this.min.x,this.max.x),this.y=new e(this.min.y,this.max.y),this.z=new e(this.min.z,this.max.z)}init(t,i){i.velocity.x+=this.x.getValue(),i.velocity.y+=this.y.getValue(),i.velocity.z+=this.z.getValue()}}const s=new t;
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -23,4 +23,5 @@ export declare class VfxActor extends BaseActor {
23
23
  private max;
24
24
  onUpdate(deltaTime: number): void;
25
25
  getParticleCount(): any;
26
+ onEndPlay(): void;
26
27
  }
@@ -1,4 +1,4 @@
1
- import{__awaiter as t,__decorate as s}from"tslib";import{Actor as e,BaseActor as i,AssetLoader as o,inject as r,World as a}from"../../gameplay";import{Rate as m}from"three-nebula";import{OnceRate as h}from"./rates";import{materializeVfx as d}from"./vfx-materializer";import*as l from"three";let n=class extends i{constructor(){super(...arguments),this.timescale=1,this.paused=!1,this.assetLoader=r(o),this.world=r(a),this._worldPos=new l.Vector3,this.max=0}fromAsset(s){return t(this,void 0,void 0,(function*(){null!=this.system&&(this.system.destroy(),this.system.emitters.forEach((t=>t.reset()))),this.sourceAsset=s,this.disposeSystem&&this.disposeSystem();const{system:t,dispose:e}=yield d(s,this.object,{getMaterial:t=>this.assetLoader.getMaterialByAssetId(t),getTexture:t=>this.assetLoader.getTextureByAssetId(t),getMesh:t=>this.assetLoader.getModelByAssetId(t).then((t=>t.scene))});this.system=t,this.disposeSystem=e}))}play(){this.paused=!1;this.system.emitters.every((t=>t.dead))&&this.restart()}pause(){this.paused=!0}stop(){this.system.emitters.forEach((t=>{const s=t.rate;s instanceof m&&(console.log("set rate to infinity",s),s.nextTime=1/0)}))}restart(){for(const t of this.system.emitters){t.removeAllParticles();const s=t.rate;s.nextTime=0,s instanceof h&&s.restart()}}onUpdate(t){var s,e;this.paused||(this.object.getWorldPosition(this._worldPos),null===(s=this.system)||void 0===s||s.emitters.forEach((t=>{})),null===(e=this.system)||void 0===e||e.update(t*this.timescale))}getParticleCount(){var t,s;return null!==(s=null===(t=this.system)||void 0===t?void 0:t.getCount())&&void 0!==s?s:0}};n=s([e()],n);export{n as VfxActor};
1
+ import{__awaiter as t,__decorate as s}from"tslib";import{Actor as e,BaseActor as i,AssetLoader as o,inject as r,World as a}from"../../gameplay";import{Rate as h}from"three-nebula";import{OnceRate as m}from"./rates";import{materializeVfx as l}from"./vfx-materializer";import*as d from"three";let n=class extends i{constructor(){super(...arguments),this.timescale=1,this.paused=!1,this.assetLoader=r(o),this.world=r(a),this._worldPos=new d.Vector3,this.max=0}fromAsset(s){return t(this,void 0,void 0,(function*(){null!=this.system&&(this.system.destroy(),this.system.emitters.forEach((t=>t.reset()))),this.sourceAsset=s,this.disposeSystem&&this.disposeSystem();const{system:t,dispose:e}=yield l(s,this.world.scene,{getMaterial:t=>this.assetLoader.getMaterialByAssetId(t),getTexture:t=>this.assetLoader.getTextureByAssetId(t),getMesh:t=>this.assetLoader.getModelByAssetId(t).then((t=>t.scene))});this.system=t,this.disposeSystem=e}))}play(){this.paused=!1;this.system.emitters.every((t=>t.dead))&&this.restart()}pause(){this.paused=!0}stop(){this.system.emitters.forEach((t=>{const s=t.rate;s instanceof h&&(console.log("set rate to infinity",s),s.nextTime=1/0)}))}restart(){for(const t of this.system.emitters){t.removeAllParticles();const s=t.rate;s.nextTime=0,s instanceof m&&s.restart()}}onUpdate(t){var s,e;this.paused||(this.object.getWorldPosition(this._worldPos),null===(s=this.system)||void 0===s||s.emitters.forEach((t=>{t.setPosition(this._worldPos)})),null===(e=this.system)||void 0===e||e.update(t*this.timescale))}getParticleCount(){var t,s;return null!==(s=null===(t=this.system)||void 0===t?void 0:t.getCount())&&void 0!==s?s:0}onEndPlay(){this.stop(),console.log("end play"),null!=this.disposeSystem&&this.disposeSystem()}};n=s([e()],n);export{n as VfxActor};
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -1,5 +1,5 @@
1
1
  import { LibraryShapeType } from "../../scene/objects/shapes";
2
- import { AssetId, CustomParamValue } from "../../scene/model";
2
+ import { AssetId, CustomParamValue, SerializedParamType } from "../../scene/model";
3
3
  import { LibraryVfxBehaviourType, LibraryVfxInitalizerType } from './vfx-defs';
4
4
  import * as THREE from "three";
5
5
  export type OnceRateData = {
@@ -78,7 +78,16 @@ export declare function EmitterDataConstructor(): {
78
78
  };
79
79
  position: [number, number, number];
80
80
  rotation: [number, number, number];
81
- initializers: any[];
81
+ initializers: {
82
+ id: string;
83
+ type: "lifetime";
84
+ params: {
85
+ duration: {
86
+ type: SerializedParamType.Number;
87
+ value: number;
88
+ };
89
+ };
90
+ }[];
82
91
  behaviours: any[];
83
92
  children: any[];
84
93
  output: {
@@ -1,4 +1,4 @@
1
- import*as t from"three";import{randomString as i}from"../../utils/math";export const BlendingModes=["additive","subtractive","multiply","normal"];export const ThreeBlendingMode={normal:t.NormalBlending,additive:t.AdditiveBlending,subtractive:t.SubtractiveBlending,multiply:t.MultiplyBlending};export function EmitterDataConstructor(){return{id:i(),name:"Emitter",rate:{type:"continuous",count:1,time:.5},position:[0,0,0],rotation:[0,0,0],initializers:[],behaviours:[],children:[],output:{type:"sprite",texture:null,color:"#ffffff",blendingMode:"normal"}}}
1
+ import{SerializedParamType as t}from"../../scene/model";import*as e from"three";import{randomString as i}from"../../utils/math";export const BlendingModes=["additive","subtractive","multiply","normal"];export const ThreeBlendingMode={normal:e.NormalBlending,additive:e.AdditiveBlending,subtractive:e.SubtractiveBlending,multiply:e.MultiplyBlending};export function EmitterDataConstructor(){return{id:i(),name:"Emitter",rate:{type:"continuous",count:1,time:.5},position:[0,0,0],rotation:[0,0,0],initializers:[{id:i(),type:"lifetime",params:{duration:{type:t.Number,value:1}}}],behaviours:[],children:[],output:{type:"sprite",texture:null,color:"#ffffff",blendingMode:"normal"}}}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -51,6 +51,33 @@ declare class VelocityDef extends BaseIniDef<VelocityDef> {
51
51
  };
52
52
  make(params?: ParamsType<this>): Initializer;
53
53
  }
54
+ declare class PositionPointDef extends BaseIniDef<PositionPointDef> {
55
+ parameters: {
56
+ position: ShapeParameterDef<Vector3>;
57
+ };
58
+ make(params?: ParamsType<this>): Initializer;
59
+ }
60
+ declare class PositionBoxDef extends BaseIniDef<PositionBoxDef> {
61
+ parameters: {
62
+ position: ShapeParameterDef<Vector3>;
63
+ dimensions: ShapeParameterDef<Vector3>;
64
+ };
65
+ make(params?: ParamsType<this>): Initializer;
66
+ }
67
+ declare class PositionSphereDef extends BaseIniDef<PositionBoxDef> {
68
+ parameters: {
69
+ position: ShapeParameterDef<Vector3>;
70
+ radius: FloatParameterDef;
71
+ };
72
+ make(params?: ParamsType<this>): Initializer;
73
+ }
74
+ declare class PositionLineDef extends BaseIniDef<PositionLineDef> {
75
+ parameters: {
76
+ a: ShapeParameterDef<Vector3>;
77
+ b: ShapeParameterDef<Vector3>;
78
+ };
79
+ make(params?: ParamsType<this>): Initializer;
80
+ }
54
81
  declare class RandomDirectionDef extends BaseIniDef<RandomDirectionDef> {
55
82
  parameters: {
56
83
  speed: FloatParameterDef;
@@ -69,6 +96,12 @@ declare class RotationDef extends BaseIniDef<RotationDef> {
69
96
  };
70
97
  make(params?: ParamsType<this>): Initializer;
71
98
  }
99
+ declare class InitialScaleDef extends BaseIniDef<InitialScaleDef> {
100
+ parameters: {
101
+ scale: FloatParameterDef;
102
+ };
103
+ make(params?: ParamsType<this>): Initializer;
104
+ }
72
105
  declare class ForceDef extends BaseBevDef<ForceDef> {
73
106
  parameters: {
74
107
  force: ShapeParameterDef<Vector3>;
@@ -143,7 +176,12 @@ declare class LinearDampingDef extends BaseBevDef<LinearDampingDef> {
143
176
  }
144
177
  declare const vfxInitializsers: {
145
178
  lifetime: LifetimeDef;
179
+ positionPoint: PositionPointDef;
180
+ positionBox: PositionBoxDef;
181
+ positionSphere: PositionSphereDef;
182
+ positionLine: PositionLineDef;
146
183
  rotation: RotationDef;
184
+ scale: InitialScaleDef;
147
185
  mass: MassDef;
148
186
  velocity: VelocityDef;
149
187
  randomDirection: RandomDirectionDef;
@@ -162,7 +200,7 @@ declare const vfxBehaviours: {
162
200
  };
163
201
  export type LibraryVfxInitalizerType = keyof typeof vfxInitializsers;
164
202
  export declare const VfxInitializserLibrary: Record<LibraryVfxInitalizerType, InitializerDefinition>;
165
- export declare const VfxInitializserLibraryKeys: ("rotation" | "mass" | "velocity" | "lifetime" | "randomDirection")[];
203
+ export declare const VfxInitializserLibraryKeys: ("rotation" | "scale" | "mass" | "velocity" | "lifetime" | "positionPoint" | "positionBox" | "positionSphere" | "positionLine" | "randomDirection")[];
166
204
  export type LibraryVfxBehaviourType = keyof typeof vfxBehaviours;
167
205
  export declare const VfxBehaviourLibrary: Record<LibraryVfxBehaviourType, BehaviourDefinition>;
168
206
  export declare const VfxBehaviourLibraryKeys: ("scale" | "rotate" | "force" | "gravity" | "randomDrift" | "changeColor" | "changeOpacity" | "vortex" | "moveTo" | "linearDamping")[];
@@ -1,4 +1,4 @@
1
- import{Color as e,MathUtils as r,Vector2 as t,Vector3 as s}from"three";import{Life as a,Force as n,Gravity as o,Scale as i,RandomDrift as c,Color as u,Alpha as m,Rotate as f,VectorVelocity as p,Vector3D as l,Mass as d,ease as w}from"three-nebula";import{LinearDamping as x,MoveOverLife as y,RotatePosition as h}from"./behaviours";import{RandomDirection as b,Rotation as k}from"./initializsers";class v{build(e={}){const r=T(e,this.parameters);return this.make(r)}}class g{build(e={}){const r=T(e,this.parameters);return this.make(r)}}function z(e,r,t){return{type:"number",default:e,float:!0,min:r,max:t}}function L(e){return{type:"vec3",default:(new s).fromArray(e)}}function V(e){return{type:"color",default:e}}function O(){return{type:"select",opts:Array.from(Object.keys(w)).map((e=>e.substring(4))),default:"Linear"}}function T(e,r){const t={};for(let s in r)null==e[s]?t[s]=r[s].default:t[s]=e[s];return t}function j(e){return null!=e?w["ease"+e]:w.easeLinear}const B={lifetime:new class extends g{constructor(){var e;super(...arguments),this.parameters={duration:(e=1,{type:"number",default:e})}}make(e={}){return new a(e.duration)}},rotation:new class extends g{constructor(){super(...arguments),this.parameters={rotation:L([0,0,0])}}make(e={}){const{x:r,y:t,z:a}=e.rotation;return new k(new s(r,t,a))}},mass:new class extends g{constructor(){super(...arguments),this.parameters={min:z(1)}}make(e={}){return new d(e.min)}},velocity:new class extends g{constructor(){super(...arguments),this.parameters={velocity:L([0,0,0])}}make(e={}){const{x:r,y:t,z:s}=e.velocity;return new p(new l(r,t,s),0)}},randomDirection:new class extends g{constructor(){super(...arguments),this.parameters={speed:z(1)}}make(e={}){return new b(e.speed)}}},D={force:new class extends v{constructor(){super(...arguments),this.parameters={force:L([0,0,0]),ease:O()}}make(e={}){return new n(e.force.x,e.force.y,e.force.z,void 0,j(e.ease))}},gravity:new class extends v{constructor(){super(...arguments),this.parameters={gravity:z(8)}}make(e={}){return new o(e.gravity)}},scale:new class extends v{constructor(){super(...arguments),this.parameters={a:z(1),b:z(1),ease:O()}}make(e={}){return new i(e.a,e.b,void 0,j(e.ease))}},randomDrift:new class extends v{constructor(){super(...arguments),this.parameters={drift:L([1,1,1]),delay:z(0),ease:O()}}make(e={}){return new c(e.drift.x,e.drift.y,e.drift.z,e.delay,void 0,j(e.ease))}},rotate:new class extends v{constructor(){super(...arguments),this.parameters={rotation:L([1,1,1]),ease:O()}}make(e={}){const{x:t,y:s,z:a}=e.rotation;return new f(r.degToRad(t),r.degToRad(s),r.degToRad(a),void 0,j(e.ease))}},changeColor:new class extends v{constructor(){super(...arguments),this.parameters={a:V("#ffffff"),b:V("#ffffff"),ease:O()}}make(r={}){return new u(new e(r.a),new e(r.b),void 0,j(r.ease))}},changeOpacity:new class extends v{constructor(){super(...arguments),this.parameters={a:z(1,0,1),b:z(0,0,1),ease:O()}}make(e={}){return new m(e.a,e.b,void 0,j(e.ease))}},vortex:new class extends v{constructor(){super(...arguments),this.parameters={axis:L([0,1,0]),amount:z(1)}}make(e={}){return new h(e.axis,e.amount)}},moveTo:new class extends v{constructor(){super(...arguments),this.parameters={target:L([0,1,0]),ease:O()}}make(e={}){return new y(e.target.x,e.target.y,e.target.z,j(e.ease))}},linearDamping:new class extends v{constructor(){super(...arguments),this.parameters={factor:z(.1,0,1)}}make(e={}){return new x(e.factor)}}};export const VfxInitializserLibrary=B;export const VfxInitializserLibraryKeys=Object.keys(VfxInitializserLibrary);export const VfxBehaviourLibrary=D;export const VfxBehaviourLibraryKeys=Object.keys(VfxBehaviourLibrary);
1
+ import{Color as e,MathUtils as r,Vector2 as t,Vector3 as s}from"three";import{Life as n,Force as a,Gravity as o,Scale as i,RandomDrift as c,Color as u,Alpha as m,Rotate as p,Mass as d,ease as l,Position as f,BoxZone as w,LineZone as x}from"three-nebula";import{LinearDamping as y,MoveOverLife as h,RotatePosition as k}from"./behaviours";import{AdditiveVelocity as b,InitialScale as v,RandomDirection as z,Rotation as g}from"./initializsers";import{SphereZone as L,PointZone as V}from"./zones";class B{build(e={}){const r=R(e,this.parameters);return this.make(r)}}class O{build(e={}){const r=R(e,this.parameters);return this.make(r)}}function T(e,r,t){return{type:"number",default:e,float:!0,min:r,max:t}}function j(e){return{type:"vec3",default:(new s).fromArray(e)}}function D(e){return{type:"color",default:e}}function I(){return{type:"select",opts:Array.from(Object.keys(l)).map((e=>e.substring(4))),default:"Linear"}}function R(e,r){const t={};for(let s in r)null==e[s]?t[s]=r[s].default:t[s]=e[s];return t}function A(e){return null!=e?l["ease"+e]:l.easeLinear}const C={lifetime:new class extends O{constructor(){var e;super(...arguments),this.parameters={duration:(e=1,{type:"number",default:e})}}make(e={}){return new n(e.duration)}},positionPoint:new class extends O{constructor(){super(...arguments),this.parameters={position:j([0,0,0])}}make(e={}){const{x:r,y:t,z:s}=e.position;return new f(new V(r,t,s))}},positionBox:new class extends O{constructor(){super(...arguments),this.parameters={position:j([0,0,0]),dimensions:j([0,0,0])}}make(e={}){const{x:r,y:t,z:s}=e.position,{x:n,y:a,z:o}=e.dimensions;return new f(new w(r,t,s,n,a,o))}},positionSphere:new class extends O{constructor(){super(...arguments),this.parameters={position:j([0,0,0]),radius:T(1)}}make(e={}){const{x:r,y:t,z:s}=e.position;return new f(new L(r,t,s,e.radius))}},positionLine:new class extends O{constructor(){super(...arguments),this.parameters={a:j([0,0,0]),b:j([0,0,1])}}make(e={}){const{x:r,y:t,z:s}=e.a,{x:n,y:a,z:o}=e.b;return new f(new x(r,t,s,n,a,o))}},rotation:new class extends O{constructor(){super(...arguments),this.parameters={rotation:j([0,0,0])}}make(e={}){const{x:r,y:t,z:n}=e.rotation;return new g(new s(r,t,n))}},scale:new class extends O{constructor(){super(...arguments),this.parameters={scale:T(1)}}make(e={}){return new v(e.scale)}},mass:new class extends O{constructor(){super(...arguments),this.parameters={min:T(1)}}make(e={}){return new d(e.min)}},velocity:new class extends O{constructor(){super(...arguments),this.parameters={velocity:j([0,0,0])}}make(e={}){const{x:r,y:t,z:n}=e.velocity;return new b(new s(r,t,n))}},randomDirection:new class extends O{constructor(){super(...arguments),this.parameters={speed:T(1)}}make(e={}){return new z(e.speed)}}},K={force:new class extends B{constructor(){super(...arguments),this.parameters={force:j([0,0,0]),ease:I()}}make(e={}){return new a(e.force.x,e.force.y,e.force.z,void 0,A(e.ease))}},gravity:new class extends B{constructor(){super(...arguments),this.parameters={gravity:T(8)}}make(e={}){return new o(e.gravity)}},scale:new class extends B{constructor(){super(...arguments),this.parameters={a:T(1),b:T(1),ease:I()}}make(e={}){return new i(e.a,e.b,void 0,A(e.ease))}},randomDrift:new class extends B{constructor(){super(...arguments),this.parameters={drift:j([1,1,1]),delay:T(0),ease:I()}}make(e={}){return new c(e.drift.x,e.drift.y,e.drift.z,e.delay,void 0,A(e.ease))}},rotate:new class extends B{constructor(){super(...arguments),this.parameters={rotation:j([1,1,1]),ease:I()}}make(e={}){const{x:t,y:s,z:n}=e.rotation;return new p(r.degToRad(t),r.degToRad(s),r.degToRad(n),void 0,A(e.ease))}},changeColor:new class extends B{constructor(){super(...arguments),this.parameters={a:D("#ffffff"),b:D("#ffffff"),ease:I()}}make(r={}){return new u(new e(r.a),new e(r.b),void 0,A(r.ease))}},changeOpacity:new class extends B{constructor(){super(...arguments),this.parameters={a:T(1,0,1),b:T(0,0,1),ease:I()}}make(e={}){return new m(e.a,e.b,void 0,A(e.ease))}},vortex:new class extends B{constructor(){super(...arguments),this.parameters={axis:j([0,1,0]),amount:T(1)}}make(e={}){return new k(e.axis,e.amount)}},moveTo:new class extends B{constructor(){super(...arguments),this.parameters={target:j([0,1,0]),ease:I()}}make(e={}){return new h(e.target.x,e.target.y,e.target.z,A(e.ease))}},linearDamping:new class extends B{constructor(){super(...arguments),this.parameters={factor:T(.1,0,1)}}make(e={}){return new y(e.factor)}}};export const VfxInitializserLibrary=C;export const VfxInitializserLibraryKeys=Object.keys(VfxInitializserLibrary);export const VfxBehaviourLibrary=K;export const VfxBehaviourLibraryKeys=Object.keys(VfxBehaviourLibrary);
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -1,4 +1,4 @@
1
- import{__awaiter as e}from"tslib";import{Object3D as t}from"three";import*as r from"three";import a,{Body as n,BoxZone as o,Emitter as i,Force as s,Life as l,Mass as d,MeshRenderer as c,PUID as m,PointZone as u,Position as p,RadialVelocity as h,Radius as w,Rate as A,Rotate as f,Scale as g,Span as y,Vector3D as v,ease as M}from"three-nebula";import{RotatePosition as b}from"./behaviours";import{OnceRate as x}from"./rates";import{VfxBehaviourLibrary as B,VfxInitializserLibrary as S}from"./vfx-defs";import{ThreeBlendingMode as I}from"./vfx-asset";import{ShapeLibrary as E}from"../../scene/objects/shapes";import{prepareShapeParameters as P,shapeDefaultColor as R}from"../../scene/materializer";class Q extends c{scale(e){e.target instanceof r.Sprite?e.target.scale.set(e.scale*e.radius,e.scale*e.radius,1):super.scale(e)}onParticleCreated(e){e.target||(e.body||(e.body=this._body),e.target=this._targetPool.get(e.body),(e.useAlpha||e.useColor)&&(e.target instanceof r.Mesh||e.target instanceof r.Sprite&&e.target.material instanceof r.Material)&&(e.target.material.__puid=m.id(e.body.material),e.target.material=this._materialPool.get(e.target.material))),e.target&&e.target instanceof t&&(e.target.position.set(e.position.x,e.position.y,e.position.z),this.container.add(e.target))}onParticleUpdate(e){const{target:t,useAlpha:a,useColor:n,rotation:o}=e;t&&(t.position.copy(e.position),this.isThreeSprite(e)||t.rotation.set(o.x,o.y,o.z),this.scale(e),t.material instanceof r.Material&&(a&&(t.material.opacity=e.alpha,t.material.transparent=!0),n&&t.material.color.copy(e.color)))}onParticleDead(e){e.target&&e.target.material&&((e.useAlpha||e.useColor)&&this._materialPool.expire(e.target.material),this._targetPool.expire(e.target),this.container.remove(e.target),e.target=null)}}export function materializeVfx(o,s,l){return e(this,void 0,void 0,(function*(){let d=s;if(!0!==o.vfx.localSpace)for(;null!=d.parent;)d=d.parent;const c=new t;c.name="particle system",d.add(c);const m=new Q(c,r),u=(new r.Mesh(new r.BoxGeometry(.3,.3,.3),new r.MeshStandardMaterial({color:16777215})),new a),p=yield Promise.all(o.vfx.emitters.map((a=>e(this,void 0,void 0,(function*(){let o,s;switch(a.rate.type){case"continuous":o=new A(a.rate.count,a.rate.time);break;case"once":o=new x(a.rate.count);break;default:console.warn(`Failed to configure rate for emitter: ${JSON.stringify(a)}`),o=new A(0,1/0)}switch(a.output.type){case"sprite":s=new n(yield function(t,a){var n,o;return e(this,void 0,void 0,(function*(){const e=null!=t.texture?yield a.getTexture(t.texture):U;var i=new r.SpriteMaterial({map:e,color:null!==(n=t.color)&&void 0!==n?n:16777215,blending:null!==(o=I[t.blendingMode])&&void 0!==o?o:r.NormalBlending,fog:!0,transparent:!0});return new r.Sprite(i)}))}(a.output,l));break;case"shape":s=new n(yield function(a,n){var o;return e(this,void 0,void 0,(function*(){const e=E[a.shape];if(null==e)return console.error(`No shape with type ${a.shape}`),new t;const i=P(null!==(o=a.params)&&void 0!==o?o:{}),s=e.geometry(i),l=null!=a.material?yield n.getMaterial(a.material):new r.MeshStandardMaterial({color:R});return new r.Mesh(s,l)}))}(a.output,l));break;case"mesh":s=new n(yield function(r,a){return e(this,void 0,void 0,(function*(){return null==r.assetId?(console.warn("Can't use mesh as particle without asset id"),new t):a.getMesh(r.assetId)}))}(a.output,l));break;default:console.error("Failed to create particly system body: "+JSON.stringify(a))}const d=(new i).setRate(o),c=yield Promise.all(a.initializers.filter((e=>null!=S[e.type])).map((t=>e(this,void 0,void 0,(function*(){var e;const r=S[t.type],a=yield P(null!==(e=t.params)&&void 0!==e?e:{});return r.build(a)})))));c.push(s),d.addInitializers(c);const m=yield Promise.all(a.behaviours.filter((e=>null!=B[e.type])).map((t=>e(this,void 0,void 0,(function*(){var e;const r=B[t.type],a=yield P(null!==(e=t.params)&&void 0!==e?e:{});return r.build(a)})))));return d.addBehaviours(m),d.emit()})))));return p.forEach((e=>u.addEmitter(e))),u.addRenderer(m).emit({onEnd:()=>{console.log("ended")}}),{system:u,dispose:()=>c.removeFromParent()}}))}const U=(new r.TextureLoader).load("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJkSURBVHjaxJeJbusgEEW94S1L//83X18M2MSuLd2pbqc4wZGqRLrKBsyZhQHny7Jk73xVL8xpVhWrcmiB5lX+6GJ5YgQ2owbAm8oIwH1VgKZUmGcRqKGGPgtEQQAzGR8hQ59fAmhJHSAagigJ4E7GPWRXOYC6owAd1JM6wDQPADyMWUqZRMqmAojHp1Vn6EQQEgUNMJLnUjMyJsM49wygBkAPw9dVFwXRkncCIIW3GRgoTQUZn6HxCMAFEFd8TwEQ78X4rHbILoAUmeT+RFG4UhQ6MiIAE4W/UsYFjuVjAIa2nIY4q1R0GFtQWG3E84lqw2GO2QOoCKBVu0BAPgDSU0eUDjjQenNkV/AW/pWChhpMTelo1a64AOKM30vk18GzTHXCNtI/Knz3DFBgsUqBGIjTInXRY1yA9xkVoqW5tVq3pDR9A0hfF5BSARmVnh7RMDCaIdcNgbPBkgzn1Bu+SfIEFSpSBmkxyrMicb0fAEuCZrWnN89veA/4XcakrPcjBWzkTuLjlbfTQPOlBhz+HwkqqPXmPQDdrQItxE1moGof1S74j/8txk8EHhTQrAE8qlwfqS5yukm1x/rAJ9Jiaa6nyATqD78aUVBhFo8b1V4DdTXdCW+IxA1zB4JhiOhZMEWO1HqnvdoHZ4FAMIhV9REF8FiUm0jsYPEJx/Fm/N8OhH90HI9YRHesWbXXZwAShU8qThe7H8YAuJmw5yOd989uRINKRTJAhoF8jbqrHKfeCYdIISZfSq26bk/K+yO3YvfKrVgiwQBHnwt8ynPB25+M8hceTt/ybPhnryJ78+tLgAEAuCFyiQgQB30AAAAASUVORK5CYII=");export function materializeVfxOld(e,m){let B=m;if(!0!==e.vfx.localSpace)for(;null!=B.parent;)B=B.parent;const S=new t;S.name="particle system",B.add(S);const I=new c(S,r),E=new r.Mesh(new r.BoxGeometry(.3,.3,.3),new r.MeshStandardMaterial({color:16777215})),P=new A(new y(3,9),new y(.02,.15)),R=new i,Q=new a;R.setLife(4).setRate(P).addInitializers([new d(1),new w(1),new l(1),new n(E),new p(new o(.5)),new h(10,new v(0,0,1),30)]).addBehaviours([new b(new r.Vector3(0,0,1),4),new s(0,0,.1),new f("random",2.5*-Math.PI,2*Math.PI,1,M.easeOutCubic),new g(1,.2)]).emit();const U=new x,V=(new i).setLife(5).addInitializers([new d(1),new w(1),new l(3),new n(E),new p(new u(0,0,0))]).addBehaviours([new g(4,6,void 0,M.easeOutExpo)]).setRate(U).emit();return U.nextTime=0,Q.addEmitter(R).addEmitter(V).addRenderer(I).emit({onEnd:()=>{console.log("ended")}}),{system:Q,rate:P,renderer:I,dispose:()=>S.removeFromParent()}}
1
+ import{__awaiter as e}from"tslib";import{Object3D as t}from"three";import*as r from"three";import a,{Behaviour as n,Body as i,BoxZone as o,Emitter as s,Force as l,Life as d,Mass as m,MeshRenderer as c,PUID as u,PointZone as p,Position as h,RadialVelocity as w,Radius as f,Rate as A,Rotate as g,Scale as y,Span as v,Vector3D as b,ease as M}from"three-nebula";import{RotatePosition as x}from"./behaviours";import{OnceRate as B}from"./rates";import{VfxBehaviourLibrary as S,VfxInitializserLibrary as I}from"./vfx-defs";import{ThreeBlendingMode as E}from"./vfx-asset";import{ShapeLibrary as P}from"../../scene/objects/shapes";import{prepareShapeParameters as R,shapeDefaultColor as Q}from"../../scene/materializer";import{particleEnergyUniformName as U,particleVelcoityUniformName as V}from"../../shader-nodes/particle";import{NodeShaderMaterial as k}from"three-shader-graph";class F extends c{scale(e){e.target instanceof r.Sprite?e.target.scale.set(e.scale*e.radius,e.scale*e.radius,1):super.scale(e)}onParticleCreated(e){e.target||(e.body||(e.body=this._body),e.target=this._targetPool.get(e.body),(e.useAlpha||e.useColor)&&(e.target instanceof r.Mesh||e.target instanceof r.Sprite&&e.target.material instanceof r.Material)&&(e.target.material.__puid=u.id(e.body.material),e.target.material=this._materialPool.get(e.target.material))),e.target&&e.target instanceof t&&(e.target.position.set(e.position.x,e.position.y,e.position.z),this.container.add(e.target))}onParticleUpdate(e){const{target:t,useAlpha:a,useColor:n,rotation:i}=e;t&&(t.position.copy(e.position),this.isThreeSprite(e)||t.rotation.set(i.x,i.y,i.z),this.scale(e),t.material instanceof r.Material&&(a&&(t.material.opacity=e.alpha,t.material.transparent=!0),n&&t.material.color.copy(e.color)))}onParticleDead(e){e.target&&e.target.material&&((e.useAlpha||e.useColor)&&this._materialPool.expire(e.target.material),this._targetPool.expire(e.target),this.container.remove(e.target),e.target=null)}}export function materializeVfx(n,o,l){return e(this,void 0,void 0,(function*(){let d=o;if(!0!==n.vfx.localSpace)for(;null!=d.parent;)d=d.parent;const m=new t;m.name="particle system",d.add(m);const c=new F(m,r),u=(new r.Mesh(new r.BoxGeometry(.3,.3,.3),new r.MeshStandardMaterial({color:16777215})),new a),p=yield Promise.all(n.vfx.emitters.map((a=>e(this,void 0,void 0,(function*(){let n,o;switch(a.rate.type){case"continuous":n=new A(a.rate.count,a.rate.time);break;case"once":n=new B(a.rate.count);break;default:console.warn(`Failed to configure rate for emitter: ${JSON.stringify(a)}`),n=new A(0,1/0)}switch(a.output.type){case"sprite":o=new i(yield function(t,a){var n,i;return e(this,void 0,void 0,(function*(){const e=null!=t.texture?yield a.getTexture(t.texture):C;var o=new r.SpriteMaterial({map:e,color:null!==(n=t.color)&&void 0!==n?n:16777215,blending:null!==(i=E[t.blendingMode])&&void 0!==i?i:r.NormalBlending,fog:!0,transparent:!0});return new r.Sprite(o)}))}(a.output,l));break;case"shape":o=new i(yield function(a,n){var i;return e(this,void 0,void 0,(function*(){const e=P[a.shape];if(null==e)return console.error(`No shape with type ${a.shape}`),new t;const o=R(null!==(i=a.params)&&void 0!==i?i:{}),s=e.geometry(o),l=null!=a.material?yield n.getMaterial(a.material):new r.MeshStandardMaterial({color:Q});return new r.Mesh(s,l)}))}(a.output,l));break;case"mesh":o=new i(yield function(r,a){return e(this,void 0,void 0,(function*(){return null==r.assetId?(console.warn("Can't use mesh as particle without asset id"),new t):a.getMesh(r.assetId)}))}(a.output,l));break;default:console.error("Failed to create particly system body: "+JSON.stringify(a))}const d=(new s).setRate(n),m=yield Promise.all(a.initializers.filter((e=>null!=I[e.type])).map((t=>e(this,void 0,void 0,(function*(){var e;const r=I[t.type],a=yield R(null!==(e=t.params)&&void 0!==e?e:{});return r.build(a)})))));m.push(o),d.addInitializers(m);const c=yield Promise.all(a.behaviours.filter((e=>null!=S[e.type])).map((t=>e(this,void 0,void 0,(function*(){var e;const r=S[t.type],a=yield R(null!==(e=t.params)&&void 0!==e?e:{});return r.build(a)})))));return c.push(new H),d.addBehaviours(c),d.emit()})))));return p.forEach((e=>u.addEmitter(e))),u.addRenderer(c).emit({onEnd:()=>{console.log("ended")}}),{system:u,dispose:()=>m.removeFromParent()}}))}const C=(new r.TextureLoader).load("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJkSURBVHjaxJeJbusgEEW94S1L//83X18M2MSuLd2pbqc4wZGqRLrKBsyZhQHny7Jk73xVL8xpVhWrcmiB5lX+6GJ5YgQ2owbAm8oIwH1VgKZUmGcRqKGGPgtEQQAzGR8hQ59fAmhJHSAagigJ4E7GPWRXOYC6owAd1JM6wDQPADyMWUqZRMqmAojHp1Vn6EQQEgUNMJLnUjMyJsM49wygBkAPw9dVFwXRkncCIIW3GRgoTQUZn6HxCMAFEFd8TwEQ78X4rHbILoAUmeT+RFG4UhQ6MiIAE4W/UsYFjuVjAIa2nIY4q1R0GFtQWG3E84lqw2GO2QOoCKBVu0BAPgDSU0eUDjjQenNkV/AW/pWChhpMTelo1a64AOKM30vk18GzTHXCNtI/Knz3DFBgsUqBGIjTInXRY1yA9xkVoqW5tVq3pDR9A0hfF5BSARmVnh7RMDCaIdcNgbPBkgzn1Bu+SfIEFSpSBmkxyrMicb0fAEuCZrWnN89veA/4XcakrPcjBWzkTuLjlbfTQPOlBhz+HwkqqPXmPQDdrQItxE1moGof1S74j/8txk8EHhTQrAE8qlwfqS5yukm1x/rAJ9Jiaa6nyATqD78aUVBhFo8b1V4DdTXdCW+IxA1zB4JhiOhZMEWO1HqnvdoHZ4FAMIhV9REF8FiUm0jsYPEJx/Fm/N8OhH90HI9YRHesWbXXZwAShU8qThe7H8YAuJmw5yOd989uRINKRTJAhoF8jbqrHKfeCYdIISZfSq26bk/K+yO3YvfKrVgiwQBHnwt8ynPB25+M8hceTt/ybPhnryJ78+tLgAEAuCFyiQgQB30AAAAASUVORK5CYII=");export function materializeVfxOld(e,n){let u=n;if(!0!==e.vfx.localSpace)for(;null!=u.parent;)u=u.parent;const S=new t;S.name="particle system",u.add(S);const I=new c(S,r),E=new r.Mesh(new r.BoxGeometry(.3,.3,.3),new r.MeshStandardMaterial({color:16777215})),P=new A(new v(3,9),new v(.02,.15)),R=new s,Q=new a;R.setLife(4).setRate(P).addInitializers([new m(1),new f(1),new d(1),new i(E),new h(new o(.5)),new w(10,new b(0,0,1),30)]).addBehaviours([new x(new r.Vector3(0,0,1),4),new l(0,0,.1),new g("random",2.5*-Math.PI,2*Math.PI,1,M.easeOutCubic),new y(1,.2)]).emit();const U=new B,V=(new s).setLife(5).addInitializers([new m(1),new f(1),new d(3),new i(E),new h(new p(0,0,0))]).addBehaviours([new y(4,6,void 0,M.easeOutExpo)]).setRate(U).emit();return U.nextTime=0,Q.addEmitter(R).addEmitter(V).addRenderer(I).emit({onEnd:()=>{console.log("ended")}}),{system:Q,rate:P,renderer:I,dispose:()=>S.removeFromParent()}}class H extends n{initialize(e){if(e.body instanceof r.Mesh){const t=e.body.material;t instanceof k&&(null!=t.uniforms[U]||null!=t.uniforms[V])&&(e.body.material=t.clone())}}mutate(e,t,a){if(e.target instanceof r.Mesh){const t=e.target.material;t instanceof k&&(null!=t.uniforms[U]&&(t.uniforms[U].value=this.energy),null!=t.uniforms[V]&&(t.uniforms[V].value=e.velocity))}}}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -0,0 +1,13 @@
1
+ import { Object3D } from "three";
2
+ import { VfxActor } from "./vfx-actor";
3
+ export declare class VisualEffect {
4
+ private actor;
5
+ constructor(actor: VfxActor);
6
+ play(): void;
7
+ stop(): void;
8
+ pause(): void;
9
+ restart(): void;
10
+ set timescale(value: number);
11
+ get timescale(): number;
12
+ get object(): Object3D;
13
+ }
@@ -0,0 +1,5 @@
1
+ export class VisualEffect{constructor(t){this.actor=t}play(){this.actor.play()}stop(){this.actor.stop()}pause(){this.actor.pause()}restart(){this.actor.restart()}set timescale(t){this.actor.timescale=t}get timescale(){return this.actor.timescale}get object(){return this.actor.object}}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,74 @@
1
+ import { Vector3D } from "three-nebula";
2
+ declare const SphereZone_base: any;
3
+ /**
4
+ * A spherical zone for particles to be emitted within.
5
+ *
6
+ */
7
+ export declare class SphereZone extends SphereZone_base {
8
+ private x;
9
+ private y;
10
+ private z;
11
+ private radius;
12
+ private the;
13
+ private phi;
14
+ protected random: number;
15
+ protected vector: Vector3D;
16
+ /**
17
+ * @constructs {SphereZone}
18
+ *
19
+ * @param {number} centerX - the sphere's center x coordinate
20
+ * @param {number} centerY - the sphere's center y coordinate
21
+ * @param {number} centerZ - the sphere's center z coordinate
22
+ * @param {number} radius - the sphere's radius value
23
+ * @return void
24
+ */
25
+ constructor(x: number, y: number, z: number, radius: number);
26
+ /**
27
+ * Returns true to indicate this is a SphereZone.
28
+ *
29
+ * @return {boolean}
30
+ */
31
+ isSphereZone(): boolean;
32
+ /**
33
+ * Sets the particle to dead if the particle collides with the sphere.
34
+ *
35
+ * @param {object} particle
36
+ * @return void
37
+ */
38
+ _dead(particle: any): void;
39
+ /**
40
+ * Warns that this zone does not support the _cross method.
41
+ *
42
+ * @return void
43
+ */
44
+ _cross(): void;
45
+ getPosition: () => Vector3D;
46
+ _bound: (particle: any) => void;
47
+ }
48
+ declare const PointZone_base: any;
49
+ export declare class PointZone extends PointZone_base {
50
+ private x;
51
+ private y;
52
+ private z;
53
+ /**
54
+ * PointZone is a point zone
55
+ * @param {Number|Vector3D} x - the center's x value or a Vector3D Object
56
+ * @param {Number} y - the center's y value
57
+ * @param {Number} z - the center's z value
58
+ * @example
59
+ * var pointZone = new System.PointZone(0,30,10);
60
+ * or
61
+ * var pointZone = new System.PointZone(new System.Vector3D(0,30,10));
62
+ * @extends {Zone}
63
+ * @constructor
64
+ */
65
+ constructor(x: number, y: number, z: number);
66
+ /**
67
+ * Returns true to indicate this is a PointZone.
68
+ *
69
+ * @return {boolean}
70
+ */
71
+ isPointZone(): boolean;
72
+ getPosition(): any;
73
+ }
74
+ export {};
@@ -0,0 +1,5 @@
1
+ import{Vector3D as t}from"three-nebula";import{SphereZone as s}from"three-nebula";const o=Math.PI;export class SphereZone extends(Object.getPrototypeOf(s)){constructor(s,i,e,r){var h,n,a;super("SphereZone"),this.x=s,this.y=i,this.z=e,this.radius=r,this.the=0,this.phi=0,this.vector=new t,this.getPosition=(()=>{var t,s,i;return()=>(this.random=Math.random(),i=this.random*this.radius,t=o*Math.random(),s=2*o*Math.random(),this.vector.x=this.x+i*Math.sin(t)*Math.cos(s),this.vector.y=this.y+i*Math.sin(s)*Math.sin(t),this.vector.z=this.z+i*Math.cos(t),this.vector)})(),this._bound=(n=new t,a=new t,function(t){t.position.distanceTo(this)+t.radius>=this.radius&&(n.copy(t.position).sub(this).normalize(),a.copy(t.velocity),h=2*a.dot(n),t.velocity.sub(n.scalar(h)))})}isSphereZone(){return!0}_dead(t){t.position.distanceTo(this)-t.radius>this.radius&&(t.dead=!0)}_cross(){console.warn(`${this.constructor.name} does not support the _cross method`)}}export class PointZone extends(Object.getPrototypeOf(s)){constructor(t,s,o){super("PointZone"),this.x=t,this.y=s,this.z=o}isPointZone(){return!0}getPosition(){return this.vector.x=this.x,this.vector.y=this.y,this.vector.z=this.z,this.vector}}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -12,3 +12,4 @@ export { Container as DIContainer } from 'typedi';
12
12
  export * from './animation/anim-sm';
13
13
  export * from './animation/root-motion';
14
14
  export * from './services/asset-loader';
15
+ export { VisualEffect } from '../effects/vfx/vfx-param';
@@ -1,4 +1,4 @@
1
- import"reflect-metadata";export*from"./initiate";export*from"./inject";export{Service,Inject}from"typedi";export{ActorFactory}from"./actors/factory";export{Actor,BaseActor}from"./actors/actor";export{Component,ActorComponent,attach,Attach}from"./actors/component";export*from"./services/world";export*from"./services/render";export*from"./services/physics/physics-system";export{Container as DIContainer}from"typedi";export*from"./animation/anim-sm";export*from"./animation/root-motion";export*from"./services/asset-loader";
1
+ import"reflect-metadata";export*from"./initiate";export*from"./inject";export{Service,Inject}from"typedi";export{ActorFactory}from"./actors/factory";export{Actor,BaseActor}from"./actors/actor";export{Component,ActorComponent,attach,Attach}from"./actors/component";export*from"./services/world";export*from"./services/render";export*from"./services/physics/physics-system";export{Container as DIContainer}from"typedi";export*from"./animation/anim-sm";export*from"./animation/root-motion";export*from"./services/asset-loader";export{VisualEffect}from"../effects/vfx/vfx-param";
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -197,6 +197,8 @@ export declare class SceneMaterializer {
197
197
  * be impossible to guarantee.
198
198
  */
199
199
  private initActorsPostInit;
200
+ private addVfxChildActors;
201
+ private removeVfxChildActors;
200
202
  private applyActorComponentParams;
201
203
  private _canBeInstancedCache;
202
204
  private canAssetBeInstanced;
@@ -1,4 +1,4 @@
1
- import{__awaiter as e}from"tslib";import{Subject as t}from"rxjs";import*as i from"three";import{BoxGeometry as r,Color as a,Euler as s,Fog as n,FogExp2 as o,Group as l,Material as c,Mesh as d,MeshLambertMaterial as h,MeshPhongMaterial as u,MeshStandardMaterial as m,Object3D as p,PointLight as f,Quaternion as v,SphereGeometry as y,Texture as g,Vector2 as w,Vector3 as A,Vector4 as S}from"three";import b,{SpriteRenderer as M}from"three-nebula";import{bool as x,BooleanNode as I,float as D,FloatNode as P,NodeShaderMaterial as N,rgb as j,RgbNode as E,Texture2dLookupNode as V,textureSampler2d as O,vec2 as F,Vec2Node as z,vec3 as B,Vec3Node as k,vec4 as C}from"three-shader-graph";import _ from"../gameplay/actors/builtin";import{extractShaderParameters as T}from"../shader/parameter";import{groupBy as $,ArrayMap as L}from"../utils/collections";import{filterChildrenShallow as R,filterSceneShallow as U}from"../utils/three/traverse";import{AssetMeshInstance as H}from"./asset-resource-loader";import{BoxCollisionShape as W,PhysicalShapeMesh as G}from"./collision/collision-shape";import{isCollisionMesh as J}from"./collision/collision-shape-import";import{initLandscape as X}from"./landscape/landscape";import{LandscapeManager as Y}from"./landscape/landscape-manager";import{SectionGrid as q,smoothNormalsCrossMeshes as Z}from"./landscape/utils";import{createGrassMaterial as K}from"./materials/grass";import{createGrassFoliageMaterial as Q}from"./materials/grass-foliage";import{getMaterialAttribute as ee}from"./materials/utils/material-painting";import{createWaterMaterial as te}from"./materials/water";import{SerializedParamType as ie}from"./model";import{Matrix4 as re}from"three";import{BaseActor as ae}from"../gameplay/actors/actor";import{Sampler2DNode as se}from"../shader-nodes";import{StandardShader as ne}from"../shader/builtin/standard-shader";import{LambertShader as oe}from"../shader/builtin/lambert-shader";import{ShapeLibrary as le,ShapeLibraryKeys as ce}from"./objects/shapes";import{ambientLightName as de,createSky as he,defaultSkyMaterial as ue}from"./sky";import{withInjectionContext as me}from"../gameplay";import{iterateMaterials as pe}from"../utils/materials";import{VfxActor as fe}from"../effects/vfx/vfx-actor";const ve={};export const shapeDefaultColor="#aaaaaa";export class SceneMaterializerLoader{constructor(e,t,i){this.dataProvider=e,this.assetsService=t,this.assetManagerService=i}get(t,i){return new SceneMaterializer(t,this.dataProvider,this.assetsService,this.assetManagerService,i,[],[],{create:()=>null,initActor:()=>e(this,void 0,void 0,(function*(){}))})}}export class SceneMaterializer{constructor(i,r,a,s,n,o,l,c){this.scene=i,this.dataProvider=r,this.assetsService=a,this.assetManagerService=s,this.renderingView=n,this.shaders=o,this.actorTypes=l,this.actorProvider=c,this.objectMap=new Map,this.sceneObjectMap=new Map,this.components=[],this.landscapeManagers=[],this.materializedActors=new Map,this.inEditor=!0,this.updated$=new t,this.removed$=new t,this.error$=new t,this.editorActorParamSnapshot=new Map,this._canBeInstancedCache=new Map,this._originalMaterials=new Map,this.originalFog=null,r.onUpdate((e=>this.update(e))),r.onRemove((e=>this.remove(e))),this.updateSubscription=a.onUpdate.subscribe((t=>e(this,void 0,void 0,(function*(){"material"==t.type?((yield this.assetsService.getAssets()).filter((e=>{var i;return(null!==(i=e.materialAssignments)&&void 0!==i?i:[]).some((e=>e.materialId===t.id))})).forEach((e=>{const t=this.findByAssetId(e.id);e.materialAssignments.forEach((e=>{t.forEach((t=>{const i=t.userData.src.materialAssignments;null!=i&&i.some((t=>t.color===e.color))||this.applyMaterial(t,e)}))}))})),U(this.scene,(e=>{var i;return null!=e.userData.src&&(null!==(i=e.userData.src.materialAssignments)&&void 0!==i?i:[]).some((e=>e.materialId===t.id))}),(e=>null!=e.userData.src)).forEach((t=>e(this,void 0,void 0,(function*(){this.deleteSceneObject(t.userData.src),this.materialize(t.userData.src)}))))):"mesh"==t.type?this.findByAssetId(t.id).forEach((e=>{De(e.userData.src.materialAssignments,t.materialAssignments).forEach((t=>{this.applyMaterial(e,t)}))})):"prefab"===t.type&&this.findByAssetId(t.id).forEach((e=>{const t=e.userData.src;this.remove(t),this.materializeAndInitActor(t)}))}))))}get actorInstances(){return Array.from(this.materializedActors.values())}prefetchAssets(){return e(this,void 0,void 0,(function*(){const e=Array.from(new Set(this.dataProvider.getObjects().filter((e=>null!=e.assetId&&"asset_mesh"==e.type)).filter((e=>e.assetId))));yield Promise.all(e.map((e=>this.assetsService.getAsset(e.assetId).then((e=>e&&this.assetManagerService.getMesh(e))))))}))}init(){return e(this,void 0,void 0,(function*(){this.preInit(),ge.clear(),yield this.prefetchAssets(),yield Promise.all(this.dataProvider.getObjects().map((e=>this.materialize(e)))),yield this.initActorsPostInit()}))}initActorsPostInit(t=this.actorInstances){const i=t.map((t=>e(this,void 0,void 0,(function*(){var e,i,r,a,s;const n=t.object.userData.src;if("vfx"===n.type)return Promise.resolve();const o=yield this.assetsService.getAsset(n.assetId),l=Object.assign(Object.assign({},null!==(i=null===(e=null==o?void 0:o.actor)||void 0===e?void 0:e.params)&&void 0!==i?i:{}),null!==(a=null===(r=n.actor)||void 0===r?void 0:r.params)&&void 0!==a?a:{});for(const e of null!==(s=n.actor.innerParams)&&void 0!==s?s:[])yield this.applyActorComponentParams(t,e.path.slice(),e.params);const c=yield Se(l,t.constructor,this.assetsService,this.assetManagerService,this.materializedActors,this.renderingView,this.shaders);Object.assign(t,c);try{return yield this.actorProvider.initActor(t)}catch(e){console.error(`Failed to initiate actor (name="${n.name}", id=${n.id})`,e)}}))));return Promise.all(i)}applyActorComponentParams(t,i,r){return e(this,void 0,void 0,(function*(){const e=i.length,a=i.shift();if(0==e){const e=yield Se(r,null,this.assetsService,this.assetManagerService,this.materializedActors,this.renderingView,this.shaders);for(const[i,r]of Object.entries(e))null!=r&&(t[i]=r)}else null!=t[a]&&(yield this.applyActorComponentParams(t[a],i,r))}))}canAssetBeInstanced(t){return e(this,void 0,void 0,(function*(){if(!this._canBeInstancedCache.has(t.assetId)){const e=yield this.createFromAsset(t);if(null==e)return!1;const i=[];e.traverse((e=>{!J(e)&&e.isMesh&&i.push(e)}));const r=1==i.length&&0==i[0].children.length,a=!0;this._canBeInstancedCache.set(t.assetId,r&&a)}return this._canBeInstancedCache.get(t.assetId)}))}preInit(){var e;null===(e=this.renderingView)||void 0===e||e.onLoop((()=>{var e;return null===(e=this.sky)||void 0===e?void 0:e.position.copy(this.renderingView.camera.position)}))}initWithInstancing(){return e(this,void 0,void 0,(function*(){this.preInit();const t=new L;for(const i of this.dataProvider.getObjects())yield Ie(i,((i,r,a)=>e(this,void 0,void 0,(function*(){var e,s;const n="asset_mesh"==i.type&&(yield this.canAssetBeInstanced(i))?i.assetId+JSON.stringify(null!==(e=i.materialAssignments)&&void 0!==e?e:[]):"other";"other"!==n&&r&&(null===(s=r.children)||void 0===s?void 0:s.length)>0&&r.children.splice(r.children.findIndex((e=>e.id===i.id)),1),"other"===n&&r||t.push(n,Object.assign(Object.assign({},i),{parentTransform:a}))}))));for(const[e,i]of t.entries())if("other"!==e&&i.length>0){const e=yield this.createFromAsset(i[0]);if(null==e)continue;const t=yield this.createInstancedMesh(i,e),r=new H;r.add(t),r.userData.src=i[0],e instanceof H&&(r.collisionShapes=e.collisionShapes),r.castShadow=!1,r.receiveShadow=!1,this.scene.add(r)}else yield Promise.all(i.map((e=>this.materialize(e))));yield this.initActorsPostInit()}))}createInstancedMesh(t,r){var a,n;return e(this,void 0,void 0,(function*(){const e=r.children.filter((e=>!J(e)))[0],o=yield this.assetsService.getAsset(t[0].assetId);yield this.applyMaterials(r,De(t[0].materialAssignments,o.materialAssignments)),e.updateMatrix();const l=e.geometry.clone().applyMatrix4(e.matrix),c=new i.InstancedMesh(l,e.material.clone(),t.length);c.material.side=i.FrontSide;for(let e=0;e<t.length;e++){const r=(new i.Matrix4).compose((new A).fromArray(t[e].position),(new v).setFromEuler((new s).fromArray(t[e].rotation)),(new A).fromArray(t[e].scale)),a=(new re).copy(t[e].parentTransform).multiply(r);c.setMatrixAt(e,a)}return c.castShadow=null===(a=o.castShadow)||void 0===a||a,c.receiveShadow=null===(n=o.receiveShadow)||void 0===n||n,c}))}remove(e){if("global_fog"==e.type)return void(this.scene.fog=this.originalFog);if("actor"==e.type){const t=this.materializedActors.get(e.id);null!=t&&t.disposed.next(!0)}const t=this.sceneObjectMap.get(e.id);null==t||t.parent.remove(t),this.sceneObjectMap.delete(e.id),this.components.filter((t=>{var i;return(null===(i=t.object.userData.src)||void 0===i?void 0:i.id)===e.id})).forEach((e=>this.components.splice(this.components.indexOf(e,1)))),this.landscapeManagers.filter((t=>t.source.id===e.id)).forEach((e=>{e.clear(),e.stop(),this.landscapeManagers.splice(this.landscapeManagers.indexOf(e,1))})),this.removed$.next({object:t,source:e})}deleteSceneObject(e){const t=this.sceneObjectMap.get(e.id);if(this.scene.remove(t),"landscape"==e.type){const t=this.landscapeManagers.findIndex((t=>t.source.id===e.id));if(t>-1){const e=this.landscapeManagers.splice(t,1)[0];e.clear(),e.stop()}}}findByAssetId(e){return U(this.scene,(t=>{var i;return(null===(i=t.userData.src)||void 0===i?void 0:i.assetId)==e}),(e=>null!=e.userData.src))}applyMaterials(e,t){return null==t?Promise.resolve([]):Promise.all(t.filter((e=>"null"!==e.materialId)).map((t=>this.applyMaterial(e,t))))}applyMaterial(t,i){const r=[];return t.traverse((t=>e(this,void 0,void 0,(function*(){if(t instanceof d||t.isMesh)for(const e of pe(t.material))e.hasOwnProperty("color")&&r.push(t)})))),Promise.all(r.map((t=>e(this,void 0,void 0,(function*(){var e,r,a,s;if(t.material instanceof Array)for(let a=0;a<t.material.length;a++){const s=t.material[a];if(null==s.color)continue;const n="#"+s.color.getHexString(),o=s.name;if(n===i.color&&(s.name===i.name||null==i.name)||t.userData["originalColor_"+a]===i.color&&t.userData["originalMaterialName_"+a]===i.name){const s=yield this.assetsService.getAsset(i.materialId),l=t.material[a];s&&(t.material[a]=yield materialFromAsset(s,this.renderingView,this.assetsService,this.assetManagerService,this.shaders),t.userData["originalColor_"+a]=null!==(e=t.userData["originalColor_"+a])&&void 0!==e?e:n,t.userData["originalMaterialName_"+a]=null!==(r=t.userData["originalMaterialName_"+a])&&void 0!==r?r:o,this.inEditor&&this._originalMaterials.set(t.id+"#"+a,l))}}else{const e="#"+t.material.color.getHexString(),r=t.material.name;if(e===i.color&&(t.material.name===i.name||null==i.name)||t.userData.originalColor===i.color&&t.userData.originalName===i.name){const n=yield this.assetsService.getAsset(i.materialId),o=t.material;n&&(t.material=yield materialFromAsset(n,this.renderingView,this.assetsService,this.assetManagerService,this.shaders),t.userData.originalColor=null!==(a=t.userData.originalColor)&&void 0!==a?a:e,t.userData.originalMaterialName=null!==(s=t.userData.originalMaterialName)&&void 0!==s?s:r,this.inEditor&&this._originalMaterials.set(t.id,o))}}})))))}unapplyMaterials(t){t.traverse((t=>e(this,void 0,void 0,(function*(){var e,i;if(t instanceof d)if(t.material instanceof Array)for(let i=0;i<t.material.length;i++)t.material[i]=null!==(e=this._originalMaterials.get(t.id+"#"+i))&&void 0!==e?e:t.material[i];else t.material=null!==(i=this._originalMaterials.get(t.id))&&void 0!==i?i:t.material}))))}updateActors(t){this.actorTypes=t;const i=new Set(Object.values(_));U(this.scene,(e=>{var t,r;return(null===(t=e.userData.src)||void 0===t?void 0:t.id)&&"actor"===e.userData.src.type&&this.materializedActors.has(null===(r=e.userData.src)||void 0===r?void 0:r.id)&&!i.has(e.userData.src.actor.type)})).forEach((t=>e(this,void 0,void 0,(function*(){this.remove(t.userData.src),yield this.materializeAndInitActor(t.userData.src)}))))}updateShaders(e){this.shaders=e;for(const[e,t]of ge.entries())t.userData.customShaderName&&ge.delete(e);this.landscapeManagers.forEach((t=>t.updateShaders(e))),U(this.scene,(e=>!0)).forEach((e=>{e.traverse((e=>{var t,i;if(e instanceof d){if(null!=(null===(t=e.material.userData)||void 0===t?void 0:t.customShaderName)){const t=null===(i=function(e,t){if(t(e))return e;let i;return e.traverseAncestors((e=>{null==i&&t(e)&&(i=e)})),i}(e,(e=>{var t;return null!=(null===(t=e.userData.src)||void 0===t?void 0:t.id)})))||void 0===i?void 0:i.userData.src;null!=t&&this.update(t)}}}))}))}update(t){return e(this,void 0,void 0,(function*(){if("sky"===t.type&&null!=this.sky&&null!=this.sky.parent)return void this.updateSky(t);const e=this.sceneObjectMap.get(t.id);if(e){const r=this.findParent(t);if(null!=r&&r.uuid!=e.uuid?r.attach(e):console.error("Parent is wrong"),"prefab"!==t.type){this.unapplyMaterials(e);this.inEditor&&t.hidden&&!1?e.traverse((e=>{e instanceof d&&(e.material.wireframe=!0)})):e.traverse((e=>{e instanceof d&&(e.material.wireframe=!1)}))}if("asset_mesh"===t.type){const i=yield this.assetsService.getAsset(t.assetId);De(t.materialAssignments,i.materialAssignments).forEach((t=>this.applyMaterial(e,t)))}else"shape_mesh"===t.type&&this.applyMaterials(e,t.materialAssignments);let s=!1;if(e.traverseAncestors((e=>{"_hology_transform_group"===e.name&&(s=!0)})),s||(e.position.fromArray(t.position),e.scale.fromArray(t.scale),e.rotation.fromArray(t.rotation)),this.applyVertexMaterials(t,e),"light"==t.type)if("point"==t.light.type){const i=e;i.color=new a(t.light.point.color),i.intensity=t.light.point.intensity,i.decay=t.light.point.decay,i.castShadow=t.light.point.castShadow,i.distance=Math.max(t.light.point.distance,0)}else"directional"===t.light.type?this.applyDirectionalLight(t.light.directional):"ambient"===t.light.type&&this.applyDirectionalAmbientLight(e,t.light.ambient);else if("landscape"===t.shape)this.applyHeightMaps(e,t.landscape.heightMaps),this.inEditor&&this.landscapeManagers.filter((e=>e.source.id===t.id)).forEach((e=>e.queueRefreshScatter(this.renderingView.camera.position,!0,(e=>!0))));else if("global_fog"===t.type){const e=(this.scene.fog instanceof o?"density":"linear")!==t.fog.type;this.scene.fog=Me(t.fog),e&&(i=this.scene).traverse((e=>{if(e instanceof d){const t=e.material;t instanceof N&&(i.fog instanceof n?(t.uniforms.fogFar.value=i.fog.far,t.uniforms.fogNear.value=i.fog.near):i.fog instanceof o&&(t.uniforms.density={value:i.fog.density}),t.needsUpdate=!0,t.uniformsNeedUpdate=!0)}})),this.fixFogColor()}else if("actor"===t.type){if(this.materializedActors.has(t.id)){const e=this.editorActorParamSnapshot.get(t.id);null!=e&&e===JSON.stringify(t.actor)||(console.log("Rematerializing actor because parameters changed"),this.remove(t),yield this.materializeAndInitActor(t))}}else if("shape_mesh"===t.type){const i=yield this.createMeshByShape(t.shape,e.material,t.shapeParams);e instanceof G&&(e.geometry=i.geometry,e.collisionShape=i.collisionShape)}("asset_mesh"===t.type||"shape_mesh"===t.type&&"landscape"!==t.shape)&&ye(e,t.castShadow,t.receiveShadow),t.name&&t.name.length>0&&(e.name=t.name),this.updated$.next({object:e,source:t})}else{const e=yield this.materializeAndInitActor(t);this.updated$.next({object:e,source:t})}var i}))}materializeAndInitActor(t,i=this.findParent(t)){return e(this,void 0,void 0,(function*(){const r=yield this.materialize(t,i);return Ie(t,(t=>e(this,void 0,void 0,(function*(){if("actor"===t.type){const e=this.materializedActors.get(t.id);null!=e?yield this.initActorsPostInit([e]):console.error(`Something went wrong when creating actor ${t.id}`)}})))),r}))}findParent(e){const t=this.dataProvider.getObjects().flatMap((t=>t.id===e.id?null:R(t,(t=>{var i;return null===(i=t.children)||void 0===i?void 0:i.some((t=>t.id===e.id))}),(()=>!0))))[0];return null==t?this.scene:null!=t?U(this.scene,(e=>{var i,r;return(null===(r=null===(i=e.userData)||void 0===i?void 0:i.src)||void 0===r?void 0:r.id)===t.id}),(e=>{var t;return null!=(null===(t=e.userData)||void 0===t?void 0:t.src)}))[0]:void 0}fixFogColor(){!0===this.renderingView.options.enableOutlines&&(this.scene.fog.color=new a(this.scene.fog.color).convertSRGBToLinear())}findMeshWithGeometry(e){let t;return e.traverse((e=>{e instanceof d&&e.geometry&&(t=e)})),t}applyVertexMaterials(e,t){if(null==e.vertexMaterials||0===e.vertexMaterials.length)return;const i=$(e.vertexMaterials,(e=>e.m));t.traverse((e=>{if(e instanceof d){const t=ee(e,!1);if(null!=t){for(let e=0;e<t.array.length;e++)t.setX(e,0);t.needsUpdate=!0}}}));const r=new Set;for(const[e,a]of i.entries()){const i=null!=e?t.getObjectByName(e):this.findMeshWithGeometry(t);let s=!1;if(null==i)return void console.warn(`Failed to apply vertex materials on mesh with name "${e}"`);const n=ee(i,!0);for(let e=0;e<n.array.length;e++)n.setX(e,0);for(const e of a)n.setX(e.i,e.w[0]),n.setY(e.i,e.w[1]),n.setZ(e.i,e.w[2]),s=!0;s&&r.add(e)}this.inEditor&&this.landscapeManagers.filter((t=>t.source.id===e.id)).forEach((e=>e.queueRefreshScatter(this.renderingView.camera.position,!0,(e=>r.has(e.name)))))}materialize(t,i,a=!1){var s,n,o,c;return e(this,void 0,void 0,(function*(){let e;switch(t.type){case"asset_mesh":e=yield this.createFromAsset(t);break;case"shape_mesh":e=yield this.createFromShape(t);break;case"light":e=yield this.createLight(t);break;case"particles":e=yield this.createParticleSystem(t),t.collisionDetection=!1;break;case"global_fog":this.scene.fog=Me(t.fog),this.fixFogColor(),e=new l;break;case"sky":this.sky=he(),this.updateSky(t),e=this.sky;break;case"actor":e=yield this.createFromActor(t);break;case"group":e=new l;break;case"prefab":e=yield this.createFromPrefabAsset(t);break;case"vfx":e=yield this.createFromVfx(t);break;default:throw console.log(t),new Error("unknown type "+t.type)}if(null!=e){if(t.name&&t.name.length>0&&(e.name=t.name),e.position.fromArray(t.position),e.scale.fromArray(t.scale),e.rotation.fromArray(t.rotation),a||(e.userData.src=t),!this.inEditor){const i=null!==(s=t.components)&&void 0!==s?s:[],r=null!=t.assetId&&null!==(o=null===(n=yield this.assetsService.getAsset(t.assetId))||void 0===n?void 0:n.components)&&void 0!==o?o:[];i.push(...r),i.length>0?e.userData.componentRefs=yield Promise.all(i.map(((i,r)=>this.createComponent(e,t,i,r)))):"asset_mesh"==t.type&&function(e){e.traverse((e=>{e.matrixAutoUpdate=!1,e.matrixWorldNeedsUpdate=!1}));const t=e.updateMatrixWorld;e.updateMatrixWorld=function(){t.apply(e),e.updateMatrixWorld=function(){}}}(e)}if(this.inEditor){let t=null;e instanceof G&&(t=function(e){if(e instanceof W)return new d(new r(...e.offset.toArray()),xe);return null}(e.collisionShape)),null!=t&&(t.layers.disable(0),t.layers.enable(18),t.scale.multiplyScalar(1.1),e.add(t))}return this.objectMap.set(e.uuid,t),this.sceneObjectMap.set(t.id,e),null==i?this.scene.add(e):null==i||i.add(e),null!=t.children&&(yield Promise.all(null===(c=t.children)||void 0===c?void 0:c.map((t=>this.materialize(t,e,a))))),e}}))}updateSky(t){var r;return e(this,void 0,void 0,(function*(){if(null==(null===(r=null==t?void 0:t.sky)||void 0===r?void 0:r.materialId))return void(this.sky.material=ue);const e=yield this.assetsService.getAsset(t.sky.materialId),a=yield materialFromAsset(e,this.renderingView,this.assetsService,this.assetManagerService,this.shaders,!1);a.side=i.BackSide,null!=this.sky?this.sky.material=a:console.warn("No sky has been created")}))}createComponent(t,i,r,a){return e(this,void 0,void 0,(function*(){const e=new ve[r.path+"/"+r.className],s=i.id+a;e.id=s,e.object=t;for(const t of r.params)null!=t.value&&(e[t.name]=t.value);return this.components.push(e),s}))}createFromActor(t){var i,r,a;return e(this,void 0,void 0,(function*(){const e=null!==(r=null===(i=this.actorTypes.find((e=>{var i;return e.name===(null===(i=t.actor)||void 0===i?void 0:i.type)})))||void 0===i?void 0:i.type)&&void 0!==r?r:_[null===(a=t.actor)||void 0===a?void 0:a.type];if(null==e)return null;this.inEditor&&this.editorActorParamSnapshot.set(t.id,JSON.stringify(t.actor));const n=yield this.actorProvider.create(e,(new A).fromArray(t.position),(new s).fromArray(t.rotation),!0);return this.materializedActors.set(t.id,n),null==n?void 0:n.object}))}createFromVfx(t){return e(this,void 0,void 0,(function*(){const e=yield this.assetsService.getAsset(t.assetId);null==e&&console.error("Could not find asset",t);const i=fe,r=yield this.actorProvider.create(i,(new A).fromArray(t.position),(new s).fromArray(t.rotation),!1);return yield r.fromAsset(e),r.play(),this.materializedActors.set(t.id,r),null==r?void 0:r.object}))}cleanup(){this.materializedActors.clear()}createFromShape(t){var i,r,s;return e(this,void 0,void 0,(function*(){const e=this.inEditor&&t.hidden;let n;if("landscape"==t.shape)n=this.createLandscape(t);else{let s=new m({name:"Default",color:new a("#aaaaaa"),visible:this.inEditor||!t.hidden,wireframe:!!e});const o=yield this.createMeshByShape(t.shape,s,t.shapeParams);o.castShadow=null===(i=t.castShadow)||void 0===i||i,o.receiveShadow=null!==(r=t.castShadow)&&void 0!==r&&r,t.collisionDetection||(o.collisionShape=null),n=o,this._originalMaterials.set(n.id,o.material),n.traverse((e=>{}))}return e||((null!==(s=t.materialAssignments)&&void 0!==s?s:[]).filter((e=>null!=e.materialId)).forEach((e=>this.applyMaterial(n,e))),this.applyVertexMaterials(t,n)),n}))}createLandscape(e){var t;if(null==(null===(t=e.landscape)||void 0===t?void 0:t.options))return console.error(`No landscape options exist on scene object ${e.id} ${e.name}`),new l;const i=X(e.landscape.options);this.applyHeightMaps(i,e.landscape.heightMaps,!0);const r=new Y(e,this.renderingView,i,this.assetManagerService,this.assetsService,this.shaders,(t=>{var i;(null!==(i=e.materialAssignments)&&void 0!==i?i:[]).filter((e=>null!=e.materialId)).forEach((e=>this.applyMaterial(t,e)))}));return this.landscapeManagers.push(r),r.refreshGeometry(),i}applyHeightMaps(e,t,i=!1){const r=new q(e.sections);for(const e of null!=t?t:[]){const t=r.find(e.x,e.y);if(!t)return;const i=t.geometry.getAttribute("position");for(const t of e.points)i.setY(t.i,t.y);i.needsUpdate=!0}const a=e.sections;a.forEach((e=>{e.geometry.computeBoundsTree(),e.geometry.computeVertexNormals()})),this.inEditor&&!i||setTimeout((()=>Z(a)),50)}createMeshByShape(t,i,r={}){return e(this,void 0,void 0,(function*(){if("landscape"!==t&&ce.includes(t)){const e=yield prepareShapeParameters(null!=r?r:{});return"cylinder"==t&&e.openEnded,new G(le[t].geometry(e),i,le[t].collision(e))}throw new Error(`Unsupported shape '${t}'`)}))}createFromAsset(t){var i,r,a,s;return e(this,void 0,void 0,(function*(){const e=yield this.assetsService.getAsset(t.assetId);if(null==e)return void console.warn(`Can not find asset with id ${t.assetId} and name ${t.name}`);let{scene:n}=yield this.assetManagerService.getMesh(e);De(t.materialAssignments,e.materialAssignments).forEach((e=>this.applyMaterial(n,e)));const o=null===(r=null!==(i=t.receiveShadow)&&void 0!==i?i:!!e.receiveShadow)||void 0===r||r,l=null!==(s=null!==(a=t.castShadow)&&void 0!==a?a:!!e.castShadow)&&void 0!==s&&s;return n.receiveShadow=o,ye(n,l,o),t.collisionDetection||(n.collisionShapes=[]),this.applyVertexMaterials(t,n),n.traverse((e=>{e instanceof d&&"computeBoundsTree"in e.geometry&&e.geometry.computeBoundsTree()})),n}))}createFromPrefabAsset(t){return e(this,void 0,void 0,(function*(){const e=yield this.assetsService.getAsset(t.assetId);if(null==e)return void console.warn(`Can not find asset with id ${t.assetId} and name ${t.name}`);const i=new l;return e.prefab.objects.filter((e=>"global_fog"!==e.type)).forEach((e=>this.materialize(e,i,!0))),i}))}createParticleSystem(t){return e(this,void 0,void 0,(function*(){const e=yield this.assetsService.getAsset(t.assetId),r=new p;return yield b.fromJSONAsync(e.particleSystem,i).then((e=>{const t=new M(r,i);e.addRenderer(t),this.renderingView.onLoop((t=>e.update()))})),r}))}createLight(t){var i;return e(this,void 0,void 0,(function*(){if("point"===t.light.type){const e=new f(t.light.point.color,t.light.point.intensity,t.light.point.distance,t.light.point.decay);if(e.castShadow=null===(i=t.light.point.castShadow)||void 0===i||i,this.inEditor){const t=new y(.3,10,10),i=new m({color:new a(16771709)}),r=new d(t,i);e.add(r)}return e}return"directional"===t.light.type?(this.applyDirectionalLight(t.light.directional),new l):"ambient"===t.light.type?(this.applyDirectionalAmbientLight(null,t.light.ambient),new l):void 0}))}applyDirectionalAmbientLight(e,t){const i=this.scene.children.find((e=>e.name===de));null!=i?(i.intensity=t.intensity,i.color.set(t.color),i.groundColor.set(t.color)):console.warn("Couldn't find ambient light")}applyDirectionalLight(e){for(const t of this.renderingView.csm.lights)t.intensity=e.intensity,t.color.set(e.color),t.castShadow=e.castShadow;this.renderingView.csm.lightDirection.fromArray(e.direction).normalize()}dispose(){this.updateSubscription.unsubscribe()}}function ye(e,t,i){e.castShadow=t,e.receiveShadow=i,e.traverse((e=>{e.castShadow=t,e.receiveShadow=i}))}const ge=new Map,we=new h({color:16711935}),Ae=new Map;export function materialFromAsset(t,r,s,n,o,l=!0){var c,d,h,m,p,f,v,y,g,w,A;return e(this,void 0,void 0,(function*(){const e=JSON.stringify(t.material);if(l&&ge.has(e))return ge.get(e);const S={opacity:t.material.params.opacity,map:null,emissive:null!==(c=t.material.params.emissive)&&void 0!==c?c:null,metalness:null!==(d=t.material.params.metalness)&&void 0!==d?d:0,flatShading:null!==(h=t.material.params.flatShading)&&void 0!==h&&h,color:new a(t.material.params.color).convertSRGBToLinear(),transparent:null!=t.material.params.opacity&&t.material.params.opacity<1},b={};if(null!=t.material.params.map){const e=t.material.params.map,i=yield s.getAsset(e);null!=i&&(S.map=yield n.getTexture(i))}let M;switch(t.material.type){case"phong":M=new u(Object.assign(Object.assign({},S),b));break;case"water":M=te(S,r);break;case"grassFoliage":M=Q({color:S.color,map:S.map},r);break;case"grass":M=K(Object.assign(Object.assign({},S),{colorTwo:new a(t.material.params.colorTwo),colorThree:new a(t.material.params.colorThree)}),r);break;case"standard":case"lambert":case"shader":const e=null!==(m={standard:ne,lambert:oe}[t.material.type])&&void 0!==m?m:null===(p=o.find((e=>e.name==t.material.shader)))||void 0===p?void 0:p.type;if(e){const i=new e,a=yield Se(null!==(v=null===(f=t.material)||void 0===f?void 0:f.shaderParams)&&void 0!==v?v:{},e,s,n,null,r,o);Object.assign(i,a);try{M=i.build()}catch(e){console.log("Shader runtime error: "+e),Ae.has(t.material.shader)||Ae.set(t.material.shader,we.clone()),M=Ae.get(t.material.shader)}M.userData.customShaderName=t.material.shader}else console.warn("Missing shader implementation with name "+t.material.shader),M=we;break;default:throw new Error("Unsupported material type"+t.material.type)}return null==r||r.csm.setupMaterial(M),l&&ge.set(e,M),M.side=null!==(g=null!==(y=t.material.side)&&void 0!==y?y:M.side)&&void 0!==g?g:i.FrontSide,M.transparent=null!==(A=null!==(w=t.material.transparent)&&void 0!==w?w:S.transparent)&&void 0!==A&&A||M.transparent,M}))}function Se(t,i,r,a,s,n,o){return e(this,void 0,void 0,(function*(){const e={};for(const[i,l]of Object.entries(t)){const t=yield be(l,r,a,s,n,o);null!=t&&(e[i]=t)}return e}))}export function prepareShapeParameters(t){return e(this,void 0,void 0,(function*(){const e={};for(const[i,r]of Object.entries(t)){const t=yield be(r,null,null,null);null!=t&&(e[i]=t)}return e}))}function be(t,i,r,n,o,l){return e(this,void 0,void 0,(function*(){if(null==t||null==t.value||""==t.value)return null;const e=t.value;switch(t.type){case ie.Number:case ie.FloatNode:let c="string"==typeof e?parseFloat(e):e;return t.type===ie.FloatNode?D(c):c;case ie.Texture:return yield r.getTexture(yield i.getAsset(e));case ie.Sampler2DNode:return O(yield r.getTexture(yield i.getAsset(e)));case ie.Boolean:return e;case ie.BooleanNode:return x(e);case ie.Vector2:case ie.Vec2Node:if("object"==typeof e){const i=e instanceof Array?(new w).fromArray(e):new w(e.x,e.y);return t.type===ie.Vec2Node?F(i):i}return null;case ie.Vector3:case ie.Vec3Node:if("object"==typeof e){const i=e instanceof Array?(new A).fromArray(e):new A(e.x,e.y,e.z);return t.type===ie.Vec3Node?B(i):i}return null;case ie.Color:case ie.RgbNode:const d=new a(e).convertSRGBToLinear();return t.type===ie.RgbNode?j(d):d;case ie.String:return e;case ie.BaseActor:const h=e;return null==n&&console.warn("Class parameters can not be prepared as actors are not passed in"),null==n?void 0:n.get(h);case ie.Euler:const u=e;return(new s).fromArray(u);case ie.Object3D:return(yield r.getMesh(yield i.getAsset(e))).scene;case ie.Material:return yield materialFromAsset(yield i.getAsset(e),o,i,r,l);case ie.AudioBuffer:return yield r.getAudio(yield i.getAsset(e))}return null}))}function Me(e){var t,i;return"linear"===e.type?new n(new a(e.color),null!==(t=e.near)&&void 0!==t?t:100,null!==(i=e.far)&&void 0!==i?i:1e3):"density"===e.type?new o(e.color,e.density):void console.warn("Invalid fog type",e)}const xe=new m({color:4229780});function Ie(t,r,a,n){var o;return e(this,void 0,void 0,(function*(){null==n&&(n=(new re).identity()),yield r(t,a,n);const e=n.clone().multiply(function(e,t){return t.compose((new A).fromArray(e.position),(new v).setFromEuler((new s).fromArray(e.rotation)),(new A).fromArray(e.scale))}(t,new i.Matrix4));return Promise.all((null!==(o=t.children)&&void 0!==o?o:[]).map((i=>Ie(i,r,t,e))))}))}export function toSerializedParamType(e){const t=e.constructor.prototype;return t instanceof Number||e===Number?ie.Number:t instanceof P||"function"==typeof e.prototype.isFloat?ie.FloatNode:t instanceof g||e===g||e.isTexture?ie.Texture:t instanceof se||e===V?ie.Sampler2DNode:t instanceof Boolean||e===Boolean?ie.Boolean:t instanceof I?ie.BooleanNode:t instanceof a||e==a?ie.Color:t instanceof E||"function"==typeof e.prototype.isRgb?ie.RgbNode:t instanceof w||e==w?ie.Vector2:t instanceof z||"function"==typeof e.prototype.isVec2?ie.Vec2Node:t instanceof A||e==A?ie.Vector3:t instanceof k||"function"==typeof e.prototype.isVec3?ie.Vec3Node:t instanceof String||e===String?ie.String:t instanceof ae||e==ae||e.prototype instanceof ae||e.prototype==ae?ie.BaseActor:t instanceof s||e==s?ie.Euler:t instanceof p||e==p?ie.Object3D:t instanceof c||e==c?ie.Material:t instanceof AudioBuffer||e==AudioBuffer?ie.AudioBuffer:void console.warn("Failed to map parameter type to serialized version",{type:e})}export function prepareCustomParams(e,t,i={}){return Object.fromEntries(e.map((e=>{var r,a,s;return[e.name,{type:toSerializedParamType(e.type),value:null!==(s=null!==(a=null===(r=t[e.name])||void 0===r?void 0:r.value)&&void 0!==a?a:i[e.name])&&void 0!==s?s:customParameterDefaultValueByType.get(toSerializedParamType(e.type))}]})))}export function prepareCustomParamsFromType(e,t,i=null){const r=T(e);if(0===r.length)return{};let a;null!=i?me(i,(()=>{a=i.get(e)})):a=new e;const s={};for(const e of r){const t=a[e.name];if(null!=t){const i=serializeCustomParameter(e.type,t);null!=i&&(s[e.name]=i)}}return prepareCustomParams(r,t,s)}export function serializeCustomParameter(e,t){function i(){console.error("Failed to serialize value",{type:e,value:t})}switch(e){case Number:case Boolean:return t;case w:return t instanceof w?t.toArray():void i();case A:return t instanceof A?t.toArray():void i();case S:return t instanceof S?t.toArray():void i();case a:return t instanceof a?"#"+t.getHexString():"string"==typeof t?t:"number"==typeof t?"#"+new a(t).getHexString():void i();case String:return t;case s:return t instanceof s?t.toArray():void i()}}function De(e,t){return function(e,t,i){const r=[],a=new Set;for(const s of[...null!=e?e:[],...null!=t?t:[]]){const e=i(s);a.has(e)||(a.add(e),r.push(s))}return r}((null!=e?e:[]).filter((e=>Pe(e.materialId))),(null!=t?t:[]).filter((e=>Pe(e.materialId))),(e=>e.color+e.name))}function Pe(e){return"null"!=e&&null!=e}export const customParameterDefaultValueByType=new Map([[ie.RgbNode,"#000000"],[ie.Color,"#000000"],[ie.Vector4,[0,0,0,0]],[ie.Vec4Node,[0,0,0,0]],[ie.Vector3,[0,0,0]],[ie.Vec3Node,[0,0,0]],[ie.Vector2,[0,0]],[ie.Vec2Node,[0,0]],[ie.Euler,[0,0,0,"XYZ"]]]);
1
+ import{__awaiter as e}from"tslib";import{Subject as t}from"rxjs";import*as i from"three";import{BoxGeometry as r,Color as a,Euler as s,Fog as o,FogExp2 as n,Group as l,Material as c,Mesh as d,MeshLambertMaterial as h,MeshPhongMaterial as u,MeshStandardMaterial as m,Object3D as p,PointLight as f,Quaternion as v,SphereGeometry as y,Texture as g,Vector2 as w,Vector3 as A,Vector4 as S}from"three";import b,{SpriteRenderer as M}from"three-nebula";import{bool as x,BooleanNode as I,float as P,FloatNode as D,NodeShaderMaterial as j,rgb as V,RgbNode as E,Texture2dLookupNode as N,textureSampler2d as C,vec2 as O,Vec2Node as F,vec3 as k,Vec3Node as z,vec4 as B}from"three-shader-graph";import _ from"../gameplay/actors/builtin";import{extractShaderParameters as T}from"../shader/parameter";import{groupBy as $,ArrayMap as L}from"../utils/collections";import{filterChildrenShallow as R,filterSceneShallow as U}from"../utils/three/traverse";import{AssetMeshInstance as H}from"./asset-resource-loader";import{BoxCollisionShape as W,PhysicalShapeMesh as G}from"./collision/collision-shape";import{isCollisionMesh as J}from"./collision/collision-shape-import";import{initLandscape as X}from"./landscape/landscape";import{LandscapeManager as Y}from"./landscape/landscape-manager";import{SectionGrid as q,smoothNormalsCrossMeshes as Z}from"./landscape/utils";import{createGrassMaterial as K}from"./materials/grass";import{createGrassFoliageMaterial as Q}from"./materials/grass-foliage";import{getMaterialAttribute as ee}from"./materials/utils/material-painting";import{createWaterMaterial as te}from"./materials/water";import{SerializedParamType as ie}from"./model";import{Matrix4 as re}from"three";import{BaseActor as ae}from"../gameplay/actors/actor";import{Sampler2DNode as se}from"../shader-nodes";import{StandardShader as oe}from"../shader/builtin/standard-shader";import{LambertShader as ne}from"../shader/builtin/lambert-shader";import{ShapeLibrary as le,ShapeLibraryKeys as ce}from"./objects/shapes";import{ambientLightName as de,createSky as he,defaultSkyMaterial as ue}from"./sky";import{ActorComponent as me,withInjectionContext as pe}from"../gameplay";import{iterateMaterials as fe}from"../utils/materials";import{VfxActor as ve}from"../effects/vfx/vfx-actor";import{VisualEffect as ye}from"../effects/vfx/vfx-param";const ge={};export const shapeDefaultColor="#aaaaaa";export class SceneMaterializerLoader{constructor(e,t,i){this.dataProvider=e,this.assetsService=t,this.assetManagerService=i}get(t,i){return new SceneMaterializer(t,this.dataProvider,this.assetsService,this.assetManagerService,i,[],[],{create:()=>null,initActor:()=>e(this,void 0,void 0,(function*(){}))})}}export class SceneMaterializer{constructor(i,r,a,s,o,n,l,c){this.scene=i,this.dataProvider=r,this.assetsService=a,this.assetManagerService=s,this.renderingView=o,this.shaders=n,this.actorTypes=l,this.actorProvider=c,this.objectMap=new Map,this.sceneObjectMap=new Map,this.components=[],this.landscapeManagers=[],this.materializedActors=new Map,this.inEditor=!0,this.updated$=new t,this.removed$=new t,this.error$=new t,this.editorActorParamSnapshot=new Map,this._canBeInstancedCache=new Map,this._originalMaterials=new Map,this.originalFog=null,r.onUpdate((e=>this.update(e))),r.onRemove((e=>this.remove(e))),this.updateSubscription=a.onUpdate.subscribe((t=>e(this,void 0,void 0,(function*(){"material"==t.type?((yield this.assetsService.getAssets()).filter((e=>{var i;return(null!==(i=e.materialAssignments)&&void 0!==i?i:[]).some((e=>e.materialId===t.id))})).forEach((e=>{const t=this.findByAssetId(e.id);e.materialAssignments.forEach((e=>{t.forEach((t=>{const i=t.userData.src.materialAssignments;null!=i&&i.some((t=>t.color===e.color))||this.applyMaterial(t,e)}))}))})),U(this.scene,(e=>{var i;return null!=e.userData.src&&(null!==(i=e.userData.src.materialAssignments)&&void 0!==i?i:[]).some((e=>e.materialId===t.id))}),(e=>null!=e.userData.src)).forEach((t=>e(this,void 0,void 0,(function*(){this.deleteSceneObject(t.userData.src),this.materialize(t.userData.src)}))))):"mesh"==t.type?this.findByAssetId(t.id).forEach((e=>{je(e.userData.src.materialAssignments,t.materialAssignments).forEach((t=>{this.applyMaterial(e,t)}))})):"prefab"===t.type&&this.findByAssetId(t.id).forEach((e=>{const t=e.userData.src;this.remove(t),this.materializeAndInitActor(t)}))}))))}get actorInstances(){return Array.from(this.materializedActors.values())}prefetchAssets(){return e(this,void 0,void 0,(function*(){const e=Array.from(new Set(this.dataProvider.getObjects().filter((e=>null!=e.assetId&&"asset_mesh"==e.type)).filter((e=>e.assetId))));yield Promise.all(e.map((e=>this.assetsService.getAsset(e.assetId).then((e=>e&&this.assetManagerService.getMesh(e))))))}))}init(){return e(this,void 0,void 0,(function*(){this.preInit(),Ae.clear(),yield this.prefetchAssets(),yield Promise.all(this.dataProvider.getObjects().map((e=>this.materialize(e)))),yield this.initActorsPostInit()}))}initActorsPostInit(t=this.actorInstances){const i=t.map((t=>e(this,void 0,void 0,(function*(){var e,i,r,a,s;const o=t.object.userData.src;if("vfx"===o.type)return Promise.resolve();const n=yield this.assetsService.getAsset(o.assetId),l=Object.assign(Object.assign({},null!==(i=null===(e=null==n?void 0:n.actor)||void 0===e?void 0:e.params)&&void 0!==i?i:{}),null!==(a=null===(r=o.actor)||void 0===r?void 0:r.params)&&void 0!==a?a:{});this.removeVfxChildActors(t);for(const e of null!==(s=o.actor.innerParams)&&void 0!==s?s:[])yield this.applyActorComponentParams(t,e.path.slice(),e.params);const c=yield Me(l,t.constructor,this.assetsService,this.assetManagerService,this.materializedActors,this.renderingView,this.shaders,this.actorProvider);Object.assign(t,c),this.addVfxChildActors(t);try{return yield this.actorProvider.initActor(t)}catch(e){console.error(`Failed to initiate actor (name="${o.name}", id=${o.id})`,e)}}))));return Promise.all(i)}addVfxChildActors(e,t=e){for(const i of Object.keys(t))t[i]instanceof ye?null!=t[i].actor&&(console.log("add actor to world",t[i].actor),e.object.add(t[i].actor.object)):t[i]instanceof me&&this.addVfxChildActors(e,t[i])}removeVfxChildActors(e,t=e){for(const i of Object.keys(t))if(t[i]instanceof ye){if(null!=t[i].actor){t[i].actor.onEndPlay(),console.log("remve actor from world",t[i].actor),e.object.remove(t[i].actor.object)}}else t[i]instanceof me&&this.removeVfxChildActors(e,t[i])}applyActorComponentParams(t,i,r){return e(this,void 0,void 0,(function*(){const e=i.length,a=i.shift();if(0==e){const e=yield Me(r,null,this.assetsService,this.assetManagerService,this.materializedActors,this.renderingView,this.shaders);for(const[i,r]of Object.entries(e))null!=r&&(t[i]=r)}else null!=t[a]&&(yield this.applyActorComponentParams(t[a],i,r))}))}canAssetBeInstanced(t){return e(this,void 0,void 0,(function*(){if(!this._canBeInstancedCache.has(t.assetId)){const e=yield this.createFromAsset(t);if(null==e)return!1;const i=[];e.traverse((e=>{!J(e)&&e.isMesh&&i.push(e)}));const r=1==i.length&&0==i[0].children.length,a=!0;this._canBeInstancedCache.set(t.assetId,r&&a)}return this._canBeInstancedCache.get(t.assetId)}))}preInit(){var e;null===(e=this.renderingView)||void 0===e||e.onLoop((()=>{var e;return null===(e=this.sky)||void 0===e?void 0:e.position.copy(this.renderingView.camera.position)}))}initWithInstancing(){return e(this,void 0,void 0,(function*(){this.preInit();const t=new L;for(const i of this.dataProvider.getObjects())yield De(i,((i,r,a)=>e(this,void 0,void 0,(function*(){var e,s;const o="asset_mesh"==i.type&&(yield this.canAssetBeInstanced(i))?i.assetId+JSON.stringify(null!==(e=i.materialAssignments)&&void 0!==e?e:[]):"other";"other"!==o&&r&&(null===(s=r.children)||void 0===s?void 0:s.length)>0&&r.children.splice(r.children.findIndex((e=>e.id===i.id)),1),"other"===o&&r||t.push(o,Object.assign(Object.assign({},i),{parentTransform:a}))}))));for(const[e,i]of t.entries())if("other"!==e&&i.length>0){const e=yield this.createFromAsset(i[0]);if(null==e)continue;const t=yield this.createInstancedMesh(i,e),r=new H;r.add(t),r.userData.src=i[0],e instanceof H&&(r.collisionShapes=e.collisionShapes),r.castShadow=!1,r.receiveShadow=!1,this.scene.add(r)}else yield Promise.all(i.map((e=>this.materialize(e))));yield this.initActorsPostInit()}))}createInstancedMesh(t,r){var a,o;return e(this,void 0,void 0,(function*(){const e=r.children.filter((e=>!J(e)))[0],n=yield this.assetsService.getAsset(t[0].assetId);yield this.applyMaterials(r,je(t[0].materialAssignments,n.materialAssignments)),e.updateMatrix();const l=e.geometry.clone().applyMatrix4(e.matrix),c=new i.InstancedMesh(l,e.material.clone(),t.length);c.material.side=i.FrontSide;for(let e=0;e<t.length;e++){const r=(new i.Matrix4).compose((new A).fromArray(t[e].position),(new v).setFromEuler((new s).fromArray(t[e].rotation)),(new A).fromArray(t[e].scale)),a=(new re).copy(t[e].parentTransform).multiply(r);c.setMatrixAt(e,a)}return c.castShadow=null===(a=n.castShadow)||void 0===a||a,c.receiveShadow=null===(o=n.receiveShadow)||void 0===o||o,c}))}remove(e){if(console.log("Remove scene object",e),"global_fog"==e.type)return void(this.scene.fog=this.originalFog);if("actor"==e.type){const t=this.materializedActors.get(e.id);null!=t&&(t.disposed.next(!0),t.onEndPlay(),this.removeVfxChildActors(t))}const t=this.sceneObjectMap.get(e.id);null==t||t.parent.remove(t),this.sceneObjectMap.delete(e.id),this.components.filter((t=>{var i;return(null===(i=t.object.userData.src)||void 0===i?void 0:i.id)===e.id})).forEach((e=>this.components.splice(this.components.indexOf(e,1)))),this.landscapeManagers.filter((t=>t.source.id===e.id)).forEach((e=>{e.clear(),e.stop(),this.landscapeManagers.splice(this.landscapeManagers.indexOf(e,1))})),this.removed$.next({object:t,source:e})}deleteSceneObject(e){const t=this.sceneObjectMap.get(e.id);if(this.scene.remove(t),"landscape"==e.type){const t=this.landscapeManagers.findIndex((t=>t.source.id===e.id));if(t>-1){const e=this.landscapeManagers.splice(t,1)[0];e.clear(),e.stop()}}}findByAssetId(e){return U(this.scene,(t=>{var i;return(null===(i=t.userData.src)||void 0===i?void 0:i.assetId)==e}),(e=>null!=e.userData.src))}applyMaterials(e,t){return null==t?Promise.resolve([]):Promise.all(t.filter((e=>"null"!==e.materialId)).map((t=>this.applyMaterial(e,t))))}applyMaterial(t,i){const r=[];return t.traverse((t=>e(this,void 0,void 0,(function*(){if(t instanceof d||t.isMesh)for(const e of fe(t.material))e.hasOwnProperty("color")&&r.push(t)})))),Promise.all(r.map((t=>e(this,void 0,void 0,(function*(){var e,r,a,s;if(t.material instanceof Array)for(let a=0;a<t.material.length;a++){const s=t.material[a];if(null==s.color)continue;const o="#"+s.color.getHexString(),n=s.name;if(o===i.color&&(s.name===i.name||null==i.name)||t.userData["originalColor_"+a]===i.color&&t.userData["originalMaterialName_"+a]===i.name){const s=yield this.assetsService.getAsset(i.materialId),l=t.material[a];s&&(t.material[a]=yield materialFromAsset(s,this.renderingView,this.assetsService,this.assetManagerService,this.shaders),t.userData["originalColor_"+a]=null!==(e=t.userData["originalColor_"+a])&&void 0!==e?e:o,t.userData["originalMaterialName_"+a]=null!==(r=t.userData["originalMaterialName_"+a])&&void 0!==r?r:n,this.inEditor&&this._originalMaterials.set(t.id+"#"+a,l))}}else{const e="#"+t.material.color.getHexString(),r=t.material.name;if(e===i.color&&(t.material.name===i.name||null==i.name)||t.userData.originalColor===i.color&&t.userData.originalName===i.name){const o=yield this.assetsService.getAsset(i.materialId),n=t.material;o&&(t.material=yield materialFromAsset(o,this.renderingView,this.assetsService,this.assetManagerService,this.shaders),t.userData.originalColor=null!==(a=t.userData.originalColor)&&void 0!==a?a:e,t.userData.originalMaterialName=null!==(s=t.userData.originalMaterialName)&&void 0!==s?s:r,this.inEditor&&this._originalMaterials.set(t.id,n))}}})))))}unapplyMaterials(t){t.traverse((t=>e(this,void 0,void 0,(function*(){var e,i;if(t instanceof d)if(t.material instanceof Array)for(let i=0;i<t.material.length;i++)t.material[i]=null!==(e=this._originalMaterials.get(t.id+"#"+i))&&void 0!==e?e:t.material[i];else t.material=null!==(i=this._originalMaterials.get(t.id))&&void 0!==i?i:t.material}))))}updateActors(t){this.actorTypes=t;const i=new Set(Object.values(_));U(this.scene,(e=>{var t,r;return(null===(t=e.userData.src)||void 0===t?void 0:t.id)&&"actor"===e.userData.src.type&&this.materializedActors.has(null===(r=e.userData.src)||void 0===r?void 0:r.id)&&!i.has(e.userData.src.actor.type)})).forEach((t=>e(this,void 0,void 0,(function*(){this.remove(t.userData.src),yield this.materializeAndInitActor(t.userData.src)}))))}updateShaders(e){this.shaders=e;for(const[e,t]of Ae.entries())t.userData.customShaderName&&Ae.delete(e);this.landscapeManagers.forEach((t=>t.updateShaders(e))),U(this.scene,(e=>!0)).forEach((e=>{e.traverse((e=>{var t,i;if(e instanceof d){if(null!=(null===(t=e.material.userData)||void 0===t?void 0:t.customShaderName)){const t=null===(i=function(e,t){if(t(e))return e;let i;return e.traverseAncestors((e=>{null==i&&t(e)&&(i=e)})),i}(e,(e=>{var t;return null!=(null===(t=e.userData.src)||void 0===t?void 0:t.id)})))||void 0===i?void 0:i.userData.src;null!=t&&this.update(t)}}}))}))}update(t){return e(this,void 0,void 0,(function*(){if("sky"===t.type&&null!=this.sky&&null!=this.sky.parent)return void this.updateSky(t);const e=this.sceneObjectMap.get(t.id);if(e){const r=this.findParent(t);if(null!=r&&r.uuid!=e.uuid?r.attach(e):console.error("Parent is wrong"),"prefab"!==t.type){this.unapplyMaterials(e);this.inEditor&&t.hidden&&!1?e.traverse((e=>{e instanceof d&&(e.material.wireframe=!0)})):e.traverse((e=>{e instanceof d&&(e.material.wireframe=!1)}))}if("asset_mesh"===t.type){const i=yield this.assetsService.getAsset(t.assetId);je(t.materialAssignments,i.materialAssignments).forEach((t=>this.applyMaterial(e,t)))}else"shape_mesh"===t.type&&this.applyMaterials(e,t.materialAssignments);let s=!1;if(e.traverseAncestors((e=>{"_hology_transform_group"===e.name&&(s=!0)})),s||(e.position.fromArray(t.position),e.scale.fromArray(t.scale),e.rotation.fromArray(t.rotation)),this.applyVertexMaterials(t,e),"light"==t.type)if("point"==t.light.type){const i=e;i.color=new a(t.light.point.color),i.intensity=t.light.point.intensity,i.decay=t.light.point.decay,i.castShadow=t.light.point.castShadow,i.distance=Math.max(t.light.point.distance,0)}else"directional"===t.light.type?this.applyDirectionalLight(t.light.directional):"ambient"===t.light.type&&this.applyDirectionalAmbientLight(e,t.light.ambient);else if("landscape"===t.shape)this.applyHeightMaps(e,t.landscape.heightMaps),this.inEditor&&this.landscapeManagers.filter((e=>e.source.id===t.id)).forEach((e=>e.queueRefreshScatter(this.renderingView.camera.position,!0,(e=>!0))));else if("global_fog"===t.type){const e=(this.scene.fog instanceof n?"density":"linear")!==t.fog.type;this.scene.fog=Ie(t.fog),e&&(i=this.scene).traverse((e=>{if(e instanceof d){const t=e.material;t instanceof j&&(i.fog instanceof o?(t.uniforms.fogFar.value=i.fog.far,t.uniforms.fogNear.value=i.fog.near):i.fog instanceof n&&(t.uniforms.density={value:i.fog.density}),t.needsUpdate=!0,t.uniformsNeedUpdate=!0)}})),this.fixFogColor()}else if("actor"===t.type){if(this.materializedActors.has(t.id)){const e=this.editorActorParamSnapshot.get(t.id);null!=e&&e===JSON.stringify(t.actor)||(console.log("Rematerializing actor because parameters changed"),this.remove(t),yield this.materializeAndInitActor(t))}}else if("shape_mesh"===t.type){const i=yield this.createMeshByShape(t.shape,e.material,t.shapeParams);e instanceof G&&(e.geometry=i.geometry,e.collisionShape=i.collisionShape)}("asset_mesh"===t.type||"shape_mesh"===t.type&&"landscape"!==t.shape)&&we(e,t.castShadow,t.receiveShadow),t.name&&t.name.length>0&&(e.name=t.name),this.updated$.next({object:e,source:t})}else{const e=yield this.materializeAndInitActor(t);this.updated$.next({object:e,source:t})}var i}))}materializeAndInitActor(t,i=this.findParent(t)){return e(this,void 0,void 0,(function*(){const r=yield this.materialize(t,i);return De(t,(t=>e(this,void 0,void 0,(function*(){if("actor"===t.type){const e=this.materializedActors.get(t.id);null!=e?yield this.initActorsPostInit([e]):console.error(`Something went wrong when creating actor ${t.id}`)}})))),r}))}findParent(e){const t=this.dataProvider.getObjects().flatMap((t=>t.id===e.id?null:R(t,(t=>{var i;return null===(i=t.children)||void 0===i?void 0:i.some((t=>t.id===e.id))}),(()=>!0))))[0];return null==t?this.scene:null!=t?U(this.scene,(e=>{var i,r;return(null===(r=null===(i=e.userData)||void 0===i?void 0:i.src)||void 0===r?void 0:r.id)===t.id}),(e=>{var t;return null!=(null===(t=e.userData)||void 0===t?void 0:t.src)}))[0]:void 0}fixFogColor(){!0===this.renderingView.options.enableOutlines&&(this.scene.fog.color=new a(this.scene.fog.color).convertSRGBToLinear())}findMeshWithGeometry(e){let t;return e.traverse((e=>{e instanceof d&&e.geometry&&(t=e)})),t}applyVertexMaterials(e,t){if(null==e.vertexMaterials||0===e.vertexMaterials.length)return;const i=$(e.vertexMaterials,(e=>e.m));t.traverse((e=>{if(e instanceof d){const t=ee(e,!1);if(null!=t){for(let e=0;e<t.array.length;e++)t.setX(e,0);t.needsUpdate=!0}}}));const r=new Set;for(const[e,a]of i.entries()){const i=null!=e?t.getObjectByName(e):this.findMeshWithGeometry(t);let s=!1;if(null==i)return void console.warn(`Failed to apply vertex materials on mesh with name "${e}"`);const o=ee(i,!0);for(let e=0;e<o.array.length;e++)o.setX(e,0);for(const e of a)o.setX(e.i,e.w[0]),o.setY(e.i,e.w[1]),o.setZ(e.i,e.w[2]),s=!0;s&&r.add(e)}this.inEditor&&this.landscapeManagers.filter((t=>t.source.id===e.id)).forEach((e=>e.queueRefreshScatter(this.renderingView.camera.position,!0,(e=>r.has(e.name)))))}materialize(t,i,a=!1){var s,o,n,c;return e(this,void 0,void 0,(function*(){let e;switch(t.type){case"asset_mesh":e=yield this.createFromAsset(t);break;case"shape_mesh":e=yield this.createFromShape(t);break;case"light":e=yield this.createLight(t);break;case"particles":e=yield this.createParticleSystem(t),t.collisionDetection=!1;break;case"global_fog":this.scene.fog=Ie(t.fog),this.fixFogColor(),e=new l;break;case"sky":this.sky=he(),this.updateSky(t),e=this.sky;break;case"actor":e=yield this.createFromActor(t);break;case"group":e=new l;break;case"prefab":e=yield this.createFromPrefabAsset(t);break;case"vfx":e=yield this.createFromVfx(t);break;default:if(this.inEditor)throw new Error("unknown type "+t.type);console.warn(`Failed to materialize object. Unknown type '${t.type}'. This might be because the hology/core library is not compatible with the editor version.`)}if(null!=e){if(t.name&&t.name.length>0&&(e.name=t.name),e.position.fromArray(t.position),e.scale.fromArray(t.scale),e.rotation.fromArray(t.rotation),a||(e.userData.src=t),!this.inEditor){const i=null!==(s=t.components)&&void 0!==s?s:[],r=null!=t.assetId&&null!==(n=null===(o=yield this.assetsService.getAsset(t.assetId))||void 0===o?void 0:o.components)&&void 0!==n?n:[];i.push(...r),i.length>0?e.userData.componentRefs=yield Promise.all(i.map(((i,r)=>this.createComponent(e,t,i,r)))):"asset_mesh"==t.type&&function(e){e.traverse((e=>{e.matrixAutoUpdate=!1,e.matrixWorldNeedsUpdate=!1}));const t=e.updateMatrixWorld;e.updateMatrixWorld=function(){t.apply(e),e.updateMatrixWorld=function(){}}}(e)}if(this.inEditor){let t=null;e instanceof G&&(t=function(e){if(e instanceof W)return new d(new r(...e.offset.toArray()),Pe);return null}(e.collisionShape)),null!=t&&(t.layers.disable(0),t.layers.enable(18),t.scale.multiplyScalar(1.1),e.add(t))}return this.objectMap.set(e.uuid,t),this.sceneObjectMap.set(t.id,e),null==i?this.scene.add(e):null==i||i.add(e),null!=t.children&&(yield Promise.all(null===(c=t.children)||void 0===c?void 0:c.map((t=>this.materialize(t,e,a))))),e}}))}updateSky(t){var r;return e(this,void 0,void 0,(function*(){if(null==(null===(r=null==t?void 0:t.sky)||void 0===r?void 0:r.materialId))return void(this.sky.material=ue);const e=yield this.assetsService.getAsset(t.sky.materialId),a=yield materialFromAsset(e,this.renderingView,this.assetsService,this.assetManagerService,this.shaders,!1);a.side=i.BackSide,null!=this.sky?this.sky.material=a:console.warn("No sky has been created")}))}createComponent(t,i,r,a){return e(this,void 0,void 0,(function*(){const e=new ge[r.path+"/"+r.className],s=i.id+a;e.id=s,e.object=t;for(const t of r.params)null!=t.value&&(e[t.name]=t.value);return this.components.push(e),s}))}createFromActor(t){var i,r,a;return e(this,void 0,void 0,(function*(){const e=null!==(r=null===(i=this.actorTypes.find((e=>{var i;return e.name===(null===(i=t.actor)||void 0===i?void 0:i.type)})))||void 0===i?void 0:i.type)&&void 0!==r?r:_[null===(a=t.actor)||void 0===a?void 0:a.type];if(null==e)return null;this.inEditor&&this.editorActorParamSnapshot.set(t.id,JSON.stringify(t.actor));const o=yield this.actorProvider.create(e,(new A).fromArray(t.position),(new s).fromArray(t.rotation),!0);return this.materializedActors.set(t.id,o),null==o?void 0:o.object}))}createFromVfx(t){return e(this,void 0,void 0,(function*(){const e=yield this.assetsService.getAsset(t.assetId);null==e&&console.error("Could not find asset",t);const i=ve,r=yield this.actorProvider.create(i,(new A).fromArray(t.position),(new s).fromArray(t.rotation),!1);return yield r.fromAsset(e),r.play(),this.materializedActors.set(t.id,r),null==r?void 0:r.object}))}cleanup(){this.materializedActors.clear()}createFromShape(t){var i,r,s;return e(this,void 0,void 0,(function*(){const e=this.inEditor&&t.hidden;let o;if("landscape"==t.shape)o=this.createLandscape(t);else{let s=new m({name:"Default",color:new a("#aaaaaa"),visible:this.inEditor||!t.hidden,wireframe:!!e});const n=yield this.createMeshByShape(t.shape,s,t.shapeParams);n.castShadow=null===(i=t.castShadow)||void 0===i||i,n.receiveShadow=null!==(r=t.castShadow)&&void 0!==r&&r,t.collisionDetection||(n.collisionShape=null),o=n,this._originalMaterials.set(o.id,n.material),o.traverse((e=>{}))}return e||((null!==(s=t.materialAssignments)&&void 0!==s?s:[]).filter((e=>null!=e.materialId)).forEach((e=>this.applyMaterial(o,e))),this.applyVertexMaterials(t,o)),o}))}createLandscape(e){var t;if(null==(null===(t=e.landscape)||void 0===t?void 0:t.options))return console.error(`No landscape options exist on scene object ${e.id} ${e.name}`),new l;const i=X(e.landscape.options);this.applyHeightMaps(i,e.landscape.heightMaps,!0);const r=new Y(e,this.renderingView,i,this.assetManagerService,this.assetsService,this.shaders,(t=>{var i;(null!==(i=e.materialAssignments)&&void 0!==i?i:[]).filter((e=>null!=e.materialId)).forEach((e=>this.applyMaterial(t,e)))}));return this.landscapeManagers.push(r),r.refreshGeometry(),i}applyHeightMaps(e,t,i=!1){const r=new q(e.sections);for(const e of null!=t?t:[]){const t=r.find(e.x,e.y);if(!t)return;const i=t.geometry.getAttribute("position");for(const t of e.points)i.setY(t.i,t.y);i.needsUpdate=!0}const a=e.sections;a.forEach((e=>{e.geometry.computeBoundsTree(),e.geometry.computeVertexNormals()})),this.inEditor&&!i||setTimeout((()=>Z(a)),50)}createMeshByShape(t,i,r={}){return e(this,void 0,void 0,(function*(){if("landscape"!==t&&ce.includes(t)){const e=yield prepareShapeParameters(null!=r?r:{});return"cylinder"==t&&e.openEnded,new G(le[t].geometry(e),i,le[t].collision(e))}if(this.inEditor)throw new Error(`Unsupported shape '${t}'`);console.warn(`Failed to create shape. Unsupported shape '${t}'. This might be because the hology/core library is not compatible with the editor version.`)}))}createFromAsset(t){var i,r,a,s;return e(this,void 0,void 0,(function*(){const e=yield this.assetsService.getAsset(t.assetId);if(null==e)return void console.warn(`Can not find asset with id ${t.assetId} and name ${t.name}`);let{scene:o}=yield this.assetManagerService.getMesh(e);je(t.materialAssignments,e.materialAssignments).forEach((e=>this.applyMaterial(o,e)));const n=null===(r=null!==(i=t.receiveShadow)&&void 0!==i?i:!!e.receiveShadow)||void 0===r||r,l=null!==(s=null!==(a=t.castShadow)&&void 0!==a?a:!!e.castShadow)&&void 0!==s&&s;return o.receiveShadow=n,we(o,l,n),t.collisionDetection||(o.collisionShapes=[]),this.applyVertexMaterials(t,o),o.traverse((e=>{e instanceof d&&"computeBoundsTree"in e.geometry&&e.geometry.computeBoundsTree()})),o}))}createFromPrefabAsset(t){return e(this,void 0,void 0,(function*(){const e=yield this.assetsService.getAsset(t.assetId);if(null==e)return void console.warn(`Can not find asset with id ${t.assetId} and name ${t.name}`);const i=new l;return e.prefab.objects.filter((e=>"global_fog"!==e.type)).forEach((e=>this.materialize(e,i,!0))),i}))}createParticleSystem(t){return e(this,void 0,void 0,(function*(){const e=yield this.assetsService.getAsset(t.assetId),r=new p;return yield b.fromJSONAsync(e.particleSystem,i).then((e=>{const t=new M(r,i);e.addRenderer(t),this.renderingView.onLoop((t=>e.update()))})),r}))}createLight(t){var i;return e(this,void 0,void 0,(function*(){if("point"===t.light.type){const e=new f(t.light.point.color,t.light.point.intensity,t.light.point.distance,t.light.point.decay);if(e.castShadow=null===(i=t.light.point.castShadow)||void 0===i||i,this.inEditor){const t=new y(.3,10,10),i=new m({color:new a(16771709)}),r=new d(t,i);e.add(r)}return e}return"directional"===t.light.type?(this.applyDirectionalLight(t.light.directional),new l):"ambient"===t.light.type?(this.applyDirectionalAmbientLight(null,t.light.ambient),new l):void 0}))}applyDirectionalAmbientLight(e,t){const i=this.scene.children.find((e=>e.name===de));null!=i?(i.intensity=t.intensity,i.color.set(t.color),i.groundColor.set(t.color)):console.warn("Couldn't find ambient light")}applyDirectionalLight(e){for(const t of this.renderingView.csm.lights)t.intensity=e.intensity,t.color.set(e.color),t.castShadow=e.castShadow;this.renderingView.csm.lightDirection.fromArray(e.direction).normalize()}dispose(){this.updateSubscription.unsubscribe()}}function we(e,t,i){e.castShadow=t,e.receiveShadow=i,e.traverse((e=>{e.castShadow=t,e.receiveShadow=i}))}const Ae=new Map,Se=new h({color:16711935}),be=new Map;export function materialFromAsset(t,r,s,o,n,l=!0){var c,d,h,m,p,f,v,y,g,w,A;return e(this,void 0,void 0,(function*(){const e=JSON.stringify(t.material);if(l&&Ae.has(e))return Ae.get(e);const S={opacity:t.material.params.opacity,map:null,emissive:null!==(c=t.material.params.emissive)&&void 0!==c?c:null,metalness:null!==(d=t.material.params.metalness)&&void 0!==d?d:0,flatShading:null!==(h=t.material.params.flatShading)&&void 0!==h&&h,color:new a(t.material.params.color).convertSRGBToLinear(),transparent:null!=t.material.params.opacity&&t.material.params.opacity<1},b={};if(null!=t.material.params.map){const e=t.material.params.map,i=yield s.getAsset(e);null!=i&&(S.map=yield o.getTexture(i))}let M;switch(t.material.type){case"phong":M=new u(Object.assign(Object.assign({},S),b));break;case"water":M=te(S,r);break;case"grassFoliage":M=Q({color:S.color,map:S.map},r);break;case"grass":M=K(Object.assign(Object.assign({},S),{colorTwo:new a(t.material.params.colorTwo),colorThree:new a(t.material.params.colorThree)}),r);break;case"standard":case"lambert":case"shader":const e=null!==(m={standard:oe,lambert:ne}[t.material.type])&&void 0!==m?m:null===(p=n.find((e=>e.name==t.material.shader)))||void 0===p?void 0:p.type;if(e){const i=new e,a=yield Me(null!==(v=null===(f=t.material)||void 0===f?void 0:f.shaderParams)&&void 0!==v?v:{},e,s,o,null,r,n);Object.assign(i,a);try{M=i.build()}catch(e){console.log("Shader runtime error: "+e),be.has(t.material.shader)||be.set(t.material.shader,Se.clone()),M=be.get(t.material.shader)}M.userData.customShaderName=t.material.shader}else console.warn("Missing shader implementation with name "+t.material.shader),M=Se;break;default:throw new Error("Unsupported material type"+t.material.type)}return null==r||r.csm.setupMaterial(M),l&&Ae.set(e,M),M.side=null!==(g=null!==(y=t.material.side)&&void 0!==y?y:M.side)&&void 0!==g?g:i.FrontSide,M.transparent=null!==(A=null!==(w=t.material.transparent)&&void 0!==w?w:S.transparent)&&void 0!==A&&A||M.transparent,M}))}function Me(t,i,r,a,s,o,n,l){return e(this,void 0,void 0,(function*(){const e={};for(const[i,c]of Object.entries(t)){const t=yield xe(c,r,a,s,o,n,l);null!=t&&(e[i]=t)}return e}))}export function prepareShapeParameters(t){return e(this,void 0,void 0,(function*(){const e={};for(const[i,r]of Object.entries(t)){const t=yield xe(r,null,null,null);null!=t&&(e[i]=t)}return e}))}function xe(t,i,r,o,n,l,c){return e(this,void 0,void 0,(function*(){if(null==t||null==t.value||""==t.value)return null;const e=t.value;switch(t.type){case ie.Number:case ie.FloatNode:let d="string"==typeof e?parseFloat(e):e;return t.type===ie.FloatNode?P(d):d;case ie.Texture:return yield r.getTexture(yield i.getAsset(e));case ie.Sampler2DNode:return C(yield r.getTexture(yield i.getAsset(e)));case ie.Boolean:return e;case ie.BooleanNode:return x(e);case ie.Vector2:case ie.Vec2Node:if("object"==typeof e){const i=e instanceof Array?(new w).fromArray(e):new w(e.x,e.y);return t.type===ie.Vec2Node?O(i):i}return null;case ie.Vector3:case ie.Vec3Node:if("object"==typeof e){const i=e instanceof Array?(new A).fromArray(e):new A(e.x,e.y,e.z);return t.type===ie.Vec3Node?k(i):i}return null;case ie.Color:case ie.RgbNode:const h=new a(e).convertSRGBToLinear();return t.type===ie.RgbNode?V(h):h;case ie.String:return e;case ie.BaseActor:const u=e;return null==o&&console.warn("Class parameters can not be prepared as actors are not passed in"),null==o?void 0:o.get(u);case ie.Euler:const m=e;return(new s).fromArray(m);case ie.Object3D:return(yield r.getMesh(yield i.getAsset(e))).scene;case ie.Material:return yield materialFromAsset(yield i.getAsset(e),n,i,r,l);case ie.AudioBuffer:return yield r.getAudio(yield i.getAsset(e));case ie.VisualEffect:const p=yield i.getAsset(e);if(null==c){console.error("Can not create instance of visual effect because missing actor provider");break}if("vfx"in p){const e=yield c.create(ve);return yield e.fromAsset(p),new ye(e)}console.error("Using a non-vfx asset for visual effect parameter")}return null}))}function Ie(e){var t,i;return"linear"===e.type?new o(new a(e.color),null!==(t=e.near)&&void 0!==t?t:100,null!==(i=e.far)&&void 0!==i?i:1e3):"density"===e.type?new n(e.color,e.density):void console.warn("Invalid fog type",e)}const Pe=new m({color:4229780});function De(t,r,a,o){var n;return e(this,void 0,void 0,(function*(){null==o&&(o=(new re).identity()),yield r(t,a,o);const e=o.clone().multiply(function(e,t){return t.compose((new A).fromArray(e.position),(new v).setFromEuler((new s).fromArray(e.rotation)),(new A).fromArray(e.scale))}(t,new i.Matrix4));return Promise.all((null!==(n=t.children)&&void 0!==n?n:[]).map((i=>De(i,r,t,e))))}))}export function toSerializedParamType(e){const t=e.constructor.prototype;return t instanceof Number||e===Number?ie.Number:t instanceof D||"function"==typeof e.prototype.isFloat?ie.FloatNode:t instanceof g||e===g||e.isTexture?ie.Texture:t instanceof se||e===N?ie.Sampler2DNode:t instanceof Boolean||e===Boolean?ie.Boolean:t instanceof I?ie.BooleanNode:t instanceof a||e==a?ie.Color:t instanceof E||"function"==typeof e.prototype.isRgb?ie.RgbNode:t instanceof w||e==w?ie.Vector2:t instanceof F||"function"==typeof e.prototype.isVec2?ie.Vec2Node:t instanceof A||e==A?ie.Vector3:t instanceof z||"function"==typeof e.prototype.isVec3?ie.Vec3Node:t instanceof String||e===String?ie.String:t instanceof ae||e==ae||e.prototype instanceof ae||e.prototype==ae?ie.BaseActor:t instanceof s||e==s?ie.Euler:t instanceof p||e==p?ie.Object3D:t instanceof c||e==c?ie.Material:t instanceof AudioBuffer||e==AudioBuffer?ie.AudioBuffer:t instanceof ye||e==ye?ie.VisualEffect:void console.warn("Failed to map parameter type to serialized version",{type:e})}export function prepareCustomParams(e,t,i={}){return Object.fromEntries(e.map((e=>{var r,a,s;return[e.name,{type:toSerializedParamType(e.type),value:null!==(s=null!==(a=null===(r=t[e.name])||void 0===r?void 0:r.value)&&void 0!==a?a:i[e.name])&&void 0!==s?s:customParameterDefaultValueByType.get(toSerializedParamType(e.type))}]})))}export function prepareCustomParamsFromType(e,t,i=null){const r=T(e);if(0===r.length)return{};let a;null!=i?pe(i,(()=>{a=i.get(e)})):a=new e;const s={};for(const e of r){const t=a[e.name];if(null!=t){const i=serializeCustomParameter(e.type,t);null!=i&&(s[e.name]=i)}}return prepareCustomParams(r,t,s)}export function serializeCustomParameter(e,t){function i(){console.error("Failed to serialize value",{type:e,value:t})}switch(e){case Number:case Boolean:return t;case w:return t instanceof w?t.toArray():void i();case A:return t instanceof A?t.toArray():void i();case S:return t instanceof S?t.toArray():void i();case a:return t instanceof a?"#"+t.getHexString():"string"==typeof t?t:"number"==typeof t?"#"+new a(t).getHexString():void i();case String:return t;case s:return t instanceof s?t.toArray():void i()}}function je(e,t){return function(e,t,i){const r=[],a=new Set;for(const s of[...null!=e?e:[],...null!=t?t:[]]){const e=i(s);a.has(e)||(a.add(e),r.push(s))}return r}((null!=e?e:[]).filter((e=>Ve(e.materialId))),(null!=t?t:[]).filter((e=>Ve(e.materialId))),(e=>e.color+e.name))}function Ve(e){return"null"!=e&&null!=e}export const customParameterDefaultValueByType=new Map([[ie.RgbNode,"#000000"],[ie.Color,"#000000"],[ie.Vector4,[0,0,0,0]],[ie.Vec4Node,[0,0,0,0]],[ie.Vector3,[0,0,0]],[ie.Vec3Node,[0,0,0]],[ie.Vector2,[0,0]],[ie.Vec2Node,[0,0]],[ie.Euler,[0,0,0,"XYZ"]]]);
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -27,7 +27,8 @@ export declare enum SerializedParamType {
27
27
  Material = 16,
28
28
  AudioBuffer = 17,
29
29
  Vector4 = 18,
30
- Vec4Node = 19
30
+ Vec4Node = 19,
31
+ VisualEffect = 20
31
32
  }
32
33
  export type CustomParamValue = {
33
34
  type: SerializedParamType;
@@ -1,4 +1,4 @@
1
- export var SerializedParamType;!function(e){e[e.FloatNode=0]="FloatNode",e[e.Number=1]="Number",e[e.Texture=2]="Texture",e[e.Sampler2DNode=3]="Sampler2DNode",e[e.Boolean=4]="Boolean",e[e.BooleanNode=5]="BooleanNode",e[e.Vector2=6]="Vector2",e[e.Vec2Node=7]="Vec2Node",e[e.Vector3=8]="Vector3",e[e.Vec3Node=9]="Vec3Node",e[e.Color=10]="Color",e[e.RgbNode=11]="RgbNode",e[e.String=12]="String",e[e.BaseActor=13]="BaseActor",e[e.Euler=14]="Euler",e[e.Object3D=15]="Object3D",e[e.Material=16]="Material",e[e.AudioBuffer=17]="AudioBuffer",e[e.Vector4=18]="Vector4",e[e.Vec4Node=19]="Vec4Node"}(SerializedParamType||(SerializedParamType={}));
1
+ export var SerializedParamType;!function(e){e[e.FloatNode=0]="FloatNode",e[e.Number=1]="Number",e[e.Texture=2]="Texture",e[e.Sampler2DNode=3]="Sampler2DNode",e[e.Boolean=4]="Boolean",e[e.BooleanNode=5]="BooleanNode",e[e.Vector2=6]="Vector2",e[e.Vec2Node=7]="Vec2Node",e[e.Vector3=8]="Vector3",e[e.Vec3Node=9]="Vec3Node",e[e.Color=10]="Color",e[e.RgbNode=11]="RgbNode",e[e.String=12]="String",e[e.BaseActor=13]="BaseActor",e[e.Euler=14]="Euler",e[e.Object3D=15]="Object3D",e[e.Material=16]="Material",e[e.AudioBuffer=17]="AudioBuffer",e[e.Vector4=18]="Vector4",e[e.Vec4Node=19]="Vec4Node",e[e.VisualEffect=20]="VisualEffect"}(SerializedParamType||(SerializedParamType={}));
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -3,7 +3,8 @@ import { Type } from '../utils/type';
3
3
  import { BaseActor } from '../gameplay/actors/actor';
4
4
  import { Color, Euler, Material, Object3D, Texture, Vector2, Vector3, Vector4 } from 'three';
5
5
  import { BooleanNode, FloatNode, RgbNode, Sampler2DNode, Vec2Node, Vec3Node, Vec4Node } from '../shader-nodes';
6
- export type ParameterType = Type<FloatNode | Number | Texture | Sampler2DNode | Boolean | BooleanNode | Vector2 | Vec2Node | Vector3 | Vec3Node | Vector4 | Vec4Node | Color | RgbNode | String | BaseActor | Euler | Object3D | Material>;
6
+ import { VisualEffect } from '../effects/vfx/vfx-param';
7
+ export type ParameterType = Type<FloatNode | Number | Texture | Sampler2DNode | Boolean | BooleanNode | Vector2 | Vec2Node | Vector3 | Vec3Node | Vector4 | Vec4Node | Color | RgbNode | String | BaseActor | Euler | Object3D | Material | VisualEffect>;
7
8
  export type ParameterOption<T> = {
8
9
  name: string;
9
10
  value: T;
@@ -1,8 +1,10 @@
1
1
  export * from 'three-shader-graph';
2
2
  export { linearEyeDepth, fragmentLinearEyeDepth, depthSampler } from './depth';
3
3
  export { timeUniforms } from './time';
4
+ export { particleUniforms } from './particle';
4
5
  export * from './layers';
5
6
  export * from './landscape';
6
7
  export * from './shapes';
7
8
  export * from './voronoi';
8
9
  export * from './effects';
10
+ export * from './math';
@@ -1,4 +1,4 @@
1
- export*from"three-shader-graph";export{linearEyeDepth,fragmentLinearEyeDepth,depthSampler}from"./depth";export{timeUniforms}from"./time";export*from"./layers";export*from"./landscape";export*from"./shapes";export*from"./voronoi";export*from"./effects";
1
+ export*from"three-shader-graph";export{linearEyeDepth,fragmentLinearEyeDepth,depthSampler}from"./depth";export{timeUniforms}from"./time";export{particleUniforms}from"./particle";export*from"./layers";export*from"./landscape";export*from"./shapes";export*from"./voronoi";export*from"./effects";export*from"./math";
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -0,0 +1,2 @@
1
+ import { FloatNode, IntNode, Vec2Node, Vec3Node, Vec4Node } from "three-shader-graph";
2
+ export declare function oneMinus<T extends FloatNode | Vec2Node | Vec3Node | Vec4Node | IntNode>(value: T): T;
@@ -0,0 +1,5 @@
1
+ import{FloatNode as t,IntNode as r,Vec2Node as e,Vec3Node as n,Vec4Node as s,float as a,int as c,vec2 as u,vec3 as o,vec4 as i}from"three-shader-graph";export function oneMinus(f){switch(!0){case f instanceof t:return a(1).subtract(f);case f instanceof r:return c(1).subtract(f);case f instanceof e:return u(1,1).subtract(f);case f instanceof n:return o(1,1,1).subtract(f);case f instanceof s:return i(1,1,1,1).subtract(f)}throw"Unsupported type "+f}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,6 @@
1
+ export declare const particleEnergyUniformName = "hology_particle_energy";
2
+ export declare const particleVelcoityUniformName = "hology_particle_velocity";
3
+ export declare const particleUniforms: {
4
+ energy: import("three-shader-graph").UniformFloatNode;
5
+ velocity: import("three-shader-graph").UniformVec3Node;
6
+ };
@@ -0,0 +1,5 @@
1
+ import{uniformFloat as e,uniformVec3 as o}from"three-shader-graph";export const particleEnergyUniformName="hology_particle_energy";export const particleVelcoityUniformName="hology_particle_velocity";export const particleUniforms={energy:e("hology_particle_energy"),velocity:o("hology_particle_velocity")};
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */