Bounding Box Not Resetting After Removing Node

Bounding Box Not Resetting After Removing Node

I am working with model transformations in a 3D viewer. When I add a new node using createMeshInstance, the model’s bounding box updates as expected. However, after removing the node using deleteNode, the bounding box does not revert to its original state.

Initial Setup

I retrieve the node’s initial transformation matrix:

initialMatrix = await this.viewer.model.getNodeMatrix(nodeid);

The bounding box before adding the node:

{
    "min": { "x": 20568326, "y": 30050302, "z": 894504.9375 },
    "max": { "x": 20712482, "y": 30192102, "z": 20502.609 }
}

Applying Transformation

I apply a transformation to set the Z-axis to 0:

{
    "x": 0,
    "y": 0,
    "z": -894504.9375
}

Resulting bounding box:

{
    "min": { "x": 20568326, "y": 30050302, "z": 0.014404296875 },
    "max": { "x": 20712482, "y": 30192102, "z": 915007.5 }
}

Adding a New Node

I add a new mesh instance:

await hwv.model.createMeshInstance(meshInstanceData);

Bounding box after adding the new node:

{
    "min": { "x": -50000, "y": 0, "z": -894504.9375 },
    "max": { "x": 20712482, "y": 30192102, "z": 915007.5 }
}

Deleting the Node

I then remove the node:

await hwv.model.deleteNode(nodeid);

I also attempt to reset the matrix:

await this.viewer.model.setNodeMatrix(
    this.viewer.model.getAbsoluteRootNode(), 
    initialMatrix
);

However, the bounding box does not revert to its initial state.

Issue

  • Even after deleting the node, the bounding box remains changed.
  • I expect the bounding box to return to its original values before adding the new node.

Question

How can I force the bounding box to reset to its original state after removing the node? Is there a method to recompute or refresh the bounding box manually?

Any guidance would be appreciated!

Hello @raja.r,

Just to confirm, once the node has been deleted, are you calling getNodesBounding again? Your code snippets do not include the aforementioned function.

Thanks,
Tino

Yes, I am calling the model bounding box instead of getNodesBounding because I need to calculate the overall model bounding box. Here’s the code I’m using: this.boundingBox = await this.viewer.model.getModelBounding(true, false);

The following call creates a mesh instance id:

let meshInstanceId = await hwv.model.createMeshInstance(meshInstanceData);

You will need to call deleteMeshInstances in addition to deleting the node, for example:

await hwv.model.deleteMeshInstances([meshInstanceId]);
await hwv.model.deleteNode(nodeId);
1 Like