forked from id-tech-3-tools/map-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbsp-to-obj.bat
More file actions
151 lines (125 loc) · 4.35 KB
/
Copy pathbsp-to-obj.bat
File metadata and controls
151 lines (125 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
@echo off
set parent=%~dp0
cd %parent%
:: ================== SETTINGS ==================
:: You can pre set BSPName, but it's not required.
:: You can pass in filename using command line, type help for usage examples.
:: The bsp file will be searched in the script(this one) and in the maps directories.
:: You can set this if you want to launch the script by double click.
set BSPName=
:: !IMPORTANT! set Q3MAP path here
set Q3MapPath=
:: !IMPORTANT! set game directory path here
set GameDirectory=
:: !IMPORTANT! correct game name here
:: For instance: q3, et, rtcw; should match the q3map2 -game argument
set GameName=q3
:: No further edits required
:: =================== END ======================
:: Type help to get usage information
if /I "%1" == "help" goto printHelp
if /I "%1" == "-help" goto printHelp
if /I "%1" == "" (
if "%BSPName%" == "" goto printHelp
)
:: Validate vars
if "%Q3MapPath%" == "" (
call :printMissingQ3MapPath
goto atExit
)
if "%GameDirectory%" == "" (
call :printMissingGameDirectoryPath
goto atExit
)
set BaseDirectoryName=baseq3
call :setBaseDirectoryName
set BasePath=%GameDirectory%/%BaseDirectoryName%
:: Find the right map/bsp file
set MapsDirectory=%BasePath%/maps/
if "%~1" == "" (
set MapName=%BSPName%
) else (
set MapName=%~1
)
set MapPath=""
call :findCorrectMapPath
if %MapPath% == "" (
call :printMapFileNotFound
goto atExit
)
:: Generate output path
if "%~2" == "" (
set OutputDirectory=%parent%
) else (
set OutputDirectory=%~f2\
)
call :getFileBaseName %MapName%
set OutputName=%baseName%.obj
set OutputPath=%OutputDirectory%%OutputName%
if not exist "%OutputDirectory%" mkdir "%OutputDirectory%"
:: Additional switches
set ExtraSwitches=-meta -patchmeta
:: Compose compiler argument string, excluding mapname
set CompilerArguments=-convert -game %GameName% -fs_basepath "%GameDirectory%" -v -format obj %ExtraSwitches%
:: Print info
echo. & echo.[Settings]
echo Q3MAP: %Q3MapPath%
echo GAME NAME: %GameName%
echo GAME DIRECTORY: %GameDirectory%
echo BASE DIRECTORY: %BaseDirectoryName%
echo MAP PATH: %MapPath%
echo EXTRA SWITCHES: %ExtraSwitches%
echo COMPILER ARGUMENTS: %CompilerArguments%
:: Do work
echo. & echo [Convert BSP to OBJ]
%Q3MapPath% %CompilerArguments% -outfile "%OutputPath%" "%MapPath%"
:atExit
echo. & pause
exit 0
:printHelp
echo Basic usage:
echo bsp-to-obj.bat mapname [output relative path]
echo bsp-to-obj.bat castle.bsp
echo bsp-to-obj.bat castle.bsp models/castle
goto atExit
:printMissingQ3MapPath
echo Error: please set Q3Map2 path by editing this file (find Q3MapPath variable)!
exit /B 0
:printMissingGameDirectoryPath
echo Error: Please set game directory path by editing this file (find GameDirectory variable)!
exit /B 0
:printMapFileNotFound
echo Error: %MapName% was not found!
exit /B 0
:setBaseDirectoryName
if "%GameName%" == "q3" set BaseDirectoryName=baseq3
if "%GameName%" == "et" set BaseDirectoryName=etmain
if "%GameName%" == "wolf" set BaseDirectoryName=main
if "%GameName%" == "darkplaces" set BaseDirectoryName=id1
if "%GameName%" == "dq" set BaseDirectoryName=basedq
if "%GameName%" == "ef" set BaseDirectoryName=basee
if "%GameName%" == "etut" set BaseDirectoryName=etut
if "%GameName%" == "ja" set BaseDirectoryName=base
if "%GameName%" == "jk2" set BaseDirectoryName=base
if "%GameName%" == "nexuiz" set BaseDirectoryName=data
if "%GameName%" == "prophecy" set BaseDirectoryName=base
if "%GameName%" == "qfusion" set BaseDirectoryName=base
if "%GameName%" == "quakelive" set BaseDirectoryName=baseq3
if "%GameName%" == "reaction" set BaseDirectoryName=Boomstick
if "%GameName%" == "sof2" set BaseDirectoryName=base
if "%GameName%" == "tenebrae" set BaseDirectoryName=base
if "%GameName%" == "tremulous" set BaseDirectoryName=base
if "%GameName%" == "unvanquished" set BaseDirectoryName=pkg
if "%GameName%" == "xonotic" set BaseDirectoryName=data
exit /B 0
:: search map in cwd
:: search map in game directory
:findCorrectMapPath
if exist "%MapName%" (
set MapPath=%parent%%MapName%
) else (
if exist "%MapsDirectory%%MapName%" set MapPath=%MapsDirectory%%MapName%
)
exit /B 0
:getFileBaseName
set baseName=%~n1