I'm making a procedural terrain generation. At the moment I got a terrain that has been generated by Perlin noise. Now I want to implement a procedural grass generation but with some constraints.
I only want to generate grass if is in a radius of the center of the world and on top of the ground. I can easily spawn grass in a radius of the center of the world. The problem is that I don't know how to know the height of the ground for that specified coordinate.
This is my attempt to implement this but doesn't work and I don't have an idea how to do it. I need some advice.
var group = new THREE.Group();
noise.seed(23);
var worldWidth = 256, worldDepth = 256;
var data = generateNoise( worldWidth, worldDepth );
var geometry = new THREE.PlaneBufferGeometry( 7500, 7500, worldWidth - 1, worldDepth - 1 );
geometry.rotateX( - Math.PI / 2 );
geometry.computeBoundingBox();
var vertices = geometry.attributes.position.array;
var positions = []
for ( var i = 0, j = 0, l = vertices.length; i < l; i ++, j += 3 ) {
vertices [ j + 1 ] = data[ i ] * 10;
//check if this coordinate is inside the radius we want to know if can spawn a grass
// if is inside spawn a plant knowing the height of this position
}
var grass = new THREEx.createGrassTufts(positions)
group.add(grass);
var texture = assets.textures.grass.val;
var material = new THREE.MeshPhongMaterial( { map: texture, shading: THREE.SmoothShading } );
var ground = new THREE.Mesh( geometry, material );
ground.receiveShadow = true;
ground.castShadow = true;
group.add(ground);