I have downloaded the .usdz models provided by Apple: https://developer.apple.com/arkit/gallery/
But now, I want to create a SCNNode with one of these models, so I am doing this to obtain the node:
guard let urlPath = Bundle.main.url(forResource: "retrotv", withExtension: "usdz") else {
return
}
let mdlAsset = MDLAsset(url: urlPath)
let modelRootNode = SCNScene(mdlAsset: mdlAsset).rootNode
Then I add it to the scene and the result is this:
Why does it have no textures?
I have the downloaded .usdz files into a folder in my project directory as you can see:
You can create usdz files online in a tool called Vectary: Open Vectary editor. Create your 3D model or import your 3D file with drag and drop (OBJ, STL, GLTF, DAE). Export as USDZ 3D file in the right panel.
For developers, USDZ is simply another file format they have to learn. Having a tool that will allow you to make your complete product catalog available in 3D and export assets to most file formats seamlessly is essential. Marxent’s 3D Cloud is capable of storing assets generically, providing access to team members when and where they need them.
For now, a USDZ file can contain only these file types: USDA: The ASCII format for saving a scene description in text. ASCII itself takes a long time to parse. USDC: The binary format of a USD file, USDC files load faster.
You can download each of those sample USDZ models into the file App on your device by clicking the sendto icon in top right-hand corner and clicking Save to Files. I'm try to do create a usdz file with Xcode but for me give me a error:
The correct way to add the .USDZ object is actually creating the scene with the file's URL:
let scene = try! SCNScene(url: usdzURL, options: [.checkConsistency: true])
Or even creating via Reference Node:
let referenceNode = SCNReferenceNode(url: usdzURL)
referenceNode.load()
It is possible to load a usdz into an ARKit scene.
It's important to have the these imports
import ARKit
import SceneKit
import SceneKit.ModelIO
Load the usdz via a URL.
guard let urlPath = Bundle.main.url(forResource: "retrotv", withExtension: "usdz") else {
return
}
let mdlAsset = MDLAsset(url: urlPath)
// you can load the textures on an MDAsset so it's not white
mdlAsset.loadTextures()
Wrap it in a node.
let asset = mdlAsset.object(at: 0) // extract first object
let assetNode = SCNNode(mdlObject: asset)
You can now attach this node in ARKit. You would need to scale and orientate the object to where you want it in the real world, but that code depends on what you are trying to do, so I've left that out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With