@hology/core 0.0.32 → 0.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/csm.d.ts +1 -1
- package/dist/csm.js +1 -1
- package/dist/effects/vfx/index.d.ts +2 -2
- package/dist/effects/vfx/index.js +1 -1
- package/dist/effects/vfx/initializsers.d.ts +14 -7
- package/dist/effects/vfx/initializsers.js +1 -1
- package/dist/effects/vfx/vfx-actor.d.ts +2 -2
- package/dist/effects/vfx/vfx-actor.js +1 -1
- package/dist/effects/vfx/vfx-asset.d.ts +3 -3
- package/dist/effects/vfx/vfx-asset.js +1 -1
- package/dist/effects/vfx/vfx-defs.d.ts +5 -2
- package/dist/effects/vfx/vfx-defs.js +1 -1
- package/dist/effects/vfx/vfx-materializer.d.ts +1 -1
- package/dist/effects/vfx/vfx-materializer.js +1 -1
- package/dist/effects/vfx/vfx-param.d.ts +1 -1
- package/dist/gameplay/actors/actor.d.ts +1 -1
- package/dist/gameplay/actors/actor.js +1 -1
- package/dist/gameplay/actors/builtin/camera-actor.d.ts +3 -3
- package/dist/gameplay/actors/builtin/camera-actor.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-animation.d.ts +3 -3
- package/dist/gameplay/actors/builtin/components/character/character-animation.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-movement copy.d.ts +4 -4
- package/dist/gameplay/actors/builtin/components/character/character-movement copy.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-movement.d.ts +4 -4
- package/dist/gameplay/actors/builtin/components/character/character-movement.js +1 -1
- package/dist/gameplay/actors/builtin/components/mesh-component.d.ts +2 -2
- package/dist/gameplay/actors/builtin/components/mesh-component.js +1 -1
- package/dist/gameplay/actors/builtin/components/scene-component.d.ts +1 -1
- package/dist/gameplay/actors/builtin/components/scene-component.js +1 -1
- package/dist/gameplay/actors/builtin/index.d.ts +4 -4
- package/dist/gameplay/actors/builtin/index.js +1 -1
- package/dist/gameplay/actors/builtin/positional-audio-actor.d.ts +6 -5
- package/dist/gameplay/actors/builtin/positional-audio-actor.js +1 -1
- package/dist/gameplay/actors/builtin/spawn-point.d.ts +3 -3
- package/dist/gameplay/actors/builtin/spawn-point.js +1 -1
- package/dist/gameplay/actors/builtin/trigger-volume.d.ts +4 -4
- package/dist/gameplay/actors/builtin/trigger-volume.js +1 -1
- package/dist/gameplay/actors/camera/camera-component.d.ts +2 -2
- package/dist/gameplay/actors/camera/camera-component.js +1 -1
- package/dist/gameplay/actors/camera/third-party-camera-component.d.ts +5 -5
- package/dist/gameplay/actors/camera/third-party-camera-component.js +1 -1
- package/dist/gameplay/actors/component.d.ts +1 -1
- package/dist/gameplay/actors/component.js +1 -1
- package/dist/gameplay/actors/factory.d.ts +3 -3
- package/dist/gameplay/actors/factory.js +1 -1
- package/dist/gameplay/actors/index.d.ts +10 -10
- package/dist/gameplay/actors/index.js +1 -1
- package/dist/gameplay/actors/internal/component-init.d.ts +2 -2
- package/dist/gameplay/actors/internal/component-init.js +1 -1
- package/dist/gameplay/actors/internal/container-map.d.ts +1 -1
- package/dist/gameplay/animation/anim-sm.js +1 -1
- package/dist/gameplay/index.d.ts +14 -13
- package/dist/gameplay/index.js +1 -1
- package/dist/gameplay/initiate.d.ts +2 -2
- package/dist/gameplay/initiate.js +1 -1
- package/dist/gameplay/inject.js +1 -1
- package/dist/gameplay/input/index.d.ts +3 -3
- package/dist/gameplay/input/index.js +1 -1
- package/dist/gameplay/input/input-service.d.ts +1 -1
- package/dist/gameplay/input/input-service.js +1 -1
- package/dist/gameplay/input/input.js +1 -1
- package/dist/gameplay/services/asset-loader.d.ts +5 -5
- package/dist/gameplay/services/asset-loader.js +1 -1
- package/dist/gameplay/services/physics/physics-system.d.ts +5 -5
- package/dist/gameplay/services/physics/physics-system.js +1 -1
- package/dist/gameplay/services/pointer-events.d.ts +58 -0
- package/dist/gameplay/services/pointer-events.js +5 -0
- package/dist/gameplay/services/render.d.ts +3 -3
- package/dist/gameplay/services/render.js +1 -1
- package/dist/gameplay/services/world.d.ts +2 -2
- package/dist/gameplay/services/world.js +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/rendering.js +1 -1
- package/dist/scene/asset-resource-loader.d.ts +2 -2
- package/dist/scene/asset-resource-loader.js +1 -1
- package/dist/scene/assets-provider.d.ts +1 -1
- package/dist/scene/bootstrap.d.ts +7 -7
- package/dist/scene/bootstrap.js +1 -1
- package/dist/scene/collision/collision-shape-import.d.ts +1 -1
- package/dist/scene/collision/collision-shape-import.js +1 -1
- package/dist/scene/landscape/landscape-manager.d.ts +6 -6
- package/dist/scene/landscape/landscape-manager.js +1 -1
- package/dist/scene/landscape/landscape.js +1 -1
- package/dist/scene/landscape/utils.d.ts +1 -1
- package/dist/scene/landscape/utils.js +1 -1
- package/dist/scene/materializer.d.ts +10 -10
- package/dist/scene/materializer.js +1 -1
- package/dist/scene/materials/grass-foliage.d.ts +2 -2
- package/dist/scene/materials/grass-foliage.js +1 -1
- package/dist/scene/materials/grass.d.ts +1 -1
- package/dist/scene/materials/grass.js +1 -1
- package/dist/scene/materials/water.d.ts +1 -1
- package/dist/scene/materials/water.js +1 -1
- package/dist/scene/model.d.ts +5 -5
- package/dist/scene/objects/shapes.d.ts +3 -3
- package/dist/scene/objects/shapes.js +1 -1
- package/dist/scene/runtime-asset-service.d.ts +3 -3
- package/dist/scene/runtime-asset-service.js +1 -1
- package/dist/scene/runtime-backend-service.d.ts +1 -1
- package/dist/scene/runtime-backend-service.js +1 -1
- package/dist/scene/scene-data-service.d.ts +1 -1
- package/dist/scene/scene-data-service.js +1 -1
- package/dist/scene/storage/storage.js +1 -1
- package/dist/shader/builtin/index.d.ts +2 -2
- package/dist/shader/builtin/index.js +1 -1
- package/dist/shader/builtin/lambert-shader.d.ts +1 -1
- package/dist/shader/builtin/lambert-shader.js +1 -1
- package/dist/shader/builtin/standard-shader.d.ts +1 -1
- package/dist/shader/builtin/standard-shader.js +1 -1
- package/dist/shader/index.d.ts +3 -3
- package/dist/shader/index.js +1 -1
- package/dist/shader/parameter.d.ts +4 -4
- package/dist/shader/parameter.js +1 -1
- package/dist/shader/shader.d.ts +4 -4
- package/dist/shader/shader.js +1 -1
- package/dist/shader-nodes/effects.js +1 -1
- package/dist/shader-nodes/index.d.ts +9 -9
- package/dist/shader-nodes/index.js +1 -1
- package/dist/shader-nodes/layers.js +1 -1
- package/dist/test/injection.test.js +1 -1
- package/dist/utils/collections.js +1 -1
- package/dist/utils/three/depth-pass.js +1 -1
- package/dist/utils/three/outline-pass.d.ts +2 -2
- package/dist/utils/three/transform-controls.d.ts +2 -2
- package/package.json +6 -7
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/cannon/CannonUtils.d.ts +0 -17
- package/dist/utils/cannon/CannonUtils.js +0 -5
- package/dist/utils/cannon/three-to-cannon/ConvexHull.d.ts +0 -47
- package/dist/utils/cannon/three-to-cannon/ConvexHull.js +0 -5
- package/dist/utils/cannon/three-to-cannon/index.d.ts +0 -63
- package/dist/utils/cannon/three-to-cannon/index.js +0 -5
- package/dist/utils/cannon/three-to-cannon/utils.d.ts +0 -9
- package/dist/utils/cannon/three-to-cannon/utils.js +0 -5
@@ -1,4 +1,4 @@
|
|
1
|
-
import{__decorate as t,__metadata as o}from"tslib";import{ArrowHelper as r,Vector3 as e,Euler as
|
1
|
+
import{__decorate as t,__metadata as o}from"tslib";import{ArrowHelper as r,Vector3 as e,Euler as s}from"three";import{Actor as i,BaseActor as n}from"../actor.js";import{Component as p,ActorComponent as m,Attach as c}from"../component.js";import{World as a}from"../../../gameplay/services/world.js";import{inject as d}from"../../../gameplay/inject.js";import{createLineSphere as l}from"../../../utils/three/line-sphere.js";let h=class extends m{onInit(){const t=l(1);this.actor.object.add(t);const o=new r(new e(0,0,1),new e,1,1268122,.3,.3);this.actor.object.add(o)}};h=t([p({inEditor:!0,editorOnly:!0})],h);export{h as SpawnPointMesh};let w=class extends n{constructor(){super(...arguments),this.world=d(a)}spawnActor(t){return this.world.spawnActor(t,this.position,new s(0,this.rotation.y,0,"XYZ"))}};t([c(),o("design:type",h)],w.prototype,"mesh",void 0),w=t([i()],w);export{w as SpawnPoint};
|
2
2
|
/*
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
4
4
|
* See the LICENSE.md file for details.
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { BaseActor } from
|
2
|
-
import { ActorComponent } from
|
3
|
-
import { PhysicsSystem } from '../../services/physics/physics-system';
|
1
|
+
import { BaseActor } from '../actor.js';
|
2
|
+
import { ActorComponent } from '../component.js';
|
3
|
+
import { PhysicsSystem } from '../../services/physics/physics-system.js';
|
4
4
|
import { Observable } from "rxjs";
|
5
|
-
import { Type } from '../../../utils/type';
|
5
|
+
import { Type } from '../../../utils/type.js';
|
6
6
|
export declare class TriggerVolumeMesh extends ActorComponent {
|
7
7
|
private dimensions;
|
8
8
|
onInit(): void | Promise<void>;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{__decorate as t,__metadata as s}from"tslib";import{EdgesGeometry as i,LineSegments as e,LineBasicMaterial as o,Vector3 as r,BoxGeometry as n,Mesh as c,MeshBasicMaterial as h,Group as p}from"three";import{Actor as m,BaseActor as a}from"../actor";import{Component as d,ActorComponent as y,Attach as l}from"../component";import{PhysicsSystem as v}from"../../services/physics/physics-system";import{BoxCollisionShape as g}from"../../../scene/collision/collision-shape";import{firstValueFrom as w}from"rxjs";let A=class extends y{constructor(){super(...arguments),this.dimensions=new r(1,1,1)}onInit(){const t=new n(this.dimensions.x,this.dimensions.y,this.dimensions.z),s=new i(t),r=new e(s,new o({color:16777215})),m=(new c(t,new h({color:16777215,transparent:!0,opacity:.3,visible:!1})),new p);m.add(r),this.actor.object.add(m)}};A=t([d({inEditor:!0,editorOnly:!0})],A);export{A as TriggerVolumeMesh};let O=class extends y{constructor(t){super(),this.physicsSystem=t,this.dimensions=new r(1,1,1)}onInit(){this.editorMesh=this.attach(A),this.physicsSystem.addActor(this.actor,[new g(this.dimensions)],{isTrigger:!0}),w(this.disposed).then((()=>{this.physicsSystem.removeActor(this.actor)}))}onBeginOverlapWithActor(t){return this.physicsSystem.onBeginOverlapWithActor(this.actor,t)}onEndOverlapWithActor(t){return this.physicsSystem.onEndOverlapWithActor(this.actor,t)}onBeginOverlapWithActorType(t){return this.physicsSystem.onBeginOverlapWithActorType(this.actor,t)}onEndOverlapWithActorType(t){return this.physicsSystem.onEndOverlapWithActorType(this.actor,t)}};O=t([d({inEditor:!0,editorOnly:!1}),s("design:paramtypes",[v])],O);export{O as TriggerVolumeComponent};let u=class extends a{};t([l(),s("design:type",O)],u.prototype,"trigger",void 0),u=t([m()],u);export{u as TriggerVolume};
|
1
|
+
import{__decorate as t,__metadata as s}from"tslib";import{EdgesGeometry as i,LineSegments as e,LineBasicMaterial as o,Vector3 as r,BoxGeometry as n,Mesh as c,MeshBasicMaterial as h,Group as p}from"three";import{Actor as m,BaseActor as a}from"../actor.js";import{Component as d,ActorComponent as y,Attach as l}from"../component.js";import{PhysicsSystem as v}from"../../services/physics/physics-system.js";import{BoxCollisionShape as g}from"../../../scene/collision/collision-shape.js";import{firstValueFrom as w}from"rxjs";let A=class extends y{constructor(){super(...arguments),this.dimensions=new r(1,1,1)}onInit(){const t=new n(this.dimensions.x,this.dimensions.y,this.dimensions.z),s=new i(t),r=new e(s,new o({color:16777215})),m=(new c(t,new h({color:16777215,transparent:!0,opacity:.3,visible:!1})),new p);m.add(r),this.actor.object.add(m)}};A=t([d({inEditor:!0,editorOnly:!0})],A);export{A as TriggerVolumeMesh};let O=class extends y{constructor(t){super(),this.physicsSystem=t,this.dimensions=new r(1,1,1)}onInit(){this.editorMesh=this.attach(A),this.physicsSystem.addActor(this.actor,[new g(this.dimensions)],{isTrigger:!0}),w(this.disposed).then((()=>{this.physicsSystem.removeActor(this.actor)}))}onBeginOverlapWithActor(t){return this.physicsSystem.onBeginOverlapWithActor(this.actor,t)}onEndOverlapWithActor(t){return this.physicsSystem.onEndOverlapWithActor(this.actor,t)}onBeginOverlapWithActorType(t){return this.physicsSystem.onBeginOverlapWithActorType(this.actor,t)}onEndOverlapWithActorType(t){return this.physicsSystem.onEndOverlapWithActorType(this.actor,t)}};O=t([d({inEditor:!0,editorOnly:!1}),s("design:paramtypes",[v])],O);export{O as TriggerVolumeComponent};let u=class extends a{};t([l(),s("design:type",O)],u.prototype,"trigger",void 0),u=t([m()],u);export{u as TriggerVolume};
|
2
2
|
/*
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
4
4
|
* See the LICENSE.md file for details.
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { ActorComponent } from '../component';
|
2
|
-
import { ViewController } from '../../services/render';
|
1
|
+
import { ActorComponent } from '../component.js';
|
2
|
+
import { ViewController } from '../../services/render.js';
|
3
3
|
import { PerspectiveCamera } from 'three';
|
4
4
|
export declare class CameraComponent extends ActorComponent {
|
5
5
|
private viewController;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import{ActorComponent as i,Component as r}from"../component";import{ViewController as
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import{ActorComponent as i,Component as r}from"../component.js";import{ViewController as s}from"../../services/render.js";import{PerspectiveCamera as n}from"three";import{Parameter as o}from"../../../shader/parameter.js";const a=void 0!==window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let h=class extends i{constructor(e){super(),this.viewController=e,this.near=.5,this.far=500,this.viewAngle=a?30:45,this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.instance=new n(this.viewAngle,this.aspect,this.near,this.far)}onInit(){this.actor.object.add(this.instance),this.instance.near=this.near,this.instance.far=this.far,this.instance.fov=this.viewAngle}};e([o(),t("design:type",Object)],h.prototype,"near",void 0),e([o(),t("design:type",Number)],h.prototype,"far",void 0),e([o(),t("design:type",Number)],h.prototype,"viewAngle",void 0),h=e([r({inEditor:!0}),t("design:paramtypes",[s])],h);export{h as CameraComponent};
|
2
2
|
/*
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
4
4
|
* See the LICENSE.md file for details.
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import { ActorComponent } from '../component';
|
2
|
-
import { CameraComponent } from './camera-component';
|
3
|
-
import { ViewController } from '../../services/render';
|
4
|
-
import { DecimalInput, RestrictedRotationInput } from '../../input';
|
5
|
-
import { PhysicsSystem } from '../../services/physics/physics-system';
|
1
|
+
import { ActorComponent } from '../component.js';
|
2
|
+
import { CameraComponent } from './camera-component.js';
|
3
|
+
import { ViewController } from '../../services/render.js';
|
4
|
+
import { DecimalInput, RestrictedRotationInput } from '../../input/index.js';
|
5
|
+
import { PhysicsSystem } from '../../services/physics/physics-system.js';
|
6
6
|
/**
|
7
7
|
* A camera that is behind the actor.
|
8
8
|
* It can also spring back and forward to avoid clipping into other elements
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{
|
1
|
+
import{__decorate as t,__metadata as e}from"tslib";import{ActorComponent as s,Component as i,Attach as o}from"../component.js";import{CameraComponent as n}from"./camera-component.js";import{Vector3 as a,MathUtils as h}from"three";import{ViewController as c}from"../../services/render.js";import{DecimalInput as r,RestrictedRotationInput as m}from"../../input/index.js";import{PhysicsSystem as d,RayTestResult as l}from"../../services/physics/physics-system.js";let u=class extends s{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 r(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()}}async onInit(){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=h.clamp(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=f;let i=!1,o=this.distance;const n=new l,a=this.camera.instance.getWorldPosition(w);for(let t=-1;t<=1;t++){const h=k.subVectors(a,e);s.copy(a).add(h.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||=n.hasHit)}i||(this.restrictedDistance=h.lerp(this.restrictedDistance,this.distance,h.clamp(this.bounceBackSpeed*t,0,1)))}getLookAtPosition(){const t=p;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)}};t([o(),e("design:type",n)],u.prototype,"camera",void 0),u=t([i(),e("design:paramtypes",[c,d])],u);export{u as ThirdPartyCameraComponent};const p=new a,f=new a,k=(new a,new a),w=new a;
|
2
2
|
/*
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
4
4
|
* See the LICENSE.md file for details.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import t,
|
1
|
+
import{Container as t,Service as n,Inject as o}from"typedi";import{_setupActorUpdateEventHandlers as e}from"./actor.js";import{activeContainerInstance as r}from"./internal/container-map.js";import{randomString as i}from"../../utils/math.js";export class ActorComponent{constructor(){e.call(this)}onInit(){}onBeginPlay(){}onEndPlay(){}onUpdate(t){}onLateUpdate(t){}get disposed(){return this.actor.disposed}attach(t,n){return this.actor.attach(t,n)}}ActorComponent.__isActorComponent=!0;export function Component(t={inEditor:!1,editorOnly:!1}){const o=n({transient:!0});return function(n){n.__inEditor=t.inEditor,n.__onlyEditor=t.editorOnly,o(n)}}export function Attach(n={},e){return function(r,i,a){if(null==r)return void Reflect.defineMetadata("design:type",e,e.prototype,i);const c=e??Reflect.getMetadata("design:type",r,i);o((()=>c))(r,i,a);const s=t.handlers.find((t=>t.object===r&&t.propertyName===i&&t.index===a)),d=s.value;s.value=t=>{const o=d(t);return Object.assign(o,n)}}}export function attach(n,o){const e=r.value??t.of("default"),a=i();e.set({id:a,type:n,transient:!0});const c=e.get(a);if(null!=o)for(const t of Object.keys(o))c[t]=o[t];return c}
|
2
2
|
/*
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
4
4
|
* See the LICENSE.md file for details.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Constructable, ContainerInstance } from "typedi";
|
2
|
-
import { BaseActor } from
|
3
|
-
import { EngineEnvironment } from '../env';
|
4
|
-
import { ActorProvider } from '../../scene/materializer';
|
2
|
+
import { BaseActor } from './actor.js';
|
3
|
+
import { EngineEnvironment } from '../env.js';
|
4
|
+
import { ActorProvider } from '../../scene/materializer.js';
|
5
5
|
import { Vector3, Euler } from "three";
|
6
6
|
export declare class ActorFactory implements ActorProvider<BaseActor> {
|
7
7
|
private container;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{
|
1
|
+
import{__decorate as t,__metadata as i}from"tslib";import{ContainerInstance as n}from"typedi";import{Service as o}from"typedi";import{initComponents as e}from"./internal/component-init.js";import{activeContainerInstance as r,containerRefMap as a}from"./internal/container-map.js";let s=class{constructor(t,i){this.container=t,this.env=i}async create(t,i,n,o){const e=this.container;r.value=e;const s=(1e4*Math.random()).toString();e.set({id:s,type:t,transient:!0});const c=e.get(s);return r.value=null,e.remove(t),a.set(c,e),i&&c.object.position.copy(i),n&&c.object.rotation.copy(n),!0!==o&&await this.initActor(c),c}async initActor(t){await e(t,t,this.env.inEditor??!1),await t.onInit(),t.__isInitialised=!0}};s=t([o(),i("design:paramtypes",[n,Object])],s);export{s as ActorFactory};
|
2
2
|
/*
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
4
4
|
* See the LICENSE.md file for details.
|
@@ -1,10 +1,10 @@
|
|
1
|
-
export { CameraActor } from './builtin/camera-actor';
|
2
|
-
export { CameraComponent } from './camera/camera-component';
|
3
|
-
export { ThirdPartyCameraComponent } from './camera/third-party-camera-component';
|
4
|
-
export { SpawnPoint } from './builtin/spawn-point';
|
5
|
-
export { TriggerVolume, TriggerVolumeComponent } from './builtin/trigger-volume';
|
6
|
-
export { PositionalAudioActor, PositionalAudioComponent } from './builtin/positional-audio-actor';
|
7
|
-
export * from './builtin/components/mesh-component';
|
8
|
-
export * from './builtin/components/character/character-movement';
|
9
|
-
export * from './builtin/components/character/modes';
|
10
|
-
export * from './builtin/components/character/character-animation';
|
1
|
+
export { CameraActor } from './builtin/camera-actor.js';
|
2
|
+
export { CameraComponent } from './camera/camera-component.js';
|
3
|
+
export { ThirdPartyCameraComponent } from './camera/third-party-camera-component.js';
|
4
|
+
export { SpawnPoint } from './builtin/spawn-point.js';
|
5
|
+
export { TriggerVolume, TriggerVolumeComponent } from './builtin/trigger-volume.js';
|
6
|
+
export { PositionalAudioActor, PositionalAudioComponent } from './builtin/positional-audio-actor.js';
|
7
|
+
export * from './builtin/components/mesh-component.js';
|
8
|
+
export * from './builtin/components/character/character-movement.js';
|
9
|
+
export * from './builtin/components/character/modes.js';
|
10
|
+
export * from './builtin/components/character/character-animation.js';
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export{CameraActor}from"./builtin/camera-actor";export{CameraComponent}from"./camera/camera-component";export{ThirdPartyCameraComponent}from"./camera/third-party-camera-component";export{SpawnPoint}from"./builtin/spawn-point";export{TriggerVolume,TriggerVolumeComponent}from"./builtin/trigger-volume";export{PositionalAudioActor,PositionalAudioComponent}from"./builtin/positional-audio-actor";export*from"./builtin/components/mesh-component";export*from"./builtin/components/character/character-movement";export*from"./builtin/components/character/modes";export*from"./builtin/components/character/character-animation";
|
1
|
+
export{CameraActor}from"./builtin/camera-actor.js";export{CameraComponent}from"./camera/camera-component.js";export{ThirdPartyCameraComponent}from"./camera/third-party-camera-component.js";export{SpawnPoint}from"./builtin/spawn-point.js";export{TriggerVolume,TriggerVolumeComponent}from"./builtin/trigger-volume.js";export{PositionalAudioActor,PositionalAudioComponent}from"./builtin/positional-audio-actor.js";export*from"./builtin/components/mesh-component.js";export*from"./builtin/components/character/character-movement.js";export*from"./builtin/components/character/modes.js";export*from"./builtin/components/character/character-animation.js";
|
2
2
|
/*
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
4
4
|
* See the LICENSE.md file for details.
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import { BaseActor } from
|
2
|
-
import { ActorComponent } from
|
1
|
+
import { BaseActor } from '../actor.js';
|
2
|
+
import { ActorComponent } from '../component.js';
|
3
3
|
export declare function initComponents(a: BaseActor | ActorComponent, actor: BaseActor, inEditor?: boolean): Promise<any[]>;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{
|
1
|
+
import{ActorComponent as o}from"../component.js";export async function initComponents(n,t,c=!1){const i=[];for(const r of Object.values(n))if(r instanceof o||null!=r?.constructor&&!0===r.constructor.__isActorComponent){if(c&&!r.constructor.__inEditor)continue;if(!c&&r.constructor.__onlyEditor)continue;r.actor=t,await r.onInit(),i.push(initComponents(r,t,c))}return Promise.all(i)}
|
2
2
|
/*
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
4
4
|
* See the LICENSE.md file for details.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
let t=0;class i{constructor(t,i){this.state=t,this.predicate=i}}export class AnimationState{constructor(i){this.clip=i,this.uuid=t++,this.transitions=[]}named(t){return this.name=t,this}getAncestors(){return null!=this.parent?[this,...this.parent.getAncestors()]:[this]}getRoot(){return null!=this.parent?this.parent.getRoot():this}createChild(t,i){const s=new AnimationState(t);return s.parent=this,this.transitionsTo(s,i),s}split(t,i=null,s=null){return[this.createChild(i,t),this.createChild(s,n(t))]}transitionsTo(t,s=(()=>!0)){this.transitions.push(new i(t,s))}transitionsOnComplete(t,i){this.transitionsTo(t,(t=>!!i&&i(t)||t>=this.clip.duration-.5))}transitionsBetween(t,i){this.transitionsTo(t,i),t.transitionsTo(this,n(i))}}export class AnimationStateMachine{constructor(t){this.initialState=t,this.timer=0,this.current=t}step(t){return this.timer+=t,this._getNext()}_getNext(t=1){const i=s(this.current.getRoot(),this.timer,this.current);return i.uuid!==this.current.uuid&&(this.timer=0,this.current=i),--t>0?this._getNext(t):this.current}}function s(t,i,n){
|
1
|
+
let t=0;class i{constructor(t,i){this.state=t,this.predicate=i}}export class AnimationState{constructor(i){this.clip=i,this.uuid=t++,this.transitions=[]}named(t){return this.name=t,this}getAncestors(){return null!=this.parent?[this,...this.parent.getAncestors()]:[this]}getRoot(){return null!=this.parent?this.parent.getRoot():this}createChild(t,i){const s=new AnimationState(t);return s.parent=this,this.transitionsTo(s,i),s}split(t,i=null,s=null){return[this.createChild(i,t),this.createChild(s,n(t))]}transitionsTo(t,s=(()=>!0)){this.transitions.push(new i(t,s))}transitionsOnComplete(t,i){this.transitionsTo(t,(t=>!!i&&i(t)||t>=this.clip.duration-.5))}transitionsBetween(t,i){this.transitionsTo(t,i),t.transitionsTo(this,n(i))}}export class AnimationStateMachine{constructor(t){this.initialState=t,this.timer=0,this.current=t}step(t){return this.timer+=t,this._getNext()}_getNext(t=1){const i=s(this.current.getRoot(),this.timer,this.current);return i.uuid!==this.current.uuid&&(this.timer=0,this.current=i),--t>0?this._getNext(t):this.current}}function s(t,i,n){for(const e of t.transitions)if(e.predicate(i))return s(e.state,e.state.uuid===n.uuid?i:0,n);return null==t.clip?t.getAncestors().find((t=>null!=t.clip))??t:t}const n=t=>i=>!t(i);
|
2
2
|
/*
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
4
4
|
* See the LICENSE.md file for details.
|
package/dist/gameplay/index.d.ts
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
import 'reflect-metadata';
|
2
|
-
export * from './initiate';
|
3
|
-
export * from './inject';
|
4
|
-
export { Service, Inject } from 'typedi';
|
5
|
-
export { ActorFactory } from './actors/factory';
|
6
|
-
export { Actor, BaseActor } from './actors/actor';
|
7
|
-
export { Component, ActorComponent, ComponentOptions, attach, Attach } from './actors/component';
|
8
|
-
export * from './services/world';
|
9
|
-
export * from './services/render';
|
10
|
-
export * from './services/physics/physics-system';
|
11
2
|
export { Container as DIContainer } from 'typedi';
|
12
|
-
export * from './
|
13
|
-
export * from './
|
14
|
-
export
|
15
|
-
export {
|
3
|
+
export * from './initiate.js';
|
4
|
+
export * from './inject.js';
|
5
|
+
export { Service, Inject } from 'typedi';
|
6
|
+
export { ActorFactory } from './actors/factory.js';
|
7
|
+
export { Actor, BaseActor } from './actors/actor.js';
|
8
|
+
export { Component, ActorComponent, ComponentOptions, attach, Attach } from './actors/component.js';
|
9
|
+
export * from './services/world.js';
|
10
|
+
export * from './services/render.js';
|
11
|
+
export * from './services/physics/physics-system.js';
|
12
|
+
export * from './animation/anim-sm.js';
|
13
|
+
export * from './animation/root-motion.js';
|
14
|
+
export * from './services/asset-loader.js';
|
15
|
+
export * from './services/pointer-events.js';
|
16
|
+
export { VisualEffect } from '../effects/vfx/vfx-param.js';
|
package/dist/gameplay/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import"reflect-metadata";export*from"./initiate";export*from"./inject";export{Service,Inject}from"typedi";export{ActorFactory}from"./actors/factory";export{Actor,BaseActor}from"./actors/actor";export{Component,ActorComponent,attach,Attach}from"./actors/component";export*from"./services/world";export*from"./services/render";export*from"./services/physics/physics-system";export
|
1
|
+
import"reflect-metadata";export{Container as DIContainer}from"typedi";export*from"./initiate.js";export*from"./inject.js";export{Service,Inject}from"typedi";export{ActorFactory}from"./actors/factory.js";export{Actor,BaseActor}from"./actors/actor.js";export{Component,ActorComponent,attach,Attach}from"./actors/component.js";export*from"./services/world.js";export*from"./services/render.js";export*from"./services/physics/physics-system.js";export*from"./animation/anim-sm.js";export*from"./animation/root-motion.js";export*from"./services/asset-loader.js";export*from"./services/pointer-events.js";export{VisualEffect}from"../effects/vfx/vfx-param.js";
|
2
2
|
/*
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
4
4
|
* See the LICENSE.md file for details.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Constructable, ContainerInstance } from "typedi";
|
2
|
-
import { ShaderType, ActorType } from '../shader/shader';
|
3
|
-
import { World } from
|
2
|
+
import { ShaderType, ActorType } from '../shader/shader.js';
|
3
|
+
import { World } from './services/world.js';
|
4
4
|
import { Observable } from 'rxjs';
|
5
5
|
type GameClass<T> = Constructable<T>;
|
6
6
|
export type InitiateGameConfig = {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import
|
1
|
+
import t from"typedi";import{loadScene as e}from"../scene/bootstrap.js";import{ActorFactory as s}from"./actors/factory.js";import{World as n}from"./services/world.js";import{ViewController as o}from"./services/render.js";import{RenderingView as r}from"../rendering.js";import{PhysicsSystem as i}from"./services/physics/physics-system.js";import{MeshComponent as a}from"./actors/builtin/components/mesh-component.js";import{activeContainerInstance as c}from"./actors/internal/container-map.js";import{InputService as m}from"./input/index.js";import{RuntimeBackendService as p}from"../scene/runtime-backend-service.js";import{RuntimeAssetsService as d}from"../scene/runtime-asset-service.js";import{AssetResourceLoader as h}from"../scene/asset-resource-loader.js";import{AssetLoader as l}from"./services/asset-loader.js";import{polyfillClient as u}from"./polyfill.js";import{Subject as f}from"rxjs";import{PointerEvents as w}from"./services/pointer-events.js";export function initiateGame(m,f){if(u(),0!=f.element.childNodes.length)return console.error("Can not initialize the game with a non-empty html element"),null;t.has(o);const g=t.of("default"),j=new HologyRuntime(g),v=new s(g,{inEditor:!1});var y;t.set(s,v),y=f.element,Object.assign(y.style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%"});const I=new r(f.element,{enableXR:!0===f.xr?.enabled});I.renderer.shadowMap.autoUpdate=!0,t.set(r,I);const S=new o(I);t.set(o,S);const b=new n(t.get(s));t.set(n,b);const x=new p(f.dataDir),D=new d(x),G=new h;G.setDataDir(f.dataDir);const H=Object.entries(f.shaders).map((([t,e])=>({name:t,type:e}))),R=new l(G,D,H);return t.set(l,R),(async()=>{const s=t.get(i);if(await s.start(),j.isShutdown)return;const{scene:n,actors:o}=await e(I,f.sceneName,f.dataDir,f.shaders,f.actors,v,x,D,G);if(b.scene=n,j.isShutdown)return void I.stop();t.import([a]);for(const t of o)b.addActor(t);s.addFromScene(n),I.loop((t=>{})),j.status=5,c.value=g,g.remove(m),g.set({id:m,type:m});const r=g.get(m);c.value=null,j.gameInstance=r,g.get(w).start(),r instanceof GameInstance&&r.onStart(),j._resolver(!0)})(),j}export class GameInstance{onStart(){}onShutdown(){}}export function createHologyScene(){}export class HologyRuntime{constructor(t){this.containerInstance=t,this.status=0,this.isShutdown=!1,this.shutdownStarted=new f,this.ready=new Promise((t=>{this._resolver=t}))}getWorld(){return this.containerInstance.get(n)}getService(t){return this.containerInstance.get(t)}shutdown(){this.isShutdown=!0,this.shutdownStarted.next(),this.gameInstance instanceof GameInstance&&this.gameInstance.onShutdown(),this.containerInstance.get(m).stop();const t=this.containerInstance.get(r);t?.stop();for(const t of this.getWorld().actors)this.getWorld().removeActor(t);this.containerInstance.get(i).stop(),this.containerInstance.get(w).stop(),this.containerInstance.reset()}}
|
2
2
|
/*
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
4
4
|
* See the LICENSE.md file for details.
|
package/dist/gameplay/inject.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import t from"typedi";import{activeContainerInstance as
|
1
|
+
import t from"typedi";import{activeContainerInstance as e}from"./actors/internal/container-map.js";export function inject(n){return e.value?.get(n)??t.get(n)}export function withInjectionContext(t,n){const o=e.value;e.value=t,n(t),e.value=o}
|
2
2
|
/*
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
4
4
|
* See the LICENSE.md file for details.
|
@@ -1,3 +1,3 @@
|
|
1
|
-
export * from './input-service';
|
2
|
-
export * from './input';
|
3
|
-
export * from './keybind';
|
1
|
+
export * from './input-service.js';
|
2
|
+
export * from './input.js';
|
3
|
+
export * from './keybind.js';
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Keybind, Mousebind, Wheelbind } from
|
1
|
+
import { Keybind, Mousebind, Wheelbind } from './keybind.js';
|
2
2
|
type InputCallback = (active: boolean | number) => void;
|
3
3
|
type DeltaCallback = (delta: number) => any;
|
4
4
|
type ToggleCallback = (active: boolean) => any;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{__decorate as e}from"tslib";import{Service as t}from"typedi";let s=class{constructor(){this.inputs=new Map,this.deltaCallbacks=new Map,this.toggleCallbacks=new Map,this.keybinds=new Map,this.mousebinds=new Map,this.touchmoveBinds=new Map,this.wheelbinds=new Map,this.onKeyDown=e=>{this.keybinds.forEach(((t,s)=>{for(const 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)=>{
|
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)=>{const n=this.inputs.get(s)??this.deltaCallbacks.get(s);if(null!=n)switch(t.axis){case"x":n(e.movementX*t.multiplier);break;case"y":n(e.movementY*t.multiplier)}else console.warn("No input callback for registered for mouse bind "+t.axis)}))},this.onTouchMove=e=>{const t=e.touches[0];null!=t&&(null!=this.prevTouchEvent&&t.identifier===this.prevTouchEvent.identifier?(this.touchmoveBinds.forEach(((e,s)=>{const n=this.inputs.get(s)??this.deltaCallbacks.get(s);if(null!=n)switch(e.axis){case"x":n((t.clientX-this.prevTouchEvent.clientX)*e.multiplier);break;case"y":n((t.clientY-this.prevTouchEvent.clientY)*e.multiplier)}else console.warn("No input callback for registered for mouse bind "+e.axis)})),this.prevTouchEvent=t):this.prevTouchEvent=e.touches[0])},this.onWheel=e=>{this.wheelbinds.forEach(((t,s)=>{const n=this.inputs.get(s)??this.deltaCallbacks.get(s);null!=n?n(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.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{Euler as t,Vector2 as i}from"three";import{
|
1
|
+
import{Euler as t,Vector2 as i}from"three";import{ArrayMap as s}from"../../utils/collections.js";import{clamp as o}from"../../utils/math.js";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 s}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,s){super(),this.min=i,this.max=s,this.rotation=new t,this.rotateX=t=>{this.rotation.x=o(this.rotation.x+t,this.min,this.max)},this.rotateY=t=>{this.rotation.y=o(this.rotation.y+t,this.min,this.max)},this.rotateZ=t=>{this.rotation.z=o(this.rotation.z+t,this.min,this.max)}}}export class DecimalInput{constructor(t=0,i,s){this.min=i,this.max=s,this.increment=t=>{this.value=o(this.value+t,this.min,this.max)},this.value=t}}
|
2
2
|
/*
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
4
4
|
* See the LICENSE.md file for details.
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import { AssetResourceLoader, LoadedMesh } from
|
2
|
-
import { AssetsProvider } from
|
3
|
-
import { AssetId } from
|
1
|
+
import { AssetResourceLoader, LoadedMesh } from '../../scene/asset-resource-loader.js';
|
2
|
+
import { AssetsProvider } from '../../scene/assets-provider.js';
|
3
|
+
import { AssetId } from '../../scene/model.js';
|
4
4
|
import { GLTF } from "three-stdlib";
|
5
5
|
import { Material } from "three";
|
6
|
-
import { ShaderImpl } from
|
6
|
+
import { ShaderImpl } from '../../shader/shader.js';
|
7
7
|
import * as THREE from 'three';
|
8
8
|
export declare class AssetLoader {
|
9
9
|
protected assetResourceLoader: AssetResourceLoader;
|
@@ -37,5 +37,5 @@ export declare class AssetLoader {
|
|
37
37
|
getModelByAssetId(id: AssetId): Promise<LoadedMesh>;
|
38
38
|
getTextureByAssetId(id: AssetId): Promise<THREE.Texture>;
|
39
39
|
getMaterialByAssetId(id: AssetId): Promise<Material>;
|
40
|
-
getAsset(id: AssetId): Promise<import("../../scene/model").Asset>;
|
40
|
+
getAsset(id: AssetId): Promise<import("../../scene/model.js").Asset>;
|
41
41
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import{AssetResourceLoader as s}from"../../scene/asset-resource-loader.js";import{FBXLoader as r,GLTFLoader as a,MTLLoader as i,OBJLoader as o,TGALoader as n}from"three-stdlib";import{AudioLoader as h,LoadingManager as l,TextureLoader as d}from"three";import{pathJoin as c}from"../../utils/files.js";import{Service as u}from"typedi";import{materialFromAsset as g}from"../../scene/materializer.js";let f=class{constructor(e,t,s){this.assetResourceLoader=e,this.assetService=t,this.shaders=s,this.baseUrl="",this.urlSuffix="",this.loadingManager=new l,this.glbLoader=new a(this.loadingManager),this.fbxLoader=new r(this.loadingManager),this.objLoader=new o(this.loadingManager),this.mtlLoader=new i(this.loadingManager),this.tgaLoader=new n(this.loadingManager),this.textureLoader=new d(this.loadingManager),this.audioLoader=new h(this.loadingManager)}resolvePath(e){return c(this.baseUrl,e)+this.urlSuffix}async getModelAtPath(e){const t=this.resolvePath(e);switch(e.split(".").pop().toLowerCase()){case"glb":case"gltf":return(await this.glbLoader.loadAsync(t)).scene;case"fbx":return this.fbxLoader.loadAsync(t);case"obj":return this.objLoader.loadAsync(t);default:throw new Error(`File suffix is not supperted in file ${e}`)}}async geGltfAtPath(e){const t=this.resolvePath(e);return this.glbLoader.loadAsync(t)}async getModelByAssetName(e){const t=(await this.assetService.getAssets()).find((t=>t.name===e));if(null==t)throw new Error(`No model could be found with asset name ${e}`);return this.assetResourceLoader.getMesh(t)}async getModelByAssetId(e){const t=await this.assetService.getAsset(e);if(null==t)throw new Error(`No model could be found with asset id ${e}`);return this.assetResourceLoader.getMesh(t)}async getTextureByAssetId(e){const t=await this.assetService.getAsset(e);if(null==t)throw new Error(`No texture could be found with asset id ${e}`);return this.assetResourceLoader.getTexture(t)}async getMaterialByAssetId(e){const t=await this.assetService.getAsset(e);if(null==t)throw new Error(`No material could be found with asset id ${e}`);return g(t,null,this.assetService,this.assetResourceLoader,this.shaders,!1)}async getAsset(e){return this.assetService.getAsset(e)}};f=e([u(),t("design:paramtypes",[s,Object,Array])],f);export{f as AssetLoader};
|
2
2
|
/*
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
4
4
|
* See the LICENSE.md file for details.
|
@@ -3,11 +3,11 @@ import { RayColliderIntersection } from "@dimforge/rapier3d-compat";
|
|
3
3
|
import { Observable, Subject } from "rxjs";
|
4
4
|
import * as THREE from "three";
|
5
5
|
import { ColorRepresentation, Object3D, Vector3 } from "three";
|
6
|
-
import { CollisionShape } from
|
7
|
-
import { AbstractType } from
|
8
|
-
import { BaseActor } from '../../actors/actor';
|
9
|
-
import { ViewController } from
|
10
|
-
import { World } from
|
6
|
+
import { CollisionShape } from '../../../index.js';
|
7
|
+
import { AbstractType } from '../../../utils/type.js';
|
8
|
+
import { BaseActor } from '../../actors/actor.js';
|
9
|
+
import { ViewController } from '../render.js';
|
10
|
+
import { World } from '../world.js';
|
11
11
|
export declare class RayTestResult {
|
12
12
|
_internal: RayColliderIntersection;
|
13
13
|
actor: BaseActor;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{__awaiter as t,__decorate as e,__metadata as i}from"tslib";import*as s from"@dimforge/rapier3d-compat";import{QueryFilterFlags as o}from"@dimforge/rapier3d-compat";import{Quaternion as n,RaycastResult as r,Vec3 as a}from"cannon-es";import{BehaviorSubject as l,distinctUntilChanged as d,filter as c,map as h,Subject as u,takeUntil as y}from"rxjs";import*as p from"three";import{ArrowHelper as g,BufferAttribute as m,BufferGeometry as v,Group as f,LineSegments as w,Matrix4 as x,MeshBasicMaterial as b,Object3D as B,Raycaster as A,Scene as C,Vector3 as D}from"three";import{Service as z}from"typedi";import{AssetMeshInstance as T}from"../../../scene/asset-resource-loader";import{BoxCollisionShape as M,CapsuleCollisionShape as E,ConeCollisionShape as S,ConvexPolyhedronCollisionShape as R,CylinderCollisionShape as W,PhysicalShapeMesh as _,PlaneCollisionShape as V,SphereCollisionShape as F,TrimeshCollisionShape as P}from"../../../";import{LandscapeGroup as k}from"../../../scene/landscape/landscape";import{ViewController as I}from"../render";import{World as L}from"../world";import*as O from"three/examples/jsm/utils/BufferGeometryUtils.js";import{calculateEffectiveScale as N}from"../../../utils/three/traverse";export class RayTestResult{constructor(){this.hasHit=!1,this.hitPoint=new D,this.hitNormal=new D}}new r,new a,new a;export var PhysicsBodyType;!function(t){t[t.dynamic=1]="dynamic",t[t.static=2]="static",t[t.kinematic=4]="kinematic",t[t.kinematicVelocityBased=8]="kinematicVelocityBased"}(PhysicsBodyType||(PhysicsBodyType={}));let j=class{set showDebug(t){this.shouldRenderDebug=t,this.debugMesh&&(this.debugMesh.visible=t)}get showDebug(){return this.shouldRenderDebug}constructor(t,e){this.viewController=t,this.gameWorld=e,this.staticMeshes=new Map,this.staticBodies=new Map,this.actorBodies=new Map,this.bodyActors=new Map,this.collisionEvents=new u,this.beforeStep=new u,this.afterStep=new u,this.shouldRenderDebug=!1,this._raycaster=new A,this._reusableResult=new RayTestResult,this._raytestDiff=new D,this._raytestDirection=new D,this.controlledActors=new Set,this.ready=this.setup()}createDebugMesh(){return new w(new v,new b({color:255}))}start(){return t(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 t=this.world.debugRender();this.debugMesh.geometry.setAttribute("position",new m(t.vertices,3))}setup(){return t(this,void 0,void 0,(function*(){if(null!=this.rapier)throw new Error("Rapier is already estup");this.rapier=yield J(),this.eventQueue=new s.EventQueue(!0),this.setupWorld()}))}handleTick(){this.fixedupdateSub=this.viewController.onUpdate().subscribe((t=>{t=Math.min(.1,t),this.beforeStep.next(t),this.updatePhysics(t),this.afterStep.next(t),this.showDebug&&this.renderDebug(),this.world.bodies.forEach((t=>{var e,i,s;if(t.isFixed())return;const o=null!==(e=this.staticMeshes.get(t))&&void 0!==e?e:null===(i=this.bodyActors.get(t))||void 0===i?void 0:i.object;var n,r;null!=o&&(o.parent instanceof C&&(Z(o.position,t.translation()),(t.isDynamic()||t.isKinematic()&&!this.controlledActors.has(null===(s=this.bodyActors.get(t))||void 0===s?void 0:s.id))&&(n=o.quaternion,r=t.rotation(),n.x=r.x,n.y=r.y,n.z=r.z,n.w=r.w)))}))}))}_updateWorld(){this.world.timestep=0,this.world.step()}updatePhysics(t){this.world.timestep=t,this.world.step(this.eventQueue),this.eventQueue.drainCollisionEvents(((t,e,i)=>{this.collisionEvents.next({handle1:t,handle2:e,started:i}),this.collisionEvents.next({handle1:e,handle2:t,started:i})}))}rayTestFromCamera(t,e,i){this._raycaster.setFromCamera(X,this.viewController.getCamera());const s=this._raycaster.ray.origin,o=this._raycaster.ray.direction.multiplyScalar(t).add(s);return this.rayTest(s,o,e,i)}rayTest(t,e,i,o){var n,r;null==i&&(i=this._reusableResult);const a=this._raytestDiff,l=this._raytestDirection;if(a.subVectors(e,t),l.copy(a).normalize(),0===l.length())return console.warn("Ray test called with to and from being equal"),i;const d=new s.Ray(t,l),c=a.length(),h=this.world.castRayAndGetNormal(d,c,!1,void 0,void 0,void 0,null!=(null==o?void 0:o.excludeActor)?this.actorBodies.get(o.excludeActor.id):void 0);if(i.hasHit=null!=h,i.hasHit){const e=d.pointAt(h.toi);i._internal=h,Z(i.hitNormal,h.normal),Z(i.hitPoint,e),i.distance=tt.subVectors(i.hitPoint,t).length();const s=this.world.bodies.getAll().find((t=>function(t,e){for(let i=0,s=t.numColliders();i<s;i++){const s=t.collider(i);if(e(s))return s}}(t,(t=>t===h.collider))));i.actor=null!=s?this.bodyActors.get(s):null}if(this.showDebug){const e=new g(l,t,c,null!==(n=null==o?void 0:o.debugColor)&&void 0!==n?n:255);this.gameWorld.scene.add(e),setTimeout((()=>this.gameWorld.scene.remove(e)),null!==(r=null==o?void 0:o.debugLifetime)&&void 0!==r?r:200)}return this._reusableResult}setGravity(t,e,i){this.world.gravity.x=t,this.world.gravity.y=e,this.world.gravity.z=i}getGravity(){return H.set(this.world.gravity.x,this.world.gravity.y,this.world.gravity.z)}addFromScene(t){this.addRecursively(t);for(const t of this.staticBodies.values())$(t,(t=>t.setActiveEvents(s.ActiveEvents.COLLISION_EVENTS)))}addRecursively(t){var e,i;if(this.removeSceneObject(t),!function(t){var e,i;if(null!=(null===(e=t.userData)||void 0===e?void 0:e.src)){return"actor"===(null===(i=t.userData)||void 0===i?void 0:i.src).type}return!1}(t))if(t instanceof _&&null!=t.collisionShape){const e=this.createStaticBody(t,[t.collisionShape]);this.staticMeshes.set(e,t),this.staticBodies.set(t,e)}else if(t instanceof T&&!1!==(null===(i=null===(e=t.userData)||void 0===e?void 0:e.src)||void 0===i?void 0:i.collisionDetection))if(t.children[0]&&t.children[0].instanceMatrix)this.createForInstancedMesh(t.children[0],t.collisionShapes);else{const e=this.createStaticBody(t,t.collisionShapes);this.staticMeshes.set(e,t),this.staticBodies.set(t,e)}else t instanceof k?this.addLandscapeGroup(t):(t instanceof f||t instanceof C)&&t.children.forEach((t=>this.addRecursively(t)))}createForInstancedMesh(t,e){const i=new x;for(let s=0;s<t.count;s++){const o=new B;o.matrix.identity(),i.fromArray(t.instanceMatrix.array,16*s),o.applyMatrix4(i);this.createStaticBody(o,e)}}getCharacterController(t=.01){var e;return null===(e=this.world)||void 0===e?void 0:e.createCharacterController(t)}getActorComputedMovement(t,e,i){const s=this.actorBodies.get(t.id);this.controlledActors.add(t.id);const n=s.collider(0);e.computeColliderMovement(n,i,o.EXCLUDE_SENSORS,null,it);const r=e.computedMovement();return Z(et,r),et}setNextKinematicTranslation(t,e){const i=this.actorBodies.get(t.id),s=i.translation();s.x+=e.x,s.y+=e.y,s.z+=e.z,null==i||i.setNextKinematicTranslation(s)}setAngularVelocity(t,e){const i=this.actorBodies.get(t.id);U.x=e.x,U.y=e.y,U.z=e.z,null==i||i.setAngvel(U,!0)}setLinearVelocity(t,e){const i=this.actorBodies.get(t.id);U.x=e.x,U.y=e.y,U.z=e.z,null==i||i.setLinvel(U,!0)}getLinearVelocity(t,e=new D){const i=this.actorBodies.get(t.id).linvel();return e.x=i.x,e.y=i.y,e.z=i.z,e}getAngularVelocity(t,e=new D){const i=this.actorBodies.get(t.id).angvel();return e.x=i.x,e.y=i.y,e.z=i.z,e}setLinearDamping(t,e){const i=this.actorBodies.get(t.id);null==i||i.setLinearDamping(e)}setAngularDamping(t,e){const i=this.actorBodies.get(t.id);null==i||i.setAngularDamping(e)}createCharacterCollision(){return new s.CharacterCollision}addLandscapeGroup(t){const e=t.userData.src,i=e.landscape.heightMaps;for(const n of t.sections){this.staticBodies.has(n)&&this.world.removeRigidBody(this.staticBodies.get(n));const t=e.landscape.options.density+1,r=e.landscape.options.sectionSize,a=new Array(t);for(let e=0;e<t;e++)a[e]=new Array(t).fill(0);const l=i.find((t=>t.x===n.x&&t.y==n.y));if(null!=l)for(const e of l.points){if(null==a[e.i%t])continue;const i=t-1-Math.floor(e.i/t);i in a[e.i%t]?a[e.i%t][i]=e.y/r:console.warn("wrong index",{points:a,point:e,i:e.i%t,k:i,heightMap:l})}const d=e.landscape.options.density,c=a.flatMap((t=>t.reverse())),h=s.ColliderDesc.heightfield(d,d,new Float32Array(c),new s.Vector3(r,r,r));var o=n.getWorldPosition(new D);const u=this.world.createRigidBody(s.RigidBodyDesc.fixed()),y=new s.Vector3(0,0,0);Y(y,o),u.setTranslation(y,!1),this.world.createCollider(h,u),this.staticBodies.set(n,u)}}addActor(t,e,i={}){var o,n;if(0==e.length)return void console.error("No collision shapes were defined when adding actor to the physics system.");this.removeActor(t);const r=t.object;let a;switch(null!==(o=i.type)&&void 0!==o?o:PhysicsBodyType.static){case PhysicsBodyType.dynamic:a=s.RigidBodyDesc.dynamic(),a.mass=null!==(n=i.mass)&&void 0!==n?n:1;break;case PhysicsBodyType.kinematic:a=s.RigidBodyDesc.kinematicPositionBased();break;case PhysicsBodyType.kinematicVelocityBased:a=s.RigidBodyDesc.kinematicVelocityBased();break;default:a=(i.isTrigger,s.RigidBodyDesc.kinematicVelocityBased())}const l=this.world.createRigidBody(a);l.enableCcd(1==i.continousCollisionDetection);for(const t of e)this.addShape(l,t,r);$(l,(t=>{null!=i.isTrigger&&(t.setSensor(i.isTrigger),t.setActiveCollisionTypes(s.ActiveCollisionTypes.ALL),t.setActiveEvents(s.ActiveEvents.COLLISION_EVENTS)),null!=i.friction&&t.setFriction(i.friction),null!=i.restitution&&t.setDensity(i.restitution),null!=i.mass&&t.setMass(i.mass),null!=i.restitution&&t.setRestitution(i.restitution)})),Q(l,r),this.actorBodies.set(t.id,l),this.bodyActors.set(l,t)}applyTorque(t,e){const i=this.actorBodies.get(t.id);U.x=e.x,U.y=e.y,U.z=e.z,null==i||i.addTorque(U,!0)}applyTorqueImpulse(t,e){const i=this.actorBodies.get(t.id);U.x=e.x,U.y=e.y,U.z=e.z,null==i||i.applyTorqueImpulse(U,!0)}resetForces(t){const e=this.actorBodies.get(t.id);null==e||e.resetForces(!1)}resetTorques(t){const e=this.actorBodies.get(t.id);null==e||e.resetTorques(!1)}applyForce(t,e){const i=this.actorBodies.get(t.id);U.x=e.x,U.y=e.y,U.z=e.z,null==i||i.addForce(U,!0)}applyImpulse(t,e){const i=this.actorBodies.get(t.id);U.x=e.x,U.y=e.y,U.z=e.z,null==i||i.applyImpulse(U,!0)}applyLocalForce(t,e,i){const s=this.actorBodies.get(t.id);Y(U,e),null==i?null==s||s.addForce(U,!0):(Y(K,i),null==s||s.addForceAtPoint(U,K,!0))}applyLocalImpulse(t,e,i){const s=this.actorBodies.get(t.id);Y(U,e),null==i?s.applyImpulse(U,!0):(Y(K,i),s.applyImpulseAtPoint(U,K,!0))}removeActor(t){this.controlledActors.delete(t.id);const e=this.actorBodies.get(t.id);null!=e&&(this.bodyActors.delete(e),this.world.removeRigidBody(e)),this.actorBodies.delete(t.id)}removeSceneObject(t){let e=this.staticBodies.get(t);null!=e&&this.world.getRigidBody(e.handle)&&this.world.removeRigidBody(e)}activateActorEvents(t){this.actorBodies.get(t.id)}_onCollisionWithActorEvent(t,e,i){return this.activateActorEvents(t),this.collisionEvents.pipe(y(t.disposed),c((({started:t})=>t===i)),h((({handle1:t,handle2:e,started:i})=>({a1:this.bodyActors.get(this.world.getCollider(t).parent()),a2:this.bodyActors.get(this.world.getCollider(e).parent()),started:i}))),c((({a1:i,a2:s})=>null!=i&&null!=s&&i.id===t.id&&e(i,s))),h((({a2:t})=>t)))}onBeginContact(t){return this.activateActorEvents(t),this.collisionEvents.pipe(y(t.disposed),c((t=>t.started)),c((({handle1:e})=>{const i=this.bodyActors.get(this.world.getCollider(e).parent());return null!=i&&i.id===t.id})),h((t=>t.handle2)))}onEndContact(t){return this.activateActorEvents(t),this.collisionEvents.pipe(y(t.disposed),c((t=>!t.started)),c((({handle1:e})=>{const i=this.bodyActors.get(this.world.getCollider(e).parent());return null!=i&&i.id===t.id})),h((t=>t.handle2)))}onHasContactChanged(t){const e=new Set,i=new l(!1);return this.onBeginContact(t).subscribe((t=>{e.add(t),i.next(e.size>0)})),this.onEndContact(t).subscribe((t=>{e.delete(t),i.next(e.size>0)})),i.pipe(d())}onBeginOverlapWithActorType(t,e){return this._onCollisionWithActorEvent(t,((t,i)=>i instanceof e),!0)}onEndOverlapWithActorType(t,e){return this._onCollisionWithActorEvent(t,((t,i)=>i instanceof e),!1)}onBeginOverlapWithActor(t,e){return this._onCollisionWithActorEvent(t,((t,i)=>e.id===i.id),!0)}onEndOverlapWithActor(t,e){return this._onCollisionWithActorEvent(t,((t,i)=>e.id===i.id),!1)}onCollisionWithActor(t,e){return this.onBeginOverlapWithActor(t,e)}onCollisionWithActorType(t,e){return this.onBeginOverlapWithActorType(t,e)}updateActorTransform(t){const e=this.actorBodies.get(t.id);null!=e?Q(e,t.object):console.warn("Actor has not been added to physics world",t)}setupWorld(){const t=new s.World({x:0,y:-9.81,z:0});this.world=t,t.maxVelocityIterations=4}getActorContacts(t,e){const i=this.actorBodies.get(t.id);if(i&&i.numColliders()>0){const o=i.collider(0);let n=o.shape,r=o.translation(),a=o.rotation(),l=e,d=.3;const c=this.world.castShape(r,a,l,n,d,!0,null,null,null,this.actorBodies.get(t.id),(t=>t.shape.type!=s.ShapeType.HeightField));if(null!=c){const t=new D,e=new D,i=new D;return Z(t,c.witness2),Z(e,c.witness1),Z(i,c.normal1),i.negate(),[{ri:t,rj:e,ni:i}]}return[]}return console.warn("Actor is not added to the physics system"),[]}stop(){var t,e,i;null===(t=this.world)||void 0===t||t.bodies.forEach((t=>this.world.removeRigidBody(t))),null===(e=this.world)||void 0===e||e.free(),null===(i=this.fixedupdateSub)||void 0===i||i.unsubscribe()}createStaticBody(t,e){const i=this.world.createRigidBody(s.RigidBodyDesc.kinematicPositionBased());for(const s of e)this.addShape(i,s,t);return Q(i,t),i}addShape(t,e,i){const s=this.createShape(e,i.scale);s.friction=.1;const o=e.offset.clone().multiply(i.scale);var r,a;Y(s.translation,o),r=s.rotation,a=(new n).setFromEuler(e.rotation.x,e.rotation.y,e.rotation.z),r.x=a.x,r.y=a.y,r.z=a.z,r.w=a.w;this.world.createCollider(s,t)}createShape(t,e){if(t instanceof M)return s.ColliderDesc.cuboid(t.dimensions.x*e.x/2,t.dimensions.y*e.y/2,t.dimensions.z*e.z/2);if(t instanceof E){return s.ColliderDesc.capsule(t.length/2*e.y,t.radius*Math.max(e.z,e.x))}if(t instanceof P){const e=null!=t.geometry.getIndex()?t.geometry:O.mergeVertices(t.geometry);return s.ColliderDesc.trimesh(new Float32Array(e.getAttribute("position").array),new Uint32Array(e.getIndex().array))}if(t instanceof R){let i;t.mesh instanceof p.Mesh?i=t.mesh.geometry:t.mesh instanceof p.BufferGeometry?i=t.mesh:console.log("Unknownd shape",{shapeInfo:t});const o=new Float32Array(i.getAttribute("position").array);if(t.mesh instanceof p.Mesh){const e=N(t.mesh);for(let t=0;t<o.length;t+=3)o[t]*=e.x,o[t+1]*=e.y,o[t+2]*=e.z}for(let t=0;t<o.length;t+=3)o[t]*=e.x,o[t+1]*=e.y,o[t+2]*=e.z;return s.ColliderDesc.convexHull(o)}return t instanceof F?s.ColliderDesc.ball(t.radius*Math.max(e.x,e.y,e.z)):t instanceof W?s.ColliderDesc.cylinder(t.height/2*e.y,t.radiusTop*Math.max(e.z,e.x)):t instanceof S?s.ColliderDesc.cone(t.height*e.y,t.radiusBottom/2*Math.max(e.z,e.x)):t instanceof V?s.ColliderDesc.cuboid(t.width/2*e.x,t.height/2*e.y,.01):(console.error("Unsupported shape",t),s.ColliderDesc.cuboid(1,1,1))}};j=e([z(),i("design:paramtypes",[I,L])],j);export{j as PhysicsSystem};const q=new D,G=new p.Quaternion;function Q(t,e){const i=e.getWorldPosition(q),o=e.getWorldQuaternion(G);t.setTranslation(new s.Vector3(i.x,i.y,i.z),!1),t.setRotation(new s.Quaternion(o.x,o.y,o.z,o.w),!1)}const H=new D,U=new s.Vector3(0,0,0),K=new s.Vector3(0,0,0),X=(new D,{x:0,y:0}),J=()=>t(void 0,void 0,void 0,(function*(){let t=yield import("@dimforge/rapier3d-compat");return yield t.init(),t}));function Y(t,e){t.x=e.x,t.y=e.y,t.z=e.z}function Z(t,e){t.x=e.x,t.y=e.y,t.z=e.z}function $(t,e){for(let i=0,s=t.numColliders();i<s;i++){e(t.collider(i))}}const tt=new D,et=new D,it=t=>!t.isSensor();
|
1
|
+
import{__decorate as t,__metadata as e}from"tslib";import*as i from"@dimforge/rapier3d-compat";import{QueryFilterFlags as s}from"@dimforge/rapier3d-compat";import{BehaviorSubject as o,distinctUntilChanged as r,filter as n,map as a,Subject as c,takeUntil as l}from"rxjs";import*as d from"three";import{ArrowHelper as h,BufferAttribute as u,BufferGeometry as y,Group as p,LineSegments as g,Matrix4 as m,MeshBasicMaterial as f,Object3D as w,Quaternion as v,Raycaster as x,Scene as b,Vector3 as B}from"three";import{Service as A}from"typedi";import{AssetMeshInstance as C}from"../../../scene/asset-resource-loader.js";import{BoxCollisionShape as D,CapsuleCollisionShape as z,ConeCollisionShape as T,ConvexPolyhedronCollisionShape as M,CylinderCollisionShape as E,PhysicalShapeMesh as S,PlaneCollisionShape as R,SphereCollisionShape as W,TrimeshCollisionShape as _}from"../../../index.js";import{LandscapeGroup as V}from"../../../scene/landscape/landscape.js";import{ViewController as F}from"../render.js";import{World as P}from"../world.js";import*as k from"three/examples/jsm/utils/BufferGeometryUtils.js";import{calculateEffectiveScale as I}from"../../../utils/three/traverse.js";export class RayTestResult{constructor(){this.hasHit=!1,this.hitPoint=new B,this.hitNormal=new B}}export var PhysicsBodyType;!function(t){t[t.dynamic=1]="dynamic",t[t.static=2]="static",t[t.kinematic=4]="kinematic",t[t.kinematicVelocityBased=8]="kinematicVelocityBased"}(PhysicsBodyType||(PhysicsBodyType={}));let L=class{set showDebug(t){this.shouldRenderDebug=t,this.debugMesh&&(this.debugMesh.visible=t)}get showDebug(){return this.shouldRenderDebug}constructor(t,e){this.viewController=t,this.gameWorld=e,this.staticMeshes=new Map,this.staticBodies=new Map,this.actorBodies=new Map,this.bodyActors=new Map,this.collisionEvents=new c,this.beforeStep=new c,this.afterStep=new c,this.shouldRenderDebug=!1,this._raycaster=new x,this._reusableResult=new RayTestResult,this._raytestDiff=new B,this._raytestDirection=new B,this.controlledActors=new Set,this.ready=this.setup()}createDebugMesh(){return new g(new y,new f({color:255}))}async start(){return await this.ready,this.handleTick(),this.ready}renderDebug(){null==this.debugMesh&&(this.debugMesh=this.createDebugMesh(),this.debugMesh.visible=this.shouldRenderDebug,this.debugMesh.raycast=function(){},this.gameWorld.scene.add(this.debugMesh));const t=this.world.debugRender();this.debugMesh.geometry.setAttribute("position",new u(t.vertices,3))}async setup(){if(null!=this.rapier)throw new Error("Rapier is already estup");this.rapier=await U(),this.eventQueue=new i.EventQueue(!0),this.setupWorld()}handleTick(){this.fixedupdateSub=this.viewController.onUpdate().subscribe((t=>{t=Math.min(.1,t),this.beforeStep.next(t),this.updatePhysics(t),this.afterStep.next(t),this.showDebug&&this.renderDebug(),this.world.bodies.forEach((t=>{if(t.isFixed())return;const e=this.staticMeshes.get(t)??this.bodyActors.get(t)?.object;var i,s;null!=e&&(e.parent instanceof b&&(X(e.position,t.translation()),(t.isDynamic()||t.isKinematic()&&!this.controlledActors.has(this.bodyActors.get(t)?.id))&&(i=e.quaternion,s=t.rotation(),i.x=s.x,i.y=s.y,i.z=s.z,i.w=s.w)))}))}))}_updateWorld(){this.world.timestep=0,this.world.step()}updatePhysics(t){this.world.timestep=t,this.world.step(this.eventQueue),this.eventQueue.drainCollisionEvents(((t,e,i)=>{this.collisionEvents.next({handle1:t,handle2:e,started:i}),this.collisionEvents.next({handle1:e,handle2:t,started:i})}))}rayTestFromCamera(t,e,i){this._raycaster.setFromCamera(H,this.viewController.getCamera());const s=this._raycaster.ray.origin,o=this._raycaster.ray.direction.multiplyScalar(t).add(s);return this.rayTest(s,o,e,i)}rayTest(t,e,s,o){null==s&&(s=this._reusableResult);const r=this._raytestDiff,n=this._raytestDirection;if(r.subVectors(e,t),n.copy(r).normalize(),0===n.length())return console.warn("Ray test called with to and from being equal"),s;const a=new i.Ray(t,n),c=r.length(),l=this.world.castRayAndGetNormal(a,c,!1,void 0,void 0,void 0,null!=o?.excludeActor?this.actorBodies.get(o.excludeActor.id):void 0);if(s.hasHit=null!=l,s.hasHit){const e=a.pointAt(l.toi);s._internal=l,X(s.hitNormal,l.normal),X(s.hitPoint,e),s.distance=Y.subVectors(s.hitPoint,t).length();const i=this.world.bodies.getAll().find((t=>function(t,e){for(let i=0,s=t.numColliders();i<s;i++){const s=t.collider(i);if(e(s))return s}}(t,(t=>t===l.collider))));s.actor=null!=i?this.bodyActors.get(i):null}if(this.showDebug){const e=new h(n,t,c,o?.debugColor??255);this.gameWorld.scene.add(e),setTimeout((()=>this.gameWorld.scene.remove(e)),o?.debugLifetime??200)}return this._reusableResult}setGravity(t,e,i){this.world.gravity.x=t,this.world.gravity.y=e,this.world.gravity.z=i}getGravity(){return q.set(this.world.gravity.x,this.world.gravity.y,this.world.gravity.z)}addFromScene(t){this.addRecursively(t);for(const t of this.staticBodies.values())J(t,(t=>t.setActiveEvents(i.ActiveEvents.COLLISION_EVENTS)))}addRecursively(t){if(this.removeSceneObject(t),!function(t){if(null!=t.userData?.src){const e=t.userData?.src;return"actor"===e.type}return!1}(t))if(t instanceof S&&null!=t.collisionShape){const e=this.createStaticBody(t,[t.collisionShape]);this.staticMeshes.set(e,t),this.staticBodies.set(t,e)}else if(t instanceof C&&!1!==t.userData?.src?.collisionDetection)if(t.children[0]&&t.children[0].instanceMatrix)this.createForInstancedMesh(t.children[0],t.collisionShapes);else{const e=this.createStaticBody(t,t.collisionShapes);this.staticMeshes.set(e,t),this.staticBodies.set(t,e)}else t instanceof V?this.addLandscapeGroup(t):(t instanceof p||t instanceof b)&&t.children.forEach((t=>this.addRecursively(t)))}createForInstancedMesh(t,e){const i=new m;for(let s=0;s<t.count;s++){const o=new w;o.matrix.identity(),i.fromArray(t.instanceMatrix.array,16*s),o.applyMatrix4(i);this.createStaticBody(o,e)}}getCharacterController(t=.01){return this.world?.createCharacterController(t)}getActorComputedMovement(t,e,i){const o=this.actorBodies.get(t.id);this.controlledActors.add(t.id);const r=o.collider(0);e.computeColliderMovement(r,i,s.EXCLUDE_SENSORS,null,$);const n=e.computedMovement();return X(Z,n),Z}setNextKinematicTranslation(t,e){const i=this.actorBodies.get(t.id),s=i.translation();s.x+=e.x,s.y+=e.y,s.z+=e.z,i?.setNextKinematicTranslation(s)}setAngularVelocity(t,e){const i=this.actorBodies.get(t.id);G.x=e.x,G.y=e.y,G.z=e.z,i?.setAngvel(G,!0)}setLinearVelocity(t,e){const i=this.actorBodies.get(t.id);G.x=e.x,G.y=e.y,G.z=e.z,i?.setLinvel(G,!0)}getLinearVelocity(t,e=new B){const i=this.actorBodies.get(t.id).linvel();return e.x=i.x,e.y=i.y,e.z=i.z,e}getAngularVelocity(t,e=new B){const i=this.actorBodies.get(t.id).angvel();return e.x=i.x,e.y=i.y,e.z=i.z,e}setLinearDamping(t,e){const i=this.actorBodies.get(t.id);i?.setLinearDamping(e)}setAngularDamping(t,e){const i=this.actorBodies.get(t.id);i?.setAngularDamping(e)}createCharacterCollision(){return new i.CharacterCollision}addLandscapeGroup(t){const e=t.userData.src,s=e.landscape.heightMaps;for(const r of t.sections){this.staticBodies.has(r)&&this.world.removeRigidBody(this.staticBodies.get(r));const t=e.landscape.options.density+1,n=e.landscape.options.sectionSize,a=new Array(t);for(let e=0;e<t;e++)a[e]=new Array(t).fill(0);const c=s.find((t=>t.x===r.x&&t.y==r.y));if(null!=c)for(const e of c.points){if(null==a[e.i%t])continue;const i=t-1-Math.floor(e.i/t);i in a[e.i%t]?a[e.i%t][i]=e.y/n:console.warn("wrong index",{points:a,point:e,i:e.i%t,k:i,heightMap:c})}const l=e.landscape.options.density,d=a.flatMap((t=>t.reverse())),h=i.ColliderDesc.heightfield(l,l,new Float32Array(d),new i.Vector3(n,n,n));var o=r.getWorldPosition(new B);const u=this.world.createRigidBody(i.RigidBodyDesc.fixed()),y=new i.Vector3(0,0,0);K(y,o),u.setTranslation(y,!1),this.world.createCollider(h,u),this.staticBodies.set(r,u)}}addActor(t,e,s={}){if(0==e.length)return void console.error("No collision shapes were defined when adding actor to the physics system.");this.removeActor(t);const o=t.object;let r;switch(s.type??PhysicsBodyType.static){case PhysicsBodyType.dynamic:r=i.RigidBodyDesc.dynamic(),r.mass=s.mass??1;break;case PhysicsBodyType.kinematic:r=i.RigidBodyDesc.kinematicPositionBased();break;case PhysicsBodyType.kinematicVelocityBased:r=i.RigidBodyDesc.kinematicVelocityBased();break;default:r=(s.isTrigger,i.RigidBodyDesc.kinematicVelocityBased())}const n=this.world.createRigidBody(r);n.enableCcd(1==s.continousCollisionDetection);for(const t of e)this.addShape(n,t,o);J(n,(t=>{null!=s.isTrigger&&(t.setSensor(s.isTrigger),t.setActiveCollisionTypes(i.ActiveCollisionTypes.ALL),t.setActiveEvents(i.ActiveEvents.COLLISION_EVENTS)),null!=s.friction&&t.setFriction(s.friction),null!=s.restitution&&t.setDensity(s.restitution),null!=s.mass&&t.setMass(s.mass),null!=s.restitution&&t.setRestitution(s.restitution)})),N(n,o),this.actorBodies.set(t.id,n),this.bodyActors.set(n,t)}applyTorque(t,e){const i=this.actorBodies.get(t.id);G.x=e.x,G.y=e.y,G.z=e.z,i?.addTorque(G,!0)}applyTorqueImpulse(t,e){const i=this.actorBodies.get(t.id);G.x=e.x,G.y=e.y,G.z=e.z,i?.applyTorqueImpulse(G,!0)}resetForces(t){const e=this.actorBodies.get(t.id);e?.resetForces(!1)}resetTorques(t){const e=this.actorBodies.get(t.id);e?.resetTorques(!1)}applyForce(t,e){const i=this.actorBodies.get(t.id);G.x=e.x,G.y=e.y,G.z=e.z,i?.addForce(G,!0)}applyImpulse(t,e){const i=this.actorBodies.get(t.id);G.x=e.x,G.y=e.y,G.z=e.z,i?.applyImpulse(G,!0)}applyLocalForce(t,e,i){const s=this.actorBodies.get(t.id);K(G,e),null==i?s?.addForce(G,!0):(K(Q,i),s?.addForceAtPoint(G,Q,!0))}applyLocalImpulse(t,e,i){const s=this.actorBodies.get(t.id);K(G,e),null==i?s.applyImpulse(G,!0):(K(Q,i),s.applyImpulseAtPoint(G,Q,!0))}removeActor(t){this.controlledActors.delete(t.id);const e=this.actorBodies.get(t.id);null!=e&&(this.bodyActors.delete(e),this.world.removeRigidBody(e)),this.actorBodies.delete(t.id)}removeSceneObject(t){let e=this.staticBodies.get(t);null!=e&&this.world.getRigidBody(e.handle)&&this.world.removeRigidBody(e)}activateActorEvents(t){this.actorBodies.get(t.id)}_onCollisionWithActorEvent(t,e,i){return this.activateActorEvents(t),this.collisionEvents.pipe(l(t.disposed),n((({started:t})=>t===i)),a((({handle1:t,handle2:e,started:i})=>({a1:this.bodyActors.get(this.world.getCollider(t).parent()),a2:this.bodyActors.get(this.world.getCollider(e).parent()),started:i}))),n((({a1:i,a2:s})=>null!=i&&null!=s&&i.id===t.id&&e(i,s))),a((({a2:t})=>t)))}onBeginContact(t){return this.activateActorEvents(t),this.collisionEvents.pipe(l(t.disposed),n((t=>t.started)),n((({handle1:e})=>{const i=this.bodyActors.get(this.world.getCollider(e).parent());return null!=i&&i.id===t.id})),a((t=>t.handle2)))}onEndContact(t){return this.activateActorEvents(t),this.collisionEvents.pipe(l(t.disposed),n((t=>!t.started)),n((({handle1:e})=>{const i=this.bodyActors.get(this.world.getCollider(e).parent());return null!=i&&i.id===t.id})),a((t=>t.handle2)))}onHasContactChanged(t){const e=new Set,i=new o(!1);return this.onBeginContact(t).subscribe((t=>{e.add(t),i.next(e.size>0)})),this.onEndContact(t).subscribe((t=>{e.delete(t),i.next(e.size>0)})),i.pipe(r())}onBeginOverlapWithActorType(t,e){return this._onCollisionWithActorEvent(t,((t,i)=>i instanceof e),!0)}onEndOverlapWithActorType(t,e){return this._onCollisionWithActorEvent(t,((t,i)=>i instanceof e),!1)}onBeginOverlapWithActor(t,e){return this._onCollisionWithActorEvent(t,((t,i)=>e.id===i.id),!0)}onEndOverlapWithActor(t,e){return this._onCollisionWithActorEvent(t,((t,i)=>e.id===i.id),!1)}onCollisionWithActor(t,e){return this.onBeginOverlapWithActor(t,e)}onCollisionWithActorType(t,e){return this.onBeginOverlapWithActorType(t,e)}updateActorTransform(t){const e=this.actorBodies.get(t.id);null!=e?N(e,t.object):console.warn("Actor has not been added to physics world",t)}setupWorld(){const t=new i.World({x:0,y:-9.81,z:0});this.world=t,t.maxVelocityIterations=4}getActorContacts(t,e){const s=this.actorBodies.get(t.id);if(s&&s.numColliders()>0){const o=s.collider(0);let r=o.shape,n=o.translation(),a=o.rotation(),c=e,l=.3;const d=this.world.castShape(n,a,c,r,l,!0,null,null,null,this.actorBodies.get(t.id),(t=>t.shape.type!=i.ShapeType.HeightField));if(null!=d){const t=new B,e=new B,i=new B;return X(t,d.witness2),X(e,d.witness1),X(i,d.normal1),i.negate(),[{ri:t,rj:e,ni:i}]}return[]}return console.warn("Actor is not added to the physics system"),[]}stop(){this.world?.bodies.forEach((t=>this.world.removeRigidBody(t))),this.world?.free(),this.fixedupdateSub?.unsubscribe()}createStaticBody(t,e){const s=this.world.createRigidBody(i.RigidBodyDesc.kinematicPositionBased());for(const i of e)this.addShape(s,i,t);return N(s,t),s}addShape(t,e,i){const s=this.createShape(e,i.scale);s.friction=.1;const o=e.offset.clone().multiply(i.scale);var r,n;K(s.translation,o),r=s.rotation,n=(new v).setFromEuler(e.rotation),r.x=n.x,r.y=n.y,r.z=n.z,r.w=n.w;this.world.createCollider(s,t)}createShape(t,e){if(t instanceof D)return i.ColliderDesc.cuboid(t.dimensions.x*e.x/2,t.dimensions.y*e.y/2,t.dimensions.z*e.z/2);if(t instanceof z){return i.ColliderDesc.capsule(t.length/2*e.y,t.radius*Math.max(e.z,e.x))}if(t instanceof _){const e=null!=t.geometry.getIndex()?t.geometry:k.mergeVertices(t.geometry);return i.ColliderDesc.trimesh(new Float32Array(e.getAttribute("position").array),new Uint32Array(e.getIndex().array))}if(t instanceof M){let s;t.mesh instanceof d.Mesh?s=t.mesh.geometry:t.mesh instanceof d.BufferGeometry?s=t.mesh:console.log("Unknownd shape",{shapeInfo:t});const o=new Float32Array(s.getAttribute("position").array);if(t.mesh instanceof d.Mesh){const e=I(t.mesh);for(let t=0;t<o.length;t+=3)o[t]*=e.x,o[t+1]*=e.y,o[t+2]*=e.z}for(let t=0;t<o.length;t+=3)o[t]*=e.x,o[t+1]*=e.y,o[t+2]*=e.z;return i.ColliderDesc.convexHull(o)}return t instanceof W?i.ColliderDesc.ball(t.radius*Math.max(e.x,e.y,e.z)):t instanceof E?i.ColliderDesc.cylinder(t.height/2*e.y,t.radiusTop*Math.max(e.z,e.x)):t instanceof T?i.ColliderDesc.cone(t.height*e.y,t.radiusBottom/2*Math.max(e.z,e.x)):t instanceof R?i.ColliderDesc.cuboid(t.width/2*e.x,t.height/2*e.y,.01):(console.error("Unsupported shape",t),i.ColliderDesc.cuboid(1,1,1))}};L=t([A(),e("design:paramtypes",[F,P])],L);export{L as PhysicsSystem};const j=new B,O=new d.Quaternion;function N(t,e){const s=e.getWorldPosition(j),o=e.getWorldQuaternion(O);t.setTranslation(new i.Vector3(s.x,s.y,s.z),!1),t.setRotation(new i.Quaternion(o.x,o.y,o.z,o.w),!1)}const q=new B,G=new i.Vector3(0,0,0),Q=new i.Vector3(0,0,0),H=(new B,{x:0,y:0}),U=async()=>{let t=await import("@dimforge/rapier3d-compat");return await t.init(),t};function K(t,e){t.x=e.x,t.y=e.y,t.z=e.z}function X(t,e){t.x=e.x,t.y=e.y,t.z=e.z}function J(t,e){for(let i=0,s=t.numColliders();i<s;i++){e(t.collider(i))}}const Y=new B,Z=new B,$=t=>!t.isSensor();
|
2
2
|
/*
|
3
3
|
* Copyright (©) 2023. All rights reserved.
|
4
4
|
* See the LICENSE.md file for details.
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import { BaseActor } from "../actors/actor";
|
2
|
+
import { Intersection, Object3D } from "three";
|
3
|
+
import { Observable } from 'rxjs';
|
4
|
+
import { Type } from "../../utils/type";
|
5
|
+
type ObjectPointerEvent = {
|
6
|
+
object: Object3D;
|
7
|
+
intersection: Intersection;
|
8
|
+
};
|
9
|
+
type ActorPointerEvent<T extends BaseActor> = {
|
10
|
+
actor: T;
|
11
|
+
intersection: Intersection;
|
12
|
+
};
|
13
|
+
export declare class PointerEvents {
|
14
|
+
private view;
|
15
|
+
private world;
|
16
|
+
private enabled;
|
17
|
+
private stopped;
|
18
|
+
constructor();
|
19
|
+
private monitoredObjects;
|
20
|
+
private addMonitoredObject;
|
21
|
+
private removeMonitoriedObject;
|
22
|
+
private useCache;
|
23
|
+
private cachePointerPosition;
|
24
|
+
private pointerPosition;
|
25
|
+
private adjustedPosition;
|
26
|
+
private raycastIntersectionResult;
|
27
|
+
private updateRaycast;
|
28
|
+
private raycaster;
|
29
|
+
private readonly onClick;
|
30
|
+
private readonly onDoubleClick;
|
31
|
+
private readonly onPointerMove;
|
32
|
+
private readonly onPointerDown;
|
33
|
+
private readonly onPointerUp;
|
34
|
+
readonly onPointerEnterObject3D: (object: Object3D) => Observable<ObjectPointerEvent>;
|
35
|
+
readonly onPointerEnterActor: <T extends BaseActor>(actor: T) => Observable<ActorPointerEvent<T>>;
|
36
|
+
readonly onPointerEnterActorType: <T extends BaseActor>(actorType: Type<T>) => Observable<ActorPointerEvent<T>>;
|
37
|
+
readonly onPointerLeaveObject3D: (object: Object3D) => Observable<ObjectPointerEvent>;
|
38
|
+
readonly onPointerLeaveActor: <T extends BaseActor>(actor: T) => Observable<ActorPointerEvent<T>>;
|
39
|
+
readonly onPointerLeaveActorType: <T extends BaseActor>(actorType: Type<T>) => Observable<ActorPointerEvent<T>>;
|
40
|
+
readonly onClickObject3D: (object: Object3D) => Observable<ObjectPointerEvent>;
|
41
|
+
readonly onClickActor: <T extends BaseActor>(actor: T) => Observable<ActorPointerEvent<T>>;
|
42
|
+
readonly onClickActorType: <T extends BaseActor>(actorType: Type<T>) => Observable<ActorPointerEvent<T>>;
|
43
|
+
readonly onPointerDownActor: <T extends BaseActor>(actor: T) => Observable<ActorPointerEvent<T>>;
|
44
|
+
readonly onPointerDownActorType: <T extends BaseActor>(actorType: Type<T>) => Observable<ActorPointerEvent<T>>;
|
45
|
+
readonly onPointerDownObject3D: (object: Object3D) => Observable<ObjectPointerEvent>;
|
46
|
+
readonly onPointerUpActor: <T extends BaseActor>(actor: T) => Observable<ActorPointerEvent<T>>;
|
47
|
+
readonly onPointerUpActorType: <T extends BaseActor>(actorType: Type<T>) => Observable<ActorPointerEvent<T>>;
|
48
|
+
readonly onPointerUpObject3D: (object: Object3D) => Observable<ObjectPointerEvent>;
|
49
|
+
readonly onPointerMoveActor: <T extends BaseActor>(actor: T) => Observable<ActorPointerEvent<T>>;
|
50
|
+
readonly onPointerMoveActorType: <T extends BaseActor>(actorType: Type<T>) => Observable<ActorPointerEvent<T>>;
|
51
|
+
readonly onPointerMoveObject3D: (object: Object3D) => Observable<ObjectPointerEvent>;
|
52
|
+
private usingPointerMoveEvents;
|
53
|
+
private tapUsingPointerMove;
|
54
|
+
private tapMonitorObject;
|
55
|
+
private findIntersection;
|
56
|
+
private handlers;
|
57
|
+
}
|
58
|
+
export {};
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import{__decorate as t,__metadata as e}from"tslib";import{Raycaster as i,Vector2 as o}from"three";import{Service as n}from"typedi";import{ViewController as s}from"./render";import{World as r}from"./world";import{inject as c}from"../../gameplay";import{Subject as h,tap as p,map as a,filter as d,takeUntil as l,withLatestFrom as b,mergeMap as P,merge as u,from as j}from"rxjs";let w=class{constructor(){this.view=c(s),this.world=c(r),this.enabled=!1,this.stopped=new h,this.monitoredObjects=new Map,this.useCache=!1,this.cachePointerPosition=new o,this.pointerPosition=new o,this.adjustedPosition=new o,this.raycastIntersectionResult=[],this.raycaster=new i,this.onClick=new h,this.onDoubleClick=new h,this.onPointerMove=new h,this.onPointerDown=new h,this.onPointerUp=new h,this.onPointerEnterObject3D=t=>{let e=!1;return this.onPointerMove.pipe(this.tapUsingPointerMove(),this.tapMonitorObject(t),a((()=>this.findIntersection(t))),p((t=>{null==t&&(e=!1)})),d((t=>null!=t&&!e)),p((()=>{e=!0})),a((e=>({intersection:e,object:t}))))},this.onPointerEnterActor=t=>this.onPointerEnterObject3D(t.object).pipe(l(t.disposed),a((({intersection:e})=>({intersection:e,actor:t})))),this.onPointerEnterActorType=t=>u(j(this.world.actors),this.world.actorAdded).pipe(d((e=>e instanceof t)),P((t=>this.onPointerEnterActor(t)))),this.onPointerLeaveObject3D=t=>{let e=!1;return this.onPointerMove.pipe(this.tapUsingPointerMove(),this.tapMonitorObject(t),a((()=>this.findIntersection(t))),p((t=>{null!=t&&(e=!1)})),d((t=>null==t&&!e)),p((()=>{e=!0})),a((e=>({intersection:e,object:t}))))},this.onPointerLeaveActor=t=>this.onPointerLeaveObject3D(t.object).pipe(l(t.disposed),a((({intersection:e})=>({intersection:e,actor:t})))),this.onPointerLeaveActorType=t=>u(j(this.world.actors),this.world.actorAdded).pipe(d((e=>e instanceof t)),P((t=>this.onPointerLeaveActor(t)))),this.onClickObject3D=t=>{const e=this.onPointerDown.pipe(a((()=>this.findIntersection(t))));return this.onPointerUp.pipe(a((()=>this.findIntersection(t)))).pipe(this.tapMonitorObject(t),b(e),d((([t,e])=>null!=t&&null!=e)),a((([e])=>({intersection:e,object:t}))))},this.onClickActor=t=>this.onClickObject3D(t.object).pipe(l(t.disposed),a((({intersection:e})=>({intersection:e,actor:t})))),this.onClickActorType=t=>u(j(this.world.actors),this.world.actorAdded).pipe(d((e=>e instanceof t)),P((t=>this.onClickActor(t)))),this.onPointerDownActor=t=>this.onPointerDownObject3D(t.object).pipe(l(t.disposed),a((({intersection:e})=>({intersection:e,actor:t})))),this.onPointerDownActorType=t=>u(j(this.world.actors),this.world.actorAdded).pipe(d((e=>e instanceof t)),P((t=>this.onPointerDownActor(t)))),this.onPointerDownObject3D=t=>this.onPointerDown.pipe(this.tapMonitorObject(t),a((()=>this.findIntersection(t))),d((t=>null!=t)),a((e=>({intersection:e,object:t})))),this.onPointerUpActor=t=>this.onPointerUpObject3D(t.object).pipe(l(t.disposed),a((({intersection:e})=>({intersection:e,actor:t})))),this.onPointerUpActorType=t=>u(j(this.world.actors),this.world.actorAdded).pipe(d((e=>e instanceof t)),P((t=>this.onPointerUpActor(t)))),this.onPointerUpObject3D=t=>this.onPointerUp.pipe(this.tapMonitorObject(t),a((()=>this.findIntersection(t))),d((t=>null!=t)),a((e=>({intersection:e,object:t})))),this.onPointerMoveActor=t=>this.onPointerMoveObject3D(t.object).pipe(l(t.disposed),a((({intersection:e})=>({intersection:e,actor:t})))),this.onPointerMoveActorType=t=>u(j(this.world.actors),this.world.actorAdded).pipe(d((e=>e instanceof t)),P((t=>this.onPointerMoveActor(t)))),this.onPointerMoveObject3D=t=>this.onPointerMove.pipe(this.tapUsingPointerMove(),this.tapMonitorObject(t),a((()=>this.findIntersection(t))),d((t=>null!=t)),a((e=>({intersection:e,object:t})))),this.usingPointerMoveEvents=!1,this.handlers={click:t=>{this.onClick.next(t)},dblclick:t=>{this.onDoubleClick.next(t)},pointermove:t=>{this.onPointerMove.next(t)},pointerup:t=>{this.onPointerUp.next(t)},pointerdown:t=>{this.onPointerDown.next(t)}},this.raycaster.firstHitOnly=!0}start(){this.enabled||(this.enabled=!0,Object.entries(this.handlers).forEach((([t,e])=>{this.view.htmlElement.addEventListener(t,(i=>{("pointermove"!==t||this.usingPointerMoveEvents)&&(this.updateRaycast(i),e(i))}))})),this.view.onLateUpdate().pipe(l(this.stopped)).subscribe((()=>this.useCache=!1)))}stop(){this.enabled=!1,Object.entries(this.handlers).forEach((([t,e])=>{document.removeEventListener(t,e)})),this.stopped.next(!0)}addMonitoredObject(t){const e=this.monitoredObjects.get(t)??0;this.monitoredObjects.set(t,e+1)}removeMonitoriedObject(t){const e=this.monitoredObjects.get(t);null!=e&&(e>1?this.monitoredObjects.set(t,e-1):this.monitoredObjects.delete(t))}updateRaycast(t){this.pointerPosition.set(t.x,t.y),this.useCache&&this.cachePointerPosition.equals(this.pointerPosition)||(this.cachePointerPosition.copy(this.pointerPosition),this.useCache=!0,this.adjustedPosition.x=t.offsetX/this.view.htmlElement.offsetWidth*2-1,this.adjustedPosition.y=-t.offsetY/this.view.htmlElement.offsetHeight*2+1,this.raycaster.setFromCamera(this.adjustedPosition,this.view.getCamera()),this.raycastIntersectionResult.length=0,this.raycaster.intersectObject(this.world.scene,!0,this.raycastIntersectionResult))}tapUsingPointerMove(){return p({subscribe:()=>{this.usingPointerMoveEvents=!0},unsubscribe:()=>{}})}tapMonitorObject(t){return p({subscribe:()=>{this.addMonitoredObject(t)},unsubscribe:()=>{this.removeMonitoriedObject(t)}})}findIntersection(t){if(this.raycastIntersectionResult.length>0){let e=this.raycastIntersectionResult[0].object;for(;null!=e;){if(e.uuid===t.uuid)return this.raycastIntersectionResult[0];e=e.parent}}return null}};w=t([n(),e("design:paramtypes",[])],w);export{w as PointerEvents};
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|