There are a litany of possible ways to bring a model into Xcode for use with an ARKit app. Depending on the format your model is in, alongside which content technology you choose to use for your app, you will find different methodologies for the best experience.
In most cases, models are brought into Xcode as .usdz or .dae objects. These can be imported directly into a project by choosing File -> Add Files To [Project], then choosing your desired model and indicating which target you plan to add to the model to.
Assuming you plan to bundle your model into your project, you can then access your model by its direct path. For example, if your model is "person.usdz", you would be able to locate the path to your model in the app's bundle, like so;
let modelURL = Bundle.main.path(forResource: "person", ofType: "usdz")The same methodology would apply if you were to download your model from a server. Using a networking session, like a
URLSession, you could download your model locally to the device, locate the path for the download, and use that to load the model.
If using
SceneKit as your content technology, you can create a
SCNScene for your model, like so;
let scene = try! SCNScene(url: modelURL, options: [.checkConsistency: true])Subsequently, you could also load your model as a
SCNNode, like so;
Code Block let referenceNode = SCNReferenceNode(url: modelURL) |
referenceNode.load() |
If using
RealityKit as your content technology, the
Loading Entities from a File documentation provides guidance on how to load your model, again, either from the app's bundle, or if necessary, asynchronously, as to ensure a smooth experience for your user. RealityKit does expect a .usdz model, whereas SceneKit can load a .usdz or .dae. Subsequently, the
Model I/O framework has additional guidance on loading models from other file formats in your app.