12#ifndef CSCI441_MD5_MODEL_HPP
13#define CSCI441_MD5_MODEL_HPP
51#ifdef CSCI441_USE_GLEW
57#include <glm/exponential.hpp>
58#include <glm/ext/quaternion_common.hpp>
59#include <glm/ext/quaternion_float.hpp>
61#define GLM_ENABLE_EXPERIMENTAL
62#include <glm/gtx/quaternion.hpp>
86 static constexpr GLint NULL_JOINT = -1;
90 static constexpr GLshort MAX_NAME_LENGTH = 256;
94 char name[MAX_NAME_LENGTH] =
"";
98 GLint parent = NULL_JOINT;
102 glm::vec3 position = {0.0f, 0.0f, 0.0f};
106 glm::quat orientation = {0.0f, 0.0f, 0.0f, 0.0f};
125 if (
this != &OTHER) {
153 void _copyFromSrc(
const MD5Joint& src) {
154 strncpy(this->name, src.
name, MAX_NAME_LENGTH);
155 this->parent = src.
parent;
164 void _moveFromSrc(MD5Joint& src) {
168 strncpy(src.name,
"", MAX_NAME_LENGTH);
169 src.parent = NULL_JOINT;
170 src.position = glm::vec3(0.0f, 0.0f, 0.0f);
171 src.orientation = glm::quat(0.0f, 0.0f, 0.0f, 0.0f);
182 glm::vec2 texCoord = {0.0f, 0.0f};
209 if (
this != &OTHER) {
237 void _copyFromSrc(
const MD5Vertex &src) {
239 this->start = src.
start;
240 this->count = src.
count;
246 void _moveFromSrc(MD5Vertex& src) {
249 src.texCoord = glm::vec2(0.0f, 0.0f);
262 static constexpr GLshort NUM_VERTICES = 3;
266 GLint index[NUM_VERTICES] = {0};
285 if (
this != &OTHER) {
314 for (GLshort i = 0; i < NUM_VERTICES; i++) {
315 this->index[i] = src.
index[i];
322 void _moveFromSrc(MD5Triangle &src) {
325 for (GLint & i : src.index) {
338 GLint joint = MD5Joint::NULL_JOINT;
346 glm::vec3 position = {0.0f, 0.0f, 0.0f};
365 if (
this != &OTHER) {
393 void _copyFromSrc(
const MD5Weight &src) {
394 this->joint = src.
joint;
395 this->bias = src.
bias;
402 void _moveFromSrc(MD5Weight &src) {
405 src.joint = MD5Joint::NULL_JOINT;
407 src.position = glm::vec3(0.0f, 0.0f, 0.0f);
418 static constexpr GLshort MAX_NAME_LENGTH = 512;
422 GLuint texHandle = 0;
426 char filename[MAX_NAME_LENGTH] =
"";
445 if (
this != &OTHER) {
475 strncpy(this->filename, src.
filename, MAX_NAME_LENGTH);
481 void _moveFromSrc(MD5Texture& src) {
485 strncpy(src.filename,
"", MAX_NAME_LENGTH);
496 static constexpr GLshort MAX_NAME_LENGTH = 512;
500 static constexpr GLshort NUM_TEXTURES = 4;
541 GLint numVertices = 0;
545 GLint numTriangles = 0;
549 GLint numWeights = 0;
554 char shader[MAX_NAME_LENGTH] =
"";
608 void _moveFromSrc(
MD5Mesh& src) {
618 for (GLshort i = 0; i < NUM_TEXTURES; i++) {
619 this->textures[i] = std::move( src.
textures[i] );
631 strncpy(this->shader, src.
shader, MAX_NAME_LENGTH);
632 strncpy(src.
shader,
"", MAX_NAME_LENGTH);
644 static constexpr GLshort MAX_NAME_LENGTH = 256;
648 char name[MAX_NAME_LENGTH] =
"";
652 GLint parent = MD5Joint::NULL_JOINT;
660 GLint startIndex = 0;
679 if (
this != &OTHER) {
708 strncpy(this->name, src.
name, MAX_NAME_LENGTH);
709 this->parent = src.
parent;
710 this->flags = src.
flags;
717 void _moveFromSrc(MD5JointInfo &src) {
720 strncpy(src.name,
"", MAX_NAME_LENGTH);
721 src.parent = MD5Joint::NULL_JOINT;
734 glm::vec3 position = {0.0f, 0.0f, 0.0f};
738 glm::quat orientation = {0.0f, 0.0f, 0.0f, 0.0f};
757 if (
this != &OTHER) {
793 void _moveFromSrc(MD5BaseFrameJoint &src) {
796 src.position = glm::vec3(0.0f, 0.0f, 0.0f);
797 src.orientation = glm::quat(0.0f, 0.0f, 0.0f, 0.0f);
809 glm::vec3 min = {0.0f, 0.0f, 0.0f};
813 glm::vec3 max = {0.0f, 0.0f, 0.0f};
832 if (
this != &OTHER) {
868 void _moveFromSrc(MD5BoundingBox& src) {
871 src.min = glm::vec3(0.0f, 0.0f, 0.0f);
872 src.max = glm::vec3(0.0f, 0.0f, 0.0f);
900 if(_skeletonFrames !=
nullptr) {
901 for (GLint i = 0; i < _numFrames; ++i) {
902 delete _skeletonFrames[i];
905 delete[] _skeletonFrames;
906 _skeletonFrames =
nullptr;
907 delete[] _boundingBoxes;
908 _boundingBoxes =
nullptr;
910 _numFrames = numFrames;
911 if ( _numFrames > 0 ) {
912 _skeletonFrames =
new MD5Joint*[_numFrames];
913 for (GLint i = 0; i < _numFrames; ++i) {
914 _skeletonFrames[i] =
nullptr;
934 if(_skeletonFrames !=
nullptr) {
935 for (GLint i = 0; i < _numFrames; ++i) {
936 delete _skeletonFrames[i];
937 _skeletonFrames[i] =
nullptr;
941 _numJoints = numJoints;
942 if (_numJoints > 0) {
943 if(_skeletonFrames !=
nullptr) {
944 for(GLint i = 0; i < _numFrames; ++i) {
946 _skeletonFrames[i] =
new MD5Joint[_numJoints];
960 if ( frameIndex < 0 || frameIndex >= _numFrames ) {
961 throw std::out_of_range(
"frameIndex out of range");
963 if (_skeletonFrames ==
nullptr) {
964 throw std::out_of_range(
"skeleton frames are null, setNumberOfFrames() may not have been called");
966 return _skeletonFrames[frameIndex];
978 if ( frameIndex < 0 || frameIndex >= _numFrames ) {
979 throw std::out_of_range(
"frameIndex out of range");
981 if ( jointIndex < 0 || jointIndex >= _numJoints ) {
982 throw std::out_of_range(
"jointIndex out of range");
984 if (_skeletonFrames ==
nullptr) {
985 throw std::out_of_range(
"skeleton frames are null, setNumberOfFrames() may not have been called");
987 if (_skeletonFrames[frameIndex] ==
nullptr) {
988 throw std::out_of_range(
"skeleton joints are null, setNumberOfJoints() may not have been called");
990 return _skeletonFrames[frameIndex][jointIndex];
1001 if(frameIndex < 0 || frameIndex >= _numFrames) {
1002 throw std::out_of_range(
"frameIndex out of range");
1004 if (_boundingBoxes ==
nullptr) {
1005 throw std::out_of_range(
"bounding boxes are null, setNumberOfFrames() may not have been called");
1007 return _boundingBoxes[frameIndex];
1018 if(_skeletonFrames !=
nullptr) {
1019 for (GLint i = 0; i < _numFrames; i++) {
1020 delete[] _skeletonFrames[i];
1021 _skeletonFrames[i] =
nullptr;
1024 delete[] _skeletonFrames;
1025 _skeletonFrames =
nullptr;
1027 delete[] _boundingBoxes;
1028 _boundingBoxes =
nullptr;
1065 GLint _numFrames = 0;
1070 GLint _numJoints = 0;
1075 MD5Joint** _skeletonFrames =
nullptr;
1087 this->_numFrames = src._numFrames;
1090 this->_numJoints = src._numJoints;
1096 this->_skeletonFrames = src._skeletonFrames;
1097 src._skeletonFrames =
nullptr;
1099 this->_boundingBoxes = src._boundingBoxes;
1100 src._boundingBoxes =
nullptr;
1111 GLint currFrame = 0;
1115 GLint nextFrame = 0;
1119 GLfloat lastTime = 0.0f;
1124 GLfloat maxTime = 0.0f;
1135 _copyFromSrc(OTHER);
1143 if (
this != &OTHER) {
1144 _copyFromSrc(OTHER);
1181 void _moveFromSrc(MD5AnimationState &src) {
1186 src.lastTime = 0.0f;
1233 [[maybe_unused]]
bool loadMD5Model(
const char* MD5_MESH_FILE,
const char* MD5_ANIM_FILE =
"");
1247 [[nodiscard]]
bool readMD5Model(
const char* FILENAME);
1256 [[maybe_unused]]
void allocVertexArrays(GLuint vPosAttribLoc, GLuint vColorAttribLoc, GLuint vTexCoordAttribLoc);
1265 [[maybe_unused]]
void setActiveTextures(GLint diffuseMapActiveTexture, GLint specularMapActiveTexture, GLint normalMapActiveTexture, GLint heightMapActiveTexture);
1270 [[maybe_unused]]
void draw()
const;
1274 [[maybe_unused]]
void drawSkeleton()
const;
1282 [[nodiscard]]
bool readMD5Anim(
const char* filename);
1287 void animate(GLfloat dt);
1294 MD5Joint* _baseSkeleton =
nullptr;
1299 MD5Mesh* _meshes =
nullptr;
1304 GLint _numJoints = 0;
1309 GLint _numMeshes = 0;
1316 GLint _maxVertices = 0;
1321 GLint _maxTriangles = 0;
1326 glm::vec3* _vertexArray =
nullptr;
1331 glm::vec2* _texelArray =
nullptr;
1336 GLuint* _vertexIndicesArray =
nullptr;
1346 GLuint _vbo[2] = {0, 0};
1352 GLuint _skeletonVAO = 0;
1356 GLuint _skeletonVBO = 0;
1360 MD5Joint* _skeleton =
nullptr;
1366 MD5Animation* _animation =
nullptr;
1370 bool _isAnimated =
false;
1374 MD5AnimationState _animationInfo;
1379 GLint _diffuseActiveTexture = GL_TEXTURE0;
1383 GLint _specularActiveTexture = GL_TEXTURE1;
1387 GLint _normalActiveTexture = GL_TEXTURE2;
1391 GLint _heightActiveTexture = GL_TEXTURE3;
1399 void _prepareMesh(
const MD5Mesh* pMESH)
const;
1404 void _drawMesh(
const MD5Mesh* pMESH)
const;
1410 [[nodiscard]]
bool _checkAnimValidity()
const;
1419 static void _buildFrameSkeleton(
const MD5JointInfo* pJOINT_INFOS,
1420 const MD5BaseFrameJoint* pBASE_FRAME,
1421 const GLfloat* pANIM_FRAME_DATA,
1422 const MD5Joint* pSkeletonFrame,
1428 void _interpolateSkeletons(GLfloat interp);
1436 void _freeVertexArrays();
1446 void _moveFromSrc(MD5Model &src);
1456 _freeVertexArrays();
1464 const char* MD5_MESH_FILE,
1465 const char* MD5_ANIM_FILE
1468 if( readMD5Model(MD5_MESH_FILE) ) {
1470 if(strcmp(MD5_ANIM_FILE,
"") != 0 ) {
1472 if( !readMD5Anim(MD5_ANIM_FILE) ) {
1476 if( !isAnimated() ) {
1477 printf (
"[.MD5_ANIM_FILE]: no animation loaded.\n");
1488 const char* FILENAME
1492 GLint currentMesh = 0;
1494 GLint totalVertices = 0;
1495 GLint totalWeights = 0;
1496 GLint totalTriangles = 0;
1498 GLfloat minX = 999999, minY = 999999, minZ = 999999;
1499 GLfloat maxX = -999999, maxY = -999999, maxZ = -999999;
1501 printf(
"[.md5mesh]: about to read %s\n", FILENAME );
1503 FILE *fp = fopen(FILENAME,
"rb" );
1505 fprintf (stderr,
"[.md5mesh]: Error: couldn't open \"%s\"!\n", FILENAME);
1509 while( !feof(fp) ) {
1511 fgets( buff,
sizeof(buff), fp );
1513 if( sscanf(buff,
" MD5Version %d", &version) == 1 ) {
1514 if( version != 10 ) {
1516 fprintf (stderr,
"[.md5mesh]: Error: bad model version\n");
1520 }
else if( sscanf(buff,
" numJoints %d", &_numJoints) == 1 ) {
1521 if( _numJoints > 0 ) {
1523 _baseSkeleton =
new MD5Joint[_numJoints];
1525 }
else if( sscanf(buff,
" numMeshes %d", &_numMeshes) == 1 ) {
1526 if( _numMeshes > 0 ) {
1528 _meshes =
new MD5Mesh[_numMeshes];
1530 }
else if( strncmp(buff,
"joints {", 8) == 0 ) {
1532 for(GLint i = 0; i < _numJoints; ++i) {
1533 MD5Joint *joint = &_baseSkeleton[i];
1536 fgets( buff,
sizeof(buff), fp );
1538 if( sscanf(buff,
"%s %d ( %f %f %f ) ( %f %f %f )",
1547 }
else if( strncmp(buff,
"mesh {", 6) == 0 ) {
1548 MD5Mesh *mesh = &_meshes[currentMesh];
1549 GLint vert_index = 0;
1550 GLint tri_index = 0;
1551 GLint weight_index = 0;
1552 GLfloat floatData[4];
1555 while( buff[0] !=
'}' && !feof(fp) ) {
1557 fgets( buff,
sizeof(buff), fp );
1559 if( strstr( buff,
"shader ") ) {
1560 GLint quote = 0, j = 0;
1563 for(
unsigned long uli = 0; uli <
sizeof(buff) && (quote < 2); ++uli) {
1564 if( buff[uli] ==
'\"' )
1567 if( (quote == 1) && (buff[uli] !=
'\"') ) {
1568 mesh->
shader[j] = buff[uli];
1577 mesh->
textures[MD5Mesh::TextureMap::DIFFUSE].
texHandle = CSCI441::TextureUtils::loadAndRegisterTexture( mesh->
textures[MD5Mesh::TextureMap::DIFFUSE].
filename, GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, GL_REPEAT, GL_REPEAT, GL_FALSE, GL_FALSE);
1581 mesh->
textures[MD5Mesh::TextureMap::DIFFUSE].
texHandle = CSCI441::TextureUtils::loadAndRegisterTexture( mesh->
textures[MD5Mesh::TextureMap::DIFFUSE].
filename, GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, GL_REPEAT, GL_REPEAT, GL_FALSE, GL_FALSE );
1585 mesh->
textures[MD5Mesh::TextureMap::DIFFUSE].
texHandle = CSCI441::TextureUtils::loadAndRegisterTexture(mesh->
textures[MD5Mesh::TextureMap::DIFFUSE].
filename, GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, GL_REPEAT, GL_REPEAT, GL_FALSE, GL_FALSE );
1587 fprintf(stderr,
"[.md5mesh | ERROR]: Could not load diffuse map for shader %s\n", mesh->
shader);
1595 mesh->
textures[MD5Mesh::TextureMap::SPECULAR].
texHandle = CSCI441::TextureUtils::loadAndRegisterTexture( mesh->
textures[MD5Mesh::TextureMap::SPECULAR].
filename, GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, GL_REPEAT, GL_REPEAT, GL_FALSE, GL_FALSE );
1599 mesh->
textures[MD5Mesh::TextureMap::SPECULAR].
texHandle = CSCI441::TextureUtils::loadAndRegisterTexture( mesh->
textures[MD5Mesh::TextureMap::SPECULAR].
filename, GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, GL_REPEAT, GL_REPEAT, GL_FALSE, GL_FALSE );
1601 fprintf(stderr,
"[.md5mesh | ERROR]: Could not load specular map for shader %s\n", mesh->
shader);
1607 strcat(mesh->
textures[MD5Mesh::TextureMap::NORMAL].
filename,
"_local.tga");
1608 mesh->
textures[MD5Mesh::TextureMap::NORMAL].
texHandle = CSCI441::TextureUtils::loadAndRegisterTexture( mesh->
textures[MD5Mesh::TextureMap::NORMAL].
filename, GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, GL_REPEAT, GL_REPEAT, GL_FALSE, GL_FALSE );
1611 strcat(mesh->
textures[MD5Mesh::TextureMap::NORMAL].
filename,
"_local.png");
1612 mesh->
textures[MD5Mesh::TextureMap::NORMAL].
texHandle = CSCI441::TextureUtils::loadAndRegisterTexture( mesh->
textures[MD5Mesh::TextureMap::NORMAL].
filename, GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, GL_REPEAT, GL_REPEAT, GL_FALSE, GL_FALSE );
1614 fprintf(stderr,
"[.md5mesh | ERROR]: Could not load normal map for shader %s\n", mesh->
shader);
1621 mesh->
textures[MD5Mesh::TextureMap::HEIGHT].
texHandle = CSCI441::TextureUtils::loadAndRegisterTexture( mesh->
textures[MD5Mesh::TextureMap::HEIGHT].
filename, GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, GL_REPEAT, GL_REPEAT, GL_FALSE, GL_FALSE );
1625 mesh->
textures[MD5Mesh::TextureMap::HEIGHT].
texHandle = CSCI441::TextureUtils::loadAndRegisterTexture( mesh->
textures[MD5Mesh::TextureMap::HEIGHT].
filename, GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, GL_REPEAT, GL_REPEAT, GL_FALSE, GL_FALSE );
1627 fprintf(stderr,
"[.md5mesh | ERROR]: Could not load height map for shader %s\n", mesh->
shader);
1631 }
else if( sscanf(buff,
" numverts %d", &mesh->
numVertices) == 1 ) {
1641 }
else if( sscanf(buff,
" numtris %d", &mesh->
numTriangles) == 1 ) {
1651 }
else if( sscanf(buff,
" numweights %d", &mesh->
numWeights) == 1 ) {
1658 }
else if( sscanf(buff,
" vert %d ( %f %f ) %d %d",
1660 &floatData[0], &floatData[1],
1661 &intData[0], &intData[1]) == 5
1668 }
else if( sscanf(buff,
" tri %d %d %d %d",
1670 &intData[0], &intData[1], &intData[2]) == 4
1676 }
else if( sscanf(buff,
" weight %d %d %f ( %f %f %f )",
1677 &weight_index, &intData[0], &floatData[3],
1678 &floatData[0], &floatData[1], &floatData[2]) == 6
1687 if( floatData[0] < minX ) { minX = floatData[0]; }
1688 if( floatData[0] > maxX ) { maxX = floatData[0]; }
1689 if( floatData[1] < minY ) { minY = floatData[1]; }
1690 if( floatData[1] > maxY ) { maxY = floatData[1]; }
1691 if( floatData[2] < minZ ) { minZ = floatData[2]; }
1692 if( floatData[2] > maxZ ) { maxZ = floatData[2]; }
1702 _skeleton = _baseSkeleton;
1704 printf(
"[.md5mesh]: finished reading %s\n", FILENAME );
1705 printf(
"[.md5mesh]: read in %d meshes, %d joints, %d vertices, %d weights, and %d triangles\n", _numMeshes, _numJoints, totalVertices, totalWeights, totalTriangles );
1706 printf(
"[.md5mesh]: base pose %f units across in X, %f units across in Y, %f units across in Z\n", (maxX - minX), (maxY-minY), (maxZ - minZ) );
1713CSCI441::MD5Model::_freeModel()
1715 delete[] _baseSkeleton;
1716 if (_baseSkeleton == _skeleton) _skeleton =
nullptr;
1717 _baseSkeleton =
nullptr;
1728 for(GLint i = 0; i < _numMeshes; ++i) {
1730 _prepareMesh(&mesh);
1736CSCI441::MD5Model::_prepareMesh(
1737 const MD5Mesh *pMESH
1742 for(k = 0, i = 0; i < pMESH->numTriangles; ++i) {
1743 for(j = 0; j < 3; ++j, ++k)
1744 _vertexIndicesArray[k] = pMESH->triangles[i].index[j];
1748 for(i = 0; i < pMESH->numVertices; ++i) {
1749 glm::vec3 finalVertex = {0.0f, 0.0f, 0.0f };
1752 for(j = 0; j < pMESH->vertices[i].count; ++j) {
1753 const MD5Weight *weight = &pMESH->weights[pMESH->vertices[i].start + j];
1754 const MD5Joint *joint = &_skeleton[weight->joint];
1757 const glm::vec3 weightedVertex = glm::rotate(joint->orientation, glm::vec4(weight->position, 0.0f));
1760 finalVertex.x += (joint->position.x + weightedVertex.x) * weight->bias;
1761 finalVertex.y += (joint->position.y + weightedVertex.y) * weight->bias;
1762 finalVertex.z += (joint->position.z + weightedVertex.z) * weight->bias;
1765 _vertexArray[i].x = finalVertex.x;
1766 _vertexArray[i].y = finalVertex.y;
1767 _vertexArray[i].z = finalVertex.z;
1769 _texelArray[i].s = pMESH->vertices[i].texCoord.s;
1770 _texelArray[i].t = pMESH->vertices[i].texCoord.t;
1773 glBindVertexArray(_vao );
1775 glBindBuffer(GL_ARRAY_BUFFER, _vbo[0] );
1776 glBufferSubData(GL_ARRAY_BUFFER, 0,
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * pMESH->numVertices, &_vertexArray[0] );
1777 glBufferSubData(GL_ARRAY_BUFFER,
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * _maxVertices,
static_cast<GLsizeiptr
>(
sizeof(glm::vec2)) * pMESH->numVertices, &_texelArray[0] );
1779 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vbo[1] );
1780 glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0,
static_cast<GLsizeiptr
>(
sizeof(GLuint)) * pMESH->numTriangles * 3, _vertexIndicesArray );
1784CSCI441::MD5Model::_drawMesh(
1785 const MD5Mesh *pMESH
1787 if (pMESH->textures[MD5Mesh::TextureMap::SPECULAR].texHandle != 0) {
1789 glActiveTexture(_specularActiveTexture);
1790 glBindTexture(GL_TEXTURE_2D, pMESH->textures[MD5Mesh::TextureMap::SPECULAR].texHandle );
1792 if (pMESH->textures[MD5Mesh::TextureMap::NORMAL].texHandle != 0) {
1794 glActiveTexture(_normalActiveTexture);
1795 glBindTexture(GL_TEXTURE_2D, pMESH->textures[MD5Mesh::TextureMap::NORMAL].texHandle );
1797 if (pMESH->textures[MD5Mesh::TextureMap::HEIGHT].texHandle != 0) {
1799 glActiveTexture(_heightActiveTexture);
1800 glBindTexture(GL_TEXTURE_2D, pMESH->textures[MD5Mesh::TextureMap::HEIGHT].texHandle );
1803 if (pMESH->textures[MD5Mesh::TextureMap::DIFFUSE].texHandle != 0) {
1805 glActiveTexture(_diffuseActiveTexture);
1806 glBindTexture(GL_TEXTURE_2D, pMESH->textures[MD5Mesh::TextureMap::DIFFUSE].texHandle );
1808 if (_diffuseActiveTexture != GL_TEXTURE0) {
1810 glActiveTexture(GL_TEXTURE0);
1813 glBindVertexArray(_vao );
1814 glDrawElements(GL_TRIANGLES, pMESH->numTriangles * 3, GL_UNSIGNED_INT, (
void*)
nullptr );
1820 const GLuint vPosAttribLoc,
1821 const GLuint vColorAttribLoc,
1822 const GLuint vTexCoordAttribLoc
1824 _vertexArray =
new glm::vec3[_maxVertices];
1825 _texelArray =
new glm::vec2[_maxVertices];
1826 _vertexIndicesArray =
new GLuint[_maxTriangles * 3];
1828 glGenVertexArrays( 1, &_vao );
1829 glBindVertexArray(_vao );
1831 glGenBuffers(2, _vbo );
1832 glBindBuffer(GL_ARRAY_BUFFER, _vbo[0] );
1833 glBufferData(GL_ARRAY_BUFFER,
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * _maxVertices +
static_cast<GLsizeiptr
>(
sizeof(glm::vec2)) * _maxVertices,
nullptr, GL_DYNAMIC_DRAW );
1835 glEnableVertexAttribArray( vPosAttribLoc );
1836 glVertexAttribPointer( vPosAttribLoc, 3, GL_FLOAT, GL_FALSE, 0,
static_cast<void *
>(
nullptr) );
1838 glEnableVertexAttribArray( vTexCoordAttribLoc );
1839 glVertexAttribPointer( vTexCoordAttribLoc, 2, GL_FLOAT, GL_FALSE, 0,
reinterpret_cast<void *
>(
sizeof(glm::vec3) * _maxVertices) );
1841 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vbo[1] );
1842 glBufferData(GL_ELEMENT_ARRAY_BUFFER,
static_cast<GLsizeiptr
>(
sizeof(GLuint)) * _maxTriangles * 3,
nullptr, GL_DYNAMIC_DRAW );
1844 printf(
"[.md5mesh]: Model VAO/VBO/IBO registered at %u/%u/%u\n", _vao, _vbo[0], _vbo[1] );
1846 glGenVertexArrays( 1, &_skeletonVAO );
1847 glBindVertexArray(_skeletonVAO );
1849 glGenBuffers( 1, &_skeletonVBO );
1850 glBindBuffer(GL_ARRAY_BUFFER, _skeletonVBO );
1851 glBufferData(GL_ARRAY_BUFFER,
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * _numJoints * 3 * 2,
nullptr, GL_DYNAMIC_DRAW );
1853 glEnableVertexAttribArray( vPosAttribLoc );
1854 glVertexAttribPointer( vPosAttribLoc, 3, GL_FLOAT, GL_FALSE, 0,
static_cast<void *
>(
nullptr) );
1856 glEnableVertexAttribArray( vColorAttribLoc );
1857 glVertexAttribPointer( vColorAttribLoc, 3, GL_FLOAT, GL_FALSE, 0,
reinterpret_cast<void *
>(
sizeof(glm::vec3) * _numJoints * 3) );
1859 printf(
"[.md5mesh]: Skeleton VAO/VBO registered at %u/%u\n", _skeletonVAO, _skeletonVBO );
1864 const GLint diffuseMapActiveTexture = GL_TEXTURE0,
1865 const GLint specularMapActiveTexture = GL_TEXTURE1,
1866 const GLint normalMapActiveTexture = GL_TEXTURE2,
1867 const GLint heightMapActiveTexture = GL_TEXTURE3
1869 _diffuseActiveTexture = diffuseMapActiveTexture;
1870 _specularActiveTexture = specularMapActiveTexture;
1871 _normalActiveTexture = normalMapActiveTexture;
1872 _heightActiveTexture = heightMapActiveTexture;
1876CSCI441::MD5Model::_freeVertexArrays()
1878 delete[] _vertexArray;
1879 _vertexArray =
nullptr;
1881 delete[] _vertexIndicesArray;
1882 _vertexIndicesArray =
nullptr;
1884 delete[] _texelArray;
1885 _texelArray =
nullptr;
1887 glDeleteVertexArrays( 1, &_vao );
1890 glDeleteBuffers(2, _vbo );
1894 glDeleteVertexArrays( 1, &_skeletonVAO );
1897 glDeleteBuffers( 1, &_skeletonVBO );
1905 glBindVertexArray(_skeletonVAO );
1906 glBindBuffer(GL_ARRAY_BUFFER, _skeletonVBO );
1908 constexpr glm::vec3 jointColor = {1.0f, 1.0f, 0.0f };
1909 constexpr glm::vec3 boneColor = {1.0f, 0.0f, 1.0f };
1912 for(GLint i = 0; i < _numJoints; ++i ) {
1913 glBufferSubData(GL_ARRAY_BUFFER, i *
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)),
sizeof(glm::vec3), &(_skeleton[i].position) );
1914 glBufferSubData(GL_ARRAY_BUFFER, i *
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) +
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * _numJoints * 3,
sizeof(glm::vec3), &jointColor[0]);
1919 for(GLint i = 0; i < _numJoints; ++i ) {
1920 if( _skeleton[i].parent != MD5Joint::NULL_JOINT ) {
1923 static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * _numJoints + (i * 2) *
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)),
1924 static_cast<GLsizeiptr
>(
sizeof(glm::vec3)),
1925 &(_skeleton[_skeleton[i].parent].position)
1929 static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * _numJoints + (i * 2) *
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) +
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * _numJoints * 3,
1936 static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * _numJoints + (i * 2) *
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) +
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)),
1937 static_cast<GLsizeiptr
>(
sizeof(glm::vec3)),
1938 &(_skeleton[i].position)
1942 static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * _numJoints + (i * 2) *
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) +
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) +
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * _numJoints * 3,
1951 glDrawArrays(GL_POINTS, 0, _numJoints );
1954 glLineWidth( 3.0f );
1955 glDrawArrays(GL_LINES, _numJoints, numBones * 2 );
1960CSCI441::MD5Model::_checkAnimValidity()
const
1963 if( _numJoints != _animation->getNumberOfJoints() ) {
1964 fprintf(stdout,
"\n[.md5anim]: skeleton and animation do not have same number of joints. cannot apply animation to skeleton\n\n");
1967 if (_animation->getNumberOfJoints() == 0 ) {
1968 fprintf(stdout,
"\n[.md5anim]: animation has zero joints. cannot apply animation to skeleton\n\n");
1973 for(GLint i = 0; i < _numJoints; ++i) {
1975 if (_baseSkeleton[i].parent != _animation->getSkeletonFrameJoint(0, i).parent) {
1976 fprintf(stdout,
"\n[.md5anim]: skeleton and animation joints do not have same parent index. cannot apply animation to skeleton\n\n");
1981 if (strcmp (_baseSkeleton[i].name, _animation->getSkeletonFrameJoint(0, i).name) != 0) {
1982 fprintf(stdout,
"\n[.md5anim]: skeleton and animation joints do not have same name. cannot apply animation to skeleton\n\n");
1987 fprintf(stdout,
"\n[.md5anim]: skeleton and animation match. animation can be applied to skeleton\n\n");
1992CSCI441::MD5Model::_buildFrameSkeleton(
1993 const MD5JointInfo* pJOINT_INFOS,
1994 const MD5BaseFrameJoint* pBASE_FRAME,
1995 const GLfloat* pANIM_FRAME_DATA,
1996 const MD5Joint* pSkeletonFrame,
1997 const GLint NUM_JOINTS
1999 if(pJOINT_INFOS ==
nullptr
2000 || pBASE_FRAME ==
nullptr
2001 || pANIM_FRAME_DATA ==
nullptr
2002 || pSkeletonFrame ==
nullptr)
return;
2004 for(GLint i = 0; i < NUM_JOINTS; ++i) {
2005 const MD5BaseFrameJoint *baseJoint = &pBASE_FRAME[i];
2006 glm::vec3 animatedPosition = baseJoint->position;
2007 glm::quat animatedOrientation = baseJoint->orientation;
2011 if(pJOINT_INFOS[i].flags & 1 ) {
2012 animatedPosition.x = pANIM_FRAME_DATA[pJOINT_INFOS[i].startIndex + j];
2017 if(pJOINT_INFOS[i].flags & 2 ) {
2018 animatedPosition.y = pANIM_FRAME_DATA[pJOINT_INFOS[i].startIndex + j];
2023 if(pJOINT_INFOS[i].flags & 4 ) {
2024 animatedPosition.z = pANIM_FRAME_DATA[pJOINT_INFOS[i].startIndex + j];
2029 if(pJOINT_INFOS[i].flags & 8 ) {
2030 animatedOrientation.x = pANIM_FRAME_DATA[pJOINT_INFOS[i].startIndex + j];
2035 if(pJOINT_INFOS[i].flags & 16 ) {
2036 animatedOrientation.y = pANIM_FRAME_DATA[pJOINT_INFOS[i].startIndex + j];
2041 if(pJOINT_INFOS[i].flags & 32 ) {
2042 animatedOrientation.z = pANIM_FRAME_DATA[pJOINT_INFOS[i].startIndex + j];
2046 animatedOrientation.w = glm::extractRealComponent(animatedOrientation);
2051 const auto thisJoint =
const_cast<MD5Joint *
>(&pSkeletonFrame[i]);
2053 const GLint parent = pJOINT_INFOS[i].parent;
2054 thisJoint->parent = parent;
2055 strcpy (thisJoint->name, pJOINT_INFOS[i].name);
2058 if( thisJoint->parent == MD5Joint::NULL_JOINT ) {
2059 thisJoint->position = animatedPosition;
2060 thisJoint->orientation = animatedOrientation;
2062 const MD5Joint *parentJoint = &pSkeletonFrame[parent];
2063 glm::vec3 rotatedPosition = glm::rotate(parentJoint->orientation, glm::vec4(animatedPosition, 0.0f));
2066 thisJoint->position = parentJoint->position + rotatedPosition;
2069 thisJoint->orientation = glm::normalize( glm::cross(parentJoint->orientation, animatedOrientation) );
2076 const char *filename
2081 GLfloat *animFrameData =
nullptr;
2083 GLint numAnimatedComponents;
2084 GLint frameIndex, numFrames, numJoints;
2087 printf(
"[.md5anim]: about to read %s\n", filename );
2089 FILE *fp = fopen( filename,
"rb" );
2091 fprintf (stderr,
"[.md5anim]: Error: couldn't open \"%s\"!\n", filename);
2095 while( !feof(fp) ) {
2097 fgets( buff,
sizeof(buff), fp );
2099 if( sscanf(buff,
" MD5Version %d", &version) == 1 ) {
2100 if( version != 10 ) {
2102 fprintf (stderr,
"[.md5anim]: Error: bad animation version\n");
2106 }
else if( sscanf(buff,
" numFrames %d", &numFrames) == 1 ) {
2108 _animation->setNumberOfFrames(numFrames);
2109 }
else if( sscanf(buff,
" numJoints %d", &numJoints) == 1 ) {
2110 if (jointInfos !=
nullptr) {
2111 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. numJoints already specified\n" );
2113 if( numJoints > 0 ) {
2114 _animation->setNumberOfJoints(numJoints);
2120 }
else if( sscanf(buff,
" frameRate %d", &_animation->frameRate) == 1 ) {
2122 }
else if( sscanf(buff,
" numAnimatedComponents %d", &numAnimatedComponents) == 1 ) {
2123 if (animFrameData !=
nullptr) {
2124 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. numAnimatedComponents already specified\n" );
2126 if( numAnimatedComponents > 0 ) {
2128 animFrameData =
new GLfloat[numAnimatedComponents];
2130 }
else if( strncmp(buff,
"hierarchy {", 11) == 0 ) {
2131 if (jointInfos ==
nullptr) {
2132 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. numJoints not specified prior to hierarchy\n" );
2134 for(i = 0; i < numJoints; ++i) {
2136 fgets( buff,
sizeof(buff), fp );
2139 sscanf(buff,
" %s %d %d %d",
2140 jointInfos[i].name, &jointInfos[i].parent,
2141 &jointInfos[i].flags, &jointInfos[i].startIndex);
2144 }
else if( strncmp(buff,
"bounds {", 8) == 0 ) {
2145 if (_animation->getNumberOfFrames() == 0) {
2146 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. numFrames not specified prior to bounds\n" );
2148 for(i = 0; i < _animation->getNumberOfFrames(); ++i) {
2150 fgets( buff,
sizeof(buff), fp );
2153 sscanf(buff,
" ( %f %f %f ) ( %f %f %f )",
2154 &_animation->getBoundingBox(i).min[0], &_animation->getBoundingBox(i).min[1], &_animation->getBoundingBox(i).min[2],
2155 &_animation->getBoundingBox(i).max[0], &_animation->getBoundingBox(i).max[1], &_animation->getBoundingBox(i).max[2]);
2158 }
else if( strncmp(buff,
"baseframe {", 10) == 0 ) {
2159 if (baseFrame ==
nullptr) {
2160 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. numJoints not specified prior to baseframe\n" );
2162 for(i = 0; i < numJoints; ++i) {
2164 fgets( buff,
sizeof(buff), fp );
2167 if( sscanf(buff,
" ( %f %f %f ) ( %f %f %f )",
2168 &baseFrame[i].position[0], &baseFrame[i].position[1], &baseFrame[i].position[2],
2169 &baseFrame[i].orientation[0], &baseFrame[i].orientation[1], &baseFrame[i].orientation[2]) == 6 ) {
2171 baseFrame[i].
orientation.w = glm::extractRealComponent(baseFrame[i].orientation);
2175 }
else if(sscanf(buff,
" frame %d", &frameIndex) == 1 ) {
2176 if (animFrameData ==
nullptr) {
2177 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. numAnimatedComponents not specified prior to frame\n" );
2178 }
else if (_animation->getNumberOfFrames() == 0) {
2179 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. numFrames not specified prior to frame\n" );
2180 }
else if (baseFrame ==
nullptr) {
2181 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. baseframe not specified prior to frame\n" );
2182 }
else if (jointInfos ==
nullptr) {
2183 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. numJoints not specified prior to frame\n" );
2186 for(i = 0; i < numAnimatedComponents; ++i)
2187 fscanf( fp,
"%f", &animFrameData[i] );
2190 _buildFrameSkeleton(jointInfos, baseFrame, animFrameData,
2191 _animation->getSkeletonFrame(frameIndex),
2199 printf(
"[.md5anim]: finished reading %s\n", filename );
2200 printf(
"[.md5anim]: read in %d frames of %d joints with %d animated components\n", _animation->getNumberOfFrames(), _animation->getNumberOfJoints(), numAnimatedComponents );
2201 printf(
"[.md5anim]: animation's frame rate is %d\n", _animation->frameRate );
2204 delete[] animFrameData;
2206 delete[] jointInfos;
2209 _animationInfo.currFrame = 0;
2210 _animationInfo.nextFrame = 1;
2212 _animationInfo.lastTime = 0.0f;
2213 _animationInfo.maxTime = 1.0f /
static_cast<GLfloat
>(_animation->frameRate);
2216 if (_animation->getNumberOfJoints() == 0) {
2217 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. numJoints never specified\n" );
2219 _skeleton =
new MD5Joint[_animation->getNumberOfJoints()];
2222 if( _checkAnimValidity() ) {
2232CSCI441::MD5Model::_freeAnim()
2235 _skeleton =
nullptr;
2238 _animation =
nullptr;
2241inline void CSCI441::MD5Model::_moveFromSrc(MD5Model &src) {
2242 this->_baseSkeleton = src._baseSkeleton;
2243 src._baseSkeleton =
nullptr;
2245 this->_meshes = src._meshes;
2246 src._meshes =
nullptr;
2248 this->_maxVertices = src._maxVertices;
2249 src._maxVertices = 0;
2251 this->_maxTriangles = src._maxTriangles;
2252 src._maxTriangles = 0;
2254 this->_vertexArray = src._vertexArray;
2255 src._vertexArray =
nullptr;
2257 this->_texelArray = src._texelArray;
2258 src._texelArray =
nullptr;
2260 this->_vertexIndicesArray = src._vertexIndicesArray;
2261 src._vertexIndicesArray =
nullptr;
2263 this->_vao = src._vao;
2266 this->_vbo[0] = src._vbo[0];
2267 this->_vbo[1] = src._vbo[1];
2271 this->_skeletonVAO = src._skeletonVAO;
2272 src._skeletonVAO = 0;
2274 this->_skeletonVBO = src._skeletonVBO;
2275 src._skeletonVBO = 0;
2277 this->_skeleton = src._skeleton;
2278 src._skeleton =
nullptr;
2280 this->_animation = src._animation;
2281 src._animation =
nullptr;
2283 this->_isAnimated = src._isAnimated;
2284 src._isAnimated =
false;
2286 this->_animationInfo = std::move( src._animationInfo );
2290CSCI441::MD5Model::_interpolateSkeletons(
const GLfloat interp)
2292 const MD5Joint *skeletonA = _animation->getSkeletonFrame(_animationInfo.currFrame);
2293 const MD5Joint *skeletonB = _animation->getSkeletonFrame(_animationInfo.nextFrame);
2295 for(GLint i = 0; i < _animation->getNumberOfJoints(); ++i) {
2297 _skeleton[i].parent = skeletonA[i].parent;
2300 _skeleton[i].position[0] = skeletonA[i].position[0] + interp * (skeletonB[i].position[0] - skeletonA[i].position[0]);
2301 _skeleton[i].position[1] = skeletonA[i].position[1] + interp * (skeletonB[i].position[1] - skeletonA[i].position[1]);
2302 _skeleton[i].position[2] = skeletonA[i].position[2] + interp * (skeletonB[i].position[2] - skeletonA[i].position[2]);
2305 _skeleton[i].orientation = glm::slerp(skeletonA[i].orientation, skeletonB[i].orientation, interp);
2314 const GLint maxFrames = _animation->getNumberOfFrames() - 1;
2315 if (maxFrames <= 0)
return;
2317 _animationInfo.lastTime += dt;
2320 if( _animationInfo.lastTime >= _animationInfo.maxTime ) {
2321 _animationInfo.currFrame++;
2322 _animationInfo.nextFrame++;
2323 _animationInfo.lastTime = 0.0;
2325 if( _animationInfo.currFrame > maxFrames )
2326 _animationInfo.currFrame = 0;
2328 if( _animationInfo.nextFrame > maxFrames )
2329 _animationInfo.nextFrame = 0;
2333 _interpolateSkeletons( _animationInfo.lastTime *
static_cast<GLfloat
>(_animation->frameRate) );
Helper functions to work with OpenGL Textures.
stores an entire animation sequence for a given MD5 Model
Definition: MD5Model.hpp:879
MD5Animation & operator=(MD5Animation &&src) noexcept
reassign object by moving an existing object
Definition: MD5Model.hpp:1054
MD5Animation()=default
construct a default animation object
MD5Animation & operator=(const MD5Animation &OTHER)=delete
do not allow animation objects to be copied
MD5Animation(MD5Animation &&src) noexcept
construct an animation object by moving an existing object
Definition: MD5Model.hpp:1046
MD5Animation(const MD5Animation &OTHER)=delete
do not allow animation objects to be copied
GLint getNumberOfFrames() const
getter to retrieve number of frames within the animation
Definition: MD5Model.hpp:891
void setNumberOfFrames(const GLint numFrames)
sets the number of frames and allocates skeletonFrames and boundingBoxes to the associated size
Definition: MD5Model.hpp:898
const MD5Joint * getSkeletonFrame(const GLint frameIndex) const
get the skeleton for a specific animation frame
Definition: MD5Model.hpp:959
GLint frameRate
number of frames per second to draw for the animation
Definition: MD5Model.hpp:885
~MD5Animation()
deallocate animation arrays
Definition: MD5Model.hpp:1017
MD5Joint & getSkeletonFrameJoint(const GLint frameIndex, const GLint jointIndex) const
get the specific joint from a skeleton for a specific animation frame
Definition: MD5Model.hpp:977
MD5BoundingBox & getBoundingBox(const GLint frameIndex) const
get the specific bounding box for a target frame
Definition: MD5Model.hpp:1000
void setNumberOfJoints(const GLint numJoints)
set the number of joints in the skeleton of each animation frame and allocates each frame of skeleton...
Definition: MD5Model.hpp:932
GLint getNumberOfJoints() const
get the number of joints in each skeleton frame
Definition: MD5Model.hpp:924
stores a Doom3 MD5 Mesh + Animation
Definition: MD5Model.hpp:76
void draw() const
draws all the meshes that make up the model
Definition: MD5Model.hpp:1725
bool readMD5Model(const char *FILENAME)
parses md5mesh file and allocates corresponding mesh data
Definition: MD5Model.hpp:1487
bool isAnimated() const
returns if the MD5 Model has an accompanying animation
Definition: MD5Model.hpp:1239
bool loadMD5Model(const char *MD5_MESH_FILE, const char *MD5_ANIM_FILE="")
loads a corresponding md5mesh and md5anim file to the object
Definition: MD5Model.hpp:1463
void setActiveTextures(GLint diffuseMapActiveTexture, GLint specularMapActiveTexture, GLint normalMapActiveTexture, GLint heightMapActiveTexture)
specify which texture targets each texture map should be bound to when rendering
Definition: MD5Model.hpp:1863
MD5Model()
initializes an empty MD5 Model
Definition: MD5Model.hpp:1196
MD5Model & operator=(const MD5Model &)=delete
do not allow MD5 models to be copied
bool readMD5Anim(const char *filename)
reads in an animation sequence from an external file
Definition: MD5Model.hpp:2075
void allocVertexArrays(GLuint vPosAttribLoc, GLuint vColorAttribLoc, GLuint vTexCoordAttribLoc)
binds model VBOs to attribute pointer locations
Definition: MD5Model.hpp:1819
void animate(GLfloat dt)
advances the model forward in its animation sequence the corresponding amount of time based on frame ...
Definition: MD5Model.hpp:2312
MD5Model & operator=(MD5Model &&src) noexcept
do not allow MD5 models to be moved
Definition: MD5Model.hpp:1220
MD5Model(const MD5Model &)=delete
do not allow MD5 models to be copied
MD5Model(MD5Model &&src) noexcept
do not allow MD5 models to be moved
Definition: MD5Model.hpp:1214
~MD5Model()
deallocates any used memory on the CPU and GPU
Definition: MD5Model.hpp:1453
void drawSkeleton() const
draws the skeleton joints (as points) and bones (as lines)
Definition: MD5Model.hpp:1903
CSCI441 Helper Functions for OpenGL.
Definition: ArcballCam.hpp:17
stores state of current animation frame
Definition: MD5Model.hpp:1107
GLint currFrame
index of current frame model is in
Definition: MD5Model.hpp:1111
MD5AnimationState(MD5AnimationState &&src) noexcept
construct an object by moving an existing object
Definition: MD5Model.hpp:1152
MD5AnimationState(const MD5AnimationState &OTHER)
construct an object by copying an existing object
Definition: MD5Model.hpp:1134
MD5AnimationState()=default
construct a default object
GLint nextFrame
index of next frame model will move to
Definition: MD5Model.hpp:1115
MD5AnimationState & operator=(MD5AnimationState &&src) noexcept
reassign object by moving an existing object
Definition: MD5Model.hpp:1160
MD5AnimationState & operator=(const MD5AnimationState &OTHER)
reassign object by copying an existing object
Definition: MD5Model.hpp:1142
GLfloat lastTime
time of last frame interpolation
Definition: MD5Model.hpp:1119
GLfloat maxTime
duration of a single frame
Definition: MD5Model.hpp:1124
base frame joint
Definition: MD5Model.hpp:730
glm::quat orientation
joint orientation expressed as a quaternion in object space
Definition: MD5Model.hpp:738
MD5BaseFrameJoint & operator=(const MD5BaseFrameJoint &OTHER)
reassign object by copying an existing object
Definition: MD5Model.hpp:756
MD5BaseFrameJoint()=default
construct a default object
MD5BaseFrameJoint(MD5BaseFrameJoint &&src) noexcept
construct object by moving an existing object
Definition: MD5Model.hpp:766
glm::vec3 position
position of the joint in object space
Definition: MD5Model.hpp:734
MD5BaseFrameJoint(const MD5BaseFrameJoint &OTHER)
construct an object by copying an existing object
Definition: MD5Model.hpp:748
MD5BaseFrameJoint & operator=(MD5BaseFrameJoint &&src) noexcept
reassign object by moving an existing object
Definition: MD5Model.hpp:774
bounding box containing the model during animation
Definition: MD5Model.hpp:805
MD5BoundingBox(const MD5BoundingBox &OTHER)
construct an object by copying an existing object
Definition: MD5Model.hpp:823
MD5BoundingBox & operator=(MD5BoundingBox &&src) noexcept
reassign object by moving an existing object
Definition: MD5Model.hpp:849
glm::vec3 min
minimum dimension bound
Definition: MD5Model.hpp:809
MD5BoundingBox(MD5BoundingBox &&src) noexcept
construct an object by moving an existing object
Definition: MD5Model.hpp:841
glm::vec3 max
maximum dimension bound
Definition: MD5Model.hpp:813
MD5BoundingBox & operator=(const MD5BoundingBox &OTHER)
reassign object by copying an existing object
Definition: MD5Model.hpp:831
MD5BoundingBox()=default
construct a default object
a joint of the MD5 Skeleton
Definition: MD5Model.hpp:82
MD5Joint(const MD5Joint &OTHER)
construct a joint object by copying an existing joint
Definition: MD5Model.hpp:116
char name[MAX_NAME_LENGTH]
joint identifier
Definition: MD5Model.hpp:94
MD5Joint(MD5Joint &&src) noexcept
construct a joint object by moving an existing object
Definition: MD5Model.hpp:134
glm::vec3 position
position of the joint in object space
Definition: MD5Model.hpp:102
MD5Joint & operator=(const MD5Joint &OTHER)
reassign an existing joint object by copying another joint object
Definition: MD5Model.hpp:124
glm::quat orientation
joint orientation expressed as a quaternion in object space
Definition: MD5Model.hpp:106
MD5Joint()=default
construct a default joint object
MD5Joint & operator=(MD5Joint &&src) noexcept
reassign an existing joint object by moving another joint object
Definition: MD5Model.hpp:142
GLint parent
index of the parent joint on skeletal tree
Definition: MD5Model.hpp:98
information pertaining to each animation joint
Definition: MD5Model.hpp:640
MD5JointInfo & operator=(MD5JointInfo &&src) noexcept
reassign object by moving an existing object
Definition: MD5Model.hpp:696
GLint startIndex
index of starting parameter
Definition: MD5Model.hpp:660
MD5JointInfo(const MD5JointInfo &OTHER)
construct a joint info object by copying an existing object
Definition: MD5Model.hpp:670
MD5JointInfo(MD5JointInfo &&src) noexcept
construct joint info object by moving an existing object
Definition: MD5Model.hpp:688
GLint parent
index of parent joint on skeletal tree
Definition: MD5Model.hpp:652
char name[MAX_NAME_LENGTH]
joint identifier
Definition: MD5Model.hpp:648
MD5JointInfo & operator=(const MD5JointInfo &OTHER)
reassign object by copying an existing object
Definition: MD5Model.hpp:678
MD5JointInfo()=default
construct a default joint info object
GLuint flags
bit flags denoted how to compute the skeleton of a frame for this joint
Definition: MD5Model.hpp:656
mesh that comprises the model's skin
Definition: MD5Model.hpp:492
GLint numTriangles
number of triangles in the mesh triangle array
Definition: MD5Model.hpp:545
MD5Texture textures[NUM_TEXTURES]
texture map array
Definition: MD5Model.hpp:516
TextureMap
named entities for different texture maps applied to the model
Definition: MD5Model.hpp:520
@ DIFFUSE
diffuse map
Definition: MD5Model.hpp:524
@ SPECULAR
specular map
Definition: MD5Model.hpp:528
@ NORMAL
normal map
Definition: MD5Model.hpp:532
MD5Mesh(MD5Mesh &&src) noexcept
construct a new mesh by moving an existing object
Definition: MD5Model.hpp:589
MD5Mesh()=default
construct a default mesh object
GLint numVertices
number of vertices in the mesh vertex array
Definition: MD5Model.hpp:541
MD5Mesh & operator=(MD5Mesh &&src) noexcept
reassign mesh object by moving an existing object
Definition: MD5Model.hpp:597
MD5Triangle * triangles
array triangles comprising the mesh
Definition: MD5Model.hpp:508
char shader[MAX_NAME_LENGTH]
base filename for all textures applied to mesh
Definition: MD5Model.hpp:554
MD5Vertex * vertices
array of vertices comprising the mesh
Definition: MD5Model.hpp:504
GLint numWeights
number of weights in the mesh weight array
Definition: MD5Model.hpp:549
~MD5Mesh()
deallocate member arrays
Definition: MD5Model.hpp:563
MD5Mesh & operator=(const MD5Mesh &OTHER)=delete
do not allow meshes to be copied
MD5Weight * weights
array of weights to determine vertex position based on joint positions
Definition: MD5Model.hpp:512
MD5Mesh(const MD5Mesh &OTHER)=delete
do not allow meshes to be copied
texture handle for the model
Definition: MD5Model.hpp:414
char filename[MAX_NAME_LENGTH]
filename texture was loaded from
Definition: MD5Model.hpp:426
MD5Texture & operator=(const MD5Texture &OTHER)
reassign texture object by copying an existing object
Definition: MD5Model.hpp:444
MD5Texture & operator=(MD5Texture &&src) noexcept
reassign texture object by moving an existing object
Definition: MD5Model.hpp:462
MD5Texture(const MD5Texture &OTHER)
construct a texture object by copying an existing object
Definition: MD5Model.hpp:436
GLuint texHandle
handle of texture stored on the GPU
Definition: MD5Model.hpp:422
MD5Texture()=default
constructs a default texture object
MD5Texture(MD5Texture &&src) noexcept
construct a texture object by moving an existing object
Definition: MD5Model.hpp:454
a triangle on the mesh
Definition: MD5Model.hpp:258
MD5Triangle & operator=(const MD5Triangle &OTHER)
reassign triangle object by copying an existing triangle
Definition: MD5Model.hpp:284
MD5Triangle(MD5Triangle &&src) noexcept
construct a triangle object by moving an existing triangle
Definition: MD5Model.hpp:294
MD5Triangle & operator=(MD5Triangle &&src) noexcept
reassign triangle object by moving an existing triangle
Definition: MD5Model.hpp:302
MD5Triangle(const MD5Triangle &OTHER)
construct a triangle by copying an existing triangle
Definition: MD5Model.hpp:276
MD5Triangle()=default
construct a default triangle object
GLint index[NUM_VERTICES]
vertex indices that make up triangle
Definition: MD5Model.hpp:266
a vertex on the mesh
Definition: MD5Model.hpp:178
MD5Vertex & operator=(const MD5Vertex &OTHER)
reassign existing vertex object by copying an existing vertex object
Definition: MD5Model.hpp:208
MD5Vertex & operator=(MD5Vertex &&src) noexcept
reassign existing vertex object by moving an existing vertex object
Definition: MD5Model.hpp:226
MD5Vertex(MD5Vertex &&src) noexcept
construct a vertex object by moving an existing vertex
Definition: MD5Model.hpp:218
glm::vec2 texCoord
texture coordinate for vertex
Definition: MD5Model.hpp:182
MD5Vertex(const MD5Vertex &OTHER)
construct a vertex object by copying an existing vertex
Definition: MD5Model.hpp:200
GLint start
index of starting weight
Definition: MD5Model.hpp:186
GLint count
number of weights that determine vertex's position
Definition: MD5Model.hpp:190
MD5Vertex()=default
construct a default vertex object
the weight for a mesh vertex
Definition: MD5Model.hpp:334
MD5Weight(MD5Weight &&src) noexcept
construct a weight object by moving an existing object
Definition: MD5Model.hpp:374
MD5Weight & operator=(MD5Weight &&src) noexcept
reassign an existing weight object by moving another
Definition: MD5Model.hpp:382
MD5Weight & operator=(const MD5Weight &OTHER)
reassign an existing weight object by copying another
Definition: MD5Model.hpp:364
MD5Weight(const MD5Weight &OTHER)
construct a weight object by copying an existing weight
Definition: MD5Model.hpp:356
GLfloat bias
contribution of the weight
Definition: MD5Model.hpp:342
GLint joint
index of joint the weight depends on
Definition: MD5Model.hpp:338
MD5Weight()=default
construct a default weight object
glm::vec3 position
weight's position in object space
Definition: MD5Model.hpp:346