From 9d46b9485db3f7898ccfe8afcfc15fde5587940c Mon Sep 17 00:00:00 2001 From: goynov Date: Wed, 8 Apr 2026 22:12:36 +0300 Subject: [PATCH] allow generic objects animation filtering --- .../GenericObject/GenericObject.js | 12 ++++++++++++ src/lib/GameEngine.js | 6 +++--- src/lib/GameManager.js | 3 --- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/components/InteractiveObjects/GenericObject/GenericObject.js b/src/components/InteractiveObjects/GenericObject/GenericObject.js index add07c5..e905e35 100644 --- a/src/components/InteractiveObjects/GenericObject/GenericObject.js +++ b/src/components/InteractiveObjects/GenericObject/GenericObject.js @@ -2,6 +2,7 @@ import { EventManager } from '@/lib/EventManager'; class GenericObject extends EventManager{ emits = ['finish', 'interaction'] + #actions = []; constructor(engine, data){ super(); return new Promise(async(resolve, reject)=>{ @@ -17,14 +18,25 @@ class GenericObject extends EventManager{ }) } + if (this.source?.animations?.length){ + let mix = this.source.animations.filter(a=>a.name.match(/\.mix/)); + if (!mix.length) mix = [this.source.animations[0]]; + mix.forEach(m=>{ + this.#actions.push(engine.playAnimation(this.object, m)); + }) + } + if (!data.exclude){ engine.clickable.add(this.object, async e=>{ this.object.__onhud = !this.object.__onhud; if (engine.dashboard){ if (data.hud){ + const filterNoHud = a=>a.getClip().name.match(/\.nohud/) if (this.object._hud ){ + this.#actions.filter(filterNoHud).forEach(a=>a.play()); engine.dashboard.detach(this.object); }else{ + this.#actions.filter(filterNoHud).forEach(a=>a.stop()); let bb = engine.meshUtils.getBoundingBox(this.object); let scale = 0.5 * engine.dashboard.height/engine.meshUtils.getBoundingBoxMaxLength(bb); let position = engine.meshUtils.getBoundingBoxCenterPoint(bb, this.object.position).multiplyScalar(scale).negate() diff --git a/src/lib/GameEngine.js b/src/lib/GameEngine.js index 8289819..780515a 100644 --- a/src/lib/GameEngine.js +++ b/src/lib/GameEngine.js @@ -94,7 +94,7 @@ class GameEngine extends EventManager{ if (this.opts.gizmo) { this.orbitControls = new OrbitControls(this.camera, this.renderer.domElement); - this.orbitControls.enableZoom = false; + //this.orbitControls.enableZoom = false; const gizmo = new ViewportGizmo(this.camera, this.renderer, { container: '.renderer-gizmo', //type:'cube' @@ -501,8 +501,8 @@ class GameEngine extends EventManager{ playAnimation(object, clip, play = true) { let action = this.mixers[0].clipAction(clip, object); - if (play) action.play(); - else action.stop(); + action[play ? 'play' : 'stop'](); + return action; } stop() { diff --git a/src/lib/GameManager.js b/src/lib/GameManager.js index 84540b9..ad1f7fe 100644 --- a/src/lib/GameManager.js +++ b/src/lib/GameManager.js @@ -79,9 +79,6 @@ class GameManager extends EventManager{ if (i.data.$go?.type == 'player3d'){ let hero = new Hero(engine, io); }else{ - if (io.source?.animations?.length){ - engine.playAnimation(engine.scene, io.source.animations[0]); - } if (i.data.collisionType == 'basic'){ let bb = engine.meshUtils.getBoundingBox(io.object); let bbs = engine.meshUtils.getBoundingBoxSize(bb);