Swift SceneKit - 物理块不会相互粘连

时间:2021-07-04 14:01:30

Blocks just crumble apart.
How can this problem be solved?
Initializing blocks:

街区刚刚崩溃。怎样才能解决这个问题?初始化块:

var boxNode = SCNNode(geometry: SCNBox(width: 0.75, height: 0.15, length: 0.25, chamferRadius: 0))
boxNode.position = SCNVector3(x: x1, y: y, z: z1)
boxNode.geometry?.firstMaterial = SCNMaterial()
boxNode.geometry?.firstMaterial?.diffuse.contents = UIImage(named: "wood.jpg")
boxNode.physicsBody = SCNPhysicsBody(type: .dynamic, shape: nil)
boxNode.eulerAngles.y = Float(Double.pi / 2) * rotation

boxNode.physicsBody?.friction = 1
boxNode.physicsBody?.mass =  0.5
boxNode.physicsBody?.angularDamping = 1.0
boxNode.physicsBody?.damping = 1

picture

video

full code

1 个解决方案

#1


0  

I won't be able to tell you how to fix it as I have the exact same problem which I wasn't able to solve. However, as I played around I figured out a couple of things (which you may find useful):

我无法告诉你如何解决它,因为我有完全相同的问题,我无法解决。但是,当我玩的时候,我想出了一些事情(你可能觉得有用):

  1. The same problem hasn't happened to me in pure SceneKit, hence I think it's a bug in ARKit

    我在纯SceneKit中没有遇到同样的问题,因此我认为这是ARKit中的一个错误

  2. Node with physics has to be added to the rootNode of the scene, otherwise odd stuff happens (elements passing through each other, gravity behaving in an inconsistent way)

    必须将具有物理的节点添加到场景的根节点,否则会发生奇怪的事情(元素通过彼此,重力以不一致的方式表现)

  3. If you pass nil as shape parameter, SceneKit will figure bounding box based on the geometry of the node. This hasn't worked properly for me so what I've done (using SceneKit editor) was to duplicate the geometry and then set it as a custom shape for the bounding box (have a look at the attached image)

    如果将nil作为形状参数传递,则SceneKit将根据节点的几何图形来绘制边界框。这对我来说没有用,所以我所做的(使用SceneKit编辑器)是复制几何体,然后将其设置为边界框的自定义形状(查看附加图像)

Swift SceneKit  - 物理块不会相互粘连

Overall I've found physics simulation in SceneKit when used with ARKit to be extremely buggy and I spent a lot of time "tricking" it into working more-or-less how I wanted it to work.

总的来说,我发现SceneKit中的物理模拟与ARKit一起使用时非常错误,我花了很多时间“欺骗”它或多或少地工作我想要它的工作方式。

#1


0  

I won't be able to tell you how to fix it as I have the exact same problem which I wasn't able to solve. However, as I played around I figured out a couple of things (which you may find useful):

我无法告诉你如何解决它,因为我有完全相同的问题,我无法解决。但是,当我玩的时候,我想出了一些事情(你可能觉得有用):

  1. The same problem hasn't happened to me in pure SceneKit, hence I think it's a bug in ARKit

    我在纯SceneKit中没有遇到同样的问题,因此我认为这是ARKit中的一个错误

  2. Node with physics has to be added to the rootNode of the scene, otherwise odd stuff happens (elements passing through each other, gravity behaving in an inconsistent way)

    必须将具有物理的节点添加到场景的根节点,否则会发生奇怪的事情(元素通过彼此,重力以不一致的方式表现)

  3. If you pass nil as shape parameter, SceneKit will figure bounding box based on the geometry of the node. This hasn't worked properly for me so what I've done (using SceneKit editor) was to duplicate the geometry and then set it as a custom shape for the bounding box (have a look at the attached image)

    如果将nil作为形状参数传递,则SceneKit将根据节点的几何图形来绘制边界框。这对我来说没有用,所以我所做的(使用SceneKit编辑器)是复制几何体,然后将其设置为边界框的自定义形状(查看附加图像)

Swift SceneKit  - 物理块不会相互粘连

Overall I've found physics simulation in SceneKit when used with ARKit to be extremely buggy and I spent a lot of time "tricking" it into working more-or-less how I wanted it to work.

总的来说,我发现SceneKit中的物理模拟与ARKit一起使用时非常错误,我花了很多时间“欺骗”它或多或少地工作我想要它的工作方式。