BBMOD_Model

A constructor defined in BBMOD_Model.gml

Extends BBMOD_Resource
Implements BBMOD_IRenderable

new BBMOD_Model([_file[, _sha1]])

Description

A model, defined by a hierarchy of nodes that draw meshes with given material and transform.

Arguments

Name Type Description
_file String The "*.bbmod" model file to load or undefined. Defaults to undefined.
_sha1 String Expected SHA1 of the file. If the actual one does not match with this, then the model will not be loaded. Use undefined if you do not want to check the SHA1 of the file. Defaults to undefined.

Properties

Name Description
BoneCount Defines a number of nodes that are bones.
Frozen If true then the model is "frozen", which means all its meshes reside in the GPU memory, which makes them faster to draw, but unmodifiable.
MaterialCount Number of materials that the model uses. Defaults to 0.
MaterialNames An array of material names. Its length must be equal to BBMOD_Model.MaterialCount.
Materials An array of materials. Each entry can be either a material struct or just a texture if you don't wish to use BBMOD's material system. Each entry defaults to BBMOD_MATERIAL_DEFAULT. The length of the array must be equal to BBMOD_Model.MaterialCount.
Meshes An array of meshes that the model consists of.
NodeCount A total number of nodes that the model consists of. Defaults to 0.
RootNode The root node of the model or undefined (default).
VersionMajor The major version of the BBMOD file from which was the model loaded. Defaults to BBMOD_VERSION_MAJOR.
VersionMinor The minor version of the BBMOD file from which was the model loaded. Defaults to BBMOD_VERSION_MINOR.
VertexFormat OBSOLETE The vertex format of the model.

Inherited properties

Name Description
IsLoaded If false then the resource has not been loaded yet.
Path The path to the file from which was the resource loaded, or undefined if the resource does not come from a file.
Persistent If true then the resource is persistent and it is not destroyed when method free is used. Default value is false.

Methods

Name Description
clone Creates a clone of the model.
copy Copies model data into another model.
find_node Recursively traverses nodes that the model consists of until it finds and returns a node with specified ID or name.
find_node_id Recursively traverses nodes that the model consists of, starting from the root node, until it finds a node with specified name and returns its ID.
freeze Freezes all vertex buffers used by the model. This should make its rendering faster, but it disables creating new batches of the model.
from_buffer Loads model data from a buffer that follows the BBMOD file format.
get_material Retrieves a material by its name.
get_vertex_format DEPRECATED Used to retrieve or create a vertex format compatible with the model.
render Enqueues the model for rendering.
set_material Sets a material.
submit Immediately submits the model for rendering.
to_buffer Writes model data to a buffer following the current version of the BBMOD file format.

Inherited methods

Name Description
destroy Frees memory used by the struct.
free Releases a reference to the resource.
from_buffer Loads the resource from a buffer.
from_file Loads the resource from a file.
from_file_async Asynchronnously loads the resource from a file.
ref Retrieves a reference to the resource.
to_buffer Writes the resource to a buffer.
to_file Writes a resource to a file.

Throws

Example

The following code loads a model from file "Model.bbmod", assings a texture to material slot 0 (meaning it won't use BBMOD's material system) and then draws the model at the x, y, z position of given instance. The model is then destroyed in the Clean Up event to avoid memory leaks.

/// @desc Create event
model = new BBMOD_Model("Model.bbmod");
model.Materials[0] = sprite_get_texture(SprTexture, 0);

/// @desc Draw event
new BBMOD_Matrix().Translate(x, y, z).ApplyWorld();
model.submit();
bbmod_material_reset();
BBMOD_MATRIX_IDENTITY.ApplyWorld();

/// @desc Clean Up event
model = model.destroy();
Do you find this page helpful?

Copyright © 2025, BlueBurn. Built on January 04, 2025 using GMDoc.