How do we calculate clipping min and max distance for given mesh in babylonjs

Hi,

I am trying to find a solution for calculating minimum and maximum distance for clipping Planes for a given mesh (which is something user is going to upload in GLTF/STL format)

Basic Playground is here given below, can someone help me in dynamically calculating the clipPlanes min and max distances.

Thanks in advance.

1 Like

Hello,

By “minimum” and “maximum” do you mean the smallest values that encompass the whole mesh?

Hi @carolhmj

Yes, I am trying calculate the maximum and minimum range for clipping for a given mesh.

slider = new BABYLON.GUI.Slider();
slider.minimum = -30; //how can we calculate this two values dynamically
slider.maximum = 20;
slider.value = -30;

If your clipping planes are axis-aligned like you have in the PG, you probably can use mesh.getBoundingInfo() to get the min and max values from the mesh.

newMeshes[0].getBoundingInfo()

2 Likes

I tried doing that but it doesn’t work, I mean I was using getBoundingInfo().boundingBox.minimum and getBoundingInfo().boundingBox.maximum to decide the minimum and maximum range for the clip but it isn’t working properly.

Here is playground for your reference, feel free to modify it. let me know if you have any solution for this,

Thanks.

Like this?
PG: https://playground.babylonjs.com/#Y6W087#255

2 Likes

It isn’t working as expected, as you can see here,

do you have any solution for this?

I only updated the y-axis. I’m sure you can figure out the x-axis. :slight_smile:

2 Likes