Skip to content
This repository has been archived by the owner on May 4, 2020. It is now read-only.

Terrain Generation #3

Open
EliteAsian123 opened this issue Aug 29, 2019 · 38 comments
Open

Terrain Generation #3

EliteAsian123 opened this issue Aug 29, 2019 · 38 comments
Labels
discussion Discuss!

Comments

@EliteAsian123
Copy link
Owner

Put all code here for Terrain Generation Ideas.

@EliteAsian123 EliteAsian123 added the discussion Discuss! label Aug 29, 2019
@levlups
Copy link

levlups commented Aug 30, 2019

I did this so far , a little flavor but no caves

NoaTerrainGen.prototype.genAdvancedTerrain = function(id, data, x, y, z, blockIDs, options, seed) {
var noiser = noise.simplex3(x+100, y+100, z+100)
if (seed) {
noise.seed(seed);
} else {
noise.seed(this.random);
}
for (var x1 = 0; x1 < data.shape[0]; ++x1) {
for (var z1 = 0; z1 < data.shape[2]; ++z1) {
var random2 = Math.floor((noise.simplex2((x1 + x) / options.a_zoom, (z1 + z) / options.a_zoom) * options.a_height)/2 + (noise.simplex2((x1 + x) / options.b_zoom, (z1 + z) / options.b_zoom) * options.b_height)/2 + (noise.simplex2((x1 + x) / options.c_zoom, (z1 + z) / options.c_zoom) * options.c_height));

		var random = Math.floor((noise.simplex2((x1 + x) / options.a_zoom, (z1 + z) / options.a_zoom) * options.a_height) + (noise.simplex2((x1 + x) / options.b_zoom, (z1 + z) / options.b_zoom) * options.b_height) + (noise.simplex2((x1 + x) / options.c_zoom, (z1 + z) / options.c_zoom) * options.c_height));
		for (var y1 = 0; y1 < data.shape[1]; ++y1) {
				
			if (y1 + y === random + 1) {
				data.set(x1, y1, z1, blockIDs[0]);
			}  else if (y1 + y <= random + 1 && noise >0.3) {
				data.set(x1, y1, z1, blockIDs[4]);
			}else if (y1 + y < random2 + 1 && y1 + y > random - 5) {
				data.set(x1, y1, z1, blockIDs[1]);
			} else if (y1 + y <= random - 5) {
				data.set(x1, y1, z1, blockIDs[2]);
			} else if (y1 + y <= -6) {
				data.set(x1, y1, z1, blockIDs[3]);
			}		
		}
	}
}
return data;

}

@EliteAsian123
Copy link
Owner Author

What does this code do?

@levlups
Copy link

levlups commented Aug 30, 2019

add some color

@EliteAsian123
Copy link
Owner Author

There is usually a number after your username. What is that?

@EliteAsian123
Copy link
Owner Author

The hills are hollow:
image

@EliteAsian123
Copy link
Owner Author

EliteAsian123 commented Aug 30, 2019

I also just updated noa-terrain-gen an made it use another noise generator, apparently more optimized.
So some things like where to put the seed is changed

@levlups
Copy link

levlups commented Aug 30, 2019

I found the code for the nice caves ut its refusing to connect to simplex2 , heres the code

` var terrainXZ = 80,
terrainY = 10
NoaTerrainGen.prototype.generateWorld= function( id, data, x, y, z, blockIDs) {

// populate chunk. xyz is the origin of the chunk in world coords
var dx = data.shape[0]
var dy = data.shape[1]
var dz = data.shape[2]

for (var i=0; i<dx; ++i) {
  for (var k=0; k<dz; ++k) {
	  
    // simple heightmap across x/z
    var cx = (x+i)/terrainXZ
    var cz = (z+k)/terrainXZ
	
	
    var height = terrainY *noise.simplex2(cx,cz) >> 0
		
	
    height -= 3
    for (var j=0; j<dy; ++j) {
		   	 var noise = noise.simplex3(x+20, y+100, z+20)
      var id = decideBlockID( x+i, y+j, z+k,-6, blockIDs,noiser )
	
      if (id !== 0) data.set( i,j,k, id )
		
    }
   
    // possibly add a tree at this x/z coord
  
    //tree(chunk, x, y, z, height, i, k)
	
  }
}

return data

}
decideBlockID= function(x, y, z, groundLevel,block1IDs) {

 // var noise =  noise.simplex3(x/specialnum, y/cloudY, z/specialnum)
 var noise = noise.simplex3(x+20, y+100, z+20)
	
if (y<groundLevel && noise > cloudCutoff/100) return block1IDs[0]
			if (y==groundLevel && noise > cloudCutoff/100 ) {
				
			 if (y <  -4) {
					  if( Math.random()*100<50){
						
						return block1IDs[1]
					}else{
					  return 0;
					  //return stoneID //stoneID
					}
			  }
			 else  if (y == -4) return block1IDs[2]
			  else if (y == -3) return block1IDs[2]
			 
			 else  if(y<groundLevel){
				return block1IDs[3]
			}
			//  console.log(2+y+block1ID)*/
			//*/}
			//  return 2+y+block1ID
			  
		//	}
			
// }

			
			 // pools of water at low level
if (y === waterLevel) return block1IDs[3]//waterID
if (y < waterLevel) return block1IDs[3]//waterID
  

// flowers
if (y==groundLevel+1 && y>-3 && y<3 ) {
  var h = hash(x,z)
  if (floor(h*70)===0)
	  
	  return block1IDs[0]
}





// otherwise air
return 0

}
}`

@levlups
Copy link

levlups commented Aug 30, 2019

in index.js you put this in worlddataneeded

data=noaTerrainGen.generateWorld( id, data, x, y, z,  [grassID, dirtID, stoneID,waterID]) 

@EliteAsian123
Copy link
Owner Author

It's probably refusing because I switched the library for noise take a look at noa-world-gen

@levlups
Copy link

levlups commented Aug 30, 2019

I didnt update to your new library yet

@EliteAsian123
Copy link
Owner Author

Oh okay

@levlups
Copy link

levlups commented Aug 30, 2019

it says Cannot read property 'simplex2'

@EliteAsian123
Copy link
Owner Author

I recommend updating, as I do not have the old version on hand, there is not much of a difference.

@levlups
Copy link

levlups commented Aug 30, 2019

ok

@EliteAsian123
Copy link
Owner Author

Also there are multiple undefined variables. You probably for got to send those along with the code.

@levlups
Copy link

levlups commented Aug 30, 2019

wait I have a new code

@levlups
Copy link

levlups commented Aug 30, 2019

how about this but too noisy im getting closer

NoaTerrainGen.prototype.genAdvancedTerrain = function(id, data, x, y, z, blockIDs, options) {
for (var x1 = 0; x1 < data.shape[0]; ++x1) {
for (var z1 = 0; z1 < data.shape[2]; ++z1) {
var random = Math.floor((this.simplexNoise.noise2D((x1 + x) / options.a_zoom, (z1 + z) / options.a_zoom) * options.a_height) + (this.simplexNoise.noise2D((x1 + x) / options.b_zoom, (z1 + z) / options.b_zoom) * options.b_height) + (this.simplexNoise.noise2D((x1 + x) / options.c_zoom, (z1 + z) / options.c_zoom) * options.c_height));
for (var y1 = 0; y1 < data.shape[1]; ++y1 ) {
if(this.simplexNoise.noise3D((x1+x/20),(y1+y/20),(z1+z/20))>0.3){
if (y1 + y === random + 1) {
data.set(x1, y1, z1, blockIDs[0]);
} else if (y1 + y < random + 1 && y1 + y > random - 5) {
data.set(x1, y1, z1, blockIDs[1]);
} else if (y1 + y <= random - 5) {
data.set(x1, y1, z1, blockIDs[2]);
}
}
}
}
}
return data;
}

@EliteAsian123
Copy link
Owner Author

Keep in mind we have to optimize this for browser use.

@levlups
Copy link

levlups commented Aug 30, 2019

ok I think I found a lead can you change that sentence into a simplex3d one

						var random = Math.floor((this.simplexNoise.noise3D((x1 + x) / options.a_zoom, (z1 + z) / options.a_zoom) * options.a_height) + (this.simplexNoise.noise2D((x1 + x) / options.b_zoom, (z1 + z) / options.b_zoom) * options.b_height) + (this.simplexNoise.noise2D((x1 + x) / options.c_zoom, (z1 + z) / options.c_zoom) * options.c_height));

I tried and my braine went ahhhhhhhh

@levlups
Copy link

levlups commented Aug 30, 2019

sorry this
var random = Math.floor((this.simplexNoise.noise2D((x1 + x) / options.a_zoom, (z1 + z) / options.a_zoom) * options.a_height) + (this.simplexNoise.noise2D((x1 + x) / options.b_zoom, (z1 + z) / options.b_zoom) * options.b_height) + (this.simplexNoise.noise2D((x1 + x) / options.c_zoom, (z1 + z) / options.c_zoom) * options.c_height));

@EliteAsian123
Copy link
Owner Author

Okay I'll try

@levlups
Copy link

levlups commented Aug 30, 2019

thanks your the best ,let me give you a present , if you want your character to fly put this

var hovering = false
noa.inputs.bind('hover', 'R')
noa.inputs.down.on('hover', function() {
hovering = true;

})
noa.inputs.up.on('hover', function() {
hovering = false;

})

var body = noa.entities.getPhysicsBody(noa.playerEntity)
noa.on('tick', function(dt) {
if (hovering) hover(noa, body);
})

function hover(noa, body) {
var f = (body.velocity[1] < 0) ? 40 : 24
body.applyForce([0, f, 0])
}

@EliteAsian123
Copy link
Owner Author

EliteAsian123 commented Aug 30, 2019

Okay thanks for the present!
Here is the 3D version

var random = Math.floor((this.simplexNoise.noise3D((x1 + x) / options.a_zoom, (y1 + y) / options.a_zoom, (z1 + z) / options.a_zoom) * options.a_height) + (this.simplexNoise.noise3D((x1 + x) / options.b_zoom, (y1 + y) / options.b_zoom, (z1 + z) / options.b_zoom) * options.b_height) (this.simplexNoise.noise3D((x1 + x) / options.c_zoom, (y1 + y) / options.c_zoom, (z1 + z) / options.c_zoom) * options.c_height));

@levlups
Copy link

levlups commented Aug 30, 2019

one step for man , one giant step for....

@levlups
Copy link

levlups commented Aug 30, 2019

damn
Uncaught TypeError: (this.simplexNoise.noise3D(...) * options.b_height) is not a function

@levlups
Copy link

levlups commented Aug 30, 2019

it worked there was a + missing lol

@EliteAsian123
Copy link
Owner Author

Oh okay I was scared for a second

@levlups
Copy link

levlups commented Aug 30, 2019

man it does affect frame rate

@EliteAsian123
Copy link
Owner Author

yeah, 3D noise is very heavy.

@levlups
Copy link

levlups commented Aug 30, 2019

maybe the amount is too high

@levlups
Copy link

levlups commented Aug 30, 2019

shoot im going to have to let go of this obsession for now lol

@EliteAsian123
Copy link
Owner Author

lol okay

@levlups
Copy link

levlups commented Aug 30, 2019

do you know wath version of babylon your using , because your frame rate and the way your land generates is fast non patchy , and im using a gaming pc

@levlups
Copy link

levlups commented Aug 30, 2019

thanks for the help have to go

@EliteAsian123
Copy link
Owner Author

Sorry I was eating, I am using the latest version of Babylon

@levlups
Copy link

levlups commented Aug 31, 2019

I kind of figure it out but I have a problem heres the code

NoaTerrainGen.prototype.genAdvancedTerrain = function(id, data, x, y, z, blockIDs, options) {
for (var x1 = 0; x1 < data.shape[0]; ++x1) {
for (var z1 = 0; z1 < data.shape[2]; ++z1) {
for (var y1 = 0; y1 < data.shape[1]; ++y1) {
var random = Math.floor((this.simplexNoise.noise2D((x1 + x) / options.a_zoom, (z1 + z) / options.a_zoom) * options.a_height) + (this.simplexNoise.noise2D((x1 + x) / options.b_zoom, (z1 + z) / options.b_zoom) * options.b_height) + (this.simplexNoise.noise2D((x1 + x) / options.c_zoom, (z1 + z) / options.c_zoom) * options.c_height));

			if (y1 + y === random + 1) {
				data.set(x1, y1, z1, blockIDs[0]);
			} else if (y1 + y < random + 1 && y1 + y > random - 5) {
				data.set(x1, y1, z1, blockIDs[1]);
			} else if (y1 + y <= random - 5) {
				data.set(x1, y1, z1, blockIDs[2]);
			}	
			
		}
	}
}
addBlocksInSphere(data,noa,0,[5,Math.random()*10+5,5],2.3)
return data;

}

function addBlocksInSphere(data,noa, id, pos, radius) {
var rad = Math.ceil(radius)
for (var i=-rad; i<=rad; ++i) {
for (var j=-rad; j<=rad/2; ++j) {
for (var k=-rad; k<=rad; ++k) {
if (ii + jj + kk <= radiusradius) {

			data.set(
			 // noa.addBlock( id, 
				i + Math.floor(pos[0]), 
				j + Math.floor(pos[1]), 
				k + Math.floor(pos[2]),
				id
			  )
		
    }
  }
}

}

}

ok it works it makes little caves but the have to be in the middle of the chunks ,it it hits the edge it makes a hole in map ,so I need a worm meaning an algorithm that will add air surrounded with blocks so even if it hits an edge it waill add a opaque block there , wath do you think

@levlups
Copy link

levlups commented Aug 31, 2019

cant believe github doesnt allow to paste code properly let me try again
`
NoaTerrainGen.prototype.genAdvancedTerrain = function(id, data, x, y, z, blockIDs, options) {
for (var x1 = 0; x1 < data.shape[0]; ++x1) {
for (var z1 = 0; z1 < data.shape[2]; ++z1) {
for (var y1 = 0; y1 < data.shape[1]; ++y1) {
var random = Math.floor((this.simplexNoise.noise2D((x1 + x) / options.a_zoom, (z1 + z) / options.a_zoom) * options.a_height) + (this.simplexNoise.noise2D((x1 + x) / options.b_zoom, (z1 + z) / options.b_zoom) * options.b_height) + (this.simplexNoise.noise2D((x1 + x) / options.c_zoom, (z1 + z) / options.c_zoom) * options.c_height));

			if (y1 + y === random + 1) {
				data.set(x1, y1, z1, blockIDs[0]);
			} else if (y1 + y < random + 1 && y1 + y > random - 5) {
				data.set(x1, y1, z1, blockIDs[1]);
			} else if (y1 + y <= random - 5) {
				data.set(x1, y1, z1, blockIDs[2]);
			}	
			
		}
	}
}
addBlocksInSphere(data,noa,0,[5,Math.random()*10+5,5],2.3)
return data;

}

function addBlocksInSphere(data,noa, id, pos, radius) {
var rad = Math.ceil(radius)
for (var i=-rad; i<=rad; ++i) {
for (var j=-rad; j<=rad/2; ++j) {
for (var k=-rad; k<=rad; ++k) {
if (ii + jj + kk <= radiusradius) {

			data.set(
			 // noa.addBlock( id, 
				i + Math.floor(pos[0]), 
				j + Math.floor(pos[1]), 
				k + Math.floor(pos[2]),
				id
			  )
		
    }
  }
}

}

}`

@EliteAsian123
Copy link
Owner Author

EliteAsian123 commented Aug 31, 2019

if you want to copy and paste code use this before and after the code:
```js
code
```

As you are just doing this:
`
code
`

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
discussion Discuss!
Projects
None yet
Development

No branches or pull requests

2 participants