如何使用 Xcode 转换器创建 USDZ 文件? [英] How to create USDZ file using Xcode converter?
问题描述
在 2018 年 WWDC 上,Apple
您也可以使用
xcrun usdz_converter
在 Xcode 10 中的命令
<块引用>在 macOS Mojave 10.14 和 Xcode 10 USDZ 转换器
不同的参数和标志集.这是终端中旧命令的样子:
xcrun usdz_converter file.obj file.usdz -color_map color.jpg -ao_map ao.png
- 在 macOS Mojave 中,默认的命令外壳是 BASH.
这是您可以在终端中看到的完整选项列表,输入 xcrun usdz_converter -h
:
-g groupName [groupNames ...] 将后续材料属性应用于命名组.-m materialName [materialNames ...] 将后续的材料属性应用于指定的材料.-h 显示帮助.-a 生成 .usda 中间文件.默认为 .usdc.-l 将中间 .usd 文件保留在源文件夹中.-v 详细输出.-f filePath 从文件中读取命令.-texCoordSet set 纹理贴图坐标集的名称,如果存在多个则使用(无引号).-opacity o 浮点值 0.0...1.0-color_default r g b a 浮点值 0.0...1.0-normal_default r g b a 浮点值 0.0...1.0-emissive_default r g b a 浮点值 0.0...1.0-metal_default r g b a 浮点值 0.0...1.0-roughness_default r g b a 浮点值 0.0...1.0-ao_default r g b a 浮点值 0.0...1.0-color_map 文件路径-normal_map 文件路径-emissive_map 文件路径-metal_map 文件路径-roughness_map 文件路径-ao_map 文件路径
At the 2018 WWDC Apple announced the introduction of new USDZ file format.
In relation to creating USDZ file the following was said:
To create your own usdz files, a usdz_converter has been bundled as part of Xcode 10 beta. Its a command line tool for creating the usdz file from OBJ files, Single-frame Alembic (ABC) files, USD file (either .usda or usd.c)
the basic command line is
xcrun usdz_converter myFile.obj myFile.usdz
I have installed Xcode 10 beta, but have been unable to run or even find usdz_converter in the Xcode 10 beta bundle made available on the 4th June 2018 (build 10L176w).
note: I’m still running on macOS highSierra, I have not installed macOS Mojave 10.14 beta yet... but didn’t think that should be the reason why.
Has anyone else been able to get this xcrun usdz_converter to work?
If so please share the steps.
Updated: August 09, 2021.
usdzconvert
command in Xcode 13, 12, 11
In macOS Monterey, Big Sur and Catalina
USDZ converter
has a rich set of commands and supports more input formats for conversion than previous version. But before using it you need to download USDZ Tools. And don't forget to setup a global variables for Python usdz tools. Here's how a new command looks like in Terminal:
usdzconvert ~/Desktop/file.gltf -diffuseColor albedo.png -metallic brass.jpg
- In macOS Monterey, Big Sur and Catalina the default command shell is ZSH.
Create Shell Resource file
If you want to use USDPython
tools you need to create a Shell Resource file .zshrc
.
For that go to Home area using change directory
command in Terminal:
cd /Users/<UserName>
Check whether you are there or not with parent working directory
command:
pwd
Then type ls
command for listing
of directory's content including hidden files:
ls -a
Now you are ready to create a hidden .zshrc
file:
touch ~/.zshrc
Open this file using the following command:
open ~/.zshrc
Now you can add these lines into zsh resource file:
export PATH="/Users/yourUserName/usdpython/USD:$PATH"
export PATH="/Users/yourUserName/usdpython/usdzconvert:$PATH"
export PYTHONPATH="/Users/yourUserName/usdpython/USD/lib/python:$PYTHONPATH"
echo "Now I can use USDPython commands here."
Save it and restart Terminal.
usdzconvert
is a Python script that converts the following assets into usdz
:
- obj
- gltf
- fbx
- abc
- usda
- usdc
- usd
If you need to use FBX
format conversion you have to download and install FBX Python SDK.
Then add to .zshrc
file one more line:
export PYTHONPATH="/Applications/Autodesk/FBXPythonSDK/2020.0.1/lib/Python27_ub:$PYTHONPATH"
Save .zshrc
file and restart Terminal.
Here's a full list of options you can see in Terminal, typing usdzconvert -h
:
# DON'T USE usdzconvert 0.63 BECAUSE IT CAUSES ERRORS.
# USE usdzconvert 0.64
# or
# USE usdzconvert 0.62
outputFile Output .usd/usda/usdc/usdz files.
-h, --help Show this help message and exit.
-f <file> Read arguments from <file>
-v Verbose output.
-url <url> Add URL metadata
-copyright "copyright message" Add copyright metadata
-copytextures Copy texture files (for .usd/usda/usdc) workflows
-metersPerUnit value Set metersPerUnit attribute with float value
-loop Set animation loop flag to 1
-no-loop Set animation loop flag to 0
-m materialName Subsequent material arguments apply to this material.
-iOS12 Make output file compatible with iOS 12 frameworks
-texCoordSet name The name of the texture coordinates to use for current material.
-diffuseColor r,g,b Set diffuseColor to constant color r,g,b with values in the range [0 .. 1]
-diffuseColor <file> fr,fg,fb Use <file> as texture for diffuseColor.
fr,fg,fb: (optional) constant fallback color, with values in the range [0..1].
-normal x,y,z Set normal to constant value x,y,z in tangent space [(-1, -1, -1), (1, 1, 1)].
-normal <file> fx,fy,fz Use <file> as texture for normal.
fx,fy,fz: (optional) constant fallback value, with values in the range [-1..1].
-emissiveColor r,g,b Set emissiveColor to constant color r,g,b with values in the range [0..1]
-emissiveColor <file> fr,fg,fb Use <file> as texture for emissiveColor.
fr,fg,fb: (optional) constant fallback color, with values in the range [0..1].
-metallic c Set metallic to constant c, in the range [0..1]
-metallic ch <file> fc Use <file> as texture for metallic.
ch: (optional) texture color channel (r, g, b or a).
fc: (optional) fallback constant in the range [0..1]
-roughness c Set roughness to constant c, in the range [0..1]
-roughness ch <file> fc Use <file> as texture for roughness.
ch: (optional) texture color channel (r, g, b or a).
fc: (optional) fallback constant in the range [0..1]
-occlusion c Set occlusion to constant c, in the range [0..1]
-occlusion ch <file> fc Use <file> as texture for occlusion.
ch: (optional) texture color channel (r, g, b or a).
fc: (optional) fallback constant in the range [0..1]
-opacity c Set opacity to constant c, in the range [0..1]
-opacity ch <file> fc Use <file> as texture for opacity.
ch: (optional) texture color channel (r, g, b or a).
fc: (optional) fallback constant in the range [0..1]
-clearcoat c Set clearcoat to constant c, in the range [0..1]
-clearcoat ch <file> fc Use <file> as texture for clearcoat.
ch: (optional) texture color channel (r, g, b or a).
fc: (optional) fallback constant in the range [0..1]
-clearcoatRoughness c Set clearcoat roughness to constant c, in the range [0..1]
-clearcoatRoughness ch <file> fc Use <file> as texture for clearcoat roughness.
ch: (optional) texture color channel (r, g, b or a).
fc: (optional) fallback constant in the range [0..1]
Or, instead of using a command line conversion tool (CLI), you could use a Reality Converter app (GUI). The new app makes it easy to convert, view, and customise .usdz
objects on Mac. Simply drag-and-drop common 3D file formats, such as .obj
, .gltf
and .usd
, to view the converted .usdz
result, customise material properties with your own textures, and edit file metadata. You can even preview your .usdz
object under a variety of lighting and environment conditions with built-in IBL options.
USDZ Export
command in Reality Composer
In Reality Composer for Xcode 13/12 you can export a
usdz
model right from Reality Composer's UI. For that you just need to activate a USDZ export in RealityComposer – Preferences menu.
Also you can use AR USD Schemas.
Create USDZ file from SceneKit's scene
Another great way to get a USDZ file is to create it from the SCNScene using the write(to:options:delegate:progressHandler:) instance method.
Let's take a look at the code:
import ARKit
class ViewController: UIViewController {
@IBOutlet var sceneView: ARSCNView!
let scene = SCNScene(named: "art.scnassets/ship.scn")!
override func viewDidLoad() {
super.viewDidLoad()
sceneView.scene = scene
let path = FileManager.default.urls(for: .documentDirectory,
in: .userDomainMask)[0]
.appendingPathComponent("model.usdz")
scene.write(to: path, options: nil,
delegate: nil, progressHandler: nil)
print(path)
}
}
xcrun usdz_converter
command in Xcode 10
In macOS Mojave 10.14 and Xcode 10
USDZ converter
has a slightly different set of arguments and flags. Here's how an old command looks like in Terminal:
xcrun usdz_converter file.obj file.usdz -color_map color.jpg -ao_map ao.png
- In macOS Mojave the default command shell is BASH.
Here's a full list of options you can see in Terminal, typing xcrun usdz_converter -h
:
-g groupName [groupNames ...] Apply subsequent material properties to the named group(s).
-m materialName [materialNames ...] Apply subsequent material properties to the named material(s).
-h Display help.
-a Generate a .usda intermediate file. Default is .usdc.
-l Leave the intermediate .usd file in the source folder.
-v Verbose output.
-f filePath Read commands from a file.
-texCoordSet set The name of the texturemap coordinate set to use if multiple exist (no quotes).
-opacity o Floating point value 0.0...1.0
-color_default r g b a Floating point values 0.0...1.0
-normal_default r g b a Floating point values 0.0...1.0
-emissive_default r g b a Floating point values 0.0...1.0
-metallic_default r g b a Floating point values 0.0...1.0
-roughness_default r g b a Floating point values 0.0...1.0
-ao_default r g b a Floating point values 0.0...1.0
-color_map filePath
-normal_map filePath
-emissive_map filePath
-metallic_map filePath
-roughness_map filePath
-ao_map filePath
这篇关于如何使用 Xcode 转换器创建 USDZ 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!