【问题标题】:ARSCNView not displaying object when embedded in navigation controller嵌入导航控制器时 ARSCNView 不显示对象
【发布时间】:2018-11-26 17:00:11
【问题描述】:

我正在尝试在点击图片时显示 3D 模型 (See here)。图片被点击,它转到3DFloorPlanViewController(嵌入在导航控制器中),相机工作但没有显示 3D 对象(See here)。

我在没有导航控制器的情况下尝试了完全相同的代码,它运行良好,所以我很困惑为什么嵌入导航控制器时它不起作用。

Storyboard picture

我的 3D 对象位于名为“3D 对象”(See here) 的文件夹中。我在addPaperPlane 函数中尝试了named: "3D Objects/paperPlane.scn"named: "paperPlane.scn",但都没有成功。

这是3DFloorPlanViewController的代码:

import UIKit
import ARKit
import SceneKit

class _DFloorPlanViewController: UIViewController, ARSCNViewDelegate {
    @IBOutlet weak var sceneView: ARSCNView!

    override func viewDidLoad() {
        super.viewDidLoad()

        sceneView.delegate = self

        addPaperPlane()
        //addCar()
        configureLighting()
    }

    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 addPaperPlane(x: Float = 0, y: Float = 0, z: Float = -0.5) {
        guard let paperPlaneScene = SCNScene(named: "3D Objects/paperPlane.scn"), let paperPlaneNode = paperPlaneScene.rootNode.childNode(withName: "paperPlane", recursively: true) else { return }
        paperPlaneNode.position = SCNVector3(x, y, z)
        sceneView.scene.rootNode.addChildNode(paperPlaneNode)
    }

    func addCar(x: Float = 0, y: Float = 0, z: Float = -0.5) {
        guard let carScene = SCNScene(named: "car.dae") else { return }
        let carNode = SCNNode()
        let carSceneChildNodes = carScene.rootNode.childNodes

        for childNode in carSceneChildNodes {
            carNode.addChildNode(childNode)
        }

        carNode.position = SCNVector3(x, y, z)
        carNode.scale = SCNVector3(0.5, 0.5, 0.5)
        sceneView.scene.rootNode.addChildNode(carNode)
    }

    func configureLighting() {
        sceneView.autoenablesDefaultLighting = true
        sceneView.automaticallyUpdatesLighting = true
    }
}

【问题讨论】:

    标签: swift uinavigationcontroller arkit arscnview


    【解决方案1】:

    目前没有为您的场景视图设置场景

    let scene = SCNScene()
    self.sceneView.scene = scene
    

    一般试试这个:

     override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    
        // Set the view's delegate
        self.sceneView.delegate = self
        self.sceneView.showsStatistics = true
        self.sceneView.autoenablesDefaultLighting = true
    
        let scene = SCNScene()
        self.sceneView.scene = scene
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-05
      • 2011-04-15
      • 1970-01-01
      • 1970-01-01
      • 2015-05-29
      • 1970-01-01
      • 2015-11-05
      相关资源
      最近更新 更多