Skip to content

Conversation

@gonnavis
Copy link
Contributor

example
mesh.containsPoint(new THREE.Vector3(0,0,0))

@mrdoob
Copy link
Owner

mrdoob commented Aug 31, 2018

So the approach is so use a Raycaster and cast a ray from the point outside of the mesh (-z specifically), right?

What's your use case?

@gonnavis
Copy link
Contributor Author

gonnavis commented Sep 1, 2018

Hi mrdoob, I often need to change a mesh to point cloud, so I wrote the demo before.
The method is inspired by this answer, and I summerized to "Just raycast once from the point to any direction, then check the intersects num, if is odd, the point is in the geometry".
And found other people have the same demand, so I think if this method can embed into three.js will be very userful.
But I konw the performance is very bad, may be use gpgpu to speed up? I'll try.

@WestLangley
Copy link
Collaborator

If the mesh is not watertight -- e.g., a planar mesh, or a cylinder without end-caps, or TeapotBufferGeometry -- your approach will either not work, or will not be guaranteed to work. Correct?

@gonnavis
Copy link
Contributor Author

gonnavis commented Sep 1, 2018

Yes, may use some method to check if the mesh is watertight first?

@gonnavis
Copy link
Contributor Author

gonnavis commented Sep 1, 2018

Or use a option parameter, let the user to specify the direction, no-matter if the mesh is watertight, just use the direction to check.

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 1, 2018

I've never seen that an engine supports such a method in their Mesh class. AFAIK, at least Unity does not provide such a functionality. Probably because it's complicated to implement a generic containsPoint() method that reliably supports all types of meshes (like @WestLangley mentioned). I vote to keep such code on app level.

@WestLangley
Copy link
Collaborator

Right. This is an application-specific method, and it only works in certain cases.

See examples/js/utils/GeometryUtils.js for methods that will generate random points on the geometry surface.

@mrdoob
Copy link
Owner

mrdoob commented Sep 4, 2018

Yeah, I can see this getting people confused when their model is not watertight. I'd prefer to add only robust methods to core. Better to leave this as application-specific.

Thanks though!

@mrdoob mrdoob closed this Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants