hud observation for generic game objects

This commit is contained in:
2025-11-07 12:48:36 +02:00
parent b972ab25f0
commit 48c7ea2e2a
7 changed files with 152 additions and 43 deletions
@@ -1,3 +1,5 @@
import { getBoundingBox, getBoundingBoxCenterPoint, getBoundingBoxMaxLength } from "@/lib/MeshUtils";
class GenericObject{
constructor(engine, data){
return new Promise(async(resolve, reject)=>{
@@ -6,8 +8,31 @@ class GenericObject{
if (!data.exclude){
engine.clickable.add(this.object, e=>{
if (engine.dashboard && data.description){
engine.dashboard.update({ hint: data.description })
if (engine.dashboard){
if (data.description){
engine.dashboard.update({ hint: data.description })
}
if (data.hud){
if (this.object._hud ){
engine.dashboard.detach(this.object);
}else{
let bb = getBoundingBox(this.object);
let scale = 0.5/getBoundingBoxMaxLength(bb);
let position = 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
}
}
engine.dashboard.attach(this.object, placement, true);
}
}
}
});
}
@@ -34,34 +34,11 @@ class VideoPlayer {
})
vi.addEventListener('play', ()=>{
if (engine.dashboard?.active){
data = {
parent: plane.parent,
location: {
position: plane.position.clone(),
quaternion: plane.quaternion.clone(),
scale: plane.scale.clone()
}
}
engine.dashboard.group.attach(plane);
engine.motionQueue.add({
o: plane,
a: {
rotation: { x:0, y:0, z:0 },
position: { x:0, y:0, z:-0.25 },
scale: { x: 1, y:1, z:1 }
},
t: 1
})
engine.dashboard.attach(plane);
}
})
vi.addEventListener('pause', ()=>{
data.parent.attach(plane);
engine.motionQueue.add({
o: plane,
a: data.location,
t: 1
})
engine.dashboard?.detach(plane);
})
})
}