Model
The Model class contains these members:
aiScene
is a custom data type from Assimp which is the root of the model loaded.VertexComponent
(s) is an enumeration listing various types of a vertex attributes.VertexLayout
(s) specifies how types of vertex attributes are laid out and their byte offsets(offsets
) from the first element ofcomponents
.Dimension
indicates the size of the model.Material
(s) are materials used by the model and they contains texture names used by the material, while_materialIndices
is the material indices referencing theaiMaterial
array inaiScene
.MVP
includes the model, view, and projection matrix of the model.
ReaFile
loads a model at the given path and filename, and with optional ModelInfo
that we can scale subsequent vertex data. Assimp::Importer
loads a model with a flag specifying post processes being executed after loading is finished. If reading file succeeds, we iterate the aiMesh
(es) in aiScene
with the following actions:
- Check whether a particular type of vertex attribute exists and record its existence to
components
and its offset tooffsets
. - Iterate all the vertex data to fill up our
vertexBuffer
, and also, we calculate the size of the model at the same time. - After iterating all the vertices, we know the boundaries of the model so we are able to calculate
_dimension.size
. - Iterate all the index data to fill up our
indexBuffer
. - Record the material indices the current
aiMesh
uses to_materialIndices
. - Iterate all the
aiMaterial
(s) and record their texture names used for various type of texture(diffuse, specular, normal, etc) to_materials
.
ModelResource
holds the buffer of vertex and indices, the indices count, Mesh
(es) recording the vertex/index count and its position in the vertex/index buffer for each Mesh
. And also, operations on the buffers cooperate with Device
like Texture
.
UploadToGPU
uploads data from Model
to vertices and indices. The method can be divided into three parts:
- For each
Mesh
inModel
, we calculate the vertices count with the stride of the currentVertexLayout
for the currentMesh
. AndvertexBase
andindexBase
are accumulatedvertexCount
andindexCount
so far while we iterate theMesh
(es). - As we did on uploading pixels to an image, we need a staging buffer for temporary storage. And copy the data of
vertexBuffer
andindexBuffer
to the corresponding staging buffers. - Record the command that copies the data of the staging buffers to
vertices
andindices
, and submit it to the queue.