It is necessary to display cubes on the plane, their dimensions are given in mm. and their coordinates in mm. When I transmit this data to THREE, huge holes are obtained between the cubes, although they stand wall to wall, tell me how to convert the units correctly so that it looks like reality?
const itemGeometry = new THREE.BoxGeometry(200, 200, 100); // mm.
const itemMaterial = new THREE.MeshNormalMaterial({ color: 0xffffff });
const mesh = new THREE.Mesh(itemGeometry, itemMaterial);
// mm. from 0.0.0
mesh.position.x = 0;
mesh.position.y = 100;
mesh.position.z = 200;
Using the experiment method, I realized that it is necessary to reduce the coordinates 3-9 times, but I do not understand why, and how to do it correctly.
here are your boxes lined up on the x axis by width, to stack high or deep you would need to setup some sort of indexing system of an area.
please try to provide at least some limited styling in examples so people can help easier
EDIT: i have used * index which will not work if each box is a different width, you would have to use the total previous sum of containers[ index ].width to offset accordingly.
Thank you, I have solved the first problem.
As you noticed, if the objects are different widths there will be problems.
The center of coordinates coincides with the center of the object, my algorithm considers that the origin of coordinates is the bottom corner of the object.
When you layer different objects, they don’t lay down correctly. How can this be fixed?
There are a number of solutions to this, for example one way is to create a bounding box for the first layer to obtain the greatest height (if heights will also all be different) from here you can move the mesh down to the last indexed sum of heights plus the lower half height of the latest box by generating the bounding box of each current box, if you are working from the closest bottom left corner you can translate your original geometry with geometry.translate(x,y,x) Once at the start of each geometry generation by the half of the overall box and then go on to use the full box height instead of half heights.
Hope this helps.
Yes. Look into box helper and bounding boxes, from the image you are going to have to creat a bounding box for each object and move it upwards until it doesn’t intersect another box
Before giving some advice,
can you please clarify where the “size” (i.e.: size.x, size.y, size.z) of the bounding box comes from?
Are you thinking of a unit-sized cube-shaped box, which will be scaled according your scale data?
Would the “position” refer to the center coordinates of the box?
Does the “rotation” imply, that you want to have a non-axis-aligned box?
Large coordinates are not a problem per se. Use those large position values to position (or translate) your mesh. Then make sure, it is within the camera frustum. There are at least two ways to achieve the latter:
leave the camera.position at the origin, then carefully aim at your far away mesh, using a small camera.fov and sufficiently large .near and .far planes
move the camera.position close to your far away mesh and be done with a fairly large camera.fov
Hi @vielzutun.ch thank you for replying. Here are answers to your questions:
can you please clarify where the “size” (i.e.: size.x, size.y, size.z) of the bounding box comes from? There is no explicit size data. However, data such as position, rotation and scaling come from an API response as a json collection representing the collection of bboxes.
Are you thinking of a unit-sized cube-shaped box, which will be scaled according your scale data? The bounding box needs to be scaled as per the incoming scaling data, which means the scaling data shall be responsible for its shape/appearance. So, yes it is a unit sized bbox
Would the “position” refer to the center coordinates of the box? The values in the position object would refer to the position where the box would appear/placed in the point cloud. Not sure what exactly you mean when you say center coordinates.
Does the “rotation” imply, that you want to have a non-axis-aligned box? No, the bounding box axis-aligned(AABB)
Also I saw your couple of solution, I am not sure if I understand them fully. But I will check. However, if you have any other suggestions based on my answers, pls comment. It is really appreciated.
OK. So you have a 1 x 1 x 1 cube which will be scaled to scale.x, scale.y, scale.z. That makes sense.
Since this bounding box has extensions in each of the three axes, you need to decide/define, for which point of the box you’ll want to apply the position data. The center coordinates of a box-shaped entity would be at the intersection of its spatial diagonals. Like: lower-left-front to upper-right-back, lower-left-back to upper-right-front, upper-left-front to lower-right-back, upper-left-back to lower-right-front.
If the bounding box shall be axis-aligned, please specify how the “rotation” data should be taken into account.