L3DT users' wiki
Large 3D terrain generator

Scripts > ExportHeightfieldAsTiles

Description Exports the heightfield as a set of HF2 tile files. This script has better memory management for very large tile sizes (>4096) than the usual mosaic export option.
Author Aaron
Created 2010/02/03
Requires L3DT v2.8 build 7 or later.
Download ExportHeightfieldAsTiles.zs

Script contents

hvar hMap
set hMap <GetMap "HF">

int nx ny
set nx <map.GetWidth hMap>
set ny <map.GetHeight hMap>

assert nx "Map not initialised!"

string FileName
set FileName <file.SaveDlg "hf2" NULL "HF2 files (*.hf2)|*.hf2|All files (*.*)|*.*|">
if <not <strlen FileName>>
  return false
endif

string BaseFileName
set BaseFileName <file.GetFilenameNoExt FileName>
string FileExt
set FileExt <file.GetExt FileName>

hvar hFormat
set hFormat <GetFormat "HF" 0 FileExt>
assert hFormat "Cannot find format!"


int TileSize
set TileSize 512
if <not <EditUI &TileSize "Enter tile size">>
  return false
endif
assert <isgt TileSize 1> "Invalid tile size!"

int nTilesX
set nTilesX <div nx TileSize>
if <mod nx TileSize>
  incr nTilesX
endif
int nTilesY
set nTilesY <div ny TileSize>
if <mod ny TileSize>
  incr nTilesY
endif

int ti tj
set tj 0
do
  set ti 0
  do 

    int x1 x2 y1 y2
    set x1 <mul ti TileSize>
    set y1 <mul tj TileSize>
    set x2 <add x1 <sub TileSize 1>>
    set y2 <add y1 <sub TileSize 1>>
    if <not <islt x2 nx>>
      set x2 <sub nx 1>
    endif
    if <not <islt y2 ny>>
      set y2 <sub ny 1>
    endif

    string TileName
    set TileName <strcat BaseFileName <strcat "_x" ti>>
    set TileName <strcat TileName <strcat "_y" tj>>
    set TileName <strcat TileName <strcat "." FileExt>>

    assert <file.export.areaH hMap TileName hFormat x1 x2 y1 y2> "Export failed!"

  while <islt <incr ti> nTilesX>
while <islt <incr tj> nTilesY>

return true

Comments

None.

 
scripts/exportheightfieldastiles.txt · Last modified: 2017/08/31 05:16 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki