Sign in to follow this  
royibernthal

Get size of mesh while taking its children into account

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?

Share this post


Link to post
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);
}

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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);
    

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.