Post

Replies

Boosts

Views

Activity

Reply to Non-convex (torus) collision shapes for VisionOS/RealityKit
Hello @allenfrostline, You can actually use ShapeResource.generateConvex(from: [SIMD3<Float>]) to achieve this by passing in the vertices of each face of the torus mesh. This approach means you will generate a single shape resource for each face which you can add to your model as an array of shapes. This works not only for torus but pretty much any mesh, but beware that shapes can be resource heavy. Convex cooking requires at least four vertices, so (assuming a triangle mesh) you have to add an extra vertex position for each face before using the function above. That extra position needs to lie outside the plane of the face as the convex cooking fails if the vertices are coplanar. I am using the negative normal direction of the face to simply add an extra position just inside the mesh, but you might find a better approach for your use case. The convex cooking might also fail if you pass vertices that are very(!) close together, so if you run into this error I would add some checks to skip or otherwise handle faces that have a significantly small surface area. I don’t remember the exact resolution for this, so you will have to experiment with this yourself.
Feb ’24