Get max and min from slice of mesh

Hi,
I’m trying to get the max and min X,Z values for varying Y values. I need points along the mesh at various heights and angles. I’m using the FacetData interface and specifically the getClosestFacetAtCoordinates function.

PG here

It works sometimes but throws lots of errors and doesn’t produce consistent results. Any thoughts on where I’m going wrong?

I take the mesh bounding box X & Z as the radius to my angle (I may through 360 degrees at various increments). I have spheres at my input nearest points and for my facetData response.

Aside from this approach I’m also going to try CSG (CSG doesn’t seem to work right when my meshes are not closed, which is often), and I’ll try for mesh intersection / collision interface where I extrude a cylinder from my nearest point into the mesh.

Any direction would be greatly appreciated. Thanks!

@Evgeni_Popov could you have a look ?

Having a look now.

What you want to do won’t really work because the facets are partitionned according to the bounding box, so if the point you are using in the getClosestFacetAtCoordinates call is not inside the bounding box you won’t get any result.

You can increase the size of the bounding box used for the facet partitionning by setting a value > 1 in partitioningBBoxRatio (for eg, 1.5 to increase the size by 50%) but it won’t really fix the problem because the getClosestFacetAtCoordinates method only checks a single bucket, the one corresponding to the point passed in: if there are no facets in this bucket, null will be returned, it won’t check for adjacent buckets.

Maybe you can use a ray intersection instead?

1 Like

I appreciate you looking into this. I’ll go through the ray intersection (it looks promising) and I may also try to search by partition (see my notes below).

A few quick thoughts from me:

When you say buckets, do you mean the facet mesh partitions like the facet docs skull in this PG? IF so, you sound like you may have some confidence in getting an accurate value near a point that is in a specific partition - so I could select a partition and look for largest X value then select a partition on the other side of the mesh to find the min X value.

I did notice that points outside of the boundingbox didn’t work so I was multiplying those values by some % like .9*boundingBox.max to keep it in.

Thanks for the help. I’ll post my progress - I am hoping to get mesh point info out by sometime next week.

Yes, the buckets I’m speaking about are the cube cells you can see in the picture: when calling getClosestFacetAtCoordinates, only a single cube cell is analyzed - the one corresponding to the point passed to the function. If there are not facets intersecting this cell, the function will return null.

1 Like

I tried to use ray picking on simple boxes but don’t seem to get the right distance values. Am I missing something? I’m using the intersetMesh.PickingInfo.Distance

I’m getting a value of 5 and would expect 25.

See below:

PG

You need to have the world matrices of the meshes up to date:

https://playground.babylonjs.com/#KNE0O#1006

It is done automatically for you in the scene.render function but it has not been called yet when you call castRay in your PG.

Silly me! Thank you for all your help and support. It is much appreciated!

So everything worked well with boxes using the computeWorldMatrix. Thanks again.

When I bring in the “dude” it doesn’t work. Any ideas on what I’m missing this time?
The console says that I am hitting a picked mesh but the intersectsMesh(mesh) call returns false.

I’m going to try the bunny and then my real stl’s next, any help in the meantime would be greatly appreciated.

PG here

So I got it working with the bunny but not the dude. I’ll have to read more on the dude’s mesh vs the bunny.

PG here

I don’t really know why intersectsMesh does not work but you can use the hit.pickedPoint instead:

https://playground.babylonjs.com/#WLDCUC#115

This forum is fantastic. Your support has been incredible and helpful. Thank you so much!

I’ll keep playing. So fun and useful.

3 Likes