How to edit usdz file in swift

I select usdz file and add reference node with file url.

let scene = SCNScene()

let refNode = SCNReferenceNode(url: usdzPath)

refNode?.position = SCNVector3(0, -0.1, -0.25)
refNode?.load()

refNode?.scale = SCNVector3(0.01, 0.01, 0.01)
scene.rootNode.addChildNode(refNode!)


sceneView.scene = scene

sceneView.delegate = self

sceneView.autoenablesDefaultLighting = true

sceneView!.allowsCameraControl = true

Its works for me. I show the 3D object.

But i want to change usdz file texture in swift. how can i it?

Replies

Do you know Model I/O framework? I think, may be it can edit usdz, but i don't try to do.

You can assign materials to the SCNGeometry object that is associated with a SCNNode. Here is an example how you would set an image as a texture for a node:

if let geometry = node.geometry {
  let texturedMaterial = SCNMaterial(contents: UIImage(named: "myTexture"))
  geometry.materials = [texturedMaterial]
}

Keep in mind that your SCNReferenceNode might not have an associated geometry itself, but possibly has multiple child nodes. Depending on your USDZ model, you may need to traverse the hierarchy of sub-nodes to identify the ones whose material you want to change.