我有以下情况。
显示桥的SCNView.scn
在屏幕的左侧,您可以看到桥梁的外观。

我想做以下事情。


在“模型浏览器”中选择左侧的项目
缩放到所选项目并专注于它


ios - 是否有可能专注于所选的SCNNode-LMLPHP

在提供的屏幕截图上。您可以看到我选择了KistSceneView中为黄色
现在,我要缩放并专注于所选的SCNNode

我已经尝试使用rayTestWithSegment查找要缩放的选定位置。但是rayTestWithSegment的结果始终是[]

我也尝试过使用SCNLookAtConstraint,但这并不能解决问题。

    var constraint: SCNLookAtConstraint!

    func handle(gesture: UIGestureRecognizer) {
        guard let result = hitTestResult(for: gesture), let world = sceneView?.scene?.physicsWorld else { return }
        let nodePosition = result.node.position
        let results = world.rayTestWithSegment(from: SCNVector3(0, 1, 0), to: nodePosition, options: nil)
        print(results)
        constraint = SCNLookAtConstraint(target: result.node)
        sceneView?.pointOfView?.constraints = [constraint]
    }

    func hitTestResult(for gesture: UIGestureRecognizer) -> SCNHitTestResult? {
        let location = gesture.location(in: sceneView)
        guard let hit = sceneView?.hitTest(location, options: nil), hit.count > 0, let result = hit.first else {
            return nil
        }
        return result
    }


我正在使用rayTestWithSegment,因为我选择的SCNNode可能无法完全显示。例如,在此透视图中,位于另一个节点后面的SCNNode

在此先感谢您,希望我能帮助/解释我做错了什么。

最佳答案

您可以看看-[SCNCameraController frameNodes:] API应该执行的操作。

关于ios - 是否有可能专注于所选的SCNNode,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59283918/

10-10 20:40