Jump to content

Get size of mesh while taking its children into account


royibernthal
 Share

Recommended Posts

I have an invisible mesh that is the parent of a few child boxes, ordered horizontally one near the other.

I'm using the following line to figure out the size of a mesh:

getBoundingInfo().boundingBox.extendSize.scale(2)

When called on each of the child boxes, the vector returned is correct. When called on the parent mesh, (0, 0, 0) is returned.

Is there a way to get the size of the parent, taking into account all of its children?

Link to comment
Share on other sites

I use this for getting size of meshes. It returns the right size even if it is set to NOT visible:

 

selected_entity is the mesh (obj).

function get_selected_mesh_size(selected_entity){
    $("#selected_entity_mesh_size_x").html(selected_entity.getBoundingInfo().boundingBox.extendSize.x*2*selected_entity.scaling.x);
    $("#selected_entity_mesh_size_y").html(selected_entity.getBoundingInfo().boundingBox.extendSize.y*2*selected_entity.scaling.y);
    $("#selected_entity_mesh_size_z").html(selected_entity.getBoundingInfo().boundingBox.extendSize.z*2*selected_entity.scaling.z);
}

Link to comment
Share on other sites

Like I said different syntax.

You're calling the same functions and accessing the same arguments with a different syntax, please help me see how it'd change anything.

I'd also like to emphasize that the problem is not invisibility of the mesh, but calculating its size while taking into account all of its children.

Link to comment
Share on other sites

http://www.babylonjs-playground.com/#QHMT1#10

Note that I'm not looking for a workaround to calculate this specific PG some other way (like the workaround example I wrote in the PG), this is a simplified case.

I need to be able to get the size of a container mesh whatever children it contains and however they are placed and rotated - get the container's 3d boundaries box.

container size.png

Link to comment
Share on other sites

  • 2 years later...

I had a problem when the combination of meshes were positioned -x,-y, or -z...

I think I fixed it here:

var min = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
var max = new BABYLON.Vector3(Number.MIN_VALUE, Number.MIN_VALUE, Number.MIN_VALUE);
 
use instead:
var min = new BABYLON.Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
 var max = new BABYLON.Vector3(Number.MAX_VALUE*-1, Number.MAX_VALUE*-1, Number.MAX_VALUE*-1);
    
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...