Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not getting desired boundaries with simple cube like shapes #158

Closed
elkizana opened this issue Jan 25, 2024 · 7 comments
Closed

not getting desired boundaries with simple cube like shapes #158

elkizana opened this issue Jan 25, 2024 · 7 comments
Labels

Comments

@elkizana
Copy link

How to get rid of these extra boundaries
cannon

@donmccurdy
Copy link
Owner

It looks like you might be fitting a bounding box to your mesh. For a closer fit, use the convex hull or mesh types: https://github.com/donmccurdy/three-to-cannon?tab=readme-ov-file#api

@elkizana
Copy link
Author

elkizana commented Jan 25, 2024

result with {type: ShapeType.HULL} :
Screenshot from 2024-01-25 18-55-08

And this when every "S" is a unique mesh :
Screenshot from 2024-01-25 19-03-45

@donmccurdy
Copy link
Owner

donmccurdy commented Jan 25, 2024

@elkizana That's what convex hulls are — think of it like stretching shrink-wrap around an object. If you need a tight fit around concave objects in Cannon.js, then the "mesh" type is your only option, and there are a bunch of performance and support caveats with that, unfortunately.

Ideally your meshes above could be fit with a collection of 'compound' box-shaped bodies, one box fitted to each box-shaped segment of the mesh... But that's not something this library can automate for you. Or if you don't need a full physics engine like cannon.js, then using a navmesh or BVH hierarchy could be alternatives: https://github.com/gkjohnson/three-mesh-bvh.

@elkizana
Copy link
Author

@donmccurdy thank you !
Have you looked at https://github.com/lo-th/phy

@donmccurdy
Copy link
Owner

Very cool! I hadn't seen this yet. It supports higher-end WASM-based physics engines like Havok and Rapier, and might have better options for you indeed.

@elkizana
Copy link
Author

how can it have more detailed collision ?

@donmccurdy
Copy link
Owner

Cannon.js has some significant limitations on collisions with trimesh bodies — discussed in more detail at pmndrs/cannon-es#21. I believe Rapier and Havok have better options for that, but it's always going to be more expensive than colliding with primitive shapes.

In general though, meshes are just a pile of triangles as far as the runtime can see, so it's difficult for an engine to guess how you want to simulate it for performance vs. detail. Usually a good idea to make that decision for the engine if you can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants