Skip to content

Grass

Updated

Grass grows wind-blown blades on any ground: a terrain, a floor, a box or a model. Grass Benders part the grass as players and objects move through it. Scripts mow and regrow grass, paint where it grows, and make the wind gust.

  • The ground. Grass grows on the entity it is added to. For a generated landscape, add it to a Terrain.
  • Raycasts. To find where the pointer touches the ground, use GraphicsRaycaster. See Input and interaction.
  • Lights. Grass reads ambient, hemisphere and directional lights. See Lighting.
ComponentTypeWhat it does
Grasscomp-grassWind-blown grass that grows on the entity's surface.
Grass Bendercomp-grass-benderMakes grass bend away as this entity moves through it.

Grass has a quality prop: 'auto' (the default), 'low' or 'high'. auto picks low on phones and headsets and high elsewhere, once per session. Leave it on auto unless you have a reason to force one.

GrassComponent goes on Terrain, Primitive Mesh, Floor and model entities (not kit pieces). It grows blades on the top surface of the entity’s own meshes.

Prop Type Default Description
preset 'lawn' | 'meadow' | 'tallGrass' | 'wheat' | 'savanna' | 'tundra' 'lawn' Blade shape, density, colours and wind.
baseColor string preset’s Colour at the roots.
tipColor string preset’s Colour at the tips.
dryness number preset’s 0 green to 1 straw, in patches and blade by blade.
dryPatch number 0.25 How much dry patches blend in, 0 to 1.
density number 1 Live thinning of the blades, 0 to 1.
windStrength number 0.5 Multiplier on wind sway, -2 to 2. 0 stops the sway.
quality 'auto' | 'low' | 'high' 'auto' Tile size, blade count and shading.
maxSlope number 55 Degrees from flat, 0 to 90, past which upright blades stop growing.
growth 'up' | 'surface' 'up' up: upright blades on top surfaces. surface: blades over every surface along its normals, like a mossy rock.
mask object none Painted coverage. Omit for full coverage.

baseColor, tipColor, dryness, dryPatch, density and windStrength are cheap to change live: nothing is rebuilt. Selecting a preset applies its colours, dryness and dry patches together.

Member Description
paint(x, z, radius, value, hardness = 1) Grow (value 1) or mow (0) a disc at (x, z), in a world-up frame at the entity’s origin. up grass only.
paintAt(point, radius, value, hardness = 1) The same at a world point with a world radius. On surface grass it paints a ball of that radius.
fill(value) 1 grows grass everywhere, 0 clears it.
encodeMask() The painted coverage in the mask prop’s format, or undefined when fully covered.
bladeCount Blades in the near tile. Read-only.

Painting shows at once with a short grow-in. It is saved only when you store it: grass.setProps({ mask: { data: grass.encodeMask() } }).

How grass draws. A near band of full, curved, wind-blown blades wraps around the viewer out to about 24 to 29 m; a far band of simple clumps carries the grass on to 60 m (low) or 100 m (high), where fog should take over. Blades are culled one by one, so only the blades in view cost anything. Blades take ambient, hemisphere and directional lights and fog; point and spot lights are not read. Blades are not raycast, collided, shadowed, outlined or part of the navigation mesh.

GrassBenderComponent goes on Camera, Primitive Mesh, model and Group entities (not kit pieces). It makes its entity part and bend the grass it moves through: the player, a character, a rolling ball. Visual only.

Prop Type Default Description
radius number 0.6 Influence radius in metres, 0 to 100.
strength number 1 Outward push, 0 to 4.
offsetY number 0 Vertical offset from the entity’s origin, -1000 to 1000 m: put a camera’s bend at its feet.

A bender has no per-frame cost of its own: each Grass uses the nearest 8 (low) or 16 (high) benders inside its tile.

1. A mower that cuts the grass it drives over

Section titled “1. A mower that cuts the grass it drives over”

A Behavior on a mower entity mows a strip of grass as it moves, and saves the mowed area into the grass mask a second after it stops.

Mower.jx
#pragma lifecycle(startup, update)
const CUT_RADIUS = 0.7;
let grass;
const blade = new THREE.Vector3();
const last = new THREE.Vector3();
const saveMask = debounce(() => {
grass.setProps({ mask: { data: grass.encodeMask() } });
log('Lawn saved');
}, 1000);
function startup() {
grass = findEntity('Lawn').getComponent(GrassComponent);
self.getWorldPosition(last);
}
function update() {
self.getWorldPosition(blade);
if (blade.distanceToSquared(last) < 0.04) return; // moved less than 20 cm
last.copy(blade);
grass.paintAt(blade, CUT_RADIUS, 0, 0.8);
saveMask();
}
  • paintAt(blade, CUT_RADIUS, 0, 0.8) mows (0) a disc around the mower with a slightly soft edge.
  • The script paints only after the mower moves 20 cm, so a parked mower costs nothing. Comparing squared distances avoids a square root.
  • debounce(fn, 1000) returns a function that runs fn once, one second after the last call. While the mower keeps moving, saving waits; when it stops, the mask is saved once.
  • encodeMask() returns the painted coverage in the format the mask prop expects.

2. Let the player part the grass, and make the wind gust

Section titled “2. Let the player part the grass, and make the wind gust”

Add a Grass Bender to the camera at the player’s feet, and make the wind gust now and then.

GrassFeel.jx
#pragma lifecycle(startup)
async function startup() {
const player = findEntity('Main Camera');
if (!player.getComponent(GrassBenderComponent)) {
player.addComponent(new GrassBenderComponent({ radius: 0.5, strength: 1.2, offsetY: -1.5 }));
}
const grass = findEntity('Terrain').getComponent(GrassComponent);
for (;;) {
await new Promise((done) => delay(done, Random.range(4000, 9000)));
const gust = Tween.value(0.5, 1.6, (w) => grass.setProps({ windStrength: w }), {
duration: 1.2, ease: Ease.InOutSine, yoyo: true, repeat: 1,
});
if (!(await gust)) return;
}
}
  • The camera entity is named Main Camera here. offsetY: -1.5 puts the bend about where the player’s feet are, below the eyes.
  • windStrength is a cheap live prop: changing it rebuilds nothing.
  • The loop waits a random four to nine seconds with delay wrapped in a promise (scripts have no setTimeout), then plays a gust that rises and falls back (yoyo with repeat: 1).
  • await gust resolves false if the tween was stopped, for example when the script is released; the loop then ends.
  • Grass costs only the blades in view; the near band is the expensive part. On phones and headsets, keep quality on auto.
  • Expecting the grass mask to persist. Grass painting shows at once but is kept only after setProps({ mask: { data: grass.encodeMask() } }).
  • Lighting grass with point lights. Grass reads ambient, hemisphere and directional lights only.