allow generic objects animation filtering

This commit is contained in:
2026-04-08 22:12:36 +03:00
parent abb6204b1f
commit 9d46b9485d
3 changed files with 15 additions and 6 deletions
@@ -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()
+3 -3
View File
@@ -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() {
-3
View File
@@ -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);