L3DT users' wiki
Large 3D terrain generator

 

This is an old revision of the document!


Scripts > HF_clip

Description A script to clip heightifled pixels that are above or below a certain elevation, and set them to another given elevation.
Author Aaron
Created 2017/08/17
Requires L3DT v15+
Download hf_clip.zs

Script contents

//
//   Title | HF_clip
// Purpose | A script to force heightfield pixels above or below a certain level
//         | to be set to another level
//  Author | Aaron Torpy
//    Date | 17 Aug 2017


hvar hHF
set hHF <GetMap "HF">
assert <not <iseq hHF NULL>> "Error: Cannot get heightfield"
assert <map.GetWidth hHF> "Error: Heightfield is not initialised"

// ask for clipping mode
combosel CS
combosel.Init &CS "Clip above|Clip below" "Clip above" 0
if <not <EditUI &CS "Select clipping mode">>
  return -1
endif

// check clipping mode, and ask for clipping altitudes
float ClipThreshold
float ClipTarget
set ClipThreshold 0
set ClipTarget 0
int ClipMode
set ClipMode 0

string CurSel
set CurSel <combosel.GetCurSelA &CS>
if <iseq CurSel "Clip above">
  set ClipMode 0
elseif <iseq CurSel "Clip below">
  set ClipMode 1
else
  echo "HF_clip script error:\r\n - unknown clipping mode"
  return -1
endif
//echo <strcat ClipAltMin ClipAltMax> // debugging


if <not <EditUI &ClipThreshold "Set clip threshold height (m)">>
  return -1
endif
set ClipTarget ClipThreshold
if <not <EditUI &ClipTarget "Set clip target height (m)">>
  return -1
endif

// store a backup
if <not <L3DTio_Backup.BackupMap "HF" "Clip height" 0 "view.ShowMap \"HF\"">>
  echo "HF_clip script error:\r\n - cannot store backup point for heightfield"
  //return -1
endif

// clip the design map alt layer
if <iseq ClipMode 0>
  if <not <calc.HF.ClipAbove hHF ClipThreshold ClipTarget true>>
    echo "HF_clip script error:\r\n - cannot clip max altitude layer of heightfield"
    return -1
  endif
endif
// clip the design map alt layer
if <iseq ClipMode 1>
  if <not <calc.HF.ClipBelow hHF ClipThreshold ClipTarget true>>
    echo "HF_clip script error:\r\n - cannot clip min altitude layer of heightfield"
    return -1
  endif
endif
  
// redraw heightfield
view.ShowMap "HF"

MessageBox "Clipping complete!" 0x40
return 0
 
scripts/hf_clip.1502970176.txt.gz · Last modified: 2017/08/31 04:59 (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