@hology/core 0.0.84 → 0.0.85

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.
@@ -48,13 +48,14 @@ export declare class CharacterAnimationComponent extends ActorComponent {
48
48
  *
49
49
  * @param currentAction The action that should be transitioned from.
50
50
  * @param clip
51
- * @param inplace
51
+ * @param options
52
52
  * @returns
53
53
  */
54
54
  transition(currentAction: AnimationAction, clip: AnimationClip, options?: PlayOptions): AnimationAction;
55
55
  }
56
56
  export type PlayOptions = Partial<{
57
57
  inPlace: boolean;
58
+ /** Whether the animation should loop. Default: true */
58
59
  loop: boolean;
59
60
  layer: BoneLayer;
60
61
  priority: number;
@@ -1,4 +1,4 @@
1
- import{__decorate as t}from"tslib";import{ActorComponent as e,Component as i}from"../../../component.js";import{RootMotionClip as r}from"../../../../animation/root-motion.js";import{inject as o}from"../../../../inject.js";import{ViewController as s}from"../../../../services/render.js";import{AnimationMixer as n,Bone as p,Object3D as l,LoopOnce as h}from"three";import{CharacterMovementComponent as u}from"./character-movement.js";let a=class extends e{constructor(){super(...arguments),this.viewController=o(s),this.stateMachines=[],this.upperStateMachines=[],this.fadeTime=.2,this.movementSpeed=null,this.upperBodyTimer=0,this.upperBodyOverride=!1,this.fullBodyTimer=0,this.currentFullBodyPriority=-1,this.currentUpperBodyPriority=-1,this.getFullBodyClip=y((t=>t.uuid),(t=>c(this.fullBodyMask,t))),this.getUpperBodyClip=y((t=>t.uuid),(t=>c(this.upperBodyMask,t)))}onInit(){this.viewController.onUpdate(this.actor).subscribe((t=>this.updateInternal(t))),this.characterMovement=this.actor.getComponent(u)}getRootMotionAction(){if(this.fullBodyAction.getClip()instanceof r)return this.fullBodyAction}setup(t,e,i){null!=e&&(this.upperBodyMask=d(e),this.fullBodyMask=function(t,e){const i=new Set(d(e).map((t=>t.uuid))),r=[];return t.traverse((t=>{(t instanceof p||t.isBone)&&!i.has(t.uuid)&&r.push(t)})),r}(function(t){let e;return t.traverse((t=>{(t instanceof p||t.isBone)&&null==e&&(e=t)})),e}(t),e)),null!=this.mixer&&this.mixer.stopAllAction(),this.mixer=new n(t)}updateStateMachines(t){this.stateMachines.forEach((e=>{e.step(t);const i=e.current.clip;null!=i&&this.play(i,{priority:0})})),this.upperStateMachines.forEach((e=>{e.step(t);const i=e.current.clip;null!=i?this.playUpper(i,{priority:0}):this.play(this.fullBodyClip)}))}updateInternal(t){null!=this.mixer&&(this.upperBodyTimer+=t,this.fullBodyTimer+=t,this.upperBodyAction&&this.upperBodyOverride&&this.upperBodyAction.getClip().duration-2*(this.overrideFadeTimeUpper??this.fadeTime)<this.upperBodyTimer&&(this.upperBodyOverride=!1,null!=this.fullBodyClip&&this.transition(this.upperBodyAction,this.getUpperBodyClip(this.fullBodyClip)),this.upperBodyAction=null,this.overrideFadeTimeUpper=null),this.fullBodyAction&&this.fullBodyAction.loop===h&&this.fullBodyAction.getClip().duration-2*(this.overrideFadeTime??this.fadeTime)<this.fullBodyTimer&&(this.currentFullBodyPriority=-1,this.overrideFadeTime=null),null!=this.characterMovement&&(this.movementSpeed=this.characterMovement.horizontalSpeed),this.updateStateMachines(t),this.syncMovementSpeed(this.fullBodyAction),this.upperBodyOverride||this.syncMovementSpeed(this.upperBodyAction),this.mixer.update(t))}syncMovementSpeed(t){if(null!=t){const e=t.getClip();if(e instanceof r&&e.fixedInPlace&&null!=this.movementSpeed){t.timeScale=e.duration/e.displacement*this.movementSpeed;const i=this.mixer.getRoot();i instanceof l&&(t.timeScale/=i.scale.x)}}}playStateMachine(t){this.stateMachines.push(t)}playUpperStateMachine(t){this.upperStateMachines.push(t)}removeStateMachine(t){const e=this.stateMachines.indexOf(t);e>=0&&this.stateMachines.splice(e,1)}removeUpperStateMachine(t){const e=this.upperStateMachines.indexOf(t);e>=0&&this.upperStateMachines.splice(e,1)}playUpper(t,e={}){const i=e?.priority??1;i<this.currentUpperBodyPriority||(this.currentUpperBodyPriority=i,this.upperBodyAction=this.transition(this.upperBodyAction,this.getUpperBodyClip(t),e),this.upperBodyTimer=0,this.upperBodyOverride=!0,this.overrideFadeTimeUpper=e.fadeTime)}play(t,e={}){!function(t,e){if(!1===t||"function"==typeof t&&!1===t())throw new Error(e)}(null!=this.mixer,"Can't play animation before setup is called");const i=e.priority??1;i<this.currentFullBodyPriority||(this.currentFullBodyPriority=i,this.fullBodyTimer=0,this.upperBodyOverride||(this.upperBodyAction=this.transition(this.upperBodyAction,this.getUpperBodyClip(t),e)),this.fullBodyClip=t,this.fullBodyAction=this.transition(this.fullBodyAction,this.getFullBodyClip(t),e),this.fullBodyAction.getClip().uuid==this.upperBodyAction.getClip().uuid&&this.upperBodyAction.syncWith(this.fullBodyAction),this.overrideFadeTime=e.fadeTime)}onActionDone(t){return new Promise((e=>{const i=r=>{r.action===t&&(e(r.action),this.mixer.removeEventListener("finished",i))};this.mixer.addEventListener("finished",i)}))}transition(t,e,i={}){if(null!=t&&t.getClip().uuid===e.uuid)return t;if(t){const r=t,o=t=this.mixer.clipAction(e);o.play(),o.enabled=!0,o.setEffectiveTimeScale(1),o.setEffectiveWeight(1),o.time=0,r.crossFadeTo(o,i?.fadeTime??this.fadeTime,!0)}else t=this.mixer.clipAction(e),t?.fadeIn(.3),t?.play();return!1===i.loop&&(t.setLoop(h,1),t.clampWhenFinished=!0,t.reset()),t}};a=t([i({inEditor:!0})],a);export{a as CharacterAnimationComponent};function c(t,e){if(null==t)return e;const i=e.clone(),r=new Set(t.map((t=>t.name)));return i.tracks=i.tracks.filter((t=>r.has(t.name.split(".")[0]))),i}function d(t){return t.flatMap((t=>function(t){const e=[];return t.traverse((t=>{e.push(t)})),e}(t))).filter((t=>t instanceof p))}function y(t,e){const i=new Map;return(r,...o)=>{const s=t(r);return i.has(s)||i.set(s,e(r,...o)),i.get(s)}}
1
+ import{__decorate as t}from"tslib";import{ActorComponent as e,Component as i}from"../../../component.js";import{RootMotionClip as o}from"../../../../animation/root-motion.js";import{inject as r}from"../../../../inject.js";import{ViewController as s}from"../../../../services/render.js";import{AnimationMixer as n,Bone as p,Object3D as l,LoopOnce as h}from"three";import{CharacterMovementComponent as u}from"./character-movement.js";let a=class extends e{constructor(){super(...arguments),this.viewController=r(s),this.stateMachines=[],this.upperStateMachines=[],this.fadeTime=.2,this.movementSpeed=null,this.upperBodyTimer=0,this.upperBodyOverride=!1,this.fullBodyTimer=0,this.currentFullBodyPriority=-1,this.currentUpperBodyPriority=-1,this.getFullBodyClip=y((t=>t.uuid),(t=>c(this.fullBodyMask,t))),this.getUpperBodyClip=y((t=>t.uuid),(t=>c(this.upperBodyMask,t)))}onInit(){this.viewController.onUpdate(this.actor).subscribe((t=>this.updateInternal(t))),this.characterMovement=this.actor.getComponent(u)}getRootMotionAction(){if(this.fullBodyAction.getClip()instanceof o)return this.fullBodyAction}setup(t,e,i){null!=e&&(this.upperBodyMask=d(e),this.fullBodyMask=function(t,e){const i=new Set(d(e).map((t=>t.uuid))),o=[];return t.traverse((t=>{(t instanceof p||t.isBone)&&!i.has(t.uuid)&&o.push(t)})),o}(function(t){let e;return t.traverse((t=>{(t instanceof p||t.isBone)&&null==e&&(e=t)})),e}(t),e)),null!=this.mixer&&this.mixer.stopAllAction(),this.mixer=new n(t)}updateStateMachines(t){this.stateMachines.forEach((e=>{e.step(t);const i=e.current.clip;null!=i&&this.play(i,{priority:0,loop:e.current.options.loop??!0})})),this.upperStateMachines.forEach((e=>{e.step(t);const i=e.current.clip;null!=i?this.playUpper(i,{priority:0,loop:e.current.options.loop??!0}):this.play(this.fullBodyClip)}))}updateInternal(t){null!=this.mixer&&(this.upperBodyTimer+=t,this.fullBodyTimer+=t,this.upperBodyAction&&this.upperBodyOverride&&this.upperBodyAction.getClip().duration-2*(this.overrideFadeTimeUpper??this.fadeTime)<this.upperBodyTimer&&(this.upperBodyOverride=!1,null!=this.fullBodyClip&&this.transition(this.upperBodyAction,this.getUpperBodyClip(this.fullBodyClip)),this.upperBodyAction=null,this.overrideFadeTimeUpper=null),this.fullBodyAction&&this.fullBodyAction.loop===h&&this.fullBodyAction.getClip().duration-2*(this.overrideFadeTime??this.fadeTime)<this.fullBodyTimer&&(this.currentFullBodyPriority=-1,this.overrideFadeTime=null),null!=this.characterMovement&&(this.movementSpeed=this.characterMovement.horizontalSpeed),this.updateStateMachines(t),this.syncMovementSpeed(this.fullBodyAction),this.upperBodyOverride||this.syncMovementSpeed(this.upperBodyAction),this.mixer.update(t))}syncMovementSpeed(t){if(null!=t){const e=t.getClip();if(e instanceof o&&e.fixedInPlace&&null!=this.movementSpeed){t.timeScale=e.duration/e.displacement*this.movementSpeed;const i=this.mixer.getRoot();i instanceof l&&(t.timeScale/=i.scale.x)}}}playStateMachine(t){this.stateMachines.push(t)}playUpperStateMachine(t){this.upperStateMachines.push(t)}removeStateMachine(t){const e=this.stateMachines.indexOf(t);e>=0&&this.stateMachines.splice(e,1)}removeUpperStateMachine(t){const e=this.upperStateMachines.indexOf(t);e>=0&&this.upperStateMachines.splice(e,1)}playUpper(t,e={}){const i=e?.priority??1;i<this.currentUpperBodyPriority||(this.currentUpperBodyPriority=i,this.upperBodyAction=this.transition(this.upperBodyAction,this.getUpperBodyClip(t),e),this.upperBodyTimer=0,this.upperBodyOverride=!0,this.overrideFadeTimeUpper=e.fadeTime)}play(t,e={}){!function(t,e){if(!1===t||"function"==typeof t&&!1===t())throw new Error(e)}(null!=this.mixer,"Can't play animation before setup is called");const i=e.priority??1;i<this.currentFullBodyPriority||(this.currentFullBodyPriority=i,this.fullBodyTimer=0,this.upperBodyOverride||(this.upperBodyAction=this.transition(this.upperBodyAction,this.getUpperBodyClip(t),e)),this.fullBodyClip=t,this.fullBodyAction=this.transition(this.fullBodyAction,this.getFullBodyClip(t),e),this.fullBodyAction.getClip().uuid==this.upperBodyAction.getClip().uuid&&this.upperBodyAction.syncWith(this.fullBodyAction),this.overrideFadeTime=e.fadeTime)}onActionDone(t){return new Promise((e=>{const i=o=>{o.action===t&&(e(o.action),this.mixer.removeEventListener("finished",i))};this.mixer.addEventListener("finished",i)}))}transition(t,e,i={}){if(null!=t&&t.getClip().uuid===e.uuid)return t;if(t){const o=t,r=t=this.mixer.clipAction(e);r.play(),r.enabled=!0,r.setEffectiveTimeScale(1),r.setEffectiveWeight(1),r.time=0,o.crossFadeTo(r,i?.fadeTime??this.fadeTime,!0)}else t=this.mixer.clipAction(e),t?.fadeIn(.3),t?.play();return!1===i.loop&&(t.setLoop(h,1),t.clampWhenFinished=!0,t.reset()),t}};a=t([i({inEditor:!0})],a);export{a as CharacterAnimationComponent};function c(t,e){if(null==t)return e;const i=e.clone(),o=new Set(t.map((t=>t.name)));return i.tracks=i.tracks.filter((t=>o.has(t.name.split(".")[0]))),i}function d(t){return t.flatMap((t=>function(t){const e=[];return t.traverse((t=>{e.push(t)})),e}(t))).filter((t=>t instanceof p))}function y(t,e){const i=new Map;return(o,...r)=>{const s=t(o);return i.has(s)||i.set(s,e(o,...r)),i.get(s)}}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -54,6 +54,13 @@ export declare class CharacterMovementComponent extends ActorComponent {
54
54
  constructor(physicsSystem: PhysicsSystem);
55
55
  private resetRootMotion;
56
56
  private rootMotionInterpolant;
57
+ /**
58
+ * Makes the character rotate to the direction of movement input instead
59
+ * of strafing or walking backwards
60
+ */
61
+ rotateToMovementDirection: boolean;
62
+ /** Makes the character rotate smoothly to the desired direction */
63
+ smoothRotation: boolean;
57
64
  onInit(): void | Promise<void>;
58
65
  private debugDirection;
59
66
  private rootMotionAction;
@@ -66,4 +73,5 @@ export declare class CharacterMovementComponent extends ActorComponent {
66
73
  private createCollisionShape;
67
74
  private step;
68
75
  private performMovement;
76
+ private arrowHelper;
69
77
  }
@@ -1,4 +1,4 @@
1
- import{__decorate as t,__metadata as i}from"tslib";import{ActionInput as e,AxisInput as o,RotationInput as s}from"../../../../../gameplay/input/index.js";import{PhysicsSystem as n,RayTestResult as r}from"../../../../../gameplay/services/physics/physics-system.js";import{MathUtils as a,Vector3 as c,ArrowHelper as l}from"three";import{ActorComponent as h,Component as p}from"../../../component.js";import{CharacterMovementMode as m}from"./modes.js";import{CapsuleCollisionShape as d}from"../../../../../scene/collision/collision-shape.js";import{takeUntil as u}from"rxjs";import{PhysicsBodyType as y}from"../../../../services/physics/physics-system.js";import g from"@dimforge/rapier3d-compat";import{RootMotionClip as f}from"../../../../../gameplay/animation/root-motion.js";import*as S from"three";const v=new c,w=new c,A=1/30,M=-131071;let x=class extends h{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)}set offset(t){this.cc.setOffset(t)}get offset(){return this.cc.offset()}set normalNudgeFactor(t){this.cc.setNormalNudgeFactor(t)}get normalNudgeFactor(){return this.cc.normalNudgeFactor()}constructor(t){super(),this.physicsSystem=t,this.directionInput=new o,this.jumpInput=new e,this.sprintInput=new e,this.rotationInput=new s,this.horizontalSpeed=0,this.maxSpeed=8,this.maxSpeedBackwards=8,this.maxSpeedSprint=12,this.jumpVelocity=7,this.fallingMovementControl=.5,this.fallingReorientation=!1,this.gravityOverride=null,this.colliderHeight=2,this.colliderRadius=.5,this.jumpInAir=!1,this.mass=50,this.allowSliding=!0,this.minSlopeSlideAngle=a.degToRad(70),this.maxSlopeClimbAngle=a.degToRad(70),this.applyImpulsesToDynamicBodies=!0,this.characterCollision=!1,this.enabled=!0,this.velocity=new c,this.mode=m.walking,this.isSprinting=!1,this.pressedJump=!1,this.rayTestResult=new r,this.resetRootMotion=!1;const i=this.cc=this.physicsSystem.getCharacterController(.1);i.enableSnapToGround(.1),i.enableAutostep(0,.1,!1)}onInit(){const t=this.cc;t.setApplyImpulsesToDynamicBodies(this.applyImpulsesToDynamicBodies),t.setMinSlopeSlideAngle(this.minSlopeSlideAngle),t.setMaxSlopeClimbAngle(this.maxSlopeClimbAngle),t.setCharacterMass(this.mass),t.setSlideEnabled(this.allowSliding),this.physicsSystem.addActor(this.actor,[this.createCollisionShape()],{mass:0,type:y.kinematic,continousCollisionDetection:!1,friction:0,restitution:.5,ignoreForNavMesh:!0}),this.rotationInput.rotation.copy(this.actor.rotation);let i=this.rotationInput.rotation.y;const e=new c,o=new c,s=new c,n=new c,r=new c,l=new c;let h=0,p=null;const d=new c,g=new c,x=new c,C=new c,T=this.characterCollision?null:M;this.physicsSystem.beforeStep.pipe(u(this.disposed)).subscribe((u=>{if(this.checkGrounded(u),!this.enabled)return;if(null!=this.rootMotionAction){if(this.rootMotionAction.getClip()instanceof f){const t=this.rootMotionInterpolant;this.resetRootMotion&&(d.fromArray(t.evaluate(0)),this.resetRootMotion=!1),C.fromArray(t.evaluate(this.rootMotionAction.time)),g.subVectors(C,d),d.copy(C),this.rootMotionAction.getRoot().getWorldScale(x),g.multiply(x)}}u>A&&(u=A);const y=null!=this.rootMotionAction&&this.rootMotionAction.enabled&&0!=g.length();this.pressedJump=this.jumpInput.activated,this.isSprinting=this.sprintInput.activated&&this.directionInput.vertical>=0;let M=i-this.rotationInput.rotation.y;i=this.rotationInput.rotation.y,s.copy(this.actor.position),n.set(-this.directionInput.vector.x,0,this.directionInput.vector.y).normalize();const j=n.z<0?this.maxSpeedBackwards:this.isSprinting?this.maxSpeedSprint:this.maxSpeed;if(l.copy(n).applyAxisAngle(I,this.rotationInput.rotation.y),this.mode===m.walking?(0!==l.length()?(h=Math.min(j,h),h=a.lerp(h,j,4*u)):h=0,r.copy(l).multiplyScalar(h),this.pressedJump&&(this.mode=m.falling,this.velocity.copy(r),this.velocity.y=this.jumpVelocity),r.y=.016*this.getEffectiveGravity()):this.mode===m.falling&&(this.pressedJump&&this.jumpInAir&&(this.mode=m.falling,this.velocity.copy(r),this.velocity.y=this.jumpVelocity),this.velocity.y+=u*this.getEffectiveGravity(),r.copy(this.velocity),r.add(l.clone().multiplyScalar(j*this.fallingMovementControl*u)),this.fallingReorientation&&r.applyAxisAngle(new c(0,1,0),-M)),o.copy(r).normalize(),e.copy(r),this.actor.rotation.y-=M,r.length(),y?(g.applyAxisAngle(I,this.actor.rotation.y),g.y+=u*this.getEffectiveGravity(),v.copy(g)):v.copy(r).multiplyScalar(u),this.isGrounded&&this.mode===m.walking&&(this.rayTestResult.distance>t.offset()||(v.y=0),this.physicsSystem.getActorComputedMovement(this.actor,t,v,T),t.computedCollision(0,R),null!=R&&null!=R.normal1)){const i=(new S.Vector3).copy(R.normal1);Math.acos(i.dot(I))>t.maxSlopeClimbAngle()&&(v.y=.016*this.getEffectiveGravity()*.5)}w.copy(this.physicsSystem.getActorComputedMovement(this.actor,t,v,T)),this.physicsSystem.setNextKinematicTranslation(this.actor,w);let G=function(t){if(t.numComputedCollisions()>0){const i=t.computedCollision(0);b.x=i.normal2.x,b.y=i.normal2.y,b.z=i.normal2.z;const e=b.angleTo(I);b.x=i.normal1.x,b.y=i.normal1.y,b.z=i.normal1.z;const o=b.angleTo(I);return!(e<100)&&o>t.minSlopeSlideAngle()}return!1}(t);y||this.isGrounded&&!G||this.mode!==m.falling&&(null==p?p=performance.now():performance.now()-p>100&&(this.mode=m.falling,this.velocity.copy(e))),this.isGrounded&&this.velocity.y<=0&&(this.mode,m.falling,this.mode=m.walking,this.velocity.y=0,p=null),this.mode,m.walking,this.horizontalSpeed=h}))}debugDirection(){const t=new l(v,this.actor.position,1,65280);this.actor.object.parent.add(t),setTimeout((()=>{t.removeFromParent()}),30);const i=new l(w,this.actor.position,1,16711680);this.actor.object.parent.add(i),setTimeout((()=>{i.removeFromParent()}),30)}setRootMotionAction(t){const i=t?.getClip();if(i instanceof f){this.rootMotionAction=t,this.resetRootMotion=!0;const e=[];this.rootMotionInterpolant=i.motionTrack.InterpolantFactoryMethodSmooth(e)}}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(){return this.gravityOverride??this.physicsSystem.getGravity().y}checkGrounded(t){this.colliderHeight,this.colliderRadius;G.y=-.05,this.physicsSystem.rayTest(C.addVectors(this.actor.position,j.set(0,this.offset,0)),T.addVectors(this.actor.position,G),this.rayTestResult,{excludeActor:this.actor,excludeTriggers:!0})}get isGrounded(){return this.rayTestResult.hasHit||this.cc.computedGrounded()}createCollisionShape(){const t=new d(this.colliderHeight,this.colliderRadius);return t.offset.y=this.colliderRadius+this.colliderHeight/2+this.offset,t.collisionGroup=M,t}step(t){}performMovement(t){}};x=t([p({inEditor:!1}),i("design:paramtypes",[n])],x);export{x as CharacterMovementComponent};const I=new c(0,1,0),b=new c;const C=new c,T=new c,j=new c(0,1,0),G=new c(0,-.1,0),R=(new c(0,-1,0),new g.CharacterCollision);
1
+ import{__decorate as t,__metadata as i}from"tslib";import{ActionInput as e,AxisInput as o,RotationInput as s}from"../../../../../gameplay/input/index.js";import{PhysicsSystem as n,RayTestResult as r}from"../../../../../gameplay/services/physics/physics-system.js";import{MathUtils as a,Vector3 as c,ArrowHelper as l}from"three";import{ActorComponent as h,Component as p}from"../../../component.js";import{CharacterMovementMode as m}from"./modes.js";import{CapsuleCollisionShape as d}from"../../../../../scene/collision/collision-shape.js";import{takeUntil as u}from"rxjs";import{PhysicsBodyType as y}from"../../../../services/physics/physics-system.js";import g from"@dimforge/rapier3d-compat";import{RootMotionClip as f}from"../../../../../gameplay/animation/root-motion.js";import*as S from"three";import{clamp as w}from"../../../../../utils/math.js";const v=new c,M=new c,A=1/30,x=-131071;let I=class extends h{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)}set offset(t){this.cc.setOffset(t)}get offset(){return this.cc.offset()}set normalNudgeFactor(t){this.cc.setNormalNudgeFactor(t)}get normalNudgeFactor(){return this.cc.normalNudgeFactor()}constructor(t){super(),this.physicsSystem=t,this.directionInput=new o,this.jumpInput=new e,this.sprintInput=new e,this.rotationInput=new s,this.horizontalSpeed=0,this.maxSpeed=8,this.maxSpeedBackwards=8,this.maxSpeedSprint=12,this.jumpVelocity=7,this.fallingMovementControl=.5,this.fallingReorientation=!1,this.gravityOverride=null,this.colliderHeight=2,this.colliderRadius=.5,this.jumpInAir=!1,this.mass=50,this.allowSliding=!0,this.minSlopeSlideAngle=a.degToRad(70),this.maxSlopeClimbAngle=a.degToRad(70),this.applyImpulsesToDynamicBodies=!0,this.characterCollision=!1,this.enabled=!0,this.velocity=new c,this.mode=m.walking,this.isSprinting=!1,this.pressedJump=!1,this.rayTestResult=new r,this.resetRootMotion=!1,this.rotateToMovementDirection=!1,this.smoothRotation=!0;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:y.kinematic,continousCollisionDetection:!1,friction:0,restitution:.5,ignoreForNavMesh:!0}),this.rotationInput.rotation.copy(this.actor.rotation);let i=this.rotationInput.rotation.y;const e=new c,o=new c,s=new c,n=new c(0,0,1),r=new c,l=new c,h=new c;let p=0,d=null;const g=new c,I=new c,C=new c,j=new c,R=this.characterCollision?null:x;this.physicsSystem.beforeStep.pipe(u(this.disposed)).subscribe((u=>{if(this.checkGrounded(u),!this.enabled)return;if(null!=this.rootMotionAction){if(this.rootMotionAction.getClip()instanceof f){const t=this.rootMotionInterpolant;this.resetRootMotion&&(g.fromArray(t.evaluate(0)),this.resetRootMotion=!1),j.fromArray(t.evaluate(this.rootMotionAction.time)),I.subVectors(j,g),g.copy(j),this.rootMotionAction.getRoot().getWorldScale(C),I.multiply(C)}}u>A&&(u=A);const y=null!=this.rootMotionAction&&this.rootMotionAction.enabled&&0!=I.length();this.pressedJump=this.jumpInput.activated,this.isSprinting=this.sprintInput.activated;let x=this.rotationInput.rotation.y-i;s.copy(this.actor.position),r.set(-this.directionInput.vector.x,0,this.directionInput.vector.y).normalize();const G=!this.rotateToMovementDirection&&r.z<0?this.maxSpeedBackwards:this.isSprinting?this.maxSpeedSprint:this.maxSpeed;if(h.set(0,0,0),this.rotateToMovementDirection){if(r.lengthSq()>0){z.setFromUnitVectors(n.clone().normalize(),r.clone().normalize()),n.copy(r);const t=(x%(2*Math.PI)+3*Math.PI)%(2*Math.PI)-Math.PI,e=Math.abs(t),o=this.smoothRotation?w(10*u*t,-e,e):t;k.setFromEuler(F.set(0,o,0)),z.multiply(k),this.actor.object.applyQuaternion(z),h.copy(this.actor.object.getWorldDirection(H).normalize()),i+=o}}else h.copy(r).applyAxisAngle(b,this.rotationInput.rotation.y),i=this.rotationInput.rotation.y,this.actor.rotation.y+=x;if(this.mode===m.walking?(0!==h.length()?(p=Math.min(G,p),p=a.lerp(p,G,4*u)):p=0,l.copy(h).multiplyScalar(p),this.pressedJump&&(this.mode=m.falling,this.velocity.copy(l),this.velocity.y=this.jumpVelocity),l.y=.016*this.getEffectiveGravity()):this.mode===m.falling&&(this.pressedJump&&this.jumpInAir&&(this.mode=m.falling,this.velocity.copy(l),this.velocity.y=this.jumpVelocity),this.velocity.y+=u*this.getEffectiveGravity(),l.copy(this.velocity),l.add(h.clone().multiplyScalar(G*this.fallingMovementControl*u)),this.fallingReorientation&&l.applyAxisAngle(new c(0,1,0),x)),o.copy(l).normalize(),e.copy(l),l.length(),y?(I.applyAxisAngle(b,this.actor.rotation.y),I.y+=u*this.getEffectiveGravity(),v.copy(I)):v.copy(l).multiplyScalar(u),this.isGrounded&&this.mode===m.walking&&(this.rayTestResult.distance>t.offset()||(v.y=0),this.physicsSystem.getActorComputedMovement(this.actor,t,v,R),t.computedCollision(0,D),null!=D&&null!=D.normal1)){const i=(new S.Vector3).copy(D.normal1);Math.acos(i.dot(b))>t.maxSlopeClimbAngle()&&(v.y=.016*this.getEffectiveGravity()*.5)}M.copy(this.physicsSystem.getActorComputedMovement(this.actor,t,v,R)),this.physicsSystem.setNextKinematicTranslation(this.actor,M);let E=function(t){if(t.numComputedCollisions()>0){const i=t.computedCollision(0);T.x=i.normal2.x,T.y=i.normal2.y,T.z=i.normal2.z;const e=T.angleTo(b);T.x=i.normal1.x,T.y=i.normal1.y,T.z=i.normal1.z;const o=T.angleTo(b);return!(e<100)&&o>t.minSlopeSlideAngle()}return!1}(t);y||this.isGrounded&&!E||this.mode!==m.falling&&(null==d?d=performance.now():performance.now()-d>100&&(this.mode=m.falling,this.velocity.copy(e))),this.isGrounded&&this.velocity.y<=0&&(this.mode,m.falling,this.mode=m.walking,this.velocity.y=0,d=null),this.mode,m.walking,this.horizontalSpeed=p}))}debugDirection(){const t=new l(v,this.actor.position,1,65280);this.actor.object.parent.add(t),setTimeout((()=>{t.removeFromParent()}),30);const i=new l(M,this.actor.position,1,16711680);this.actor.object.parent.add(i),setTimeout((()=>{i.removeFromParent()}),30)}setRootMotionAction(t){const i=t?.getClip();if(i instanceof f){this.rootMotionAction=t,this.resetRootMotion=!0;const e=[];this.rootMotionInterpolant=i.motionTrack.InterpolantFactoryMethodSmooth(e)}}getWallDirection(t,i){const e=t.clone().negate().cross(b);return e.dot(i)<0?e.negate():e}moveTo(t){this.actor.position.copy(t),this.physicsSystem.updateActorTransform(this.actor)}getEffectiveGravity(){return this.gravityOverride??this.physicsSystem.getGravity().y}checkGrounded(t){this.colliderHeight,this.colliderRadius;G.y=-.05,this.physicsSystem.rayTest(C.addVectors(this.actor.position,R.set(0,this.offset,0)),j.addVectors(this.actor.position,G),this.rayTestResult,{excludeActor:this.actor,excludeTriggers:!0})}get isGrounded(){return this.rayTestResult.hasHit||this.cc.computedGrounded()}createCollisionShape(){const t=new d(this.colliderHeight,this.colliderRadius);return t.offset.y=this.colliderRadius+this.colliderHeight/2+this.offset,t.collisionGroup=x,t}step(t){}performMovement(t){}arrowHelper(t,i,e){const o=new l(t,i,1,e);this.actor.object.parent.add(o),setTimeout((()=>{o.removeFromParent()}),30)}};I=t([p({inEditor:!1}),i("design:paramtypes",[n])],I);export{I as CharacterMovementComponent};const b=new c(0,1,0),T=new c;const C=new c,j=new c,R=new c(0,1,0),G=new c(0,-.1,0),D=(new c(0,-1,0),new g.CharacterCollision),z=new S.Quaternion,k=new S.Quaternion,F=new S.Euler,H=new S.Vector3;
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -1,5 +1,5 @@
1
1
  import { ActorComponent } from '../component.js';
2
- import { CameraComponent } from './camera-component.js';
2
+ import { PerspectiveCamera } from 'three';
3
3
  import { ViewController } from '../../services/render.js';
4
4
  import { DecimalInput, RestrictedRotationInput } from '../../input/index.js';
5
5
  import { PhysicsSystem } from '../../services/physics/physics-system.js';
@@ -10,7 +10,11 @@ import { PhysicsSystem } from '../../services/physics/physics-system.js';
10
10
  export declare class ThirdPersonCameraComponent extends ActorComponent {
11
11
  private viewController;
12
12
  private physicsSystem;
13
- camera: CameraComponent;
13
+ private aspect;
14
+ near: number;
15
+ far: number;
16
+ viewAngle: number;
17
+ camera: PerspectiveCamera;
14
18
  distance: number;
15
19
  minDistance: number;
16
20
  maxDistance: number;
@@ -25,6 +29,8 @@ export declare class ThirdPersonCameraComponent extends ActorComponent {
25
29
  readonly zoomInput: DecimalInput;
26
30
  private readonly offset;
27
31
  private readonly lookAtOffset;
32
+ fixedBehind: boolean;
33
+ private world;
28
34
  constructor(viewController: ViewController, physicsSystem: PhysicsSystem);
29
35
  isMouseLocked: boolean;
30
36
  onInit(): Promise<void>;
@@ -1,4 +1,4 @@
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.camera=o(n),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.activate()}activate(){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(){"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0||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,excludeTriggers:!0}),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)}};u=t([i(),e("design:paramtypes",[c,d])],u);export{u as ThirdPersonCameraComponent};const p=new a,f=new a,k=(new a,new a),w=new a;export class ThirdPartyCameraComponent extends u{}
1
+ import{__decorate as t,__metadata as e}from"tslib";import{ActorComponent as i,Component as s}from"../component.js";import{Vector3 as o,MathUtils as n,PerspectiveCamera as a}from"three";import{ViewController as h}from"../../services/render.js";import{DecimalInput as r,RestrictedRotationInput as c}from"../../input/index.js";import{PhysicsSystem as d,RayTestResult as m}from"../../services/physics/physics-system.js";import{Parameter as l}from"../../../shader/parameter.js";import{World as p}from"../../services/world.js";import{inject as u}from"../../../gameplay/inject.js";const f=void 0!==window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let w=class extends i{constructor(t,e){super(),this.viewController=t,this.physicsSystem=e,this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.near=.5,this.far=500,this.viewAngle=f?30:45,this.camera=new a(this.viewAngle,this.aspect,this.near,this.far),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 c(-Math.PI/4,Math.PI/2-.7),this.zoomInput=new r(1,0,1),this.offset=new o,this.lookAtOffset=new o(this.offsetX,0,this.offsetZ),this.fixedBehind=!0,this.world=u(p),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.world.scene.add(this.camera),this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.autoActivate&&this.activate()}activate(){this.viewController.setCamera(this.camera);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(){"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0||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=n.clamp(Math.min(this.restrictedDistance,this.distance),Math.min(this.minDistance,this.restrictedDistance),Math.max(this.distance*this.zoomInput.value,this.minDistance)),i=Math.cos(this.rotationInput.rotation.x)*e,s=this.fixedBehind?0:this.rotationInput.rotation.y;this.offset.x=Math.sin(-s)*i,this.offset.y=Math.sin(this.rotationInput.rotation.x)*e+2,this.offset.z=Math.cos(-s)*-i,this.offset.add(this.lookAtOffset),this.updateCameraPosition()}checkForCollision(t){const e=this.getLookAtPosition(),i=y;let s=!1,o=this.distance;const a=new m,h=this.camera.getWorldPosition(g);for(let t=-1;t<=1;t++){const n=k.subVectors(h,e);i.copy(h).add(n.multiplyScalar(1.2)),i.x+=t*this.collisionCheckRadius,this.physicsSystem.rayTest(e,i,a,{debugLifetime:0,excludeActor:this.actor,excludeTriggers:!0}),a.hasHit&&a.distance<this.distance&&(o=Math.min(a.distance,o),s||=a.hasHit)}s||(this.restrictedDistance=n.lerp(this.restrictedDistance,this.distance,n.clamp(this.bounceBackSpeed*t,0,1)))}getLookAtPosition(){const t=v;return t.set(0,0,0),t.y=this.height,t.add(this.lookAtOffset),t.applyMatrix4(this.actor.object.matrixWorld),t}updateCameraPosition(){this.fixedBehind?(this.actor.object.updateWorldMatrix(!0,!1),this.camera.position.set(this.offset.x,this.offset.y,this.offset.z),this.camera.rotation.set(0,0,0),this.camera.scale.set(1,1,1),this.camera.applyMatrix4(this.actor.object.matrix)):this.camera.position.copy(this.actor.position).add(this.offset);const t=this.getLookAtPosition();this.camera.lookAt(t)}};t([l(),e("design:type",Number)],w.prototype,"near",void 0),t([l(),e("design:type",Number)],w.prototype,"far",void 0),t([l(),e("design:type",Number)],w.prototype,"viewAngle",void 0),w=t([s(),e("design:paramtypes",[h,d])],w);export{w as ThirdPersonCameraComponent};const v=new o,y=new o,k=(new o,new o),g=new o;export class ThirdPartyCameraComponent extends w{}
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -5,8 +5,13 @@ declare class Transition {
5
5
  readonly predicate: TransitionPredicate;
6
6
  constructor(state: AnimationState, predicate: TransitionPredicate);
7
7
  }
8
+ export type AnimationStateOptions = {
9
+ /** Whether the animation should loop. Default: true */
10
+ loop: boolean;
11
+ };
8
12
  export declare class AnimationState {
9
13
  readonly clip?: AnimationClip;
14
+ options: Partial<AnimationStateOptions>;
10
15
  readonly uuid: number;
11
16
  parent: AnimationState;
12
17
  readonly transitions: Transition[];
@@ -17,7 +22,7 @@ export declare class AnimationState {
17
22
  * This works both for standalone states as well as child states to group multiple children together
18
23
  * under the same transition predicate.
19
24
  */
20
- constructor(clip?: AnimationClip);
25
+ constructor(clip?: AnimationClip, options?: Partial<AnimationStateOptions>);
21
26
  named(name: string): this;
22
27
  getAncestors(): AnimationState[];
23
28
  getRoot(): AnimationState;
@@ -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){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);
1
+ let t=0;class i{constructor(t,i){this.state=t,this.predicate=i}}const s={loop:!0};export class AnimationState{constructor(i,n=s){this.clip=i,this.options=n,this.uuid=t++,this.transitions=[],this.options={...s,...n}}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,e(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,e(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=n(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 n(t,i,s){for(const e of t.transitions)if(e.predicate(i))return n(e.state,e.state.uuid===s.uuid?i:0,s);return null==t.clip?t.getAncestors().find((t=>null!=t.clip))??t:t}const e=t=>i=>!t(i);
2
2
  /*
3
3
  * Copyright (©) 2023. All rights reserved.
4
4
  * See the LICENSE.md file for details.
@@ -23,10 +23,14 @@ export declare class RotationInput {
23
23
  readonly rotateZ: (delta: number) => void;
24
24
  }
25
25
  export declare class RestrictedRotationInput extends RotationInput {
26
- private readonly min;
27
- private readonly max;
26
+ private readonly minX;
27
+ private readonly maxX;
28
+ private readonly minY;
29
+ private readonly maxY;
30
+ private readonly minZ;
31
+ private readonly maxZ;
28
32
  readonly rotation: Euler;
29
- constructor(min: number, max: number);
33
+ constructor(minX?: number, maxX?: number, minY?: number, maxY?: number, minZ?: number, maxZ?: number);
30
34
  readonly rotateX: (delta: number) => void;
31
35
  readonly rotateY: (delta: number) => void;
32
36
  readonly rotateZ: (delta: number) => void;
@@ -1,4 +1,4 @@
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}}
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 h{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 h,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 e=2*Math.PI;export class RotationInput{constructor(){this.rotation=new t,this.rotateX=t=>{this.rotation.x=(this.rotation.x+t)%e},this.rotateY=t=>{this.rotation.y=(this.rotation.y+t)%e},this.rotateZ=t=>{this.rotation.z=(this.rotation.z+t)%e}}}export class RestrictedRotationInput extends RotationInput{constructor(i=-1/0,s=1/0,h=-1/0,e=1/0,r=-1/0,a=1/0){super(),this.minX=i,this.maxX=s,this.minY=h,this.maxY=e,this.minZ=r,this.maxZ=a,this.rotation=new t,this.rotateX=t=>{this.rotation.x=o(this.rotation.x+t,this.minX,this.maxX)},this.rotateY=t=>{this.rotation.y=o(this.rotation.y+t,this.minY,this.maxY)},this.rotateZ=t=>{this.rotation.z=o(this.rotation.z+t,this.minZ,this.maxZ)}}}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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hology/core",
3
- "version": "0.0.84",
3
+ "version": "0.0.85",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",