@hology/core 0.0.83 → 0.0.84

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.
@@ -8,6 +8,8 @@ export declare class CharacterAnimationComponent extends ActorComponent {
8
8
  private stateMachines;
9
9
  private upperStateMachines;
10
10
  private fadeTime;
11
+ private overrideFadeTime?;
12
+ private overrideFadeTimeUpper?;
11
13
  movementSpeed: any;
12
14
  private fullBodyAction;
13
15
  private upperBodyAction;
@@ -56,4 +58,5 @@ export type PlayOptions = Partial<{
56
58
  loop: boolean;
57
59
  layer: BoneLayer;
58
60
  priority: number;
61
+ fadeTime: number;
59
62
  }>;
@@ -1,4 +1,4 @@
1
- import{__decorate as t}from"tslib";import{ActorComponent as i,Component as e}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 c=class extends i{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=>a(this.fullBodyMask,t))),this.getUpperBodyClip=y((t=>t.uuid),(t=>a(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,i,e){null!=i&&(this.upperBodyMask=d(i),this.fullBodyMask=function(t,i){const e=new Set(d(i).map((t=>t.uuid))),o=[];return t.traverse((t=>{(t instanceof p||t.isBone)&&!e.has(t.uuid)&&o.push(t)})),o}(function(t){let i;return t.traverse((t=>{(t instanceof p||t.isBone)&&null==i&&(i=t)})),i}(t),i)),null!=this.mixer&&this.mixer.stopAllAction(),this.mixer=new n(t)}updateStateMachines(t){this.stateMachines.forEach((i=>{i.step(t);const e=i.current.clip;null!=e&&this.play(e,{priority:0})})),this.upperStateMachines.forEach((i=>{i.step(t);const e=i.current.clip;null!=e?this.playUpper(e,{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.fadeTime<this.upperBodyTimer&&(this.upperBodyOverride=!1,null!=this.fullBodyClip&&this.transition(this.upperBodyAction,this.getUpperBodyClip(this.fullBodyClip)),this.upperBodyAction=null),this.fullBodyAction&&this.fullBodyAction.loop===h&&this.fullBodyAction.getClip().duration-2*this.fadeTime<this.fullBodyTimer&&(this.currentFullBodyPriority=-1),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 i=t.getClip();if(i instanceof o&&i.fixedInPlace&&null!=this.movementSpeed){t.timeScale=i.duration/i.displacement*this.movementSpeed;const e=this.mixer.getRoot();e instanceof l&&(t.timeScale/=e.scale.x)}}}playStateMachine(t){this.stateMachines.push(t)}playUpperStateMachine(t){this.upperStateMachines.push(t)}removeStateMachine(t){const i=this.stateMachines.indexOf(t);i>=0&&this.stateMachines.splice(i,1)}removeUpperStateMachine(t){const i=this.upperStateMachines.indexOf(t);i>=0&&this.upperStateMachines.splice(i,1)}playUpper(t,i={}){const e=i?.priority??1;e<this.currentUpperBodyPriority||(this.currentUpperBodyPriority=e,this.upperBodyAction=this.transition(this.upperBodyAction,this.getUpperBodyClip(t),i),this.upperBodyTimer=0,this.upperBodyOverride=!0)}play(t,i={}){!function(t,i){if(!1===t||"function"==typeof t&&!1===t())throw new Error(i)}(null!=this.mixer,"Can't play animation before setup is called");const e=i.priority??1;e<this.currentFullBodyPriority||(this.currentFullBodyPriority=e,this.fullBodyTimer=0,this.upperBodyOverride||(this.upperBodyAction=this.transition(this.upperBodyAction,this.getUpperBodyClip(t),i)),this.fullBodyClip=t,this.fullBodyAction=this.transition(this.fullBodyAction,this.getFullBodyClip(t),i),this.fullBodyAction.getClip().uuid==this.upperBodyAction.getClip().uuid&&this.upperBodyAction.syncWith(this.fullBodyAction))}onActionDone(t){return new Promise((i=>{const e=o=>{o.action===t&&(i(o.action),this.mixer.removeEventListener("finished",e))};this.mixer.addEventListener("finished",e)}))}transition(t,i,e={}){if(null!=t&&t.getClip().uuid===i.uuid)return t;if(t){const e=t,o=t=this.mixer.clipAction(i);o.play(),o.enabled=!0,o.setEffectiveTimeScale(1),o.setEffectiveWeight(1),o.time=0,e.crossFadeTo(o,this.fadeTime,!0)}else t=this.mixer.clipAction(i),t?.fadeIn(.3),t?.play();return!1===e.loop&&(t.setLoop(h,1),t.clampWhenFinished=!0,t.reset()),t}};c=t([e({inEditor:!0})],c);export{c as CharacterAnimationComponent};function a(t,i){if(null==t)return i;const e=i.clone(),o=new Set(t.map((t=>t.name)));return e.tracks=e.tracks.filter((t=>o.has(t.name.split(".")[0]))),e}function d(t){return t.flatMap((t=>function(t){const i=[];return t.traverse((t=>{i.push(t)})),i}(t))).filter((t=>t instanceof p))}function y(t,i){const e=new Map;return(o,...r)=>{const s=t(o);return e.has(s)||e.set(s,i(o,...r)),e.get(s)}}
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)}}
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.83",
3
+ "version": "0.0.84",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",