API reference

MeshManager Class

Modifiers: final
Manages 3D meshes for entities.
MeshManager is responsible for loading, attaching, and destroying meshes for entities. It supports different mesh sources (mesh://, gfx://, file://, http://, https://) and manages the lifecycle of SceneObjects and SceneMeshes. It also handles input events for meshes and forwards them to the data model.
Example usage:
// Register a custom mesh creator with URI parameters
meshManager.registerMeshCreator("mesh://custom/sphere") { entity, uri ->
    val radius = uri.getQueryParameter("radius")?.toFloatOrNull() ?: 1.0f
    SceneMesh.sphere(radius, material)
}
// Set a mesh for an entity using a URI with parameters
entity.setComponent(Mesh(Uri.parse("mesh://custom/sphere?radius=2.5")))
// Set a mesh for an entity using a file URI
meshManager.setMeshForEntity(
    entity,
    Uri.parse("models/cube.glb"),
    Uri.parse("file:///data/data/com.example.app/files/models/cube.glb"),
    "",  // default shader override
    -1,  // default scene override
    true // use cache
)
// Set a mesh directly for an entity
meshManager.setMeshForEntityDirectly(entity, sceneMesh)

Signature

class MeshManager(val scene: Scene, val meshCreators: HashMap<String, (ent: Entity) -> SceneMesh>, val sceneObjectSystem: SceneObjectSystem)

Constructors

MeshManager ( scene , meshCreators , sceneObjectSystem )
Signature
constructor(scene: Scene, meshCreators: HashMap<String, (ent: Entity) -> SceneMesh>, sceneObjectSystem: SceneObjectSystem)
Parameters
scene: Scene  The Scene instance used for rendering
meshCreators: HashMap  Map of URI schemes to mesh creator functions (deprecated, use registerMeshCreator)
sceneObjectSystem: SceneObjectSystem  System for managing SceneObjects

Properties

meshCreators : HashMap
[Get]
Map of URI schemes to mesh creator functions (deprecated, use registerMeshCreator)
Signature
val meshCreators: HashMap<String, (ent: Entity) -> SceneMesh>
scene : Scene
[Get]
The Scene instance used for rendering
Signature
val scene: Scene
sceneObjectSystem : SceneObjectSystem
[Get]
System for managing SceneObjects
Signature
val sceneObjectSystem: SceneObjectSystem

Methods

cachedMeshTokens ()
Snapshot of every load token currently held in the MeshManager.requestedMeshes_ dedup cache.
Signature
fun cachedMeshTokens(): Set<String>
Returns
Set
computeLoadTokenFor ( meshSimpleUri , meshFullPathUri , defaultShaderOverride , defaultSceneOverride )
Computes the MeshManager.requestedMeshes_ cache key for the given inputs. Returns null for mesh:// URIs (those go through MeshManager.otherMeshes_, not the dedup cache).
Signature
fun computeLoadTokenFor(meshSimpleUri: Uri, meshFullPathUri: Uri, defaultShaderOverride: String, defaultSceneOverride: Int): String?
Parameters
meshSimpleUri: Uri
meshFullPathUri: Uri
defaultShaderOverride: String
defaultSceneOverride: Int
Returns
String?
computeLoadTokenForEntity ( entity )
Returns the MeshManager.requestedMeshes_ cache key for MeshManager.computeLoadTokenForEntity's Mesh component, or null if the entity has no Mesh or its scheme bypasses the dedup cache. Resolves the URI against apk:/// to match what MeshCreationSystem.execute does.
Signature
fun computeLoadTokenForEntity(entity: Entity): String?
Parameters
entity: Entity
Returns
String?
deleteMeshForEntity ( entity )
This method removes the SceneObject associated with the entity and destroys any meshes that were created for it.
Signature
fun deleteMeshForEntity(entity: Entity)
Parameters
entity: Entity  The entity to remove the mesh from
destroy ()
Signature
fun destroy()
preloadMesh ( meshSimpleUri , meshFullPathUri , defaultShaderOverride , defaultSceneOverride , useCache )
Preloads a mesh without attaching it to any entity for faster loading later.
This method loads and caches a mesh from the specified URI so that when it's later attached to an entity, it will be available immediately. It supports the same URI schemes as setMeshForEntity:
  • file:// - Loads a mesh from a local file
  • http://, https:// - Loads a mesh from a network location
  • apk:// - Loads a mesh from the APK assets
Note: mesh:// and gfx:// schemes are not supported for preloading as they require entity-specific context.
Signature
fun preloadMesh(meshSimpleUri: Uri, meshFullPathUri: Uri, defaultShaderOverride: String, defaultSceneOverride: Int, useCache: Boolean = true)
Parameters
meshSimpleUri: Uri  A simple URI used for identification and caching
meshFullPathUri: Uri  The full URI path to the mesh resource
defaultShaderOverride: String  Optional shader override to use when loading the mesh
defaultSceneOverride: Int  Optional scene index override to use when loading the mesh
useCache: Boolean  Whether to use cached meshes (default: true)
registerAsyncMeshCreator ( baseUrl , creator )
Registers an async mesh creator for a base URL pattern.
Unlike MeshManager.registerMeshCreator, the creator function will be invoked on a background thread (Dispatchers.Default). The resulting SceneMesh will be attached to the entity on the main thread. This is suitable for mesh creators that perform expensive computation (e.g., procedural geometry generation).
The creator will be invoked for any mesh URI that matches the base URL (scheme + authority + path). Query parameters from the full URI will be passed to the creator for customization.
Parameters
baseUrl: String  The base URL to match (scheme + authority + path, query params ignored)
creator: SuspendFunction2  Function that takes an Entity and full URI, returns a SceneMesh. Called on a background thread.
registerMeshCreator ( baseUrl , creator )
Registers a mesh creator for a base URL pattern.
The creator will be invoked for any mesh URI that matches the base URL (scheme + authority + path). Query parameters from the full URI will be passed to the creator for customization.
Example:
meshManager.registerMeshCreator("mesh://custom/sphere") { entity, uri ->
    val radius = uri.getQueryParameter("radius")?.toFloatOrNull() ?: 1.0f
    SceneMesh.sphere(radius, material)
}

Parameters
baseUrl: String  The base URL to match (scheme + authority + path, query params ignored)
creator: Function2  Function that takes an Entity and full URI, returns a SceneMesh
retrieveAssociatedMeshFilesForEntity ( entity )
Parameters
entity: Entity
Returns
Array?
setMeshForEntity ( entity , meshSimpleUri , meshFullPathUri , defaultShaderOverride , defaultSceneOverride , useCache )
Attaches a mesh to an Entity based on the provided URIs. Avoid using this method directly and instead assign the Mesh component the Entity.
This method loads a mesh from the specified URI and attaches it to the entity. It supports different URI schemes:
  • mesh:// - Uses a registered mesh creator function
  • gfx:// - Loads a mesh from the GFX system
  • file:// - Loads a mesh from a local file
  • http://, https:// - Loads a mesh from a network location
Any previous mesh attached to the entity will be destroyed.
Signature
fun setMeshForEntity(entity: Entity, meshSimpleUri: Uri, meshFullPathUri: Uri, defaultShaderOverride: String, defaultSceneOverride: Int, useCache: Boolean = true)
Parameters
entity: Entity  The entity to attach the mesh to
meshSimpleUri: Uri  A simple URI used for identification and caching
meshFullPathUri: Uri  The full URI path to the mesh resource
defaultShaderOverride: String  Optional shader override to use when loading the mesh
defaultSceneOverride: Int  Optional scene index override to use when loading the mesh
useCache: Boolean  Whether to use cached meshes (default: true)
setMeshForEntityDirectly ( entity , mesh )
Attaches a mesh directly to an Entity, bypassing the data model. Should use the Mesh component instead.
This method should be used sparingly as it is not reflected by the data model. It's intended as an escape hatch when the mesh creators don't fit well with the standard workflow. Any previous mesh attached to the entity will be destroyed.
Signature
fun setMeshForEntityDirectly(entity: Entity, mesh: SceneMesh)
Parameters
entity: Entity  The entity to attach the mesh to
mesh: SceneMesh  The SceneMesh to attach
sweepUnusedMeshes ( candidateTokens )
Conservative mark-and-sweep over the MeshManager.requestedMeshes_ dedup cache.
Mark: queries the ECS for every entity carrying a Mesh component and computes its load token. Sweep: removes any token in MeshManager.sweepUnusedMeshes that is not live, destroying the cached SceneMesh and cancelling any in-flight load. Tokens not in MeshManager.sweepUnusedMeshes are left alone.
Pending futures are evicted too, otherwise an in-flight load could repopulate the cache after the sweep returns.
Signature
fun sweepUnusedMeshes(candidateTokens: Set<String>): Int
Parameters
candidateTokens: Set  the closed set of cache keys the caller is willing to free.
Returns
Int  the number of cache entries actually removed.
unregisterAsyncMeshCreator ( baseUrl )
Unregisters an async mesh creator for the given base URL.
Signature
fun unregisterAsyncMeshCreator(baseUrl: String)
Parameters
baseUrl: String  The base URL that was registered
unregisterMeshCreator ( baseUrl )
Unregisters a mesh creator for the given base URL.
Signature
fun unregisterMeshCreator(baseUrl: String)
Parameters
baseUrl: String  The base URL that was registered