A VT creation tool for the GIMP
Posted: 23.02.2004, 16:36
If you want to make your own VT, the best solution is ImageMagick and Fridger's Virtualtex script.
It is fast (especially for such an intensive job), simple and reliable.
Unfortunately, it needs a Unix-kind of environment to work.
If you do not want to mess with Cygwin, console commands, etc. and the GIMP is installed in your system, you can use the script below:
If you create more than a level in the same session (ie. without closing the GIMP) some of the above parameters will remain in memory, so you will only need to enter the tile level desired.
Remember that GIMP in not the best tool to do this kind of job. This script is only implemented as a resource for certain particular cases, so if GIMP can't manage some really huge textures, you will need to learn a tiny bit of Unix environments and run ImageMagick and Virtualtex.
Please post bugs, improvement ideas, etc. here, in this thread.
Hope this helps. I know this time at least Ziggy will use it
Bye
Edit: ordered the post
It is fast (especially for such an intensive job), simple and reliable.
Unfortunately, it needs a Unix-kind of environment to work.
If you do not want to mess with Cygwin, console commands, etc. and the GIMP is installed in your system, you can use the script below:
Code: Select all
(define (script-fu-map-create-vt inImageFile inPath inLevel inBaseTileSize inFirstX inFirstY inOrigLevel inHemisphere inSaveFormat)
(set! inPath (string-append inPath "/level" (number->string (+ inLevel inOrigLevel))))
(set! theImage (car (gimp-file-load 1 inImageFile inImageFile)))
(gimp-image-undo-disable theImage)
(set! theDrawable (car (gimp-image-active-drawable theImage)))
(set! theImageWidth (car (gimp-drawable-width theDrawable)))
(set! theImageHeight (car (gimp-drawable-height theDrawable)))
(set! theAspectRatio (/ theImageWidth theImageHeight))
(set! theImageType (car (gimp-image-base-type theImage)))
(set! theMultiplier (pow 2 inLevel))
(set! theNewWidth (* (* inBaseTileSize theMultiplier) theAspectRatio))
(set! theNewHeight (* inBaseTileSize theMultiplier))
(if (= inHemisphere 1)
(set! inFirstX 1)
); if
(set! inFirstX (* inFirstX theMultiplier))
(set! inFirstY (* inFirstY theMultiplier))
(if (<= theNewWidth theImageWidth) ;avoids oversampling
(begin
(if (< theNewWidth theImageWidth) (gimp-image-scale theImage theNewWidth theNewHeight))
(set! j 0)
(set! theInitPosY 0)
(while (<= (+ theInitPosY inBaseTileSize) theNewHeight)
(set! i 0)
(set! theInitPosX 0)
(while (<= (+ theInitPosX inBaseTileSize) theNewWidth)
(gimp-rect-select theImage theInitPosX theInitPosY inBaseTileSize inBaseTileSize 2 FALSE 0)
(gimp-edit-copy theDrawable)
(set! theImage2 (car (gimp-image-new inBaseTileSize inBaseTileSize theImageType)))
(set! theLayer (car (gimp-layer-new theImage2 inBaseTileSize inBaseTileSize theImageType "layer1" 100 0)))
(set! theFloat (car (gimp-edit-paste theLayer 0)))
(gimp-floating-sel-anchor theFloat)
(set! theTileName (string-append "tx_" (number->string (+ i inFirstX)) "_" (number->string (+ j inFirstY))))
;ugly workaround to avoid gimp-file-save internal bug:
(cond
((= inSaveFormat 0)
(set! theFileName (string-append inPath "/" theTileName ".tga"))
(file-tga-save 1 theImage2 theLayer theFileName theFileName 0 0))
((= inSaveFormat 1)
(set! theFileName (string-append inPath "/" theTileName ".jpg"))
(file-jpeg-save 1 theImage2 theLayer theFileName theFileName 0.75 0 0 0 "" 0 0 0 0))
((= inSaveFormat 2)
(set! theFileName (string-append inPath "/" theTileName ".png"))
(file-png-save 1 theImage2 theLayer theFileName theFileName 0 0 0 0 0 0 0))
) ;cond
(gimp-image-delete theImage2)
(set! i (+ i 1))
(set! theInitPosX (* inBaseTileSize i))
) ;inner while
(set! j (+ j 1))
(set! theInitPosY (* inBaseTileSize j))
) ;outer while
(gimp-message (string-append "Level " (number->string inLevel) " succesfully completed"))
) ;begin;
(begin
;this should be an 'if' but this way is shorter to write:
(cond
((> inBaseTileSize theImageWidth ) (gimp-message "'Size of each tile' parameter too high for your texture"))
((<= inBaseTileSize theImageWidth ) (gimp-message "'Level to split...' parameter too high for your texture"))
) ;cond
) ;begin
) ;if
(gimp-selection-none theImage)
(gimp-image-clean-all theImage)
(gimp-image-undo-enable theImage)
(gimp-image-delete theImage)
)
(script-fu-register
"script-fu-map-create-vt"
_"<Toolbox>/Xtns/Script-Fu/Celestia Scripts/Map Create VT"
"creates a specified level of Celestia VT from a source image"
"Toti. Based on Dr. Fridger Schrempp's Virtualtex functionality"
"2004"
"March 2 2004"
"RGB* GRAY* INDEXED*"
SF-FILENAME _"Image file" ""
SF-FILENAME _"Path to save tiles into" ""
SF-VALUE _"Level to split texture into" "0"
SF-VALUE _"Size of each tile (powers of two)" "1024"
SF-VALUE _"First X" "0"
SF-VALUE _"First Y" "0"
SF-VALUE _"Original tile level" "0"
SF-OPTION _"Working Hemisphere" '(_"Whole map/West" _"East")
SF-OPTION _"Format for saved tiles" '(_"tga" _"jpg" _"png")
)
- 1)Copy and paste it in your text editor. Then save it as any_name.scm in any of your GIMP <scripts> folders.
2)Create your VT folder. Example:
- celestia\textures\hires\earth\level0
celestia\textures\hires\earth\level1
celestia\textures\hires\earth\level2
...
3)Run the Gimp
4)For each tile level that you want to produce do the following:
- a)Go to Xtns -> Script-Fu -> Celestia Scripts -> Map Create VT
b)In the window that appears, enter:
- * the source image file.
* the base directory where your produced tiles will be saved. In the above example celestia\textures\hires\earth. Important: check that the directory displayed in this field really is the one you selected.
* the tile level that you want to produce.
* the tile size that you have chosen for your VT (must be a power of 2)
* The original tile offset X index, if you want to create ultra high resolution tiles from/inside individual existing tiles; otherwise leave it as 0.
* Same for the original tile offset Y index
* Same for the original tile level
* The hemisphere that corresponds with your original image, If you downloaded it already splitted in two hemispheres (west and east). If not, leave it as it is.
* the graphic format that you want the tiles to be in (loseless tga is recommended if you plan to convert them to DXT format)
d)When finished, a message will appear. Your tiles will be saved in the corresponding directory structure.
If you create more than a level in the same session (ie. without closing the GIMP) some of the above parameters will remain in memory, so you will only need to enter the tile level desired.
Remember that GIMP in not the best tool to do this kind of job. This script is only implemented as a resource for certain particular cases, so if GIMP can't manage some really huge textures, you will need to learn a tiny bit of Unix environments and run ImageMagick and Virtualtex.
Please post bugs, improvement ideas, etc. here, in this thread.
Hope this helps. I know this time at least Ziggy will use it
Bye
Edit: ordered the post