@hology/core 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE.md +15 -0
- package/README.md +3 -0
- package/dist/config/project-config.d.ts +10 -0
- package/dist/config/project-config.js +5 -0
- package/dist/controllers/base-game-controller.d.ts +3 -0
- package/dist/controllers/base-game-controller.js +5 -0
- package/dist/csm.d.ts +7 -0
- package/dist/csm.js +5 -0
- package/dist/effects/particles/examples.d.ts +271 -0
- package/dist/effects/particles/examples.js +5 -0
- package/dist/effects/particles/particle-system-config.d.ts +85 -0
- package/dist/effects/particles/particle-system-config.js +5 -0
- package/dist/game-component/component-decorators.d.ts +5 -0
- package/dist/game-component/component-decorators.js +5 -0
- package/dist/game-component/game-component.d.ts +8 -0
- package/dist/game-component/game-component.js +5 -0
- package/dist/gameplay/actors/actor.d.ts +37 -0
- package/dist/gameplay/actors/actor.js +5 -0
- package/dist/gameplay/actors/builtin/camera-actor.d.ts +11 -0
- package/dist/gameplay/actors/builtin/camera-actor.js +5 -0
- package/dist/gameplay/actors/builtin/components/character/character-animation.d.ts +67 -0
- package/dist/gameplay/actors/builtin/components/character/character-animation.js +5 -0
- package/dist/gameplay/actors/builtin/components/character/character-movement copy.d.ts +37 -0
- package/dist/gameplay/actors/builtin/components/character/character-movement copy.js +5 -0
- package/dist/gameplay/actors/builtin/components/character/character-movement.d.ts +51 -0
- package/dist/gameplay/actors/builtin/components/character/character-movement.js +5 -0
- package/dist/gameplay/actors/builtin/components/character/modes.d.ts +18 -0
- package/dist/gameplay/actors/builtin/components/character/modes.js +5 -0
- package/dist/gameplay/actors/builtin/components/mesh-component.d.ts +20 -0
- package/dist/gameplay/actors/builtin/components/mesh-component.js +5 -0
- package/dist/gameplay/actors/builtin/components/scene-component.d.ts +7 -0
- package/dist/gameplay/actors/builtin/components/scene-component.js +5 -0
- package/dist/gameplay/actors/builtin/index.d.ts +11 -0
- package/dist/gameplay/actors/builtin/index.js +5 -0
- package/dist/gameplay/actors/builtin/positional-audio-actor.d.ts +19 -0
- package/dist/gameplay/actors/builtin/positional-audio-actor.js +5 -0
- package/dist/gameplay/actors/builtin/spawn-point.d.ts +11 -0
- package/dist/gameplay/actors/builtin/spawn-point.js +5 -0
- package/dist/gameplay/actors/builtin/trigger-volume.d.ts +23 -0
- package/dist/gameplay/actors/builtin/trigger-volume.js +5 -0
- package/dist/gameplay/actors/camera/camera-component.d.ts +13 -0
- package/dist/gameplay/actors/camera/camera-component.js +5 -0
- package/dist/gameplay/actors/camera/third-party-camera-component.d.ts +43 -0
- package/dist/gameplay/actors/camera/third-party-camera-component.js +5 -0
- package/dist/gameplay/actors/component.d.ts +41 -0
- package/dist/gameplay/actors/component.js +5 -0
- package/dist/gameplay/actors/factory.d.ts +12 -0
- package/dist/gameplay/actors/factory.js +5 -0
- package/dist/gameplay/actors/index.d.ts +10 -0
- package/dist/gameplay/actors/index.js +5 -0
- package/dist/gameplay/actors/internal/component-init.d.ts +3 -0
- package/dist/gameplay/actors/internal/component-init.js +5 -0
- package/dist/gameplay/actors/internal/container-map.d.ts +6 -0
- package/dist/gameplay/actors/internal/container-map.js +5 -0
- package/dist/gameplay/animation/anim-sm.d.ts +38 -0
- package/dist/gameplay/animation/anim-sm.js +5 -0
- package/dist/gameplay/animation/root-motion.d.ts +31 -0
- package/dist/gameplay/animation/root-motion.js +5 -0
- package/dist/gameplay/env.d.ts +3 -0
- package/dist/gameplay/env.js +5 -0
- package/dist/gameplay/index.d.ts +14 -0
- package/dist/gameplay/index.js +5 -0
- package/dist/gameplay/initiate.d.ts +51 -0
- package/dist/gameplay/initiate.js +5 -0
- package/dist/gameplay/inject.d.ts +3 -0
- package/dist/gameplay/inject.js +5 -0
- package/dist/gameplay/input/index.d.ts +3 -0
- package/dist/gameplay/input/index.js +5 -0
- package/dist/gameplay/input/input-service.d.ts +33 -0
- package/dist/gameplay/input/input-service.js +5 -0
- package/dist/gameplay/input/input.d.ts +41 -0
- package/dist/gameplay/input/input.js +5 -0
- package/dist/gameplay/input/keybind.d.ts +23 -0
- package/dist/gameplay/input/keybind.js +5 -0
- package/dist/gameplay/services/asset-loader.d.ts +34 -0
- package/dist/gameplay/services/asset-loader.js +5 -0
- package/dist/gameplay/services/physics/collision-contact.d.ts +2 -0
- package/dist/gameplay/services/physics/collision-contact.js +5 -0
- package/dist/gameplay/services/physics/physics-system.d.ts +145 -0
- package/dist/gameplay/services/physics/physics-system.js +5 -0
- package/dist/gameplay/services/render.d.ts +19 -0
- package/dist/gameplay/services/render.js +5 -0
- package/dist/gameplay/services/world.d.ts +15 -0
- package/dist/gameplay/services/world.js +5 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/rendering/shader-override.d.ts +2 -0
- package/dist/rendering/shader-override.js +5 -0
- package/dist/rendering.d.ts +53 -0
- package/dist/rendering.js +5 -0
- package/dist/scene/asset-resource-loader.d.ts +32 -0
- package/dist/scene/asset-resource-loader.js +5 -0
- package/dist/scene/assets-provider.d.ts +9 -0
- package/dist/scene/assets-provider.js +5 -0
- package/dist/scene/bootstrap.d.ts +21 -0
- package/dist/scene/bootstrap.js +5 -0
- package/dist/scene/collision/collision-shape-import.d.ts +4 -0
- package/dist/scene/collision/collision-shape-import.js +5 -0
- package/dist/scene/collision/collision-shape.d.ts +59 -0
- package/dist/scene/collision/collision-shape.js +5 -0
- package/dist/scene/landscape/landscape-manager.d.ts +43 -0
- package/dist/scene/landscape/landscape-manager.js +5 -0
- package/dist/scene/landscape/landscape.d.ts +20 -0
- package/dist/scene/landscape/landscape.js +5 -0
- package/dist/scene/landscape/utils.d.ts +9 -0
- package/dist/scene/landscape/utils.js +5 -0
- package/dist/scene/materializer.d.ts +245 -0
- package/dist/scene/materializer.js +5 -0
- package/dist/scene/materials/grass-foliage.d.ts +8 -0
- package/dist/scene/materials/grass-foliage.js +5 -0
- package/dist/scene/materials/grass.d.ts +4 -0
- package/dist/scene/materials/grass.js +5 -0
- package/dist/scene/materials/utils/material-painting.d.ts +2 -0
- package/dist/scene/materials/utils/material-painting.js +5 -0
- package/dist/scene/materials/utils/noise.glsl.d.ts +1 -0
- package/dist/scene/materials/utils/noise.glsl.js +5 -0
- package/dist/scene/materials/water.d.ts +3 -0
- package/dist/scene/materials/water.js +5 -0
- package/dist/scene/model.d.ts +96 -0
- package/dist/scene/model.js +5 -0
- package/dist/scene/objects/ramp-geometry.d.ts +2 -0
- package/dist/scene/objects/ramp-geometry.js +5 -0
- package/dist/scene/objects/shapes.d.ts +121 -0
- package/dist/scene/objects/shapes.js +5 -0
- package/dist/scene/runtime-asset-service.d.ts +14 -0
- package/dist/scene/runtime-asset-service.js +5 -0
- package/dist/scene/runtime-backend-service.d.ts +12 -0
- package/dist/scene/runtime-backend-service.js +5 -0
- package/dist/scene/scene-data-service.d.ts +33 -0
- package/dist/scene/scene-data-service.js +5 -0
- package/dist/scene/sky.d.ts +3 -0
- package/dist/scene/sky.js +5 -0
- package/dist/scene/storage/storage.d.ts +39 -0
- package/dist/scene/storage/storage.js +5 -0
- package/dist/shader/builtin/index.d.ts +2 -0
- package/dist/shader/builtin/index.js +5 -0
- package/dist/shader/builtin/lambert-shader.d.ts +19 -0
- package/dist/shader/builtin/lambert-shader.js +5 -0
- package/dist/shader/builtin/standard-shader.d.ts +29 -0
- package/dist/shader/builtin/standard-shader.js +5 -0
- package/dist/shader/index.d.ts +2 -0
- package/dist/shader/index.js +5 -0
- package/dist/shader/parameter.d.ts +23 -0
- package/dist/shader/parameter.js +5 -0
- package/dist/shader/shader.d.ts +25 -0
- package/dist/shader/shader.js +5 -0
- package/dist/shader-nodes/depth.d.ts +10 -0
- package/dist/shader-nodes/depth.js +5 -0
- package/dist/shader-nodes/index.d.ts +5 -0
- package/dist/shader-nodes/index.js +5 -0
- package/dist/shader-nodes/landscape.d.ts +5 -0
- package/dist/shader-nodes/landscape.js +5 -0
- package/dist/shader-nodes/layers.d.ts +14 -0
- package/dist/shader-nodes/layers.js +5 -0
- package/dist/shader-nodes/time.d.ts +4 -0
- package/dist/shader-nodes/time.js +5 -0
- package/dist/test/injection.test.d.ts +1 -0
- package/dist/test/injection.test.js +5 -0
- package/dist/utils/async.d.ts +5 -0
- package/dist/utils/async.js +5 -0
- package/dist/utils/cannon/CannonUtils.d.ts +17 -0
- package/dist/utils/cannon/CannonUtils.js +5 -0
- package/dist/utils/cannon/three-to-cannon/ConvexHull.d.ts +47 -0
- package/dist/utils/cannon/three-to-cannon/ConvexHull.js +5 -0
- package/dist/utils/cannon/three-to-cannon/index.d.ts +63 -0
- package/dist/utils/cannon/three-to-cannon/index.js +5 -0
- package/dist/utils/cannon/three-to-cannon/utils.d.ts +9 -0
- package/dist/utils/cannon/three-to-cannon/utils.js +5 -0
- package/dist/utils/collections.d.ts +26 -0
- package/dist/utils/collections.js +5 -0
- package/dist/utils/files.d.ts +1 -0
- package/dist/utils/files.js +5 -0
- package/dist/utils/math.d.ts +24 -0
- package/dist/utils/math.js +5 -0
- package/dist/utils/mesh.d.ts +6 -0
- package/dist/utils/mesh.js +5 -0
- package/dist/utils/polyfill.d.ts +1 -0
- package/dist/utils/polyfill.js +5 -0
- package/dist/utils/three/depth-pass.d.ts +13 -0
- package/dist/utils/three/depth-pass.js +5 -0
- package/dist/utils/three/line-sphere.d.ts +2 -0
- package/dist/utils/three/line-sphere.js +5 -0
- package/dist/utils/three/outline-pass.d.ts +61 -0
- package/dist/utils/three/outline-pass.js +5 -0
- package/dist/utils/three/positional-audio-helper.d.ts +11 -0
- package/dist/utils/three/positional-audio-helper.js +5 -0
- package/dist/utils/three/stats.d.ts +12 -0
- package/dist/utils/three/stats.js +5 -0
- package/dist/utils/three/transform-controls.d.ts +73 -0
- package/dist/utils/three/transform-controls.js +5 -0
- package/dist/utils/three/traverse.d.ts +13 -0
- package/dist/utils/three/traverse.js +5 -0
- package/dist/utils/type.d.ts +4 -0
- package/dist/utils/type.js +5 -0
- package/dist/utils/uuid.d.ts +1 -0
- package/dist/utils/uuid.js +5 -0
- package/package.json +114 -0
- package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
import { Constructable, ContainerInstance } from "typedi";
|
2
|
+
import { ShaderType, ActorType } from '../shader/shader';
|
3
|
+
import { World } from "./services/world";
|
4
|
+
type GameClass<T> = Constructable<T>;
|
5
|
+
export type InitiateGameConfig = {
|
6
|
+
element: HTMLElement;
|
7
|
+
sceneName: string;
|
8
|
+
dataDir: string;
|
9
|
+
shaders: {
|
10
|
+
[name: string]: ShaderType;
|
11
|
+
};
|
12
|
+
actors: {
|
13
|
+
[name: string]: ActorType;
|
14
|
+
};
|
15
|
+
};
|
16
|
+
export declare function initiateGame<T_Game>(gameClass: GameClass<T_Game>, config: InitiateGameConfig): HologyRuntime<T_Game>;
|
17
|
+
export declare abstract class GameInstance {
|
18
|
+
onStart(): void | Promise<void>;
|
19
|
+
onShutdown(): void | Promise<void>;
|
20
|
+
}
|
21
|
+
export declare function createHologyScene(): void;
|
22
|
+
/**
|
23
|
+
* It ideally shouldn't be async.
|
24
|
+
*
|
25
|
+
* It should return a runtime and it could have a status to tell you when it is ready.
|
26
|
+
* There will be stages of loading, etc. Ideally information about loading should be exposed.
|
27
|
+
*
|
28
|
+
*/
|
29
|
+
export declare const enum HologyRuntimeStatus {
|
30
|
+
INITIATING = 0,
|
31
|
+
RUNNING = 5,
|
32
|
+
STOPPED = 10
|
33
|
+
}
|
34
|
+
export declare class HologyRuntime<T_Game = unknown> {
|
35
|
+
private containerInstance;
|
36
|
+
status: HologyRuntimeStatus;
|
37
|
+
gameInstance?: T_Game;
|
38
|
+
private _resolver;
|
39
|
+
/**
|
40
|
+
* A promise that you can await on to delay some logic until the runtime has finished loading
|
41
|
+
*/
|
42
|
+
readonly ready: Promise<boolean>;
|
43
|
+
constructor(containerInstance: ContainerInstance);
|
44
|
+
getWorld(): World;
|
45
|
+
getService<T>(serviceType: Constructable<T>): T;
|
46
|
+
/**
|
47
|
+
* Stops rendering and all game activity on this client.
|
48
|
+
*/
|
49
|
+
shutdown(): void;
|
50
|
+
}
|
51
|
+
export {};
|
@@ -0,0 +1,5 @@
|
|
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 p}from"../scene/runtime-backend-service";import{RuntimeAssetsService as d}from"../scene/runtime-asset-service";import{AssetResourceLoader as h}from"../scene/asset-resource-loader";import{AssetLoader as f}from"./services/asset-loader";export function initiateGame(l,u){if(0!=u.element.childNodes.length)return console.error("Can not initialize the game with a non-empty html element"),null;t.has(r);const g=t.of("default"),w=new HologyRuntime(g),v=new o(g,{inEditor:!1});var y;t.set(o,v),y=u.element,Object.assign(y.style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%"});const I=new i(u.element);I.renderer.shadowMap.autoUpdate=!0,t.set(i,I);const S=new r(I);t.set(r,S);const b=new s(t.get(o));t.set(s,b);const D=new p(u.dataDir),x=new d(D),G=new h;G.setDataDir(u.dataDir);const H=new f(G,x);return t.set(f,H),(()=>{e(this,void 0,void 0,(function*(){const e=t.get(a);yield e.start();const{scene:o,actors:s}=yield n(I,u.sceneName,u.dataDir,u.shaders,u.actors,v,D,x,G);b.scene=o,t.import([c]);for(const e of s)b.addActor(e);e.addFromScene(o),I.loop((e=>{})),w.status=5,m.value=g,g.remove(l),g.set({id:l,type:l});const r=g.get(l);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(e){this.containerInstance=e,this.status=0,this.ready=new Promise((e=>{this._resolver=e}))}getWorld(){return this.containerInstance.get(s)}getService(e){return this.containerInstance.get(e)}shutdown(){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
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import t from"typedi";import{activeContainerInstance as n}from"./actors/internal/container-map";export function inject(o){var e,i;return null!==(i=null===(e=n.value)||void 0===e?void 0:e.get(o))&&void 0!==i?i:t.get(o)}export function withInjectionContext(t,o){const e=n.value;n.value=t,o(t),n.value=e}
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import { Keybind, Mousebind, Wheelbind } from "./keybind";
|
2
|
+
type InputCallback = (active: boolean | number) => void;
|
3
|
+
type DeltaCallback = (delta: number) => any;
|
4
|
+
type ToggleCallback = (active: boolean) => any;
|
5
|
+
type ActionIdentifier = string | number;
|
6
|
+
export declare class InputService {
|
7
|
+
private inputs;
|
8
|
+
private deltaCallbacks;
|
9
|
+
private toggleCallbacks;
|
10
|
+
private keybinds;
|
11
|
+
private mousebinds;
|
12
|
+
private wheelbinds;
|
13
|
+
private onKeyDown;
|
14
|
+
private onKeyUp;
|
15
|
+
private onMouseMove;
|
16
|
+
private onWheel;
|
17
|
+
start(): void;
|
18
|
+
stop(): void;
|
19
|
+
/**
|
20
|
+
* @deprecated Use bindToggle or bindDelta instead
|
21
|
+
*/
|
22
|
+
bind(name: ActionIdentifier, input: InputCallback): void;
|
23
|
+
bindToggle(name: ActionIdentifier, input: ToggleCallback): void;
|
24
|
+
bindDelta(name: ActionIdentifier, callback: DeltaCallback): void;
|
25
|
+
unbind(name: ActionIdentifier): void;
|
26
|
+
setKeybind(name: ActionIdentifier, key: Keybind): void;
|
27
|
+
setMousebind(name: ActionIdentifier, mouse: Mousebind): void;
|
28
|
+
setWheelbind(name: ActionIdentifier, mouse: Wheelbind): void;
|
29
|
+
removeKeybind(name: ActionIdentifier): void;
|
30
|
+
removeMousebind(name: ActionIdentifier): void;
|
31
|
+
removeWheelbind(name: ActionIdentifier): void;
|
32
|
+
}
|
33
|
+
export {};
|
@@ -0,0 +1,5 @@
|
|
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};
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { Euler, Vector2 } from "three";
|
2
|
+
export declare class AxisInput {
|
3
|
+
readonly vector: Vector2;
|
4
|
+
get horizontal(): number;
|
5
|
+
get vertical(): number;
|
6
|
+
readonly togglePositiveY: (active: boolean) => void;
|
7
|
+
readonly toggleNegativeY: (active: boolean) => void;
|
8
|
+
readonly togglePositiveX: (active: boolean) => void;
|
9
|
+
readonly toggleNegativeX: (active: boolean) => void;
|
10
|
+
}
|
11
|
+
type Callback = () => void;
|
12
|
+
export declare class ActionInput {
|
13
|
+
private readonly emitter;
|
14
|
+
activated: boolean;
|
15
|
+
readonly toggle: (active: boolean) => void;
|
16
|
+
onStart(cb: Callback): void;
|
17
|
+
onEnd(cb: Callback): void;
|
18
|
+
}
|
19
|
+
export declare class RotationInput {
|
20
|
+
readonly rotation: Euler;
|
21
|
+
readonly rotateX: (delta: number) => void;
|
22
|
+
readonly rotateY: (delta: number) => void;
|
23
|
+
readonly rotateZ: (delta: number) => void;
|
24
|
+
}
|
25
|
+
export declare class RestrictedRotationInput extends RotationInput {
|
26
|
+
private readonly min;
|
27
|
+
private readonly max;
|
28
|
+
readonly rotation: Euler;
|
29
|
+
constructor(min: number, max: number);
|
30
|
+
readonly rotateX: (delta: number) => void;
|
31
|
+
readonly rotateY: (delta: number) => void;
|
32
|
+
readonly rotateZ: (delta: number) => void;
|
33
|
+
}
|
34
|
+
export declare class DecimalInput {
|
35
|
+
private min?;
|
36
|
+
private max?;
|
37
|
+
value: number;
|
38
|
+
constructor(defaultValue?: number, min?: number, max?: number);
|
39
|
+
readonly increment: (delta: number) => void;
|
40
|
+
}
|
41
|
+
export {};
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import{Euler as t,Vector2 as i}from"three";import{clamp as s}from"three/src/math/MathUtils";import{ArrayMap as o}from"../../utils/collections";export class AxisInput{constructor(){this.vector=new i,this.togglePositiveY=t=>{this.vector.y=t?1:Math.min(this.vector.y,0)},this.toggleNegativeY=t=>{this.vector.y=t?-1:Math.max(this.vector.y,0)},this.togglePositiveX=t=>{this.vector.x=t?1:Math.min(this.vector.x,0)},this.toggleNegativeX=t=>{this.vector.x=t?-1:Math.max(this.vector.x,0)}}get horizontal(){return this.vector.x}get vertical(){return this.vector.y}}class e{constructor(){this.map=new o}emit(t){this.map.get(t).forEach((t=>t()))}add(t,i){this.map.push(t,i)}}export class ActionInput{constructor(){this.emitter=new e,this.activated=!1,this.toggle=t=>{t&&!this.activated?this.emitter.emit("start"):!t&&this.activated&&this.emitter.emit("end"),this.activated=t}}onStart(t){this.emitter.add("start",t)}onEnd(t){this.emitter.add("end",t)}}const h=2*Math.PI;export class RotationInput{constructor(){this.rotation=new t,this.rotateX=t=>{this.rotation.x=(this.rotation.x+t)%h},this.rotateY=t=>{this.rotation.y=(this.rotation.y+t)%h},this.rotateZ=t=>{this.rotation.z=(this.rotation.z+t)%h}}}export class RestrictedRotationInput extends RotationInput{constructor(i,o){super(),this.min=i,this.max=o,this.rotation=new t,this.rotateX=t=>{this.rotation.x=s(this.rotation.x+t,this.min,this.max)},this.rotateY=t=>{this.rotation.y=s(this.rotation.y+t,this.min,this.max)},this.rotateZ=t=>{this.rotation.z=s(this.rotation.z+t,this.min,this.max)}}}export class DecimalInput{constructor(t=0,i,o){this.min=i,this.max=o,this.increment=t=>{this.value=s(this.value+t,this.min,this.max)},this.value=t}}
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,23 @@
|
|
1
|
+
export type MouseButtonKey = 'MouseLeft' | 'MouseMiddle' | 'MouseRight';
|
2
|
+
export type ButtonKey = 'Enter' | 'Shift' | 'Escape' | 'Control' | 'Alt' | 'Meta' | MouseButtonKey | string;
|
3
|
+
export declare class Keybind {
|
4
|
+
key: ButtonKey;
|
5
|
+
shift?: boolean;
|
6
|
+
ctrl?: boolean;
|
7
|
+
constructor(key: ButtonKey, shift?: boolean, ctrl?: boolean);
|
8
|
+
test(event: KeyboardEvent | MouseEvent): boolean;
|
9
|
+
display(): string;
|
10
|
+
}
|
11
|
+
export declare class Mousebind {
|
12
|
+
readonly sensitivity: number;
|
13
|
+
readonly flipped: boolean;
|
14
|
+
readonly axis: 'x' | 'y';
|
15
|
+
constructor(sensitivity?: number, flipped?: boolean, axis?: 'x' | 'y');
|
16
|
+
get multiplier(): number;
|
17
|
+
}
|
18
|
+
export declare class Wheelbind {
|
19
|
+
readonly sensitivity: number;
|
20
|
+
readonly flipped: boolean;
|
21
|
+
constructor(sensitivity?: number, flipped?: boolean);
|
22
|
+
get multiplier(): number;
|
23
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
const t=navigator.platform.toUpperCase().indexOf("MAC")>=0?"⌘":"Ctrl",i=["MouseLeft","MouseMiddle","MouseRight"];export class Keybind{constructor(t,i,s){this.key=t,this.shift=i,this.ctrl=s}test(t){const s=!(null!=this.shift&&"Shift"!==this.key&&this.shift!==t.shiftKey||null!=this.ctrl&&"Control"!==this.key&&this.ctrl!=t.ctrlKey);return"key"in t?t.key.toLowerCase()===this.key.toLowerCase()&&s:i[t.button]===this.key&&s}display(){return(this.shift?"⇧ + ":"")+(this.ctrl?t+" + ":"")+this.key}}export class Mousebind{constructor(t=1,i=!1,s="x"){this.sensitivity=t,this.flipped=i,this.axis=s}get multiplier(){return(this.flipped?-1:1)*this.sensitivity}}export class Wheelbind{constructor(t=1,i=!1){this.sensitivity=t,this.flipped=i}get multiplier(){return(this.flipped?-1:1)*this.sensitivity}}
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { AssetResourceLoader } from "../../scene/asset-resource-loader";
|
2
|
+
import { AssetsProvider } from "../../scene/assets-provider";
|
3
|
+
import { AssetId } from "../../scene/model";
|
4
|
+
import { GLTF } from "three-stdlib";
|
5
|
+
export declare class AssetLoader {
|
6
|
+
protected assetResourceLoader: AssetResourceLoader;
|
7
|
+
protected assetService: AssetsProvider;
|
8
|
+
protected baseUrl: string;
|
9
|
+
protected urlSuffix: string;
|
10
|
+
private loadingManager;
|
11
|
+
private glbLoader;
|
12
|
+
private fbxLoader;
|
13
|
+
private objLoader;
|
14
|
+
private mtlLoader;
|
15
|
+
private tgaLoader;
|
16
|
+
private textureLoader;
|
17
|
+
private audioLoader;
|
18
|
+
constructor(assetResourceLoader: AssetResourceLoader, assetService: AssetsProvider);
|
19
|
+
/**
|
20
|
+
* @param filePath
|
21
|
+
* @returns A path to the file that works both in the editor and
|
22
|
+
*/
|
23
|
+
protected resolvePath(filePath: string): string;
|
24
|
+
/**
|
25
|
+
* @param filePath A path relative to your website's base url. Always use backslash for directory separetors, even in Windows.
|
26
|
+
*/
|
27
|
+
getModelAtPath(filePath: string): Promise<THREE.Object3D>;
|
28
|
+
/**
|
29
|
+
* @param filePath A path relative to your website's base url. Always use backslash for directory separetors, even in Windows.
|
30
|
+
*/
|
31
|
+
geGltfAtPath(filePath: string): Promise<GLTF>;
|
32
|
+
getModelByAssetName(name: string): Promise<import("../../scene/asset-resource-loader").LoadedMesh>;
|
33
|
+
getModelByAssetId(id: AssetId): Promise<import("../../scene/asset-resource-loader").LoadedMesh>;
|
34
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import{__awaiter as e,__decorate as t,__metadata as s}from"tslib";import{AssetResourceLoader as r}from"../../scene/asset-resource-loader";import{FBXLoader as o,GLTFLoader as i,MTLLoader as a,OBJLoader as n,TGALoader as d}from"three-stdlib";import{AudioLoader as l,LoadingManager as h,TextureLoader as u}from"three";import{pathJoin as c}from"../../utils/files";import{Service as g}from"typedi";let f=class{constructor(e,t){this.assetResourceLoader=e,this.assetService=t,this.baseUrl="",this.urlSuffix="",this.loadingManager=new h,this.glbLoader=new i(this.loadingManager),this.fbxLoader=new o(this.loadingManager),this.objLoader=new n(this.loadingManager),this.mtlLoader=new a(this.loadingManager),this.tgaLoader=new d(this.loadingManager),this.textureLoader=new u(this.loadingManager),this.audioLoader=new l(this.loadingManager)}resolvePath(e){return c(this.baseUrl,e)+this.urlSuffix}getModelAtPath(t){return e(this,void 0,void 0,(function*(){const e=this.resolvePath(t);switch(t.split(".").pop().toLowerCase()){case"glb":case"gltf":return(yield this.glbLoader.loadAsync(e)).scene;case"fbx":return this.fbxLoader.loadAsync(e);case"obj":return this.objLoader.loadAsync(e);default:throw new Error(`File suffix is not supperted in file ${t}`)}}))}geGltfAtPath(t){return e(this,void 0,void 0,(function*(){const e=this.resolvePath(t);return this.glbLoader.loadAsync(e)}))}getModelByAssetName(t){return e(this,void 0,void 0,(function*(){const e=(yield this.assetService.getAssets()).find((e=>e.name===t));if(null==e)throw new Error(`No model could be found with asset name ${t}`);return this.assetResourceLoader.getMesh(e)}))}getModelByAssetId(t){return e(this,void 0,void 0,(function*(){const e=yield this.assetService.getAsset(t);if(null==e)throw new Error(`No model could be found with asset id ${t}`);return this.assetResourceLoader.getMesh(e)}))}};f=t([g(),s("design:paramtypes",[r,Object])],f);export{f as AssetLoader};
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,145 @@
|
|
1
|
+
import * as RAPIER from "@dimforge/rapier3d-compat";
|
2
|
+
import { RayColliderIntersection } from "@dimforge/rapier3d-compat";
|
3
|
+
import { Observable, Subject } from "rxjs";
|
4
|
+
import * as THREE from "three";
|
5
|
+
import { ColorRepresentation, Object3D, Vector3 } from "three";
|
6
|
+
import { CollisionShape } from "../../../";
|
7
|
+
import { Type } from "../../../utils/type";
|
8
|
+
import { BaseActor } from "../../actors/actor";
|
9
|
+
import { ViewController } from "../render";
|
10
|
+
import { World } from "../world";
|
11
|
+
import { CollisionContact } from "./collision-contact";
|
12
|
+
export declare class RayTestResult {
|
13
|
+
_internal: RayColliderIntersection;
|
14
|
+
actor: BaseActor;
|
15
|
+
hasHit: boolean;
|
16
|
+
distance: number;
|
17
|
+
hitPoint: Vector3;
|
18
|
+
hitNormal: Vector3;
|
19
|
+
}
|
20
|
+
interface RayTestOptions {
|
21
|
+
debugColor?: ColorRepresentation;
|
22
|
+
debugLifetime?: number;
|
23
|
+
collisionFilter?: number;
|
24
|
+
excludeActor?: BaseActor;
|
25
|
+
}
|
26
|
+
export declare enum PhysicsBodyType {
|
27
|
+
dynamic = 1,
|
28
|
+
static = 2,
|
29
|
+
kinematic = 4,
|
30
|
+
kinematicVelocityBased = 8
|
31
|
+
}
|
32
|
+
export type ActorPhysicsOptions = {
|
33
|
+
isTrigger: boolean;
|
34
|
+
mass: number;
|
35
|
+
friction: number;
|
36
|
+
continousCollisionDetection: boolean;
|
37
|
+
density: number;
|
38
|
+
restitution: number;
|
39
|
+
type: PhysicsBodyType;
|
40
|
+
};
|
41
|
+
export declare class PhysicsSystem {
|
42
|
+
viewController: ViewController;
|
43
|
+
private gameWorld;
|
44
|
+
readonly ready: Promise<void>;
|
45
|
+
private world;
|
46
|
+
private rapier;
|
47
|
+
private staticMeshes;
|
48
|
+
private staticBodies;
|
49
|
+
private actorBodies;
|
50
|
+
private bodyActors;
|
51
|
+
private eventQueue;
|
52
|
+
private readonly collisionEvents;
|
53
|
+
readonly beforeStep: Subject<number>;
|
54
|
+
readonly afterStep: Subject<number>;
|
55
|
+
private shouldRenderDebug;
|
56
|
+
set showDebug(value: boolean);
|
57
|
+
get showDebug(): boolean;
|
58
|
+
constructor(viewController: ViewController, gameWorld: World);
|
59
|
+
private debugMesh;
|
60
|
+
private createDebugMesh;
|
61
|
+
start(): Promise<void>;
|
62
|
+
renderDebug(): void;
|
63
|
+
private setup;
|
64
|
+
private handleTick;
|
65
|
+
/**
|
66
|
+
* Trigger a single step of the physics animation.
|
67
|
+
* This should only be needed if physics is not running but you need
|
68
|
+
* to update the physical bodies.
|
69
|
+
*/
|
70
|
+
private _updateWorld;
|
71
|
+
private updatePhysics;
|
72
|
+
private _raycaster;
|
73
|
+
rayTestFromCamera(distance: number, result?: RayTestResult, options?: RayTestOptions): RayTestResult;
|
74
|
+
private _reusableResult;
|
75
|
+
private _raytestDiff;
|
76
|
+
private _raytestDirection;
|
77
|
+
rayTest(from: Vector3, to: Vector3, result?: RayTestResult, options?: RayTestOptions): RayTestResult;
|
78
|
+
setGravity(x: number, y: number, z: number): void;
|
79
|
+
getGravity(): Vector3;
|
80
|
+
/**
|
81
|
+
* Add static bodies for collision to the world based on an existing scene and contained objects' collision shapes.
|
82
|
+
*/
|
83
|
+
addFromScene(object: Object3D): void;
|
84
|
+
private addRecursively;
|
85
|
+
private createForInstancedMesh;
|
86
|
+
private readonly controlledActors;
|
87
|
+
getCharacterController(offset?: number): RAPIER.KinematicCharacterController;
|
88
|
+
getActorComputedMovement(actor: BaseActor, cc: RAPIER.KinematicCharacterController, desiredTranslation: Vector3): Vector3;
|
89
|
+
setNextKinematicTranslation(actor: BaseActor, vel: Vector3): void;
|
90
|
+
setAngularVelocity(actor: BaseActor, velocity: Vector3): void;
|
91
|
+
setLinearVelocity(actor: BaseActor, velocity: Vector3): void;
|
92
|
+
getLinearVelocity(actor: BaseActor, target?: Vector3): THREE.Vector3;
|
93
|
+
getAngularVelocity(actor: BaseActor, target?: Vector3): THREE.Vector3;
|
94
|
+
setLinearDamping(actor: BaseActor, factor: number): void;
|
95
|
+
setAngularDamping(actor: BaseActor, factor: number): void;
|
96
|
+
createCharacterCollision(): RAPIER.CharacterCollision;
|
97
|
+
private addLandscapeGroup;
|
98
|
+
addActor<A extends BaseActor>(actor: A, collisionShapes: CollisionShape[], options?: Partial<ActorPhysicsOptions>): void;
|
99
|
+
applyTorque(actor: BaseActor, torque: Vector3): void;
|
100
|
+
applyTorqueImpulse(actor: BaseActor, torqueImpulse: Vector3): void;
|
101
|
+
resetForces(actor: BaseActor): void;
|
102
|
+
resetTorques(actor: BaseActor): void;
|
103
|
+
applyForce(actor: BaseActor, force: Vector3): void;
|
104
|
+
applyImpulse(actor: BaseActor, force: Vector3): void;
|
105
|
+
applyLocalForce(actor: BaseActor, force: Vector3, localPoint?: Vector3): void;
|
106
|
+
applyLocalImpulse(actor: BaseActor, force: Vector3, localPoint?: Vector3): void;
|
107
|
+
removeActor(actor: BaseActor): void;
|
108
|
+
removeSceneObject(object: Object3D): void;
|
109
|
+
private activateActorEvents;
|
110
|
+
private _onCollisionWithActorEvent;
|
111
|
+
onBeginOverlapWithActorType<T extends BaseActor, A extends BaseActor>(self: T, actorType: Type<A>): Observable<A>;
|
112
|
+
onEndOverlapWithActorType<T extends BaseActor, A extends BaseActor>(self: T, actorType: Type<A>): Observable<A>;
|
113
|
+
onBeginOverlapWithActor<T extends BaseActor, A extends BaseActor>(self: T, actor: A): Observable<A>;
|
114
|
+
onEndOverlapWithActor<T extends BaseActor, A extends BaseActor>(self: T, actor: A): Observable<A>;
|
115
|
+
onCollisionWithActor<A extends BaseActor, S extends BaseActor>(self: S, actor: A): Observable<A>;
|
116
|
+
onCollisionWithActorType<A extends BaseActor, S extends BaseActor>(self: S, actorType: Type<A>): Observable<A>;
|
117
|
+
/**
|
118
|
+
* Whenever there is collision with anything in the world which is not a trigger volume?
|
119
|
+
* I suppose I can filter out trigger bodies.
|
120
|
+
* Only return collision contact information
|
121
|
+
*
|
122
|
+
* It should be possible to pass in a collision filter (mask) to be able to narrow down the search.
|
123
|
+
* Collision groups should be defined in code as integers. I suppose I can also have predefined collision groups that are available both in the editor and here.
|
124
|
+
*
|
125
|
+
* You might want more information about the object you are colliding with.
|
126
|
+
* If it is a static object, I could provide the raw threejs mesh object.
|
127
|
+
* I could also provide scene object information.
|
128
|
+
*/
|
129
|
+
onCollision<S extends BaseActor>(self: S): Observable<CollisionContact>;
|
130
|
+
updateActorTransform(actor: BaseActor): void;
|
131
|
+
private setupWorld;
|
132
|
+
getActorContacts(actor: BaseActor, direction: Vector3): {
|
133
|
+
ri: Vector3;
|
134
|
+
rj: Vector3;
|
135
|
+
ni: Vector3;
|
136
|
+
}[];
|
137
|
+
stop(): void;
|
138
|
+
/**
|
139
|
+
* Simple body for static scene objects.
|
140
|
+
*/
|
141
|
+
private createStaticBody;
|
142
|
+
private addShape;
|
143
|
+
private createShape;
|
144
|
+
}
|
145
|
+
export {};
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import{__awaiter as e,__decorate as t,__metadata as i}from"tslib";import*as o from"@dimforge/rapier3d-compat";import{QueryFilterFlags as s}from"@dimforge/rapier3d-compat";import{Quaternion as r,RaycastResult as n,Vec3 as a}from"cannon-es";import{filter as l,map as c,Observable as d,Subject as h,takeUntil as u}from"rxjs";import*as y from"three";import{ArrowHelper as p,BufferAttribute as g,BufferGeometry as m,Group as f,LineSegments as w,Matrix4 as v,MeshBasicMaterial as x,Object3D as B,Raycaster as A,Scene as b,Vector3 as C}from"three";import{Service as D}from"typedi";import{AssetMeshInstance as z}from"../../../scene/asset-resource-loader";import{BoxCollisionShape as T,CapsuleCollisionShape as M,ConeCollisionShape as R,ConvexPolyhedronCollisionShape as S,CylinderCollisionShape as E,PhysicalShapeMesh as W,PlaneCollisionShape as _,SphereCollisionShape as F,TrimeshCollisionShape as V}from"../../../";import{LandscapeGroup as P}from"../../../scene/landscape/landscape";import{ViewController as k}from"../render";import{World as I}from"../world";import*as L from"three/examples/jsm/utils/BufferGeometryUtils.js";import{calculateEffectiveScale as O}from"../../../utils/three/traverse";export class RayTestResult{constructor(){this.hasHit=!1,this.hitPoint=new C,this.hitNormal=new C}}new n,new a,new a;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 N=class{set showDebug(e){this.shouldRenderDebug=e,this.debugMesh&&(this.debugMesh.visible=e)}get showDebug(){return this.shouldRenderDebug}constructor(e,t){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 h,this.beforeStep=new h,this.afterStep=new h,this.shouldRenderDebug=!1,this._raycaster=new A,this._reusableResult=new RayTestResult,this._raytestDiff=new C,this._raytestDirection=new C,this.controlledActors=new Set,this.ready=this.setup()}createDebugMesh(){return new w(new m,new x({color:255}))}start(){return e(this,void 0,void 0,(function*(){return yield 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 g(e.vertices,3))}setup(){return e(this,void 0,void 0,(function*(){if(null!=this.rapier)throw new Error("Rapier is already estup");this.rapier=yield X(),this.eventQueue=new o.EventQueue(!0),this.setupWorld()}))}handleTick(){this.viewController.onUpdate().subscribe((e=>{this.beforeStep.next(e),this.updatePhysics(),this.afterStep.next(e),this.showDebug&&this.renderDebug(),this.world.bodies.forEach((e=>{var t,i,o;if(e.isFixed())return;const s=null!==(t=this.staticMeshes.get(e))&&void 0!==t?t:null===(i=this.bodyActors.get(e))||void 0===i?void 0:i.container;var r,n;null!=s&&(Y(s.position,e.translation()),(e.isDynamic()||e.isKinematic()&&!this.controlledActors.has(null===(o=this.bodyActors.get(e))||void 0===o?void 0:o.id))&&(r=s.quaternion,n=e.rotation(),r.x=n.x,r.y=n.y,r.z=n.z,r.w=n.w))}))}))}_updateWorld(){this.world.timestep=0,this.world.step()}updatePhysics(){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(K,this.viewController.getCamera());const o=this._raycaster.ray.origin,s=this._raycaster.ray.direction.multiplyScalar(e).add(o);return this.rayTest(o,s,t,i)}rayTest(e,t,i,s){var r,n;null==i&&(i=this._reusableResult);const a=this._raytestDiff,l=this._raytestDirection;if(a.subVectors(t,e),l.copy(a).normalize(),0===l.length())return console.warn("Ray test called with to and from being equal"),i;const c=new o.Ray(e,l),d=a.length(),h=this.world.castRayAndGetNormal(c,d,!1,void 0,void 0,void 0,null!=(null==s?void 0:s.excludeActor)?this.actorBodies.get(s.excludeActor.id):void 0);if(i.hasHit=null!=h,i.hasHit){const t=c.pointAt(h.toi);i._internal=h,Y(i.hitNormal,h.normal),Y(i.hitPoint,t),i.distance=$.subVectors(i.hitPoint,e).length();const o=this.world.bodies.getAll().find((e=>function(e,t){for(let i=0,o=e.numColliders();i<o;i++){const o=e.collider(i);if(t(o))return o}}(e,(e=>e===h.collider))));i.actor=null!=o?this.bodyActors.get(o):null}if(this.showDebug){const t=new p(l,e,d,null!==(r=null==s?void 0:s.debugColor)&&void 0!==r?r:255);this.gameWorld.scene.add(t),setTimeout((()=>this.gameWorld.scene.remove(t)),null!==(n=null==s?void 0:s.debugLifetime)&&void 0!==n?n: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 j.set(this.world.gravity.x,this.world.gravity.y,this.world.gravity.z)}addFromScene(e){this.addRecursively(e)}addRecursively(e){var t,i;if(this.removeSceneObject(e),!function(e){var t,i;if(null!=(null===(t=e.userData)||void 0===t?void 0:t.src)){return"actor"===(null===(i=e.userData)||void 0===i?void 0:i.src).type}return!1}(e))if(e instanceof W&&null!=e.collisionShape){const t=this.createStaticBody(e,[e.collisionShape]);this.staticMeshes.set(t,e),this.staticBodies.set(e,t)}else if(e instanceof z&&!1!==(null===(i=null===(t=e.userData)||void 0===t?void 0:t.src)||void 0===i?void 0:i.collisionDetection))if(e.children[0]&&e.children[0].instanceMatrix)this.createForInstancedMesh(e.children[0],e.collisionShapes);else{const t=this.createStaticBody(e,e.collisionShapes);this.staticMeshes.set(t,e),this.staticBodies.set(e,t)}else e instanceof P?this.addLandscapeGroup(e):(e instanceof f||e instanceof b)&&e.children.forEach((e=>this.addRecursively(e)))}createForInstancedMesh(e,t){const i=new v;for(let o=0;o<e.count;o++){const s=new B;s.matrix.identity(),i.fromArray(e.instanceMatrix.array,16*o),s.applyMatrix4(i);this.createStaticBody(s,t)}}getCharacterController(e=.01){var t;return null===(t=this.world)||void 0===t?void 0:t.createCharacterController(e)}getActorComputedMovement(e,t,i){const o=this.actorBodies.get(e.id);this.controlledActors.add(e.id);const r=o.collider(0);t.computeColliderMovement(r,i,s.EXCLUDE_SENSORS,null,te);const n=t.computedMovement();return Y(ee,n),ee}setNextKinematicTranslation(e,t){const i=this.actorBodies.get(e.id),o=i.translation();o.x+=t.x,o.y+=t.y,o.z+=t.z,null==i||i.setNextKinematicTranslation(o)}setAngularVelocity(e,t){const i=this.actorBodies.get(e.id);U.x=t.x,U.y=t.y,U.z=t.z,null==i||i.setAngvel(U,!0)}setLinearVelocity(e,t){const i=this.actorBodies.get(e.id);U.x=t.x,U.y=t.y,U.z=t.z,null==i||i.setLinvel(U,!0)}getLinearVelocity(e,t=new C){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 C){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);null==i||i.setLinearDamping(t)}setAngularDamping(e,t){const i=this.actorBodies.get(e.id);null==i||i.setAngularDamping(t)}createCharacterCollision(){return new o.CharacterCollision}addLandscapeGroup(e){const t=e.userData.src,i=t.landscape.heightMaps;for(const r of e.sections){this.staticBodies.has(r)&&this.world.removeRigidBody(this.staticBodies.get(r));const e=t.landscape.options.density+1,n=t.landscape.options.sectionSize,a=new Array(e);for(let t=0;t<e;t++)a[t]=new Array(e).fill(0);const l=i.find((e=>e.x===r.x&&e.y==r.y));if(null!=l)for(const t of l.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/n:console.warn("wrong index",{points:a,point:t,i:t.i%e,k:i,heightMap:l})}const c=t.landscape.options.density,d=a.flatMap((e=>e.reverse())),h=o.ColliderDesc.heightfield(c,c,new Float32Array(d),new o.Vector3(n,n,n));var s=r.getWorldPosition(new C);const u=this.world.createRigidBody(o.RigidBodyDesc.fixed()),y=new o.Vector3(0,0,0);J(y,s),u.setTranslation(y,!1),this.world.createCollider(h,u),this.staticBodies.set(r,u)}}addActor(e,t,i={}){var s,r;if(0==t.length)return void console.error("No collision shapes were defined when adding actor to the physics system.");this.removeActor(e);const n=e.container;let a;switch(null!==(s=i.type)&&void 0!==s?s:PhysicsBodyType.static){case PhysicsBodyType.dynamic:a=o.RigidBodyDesc.dynamic(),a.mass=null!==(r=i.mass)&&void 0!==r?r:1;break;case PhysicsBodyType.kinematic:a=o.RigidBodyDesc.kinematicPositionBased();break;case PhysicsBodyType.kinematicVelocityBased:a=o.RigidBodyDesc.kinematicVelocityBased();break;default:a=(i.isTrigger,o.RigidBodyDesc.kinematicVelocityBased())}const l=this.world.createRigidBody(a);l.enableCcd(1==i.continousCollisionDetection);for(const e of t)this.addShape(l,e,n);Z(l,(e=>{null!=i.isTrigger&&(e.setSensor(i.isTrigger),e.setActiveCollisionTypes(o.ActiveCollisionTypes.ALL)),null!=i.friction&&e.setFriction(i.friction),null!=i.restitution&&e.setDensity(i.restitution),null!=i.mass&&e.setMass(i.mass),null!=i.restitution&&e.setRestitution(i.restitution)})),Q(l,n),this.actorBodies.set(e.id,l),this.bodyActors.set(l,e)}applyTorque(e,t){const i=this.actorBodies.get(e.id);U.x=t.x,U.y=t.y,U.z=t.z,null==i||i.addTorque(U,!0)}applyTorqueImpulse(e,t){const i=this.actorBodies.get(e.id);U.x=t.x,U.y=t.y,U.z=t.z,null==i||i.applyTorqueImpulse(U,!0)}resetForces(e){const t=this.actorBodies.get(e.id);null==t||t.resetForces(!1)}resetTorques(e){const t=this.actorBodies.get(e.id);null==t||t.resetTorques(!1)}applyForce(e,t){const i=this.actorBodies.get(e.id);U.x=t.x,U.y=t.y,U.z=t.z,null==i||i.addForce(U,!0)}applyImpulse(e,t){const i=this.actorBodies.get(e.id);U.x=t.x,U.y=t.y,U.z=t.z,null==i||i.applyImpulse(U,!0)}applyLocalForce(e,t,i){const o=this.actorBodies.get(e.id);J(U,t),null==i?null==o||o.addForce(U,!0):(J(H,i),null==o||o.addForceAtPoint(U,H,!0))}applyLocalImpulse(e,t,i){const o=this.actorBodies.get(e.id);J(U,t),null==i?o.applyImpulse(U,!0):(J(H,i),o.applyImpulseAtPoint(U,H,!0))}removeActor(e){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)}removeSceneObject(e){let t=this.staticBodies.get(e);null!=t&&this.world.getRigidBody(t.handle)&&this.world.removeRigidBody(t)}activateActorEvents(e){const t=this.actorBodies.get(e.id);t&&Z(t,(e=>e.setActiveEvents(o.ActiveEvents.COLLISION_EVENTS)))}_onCollisionWithActorEvent(e,t,i){return this.activateActorEvents(e),this.collisionEvents.pipe(u(e.disposed),l((({started:e})=>e===i)),c((({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}))),l((({a1:i,a2:o})=>null!=i&&null!=o&&i.id===e.id&&t(i,o))),c((({a2:e})=>e)))}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)}onCollision(e){return new d((t=>{if(null==this.actorBodies.get(e.id))throw new Error("Actor must be added to the physics system before setting up collision event handler");return()=>{}}))}updateActorTransform(e){const t=this.actorBodies.get(e.id);null!=t?Q(t,e.container):console.warn("Actor has not been added to physics world",e)}setupWorld(){const e=new o.World({x:0,y:-9.81,z:0});this.world=e,e.maxVelocityIterations=4}getActorContacts(e,t){const i=this.actorBodies.get(e.id);if(i&&i.numColliders()>0){const s=i.collider(0);let r=s.shape,n=s.translation(),a=s.rotation(),l=t,c=.3;const d=this.world.castShape(n,a,l,r,c,!0,null,null,null,this.actorBodies.get(e.id),(e=>e.shape.type!=o.ShapeType.HeightField));if(null!=d){const e=new C,t=new C,i=new C;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.free()}createStaticBody(e,t){const i=this.world.createRigidBody(o.RigidBodyDesc.kinematicPositionBased());for(const o of t)this.addShape(i,o,e);return Q(i,e),i}addShape(e,t,i){const o=this.createShape(t,i.scale);o.friction=.1;const s=t.offset.clone().multiply(i.scale);var n,a;J(o.translation,s),n=o.rotation,a=(new r).setFromEuler(t.rotation.x,t.rotation.y,t.rotation.z),n.x=a.x,n.y=a.y,n.z=a.z,n.w=a.w;this.world.createCollider(o,e)}createShape(e,t){if(e instanceof T)return o.ColliderDesc.cuboid(e.dimensions.x*t.x/2,e.dimensions.y*t.y/2,e.dimensions.z*t.z/2);if(e instanceof M){return o.ColliderDesc.capsule(e.length/2*t.y,e.radius*Math.max(t.z,t.x))}if(e instanceof V){const t=null!=e.geometry.getIndex()?e.geometry:L.mergeVertices(e.geometry);return o.ColliderDesc.trimesh(new Float32Array(t.getAttribute("position").array),new Uint32Array(t.getIndex().array))}if(e instanceof S){let i;e.mesh instanceof y.Mesh?i=e.mesh.geometry:e.mesh instanceof y.BufferGeometry?i=e.mesh:console.log("Unknownd shape",{shapeInfo:e});const s=new Float32Array(i.getAttribute("position").array);if(e.mesh instanceof y.Mesh){const t=O(e.mesh);for(let e=0;e<s.length;e+=3)s[e]*=t.x,s[e+1]*=t.y,s[e+2]*=t.z}for(let e=0;e<s.length;e+=3)s[e]*=t.x,s[e+1]*=t.y,s[e+2]*=t.z;return o.ColliderDesc.convexHull(s)}return e instanceof F?o.ColliderDesc.ball(e.radius*Math.max(t.x,t.y,t.z)):e instanceof E?o.ColliderDesc.cylinder(e.height/2*t.y,e.radiusTop*Math.max(t.z,t.x)):e instanceof R?o.ColliderDesc.cone(e.height*t.y,e.radiusBottom/2*Math.max(t.z,t.x)):e instanceof _?o.ColliderDesc.cuboid(e.width/2*t.x,e.height/2*t.y,.01):(console.error("Unsupported shape",e),o.ColliderDesc.cuboid(1,1,1))}};N=t([D(),i("design:paramtypes",[k,I])],N);export{N as PhysicsSystem};const q=new C,G=new y.Quaternion;function Q(e,t){const i=t.getWorldPosition(q),s=t.getWorldQuaternion(G);e.setTranslation(new o.Vector3(i.x,i.y,i.z),!1),e.setRotation(new o.Quaternion(s.x,s.y,s.z,s.w),!1)}const j=new C,U=new o.Vector3(0,0,0),H=new o.Vector3(0,0,0),K=(new C,{x:0,y:0}),X=()=>e(void 0,void 0,void 0,(function*(){let e=yield import("@dimforge/rapier3d-compat");return yield e.init(),e}));function J(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,o=e.numColliders();i<o;i++){t(e.collider(i))}}const $=new C,ee=new C,te=e=>!e.isSensor();
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { Camera } from "three";
|
2
|
+
import { RenderingView } from "../../rendering";
|
3
|
+
import { Observable } from "rxjs";
|
4
|
+
import * as THREE from "three";
|
5
|
+
export declare class ViewController {
|
6
|
+
private view;
|
7
|
+
private readonly tick;
|
8
|
+
private readonly lateTick;
|
9
|
+
readonly audioListener: THREE.AudioListener;
|
10
|
+
constructor(view: RenderingView);
|
11
|
+
onUpdate(actor?: any): Observable<number>;
|
12
|
+
onLateUpdate(actor?: any): Observable<number>;
|
13
|
+
setCamera(camera: Camera): void;
|
14
|
+
getCamera(): Camera;
|
15
|
+
get htmlElement(): HTMLElement;
|
16
|
+
pauseRendering(): void;
|
17
|
+
unpauseRendering(): void;
|
18
|
+
dispose(): void;
|
19
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import{Service as i}from"typedi";import{RenderingView as s}from"../../rendering";import{Subject as r,takeUntil as a}from"rxjs";import*as n from"three";let o=class{constructor(e){this.view=e,this.tick=new r,this.lateTick=new r,this.audioListener=new n.AudioListener,e.onLoop((e=>{this.tick.next(e),this.lateTick.next(e)})),e.camera.add(this.audioListener)}onUpdate(e){return null!=e&&this.tick.pipe(a(e.disposed)),this.tick}onLateUpdate(e){return null!=e&&this.lateTick.pipe(a(e.disposed)),this.lateTick}setCamera(e){this.view.setCamera(e),e.add(this.audioListener)}getCamera(){return this.view.camera}get htmlElement(){return this.view.container}pauseRendering(){this.view.paused=!0}unpauseRendering(){this.view.paused=!1}dispose(){this.view.stop()}};o=e([i(),t("design:paramtypes",[s])],o);export{o as ViewController};
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { Constructable } from "typedi";
|
2
|
+
import { BaseActor } from "../actors/actor";
|
3
|
+
import { ActorFactory } from "../actors/factory";
|
4
|
+
import { Euler, Scene, Vector3 } from 'three';
|
5
|
+
export declare class World {
|
6
|
+
private actorFactory;
|
7
|
+
readonly actors: BaseActor[];
|
8
|
+
scene: Scene;
|
9
|
+
constructor(actorFactory: ActorFactory);
|
10
|
+
spawnActor<T extends BaseActor>(type: Constructable<T>, position?: Vector3, rotation?: Euler): Promise<T>;
|
11
|
+
addActor(actor: BaseActor, position?: Vector3, rotation?: Euler): void;
|
12
|
+
removeActor(actor: BaseActor): void;
|
13
|
+
findActorByType<T extends BaseActor>(type: Constructable<T>, name?: string): T;
|
14
|
+
findActorsByType<T extends BaseActor>(type: Constructable<T>, name?: string): T[];
|
15
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import{__awaiter as t,__decorate as o,__metadata as r}from"tslib";import{Service as n}from"typedi";import{ActorFactory as e}from"../actors/factory";import{ActorComponent as i}from"../../gameplay/actors/component";let c=class{constructor(t){this.actorFactory=t,this.actors=[]}spawnActor(o,r,n){return t(this,void 0,void 0,(function*(){const t=yield this.actorFactory.create(o,r,n);return this.addActor(t,r,n),t}))}addActor(t,o,r){o&&t.container.position.copy(o),r&&t.container.rotation.copy(r),this.scene.add(t.container),this.actors.push(t),s(t,(t=>t.onBeginPlay()))}removeActor(t){s(t,(t=>t.onEndPlay())),this.actors.splice(this.actors.indexOf(t),1),this.scene.remove(t.container),t.disposed.next(!0)}findActorByType(t,o){return this.actors.find((r=>r instanceof t&&(null==o||r.container.name==o)))}findActorsByType(t,o){return this.actors.filter((r=>r instanceof t&&(null==o||r.container.name==o)))}};c=o([n(),r("design:paramtypes",[e])],c);export{c as World};function s(t,o){return o(t),Object.entries(t).filter((([t,o])=>o instanceof i)).forEach((([t,r])=>{s(r,o)}))}
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
export{loadScene}from"./scene/bootstrap";export{BaseGameController}from"./controllers/base-game-controller";export*from"./scene/collision/collision-shape";export{AssetMeshInstance}from"./scene/asset-resource-loader";
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,2 @@
|
|
1
|
+
export declare const lambertVertexShaderOverride = "\nvec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\nvIndirectFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n\tvLightBack = vec3( 0.0 );\n\tvIndirectBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\nvIndirectFront += getAmbientLightIrradiance( ambientLightColor );\nvIndirectFront += getLightProbeIrradiance( lightProbe, geometry.normal );\n#ifdef DOUBLE_SIDED\n\tvIndirectBack += getAmbientLightIrradiance( ambientLightColor );\n\tvIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry.normal );\n#endif\n#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tgetPointLightInfo( pointLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( - dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tgetSpotLightInfo( spotLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( - dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_DIR_LIGHTS > 0\n float linearDepth = (-mvPosition.z) / (shadowFar - cameraNear);\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\n #if ( UNROLLED_LOOP_INDEX < CSM_CASCADES )\n if(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && (linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1)) {\n #endif \n getDirectionalLightInfo( directionalLights[ i ], geometry, directLight );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;\n #endif\n #if ( UNROLLED_LOOP_INDEX < CSM_CASCADES )\n }\n #endif \n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\tvIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry.normal );\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n";
|
2
|
+
export declare const shadowMaskOverride = "\nvarying vec3 vViewPosition;\nfloat getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n // TODO this does not work as this varying does not exist in this shader\n float linearDepth = (-vViewPosition.z) / (shadowFar - cameraNear);\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n #if ( UNROLLED_LOOP_INDEX < CSM_CASCADES )\n if(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y) {\n #endif \n directionalLight = directionalLightShadows[ i ];\n shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #if ( UNROLLED_LOOP_INDEX < CSM_CASCADES )\n }\n #endif \n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}\n";
|
@@ -0,0 +1,5 @@
|
|
1
|
+
export const lambertVertexShaderOverride="\nvec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\nvIndirectFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n\tvLightBack = vec3( 0.0 );\n\tvIndirectBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\nvIndirectFront += getAmbientLightIrradiance( ambientLightColor );\nvIndirectFront += getLightProbeIrradiance( lightProbe, geometry.normal );\n#ifdef DOUBLE_SIDED\n\tvIndirectBack += getAmbientLightIrradiance( ambientLightColor );\n\tvIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry.normal );\n#endif\n#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tgetPointLightInfo( pointLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( - dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tgetSpotLightInfo( spotLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( - dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_DIR_LIGHTS > 0\n float linearDepth = (-mvPosition.z) / (shadowFar - cameraNear);\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\n #if ( UNROLLED_LOOP_INDEX < CSM_CASCADES )\n if(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && (linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1)) {\n #endif \n getDirectionalLightInfo( directionalLights[ i ], geometry, directLight );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;\n #endif\n #if ( UNROLLED_LOOP_INDEX < CSM_CASCADES )\n }\n #endif \n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\tvIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry.normal );\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n";export const shadowMaskOverride="\nvarying vec3 vViewPosition;\nfloat getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n // TODO this does not work as this varying does not exist in this shader\n float linearDepth = (-vViewPosition.z) / (shadowFar - cameraNear);\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n #if ( UNROLLED_LOOP_INDEX < CSM_CASCADES )\n if(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y) {\n #endif \n directionalLight = directionalLightShadows[ i ];\n shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #if ( UNROLLED_LOOP_INDEX < CSM_CASCADES )\n }\n #endif \n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}\n";
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import * as THREE from "three";
|
2
|
+
import { WebGLRenderer, Object3D, WebGLRenderTarget, Camera } from "three";
|
3
|
+
import { CSM } from "three-stdlib";
|
4
|
+
export type RenderingViewOptions = {
|
5
|
+
enableOutlines?: boolean;
|
6
|
+
};
|
7
|
+
export declare class RenderingView {
|
8
|
+
container: HTMLElement;
|
9
|
+
readonly options: RenderingViewOptions;
|
10
|
+
camera: THREE.Camera;
|
11
|
+
windowVisible: boolean;
|
12
|
+
renderer: WebGLRenderer;
|
13
|
+
rendererDepth: WebGLRenderer;
|
14
|
+
private composer;
|
15
|
+
private outlinePass;
|
16
|
+
scene: THREE.Scene;
|
17
|
+
running: boolean;
|
18
|
+
paused: boolean;
|
19
|
+
depthRenderTarget: WebGLRenderTarget;
|
20
|
+
csm: CSM | null;
|
21
|
+
fpsCap: number | null;
|
22
|
+
setPaused(value: boolean): void;
|
23
|
+
resolutionScale: number;
|
24
|
+
private onResize;
|
25
|
+
private previousClientWith;
|
26
|
+
private previousClientHeight;
|
27
|
+
private resizeRender;
|
28
|
+
private onVisiblityChane;
|
29
|
+
private isDepthTextureExtensionSupported;
|
30
|
+
constructor(container: HTMLElement, options?: RenderingViewOptions);
|
31
|
+
setCamera(camera: Camera): void;
|
32
|
+
setSelectedObjects(obj: Object3D[]): void;
|
33
|
+
private static createDepthRenderTarget;
|
34
|
+
private setupEventListeners;
|
35
|
+
stop(): void;
|
36
|
+
private onLoopCallbacks;
|
37
|
+
onLoop(onFrame: (deltaTime: number) => any): void;
|
38
|
+
removeOnLoop(onFrame: (deltaTime: number) => any): void;
|
39
|
+
loop(onFrame: (deltaTime: number) => any, showStats?: boolean): void;
|
40
|
+
private insetHeight;
|
41
|
+
private insetWidth;
|
42
|
+
private insetOffsetY;
|
43
|
+
private insetMargin;
|
44
|
+
private maxInsetCameras;
|
45
|
+
private overlayCameras;
|
46
|
+
private renderOverlay;
|
47
|
+
addOverlayCamera(camera: Camera): void;
|
48
|
+
clearOverlayCameras(): void;
|
49
|
+
removeOverlayCamera(camera: Camera): void;
|
50
|
+
render(): void;
|
51
|
+
private initDepthUniform;
|
52
|
+
}
|
53
|
+
export declare function setRenderingPaused(value: boolean): void;
|