L3DT users' wiki
Large 3D terrain generator

Scripts > Import OpenSim RAW file

Description Import a heightmap from a 13-channel RAW file from OpenSim / Second Life.
Author aaron@bundysoft.com
Created 2013/05/24
Requires L3DT v11.11
Download import opensim raw file.zs
Forum thread http://www.bundysoft.com/phpBB2/viewtopic.php?f=4&t=2718

Script contents

//
//  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
 
scripts/import_opensim_raw_file.txt · Last modified: 2017/08/31 05:09 (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