Bladetrick Posted November 20, 2018 Share Posted November 20, 2018 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! Quote Link to comment Share on other sites More sharing options...
Sebavan Posted November 20, 2018 Share Posted November 20, 2018 @Bladetrick it would be amazing to have a PG with a repro ? Pinging at @jerome the facet master. Bladetrick 1 Quote Link to comment Share on other sites More sharing options...
Sebavan Posted November 20, 2018 Share Posted November 20, 2018 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 jerome and Bladetrick 1 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted November 20, 2018 Share Posted November 20, 2018 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 Bladetrick 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted November 20, 2018 Share Posted November 20, 2018 @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 ... Bladetrick 1 Quote Link to comment Share on other sites More sharing options...
Sebavan Posted November 20, 2018 Share Posted November 20, 2018 IT is because the private fields have been replaced by public properties: https://www.babylonjs-playground.com/#UZGNA#6 Bladetrick and jerome 2 Quote Link to comment Share on other sites More sharing options...
Sebavan Posted November 20, 2018 Share Posted November 20, 2018 I have updated the doc. Bladetrick 1 Quote Link to comment Share on other sites More sharing options...
Bladetrick Posted November 20, 2018 Author Share Posted November 20, 2018 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. Quote Link to comment Share on other sites More sharing options...
jerome Posted November 20, 2018 Share Posted November 20, 2018 Just check your code : the mesh is probably not loaded yet when you call getClosestEtc() Bladetrick 1 Quote Link to comment Share on other sites More sharing options...
Bladetrick Posted November 20, 2018 Author Share Posted November 20, 2018 You're right, Jerome. I rearranged it and got it to load properly; however, my point (a sphere) is close as heck and it still gives a value of null. https://www.babylonjs-playground.com/#UZGNA#13 Not sure what I'm doing wrong. I'm just trying to cast a ray to the closest facet/point Quote Link to comment Share on other sites More sharing options...
Bladetrick Posted November 20, 2018 Author Share Posted November 20, 2018 i used getClosestFaceAtLocalCoordinates and it works, though the point it came up with is not the closest that I can see. i don't know. I'll do some more reading/testing and let you know my results. Thanks all, for the help/ideas! Sebavan 1 Quote Link to comment Share on other sites More sharing options...
Bladetrick Posted November 21, 2018 Author Share Posted November 21, 2018 From the links suggested I figured out how things worked; however, I have another problem on my end. I started a new topic here in case anyone wants to take a looksee: Again thanks for all the advice up to this point Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.