I'm currently working on a procedural terrain generation project. I have successfully generated terrain using Perlin noise, and now I want to add procedural grass generation with some specific constraints.
My goal is to only generate grass within a certain radius of the world center and on top of the ground. While I can easily spawn grass within the specified radius, I am struggling to determine the height of the ground at a given coordinate.
I've made an attempt to implement this functionality, but it's not working as intended. I would greatly appreciate any advice or guidance on how to proceed.
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 where we want to see if grass can be spawned
// If it's inside, spawn a plant at 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);