SCNPhysicsShape(shapes:transforms:) creates MULTIPLE shapes?

0
59


My goal is to create a single physics body out of several of SceneKit’s SCNBox geometries.

My understanding is that when I pass an SCNPhysicsShape(shapes:transforms:) to an SCNPhysicsBody(type:shape:), it should create a single physics body.

However, I end up with something that seems suspiciously like it’s not a single physics body at all, but rather several separate physics bodies — one for each shape I passed into SCNPhysicsShape(shapes:transforms:).

When I turn on scnView.debugOptions = .showPhysicsShapes, I can clearly see red lines defining the separate bodies in question. On its own, this isn’t very convincing evidence (it’s conceivable that those lines could be shown for whatever reason while still being a single physics body).

But there’s another piece of data, here: The project in which I’m encountering this issue features a small ball that rolls around the scene — and when that ball rolls over the red lines in question, the ball bounces up into the air a bit. So, it’s quite obvious that, whatever is actually going on, there are edges where I would expect to see none.

Here’s some code illustrating the issue. parent is an SCNNode that holds the child nodes, and is the node to which I assign the physics body. Please assume that all properties are defined; I’m omitting things that aren’t terribly relevant.

let childShape1 = SCNBox(width: 6, height: 2, length: 6, chamferRadius: 0.0)
//Other child shapes defined here...

//Set up the positional translation relative to the child node's parent:
let translateMatrixShape1 = SCNMatrix4MakeTranslation(childShape1.position.x, childShape1.position.y, childShape1.position.z)
//Other child translations defined here...

let parentShape = SCNPhysicsShape(shapes: [childShape1, childShape2, childShape3, childShape4], transforms: [translateMatrixShape1, translateMatrixShape2, translateMatrixShape3, translateMatrixShape4])

parent.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.static, shape: parentShape)

Now, parentShape is four rectangular boxes arranged around a central point, creating a sort of picture-frame-shaped object.

The ball is an SCNNode with an SCNSphere geometry and a dynamic physics body.

Question: Does anyone have any idea what might be going on, here? Have I somehow misunderstood how this whole thing works, or is this a limitation of SceneKit?