首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何为单个图像有多个选择选项?

如何为单个图像有多个选择选项?
EN

Stack Overflow用户
提问于 2015-10-06 11:55:18
回答 1查看 158关注 0票数 1

我正在使用SceneKit导入人体的三维图像模型。当我在图像中选择一个特定的位置点时,我希望应用程序能够识别身体部分,并为每个部分执行不同的功能。我该如何实现这一点呢?做这件事最好的方法是什么?

附注:当图像被旋转时,它会显示一个不同的视图。我需要应用程序能够识别身体部分,即使它是由用户旋转。如能就如何开展工作提供任何指导,将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-07 08:11:03

下面是一个简单的SceneKit选择示例。

场景是在viewDidLoad中设置的,对于您的用例,我希望场景将从文件中加载(最好在另一种方法中完成)。希望这个文件有不同的组件,您希望在树状层次结构中选择它们作为单独的组件。这个3D身体模型的作者将有希望适当地标记这些组件,以便您的代码能够识别当您的左股骨被选中时该做什么(而不是comp2345)。

对于一个复杂的模型,对任何xy坐标都期望有几个“命中”,因为您将被返回由命中射线相交的所有节点。您可能希望只使用第一个命中。

代码语言:javascript
运行
复制
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()
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32969309

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档