This Bash script automates the conversion of Quake 3 map files (.bsp,.map) into other formats using tools such as quake3e_q3map2 and Blender. The script searches for files with specified extensions, checks for file existence and size, and performs conversions and recompilations as necessary.
#bash
for i in $(find . -iname '*.bsp' -o -iname '*.map'); do
if [[ ! "$i" =~ concepts/ ]]; then
if [[ ! "$i" =~ autosave/ ]]; then
if [[ ! "$i" =~ quarantine/ ]]; then
if [ ! -f "${i%.*}.map" ]; then
if [ -f "${i%.*}_converted.map" ]; then
mv "${i%.*}_converted.map" "${i%.*}.map";
fi;
fi;
if [ ! -f "${i%.*}.map" ]; then
if [ -f "${i%.*}.bsp" ]; then
~/Quake3e/build/release-darwin-arm/quake3e_q3map2 -convert -format map -keeplights -game quake3 -fs_basepath /Users/briancullinan/planet_quake_data -fs_game quake3-baseq3 "${i%.*}.bsp";
mv "${i%.*}_converted.map" "${i%.*}.map";
fi;
fi;
# comment out this line and third fi; to replace existing bsps?
if [ ! -f "${i%.*}.bsp" ]; then
if [ -f "${i%.*}.map" ]; then
if [ $(wc -c <"${i%.*}.map") -le 100000 ]; then
~/Quake3e/build/release-darwin-arm/quake3e_q3map2 -meta -keeplights -game quake3 -fs_basepath /Users/briancullinan/planet_quake_data -fs_game quake3-baseq3 "${i%.*}.map";
~/Quake3e/build/release-darwin-arm/quake3e_q3map2 -light -fast -game quake3 -fs_basepath /Users/briancullinan/planet_quake_data -fs_game quake3-baseq3 "${i%.*}.bsp";
fi;
fi;
fi;
# if [ -f "${i%.*}.bsp" ]; then
# if [ $(wc -c <"${i%.*}.bsp") -le 900000 ]; then
# /Applications/Blender.app/Contents/MacOS/Blender --python ../model-convert.py -- "${i%.*}.bsp";
# fi;
# fi;
# if it still doesn't exist
# if [ ! -f "${i%.*}.md3" ]; then
# if [ ! -f "${i%.*}-half.md3" ]; then
# if [ -f "${i%.*}.map" ]; then
# if [ $(wc -c <"${i%.*}.map") -le 900000 ]; then
# /Applications/Blender.app/Contents/MacOS/Blender --python ../model-convert.py -- "${i%.*}.map";
# fi;
# fi;
# fi;
# fi;
fi;
fi;
fi;
done;
#!/bin/bash
# Define constants
QUAKE3E_BUILD_PATH="~/Quake3e/build/release-darwin-arm/"
QUAKE3E_Q3MAP2="quake3e_q3map2"
GAME_NAME="quake3"
BASE_PATH="/Users/briancullinan/planet_quake_data"
GAME_BASE="quake3-baseq3"
# Functions to convert.bsp to.map and vice versa
convert_bsp_to_map() {
local bsp_file=$1
local map_file="${bsp_file%.bsp}.map"
if [ -f "$map_file" ]; then
if [! -s "$map_file" ]; then
$QUAKE3E_BUILD_PATH$QUAKE3E_Q3MAP2 -convert -format map -keeplights -game $GAME_NAME -fs_basepath $BASE_PATH -fs_game $GAME_BASE "$bsp_file"
mv "${bsp_file%.bsp}_converted.map" "$map_file"
fi
fi
}
convert_map_to_bsp() {
local map_file=$1
local bsp_file="${map_file%.map}.bsp"
if [! -f "$bsp_file" ]; then
$QUAKE3E_BUILD_PATH$QUAKE3E_Q3MAP2 -convert -format bsp -keeplights -game $GAME_NAME -fs_basepath $BASE_PATH -fs_game $GAME_BASE "$map_file"
mv "${map_file%.map}_converted.bsp" "$bsp_file"
fi
}
# Find all.bsp and.map files in the current directory
for file in $(find. -iname '*.bsp' -o -iname '*.map'); do
# Check if the file is not in the concepts, autosave or quarantine directories
if [[! "$file" =~ concepts/ ]] && [[! "$file" =~ autosave/ ]] && [[! "$file" =~ quarantine/ ]]; then
# Check if the.map file exists for the.bsp file
if [! -f "${file%.bsp}.map" ]; then
# Check if the.map file was previously converted
if [ -f "${file%.bsp}_converted.map" ]; then
mv "${file%.bsp}_converted.map" "${file%.bsp}.map"
fi
# If not, convert the.bsp file to.map
convert_bsp_to_map "$file"
fi
# Check if the.bsp file exists for the.map file
if [! -f "${file%.map}.bsp" ]; then
# If not, convert the.map file to.bsp
convert_map_to_bsp "$file"
fi
# Check if the.map file is smaller than 100,000 bytes
if [ -f "$file" ] && [ $(wc -c <"$file") -le 100000 ]; then
# If so, re-convert the.map file to.bsp and vice versa
convert_map_to_bsp "$file"
convert_bsp_to_map "$file"
fi
fi
doneThis is a Bash script that automates the conversion of Quake 3 map files (.bsp, .map) into other formats. It uses the find command to search for files with the specified extensions and then performs operations on each found file.
.bsp and .map in the current directory and its subdirectories using the find command.concepts/, autosave/, or quarantine/ directories..bsp file and a corresponding .map file does not exist, it converts the .bsp file into a .map file using the quake3e_q3map2 tool..map file and its size is less than or equal to 100000 bytes, it appends metadata to the file and recompiles the .bsp file using the quake3e_q3map2 tool..bsp file and its size is less than or equal to 900000 bytes, it attempts to convert the file into an MD3 model using the Blender tool (commented out in the script).find command to search for files with the specified extensionsquake3e_q3map2 tool to convert .bsp files into .map files and to recompile .map files with metadatawc -c command to get the size of a file in bytesBlender tool to convert .bsp or .map files into an MD3 model (commented out in the script)The script uses the following file naming conventions:
.bsp files are the original map files.map files are the converted map files.md3 files are the converted MD3 models*_converted.map files are the intermediate files created during the conversion process