Methods
Every public runtime method is documented below as an independently addressable reference entry. Use the URL fragment to link directly to a method.
Configuration & Serialization
setConfig
async setConfig(config = {})Applies a configuration object to an existing system, including type, preset, LOD, interaction, visibility and shadow settings.
Parameters
- config — object.
Returns
Promise<this> — the Grassworks instance for chaining.
Example
await grassworks.setConfig({
maxDistance: 150,
tileSize: 20
});applyConfig
async applyConfig(config = {})Applies a configuration object and is the documented GUI-to-production configuration path.
Parameters
- config — object.
Returns
Promise<this> — the Grassworks instance for chaining.
Example
await grassworks.applyConfig(finalConfig);toJSON
toJSON()Returns a serializable configuration/state snapshot.
Returns
object.
Example
const config = grassworks.toJSON();
console.log(config);Grass
setGrassType
async setGrassType(type)Switches between Blade and Billboard grass without recreating the Grassworks instance.
Parameters
- type — "blade" | "billboard".
Returns
Promise<this> — the Grassworks instance for chaining.
Example
await grassworks.setGrassType("billboard");setPreset
setPreset(name)Applies one of the named Blade presets.
Parameters
- name — string; available Blade preset key.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.setPreset("kentuckyBluegrass");getPreset
getPreset()Returns the current preset key.
Returns
string.
Example
const preset = grassworks.getPreset();
console.log(preset);getPresets
getPresets()Returns the available named Blade preset keys. Billboard returns an empty array.
Returns
string[].
Example
const presets = grassworks.getPresets();setGrassParam
setGrassParam(name, value)Updates one grass parameter at runtime.
Parameters
- name — string; supported grass parameter name.
- value — parameter value.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.setGrassParam("windIntensity", 0.4);setGrassParams
setGrassParams(params = {})Updates multiple grass parameters at runtime.
Parameters
- params — object; parameter/value pairs.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.setGrassParams({
bladeHeight: 2.5,
windIntensity: 0.3
});getGrassParams
getGrassParams()Returns a shallow copy of the current grass parameters.
Returns
object.
Example
const params = grassworks.getGrassParams();Interaction
addInfluence
addInfluence(mesh)Registers an influence object whose nearby presence bends grass.
Parameters
- mesh — THREE.Object3D; influence object.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.addInfluence(carTire);removeInfluence
removeInfluence(mesh)Removes a previously registered influence object.
Parameters
- mesh — THREE.Object3D; registered influence object.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.removeInfluence(carTire);clearInfluences
clearInfluences()Removes all registered influence objects.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.clearInfluences();setInteraction
setInteraction(enabled)Enables or disables the interaction system.
Parameters
- enabled — boolean.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.setInteraction(false);setInfluenceRecoverySpeed
setInfluenceRecoverySpeed(value)Sets how quickly influence effects recover toward the upright state.
Parameters
- value — number; 0–1.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.setInfluenceRecoverySpeed(0.95);setInfluenceWorldSize
setInfluenceWorldSize(value)Sets the world-space coverage of the camera-following interaction map.
Parameters
- value — number; greater than 0.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.setInfluenceWorldSize(80);setInfluenceResolution
async setInfluenceResolution(value)Sets the interaction-map resolution.
Parameters
- value — positive integer.
Returns
Promise<this> — the Grassworks instance for chaining.
Example
await grassworks.setInfluenceResolution(512);setInfluenceDebugPlaneVisible
setInfluenceDebugPlaneVisible(enabled)Shows or hides the influence debug plane.
Parameters
- enabled — boolean.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.setInfluenceDebugPlaneVisible(true);Performance
setLOD
setLOD(name, params = {})Updates one LOD level and immediately re-evaluates the scene.
Parameters
- name — "high" | "medium" | "low" | "veryLow".
- params — object; distance, density and/or detail.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.setLOD("high", {
distance: 0.35,
density: 4,
detail: 4
});setLODConfig
setLODConfig(config = {})Updates one or more LOD levels at once.
Parameters
- config — object containing high, medium, low and/or veryLow configurations.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.setLODConfig({
high: { distance: 0.4 },
medium: { distance: 0.7 }
});getLOD
getLOD(name)Returns the configuration of one LOD level.
Parameters
- name — "high" | "medium" | "low" | "veryLow".
Returns
object.
Example
const high = grassworks.getLOD("high");getLODConfig
getLODConfig()Returns all four LOD configurations.
Returns
object.
Example
const lod = grassworks.getLODConfig();setTileSize
setTileSize(value)Changes the world-space size of grass tiles and recalculates the tile grid.
Parameters
- value — number; greater than 0.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.setTileSize(20);setMaxDistance
setMaxDistance(value)Sets the maximum camera distance at which grass remains visible.
Parameters
- value — number; greater than 0.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.setMaxDistance(150);refresh
refresh()Recalculates tile/grid state and re-evaluates visibility and LOD using the current terrain and configuration.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.refresh();rebuild
rebuild()Rebuilds the current tile grid and re-evaluates visibility.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.rebuild();refreshTerrain
async refreshTerrain()Re-captures the current terrain and rebuilds the terrain-dependent grass state.
Returns
Promise<object>.
Example
await grassworks.refreshTerrain();Scene & Visibility
setCamera
setCamera(camera)Changes the camera Grassworks uses for culling, LOD and interaction follow behavior.
Parameters
- camera — THREE.Camera.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.setCamera(newCamera);setVisible
setVisible(visible)Sets the visible state of generated grass meshes.
Parameters
- visible — boolean.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.setVisible(false);setEnabled
setEnabled(enabled)Enables or disables Grassworks per-frame updating.
Parameters
- enabled — boolean.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.setEnabled(false);setCastShadow
setCastShadow(enabled)Sets generated grass meshes to cast shadows.
Parameters
- enabled — boolean.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.setCastShadow(true);setReceiveShadow
setReceiveShadow(enabled)Sets generated grass meshes to receive shadows.
Parameters
- enabled — boolean.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.setReceiveShadow(true);Runtime GUI
createGUI
createGUI()Creates the runtime authoring GUI and returns it; repeated calls reuse the existing GUI.
Returns
GrassGUI.
Example
grassworks.createGUI();destroyGUI
destroyGUI()Destroys the runtime GUI if one exists.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.destroyGUI();Debugging
setDebugBoxes
setDebugBoxes(enabled)Shows or hides tile debug boxes.
Parameters
- enabled — boolean.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.setDebugBoxes(true);Events
on
on(event, callback)Subscribes to a public Grassworks event.
Parameters
- event — string; public event name.
- callback — function; called with the event payload.
Returns
this — the Grassworks instance for chaining.
Example
grassworks.on("ready", (instance) => {
console.log(instance);
});off
off(event, callback)Removes one event callback, or all callbacks for an event when callback is omitted.
Parameters
- event — string; public event name.
- callback — function; optional callback to remove.
Returns
this — the Grassworks instance for chaining.
Example
const callback = (payload) => console.log(payload);
grassworks.on("ready", callback);
grassworks.off("ready", callback);Lifecycle
dispose
dispose()Disposes Grassworks resources, removes its generated scene state and marks the instance disposed.
Returns
void.
Example
grassworks.dispose();