Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift SceneKit:抽头位置的z值?_Swift_Xcode_Scenekit_Arkit_Skscene - Fatal编程技术网

Swift SceneKit:抽头位置的z值?

Swift SceneKit:抽头位置的z值?,swift,xcode,scenekit,arkit,skscene,Swift,Xcode,Scenekit,Arkit,Skscene,我在我的项目中使用sceneKit,并希望在用户点击人体三维模型的位置上添加一个红色球体(作为标记)(见下图)。使用我目前的代码,球体被添加到正确的位置-但是,它并没有添加到人体顶部,而是非常靠近摄影机(z值为off)。如何更改红色球体的z值,以便将其添加到人体顶部而不是相机前面?非常感谢:) 导入UIKit 进口石英砂 导入SceneKit 类GameViewController:UIViewController{ 变量selectedNode:SCNNode! var markerSpher

我在我的项目中使用sceneKit,并希望在用户点击人体三维模型的位置上添加一个红色球体(作为标记)(见下图)。使用我目前的代码,球体被添加到正确的位置-但是,它并没有添加到人体顶部,而是非常靠近摄影机(z值为off)。如何更改红色球体的z值,以便将其添加到人体顶部而不是相机前面?非常感谢:)

导入UIKit
进口石英砂
导入SceneKit
类GameViewController:UIViewController{
变量selectedNode:SCNNode!
var markerSphereNode:SCNNode!
var bodyNode:SCNNode!
@IBVAR场景视图:SCNView!
重写func viewDidLoad(){
super.viewDidLoad()
let scene=SCNScene(名为:“art.scnassets/femaleBodySceneKit scene.scn”)
markerSphereNode=scene?.rootNode.childNode(名称为“markerSphere”,递归:true)
bodyNode=scene?.rootNode.childNode(名称为:“Body\M\u GeoRndr”,递归:true)
sceneView.scene=场景
sceneView.allowsCameraControl=true
_=sceneView.pointOfView
}
覆盖func TouchesBegind(Touchs:Set,带有事件:UIEvent?){
让我们先接触!
让接触点=接触位置(在:场景视图中)
如果sceneView.hitTest(touch.location(in:sceneView),选项:nil.first!=nil{
markerSphereNode.position=sceneView.unprojectPoint(
SCInvector3(x:Float(touchPoint.x),
y:浮动(接触点y),
z:0.56182814)
}
}
}
单击主体中的某个位置时红色球体的显示方式

当你旋转相机时,它离身体有多远(如果你仔细看,它在背景中

红点应该如何显示
SCNHITTSRESULT
为您提供并且已经提供了。需要使用
取消项目点
方法。

SCNHITTSRESULT
为您提供并且已经提供了。需要使用
取消项目点
方法

  import UIKit
  import QuartzCore
  import SceneKit
      
   class GameViewController: UIViewController {
        
    var selectedNode: SCNNode!
    var markerSphereNode: SCNNode!
    var bodyNode: SCNNode!
    @IBOutlet weak var sceneView: SCNView!
    override func viewDidLoad() {
        super.viewDidLoad()
        let scene = SCNScene(named: "art.scnassets/femaleBodySceneKit Scene.scn")
        markerSphereNode = scene?.rootNode.childNode(withName: "markerSphere", recursively: true)
        bodyNode = scene?.rootNode.childNode(withName: "Body_M_GeoRndr", recursively: true)
        
        sceneView.scene = scene
        sceneView.allowsCameraControl = true
        _ = sceneView.pointOfView
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        let touch = touches.first!
        let touchPoint = touch.location(in: sceneView)
        
        if sceneView.hitTest(touch.location(in: sceneView), options: nil).first != nil {
            markerSphereNode.position = sceneView.unprojectPoint(
                SCNVector3(x: Float(touchPoint.x),
                           y: Float(touchPoint.y),
                           z: 0.56182814))
        }
    }
}