我正在使用SceneKit导入人体的三维图像模型。当我在图像中选择一个特定的位置点时,我希望应用程序能够识别身体部分,并为每个部分执行不同的功能。我该如何实现这一点呢?做这件事最好的方法是什么?
附注:当图像被旋转时,它会显示一个不同的视图。我需要应用程序能够识别身体部分,即使它是由用户旋转。如能就如何开展工作提供任何指导,将不胜感激。
发布于 2015-10-07 08:11:03
下面是一个简单的SceneKit选择示例。
场景是在viewDidLoad中设置的,对于您的用例,我希望场景将从文件中加载(最好在另一种方法中完成)。希望这个文件有不同的组件,您希望在树状层次结构中选择它们作为单独的组件。这个3D身体模型的作者将有希望适当地标记这些组件,以便您的代码能够识别当您的左股骨被选中时该做什么(而不是comp2345)。
对于一个复杂的模型,对任何xy坐标都期望有几个“命中”,因为您将被返回由命中射线相交的所有节点。您可能希望只使用第一个命中。
import UIKit
import SceneKit
class ViewController: UIViewController {
@IBOutlet var scenekitView: SCNView!
override func viewDidLoad() {
super.viewDidLoad()
let scene = SCNScene()
let boxNode = SCNNode(geometry: SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0))
boxNode.name = "box"
scene.rootNode.addChildNode(boxNode)
let sphereNode = SCNNode(geometry: SCNSphere(radius: 1))
sphereNode.name = "sphere"
sphereNode.position = SCNVector3Make(2, 0, 0)
boxNode.addChildNode(sphereNode)
let torusNode = SCNNode(geometry: SCNTorus(ringRadius: 1, pipeRadius: 0.3))
torusNode.name = "torus"
torusNode.position = SCNVector3Make(2, 0, 0)
sphereNode.addChildNode(torusNode)
scenekitView.scene = scene
scenekitView.autoenablesDefaultLighting = true
scenekitView.allowsCameraControl = true
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
//get the first touch location in screen coordinates
guard let touch = touches.first else {
return
}
//convert the screen coordinates to view coordinates as the SCNView make not take
//up the entire screen.
let pt = touch.locationInView(self.scenekitView)
//pass a ray from the points 2d coordinates into the scene, returning a list
//of objects it hits
let hits = self.scenekitView.hitTest(pt, options: nil)
for hit in hits {
//do something with each hit
print("touched ", hit.node.name!)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}https://stackoverflow.com/questions/32969309
复制相似问题