Skip to content

Instantly share code, notes, and snippets.

@daprice daprice/README.md
Last active Jun 8, 2019

Embed
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: ./stl_to_usdz.sh 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.

#!/bin/bash
BASEPATH=$(dirname "$0")
export PATH=$PATH:$BASEPATH/USD:$PATH:$BASEPATH/usdzconvert;
export PYTHONPATH=$PYTHONPATH:$BASEPATH/USD/lib/python
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.