1

I want to show two different 3D objects in two different ARSCNViews. With this question it's allowed to show the two ARSCNViews, but it is basically cloned one view to another.

I want to display different objects in each view.

Do you have any idea?

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
one1color
  • 151
  • 1
  • 6

1 Answers1

1

Yes, it's possible. You can create two ARSCNViews with different models, or even a RealityKit view and an ARKit view. However, in both cases you have to use the same running ARSession. It is not possible to run two different sessions in parallel.

import ARKit

class ViewController: UIViewController {

    @IBOutlet var sceneView: ARSCNView!
    @IBOutlet var sceneViewTwo: ARSCNView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        sceneViewTwo.session = sceneView.session
        
        let scene = SCNScene(named: "art.scnassets/ship.scn")!
        sceneView.scene = scene
        
        let sceneTwo = SCNScene()
        sceneViewTwo.scene = sceneTwo
        
        let sphere = SCNNode(geometry: SCNSphere(radius: 0.1))
        sphere.position.z = -1.0
        sceneViewTwo.scene.rootNode.addChildNode(sphere)
        
        let config = ARWorldTrackingConfiguration()
        sceneView.session.run(config)
    }
}

enter image description here

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
  • 1
    Thanks for your answer. I tried your code, and it worked for me as well. But if I try to implement two ARSCNView, it didn't work(no error, but a black screen is shown) – one1color Apr 28 '22 at 15:45
  • 1
    Yesss! It helped me a lot what i want to do! Thanks! :) – one1color Apr 30 '22 at 08:38