如何在ARKit中将3D对象放置在垂直平面上?

时间:2019-07-04 13:11:19

标签: ios swift 3d scenekit arkit

我正在尝试使用下面的代码在垂直平面上放置3D对象,但其位置不正确。如果有人完成了垂直对象的放置,则需要您的帮助。

@objc func addObjectToSceneView1(withGestureRecognizer recognizer: UIGestureRecognizer){
let tapLocation = recognizer.location(in: sceneView)
let hitTestResults = sceneView.hitTest(tapLocation, types: .existingPlaneUsingExtent)

guard let hitTestResult = hitTestResults.first, let anchor = hitTestResult.anchor as? ARPlaneAnchor else { return }
// create anchor and add to session and wait for callback
let anchor = ARAnchor(transform: hitTestResult.worldTransform)
sceneView.session.add(anchor: anchor)} 

func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
if anchor is ARPlaneAnchor {
    // node for plane anchor
    let anchorNode = SCNNode()
    return anchorNode
} else {
    // must be node for most recent hit test
    guard let frameScene = SCNScene(named: "art.scnassets/frame/frame.scn"),
          let frameNode = frameScene.rootNode.childNode(withName: "frame", recursively: true) else { return nil }
    return frameNode
}}

我不明白这是怎么回事?

0 个答案:

没有答案