Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a SCNNode from a .usdz?

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:

enter image description here

Why does it have no textures?

I have the downloaded .usdz files into a folder in my project directory as you can see:

enter image description here

like image 598
Sergio Avatar asked Nov 15 '18 10:11

Sergio


People also ask

How to create USDZ file online?

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.

What is USDZ and why do developers need it?

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.

What is the difference between USDZ and USDC?

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.

How to download USDZ file from Xcode?

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:


Video Answer


2 Answers

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()
like image 192
Flavio Kruger Avatar answered Sep 20 '22 06:09

Flavio Kruger


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.

like image 44
skymook Avatar answered Sep 20 '22 06:09

skymook