Recommended Posts

On 10/8/2019 at 6:27 AM, SylvainLS said:

Height variation option has been added.  A few improvements too (corrections, texts, input, error reporting…).

I’m not happy with the results yet: a flat top may look unnatural (though Lego-like) but a “varied” top looks roof-like, especially without plants (as the plates are all parallel).  I tried to add a bit of simple “noise” but it doesn’t work well often enough. :hmpf_bad:  Of course, one solution would be to make a complete “rolling hills” generator for the top but making a complete world was not the goal of the script :grin:

One more suggestion should you want to keep on down this path. Foe the multiple colors on the wall, can you make it an option ti be color variation through out the wall vs layers of color?

Share this post


Link to post
Share on other sites

Random colours?  Done.

But you won’t like it: the colours are computer-random, not human-(non)random.  The bigger the wall, the more uniformly spread they are (use black and white and you get “newspaper grey”).

Share this post


Link to post
Share on other sites

Actually I like the result, eg. with a low density of grey over white (71,15:10). Did you improve top covering with randonm height option? it seems to look even better now ;)

Share this post


Link to post
Share on other sites
5 hours ago, Philo said:

Actually I like the result, eg. with a low density of grey over white (71,15:10). Did you improve top covering with randonm height option? it seems to look even better now ;)

It’s just random luck, or should I say luck with random() :wink:

Share this post


Link to post
Share on other sites
14 hours ago, SylvainLS said:

Random colours?  Done.

But you won’t like it: the colours are computer-random, not human-(non)random.  The bigger the wall, the more uniformly spread they are (use black and white and you get “newspaper grey”).

This is exactly perfect!

9 hours ago, Philo said:

Actually I like the result, eg. with a low density of grey over white (71,15:10). Did you improve top covering with randonm height option? it seems to look even better now ;)

This tip helped a lot. I did a very high number of the main color and then lower fo the accent colors. It can be tweaked and improved but I really like the result! 

LDraw%20Cliff%20Test.png

Share this post


Link to post
Share on other sites

Hi,

Outstanding work, This is how the beta version of Lego Worlds generated terrain, using 'procedural generation'.

The only thing that the game had missing was the ability to import advanced models (an example of which could be SNOT.)

I wonder how much of a performance hit there would be if your generated maps had a few simple hand made SNOT models on top, maybe a small car or house.

Maybe LEGO will see this topic one day and make a real lego create and build game.

Edited by SNIPE

Share this post


Link to post
Share on other sites

Using models instead of bricks doesn’t change the performance.
Instead of using “3001.dat,” you use “house.dat,” and you arrange the building process to allow for your submodels.  Either you need a bit more complex rules to know if you can put a house (is the terrain big and flat enough?) or you arrange the terrain before putting it (like we do in real life).  Those changes aren’t time expensive.

But you need to build the models first :wink: and the more complex the models, the less generic the generated landscape.

I had another script which generated a lunar base from a few models (module skeletons, side panels, roofs, connecting corridors, and a few accessories).  The rules are pretty simple: a few types of connections and collision avoidance and just randomly connect models to each available connection.  And it gave something like that (latest version had a few spaceships, astronauts and robots sprinkled around):

autobase.png

(Old LDView render.)

The difficult part is making the modules and their connection.  And it’s fun but not very realistic.

Share this post


Link to post
Share on other sites
3 hours ago, SylvainLS said:

Using models instead of bricks doesn’t change the performance.
Instead of using “3001.dat,” you use “house.dat,” and you arrange the building process to allow for your submodels.  Either you need a bit more complex rules to know if you can put a house (is the terrain big and flat enough?) or you arrange the terrain before putting it (like we do in real life).  Those changes aren’t time expensive.

But you need to build the models first :wink: and the more complex the models, the less generic the generated landscape.

I had another script which generated a lunar base from a few models (module skeletons, side panels, roofs, connecting corridors, and a few accessories).  The rules are pretty simple: a few types of connections and collision avoidance and just randomly connect models to each available connection.  And it gave something like that (latest version had a few spaceships, astronauts and robots sprinkled around):

autobase.png

(Old LDView render.)

The difficult part is making the modules and their connection.  And it’s fun but not very realistic.

This is amazing. Could you give a course on this stuff? I would love to get more procedural generated roads and cities and other terrain types. 

Share this post


Link to post
Share on other sites

That's nice @SylvainLS - my early attempts at procedural modelling (these images are from a couple of years ago now) rotated and placed "sub-models" from a "library" of 11 sub-models on a 48x48 base plate.  Although the code selects and places the sub-models on the base, this isn't really procedural as I built the sub-models for the library, but I'm currently working on some code to create more appealing sub-models (as opposed to the completely random sub-models that I posted here initially) 

48909652051_11b16b2bb4_z.jpg  

48909120233_b53e0b47ec_z.jpg

48909861842_9754461ce2_z.jpg

48909856527_ce8f7d0a61_z.jpg

 

 

Share this post


Link to post
Share on other sites
41 minutes ago, supertruper1988 said:

Could you give a course on this stuff?

Gee!  You know you’re practicaly asking me to write a book? :grin:

 

@pennyforge Nice microcity!  Just randomizing the buildings’ heights would do wonders.  Parametrise the models (say, same building but 3, 4, or 5 storeys; or 2-, 3-, or 4-stud-wide).  It’d add diversity but keep the style.  Or add random details (chimney, tank, giant ad/screen… on the roof).  After all, that’s how architects do it! :wink:

Share this post


Link to post
Share on other sites

Hi @SylvainLS yes - height is key - over the last couple of years I've disappeared down a rabbit hole trying to track height (and density) of the model build!  However I think I'm starting to make progress...

48910193273_8186688f4d_z.jpg

Share this post


Link to post
Share on other sites
4 hours ago, SylvainLS said:

Gee!  You know you’re practicaly asking me to write a book? :grin:

I am well aware haha! I would love to learn or at lease get some pointers. I have a basic understanding of coding but no real specific knowledge and would like to learn more but I feel lost in the vast amount of material available and how that would apply to this. 

Share this post


Link to post
Share on other sites

A little update on my cliff generator.

Impelled by a discussion with supertruper1988, I changed the way the grass (or little bumps) on top of the cliff works.

  • I simplified the algorithm and it now has fewer artefacts.
  • When the top is flat (no height variation), it uses all sizes of plates (up to 16x16).  That greatly reduces the number of parts.
  • You can set the max height.

This allows you to generate a slightly bumpy landscape (that was supertruper1988’s first goal):

  • set the width (e.g. 100),
  • set the height to 0,
  • uncheck all the checkboxes,
  • set the back line to the depth you want (e.g. 100),
  • change the grass variation if you wish (e.g. 10),
  • generate and save.

grass-small.png

Download is here.

Share this post


Link to post
Share on other sites

The reduction of parts is very nice! I was doing some testing and accidentally generated a file with 170,000+ parts. 168,000 or so of those were 1x1 green plates :facepalm:

 

Share this post


Link to post
Share on other sites

The results of these generators are really amazing, very useful for digital models.

I've a question: would it be possible to use the software to generate landscapes with the shape inspired by historic LEGO baseplates such as the the moon baseplate or some castle baseplates, maybe in a different scale?

Share this post


Link to post
Share on other sites

It depends on the algorithm but it would be quite possible to force some features or altitudes.

*sigh* And now you got me thinking and I will have to try something….

Share this post


Link to post
Share on other sites
4 hours ago, SylvainLS said:

*sigh* And now you got me thinking and I will have to try something…. 

Absolutely, I wasn't going to!   :grin::wink:

Share this post


Link to post
Share on other sites

Okay, so here it is.

It’s a simple diamong-square/“plasma” algorithm.

You can feed it a heightfield image and it will “alter” the results.  Actually, it’s a multiplication: the image is grayscaled and we multiply each point of the randomized landscape with the luminance (black = 0, white = 1) of the matching point on the image (scaled to size).

If you set the “height offset” (or max slope) to 0, the landscape is not random at all.  So it’ll be totally flat if there’s no heightfield, and it’ll exactly be the heightfield if there’s one.

Here’s the heightfield I used: simple_heightfield.jpg

Here’s the landscape with an offset of 0: heightfield0.png

And with an offset of 0.4: heightfield4.png

There’s no need to use a big image.  Try to use one that more or less matches the desired dimensions.

Force reload the page to clear the heightfield.

(Note: it seems the image doesn’t always load correctly.  Try again if it doesn’t appear below the button.)

Download is here!

EDIT: and of course, there was an “oopsy typo” in the code I uploaded :ugh:

Edited by SylvainLS

Share this post


Link to post
Share on other sites

That’s very good - I’ve been thinking about something like that for a while but haven’t managed to write anything - nice job!

Share this post


Link to post
Share on other sites

@SylvainLS you are a machine! 

This is frankly genius, now one question. Might someone have a way to turn a 3D mesh into a height field? I have a lot of experience in 3D modeling so making a "landscape" then having a height map of it would be very useful.

Share this post


Link to post
Share on other sites
19 hours ago, pennyforge said:

That’s very good - I’ve been thinking about something like that for a while but haven’t managed to write anything - nice job!

Thanks.

I usually prefer the look of the old “fractal mountains” (isocele triangle, take the middle points, add random value, apply on the 4 smaller triangles, and again…) but it doen’t render well with squares, and, until recently, I found diamond-square to have too harsh artefacts (visible lines).  But I recently found a simple implementation for the fractal line: instead of just adding a random value to the middle point, you can control the slope.  And that’s what I applied here to diamond-square: instead of taking the average and adding a random value (which is one thing that creates artefacts because diagonals are longer than sides), I simply control the slope (find how high/low the point can be to respect the slope, set it randomly between those values).

 

10 hours ago, supertruper1988 said:

@SylvainLS you are a machine! 

This is frankly genius, now one question. Might someone have a way to turn a 3D mesh into a height field? I have a lot of experience in 3D modeling so making a "landscape" then having a height map of it would be very useful.

Thanks.

I thought about using .dat files but didn’t do anything yet because they are recursive.  Otherwise the principle is simple: take all the quads and triangles in the mesh, find the min and max X and Y and Z to scale them on your image, and put all the points in a bitmap on width*(X-Xmin)/(Xmax-Xmin), height*(Y-Ymin)/(Ymax-Ymin) and in a gray 255*(Z-Zmin)/(Zmax-Zmin).

I don’t think I will do that in Javascript though, it’s impossible to read the recursive .dat files and stay simple/portable.

Share this post


Link to post
Share on other sites
2 minutes ago, SylvainLS said:

I don’t think I will do that in Javascript though, it’s impossible to read the recursive .dat files and stay simple/portable.

Or you could accept only "flattened" .dat files? There are tools to do that.

Share this post


Link to post
Share on other sites

After some digging, it appears that blender can export height maps. I guess I am off to learn a new 3D program haha. 

So now digging into this, would it be possible to combine the cliff section into this? Say if the slop is greater than 85 degrees on the heigh map, it makes a cliff instead? My use case is to make a "cut" through a mountain for a rail road. 

 

Share this post


Link to post
Share on other sites
1 hour ago, Philo said:

Or you could accept only "flattened" .dat files? There are tools to do that.

But then, people would need to use those tools beforehand, so making a tool that combines flattening and making a heighfield reduces the number of tools.

I started something but I forgot there were giant quads and triangles on baseplates, I need to “fill” them :laugh:

 

1 hour ago, supertruper1988 said:

So now digging into this, would it be possible to combine the cliff section into this? Say if the slop is greater than 85 degrees on the heigh map, it makes a cliff instead? My use case is to make a "cut" through a mountain for a rail road. 

Sort of.  Using bricks for high slopes would be great indeed but it’s a bit more complicated than replacing 1x1 plates with bigger plates, and the techniques are quite different and incompatible: ldraw_cliff builds the cliff by randomly piling bricks, ldraw_landscape creates or uses (or both) a heighfield and then uses plates to represent it. 

A lead I’m thinking about is to 3D-ize my plate-replacement algorithm to include bricks (and maybe slopes).

Share this post


Link to post
Share on other sites
5 hours ago, SylvainLS said:

But then, people would need to use those tools beforehand, so making a tool that combines flattening and making a heighfield reduces the number of tools.

I started something but I forgot there were giant quads and triangles on baseplates, I need to “fill” them :laugh:

 

Sort of.  Using bricks for high slopes would be great indeed but it’s a bit more complicated than replacing 1x1 plates with bigger plates, and the techniques are quite different and incompatible: ldraw_cliff builds the cliff by randomly piling bricks, ldraw_landscape creates or uses (or both) a heighfield and then uses plates to represent it. 

A lead I’m thinking about is to 3D-ize my plate-replacement algorithm to include bricks (and maybe slopes).

You have put so much work in already I would hate to ask more so please dont spend time on it on my account

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.