如何为单个图像设置多个 select 选项?
How can i have multiple select options for a single image?
我正在使用 SceneKit
导入人体 body 的 3d 图像模型。当我 select 图像中的特定位置点时,我希望应用程序识别 body 部分并为每个部分执行不同的功能。我该如何着手实施呢?做这个的最好方式是什么?
P.s。当图像旋转时,它会显示不同的视图。我需要应用程序能够识别 body 部分,即使它被用户旋转也是如此。任何关于如何进行的指导将不胜感激..
这是一个简单的 SceneKit 拾取示例。
场景在 viewDidLoad
中设置,对于您的用例,我希望场景将从文件中加载(最好用另一种方法完成)。该文件有望包含您希望选择的不同组件,作为 tree-like 层次结构中的单独组件。此 3D body 模型的作者有望适当地标记这些组件,以便您的代码可以确定在选择 left-femur(而不是 comp2345)时要执行的操作。
对于复杂模型,任何 xy 坐标都需要几个 'hits',因为您将返回与命中射线相交的所有节点。您可能希望只使用第一次命中。
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()
}
}
我正在使用 SceneKit
导入人体 body 的 3d 图像模型。当我 select 图像中的特定位置点时,我希望应用程序识别 body 部分并为每个部分执行不同的功能。我该如何着手实施呢?做这个的最好方式是什么?
P.s。当图像旋转时,它会显示不同的视图。我需要应用程序能够识别 body 部分,即使它被用户旋转也是如此。任何关于如何进行的指导将不胜感激..
这是一个简单的 SceneKit 拾取示例。
场景在 viewDidLoad
中设置,对于您的用例,我希望场景将从文件中加载(最好用另一种方法完成)。该文件有望包含您希望选择的不同组件,作为 tree-like 层次结构中的单独组件。此 3D body 模型的作者有望适当地标记这些组件,以便您的代码可以确定在选择 left-femur(而不是 comp2345)时要执行的操作。
对于复杂模型,任何 xy 坐标都需要几个 'hits',因为您将返回与命中射线相交的所有节点。您可能希望只使用第一次命中。
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()
}
}