SceneKit - 几何渗透

SceneKit – Geometry penetration

我在ScenekKit中导入一个3D模型,然后改变肢体的欧拉角,让肢体做动作。不过,这时候,衣服和四肢会穿透。我该如何处理这种情况?

我认为您必须使用 continuousCollisionDetectionThreshold 实例 属性。此值为您提供了 body 必须行进的最小距离,SceneKit 才能应用更精确(但 CPU/GPU 成本更高)的算法来检测与其他物体的接触。

var continuousCollisionDetectionThreshold: CGFloat { get set }

SceneKit's physics engine can employ two kinds of collision detection:

  • With discrete collision detection, when SceneKit simulates physics before rendering each frame (see timeStep and SCNSceneRendererDelegate), it updates the position of each physics body based on the body's velocity during that time interval, then checks to see whether the body at its new position intersects other bodies.

  • With continuous collision detection, SceneKit calculates the volume that will be traversed by a body during each frame, then checks to see whether that volume intersects other bodies. This property's value defaults to 0.0, resulting in discrete collision detection at all times. When this value is nonzero, SceneKit applies continuous collision whenever the body travels more than the specified distance within one timeStep.

离散碰撞检测提供了高性能,但可能导致小型 fast-moving 实体的结果不准确。连续碰撞检测具有性能成本并且仅适用于球形物理形状,但提供更准确的结果。