@hology/core 0.0.96 → 0.0.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/effects/vfx/vfx-actor.d.ts +1 -0
- package/dist/effects/vfx/vfx-actor.d.ts.map +1 -1
- package/dist/effects/vfx/vfx-actor.js +1 -1
- package/dist/effects/vfx/vfx-asset.d.ts +8 -3
- package/dist/effects/vfx/vfx-asset.d.ts.map +1 -1
- package/dist/effects/vfx/vfx-materializer.d.ts +2 -8
- package/dist/effects/vfx/vfx-materializer.d.ts.map +1 -1
- package/dist/effects/vfx/vfx-materializer.js +1 -1
- package/dist/effects/vfx/vfx-renderers.d.ts.map +1 -1
- package/dist/effects/vfx/vfx-renderers.js +1 -1
- package/dist/gameplay/actors/builtin/components/mesh-component.d.ts +1 -0
- package/dist/gameplay/actors/builtin/components/mesh-component.d.ts.map +1 -1
- package/dist/gameplay/actors/builtin/components/mesh-component.js +1 -1
- package/dist/gameplay/index.d.ts +1 -0
- package/dist/gameplay/index.d.ts.map +1 -1
- package/dist/gameplay/index.js +1 -1
- package/dist/gameplay/initiate.d.ts.map +1 -1
- package/dist/gameplay/initiate.js +1 -1
- package/dist/gameplay/input/input-service.d.ts +8 -0
- package/dist/gameplay/input/input-service.d.ts.map +1 -1
- package/dist/gameplay/input/input-service.js +1 -1
- package/dist/gameplay/services/physics/physics-system.d.ts +2 -1
- package/dist/gameplay/services/physics/physics-system.d.ts.map +1 -1
- package/dist/gameplay/services/physics/physics-system.js +1 -1
- package/dist/gameplay/services/shader-provider.d.ts +7 -0
- package/dist/gameplay/services/shader-provider.d.ts.map +1 -0
- package/dist/gameplay/services/shader-provider.js +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/scene/asset-resource-loader.d.ts.map +1 -1
- package/dist/scene/asset-resource-loader.js +1 -1
- package/dist/scene/collision/collision-shape.d.ts +8 -0
- package/dist/scene/collision/collision-shape.d.ts.map +1 -1
- package/dist/scene/collision/collision-shape.js +1 -1
- package/dist/scene/materializer.d.ts +6 -1
- package/dist/scene/materializer.d.ts.map +1 -1
- package/dist/scene/materializer.js +1 -1
- package/dist/shader/index.d.ts +2 -0
- package/dist/shader/index.d.ts.map +1 -1
- package/dist/shader/index.js +1 -1
- package/dist/shader/sprite-shader.d.ts +17 -0
- package/dist/shader/sprite-shader.d.ts.map +1 -0
- package/dist/shader/sprite-shader.js +4 -0
- package/package.json +2 -2
- package/tsconfig.tsbuildinfo +1 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"vfx-actor.d.ts","sourceRoot":"","sources":["../../../src/effects/vfx/vfx-actor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,SAAS,EAAE,MAAM,gCAAgC,CAAA;AAKjE,OAAO,EAAE,KAAK,EAAqB,MAAM,sBAAsB,CAAA;
|
1
|
+
{"version":3,"file":"vfx-actor.d.ts","sourceRoot":"","sources":["../../../src/effects/vfx/vfx-actor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,SAAS,EAAE,MAAM,gCAAgC,CAAA;AAKjE,OAAO,EAAE,KAAK,EAAqB,MAAM,sBAAsB,CAAA;AAM/D,qBACa,QAAS,SAAQ,SAAS;IAErC;;OAEG;IACI,SAAS,SAAI;IACb,MAAM,UAAQ;IAErB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,WAAW,CAAU;IAE7B,OAAO,CAAC,WAAW,CAAsB;IACzC,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,IAAI,CAAyB;IAErC,OAAO,CAAC,uBAAuB,CAAgB;IAC/C,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,cAAc,CAAyB;IAE/C;;OAEG;IACU,SAAS,CAAC,KAAK,EAAE,KAAK;IAyDnC,IAAI;IASJ,KAAK;IAIL,IAAI;IAiBJ,OAAO;IAYP,OAAO,CAAC,SAAS,CAAsB;IAEvC,OAAO,CAAC,GAAG,CAAK;IAEhB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAuBjC;;;;;;;;;;OAUG;IAEH,gBAAgB;IAIhB,SAAS,IAAI,IAAI;CAelB"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{__decorate as s}from"tslib";import*as t from"three";import{Rate as e}from"@hology/nebula";import{Actor as i,BaseActor as r}from"../../gameplay/actors/actor.js";import{inject as o}from"../../gameplay/inject.js";import{AssetLoader as a}from"../../gameplay/services/asset-loader.js";import{ViewController as m}from"../../gameplay/services/render.js";import{World as h}from"../../gameplay/services/world.js";import{DelayRate as
|
1
|
+
import{__decorate as s}from"tslib";import*as t from"three";import{Rate as e}from"@hology/nebula";import{Actor as i,BaseActor as r}from"../../gameplay/actors/actor.js";import{inject as o}from"../../gameplay/inject.js";import{AssetLoader as a}from"../../gameplay/services/asset-loader.js";import{ViewController as m}from"../../gameplay/services/render.js";import{World as h}from"../../gameplay/services/world.js";import{DelayRate as d}from"./rates.js";import{materializeVfx as p}from"./vfx-materializer.js";import{PhysicsSystem as l}from"../../gameplay/index.js";import{ShaderProvider as c}from"../../gameplay/services/shader-provider.js";let y=class extends r{constructor(){super(...arguments),this.timescale=1,this.paused=!1,this.assetLoader=o(a),this.world=o(h),this.view=o(m),this.physics=o(l),this.shaderProvider=o(c),this._worldPos=new t.Vector3,this.max=0}async fromAsset(s){if("vfx"!==s.type)throw"Asset must be a VFX asset but is "+s.type;null!=this.system&&(this.system.destroy(),this.system.emitters.forEach((s=>s.reset()))),this.sourceAsset=s,this.disposeSystem&&this.disposeSystem(),this.world.scene.add(this.object);const{system:t,dispose:e,container:i}=await p(this.sourceAsset,this.object,{getAsset:s=>this.assetLoader.getAsset(s),getMaterial:s=>this.assetLoader.getMaterialByAssetId(s),getTexture:s=>this.assetLoader.getTextureByAssetId(s),getMesh:s=>this.assetLoader.getModelByAssetId(s).then((s=>s.scene))},this.view,this.physics,this.shaderProvider);this.system=t,this.disposeSystem=e,this.particleSystemContainer=i}play(){this.paused=!1;this.system.emitters.every((s=>s.dead))&&this.restart()}pause(){this.paused=!0}stop(){this.system.emitters.forEach((s=>{const t=s.rate;t instanceof e&&(t.nextTime=1/0)}))}restart(){for(const s of this.system.emitters){const t=s.rate;t instanceof d?t.restart():t.nextTime=0,s.removeAllParticles()}}onUpdate(s){this.paused||(this.object.getWorldPosition(this._worldPos),this.system?.emitters.forEach((s=>{"world"===s._space&&s.setPosition(this._worldPos)})),this.system?.update(s*this.timescale))}getParticleCount(){return this.system?.getCount()??0}onEndPlay(){this.stop(),null!=this.disposeSystem&&this.disposeSystem()}};y=s([i()],y);export{y as VfxActor};/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
@@ -41,6 +41,10 @@ export type FlipbookSettings = {
|
|
41
41
|
fps: number;
|
42
42
|
mode: FlipbookMode;
|
43
43
|
};
|
44
|
+
export type OutputCustomShader = {
|
45
|
+
shader: string;
|
46
|
+
shaderParams: Record<string, CustomParamValue>;
|
47
|
+
};
|
44
48
|
export type CommonOutput = {
|
45
49
|
space: 'world' | 'local';
|
46
50
|
};
|
@@ -51,7 +55,7 @@ export type SpriteOutput = {
|
|
51
55
|
blendingMode: BlendingMode;
|
52
56
|
softness: number;
|
53
57
|
flipbook?: FlipbookSettings;
|
54
|
-
} & CommonOutput
|
58
|
+
} & CommonOutput & Partial<OutputCustomShader>;
|
55
59
|
export type StretchedSpriteOutput = {
|
56
60
|
type: 'stretchedSprite';
|
57
61
|
texture: string;
|
@@ -59,7 +63,7 @@ export type StretchedSpriteOutput = {
|
|
59
63
|
blendingMode: BlendingMode;
|
60
64
|
scale: number;
|
61
65
|
softness: number;
|
62
|
-
} & CommonOutput
|
66
|
+
} & CommonOutput & Partial<OutputCustomShader>;
|
63
67
|
export type MeshOutput = {
|
64
68
|
type: 'mesh';
|
65
69
|
assetId: AssetId;
|
@@ -80,7 +84,8 @@ export type ShapeOutput = {
|
|
80
84
|
shape: LibraryShapeType;
|
81
85
|
params: Record<string, CustomParamValue>;
|
82
86
|
material: AssetId;
|
83
|
-
|
87
|
+
bloom?: boolean;
|
88
|
+
} & CommonOutput & OutputCustomShader;
|
84
89
|
export type EmitterOutput = SpriteOutput | MeshOutput | ShapeOutput | StretchedSpriteOutput | TrailOutput;
|
85
90
|
export type EmitterData = {
|
86
91
|
id: string;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"vfx-asset.d.ts","sourceRoot":"","sources":["../../../src/effects/vfx/vfx-asset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAA0B,MAAM,eAAe,CAAC;AAM1G,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAA;IAEZ,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AACD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,YAAY,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AACD,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAC,kBAAkB,CAAA;AAEtD,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,wBAAwB,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;CACzC,CAAA;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,uBAAuB,CAAA;IAE7B,MAAM,EAAE,MAAM,CAAC,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AA;IACb,KAAK,EAAE,gBAAgB,CAAC;IAExB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;IAOxC,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,GAAG,YAAY,GAAG,kBAAkB,CAAA;AACrC,MAAM,MAAM,aAAa,GAAG,YAAY,GAAG,UAAU,GAAG,WAAW,GAAG,qBAAqB,GAAG,WAAW,CAAA;AAEzG,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAA;IAIZ,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,EAAE,WAAW,CAAC;IACtB,QAAQ,EAAE,WAAW,CAAC;IACtB,YAAY,EAAE,eAAe,EAAE,CAAC;IAChC,UAAU,EAAE,aAAa,EAAE,CAAC;IAC5B,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAA;IAGxB,MAAM,EAAE,aAAa,CAAA;IAErB,UAAU,CAAC,EAAE,uBAAuB,CAAA;CACrC,CAAA;AAED,eAAO,MAAM,wBAAwB,iCAAkC,CAAA;AACvE,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE/E,MAAM,MAAM,YAAY,GAAG;IACzB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,WAAW,EAAE,CAAA;CAExB,CAAA;AAGD,wBAAgB,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsCrC"}
|
@@ -1,26 +1,20 @@
|
|
1
1
|
import System from "@hology/nebula";
|
2
2
|
import * as THREE from 'three';
|
3
3
|
import { Object3D } from "three";
|
4
|
-
import { NodeShaderMaterial } from "three-shader-graph";
|
5
4
|
import { PhysicsSystem, ViewController } from '../../gameplay/index.js';
|
6
5
|
import { Asset, VfxAsset } from '../../scene/model.js';
|
6
|
+
import { ShaderProvider } from "../../gameplay/services/shader-provider.js";
|
7
7
|
export type VfxAssetProvider = {
|
8
8
|
getAsset(assetId: string): Promise<Asset>;
|
9
9
|
getTexture(assetId: string): Promise<THREE.Texture>;
|
10
10
|
getMesh(assetId: string): Promise<THREE.Object3D>;
|
11
11
|
getMaterial(assetId: string): Promise<THREE.Material>;
|
12
12
|
};
|
13
|
-
export declare function materializeVfx(asset: VfxAsset, target: Object3D, assetProvider: VfxAssetProvider, view: ViewController, physics: PhysicsSystem): Promise<{
|
13
|
+
export declare function materializeVfx(asset: VfxAsset, target: Object3D, assetProvider: VfxAssetProvider, view: ViewController, physics: PhysicsSystem, shaderProvider: ShaderProvider): Promise<{
|
14
14
|
container: THREE.Object3D<THREE.Object3DEventMap>;
|
15
15
|
system: System;
|
16
16
|
dispose: () => void;
|
17
17
|
}>;
|
18
|
-
export declare class SpriteNodeShaderMaterial extends NodeShaderMaterial {
|
19
|
-
get color(): THREE.ColorRepresentation;
|
20
|
-
set color(value: THREE.ColorRepresentation);
|
21
|
-
get rotation(): number;
|
22
|
-
set rotation(value: number);
|
23
|
-
}
|
24
18
|
export declare class EmitterPool<T> {
|
25
19
|
private creator;
|
26
20
|
instances: T[];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"vfx-materializer.d.ts","sourceRoot":"","sources":["../../../src/effects/vfx/vfx-materializer.ts"],"names":[],"mappings":"AAAA,OAAO,MAAiE,MAAM,gBAAgB,CAAC;AAC/F,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
1
|
+
{"version":3,"file":"vfx-materializer.d.ts","sourceRoot":"","sources":["../../../src/effects/vfx/vfx-materializer.ts"],"names":[],"mappings":"AAAA,OAAO,MAAiE,MAAM,gBAAgB,CAAC;AAC/F,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGjC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAExE,OAAO,EAAE,KAAK,EAAuB,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAa5E,OAAO,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAK5E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAA;IACzC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACnD,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IACjD,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;CACtD,CAAA;AAGD,wBAAsB,cAAc,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,gBAAgB,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc;;;;GAyDpL;AAguBD,qBAAa,WAAW,CAAC,CAAC;IAIZ,OAAO,CAAC,OAAO;IAF3B,SAAS,EAAE,CAAC,EAAE,CAAK;gBAEC,OAAO,EAAE,MAAM,CAAC;IAEpC;;;OAGG;IACH,GAAG,IAAI,CAAC;IAQR;;;OAGG;IACH,OAAO,CAAC,QAAQ,EAAE,CAAC;IAMnB,OAAO;CAGR"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import e,{Behaviour as t,Body as i,Emitter as n,Rate as s}from"@hology/nebula";import*as o from"three";import{Object3D as r}from"three";import{AttributeVec3Node as a,AttributeVec4Node as l,NodeShaderMaterial as c,RgbNode as m,UniformFloatNode as p,UniformVec3Node as u,Vec3ExpressionNode as h,Vec4Node as d,attributeFloat as f,attributeVec3 as y,attributeVec4 as g,attributes as w,float as v,glslFunction as A,lambertMaterial as x,log as E,pow as b,rgb as M,rgba as P,saturate as I,standardMaterial as S,textureSampler2d as T,transformed as R,uniformFloat as C,uniforms as B,varying as j,varyingAttributes as k,varyingVec3 as z,varyingVec4 as V}from"three-shader-graph";import{prepareShapeParameters as D}from"../../scene/materializer.js";import{SerializedParamType as F}from"../../scene/model.js";import{ShapeLibrary as Q}from"../../scene/objects/shapes.js";import{fragmentLinearEyeDepth as U,linearEyeDepth as W}from"../../shader-nodes/depth.js";import{particleEnergyUniformName as L,particleTimeUniformName as q,particleUniforms as H,particleVelcoityUniformName as G}from"../../shader-nodes/particle.js";import{sampleFlipbook as J}from"../../shader-nodes/texture-sequence.js";import{DefaultInitializer as N}from"./initializsers.js";import{DelayRate as O,OnceRate as K}from"./rates.js";import{StretchedSprite as X}from"./stretched-sprite.js";import{ThreeBlendingMode as Y}from"./vfx-asset.js";import{VfxBehaviourLibrary as Z,VfxInitializserLibrary as _}from"./vfx-defs.js";import{MultiRenderer as $}from"./vfx-renderers.js";import{WorldCollisionBehaviour as ee}from"./vfx-collision-behaviour.js";export async function materializeVfx(t,i,n,s,a){let l=i;for(;null!=l.parent;)l=l.parent;const c=new r;c.name="particle system local",i.add(c);const m=new r;m.name="particle system world",l.add(m);const p=new $(m,c,o,s),u=new e;return(await Promise.all(t.vfx.emitters.map((async e=>{const t=await te(e,n,u,a);return t.setParentRecursive(u),t.emit()})))).forEach((e=>u.addEmitter(e))),u.addRenderer(p).emit({onEnd:()=>{}}),{container:m,system:u,dispose:()=>{m.removeFromParent(),c.removeFromParent(),p.dispose()}}}async function te(e,t,n,m){const z=function(e){let t;switch(e.rate.type){case"continuous":t=new O(e.rate.delay??0,e.rate.count,e.rate.time);break;case"once":t=new K(e.rate.delay??0,e.rate.count);break;default:console.warn(`Failed to configure rate for emitter: ${JSON.stringify(e)}`),t=new s(0,1/0)}return t}(e);let L;switch(e.output.type){case"sprite":L=new i(await async function(e,t){const i=null!=e.texture?await t.getTexture(e.texture):ie,n=T(i);let s=n.sample(k.uv);e.flipbook?.enabled&&(s=J(n,w.uv,e.flipbook.columns,e.flipbook.rows,H.time,e.flipbook.fps,e.flipbook.mode));const r=new p("rotation",0),a=new u("color").rgb,l=C("opacity",1),c=W.subtract(U).divide(W);let m=s.x.multiply(l);if("number"==typeof e.softness&&e.softness>0){const t=b(c,v(e.softness));m=m.multiply(t)}const h=A(d,{position:R.position,modelViewMatrix:B.modelViewMatrix,rotation:r},"\n vec2 center = vec2(0.5, 0.5);\n vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n // Using scale form instance matrix instead of modelMatrix\n vec2 scale;\n scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\n // This times 2 on scale seem to make it appear like when using regular sprites. \n // Not sure if this is correct though.\n vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * (scale);\n\n vec2 rotatedPosition;\n rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\n mvPosition.xy += rotatedPosition;\n return projectionMatrix * mvPosition;\n ");var f=new SpriteNodeShaderMaterial({color:P(a,m).multiply(s),transparent:!0,position:h,uniforms:{color:{value:new o.Color(e.color)}}});f.blending=Y[e.blendingMode]??o.NormalBlending;const y=new o.Mesh(new o.PlaneGeometry(1,1),f);return y.name="sprite",y}(e.output,t));break;case"stretchedSprite":L=new i(await async function(e,t){const i=null!=e.texture?await t.getTexture(e.texture):ie,n=T(i).sample(k.uv),s=V(new l("color")),r=s.rgb;let a=s.w;if("number"==typeof e.softness&&e.softness>0){const t=W.subtract(U).divide(E(W)),i=b(t,v(e.softness));a=I(a.multiply(i))}const c=A(d,{position:w.position,offset:y("offset"),modelViewMatrix:B.modelViewMatrix,velocity:g("velocity"),size:y("size"),rotation:f("rotation")},"\n float lengthFactor = velocity.w;\n float avgSize = (size.x + size.y) * 0.5;\n\n vec4 mvPosition = modelViewMatrix * vec4( offset , 1.0 );\n vec3 viewVelocity = normalMatrix * velocity.xyz;\n float vlength = length(viewVelocity); \n mvPosition.xyz += position.y * normalize(cross(mvPosition.xyz, viewVelocity)) * avgSize; \n mvPosition.xyz -= (position.x + 0.5) * viewVelocity * (1.0 + lengthFactor / vlength) * avgSize;\n return projectionMatrix * mvPosition;\n ");var m=new SpriteNodeShaderMaterial({color:P(r,a).multiply(n),transparent:!0,position:c,uniforms:{color:{value:new o.Color(e.color)}}});m.blending=Y[e.blendingMode]??o.NormalBlending;const p=new X(new o.PlaneGeometry(1,1),m);return p.scaleFactor=e.scale,p}(e.output,t));break;case"shape":L=new i(await async function(e,t){if(null==e.shape)return console.log("Shape is null"),new r;const i=Q[e.shape];if(null==i)return console.error(`No shape with type ${e.shape}`),new r;const n=D(e.params??{}),s=i.geometry(n),l=null!=e.material?function(e){const t=j(new h("instanceColor")).rgb;let i,n=j(new a("particleData")).x;if(e instanceof o.MeshStandardMaterial||e instanceof o.MeshLambertMaterial||e instanceof o.MeshBasicMaterial){let s=t.multiply(M(e.color));null!=e.map&&(s=s.multiply(T(e.map).sample(k.uv).rgb)),null!=e.alphaMap&&(n=n.multiply(T(e.alphaMap).sample(k.uv).r)),e instanceof o.MeshStandardMaterial?i=new c({color:S({color:s,emissive:M(e.emissive),emissiveIntensity:v(e.emissiveIntensity),roughness:e.roughness,metalness:e.metalness}).rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}):e instanceof o.MeshLambertMaterial?i=new c({color:x({color:s}).rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}):e instanceof o.MeshBasicMaterial&&(i=new c({color:s.rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}))}null!=i&&(!0===e.userData?.hasBloom&&null!=i&&(i.userData.hasBloom=!0),i.side=e.side,i.transparent=e.transparent);return i??e}(await t.getMaterial(e.material)):function(){const e=j(new h("instanceColor")).rgb,t=j(new a("particleData")).x;return new c({color:x({color:e}).rgb.rgba(t),transparent:!0})}();return new o.Mesh(s,l)}(e.output,t));break;case"mesh":L=new i(await async function(e,t){if(null==e.assetId)return console.warn("Can't use mesh as particle without asset id"),new r;const i=await t.getMesh(e.assetId),n=await t.getAsset(e.assetId),s=[];if(null!=n.materialAssignments)for(const e of n.materialAssignments)i.traverse((i=>{i instanceof o.Mesh&&i.material instanceof o.Material&&i.material.color instanceof o.Color&&(i.material.name!=e.name&&null!=e.name||"#"+i.material.color.getHexString()!==e.color||s.push(t.getMaterial(e.materialId).then((e=>i.material=e))))}));await Promise.all(s);const a=[];if(i.traverse((e=>{e instanceof o.Mesh&&a.push(e)})),1===a.length){const e=a[0];return e.updateWorldMatrix(!0,!0),e.updateMatrixWorld(),e.matrix.copy(e.matrixWorld),e.matrixWorld.decompose(e.position,e.quaternion,e.scale),e.removeFromParent(),e}return i}(e.output,t));break;case"trail":L=new i({type:"trail",taper:e.output.taper,headGeometry:null,dragTexture:!1,color:e.output.color,colorEnd:e.output.colorEnd,length:e.output.length,opacityStart:e.output.opacityStart,opacityEnd:e.output.opacityEnd,bloom:e.output.bloom});break;default:console.error("Failed to create particly system body: "+JSON.stringify(e))}const q=new se;q.parent=n,q.setRate(z),q._space=e.output.space;const G=await Promise.all(e.initializers.filter((e=>null!=_[e.type])).map((async e=>{const t=_[e.type],i=await D(e.params??{});return t.build(i)})));G.push(L,new N),q.addInitializers(G);const $=await Promise.all(e.behaviours.filter((e=>null!=Z[e.type])).map((async e=>{const t=Z[e.type];for(const[i,n]of Object.entries(e.params))t.parameters&&null!=t.parameters[i]&&"curve"===t.parameters[i].type&&n.type!==F.Curve&&(n.type=F.Curve);const i=await D(e.params??{});return t.build(i)})).sort(((e,t)=>e instanceof ee?1:0)));$.push(new ne);for(const e of $)e instanceof ee&&(e.physics=m);q.addBehaviours($);for(const i of e.children){const e=await te(i,t,n,m),s=new EmitterPool((()=>{const t=e.clone();return t.onExpired=()=>{const e=q.childEmitters.findIndex((e=>e.id===t.id));-1!=e&&q.childEmitters.splice(e,1),s.release(t)},t})),o=q.eventDispatcher,r=new Map;q.bindEmitterEvent=!0,o.addEventListener("PARTICLE_DEAD",(e=>{const t=r.get(e.id);if(null!=t){const e=q.childEmitters.findIndex((e=>e.id===t.id));null!=e&&t.stopEmit()}}));let a="PARTICLE_CREATED";if("spawnEvent"in i)switch(i.spawnEvent){case"collision":a="PARTICLE_COLLISION";break;case"start":a="PARTICLE_CREATED"}o.addEventListener(a,(e=>{const t=s.get();t.age=0,t.totalEmitTimes=-1,t.particles.length=0,t.currentEmitTime=0,t.cID=0,t.eventDispatcher.removeAllEventListeners(),q.childEmitters.push(t),r.set(e.id,t),t.parentParticle=e,t.system=q.system,t.emit()}))}return q}const ie=(new o.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 class SpriteNodeShaderMaterial extends c{get color(){return this.uniforms.color.value}set color(e){this.uniforms.color.value=new o.Color(e)}get rotation(){return this.uniforms.rotation.value}set rotation(e){this.uniforms.rotation.value=e}}(new o.SpriteMaterial).rotation;class ne extends t{initialize(e){e.body instanceof o.Object3D&&e.body.traverse((e=>{if(e instanceof o.Mesh){const t=e.material;t instanceof c&&(null!=t.uniforms[L]||null!=t.uniforms[q]||t.uniforms[G])}}))}mutate(e,t,i){this.energize(e,t),e.target instanceof r&&e.target.traverse((t=>{if(t instanceof o.Mesh){const i=t.material;i instanceof c&&(null!=i.uniforms[L]&&(i.uniforms[L].value=this.energy),null!=i.uniforms[q]&&(i.uniforms[q].value=e.age),null!=i.uniforms[G]&&(i.uniforms[G].value=e.velocity))}}))}}class se extends n{constructor(){super(...arguments),this.childEmitters=[],this.bindEmitterEvent=!1,this.onExpired=()=>{}}update(e){if(!this.isEmitting&&0===this.particles.length)return;this.age+=e,(this.dead||this.age>=this.life)&&this.destroy(),this.generate(e),this.integrate(e);let t=this.particles.length;for(;t--;){const e=this.particles[t];e.dead&&(this.system&&this.system.dispatch("PARTICLE_DEAD",e),this.bindEmitterEvent&&this.dispatch("PARTICLE_DEAD",e),this.system.pool.expire(e.reset()),this.particles.splice(t,1))}this.updateEmitterBehaviours(e),this.updateChildren(e),this.isEmitting||0!==this.particles.length||this.onExpired()}updateChildren(e){for(const t of this.childEmitters)null!=t.parentParticle?t.position.copy(t.parentParticle.position):t.setPosition(this.position),t.update(e)}clone(){const e=new se;return e.setRate(this.rate.clone()),e.behaviours=this.behaviours,e.initializers=this.initializers,e._space=this._space,e.body=this.body,e.parent=this.parent,e.system=this.system,e}setParentRecursive(e){this.system=e,this.childEmitters.forEach((t=>t.setParentRecursive(e)))}}export class EmitterPool{constructor(e){this.creator=e,this.instances=[]}get(){0==this.instances.length&&this.instances.push(this.creator());return this.instances.pop()}release(e){this.instances.push(e)}dispose(){this.instances.length=0}}/*
|
1
|
+
import e,{Behaviour as t,Body as i,Emitter as n,Rate as s}from"@hology/nebula";import*as a from"three";import{Object3D as r}from"three";import{AttributeVec3Node as o,AttributeVec4Node as l,NodeShaderMaterial as c,RgbNode as m,UniformFloatNode as p,UniformVec3Node as u,Vec3ExpressionNode as h,Vec4Node as d,attributeFloat as f,attributeVec3 as g,attributeVec4 as y,attributes as w,float as v,glslFunction as x,lambertMaterial as A,log as b,pow as E,rgb as M,rgba as P,saturate as I,standardMaterial as T,textureSampler2d as R,transformed as j,uniformFloat as B,uniforms as C,varying as k,varyingAttributes as z,varyingVec3 as S,varyingVec4 as V}from"three-shader-graph";import{prepareClassParameters as D,prepareShapeParameters as F}from"../../scene/materializer.js";import{SerializedParamType as Q}from"../../scene/model.js";import{ShapeLibrary as U}from"../../scene/objects/shapes.js";import{fragmentLinearEyeDepth as W,linearEyeDepth as L}from"../../shader-nodes/depth.js";import{particleEnergyUniformName as q,particleTimeUniformName as H,particleUniforms as G,particleVelcoityUniformName as J}from"../../shader-nodes/particle.js";import{sampleFlipbook as O}from"../../shader-nodes/texture-sequence.js";import{DefaultInitializer as N}from"./initializsers.js";import{DelayRate as K,OnceRate as X}from"./rates.js";import{StretchedSprite as Y}from"./stretched-sprite.js";import{ThreeBlendingMode as Z}from"./vfx-asset.js";import{VfxBehaviourLibrary as _,VfxInitializserLibrary as $}from"./vfx-defs.js";import{MultiRenderer as ee}from"./vfx-renderers.js";import{WorldCollisionBehaviour as te}from"./vfx-collision-behaviour.js";import{SpriteNodeShaderMaterial as ie}from"../../shader/sprite-shader.js";export async function materializeVfx(t,i,n,s,o,l){let c=i;for(;null!=c.parent;)c=c.parent;const m=new r;m.name="particle system local",i.add(m);const p=new r;p.name="particle system world",c.add(p);const u=new ee(p,m,a,s),h=new e;return(await Promise.all(t.vfx.emitters.map((async e=>{const t=await ne(e,n,h,o,l);return t.setParentRecursive(h),t.emit()})))).forEach((e=>h.addEmitter(e))),h.addRenderer(u).emit({onEnd:()=>{}}),{container:p,system:h,dispose:()=>{p.removeFromParent(),m.removeFromParent(),u.dispose()}}}async function ne(e,t,n,m,S){const D=function(e){let t;switch(e.rate.type){case"continuous":t=new K(e.rate.delay??0,e.rate.count,e.rate.time);break;case"once":t=new X(e.rate.delay??0,e.rate.count);break;default:console.warn(`Failed to configure rate for emitter: ${JSON.stringify(e)}`),t=new s(0,1/0)}return t}(e);let q;switch(e.output.type){case"sprite":q=new i(await async function(e,t,i){let n=null;n=null!=e.shader?await ae(e,t,i):await async function(e,t){const i=null!=e.texture?await t.getTexture(e.texture):se,n=R(i);let s=n.sample(z.uv);e.flipbook?.enabled&&(s=O(n,w.uv,e.flipbook.columns,e.flipbook.rows,G.time,e.flipbook.fps,e.flipbook.mode));const r=new p("rotation",0),o=new u("color").rgb,l=B("opacity",1),c=L.subtract(W).divide(L);let m=s.x.multiply(l);if("number"==typeof e.softness&&e.softness>0){const t=E(c,v(e.softness));m=m.multiply(t)}const h=x(d,{position:j.position,modelViewMatrix:C.modelViewMatrix,rotation:r},"\n vec2 center = vec2(0.5, 0.5);\n vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n // Using scale form instance matrix instead of modelMatrix\n vec2 scale;\n scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\n // This times 2 on scale seem to make it appear like when using regular sprites. \n // Not sure if this is correct though.\n vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * (scale);\n\n vec2 rotatedPosition;\n rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\n mvPosition.xy += rotatedPosition;\n return projectionMatrix * mvPosition;\n ");var f=new ie({color:P(o,m).multiply(s),transparent:!0,position:h,uniforms:{color:{value:new a.Color(e.color)}}});return f.blending=Z[e.blendingMode]??a.NormalBlending,f}(e,t);const s=new a.Mesh(new a.PlaneGeometry(1,1),n);return s.name="sprite",s}(e.output,t,S));break;case"stretchedSprite":q=new i(await async function(e,t){const i=null!=e.texture?await t.getTexture(e.texture):se,n=R(i).sample(z.uv),s=V(new l("color")),r=s.rgb;let o=s.w;if("number"==typeof e.softness&&e.softness>0){const t=L.subtract(W).divide(b(L)),i=E(t,v(e.softness));o=I(o.multiply(i))}const c=x(d,{position:w.position,offset:g("offset"),modelViewMatrix:C.modelViewMatrix,velocity:y("velocity"),size:g("size"),rotation:f("rotation")},"\n float lengthFactor = velocity.w;\n float avgSize = (size.x + size.y) * 0.5;\n\n vec4 mvPosition = modelViewMatrix * vec4( offset , 1.0 );\n vec3 viewVelocity = normalMatrix * velocity.xyz;\n float vlength = length(viewVelocity); \n mvPosition.xyz += position.y * normalize(cross(mvPosition.xyz, viewVelocity)) * avgSize; \n mvPosition.xyz -= (position.x + 0.5) * viewVelocity * (1.0 + lengthFactor / vlength) * avgSize;\n return projectionMatrix * mvPosition;\n ");var m=new ie({color:P(r,o).multiply(n),transparent:!0,position:c,uniforms:{color:{value:new a.Color(e.color)}}});m.blending=Z[e.blendingMode]??a.NormalBlending;const p=new Y(new a.PlaneGeometry(1,1),m);return p.scaleFactor=e.scale,p}(e.output,t));break;case"shape":q=new i(await async function(e,t,i){if(null==e.shape)return console.log("Shape is null"),new r;const n=U[e.shape];if(null==n)return console.error(`No shape with type ${e.shape}`),new r;const s=F(e.params??{}),l=n.geometry(s);let m=null;null!=e.shader?(m=await ae(e,t,i),null!=m&&!0===e.bloom&&(m.userData.hasBloom=!0)):m=null!=e.material?function(e){const t=k(new h("instanceColor")).rgb;let i,n=k(new o("particleData")).x;if(e instanceof a.MeshStandardMaterial||e instanceof a.MeshLambertMaterial||e instanceof a.MeshBasicMaterial){let s=t.multiply(M(e.color));null!=e.map&&(s=s.multiply(R(e.map).sample(z.uv).rgb)),null!=e.alphaMap&&(n=n.multiply(R(e.alphaMap).sample(z.uv).r)),e instanceof a.MeshStandardMaterial?i=new c({color:T({color:s,emissive:M(e.emissive),emissiveIntensity:v(e.emissiveIntensity),roughness:e.roughness,metalness:e.metalness}).rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}):e instanceof a.MeshLambertMaterial?i=new c({color:A({color:s}).rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}):e instanceof a.MeshBasicMaterial&&(i=new c({color:s.rgb.rgba(n),transparent:e.transparent,alphaTest:e.alphaTest}))}null!=i&&(!0===e.userData?.hasBloom&&null!=i&&(i.userData.hasBloom=!0),i.side=e.side,i.transparent=e.transparent);return i??e}(await t.getMaterial(e.material)):function(){const e=k(new h("instanceColor")).rgb,t=k(new o("particleData")).x;return new c({color:A({color:e}).rgb.rgba(t),transparent:!0})}();return new a.Mesh(l,m)}(e.output,t,S));break;case"mesh":q=new i(await async function(e,t){if(null==e.assetId)return console.warn("Can't use mesh as particle without asset id"),new r;const i=await t.getMesh(e.assetId),n=await t.getAsset(e.assetId),s=[];if(null!=n.materialAssignments)for(const e of n.materialAssignments)i.traverse((i=>{i instanceof a.Mesh&&i.material instanceof a.Material&&i.material.color instanceof a.Color&&(i.material.name!=e.name&&null!=e.name||"#"+i.material.color.getHexString()!==e.color||s.push(t.getMaterial(e.materialId).then((e=>i.material=e))))}));await Promise.all(s);const o=[];if(i.traverse((e=>{e instanceof a.Mesh&&o.push(e)})),1===o.length){const e=o[0];return e.updateWorldMatrix(!0,!0),e.updateMatrixWorld(),e.matrix.copy(e.matrixWorld),e.matrixWorld.decompose(e.position,e.quaternion,e.scale),e.removeFromParent(),e}return i}(e.output,t));break;case"trail":q=new i({type:"trail",taper:e.output.taper,headGeometry:null,dragTexture:!1,color:e.output.color,colorEnd:e.output.colorEnd,length:e.output.length,opacityStart:e.output.opacityStart,opacityEnd:e.output.opacityEnd,bloom:e.output.bloom});break;default:console.error("Failed to create particly system body: "+JSON.stringify(e))}const H=new oe;H.parent=n,H.setRate(D),H._space=e.output.space;const J=await Promise.all(e.initializers.filter((e=>null!=$[e.type])).map((async e=>{const t=$[e.type],i=await F(e.params??{});return t.build(i)})));J.push(q,new N),H.addInitializers(J);const ee=await Promise.all(e.behaviours.filter((e=>null!=_[e.type])).map((async e=>{const t=_[e.type];for(const[i,n]of Object.entries(e.params))t.parameters&&null!=t.parameters[i]&&"curve"===t.parameters[i].type&&n.type!==Q.Curve&&(n.type=Q.Curve);const i=await F(e.params??{});return t.build(i)})).sort(((e,t)=>e instanceof te?1:0)));ee.push(new re);for(const e of ee)e instanceof te&&(e.physics=m);H.addBehaviours(ee);for(const i of e.children){const e=await ne(i,t,n,m,S),s=new EmitterPool((()=>{const t=e.clone();return t.onExpired=()=>{const e=H.childEmitters.findIndex((e=>e.id===t.id));-1!=e&&H.childEmitters.splice(e,1),s.release(t)},t})),a=H.eventDispatcher,r=new Map;H.bindEmitterEvent=!0,a.addEventListener("PARTICLE_DEAD",(e=>{const t=r.get(e.id);if(null!=t){const e=H.childEmitters.findIndex((e=>e.id===t.id));null!=e&&t.stopEmit()}}));let o="PARTICLE_CREATED";if("spawnEvent"in i)switch(i.spawnEvent){case"collision":o="PARTICLE_COLLISION";break;case"start":o="PARTICLE_CREATED"}a.addEventListener(o,(e=>{const t=s.get();t.age=0,t.totalEmitTimes=-1,t.particles.length=0,t.currentEmitTime=0,t.cID=0,t.eventDispatcher.removeAllEventListeners(),H.childEmitters.push(t),r.set(e.id,t),t.parentParticle=e,t.system=H.system,t.emit()}))}return H}const se=(new a.TextureLoader).load("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJkSURBVHjaxJeJbusgEEW94S1L//83X18M2MSuLd2pbqc4wZGqRLrKBsyZhQHny7Jk73xVL8xpVhWrcmiB5lX+6GJ5YgQ2owbAm8oIwH1VgKZUmGcRqKGGPgtEQQAzGR8hQ59fAmhJHSAagigJ4E7GPWRXOYC6owAd1JM6wDQPADyMWUqZRMqmAojHp1Vn6EQQEgUNMJLnUjMyJsM49wygBkAPw9dVFwXRkncCIIW3GRgoTQUZn6HxCMAFEFd8TwEQ78X4rHbILoAUmeT+RFG4UhQ6MiIAE4W/UsYFjuVjAIa2nIY4q1R0GFtQWG3E84lqw2GO2QOoCKBVu0BAPgDSU0eUDjjQenNkV/AW/pWChhpMTelo1a64AOKM30vk18GzTHXCNtI/Knz3DFBgsUqBGIjTInXRY1yA9xkVoqW5tVq3pDR9A0hfF5BSARmVnh7RMDCaIdcNgbPBkgzn1Bu+SfIEFSpSBmkxyrMicb0fAEuCZrWnN89veA/4XcakrPcjBWzkTuLjlbfTQPOlBhz+HwkqqPXmPQDdrQItxE1moGof1S74j/8txk8EHhTQrAE8qlwfqS5yukm1x/rAJ9Jiaa6nyATqD78aUVBhFo8b1V4DdTXdCW+IxA1zB4JhiOhZMEWO1HqnvdoHZ4FAMIhV9REF8FiUm0jsYPEJx/Fm/N8OhH90HI9YRHesWbXXZwAShU8qThe7H8YAuJmw5yOd989uRINKRTJAhoF8jbqrHKfeCYdIISZfSq26bk/K+yO3YvfKrVgiwQBHnwt8ynPB25+M8hceTt/ybPhnryJ78+tLgAEAuCFyiQgQB30AAAAASUVORK5CYII=");async function ae(e,t,i){const n=i.get(e.shader);if(null==n)return console.error("No shader exists with name "+e.shader),new a.Material;const s=new n.type,r=await D(e.shaderParams,n.type,t,{getTexture:e=>t.getTexture(e.id),getMaterial:e=>t.getMaterial(e.id),getMesh:e=>t.getMesh(e.id)},void 0,void 0,void 0,void 0);return Object.assign(s,r),s.build()}class re extends t{initialize(e){e.body instanceof a.Object3D&&e.body.traverse((e=>{if(e instanceof a.Mesh){const t=e.material;t instanceof c&&(null!=t.uniforms[q]||null!=t.uniforms[H]||t.uniforms[J])}}))}mutate(e,t,i){this.energize(e,t),e.target instanceof r&&e.target.traverse((t=>{if(t instanceof a.Mesh){const i=t.material;i instanceof c&&(null!=i.uniforms[q]&&(i.uniforms[q].value=this.energy),null!=i.uniforms[H]&&(i.uniforms[H].value=e.age),null!=i.uniforms[J]&&(i.uniforms[J].value=e.velocity))}}))}}class oe extends n{constructor(){super(...arguments),this.childEmitters=[],this.bindEmitterEvent=!1,this.onExpired=()=>{}}update(e){if(!this.isEmitting&&0===this.particles.length)return;this.age+=e,(this.dead||this.age>=this.life)&&this.destroy(),this.generate(e),this.integrate(e);let t=this.particles.length;for(;t--;){const e=this.particles[t];e.dead&&(this.system&&this.system.dispatch("PARTICLE_DEAD",e),this.bindEmitterEvent&&this.dispatch("PARTICLE_DEAD",e),this.system.pool.expire(e.reset()),this.particles.splice(t,1))}this.updateEmitterBehaviours(e),this.updateChildren(e),this.isEmitting||0!==this.particles.length||this.onExpired()}updateChildren(e){for(const t of this.childEmitters)null!=t.parentParticle?t.position.copy(t.parentParticle.position):t.setPosition(this.position),t.update(e)}clone(){const e=new oe;return e.setRate(this.rate.clone()),e.behaviours=this.behaviours,e.initializers=this.initializers,e._space=this._space,e.body=this.body,e.parent=this.parent,e.system=this.system,e}setParentRecursive(e){this.system=e,this.childEmitters.forEach((t=>t.setParentRecursive(e)))}}export class EmitterPool{constructor(e){this.creator=e,this.instances=[]}get(){0==this.instances.length&&this.instances.push(this.creator());return this.instances.pop()}release(e){this.instances.push(e)}dispose(){this.instances.length=0}}/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"vfx-renderers.d.ts","sourceRoot":"","sources":["../../../src/effects/vfx/vfx-renderers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAQ,QAAQ,EAA4B,MAAM,gBAAgB,CAAA;AACvG,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAA4B,QAAQ,EAAE,MAAM,OAAO,CAAA;
|
1
|
+
{"version":3,"file":"vfx-renderers.d.ts","sourceRoot":"","sources":["../../../src/effects/vfx/vfx-renderers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAQ,QAAQ,EAA4B,MAAM,gBAAgB,CAAA;AACvG,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAA4B,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAU/C,qBAAa,aAAc,SAAQ,cAAc;IAInC,OAAO,CAAC,cAAc;IAAY,OAAO,CAAC,cAAc;IAAY,OAAO,CAAC,KAAK;IAAgB,OAAO,CAAC,IAAI;IAHzH,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,cAAc,CAAK;gBAEP,cAAc,EAAE,QAAQ,EAAU,cAAc,EAAE,QAAQ,EAAU,KAAK,EAAE,OAAO,KAAK,EAAU,IAAI,EAAE,cAAc;IAMzI,cAAc;IASd,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAI3C,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAI1C,cAAc,CAAC,QAAQ,EAAE,Q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{InstancedBufferAttribute as s,Object3D as i}from"three";import{NodeShaderMaterial as n}from"three-shader-graph";import{SpriteNodeShaderMaterial as o}from"../../effects/vfx/vfx-materializer";import{StretchedSprite as l}from"./stretched-sprite.js";import{Trail as c}from"./trail-renderer.js";var d;!function(e){e[e.mesh=0]="mesh",e[e.instanced=1]="instanced",e[e.sprite=2]="sprite",e[e.stretchedBillboard=3]="stretchedBillboard",e[e.trail=4]="trail"}(d||(d={}));export class MultiRenderer extends e{constructor(e,t,r,a){super(),this.worldContainer=e,this.localContainer=t,this.three=r,this.view=a,this.localRenderers=[],this.worldRenderers=[]}onSystemUpdate(){for(const e of this.worldRenderers)e?.onSystemUpdate();for(const e of this.localRenderers)e?.onSystemUpdate()}onParticleCreated(e){this.getRenderer(e)?.onParticleCreated(e)}onParticleUpdate(e){this.getRenderer(e)?.onParticleUpdate(e)}onParticleDead(e){this.getRenderer(e)?.onParticleDead(e),e._renderer=null}getRenderer(e){if(e._renderer)return e._renderer;const t=(null!=e?.parent?e?.parent._space:null)??"world",r="world"===t?this.worldContainer:this.localContainer,s="world"===t?this.worldRenderers:this.localRenderers;return"trail"===e.body.type?(null==s[d.trail]&&(s[d.trail]=new TrailRenderer(r,this.three)),e._renderer=s[d.trail]):e.body instanceof l?(null==s[d.stretchedBillboard]&&(s[d.stretchedBillboard]=new StretchedSpriteInstancedRenderer(r,this.three,this.view)),e._renderer=s[d.stretchedBillboard]):e.body instanceof a.Sprite||e.body instanceof a.Mesh&&"sprite"===e.body.name?(null==s[d.sprite]&&(s[d.sprite]=new CombinedRenderer(r,this.three)),e._renderer=s[d.sprite]):e.body instanceof a.Mesh&&0==e.body.children.length&&e.body.material instanceof n?(null==s[d.instanced]&&(s[d.instanced]=new InstancedRenderer(r,this.three,this.view)),e._renderer=s[d.instanced]):e.body instanceof a.Object3D?(null==s[d.mesh]&&(s[d.mesh]=new CombinedRenderer(r,this.three)),e._renderer=s[d.mesh]):void 0}dispose(){this.localRenderers.forEach((e=>{e instanceof InstancedRenderer&&e.dispose()})),this.worldRenderers.forEach((e=>{e instanceof InstancedRenderer&&e.dispose()}))}}export class TrailRenderer extends t{constructor(){super(...arguments),this.trails=[]}dispose(){}onSystemUpdate(){for(const e of this.trails)e.update()}onParticleCreated(e){const t=e.body,r=new c(this.container,!0),s=new i,n=c.createBaseMaterial();n.uniforms.taper.value=t.taper??!1;const o=new a.Color(t.color??0),l=new a.Color(t.colorEnd??0);n.uniforms.headColor.value.set(o.r,o.g,o.b,t.opacityStart??1),n.uniforms.tailColor.value.set(l.r,l.g,l.b,t.opacityEnd??1),t.bloom&&(n.userData.hasBloom=!0),r.initialize(n,Math.round(t.length??10),!1,0,null,s);const d=e.rotation;s.rotation.set(d.x,d.y,d.z);e.scale;r.activate(),this.trails.push(r),e.target=s}onParticleUpdate(e){const t=e.target;t.position.copy(e.position);e.velocity.clone().normalize();const r=this.trails.findIndex((e=>e.targetObject.id===t.id));if(-1!=r){const t=this.trails[r];if(e.useAlpha){t.material.uniforms.headColor.value.setW(e.alpha);t.material.uniforms.tailColor.value.setW(e.alpha)}}}onParticleDead(e){const t=e.target,r=this.trails.findIndex((e=>e.targetObject.id===t.id));if(-1!=r){const e=this.trails[r];e.removeFromParent(),e.mesh.removeFromParent(),t.removeFromParent(),this.trails.splice(r,1)}}}export class CombinedRenderer extends t{dispose(){}scale(e){const t=e.transform.initialScale;e.target instanceof a.Sprite?null!=t?e.target.scale.set(t.x*e.scale*e.radius,t.y*e.scale*e.radius,1):e.target.scale.set(e.scale*e.radius,e.scale*e.radius,1):null!=t?e.target.scale.set(t.x*e.scale,t.y*e.scale,t.z*e.scale):super.scale(e)}rotate(e){e.target.material.rotation=e.rotation.z}onParticleCreated(e){e.target||(e.target=this._targetPool.get(e.body),(e.useAlpha||e.useColor)&&(e.target instanceof a.Mesh||e.target instanceof a.Sprite&&e.target.material instanceof a.Material)&&(e.target.material.__puid=r.id(e.body.material),e.target.material=this._materialPool.get(e.target.material))),e.target&&e.target instanceof i&&(e.target.position.set(e.position.x,e.position.y,e.position.z),this.container.add(e.target))}onParticleUpdate(e){const{target:t,useAlpha:r,useColor:s,rotation:n}=e;if(t){if(t.position.copy(e.position),this.isThreeSprite(e)||(t instanceof a.Mesh&&t.material instanceof o?e.target.material.rotation=e.rotation.z:t.rotation.set(n.x,n.y,n.z)),this.scale(e),e.transform&&e.transform.orientAlongVelocity&&t instanceof i){const r=m.set(e.velocity.x,e.velocity.y,e.velocity.z).normalize(),a=t.getWorldDirection(h);a.applyAxisAngle(p,Math.PI/-2),u.setFromUnitVectors(a,r),t.quaternion.copy(u)}t.material instanceof a.Material&&(r&&(t.material instanceof o&&null!=t.material.uniforms.opacity&&(t.material.uniforms.opacity.value=e.alpha,t.material.uniformsNeedUpdate=!0),t.material.opacity=e.alpha,t.material.transparent=!0),s&&(null!=t.material.color?t.material.color.copy(e.color):t.material instanceof a.ShaderMaterial&&null!=t.material.uniforms.color&&(t.material.uniforms.color.value=e.color,t.material.uniformsNeedUpdate=!0)))}}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 class StretchedSpriteInstancedRenderer extends t{constructor(e,t,r){super(e,t),this.view=r,this.meshes=[]}dispose(){this.meshes.forEach((e=>e.mesh.geometry.dispose()))}onSystemUpdate(){for(const e of this.meshes){const t=e.mesh.geometry.getAttribute("offset"),r=e.mesh.geometry.getAttribute("size"),s=e.mesh.geometry.getAttribute("velocity"),i=e.mesh.geometry.getAttribute("rotation"),n=e.mesh.geometry.getAttribute("color");let o=0;for(const l of e.particles){if(null==l||l.dead)continue;if(l.useColor||l.color instanceof a.Color){const e=U.copy(l.color).getRGB(C);n.setXYZW(o,e.r,e.g,e.b,1),n.needsUpdate=!0}l.useAlpha&&(n.setW(o,l.alpha),n.needsUpdate=!0),"number"==typeof l.rotation?i.setX(o,l.rotation):i.setX(o,l.rotation.x);const e=l.position;if(t.setXYZ(o,e.x,e.y,e.z),"number"!=typeof l.scale)throw new Error("Particle scale is not a number");r.setXYZ(o,l.scale,l.scale,l.scale);let c=l.body.scaleFactor;0===c&&(c=.001);const d=1,m=l.velocity;s.setXYZW(o,m.x*c,m.y*c,m.z*c,d),o++}o>0&&(t.clearUpdateRanges(),t.addUpdateRange(0,3*o),t.needsUpdate=!0,r.clearUpdateRanges(),r.addUpdateRange(0,3*o),r.needsUpdate=!0,n.clearUpdateRanges(),n.addUpdateRange(0,4*o),n.needsUpdate=!0,s.clearUpdateRanges(),s.addUpdateRange(0,4*o),s.needsUpdate=!0,i.clearUpdateRanges(),i.addUpdateRange(0,o),i.needsUpdate=!0)}}calcMaxCount(e){if(null==e)return 1;const t=e.parent.rate;return Math.min(t.numPan.b*Math.ceil(e.life/Math.min(Math.max(t.timePan.a,.01),1)),1e5)*this.calcMaxCount(e.parent.parentParticle)}onParticleCreated(e){if(e.body instanceof l&&null==e.target){const t=e.body;let r=this.meshes.find((e=>e.mesh.material.uuid===t.material.uuid));if(null==r){const i=this.calcMaxCount(e),n=new a.InstancedBufferGeometry;n.setIndex(t.geometry.getIndex()),n.setAttribute("position",t.geometry.getAttribute("position")),t.geometry.hasAttribute("normal")&&n.setAttribute("normal",t.geometry.getAttribute("normal")),n.setAttribute("uv",t.geometry.getAttribute("uv"));const l=new s(new Float32Array(3*i),3);l.setUsage(a.DynamicDrawUsage),n.setAttribute("offset",l);const c=new s(new Float32Array(4*i),4);if(c.setUsage(a.DynamicDrawUsage),n.setAttribute("color",c),t.material instanceof o){const e=new a.Color(t.material.color);for(let t=0;t<c.count;t++)c.setXYZW(t,e.r,e.g,e.b,1)}const d=new s(new Float32Array(3*i),3);d.setUsage(a.DynamicDrawUsage),n.setAttribute("size",d);const m=new s(new Float32Array(4*i),4);m.setUsage(a.DynamicDrawUsage),n.setAttribute("velocity",m);const h=new s(new Float32Array(4*i),1);h.setUsage(a.DynamicDrawUsage),n.setAttribute("rotation",h),r={mesh:new a.Mesh(n,t.material),indices:new Float32Array(i),particles:[]},this.meshes.push(r),this.container.add(r.mesh)}let i=r.indices.findIndex((e=>0===e));i<0&&(i=function(e){let t=e[0],r=0;for(let a=1;a<e.length;a++)e[a]<t&&(t=e[a],r=a);return r}(r.indices)),r.indices[i]=performance.now(),e.target=i,r.particles[i]=e}}onParticleUpdate(e){}onParticleDead(e){const t=e.body;let r=this.meshes.find((e=>e.mesh.material.uuid===t.material.uuid));if(r){const t=r.mesh.geometry.getAttribute("size");t.setXYZ(e.target,0,0,0),t.needsUpdate=!0,r.particles[e.target]=null,r.indices[e.target]=0}e.target=null}}const m=new a.Vector3,h=new a.Vector3,u=new a.Quaternion,p=new a.Vector3(1,0,0);export class InstancedRenderer extends t{constructor(e,t,r){super(e,t),this.view=r,this.meshes=[]}dispose(){this.meshes.forEach((e=>e.mesh.dispose()))}onSystemUpdate(){for(const e of this.meshes);}calcMaxCount(e){if(null==e)return 1;const t=e.parent.rate;return Math.min(t.numPan.b*Math.ceil(e.life/Math.min(Math.max(t.timePan.a,.01),1)),1e5)*this.calcMaxCount(e.parent.parentParticle)}onParticleCreated(e){if(!(e.body instanceof a.Sprite)){if(null==e.target){const t=e.body;let r=this.meshes.find((e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid));if(null==r){const s=this.calcMaxCount(e);r={mesh:new a.InstancedMesh(t.geometry,t.material,s),indices:new Array(s).fill(null),particles:[]},r.mesh.setColorAt(0,U.setScalar(1)),r.mesh.instanceColor.needsUpdate=!0,r.mesh.material.defines.USE_INSTANCING="";const i=new Float32Array(3*s);y.makeScale(0,0,0);for(let e=0;e<s;e++)i[3*e+0]=1,i[3*e+1]=1,r.mesh.setMatrixAt(e,y);r.mesh.instanceMatrix.needsUpdate=!0,r.mesh.geometry.setAttribute("particleData",new a.InstancedBufferAttribute(i,3)),this.meshes.push(r),this.container.add(r.mesh)}let s=r.indices.findIndex((e=>null==e));s<0&&(s=r.indices.indexOf(Math.min(...r.indices))),r.indices[s]=performance.now(),e.target=s,r.particles[s]=e}if("number"==typeof e.target){e.transform.initialScale;const t=e.body;let r=this.meshes.find((e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid));f(e,r.mesh),e.useAlpha&&(r.mesh.material.transparent=!0)}}}onParticleUpdate(e){const{target:t,useAlpha:r,useColor:a,rotation:s}=e;if(null==t)return;const i=e.body,n=this.meshes.find((e=>e.mesh.geometry.uuid===i.geometry.uuid&&e.mesh.material.uuid===i.material.uuid));if(null==n)return;f(e,n.mesh),a&&(n.mesh.setColorAt(e.target,U.copy(e.color)),n.mesh.instanceColor.needsUpdate=!0);const o=n.mesh.geometry.getAttribute("particleData");r&&o.setX(e.target,e.alpha),o.setY(e.target,e.energy),o.needsUpdate=!0}onParticleDead(e){if(null!=e.target){const t=e.body,r=this.meshes.find((e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid));if(null==r)return;r.indices[e.target]=null,e.scale=0,f(e,r.mesh),r.mesh.instanceMatrix.needsUpdate=!0,e.target=null}}}const g=new i;function f(e,t){if(w.set(e.position.x,e.position.y,e.position.z),e.transform&&e.transform.orientAlongVelocity){const r=m.set(e.position.x-e.old.position.x,e.position.y-e.old.position.y,e.position.z-e.old.position.z).normalize();t.getMatrixAt(e.target,g.matrix);const a=g.getWorldDirection(x);a.applyAxisAngle(p,Math.PI/-2),b.setFromUnitVectors(a,r)}else A.set(e.rotation.x,e.rotation.y,e.rotation.z),b.setFromEuler(A);const r=e.transform.initialScale;null!=r?x.set(r.x*e.scale,r.y*e.scale,r.z*e.scale):x.set(e.scale,e.scale,e.scale),y.compose(w,b,x),t.setMatrixAt(e.target,y),t.instanceMatrix.needsUpdate=!0}const y=new a.Matrix4,b=new a.Quaternion,w=new a.Vector3,x=new a.Vector3,A=new a.Euler,U=new a.Color(0),C={r:0,g:0,b:0};function M(e,t){const r=e.mesh,s=r.count,i=[],n=r.geometry.getAttribute("particleData"),o=new a.Vector3;for(let l=0;l<s;l++){const s=new a.Matrix4,c=new a.Color;r.getMatrixAt(l,s),r.getColorAt(l,c);const d=n.getX(l);o.setFromMatrixPosition(s);const m=o.distanceTo(t.position);i.push({index:l,distance:m,matrix:s,particle:e.particles[l],color:c,pdx:d})}i.sort(((e,t)=>t.distance-e.distance));for(let e=0;e<s;e++){const t=i[e].matrix;null==i[e].particle&&t.makeScale(0,0,0),r.setMatrixAt(e,t),r.setColorAt(e,i[e].color),n.setX(e,i[e].pdx)}r.instanceMatrix.needsUpdate=!0}export{M as sortInstancedMeshByDistance};/*
|
1
|
+
import{CustomRenderer as e,MeshRenderer as t,PUID as r}from"@hology/nebula";import*as a from"three";import{InstancedBufferAttribute as s,Object3D as i}from"three";import{NodeShaderMaterial as n}from"three-shader-graph";import{StretchedSprite as o}from"./stretched-sprite.js";import{Trail as l}from"./trail-renderer.js";import{SpriteNodeShaderMaterial as c}from"../../shader/sprite-shader";var d;!function(e){e[e.mesh=0]="mesh",e[e.instanced=1]="instanced",e[e.sprite=2]="sprite",e[e.stretchedBillboard=3]="stretchedBillboard",e[e.trail=4]="trail"}(d||(d={}));export class MultiRenderer extends e{constructor(e,t,r,a){super(),this.worldContainer=e,this.localContainer=t,this.three=r,this.view=a,this.localRenderers=[],this.worldRenderers=[]}onSystemUpdate(){for(const e of this.worldRenderers)e?.onSystemUpdate();for(const e of this.localRenderers)e?.onSystemUpdate()}onParticleCreated(e){this.getRenderer(e)?.onParticleCreated(e)}onParticleUpdate(e){this.getRenderer(e)?.onParticleUpdate(e)}onParticleDead(e){this.getRenderer(e)?.onParticleDead(e),e._renderer=null}getRenderer(e){if(e._renderer)return e._renderer;const t=(null!=e?.parent?e?.parent._space:null)??"world",r="world"===t?this.worldContainer:this.localContainer,s="world"===t?this.worldRenderers:this.localRenderers;return"trail"===e.body.type?(null==s[d.trail]&&(s[d.trail]=new TrailRenderer(r,this.three)),e._renderer=s[d.trail]):e.body instanceof o?(null==s[d.stretchedBillboard]&&(s[d.stretchedBillboard]=new StretchedSpriteInstancedRenderer(r,this.three,this.view)),e._renderer=s[d.stretchedBillboard]):e.body instanceof a.Sprite||e.body instanceof a.Mesh&&"sprite"===e.body.name?(null==s[d.sprite]&&(s[d.sprite]=new CombinedRenderer(r,this.three)),e._renderer=s[d.sprite]):e.body instanceof a.Mesh&&0==e.body.children.length&&e.body.material instanceof n?(null==s[d.instanced]&&(s[d.instanced]=new InstancedRenderer(r,this.three,this.view)),e._renderer=s[d.instanced]):e.body instanceof a.Object3D?(null==s[d.mesh]&&(s[d.mesh]=new CombinedRenderer(r,this.three)),e._renderer=s[d.mesh]):void 0}dispose(){this.localRenderers.forEach((e=>{e instanceof InstancedRenderer&&e.dispose()})),this.worldRenderers.forEach((e=>{e instanceof InstancedRenderer&&e.dispose()}))}}export class TrailRenderer extends t{constructor(){super(...arguments),this.trails=[]}dispose(){}onSystemUpdate(){for(const e of this.trails)e.update()}onParticleCreated(e){const t=e.body,r=new l(this.container,!0),s=new i,n=l.createBaseMaterial();n.uniforms.taper.value=t.taper??!1;const o=new a.Color(t.color??0),c=new a.Color(t.colorEnd??0);n.uniforms.headColor.value.set(o.r,o.g,o.b,t.opacityStart??1),n.uniforms.tailColor.value.set(c.r,c.g,c.b,t.opacityEnd??1),t.bloom&&(n.userData.hasBloom=!0),r.initialize(n,Math.round(t.length??10),!1,0,null,s);const d=e.rotation;s.rotation.set(d.x,d.y,d.z);e.scale;r.activate(),this.trails.push(r),e.target=s}onParticleUpdate(e){const t=e.target;t.position.copy(e.position);e.velocity.clone().normalize();const r=this.trails.findIndex((e=>e.targetObject.id===t.id));if(-1!=r){const t=this.trails[r];if(e.useAlpha){t.material.uniforms.headColor.value.setW(e.alpha);t.material.uniforms.tailColor.value.setW(e.alpha)}}}onParticleDead(e){const t=e.target,r=this.trails.findIndex((e=>e.targetObject.id===t.id));if(-1!=r){const e=this.trails[r];e.removeFromParent(),e.mesh.removeFromParent(),t.removeFromParent(),this.trails.splice(r,1)}}}export class CombinedRenderer extends t{dispose(){}scale(e){const t=e.transform.initialScale;e.target instanceof a.Sprite?null!=t?e.target.scale.set(t.x*e.scale*e.radius,t.y*e.scale*e.radius,1):e.target.scale.set(e.scale*e.radius,e.scale*e.radius,1):null!=t?e.target.scale.set(t.x*e.scale,t.y*e.scale,t.z*e.scale):super.scale(e)}rotate(e){e.target.material.rotation=e.rotation.z}onParticleCreated(e){e.target||(e.target=this._targetPool.get(e.body),(e.useAlpha||e.useColor)&&(e.target instanceof a.Mesh||e.target instanceof a.Sprite&&e.target.material instanceof a.Material)&&(e.target.material.__puid=r.id(e.body.material),e.target.material=this._materialPool.get(e.target.material))),e.target&&e.target instanceof i&&(e.target.position.set(e.position.x,e.position.y,e.position.z),this.container.add(e.target))}onParticleUpdate(e){const{target:t,useAlpha:r,useColor:s,rotation:n}=e;if(t){if(t.position.copy(e.position),this.isThreeSprite(e)||(t instanceof a.Mesh&&t.material instanceof c?e.target.material.rotation=e.rotation.z:t.rotation.set(n.x,n.y,n.z)),this.scale(e),e.transform&&e.transform.orientAlongVelocity&&t instanceof i){const r=m.set(e.velocity.x,e.velocity.y,e.velocity.z).normalize(),a=t.getWorldDirection(h);a.applyAxisAngle(p,Math.PI/-2),u.setFromUnitVectors(a,r),t.quaternion.copy(u)}t.material instanceof a.Material&&(r&&(t.material instanceof c&&null!=t.material.uniforms.opacity&&(t.material.uniforms.opacity.value=e.alpha,t.material.uniformsNeedUpdate=!0),t.material.opacity=e.alpha,t.material.transparent=!0),s&&(null!=t.material.color?t.material.color.copy(e.color):t.material instanceof a.ShaderMaterial&&null!=t.material.uniforms.color&&(t.material.uniforms.color.value=e.color,t.material.uniformsNeedUpdate=!0)))}}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 class StretchedSpriteInstancedRenderer extends t{constructor(e,t,r){super(e,t),this.view=r,this.meshes=[]}dispose(){this.meshes.forEach((e=>e.mesh.geometry.dispose()))}onSystemUpdate(){for(const e of this.meshes){const t=e.mesh.geometry.getAttribute("offset"),r=e.mesh.geometry.getAttribute("size"),s=e.mesh.geometry.getAttribute("velocity"),i=e.mesh.geometry.getAttribute("rotation"),n=e.mesh.geometry.getAttribute("color");let o=0;for(const l of e.particles){if(null==l||l.dead)continue;if(l.useColor||l.color instanceof a.Color){const e=U.copy(l.color).getRGB(C);n.setXYZW(o,e.r,e.g,e.b,1),n.needsUpdate=!0}l.useAlpha&&(n.setW(o,l.alpha),n.needsUpdate=!0),"number"==typeof l.rotation?i.setX(o,l.rotation):i.setX(o,l.rotation.x);const e=l.position;if(t.setXYZ(o,e.x,e.y,e.z),"number"!=typeof l.scale)throw new Error("Particle scale is not a number");r.setXYZ(o,l.scale,l.scale,l.scale);let c=l.body.scaleFactor;0===c&&(c=.001);const d=1,m=l.velocity;s.setXYZW(o,m.x*c,m.y*c,m.z*c,d),o++}o>0&&(t.clearUpdateRanges(),t.addUpdateRange(0,3*o),t.needsUpdate=!0,r.clearUpdateRanges(),r.addUpdateRange(0,3*o),r.needsUpdate=!0,n.clearUpdateRanges(),n.addUpdateRange(0,4*o),n.needsUpdate=!0,s.clearUpdateRanges(),s.addUpdateRange(0,4*o),s.needsUpdate=!0,i.clearUpdateRanges(),i.addUpdateRange(0,o),i.needsUpdate=!0)}}calcMaxCount(e){if(null==e)return 1;const t=e.parent.rate;return Math.min(t.numPan.b*Math.ceil(e.life/Math.min(Math.max(t.timePan.a,.01),1)),1e5)*this.calcMaxCount(e.parent.parentParticle)}onParticleCreated(e){if(e.body instanceof o&&null==e.target){const t=e.body;let r=this.meshes.find((e=>e.mesh.material.uuid===t.material.uuid));if(null==r){const i=this.calcMaxCount(e),n=new a.InstancedBufferGeometry;n.setIndex(t.geometry.getIndex()),n.setAttribute("position",t.geometry.getAttribute("position")),t.geometry.hasAttribute("normal")&&n.setAttribute("normal",t.geometry.getAttribute("normal")),n.setAttribute("uv",t.geometry.getAttribute("uv"));const o=new s(new Float32Array(3*i),3);o.setUsage(a.DynamicDrawUsage),n.setAttribute("offset",o);const l=new s(new Float32Array(4*i),4);if(l.setUsage(a.DynamicDrawUsage),n.setAttribute("color",l),t.material instanceof c){const e=new a.Color(t.material.color);for(let t=0;t<l.count;t++)l.setXYZW(t,e.r,e.g,e.b,1)}const d=new s(new Float32Array(3*i),3);d.setUsage(a.DynamicDrawUsage),n.setAttribute("size",d);const m=new s(new Float32Array(4*i),4);m.setUsage(a.DynamicDrawUsage),n.setAttribute("velocity",m);const h=new s(new Float32Array(4*i),1);h.setUsage(a.DynamicDrawUsage),n.setAttribute("rotation",h),r={mesh:new a.Mesh(n,t.material),indices:new Float32Array(i),particles:[]},this.meshes.push(r),this.container.add(r.mesh)}let i=r.indices.findIndex((e=>0===e));i<0&&(i=function(e){let t=e[0],r=0;for(let a=1;a<e.length;a++)e[a]<t&&(t=e[a],r=a);return r}(r.indices)),r.indices[i]=performance.now(),e.target=i,r.particles[i]=e}}onParticleUpdate(e){}onParticleDead(e){const t=e.body;let r=this.meshes.find((e=>e.mesh.material.uuid===t.material.uuid));if(r){const t=r.mesh.geometry.getAttribute("size");t.setXYZ(e.target,0,0,0),t.needsUpdate=!0,r.particles[e.target]=null,r.indices[e.target]=0}e.target=null}}const m=new a.Vector3,h=new a.Vector3,u=new a.Quaternion,p=new a.Vector3(1,0,0);export class InstancedRenderer extends t{constructor(e,t,r){super(e,t),this.view=r,this.meshes=[]}dispose(){this.meshes.forEach((e=>e.mesh.dispose()))}onSystemUpdate(){for(const e of this.meshes);}calcMaxCount(e){if(null==e)return 1;const t=e.parent.rate;return Math.min(t.numPan.b*Math.ceil(e.life/Math.min(Math.max(t.timePan.a,.01),1)),1e5)*this.calcMaxCount(e.parent.parentParticle)}onParticleCreated(e){if(!(e.body instanceof a.Sprite)){if(null==e.target){const t=e.body;let r=this.meshes.find((e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid));if(null==r){const s=this.calcMaxCount(e);r={mesh:new a.InstancedMesh(t.geometry,t.material,s),indices:new Array(s).fill(null),particles:[]},r.mesh.setColorAt(0,U.setScalar(1)),r.mesh.instanceColor.needsUpdate=!0,r.mesh.material.defines.USE_INSTANCING="";const i=new Float32Array(3*s);y.makeScale(0,0,0);for(let e=0;e<s;e++)i[3*e+0]=1,i[3*e+1]=1,r.mesh.setMatrixAt(e,y);r.mesh.instanceMatrix.needsUpdate=!0,r.mesh.geometry.setAttribute("particleData",new a.InstancedBufferAttribute(i,3)),this.meshes.push(r),this.container.add(r.mesh)}let s=r.indices.findIndex((e=>null==e));s<0&&(s=r.indices.indexOf(Math.min(...r.indices))),r.indices[s]=performance.now(),e.target=s,r.particles[s]=e}if("number"==typeof e.target){e.transform.initialScale;const t=e.body;let r=this.meshes.find((e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid));f(e,r.mesh),e.useAlpha&&(r.mesh.material.transparent=!0)}}}onParticleUpdate(e){const{target:t,useAlpha:r,useColor:a,rotation:s}=e;if(null==t)return;const i=e.body,n=this.meshes.find((e=>e.mesh.geometry.uuid===i.geometry.uuid&&e.mesh.material.uuid===i.material.uuid));if(null==n)return;f(e,n.mesh),a&&(n.mesh.setColorAt(e.target,U.copy(e.color)),n.mesh.instanceColor.needsUpdate=!0);const o=n.mesh.geometry.getAttribute("particleData");r&&o.setX(e.target,e.alpha),o.setY(e.target,e.energy),o.needsUpdate=!0}onParticleDead(e){if(null!=e.target){const t=e.body,r=this.meshes.find((e=>e.mesh.geometry.uuid===t.geometry.uuid&&e.mesh.material.uuid===t.material.uuid));if(null==r)return;r.indices[e.target]=null,e.scale=0,f(e,r.mesh),r.mesh.instanceMatrix.needsUpdate=!0,e.target=null}}}const g=new i;function f(e,t){if(w.set(e.position.x,e.position.y,e.position.z),e.transform&&e.transform.orientAlongVelocity){const r=m.set(e.position.x-e.old.position.x,e.position.y-e.old.position.y,e.position.z-e.old.position.z).normalize();t.getMatrixAt(e.target,g.matrix);const a=g.getWorldDirection(x);a.applyAxisAngle(p,Math.PI/-2),b.setFromUnitVectors(a,r)}else A.set(e.rotation.x,e.rotation.y,e.rotation.z),b.setFromEuler(A);const r=e.transform.initialScale;null!=r?x.set(r.x*e.scale,r.y*e.scale,r.z*e.scale):x.set(e.scale,e.scale,e.scale),y.compose(w,b,x),t.setMatrixAt(e.target,y),t.instanceMatrix.needsUpdate=!0}const y=new a.Matrix4,b=new a.Quaternion,w=new a.Vector3,x=new a.Vector3,A=new a.Euler,U=new a.Color(0),C={r:0,g:0,b:0};function M(e,t){const r=e.mesh,s=r.count,i=[],n=r.geometry.getAttribute("particleData"),o=new a.Vector3;for(let l=0;l<s;l++){const s=new a.Matrix4,c=new a.Color;r.getMatrixAt(l,s),r.getColorAt(l,c);const d=n.getX(l);o.setFromMatrixPosition(s);const m=o.distanceTo(t.position);i.push({index:l,distance:m,matrix:s,particle:e.particles[l],color:c,pdx:d})}i.sort(((e,t)=>t.distance-e.distance));for(let e=0;e<s;e++){const t=i[e].matrix;null==i[e].particle&&t.makeScale(0,0,0),r.setMatrixAt(e,t),r.setColorAt(e,i[e].color),n.setX(e,i[e].pdx)}r.instanceMatrix.needsUpdate=!0}export{M as sortInstancedMeshByDistance};/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
@@ -9,6 +9,7 @@ export declare class MeshComponent<TObj extends Object3D = Object3D> extends Act
|
|
9
9
|
readonly scale: Vector3;
|
10
10
|
readonly mass: number;
|
11
11
|
readonly friction: number;
|
12
|
+
readonly restitution: number;
|
12
13
|
readonly bodyType: PhysicsBodyType;
|
13
14
|
readonly isTrigger: boolean;
|
14
15
|
readonly continousCollisionDetection: boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mesh-component.d.ts","sourceRoot":"","sources":["../../../../../src/gameplay/actors/builtin/components/mesh-component.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,aAAa,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1
|
-
import{__decorate as t,__metadata as
|
1
|
+
import{__decorate as t,__metadata as i}from"tslib";import{PhysicsBodyType as s,PhysicsSystem as e}from"../../../../gameplay/services/physics/physics-system.js";import{AssetMeshInstance as o}from"../../../../scene/asset-resource-loader.js";import{PhysicalShapeMesh as r}from"../../../../index.js";import{Parameter as n}from"../../../../shader/parameter.js";import{Euler as c,Object3D as h,Vector3 as p}from"three";import{ActorComponent as a,Component as l}from"../../component.js";import{firstValueFrom as m}from"rxjs";const u={friction:.1,mass:0,restitution:1,bodyType:s.static,continousCollisionDetection:!1};let y=class extends a{constructor(t){super(),this.physicsSystem=t,this.position=new p,this.rotation=new c,this.scale=new p(1,1,1),this.mass=u.mass,this.friction=u.friction,this.restitution=u.restitution,this.bodyType=s.static,this.isTrigger=!1,this.continousCollisionDetection=u.continousCollisionDetection}onInit(){null!=this.object&&(this.currentMesh=this.object,this.updateMesh()),m(this.disposed).then((()=>{this.physicsSystem.removeActor(this.actor)}))}setObject(t){null!=this.currentMesh&&this.actor.object.remove(this.currentMesh),this.object=this.currentMesh=t,this.updateMesh()}updateMesh(){this.currentMesh.position.copy(this.position),this.currentMesh.rotation.copy(this.rotation),this.currentMesh.scale.copy(this.scale);const t=this.getCollisionShapes();t.length>0&&this.physicsSystem.addActor(this.actor,t,{...u,isTrigger:this.isTrigger??!1,mass:this.mass,friction:this.friction,type:this.bodyType,continousCollisionDetection:this.continousCollisionDetection,restitution:this.restitution}),this.actor.object.add(this.currentMesh)}getCollisionShapes(){return this.currentMesh instanceof o?this.currentMesh.collisionShapes:this.currentMesh instanceof r?[this.currentMesh.collisionShape]:"collisionShape"in this.currentMesh?(console.error("Could not understand wehre to get collision shapes from. This is likely due to an import issue"),[this.currentMesh.collisionShape]):[]}};t([n({type:h}),i("design:type",Object)],y.prototype,"object",void 0),t([n(),i("design:type",p)],y.prototype,"position",void 0),t([n(),i("design:type",c)],y.prototype,"rotation",void 0),t([n(),i("design:type",p)],y.prototype,"scale",void 0),t([n(),i("design:type",Number)],y.prototype,"mass",void 0),t([n(),i("design:type",Number)],y.prototype,"friction",void 0),t([n(),i("design:type",Number)],y.prototype,"restitution",void 0),t([n({options:[{name:"Static",value:s.static},{name:"Kinematic",value:s.kinematic},{name:"Dynamic",value:s.dynamic}]}),i("design:type",Number)],y.prototype,"bodyType",void 0),t([n(),i("design:type",Boolean)],y.prototype,"isTrigger",void 0),y=t([l({inEditor:!0}),i("design:paramtypes",[e])],y);export{y as MeshComponent};/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
package/dist/gameplay/index.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gameplay/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAA;AACzB,OAAO,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAA;AACjD,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,OAAO,EAAG,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,KAAK,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACzG,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,sCAAsC,CAAA;AAEpD,cAAc,wBAAwB,CAAA;AACtC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,8BAA8B,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAC1D,cAAc,wBAAwB,CAAA;AACtC,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gameplay/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAA;AACzB,OAAO,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,QAAQ,CAAA;AACjD,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,OAAO,EAAE,OAAO,EAAG,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,KAAK,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACzG,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,sCAAsC,CAAA;AAEpD,cAAc,wBAAwB,CAAA;AACtC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,8BAA8B,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAA;AAC1D,cAAc,wBAAwB,CAAA;AACtC,cAAc,eAAe,CAAA;AAC7B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,+BAA+B,CAAA"}
|
package/dist/gameplay/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import"reflect-metadata";export{Container as DIContainer}from"typedi";export*from"./initiate.js";export*from"./inject.js";export{Service,Inject}from"typedi";export{ActorFactory}from"./actors/factory.js";export{Actor,BaseActor}from"./actors/actor.js";export{Component,ActorComponent,attach,Attach}from"./actors/component.js";export*from"./services/world.js";export*from"./services/render.js";export*from"./services/physics/physics-system.js";export*from"./animation/anim-sm.js";export*from"./animation/root-motion.js";export*from"./services/asset-loader.js";export*from"./services/pointer-events.js";export{VisualEffect}from"../effects/vfx/vfx-param.js";export*from"../shader/parameter.js";export*from"./ai/index.js";export*from"../effects/vfx";/*
|
1
|
+
import"reflect-metadata";export{Container as DIContainer}from"typedi";export*from"./initiate.js";export*from"./inject.js";export{Service,Inject}from"typedi";export{ActorFactory}from"./actors/factory.js";export{Actor,BaseActor}from"./actors/actor.js";export{Component,ActorComponent,attach,Attach}from"./actors/component.js";export*from"./services/world.js";export*from"./services/render.js";export*from"./services/physics/physics-system.js";export*from"./animation/anim-sm.js";export*from"./animation/root-motion.js";export*from"./services/asset-loader.js";export*from"./services/pointer-events.js";export{VisualEffect}from"../effects/vfx/vfx-param.js";export*from"../shader/parameter.js";export*from"./ai/index.js";export*from"../effects/vfx";export*from"./services/shader-provider.js";/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"initiate.d.ts","sourceRoot":"","sources":["../../src/gameplay/initiate.ts"],"names":[],"mappings":"AAAA,OAAkB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AAEpE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAa3C,OAAO,EAAE,UAAU,EAAW,MAAM,MAAM,CAAA;
|
1
|
+
{"version":3,"file":"initiate.d.ts","sourceRoot":"","sources":["../../src/gameplay/initiate.ts"],"names":[],"mappings":"AAAA,OAAkB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AAEpE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAa3C,OAAO,EAAE,UAAU,EAAW,MAAM,MAAM,CAAA;AAM1C,KAAK,SAAS,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,CAAA;AAGpC,M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AAK,mBAA8D;gBAGzE,iBAAiB,EAAE,iBAAiB;IAE9C,QAAQ,IAAI,KAAK;IAIjB,UAAU,CAAC,CAAC,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC;IAI/C;;OAEG;IACH,QAAQ;CAuBT"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import e from"typedi";import{loadScene as t}from"../scene/bootstrap.js";import{ActorFactory as n}from"./actors/factory.js";import{World as s}from"./services/world.js";import{ViewController as o}from"./services/render.js";import{RenderingView as r}from"../rendering.js";import{PhysicsSystem as i}from"./services/physics/physics-system.js";import{MeshComponent as a}from"./actors/builtin/components/mesh-component.js";import{activeContainerInstance as c}from"./actors/internal/container-map.js";import{InputService as m}from"./input/index.js";import{RuntimeAssetsService as d}from"../scene/runtime-asset-service.js";import{AssetResourceLoader as l}from"../scene/asset-resource-loader.js";import{AssetLoader as
|
1
|
+
import e from"typedi";import{loadScene as t}from"../scene/bootstrap.js";import{ActorFactory as n}from"./actors/factory.js";import{World as s}from"./services/world.js";import{ViewController as o}from"./services/render.js";import{RenderingView as r}from"../rendering.js";import{PhysicsSystem as i}from"./services/physics/physics-system.js";import{MeshComponent as a}from"./actors/builtin/components/mesh-component.js";import{activeContainerInstance as c}from"./actors/internal/container-map.js";import{InputService as m}from"./input/index.js";import{RuntimeAssetsService as d}from"../scene/runtime-asset-service.js";import{AssetResourceLoader as l}from"../scene/asset-resource-loader.js";import{AssetLoader as p}from"./services/asset-loader.js";import{polyfillClient as h}from"./polyfill.js";import{Subject as u}from"rxjs";import{PointerEvents as f}from"./services/pointer-events.js";import{RuntimeBundledBackendService as w}from"../scene/runtime-bundled-backend-service.js";import{Scene as g}from"three";import{ShaderProvider as v}from"./services/shader-provider.js";export function initiateGame(m,u){if(h(),0!=u.element.childNodes.length)return console.error("Can not initialize the game with a non-empty html element"),null;e.has(o);const j=e.of("default"),S=new HologyRuntime(j),y=new n(j,{inEditor:!1});var I;e.set(n,y),I=u.element,Object.assign(I.style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",overflow:"hidden"});const x=new r(u.element,{enableXR:!0===u.xr?.enabled,maxPixelRatio:u.rendering?.maxPixelRatio});x.renderer.shadowMap.enabled=u.rendering?.shadows?.enabled??!0,x.renderer.shadowMap.autoUpdate=u.rendering?.shadows?.autoUpdate??!0,null!=u?.rendering?.resolutionScale&&(x.resolutionScale=u.rendering.resolutionScale),e.set(r,x);const b=new o(x);e.set(o,b);const D=e.get(s);e.set(s,D);const R=new w,G=new d(R),H=new l;H.setDataDir(u.dataDir);const P=Object.entries(u.shaders).map((([e,t])=>({name:e,type:t}))),W=new v(P);e.set(v,W);const A=new p(H,G,P);return e.set(p,A),(async()=>{const n=e.get(i);if(await n.start(),S.isShutdown)return;if(await R.preloadData(),S.isShutdown)return;const s=new g;D.scene=s;const{scene:o,actors:r}=await t(x,u.sceneName,u.dataDir,u.shaders,u.actors,y,R,G,H);D.scene=o;for(const e of s.children)D.scene.add(e);if(S.isShutdown)return void x.stop();e.import([a]);for(const e of r)D.addActor(e);n.addFromScene(o),x.loop((e=>{})),S.status=5,c.value=j,j.remove(m),j.set({id:m,type:m});const d=j.get(m);c.value=null,S.gameInstance=d,j.get(f).start(),d instanceof GameInstance&&d.onStart(),S._resolver(!0)})(),S}export class GameInstance{onStart(){}onShutdown(){}}export function createHologyScene(){}export class HologyRuntime{constructor(e){this.containerInstance=e,this.status=0,this.isShutdown=!1,this.shutdownStarted=new u,this.ready=new Promise((e=>{this._resolver=e}))}getWorld(){return this.containerInstance.get(s)}getService(e){return this.containerInstance.get(e)}shutdown(){this.isShutdown=!0,this.shutdownStarted.next(),this.gameInstance instanceof GameInstance&&this.gameInstance.onShutdown(),this.containerInstance.get(m).stop();const e=this.containerInstance.get(r);e?.stop();for(const e of this.getWorld().actors)this.getWorld().removeActor(e);this.containerInstance.get(i).stop(),this.containerInstance.get(f).stop(),this.containerInstance.reset()}}/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
@@ -12,6 +12,14 @@ export declare class InputService {
|
|
12
12
|
private touchmoveBinds;
|
13
13
|
private wheelbinds;
|
14
14
|
private onKeyDown;
|
15
|
+
/**
|
16
|
+
* Multiple keybinds can possibly affect the same axis such as pressing space to break
|
17
|
+
* while still holding down W to move forward. If breaking is just toggling negative Y axis
|
18
|
+
* on the axis input, then when releasing space, the input would normally just be reset to 0
|
19
|
+
* even while holding down W to more forward. By keeping track of active toggle callbacks,
|
20
|
+
* we can retrigger any active callbacks to get back to the state we were at beforeds
|
21
|
+
*/
|
22
|
+
private activeToggleCallbacks;
|
15
23
|
private onKeyUp;
|
16
24
|
private onMouseMove;
|
17
25
|
private prevTouchEvent;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"input-service.d.ts","sourceRoot":"","sources":["../../../src/gameplay/input/input-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE7D,KAAK,aAAa,GAAG,CAAC,MAAM,EAAE,OAAO,GAAC,MAAM,KAAK,IAAI,CAAA;AACrD,KAAK,aAAa,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,GAAG,CAAA;AAC3C,KAAK,cAAc,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,GAAG,CAAA;AAC9C,KAAK,gBAAgB,GAAG,MAAM,GAAG,MAAM,CAAA;AAEvC,qBACa,YAAY;IAErB,OAAO,CAAC,MAAM,CAA6C;IAC3D,OAAO,CAAC,cAAc,CAA6C;IACnE,OAAO,CAAC,eAAe,CAA8C;IACrE,OAAO,CAAC,QAAQ,CAAyC;IACzD,OAAO,CAAC,UAAU,CAAyC;IAC3D,OAAO,CAAC,cAAc,CAAyC;IAC/D,OAAO,CAAC,UAAU,CAAyC;IAE3D,OAAO,CAAC,SAAS,
|
1
|
+
{"version":3,"file":"input-service.d.ts","sourceRoot":"","sources":["../../../src/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E,SAAS;IAIrD,gBAAgB,CAAC,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,SAAS;IAIzD,YAAY,CAAC,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,SAAS;IAIrD,aAAa,CAAC,IAAI,EAAE,gBAAgB;IAIpC,eAAe,CAAC,IAAI,EAAE,gBAAgB;IAItC,eAAe,CAAC,IAAI,EAAE,gBAAgB;CAIhD"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{__decorate as e}from"tslib";import{Service as t}from"typedi";let s=class{constructor(){this.inputs=new Map,this.deltaCallbacks=new Map,this.toggleCallbacks=new Map,this.keybinds=new Map,this.mousebinds=new Map,this.touchmoveBinds=new Map,this.wheelbinds=new Map,this.onKeyDown=e=>{this.keybinds.forEach(((t,s)=>{for(const
|
1
|
+
import{__decorate as e}from"tslib";import{Service as t}from"typedi";let s=class{constructor(){this.inputs=new Map,this.deltaCallbacks=new Map,this.toggleCallbacks=new Map,this.keybinds=new Map,this.mousebinds=new Map,this.touchmoveBinds=new Map,this.wheelbinds=new Map,this.onKeyDown=e=>{this.keybinds.forEach(((t,s)=>{for(const i of t)if(i.test(e))if(this.inputs.has(s))this.inputs.get(s)(!0);else if(this.toggleCallbacks.has(s)){this.toggleCallbacks.get(s)(!0);this.activeToggleCallbacks.findIndex((e=>e.keybind===i&&e.toggle===this.toggleCallbacks.get(s)))<0&&this.activeToggleCallbacks.push({keybind:i,toggle:this.toggleCallbacks.get(s)})}else console.warn("No input callback for registered for key bind "+i.display())}))},this.activeToggleCallbacks=[],this.onKeyUp=e=>{this.keybinds.forEach(((t,s)=>{for(const i of t)if(i.test(e))if(this.inputs.has(s))this.inputs.get(s)(!1);else if(this.toggleCallbacks.has(s)){this.toggleCallbacks.get(s)(!1);const e=this.activeToggleCallbacks.findIndex((e=>e.keybind===i&&e.toggle===this.toggleCallbacks.get(s)));e>=0&&this.activeToggleCallbacks.splice(e,1);for(const e of this.activeToggleCallbacks)e.toggle(!0)}else console.warn("No input callback for registered for key bind "+i.display())}))},this.onMouseMove=e=>{(null!=document.pointerLockElement||null!=document.mozPointerLockElement)&&this.mousebinds.forEach(((t,s)=>{const i=this.inputs.get(s)??this.deltaCallbacks.get(s);if(null!=i)switch(t.axis){case"x":i(e.movementX*t.multiplier);break;case"y":i(e.movementY*t.multiplier)}else console.warn("No input callback for registered for mouse bind "+t.axis)}))},this.onTouchMove=e=>{const t=e.touches[0];null!=t&&(null!=this.prevTouchEvent&&t.identifier===this.prevTouchEvent.identifier?(this.touchmoveBinds.forEach(((e,s)=>{const i=this.inputs.get(s)??this.deltaCallbacks.get(s);if(null!=i)switch(e.axis){case"x":i((t.clientX-this.prevTouchEvent.clientX)*e.multiplier);break;case"y":i((t.clientY-this.prevTouchEvent.clientY)*e.multiplier)}else console.warn("No input callback for registered for mouse bind "+e.axis)})),this.prevTouchEvent=t):this.prevTouchEvent=e.touches[0])},this.onWheel=e=>{this.wheelbinds.forEach(((t,s)=>{const i=this.inputs.get(s)??this.deltaCallbacks.get(s);null!=i?i(e.deltaY*t.multiplier):console.warn("No input callback for registered for wheel bind")}))}}start(){document.addEventListener("keydown",this.onKeyDown),document.addEventListener("mousedown",this.onKeyDown),document.addEventListener("mouseup",this.onKeyUp),document.addEventListener("keyup",this.onKeyUp),document.addEventListener("mousemove",this.onMouseMove),document.addEventListener("touchmove",this.onTouchMove),document.addEventListener("wheel",this.onWheel)}stop(){document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("mousedown",this.onKeyDown),document.removeEventListener("mouseup",this.onKeyUp),document.removeEventListener("keyup",this.onKeyUp),document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("touchmove",this.onTouchMove),document.removeEventListener("wheel",this.onWheel)}bind(e,t){this.inputs.set(e,t)}bindToggle(e,t){this.toggleCallbacks.set(e,t)}bindDelta(e,t){this.deltaCallbacks.set(e,t)}unbind(e){this.inputs.delete(e),this.toggleCallbacks.delete(e),this.deltaCallbacks.delete(e)}setKeybind(e,t){this.keybinds.has(e)||this.keybinds.set(e,[]),this.keybinds.get(e).push(t)}setMousebind(e,t){this.mousebinds.set(e,t)}setTouchMoveBind(e,t){this.touchmoveBinds.set(e,t)}setWheelbind(e,t){this.wheelbinds.set(e,t)}removeKeybind(e){this.keybinds.delete(e)}removeMousebind(e){this.mousebinds.delete(e)}removeWheelbind(e){this.wheelbinds.delete(e)}};s=e([t()],s);export{s as InputService};/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
@@ -7,6 +7,7 @@ import { BaseActor } from '../../actors/actor.js';
|
|
7
7
|
import { ViewController } from '../render.js';
|
8
8
|
import { World } from '../world.js';
|
9
9
|
import { AbstractPhysicsSystem, ActorPhysicsOptions } from './abstract-physics-system.js';
|
10
|
+
export { Component, ActorComponent, type ComponentOptions, attach, Attach } from '../../actors/component.js';
|
10
11
|
export declare class RayTestResult {
|
11
12
|
actor?: BaseActor;
|
12
13
|
hasHit: boolean;
|
@@ -201,6 +202,7 @@ export declare class PhysicsSystem extends AbstractPhysicsSystem {
|
|
201
202
|
* @private
|
202
203
|
*/
|
203
204
|
private addLandscapeGroup;
|
205
|
+
setEnabled(actor: BaseActor, value: boolean): void;
|
204
206
|
/**
|
205
207
|
* Adds an actor to the physics world with the specified collision shapes and options.
|
206
208
|
* @param actor - The actor to add
|
@@ -406,5 +408,4 @@ export declare class PhysicsSystem extends AbstractPhysicsSystem {
|
|
406
408
|
*/
|
407
409
|
createCharacterCollision(): RAPIER.CharacterCollision;
|
408
410
|
}
|
409
|
-
export {};
|
410
411
|
//# sourceMappingURL=physics-system.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"physics-system.d.ts","sourceRoot":"","sources":["../../../../src/gameplay/services/physics/physics-system.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,2BAA2B,CAAA;AAEnD,OAAO,EAAgE,UAAU,EAAE,OAAO,EAA2B,MAAM,MAA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,4 +1,4 @@
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import*as i from"@dimforge/rapier3d-compat";import{QueryFilterFlags as s}from"@dimforge/rapier3d-compat";import{BehaviorSubject as o,distinctUntilChanged as n,filter as r,map as a,Subject as c,takeUntil as l}from"rxjs";import*as d from"three";import{ArrowHelper as h,BufferAttribute as u,BufferGeometry as y,Group as p,LineSegments as g,Matrix4 as m,Object3D as f,Quaternion as w,Raycaster as v,Scene as x,Vector3 as B}from"three";import{Service as b}from"typedi";import{AssetMeshInstance as A}from"../../../scene/asset-resource-loader.js";import{BoxCollisionShape as C,CapsuleCollisionShape as D,ConeCollisionShape as z,ConvexPolyhedronCollisionShape as M,CylinderCollisionShape as R,PhysicalShapeMesh as S,PlaneCollisionShape as T,SphereCollisionShape as E,TrimeshCollisionShape as W}from"../../../index.js";import{LandscapeGroup as F}from"../../../scene/landscape/landscape.js";import{ViewController as V}from"../render.js";import{World as _}from"../world.js";import*as I from"three/examples/jsm/utils/BufferGeometryUtils.js";import{calculateEffectiveScale as j}from"../../../utils/three/traverse.js";import{AbstractPhysicsSystem as L}from"./abstract-physics-system.js";export class RayTestResult{constructor(){this.hasHit=!1,this.hitPoint=new B,this.hitNormal=new B}}export var PhysicsBodyType;!function(e){e[e.dynamic=1]="dynamic",e[e.static=2]="static",e[e.kinematic=4]="kinematic",e[e.kinematicVelocityBased=8]="kinematicVelocityBased"}(PhysicsBodyType||(PhysicsBodyType={}));let P=class extends L{set showDebug(e){this.shouldRenderDebug=e,this.debugMesh&&(this.debugMesh.visible=e)}get showDebug(){return this.shouldRenderDebug}constructor(e,t){super(),this.viewController=e,this.gameWorld=t,this.staticMeshes=new Map,this.staticBodies=new Map,this.actorBodies=new Map,this.bodyActors=new Map,this.collisionEvents=new c,this.beforeStep=new c,this.afterStep=new c,this.shouldRenderDebug=!1,this._raycaster=new v,this._reusableResult=new RayTestResult,this._raytestDiff=new B,this._raytestDirection=new B,this.controlledActors=new Set,this.ready=this.setup()}createDebugMesh(){return new g(new y,new d.LineBasicMaterial({color:255}))}async start(){return await this.ready,this.handleTick(),this.ready}renderDebug(){null==this.debugMesh&&(this.debugMesh=this.createDebugMesh(),this.debugMesh.visible=this.shouldRenderDebug,this.debugMesh.raycast=function(){},this.gameWorld.scene.add(this.debugMesh));const e=this.world.debugRender();this.debugMesh.geometry.setAttribute("position",new u(e.vertices,3))}async setup(){if(null!=this.rapier)throw new Error("Rapier is already estup");this.rapier=await X(),this.eventQueue=new i.EventQueue(!0),this.setupWorld()}handleTick(){this.fixedupdateSub=this.viewController.onUpdate().subscribe((e=>{e=Math.min(.1,e),this.beforeStep.next(e),this.updatePhysics(e),this.showDebug&&this.renderDebug(),this.world.bodies.forEach((e=>{if(e.isFixed())return;const t=this.staticMeshes.get(e)??this.bodyActors.get(e)?.object;var i,s;null!=t&&(t.parent instanceof x&&(Y(t.position,e.translation()),(e.isDynamic()||e.isKinematic()&&!this.controlledActors.has(this.bodyActors.get(e)?.id))&&(i=t.quaternion,s=e.rotation(),i.x=s.x,i.y=s.y,i.z=s.z,i.w=s.w),t.updateMatrix(),t.updateWorldMatrix(!1,!1)))})),this.afterStep.next(e)}))}_updateWorld(){this.world.timestep=0,this.world.step()}updatePhysics(e){this.world.timestep=e,this.world.step(this.eventQueue),this.eventQueue.drainCollisionEvents(((e,t,i)=>{this.collisionEvents.next({handle1:e,handle2:t,started:i}),this.collisionEvents.next({handle1:t,handle2:e,started:i})}))}rayTestFromCamera(e,t,i){this._raycaster.setFromCamera(H,this.viewController.getCamera());const s=this._raycaster.ray.origin,o=this._raycaster.ray.direction.multiplyScalar(e).add(s);return this.rayTest(s,o,t,i)}rayTest(e,t,i,s){null==i&&(i=this._reusableResult);const o=this._raytestDiff,n=this._raytestDirection;if(o.subVectors(t,e),n.copy(o).normalize(),0===n.length())return console.warn("Ray test called with to and from being equal"),i;K(ie.origin,e),K(ie.dir,n);const r=o.length(),a=this.world.castRayAndGetNormal(ie,r,!1,void 0,void 0,void 0,null!=s?.excludeActor?this.actorBodies.get(s.excludeActor.id):void 0,s?.excludeTriggers?e=>!e.isSensor():void 0);if(i.hasHit=null!=a,i.hasHit){const t=ie.pointAt(a.timeOfImpact);i._internal=a,Y(i.hitNormal,a.normal),Y(i.hitPoint,t),i.distance=J.subVectors(i.hitPoint,e).length();const s=this.world.bodies.getAll().find((e=>function(e,t){for(let i=0,s=e.numColliders();i<s;i++){const s=e.collider(i);if(t(s))return s}}(e,(e=>e===a.collider))));i.actor=null!=s?this.bodyActors.get(s):null}if(this.showDebug){const t=new h(n,e,r,s?.debugColor??255);this.gameWorld.scene.add(t),setTimeout((()=>this.gameWorld.scene.remove(t)),s?.debugLifetime??200)}return this._reusableResult}setGravity(e,t,i){this.world.gravity.x=e,this.world.gravity.y=t,this.world.gravity.z=i}getGravity(){return G.set(this.world.gravity.x,this.world.gravity.y,this.world.gravity.z)}addFromScene(e){this.addRecursively(e);for(const e of this.staticBodies.values())Z(e,(e=>e.setActiveEvents(i.ActiveEvents.COLLISION_EVENTS)))}addRecursively(e){if(this.removeSceneObject(e),!function(e){if(null!=e.userData?.src){const t=e.userData?.src;return"actor"===t.type}return!1}(e))if(e instanceof S&&null!=e.collisionShape){const t=this.createStaticBody(e,[e.collisionShape],e.physics);this.staticMeshes.set(t,e),this.staticBodies.set(e,t)}else if(e instanceof A&&!1!==e.userData?.src?.collisionDetection)if(e.children[0]&&e.children[0].instanceMatrix)this.createForInstancedMesh(e.children[0],e.collisionShapes);else{const t=this.createStaticBody(e,e.collisionShapes,e.physics);this.staticMeshes.set(t,e),this.staticBodies.set(e,t)}else e instanceof F?this.addLandscapeGroup(e):(e instanceof p||e instanceof x)&&e.children.forEach((e=>this.addRecursively(e)))}createForInstancedMesh(e,t){const i=new m;for(let s=0;s<e.count;s++){const o=new f;o.matrix.identity(),i.fromArray(e.instanceMatrix.array,16*s),o.applyMatrix4(i);this.createStaticBody(o,t)}}getCharacterController(e){return this.world?.createCharacterController(e)}getActorComputedMovement(e,t,i,o=null){const n=this.actorBodies.get(e.id);this.controlledActors.add(e.id);const r=n.collider(0);t.computeColliderMovement(r,i,s.EXCLUDE_SENSORS,o,ee);const a=t.computedMovement();return Y($,a),$}setNextKinematicTranslation(e,t){const i=this.actorBodies.get(e.id),s=i.translation();s.x+=t.x,s.y+=t.y,s.z+=t.z,i?.setNextKinematicTranslation(s)}setAngularVelocity(e,t){const i=this.actorBodies.get(e.id);q.x=t.x,q.y=t.y,q.z=t.z,i?.setAngvel(q,!0)}setLinearVelocity(e,t){const i=this.actorBodies.get(e.id);q.x=t.x,q.y=t.y,q.z=t.z,i?.setLinvel(q,!0)}getLinearVelocity(e,t=new B){const i=this.actorBodies.get(e.id).linvel();return t.x=i.x,t.y=i.y,t.z=i.z,t}getAngularVelocity(e,t=new B){const i=this.actorBodies.get(e.id).angvel();return t.x=i.x,t.y=i.y,t.z=i.z,t}setLinearDamping(e,t){const i=this.actorBodies.get(e.id);i?.setLinearDamping(t)}setAngularDamping(e,t){const i=this.actorBodies.get(e.id);i?.setAngularDamping(t)}addLandscapeGroup(e){const t=e.userData.src,s=t.landscape.heightMaps;for(const n of e.sections){this.staticBodies.has(n)&&this.world.removeRigidBody(this.staticBodies.get(n));var o=n.getWorldPosition(new B);if(t.landscape.holes&&t.landscape.holes.some((e=>e.m===n.name&&0!==e.w[0]))){const e=n.geometry.clone(),s=n.scale,r=n.geometry.getAttribute("hole"),a=new Float32Array(e.getAttribute("position").array);for(let e=0;e<a.length;e+=3)a[e]*=s.x,a[e+1]*=s.y,a[e+2]*=s.z;const c=e.index;for(let e=0;e<c.count;e+=3){const t=r.getX(c.getX(e)),i=r.getX(c.getY(e)),s=r.getX(c.getZ(e));(t>.5||i>.5||s>.5)&&(c.setX(e,0),c.setY(e,0),c.setZ(e,0))}const l=i.ColliderDesc.trimesh(a,new Uint32Array(e.getIndex().array));if(!1!==t.collisionDetection){const e=this.world.createRigidBody(i.RigidBodyDesc.fixed()),t=new i.Vector3(0,0,0);K(t,o),e.setTranslation(t,!1),this.world.createCollider(l,e),this.staticBodies.set(n,e)}continue}const e=t.landscape.options.density+1,r=t.landscape.options.sectionSize,a=new Array(e);for(let t=0;t<e;t++)a[t]=new Array(e).fill(0);const c=s.find((e=>e.x===n.x&&e.y==n.y));if(null!=c)for(const t of c.points){if(null==a[t.i%e])continue;const i=e-1-Math.floor(t.i/e);i in a[t.i%e]?a[t.i%e][i]=t.y/r:console.warn("wrong index",{points:a,point:t,i:t.i%e,k:i,heightMap:c})}const l=t.landscape.options.density,d=a.flatMap((e=>e.reverse())),h=i.ColliderDesc.heightfield(l,l,new Float32Array(d),new i.Vector3(r,r,r));if(!1!==t.collisionDetection){const e=this.world.createRigidBody(i.RigidBodyDesc.fixed()),t=new i.Vector3(0,0,0);K(t,o),e.setTranslation(t,!1),this.world.createCollider(h,e),this.staticBodies.set(n,e)}}}addActor(e,t,s={}){if(0==t.length)return void console.error("No collision shapes were defined when adding actor to the physics system.");this.removeActor(e);const o=e.object;let n;switch(s.type??PhysicsBodyType.static){case PhysicsBodyType.dynamic:n=i.RigidBodyDesc.dynamic(),n.mass=s.mass??1;break;case PhysicsBodyType.kinematic:n=i.RigidBodyDesc.kinematicPositionBased();break;case PhysicsBodyType.kinematicVelocityBased:n=i.RigidBodyDesc.kinematicVelocityBased();break;default:n=s.isTrigger?i.RigidBodyDesc.kinematicVelocityBased():i.RigidBodyDesc.fixed()}const r=this.world.createRigidBody(n);r.enableCcd(1==s.continousCollisionDetection);for(const e of t)this.addShape(r,e,o);Z(r,(e=>{null!=s.isTrigger&&(e.setSensor(s.isTrigger),e.setActiveCollisionTypes(i.ActiveCollisionTypes.ALL),e.setActiveEvents(i.ActiveEvents.COLLISION_EVENTS)),null!=s.friction&&e.setFriction(s.friction),null!=s.density&&e.setDensity(s.density),null!=s.mass&&e.setMass(s.mass),null!=s.restitution&&e.setRestitution(s.restitution)})),N(r,o),!0===s.ignoreForNavMesh&&(r.userData={ignoreForNavMesh:!0}),this.actorBodies.set(e.id,r),this.bodyActors.set(r,e)}applyTorque(e,t){const i=this.actorBodies.get(e.id);q.x=t.x,q.y=t.y,q.z=t.z,i?.addTorque(q,!0)}applyTorqueImpulse(e,t){const i=this.actorBodies.get(e.id);q.x=t.x,q.y=t.y,q.z=t.z,i?.applyTorqueImpulse(q,!0)}resetForces(e){const t=this.actorBodies.get(e.id);t?.resetForces(!1)}resetTorques(e){const t=this.actorBodies.get(e.id);t?.resetTorques(!1)}applyForce(e,t){const i=this.actorBodies.get(e.id);q.x=t.x,q.y=t.y,q.z=t.z,i?.addForce(q,!0)}applyImpulse(e,t){const i=this.actorBodies.get(e.id);q.x=t.x,q.y=t.y,q.z=t.z,i?.applyImpulse(q,!0)}applyLocalForce(e,t,i){const s=this.actorBodies.get(e.id);K(q,t),null==i?s?.addForce(q,!0):(K(Q,i),s?.addForceAtPoint(q,Q,!0))}applyLocalImpulse(e,t,i){const s=this.actorBodies.get(e.id);K(q,t),null==i?s.applyImpulse(q,!0):(K(Q,i),s.applyImpulseAtPoint(q,Q,!0))}applyRadiusImpulse(e,t,s){this.world.bodies.forEach((o=>{if(o.collider(0)?.isSensor())return;if(o.bodyType()!==i.RigidBodyType.Dynamic)return;const n=U;Y(n,o.translation());const r=n.clone().sub(e);if(r.length()>t)return;const a=r.clone().normalize().multiplyScalar(s);q.x=a.x,q.y=a.y,q.z=a.z,o.applyImpulse(q,!0)}))}removeActor(e){if(null==e)return;this.controlledActors.delete(e.id);const t=this.actorBodies.get(e.id);null!=t&&(this.bodyActors.delete(t),this.world.removeRigidBody(t)),this.actorBodies.delete(e.id)}removeRemoved(e){const t=new Set;e.traverse((e=>{t.add(e.uuid)}));for(const[e,i]of this.staticBodies.entries())!t.has(e.uuid)&&this.world.getRigidBody(i.handle)&&(this.staticBodies.delete(e),this.world.removeRigidBody(i))}removeSceneObject(e){if(e instanceof F){for(const t of e.sections)this.removeSceneObject(t);return}let t=this.staticBodies.get(e);null!=t&&this.world.getRigidBody(t.handle)&&this.world.removeRigidBody(t),this.staticBodies.delete(e)}activateActorEvents(e){this.actorBodies.get(e.id)}_onCollisionWithActorEvent(e,t,i){return this.activateActorEvents(e),this.collisionEvents.pipe(l(e.disposed),r((({started:e})=>e===i)),a((({handle1:e,handle2:t,started:i})=>({a1:this.bodyActors.get(this.world.getCollider(e)?.parent()),a2:this.bodyActors.get(this.world.getCollider(t)?.parent()),started:i}))),r((({a1:i,a2:s})=>null!=i&&null!=s&&i.id===e.id&&t(i,s))),a((({a2:e})=>e)))}onBeginContact(e){return this.activateActorEvents(e),this.collisionEvents.pipe(l(e.disposed),r((e=>e.started)),r((({handle1:t})=>{const i=this.bodyActors.get(this.world.getCollider(t)?.parent());return null!=i&&i.id===e.id})),a((e=>e.handle2)))}onEndContact(e){return this.activateActorEvents(e),this.collisionEvents.pipe(l(e.disposed),r((e=>!e.started)),r((({handle1:t})=>{const i=this.bodyActors.get(this.world.getCollider(t)?.parent());return null!=i&&i.id===e.id})),a((e=>e.handle2)))}onHasContactChanged(e){const t=new Set,i=new o(!1);return this.onBeginContact(e).subscribe((e=>{t.add(e),i.next(t.size>0)})),this.onEndContact(e).subscribe((e=>{t.delete(e),i.next(t.size>0)})),i.pipe(n())}onBeginOverlapWithActorType(e,t){return this._onCollisionWithActorEvent(e,((e,i)=>i instanceof t),!0)}onEndOverlapWithActorType(e,t){return this._onCollisionWithActorEvent(e,((e,i)=>i instanceof t),!1)}onBeginOverlapWithActor(e,t){return this._onCollisionWithActorEvent(e,((e,i)=>t.id===i.id),!0)}onEndOverlapWithActor(e,t){return this._onCollisionWithActorEvent(e,((e,i)=>t.id===i.id),!1)}onCollisionWithActor(e,t){return this.onBeginOverlapWithActor(e,t)}onCollisionWithActorType(e,t){return this.onBeginOverlapWithActorType(e,t)}updateActorTransform(e){const t=this.actorBodies.get(e.id);null!=t?N(t,e.object):console.warn("Actor has not been added to physics world",e)}setupWorld(){const e=new i.World({x:0,y:-9.81,z:0});this.world=e}getActorContacts(e,t){const s=this.actorBodies.get(e.id);if(s&&s.numColliders()>0){const o=s.collider(0);let n=o.shape,r=o.translation(),a=o.rotation(),c=t,l=.3;const d=this.world.castShape(r,a,c,n,.1,l,!0,null,null,null,this.actorBodies.get(e.id),(e=>e.shape.type!=i.ShapeType.HeightField));if(null!=d){const e=new B,t=new B,i=new B;return Y(e,d.witness2),Y(t,d.witness1),Y(i,d.normal1),i.negate(),[{ri:e,rj:t,ni:i}]}return[]}return console.warn("Actor is not added to the physics system"),[]}stop(){this.world?.bodies.forEach((e=>this.world.removeRigidBody(e))),this.world?.free(),this.fixedupdateSub?.unsubscribe()}createStaticBody(e,t,s){const o=s?.type===PhysicsBodyType.dynamic?i.RigidBodyDesc.dynamic():i.RigidBodyDesc.fixed(),n=this.world.createRigidBody(o);for(const i of t){if(null==i){console.warn("Collision shape is missing for object",e);continue}const o=this.addShape(n,i,e);null!=s?.friction&&o.setFriction(s.friction),null!=s?.density&&o.setDensity(s.density),null!=s?.mass&&o.setMass(s.mass/t.length),null!=s?.restitution&&o.setRestitution(s.restitution)}return N(n,e),n.userData=e.uuid,n}addShape(e,t,i){const s=i.getWorldScale(te),o=this.createShape(t,s);null!=t.collisionGroup&&o.setCollisionGroups(t.collisionGroup),o.friction=.1;const n=t.offset.clone().multiply(s);K(o.translation,n);const r=(new w).setFromEuler(t.rotation);var a,c;t instanceof M&&t.mesh instanceof d.Mesh&&r.multiply(t.mesh.getWorldQuaternion(O)),a=o.rotation,c=r,a.x=c.x,a.y=c.y,a.z=c.z,a.w=c.w;return this.world.createCollider(o,e)}createShape(e,t){if(e instanceof C)return i.ColliderDesc.cuboid(e.dimensions.x*t.x/2,e.dimensions.y*t.y/2,e.dimensions.z*t.z/2);if(e instanceof D){return i.ColliderDesc.capsule(e.length/2*t.y,e.radius*Math.max(t.z,t.x))}if(e instanceof W){const s=null!=e.geometry.getIndex()?e.geometry:I.mergeVertices(e.geometry),o=new Float32Array(s.getAttribute("position").array);for(let e=0;e<o.length;e+=3)o[e]*=t.x,o[e+1]*=t.y,o[e+2]*=t.z;return i.ColliderDesc.trimesh(o,new Uint32Array(s.getIndex().array))}if(e instanceof M){let s;e.mesh instanceof d.Mesh?s=e.mesh.geometry:e.mesh instanceof d.BufferGeometry?s=e.mesh:console.log("Unknownd shape",{shapeInfo:e});const o=new Float32Array(s.getAttribute("position").array);if(e.mesh instanceof d.Mesh){const t=j(e.mesh);for(let e=0;e<o.length;e+=3)o[e]*=t.x,o[e+1]*=t.y,o[e+2]*=t.z}for(let e=0;e<o.length;e+=3)o[e]*=t.x,o[e+1]*=t.y,o[e+2]*=t.z;const n=o;return i.ColliderDesc.convexHull(n)}if(e instanceof E){const s=2*t.x-t.y-t.z;return Math.abs(s)>.01?this.createShape(new M(new d.SphereGeometry(e.radius).scale(t.x,t.y,t.z)),new B(1,1,1)):i.ColliderDesc.ball(e.radius*Math.max(t.x,t.y,t.z))}return e instanceof R?i.ColliderDesc.cylinder(e.height/2*t.y,e.radiusTop*Math.max(t.z,t.x)):e instanceof z?i.ColliderDesc.cone(e.height*t.y,e.radiusBottom/2*Math.max(t.z,t.x)):e instanceof T?i.ColliderDesc.cuboid(e.width/2*t.x,e.height/2*t.y,.001):(console.error("Unsupported shape",e),i.ColliderDesc.cuboid(1,1,1))}createCharacterCollision(){return new i.CharacterCollision}};P=e([b(),t("design:paramtypes",[V,_])],P);export{P as PhysicsSystem};const k=new B,O=new d.Quaternion;function N(e,t){const s=t.getWorldPosition(k),o=t.getWorldQuaternion(O);e.setTranslation(new i.Vector3(s.x,s.y,s.z),!1),e.setRotation(new i.Quaternion(o.x,o.y,o.z,o.w),!1)}const G=new B,q=new i.Vector3(0,0,0),Q=new i.Vector3(0,0,0),U=new B,H=new d.Vector2,X=async()=>{let e=await import("@dimforge/rapier3d-compat");return await e.init(),e};function K(e,t){e.x=t.x,e.y=t.y,e.z=t.z}function Y(e,t){e.x=t.x,e.y=t.y,e.z=t.z}function Z(e,t){for(let i=0,s=e.numColliders();i<s;i++){t(e.collider(i))}}const J=new B,$=new B,ee=e=>!e.isSensor(),te=new B;const ie=new i.Ray(new i.Vector3(0,0,0),new i.Vector3(0,1,0));/*
|
1
|
+
import{__decorate as t,__metadata as e}from"tslib";import*as i from"@dimforge/rapier3d-compat";import{QueryFilterFlags as s}from"@dimforge/rapier3d-compat";import{BehaviorSubject as o,distinctUntilChanged as n,filter as r,map as a,Subject as c,takeUntil as l}from"rxjs";import*as d from"three";import{ArrowHelper as h,BufferAttribute as u,BufferGeometry as y,Group as p,LineSegments as g,Matrix4 as m,Object3D as f,Quaternion as w,Raycaster as v,Scene as x,Vector3 as b}from"three";import{Service as B}from"typedi";import{AssetMeshInstance as A}from"../../../scene/asset-resource-loader.js";import{BoxCollisionShape as C,CapsuleCollisionShape as D,ConeCollisionShape as M,ConvexPolyhedronCollisionShape as z,CylinderCollisionShape as R,PhysicalShapeMesh as S,PlaneCollisionShape as T,SphereCollisionShape as E,TrimeshCollisionShape as W}from"../../../index.js";import{LandscapeGroup as j}from"../../../scene/landscape/landscape.js";import{ViewController as F}from"../render.js";import{World as V}from"../world.js";import*as _ from"three/examples/jsm/utils/BufferGeometryUtils.js";import{calculateEffectiveScale as P}from"../../../utils/three/traverse.js";import{AbstractPhysicsSystem as I}from"./abstract-physics-system.js";import{ActorComponent as L,Component as k}from"../../../gameplay/actors/component.js";import{inject as O}from"../../../gameplay/inject.js";export{Component,ActorComponent,attach,Attach}from"../../actors/component.js";export class RayTestResult{constructor(){this.hasHit=!1,this.hitPoint=new b,this.hitNormal=new b}}export var PhysicsBodyType;!function(t){t[t.dynamic=1]="dynamic",t[t.static=2]="static",t[t.kinematic=4]="kinematic",t[t.kinematicVelocityBased=8]="kinematicVelocityBased"}(PhysicsBodyType||(PhysicsBodyType={}));let N=class extends I{set showDebug(t){this.shouldRenderDebug=t,this.debugMesh&&(this.debugMesh.visible=t)}get showDebug(){return this.shouldRenderDebug}constructor(t,e){super(),this.viewController=t,this.gameWorld=e,this.staticMeshes=new Map,this.staticBodies=new Map,this.actorBodies=new Map,this.bodyActors=new Map,this.collisionEvents=new c,this.beforeStep=new c,this.afterStep=new c,this.shouldRenderDebug=!1,this._raycaster=new v,this._reusableResult=new RayTestResult,this._raytestDiff=new b,this._raytestDirection=new b,this.controlledActors=new Set,this.ready=this.setup()}createDebugMesh(){return new g(new y,new d.LineBasicMaterial({color:255}))}async start(){return await this.ready,this.handleTick(),this.ready}renderDebug(){null==this.debugMesh&&(this.debugMesh=this.createDebugMesh(),this.debugMesh.visible=this.shouldRenderDebug,this.debugMesh.raycast=function(){},this.gameWorld.scene.add(this.debugMesh));const t=this.world.debugRender();this.debugMesh.geometry.setAttribute("position",new u(t.vertices,3))}async setup(){if(null!=this.rapier)throw new Error("Rapier is already estup");this.rapier=await Z(),this.eventQueue=new i.EventQueue(!0),this.setupWorld()}handleTick(){this.fixedupdateSub=this.viewController.onUpdate().subscribe((t=>{t=Math.min(.1,t),this.beforeStep.next(t),this.updatePhysics(t),this.showDebug&&this.renderDebug(),this.world.bodies.forEach((t=>{if(t.isFixed())return;const e=this.staticMeshes.get(t)??this.bodyActors.get(t)?.object;var i,s;null!=e&&(e.parent instanceof x&&($(e.position,t.translation()),(t.isDynamic()||t.isKinematic()&&!this.controlledActors.has(this.bodyActors.get(t)?.id))&&(i=e.quaternion,s=t.rotation(),i.x=s.x,i.y=s.y,i.z=s.z,i.w=s.w),e.updateMatrix(),e.updateWorldMatrix(!1,!1)))})),this.afterStep.next(t)}))}_updateWorld(){this.world.timestep=0,this.world.step()}updatePhysics(t){this.world.timestep=t,this.world.step(this.eventQueue),this.eventQueue.drainCollisionEvents(((t,e,i)=>{this.collisionEvents.next({handle1:t,handle2:e,started:i}),this.collisionEvents.next({handle1:e,handle2:t,started:i})}))}rayTestFromCamera(t,e,i){this._raycaster.setFromCamera(Y,this.viewController.getCamera());const s=this._raycaster.ray.origin,o=this._raycaster.ray.direction.multiplyScalar(t).add(s);return this.rayTest(s,o,e,i)}rayTest(t,e,i,s){null==i&&(i=this._reusableResult);const o=this._raytestDiff,n=this._raytestDirection;if(o.subVectors(e,t),n.copy(o).normalize(),0===n.length())return console.warn("Ray test called with to and from being equal"),i;J(nt.origin,t),J(nt.dir,n);const r=o.length(),a=this.world.castRayAndGetNormal(nt,r,!1,void 0,void 0,void 0,null!=s?.excludeActor?this.actorBodies.get(s.excludeActor.id):void 0,s?.excludeTriggers?t=>!t.isSensor():void 0);if(i.hasHit=null!=a,i.hasHit){const e=nt.pointAt(a.timeOfImpact);i._internal=a,$(i.hitNormal,a.normal),$(i.hitPoint,e),i.distance=et.subVectors(i.hitPoint,t).length();const s=this.world.bodies.getAll().find((t=>function(t,e){for(let i=0,s=t.numColliders();i<s;i++){const s=t.collider(i);if(e(s))return s}}(t,(t=>t===a.collider))));i.actor=null!=s?this.bodyActors.get(s):null}if(this.showDebug){const e=new h(n,t,r,s?.debugColor??255);this.gameWorld.scene.add(e),setTimeout((()=>this.gameWorld.scene.remove(e)),s?.debugLifetime??200)}return i}setGravity(t,e,i){this.world.gravity.x=t,this.world.gravity.y=e,this.world.gravity.z=i}getGravity(){return U.set(this.world.gravity.x,this.world.gravity.y,this.world.gravity.z)}addFromScene(t){this.addRecursively(t);for(const t of this.staticBodies.values())tt(t,(t=>t.setActiveEvents(i.ActiveEvents.COLLISION_EVENTS)))}addRecursively(t){if(this.removeSceneObject(t),!function(t){if(null!=t.userData?.src){const e=t.userData?.src;return"actor"===e.type}return!1}(t))if(t instanceof S&&null!=t.collisionShape){const e=this.createStaticBody(t,[t.collisionShape],t.physics);this.staticMeshes.set(e,t),this.staticBodies.set(t,e)}else if(t instanceof A&&!1!==t.userData?.src?.collisionDetection)if(t.children[0]&&t.children[0].instanceMatrix)this.createForInstancedMesh(t.children[0],t.collisionShapes);else{const e=this.createStaticBody(t,t.collisionShapes,t.physics);this.staticMeshes.set(e,t),this.staticBodies.set(t,e)}else t instanceof j?this.addLandscapeGroup(t):(t instanceof p||t instanceof x)&&t.children.forEach((t=>this.addRecursively(t)))}createForInstancedMesh(t,e){const i=new m;for(let s=0;s<t.count;s++){const o=new f;o.matrix.identity(),i.fromArray(t.instanceMatrix.array,16*s),o.applyMatrix4(i);this.createStaticBody(o,e)}}getCharacterController(t){return this.world?.createCharacterController(t)}getActorComputedMovement(t,e,i,o=null){const n=this.actorBodies.get(t.id);this.controlledActors.add(t.id);const r=n.collider(0);e.computeColliderMovement(r,i,s.EXCLUDE_SENSORS,o,st);const a=e.computedMovement();return $(it,a),it}setNextKinematicTranslation(t,e){const i=this.actorBodies.get(t.id),s=i.translation();s.x+=e.x,s.y+=e.y,s.z+=e.z,i?.setNextKinematicTranslation(s)}setAngularVelocity(t,e){const i=this.actorBodies.get(t.id);H.x=e.x,H.y=e.y,H.z=e.z,i?.setAngvel(H,!0)}setLinearVelocity(t,e){const i=this.actorBodies.get(t.id);H.x=e.x,H.y=e.y,H.z=e.z,i?.setLinvel(H,!0)}getLinearVelocity(t,e=new b){const i=this.actorBodies.get(t.id).linvel();return e.x=i.x,e.y=i.y,e.z=i.z,e}getAngularVelocity(t,e=new b){const i=this.actorBodies.get(t.id).angvel();return e.x=i.x,e.y=i.y,e.z=i.z,e}setLinearDamping(t,e){const i=this.actorBodies.get(t.id);i?.setLinearDamping(e)}setAngularDamping(t,e){const i=this.actorBodies.get(t.id);i?.setAngularDamping(e)}addLandscapeGroup(t){const e=t.userData.src,s=e.landscape.heightMaps;for(const n of t.sections){this.staticBodies.has(n)&&this.world.removeRigidBody(this.staticBodies.get(n));var o=n.getWorldPosition(new b);if(e.landscape.holes&&e.landscape.holes.some((t=>t.m===n.name&&0!==t.w[0]))){const t=n.geometry.clone(),s=n.scale,r=n.geometry.getAttribute("hole"),a=new Float32Array(t.getAttribute("position").array);for(let t=0;t<a.length;t+=3)a[t]*=s.x,a[t+1]*=s.y,a[t+2]*=s.z;const c=t.index;for(let t=0;t<c.count;t+=3){const e=r.getX(c.getX(t)),i=r.getX(c.getY(t)),s=r.getX(c.getZ(t));(e>.5||i>.5||s>.5)&&(c.setX(t,0),c.setY(t,0),c.setZ(t,0))}const l=i.ColliderDesc.trimesh(a,new Uint32Array(t.getIndex().array));if(!1!==e.collisionDetection){const t=this.world.createRigidBody(i.RigidBodyDesc.fixed()),e=new i.Vector3(0,0,0);J(e,o),t.setTranslation(e,!1),this.world.createCollider(l,t),this.staticBodies.set(n,t)}continue}const t=e.landscape.options.density+1,r=e.landscape.options.sectionSize,a=new Array(t);for(let e=0;e<t;e++)a[e]=new Array(t).fill(0);const c=s.find((t=>t.x===n.x&&t.y==n.y));if(null!=c)for(const e of c.points){if(null==a[e.i%t])continue;const i=t-1-Math.floor(e.i/t);i in a[e.i%t]?a[e.i%t][i]=e.y/r:console.warn("wrong index",{points:a,point:e,i:e.i%t,k:i,heightMap:c})}const l=e.landscape.options.density,d=a.flatMap((t=>t.reverse())),h=i.ColliderDesc.heightfield(l,l,new Float32Array(d),new i.Vector3(r,r,r));if(!1!==e.collisionDetection){const t=this.world.createRigidBody(i.RigidBodyDesc.fixed()),e=new i.Vector3(0,0,0);J(e,o),t.setTranslation(e,!1),this.world.createCollider(h,t),this.staticBodies.set(n,t)}}}setEnabled(t,e){const i=this.actorBodies.get(t.id);i?.setEnabled(e)}addActor(t,e,s={}){if(0==e.length)return void console.error("No collision shapes were defined when adding actor to the physics system.");this.removeActor(t);const o=t.object;let n;switch(s.type??PhysicsBodyType.static){case PhysicsBodyType.dynamic:n=i.RigidBodyDesc.dynamic(),n.mass=s.mass??1;break;case PhysicsBodyType.kinematic:n=i.RigidBodyDesc.kinematicPositionBased();break;case PhysicsBodyType.kinematicVelocityBased:n=i.RigidBodyDesc.kinematicVelocityBased();break;default:n=s.isTrigger?i.RigidBodyDesc.kinematicVelocityBased():i.RigidBodyDesc.fixed()}const r=this.world.createRigidBody(n);r.enableCcd(1==s.continousCollisionDetection);for(const t of e)this.addShape(r,t,o);tt(r,(t=>{null!=s.isTrigger&&(t.setSensor(s.isTrigger),t.setActiveCollisionTypes(i.ActiveCollisionTypes.ALL),t.setActiveEvents(i.ActiveEvents.COLLISION_EVENTS)),null!=s.friction&&t.setFriction(s.friction),null!=s.density&&t.setDensity(s.density),null!=s.mass&&t.setMass(s.mass),null!=s.restitution&&t.setRestitution(s.restitution)})),Q(r,o),!0===s.ignoreForNavMesh&&(r.userData={ignoreForNavMesh:!0}),this.actorBodies.set(t.id,r),this.bodyActors.set(r,t)}applyTorque(t,e){const i=this.actorBodies.get(t.id);H.x=e.x,H.y=e.y,H.z=e.z,i?.addTorque(H,!0)}applyTorqueImpulse(t,e){const i=this.actorBodies.get(t.id);H.x=e.x,H.y=e.y,H.z=e.z,i?.applyTorqueImpulse(H,!0)}resetForces(t){const e=this.actorBodies.get(t.id);e?.resetForces(!1)}resetTorques(t){const e=this.actorBodies.get(t.id);e?.resetTorques(!1)}applyForce(t,e){const i=this.actorBodies.get(t.id);H.x=e.x,H.y=e.y,H.z=e.z,i?.addForce(H,!0)}applyImpulse(t,e){const i=this.actorBodies.get(t.id);H.x=e.x,H.y=e.y,H.z=e.z,i?.applyImpulse(H,!0)}applyLocalForce(t,e,i){const s=this.actorBodies.get(t.id);J(H,e),null==i?s?.addForce(H,!0):(J(X,i),s?.addForceAtPoint(H,X,!0))}applyLocalImpulse(t,e,i){const s=this.actorBodies.get(t.id);J(H,e),null==i?s.applyImpulse(H,!0):(J(X,i),s.applyImpulseAtPoint(H,X,!0))}applyRadiusImpulse(t,e,s){this.world.bodies.forEach((o=>{if(o.collider(0)?.isSensor())return;if(o.bodyType()!==i.RigidBodyType.Dynamic)return;const n=K;$(n,o.translation());const r=n.clone().sub(t);if(r.length()>e)return;const a=r.clone().normalize().multiplyScalar(s);H.x=a.x,H.y=a.y,H.z=a.z,o.applyImpulse(H,!0)}))}removeActor(t){if(null==t)return;this.controlledActors.delete(t.id);const e=this.actorBodies.get(t.id);null!=e&&(this.bodyActors.delete(e),this.world.removeRigidBody(e)),this.actorBodies.delete(t.id)}removeRemoved(t){const e=new Set;t.traverse((t=>{e.add(t.uuid)}));for(const[t,i]of this.staticBodies.entries())!e.has(t.uuid)&&this.world.getRigidBody(i.handle)&&(this.staticBodies.delete(t),this.world.removeRigidBody(i))}removeSceneObject(t){if(t instanceof j){for(const e of t.sections)this.removeSceneObject(e);return}let e=this.staticBodies.get(t);null!=e&&this.world.getRigidBody(e.handle)&&this.world.removeRigidBody(e),this.staticBodies.delete(t)}activateActorEvents(t){this.actorBodies.get(t.id)}_onCollisionWithActorEvent(t,e,i){return this.activateActorEvents(t),this.collisionEvents.pipe(l(t.disposed),r((({started:t})=>t===i)),a((({handle1:t,handle2:e,started:i})=>({a1:this.bodyActors.get(this.world.getCollider(t)?.parent()),a2:this.bodyActors.get(this.world.getCollider(e)?.parent()),started:i}))),r((({a1:i,a2:s})=>null!=i&&null!=s&&i.id===t.id&&e(i,s))),a((({a2:t})=>t)))}onBeginContact(t){return this.activateActorEvents(t),this.collisionEvents.pipe(l(t.disposed),r((t=>t.started)),r((({handle1:e})=>{const i=this.bodyActors.get(this.world.getCollider(e)?.parent());return null!=i&&i.id===t.id})),a((t=>t.handle2)))}onEndContact(t){return this.activateActorEvents(t),this.collisionEvents.pipe(l(t.disposed),r((t=>!t.started)),r((({handle1:e})=>{const i=this.bodyActors.get(this.world.getCollider(e)?.parent());return null!=i&&i.id===t.id})),a((t=>t.handle2)))}onHasContactChanged(t){const e=new Set,i=new o(!1);return this.onBeginContact(t).subscribe((t=>{e.add(t),i.next(e.size>0)})),this.onEndContact(t).subscribe((t=>{e.delete(t),i.next(e.size>0)})),i.pipe(n())}onBeginOverlapWithActorType(t,e){return this._onCollisionWithActorEvent(t,((t,i)=>i instanceof e),!0)}onEndOverlapWithActorType(t,e){return this._onCollisionWithActorEvent(t,((t,i)=>i instanceof e),!1)}onBeginOverlapWithActor(t,e){return this._onCollisionWithActorEvent(t,((t,i)=>e.id===i.id),!0)}onEndOverlapWithActor(t,e){return this._onCollisionWithActorEvent(t,((t,i)=>e.id===i.id),!1)}onCollisionWithActor(t,e){return this.onBeginOverlapWithActor(t,e)}onCollisionWithActorType(t,e){return this.onBeginOverlapWithActorType(t,e)}updateActorTransform(t){const e=this.actorBodies.get(t.id);null!=e?Q(e,t.object):console.warn("Actor has not been added to physics world",t)}setupWorld(){const t=new i.World({x:0,y:-9.81,z:0});this.world=t}getActorContacts(t,e){const s=this.actorBodies.get(t.id);if(s&&s.numColliders()>0){const o=s.collider(0);let n=o.shape,r=o.translation(),a=o.rotation(),c=e,l=.3;const d=this.world.castShape(r,a,c,n,.1,l,!0,null,null,null,this.actorBodies.get(t.id),(t=>t.shape.type!=i.ShapeType.HeightField));if(null!=d){const t=new b,e=new b,i=new b;return $(t,d.witness2),$(e,d.witness1),$(i,d.normal1),i.negate(),[{ri:t,rj:e,ni:i}]}return[]}return console.warn("Actor is not added to the physics system"),[]}stop(){this.world?.bodies.forEach((t=>this.world.removeRigidBody(t))),this.world?.free(),this.fixedupdateSub?.unsubscribe()}createStaticBody(t,e,s){const o=s?.type===PhysicsBodyType.dynamic?i.RigidBodyDesc.dynamic():i.RigidBodyDesc.fixed(),n=this.world.createRigidBody(o);for(const i of e){if(null==i){console.warn("Collision shape is missing for object",t);continue}const o=this.addShape(n,i,t);null!=s?.friction&&o.setFriction(s.friction),null!=s?.density&&o.setDensity(s.density),null!=s?.mass&&o.setMass(s.mass/e.length),null!=s?.restitution&&o.setRestitution(s.restitution)}return Q(n,t),n.userData=t.uuid,n}addShape(t,e,s){const o=s.getWorldScale(ot),n=this.createShape(e,o);null!=e.collisionGroup&&n.setCollisionGroups(e.collisionGroup),n.friction=e.friction??.1,null!=e.restitution&&(n.restitution=e.restitution),null!=e.density&&(n.density=e.density,n.massPropsMode=i.MassPropsMode.Density),null!=e.mass&&(n.mass=e.mass,n.massPropsMode=i.MassPropsMode.Mass);const r=e.offset.clone().multiply(o);J(n.translation,r);const a=(new w).setFromEuler(e.rotation);var c,l;e instanceof z&&e.mesh instanceof d.Mesh&&a.multiply(e.mesh.getWorldQuaternion(q)),c=n.rotation,l=a,c.x=l.x,c.y=l.y,c.z=l.z,c.w=l.w;return this.world.createCollider(n,t)}createShape(t,e){if(t instanceof C)return i.ColliderDesc.cuboid(t.dimensions.x*e.x/2,t.dimensions.y*e.y/2,t.dimensions.z*e.z/2);if(t instanceof D){return i.ColliderDesc.capsule(t.length/2*e.y,t.radius*Math.max(e.z,e.x))}if(t instanceof W){const s=null!=t.geometry.getIndex()?t.geometry:_.mergeVertices(t.geometry),o=new Float32Array(s.getAttribute("position").array);for(let t=0;t<o.length;t+=3)o[t]*=e.x,o[t+1]*=e.y,o[t+2]*=e.z;return i.ColliderDesc.trimesh(o,new Uint32Array(s.getIndex().array))}if(t instanceof z){let s;t.mesh instanceof d.Mesh?s=t.mesh.geometry:t.mesh instanceof d.BufferGeometry?s=t.mesh:console.log("Unknownd shape",{shapeInfo:t});const o=new Float32Array(s.getAttribute("position").array);if(t.mesh instanceof d.Mesh){const e=P(t.mesh);for(let t=0;t<o.length;t+=3)o[t]*=e.x,o[t+1]*=e.y,o[t+2]*=e.z}for(let t=0;t<o.length;t+=3)o[t]*=e.x,o[t+1]*=e.y,o[t+2]*=e.z;const n=o;return i.ColliderDesc.convexHull(n)}if(t instanceof E){const s=2*e.x-e.y-e.z;return Math.abs(s)>.01?this.createShape(new z(new d.SphereGeometry(t.radius).scale(e.x,e.y,e.z)),new b(1,1,1)):i.ColliderDesc.ball(t.radius*Math.max(e.x,e.y,e.z))}return t instanceof R?i.ColliderDesc.cylinder(t.height/2*e.y,t.radiusTop*Math.max(e.z,e.x)):t instanceof M?i.ColliderDesc.cone(t.height*e.y,t.radiusBottom/2*Math.max(e.z,e.x)):t instanceof T?i.ColliderDesc.cuboid(t.width/2*e.x,t.height/2*e.y,.001):(console.error("Unsupported shape",t),i.ColliderDesc.cuboid(1,1,1))}createCharacterCollision(){return new i.CharacterCollision}};N=t([B(),e("design:paramtypes",[F,V])],N);export{N as PhysicsSystem};const G=new b,q=new d.Quaternion;function Q(t,e){const s=e.getWorldPosition(G),o=e.getWorldQuaternion(q);t.setTranslation(new i.Vector3(s.x,s.y,s.z),!1),t.setRotation(new i.Quaternion(o.x,o.y,o.z,o.w),!1)}const U=new b,H=new i.Vector3(0,0,0),X=new i.Vector3(0,0,0),K=new b,Y=new d.Vector2,Z=async()=>{let t=await import("@dimforge/rapier3d-compat");return await t.init(),t};function J(t,e){t.x=e.x,t.y=e.y,t.z=e.z}function $(t,e){t.x=e.x,t.y=e.y,t.z=e.z}function tt(t,e){for(let i=0,s=t.numColliders();i<s;i++){e(t.collider(i))}}const et=new b,it=new b,st=t=>!t.isSensor(),ot=new b;const nt=new i.Ray(new i.Vector3(0,0,0),new i.Vector3(0,1,0));let rt=class extends L{constructor(){super(...arguments),this._active=!0,this.physics=O(N),this.world=O(V)}set active(t){this._active=t,t?(this.world.scene.remove(this.actor.object),this.physics.setEnabled(this.actor,t)):(this.world.scene.add(this.actor.object),this.physics.setEnabled(this.actor,t))}get active(){return this._active}};rt=t([k()],rt);/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"shader-provider.d.ts","sourceRoot":"","sources":["../../../src/gameplay/services/shader-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAK1C,qBACa,cAAc;IAGhB,OAAO,EAAE,UAAU,EAAE;gBAArB,OAAO,GAAE,UAAU,EAAO;IAGnC,GAAG,CAAC,IAAI,EAAE,MAAM;CAGjB"}
|