3D artwork that is exported as USDZ has different colors
About Blender, Maya and Xcode
Unfortunately, the issue you mentioned here is a great old issue in Blender. Indeed, Blender outputs wrong (a.k.a. inconsistent) shaders' colors, due to the fact that Blender operates in linear color space (not sRGB) of shader colors. There are 2 possible solutions in this case. The first one is quite radical - to use a real PRO software, like Autodesk Maya 2023 with USD plugin (because it takes a decent amount of time to learn Maya), in which exported shaders' colors are reproduced very accurately in correct color space – you must reassign all the materials from scratch. The second one – fix colors in Xcode's inspector manually, or programmatically.
From Maya you can export your model as binary or ASCII .usd
file format (make sure that MayaUSD plugin is loaded). Then use Reality Converter, to convert the resulting model in .usdz
archive.
Xcode solution
Load your van.usdz
model into Xcode. Rename model's nodes in hierarchy for convenience.
Very important!
Select Body_Orange
node and go to Attributes Inspector
tab. Delete Colors
attribute.
Colors
attribute keeps .usdz
colour schema.
Then in Material Inspector
assign a needed Diffuse
color of physicallyBased
shader.
Also, you can do it programmatically. Here's a SwiftUI sample code for SceneKit:
import SwiftUI
import SceneKit
...
func makeUIView(context: Context) -> SCNView {
let sceneView = SCNView(frame: .zero)
sceneView.scene = SCNScene(named: "van.usdz")
let orangeBody = sceneView.scene?.rootNode.childNodes[0].childNodes[0]
.childNodes[0].childNode(withName: "Body_Orange", recursively: true)
orangeBody?.geometry?.firstMaterial?.diffuse.contents =
UIColor(red: 218/255, green: 154/255, blue: 93/255, alpha: 255/255)
let blueBody = sceneView.scene?.rootNode.childNodes[0].childNodes[0]
.childNodes[0].childNode(withName: "Body_Blue", recursively: true)
blueBody?.geometry?.firstMaterial?.diffuse.contents =
UIColor(red: 58/255, green: 150/255, blue: 207/255, alpha: 255/255)
sceneView.backgroundColor = .black
sceneView.autoenablesDefaultLighting = true
sceneView.allowsCameraControl = true
sceneView.showsStatistics = true
return sceneView
}
And here's a SwiftUI sample code for RealityKit version:
import SwiftUI
import RealityKit
...
func makeUIView(context: Context) -> ARView {
let arView = ARView(frame: .zero)
arView.backgroundColor = .black
let vanModel = try! ModelEntity.load(named: "van.usdz")
let orangeBodyPart = vanModel.children[0].children[0].children[0]
.children[0].children[0] as! ModelEntity
let colorOrange = UIColor(red: 218/255, green: 154/255,
blue: 93/255, alpha: 255/255)
orangeBodyPart.model?.materials = [SimpleMaterial(color: colorOrange,
isMetallic: false)]
let blueBodyPart = vanModel.children[0].children[0].children[0]
.children[0].children[1] as! ModelEntity
let colorBlue = UIColor(red: 58/255, green: 150/255,
blue: 207/255, alpha: 255/255)
blueBodyPart.model?.materials = [SimpleMaterial(color: colorBlue,
isMetallic: false)]
let anchor = AnchorEntity(world: [0, 0,-5])
vanModel.setParent(anchor)
arView.scene.anchors.append(anchor)
return arView
}
A few words on poly count and retopology in Maya
I would like to make one remark about the polygons' count in your model. Such a simple model can be made having 2K to 5K polygons. But your model has over 50,000 polygons, which is a tremendous number. Your hi-poly model will consume a lot of resources (CPU, GPU, memory), thus, drop frame is possible (58 fps, as you can see in the picture).
So, what can you do about it? Ideally, it's a 3D modeler's job to conceive and create low-poly models for games and mobile platforms – it's really a precious skill. Modifying an already finished mesh (saved to distribution formats like .fbx or .usdz) is often a bad idea. However, Autodesk Maya for example, has a retopology tool (Mesh –> Retopologize
) that helps you significantly reduce the number of polygons using advanced algorithm. Watch the official video (Time - 00:50).
How can I convert .obj or .stl to .usdz without Vectary?
With iOS 13 & Reality Kit, Apple has released a USDZ converter that does not require Xcode; the converter is a Python based tool. I have been using it the last few days to convert various files gltf, obj files.
Download link:
https://developer.apple.com/download/more/?=USDPython
Example usage:
usdzconvert someobject.obj
You will want to edit paths for your environment variables.
Or double click the file which is in the top level of the folder:
USD.command
to launch a shell with the environment variables set.
And within Xcode 11, you can export SCN files to USDZ files.
It is well worth watching the WWDC 2019 video; it is just over 30 minutes:
https://developer.apple.com/videos/play/wwdc2019/602/
Is there any way to get a USDZ file without a Mac?
The answer is YES.
As we all know Apple and Pixar together developed a USDZ
file format. It's a compact and simple format that's designed to let people share AR content "while retaining great 3D graphics and even animations." The USDZ
format is addressing the typically large storage size of AR content, which can make it harder to share information easily and quickly. Companies like Adobe are adopting the USDZ
format to work with its Creative Cloud platform, which includes apps like Photoshop and Dimension. Thus, USDZ
file format is not platform-dependant.
A USDZ
package is merely a zero compression, unencrypted Zip Archive
. USDZ
packages are maximally useful within production pipelines. A USDZ
file is read-only - editing its contents requires first unpacking the package and editing its constituent parts using appropriate tools because USDZ
is a "core" USD
file format.
Of course, you can generate a
USDZ
file without a Mac. For this you need a plugin for any of the following professional tools: Autodesk Maya, The Foundry Katana, or SideFX Houdini. For more detailed information read this Pixar's webpage.
How to generate USDZ file again from ZIP file?
To pack my modified USDZ file back, I used the tools provided here: https://github.com/PixarAnimationStudios/USD (usdzip) which works in Windows and Linux.
Related Topics
Structure VS Class in Swift Language
Creating Custom Tableview Cells in Swift
Xcode 8 Beta 3 Use Legacy Swift Issue
How to Unwrap an Optional Value from Any Type
Realitykit VS Scenekit VS Metal - High-Quality Rendering
Swift 2 - Pattern Matching in "If"
Calculate Age from Birth Date Using Nsdatecomponents in Swift
Sharing Userdefaults Between Extensions
How to Set Uicollectionviewcell Width and Height Programmatically
How to Convert Array of Bytes [Uint8] into Hexa String in Swift
How to Pop to the Root View Using Swiftui
Swift Variable Decorations With "" (Question Mark) and "!" (Exclamation Mark)
Initialize @Stateobject With a Parameter in Swiftui
How to Set Layer Cornerradius For Only Bottom-Left, Bottom-Right, and Top-Left Corner
Get Terminal Output After a Command Swift
Swift Function Object Wrapper in Apple/Swift
How to Create a Multi-Line Text Inside a Scrollview in Swiftui