Sign in to follow this  
Bladetrick

Facet Index = null when using getClosestFacetAtCoordinates

Recommended Posts

Hello!

I was noticing that .getClosestFacetAtCoordinates results in index == null given the parameters below.  In what situation can this occur?  The nearestMesh is valid from what I can see.  It occurs fairly often in this set of data i'm using.

    nearestpoint = BABYLON.Vector3.Zero();
    var index = nearestMesh.getClosestFacetAtCoordinates(-20.5, 115, 226, nearestpoint);  // If i change the second parameter to 115 I get a facet index. 

    if (index != null) {
        worldPos = nearestMesh.getFacetPosition(index);
    }

 

I noticed that if i switch the second paramter's value by just 2, I get an index back.  Does this mean that the distance between the given point and a mesh facet has a limit for it to work?

Thanks for the help!

Share this post


Link to post
Share on other sites

and @Bladetrick this could happen if your position is outside the block partitioning use for facet.

From the doc: 

The method returns just the index of the closest facet, if any.
Actually the world coordinates (x, y, z) are internally transformed to local coordinates in the mesh local system.
If these local coordinates aren't in any block or if there's no facet in this block, it returns null.
This method can be called as many times you need, even in the render loop.

You might try to tweak the partitioning using : https://doc.babylonjs.com/how_to/how_to_use_facetdata#tweaking-the-partitioning

Share this post


Link to post
Share on other sites

of course, there's a limit for it to work, in order to avoid to compute things when not necessary (too far from the mesh).

It depends mainly on the size of the global box (bouding box) containing the partitioning : https://doc.babylonjs.com/how_to/how_to_use_facetdata#mesh-partitioning

maybe, you could change the partiotining Bbox ratio

mesh.partitioningBBoxRatio = 1.08;   // 8% bigger than the mesh

to get a bigger bbox

Share this post


Link to post
Share on other sites

@Sebavan

it looks like something doesn't work in the PG examples in the partitioning section in the doc because we can't see any longer the plane depicting the partitioning around the skull https://www.babylonjs-playground.com/#UZGNA#1

Maybe this has something to do with the modification of the BBox implementation in the last BJS version, not sure ...

Share this post


Link to post
Share on other sites

Thanks, that's giving me a good starting point to work with.  I'm reading on partitioning more carefully and playing with the updated playground.   Question, though:

When using 

var index = mesh.getClosestFacetAtCoordinates(dot.position.x, dot.position.y, dot.position.z, nearestpoint);

on the playground I get the following error:

Line 38:22 - Cannot read property 'getClosestFacetAtCoordinates' of undefined

even though the intellisense picked it up fine.  am I doing something wrong here?

Thanks again.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.