From 2c5f6a70e73b9efa9f22ecce3b233dbdfcd8b65d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20D=C3=ADaz?= Date: Mon, 26 Feb 2024 18:11:04 -0300 Subject: [PATCH] fix: Loading entity twice doesn't trigger boundingBox (#905) --- .../src/lib/babylon/decentraland/EcsEntity.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/@dcl/inspector/src/lib/babylon/decentraland/EcsEntity.ts b/packages/@dcl/inspector/src/lib/babylon/decentraland/EcsEntity.ts index ab3c9c82c..fde33081e 100644 --- a/packages/@dcl/inspector/src/lib/babylon/decentraland/EcsEntity.ts +++ b/packages/@dcl/inspector/src/lib/babylon/decentraland/EcsEntity.ts @@ -173,7 +173,9 @@ export class EcsEntity extends BABYLON.TransformNode { const meshesBoundingBox = this.getMeshesBoundingBox() this.boundingInfoMesh = new BABYLON.Mesh(`BoundingMesh-${this.id}`) - this.boundingInfoMesh.parent = this + this.boundingInfoMesh.position = this.absolutePosition + this.boundingInfoMesh.rotationQuaternion = this.absoluteRotationQuaternion + this.boundingInfoMesh.scaling = this.absoluteScaling this.boundingInfoMesh.setBoundingInfo( new BABYLON.BoundingInfo(meshesBoundingBox.minimum, meshesBoundingBox.maximum, this.getWorldMatrix()) @@ -186,6 +188,15 @@ export class EcsEntity extends BABYLON.TransformNode { this.onAfterWorldMatrixUpdateObservable.addOnce((eventData) => { void validateEntityIsOutsideLayout(eventData as EcsEntity) }) + + // Updates the boundingInfoMesh position, rotation and scaling + this.onAfterWorldMatrixUpdateObservable.add((eventData) => { + if (this.boundingInfoMesh) { + this.boundingInfoMesh.position = eventData.absolutePosition + this.boundingInfoMesh.rotationQuaternion = eventData.absoluteRotationQuaternion + this.boundingInfoMesh.scaling = eventData.absoluteScaling + } + }) } } }