【发布时间】:2020-11-29 10:56:33
【问题描述】:
我在我的项目中使用sceneKit,并想在用户点击人体3d模型的位置添加一个红色球体(作为标记)(见下图)。使用我目前的代码,将球体添加到正确的位置 - 但是,它没有添加到人体顶部,而是非常靠近相机(z 值关闭)。如何更改红色球体的 z 值,使其添加到人体顶部而不是相机前面?非常感谢:)
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))
}
}
}
旋转相机时它离身体多远(如果仔细观察,它在背景中
【问题讨论】:
标签: swift xcode scenekit arkit skscene