Forum

Get object dimension

26 September 2017 13:22
Hello everybody,
I have some super-newbie questions .

My objective is to load some scenes (following the tutorial Dynamic Loading tutorial) and put them in a row in the center of the scene (I'm using a target camera). For this reason I would like to:

    -load the scenes (each one with a single object) and store them in an array;
    -loop the array, find and sum the objects widths;
    -in another loop set the position of each object with the set_translation method; I thought to find the position of each one from the center of the scene (x = sum of previous objects widths) and substract half of the total width.

I hope that it makes sense. Here come my newbie questions.

1) Is it correct that Blend4Web do not have a method to group meshes? For example, I wanted to group all the meshes to position the whole group in the center, but I could not find a way to do it.

2) I'm struggling to find a Javascript API method to get the width of an object. I understood that in 3d space I have to leave my bias and I should not search for the width, but for the dimension in one of the axis. I tried to use the get_object_bounding_box and the get_matrix methods, but my uncertainty about 3d concepts left me with nothing. How do you find, for example, the x dimension of an object?

3) Would you do this task, putting objects in row, in a different way?

Thanks everybody for every advice to understand better how to do something like that.
Cheers.
29 September 2017 21:58
1) Is it correct that Blend4Web do not have a method to group meshes? For example, I wanted to group all the meshes to position the whole group in the center, but I could not find a way to do it.

List all objects in the scene by type or ID
link

2) I'm struggling to find a Javascript API method to get the width of an object. I understood that in 3d space I have to leave my bias and I should not search for the width, but for the dimension in one of the axis. I tried to use the get_object_bounding_box and the get_matrix methods, but my uncertainty about 3d concepts left me with nothing. How do you find, for example, the x dimension of an object?

This method returns a list with values {max_x, min_x, max_y, min_y, max_z, min_z}, here we have all the dimensions of the mesh. If for example I want to know what is the dimension of a cube on the x axis and the method says :
max_x: 10.25, min_x: 8.25, I do a mathematical operation 10.25 - 8.25 and the value I get is the dimension of the object on the x-axis.

3) Would you do this task, putting objects in row, in a different way?


I do not find a better method.
 
Please register or log in to leave a reply.