Skip to content

Instantly share code, notes, and snippets.

@Anerag

Anerag/mtlc.sh Secret

Last active June 7, 2020 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Anerag/dccef061d24c606dce1f6c07002f0c85 to your computer and use it in GitHub Desktop.
Save Anerag/dccef061d24c606dce1f6c07002f0c85 to your computer and use it in GitHub Desktop.
MM material converter
#!/usr/bin/env bash
# mtlc.sh - convert materials
#
# Copyright 2020 Riku Salminen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
SUFFIX="_fixed"
if [ -z "$1" ]; then
echo "usage: mtlc.sh [FILE]"
exit 1
fi
NEWFILE="${1%.*}$SUFFIX.${1##*.}"
if [ -f "$NEWFILE" ]; then
echo "warning: overwriting existing file: $NEWFILE"
> "$NEWFILE"
fi
while IFS= read -r line; do
echo "$line" >> "$NEWFILE"
if [ "$line" == "newmtl __TB_empty" ]; then
continue
fi
echo "map_Kd ${line##*/}" >> "$NEWFILE"
done < "$1"
echo "wrote new file to: $NEWFILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment