0

我下面的代码仅在 touches started 函数中显示 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
}
4

2 回答 2

1

傻米莉,您每次都在更改整个场景,而是将节点添加到 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)

}

于 2019-01-27T09:21:15.683 回答
0

您必须在 ARSCNView 上添加多个子节点

如果您的 .scn 文件结构类似于

let careScene = SCNScene.init(named: "art.scnassets/dontCare.scn")
let childNode = (careScene?.rootNode.childNode(withName: "Frame", recursively: false))!
childNode.position = SCNVector3(x,y,z)
scenView.scene.rootNode.addChildNode(childNode)
于 2019-07-25T13:13:26.863 回答