modules.models#
- class modules.models.Models(*args: Any, **kwargs: Any)#
Bases:
Context- class CPUMeshData(combined: ndarray, indices: ndarray, num_indices: int, material: int, path: Path, mesh: Any, aabb: tuple[ndarray, ndarray])#
Bases:
objectCPU-side representation of a mesh. (used for loading)
Stores interleaved vertex data, indices, and metadata required for uploading the mesh to the GPU.
- Parameters:
combined – Interleaved vertex attributes (pos, normal, uv, tangent, bitangent)
indices – Triangle index buffer (uint32)
num_indices – Total number of indices
material – Material ID assigned to the mesh
path – Source model path
mesh – Original imported mesh reference
- __init__(combined: ndarray, indices: ndarray, num_indices: int, material: int, path: Path, mesh: Any, aabb: tuple[ndarray, ndarray]) None#
- aabb: tuple[ndarray, ndarray]#
- combined: ndarray#
- indices: ndarray#
- material: int#
- mesh: Any#
- num_indices: int#
- path: Path#
- class Load(path: Path, material: int)#
Bases:
objectModel load request descriptor.
Contains the source path and optional material override.
- Parameters:
path – Path to the model file
material – Optional material override (-1 = auto)
- __init__(path: Path, material: int) None#
- material: int#
- path: Path#
- class Mesh#
Bases:
TypedDict“Final representation a mesh (used for rendering)
- aabb: tuple[ndarray, ndarray]#
- baseVertex: int#
- firstIndex: int#
- material: int#
- num_indices: int#
- __init__(context)#
Setup model buffers, containg mesh and material information required to render.
- Parameters:
context (EmberEngine) – This is the main context of the application
- compute_tangents_bitangents(vertices, tex_coords, indices)#
Compute tangent spaces for vertices
- Parameters:
vertices (ndarray - shape 3.) – The vertices in the mesh
tex_coords (ndarray - shape 2.) – The texture coordinates
indices (ndarray - c.) – The indices for the mesh
- Returns:
tangents, bitanges
- Return type:
ndarray; shape 3, ndarray; shape 3
- create_matrices(model)#
Collect local model matrices for nodes in this model
- draw(model: Model, model_matrix: Matrix44, instant: bool = False, uuid=None) None#
Begin drawing a model
- Parameters:
model (Model) – The model object
model_matrix (matrix44) – The transformation model matrix, used along with view and projection matrices
instant (bool) – either collect the drawcalls and submit them in renderer.end_frame() or render now/nstantly
- loadOrFind(path: Path, material: int = -1, lazy_load: bool = True) int#
Load or find an model, implement find later
- Parameters:
path (Path) – The path to the model file
material (int) – Could contain a material override if not -1
lazy (bool) – Lazy load models using threading
- model_loader_thread()#
Worker thread for model loading and CPU pre-processing.
Pulls load requests from the queue, assimp loads and prepares models (tangents). Then outputs prepared meshes to the ready queue.
- model_loader_thread_flush() None#
Receives ready CPU prepared meshes from work thread and uploads them to the GPU.
- static normalize(vectors)#
Normalize a vector array
- prepare_mesh_cpu(mesh, path: Path, material: int) CPUMeshData#
Convert a mesh into an CPUMeshData CPU-side format.
Generates missing attributes if needed and computes tangents and bitangents for normal mapping.
- Parameters:
mesh – Imported mesh object
path (Path) – Source model path
material (int) – Material ID override (-1 = auto)
- Returns:
CPU-side mesh data
- Return type:
- prepare_on_CPU(index: int, path: Path, material: int = -1) None#
Load a model from disk and prepare all meshes on the CPU.
Returns a list of CPU-ready mesh data objects.
- Parameters:
index (int) – Internal model index
path (Path) – Path to the model file
material (int) – Material ID override (-1 = auto)
- Returns:
List of prepared CPU meshes
- Return type:
list[CPUMeshData]
- upload_to_GPU(index: int, cpu_meshes: list[CPUMeshData]) bool#
Upload CPU-prepared meshes to the GPU. Then free the list
- Parameters:
index (int) – Internal model index
cpu_meshes (list[CPUMeshData]) – List of CPU mesh data objects
- Returns:
True if upload succeeded
- Return type:
bool