Display meshs based on coordinates

Hi guys,
I have a question, I can get all the meshes in the scene, but I need to display them from small to large according to the xyz coordinates.
Could you help me with this problem please, thanks in advance!

A playground and some more detail would be useful.

How do you determine the size (small or large) of a mesh, by height? by volume? by radius of bounding sphere?


Hi gang. Hey jasOn… just in case you haven’t done much mesh-measuring… (mesh-uring?) :slight_smile:

var stuff = someMesh.getBoundingInfo()

…is the highway to measurements land. That returns a boundingInfo object in stuff, which has some interesting properties and methods upon it… for measuring stuff. :slight_smile:

Party in Boundingville! :slight_smile:


here is PG: Babylon.js Playground
origin xyz = (0, 0, 0)

Shouldn’t I use Babylon.js to do some calculations, just only render?

Neat playground, all the boxes line up nicely. What is the issue?

What calculations? Some calculations, such as vector addition will be done by Babylon.js, standard ones such as adding two numbers will be done by JavaScript. You use whatever is necessary to do your calculations.

Please give much more detail and explanation of your issue. You will be surprised just how much detail you need to give for people to understand someone else’s problem. For example are you importing or creating your meshes?

1 Like

Sorry, I try to make it clear.
There are five meshes in total, and they can be displayed normally, this is fine.
I want to use Babylon.js to calculate which mesh is closest to the origin (0, 0, 0), and then the second, the third…is this OK?

This shows how to get the distance of the center of the mesh to the origin. https://www.babylonjs-playground.com/#PZYBLN#1

1 Like

If your meshes are in a random order you can sort them into order of distance


1 Like

This will be very helpful, thanks!
Another PG https://www.babylonjs-playground.com/#PZYBLN#4
console log:

distance from origin 1
distance from origin 3
distance from origin 5
distance from origin 7
distance from origin 9
**distance from origin 3.1622776601683795**
**distance from origin 4.242640687119285**
**distance from origin 5.830951894845301**
**distance from origin 7.615773105863909**
**distance from origin 9.486832980505138**

Why are the last five meshes decimal?

Because for the first 5 the vectors from the box centers to the origin lie along the x axis and so have no y and z component. For the second 5 the vectors from centers to origin have a x and y component and so Pythagoras is needed giving distance is sqrt(x2 + y2) which is rarely an integer.

1 Like