natiny.mesh.reload

Lua
natiny.mesh.reload(mesh, resource)

Replaces the geometry inside an existing mesh. The handle does not change.

Parameters

Name Type Description
mesh number Live mesh handle from natiny.mesh.load
resource number Resource handle containing a glTF or GLB model

Example

Lua
local mesh = natiny.mesh.load(resource)
natiny.model.set_mesh(model, mesh)
local replacement = natiny.resource.load("models/tree.glb")

-- the model keeps its place in the scene and shows the new shape
natiny.mesh.reload(mesh, replacement)
natiny.resource.destroy(replacement)

Notes

  • Every model built on this mesh keeps its transform, its material and its place in the scene, and shows the new shape.
  • Whether the mesh is dynamic is a decision the program made, not something the file says; a reload does not take it back.
  • Per-part overrides set with natiny.model.set_part_material and natiny.model.set_part_texture are indexed by part. They survive a reload that keeps the part count and are dropped by one that changes it, because the indices would otherwise name different parts.
  • Raises an error if mesh is not live or the resource cannot be loaded as glTF 2.0. A failure leaves the mesh exactly as it was.
  • The resource data is copied during the call and may be destroyed after a successful reload.