1337ad / sketchrip

Ripper and Conversion for Sketchfab Models
70 stars 15 forks source link

Linux obj to glb merger #5

Open SidYa opened 1 year ago

SidYa commented 1 year ago

In order to use the merge of multiple obj files into a single gltf on linux, you can use the following script:

!/bin/bash

merge_files() { echo "Merging OBJ files into GLTF..." obj_files=(*.obj) if [ ${#obj_files[@]} -eq 0 ]; then echo "No OBJ files found in the current directory." exit 1 fi

merged_file="merged.gltf"
obj2gltf -i "${obj_files[@]}" -o "$merged_file"

if [ $? -eq 0 ]; then
    echo "Merging successful. Merged file: $merged_file"
else
    echo "Error occurred while merging OBJ files."
    exit 1
fi

}

optimize_file() { echo "Optimizing the merged GLTF file..." optimized_file="optimized.gltf" gltf-pipeline -i merged.gltf -o "$optimized_file"

if [ $? -eq 0 ]; then
    echo "Optimization successful. Optimized file: $optimized_file"
else
    echo "Error occurred while optimizing the GLTF file."
    exit 1
fi

}

merge_files optimize_file


But first install:
sudo npm install -g obj2gltf
sudo npm install -g gltf-pipeline