【发布时间】:2019-11-22 00:58:59
【问题描述】:
我正在尝试通过命中测试将不同的对象添加到场景中,而我目前只能添加一个对象。我想访问命中测试结果中的第二个、第三个和第四个索引,以便通过触摸添加这些对象。
我尝试通过.indices访问,但它与UITouch不兼容。
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
let touchLocation = touch.location(in: sceneView)
let results = sceneView.hitTest(touchLocation, types: .featurePoint)
if let hitResult = results.first {
let cubeScene = SCNScene(named: "art.scnassets/cube.scn")!
if let cubeNode = cubeScene.rootNode.childNode(withName: "cube", recursively: true) {
sceneView.scene.rootNode.addChildNode(cubeNode)
}
}
}
}
我应该怎么做?我考虑过创建一个 SCNScene,将其作为数组传递,然后从场景中加载所有模型。
【问题讨论】:
-
也许你可以为结果数组做一个 for 循环,而不是仅仅检查第一个元素是否包含某些东西