Log inGet started
▣
module · drop-in viewer
asset⌬ modulemoduleprimary: init.luau·part ofmodule renderer.module·originates fromworld 07158574-5…

mesh

`renderer.mesh`: the ZMSH codec, the guid-keyed CPU mesh store, the GPU meshes created from it, their clusters and level of detail, and the instanced draws of a mesh.

by◐lumi·posted 5d ago
What it does

renderer.mesh

renderer.mesh: the ZMSH codec, the guid-keyed CPU mesh store, the GPU meshes created from it, their clusters and level of detail, and the instanced draws of a mesh.

Interface

What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.

conforms to

zero/source-extract/v2

module renderer.mesh global renderer renderer.mesh: the mesh codec, the CPU store and the GPU meshes, their clusters and their instanced draws.

encode(geom: MeshGeometry) →

Encode raw geometry into engine-native `ZMSH` bytes (the on-disk mesh payload). The CPU codec behind the mesh assetType's `onCreate`. Every stream the format carries — including tangents, per-vertex skinning, and the skeleton — round-trips back through `renderer.mesh.decode`. This pair moves DATA the caller is holding; the geometry of a mesh the ENGINE is holding comes from `renderer.mesh.geometry(mesh)`. (nil, errmsg) naming what the geometry could not describe.

argtypedescription
geomMeshGeometry`MeshGeometry` — flat per-vertex float / u32 arrays plus optional `skinning` and `skins`.

examples

local bytes = renderer.mesh.encode({ positions = {...}, indices = {...} })
local bytes = renderer.mesh.encode(renderer.mesh.geometry(meshHandle))

decode(zmsh: buffer | string) →

Decode engine-native `ZMSH` bytes back into a `MeshGeometry`. Inverse of `renderer.mesh.encode`; each optional stream is present only when the blob carries it. Takes the bytes themselves — the geometry of a mesh the engine is holding comes from `renderer.mesh.geometry(mesh)`.

argtypedescription
zmshbuffer | stringEngine-native ZMSH bytes (binary-safe).

examples

local geom = renderer.mesh.decode(meshRef:getBytes())

isResident(mesh: string | { [string]: any } | AssetRef) → boolean

True if a GPU mesh is resident under this mesh's guid — the device holds its buffers, or the upload queued this frame is still going to hand them over. This is the store the draw paths are gated on, so a mesh this reports resident is one `renderer.mesh.drawInstanced` and a `Model` can draw — from the frame after the upload commits: a render asked for in the same tick the upload was queued does not carry the mesh yet. `renderer.mesh.onDevice` is the answer that waits for that commit.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh — a `MeshHandle`, a `MeshCpuHandle`, a guid, or a mesh `AssetRef`.

examples

print(renderer.mesh.isResident(handle))

onDevice(mesh: string | { [string]: any } | AssetRef) → boolean

True once the device holds this mesh's buffers — the upload queued for it has committed — so the next render asked for carries the mesh. `renderer.mesh.isResident` answers true one frame earlier, while the upload is still queued; a reader about to render and read the picture back waits on this one.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh — a `MeshHandle`, a `MeshCpuHandle`, a guid, or a mesh `AssetRef`.

examples

while not renderer.mesh.onDevice(guid) do task.wait() end

heldOffDevice(mesh: string | { [string]: any } | AssetRef) → boolean

True while the engine holds this mesh off the device: nothing displays it, so its GPU buffers were given back and the engine keeps what rebuilds them. The next `Model` or instanced draw that names the mesh puts it back on the device, where `renderer.mesh.isResident` reads true again from the frame that bind lands in. A mesh is one of three things: resident, held off the device, or gone; a mesh neither this nor `isResident` answers true for names nothing the engine can draw.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh: a `MeshHandle`, a `MeshCpuHandle`, a guid, or a mesh `AssetRef`.

examples

local named = renderer.mesh.isResident(h) or renderer.mesh.heldOffDevice(h)

morphTargets(mesh: string | { [string]: any } | AssetRef) →

The names of the shapes this mesh blends towards, in the order an entity's `ecs.MorphWeights` addresses them — weight `i` drives the target named at `i`. An imported model carries the names its source file gave its blend shapes, so content drives a face by the shape it means rather than by the ordinal that shape happened to import at (which moves when the model is re-exported). A target the source never named reads as an empty string. Empty for a mesh with no morph targets. Errors when the mesh is neither GPU- nor CPU-resident — materialise it first (`meshRef:handle()`).

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh — a `MeshHandle`, a `MeshCpuHandle`, a guid, or a mesh `AssetRef`.

examples

for i, name in renderer.mesh.morphTargets(meshRef) do print(i, name) end

bounds(mesh: string | { [string]: any } | AssetRef) → Aabb

The mesh's extent in its own space: the box its vertices span, or the one its author stated (`aabbMin` / `aabbMax`) for a mesh whose vertices live only on the GPU. It is what the mesh is culled against and what framing reads; place it in the world through whatever draws the mesh — an entity's transform, or `instanceBounds` for an instanced population. A mesh asset nothing has drawn yet answers the box of its stored geometry: read from its CPU copy when one is resident, else from its stored bytes, which are read for the call and released again, so the mesh is left as resident as it was. answers to, or whose extent nobody knows.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh — a `MeshHandle`, a `MeshCpuHandle`, a guid, or a mesh `AssetRef`.

examples

local box = renderer.mesh.bounds(asset.resolve("@builtin::meshes.torus", "mesh"))

boundsSource(mesh: string | { [string]: any } | AssetRef) → string

Where this mesh's culling bounds come from. `"compute"` once a compute pass has written its vertices: the engine reduces those vertices to an AABB every frame, so the mesh is culled against the geometry the pass produced wherever it puts it. `"geometry"` otherwise: the AABB of the geometry the mesh was created with.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh — a `MeshHandle`, a `MeshCpuHandle`, a guid, or a mesh `AssetRef`.

examples

print(renderer.mesh.boundsSource(mesh))

canBuildClusters( ) → boolean

Whether this engine bakes cluster-LOD hierarchies. It reads the binding the running engine registered: every target the engine ships on carries the builder, so a mesh loaded in a browser bakes its own clusters the same way one loaded natively does, and an engine built without it reports false and answers nil from `renderer.mesh.buildClusters`.

examples

if renderer.mesh.canBuildClusters() then ... end

buildClusters(mesh: string | { [string]: any } | AssetRef) → string

Build a cluster-LOD DAG (Nanite-style virtualized geometry) for the static CPU mesh held under `guid` and return its serialized `data.clusters` bytes. Returns nil when the mesh is degenerate, and on an engine whose `renderer.mesh.canBuildClusters` reports false. Pair with `renderer.mesh.uploadClusters`. `MeshCpuHandle`, a `MeshHandle`, a guid, or a mesh `AssetRef`.

argtypedescription
meshstring | { [string]: any } | AssetRefA mesh loaded into the CPU store (`renderer.mesh.loadCpu`) — the

examples

local cb = renderer.mesh.buildClusters(cpu)

scheduleClusters(mesh: string | { [string]: any } | AssetRef, opts: { levels: string?, defer: boolean? }?) → boolean

Queue a cluster bake over the mesh's geometry, off the frame loop. The mesh keeps drawing its current cluster set while the bake runs, and the set the bake produces replaces it when it lands. `opts.levels` is `"dag"` for the LOD hierarchy or `"single"` for one level of clusters at full detail; when omitted, a mesh `AssetRef` bakes the depth its `clusterLod` setting asks for and any other argument bakes `"dag"`. The CPU mesh may be unloaded on the very next line. Geometry with a triangle joining two independently moving parts leaves the queue unbaked with a warning; a mesh `renderer.mesh.clusters` reports as `"deformable"` or `"heapFull"` leaves it unbaked without one. The queue runs `renderer.mesh.clusterBakes().concurrency` bakes at once whatever geometry they hold, and more while what the running ones hold is under `renderer.mesh.clusterBakeHeldBytes`, and a bake reads its geometry when it starts, once the mesh's GPU upload has landed, from the definition the engine holds for the mesh. The queue therefore holds the geometry of the bakes it runs rather than one copy per mesh queued, whatever their depth, and the set installs only on the geometry it was read from: a mesh whose geometry is replaced before its set lands keeps the set of its new geometry. The set is held to its mesh and encoded off the frame too, and the frame places finished sets until it has spent the bake budget. A finished set is kept by the geometry it was built from, so a mesh of geometry baked before (shown again after it left the device, created again, or a second mesh of the same geometry) takes that set and walks nothing. `renderer.mesh.clusterBakes().heldBytes` reports what the queue is holding, and its `inFlight` rows report which bakes it is holding for. This is what the `.mesh` assetType materialisation path uses; reach for `renderer.mesh.buildClusters` when you want the bytes in hand instead. Scheduling the same mesh again replaces the bake already in flight for it. mesh `AssetRef`, loaded into the CPU store (`renderer.mesh.loadCpu`). a previously registered off-device mesh remembers this explicit depth for its next upload without loading a CPU copy. An unknown guid returns false. A resident mesh still requires its CPU copy. or being created under its guid.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh to bake — a `MeshHandle`, a `MeshCpuHandle`, a guid, or a
opts{ levels: string?, defer: boolean? }?`{ levels: "dag" | "single", defer: boolean? }?`. With `defer = true`,

examples

renderer.mesh.scheduleClusters(cpu, { levels = "single" }) ; cpu:unload()

clusterBakes( ) →

What the scheduled cluster bakes are costing. `budgetMs` is the slice a frame may spend, `pending` how many bakes are queued, `completed` how many have finished since the engine started, `dropped` how many left the queue because the geometry they were scheduled over stopped being readable or cannot be drawn as clusters, and `heldBytes` the source geometry the queue is holding across all of them — the vertex pools and index runs the running bakes are reading. `walks` is how many bakes have walked their geometry to a hierarchy since the engine started (a bake that takes a kept set walks nothing), `frameMs` the most the queue's work (starting and landing bakes, installing their sets) cost the frame thread on one of the last eight frames, `concurrency` how many bakes run at once whatever they hold (more run while what they hold is under `renderer.mesh.clusterBakeHeldBytes`), `running` how many bakes are out on the off-frame workers now and `runningBytes` the geometry they hold there, which is what the next bake to start is counted against (a bake whose mesh is destroyed, or whose geometry is replaced, stops counting the frame it leaves the queue), and `cache` the finished sets kept by the geometry they were built from — `{ entries, bytes, capBytes, hits, misses }`. `inFlight` is one row per queued bake — `{ guid, cpuMs, frames, slices, bytes, state, levels }`: the wall time spent advancing it, the frames it has been queued for, the slices it has been advanced by, the geometry it is holding, `"baking"` for a bake started (its set placed once it finishes) against `"queued"` for the ones waiting their turn, and `levels` the depth the bake builds, `"dag"` or `"single"`.

examples

print(renderer.mesh.clusterBakes().heldBytes)

clusterBakeBudget(ms: number?) → number

The wall time one frame may spend advancing scheduled cluster bakes, in milliseconds — set first when `ms` is given. A slice always runs at least one unit of the build, so the budget bounds what a frame spends by choice and the largest single unit a mesh imposes sets the floor under it. not a positive, finite number raises.

argtypedescription
msnumber?New per-frame budget in milliseconds, capped at 1000. A value that is

examples

renderer.mesh.clusterBakeBudget(2)

clusterBakeHeldBytes(bytes: number?) → number

The source geometry, in bytes, the scheduled cluster bakes running off the frame may hold together before a frame stops starting more of them than `renderer.mesh.clusterBakes().concurrency` — set first when `bytes` is given. That many bakes start whatever they hold, and more start while what the running ones hold is under this bound, so the many small meshes a world load brings in bake together and large ones a few at a time. or more raises.

argtypedescription
bytesnumber?New bound in bytes. A value that is not a finite number of zero

examples

renderer.mesh.clusterBakeHeldBytes(16 * 1024 * 1024)

uploadClusters(mesh: string | { [string]: any } | AssetRef, clusters: string) → boolean

Replace the cluster set a mesh draws with a serialized set (bytes from `renderer.mesh.buildClusters`), built from the geometry the mesh holds as the call is made. A set whose vertex count, vertex maps or nodes do not describe the mesh, or one whose mesh's geometry is replaced before it lands, is refused with a warning, and the mesh keeps its current set and the set it was asked for. Once the set is installed, a bake still in flight for the mesh is cancelled, and the engine keeps the bytes on the CPU (`renderer.mesh.clusterStore().scriptSetBytes`) so the mesh draws this set again when it returns to the device after nothing displayed it, or after the device is rebuilt. The bytes go when the mesh's geometry is redefined, when `renderer.mesh.dropClusters` returns it to `lod0`, and when the mesh is destroyed. not landed yet.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh the clusters belong to — a `MeshHandle`, a `MeshCpuHandle`, a guid, or a mesh `AssetRef`.
clustersstringSerialized cluster bytes (binary-safe).

examples

renderer.mesh.uploadClusters(gpu, cb)

clusters(mesh: string | { [string]: any } | AssetRef) →

The cluster set a mesh draws. Every static mesh the geometry heap holds draws through clusters: `kind` is `"lod0"` while it draws the full-detail set built from its geometry as it uploaded, `"single"` for one baked level (`clusterLod = false`), and `"dag"` for the baked LOD hierarchy. `clusterCount`, `levelCount` and `triangleCount` describe that set, `nodes` how many node transforms its clusters lie in, and `bytes` its size in the heap. A mesh that is not drawn through clusters reads `resident = false` with `reason`: `"heapFull"` (the heap cannot grow to hold it), `"spansNodes"` (a triangle joins two independently moving parts) or `"deformable"` (a pass deforms its vertices). Nil for a mesh the renderer holds no GPU geometry for. `bake` is the state of the bake queued for the mesh, `"queued"` or `"baking"` as `renderer.mesh.clusterBakes().inFlight` reports it, with `bakeLevels` the depth it builds; both are nil when no bake is queued. `status` reads the two together: `"queued"` or `"baking"` while a bake is in flight; otherwise `"adaptive"` for a `dag` set, `"singleLevel"` for a `single` set, `"unbaked"` for a mesh drawing `lod0` with no bake queued (nothing asked for its hierarchy, or its bake left the queue without installing one), and `"excluded"` for a mesh kept out of cluster drawing, whose `reason` says why.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh to read — a `MeshHandle`, a `MeshCpuHandle`, a guid, or a mesh `AssetRef`.

examples

local c = renderer.mesh.clusters(gpu) ; if c then print(c.status, c.kind, c.bake) end

clusterStore( ) →

What the geometry heap holds for cluster drawing. `heapCapacity` and `heapLive` are the heap's size and the bytes in use. The heap grows to place what does not fit, and gives memory back as meshes leave it: once what it holds has packed into a quarter of its size for 60 frames in a row, it shrinks to double that, never below the size it started at. A mesh destroyed and created again inside those frames finds the heap at the size it left it. `vertexBytes` and `lightmapBytes` are the vertex pools and lightmap-UV runs of the meshes drawn through clusters. `bakedBytes` is the cluster sets of meshes drawing a baked set; `unbakedBytes` is the sets of meshes still drawing `lod0` plus those meshes' vertex pools — geometry drawn at full detail while its bake is outstanding. `meshes` counts meshes drawing any set, `unbakedMeshes` those on `lod0`. `scriptSetBytes` is CPU memory beside the heap: the sets scripts installed with `renderer.mesh.uploadClusters`, held so each mesh draws its set again after it returns to the device.

examples

local s = renderer.mesh.clusterStore(); print(s.unbakedBytes / 1048576, "MiB drawn at full detail while bakes are outstanding")

dropClusters(mesh: string | { [string]: any } | AssetRef) → boolean

Return a mesh to its `lod0` set and cancel a bake still in flight for it. `lod0` stays the set the mesh draws: it draws it again when it until `renderer.mesh.scheduleClusters` or `renderer.mesh.uploadClusters` asks for another. The inverse of `renderer.mesh.uploadClusters`.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh to return — a `MeshHandle`, a `MeshCpuHandle`, a guid, or a mesh `AssetRef`.

examples

renderer.mesh.dropClusters(gpu)

clusterComponents(clusterBytes: buffer | string) →

Split a cluster blob (from `renderer.mesh.buildClusters`) into its GPU-ready component byte pools — the cluster vertex pool, the geometry-addressing pool (every cluster's local→global vertex map, then every cluster's triangle bytes), and the per-cluster record array — plus their counts. A cluster's triangles address positions inside its own vertex map one byte at a time, and a record's `vertexOffset` indexes the geometry pool in `u32` elements while its `indexOffset` indexes it in bytes, so ONE binding resolves a corner. A pure decode (no GPU work): upload the pools into buffers a compute shader owns (`shaderRef:createBuffer` + `buf:writeBytes`) to drive a cluster draw from Luau.

argtypedescription
clusterBytesbuffer | stringSerialized cluster bytes (binary-safe).

examples

local c = renderer.mesh.clusterComponents(cb)

encodeCpu(mesh: string | { [string]: any } | AssetRef) → string

Encode a mesh's resident CPU copy into `ZMSH` bytes. Reads the ONE guid-keyed CPU store — `meshRef:load()` populates it for assets, and `renderer.mesh.readback(mesh)` populates it for a runtime mesh. Errors loudly when the mesh has no resident CPU copy.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh — a `MeshHandle`, a `MeshCpuHandle`, a guid, or a mesh `AssetRef`.

examples

local bytes = renderer.mesh.encodeCpu(handle)

isCpuResident(mesh: string | { [string]: any } | AssetRef) → boolean

True if this mesh has a resident CPU copy in the guid-keyed CPU store.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh — a `MeshHandle`, a `MeshCpuHandle`, a guid, or a mesh `AssetRef`.

examples

if renderer.mesh.isCpuResident(handle) then ... end

noCpuMeshRemedy(guid: string) → string

The three routes that put a mesh's geometry in the guid-keyed CPU store, said the same way wherever a read or an in-place write finds the store empty.

argtypedescription
guidstring

getVertices(mesh: string | { [string]: any } | AssetRef) →

Read the vertices of a mesh's resident CPU copy — one entry per vertex, `{ pos = {x,y,z}, normal = {x,y,z}, uv = {u,v} }`. Reads the resident CPU store directly (no re-decode). Errors when the mesh has no resident CPU copy — `renderer.mesh.geometry(mesh)` is the read that works wherever the mesh lives, and returns the tangent, colour and skinning streams too. Each record carries `pos`, `normal`, `uv` and `uv1` as named channels (`{ x = , y = , z = }`). Geometry going the other way — into `renderer.mesh.create` — is parallel flat arrays (`positions`, `normals`, `uvs`), and `create` accepts this record list under `vertices` so a mesh read back here can go straight into a new one.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh — a `MeshHandle`, a `MeshCpuHandle`, a guid, or a mesh `AssetRef`.

setVertices(mesh: string | { [string]: any } | AssetRef, positions: { number }) → void

Replace a mesh's resident CPU vertex positions (flat `{ x,y,z, ... }`) IN PLACE — indices, normals/uvs, and skinning are preserved, the AABB recomputes, and the GPU re-fetches the new geometry so it shows on screen. The positions alone travel, so this is the per-frame deformation path where `renderer.mesh.update` re-sends the whole geometry. The mesh must be CPU-resident: `renderer.mesh.create({ ..., keepCpu = true })` keeps a copy from the start, `renderer.mesh.readback(mesh)` recovers one from the GPU, and `meshRef:load()` loads one for a `.mesh` asset. Errors with the reason otherwise, or when the vertex count doesn't match.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh — a `MeshHandle`, a `MeshCpuHandle`, a guid, or a mesh `AssetRef`.
positions{ number }Flat `{ x,y,z, ... }` — one xyz per vertex; count must match the mesh.

examples

local m = renderer.mesh.create({ positions = P, indices = I, keepCpu = true })
renderer.mesh.setVertices(m, P) -- P mutated in place each frame

unloadCpu(mesh: string | { [string]: any } | AssetRef) → void

Drop a mesh's resident CPU copy from the guid-keyed CPU store. The explicit release for a runtime geometry mesh's recoverable definition.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh — a `MeshHandle`, a `MeshCpuHandle`, a guid, or a mesh `AssetRef`.

wrapMeshCpuHandle(guid: string, vertexCount: number, indexCount: number) → MeshCpuHandle

Build a `MeshCpuHandle` over the guid-keyed CPU store: read (triangles / vertices / bounds) + encode + unload, each reading the Rust-side store. Shared by `loadCpu` (Disk→CPU) and `readback` (GPU→CPU) — both populate the store under `guid`, then hand out this handle.

argtypedescription
guidstring
vertexCountnumber
indexCountnumber

cpuRead(op: string, value: any) → any

Every read goes through the guid-keyed CPU store. A read after the store entry was dropped (`handle:unload()`, or the default drop-after-GPU-upload lifecycle) errors with the remedy instead of returning nil into arithmetic three frames later.

argtypedescription
opstring
valueany

getTriangles(_self: ?) → void

argtypedescription
_self?

getVertices(_self: ?) → void

argtypedescription
_self?

getBounds(_self: ?) → void

argtypedescription
_self?

geometry(_self: ?) → MeshGeometry

argtypedescription
_self?

encode(_self: ?) → string

argtypedescription
_self?

unload(_self: ?) → void

argtypedescription
_self?

loadCpu(ref: string | AssetRef, into: string?) → MeshCpuHandle

Load a `.mesh` asset's geometry into the ONE guid-keyed CPU store (the Disk→CPU step) and return a CPU handle. The handle holds NO geometry — only the guid plus counts and the per-handle read/encode/unload ops (which read the Rust-side store). Called by `meshRef:load()`. DEFAULT lifecycle: upload to the GPU then `handle:unload()`; the store is populated only by this call. The CPU store is keyed by guid and shared by everything that reads the mesh, so a copy under the asset's own guid is one any other reader can drop. `into` lands the copy under a key of the caller's own instead: the handle answers for that key, the asset's own entry is left as it was, and the copy stays resident until the caller unloads it. or any string `asset.ref` resolves to one — the guid `encodeCpu` takes, an identity, a name or a source path.

argtypedescription
refstring | AssetRefA mesh `AssetRef` (carries `.guid` and reads its primary via getBytes),
intostring?The CPU-store key the geometry lands under. Defaults to the asset's own guid.

examples

local cpu = meshRef:load(); local gpu = renderer.mesh.create(cpu); cpu:unload()
local cpu = renderer.mesh.loadCpu(gpuMesh.guid)
local own = renderer.mesh.loadCpu(meshRef, "bake:" .. meshRef.guid); own:unload()

destroy(mesh: string | { [string]: any } | AssetRef) → boolean

Release the GPU mesh `mesh` names, the release that pairs with `renderer.mesh.create`. Takes every form that names a mesh — the `MeshHandle` `create` returned, the guid `renderer.mesh.list` hands out, a `MeshCpuHandle` or a mesh `AssetRef` — and routes through `renderer.destroy`, the verb that releases any renderer resource by its kind. The CPU copy, if one was loaded, is freed separately by the CPU handle's `:unload()`. mesh `AssetRef`.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh to release — a `MeshHandle`, a guid, a `MeshCpuHandle` or a

examples

local m = renderer.mesh.create(cpu); renderer.mesh.destroy(m)
renderer.mesh.destroy(renderer.mesh.list()[1].guid)

readback(mesh: string | { [string]: any } | AssetRef, into: string?) → MeshCpuHandle

Read a runtime GPU mesh's geometry back to CPU and return a `MeshCpuHandle` for it — the GPU→CPU half of the runtime-mesh freeze path. A mesh made with `renderer.mesh.create` keeps no CPU copy, so persisting it (`:encode()` → `asset.create("mesh", …)`) reads it back here first. Yields until the readback completes (a frame or two). After it returns the geometry is resident in the guid-keyed CPU store: `:getTriangles`, `:getVertices`, `:getBounds`, `:geometry`, `:encode`, `:unload` all work. Errors if the mesh never becomes resident in the vertex pool. The CPU store is keyed by guid and shared by everything that reads the mesh, and whatever owns the mesh can retire the copy under its own guid: `renderer.mesh.update` from compute buffers unloads it, which an ocean surface does every frame it steps. `into` lands the copy under a key of the caller's own instead: the handle answers for that key, and it stays resident until the caller unloads it, whatever happens to the mesh.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh — the `MeshHandle` `renderer.mesh.create` returned, a guid, or a mesh `AssetRef`.
intostring?The CPU-store key the geometry lands under. Defaults to the mesh's own guid.

examples

local cpu = renderer.mesh.readback(handle); local zmsh = cpu:encode(); cpu:unload()
local snap = renderer.mesh.readback(handle, "bake:" .. handle.guid); local tris = snap:getTriangles(); snap:unload()

readbackPosed(requests: { { entity: string, mesh: any, into: string? } }) →

Read the POSED geometry of skinned entities back to CPU: for each request, the vertices the skinning pass wrote for that entity this frame, joined by the indices of the mesh it is posed from. A skinned surface's world-space triangles are produced on the GPU from the entity's joint matrices, so the mesh asset holds the bind pose and only this reads where the surface actually is. The posed vertices are in model space, so the entity's own world transform still places them — the same transform the raster draw uses. Takes a LIST and answers a map, because the readbacks are queued together and polled together: a scene's worth of characters costs the frames of one readback rather than one entity's after another. Each posed mesh lands in the CPU store under a guid of its own, derived from the entity, so `compute.buildBvh`, `meshcpu.*` and every other guid-keyed reader takes it like any other mesh. Call `handle:unload()` when done with it. A request's `into` lands that entity's copy under a key of the caller's own, which no other read of the same entity replaces or drops. An entity the map omits holds no live pose — nothing skinned it this frame, which is also what makes its draws read the source mesh, so its bind-pose geometry is what stands for it. The vertices read are ones the skinning pass wrote for the pose the entity is bound to. An entity bound to a pose that pass has not written yet — the frame it was posed, before the pass reached the queue — is asked again on the next frame rather than read from a slice still holding what stood there before.

argtypedescription
requests{ { entity: string, mesh: any, into: string? } }`{ { entity = <id>, mesh = <mesh>, into = <key>? } }` — the entity to read, the mesh it is posed from (a guid, `MeshHandle` or mesh `AssetRef`), and the CPU-store key its copy lands under (default `"posed:" .. entity`).

examples

local posed = renderer.mesh.readbackPosed({ { entity = id, mesh = ecs.get(id, ecs.Mesh).mesh } })
local tris = posed[id]:getTriangles()

geometry(mesh: string | { [string]: any } | AssetRef) → MeshGeometry

The complete geometry of a mesh the engine is holding, as a `MeshGeometry` — the same shape `renderer.mesh.create` and `renderer.mesh.encode` take, carrying every stream the mesh has (`positions`, `indices`, and whichever of `normals`, `uvs`, `colors`, `uvs1`, `tangents`, `skinning`, `skins` it was built with). The read that pairs with `create`: hand it the `MeshHandle` `create` returned and get the vertex data back. Reads the resident CPU copy when there is one; for a runtime mesh that lives only on the GPU it reads the geometry back off the GPU first (yielding a frame or two) and leaves CPU residency as it found it. An optional stream is present only when the mesh carries one, so `uvs1 == nil` is the answer to whether it has a second UV set. The drawable mesh the renderer holds carries the tangent basis its positions, uvs and normals determine — supplied by the caller, or derived at the ingest that made it drawable — and that is what the GPU read gives back. The CPU store answers with the streams the bytes it decoded hold, so a `.mesh` written without a tangent stream reads back `tangents == nil` for as long as a CPU copy of it is resident.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh — a `MeshHandle`, a `MeshCpuHandle`, a guid, or a mesh `AssetRef`.

examples

local geom = renderer.mesh.geometry(renderer.mesh.create({ positions = P, indices = I }))
local tangents = renderer.mesh.geometry(handle).tangents

retainCpuCopy(guid: string, src: any, what: string) → void

Seed the guid-keyed CPU store from the geometry a runtime mesh is made of, so `getVertices` and the in-place `setVertices` reach it with no GPU→CPU readback. The codec is the one a `.mesh` asset decodes through, so every stream the geometry carries arrives in the store.

argtypedescription
guidstring
srcany
whatstring

keepFullDetail(guid: string, keep: boolean) → void

Record whether the mesh `renderer.mesh.create` put on the device under `guid` draws its full-detail set.

argtypedescription
guidstring
keepboolean

request(guid: string, levels: string, fresh: boolean) → void

Ask for the cluster set the mesh under `guid` draws by default. `fresh` says this call uploaded the mesh's buffers. The engine keeps the set the mesh was last asked for (a bake depth, a script's set, or `lod0` from `renderer.mesh.dropClusters`), leaves a bake already in flight running, and otherwise bakes `levels` over the definition it holds for the mesh, with no CPU copy needed.

argtypedescription
guidstring
levelsstring
freshboolean

forPopulation(guid: string) → void

Ask for the cluster set of a mesh a population draws, whichever way the mesh reached the device. A mesh no set was asked for bakes at the depth its asset's `clusterLod` setting names, or the hierarchy when no asset answers for it; one held off the device is owed that bake for when it returns. A mesh `renderer.mesh.create` made to draw its full-detail set keeps it, and a set asked for earlier stands.

argtypedescription
guidstring

assetSettings(guid: string, what: string) → void

The settings of the mesh asset under `guid`, or nil when no asset answers for it. A read that raises is reported under `what`, the call that asked, and reads as the defaults.

argtypedescription
guidstring
whatstring

depth(clusterLod: any) → string

The cluster depth a `clusterLod` value asks for: one level when false, the LOD hierarchy otherwise.

argtypedescription
clusterLodany

srcClusterLod(src: any) → boolean

The `clusterLod` field of a geometry or `zmsh` src: nil, true or false.

argtypedescription
srcany

recordMeshFacts(guid: string, vertexCount: number?, indexCount: number?) → void

argtypedescription
guidstring
vertexCountnumber?
indexCountnumber?

listRuntimeResources(kind: string, enrich: ((string, { [string]: any }) → void

Every runtime resource of one kind, from the registry each create path stamps. `enrich` adds the per-kind facts to an entry.

argtypedescription
kindstring
enrich((string, { [string]: any }

create(src: any, guid: string?) → MeshHandle

Create (or fetch) a GPU mesh resource and return its `MeshHandle`. `src`: a `MeshCpuHandle` from `meshRef:load()` (CPU→GPU upload under the asset's guid, idempotent — returns the resident handle if already uploaded); raw geometry `{positions, indices, normals?, uvs?, colors?, uvs1?, unwrapUvs?, tangents?, skinning?, skins?}` (a new runtime mesh — `uvs1` is the lightmap UV set, `unwrapUvs` generates one, `skinning`/`skins` bind a skeleton); engine-native `ZMSH` bytes `{ zmsh, name?, keepCpu? }` (a new runtime mesh the engine decodes and uploads itself, every stream the bytes carry included, with no geometry crossing into Luau — the bytes `renderer.mesh.encode` and `renderer.mesh.encodeCpu` answer); GPU compute buffers `{vertexBuffer, indexBuffer, vertexCount, indexCount, aabbMin?, aabbMax?, prevVertexBuffer?}` (size the vertex buffer at `vertexCount * engine.vertexStride` bytes, the engine's standard Vertex layout); or a `MeshHandle` (returned as-is). NEVER takes an AssetRef — load the CPU first. `prevVertexBuffer` is a second buffer of the same size and layout holding those vertices as they stood on the previous frame. Naming it is what makes geometry a compute pass moves report a motion vector: the surface differences the two streams, so every consumer of screen-space velocity — motion blur, temporal reprojection — sees the movement. Ahead of each frame's compute dispatches the engine makes it equal to the current vertices, copying them on a frame after something wrote them, so a frame in which the pass does not run leaves the two streams equal and the geometry reports standing still. `morphTargets` are the shapes the mesh can blend towards: a list of `{ name?, positions, normals? }` records, each holding one offset per vertex from the base geometry, in the mesh's own vertex order. An entity blends them with `ecs.MorphWeights`, weight `i` scaling target `i`. A `name` makes the shape addressable as itself — `renderer.mesh.morphTargets` reads the names back and `renderer.mesh.morphWeights` drives them by name. Raw geometry is read against the mesh type's conventions: `indices` count vertices from 0, and a triangle's FRONT face is the one whose vertices turn counter-clockwise as the viewer sees them — `cross(v1 - v0, v2 - v0)` points out of it. A material culls its back faces by default, so a triangle wound the other way draws nothing where it stands; reverse the index triple, or give the material `render = { cull = "none" }`, to draw that side. `normals` give the surface its outward direction and shade the face; the side that draws comes from the index order alone. `uvs` sample `(0,0)` at the image's top-left. Model space carries the world's basis: +X right, +Y up, -Z the direction `transform.forward` points. `guides { path = "types/mesh" }` has the whole table. A geometry src carrying `keepCpu = true` also keeps its geometry in the guid-keyed CPU store, so `renderer.mesh.getVertices` reads it and `renderer.mesh.setVertices` rewrites its positions in place — the per-frame deformation path, which sends positions alone where `renderer.mesh.update` re-sends the whole geometry. `renderer.mesh.unloadCpu(mesh)` releases that copy. Without it the geometry lives on the GPU alone and `renderer.mesh.readback(mesh)` is what brings it back. A mesh this call builds lives while the returned handle, or another handle over the same guid, is reachable from a script, or while something else holds it (an entity or instanced draw displaying it, its owner, a `renderer.hold`). The owner is the component instance whose code ran the create, or the scene load whose own code (its entrypoint) ran it, so a component a scene load attaches owns what it builds while the load runs; a mesh a component's task built stops being its owner's once that task is cancelled, and a mesh a component's life built stops being its owner's once that life ends (a hot reload of its script, an `awake()` that raises, a watchdog halt, the component's removal or its entity's despawn). Once nothing holds it and the garbage collector has taken its last handle, the engine releases it mid-session: its definition, its buffers and its `renderer.mesh.list` row go, and its guid names nothing. A script that displays a mesh again later keeps its handle (or holds it) for as long as it means to. A handle a script keeps names its mesh for the rest of the session: a module table or `_SCRATCH` holding it carries it across play/edit flips, scene loads and hot reloads of the components that use it, and a `Model` handed it after any of them draws the mesh. While nothing displays the mesh, the engine holds it off the device (`renderer.mesh.heldOffDevice`) and the next display puts it back. Only a destroy ends a mesh a handle still reaches (`renderer.destroy`, `renderer.mesh.destroy`): every handle a create returned over it then carries `released`, the verb that released it, and a point of use (`ecs.Mesh`, a `Model`'s `model` field) refuses such a handle by name until a mesh stands under its guid again, which the handle then names and holds. Static geometry draws through an adaptive cluster set by default. The call that uploads a mesh asks for its cluster bake, which runs off the frame over the geometry the engine holds, so no CPU copy is needed: the LOD hierarchy, or one level of clusters when `clusterLod` is false — the asset's setting for a `MeshCpuHandle` (`meshRef:load()`, whose copy may be unloaded on the next line), and the src's own `clusterLod` field for geometry and `zmsh` bytes. Geometry carrying `keepCpu`, `morphTargets`, `skinning` or `skins` draws the full-detail set it uploaded with. The mesh draws `lod0` until the bake lands, and `renderer.mesh.clusters(mesh).status` reads `"queued"` or `"baking"` meanwhile. A set asked for the mesh earlier (`renderer.mesh.scheduleClusters`, `renderer.mesh.uploadClusters`, or `lod0` through `renderer.mesh.dropClusters`) is the one it draws again when this call uploads it anew. Creating a mesh again while it is on the device returns the resident mesh and leaves its set and any bake in flight as they are. absent). Ignored for the CPU-handle path (the asset's guid is used).

argtypedescription
srcanyA MeshCpuHandle, geometry, compute buffers, or a MeshHandle.
guidstring?Optional v4 guid for a NEW runtime mesh (minted Luau-side when

examples

local gpu = renderer.mesh.create(meshRef:load())
local gpu = renderer.mesh.create({ positions = {...}, indices = {...} })
-- a runtime mesh whose positions are rewritten in place each frame
local m = renderer.mesh.create({ positions = P, indices = I, keepCpu = true })
renderer.mesh.setVertices(m, P)
-- a runtime mesh carrying a lightmap UV set (unwrapped at creation)
local gpu = renderer.mesh.create({ positions = {...}, indices = {...}, unwrapUvs = true })
-- a mesh with one shape to blend towards, driven by ecs.MorphWeights
local gpu = renderer.mesh.create({ positions = P, indices = I, morphTargets = { { positions = D } } })

list( ) →

Every mesh currently registered, ordered by guid — the ones a script created and the ones that reached the device through an asset alike. Answers "which mesh is this?" when all that is known is a size: each entry carries the guid, the vertex/index counts it was created with, where it came from (`origin` is `"asset"` for a mesh the asset path uploaded), whether the GPU still holds it, and where its culling bounds come from (`boundsFrom` is `"compute"` for a mesh a compute pass writes). A resident entry also carries the bytes its buffers cost. The buffer columns `vertexBytes`, `vertexStorageBytes`, `indexBytes` and `lightmapBytes` are the sizes of the buffers the mesh holds of its own. A static mesh in the shared geometry heap draws its vertices and indices out of its regions of the heap and the shared index buffer (the `geometry` category of `renderer.gpuMemory()` counts them), so its vertex and index columns are 0; a mesh outside the heap holds both of its own, and a mesh a compute pass writes holds its vertices of its own. The storage column is the rest copy of the vertices a skinned mesh's deformation pass reads, and 0 for every other mesh; the lightmap column is 0 for a mesh with no lightmap UV set, which is lit through its uv0. `bytes` is what the mesh holds of its own, the four columns summed. A mesh made from compute buffers (`computeOwned`) holds none of them, so its `bytes` is 0 and the `compute` category counts them. The `bytes` column is what sums to the `meshes` category of `renderer.gpuMemory()`. `renderer.references("mesh", guid)` says what is still holding a row, and `renderer.collect()` releases the rows nothing holds. boundsFrom, bytes?, vertexBytes?, vertexStorageBytes?, indexBytes?, lightmapBytes?, computeOwned?, primitives?, revision? }`.

examples

for _, m in ipairs(renderer.mesh.list()) do print(m.guid, m.bytes) end

update(mesh: string | { [string]: any } | AssetRef, src: any) → MeshHandle

Overwrite the GPU resource `mesh` names IN PLACE, under the same guid, from new geometry or compute buffers. Never writes a `.mesh` file — the play-mode mutate path. A Model bound to the guid reflects the change with no re-bind. Takes every form that names a mesh — the `MeshHandle` `create` returned, the guid `renderer.mesh.list` hands out, a `MeshCpuHandle` or a mesh `AssetRef`. Returns a handle carrying the bounds the new geometry has: the handle it was given, refreshed, and a handle over the guid otherwise. A mesh an exact `MeshCollider` is built from takes the new geometry in the frame its collider, cooked from it off the frame, stands: what is drawn and what collides change together, a frame or more after the call. mesh `AssetRef`. buffers `{vertexBuffer, indexBuffer, vertexCount, indexCount, prevVertexBuffer?}`. `aabbMin` / `aabbMax`, given together, state the mesh's extent in place of the box its vertices reach.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh to update — a `MeshHandle`, a guid, a `MeshCpuHandle` or a
srcanyNew geometry `{positions, indices, aabbMin?, aabbMax?, ...}` or compute

instancedRecord(record: any) → any

The registration record the FFI answers with. The record is itself the `InstancedDraw` of the registration it describes (`kind` and `id`), and `draw` carries that same handle, so every lifecycle call takes the record or its `draw` alike.

argtypedescription
recordany

drawHandleId(draw: any, what: string) → number

argtypedescription
drawany
whatstring

parentEntityId(parent: any, what: string) → string

The id of the entity a population stands in: an id string, or anything carrying one as `.id` or `.entityId` (an entity proxy, a component).

argtypedescription
parentany
whatstring

drawInstanced(mesh: string | { [string]: any } | AssetRef, opts: any) → InstancedDraw

Draw one mesh `instanceCount` times in a single call, each copy placed by a world matrix read from a GPU buffer. The population is a renderable in its own right — it goes through the mesh's ordinary pipeline and the material's ordinary bind groups, so it appears in the deferred pass, the forward passes and the shadow maps exactly as an entity-backed draw of that mesh does. The buffer holds `instanceCount` **column-major** 4x4 matrices, 64 bytes each, tightly packed — the layout a vertex shader reads as `array<mat4x4<f32>>`, which puts each matrix's translation in its LAST four floats (Lua indices 13/14/15 for x/y/z). Packing row-major transposes every instance. The matrices are COPIED into the engine's transform slots, which is what buys that full-pass parity. Rewrite the buffer between frames and the instances move, with no re-registration and no re-upload. The copy is made on the frames that follow a write of the buffer (a `:write`, a compute pass whose shader binds it `read_write`, and every frame a material whose shader binds it `read_write` is live), so a population whose buffer nothing writes costs no copy per frame however many instances it holds; `renderer.uploadStats()` counts the copies a frame made. `material` is what the population draws with, and it is required: a `MaterialHandle` (`matRef:handle()`), an `AssetRef`, or a registry key. `instanceDataBuffer` names a second buffer, holding 64 bytes per instance — four `vec4` lanes, tightly packed, in instance order. Those lanes arrive in the fragment stage as `zero_object_data(in.instance_id, lane)`, the same read a per-entity `__instancedata` block answers, so the members of one population can differ in whatever their material's shader agrees the lanes carry. Copied like the transforms, on the frames that follow a write of the buffer, from a buffer a compute pass writes: the values never touch the CPU. Omit it and the lanes read zero. The material's `vertex()` hook reads the lanes too, as `zero_object_data(v.instance_id, lane)`, beside `v.vertex_index`, the index of the vertex in the mesh: a hook can build each copy's shape from them, which is how a field of grass blades, kelp, hair cards or debris is one strip mesh and one call, lit and shadowed like the rest of the scene (`guides { path = "topics/rendering-instance-data" }`). `@builtin::materials.instance_color` (and `instance_color_unlit`) colour each copy from lane 2 of its block, `(r, g, b, coverage)`, given as its `AssetRef`: `material = asset.resolve("@builtin::materials.instance_color", "material")`. `reserveCount` sizes the reservation above `instanceCount` so `renderer.mesh.setInstanceCount` can raise the drawn count later without re-registering; both buffers must back the reservation, not just the count. The renderer's own per-instance memory follows the drawn count: a population holds slots for the most copies it has drawn, so a reservation costs only the caller's buffers. `traced` states whether the copies stand in the ray-traced scene, the geometry probe GI, ray-traced shadows and every other pass that traces rays hit: a traced copy bounces light, blocks it and is lit by it, and an untraced one is invisible to all of them. It is true when left out for a population that casts shadows and false for one that does not, so copies that cast nothing stay out of the traced scene. The copies are placed from the matrices the CPU wrote into the transform buffer (`buf:write`, `buf:writeBytes`), and for a buffer a compute pass writes, from the matrices read back from the device a frame or more after each write. `renderer.mesh.setInstanceTraced` changes it later. `mobility` states whether the copies stand still — `"static"`, or `"movable"` when it is left out. It is what a scene gather collecting geometry for precomputed lighting admits a population on, the same declaration `Model.mobility` makes for an entity: the transforms live in a buffer anything may rewrite between frames, so a population that says nothing is taken as one that moves. Every copy draws the mesh's cluster LOD, cut from that copy's own distance, so a population needs no near/mid/far meshes to thin out with range. The registration asks for the mesh's bake, whichever way the mesh reached the device: a mesh no set was asked for bakes at the depth its asset's `clusterLod` setting names (the hierarchy when no asset answers for it), and draws full detail until the bake lands. A set asked for the mesh earlier stands, and so does the full-detail set of geometry `renderer.mesh.create` made with `keepCpu`, `morphTargets`, `skinning` or `skins`, or from compute buffers. `renderer.mesh.clusters(mesh).kind` reads `"dag"` while the mesh draws its LOD hierarchy and `"lod0"` while it draws full detail at every distance (`guides { path = "topics/world-detail" }`). `renderer.mesh.list` hands out, a `MeshCpuHandle` or a mesh `AssetRef`. A registration holds the mesh on the device for as long as it lives, and takes a mesh that is currently held off the device — one nothing displays — back onto it. `castsShadows` and `receivesShadows`, both true when left out, state whether the copies cast shadows and whether shadows darken them. `traced` states whether the copies stand in the ray-traced scene; it takes the value of `castsShadows` when left out. `parent` stands the copies in an entity's space, as `setInstanceParent` does.

argtypedescription
meshstring | { [string]: any } | AssetRefThe mesh the population draws — a `MeshHandle`, the guid
optsany`{ transformBuffer, instanceCount, material, instanceDataBuffer?, reserveCount?, renderLayer?, castsShadows?, receivesShadows?, traced?, mobility?, parent? }`.

examples

local m = renderer.mesh.create({ positions = ..., indices = ... })
local buf = substrate.createBuffer({
name = "crowd.xf", type = "mat4", len = 64, kind = "gpu",
})
-- Column-major: translation lives at indices 13/14/15.
local xf = {}
for i = 0, 63 do
local m4 = { 1,0,0,0, 0,1,0,0, 0,0,1,0, i * 2, 0, 0, 1 }
for _, v in ipairs(m4) do xf[#xf + 1] = v end
end
buf:write(xf)
local rock = asset.resolve("rock", "material"):handle()
local draw = renderer.mesh.drawInstanced(m, { transformBuffer = "crowd.xf", instanceCount = 64, material = rock })

setInstanceParent(draw: InstancedDraw, parent: any?) → InstancedDraw

Stand a registration's copies in an entity's space: every copy's matrix is taken relative to the entity, so the population moves, turns and scales with it from the next frame on, with its transform buffer untouched. `nil` puts the copies back in world space. It is the verb for a population that belongs to something — a generator's output, an asset stood on an entity. The copies are hidden while the entity or an ancestor of it is deactivated, and while no entity holds the id; they stand under the entity again once one does. A population whose parent stands still, or is hidden or gone, costs nothing per frame. world space.

argtypedescription
drawInstancedDrawThe `InstancedDraw` to reconfigure.
parentany?The entity the copies stand in (a proxy or its id), or nil for

examples

renderer.mesh.setInstanceParent(draw, entity.find("Forest"))

setInstanceTraced(draw: InstancedDraw, traced: boolean) → InstancedDraw

Put a registration's copies into the ray-traced scene, or take them out of it, from the next frame on. The ray-traced scene is the geometry probe GI, ray-traced shadows and every other pass that traces rays hit: a traced copy bounces light, blocks it and is lit by it. `drawInstanced` takes the initial value as `traced`. `instanceInfo(draw).traced` reads `"unreadable"` for a population whose transform buffer the CPU holds none of the matrices of and that cannot be copied back from the device.

argtypedescription
drawInstancedDrawThe `InstancedDraw` to reconfigure.
tracedbooleanWhether the copies stand in the ray-traced scene.

examples

renderer.mesh.setInstanceTraced(draw, false)

setInstanceCount(draw: InstancedDraw, count: number) → InstancedDraw

Change how many of a registration's instances draw. The reservation, the transform buffer and the pipeline all stay put, so this is the verb for a population whose size changes per frame. The new count must fit the reservation `drawInstanced` was given. A count within the per-instance slots the renderer holds for the population is constant time; a count past them grows them to the larger of the count and twice what they were, within the reservation, so a count that climbs grows them a handful of times rather than on every call.

argtypedescription
drawInstancedDrawThe `InstancedDraw` to reconfigure.
countnumberInstances to draw, at least 1 and within the reservation.

examples

renderer.mesh.setInstanceCount(draw, visibleCount)

setInstanceRenderLayer(draw: InstancedDraw, renderLayer: number) → InstancedDraw

Change which render layers a registration's copies belong to. Constant time — the reservation, the transform buffer and the pipeline all stay put, and the next frame drawn tests the copies against the new membership. It is the verb for a population that follows something whose membership moves: a camera or a capture including the layer draws the copies, one excluding it does not. as `renderLayer`. At least one bit must be set.

argtypedescription
drawInstancedDrawThe `InstancedDraw` to reconfigure.
renderLayernumberThe membership bitmask, the same value `drawInstanced` takes

examples

renderer.mesh.setInstanceRenderLayer(draw, mask)

instanceInfo(draw: InstancedDraw) → InstancedDrawInfo

What a live instanced-draw registration is drawing: which mesh, which transform buffer, which per-instance data buffer if it named one, how many instances, and how many slots it reserved. Returns nil once the registration has been dropped. `status` is what the renderer did with it. The fields above it are the request, made a stage before the renderer sees it; `status` is the answer: `"drawing"` for a registration the renderer is drawing, `"hidden"` for one it holds but does not draw while its parent entity, or an ancestor of it, is deactivated or gone, `"refused"` for one it turned away — `error` carries its reason — and `"pending"` for the frame between the call and the renderer answering. So a registration whose copies are not being drawn says so here. returned, a ray hit's `instancedDraw`, or a record `listInstanced` answers.

argtypedescription
drawInstancedDrawThe `InstancedDraw` to report on: the handle `drawInstanced`

examples

print(renderer.mesh.instanceInfo(draw).instanceCount)
local info = renderer.mesh.instanceInfo(draw)
if info.status == "refused" then error(info.error) end

listInstanced( ) →

Every instanced-draw registration this engine is drawing, in registration order, whoever registered it: a script's `renderer.mesh.drawInstanced`, a Generator's or a quick-geometry model's scatter, a Population. Each record is what `instanceInfo` answers with, and is itself the `InstancedDraw` of its registration (`record.id` is its `handle`; `record.draw` is the same handle), so a record goes straight to `instanceInfo`, `instanceWorlds`, `dropInstanced` and every other `renderer.mesh.instance*` call, and a population whose handle its caller no longer holds is reached here and released, resized or read like any other. A ray hit on a copy names the same registration: `hit.instancedDraw.id == record.handle`, and `record.parent` is the entity the copies stand in (the Generator, for a Generator's output).

examples

for _, pop in renderer.mesh.listInstanced() do
print(pop.handle, pop.parent, pop.instanceCount, pop.material)
end
for _, pop in ipairs(renderer.mesh.listInstanced()) do
renderer.mesh.dropInstanced(pop)
end

instanceTransforms(draw: InstancedDraw) → any

Read back the world matrices a registration's drawn copies are placed by: `instanceCount` matrices of 16 floats, column-major and tightly packed, in the layout the transform buffer holds them. The read is of the buffer as it stands when it runs, so a population a compute pass rewrites every frame answers with the placement of the frame the read lands in. registration that is no longer live.

argtypedescription
drawInstancedDrawThe `InstancedDraw` whose copies to locate.

examples

local pending = renderer.mesh.instanceTransforms(draw)
while not pending:ready() do task.wait() end
local floats = pending:result()

instanceWorlds(draw: InstancedDraw) → any

Read back where a registration's drawn copies stand in the world, as the engine composed them for the last frame drawn: each copy's matrix from the transform buffer, carried through the world matrix of the entity the copies stand in when they have one (`setInstanceParent`). `instanceCount` column-major 4x4 matrices, 16 floats each. Async — poll the handle it

argtypedescription
drawInstancedDrawThe `InstancedDraw` to read.

examples

local pending = renderer.mesh.instanceWorlds(draw)
while not pending:ready() do task.wait() end
local x = pending:result()[13]

instanceBounds(draw: InstancedDraw, opts: { keep: number? }?) →

The world box a registration's drawn copies occupy: every copy of the mesh's extent (`renderer.mesh.bounds`) where the engine composed it for the last frame drawn, carried through the entity the copies stand in when `setInstanceParent` named one. It reads the copies back from the GPU, so it waits a few drawn frames. A copy scaled to nothing draws nothing and is left out. A mesh whose extent nobody knows answers with the box around the copies' origins, and says so. (default 1, all of them). Below 1, the copies reaching furthest out on each side are left out: `keep = 0.9` is the box around where the body of a spray stands, without the few copies thrown far from it. alone comes with the note that says so.

argtypedescription
drawInstancedDrawThe `InstancedDraw` to measure.
opts{ keep: number? }?`{ keep? }` — the share of the copies the box holds along each axis

examples

local box, note = renderer.mesh.instanceBounds(draw)
local body = renderer.mesh.instanceBounds(draw, { keep = 0.9 })

dropInstanced(draw: InstancedDraw) → boolean

Release an instanced-draw registration and the transform slots it reserved. The mesh and the transform buffer outlive it — destroy those through `renderer.destroy` and the buffer handle's `:destroy()`.

argtypedescription
drawInstancedDrawThe `InstancedDraw` to release.

examples

renderer.mesh.dropInstanced(draw)

Problems

Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.

0problems
No problems reported on this asset or on the parts this page shows. Parts it leaves out are not counted here.
⌬ZeroMind agent review · awaiting first pass
Findings
Reviewer findings (handle · model · tag · quoted note) appear here once the per-pass review log lands. Today only the rolled-up agent_score is exposed.
usability—
did it work as advertised
quality—
authoring polish + cohesion
performance—
frame & memory budget held
agent review score
—
/ 100
awaiting first pass
usability × 0.40
+ quality × 0.35
+ performance × 0.25
± compat factor

Usability ratings

Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".

—%no reports yet
Sign in to report whether this part worked for you.
Discussion

Scoped to this part · feeds back into the world's score.

0comments
Sign in to post.sign in
No comments yet. Be the first.