Heightmap to brick converter?


RE: Heightmap to brick converter?
#11
With many thanks to Roland, here is an example of a complete script to generate a kind of landscape with a "height map" from Excel.
Excel source and LDraw file attached.

Result:

.png   genHeightMap.png (Size: 68.28 KB / Downloads: 134)

Script saved as generate.lua and put in folder C:\Users\[user]\AppData\Roaming\LDCad 1.6b\scripts\default\global



Code:
local genTools=require('genTools')

function heightGen()

 local sf=ldc.subfile()
 if not sf:isLinked() then
   ldc.dialog.runMessage('No active session')
   return
 end
 
 local sel=ldc.selection()
 sel:remove()

 local depthMap={
{1,1,2,2,3,2,2,1,1},
  {1,1,2,3,3,3,2,1,1},
  {2,2,3,4,4,4,3,2,2},
  {2,3,4,4,5,4,4,3,2},
  {3,3,4,5,6,5,4,3,3},
  {2,3,4,4,5,4,4,3,2},
  {2,2,3,4,4,4,3,2,2},
  {1,1,2,3,3,3,2,1,1},
  {1,1,2,2,3,2,2,1,1}
 }

 local colorMap={
{1,1,2,2,3,2,2,1,1},
  {1,1,2,3,3,3,2,1,1},
  {2,2,3,4,4,4,3,2,2},
  {2,3,4,4,5,4,4,3,2},
  {3,3,4,5,6,5,4,3,3},
  {2,3,4,4,5,4,4,3,2},
  {2,2,3,4,4,4,3,2,2},
  {1,1,2,3,3,3,2,1,1},
  {1,1,2,2,3,2,2,1,1}
 }

 local h=genTools.tableArrayCount(depthMap)
 local w=genTools.tableArrayCount(depthMap[1])

 for x=1,w do
   for z=1,h do
     local v=depthMap[z][x]
     local c=colorMap[z][x]

     local v1=v // 3
     local v2=v % 3
   
     local xx=(x-1)*20
     local zz=(z-1)*20
     local yy=0
     
     for b=1,v1  do
       yy=yy-24
       sel:add(sf:addNewRef('3005.dat', c, ldc.matrix(xx, yy, zz)))      
     end
     
     for p=1,v2 do
       yy=yy-8
       sel:add(sf:addNewRef('3024.dat', c, ldc.matrix(xx, yy, zz)))
     end
     
   end
 end
end

function register()

  local macro=ldc.macro('Gen Heightmap')
  macro:setHint('Generate terrain from heightmap')
  macro:setEvent('run', 'heightGen')

end

register()


Attached Files
.ldr   genHeightMap.ldr (Size: 5.5 KB / Downloads: 3)
.xlsx   genHeightMap.xlsx (Size: 9.39 KB / Downloads: 4)
Jaco van der Molen
lpub.binarybricks.nl
Reply
« Next Oldest | Next Newest »



Messages In This Thread
RE: Heightmap to brick converter? - by Jaco van der Molen - 2018-06-19, 13:28

Forum Jump:


Users browsing this thread: 1 Guest(s)