L3DT users' wiki
Large 3D terrain generator

Scripts > AM_ConvertToBYTE

Description Generates an 8-bit representation of the attributes map and saves it as a bitmap or RAW file.
Author Aaron.
Created 2012/09/12 07:28
Requires L3DT v12.09 (specifically, ZeoWrap 12.09)
Download AM_ConvertToByte.zs

About

Please see this forum thread for more information.

This script is really slow.

Script contents

// Author:  A. Torpy
// Written: 13 Sept 2012

hvar hAM
set hAM <project.GetMap "AM">
int nx ny
set nx <map.GetWidth hAM>
set ny <map.GetHeight hAM>

assert <iseq 40 <map.GetMapType hAM>> "Attributes map is not initialised!"

// ask user for output filename
filesel fs
filesel.Init &fs false NULL "Bitmap image (*.bmp)|*.bmp|8-bit RAW file (*.raw)|*.raw|" "bmp" NULL
if <not <EditUI &fs "Select output file">>
  return -1
endif
string FileName
set FileName <filesel.GetPathA &fs>

// create an output map
map TempMap
assert <map.Init &TempMap nx ny 1 1 false> "Cannot initialise temp map!"


int i j
set i 0
set j 0

buffer buf
buffer.InitByType &buf 256 ushort

ushort us
byte b

progbox pb
progbox.SetTitle &pb "Converting attributes map to 8-bit"
progbox.ShowWnd &pb

int64 p pmax
set p 0
set pmax <mul <cast int64 nx> ny>

do
  set i 0
  do

    progbox.SetProgress &pb <incr p> pmax    

    map.GetPixel hAM i j &us

    set b <div us 255>

    map.SetPixel &TempMap i j &b

    buffer.SetValue &buf b us

  while <islt <incr i> nx>
while <islt <incr j> ny>

assert <map.SaveFile2 &TempMap FileName false true> "Error saving file!"

// now compile palette list
voidptr fp
set fp <fopen <strcat <file.TrimExt FileName> " palette.txt"> "w">
assert fp "Cannot create palette file!"

int k
string s
do
  set us 0 
  buffer.GetValue &buf k us  
  if <isgt us 0>
    set s <strcat k <strcat ": " <strcat <landtype.GetTypeNameByID us> "\n">>>
    fwrite fp s
  endif
while <islt <incr k> 256>

fclose fp

MessageBox "File saved OK" 0x40

return 0
 
scripts/convert_am_to_byte.txt · Last modified: 2017/08/31 05:25 (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