claygl icon indicating copy to clipboard operation
claygl copied to clipboard

Fix bug to get correct bounding box of a mesh node.

Open birdinforest opened this issue 5 years ago • 2 comments

When we call Node.prototype.getBoundingBox to get the bounding box of a node contains geometry (mesh), the returned bounding box has applied world transform of that node. So that it shouldn't union with bounding box of geometry.

Unless there are other cases in which we do need to do union. Please advice. Thanks.

birdinforest avatar Feb 06 '20 01:02 birdinforest

Hi @birdinforest

Node#getBoundingBox returns a local bounding box including all the children and itself, if it has geometry. The bounding box is relative to the node transform and won't be applied world transform,

Are you meeting some issues when using this function?

pissang avatar Feb 06 '20 03:02 pissang

Hi @pissang

Thanks for your response. Sorry it was incorrect to say the node has been 'transformed by world transform'.

According to my understanding, Node#getBoundingBox returns a bounding box relative to its parent node. If the world transform of a node isn't identity, bounding box of that node will be transformed relatively to its parent. So that it might cause problem to do union with original geometry bounding box.

I did encounter an issue to get the bounding box in that scenario. Please reference following screen shots:

claygl_bbox_issue
node.worldTransform: 
[0.2857008901599777, 0, 0.7414056445312012, 0, 0, 0.7332189, 0, 0, -0.6031628217506998, 0, 0.23242897644047653, 0, 106.715439, -4.00169754, -9.18224049, 1]

node._parent.worldTransform:
[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]

node.geometry.getBoundingBox:
min: [-0.7505188, -0.104103565, -0.403491974] 
max: [0.66633606, 2.11563349, 0.8133888]

Expected bounding box (In world view and relative to parent):
min: [106.01040922696978, -4.078028241415379, -9.832462591165552] 
max: [107.1491831630793, -2.4504750796590393, -8.499160047729172]

Returned bounding box:
min: [-0.7505188, -0.104103565, -0.403491974] 
max: [107.1491831630793, -2.4504750796590393, -8.499160047729172]

Expected result: claygl_bbox_correct

Please advice.

By the way, thanks for your work on clayGL. I have learned a lot from it :)

birdinforest avatar Feb 07 '20 11:02 birdinforest