//
// Title | Import OpenSim RAW.zs
// About | A script to import 13 channel 8-bit OpenSim / Second Life RAW files
// Author | Aaron Torpy (aaron@bundysoft.com)
// Date | 24 May 2013
//
filesel fs
filesel.Init &fs true NULL "OpenSim/SL RAW files (*.raw)|*.raw|" "raw" NULL
if <not <EditUI &fs "Select file">>
return -1
endif
string FileName
set FileName <filesel.GetPathA &fs>
if <project.IsInit>
project.FreeProject
endif
assert <project.InitProject> "Cannot initialise project"
voidptr fp
if <not <fopen_s fp FileName "rb">>
return -1
endif
int nx ny
set nx 256
set ny 256
hvar pHF
set pHF <project.GetMap "HF">
assert <map.Init pHF nx ny 20 1.0 false> "Cannot initialise heightfield"
float SeaLevel
set SeaLevel 0
progbox prog
progbox.SetTitle &prog "Importing RAW file (slowly)"
progbox.ShowWnd &prog
int i j
set j 0
do
set i 0
do
byte b1 b2 b3
assert <fread fp b1> "Cannot read file"
assert <fread fp b2> "Cannot read file"
assert <fread fp b3> "Cannot read file"
fseek fp 10 1 // skip over next 10 bytes
if <and <iseq i 0> <iseq j 0> >
set SeaLevel <cast float b3>
endif
float height
set height <sub <div <mul <cast float b1> b2> 128.0> SeaLevel>
assert <map.SetPixel pHF i j &height> "Cannot set pixel"
while <islt <incr i> nx>
progbox.SetProgress &prog j ny
while <islt <incr j> ny>
fclose fp
map.SetFlag pHF 1 true // MAPFLAG_READY
view.ShowMap "HF"
return 0