Last active
August 31, 2023 19:17
-
-
Save yibojiang/907b22f4b4049e53481d95de5b249ea5 to your computer and use it in GitHub Desktop.
a simple bash tool converting model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Author Yibo Jiang | |
# Contact: yibojiang00@gmail.com | |
# Assimp | |
# License 3-clause BSD-License. Copyright (c) 2006-2015 assimp team All rights reserved.. | |
function list { | |
echo " | |
Support model formats: | |
Autodesk ( fbx ) | |
Collada ( dae ) | |
glTF ( gltf, glb ) | |
Blender 3D ( blend ) | |
3ds Max 3DS ( 3ds ) | |
3ds Max ASE ( ase ) | |
Wavefront Object ( obj ) | |
Industry Foundation Classes (IFC/Step) ( ifc ) | |
XGL ( xgl,zgl ) | |
Stanford Polygon Library ( ply ) | |
AutoCAD DXF ( dxf ) | |
LightWave ( lwo ) | |
LightWave Scene ( lws ) | |
Modo ( lxo ) | |
Stereolithography ( stl ) | |
DirectX X ( x ) | |
AC3D ( ac ) | |
Milkshape 3D ( ms3d ) | |
TrueSpace ( cob, scn ) | |
Support export formats: | |
Collada ( dae ) | |
X Files ( x ) | |
Step Files ( stp ) | |
Wavefront OBJ format ( obj ) | |
Stereolithography ( binary) ( stl ) | |
Stanford Polygon Library ( stp ) | |
Stanford Polygon Library ( binary ) ( plyb ) | |
Autodesk 3DS ( legacy) ( 3ds ) | |
GL Transmission Format ( gltf ) | |
GL Transmission Format ( binary ) ( glb ) | |
Assimp Binary ( assbin ) | |
Assxml Document ( xml ) | |
Extensible 3D ( x3d ) | |
" | |
exit 1 | |
} | |
function install_assimp { | |
LIB=$HOME/"lib" | |
FILE="libassimp.3.3.1 3.dylib" | |
ALIAS_FILE="libassimp.3.dylib" | |
ALIAS_FILE2="libassimp.dylib" | |
FILE_PATH=$LIB/$FILE | |
# echo $FILE_PATH | |
if [ -f $FILE_PATH ]; then | |
echo "No need to cp the libassimp.3.dylib, already exists." | |
echo "" | |
else | |
if [[ -d ${LIB} ]]; then | |
# echo "${LIB} exists" | |
echo "" | |
else | |
echo "${LIB} doesn't exists, create one." | |
mkdir ${LIB} | |
fi | |
ln "$FILE" "$LIB/$ALIAS_FILE" | |
ln "$FILE" "$LIB/$ALIAS_FILE2" | |
ln "$FILE" "$LIB/$FILE" | |
echo "ln $FILE $LIB/$ALIAS_FILE" | |
echo "ln $FILE $LIB/$ALIAS_FILE2" | |
echo "ln $FILE $LIB/$FILE" | |
fi | |
} | |
function usage { | |
cat << EOF | |
Usage: | |
./converter.sh -i = Install assimp library. | |
./converter.sh -l = List all supported model formats. | |
./converter.sh -f <export_format> -s <src_folder> -r <dist_folder> = Batch Export the models with specific format. | |
Example: | |
./converter.sh -f obj -s test/ -d export/ | |
EOF | |
say "check the usage" | |
# exit 1 | |
} | |
if [[ "$#" -eq 0 ]]; then | |
echo " | |
This is a program for batch model to a specific format. | |
Contact Yibo Jiang or sent email to yibojiang00@gmail.com if you meet any problems. | |
Before using the shell, you have to install by calling ./converter.sh -i | |
" | |
usage | |
say "Contact Yibo Jiang or sent email to yibojiang00@gmail.com if you meet any problems." | |
exit 1 | |
fi | |
while getopts “ilf:s:d:” OPTION | |
do | |
case $OPTION in | |
i) | |
install_assimp | |
exit 1 | |
;; | |
l) | |
list | |
exit 1 | |
;; | |
f) | |
FORMAT=$OPTARG | |
;; | |
s) | |
SRC=$OPTARG | |
;; | |
d) | |
DEST=$OPTARG | |
;; | |
?) | |
usage | |
exit | |
;; | |
esac | |
done | |
install_assimp | |
if [[ -d ${SRC} ]]; then | |
echo "Reading models from ${SRC}" | |
say "Reading models from ${SRC}" | |
else | |
echo "Invalid src Path ${SRC}" | |
say "Invalid src Path ${SRC}" | |
exit 1 | |
fi | |
if [[ -d ${DEST} ]]; then | |
echo "Exporting models to ${DEST}" | |
say "Exporting models to ${DEST}" | |
else | |
echo "Invalid dest Path ${DEST}" | |
exit 1 | |
fi | |
for f in $SRC/*; | |
do | |
xpath=${f%/*} | |
xbase=${f##*/} | |
xfext=${xbase##*.} | |
xpref=${xbase%.*} | |
# echo;echo path=${xpath};echo pref=${xpref};echo ext=${xfext} | |
echo "export to $DEST/$xpref.$FORMAT " | |
# say "export to $DEST/$xpref.$FORMAT " | |
./assimp export $f $DEST/$xpref.$FORMAT -f$FORMAT | |
# rm $DEST/$xpref.$FORMAT.mtl | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@yibojiang How do I get the file "libassimp.3.3.1 3.dylib"?