gpt4 book ai didi

swift - ARSCNView 嵌入导航 Controller 时不显示对象

转载 作者:行者123 更新时间:2023-11-30 11:00:03 26 4
gpt4 key购买 nike

我试图在点击图片时显示 3D 模型 ( See here )。点击图片后,它会转到 3DFloorPlanViewController(嵌入在导航 Controller 中),相机可以工作,但没有显示 3D 对象 ( See here )。

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

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
}
}

最佳答案

目前您的场景 View 中没有设置场景

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
}

关于swift - ARSCNView 嵌入导航 Controller 时不显示对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53485811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com