@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,5 @@
|
|
1
|
+
import{__decorate as t,__metadata as i}from"tslib";import{ActionInput as s,AxisInput as e,RotationInput as o}from"../../../../../gameplay/input";import{PhysicsSystem as n,RayTestResult as r}from"../../../../../gameplay/services/physics/physics-system";import{toDegrees as a}from"../../../../../utils/math";import{Vector3 as h}from"three";import{ActorComponent as l,Component as c}from"../../../component";import{CharacterMovementMode as p}from"./modes";import{Quaternion as m,Vec3 as y}from"cannon-es";import{CapsuleCollisionShape as d}from"../../../../../scene/collision/collision-shape";import{lerp as u}from"three/src/math/MathUtils";import{takeUntil as g}from"rxjs";import{PhysicsBodyType as S}from"../../../../services/physics/physics-system";let f=class extends l{constructor(t){super(),this.physicsSystem=t,this.directionInput=new e,this.jumpInput=new s,this.sprintInput=new s,this.rotationInput=new o,this.horizontalSpeed=0,this.maxSpeed=8,this.maxSpeedBackwards=8,this.maxSpeedSprint=10,this.maxWalkingSlopeAngle=70,this.jumpVelocity=7,this.fallingMovementControl=.5,this.fallingReorientation=!1,this.gravityOverride=null,this.colliderHeight=2.5,this.colliderRadius=.5,this.velocity=new h,this.mode=p.walking,this.isSprinting=!1,this.pressedJump=!1,this.rayTestResult=new r}onInit(){this.physicsSystem.addActor(this.actor,[this.createCollisionShape()],{mass:0,type:S.kinematic}),this.rotationInput.rotation.copy(this.actor.rotation);let t=this.rotationInput.rotation.y;const i=new h,s=new h,e=new h,o=new h,n=new h;let l=0;this.physicsSystem.afterStep.pipe(g(this.disposed)).subscribe((r=>{this.pressedJump=this.jumpInput.activated,this.isSprinting=this.sprintInput.activated;let a=t-this.rotationInput.rotation.y;t=this.rotationInput.rotation.y,e.copy(this.actor.position),o.set(-this.directionInput.vector.x,0,this.directionInput.vector.y).normalize();const c=o.z<0?this.maxSpeedBackwards:this.isSprinting?this.maxSpeedSprint:this.maxSpeed,m=o.clone().applyAxisAngle(new h(0,1,0),this.rotationInput.rotation.y);this.mode===p.walking&&(0!==m.length()?(l=Math.min(c,l),l=u(l,c,4*r)):l=0,n.copy(m).multiplyScalar(l),this.pressedJump&&(this.mode=p.falling,this.velocity.copy(n),this.velocity.y=this.jumpVelocity)),this.mode===p.falling&&(this.velocity.y+=r*this.getEffectiveGravity(),n.copy(this.velocity),n.add(m.clone().multiplyScalar(c*this.fallingMovementControl*r)),this.fallingReorientation&&n.applyAxisAngle(new h(0,1,0),-a)),s.copy(n).normalize(),i.copy(n),this.actor.rotation.y-=a;const y=this.actor.position.add(n.multiplyScalar(r));this.moveTo(y),f(),this.isGrounded?this.velocity.y<=0&&(this.mode=p.walking,this.velocity.y=0):(this.mode=p.falling,this.velocity.copy(i)),this.mode===p.walking&&v(r),x(r),this.horizontalSpeed=l}));const c=new h(0,1,0),m=new h(0,-.1,0),y=new h,d=new h,f=()=>{const t=this.colliderHeight+2*this.colliderRadius;this.physicsSystem.rayTest(y.addVectors(this.actor.position,c.set(0,t/4,0)),d.addVectors(this.actor.position,m),this.rayTestResult,{excludeActor:this.actor})},v=t=>{if(this.isGrounded){const s=Math.acos(this.rayTestResult.hitNormal.y),o=this.rayTestResult.hitPoint.y;if(a(s)<this.maxWalkingSlopeAngle){this.actor.position.y=o;const s=this.actor.position.sub(e).normalize().multiplyScalar(i.length()*t);this.moveTo(e.clone().add(s))}}},w=new r,x=t=>{const i=this.physicsSystem.getActorContacts(this.actor,s).filter((t=>a(Math.acos(-t.ni.y))>this.maxWalkingSlopeAngle));if(i.length>0){if(i[0].ni.clone().dot(s)<=0)return;this.moveTo(e);const o=i[0].rj.clone(),n=this.getWallDirection(i[0].ni,s);if(!this.physicsSystem.rayTest(o,n.clone().multiplyScalar(this.colliderRadius).add(o),w,{debugColor:0}).hasHit){const i=s.dot(n),e=n.multiplyScalar(this.horizontalSpeed*i);e.y+=this.velocity.y,e.multiplyScalar(t);const o=this.actor.position.clone().add(e);this.moveTo(o)}}}}getWallDirection(t,i){const s=t.clone().negate().cross(new h(0,1,0));return s.dot(i)<0?s.negate():s}moveTo(t){this.actor.position.copy(t),this.physicsSystem.updateActorTransform(this.actor)}getEffectiveGravity(){var t;return null!==(t=this.gravityOverride)&&void 0!==t?t:this.physicsSystem.getGravity().y}get isGrounded(){return this.rayTestResult.hasHit}createCollisionShape(){const t=new d(this.colliderHeight,this.colliderRadius);return t.offset.y=this.colliderRadius+this.colliderHeight/2,t}step(t){}performMovement(t){}};f=t([c(),i("design:paramtypes",[n])],f);export{f as CharacterMovementComponent};
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { ActionInput, AxisInput, RotationInput } from "../../../../../gameplay/input";
|
2
|
+
import { PhysicsSystem } from "../../../../../gameplay/services/physics/physics-system";
|
3
|
+
import { Vector3 } from 'three';
|
4
|
+
import { ActorComponent } from "../../../component";
|
5
|
+
import { CharacterMovementMode } from "./modes";
|
6
|
+
export declare class CharacterMovementComponent extends ActorComponent {
|
7
|
+
private physicsSystem;
|
8
|
+
readonly directionInput: AxisInput;
|
9
|
+
readonly jumpInput: ActionInput;
|
10
|
+
readonly sprintInput: ActionInput;
|
11
|
+
readonly rotationInput: RotationInput;
|
12
|
+
horizontalSpeed: number;
|
13
|
+
maxSpeed: number;
|
14
|
+
maxSpeedBackwards: number;
|
15
|
+
maxSpeedSprint: number;
|
16
|
+
jumpVelocity: number;
|
17
|
+
fallingMovementControl: number;
|
18
|
+
fallingReorientation: boolean;
|
19
|
+
gravityOverride: number;
|
20
|
+
colliderHeight: number;
|
21
|
+
colliderRadius: number;
|
22
|
+
jumpInAir: boolean;
|
23
|
+
mass: number;
|
24
|
+
allowSliding: boolean;
|
25
|
+
minSlopeSlideAngle: number;
|
26
|
+
maxSlopeClimbAngle: number;
|
27
|
+
applyImpulsesToDynamicBodies: boolean;
|
28
|
+
get autoStepMinWidth(): number;
|
29
|
+
set autoStepMinWidth(minWidth: number);
|
30
|
+
get autoStepDynamicObjects(): boolean;
|
31
|
+
set autoStepDynamicObjects(enabled: boolean);
|
32
|
+
get autoStepMaxHeight(): number;
|
33
|
+
set autoStepMaxHeight(maxHeight: number);
|
34
|
+
get snapToGround(): number;
|
35
|
+
set snapToGround(distance: number);
|
36
|
+
readonly velocity: Vector3;
|
37
|
+
mode: CharacterMovementMode;
|
38
|
+
isSprinting: boolean;
|
39
|
+
pressedJump: boolean;
|
40
|
+
private cc;
|
41
|
+
private rayTestResult;
|
42
|
+
constructor(physicsSystem: PhysicsSystem);
|
43
|
+
onInit(): void | Promise<void>;
|
44
|
+
private getWallDirection;
|
45
|
+
private moveTo;
|
46
|
+
getEffectiveGravity(): number;
|
47
|
+
get isGrounded(): boolean;
|
48
|
+
private createCollisionShape;
|
49
|
+
private step;
|
50
|
+
private performMovement;
|
51
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import{__decorate as t,__metadata as i}from"tslib";import{ActionInput as e,AxisInput as s,RotationInput as o}from"../../../../../gameplay/input";import{PhysicsSystem as n,RayTestResult as a}from"../../../../../gameplay/services/physics/physics-system";import{MathUtils as l,Vector3 as r}from"three";import{ActorComponent as c,Component as h}from"../../../component";import{CharacterMovementMode as p}from"./modes";import{Quaternion as m,Vec3 as y}from"cannon-es";import{CapsuleCollisionShape as d}from"../../../../../scene/collision/collision-shape";import{lerp as u}from"three/src/math/MathUtils";import{takeUntil as g}from"rxjs";import{PhysicsBodyType as S}from"../../../../services/physics/physics-system";const f=new r,v=new r,w=1/30;let x=class extends c{get autoStepMinWidth(){return this.cc.autostepMinWidth()}set autoStepMinWidth(t){this.cc.enableAutostep(this.cc.autostepMaxHeight(),t,this.cc.autostepIncludesDynamicBodies())}get autoStepDynamicObjects(){return this.cc.autostepIncludesDynamicBodies()}set autoStepDynamicObjects(t){this.cc.enableAutostep(this.cc.autostepMaxHeight(),this.cc.autostepMinWidth(),t)}get autoStepMaxHeight(){return this.cc.autostepMaxHeight()}set autoStepMaxHeight(t){this.cc.enableAutostep(t,this.cc.autostepMinWidth(),this.cc.autostepIncludesDynamicBodies())}get snapToGround(){return this.cc.snapToGroundDistance()}set snapToGround(t){this.cc.enableSnapToGround(t)}constructor(t){super(),this.physicsSystem=t,this.directionInput=new s,this.jumpInput=new e,this.sprintInput=new e,this.rotationInput=new o,this.horizontalSpeed=0,this.maxSpeed=8,this.maxSpeedBackwards=8,this.maxSpeedSprint=12,this.jumpVelocity=7,this.fallingMovementControl=.5,this.fallingReorientation=!1,this.gravityOverride=null,this.colliderHeight=2,this.colliderRadius=.5,this.jumpInAir=!1,this.mass=50,this.allowSliding=!0,this.minSlopeSlideAngle=l.degToRad(70),this.maxSlopeClimbAngle=l.degToRad(70),this.applyImpulsesToDynamicBodies=!0,this.velocity=new r,this.mode=p.walking,this.isSprinting=!1,this.pressedJump=!1,this.rayTestResult=new a;const i=this.cc=this.physicsSystem.getCharacterController(.1);i.enableSnapToGround(.1),i.enableAutostep(0,.1,!1)}onInit(){const t=this.cc;t.setApplyImpulsesToDynamicBodies(this.applyImpulsesToDynamicBodies),t.setMinSlopeSlideAngle(this.minSlopeSlideAngle),t.setMaxSlopeClimbAngle(this.maxSlopeClimbAngle),t.setCharacterMass(this.mass),t.setSlideEnabled(this.allowSliding),this.physicsSystem.addActor(this.actor,[this.createCollisionShape()],{mass:0,type:S.kinematic,continousCollisionDetection:!0,friction:1}),this.rotationInput.rotation.copy(this.actor.rotation);let i=this.rotationInput.rotation.y;const e=new r,s=new r,o=new r,n=new r,a=new r,l=new r;let c=0,h=null;this.physicsSystem.beforeStep.pipe(g(this.disposed)).subscribe((m=>{m>w&&(m=w),this.pressedJump=this.jumpInput.activated,this.isSprinting=this.sprintInput.activated;let y=i-this.rotationInput.rotation.y;i=this.rotationInput.rotation.y,o.copy(this.actor.position),n.set(-this.directionInput.vector.x,0,this.directionInput.vector.y).normalize();const d=n.z<0?this.maxSpeedBackwards:this.isSprinting?this.maxSpeedSprint:this.maxSpeed;l.copy(n).applyAxisAngle(I,this.rotationInput.rotation.y),this.mode===p.walking&&(0!==l.length()?(c=Math.min(d,c),c=u(c,d,4*m)):c=0,a.copy(l).multiplyScalar(c),this.pressedJump&&(this.mode=p.falling,this.velocity.copy(a),this.velocity.y=this.jumpVelocity),a.y=m*this.getEffectiveGravity()),this.mode===p.falling&&(this.pressedJump&&this.jumpInAir&&(this.mode=p.falling,this.velocity.copy(a),this.velocity.y=this.jumpVelocity),this.velocity.y+=m*this.getEffectiveGravity(),a.copy(this.velocity),a.add(l.clone().multiplyScalar(d*this.fallingMovementControl*m)),this.fallingReorientation&&a.applyAxisAngle(new r(0,1,0),-y)),s.copy(a).normalize(),e.copy(a),this.actor.rotation.y-=y,a.length(),f.copy(a).multiplyScalar(m),v.copy(this.physicsSystem.getActorComputedMovement(this.actor,t,f)),this.physicsSystem.setNextKinematicTranslation(this.actor,v);let g=function(t){if(t.numComputedCollisions()>0){const i=t.computedCollision(0);A.x=i.normal2.x,A.y=i.normal2.y,A.z=i.normal2.z;const e=A.angleTo(I);A.x=i.normal1.x,A.y=i.normal1.y,A.z=i.normal1.z;const s=A.angleTo(I);return!(e<100)&&s>t.minSlopeSlideAngle()}return!1}(t);!t.computedGrounded()||g?this.mode!==p.falling&&(null==h?h=performance.now():performance.now()-h>100&&(this.mode=p.falling,this.velocity.copy(e))):this.velocity.y<=0&&(this.mode,p.falling,this.mode=p.walking,this.velocity.y=0,h=null),this.mode,p.walking,this.horizontalSpeed=c}))}getWallDirection(t,i){const e=t.clone().negate().cross(I);return e.dot(i)<0?e.negate():e}moveTo(t){this.actor.position.copy(t),this.physicsSystem.updateActorTransform(this.actor)}getEffectiveGravity(){var t;return null!==(t=this.gravityOverride)&&void 0!==t?t:this.physicsSystem.getGravity().y}get isGrounded(){return this.rayTestResult.hasHit}createCollisionShape(){const t=new d(this.colliderHeight,this.colliderRadius);return t.offset.y=this.colliderRadius+this.colliderHeight/2,t}step(t){}performMovement(t){}};x=t([h({inEditor:!1}),i("design:paramtypes",[n])],x);export{x as CharacterMovementComponent};const I=new r(0,1,0),A=new r;
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/**
|
2
|
+
* A mode is used for state mode transitions and phsyics calculations
|
3
|
+
* Slight adjustments which does not change which modes you can transition to
|
4
|
+
* should be handled by flags
|
5
|
+
*
|
6
|
+
* For example, while in walking state and you walk off a ledge or you start a jump, you
|
7
|
+
* will not longer be on the ground and instead transition into the falling state.
|
8
|
+
* At this point gravity will be simulated.
|
9
|
+
*
|
10
|
+
* Something that would require a new mode is wallriding as no other
|
11
|
+
* mode will have physics that support it
|
12
|
+
*/
|
13
|
+
export declare enum CharacterMovementMode {
|
14
|
+
walking = 0,
|
15
|
+
swimming = 1,
|
16
|
+
falling = 2,
|
17
|
+
flying = 3
|
18
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
export var CharacterMovementMode;!function(e){e[e.walking=0]="walking",e[e.swimming=1]="swimming",e[e.falling=2]="falling",e[e.flying=3]="flying"}(CharacterMovementMode||(CharacterMovementMode={}));
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { PhysicsBodyType, PhysicsSystem } from "../../../../gameplay/services/physics/physics-system";
|
2
|
+
import { Euler, Mesh, Vector3 } from "three";
|
3
|
+
import { ActorComponent } from "../../component";
|
4
|
+
export declare class MeshComponent extends ActorComponent {
|
5
|
+
private physicsSystem;
|
6
|
+
mesh: Mesh;
|
7
|
+
readonly position: Vector3;
|
8
|
+
readonly rotation: Euler;
|
9
|
+
readonly scale: Vector3;
|
10
|
+
readonly mass: number;
|
11
|
+
readonly friction: number;
|
12
|
+
readonly bodyType: PhysicsBodyType;
|
13
|
+
readonly continousCollisionDetection: boolean;
|
14
|
+
private currentMesh;
|
15
|
+
constructor(physicsSystem: PhysicsSystem);
|
16
|
+
onInit(): void | Promise<void>;
|
17
|
+
replaceMesh(replacement: Mesh): void;
|
18
|
+
private updateMesh;
|
19
|
+
private getCollisionShapes;
|
20
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import{__decorate as t,__metadata as s}from"tslib";import{PhysicsBodyType as i,PhysicsSystem as e}from"../../../../gameplay/services/physics/physics-system";import{AssetMeshInstance as o}from"../../../../scene/asset-resource-loader";import{PhysicalShapeMesh as n}from"../../../../";import{Parameter as r}from"../../../../shader/parameter";import{Euler as h,Mesh as c,Vector3 as p}from"three";import{ActorComponent as a,Component as l}from"../../component";import{firstValueFrom as m}from"rxjs";const y={friction:.1,mass:0,bodyType:i.static,continousCollisionDetection:!1};let d=class extends a{constructor(t){super(),this.physicsSystem=t,this.position=new p,this.rotation=new h,this.scale=new p(1,1,1),this.mass=y.mass,this.friction=y.friction,this.bodyType=i.static,this.continousCollisionDetection=y.continousCollisionDetection}onInit(){null!=this.mesh&&(this.currentMesh=this.mesh,this.updateMesh()),m(this.disposed).then((()=>{this.physicsSystem.removeActor(this.actor)}))}replaceMesh(t){null!=this.currentMesh&&this.actor.container.remove(this.currentMesh),this.mesh=this.currentMesh=t,this.updateMesh()}updateMesh(){this.currentMesh.position.copy(this.position),this.currentMesh.rotation.copy(this.rotation),this.currentMesh.scale.copy(this.scale);const t=this.getCollisionShapes();t.length>0&&this.physicsSystem.addActor(this.actor,t,Object.assign(Object.assign({},y),{isTrigger:!1,mass:this.mass,friction:this.friction,type:this.bodyType,continousCollisionDetection:this.continousCollisionDetection})),this.actor.container.add(this.currentMesh)}getCollisionShapes(){return this.currentMesh instanceof o?this.currentMesh.collisionShapes:this.currentMesh instanceof n?[this.currentMesh.collisionShape]:"collisionShape"in this.currentMesh?(console.error("Could not understand wehre to get collision shapes from. This is likely due to an import issue"),[this.currentMesh.collisionShape]):[]}};t([r(),s("design:type",c)],d.prototype,"mesh",void 0),t([r(),s("design:type",p)],d.prototype,"position",void 0),t([r(),s("design:type",h)],d.prototype,"rotation",void 0),t([r(),s("design:type",p)],d.prototype,"scale",void 0),t([r(),s("design:type",Number)],d.prototype,"mass",void 0),t([r(),s("design:type",Number)],d.prototype,"friction",void 0),t([r({options:[{name:"Static",value:i.static},{name:"Dynamic",value:i.dynamic}]}),s("design:type",Number)],d.prototype,"bodyType",void 0),d=t([l({inEditor:!0}),s("design:paramtypes",[e])],d);export{d as MeshComponent};
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import{__decorate as t}from"tslib";import{Group as r}from"three";import{ActorComponent as e,Component as n}from"../../component";let o=class extends e{constructor(){super(...arguments),this.container=new r}set parent(t){this._parent=t,t.container.add(this.container)}get parent(){return this._parent}};o=t([n()],o);export{o as SceneComponent};
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { CameraActor } from './camera-actor';
|
2
|
+
import { PositionalAudioActor } from './positional-audio-actor';
|
3
|
+
import { SpawnPoint } from './spawn-point';
|
4
|
+
import { TriggerVolume } from './trigger-volume';
|
5
|
+
declare const _default: {
|
6
|
+
Camera: typeof CameraActor;
|
7
|
+
SpawnPoint: typeof SpawnPoint;
|
8
|
+
TriggerVolume: typeof TriggerVolume;
|
9
|
+
PositionalAudio: typeof PositionalAudioActor;
|
10
|
+
};
|
11
|
+
export default _default;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import{CameraActor as o}from"./camera-actor";import{PositionalAudioActor as r}from"./positional-audio-actor";import{SpawnPoint as i}from"./spawn-point";import{TriggerVolume as t}from"./trigger-volume";export default{Camera:o,SpawnPoint:i,TriggerVolume:t,PositionalAudio:r};
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import * as THREE from "three";
|
2
|
+
import { BaseActor } from "../actor";
|
3
|
+
import { ActorComponent } from '../component';
|
4
|
+
export declare class PositionalAudioActor extends BaseActor {
|
5
|
+
audio: PositionalAudioComponent;
|
6
|
+
}
|
7
|
+
export declare class PositionalAudioComponent extends ActorComponent {
|
8
|
+
private audioBuffer;
|
9
|
+
private refDistance;
|
10
|
+
private rollofFactor;
|
11
|
+
private maxDistance;
|
12
|
+
private directionalInnerAngle;
|
13
|
+
private directionalOuterAngle;
|
14
|
+
private directionalOuterGain;
|
15
|
+
private view;
|
16
|
+
readonly sound: THREE.PositionalAudio;
|
17
|
+
private visualisation;
|
18
|
+
onInit(): void | Promise<void>;
|
19
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import{__decorate as t,__metadata as i}from"tslib";import*as e from"three";import{Actor as o,BaseActor as r}from"../actor";import{ActorComponent as n,Component as s,attach as a}from"../component";import{Parameter as l}from"../../../shader";import{ViewController as d}from"../../services/render";import{inject as u}from"../../inject";import{PositionalAudioHelper as p}from"../../../utils/three/positional-audio-helper";let c=class extends r{constructor(){super(...arguments),this.audio=a(m)}};c=t([o()],c);export{c as PositionalAudioActor};let h=class extends n{onInit(){const t=(new e.TextureLoader).load("assets/audio.png"),i=new e.SpriteMaterial({map:t}),o=new e.Sprite(i);this.actor.container.add(o),this.helper=new p(this.positionalAudio)}};h=t([s({inEditor:!0,editorOnly:!0})],h);let m=class extends n{constructor(){super(...arguments),this.view=u(d),this.sound=new e.PositionalAudio(this.view.audioListener),this.visualisation=a(h,{positionalAudio:this.sound})}onInit(){var t,i;this.sound.setBuffer(this.audioBuffer),null!=this.refDistance&&this.sound.setRefDistance(this.refDistance),null!=this.rollofFactor&&this.sound.setRolloffFactor(this.rollofFactor),null!=this.maxDistance&&this.sound.setMaxDistance(this.maxDistance),null!=this.directionalInnerAngle&&null!=this.directionalOuterAngle&&null!=this.directionalOuterGain&&this.sound.setDirectionalCone(this.directionalInnerAngle,this.directionalOuterAngle,this.directionalOuterGain),null===(i=null===(t=this.visualisation)||void 0===t?void 0:t.helper)||void 0===i||i.update(),this.actor.container.add(this.sound),this.sound.play()}};t([l(),i("design:type",AudioBuffer)],m.prototype,"audioBuffer",void 0),t([l(),i("design:type",Number)],m.prototype,"refDistance",void 0),t([l(),i("design:type",Number)],m.prototype,"rollofFactor",void 0),t([l(),i("design:type",Number)],m.prototype,"maxDistance",void 0),t([l(),i("design:type",Number)],m.prototype,"directionalInnerAngle",void 0),t([l(),i("design:type",Number)],m.prototype,"directionalOuterAngle",void 0),t([l({range:[0,1]}),i("design:type",Number)],m.prototype,"directionalOuterGain",void 0),m=t([s({inEditor:!0})],m);export{m as PositionalAudioComponent};
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { BaseActor } from "../actor";
|
2
|
+
import { ActorComponent } from "../component";
|
3
|
+
import { Type } from "../../../utils/type";
|
4
|
+
export declare class SpawnPointMesh extends ActorComponent {
|
5
|
+
onInit(): void | Promise<void>;
|
6
|
+
}
|
7
|
+
export declare class SpawnPoint extends BaseActor {
|
8
|
+
mesh: SpawnPointMesh;
|
9
|
+
private readonly world;
|
10
|
+
spawnActor<T extends BaseActor>(type: Type<T>): Promise<T>;
|
11
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import{__decorate as t,__metadata as o}from"tslib";import{EdgesGeometry as r,ArrowHelper as e,Vector3 as i,BoxGeometry as n,Euler as s}from"three";import{Actor as p,BaseActor as c}from"../actor";import{Component as a,ActorComponent as m,Attach as d}from"../component";import{World as l}from"../../../gameplay/services/world";import{inject as w}from"../../../gameplay/inject";import{createLineSphere as h}from"../../../utils/three/line-sphere";let f=class extends m{onInit(){const t=new n(1,1,1),o=(new r(t),h(1));this.actor.container.add(o);this.actor.container.getWorldDirection(new i);const s=new e(new i(0,0,1),new i,1,16773120);this.actor.container.add(s)}};f=t([a({inEditor:!0,editorOnly:!0})],f);export{f as SpawnPointMesh};let y=class extends c{constructor(){super(...arguments),this.world=w(l)}spawnActor(t){return this.world.spawnActor(t,this.position,new s(0,this.rotation.y,0,"XYZ"))}};t([d(),o("design:type",f)],y.prototype,"mesh",void 0),y=t([p()],y);export{y as SpawnPoint};
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { BaseActor } from "../actor";
|
2
|
+
import { ActorComponent } from "../component";
|
3
|
+
import { PhysicsSystem } from '../../services/physics/physics-system';
|
4
|
+
import { Observable } from "rxjs";
|
5
|
+
import { Type } from '../../../utils/type';
|
6
|
+
export declare class TriggerVolumeMesh extends ActorComponent {
|
7
|
+
private dimensions;
|
8
|
+
onInit(): void | Promise<void>;
|
9
|
+
}
|
10
|
+
export declare class TriggerVolumeComponent extends ActorComponent {
|
11
|
+
private physicsSystem;
|
12
|
+
private dimensions;
|
13
|
+
private editorMesh;
|
14
|
+
constructor(physicsSystem: PhysicsSystem);
|
15
|
+
onInit(): void | Promise<void>;
|
16
|
+
onBeginOverlapWithActor<A extends BaseActor>(actor: A): Observable<A>;
|
17
|
+
onEndOverlapWithActor<A extends BaseActor>(actor: A): Observable<A>;
|
18
|
+
onBeginOverlapWithActorType<A extends BaseActor>(actorType: Type<A>): Observable<A>;
|
19
|
+
onEndOverlapWithActorType<A extends BaseActor>(actorType: Type<A>): Observable<A>;
|
20
|
+
}
|
21
|
+
export declare class TriggerVolume extends BaseActor {
|
22
|
+
trigger: TriggerVolumeComponent;
|
23
|
+
}
|
@@ -0,0 +1,5 @@
|
|
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 a,BaseActor as d}from"../actor";import{Component as m,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})),a=(new c(t,new h({color:16777215,transparent:!0,opacity:.3,visible:!1})),new p);a.add(r),this.actor.container.add(a)}};A=t([m({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),console.log("add actor",this.actor),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([m({inEditor:!0,editorOnly:!1}),s("design:paramtypes",[v])],O);export{O as TriggerVolumeComponent};let u=class extends d{};t([l(),s("design:type",O)],u.prototype,"trigger",void 0),u=t([a()],u);export{u as TriggerVolume};
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { ActorComponent } from '../component';
|
2
|
+
import { ViewController } from '../../services/render';
|
3
|
+
import { PerspectiveCamera } from 'three';
|
4
|
+
export declare class CameraComponent extends ActorComponent {
|
5
|
+
private viewController;
|
6
|
+
near: number;
|
7
|
+
far: number;
|
8
|
+
viewAngle: number;
|
9
|
+
private aspect;
|
10
|
+
instance: PerspectiveCamera;
|
11
|
+
constructor(viewController: ViewController);
|
12
|
+
onInit(): void | Promise<void>;
|
13
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import{ActorComponent as i,Component as r}from"../component";import{ViewController as n}from"../../services/render";import{PerspectiveCamera as s}from"three";import{Parameter as o}from"../../../shader/parameter";const a=/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 s(this.viewAngle,this.aspect,this.near,this.far)}onInit(){this.actor.container.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",[n])],h);export{h as CameraComponent};
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,43 @@
|
|
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';
|
6
|
+
/**
|
7
|
+
* A camera that is behind the actor.
|
8
|
+
* It can also spring back and forward to avoid clipping into other elements
|
9
|
+
*/
|
10
|
+
export declare class ThirdPartyCameraComponent extends ActorComponent {
|
11
|
+
private viewController;
|
12
|
+
private physicsSystem;
|
13
|
+
camera: CameraComponent;
|
14
|
+
distance: number;
|
15
|
+
minDistance: number;
|
16
|
+
maxDistance: number;
|
17
|
+
height: number;
|
18
|
+
offsetX: number;
|
19
|
+
offsetZ: number;
|
20
|
+
autoActivate: boolean;
|
21
|
+
bounceBackSpeed: number;
|
22
|
+
private collisionCheckRadius;
|
23
|
+
private restrictedDistance;
|
24
|
+
readonly rotationInput: RestrictedRotationInput;
|
25
|
+
readonly zoomInput: DecimalInput;
|
26
|
+
private readonly offset;
|
27
|
+
private readonly lookAtOffset;
|
28
|
+
constructor(viewController: ViewController, physicsSystem: PhysicsSystem);
|
29
|
+
isMouseLocked: boolean;
|
30
|
+
onInit(): Promise<void>;
|
31
|
+
private get element();
|
32
|
+
private canvas;
|
33
|
+
hideCursor(): void;
|
34
|
+
private pointerLockInactivatedAt;
|
35
|
+
showCursor(): void;
|
36
|
+
private onMouseDown;
|
37
|
+
private onKeyDown;
|
38
|
+
private onPointerLockChange;
|
39
|
+
private setFromRotation;
|
40
|
+
private checkForCollision;
|
41
|
+
private getLookAtPosition;
|
42
|
+
private updateCameraPosition;
|
43
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import{__awaiter as t,__decorate as e,__metadata as s}from"tslib";import{ActorComponent as i,Component as o,Attach as n}from"../component";import{CameraComponent as h}from"./camera-component";import{Vector3 as a}from"three";import{ViewController as r}from"../../services/render";import{DecimalInput as c,RestrictedRotationInput as m}from"../../input";import{PhysicsSystem as d,RayTestResult as l}from"../../services/physics/physics-system";import{clamp as u,lerp as p}from"three/src/math/MathUtils";let f=class extends i{constructor(t,e){super(),this.viewController=t,this.physicsSystem=e,this.distance=9,this.minDistance=1.5,this.maxDistance=this.distance,this.height=3,this.offsetX=-1,this.offsetZ=1.5,this.autoActivate=!0,this.bounceBackSpeed=5,this.collisionCheckRadius=.5,this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.rotationInput=new m(-Math.PI/4,Math.PI/2-.7),this.zoomInput=new c(1,0,1),this.offset=new a,this.lookAtOffset=new a(this.offsetX,0,this.offsetZ),this.isMouseLocked=!1,this.canvas=null,this.pointerLockInactivatedAt=null,this.onMouseDown=t=>{this.isMouseLocked||this.hideCursor()},this.onKeyDown=t=>{"Escape"===t.key&&this.showCursor()},this.onPointerLockChange=()=>{null!=document.pointerLockElement||null!=document.mozPointerLockElement||this.showCursor()}}onInit(){return t(this,void 0,void 0,(function*(){this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.autoActivate&&this.viewController.setCamera(this.camera.instance),this.physicsSystem.beforeStep.subscribe((t=>{this.setFromRotation(t)}));const t=this.element;t.addEventListener("mousedown",this.onMouseDown),t.addEventListener("keydown",this.onKeyDown),document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),this.disposed.subscribe((()=>{t.removeEventListener("mousedown",this.onMouseDown),t.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("pointerlockchange",this.onPointerLockChange,!1)}))}))}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){const e=u(Math.min(this.restrictedDistance,this.distance),this.minDistance,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(),this.checkForCollision(t)}checkForCollision(t){const e=this.getLookAtPosition(),s=v;let i=!1,o=this.distance;const n=new l,h=this.camera.instance.getWorldPosition(y);for(let t=-1;t<=1;t++){const a=w.subVectors(h,e);s.copy(h).add(a.multiplyScalar(1.2)),s.x+=t*this.collisionCheckRadius,this.physicsSystem.rayTest(e,s,n,{debugLifetime:0}),n.hasHit&&n.distance<this.distance&&(o=Math.min(n.distance,o),i||(i=n.hasHit))}i||(this.restrictedDistance=p(this.restrictedDistance,this.distance,this.bounceBackSpeed*t))}getLookAtPosition(){const t=k;return t.set(0,0,0),t.y=this.height,t.add(this.lookAtOffset),t.applyMatrix4(this.actor.container.matrixWorld),t}updateCameraPosition(){this.camera.instance.position.copy(this.offset);const t=this.getLookAtPosition();this.camera.instance.lookAt(t)}};e([n(),s("design:type",h)],f.prototype,"camera",void 0),f=e([o(),s("design:paramtypes",[r,d])],f);export{f as ThirdPartyCameraComponent};const k=new a,v=new a,w=(new a,new a),y=new a;
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { Constructable } from 'typedi';
|
2
|
+
import { BaseActor } from "./actor";
|
3
|
+
export declare abstract class ActorComponent<ActorType extends BaseActor = BaseActor> {
|
4
|
+
actor: ActorType;
|
5
|
+
constructor();
|
6
|
+
onInit(): Promise<void> | void;
|
7
|
+
onBeginPlay(): void;
|
8
|
+
onEndPlay(): void;
|
9
|
+
/**
|
10
|
+
* Code that has to run before every rendered frame. This will run after the
|
11
|
+
* actor's onInit method has run.
|
12
|
+
* @param deltaTime The amount of time in seconds since the last frame
|
13
|
+
*/
|
14
|
+
onUpdate(deltaTime: number): void;
|
15
|
+
/**
|
16
|
+
* Code that has to run before every rendered frame but after the update method has been
|
17
|
+
* called on all actors.
|
18
|
+
* @param deltaTime The amount of time in seconds since the last frame
|
19
|
+
*/
|
20
|
+
onLateUpdate(deltaTime: number): void;
|
21
|
+
get disposed(): import("rxjs").Subject<true>;
|
22
|
+
protected attach<T extends ActorComponent>(type: Constructable<T>, props?: ComponentAttachProps<T>): T;
|
23
|
+
}
|
24
|
+
export type ComponentOptions = {
|
25
|
+
/**
|
26
|
+
* While in the editor, only components explicitly set to be used in the editor should be initiated.
|
27
|
+
* This is because other components may fail as there will be many things that are not
|
28
|
+
* available or initiated like various game services. For example, a component that
|
29
|
+
* act as an AI controller that moves the actor around the map would probably not be wanted
|
30
|
+
* in the editor where things are expected to be static.
|
31
|
+
* However, some animations may be wanted to be able to visualise how it looks in the world without running the game.
|
32
|
+
*/
|
33
|
+
inEditor: boolean;
|
34
|
+
editorOnly: boolean;
|
35
|
+
};
|
36
|
+
export declare function Component(options?: Partial<ComponentOptions>): (targetConstructor: any) => void;
|
37
|
+
export type ComponentAttachProps<T> = Partial<Omit<{
|
38
|
+
[p in keyof T]: T[p];
|
39
|
+
}, keyof ActorComponent>>;
|
40
|
+
export declare function Attach<T extends ActorComponent>(props?: ComponentAttachProps<T>, type?: Constructable<T>): (target: Object, propertyName: string | Symbol, index?: number) => void;
|
41
|
+
export declare function attach<T extends ActorComponent>(type: Constructable<T>, props?: ComponentAttachProps<T>): T;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import t,{Service as n,Inject as o}from"typedi";import{_setupActorUpdateEventHandlers as e}from"./actor";import{activeContainerInstance as r}from"./internal/container-map";import{randomString as i}from"../../utils/math";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=null!=e?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){var e;const a=null!==(e=r.value)&&void 0!==e?e:t.of("default"),c=i();a.set({id:c,type:n,transient:!0});const s=a.get(c);if(null!=o)for(const t of Object.keys(o))s[t]=o[t];return s}
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { Constructable, ContainerInstance } from "typedi";
|
2
|
+
import { BaseActor } from "./actor";
|
3
|
+
import { EngineEnvironment } from '../env';
|
4
|
+
import { ActorProvider } from '../../scene/materializer';
|
5
|
+
import { Vector3, Euler } from "three";
|
6
|
+
export declare class ActorFactory implements ActorProvider<BaseActor> {
|
7
|
+
private container;
|
8
|
+
private env;
|
9
|
+
constructor(container: ContainerInstance, env: EngineEnvironment);
|
10
|
+
create<T extends BaseActor>(type: Constructable<T>, position?: Vector3, rotation?: Euler, delayInit?: boolean): Promise<T>;
|
11
|
+
initActor(actor: BaseActor): Promise<void>;
|
12
|
+
}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import{__awaiter as t,__decorate as i,__metadata as n}from"tslib";import{ContainerInstance as o}from"typedi";import{Service as r}from"typedi";import{initComponents as e}from"./internal/component-init";import{activeContainerInstance as s,containerRefMap as a}from"./internal/container-map";let c=class{constructor(t,i){this.container=t,this.env=i}create(i,n,o,r){return t(this,void 0,void 0,(function*(){const t=this.container;s.value=t;const e=(1e4*Math.random()).toString();t.set({id:e,type:i,transient:!0});const c=t.get(e);return s.value=null,t.remove(i),a.set(c,t),n&&c.container.position.copy(n),o&&c.container.rotation.copy(o),!0!==r&&(yield this.initActor(c)),c}))}initActor(i){var n;return t(this,void 0,void 0,(function*(){yield e(i,i,null!==(n=this.env.inEditor)&&void 0!==n&&n),yield i.onInit(),i.__isInitialised=!0}))}};c=i([r(),n("design:paramtypes",[o,Object])],c);export{c as ActorFactory};
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +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';
|
@@ -0,0 +1,5 @@
|
|
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";
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import{__awaiter as o}from"tslib";import{ActorComponent as n}from"../component";export function initComponents(t,i,r=!1){return o(this,void 0,void 0,(function*(){const o=[];for(const c of Object.values(t))if(c instanceof n||null!=(null==c?void 0:c.constructor)&&!0===c.constructor.__isActorComponent){if(r&&!c.constructor.__inEditor)continue;if(!r&&c.constructor.__onlyEditor)continue;c.actor=i,yield c.onInit(),o.push(initComponents(c,i,r))}return Promise.all(o)}))}
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { AnimationClip } from "three";
|
2
|
+
type TransitionPredicate = (timeElapsed: number) => boolean;
|
3
|
+
declare class Transition {
|
4
|
+
readonly state: AnimationState;
|
5
|
+
readonly predicate: TransitionPredicate;
|
6
|
+
constructor(state: AnimationState, predicate: TransitionPredicate);
|
7
|
+
}
|
8
|
+
export declare class AnimationState {
|
9
|
+
readonly clip?: AnimationClip;
|
10
|
+
readonly uuid: number;
|
11
|
+
parent: AnimationState;
|
12
|
+
readonly transitions: Transition[];
|
13
|
+
name: string;
|
14
|
+
/**
|
15
|
+
* An animation clip does not need to be specified.
|
16
|
+
* This is is to treat the animation state as a conduit to transition to other states.
|
17
|
+
* This works both for standalone states as well as child states to group multiple children together
|
18
|
+
* under the same transition predicate.
|
19
|
+
*/
|
20
|
+
constructor(clip?: AnimationClip);
|
21
|
+
named(name: string): this;
|
22
|
+
getAncestors(): AnimationState[];
|
23
|
+
getRoot(): AnimationState;
|
24
|
+
createChild(clip: AnimationClip, predicate: TransitionPredicate): AnimationState;
|
25
|
+
split(predicate: TransitionPredicate, ifTrue?: AnimationClip, otherwise?: AnimationClip): AnimationState[];
|
26
|
+
transitionsTo(state: AnimationState, predicate?: TransitionPredicate): void;
|
27
|
+
transitionsOnComplete(state: AnimationState, predicate?: TransitionPredicate): void;
|
28
|
+
transitionsBetween(state: AnimationState, predicate: TransitionPredicate): void;
|
29
|
+
}
|
30
|
+
export declare class AnimationStateMachine {
|
31
|
+
private initialState;
|
32
|
+
current: AnimationState;
|
33
|
+
timer: number;
|
34
|
+
constructor(initialState: AnimationState);
|
35
|
+
step(deltaTime: number): any;
|
36
|
+
private _getNext;
|
37
|
+
}
|
38
|
+
export {};
|
@@ -0,0 +1,5 @@
|
|
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){var e;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&&null!==(e=t.getAncestors().find((t=>null!=t.clip)))&&void 0!==e?e:t}const n=t=>i=>!t(i);
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { AnimationClip, VectorKeyframeTrack, Bone } from "three";
|
2
|
+
/**
|
3
|
+
* A root motion clip removes the movement track from the clip but stores
|
4
|
+
* it so that it can be reused by a movement controller.
|
5
|
+
* The clip can be configured to be fixed in place which is usually appropriate
|
6
|
+
* for animations that should not affect the character's position like normal
|
7
|
+
* movement animations like walking and jumping which should be controlled
|
8
|
+
* by game logic and physics rather than animation tracks.
|
9
|
+
* Wrapping the animation in root motion though helps the character animation
|
10
|
+
* system to use the movement information embedded in the source clip
|
11
|
+
* to determine how fast or slow to play the animation.
|
12
|
+
*
|
13
|
+
* TODO Replace root motion clip with something else. Should not need to subclass animation clip.
|
14
|
+
* Instead the play function should support a more complex type like an animation blueprint/graph/sequence.
|
15
|
+
*/
|
16
|
+
export declare class RootMotionClip extends AnimationClip {
|
17
|
+
motionTrack: VectorKeyframeTrack;
|
18
|
+
displacement: number;
|
19
|
+
fixedInPlace: boolean;
|
20
|
+
private rootBone;
|
21
|
+
private source;
|
22
|
+
static fromClip(source: AnimationClip, fixedInPlace?: boolean, rootBone?: Bone): RootMotionClip;
|
23
|
+
clone(): this;
|
24
|
+
}
|
25
|
+
type BoneLayerId = number;
|
26
|
+
export declare class BoneLayer {
|
27
|
+
uuid: BoneLayerId;
|
28
|
+
order: number;
|
29
|
+
boneMask: Bone[];
|
30
|
+
}
|
31
|
+
export {};
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import{AnimationClip as o,Vector3 as t}from"three";export class RootMotionClip extends o{constructor(){super(...arguments),this.displacement=0,this.fixedInPlace=!1}static fromClip(o,e=!1,n){const i=new RootMotionClip(o.name,o.duration,o.tracks.slice(),o.blendMode);if(i.fixedInPlace=e,i.rootBone=n,i.source=o,i.uuid=o.uuid,i.motionTrack=null!=n?o.tracks.find((o=>o.name===`${n.name}.position`)):o.tracks.find((o=>o.name.endsWith(".position"))),i.motionTrack){i.tracks.splice(i.tracks.indexOf(i.motionTrack),1);const o=(new t).fromArray(i.motionTrack.values,0),e=(new t).fromArray(i.motionTrack.values,i.motionTrack.values.length-3);i.displacement=e.distanceTo(o)}else console.error("Could not find root motion track",o,n);return i}clone(){return RootMotionClip.fromClip(this.source.clone(),this.fixedInPlace,this.rootBone)}}let e=53912381;export class BoneLayer{constructor(){this.uuid=e++,this.order=0,this.boneMask=[]}}
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|
@@ -0,0 +1,14 @@
|
|
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
|
+
export { Container as DIContainer } from 'typedi';
|
12
|
+
export * from './animation/anim-sm';
|
13
|
+
export * from './animation/root-motion';
|
14
|
+
export * from './services/asset-loader';
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import"reflect-metadata";export*from"./initiate";export*from"./inject";export{Service,Inject}from"typedi";export{ActorFactory}from"./actors/factory";export{Actor,BaseActor}from"./actors/actor";export{Component,ActorComponent,attach,Attach}from"./actors/component";export*from"./services/world";export*from"./services/render";export*from"./services/physics/physics-system";export{Container as DIContainer}from"typedi";export*from"./animation/anim-sm";export*from"./animation/root-motion";export*from"./services/asset-loader";
|
2
|
+
/*
|
3
|
+
* Copyright (©) 2023. All rights reserved.
|
4
|
+
* See the LICENSE.md file for details.
|
5
|
+
*/
|