Windows installation script to make and install VTs

Tips for creating and manipulating planet textures for Celestia.
Avatar
Topic author
jogad
Posts: 458
Joined: 17.09.2008
With us: 16 years 2 months
Location: Paris France

Windows installation script to make and install VTs

Post #1by jogad » 29.05.2009, 15:29

Hello,

With the Moon textures here and there, virtual textures appear to be a hot topic.
For the poor Windows user (me), I try to make a batch file (windows script) that allows the user to create and distribute their virtual textures (VT) without too much trouble.
Of course the batch relies on the F-TexTools that must be installed before using it.

I Know that other batch file have been created before that. But they may be difficult to adapt without a complete rewriting.
I Just want to have only one file which is versatile and do the job completely for the texture designer and the end user.

The features I want are:

It is possible to create the VT from a PNG file or a BIN file.
The batch creates automatically an add-on in the proper directory of celestia. It may be an alternate Surface or an add-on to change the default texture of celestia. It is also possible to create only a virtual texture in the celestia\textures\hires folder.

To create the VT it is only necessary to edit the batch parameters a little bit.
In this first attempt, only the six first parameters are crucial.
Just put your file texture in the same folder than the batch file, double-click on the bacht, wait until the process finishes... and you are prompted to lauch (or not) Celestia to see the result.

To distribute a texture, send it together with the batch AND a readme file.
The end user has only to read the readme file that tells him how to load and install the F-TexTools before double-clicking on the batch installation file.

Code: Select all

@echo off
rem      Virtual Textures CREATION
rem !------------------------------------!
rem ! attention not to add extra spaces  !
rem !at the end of the lines nor after = !
rem !------------------------------------!
rem !  REQUIRED PARAMAMETERS     !
rem ! no extension for imageName !
rem !----------------------------!
SET imageName=Clementine64k
SET width=65536
SET channels=1
SET name=Clementine 64k gray
SET body=Moon
SET bodyPath=Sol/Earth

rem DEFAULT PARAMETERS modify at your risks
rem ---------------------------------------
SET tileSize=1024
SET tileType=dds
SET fastMode=0
SET addonType=AltSurface
SET AddonDir=%name%
SET popupName=%name%
SET deleteBinFiles=yes
SET celestiaPath=%ProgramFiles%\celestia
SET celestia=celestia.exe
rem ====================================

Title VT creation: %name%
FOR /F %%i in ( "txtiles.exe" ) do SET txtiles=%%~$PATH:i
if NOT exist "%txtiles%" GOTO errFTools
SET start=%TIME%
SET ICI=%CD%

if not "%tileType%"=="png" SET tileType=dds

rem calculate max level
SET /a sz=tileSize*2
SET level=0
:calcLevel
if %sz%==%width% goto endCalc
if %sz% GTR %width% goto errSize
SET /a sz*=2
SET /a level+=1
goto calcLevel
:endCalc

REM verif image file and create binary if necessary
SET binary=%imageName%.bin
if exist "%binary%" goto endVerifFile
if NOT exist "%imageName%.png" goto errImFile
png2bin < "%imageName%.png" > "%binary%"
:endVerifFile

REM Style of addon
if "%addonType%"=="AltSurface" goto endStyleAd
if "%addonType%"=="Modify" goto endStyleAd
Rem simple VT structure in celestia\textures\hires
cd /D "%celestiaPath%\textures\hires"
goto makeCTX
:endStyleAd

REM create addon dir
md "%celestiaPath%\extras\%AddonDir%"
cd /D "%celestiaPath%\extras\%AddonDir%"

REM make ssc file
if %addonType%==AltSurface echo AltSurface "%popupName%" "%bodyPath%/%body%" > "%name%.ssc"
if %addonType%==Modify echo Modify "%body%" "%bodyPath%" > "%name%.ssc"
echo { >> "%name%.ssc"
echo    Texture "%name%.ctx" >> "%name%.ssc"
echo } >> "%name%.ssc"

REM make directories and ctx file
md textures\hires
cd textures\hires

:makeCTX
SET /a tileSize/=2
echo VirtualTexture > "%name%.ctx"
echo { >> "%name%.ctx"
echo         ImageDirectory "%name%_VT" >> "%name%.ctx"
echo         BaseSplit 0 >> "%name%.ctx"
echo         TileSize %tileSize% >> "%name%.ctx"
echo         TileType "%tileType%" >> "%name%.ctx"
echo } >> "%name%.ctx"

REM actual VT creation
SET txtiles=txtiles.exe
if %tileType%==dds SET txtiles=txtilesDXT.exe
if exist "%name%_VT" rmdir /S /Q "%name%_VT"
md "%name%_VT"
cd "%name%_VT"
goto makeLevel

:nextLevel
SET /A level-=1
SET /A half=width/2
tx2half %channels% %width% < "%ICI%\%binary%" > "%ICI%\%half%.bin"
if /I %deleteBinFiles%==yes del "%ICI%\%binary%"
SET width=%half%
SET binary=%half%.bin

:makeLevel
md level%level%
cd level%level%
SET paramtxtiles=%channels% %width% %level%
if %tileType%==dds SET paramtxtiles=%paramtxtiles% %fastMode%
%txtiles% %paramtxtiles%  < "%ICI%\%binary%"
cd ..
if NOT %level%==0 goto nextLevel

if /I %deleteBinFiles%==yes del "%ICI%\%binary%"
goto fin

REM ======= error messages ==========
:errFTools
echo.
echo the F-TexTools must be installed
echo Please see the readme.txt file
goto endErr

:errSize
echo.
echo width and tileSise must be powers of 2
echo and width must be greater or equal to 2 x tileSize
goto endErr

:errImFile
echo.
Echo did not find %imageName%.bin nor %imageName%.png
echo in the directory of:
echo %0

:endErr
pause
goto EOF

:fin
echo.
echo --------------------
echo  Start: %start%
echo  End  : %TIME%
echo --------------------
SET /P lc=Launch Celestia? (Y/N)_
cd /D "%celestiaPath%"
if /I %lc%==Y start %celestia%


I have not tested intensively. I think there are no big errors but I am not that sure.
If you find errors, tell me.
if you have ideas to improve it, tell me.
And if I am reinventing the wheel, stop me. Anyways I learnt something about DOS scripting.

Avatar
t00fri
Developer
Posts: 8772
Joined: 29.03.2002
Age: 22
With us: 22 years 7 months
Location: Hamburg, Germany

Re: Windows installation script to make and install VTs

Post #2by t00fri » 29.05.2009, 19:22

That's good and long due ;-) Thanks for contributing the script!

Fridger
Image


Return to “Textures”