Pikebu
Pikebu

Reputation: 111

.usdz model has no texture when loaded into scene

I'm loading a .usdz model (downloaded from Apple) into my ARSCNSceneView which works. But unfortunately the model is always rendered without any texture and appears black.

// Get the url to the .usdz file
guard let usdzURL = Bundle.main.url(forResource:   "toy_robot_vintage", withExtension: "usdz")
else {
    return
}

// Load the SCNNode from file             
let referenceNode = SCNReferenceNode(url: usdzURL)!
referenceNode.load()

// Add node to scene
sceneView.scene.rootNode.addChildNode(referenceNode)

enter image description here

Upvotes: 3

Views: 2978

Answers (2)

Andy Jazz
Andy Jazz

Reputation: 58093

If you have already implemented lights in your 3D scene and these lights have necessary intensity level (default is 1000 lumens), that's Ok. If not, just use the following code for implementing an automatic lighting:

let sceneView = ARSCNView()
sceneView.autoenablesDefaultLighting = true
sceneView.automaticallyUpdatesLighting = true

But if you still don't see a shader of robot model:

  • in Xcode in the Scene Inspector just turn on Procedural Sky value of Environment property from drop-down menu.

enter image description here

Upvotes: 1

M Reza
M Reza

Reputation: 19708

Your scene has no light, that's why the object is showing dark. Just add a directional light to your scene:

let spotLight = SCNNode()
spotLight.light = SCNLight()
spotLight.light?.type = .directional

sceneView.scene.rootNode.addChildNode(spotLight)

Upvotes: 5

Related Questions