I am trying to display a 3D model when a picture is tapped (See here). The picture gets tapped, it segues to 3DFloorPlanViewController
(which is embedded in a navigation controller), the camera works but there is no 3D object displayed (See here).
I've tried this exact same code without a navigation controller and it works perfectly so I'm confused as to why it's not working when embedded in a navigation controller.
My 3D objects are located in a folder called "3D Objects" (See here). I've tried both named: "3D Objects/paperPlane.scn"
and named: "paperPlane.scn"
in the addPaperPlane
function and neither worked.
Here's the code to 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
}
}
At the moment there is no scene set to your scene view
in general try this: