SceneKit physical body does not match SCNPhysicsShape

I have a very simple scene: a cube with a dynamic physical body and a plane with a static physical body. When the cube falls and hits the ground, there is a visible gap between the two objects, you can see the video here:

https://drive.google.com/file/d/0B6IeoVvK5eNLSi01Snowb2kxZFk/view?usp=sharing

I've tried all the different combinations SCNPhysicsShapeTypeKey

and tried setting the SCNPhysicsBody to zero (the docs say, "Leaving this zero, the system will resolve and use the constraint view more efficiently"), but nothing succeeded to remove the gap.

                // ...
                // plane physics
                var body = SCNPhysicsBody(type: SCNPhysicsBodyType.Static, shape: SCNPhysicsShape(geometry: result.node!.geometry!, options: [SCNPhysicsShapeTypeKey:SCNPhysicsShapeTypeConvexHull]));
                result.node!.physicsBody = body;
            } else {
                // cube physics
                var body = SCNPhysicsBody(type: SCNPhysicsBodyType.Dynamic, shape: SCNPhysicsShape(node: result.node!, options: [SCNPhysicsShapeTypeKey:SCNPhysicsShapeTypeConvexHull]));
                result.node!.physicsBody = body;
            }

      

I checked my dae file ( attached here ) and applied all scale / transforms as for this question , however the same result.

I think I am missing something obvious here, any ideas?

+3


source to share


1 answer


@ Toyos' comment about filing a bug is a good idea. However, in this case, it is best not to rely on the default convex hull generation.

TL; DR: Use primitive parametric solids (or their joints) for physical shapes whenever you can.

When you create a physical shape from custom geometry (i.e. loaded from the DAE), SceneKit must build a complex data structure that describes the convex hull of that geometry, and it must work through this data structure to perform collision detection for every processed frame (i.e. i.e. up to 60 times per second).



If you are using one of the built-in parametric shapes ( SCNBox

, SCNSphere

etc.), you are signaling SceneKit that it can use an idealized representation of that shape, rather than a complex data structure based on its polygon mesh.

For an extreme example, consider a sphere: rendering an attractive sphere requires many polygons . If you feed such a mesh into a collision detection algorithm, it either struggles with the complexity of the vertex data, or it should generate an approximation of a shape that is less complex but less accurate (say, a dodecahedron). On the other hand, a sphere is the simplest form of collision detection - all you have to do to find out if a given point is inside the sphere, get the distance from that point to the center of the sphere, and see if it is less than the radius. (Do it right. and you don't even have a cost sqrt

to worry about.)

+4


source







All Articles