2015-08-14, 10:28
Does anyone know of any heightmap to LDraw brick converters? I know MLCad can create fractal terrain, but I could have sworn someone had written a converter at some point. Thanks.
(2015-08-14, 10:28)Michael Horvath Wrote: [ -> ]Does anyone know of any heightmap to LDraw brick converters? I know MLCad can create fractal terrain, but I could have sworn someone had written a converter at some point. Thanks.
(2015-08-15, 5:21)Michael Horvath Wrote: [ -> ]Thanks! But, there seems to be a limit on the "max size" a model can be. Not sure how to get around that.What area (in studs/baseplates) are you talking about?
(2018-06-18, 13:40)Gerald Lasser Wrote: [ -> ](2015-08-15, 5:21)Michael Horvath Wrote: [ -> ]Thanks! But, there seems to be a limit on the "max size" a model can be. Not sure how to get around that.What area (in studs/baseplates) are you talking about?
Do you want to import a greyscale image that represents a height map?
(2018-06-18, 20:14)Jaco van der Molen Wrote: [ -> ]No idea so far how to do that.
Any thoughts.![]()
local depthMap={ {0, 1, 2}, {4, 5, 6}, {7, 8, 9} }
function renDepthGen()
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={
{0, 1, 2},
{4, 5, 6},
{7, 8, 9}
}
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 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', 4, ldc.matrix(xx, yy, zz)))
end
for p=1,v2 do
yy=yy-8
sel:add(sf:addNewRef('3024.dat', 4, ldc.matrix(xx, yy, zz)))
end
end
end
end
(2018-06-18, 20:56)NRoland Melkert Wrote: [ -> ](2018-06-18, 20:14)Jaco van der Molen Wrote: [ -> ]No idea so far how to do that.
Any thoughts.![]()
If you can somehow generate a lua variable definition with excel.
Then you can do the actual generating of the model in LDCad using a macro. All you would need is the x/z values in an array.
For an 3x3 grid you would need something like this:
Code:local depthMap={ {0, 1, 2}, {4, 5, 6}, {7, 8, 9} }
You use that in a macro run event like so:
Code:function renDepthGen()
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={
{0, 1, 2},
{4, 5, 6},
{7, 8, 9}
}
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 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', 4, ldc.matrix(xx, yy, zz)))
end
for p=1,v2 do
yy=yy-8
sel:add(sf:addNewRef('3024.dat', 4, ldc.matrix(xx, yy, zz)))
end
end
end
end
Which would give you:
(2018-06-18, 21:10)Jaco van der Molen Wrote: [ -> ]Ah! Ok, I see. That is exactly what I meant!You could choose between green and blue (instead of the constant red) depending on the height of 'yy' to mimic above/below sea level. Or do you want the whole column to vary in color depending on an excel variable?
My excel source can make the depth map, I understand how it works.
For a 16 by 16 baseplate you have 16 arrays with each 16 values.
Now if you can incorporate the color of the column too, I am there.
genTools.IF(yy<seaLevel, 2, 1)
local seaLevel=-24
local genTools=require('genTools')
local colorMap={
{ 1, 2, 3, 4 },
{ 5, 6, 7, 8 },
{ 9, 10, 11, 12 }
}
local c=colorMap[z][x]
sel:add(sf:addNewRef('3005.dat', c, ldc.matrix(xx, yy, zz)))
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()
(2018-06-19, 13:28)Jaco van der Molen Wrote: [ -> ]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.
(2018-06-19, 18:19)Roland Melkert Wrote: [ -> ](2018-06-19, 13:28)Jaco van der Molen Wrote: [ -> ]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.
Fun
I was playing around with actual landscape generating last night using a "Diamond square algorithm" lua module I found somewhere.
Unfortunately it was too slow (due to the hard coded max script run time) to generate any real sized ones.
(2018-06-20, 10:22)Jaco van der Molen Wrote: [ -> ]Oh, I see. Very interesting. I know the Diamond square algorithm is used in games for example to create terrain.
I found a post on Stackoverflow how to make a Diamond square algorithm output to excel, but it doesn't work properly.
If we could somehow get a Diamond square algorithm to work in excel and it outputs numbers in cells, we could use your script.
Or better still straight in LDCad.
I have a few thoughts on this and what it should be able to do, but alas I am not a programmer so no idea how to make it.
My idea is as follows:Then
- Modify the script to use only 1x1 plates
- Be able to set user prefs like set up dimensions in baseplate format 16x16, 32x32 or 48x48
- Set up colors corresponding to plate height for terrain
Ie. very global 0 = blue water, 1 = tan sand, 2 = bright green gras, 3 = green trees, 4 = DBG hill, 5 = LBG mountain, 6 = whith snow top
That would be awesome.
- Using the Diamond square algorithm create output in Excel or straight in LDCad (?) to fill the height array
- Generate the LDraw model
(2018-06-20, 17:18)Roland Melkert Wrote: [ -> ]Should all be possible directly in LDCad, but with 1.6 the main problem is the 'slowness' of the addNewRef function as it takes ~1ms and currently the maximum runtime of a script is limited to 2000ms. I will remove that limitation in 1.6c though (if ever released, so 2.0 otherwise).
(2018-06-21, 5:50)Jaco van der Molen Wrote: [ -> ](2018-06-20, 17:18)Roland Melkert Wrote: [ -> ]Should all be possible directly in LDCad, but with 1.6 the main problem is the 'slowness' of the addNewRef function as it takes ~1ms and currently the maximum runtime of a script is limited to 2000ms. I will remove that limitation in 1.6c though (if ever released, so 2.0 otherwise).
OK, so that means the current limit is about 2000 bricks or a bit less?
(2018-06-21, 22:17)Roland Melkert Wrote: [ -> ](2018-06-21, 5:50)Jaco van der Molen Wrote: [ -> ]OK, so that means the current limit is about 2000 bricks or a bit less?
It depends on multiple things, but the bottle neck is clearly the addNewRef.
I compiled a version without the max execution time, and played around with diamond square.
This consists of 36000 bricks and, the script took about 35 seconds.
2.0's scripting environment will be much more suited for these kinds of things as the one in 1.6 is mostly optimized for animations.
(2018-06-22, 7:14)Jaco van der Molen Wrote: [ -> ]Do you mind sharing this script? Can I run some tests too on smaller scale?
(2018-06-22, 17:39)Roland Melkert Wrote: [ -> ](2018-06-22, 7:14)Jaco van der Molen Wrote: [ -> ]Do you mind sharing this script? Can I run some tests too on smaller scale?
Attached zip contains two .lua files, put landscape.lua in the global folder and heightmap.lua in the modules folder of %appdata%/LDCad/scripts/default
Also change the
maxExecTime
value to 2000 in main.cfg for the maximum time allowed in 1.6b (instead of the default 250ms)
Using a freshly started new file might be slightly faster as deleted type 1 lines are still kept in memory and thus processed during addNewRef stuff.
On my system it runs at max 64x64 (most of the time) within the 2s limit. It's an older system though, so you might go higher if you have a more recent one.
Look for hMap.create to change the dimensions, (should be powers of 2).
(2018-06-25, 12:34)Jaco van der Molen Wrote: [ -> ]I get this error:Did you put the loose heightmap.lua file in the global folder and not its whole containing folder.
[string "landscape.lua"]:11: module 'heightmap' not found:
no field package.preload['heightmap']
no file 'C:\Users\mj\AppData\Roaming\LDCad 1.6b\scripts\default\global\heightmap.lua'
no file 'C:\Users\mj\AppData\Roaming\LDCad 1.6b\scripts\default\modules\heightmap.lua'
no file 'C:\Program Files (x86)\LDraw\LDCad 1.6b\heightmap.dll'
no file 'C:\Program Files (x86)\LDraw\LDCad 1.6b\..\lib\lua\5.3\heightmap.dll'
no file 'C:\Program Files (x86)\LDraw\LDCad 1.6b\loadall.dll'
no file '.\heightmap.dll'
Script main run failed.
(2018-06-25, 19:57)Roland Melkert Wrote: [ -> ](2018-06-25, 12:34)Jaco van der Molen Wrote: [ -> ]I get this error:Did you put the loose heightmap.lua file in the global folder and not its whole containing folder.
[string "landscape.lua"]:11: module 'heightmap' not found:
no field package.preload['heightmap']
no file 'C:\Users\mj\AppData\Roaming\LDCad 1.6b\scripts\default\global\heightmap.lua'
no file 'C:\Users\mj\AppData\Roaming\LDCad 1.6b\scripts\default\modules\heightmap.lua'
no file 'C:\Program Files (x86)\LDraw\LDCad 1.6b\heightmap.dll'
no file 'C:\Program Files (x86)\LDraw\LDCad 1.6b\..\lib\lua\5.3\heightmap.dll'
no file 'C:\Program Files (x86)\LDraw\LDCad 1.6b\loadall.dll'
no file '.\heightmap.dll'
Script main run failed.