Xcode, 3D obj doesn't show up in Simulator

Hi everybody, I am an Engineering Student and at the University we have to create a little AR-App.

Now, in Xcode I want to make an Image Tracking and above that Image, it should show my 3D Object. I followed this Video: "https://www.youtube.com/watch?v=VmPHE8M2GZI" until the minute 39:18. After that, it doesnt work.

The simulator detects the Image and shows a light grey Plane above it, even if I move around. But the 3D Model doesn't show up.

  1. I imported the ns.obj file in art.scnassets
  2. Converted to SceneKit file .scn
  3. changed the texture "diffusion" to green
  4. I tried to scale it, but still no result
  5. I tried also with an 3D Object downloaded from the internet

Long Story short.... it doesn't work. Does anyone knows what the Problem could be?

Thank you very much.

Greetings, Rosario

PS:

I use the Xcode Version 14.3.

Thats my code in the ViewController.swift file:

import SwiftUI
import RealityKit
import UIKit
import SceneKit
import ARKit

class ViewController: UIViewController, ARSCNViewDelegate {
    
    @IBOutlet var sceneView: ARSCNView!
    
    var nsNode: SCNNode?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        sceneView.delegate = self
        sceneView.autoenablesDefaultLighting = true
        let nsScene = SCNScene(named: "art.scnassets/ns.scn")
        nsNode = nsScene?.rootNode

    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        let configuration = ARImageTrackingConfiguration()
        
        if let trackingImages = ARReferenceImage.referenceImages(inGroupNamed: "AR Resources", bundle: Bundle.main) {
            configuration.trackingImages = trackingImages
            configuration.maximumNumberOfTrackedImages = 2
        }
        
        sceneView.session.run(configuration)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        sceneView.session.pause()
    }
    
    func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
        
        let node = SCNNode()
        
        if let imageAnchor = anchor as? ARImageAnchor   {
            let size = imageAnchor.referenceImage.physicalSize
            let plane = SCNPlane(width: size.width, height: size.height)
            plane.firstMaterial?.diffuse.contents = UIColor.white.withAlphaComponent(0.5)
            plane.cornerRadius = 0.005
            let planeNode = SCNNode(geometry: plane)
            planeNode.eulerAngles.x = -.pi / 2
            node.addChildNode(planeNode)
            
            if let shapeNode = nsNode {
                node.addChildNode(shapeNode)
            }
            
        }
        
        return node
        
    }
    
}
  • I don't mean the Simulator. I know that in ARKIT the simulator doesn't work, I've done it with my iPhone connected in my Mac...

Add a Comment