The small3d library
Classes | Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
small3d::Model Class Reference

A 3D model. It can be loaded from a WavefrontFile or GlbFile. It can also be constructed procedurally by code, by inserting values to the appropriate member variables. More...

#include <Model.hpp>

Classes

struct  Animation
 animation More...
 
struct  AnimationComponent
 animation component More...
 
struct  Joint
 joint More...
 

Public Member Functions

 Model ()
 Default constructor.
 
 Model (File &file, const std::string &meshName="")
 Constructor. More...
 
 Model (File &&file, const std::string &meshName="")
 Constructor (rvalue file - helps for declaring the file on the fly when using gcc) More...
 
uint64_t getNumPoses ()
 Get the number of animation poses in the current animation. More...
 
size_t getNumAnimations ()
 Get the number of available animations. More...
 
void setAnimation (uint32_t animationIdx)
 Set the current animation. More...
 
Mat4 getTransform (uint32_t animationIdx, uint64_t currentPose, float seconds=0.0f)
 Get a transform of the model. More...
 
Mat4 getJointTransform (size_t jointIdx, uint32_t animationIdx, uint64_t currentPose, float seconds=0.0f)
 Get a joint transform, also calculating the transorms of the parent joints in the same tree and the animations, if any exist. More...
 
Vec3 getOriginalScale ()
 Get the Model's original scale (usually the one read from the file the Model was loaded from.
 
void saveBinary (const std::string &binaryFilePath)
 Save model data in binary format. More...
 
template<class Archive >
void serialize (Archive &archive)
 

Public Attributes

Material material
 The material of the model.
 
Vec3 scale = Vec3(1.0f, 1.0f, 1.0f)
 Use this to scale the model and not origScale.
 
std::shared_ptr< ImagedefaultTextureImage
 Image found in the file the model was loaded from (empty image if not - check the size). It can be used to generate a texture for the model, but other textures can also be used.
 
std::vector< float > vertexData
 The vertex data. This is an array, which is to be treated as a 4 column table, holding the x, y, z values in each column. The fourth column is there to assist in matrix operations.
 
uint32_t vertexDataByteSize = 0
 Size of the vertex data, in bytes.
 
std::vector< uint16_t > indexData
 3 column table. Each element refers to a "row" in the vertex data table. Each "row" in the index data table forms a triangle.
 
uint32_t indexDataByteSize = 0
 Size of the index data, in bytes.
 
std::vector< float > normalsData
 Array, to be treated as a 3 column table. Each "row" contains the x, y and z components of the vector representing the normal of a vertex. The position of the "row" in the array is the same as the position of the corresponding vertex "row" in the vertexData array.
 
uint32_t normalsDataByteSize = 0
 Size of the normals data, in bytes.
 
std::vector< float > textureCoordsData
 Array, to be treated as a 2 column table. Each "row" contains the x and y components of the pixel coordinates on the model's texture image for the vertex in the corresponding "row" of the vertex data "table".
 
uint32_t textureCoordsDataByteSize = 0
 Size of the texture coordinates data, in bytes.
 
std::vector< uint8_t > jointData
 Array, to be treated as a 4 column table. Each "row" potentially contains up to 4 joints that can influence each vertex.
 
uint32_t jointDataByteSize = 0
 Size of the joint data, in bytes.
 
std::vector< float > weightData
 Array, to be treated as a 4 column table. Each "row" contains the weights by which each of the corresponding joints affect each vertex.
 
uint32_t weightDataByteSize = 0
 Size of the weight data, in bytes.
 
std::vector< Jointjoints
 The model's joints.
 
std::vector< Animationanimations
 Animations of the model (there are also joint animations)
 
bool noShadow = false
 Should the model produce a shadow?
 

Static Public Attributes

static const uint32_t MAX_JOINTS_SUPPORTED = 32
 Maximum number of supported joints.
 

Friends

class GlbFile
 
class Renderer
 

Detailed Description

A 3D model. It can be loaded from a WavefrontFile or GlbFile. It can also be constructed procedurally by code, by inserting values to the appropriate member variables.

Constructor & Destructor Documentation

◆ Model() [1/2]

small3d::Model::Model ( File file,
const std::string &  meshName = "" 
)

Constructor.

Parameters
fileThe file parsing object from which to load the model
meshNameThe name of the model mesh in the file

◆ Model() [2/2]

small3d::Model::Model ( File &&  file,
const std::string &  meshName = "" 
)

Constructor (rvalue file - helps for declaring the file on the fly when using gcc)

Parameters
fileThe file parsing object from which to load the model
meshNameThe name of the model mesh in the file

Member Function Documentation

◆ getJointTransform()

Mat4 small3d::Model::getJointTransform ( size_t  jointIdx,
uint32_t  animationIdx,
uint64_t  currentPose,
float  seconds = 0.0f 
)

Get a joint transform, also calculating the transorms of the parent joints in the same tree and the animations, if any exist.

Parameters
jointIdxThe index of the joint in the list of joints
animationIdxThe index of the animation to use
currentPoseThe pose of the animation to calculate the joint transformation for.
secondsThe animation moment (in seconds) - mostly used internally
Returns
The transform

◆ getNumAnimations()

size_t small3d::Model::getNumAnimations ( )

Get the number of available animations.

Returns
The number of animations

◆ getNumPoses()

uint64_t small3d::Model::getNumPoses ( )

Get the number of animation poses in the current animation.

Returns
The number of animation poses

◆ getTransform()

Mat4 small3d::Model::getTransform ( uint32_t  animationIdx,
uint64_t  currentPose,
float  seconds = 0.0f 
)

Get a transform of the model.

Parameters
animationIdxThe index of the animation to use
currentPoseThe pose of the animation to calculate the joint transformation for.
secondsThe animation moment (in seconds) - mostly used internally
Returns
The transform

◆ saveBinary()

void small3d::Model::saveBinary ( const std::string &  binaryFilePath)

Save model data in binary format.

Parameters
binaryFilePathPath of file to save binary data to.

◆ setAnimation()

void small3d::Model::setAnimation ( uint32_t  animationIdx)

Set the current animation.

Parameters
animationIdxThe index of the current animation

The documentation for this class was generated from the following files: