@echo off
rem -- by hypob8
rem -- kingpin md2 to mdx all in 1 batch
rem -- will convert every md2 in specified folder into mdx
rem -- copy kpdata.exe and md2tool.exe to a folder of choice
rem -- setup "KPtool" and "KPmdl" below
rem -- kpdate.exe is from the kingpin SDK
rem -- md2tool.exe repair tool is from Jaakko Kerġnen


rem -------------------------------------------
rem -------------------------------------------
rem ------- this is all you need to set -------
rem -------------------------------------------
set KPtool=D:\Kingpin\kprad\tools
set KPmdl=D:\Kingpin\main\players\female_wilma
rem -------------------------------------------
rem ----------- finished with setup -----------
rem -------------------------------------------
rem -------------------------------------------

rem set current working path
pushd %KPmdl%

rem -- set temp file names
set MakeMDXFile=_Make_mdx_.qdt
set JunkFile=_junk.txt

rem -- output files to a txt file
dir "%KPmdl%\*.md2" /L /B > "%KPmdl%\%JunkFile%"

rem -- start writeing ti mdx.qdt file
@echo // File created by Hypov8 batch model converter. File is allways overwritten.> "%KPmdl%\%MakeMDXFile%" 
@echo //>> "%KPmdl%\%MakeMDXFile%" 
@echo // This is an example kpdata script, used to convert a bunch of .md2 files into a single .mdx file.>> "%KPmdl%\%MakeMDXFile%" 
@echo //>> "%KPmdl%\%MakeMDXFile%" 
@echo // A line that starts with // is considered a comment, and ignored by kpdata.>> "%KPmdl%\%MakeMDXFile%" 
@echo //>> "%KPmdl%\%MakeMDXFile%" 
@echo // To create a .mdx file, you first need to create a bunch of .md2 files (standard Quake2 models),>> "%KPmdl%\%MakeMDXFile%" 
@echo //	you would then use kpdata, to create the .mdx file, using the $mdx command.>> "%KPmdl%\%MakeMDXFile%" 
@echo //>> "%KPmdl%\%MakeMDXFile%" 
@echo // The format of the $mdx command is:>> "%KPmdl%\%MakeMDXFile%" 
@echo //>> "%KPmdl%\%MakeMDXFile%" 
@echo //	$mdx (mdx_name) -objects {md2 md2 ..}>> "%KPmdl%\%MakeMDXFile%" 
@echo //>> "%KPmdl%\%MakeMDXFile%" 
@echo // So, for example..>> "%KPmdl%\%MakeMDXFile%" 
@echo //>> "%KPmdl%\%MakeMDXFile%" 
@echo //$mdx bitch_body -objects bitch_rarm bitch_larm bitch_torso bitch_rhand bitch_lhand>> "%KPmdl%\%MakeMDXFile%" 
@echo. >> "%KPmdl%\%MakeMDXFile%" 
@echo. >> "%KPmdl%\%MakeMDXFile%" 


echo.
echo --------------------------------------------
echo ----^|  fix model. add opengl commands  ^|----
echo --------------------------------------------


rem -- loop through file names stored in tmp file
FOR /f "delims=. usebackq tokens=1" %%i IN ("%KPmdl%\%JunkFile%") DO (

	rem -- repair each md2 model for kpdata compatable use(gl commands)
	"%KPtool%\md2tool.exe" -weldtc -renorm -gl "%KPmdl%\%%i.md2"
	
	rem -- copy file names to to mdx.qdt	
	@echo $mdx "%%i" -objects "%%i">> "%KPmdl%\%MakeMDXFile%"
)


@echo. >> "%KPmdl%\%MakeMDXFile%" 
@echo. >> "%KPmdl%\%MakeMDXFile%" 
@echo // Would create a file called bitch_body.mdx in the current directory, composed of the given .md2 files.>> "%KPmdl%\%MakeMDXFile%" 
@echo //>> "%KPmdl%\%MakeMDXFile%" 
@echo // Each .md2 files becomes an object with it's own bounding box, within the .mdx file. Assuming>> "%KPmdl%\%MakeMDXFile%" 
@echo //	the game code is written to use those bounding boxes, you will be able to shoot individual limbs>> "%KPmdl%\%MakeMDXFile%" 
@echo //	on the new character.>> "%KPmdl%\%MakeMDXFile%" 
@echo //>> "%KPmdl%\%MakeMDXFile%" 
@echo // You can create an .mdx made of just a single .md2 file, although it will behave exactly the same as>> "%KPmdl%\%MakeMDXFile%" 
@echo //	the .md2 file. Kingpin supports the .md2 file format also, so doing this would be pointless.>> "%KPmdl%\%MakeMDXFile%" 
@echo //>> "%KPmdl%\%MakeMDXFile%" 
@echo // NOTE: if you intend on using this process to create a PPM (plugin player model) for Kingpin, your>> "%KPmdl%\%MakeMDXFile%" 
@echo //	model MUST consist of the same models that exist in the existing player folders>> "%KPmdl%\%MakeMDXFile%" 
@echo //	(head.mdx, body.mdx, legs.mdx). Also, player models must not contain any skins explicitly listed>> "%KPmdl%\%MakeMDXFile%" 
@echo //	inside the .mdx. Doing so will cause problems within the game.>> "%KPmdl%\%MakeMDXFile%" 



echo.
echo --------------------------------------------
echo ----^|       kingpin md2 to mdx         ^|----
echo --------------------------------------------
echo.

rem -- run the md2 -> mdx converter
%KPtool%\kpdata.exe "%KPmdl%\%MakeMDXFile%"

echo.
echo --------------------------------------------
echo ----^|       mdx batch by hypov8!       ^|----
echo ----^|       conversion complet!!       ^|----
echo --------------------------------------------


pause


rem -- colt animation frames
rem -- raise 0-5
rem -- shoot 6-9
rem -- reload 10-28
rem -- idle 29-44
rem -- drop 45-49

