arkit framework

While placing .scn file using ARKit 2 when user taps on screen models with single layer are rendering on screen instantly but problem arrises when multilayer(2 to 3 layers) .scn file taking about 1 to 3 seconds to render, kind of stuck UI while rendering? And once the ARConfiguration session is reset then it works fine for all the models. I have checked these models on apple provided demo for handling interaction app and same happens their also. Can anyone help me out why multilayer objects are not rendering instantly for the first time?

Replies

Hello,


If you run the SceneKit Instrument on your app, you will notice that a very large chunk of time (probably multiple seconds) is spent "preparing" your object, which is causing your app to freeze up.


Here is a code snippet demonstrating the proper way to insert a new model into your current scene:


if let sceneToPrepare = SCNScene(named: "Art.scnassets/stratocaster.scn") {
      self.sceneView.prepare([sceneToPrepare], completionHandler: { (_) in
          if let preparedNode = sceneToPrepare.rootNode.childNode(withName: "Stratocaster", recursively: true) {
              self.sceneView.scene.rootNode.addChildNode(preparedNode)
          }
      })
}


This allows us to "prepare" the model that we are about to insert before we actually need to render it on the screen, which should help us entirely avoid freezing up our scene!


Important: If the model you are loading has an environmental texture, this will not get prepared when you pass in the SCNScene, so you will still experience lag unless you prepare that environmental texture seperately beforehand.