在2018年WWDC announced上,引入了新的USDZ文件格式。
关于创建USDZ文件,如下所述:
为了创建您自己的usdz文件,Xcode10beta中捆绑了一个usdz_converter。它是一个命令行工具,用于从OBJ文件、单帧Alembic (ABC)文件、USD文件( .usda或usd.c)创建usdz文件。
基本的命令行是
xcrun usdz_converter myFile.obj myFile.usdz我已经安装了Xcode10beta,但在2018年6月4日提供的Xcode10beta包(内部版本10L176w)中无法运行甚至无法找到usdz_converter。
注意:我仍然在macOS highSierra上运行,我还没有安装macOS Mojave 10.14测试版...但我认为这不应该是原因。
还有没有人能让这个xcrun usdz_converter运行起来?
如果是这样,请分享步骤。
发布于 2018-06-15 06:56:57
更新时间:2021年8月09日。
Xcode 13、12、11中的usdzconvert命令
macOS蒙特利中的
,Big Sur和Catalina
USDZ converter具有丰富的命令集,并支持比以前版本更多的输入格式进行转换。但在使用它之前,您需要下载USDZ Tools。别忘了为Python usdz工具设置一个全局变量。下面是终端中新命令的外观:
usdzconvert ~/Desktop/file.gltf -diffuseColor albedo.png -metallic brass.jpgZSH.在蒙特利、大苏尔和卡特琳娜的
创建Shell资源文件
如果要使用USDPython外壳工具,则需要创建一个资源文件.zshrc。
为此,在终端中使用change directory命令转到主页区域:
cd /Users/<UserName>使用parent working directory命令检查您是否在那里:
pwd然后为包含隐藏文件的目录内容的listing键入ls命令:
ls -a现在您已经准备好创建一个隐藏的.zshrc文件:
touch ~/.zshrc使用以下命令打开此文件:
open ~/.zshrc现在您可以将以下行添加到zsh资源文件中:
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."保存并重新启动终端。
usdzconvert是将以下资源转换为usdz的Python脚本
如果你需要使用FBX格式转换,你必须下载并安装FBX Python SDK。
然后在.zshrc文件中再添加一行:
export PYTHONPATH="/Applications/Autodesk/FBXPythonSDK/2020.0.1/lib/Python27_ub:$PYTHONPATH"保存.zshrc文件并重新启动终端。
以下是您可以在终端中看到的完整选项列表,键入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]或者,您可以使用应用程序,而不是使用命令行转换工具。这款新应用使得在苹果电脑上转换、查看和定制.usdz对象变得很容易。只需简单地拖放常用的3D文件格式,如.obj、.gltf和.usd,即可查看转换后的.usdz结果,使用自己的纹理自定义材质属性,以及编辑文件元数据。您甚至可以使用内置的IBL选项在各种照明和环境条件下预览您的.usdz对象。
Reality Composer中的USDZ Export命令
在Reality Composer Xcode 13/12中,您可以直接从Reality Composer的UI导出
usdz模型。为此,您只需在RealityComposer - Preferences菜单中激活USDZ导出。

您也可以使用.
从SceneKit的场景创建USDZ文件
获取USDZ文件的另一个好方法是使用write(to:options:delegate:progressHandler:)实例方法从SCNScene创建它。
让我们来看一下代码:
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)
}
}

Xcode10中的xcrun usdz_converter命令
macOS Mojave 10.14和Xcode 10 USDZ converter中的
有一组略有不同的参数和标志。下面是旧命令在终端中的样子:
xcrun usdz_converter file.obj file.usdz -color_map color.jpg -ao_map ao.png以下是您可以在终端中看到的完整选项列表,键入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发布于 2018-06-14 22:29:01
您必须在Xcode首选项中激活命令行工具,以防它们尚未激活(这就是我的情况)。请参阅此主题:
https://stackoverflow.com/questions/50846627
复制相似问题