我的以下代码在touches begin函数中仅显示1个arkit对象。我希望用户能够在arkit场景视图中显示几个相同的arkit对象。现在,用户可以放置图像,但是一旦放置下一个图像,则另一个图像将被删除。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
//Handle the shooting
guard let frame = sceneView.session.currentFrame else { return }
let camMatrix = SCNMatrix4(frame.camera.transform)
let direction = SCNVector3Make(-camMatrix.m31 * 5.0, -camMatrix.m32 * 10.0, -camMatrix.m33 * 5.0)
let position = SCNVector3Make(camMatrix.m41, camMatrix.m42, camMatrix.m43)
let scene = SCNScene(named: "art.scnassets/dontCare.scn")!
// Set the scene to the view
sceneView.scene = scene
}
答案 0 :(得分:0)
Silly Milly,您每次都更改整个场景,而是将节点添加到sceneView.scene
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let frame = sceneView.session.currentFrame else { return }
let camMatrix = SCNMatrix4(frame.camera.transform)
let position = SCNVector3Make(camMatrix.m41, camMatrix.m42, camMatrix.m43)
let object = SCNScene(named: "art.scnassets/dontCare.scn")!.rootNode
object.position = position
sceneView.scene.rootNode.addChildNode(object)
}
答案 1 :(得分:0)