我想在真正的地板所在的地方添加一个 scnfloor,但它出现在上方,并且在添加 childNode 时,该对象并没有躺在地板上,而是看起来像在飞行。
在记录添加的节点或平面锚点的位置时y = 0
,无论我是在扫描地板还是桌子,我总是得到。
我错过了什么?还是无法更改 scnfloor 的 y?但是在文档中是这样写的
“……它的局部坐标空间”
,所以我认为这是可能的。
谢谢
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
guard let planeAnchor = anchor as? ARPlaneAnchor else {return}
let anchorX = planeAnchor.center.x
let anchorY = planeAnchor.center.y
let anchorZ = planeAnchor.center.z
print("planeAnchor.center %@", planeAnchor.center) //y always 0
print("node.position %@", node.position) //y always 0
print("convert %@", node.convertPosition(SCNVector3(anchorX, anchorY, anchorZ), to: nil)) //y always 0
let floor = SCNFloor()
let floorNode = SCNNode(geometry: floor)
floorNode.position = SCNVector3(anchorX, anchorY, anchorZ)
let floorShape = SCNPhysicsShape(geometry: floor, options: nil)
floorNode.physicsBody = SCNPhysicsBody(type: .static, shape: floorShape)
node.addChildNode(floorNode)
let childNode = createChildNode()
floorNode.addChildNode(childNode)
}