SCNNode 边界大小和缩放
SCNNode Bounding size and Scaling
我正在尝试获取屏幕上节点的大小。这是代码:
var v1 = SCNVector3(x:0, y:0, z:0)
var v2 = SCNVector3(x:0, y:0, z:0)
carNode.getBoundingBoxMin(&v1, max: &v2)
print(v2)
carNode.scale = SCNVector3(0.9, 1.2, 0.5)
//carNode.transform = SCNMatrix4MakeScale(0.9, 1.2, 0.5)
carNode.getBoundingBoxMin(&v1, max: &v2)
print(v2)
但是getBoundingBoxMin前后返回的值是一样的,就好像没有考虑缩放一样。这是为什么?我需要此信息来为碰撞检测节点上的物理体设置正确的大小,并确定其他节点是否在对象的某个范围内。
每 SCNBoundingVolume Protocol Reference:
The SCNBoundingVolume protocol's ... methods measure the location and size of an object in the object’s local coordinate space, expressed as either a box or a sphere.
缩放节点不会改变其局部坐标 space。所以你得到了正确的结果。
不过,您可能不需要做任何事情。在 SCNPhysicsShapeScaleKey
文档下注释(在 SCNPhysicsShape
class 参考下:
SceneKit’s physics simulation ignores the scale property of nodes containing physics bodies when simulating collisions. Instead, use this option to provide a scale factor when creating custom physics shapes. (If you create a physics body for a node without specifying a custom shape, SceneKit uses the node’s scale property to infer this scale factor at creation time.)
所以如果你的比例因子没有自动应用,看起来(我还没有测试过)将你的比例矢量传递给 SCNPhysicsShape.init(node:options:)
,使用选项键 SCNPhysicsShapeScaleKey
,就可以了你想要什么。
我正在尝试获取屏幕上节点的大小。这是代码:
var v1 = SCNVector3(x:0, y:0, z:0)
var v2 = SCNVector3(x:0, y:0, z:0)
carNode.getBoundingBoxMin(&v1, max: &v2)
print(v2)
carNode.scale = SCNVector3(0.9, 1.2, 0.5)
//carNode.transform = SCNMatrix4MakeScale(0.9, 1.2, 0.5)
carNode.getBoundingBoxMin(&v1, max: &v2)
print(v2)
但是getBoundingBoxMin前后返回的值是一样的,就好像没有考虑缩放一样。这是为什么?我需要此信息来为碰撞检测节点上的物理体设置正确的大小,并确定其他节点是否在对象的某个范围内。
每 SCNBoundingVolume Protocol Reference:
The SCNBoundingVolume protocol's ... methods measure the location and size of an object in the object’s local coordinate space, expressed as either a box or a sphere.
缩放节点不会改变其局部坐标 space。所以你得到了正确的结果。
不过,您可能不需要做任何事情。在 SCNPhysicsShapeScaleKey
文档下注释(在 SCNPhysicsShape
class 参考下:
SceneKit’s physics simulation ignores the scale property of nodes containing physics bodies when simulating collisions. Instead, use this option to provide a scale factor when creating custom physics shapes. (If you create a physics body for a node without specifying a custom shape, SceneKit uses the node’s scale property to infer this scale factor at creation time.)
所以如果你的比例因子没有自动应用,看起来(我还没有测试过)将你的比例矢量传递给 SCNPhysicsShape.init(node:options:)
,使用选项键 SCNPhysicsShapeScaleKey
,就可以了你想要什么。