@hology/core 0.0.27 → 0.0.29

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. package/dist/effects/vfx/behaviours.d.ts +26 -0
  2. package/dist/effects/vfx/behaviours.js +5 -0
  3. package/dist/effects/vfx/index.d.ts +2 -0
  4. package/dist/effects/vfx/index.js +5 -0
  5. package/dist/effects/vfx/initializsers.d.ts +34 -0
  6. package/dist/effects/vfx/initializsers.js +5 -0
  7. package/dist/effects/vfx/rates.d.ts +6 -0
  8. package/dist/effects/vfx/rates.js +5 -0
  9. package/dist/effects/vfx/vfx-actor.d.ts +26 -0
  10. package/dist/effects/vfx/vfx-actor.js +5 -0
  11. package/dist/effects/vfx/vfx-asset.d.ts +90 -0
  12. package/dist/effects/vfx/vfx-asset.js +5 -0
  13. package/dist/effects/vfx/vfx-defs.d.ts +169 -0
  14. package/dist/effects/vfx/vfx-defs.js +5 -0
  15. package/dist/effects/vfx/vfx-materializer.d.ts +19 -0
  16. package/dist/effects/vfx/vfx-materializer.js +5 -0
  17. package/dist/gameplay/actors/builtin/components/character/character-movement.d.ts +5 -1
  18. package/dist/gameplay/actors/builtin/components/character/character-movement.js +1 -1
  19. package/dist/gameplay/actors/camera/third-party-camera-component.js +1 -1
  20. package/dist/gameplay/initiate.d.ts +3 -0
  21. package/dist/gameplay/initiate.js +1 -1
  22. package/dist/gameplay/input/input-service.d.ts +4 -0
  23. package/dist/gameplay/input/input-service.js +1 -1
  24. package/dist/gameplay/polyfill.d.ts +1 -0
  25. package/dist/gameplay/polyfill.js +5 -0
  26. package/dist/gameplay/services/asset-loader.d.ts +9 -4
  27. package/dist/gameplay/services/asset-loader.js +1 -1
  28. package/dist/gameplay/services/render.d.ts +3 -2
  29. package/dist/rendering.d.ts +1 -0
  30. package/dist/rendering.js +1 -1
  31. package/dist/scene/materializer.d.ts +18 -3
  32. package/dist/scene/materializer.js +1 -1
  33. package/dist/scene/model.d.ts +6 -1
  34. package/dist/scene/objects/shapes.d.ts +4 -2
  35. package/dist/scene/scene-data-service.js +1 -1
  36. package/dist/scene/sky.d.ts +3 -0
  37. package/dist/scene/sky.js +1 -1
  38. package/dist/shader-nodes/effects.d.ts +8 -0
  39. package/dist/shader-nodes/effects.js +5 -0
  40. package/dist/shader-nodes/glsl-node.d.ts +16 -0
  41. package/dist/shader-nodes/glsl-node.js +5 -0
  42. package/dist/shader-nodes/index.d.ts +3 -0
  43. package/dist/shader-nodes/index.js +1 -1
  44. package/dist/shader-nodes/shapes.d.ts +3 -0
  45. package/dist/shader-nodes/shapes.js +5 -0
  46. package/dist/shader-nodes/voronoi.d.ts +5 -0
  47. package/dist/shader-nodes/voronoi.js +5 -0
  48. package/dist/utils/math.js +1 -1
  49. package/package.json +3 -2
  50. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,26 @@
1
+ import { Behaviour, Emitter, Particle, EasingFunction } from "three-nebula";
2
+ /**
3
+ * Rotate position around an axis.
4
+ */
5
+ export declare class RotatePosition extends Behaviour {
6
+ private axis;
7
+ private angle;
8
+ constructor(axis: THREE.Vector3, angle: number);
9
+ private axis3D;
10
+ mutate(target: Particle | Emitter, time: number, index: number): void;
11
+ }
12
+ export declare class LinearDamping extends Behaviour {
13
+ private factor;
14
+ constructor(factor: number);
15
+ mutate(target: Particle | Emitter, time: number, index: number): void;
16
+ }
17
+ export declare class MoveOverLife extends Behaviour {
18
+ private x;
19
+ private y;
20
+ private z;
21
+ private displacement;
22
+ private initial;
23
+ constructor(x: number, y: number, z: number, easing?: EasingFunction);
24
+ initialize(particle: Particle): void;
25
+ mutate(target: Particle | Emitter, time: number, index: number): void;
26
+ }
@@ -0,0 +1,5 @@
1
+ import{Behaviour as i,Vector3D as t,ease as s}from"three-nebula";export class RotatePosition extends i{constructor(i,s){super(),this.axis=i,this.angle=s,this.axis3D=new t(this.axis.x,this.axis.y,this.axis.z)}mutate(i,t,s){this.energize(i,t),i.position.sub(i.parent.position),i.position.applyAxisAngle(this.axis3D,this.angle*t),i.position.add(i.parent.position)}}export class LinearDamping extends i{constructor(i){super(),this.factor=i}mutate(i,t,s){this.energize(i,t);const o=e.copy(i.velocity).multiplyScalar(-this.factor*t);i.velocity.add(o)}}const e=new t;export class MoveOverLife extends i{constructor(i,t,e,o=s.easeLinear){super(void 0,o,void 0,!0),this.x=i,this.y=t,this.z=e}initialize(i){i.transform.initialPos=i.position.clone()}mutate(i,t,s){this.energize(i,t);const e=i.transform.initialPos,o=1-this.energy;i.position.x=e.x+this.x*o,i.position.y=e.y+this.y*o,i.position.z=e.z+this.z*o}}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,2 @@
1
+ export * from './vfx-asset';
2
+ export * from './vfx-materializer';
@@ -0,0 +1,5 @@
1
+ export*from"./vfx-asset";export*from"./vfx-materializer";
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,34 @@
1
+ import { Vector3 } from "three";
2
+ import Initializer, { Emitter, Particle } from "three-nebula";
3
+ export declare class Rotation extends Initializer {
4
+ private rotation;
5
+ constructor(rotation: Vector3);
6
+ init(emitter: Emitter, particle: Particle): void;
7
+ }
8
+ export declare class RandomDirection extends Initializer {
9
+ private speed;
10
+ constructor(speed: number);
11
+ init(emitter: Emitter, particle: Particle): void;
12
+ }
13
+ /**
14
+ * Restrict randomness with two vectors
15
+ */
16
+ export declare class RandomComponentsDirection extends Initializer {
17
+ private speed;
18
+ private min;
19
+ private max;
20
+ private x;
21
+ private y;
22
+ private z;
23
+ constructor(speed: number, min: Vector3, max: Vector3);
24
+ init(emitter: Emitter, particle: Particle): void;
25
+ }
26
+ export declare class RandomVelocity extends Initializer {
27
+ private min;
28
+ private max;
29
+ private x;
30
+ private y;
31
+ private z;
32
+ constructor(min: Vector3, max: Vector3);
33
+ init(emitter: Emitter, particle: Particle): void;
34
+ }
@@ -0,0 +1,5 @@
1
+ import{Vector3 as t}from"three";import i,{Span as e}from"three-nebula";export class Rotation extends i{constructor(t){super(),this.rotation=t}init(t,i){"number"!=typeof i.rotation&&i.rotation.copy(this.rotation)}}export class RandomDirection extends i{constructor(t){super(),this.speed=t}init(t,i){s.set(2*Math.random()-1,2*Math.random()-1,2*Math.random()-1).normalize().multiplyScalar(this.speed),i.velocity.x+=s.x,i.velocity.y+=s.y,i.velocity.z+=s.z}}export class RandomComponentsDirection extends i{constructor(t,i,s){super(),this.speed=t,this.min=i,this.max=s,this.x=new e(this.min.x,this.max.x),this.y=new e(this.min.y,this.max.y),this.z=new e(this.min.z,this.max.z)}init(t,i){s.set(this.x.getValue(),this.y.getValue(),this.z.getValue()).normalize().multiplyScalar(this.speed),i.velocity.x+=s.x,i.velocity.y+=s.y,i.velocity.z+=s.z}}export class RandomVelocity extends i{constructor(t,i){super(),this.min=t,this.max=i,this.x=new e(this.min.x,this.max.x),this.y=new e(this.min.y,this.max.y),this.z=new e(this.min.z,this.max.z)}init(t,i){i.velocity.x+=this.x.getValue(),i.velocity.y+=this.y.getValue(),i.velocity.z+=this.z.getValue()}}const s=new t;
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,6 @@
1
+ import { Rate } from "three-nebula";
2
+ export { Rate } from 'three-nebula';
3
+ export declare class OnceRate extends Rate {
4
+ constructor(count?: number);
5
+ restart(): void;
6
+ }
@@ -0,0 +1,5 @@
1
+ import{Rate as e}from"three-nebula";export{Rate}from"three-nebula";export class OnceRate extends e{constructor(e=1){super(e,1/0)}restart(){this.nextTime=0}}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,26 @@
1
+ import { BaseActor } from "../../gameplay";
2
+ import { VfxAsset } from "../../scene/model";
3
+ export declare class VfxActor extends BaseActor {
4
+ /**
5
+ * A multiplier for the speed of the visual effect.
6
+ */
7
+ timescale: number;
8
+ paused: boolean;
9
+ private system;
10
+ private disposeSystem;
11
+ private sourceAsset;
12
+ private assetLoader;
13
+ private world;
14
+ /**
15
+ * Replace visual effect with its definition in an asset
16
+ */
17
+ fromAsset(asset: VfxAsset): Promise<void>;
18
+ play(): void;
19
+ pause(): void;
20
+ stop(): void;
21
+ restart(): void;
22
+ private _worldPos;
23
+ private max;
24
+ onUpdate(deltaTime: number): void;
25
+ getParticleCount(): any;
26
+ }
@@ -0,0 +1,5 @@
1
+ import{__awaiter as t,__decorate as s}from"tslib";import{Actor as e,BaseActor as i,AssetLoader as o,inject as r,World as a}from"../../gameplay";import{Rate as m}from"three-nebula";import{OnceRate as h}from"./rates";import{materializeVfx as d}from"./vfx-materializer";import*as l from"three";let n=class extends i{constructor(){super(...arguments),this.timescale=1,this.paused=!1,this.assetLoader=r(o),this.world=r(a),this._worldPos=new l.Vector3,this.max=0}fromAsset(s){return t(this,void 0,void 0,(function*(){null!=this.system&&(this.system.destroy(),this.system.emitters.forEach((t=>t.reset()))),this.sourceAsset=s,this.disposeSystem&&this.disposeSystem();const{system:t,dispose:e}=yield d(s,this.object,{getMaterial:t=>this.assetLoader.getMaterialByAssetId(t),getTexture:t=>this.assetLoader.getTextureByAssetId(t),getMesh:t=>this.assetLoader.getModelByAssetId(t).then((t=>t.scene))});this.system=t,this.disposeSystem=e}))}play(){this.paused=!1;this.system.emitters.every((t=>t.dead))&&this.restart()}pause(){this.paused=!0}stop(){this.system.emitters.forEach((t=>{const s=t.rate;s instanceof m&&(console.log("set rate to infinity",s),s.nextTime=1/0)}))}restart(){for(const t of this.system.emitters){t.removeAllParticles();const s=t.rate;s.nextTime=0,s instanceof h&&s.restart()}}onUpdate(t){var s,e;this.paused||(this.object.getWorldPosition(this._worldPos),null===(s=this.system)||void 0===s||s.emitters.forEach((t=>{})),null===(e=this.system)||void 0===e||e.update(t*this.timescale))}getParticleCount(){var t,s;return null!==(s=null===(t=this.system)||void 0===t?void 0:t.getCount())&&void 0!==s?s:0}};n=s([e()],n);export{n as VfxActor};
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,90 @@
1
+ import { LibraryShapeType } from "../../scene/objects/shapes";
2
+ import { AssetId, CustomParamValue } from "../../scene/model";
3
+ import { LibraryVfxBehaviourType, LibraryVfxInitalizerType } from './vfx-defs';
4
+ import * as THREE from "three";
5
+ export type OnceRateData = {
6
+ type: 'once';
7
+ count: number;
8
+ };
9
+ export type ContinuousRateData = {
10
+ type: 'continuous';
11
+ count: number;
12
+ time: number;
13
+ };
14
+ export type RateData = OnceRateData | ContinuousRateData;
15
+ export type InitializerData = {
16
+ id: string;
17
+ type: LibraryVfxInitalizerType;
18
+ params: Record<string, CustomParamValue>;
19
+ };
20
+ export interface BehaviourData {
21
+ id: string;
22
+ type: LibraryVfxBehaviourType;
23
+ params: Record<string, CustomParamValue>;
24
+ }
25
+ export type Vector3Data = [number, number, number];
26
+ export declare const BlendingModes: readonly ["additive", "subtractive", "multiply", "normal"];
27
+ export type BlendingMode = (typeof BlendingModes)[number];
28
+ export declare const ThreeBlendingMode: {
29
+ normal: THREE.Blending;
30
+ additive: THREE.Blending;
31
+ subtractive: THREE.Blending;
32
+ multiply: THREE.Blending;
33
+ };
34
+ export type SpriteOutput = {
35
+ type: 'sprite';
36
+ texture: string;
37
+ color: string;
38
+ blendingMode: BlendingMode;
39
+ };
40
+ export type MeshOutput = {
41
+ type: 'mesh';
42
+ assetId: AssetId;
43
+ };
44
+ export type ShapeOutput = {
45
+ type: 'shape';
46
+ shape: LibraryShapeType;
47
+ params: Record<string, CustomParamValue>;
48
+ material: AssetId;
49
+ };
50
+ export type EmitterOutput = SpriteOutput | MeshOutput | ShapeOutput;
51
+ export type EmitterData = {
52
+ id: string;
53
+ name: string;
54
+ rate: RateData;
55
+ position: Vector3Data;
56
+ rotation: Vector3Data;
57
+ initializers: InitializerData[];
58
+ behaviours: BehaviourData[];
59
+ children?: EmitterData[];
60
+ output: EmitterOutput;
61
+ };
62
+ export type VfxAssetData = {
63
+ /**
64
+ * Whether particles position should be relative to local space as opposed to world space.
65
+ * It is usually not realistic that particles moves along with it's parent object but
66
+ * it can be useful for certain effects.
67
+ */
68
+ localSpace?: boolean;
69
+ emitters: EmitterData[];
70
+ };
71
+ export declare function EmitterDataConstructor(): {
72
+ id: string;
73
+ name: string;
74
+ rate: {
75
+ type: "continuous";
76
+ count: number;
77
+ time: number;
78
+ };
79
+ position: [number, number, number];
80
+ rotation: [number, number, number];
81
+ initializers: any[];
82
+ behaviours: any[];
83
+ children: any[];
84
+ output: {
85
+ type: "sprite";
86
+ texture: any;
87
+ color: string;
88
+ blendingMode: "normal";
89
+ };
90
+ };
@@ -0,0 +1,5 @@
1
+ import*as t from"three";import{randomString as i}from"../../utils/math";export const BlendingModes=["additive","subtractive","multiply","normal"];export const ThreeBlendingMode={normal:t.NormalBlending,additive:t.AdditiveBlending,subtractive:t.SubtractiveBlending,multiply:t.MultiplyBlending};export function EmitterDataConstructor(){return{id:i(),name:"Emitter",rate:{type:"continuous",count:1,time:.5},position:[0,0,0],rotation:[0,0,0],initializers:[],behaviours:[],children:[],output:{type:"sprite",texture:null,color:"#ffffff",blendingMode:"normal"}}}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,169 @@
1
+ import { Vector2, Vector3 } from "three";
2
+ import { Behaviour } from "three-nebula";
3
+ import Initializer from "three-nebula/src/initializer/Initializer";
4
+ type HexColor = `#${string}`;
5
+ export type ShapeParameterDef<T = boolean | number | string | Vector3 | Vector2 | HexColor> = {
6
+ type: T extends number ? 'number' : T extends HexColor ? 'color' : T extends string ? 'string' | 'select' : T extends Vector2 ? 'vec2' : T extends Vector3 ? 'vec3' : T extends boolean ? 'boolean' : never;
7
+ default: T;
8
+ };
9
+ type FloatParameterDef = ShapeParameterDef<number> & {
10
+ float: boolean;
11
+ min?: number;
12
+ max?: number;
13
+ };
14
+ export type SelectParameterDef<T> = ShapeParameterDef<T> & {
15
+ type: 'select';
16
+ opts: Readonly<T[]>;
17
+ };
18
+ interface InitializerDefinition {
19
+ build(params?: any): Initializer;
20
+ parameters?: Record<string, ShapeParameterDef>;
21
+ }
22
+ interface BehaviourDefinition {
23
+ build(params?: any): Behaviour;
24
+ parameters?: Record<string, ShapeParameterDef>;
25
+ }
26
+ declare abstract class BaseBevDef<T extends DefBuilder> implements BehaviourDefinition {
27
+ abstract parameters: any;
28
+ build(params?: ParamsType<T>): Behaviour;
29
+ abstract make(params: ParamsType<T>): Behaviour;
30
+ }
31
+ declare abstract class BaseIniDef<T extends DefBuilder> implements InitializerDefinition {
32
+ abstract parameters: any;
33
+ build(params?: ParamsType<T>): Initializer;
34
+ abstract make(params: ParamsType<T>): Initializer;
35
+ }
36
+ export type DefBuilder = {
37
+ parameters?: Record<string, ShapeParameterDef>;
38
+ };
39
+ type ParamsType<T extends DefBuilder> = Partial<{
40
+ [K in keyof T['parameters']]: T['parameters'][K]['default'];
41
+ }>;
42
+ declare class LifetimeDef extends BaseIniDef<LifetimeDef> {
43
+ parameters: {
44
+ duration: ShapeParameterDef<number>;
45
+ };
46
+ make(params?: ParamsType<this>): Initializer;
47
+ }
48
+ declare class VelocityDef extends BaseIniDef<VelocityDef> {
49
+ parameters: {
50
+ velocity: ShapeParameterDef<Vector3>;
51
+ };
52
+ make(params?: ParamsType<this>): Initializer;
53
+ }
54
+ declare class RandomDirectionDef extends BaseIniDef<RandomDirectionDef> {
55
+ parameters: {
56
+ speed: FloatParameterDef;
57
+ };
58
+ make(params?: ParamsType<this>): Initializer;
59
+ }
60
+ declare class MassDef extends BaseIniDef<MassDef> {
61
+ parameters: {
62
+ min: FloatParameterDef;
63
+ };
64
+ make(params?: ParamsType<this>): Initializer;
65
+ }
66
+ declare class RotationDef extends BaseIniDef<RotationDef> {
67
+ parameters: {
68
+ rotation: ShapeParameterDef<Vector3>;
69
+ };
70
+ make(params?: ParamsType<this>): Initializer;
71
+ }
72
+ declare class ForceDef extends BaseBevDef<ForceDef> {
73
+ parameters: {
74
+ force: ShapeParameterDef<Vector3>;
75
+ ease: SelectParameterDef<string>;
76
+ };
77
+ make(params?: ParamsType<this>): Behaviour;
78
+ }
79
+ declare class GravityDef extends BaseBevDef<GravityDef> {
80
+ parameters: {
81
+ gravity: FloatParameterDef;
82
+ };
83
+ make(params?: ParamsType<this>): Behaviour;
84
+ }
85
+ declare class ScaleDef extends BaseBevDef<ScaleDef> {
86
+ parameters: {
87
+ a: FloatParameterDef;
88
+ b: FloatParameterDef;
89
+ ease: SelectParameterDef<string>;
90
+ };
91
+ make(params?: ParamsType<this>): Behaviour;
92
+ }
93
+ declare class RandomDriftDef extends BaseBevDef<RandomDriftDef> {
94
+ parameters: {
95
+ drift: ShapeParameterDef<Vector3>;
96
+ delay: FloatParameterDef;
97
+ ease: SelectParameterDef<string>;
98
+ };
99
+ make(params?: ParamsType<this>): Behaviour;
100
+ }
101
+ declare class RotateDef extends BaseBevDef<RotateDef> {
102
+ parameters: {
103
+ rotation: ShapeParameterDef<Vector3>;
104
+ ease: SelectParameterDef<string>;
105
+ };
106
+ make(params?: ParamsType<this>): Behaviour;
107
+ }
108
+ declare class ChangeColorDef extends BaseBevDef<ChangeColorDef> {
109
+ parameters: {
110
+ a: ShapeParameterDef<`#${string}`>;
111
+ b: ShapeParameterDef<`#${string}`>;
112
+ ease: SelectParameterDef<string>;
113
+ };
114
+ make(params?: ParamsType<this>): Behaviour;
115
+ }
116
+ declare class ChangeOpacityDef extends BaseBevDef<ChangeOpacityDef> {
117
+ parameters: {
118
+ a: FloatParameterDef;
119
+ b: FloatParameterDef;
120
+ ease: SelectParameterDef<string>;
121
+ };
122
+ make(params?: ParamsType<this>): Behaviour;
123
+ }
124
+ declare class VortexDef extends BaseBevDef<VortexDef> {
125
+ parameters: {
126
+ axis: ShapeParameterDef<Vector3>;
127
+ amount: FloatParameterDef;
128
+ };
129
+ make(params?: ParamsType<this>): Behaviour;
130
+ }
131
+ declare class MoveToDef extends BaseBevDef<MoveToDef> {
132
+ parameters: {
133
+ target: ShapeParameterDef<Vector3>;
134
+ ease: SelectParameterDef<string>;
135
+ };
136
+ make(params?: ParamsType<this>): Behaviour;
137
+ }
138
+ declare class LinearDampingDef extends BaseBevDef<LinearDampingDef> {
139
+ parameters: {
140
+ factor: FloatParameterDef;
141
+ };
142
+ make(params?: ParamsType<this>): Behaviour;
143
+ }
144
+ declare const vfxInitializsers: {
145
+ lifetime: LifetimeDef;
146
+ rotation: RotationDef;
147
+ mass: MassDef;
148
+ velocity: VelocityDef;
149
+ randomDirection: RandomDirectionDef;
150
+ };
151
+ declare const vfxBehaviours: {
152
+ force: ForceDef;
153
+ gravity: GravityDef;
154
+ scale: ScaleDef;
155
+ randomDrift: RandomDriftDef;
156
+ rotate: RotateDef;
157
+ changeColor: ChangeColorDef;
158
+ changeOpacity: ChangeOpacityDef;
159
+ vortex: VortexDef;
160
+ moveTo: MoveToDef;
161
+ linearDamping: LinearDampingDef;
162
+ };
163
+ export type LibraryVfxInitalizerType = keyof typeof vfxInitializsers;
164
+ export declare const VfxInitializserLibrary: Record<LibraryVfxInitalizerType, InitializerDefinition>;
165
+ export declare const VfxInitializserLibraryKeys: ("rotation" | "mass" | "velocity" | "lifetime" | "randomDirection")[];
166
+ export type LibraryVfxBehaviourType = keyof typeof vfxBehaviours;
167
+ export declare const VfxBehaviourLibrary: Record<LibraryVfxBehaviourType, BehaviourDefinition>;
168
+ export declare const VfxBehaviourLibraryKeys: ("scale" | "rotate" | "force" | "gravity" | "randomDrift" | "changeColor" | "changeOpacity" | "vortex" | "moveTo" | "linearDamping")[];
169
+ export {};
@@ -0,0 +1,5 @@
1
+ import{Color as e,MathUtils as r,Vector2 as t,Vector3 as s}from"three";import{Life as a,Force as n,Gravity as o,Scale as i,RandomDrift as c,Color as u,Alpha as m,Rotate as f,VectorVelocity as p,Vector3D as l,Mass as d,ease as w}from"three-nebula";import{LinearDamping as x,MoveOverLife as y,RotatePosition as h}from"./behaviours";import{RandomDirection as b,Rotation as k}from"./initializsers";class v{build(e={}){const r=T(e,this.parameters);return this.make(r)}}class g{build(e={}){const r=T(e,this.parameters);return this.make(r)}}function z(e,r,t){return{type:"number",default:e,float:!0,min:r,max:t}}function L(e){return{type:"vec3",default:(new s).fromArray(e)}}function V(e){return{type:"color",default:e}}function O(){return{type:"select",opts:Array.from(Object.keys(w)).map((e=>e.substring(4))),default:"Linear"}}function T(e,r){const t={};for(let s in r)null==e[s]?t[s]=r[s].default:t[s]=e[s];return t}function j(e){return null!=e?w["ease"+e]:w.easeLinear}const B={lifetime:new class extends g{constructor(){var e;super(...arguments),this.parameters={duration:(e=1,{type:"number",default:e})}}make(e={}){return new a(e.duration)}},rotation:new class extends g{constructor(){super(...arguments),this.parameters={rotation:L([0,0,0])}}make(e={}){const{x:r,y:t,z:a}=e.rotation;return new k(new s(r,t,a))}},mass:new class extends g{constructor(){super(...arguments),this.parameters={min:z(1)}}make(e={}){return new d(e.min)}},velocity:new class extends g{constructor(){super(...arguments),this.parameters={velocity:L([0,0,0])}}make(e={}){const{x:r,y:t,z:s}=e.velocity;return new p(new l(r,t,s),0)}},randomDirection:new class extends g{constructor(){super(...arguments),this.parameters={speed:z(1)}}make(e={}){return new b(e.speed)}}},D={force:new class extends v{constructor(){super(...arguments),this.parameters={force:L([0,0,0]),ease:O()}}make(e={}){return new n(e.force.x,e.force.y,e.force.z,void 0,j(e.ease))}},gravity:new class extends v{constructor(){super(...arguments),this.parameters={gravity:z(8)}}make(e={}){return new o(e.gravity)}},scale:new class extends v{constructor(){super(...arguments),this.parameters={a:z(1),b:z(1),ease:O()}}make(e={}){return new i(e.a,e.b,void 0,j(e.ease))}},randomDrift:new class extends v{constructor(){super(...arguments),this.parameters={drift:L([1,1,1]),delay:z(0),ease:O()}}make(e={}){return new c(e.drift.x,e.drift.y,e.drift.z,e.delay,void 0,j(e.ease))}},rotate:new class extends v{constructor(){super(...arguments),this.parameters={rotation:L([1,1,1]),ease:O()}}make(e={}){const{x:t,y:s,z:a}=e.rotation;return new f(r.degToRad(t),r.degToRad(s),r.degToRad(a),void 0,j(e.ease))}},changeColor:new class extends v{constructor(){super(...arguments),this.parameters={a:V("#ffffff"),b:V("#ffffff"),ease:O()}}make(r={}){return new u(new e(r.a),new e(r.b),void 0,j(r.ease))}},changeOpacity:new class extends v{constructor(){super(...arguments),this.parameters={a:z(1,0,1),b:z(0,0,1),ease:O()}}make(e={}){return new m(e.a,e.b,void 0,j(e.ease))}},vortex:new class extends v{constructor(){super(...arguments),this.parameters={axis:L([0,1,0]),amount:z(1)}}make(e={}){return new h(e.axis,e.amount)}},moveTo:new class extends v{constructor(){super(...arguments),this.parameters={target:L([0,1,0]),ease:O()}}make(e={}){return new y(e.target.x,e.target.y,e.target.z,j(e.ease))}},linearDamping:new class extends v{constructor(){super(...arguments),this.parameters={factor:z(.1,0,1)}}make(e={}){return new x(e.factor)}}};export const VfxInitializserLibrary=B;export const VfxInitializserLibraryKeys=Object.keys(VfxInitializserLibrary);export const VfxBehaviourLibrary=D;export const VfxBehaviourLibraryKeys=Object.keys(VfxBehaviourLibrary);
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -0,0 +1,19 @@
1
+ import { VfxAsset } from "../../scene/model";
2
+ import { Object3D } from "three";
3
+ import * as THREE from 'three';
4
+ import System, { MeshRenderer, Rate } from "three-nebula";
5
+ export type VfxAssetProvider = {
6
+ getTexture(assetId: string): Promise<THREE.Texture>;
7
+ getMesh(assetId: string): Promise<THREE.Object3D>;
8
+ getMaterial(assetId: string): Promise<THREE.Material>;
9
+ };
10
+ export declare function materializeVfx(asset: VfxAsset, target: Object3D, assetProvider: VfxAssetProvider): Promise<{
11
+ system: System;
12
+ dispose: () => Object3D<THREE.Event>;
13
+ }>;
14
+ export declare function materializeVfxOld(asset: VfxAsset, target: Object3D): {
15
+ system: System;
16
+ rate: Rate;
17
+ renderer: MeshRenderer;
18
+ dispose: () => Object3D<THREE.Event>;
19
+ };
@@ -0,0 +1,5 @@
1
+ import{__awaiter as e}from"tslib";import{Object3D as t}from"three";import*as r from"three";import a,{Body as n,BoxZone as o,Emitter as i,Force as s,Life as l,Mass as d,MeshRenderer as c,PUID as m,PointZone as u,Position as p,RadialVelocity as h,Radius as w,Rate as A,Rotate as f,Scale as g,Span as y,Vector3D as v,ease as M}from"three-nebula";import{RotatePosition as b}from"./behaviours";import{OnceRate as x}from"./rates";import{VfxBehaviourLibrary as B,VfxInitializserLibrary as S}from"./vfx-defs";import{ThreeBlendingMode as I}from"./vfx-asset";import{ShapeLibrary as E}from"../../scene/objects/shapes";import{prepareShapeParameters as P,shapeDefaultColor as R}from"../../scene/materializer";class Q extends c{scale(e){e.target instanceof r.Sprite?e.target.scale.set(e.scale*e.radius,e.scale*e.radius,1):super.scale(e)}onParticleCreated(e){e.target||(e.body||(e.body=this._body),e.target=this._targetPool.get(e.body),(e.useAlpha||e.useColor)&&(e.target instanceof r.Mesh||e.target instanceof r.Sprite&&e.target.material instanceof r.Material)&&(e.target.material.__puid=m.id(e.body.material),e.target.material=this._materialPool.get(e.target.material))),e.target&&e.target instanceof t&&(e.target.position.set(e.position.x,e.position.y,e.position.z),this.container.add(e.target))}onParticleUpdate(e){const{target:t,useAlpha:a,useColor:n,rotation:o}=e;t&&(t.position.copy(e.position),this.isThreeSprite(e)||t.rotation.set(o.x,o.y,o.z),this.scale(e),t.material instanceof r.Material&&(a&&(t.material.opacity=e.alpha,t.material.transparent=!0),n&&t.material.color.copy(e.color)))}onParticleDead(e){e.target&&e.target.material&&((e.useAlpha||e.useColor)&&this._materialPool.expire(e.target.material),this._targetPool.expire(e.target),this.container.remove(e.target),e.target=null)}}export function materializeVfx(o,s,l){return e(this,void 0,void 0,(function*(){let d=s;if(!0!==o.vfx.localSpace)for(;null!=d.parent;)d=d.parent;const c=new t;c.name="particle system",d.add(c);const m=new Q(c,r),u=(new r.Mesh(new r.BoxGeometry(.3,.3,.3),new r.MeshStandardMaterial({color:16777215})),new a),p=yield Promise.all(o.vfx.emitters.map((a=>e(this,void 0,void 0,(function*(){let o,s;switch(a.rate.type){case"continuous":o=new A(a.rate.count,a.rate.time);break;case"once":o=new x(a.rate.count);break;default:console.warn(`Failed to configure rate for emitter: ${JSON.stringify(a)}`),o=new A(0,1/0)}switch(a.output.type){case"sprite":s=new n(yield function(t,a){var n,o;return e(this,void 0,void 0,(function*(){const e=null!=t.texture?yield a.getTexture(t.texture):U;var i=new r.SpriteMaterial({map:e,color:null!==(n=t.color)&&void 0!==n?n:16777215,blending:null!==(o=I[t.blendingMode])&&void 0!==o?o:r.NormalBlending,fog:!0,transparent:!0});return new r.Sprite(i)}))}(a.output,l));break;case"shape":s=new n(yield function(a,n){var o;return e(this,void 0,void 0,(function*(){const e=E[a.shape];if(null==e)return console.error(`No shape with type ${a.shape}`),new t;const i=P(null!==(o=a.params)&&void 0!==o?o:{}),s=e.geometry(i),l=null!=a.material?yield n.getMaterial(a.material):new r.MeshStandardMaterial({color:R});return new r.Mesh(s,l)}))}(a.output,l));break;case"mesh":s=new n(yield function(r,a){return e(this,void 0,void 0,(function*(){return null==r.assetId?(console.warn("Can't use mesh as particle without asset id"),new t):a.getMesh(r.assetId)}))}(a.output,l));break;default:console.error("Failed to create particly system body: "+JSON.stringify(a))}const d=(new i).setRate(o),c=yield Promise.all(a.initializers.filter((e=>null!=S[e.type])).map((t=>e(this,void 0,void 0,(function*(){var e;const r=S[t.type],a=yield P(null!==(e=t.params)&&void 0!==e?e:{});return r.build(a)})))));c.push(s),d.addInitializers(c);const m=yield Promise.all(a.behaviours.filter((e=>null!=B[e.type])).map((t=>e(this,void 0,void 0,(function*(){var e;const r=B[t.type],a=yield P(null!==(e=t.params)&&void 0!==e?e:{});return r.build(a)})))));return d.addBehaviours(m),d.emit()})))));return p.forEach((e=>u.addEmitter(e))),u.addRenderer(m).emit({onEnd:()=>{console.log("ended")}}),{system:u,dispose:()=>c.removeFromParent()}}))}const U=(new r.TextureLoader).load("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJkSURBVHjaxJeJbusgEEW94S1L//83X18M2MSuLd2pbqc4wZGqRLrKBsyZhQHny7Jk73xVL8xpVhWrcmiB5lX+6GJ5YgQ2owbAm8oIwH1VgKZUmGcRqKGGPgtEQQAzGR8hQ59fAmhJHSAagigJ4E7GPWRXOYC6owAd1JM6wDQPADyMWUqZRMqmAojHp1Vn6EQQEgUNMJLnUjMyJsM49wygBkAPw9dVFwXRkncCIIW3GRgoTQUZn6HxCMAFEFd8TwEQ78X4rHbILoAUmeT+RFG4UhQ6MiIAE4W/UsYFjuVjAIa2nIY4q1R0GFtQWG3E84lqw2GO2QOoCKBVu0BAPgDSU0eUDjjQenNkV/AW/pWChhpMTelo1a64AOKM30vk18GzTHXCNtI/Knz3DFBgsUqBGIjTInXRY1yA9xkVoqW5tVq3pDR9A0hfF5BSARmVnh7RMDCaIdcNgbPBkgzn1Bu+SfIEFSpSBmkxyrMicb0fAEuCZrWnN89veA/4XcakrPcjBWzkTuLjlbfTQPOlBhz+HwkqqPXmPQDdrQItxE1moGof1S74j/8txk8EHhTQrAE8qlwfqS5yukm1x/rAJ9Jiaa6nyATqD78aUVBhFo8b1V4DdTXdCW+IxA1zB4JhiOhZMEWO1HqnvdoHZ4FAMIhV9REF8FiUm0jsYPEJx/Fm/N8OhH90HI9YRHesWbXXZwAShU8qThe7H8YAuJmw5yOd989uRINKRTJAhoF8jbqrHKfeCYdIISZfSq26bk/K+yO3YvfKrVgiwQBHnwt8ynPB25+M8hceTt/ybPhnryJ78+tLgAEAuCFyiQgQB30AAAAASUVORK5CYII=");export function materializeVfxOld(e,m){let B=m;if(!0!==e.vfx.localSpace)for(;null!=B.parent;)B=B.parent;const S=new t;S.name="particle system",B.add(S);const I=new c(S,r),E=new r.Mesh(new r.BoxGeometry(.3,.3,.3),new r.MeshStandardMaterial({color:16777215})),P=new A(new y(3,9),new y(.02,.15)),R=new i,Q=new a;R.setLife(4).setRate(P).addInitializers([new d(1),new w(1),new l(1),new n(E),new p(new o(.5)),new h(10,new v(0,0,1),30)]).addBehaviours([new b(new r.Vector3(0,0,1),4),new s(0,0,.1),new f("random",2.5*-Math.PI,2*Math.PI,1,M.easeOutCubic),new g(1,.2)]).emit();const U=new x,V=(new i).setLife(5).addInitializers([new d(1),new w(1),new l(3),new n(E),new p(new u(0,0,0))]).addBehaviours([new g(4,6,void 0,M.easeOutExpo)]).setRate(U).emit();return U.nextTime=0,Q.addEmitter(R).addEmitter(V).addRenderer(I).emit({onEnd:()=>{console.log("ended")}}),{system:Q,rate:P,renderer:I,dispose:()=>S.removeFromParent()}}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */
@@ -1,6 +1,6 @@
1
1
  import { ActionInput, AxisInput, RotationInput } from "../../../../../gameplay/input";
2
2
  import { PhysicsSystem } from "../../../../../gameplay/services/physics/physics-system";
3
- import { Vector3 } from 'three';
3
+ import { Vector3, AnimationAction } from 'three';
4
4
  import { ActorComponent } from "../../../component";
5
5
  import { CharacterMovementMode } from "./modes";
6
6
  export declare class CharacterMovementComponent extends ActorComponent {
@@ -40,7 +40,11 @@ export declare class CharacterMovementComponent extends ActorComponent {
40
40
  private cc;
41
41
  private rayTestResult;
42
42
  constructor(physicsSystem: PhysicsSystem);
43
+ private resetRootMotion;
44
+ private rootMotionInterpolant;
43
45
  onInit(): void | Promise<void>;
46
+ private rootMotionAction;
47
+ setRootMotionAction(action: AnimationAction): void;
44
48
  private getWallDirection;
45
49
  private moveTo;
46
50
  getEffectiveGravity(): number;
@@ -1,4 +1,4 @@
1
- import{__decorate as t,__metadata as i}from"tslib";import{ActionInput as e,AxisInput as s,RotationInput as o}from"../../../../../gameplay/input";import{PhysicsSystem as n,RayTestResult as a}from"../../../../../gameplay/services/physics/physics-system";import{MathUtils as l,Vector3 as r}from"three";import{ActorComponent as c,Component as h}from"../../../component";import{CharacterMovementMode as p}from"./modes";import{Quaternion as m,Vec3 as y}from"cannon-es";import{CapsuleCollisionShape as d}from"../../../../../scene/collision/collision-shape";import{lerp as u}from"three/src/math/MathUtils";import{takeUntil as g}from"rxjs";import{PhysicsBodyType as S}from"../../../../services/physics/physics-system";const f=new r,v=new r,w=1/30;let x=class extends c{get autoStepMinWidth(){return this.cc.autostepMinWidth()}set autoStepMinWidth(t){this.cc.enableAutostep(this.cc.autostepMaxHeight(),t,this.cc.autostepIncludesDynamicBodies())}get autoStepDynamicObjects(){return this.cc.autostepIncludesDynamicBodies()}set autoStepDynamicObjects(t){this.cc.enableAutostep(this.cc.autostepMaxHeight(),this.cc.autostepMinWidth(),t)}get autoStepMaxHeight(){return this.cc.autostepMaxHeight()}set autoStepMaxHeight(t){this.cc.enableAutostep(t,this.cc.autostepMinWidth(),this.cc.autostepIncludesDynamicBodies())}get snapToGround(){return this.cc.snapToGroundDistance()}set snapToGround(t){this.cc.enableSnapToGround(t)}constructor(t){super(),this.physicsSystem=t,this.directionInput=new s,this.jumpInput=new e,this.sprintInput=new e,this.rotationInput=new o,this.horizontalSpeed=0,this.maxSpeed=8,this.maxSpeedBackwards=8,this.maxSpeedSprint=12,this.jumpVelocity=7,this.fallingMovementControl=.5,this.fallingReorientation=!1,this.gravityOverride=null,this.colliderHeight=2,this.colliderRadius=.5,this.jumpInAir=!1,this.mass=50,this.allowSliding=!0,this.minSlopeSlideAngle=l.degToRad(70),this.maxSlopeClimbAngle=l.degToRad(70),this.applyImpulsesToDynamicBodies=!0,this.velocity=new r,this.mode=p.walking,this.isSprinting=!1,this.pressedJump=!1,this.rayTestResult=new a;const i=this.cc=this.physicsSystem.getCharacterController(.1);i.enableSnapToGround(.1),i.enableAutostep(0,.1,!1)}onInit(){const t=this.cc;t.setApplyImpulsesToDynamicBodies(this.applyImpulsesToDynamicBodies),t.setMinSlopeSlideAngle(this.minSlopeSlideAngle),t.setMaxSlopeClimbAngle(this.maxSlopeClimbAngle),t.setCharacterMass(this.mass),t.setSlideEnabled(this.allowSliding),this.physicsSystem.addActor(this.actor,[this.createCollisionShape()],{mass:0,type:S.kinematic,continousCollisionDetection:!0,friction:1}),this.rotationInput.rotation.copy(this.actor.rotation);let i=this.rotationInput.rotation.y;const e=new r,s=new r,o=new r,n=new r,a=new r,l=new r;let c=0,h=null;this.physicsSystem.beforeStep.pipe(g(this.disposed)).subscribe((m=>{m>w&&(m=w),this.pressedJump=this.jumpInput.activated,this.isSprinting=this.sprintInput.activated&&this.directionInput.vertical>=0;let y=i-this.rotationInput.rotation.y;i=this.rotationInput.rotation.y,o.copy(this.actor.position),n.set(-this.directionInput.vector.x,0,this.directionInput.vector.y).normalize();const d=n.z<0?this.maxSpeedBackwards:this.isSprinting?this.maxSpeedSprint:this.maxSpeed;l.copy(n).applyAxisAngle(I,this.rotationInput.rotation.y),this.mode===p.walking&&(0!==l.length()?(c=Math.min(d,c),c=u(c,d,4*m)):c=0,a.copy(l).multiplyScalar(c),this.pressedJump&&(this.mode=p.falling,this.velocity.copy(a),this.velocity.y=this.jumpVelocity),a.y=m*this.getEffectiveGravity()),this.mode===p.falling&&(this.pressedJump&&this.jumpInAir&&(this.mode=p.falling,this.velocity.copy(a),this.velocity.y=this.jumpVelocity),this.velocity.y+=m*this.getEffectiveGravity(),a.copy(this.velocity),a.add(l.clone().multiplyScalar(d*this.fallingMovementControl*m)),this.fallingReorientation&&a.applyAxisAngle(new r(0,1,0),-y)),s.copy(a).normalize(),e.copy(a),this.actor.rotation.y-=y,a.length(),f.copy(a).multiplyScalar(m),v.copy(this.physicsSystem.getActorComputedMovement(this.actor,t,f)),this.physicsSystem.setNextKinematicTranslation(this.actor,v);let g=function(t){if(t.numComputedCollisions()>0){const i=t.computedCollision(0);A.x=i.normal2.x,A.y=i.normal2.y,A.z=i.normal2.z;const e=A.angleTo(I);A.x=i.normal1.x,A.y=i.normal1.y,A.z=i.normal1.z;const s=A.angleTo(I);return!(e<100)&&s>t.minSlopeSlideAngle()}return!1}(t);!t.computedGrounded()||g?this.mode!==p.falling&&(null==h?h=performance.now():performance.now()-h>100&&(this.mode=p.falling,this.velocity.copy(e))):this.velocity.y<=0&&(this.mode,p.falling,this.mode=p.walking,this.velocity.y=0,h=null),this.mode,p.walking,this.horizontalSpeed=c}))}getWallDirection(t,i){const e=t.clone().negate().cross(I);return e.dot(i)<0?e.negate():e}moveTo(t){this.actor.position.copy(t),this.physicsSystem.updateActorTransform(this.actor)}getEffectiveGravity(){var t;return null!==(t=this.gravityOverride)&&void 0!==t?t:this.physicsSystem.getGravity().y}get isGrounded(){return this.rayTestResult.hasHit}createCollisionShape(){const t=new d(this.colliderHeight,this.colliderRadius);return t.offset.y=this.colliderRadius+this.colliderHeight/2,t}step(t){}performMovement(t){}};x=t([h({inEditor:!1}),i("design:paramtypes",[n])],x);export{x as CharacterMovementComponent};const I=new r(0,1,0),A=new r;
1
+ import{__decorate as t,__metadata as i}from"tslib";import{ActionInput as o,AxisInput as e,RotationInput as s}from"../../../../../gameplay/input";import{PhysicsSystem as n,RayTestResult as r}from"../../../../../gameplay/services/physics/physics-system";import{MathUtils as a,Vector3 as l}from"three";import{ActorComponent as c,Component as h}from"../../../component";import{CharacterMovementMode as p}from"./modes";import{Quaternion as m,Vec3 as y}from"cannon-es";import{CapsuleCollisionShape as u}from"../../../../../scene/collision/collision-shape";import{lerp as d}from"three/src/math/MathUtils";import{takeUntil as g}from"rxjs";import{PhysicsBodyType as S}from"../../../../services/physics/physics-system";import{RootMotionClip as f}from"../../../../../gameplay/animation/root-motion";const v=new l,M=new l,A=1/30;let w=class extends c{get autoStepMinWidth(){return this.cc.autostepMinWidth()}set autoStepMinWidth(t){this.cc.enableAutostep(this.cc.autostepMaxHeight(),t,this.cc.autostepIncludesDynamicBodies())}get autoStepDynamicObjects(){return this.cc.autostepIncludesDynamicBodies()}set autoStepDynamicObjects(t){this.cc.enableAutostep(this.cc.autostepMaxHeight(),this.cc.autostepMinWidth(),t)}get autoStepMaxHeight(){return this.cc.autostepMaxHeight()}set autoStepMaxHeight(t){this.cc.enableAutostep(t,this.cc.autostepMinWidth(),this.cc.autostepIncludesDynamicBodies())}get snapToGround(){return this.cc.snapToGroundDistance()}set snapToGround(t){this.cc.enableSnapToGround(t)}constructor(t){super(),this.physicsSystem=t,this.directionInput=new e,this.jumpInput=new o,this.sprintInput=new o,this.rotationInput=new s,this.horizontalSpeed=0,this.maxSpeed=8,this.maxSpeedBackwards=8,this.maxSpeedSprint=12,this.jumpVelocity=7,this.fallingMovementControl=.5,this.fallingReorientation=!1,this.gravityOverride=null,this.colliderHeight=2,this.colliderRadius=.5,this.jumpInAir=!1,this.mass=50,this.allowSliding=!0,this.minSlopeSlideAngle=a.degToRad(70),this.maxSlopeClimbAngle=a.degToRad(70),this.applyImpulsesToDynamicBodies=!0,this.velocity=new l,this.mode=p.walking,this.isSprinting=!1,this.pressedJump=!1,this.rayTestResult=new r,this.resetRootMotion=!1;const i=this.cc=this.physicsSystem.getCharacterController(.1);i.enableSnapToGround(.1),i.enableAutostep(0,.1,!1)}onInit(){const t=this.cc;t.setApplyImpulsesToDynamicBodies(this.applyImpulsesToDynamicBodies),t.setMinSlopeSlideAngle(this.minSlopeSlideAngle),t.setMaxSlopeClimbAngle(this.maxSlopeClimbAngle),t.setCharacterMass(this.mass),t.setSlideEnabled(this.allowSliding),this.physicsSystem.addActor(this.actor,[this.createCollisionShape()],{mass:0,type:S.kinematic,continousCollisionDetection:!0,friction:1}),this.rotationInput.rotation.copy(this.actor.rotation);let i=this.rotationInput.rotation.y;const o=new l,e=new l,s=new l,n=new l,r=new l,a=new l;let c=0,h=null;const m=new l,y=new l,u=new l,w=new l;this.physicsSystem.beforeStep.pipe(g(this.disposed)).subscribe((g=>{if(null!=this.rootMotionAction){if(this.rootMotionAction.getClip()instanceof f){const t=this.rootMotionInterpolant;this.resetRootMotion&&(m.fromArray(t.evaluate(0)),this.resetRootMotion=!1),w.fromArray(t.evaluate(this.rootMotionAction.time)),y.subVectors(w,m),m.copy(w),this.rootMotionAction.getRoot().getWorldScale(u),y.multiply(u)}}g>A&&(g=A);const S=null!=this.rootMotionAction&&this.rootMotionAction.enabled&&0!=y.length();this.pressedJump=this.jumpInput.activated,this.isSprinting=this.sprintInput.activated&&this.directionInput.vertical>=0;let b=i-this.rotationInput.rotation.y;i=this.rotationInput.rotation.y,s.copy(this.actor.position),n.set(-this.directionInput.vector.x,0,this.directionInput.vector.y).normalize();const T=n.z<0?this.maxSpeedBackwards:this.isSprinting?this.maxSpeedSprint:this.maxSpeed;a.copy(n).applyAxisAngle(x,this.rotationInput.rotation.y),this.mode===p.walking?(0!==a.length()?(c=Math.min(T,c),c=d(c,T,4*g)):c=0,r.copy(a).multiplyScalar(c),this.pressedJump&&(this.mode=p.falling,this.velocity.copy(r),this.velocity.y=this.jumpVelocity),r.y=g*this.getEffectiveGravity()):this.mode===p.falling&&(this.pressedJump&&this.jumpInAir&&(this.mode=p.falling,this.velocity.copy(r),this.velocity.y=this.jumpVelocity),this.velocity.y+=g*this.getEffectiveGravity(),r.copy(this.velocity),r.add(a.clone().multiplyScalar(T*this.fallingMovementControl*g)),this.fallingReorientation&&r.applyAxisAngle(new l(0,1,0),-b)),e.copy(r).normalize(),o.copy(r),this.actor.rotation.y-=b,r.length(),S?(y.applyAxisAngle(x,this.actor.rotation.y),y.y+=g*this.getEffectiveGravity(),v.copy(y)):v.copy(r).multiplyScalar(g),M.copy(this.physicsSystem.getActorComputedMovement(this.actor,t,v)),this.physicsSystem.setNextKinematicTranslation(this.actor,M);let C=function(t){if(t.numComputedCollisions()>0){const i=t.computedCollision(0);I.x=i.normal2.x,I.y=i.normal2.y,I.z=i.normal2.z;const o=I.angleTo(x);I.x=i.normal1.x,I.y=i.normal1.y,I.z=i.normal1.z;const e=I.angleTo(x);return!(o<100)&&e>t.minSlopeSlideAngle()}return!1}(t);S||(!t.computedGrounded()||C?this.mode!==p.falling&&(null==h?h=performance.now():performance.now()-h>100&&(this.mode=p.falling,this.velocity.copy(o))):this.velocity.y<=0&&(this.mode,p.falling,this.mode=p.walking,this.velocity.y=0,h=null)),this.mode,p.walking,this.horizontalSpeed=c}))}setRootMotionAction(t){const i=null==t?void 0:t.getClip();if(i instanceof f){this.rootMotionAction=t,this.resetRootMotion=!0;const o=[];this.rootMotionInterpolant=i.motionTrack.InterpolantFactoryMethodSmooth(o)}}getWallDirection(t,i){const o=t.clone().negate().cross(x);return o.dot(i)<0?o.negate():o}moveTo(t){this.actor.position.copy(t),this.physicsSystem.updateActorTransform(this.actor)}getEffectiveGravity(){var t;return null!==(t=this.gravityOverride)&&void 0!==t?t:this.physicsSystem.getGravity().y}get isGrounded(){return this.rayTestResult.hasHit}createCollisionShape(){const t=new u(this.colliderHeight,this.colliderRadius);return t.offset.y=this.colliderRadius+this.colliderHeight/2,t}step(t){}performMovement(t){}};w=t([h({inEditor:!1}),i("design:paramtypes",[n])],w);export{w as CharacterMovementComponent};const x=new l(0,1,0),I=new l;
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -1,4 +1,4 @@
1
- import{__awaiter as t,__decorate as e,__metadata as s}from"tslib";import{ActorComponent as i,Component as o,Attach as n}from"../component";import{CameraComponent as h}from"./camera-component";import{Vector3 as a}from"three";import{ViewController as r}from"../../services/render";import{DecimalInput as c,RestrictedRotationInput as m}from"../../input";import{PhysicsSystem as d,RayTestResult as l}from"../../services/physics/physics-system";import{clamp as u,lerp as p}from"three/src/math/MathUtils";let f=class extends i{constructor(t,e){super(),this.viewController=t,this.physicsSystem=e,this.distance=9,this.minDistance=1.5,this.maxDistance=this.distance,this.height=3,this.offsetX=-1,this.offsetZ=1.5,this.autoActivate=!0,this.bounceBackSpeed=5,this.collisionCheckRadius=.5,this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.rotationInput=new m(-Math.PI/4,Math.PI/2-.7),this.zoomInput=new c(1,0,1),this.offset=new a,this.lookAtOffset=new a(this.offsetX,0,this.offsetZ),this.isMouseLocked=!1,this.canvas=null,this.pointerLockInactivatedAt=null,this.onMouseDown=t=>{this.isMouseLocked||this.hideCursor()},this.onKeyDown=t=>{"Escape"===t.key&&this.showCursor()},this.onPointerLockChange=()=>{null!=document.pointerLockElement||null!=document.mozPointerLockElement||this.showCursor()}}onInit(){return t(this,void 0,void 0,(function*(){this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.autoActivate&&this.viewController.setCamera(this.camera.instance);const t=this.element;t.addEventListener("mousedown",this.onMouseDown),t.addEventListener("keydown",this.onKeyDown),document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),this.disposed.subscribe((()=>{t.removeEventListener("mousedown",this.onMouseDown),t.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("pointerlockchange",this.onPointerLockChange,!1)}))}))}onLateUpdate(t){this.setFromRotation(t)}get element(){return this.viewController.htmlElement}hideCursor(){null!=this.pointerLockInactivatedAt&&performance.now()-this.pointerLockInactivatedAt<1600||(this.element.style.cursor="none",null==this.canvas&&(this.canvas=this.element.getElementsByTagName("canvas")[0]),this.canvas&&(this.canvas.requestPointerLock(),this.isMouseLocked=!0))}showCursor(){this.pointerLockInactivatedAt=performance.now(),this.element.style.cursor="default",window.document.exitPointerLock(),this.isMouseLocked=!1}setFromRotation(t){this.checkForCollision(t);const e=u(Math.min(this.restrictedDistance,this.distance),Math.min(this.minDistance,this.restrictedDistance),Math.max(this.distance*this.zoomInput.value,this.minDistance)),s=Math.cos(this.rotationInput.rotation.x)*e;this.offset.x=Math.sin(this.rotationInput.rotation.y)*s,this.offset.y=Math.sin(this.rotationInput.rotation.x)*e+2,this.offset.z=Math.cos(this.rotationInput.rotation.y)*-s,this.offset.add(this.lookAtOffset),this.updateCameraPosition()}checkForCollision(t){const e=this.getLookAtPosition(),s=v;let i=!1,o=this.distance;const n=new l,h=this.camera.instance.getWorldPosition(y);for(let t=-1;t<=1;t++){const a=w.subVectors(h,e);s.copy(h).add(a.multiplyScalar(1.2)),s.x+=t*this.collisionCheckRadius,this.physicsSystem.rayTest(e,s,n,{debugLifetime:0,excludeActor:this.actor}),n.hasHit&&n.distance<this.distance&&(o=Math.min(n.distance,o),i||(i=n.hasHit))}i||(this.restrictedDistance=p(this.restrictedDistance,this.distance,u(this.bounceBackSpeed*t,0,1)))}getLookAtPosition(){const t=k;return t.set(0,0,0),t.y=this.height,t.add(this.lookAtOffset),t.applyMatrix4(this.actor.object.matrixWorld),t}updateCameraPosition(){this.camera.instance.position.copy(this.offset);const t=this.getLookAtPosition();this.camera.instance.lookAt(t)}};e([n(),s("design:type",h)],f.prototype,"camera",void 0),f=e([o(),s("design:paramtypes",[r,d])],f);export{f as ThirdPartyCameraComponent};const k=new a,v=new a,w=(new a,new a),y=new a;
1
+ import{__awaiter as t,__decorate as e,__metadata as s}from"tslib";import{ActorComponent as i,Component as o,Attach as n}from"../component";import{CameraComponent as h}from"./camera-component";import{Vector3 as a}from"three";import{ViewController as r}from"../../services/render";import{DecimalInput as c,RestrictedRotationInput as m}from"../../input";import{PhysicsSystem as d,RayTestResult as l}from"../../services/physics/physics-system";import{clamp as u,lerp as p}from"three/src/math/MathUtils";let f=class extends i{constructor(t,e){super(),this.viewController=t,this.physicsSystem=e,this.distance=9,this.minDistance=1.5,this.maxDistance=this.distance,this.height=3,this.offsetX=-1,this.offsetZ=1.5,this.autoActivate=!0,this.bounceBackSpeed=5,this.collisionCheckRadius=.5,this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.rotationInput=new m(-Math.PI/4,Math.PI/2-.7),this.zoomInput=new c(1,0,1),this.offset=new a,this.lookAtOffset=new a(this.offsetX,0,this.offsetZ),this.isMouseLocked=!1,this.canvas=null,this.pointerLockInactivatedAt=null,this.onMouseDown=t=>{this.isMouseLocked||this.hideCursor()},this.onKeyDown=t=>{"Escape"===t.key&&this.showCursor()},this.onPointerLockChange=()=>{null!=document.pointerLockElement||null!=document.mozPointerLockElement||this.showCursor()}}onInit(){return t(this,void 0,void 0,(function*(){this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.autoActivate&&this.viewController.setCamera(this.camera.instance);const t=this.element;null!=document.body.requestPointerLock&&(t.addEventListener("mousedown",this.onMouseDown),t.addEventListener("keydown",this.onKeyDown),document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),this.disposed.subscribe((()=>{t.removeEventListener("mousedown",this.onMouseDown),t.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("pointerlockchange",this.onPointerLockChange,!1)})))}))}onLateUpdate(t){this.setFromRotation(t)}get element(){return this.viewController.htmlElement}hideCursor(){null!=this.pointerLockInactivatedAt&&performance.now()-this.pointerLockInactivatedAt<1600||(this.element.style.cursor="none",null==this.canvas&&(this.canvas=this.element.getElementsByTagName("canvas")[0]),this.canvas&&(this.canvas.requestPointerLock(),this.isMouseLocked=!0))}showCursor(){this.pointerLockInactivatedAt=performance.now(),this.element.style.cursor="default",window.document.exitPointerLock(),this.isMouseLocked=!1}setFromRotation(t){this.checkForCollision(t);const e=u(Math.min(this.restrictedDistance,this.distance),Math.min(this.minDistance,this.restrictedDistance),Math.max(this.distance*this.zoomInput.value,this.minDistance)),s=Math.cos(this.rotationInput.rotation.x)*e;this.offset.x=Math.sin(this.rotationInput.rotation.y)*s,this.offset.y=Math.sin(this.rotationInput.rotation.x)*e+2,this.offset.z=Math.cos(this.rotationInput.rotation.y)*-s,this.offset.add(this.lookAtOffset),this.updateCameraPosition()}checkForCollision(t){const e=this.getLookAtPosition(),s=v;let i=!1,o=this.distance;const n=new l,h=this.camera.instance.getWorldPosition(y);for(let t=-1;t<=1;t++){const a=w.subVectors(h,e);s.copy(h).add(a.multiplyScalar(1.2)),s.x+=t*this.collisionCheckRadius,this.physicsSystem.rayTest(e,s,n,{debugLifetime:0,excludeActor:this.actor}),n.hasHit&&n.distance<this.distance&&(o=Math.min(n.distance,o),i||(i=n.hasHit))}i||(this.restrictedDistance=p(this.restrictedDistance,this.distance,u(this.bounceBackSpeed*t,0,1)))}getLookAtPosition(){const t=k;return t.set(0,0,0),t.y=this.height,t.add(this.lookAtOffset),t.applyMatrix4(this.actor.object.matrixWorld),t}updateCameraPosition(){this.camera.instance.position.copy(this.offset);const t=this.getLookAtPosition();this.camera.instance.lookAt(t)}};e([n(),s("design:type",h)],f.prototype,"camera",void 0),f=e([o(),s("design:paramtypes",[r,d])],f);export{f as ThirdPartyCameraComponent};const k=new a,v=new a,w=(new a,new a),y=new a;
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -12,6 +12,9 @@ export type InitiateGameConfig = {
12
12
  actors: {
13
13
  [name: string]: ActorType;
14
14
  };
15
+ xr?: {
16
+ enabled: boolean;
17
+ };
15
18
  };
16
19
  export declare function initiateGame<T_Game>(gameClass: GameClass<T_Game>, config: InitiateGameConfig): HologyRuntime<T_Game>;
17
20
  export declare abstract class GameInstance {
@@ -1,4 +1,4 @@
1
- import{__awaiter as t}from"tslib";import e from"typedi";import{loadScene as n}from"../scene/bootstrap";import{ActorFactory as o}from"./actors/factory";import{World as s}from"./services/world";import{ViewController as r}from"./services/render";import{RenderingView as i}from"../rendering";import{PhysicsSystem as a}from"./services/physics/physics-system";import{MeshComponent as c}from"./actors/builtin/components/mesh-component";import{activeContainerInstance as m}from"./actors/internal/container-map";import{InputService as d}from"./input";import{RuntimeBackendService as l}from"../scene/runtime-backend-service";import{RuntimeAssetsService as p}from"../scene/runtime-asset-service";import{AssetResourceLoader as h}from"../scene/asset-resource-loader";import{AssetLoader as u}from"./services/asset-loader";export function initiateGame(d,f){if(0!=f.element.childNodes.length)return console.error("Can not initialize the game with a non-empty html element"),null;e.has(r);const g=e.of("default"),w=new HologyRuntime(g),v=new o(g,{inEditor:!1});var y;e.set(o,v),y=f.element,Object.assign(y.style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%"});const I=new i(f.element);I.renderer.shadowMap.autoUpdate=!0,e.set(i,I);const S=new r(I);e.set(r,S);const b=new s(e.get(o));e.set(s,b);const D=new l(f.dataDir),x=new p(D),G=new h;G.setDataDir(f.dataDir);const H=new u(G,x);return e.set(u,H),(()=>{t(this,void 0,void 0,(function*(){const t=e.get(a);if(yield t.start(),w.isShutdown)return;const{scene:o,actors:s}=yield n(I,f.sceneName,f.dataDir,f.shaders,f.actors,v,D,x,G);if(b.scene=o,w.isShutdown)return void I.stop();e.import([c]);for(const t of s)b.addActor(t);t.addFromScene(o),I.loop((t=>{})),w.status=5,m.value=g,g.remove(d),g.set({id:d,type:d});const r=g.get(d);m.value=null,w.gameInstance=r,r instanceof GameInstance&&r.onStart(),w._resolver(!0)}))})(),w}export class GameInstance{onStart(){}onShutdown(){}}export function createHologyScene(){}export class HologyRuntime{constructor(t){this.containerInstance=t,this.status=0,this.isShutdown=!1,this.ready=new Promise((t=>{this._resolver=t}))}getWorld(){return this.containerInstance.get(s)}getService(t){return this.containerInstance.get(t)}shutdown(){this.isShutdown=!0,this.gameInstance instanceof GameInstance&&this.gameInstance.onShutdown(),this.containerInstance.get(d).stop();const t=this.containerInstance.get(i);null==t||t.stop();for(const t of this.getWorld().actors)this.getWorld().removeActor(t);this.containerInstance.get(a).stop(),this.containerInstance.reset()}}
1
+ import{__awaiter as e}from"tslib";import t from"typedi";import{loadScene as n}from"../scene/bootstrap";import{ActorFactory as o}from"./actors/factory";import{World as s}from"./services/world";import{ViewController as r}from"./services/render";import{RenderingView as i}from"../rendering";import{PhysicsSystem as a}from"./services/physics/physics-system";import{MeshComponent as c}from"./actors/builtin/components/mesh-component";import{activeContainerInstance as m}from"./actors/internal/container-map";import{InputService as l}from"./input";import{RuntimeBackendService as d}from"../scene/runtime-backend-service";import{RuntimeAssetsService as p}from"../scene/runtime-asset-service";import{AssetResourceLoader as h}from"../scene/asset-resource-loader";import{AssetLoader as u}from"./services/asset-loader";import{polyfillClient as f}from"./polyfill";export function initiateGame(l,g){var w;if(f(),0!=g.element.childNodes.length)return console.error("Can not initialize the game with a non-empty html element"),null;t.has(r);const v=t.of("default"),y=new HologyRuntime(v),I=new o(v,{inEditor:!1});var S;t.set(o,I),S=g.element,Object.assign(S.style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%"});const b=new i(g.element,{enableXR:!0===(null===(w=g.xr)||void 0===w?void 0:w.enabled)});b.renderer.shadowMap.autoUpdate=!0,t.set(i,b);const x=new r(b);t.set(r,x);const D=new s(t.get(o));t.set(s,D);const G=new d(g.dataDir),H=new p(G),R=new h;R.setDataDir(g.dataDir);const W=Object.entries(g.shaders).map((([e,t])=>({name:e,type:t}))),j=new u(R,H,W);return t.set(u,j),(()=>{e(this,void 0,void 0,(function*(){const e=t.get(a);if(yield e.start(),y.isShutdown)return;const{scene:o,actors:s}=yield n(b,g.sceneName,g.dataDir,g.shaders,g.actors,I,G,H,R);if(D.scene=o,y.isShutdown)return void b.stop();t.import([c]);for(const e of s)D.addActor(e);e.addFromScene(o),b.loop((e=>{})),y.status=5,m.value=v,v.remove(l),v.set({id:l,type:l});const r=v.get(l);m.value=null,y.gameInstance=r,r instanceof GameInstance&&r.onStart(),y._resolver(!0)}))})(),y}export class GameInstance{onStart(){}onShutdown(){}}export function createHologyScene(){}export class HologyRuntime{constructor(e){this.containerInstance=e,this.status=0,this.isShutdown=!1,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.gameInstance instanceof GameInstance&&this.gameInstance.onShutdown(),this.containerInstance.get(l).stop();const e=this.containerInstance.get(i);null==e||e.stop();for(const e of this.getWorld().actors)this.getWorld().removeActor(e);this.containerInstance.get(a).stop(),this.containerInstance.reset()}}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -9,10 +9,13 @@ export declare class InputService {
9
9
  private toggleCallbacks;
10
10
  private keybinds;
11
11
  private mousebinds;
12
+ private touchmoveBinds;
12
13
  private wheelbinds;
13
14
  private onKeyDown;
14
15
  private onKeyUp;
15
16
  private onMouseMove;
17
+ private prevTouchEvent;
18
+ private onTouchMove;
16
19
  private onWheel;
17
20
  start(): void;
18
21
  stop(): void;
@@ -25,6 +28,7 @@ export declare class InputService {
25
28
  unbind(name: ActionIdentifier): void;
26
29
  setKeybind(name: ActionIdentifier, key: Keybind): void;
27
30
  setMousebind(name: ActionIdentifier, mouse: Mousebind): void;
31
+ setTouchMoveBind(name: ActionIdentifier, mouse: Mousebind): void;
28
32
  setWheelbind(name: ActionIdentifier, mouse: Wheelbind): void;
29
33
  removeKeybind(name: ActionIdentifier): void;
30
34
  removeMousebind(name: ActionIdentifier): void;
@@ -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.wheelbinds=new Map,this.onKeyDown=e=>{this.keybinds.forEach(((t,s)=>{for(const n of t)n.test(e)&&(this.inputs.has(s)?this.inputs.get(s)(!0):this.toggleCallbacks.has(s)?this.toggleCallbacks.get(s)(!0):console.warn("No input callback for registered for key bind "+n.display()))}))},this.onKeyUp=e=>{this.keybinds.forEach(((t,s)=>{for(const n of t)n.test(e)&&(this.inputs.has(s)?this.inputs.get(s)(!1):this.toggleCallbacks.has(s)?this.toggleCallbacks.get(s)(!1):console.warn("No input callback for registered for key bind "+n.display()))}))},this.onMouseMove=e=>{(null!=document.pointerLockElement||null!=document.mozPointerLockElement)&&this.mousebinds.forEach(((t,s)=>{var n;const i=null!==(n=this.inputs.get(s))&&void 0!==n?n: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.onWheel=e=>{this.wheelbinds.forEach(((t,s)=>{var n;const i=null!==(n=this.inputs.get(s))&&void 0!==n?n: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("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("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)}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};
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 n of t)n.test(e)&&(this.inputs.has(s)?this.inputs.get(s)(!0):this.toggleCallbacks.has(s)?this.toggleCallbacks.get(s)(!0):console.warn("No input callback for registered for key bind "+n.display()))}))},this.onKeyUp=e=>{this.keybinds.forEach(((t,s)=>{for(const n of t)n.test(e)&&(this.inputs.has(s)?this.inputs.get(s)(!1):this.toggleCallbacks.has(s)?this.toggleCallbacks.get(s)(!1):console.warn("No input callback for registered for key bind "+n.display()))}))},this.onMouseMove=e=>{(null!=document.pointerLockElement||null!=document.mozPointerLockElement)&&this.mousebinds.forEach(((t,s)=>{var n;const i=null!==(n=this.inputs.get(s))&&void 0!==n?n: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)=>{var n;const i=null!==(n=this.inputs.get(s))&&void 0!==n?n: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)=>{var n;const i=null!==(n=this.inputs.get(s))&&void 0!==n?n: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
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -0,0 +1 @@
1
+ export declare function polyfillClient(): void;
@@ -0,0 +1,5 @@
1
+ export function polyfillClient(){window.requestIdleCallback=window.requestIdleCallback||function(n){const e=Date.now();return setTimeout((function(){n({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-e))}})}),1)},window.cancelIdleCallback=window.cancelIdleCallback||function(n){clearTimeout(n)}}
2
+ /*
3
+ * Copyright (©) 2023. All rights reserved.
4
+ * See the LICENSE.md file for details.
5
+ */