Skip to content

Instantly share code, notes, and snippets.

@daprice daprice/
Last active Jun 8, 2019

What would you like to do?
Convert an STL intended for 3D printing (Z up, mm units) to a USDZ file compatible with Apple's AR Quick Look and ARKit

This script must be placed in the root folder of the USD tools library provided by Apple on their AR Quick Look Gallery page. Requires assimp to be installed.

Command format: ./ input_file.stl output_file.usdz

For now, this just inserts the necessary transformations at a hardcoded line number in the USD markup, so compatibility with future versions of usdzconvert is not guaranteed.

BASEPATH=$(dirname "$0")
TEMPDIR=$(mktemp -d)
assimp export "$1" $TEMPDIR/model.obj
usdzconvert $TEMPDIR/model.obj $TEMPDIR/model_orig.usdz
usdcat $TEMPDIR/model_orig.usdz -o $TEMPDIR/model.usda
sed -i.bak "17i\\
custom double3 xformOp:scale = (0.1, 0.1, 0.1)\\
uniform token[] xformOpOrder = [\"xformOp:scale\"]
" $TEMPDIR/model.usda
sed -i.bak2 's/Y/Z/g' $TEMPDIR/model.usda
usdzip "$2" --arkitAsset $TEMPDIR/model.usda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.