Grassworks

The Grassworks class is the public entry point for the library. Grassworks 1.0.0 targets Three.js 0.185.0 and requires WebGPU through WebGPURenderer.

Import

import Grassworks from "./grassworks.min.js";

Reference sections

Initialization and lifecycle

create

js
static async create(config = {})

Creates a Grassworks instance, initializes it and resolves with the ready system.

Parameters

  • config — object; configuration object.

Behavior

The normal creation path initializes the system before the returned promise resolves.

Validation

The configuration must include the required camera, scene, renderer, terrain, tileSize and maxDistance values; invalid configuration rejects initialization.

Returns

Promise<Grassworks>.

Example

js
const grassworks = await Grassworks.create({
  camera,
  scene,
  renderer,
  terrain,
  tileSize: 25,
  maxDistance: 200
});

init

js
async init()

Initializes the Grassworks system. Grassworks.create() calls this for the normal setup flow.

Behavior

The normal API flow is Grassworks.create(config); manual construction plus init() is available but create() is the canonical path.

Returns

Promise<void>.

Example

js
const grassworks = new Grassworks(config);
await grassworks.init();

update

js
update(clock)

Advances Grassworks per frame. The shipped example passes the current THREE.Timer instance.

Parameters

  • clock — THREE.Timer instance used by the current update contract.

Behavior

Call this from the render loop after updating the THREE.Timer. Grassworks performs its normal per-frame tile, interaction and LOD work through this call.

Returns

this — the Grassworks instance for chaining.

Example

js
timer.update();
grassworks.update(timer);