massive interactive objects refactoring

This commit is contained in:
2026-04-04 10:57:43 +03:00
parent 401a6cb144
commit 6009d52139
30 changed files with 104 additions and 28 deletions
@@ -0,0 +1,52 @@
import { EventManager } from '@/lib/EventManager';
class GenericObject extends EventManager{
emits = ['finish', 'interaction']
constructor(engine, data){
super();
return new Promise(async(resolve, reject)=>{
this.source = await engine.load(data.$go.asset.name);
this.object = engine.meshUtils.bottomOrigin(this.source.scene)
if (!data.exclude){
engine.clickable.add(this.object, async e=>{
this.object.__onhud = !this.object.__onhud;
if (engine.dashboard){
if (data.hud){
if (this.object._hud ){
engine.dashboard.detach(this.object);
}else{
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()
let placement = {
quaternion: { x:0, y:0, z:0, w:0 },
position,
scale: {
x: scale*this.object.scale.x,
y: scale*this.object.scale.y,
z: scale*this.object.scale.z
}
}
await engine.dashboard.attach(this.object, {
placement, rotate: true, plane: true
});
}
}
if (data.description){
engine.dashboard.updateText(this.object.__onhud ? data.description : '', false, (d)=>{
d && this.dispatchEvent({type:'finish'})
})
}
}
this.dispatchEvent({type:'interaction'})
});
}
resolve(this);
})
}
}
export {GenericObject}