ModelAsset class final

An immutable, GPU-resident model that can be placed in a scene any number of times.

The asset/instance split matters: without it a loaded model is the thing being drawn, so putting it in a scene twice means loading it twice. instantiate creates nodes that share the uploaded meshes and textures.

Available extensions

Constructors

ModelAsset({required List<ModelPart> parts, required Aabb3 localBounds, List<ModelNode>? nodes, List<int>? roots, List<ModelSkin> skins = const <ModelSkin>[], List<AnimationClip> clips = const <AnimationClip>[], List<String> warnings = const <String>[], String? name, List<String> variants = const <String>[], Map<int, RenderMaterial> materials = const <int, RenderMaterial>{}, Map<ModelImpostor, ImpostorPart> impostors = const <ModelImpostor, ImpostorPart>{}, GraphicsDevice? device})
An asset assembled from already uploaded parts.
ModelAsset.fromMesh(GraphicsDevice device, MeshData mesh, {RenderMaterial? material, String? name})
Wraps a single procedurally generated mesh.
factory

Properties

clips → List<AnimationClip>
The animation clips the file brought, empty when it brought none; an instance's player plays them.
final
hashCode → int
The hash code for this object.
no setterinherited
impostors → Map<ModelImpostor, ImpostorPart>
What each impostor level in nodes draws with — C4: its card and its two atlases, uploaded once however many instances stand in a scene. Keyed by the level's own ModelImpostor; empty for the model with none, which is nearly every model.
final
isAnimated → bool
Whether the file brought any animation with it.
no setter
isDisposed → bool
Whether dispose has run.
no setter
isSkinned → bool
Whether the file brought any skeleton, so that some of its meshes are bent by joints rather than drawn rigid.
no setter
localBounds → Aabb3
Bounds in the model's own space, for framing a camera before anything is instantiated.
final
materials → Map<int, RenderMaterial>
The bound material for each of the document's materials that anything uses, by its index there.
final
name → String?
A name for the asset, for logs and tools, or null when none was given.
final
nodes → List<ModelNode>
The model's hierarchy, index-aligned with whatever the decoder produced.
final
parts → List<ModelPart>
The uploaded surfaces, one per surface of the decoded document, each with its mesh, material and variant materials; a ModelNode names the ones it draws by index here.
final
roots → List<int>
Indices into nodes of the nodes with no parent, the ones an instance hangs under its root.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
skins → List<ModelSkin>
Skeletons, index-aligned with what the decoder produced.
final
triangleCount → int
The triangle count summed over every part's mesh, a third of its index count; a mesh two parts share is counted twice.
no setter
variants → List<String>
The material variants the file offers, by name — see ModelInstance.selectVariant and ModelPart.variantMaterials.
final
vertexCount → int
The vertex count summed over every part's uploaded mesh; a mesh two parts share is counted twice.
no setter
warnings → List<String>
What the decoder and the upload had to give up, one sentence each: a texture that did not upload, morph targets left out, texture transforms that could not be honoured. Empty for a model that loaded whole.
final

Methods

dispose() → void
Gives every uploaded mesh and texture back to the device they were uploaded to; a second call does nothing.
instantiate(Scene scene, {SceneNode? parent, String? name, bool shareMaterials = true}) → ModelInstance

Available on ModelAsset, provided by the ModelAssetInstantiate extension

Adds this model to scene and returns the instance.
instantiateFitted(Scene scene, {required double length, int axis = 2, bool onGround = false, SceneNode? parent, String? name, bool shareMaterials = true}) → ModelInstance

Available on ModelAsset, provided by the ModelAssetInstantiate extension

instantiate, scaled and moved so the model is length metres long and sits on parent's origin: centred on it, or standing on it when onGround.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

fromDocument(ModelDocument document, {required GraphicsDevice device, LightingModel lighting = LightingModel.pbr, String? name, ImageDecoder decodeImage = defaultImageDecoder, TextureCodecs? codecs}) → Future<ModelAsset>
Uploads any decoded ModelDocument.