Skip to content

Commit

Permalink
fix: Loading entity twice doesn't trigger boundingBox (#905)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyaiox authored Feb 26, 2024
1 parent f06a0a7 commit 2c5f6a7
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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
}
})
}
}
}
Expand Down

0 comments on commit 2c5f6a7

Please sign in to comment.