Open EliteAsian123 opened 5 years ago
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;
}
What does this code do?
add some color
There is usually a number after your username. What is that?
The hills are hollow:
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
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
} }`
in index.js you put this in worlddataneeded
data=noaTerrainGen.generateWorld( id, data, x, y, z, [grassID, dirtID, stoneID,waterID])
It's probably refusing because I switched the library for noise take a look at noa-world-gen
I didnt update to your new library yet
Oh okay
it says Cannot read property 'simplex2'
I recommend updating, as I do not have the old version on hand, there is not much of a difference.
ok
Also there are multiple undefined variables. You probably for got to send those along with the code.
wait I have a new code
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;
}
Keep in mind we have to optimize this for browser use.
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
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));
Okay I'll try
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]) }
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));
one step for man , one giant step for....
damn Uncaught TypeError: (this.simplexNoise.noise3D(...) * options.b_height) is not a function
it worked there was a + missing lol
Oh okay I was scared for a second
man it does affect frame rate
yeah, 3D noise is very heavy.
maybe the amount is too high
shoot im going to have to let go of this obsession for now lol
lol okay
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
thanks for the help have to go
Sorry I was eating, I am using the latest version of Babylon
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
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
)
}
}
}
}
}`
if you want to copy and paste code use this before and after the code: ```js code ```
As you are just doing this: ` code `
Put all code here for Terrain Generation Ideas.