【问题标题】:arkit scene view is only display 1 arkit objectarkit 场景视图仅显示 1 个 arkit 对象
【发布时间】:2019-06-19 21:57:01
【问题描述】:

我下面的代码仅在 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
}

【问题讨论】:

    标签: swift4 arkit touchesbegan sceneview


    【解决方案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)
    

    }

    【讨论】:

    • 我把这段代码放在什么函数里。我试着把它放在 touches 开始但没有用。
    • 你可以保持联系开始了。我认为你的问题是立场。您需要在现实世界中执行命中测试。试试 Apple 的放置对象代码。
    • 这在接触开始的对象节点未被识别时不起作用。
    【解决方案2】:

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

    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)
    

    【讨论】:

    • 我把这段代码放在 touchesBegan 中的什么函数?当我把它放在那里时,它会导致编译错误。
    • 是的,你可以开始 touchesBegan。你得到哪个错误?
    猜你喜欢
    • 2019-06-26
    • 2018-08-26
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    • 2019-03-20
    • 1970-01-01
    • 1970-01-01
    • 2018-01-31
    相关资源
    最近更新 更多