A mower that cuts the grass it drives over
Updated
Drag a mower across a lawn and it cuts a strip through the grass, saving the mowed area to the grass mask a second after it stops: a Grass component painted by a Behavior script.
Drag the amber mower over the grass, then let go: "Lawn saved" appears in the log. Drag the background to orbit the camera, scroll to zoom.
A mower that cuts the grass it drives over
#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();}How it works
Section titled “How it works”The script is explained step by step in A mower that cuts the grass it drives over.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
GrassMower.xrproj