ARKit如何禁用SCNNode上的交互

时间:2018-12-04 08:10:32

标签: ios arkit

我通过在ARSCNView中添加一个SCNNode框创建了一个最简单的ARKit演示。

    let box = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0)

    let boxNode = SCNNode()
    boxNode.geometry = box
    boxNode.position = SCNVector3(x, y, z)

    sceneView.scene.rootNode.addChildNode(boxNode)

我的应用程序中显示一个白框。当我四处走动时,盒子会留在原先的位置。

我可以放大/缩小框,也可以旋转框。当盒子被缩放或旋转时,它不会停留在固定的位置,而是用我的相机移动。

如何禁用此缩放/旋转功能?

===

这是我的viewcontroller.swfit

//
//  ViewController.swift
//  ARKitDemo1
//
//  Created by David Peng on 2018/11/27.
//  Copyright © 2018 David Peng. All rights reserved.
//

import UIKit
import SceneKit
import ARKit

class ViewController: UIViewController, ARSCNViewDelegate {

    @IBOutlet weak var sceneView: ARSCNView!

    override func viewDidLoad() {
        super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
        sceneView.delegate = self

        addBox()
        // debug feature
        sceneView.showsStatistics = true
        sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints]
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        let configuration = ARWorldTrackingConfiguration()
        sceneView.session.run(configuration)
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        sceneView.session.pause()
    }

    func addBox(x: Float = 0, y: Float = 0, z: Float = -0.2) {
        let box = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0)

        let boxNode = SCNNode()
        boxNode.geometry = box
        boxNode.position = SCNVector3(x, y, z)

        sceneView.scene.rootNode.addChildNode(boxNode)
    }

 }

0 个答案:

没有答案