Help with autoplacement for multi level (3D) map

Place to get help with not working mods / modding interface.
Post Reply
mrvn
Smart Inserter
Smart Inserter
Posts: 5704
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Help with autoplacement for multi level (3D) map

Post by mrvn »

In vanilla everything is placed on the surface of the world. You don't have to dig down into the ground to mine ores, they are simply lying around on top. This is hardly realistic.

But factorio supports having multiple surfaces. So it wouldn't be hard to have actual mines underground using multiple surfaces as layers at different depths.

Now here comes my problem:

Can I change the autoplacement of ores in such a way that the layers look realistic? That means that if one layer has a huge iron ore patch then the layer above and below should also have iron ore patches at about the same place. Ore patches from different layers combined should look like a 3D blob of ore.

Similar problem: Deep water on the surface should also be water in the first layer (or first few depending on depth). The difference to ore would be that water (I think) shouldn't have underground caverns. On the other hand underground seas or rivers might be fun too.


User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Help with autoplacement for multi level (3D) map

Post by darkfrei »

Or you can go to RSO's way: place all resources by the script only. You can make your own maths for ores placing, just make new noise and change the section level on each surface.

mrvn
Smart Inserter
Smart Inserter
Posts: 5704
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Help with autoplacement for multi level (3D) map

Post by mrvn »

Placing all resources by script would certainly work. Good to have an example for that.

As for making new noise.... Do you mean specifying a different noise layer? As far as I can see the noise layers are defined by the game and are all non correlated 2D perlin noise. Using different noise layers per surface gives ore at different positions. I need loosely correlated layers.

PS: Can anyone recommend a noise function for 3D?

User avatar
WeirdConstructor
Inserter
Inserter
Posts: 39
Joined: Wed Aug 08, 2018 6:31 am
Contact:

Re: Help with autoplacement for multi level (3D) map

Post by WeirdConstructor »

mrvn wrote: ↑
Mon Sep 17, 2018 1:24 pm

PS: Can anyone recommend a noise function for 3D?
Just use any RNG or even hash function (like xorshift or whatever, even the Lua random number generator might wirk)
and throw in the coordinates as seed (hashed and/or xor'ed x/y/z) and you got your value for that position.
You can mix multiple octaves and interpolate for more smooth transitions to neighbor coordinates.

mrvn
Smart Inserter
Smart Inserter
Posts: 5704
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Help with autoplacement for multi level (3D) map

Post by mrvn »

WeirdConstructor wrote: ↑
Mon Sep 17, 2018 1:37 pm
mrvn wrote: ↑
Mon Sep 17, 2018 1:24 pm

PS: Can anyone recommend a noise function for 3D?
Just use any RNG or even hash function (like xorshift or whatever, even the Lua random number generator might wirk)
and throw in the coordinates as seed (hashed and/or xor'ed x/y/z) and you got your value for that position.
You can mix multiple octaves and interpolate for more smooth transitions to neighbor coordinates.
That would give me white noise with single tiles of ores randomly distributed all across the surface.

I want a nice patch of ore over 3 dimensions. Like a raisin in a cake.

User avatar
WeirdConstructor
Inserter
Inserter
Posts: 39
Joined: Wed Aug 08, 2018 6:31 am
Contact:

Re: Help with autoplacement for multi level (3D) map

Post by WeirdConstructor »

mrvn wrote: ↑
Mon Sep 17, 2018 1:49 pm
WeirdConstructor wrote: ↑
Mon Sep 17, 2018 1:37 pm
mrvn wrote: ↑
Mon Sep 17, 2018 1:24 pm

PS: Can anyone recommend a noise function for 3D?
Just use any RNG or even hash function (like xorshift or whatever, even the Lua random number generator might wirk)
and throw in the coordinates as seed (hashed and/or xor'ed x/y/z) and you got your value for that position.
You can mix multiple octaves and interpolate for more smooth transitions to neighbor coordinates.
That would give me white noise with single tiles of ores randomly distributed all across the surface.

I want a nice patch of ore over 3 dimensions. Like a raisin in a cake.
Thats why I said u should mix/blend multiple resolutions aka octaves with interpolation. At x u sample x and x modulo 10 and other modulos. The remainder of that modulo you use to interpolate between (x modulo 10) and ((x modulo 10) + 1). You get a noise value for each octave and you can blend them at will. Thats basically what most call "perlin noise" even though real perlin noise is a bit more specific.

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Help with autoplacement for multi level (3D) map

Post by orzelek »

I think this might be useful:
https://en.wikipedia.org/wiki/Metaballs
RSO uses 2D variant of those to generate ores. It might be pretty easy to use current gen as "base" and expand them in z dimension.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Help with autoplacement for multi level (3D) map

Post by darkfrei »

mrvn wrote: ↑
Mon Sep 17, 2018 1:49 pm
I want a nice patch of ore over 3 dimensions. Like a raisin in a cake.
For better understanding of 3d noise, you must make nice 2d noise before.

I've made some 2d noise here: NewIslands.
The simple noise is:
h=cos(X)*cos(Y), if h > 0.5 then b = true else b = false end, but this noise is absolutely not noise.

Some complicated (more octaves):
h=(A*cos(X)*cos(Y)+B*cos(2*X)*cos(2*Y))/(A+B)
h=(A*cos(X)*cos(Y)+B*cos(2*X)*cos(2*Y)+C*cos(4*X)*cos(4*Y))/(A+B+C) etc. All of them are symmetrically, you are need just add some odd stuff and shift it.

The example for 1D noise (shifted by x to 10):
y = (cos(x)+(1/2)*cos(3.1(x+10))+(1/3)*cos(5.1(x+10))+(1/5)*cos(8.1(x+10)))/(1+1/2+1/3+1/5)

mrvn
Smart Inserter
Smart Inserter
Posts: 5704
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Help with autoplacement for multi level (3D) map

Post by mrvn »

orzelek wrote: ↑
Mon Sep 17, 2018 4:24 pm
I think this might be useful:
https://en.wikipedia.org/wiki/Metaballs
RSO uses 2D variant of those to generate ores. It might be pretty easy to use current gen as "base" and expand them in z dimension.
That would wok well with the random dots from the last FFF.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Help with autoplacement for multi level (3D) map

Post by darkfrei »

mrvn wrote: ↑
Thu Sep 20, 2018 9:07 am
That would wok well with the random dots from the last FFF.
But you are need to define each metaball! It's not good for unlimited map.

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Help with autoplacement for multi level (3D) map

Post by orzelek »

darkfrei wrote: ↑
Thu Sep 20, 2018 10:22 am
mrvn wrote: ↑
Thu Sep 20, 2018 9:07 am
That would wok well with the random dots from the last FFF.
But you are need to define each metaball! It's not good for unlimited map.
It's not a big problem - RSO just rolls randomly few of them (positive and negative) to create nicely looking patches. A bit tricky part is getting patch of size you actually want and balancing total amount of resources. I'm not sure why unlimited map would be a problem?

mrvn
Smart Inserter
Smart Inserter
Posts: 5704
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Help with autoplacement for multi level (3D) map

Post by mrvn »

orzelek wrote: ↑
Thu Sep 20, 2018 11:36 am
darkfrei wrote: ↑
Thu Sep 20, 2018 10:22 am
mrvn wrote: ↑
Thu Sep 20, 2018 9:07 am
That would wok well with the random dots from the last FFF.
But you are need to define each metaball! It's not good for unlimited map.
It's not a big problem - RSO just rolls randomly few of them (positive and negative) to create nicely looking patches. A bit tricky part is getting patch of size you actually want and balancing total amount of resources. I'm not sure why unlimited map would be a problem?
Exactly. I would use the random dots from the last FFF as locations of the metaballs and then the combination of them gives the patch.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Help with autoplacement for multi level (3D) map

Post by darkfrei »

So looks like cosinus-octaves-noise:
Image
Every tile on the map needs the same calculating time.

Code: Select all

function cos_octaves (octaves, position, p)
  local h = 0
  local summ = 0
  if octaves then
    -- log ('octaves = ' .. serpent.block (octaves))
    for i, octave in pairs (octaves) do
    
      local x = position.x*math.cos(octave.teta)-position.y*math.sin(octave.teta)
      local y = position.x*math.sin(octave.teta)+position.y*math.cos(octave.teta)
      summ = summ + octave.length
      h = h + octave.length * mycos (p*(x+octave.shift.x)/(octave.length^1.1))*mycos(p*(y+octave.shift.y)/(octave.length^1.1))
    end
  end
  return h/summ
end

mrvn
Smart Inserter
Smart Inserter
Posts: 5704
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Help with autoplacement for multi level (3D) map

Post by mrvn »

darkfrei wrote: ↑
Fri Sep 21, 2018 7:18 am
So looks like cosinus-octaves-noise:
Image
Every tile on the map needs the same calculating time.
A circle in the middle of the map doesn't look much noisy to me.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Help with autoplacement for multi level (3D) map

Post by darkfrei »

mrvn wrote: ↑
Tue Sep 25, 2018 8:10 am
A circle in the middle of the map doesn't look much noisy to me.
It's exception for spawning area: you have too big chance to drawn in the lake. The form of starting area will be changed in next versions.

Post Reply

Return to β€œModding help”