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>
87 static constexpr GLint NULL_JOINT = -1;
91 static constexpr GLshort MAX_NAME_LENGTH = 256;
95 char name[MAX_NAME_LENGTH] =
"";
99 GLint parent = NULL_JOINT;
103 glm::vec3 position = {0.0f, 0.0f, 0.0f};
107 glm::quat orientation = {0.0f, 0.0f, 0.0f, 0.0f};
126 if (
this != &OTHER) {
154 void _copyFromSrc(
const MD5Joint& src) {
155 strncpy(this->name, src.
name, MAX_NAME_LENGTH);
156 this->parent = src.
parent;
165 void _moveFromSrc(MD5Joint& src) {
169 strncpy(src.name,
"", MAX_NAME_LENGTH);
170 src.parent = NULL_JOINT;
171 src.position = glm::vec3(0.0f, 0.0f, 0.0f);
172 src.orientation = glm::quat(0.0f, 0.0f, 0.0f, 0.0f);
183 glm::vec2 texCoord = {0.0f, 0.0f};
210 if (
this != &OTHER) {
238 void _copyFromSrc(
const MD5Vertex &src) {
240 this->start = src.
start;
241 this->count = src.
count;
247 void _moveFromSrc(MD5Vertex& src) {
250 src.texCoord = glm::vec2(0.0f, 0.0f);
263 static constexpr GLshort NUM_VERTICES = 3;
267 GLint index[NUM_VERTICES] = {0};
286 if (
this != &OTHER) {
315 for (GLshort i = 0; i < NUM_VERTICES; i++) {
316 this->index[i] = src.
index[i];
323 void _moveFromSrc(MD5Triangle &src) {
326 for (GLint & i : src.index) {
339 GLint joint = MD5Joint::NULL_JOINT;
347 glm::vec3 position = {0.0f, 0.0f, 0.0f};
366 if (
this != &OTHER) {
394 void _copyFromSrc(
const MD5Weight &src) {
395 this->joint = src.
joint;
396 this->bias = src.
bias;
403 void _moveFromSrc(MD5Weight &src) {
406 src.joint = MD5Joint::NULL_JOINT;
408 src.position = glm::vec3(0.0f, 0.0f, 0.0f);
419 static constexpr GLshort MAX_NAME_LENGTH = 512;
423 GLuint texHandle = 0;
427 char filename[MAX_NAME_LENGTH] =
"";
446 if (
this != &OTHER) {
476 strncpy(this->filename, src.
filename, MAX_NAME_LENGTH);
482 void _moveFromSrc(MD5Texture& src) {
486 strncpy(src.filename,
"", MAX_NAME_LENGTH);
497 static constexpr GLshort MAX_NAME_LENGTH = 512;
501 static constexpr GLshort NUM_TEXTURES = 4;
542 GLint numVertices = 0;
546 GLint numTriangles = 0;
550 GLint numWeights = 0;
555 char shader[MAX_NAME_LENGTH] =
"";
609 void _moveFromSrc(
MD5Mesh& src) {
619 for (GLshort i = 0; i < NUM_TEXTURES; i++) {
620 this->textures[i] = std::move( src.
textures[i] );
632 strncpy(this->shader, src.
shader, MAX_NAME_LENGTH);
633 strncpy(src.
shader,
"", MAX_NAME_LENGTH);
645 static constexpr GLshort MAX_NAME_LENGTH = 256;
649 char name[MAX_NAME_LENGTH] =
"";
653 GLint parent = MD5Joint::NULL_JOINT;
661 GLint startIndex = 0;
680 if (
this != &OTHER) {
709 strncpy(this->name, src.
name, MAX_NAME_LENGTH);
710 this->parent = src.
parent;
711 this->flags = src.
flags;
718 void _moveFromSrc(MD5JointInfo &src) {
721 strncpy(src.name,
"", MAX_NAME_LENGTH);
722 src.parent = MD5Joint::NULL_JOINT;
735 glm::vec3 position = {0.0f, 0.0f, 0.0f};
739 glm::quat orientation = {0.0f, 0.0f, 0.0f, 0.0f};
758 if (
this != &OTHER) {
794 void _moveFromSrc(MD5BaseFrameJoint &src) {
797 src.position = glm::vec3(0.0f, 0.0f, 0.0f);
798 src.orientation = glm::quat(0.0f, 0.0f, 0.0f, 0.0f);
810 glm::vec3 min = {0.0f, 0.0f, 0.0f};
814 glm::vec3 max = {0.0f, 0.0f, 0.0f};
833 if (
this != &OTHER) {
869 void _moveFromSrc(MD5BoundingBox& src) {
872 src.min = glm::vec3(0.0f, 0.0f, 0.0f);
873 src.max = glm::vec3(0.0f, 0.0f, 0.0f);
901 if(_skeletonFrames !=
nullptr) {
902 for (GLint i = 0; i < _numFrames; ++i) {
903 delete _skeletonFrames[i];
906 delete[] _skeletonFrames;
907 _skeletonFrames =
nullptr;
908 delete[] _boundingBoxes;
909 _boundingBoxes =
nullptr;
911 _numFrames = numFrames;
912 if ( _numFrames > 0 ) {
913 _skeletonFrames =
new MD5Joint*[_numFrames];
914 for (GLint i = 0; i < _numFrames; ++i) {
915 _skeletonFrames[i] =
nullptr;
935 if(_skeletonFrames !=
nullptr) {
936 for (GLint i = 0; i < _numFrames; ++i) {
937 delete _skeletonFrames[i];
938 _skeletonFrames[i] =
nullptr;
942 _numJoints = numJoints;
943 if (_numJoints > 0) {
944 if(_skeletonFrames !=
nullptr) {
945 for(GLint i = 0; i < _numFrames; ++i) {
947 _skeletonFrames[i] =
new MD5Joint[_numJoints];
961 if ( frameIndex < 0 || frameIndex >= _numFrames ) {
962 throw std::out_of_range(
"frameIndex out of range");
964 if (_skeletonFrames ==
nullptr) {
965 throw std::out_of_range(
"skeleton frames are null, setNumberOfFrames() may not have been called");
967 return _skeletonFrames[frameIndex];
979 if ( frameIndex < 0 || frameIndex >= _numFrames ) {
980 throw std::out_of_range(
"frameIndex out of range");
982 if ( jointIndex < 0 || jointIndex >= _numJoints ) {
983 throw std::out_of_range(
"jointIndex out of range");
985 if (_skeletonFrames ==
nullptr) {
986 throw std::out_of_range(
"skeleton frames are null, setNumberOfFrames() may not have been called");
988 if (_skeletonFrames[frameIndex] ==
nullptr) {
989 throw std::out_of_range(
"skeleton joints are null, setNumberOfJoints() may not have been called");
991 return _skeletonFrames[frameIndex][jointIndex];
1002 if(frameIndex < 0 || frameIndex >= _numFrames) {
1003 throw std::out_of_range(
"frameIndex out of range");
1005 if (_boundingBoxes ==
nullptr) {
1006 throw std::out_of_range(
"bounding boxes are null, setNumberOfFrames() may not have been called");
1008 return _boundingBoxes[frameIndex];
1019 if(_skeletonFrames !=
nullptr) {
1020 for (GLint i = 0; i < _numFrames; i++) {
1021 delete[] _skeletonFrames[i];
1022 _skeletonFrames[i] =
nullptr;
1025 delete[] _skeletonFrames;
1026 _skeletonFrames =
nullptr;
1028 delete[] _boundingBoxes;
1029 _boundingBoxes =
nullptr;
1066 GLint _numFrames = 0;
1071 GLint _numJoints = 0;
1076 MD5Joint** _skeletonFrames =
nullptr;
1088 this->_numFrames = src._numFrames;
1091 this->_numJoints = src._numJoints;
1097 this->_skeletonFrames = src._skeletonFrames;
1098 src._skeletonFrames =
nullptr;
1100 this->_boundingBoxes = src._boundingBoxes;
1101 src._boundingBoxes =
nullptr;
1112 GLint currFrame = 0;
1116 GLint nextFrame = 0;
1120 GLfloat lastTime = 0.0f;
1125 GLfloat maxTime = 0.0f;
1136 _copyFromSrc(OTHER);
1144 if (
this != &OTHER) {
1145 _copyFromSrc(OTHER);
1182 void _moveFromSrc(MD5AnimationState &src) {
1187 src.lastTime = 0.0f;
1242 [[maybe_unused]]
bool loadMD5Model(
const char* MD5_MESH_FILE,
const char* MD5_ANIM_FILE =
"");
1256 [[nodiscard]]
bool readMD5Model(
const char* FILENAME);
1265 [[maybe_unused]]
void allocVertexArrays(GLuint vPosAttribLoc, GLuint vColorAttribLoc, GLuint vTexCoordAttribLoc);
1274 [[maybe_unused]]
void setActiveTextures(GLint diffuseMapActiveTexture, GLint specularMapActiveTexture, GLint normalMapActiveTexture, GLint heightMapActiveTexture);
1279 [[maybe_unused]]
void draw()
const;
1283 [[maybe_unused]]
void drawSkeleton()
const;
1292 [[nodiscard]]
bool readMD5Anim(
const char* filename, GLushort targetAnimationIndex = 0);
1298 [[nodiscard]]
bool addMD5Anim(
const char* filename);
1307 if (!_isAnimated)
return 0;
1309 return _numAnimations;
1316 void useTargetAnimationIndex(GLushort targetAnimationIndex);
1321 void animate(GLfloat dt);
1328 MD5Joint* _baseSkeleton =
nullptr;
1333 MD5Mesh* _meshes =
nullptr;
1338 GLint _numJoints = 0;
1343 GLint _numMeshes = 0;
1350 GLint _maxVertices = 0;
1355 GLint _maxTriangles = 0;
1360 glm::vec3* _vertexArray =
nullptr;
1365 glm::vec2* _texelArray =
nullptr;
1370 GLuint* _vertexIndicesArray =
nullptr;
1380 GLuint _vbo[2] = {0, 0};
1386 GLuint _skeletonVAO = 0;
1390 GLuint _skeletonVBO = 0;
1394 MD5Joint* _skeleton =
nullptr;
1400 MD5Animation** _animations =
nullptr;
1404 GLushort _numAnimations = 0;
1408 GLushort _currentAnimationIndex = 0;
1412 bool _isAnimated =
false;
1416 MD5AnimationState* _animationInfos =
nullptr;
1421 GLint _diffuseActiveTexture = GL_TEXTURE0;
1425 GLint _specularActiveTexture = GL_TEXTURE1;
1429 GLint _normalActiveTexture = GL_TEXTURE2;
1433 GLint _heightActiveTexture = GL_TEXTURE3;
1441 void _prepareMesh(
const MD5Mesh* pMESH)
const;
1446 void _drawMesh(
const MD5Mesh* pMESH)
const;
1453 [[nodiscard]]
bool _checkAnimValidity(GLushort targetAnimationIndex)
const;
1462 static void _buildFrameSkeleton(
const MD5JointInfo* pJOINT_INFOS,
1463 const MD5BaseFrameJoint* pBASE_FRAME,
1464 const GLfloat* pANIM_FRAME_DATA,
1465 const MD5Joint* pSkeletonFrame,
1471 void _interpolateSkeletons(GLfloat interp);
1479 void _freeVertexArrays();
1489 void _moveFromSrc(MD5Model &src);
1499 _freeVertexArrays();
1507 const char* MD5_MESH_FILE,
1508 const char* MD5_ANIM_FILE
1511 if( readMD5Model(MD5_MESH_FILE) ) {
1513 if(strcmp(MD5_ANIM_FILE,
"") != 0 ) {
1515 if( !readMD5Anim(MD5_ANIM_FILE) ) {
1519 if( !isAnimated() ) {
1520 printf (
"[.MD5_ANIM_FILE]: no animation loaded.\n");
1531 const char* FILENAME
1535 GLint currentMesh = 0;
1537 GLint totalVertices = 0;
1538 GLint totalWeights = 0;
1539 GLint totalTriangles = 0;
1541 GLfloat minX = 999999, minY = 999999, minZ = 999999;
1542 GLfloat maxX = -999999, maxY = -999999, maxZ = -999999;
1544 printf(
"[.md5mesh]: about to read %s\n", FILENAME );
1546 FILE *fp = fopen(FILENAME,
"rb" );
1548 fprintf (stderr,
"[.md5mesh]: Error: couldn't open \"%s\"!\n", FILENAME);
1552 while( !feof(fp) ) {
1554 fgets( buff,
sizeof(buff), fp );
1556 if( sscanf(buff,
" MD5Version %d", &version) == 1 ) {
1557 if( version != 10 ) {
1559 fprintf (stderr,
"[.md5mesh]: Error: bad model version\n");
1563 }
else if( sscanf(buff,
" numJoints %d", &_numJoints) == 1 ) {
1564 if( _numJoints > 0 ) {
1566 _baseSkeleton =
new MD5Joint[_numJoints];
1568 }
else if( sscanf(buff,
" numMeshes %d", &_numMeshes) == 1 ) {
1569 if( _numMeshes > 0 ) {
1571 _meshes =
new MD5Mesh[_numMeshes];
1573 }
else if( strncmp(buff,
"joints {", 8) == 0 ) {
1575 for(GLint i = 0; i < _numJoints; ++i) {
1576 MD5Joint *joint = &_baseSkeleton[i];
1579 fgets( buff,
sizeof(buff), fp );
1581 if( sscanf(buff,
"%s %d ( %f %f %f ) ( %f %f %f )",
1590 }
else if( strncmp(buff,
"mesh {", 6) == 0 ) {
1591 MD5Mesh *mesh = &_meshes[currentMesh];
1592 GLint vert_index = 0;
1593 GLint tri_index = 0;
1594 GLint weight_index = 0;
1595 GLfloat floatData[4];
1598 while( buff[0] !=
'}' && !feof(fp) ) {
1600 fgets( buff,
sizeof(buff), fp );
1602 if( strstr( buff,
"shader ") ) {
1603 GLint quote = 0, j = 0;
1606 for(
unsigned long uli = 0; uli <
sizeof(buff) && (quote < 2); ++uli) {
1607 if( buff[uli] ==
'\"' )
1610 if( (quote == 1) && (buff[uli] !=
'\"') ) {
1611 mesh->
shader[j] = buff[uli];
1620 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);
1624 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 );
1628 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 );
1630 fprintf(stderr,
"[.md5mesh | ERROR]: Could not load diffuse map for shader %s\n", mesh->
shader);
1638 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 );
1642 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 );
1644 fprintf(stderr,
"[.md5mesh | ERROR]: Could not load specular map for shader %s\n", mesh->
shader);
1650 strcat(mesh->
textures[MD5Mesh::TextureMap::NORMAL].
filename,
"_local.tga");
1651 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 );
1654 strcat(mesh->
textures[MD5Mesh::TextureMap::NORMAL].
filename,
"_local.png");
1655 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 );
1657 fprintf(stderr,
"[.md5mesh | ERROR]: Could not load normal map for shader %s\n", mesh->
shader);
1664 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 );
1668 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 );
1670 fprintf(stderr,
"[.md5mesh | ERROR]: Could not load height map for shader %s\n", mesh->
shader);
1674 }
else if( sscanf(buff,
" numverts %d", &mesh->
numVertices) == 1 ) {
1684 }
else if( sscanf(buff,
" numtris %d", &mesh->
numTriangles) == 1 ) {
1694 }
else if( sscanf(buff,
" numweights %d", &mesh->
numWeights) == 1 ) {
1701 }
else if( sscanf(buff,
" vert %d ( %f %f ) %d %d",
1703 &floatData[0], &floatData[1],
1704 &intData[0], &intData[1]) == 5
1711 }
else if( sscanf(buff,
" tri %d %d %d %d",
1713 &intData[0], &intData[1], &intData[2]) == 4
1719 }
else if( sscanf(buff,
" weight %d %d %f ( %f %f %f )",
1720 &weight_index, &intData[0], &floatData[3],
1721 &floatData[0], &floatData[1], &floatData[2]) == 6
1730 if( floatData[0] < minX ) { minX = floatData[0]; }
1731 if( floatData[0] > maxX ) { maxX = floatData[0]; }
1732 if( floatData[1] < minY ) { minY = floatData[1]; }
1733 if( floatData[1] > maxY ) { maxY = floatData[1]; }
1734 if( floatData[2] < minZ ) { minZ = floatData[2]; }
1735 if( floatData[2] > maxZ ) { maxZ = floatData[2]; }
1745 _skeleton = _baseSkeleton;
1747 printf(
"[.md5mesh]: finished reading %s\n", FILENAME );
1748 printf(
"[.md5mesh]: read in %d meshes, %d joints, %d vertices, %d weights, and %d triangles\n", _numMeshes, _numJoints, totalVertices, totalWeights, totalTriangles );
1749 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) );
1756CSCI441::MD5Model::_freeModel()
1758 delete[] _baseSkeleton;
1759 if (_baseSkeleton == _skeleton) _skeleton =
nullptr;
1760 _baseSkeleton =
nullptr;
1771 for(GLint i = 0; i < _numMeshes; ++i) {
1773 _prepareMesh(&mesh);
1779CSCI441::MD5Model::_prepareMesh(
1780 const MD5Mesh *pMESH
1785 for(k = 0, i = 0; i < pMESH->numTriangles; ++i) {
1786 for(j = 0; j < 3; ++j, ++k)
1787 _vertexIndicesArray[k] = pMESH->triangles[i].index[j];
1791 for(i = 0; i < pMESH->numVertices; ++i) {
1792 glm::vec3 finalVertex = {0.0f, 0.0f, 0.0f };
1795 for(j = 0; j < pMESH->vertices[i].count; ++j) {
1796 const MD5Weight *weight = &pMESH->weights[pMESH->vertices[i].start + j];
1797 const MD5Joint *joint = &_skeleton[weight->joint];
1800 const glm::vec3 weightedVertex = glm::rotate(joint->orientation, glm::vec4(weight->position, 0.0f));
1803 finalVertex.x += (joint->position.x + weightedVertex.x) * weight->bias;
1804 finalVertex.y += (joint->position.y + weightedVertex.y) * weight->bias;
1805 finalVertex.z += (joint->position.z + weightedVertex.z) * weight->bias;
1808 _vertexArray[i].x = finalVertex.x;
1809 _vertexArray[i].y = finalVertex.y;
1810 _vertexArray[i].z = finalVertex.z;
1812 _texelArray[i].s = pMESH->vertices[i].texCoord.s;
1813 _texelArray[i].t = pMESH->vertices[i].texCoord.t;
1816 glBindVertexArray(_vao );
1818 glBindBuffer(GL_ARRAY_BUFFER, _vbo[0] );
1819 glBufferSubData(GL_ARRAY_BUFFER, 0,
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * pMESH->numVertices, &_vertexArray[0] );
1820 glBufferSubData(GL_ARRAY_BUFFER,
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * _maxVertices,
static_cast<GLsizeiptr
>(
sizeof(glm::vec2)) * pMESH->numVertices, &_texelArray[0] );
1822 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vbo[1] );
1823 glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0,
static_cast<GLsizeiptr
>(
sizeof(GLuint)) * pMESH->numTriangles * 3, _vertexIndicesArray );
1827CSCI441::MD5Model::_drawMesh(
1828 const MD5Mesh *pMESH
1830 if (pMESH->textures[MD5Mesh::TextureMap::SPECULAR].texHandle != 0) {
1832 glActiveTexture(_specularActiveTexture);
1833 glBindTexture(GL_TEXTURE_2D, pMESH->textures[MD5Mesh::TextureMap::SPECULAR].texHandle );
1835 if (pMESH->textures[MD5Mesh::TextureMap::NORMAL].texHandle != 0) {
1837 glActiveTexture(_normalActiveTexture);
1838 glBindTexture(GL_TEXTURE_2D, pMESH->textures[MD5Mesh::TextureMap::NORMAL].texHandle );
1840 if (pMESH->textures[MD5Mesh::TextureMap::HEIGHT].texHandle != 0) {
1842 glActiveTexture(_heightActiveTexture);
1843 glBindTexture(GL_TEXTURE_2D, pMESH->textures[MD5Mesh::TextureMap::HEIGHT].texHandle );
1846 if (pMESH->textures[MD5Mesh::TextureMap::DIFFUSE].texHandle != 0) {
1848 glActiveTexture(_diffuseActiveTexture);
1849 glBindTexture(GL_TEXTURE_2D, pMESH->textures[MD5Mesh::TextureMap::DIFFUSE].texHandle );
1851 if (_diffuseActiveTexture != GL_TEXTURE0) {
1853 glActiveTexture(GL_TEXTURE0);
1856 glBindVertexArray(_vao );
1857 glDrawElements(GL_TRIANGLES, pMESH->numTriangles * 3, GL_UNSIGNED_INT, (
void*)
nullptr );
1863 const GLuint vPosAttribLoc,
1864 const GLuint vColorAttribLoc,
1865 const GLuint vTexCoordAttribLoc
1867 _vertexArray =
new glm::vec3[_maxVertices];
1868 _texelArray =
new glm::vec2[_maxVertices];
1869 _vertexIndicesArray =
new GLuint[_maxTriangles * 3];
1871 glGenVertexArrays( 1, &_vao );
1872 glBindVertexArray(_vao );
1874 glGenBuffers(2, _vbo );
1875 glBindBuffer(GL_ARRAY_BUFFER, _vbo[0] );
1876 glBufferData(GL_ARRAY_BUFFER,
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * _maxVertices +
static_cast<GLsizeiptr
>(
sizeof(glm::vec2)) * _maxVertices,
nullptr, GL_DYNAMIC_DRAW );
1878 glEnableVertexAttribArray( vPosAttribLoc );
1879 glVertexAttribPointer( vPosAttribLoc, 3, GL_FLOAT, GL_FALSE, 0,
static_cast<void *
>(
nullptr) );
1881 glEnableVertexAttribArray( vTexCoordAttribLoc );
1882 glVertexAttribPointer( vTexCoordAttribLoc, 2, GL_FLOAT, GL_FALSE, 0,
reinterpret_cast<void *
>(
sizeof(glm::vec3) * _maxVertices) );
1884 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vbo[1] );
1885 glBufferData(GL_ELEMENT_ARRAY_BUFFER,
static_cast<GLsizeiptr
>(
sizeof(GLuint)) * _maxTriangles * 3,
nullptr, GL_DYNAMIC_DRAW );
1887 printf(
"[.md5mesh]: Model VAO/VBO/IBO registered at %u/%u/%u\n", _vao, _vbo[0], _vbo[1] );
1889 glGenVertexArrays( 1, &_skeletonVAO );
1890 glBindVertexArray(_skeletonVAO );
1892 glGenBuffers( 1, &_skeletonVBO );
1893 glBindBuffer(GL_ARRAY_BUFFER, _skeletonVBO );
1894 glBufferData(GL_ARRAY_BUFFER,
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * _numJoints * 3 * 2,
nullptr, GL_DYNAMIC_DRAW );
1896 glEnableVertexAttribArray( vPosAttribLoc );
1897 glVertexAttribPointer( vPosAttribLoc, 3, GL_FLOAT, GL_FALSE, 0,
static_cast<void *
>(
nullptr) );
1899 glEnableVertexAttribArray( vColorAttribLoc );
1900 glVertexAttribPointer( vColorAttribLoc, 3, GL_FLOAT, GL_FALSE, 0,
reinterpret_cast<void *
>(
sizeof(glm::vec3) * _numJoints * 3) );
1902 printf(
"[.md5mesh]: Skeleton VAO/VBO registered at %u/%u\n", _skeletonVAO, _skeletonVBO );
1907 const GLint diffuseMapActiveTexture = GL_TEXTURE0,
1908 const GLint specularMapActiveTexture = GL_TEXTURE1,
1909 const GLint normalMapActiveTexture = GL_TEXTURE2,
1910 const GLint heightMapActiveTexture = GL_TEXTURE3
1912 _diffuseActiveTexture = diffuseMapActiveTexture;
1913 _specularActiveTexture = specularMapActiveTexture;
1914 _normalActiveTexture = normalMapActiveTexture;
1915 _heightActiveTexture = heightMapActiveTexture;
1919CSCI441::MD5Model::_freeVertexArrays()
1921 delete[] _vertexArray;
1922 _vertexArray =
nullptr;
1924 delete[] _vertexIndicesArray;
1925 _vertexIndicesArray =
nullptr;
1927 delete[] _texelArray;
1928 _texelArray =
nullptr;
1930 glDeleteVertexArrays( 1, &_vao );
1933 glDeleteBuffers(2, _vbo );
1937 glDeleteVertexArrays( 1, &_skeletonVAO );
1940 glDeleteBuffers( 1, &_skeletonVBO );
1948 glBindVertexArray(_skeletonVAO );
1949 glBindBuffer(GL_ARRAY_BUFFER, _skeletonVBO );
1951 constexpr glm::vec3 jointColor = {1.0f, 1.0f, 0.0f };
1952 constexpr glm::vec3 boneColor = {1.0f, 0.0f, 1.0f };
1955 for(GLint i = 0; i < _numJoints; ++i ) {
1956 glBufferSubData(GL_ARRAY_BUFFER, i *
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)),
sizeof(glm::vec3), &(_skeleton[i].position) );
1957 glBufferSubData(GL_ARRAY_BUFFER, i *
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) +
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * _numJoints * 3,
sizeof(glm::vec3), &jointColor[0]);
1962 for(GLint i = 0; i < _numJoints; ++i ) {
1963 if( _skeleton[i].parent != MD5Joint::NULL_JOINT ) {
1966 static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * _numJoints + (i * 2) *
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)),
1967 static_cast<GLsizeiptr
>(
sizeof(glm::vec3)),
1968 &(_skeleton[_skeleton[i].parent].position)
1972 static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * _numJoints + (i * 2) *
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) +
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * _numJoints * 3,
1979 static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) * _numJoints + (i * 2) *
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)) +
static_cast<GLsizeiptr
>(
sizeof(glm::vec3)),
1980 static_cast<GLsizeiptr
>(
sizeof(glm::vec3)),
1981 &(_skeleton[i].position)
1985 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,
1994 glDrawArrays(GL_POINTS, 0, _numJoints );
1997 glLineWidth( 3.0f );
1998 glDrawArrays(GL_LINES, _numJoints, numBones * 2 );
2003CSCI441::MD5Model::_checkAnimValidity(
const GLushort targetAnimationIndex)
const
2006 if( _numJoints != _animations[targetAnimationIndex]->getNumberOfJoints() ) {
2007 fprintf(stdout,
"\n[.md5anim]: skeleton and animation do not have same number of joints. cannot apply animation %u to skeleton\n\n", targetAnimationIndex);
2010 if (_animations[targetAnimationIndex]->getNumberOfJoints() == 0 ) {
2011 fprintf(stdout,
"\n[.md5anim]: animation has zero joints. cannot apply animation %u to skeleton\n\n", targetAnimationIndex);
2016 for(GLint i = 0; i < _numJoints; ++i) {
2018 if (_baseSkeleton[i].parent != _animations[targetAnimationIndex]->getSkeletonFrameJoint(0, i).parent) {
2019 fprintf(stdout,
"\n[.md5anim]: skeleton and animation joints do not have same parent index. cannot apply animation %u to skeleton\n\n", targetAnimationIndex);
2024 if (strcmp (_baseSkeleton[i].name, _animations[targetAnimationIndex]->getSkeletonFrameJoint(0, i).name) != 0) {
2025 fprintf(stdout,
"\n[.md5anim]: skeleton and animation joints do not have same name. cannot apply animation %u to skeleton\n\n", targetAnimationIndex);
2030 fprintf(stdout,
"\n[.md5anim]: skeleton and animation match. animation %u can be applied to skeleton\n\n", targetAnimationIndex);
2035CSCI441::MD5Model::_buildFrameSkeleton(
2036 const MD5JointInfo* pJOINT_INFOS,
2037 const MD5BaseFrameJoint* pBASE_FRAME,
2038 const GLfloat* pANIM_FRAME_DATA,
2039 const MD5Joint* pSkeletonFrame,
2040 const GLint NUM_JOINTS
2042 if(pJOINT_INFOS ==
nullptr
2043 || pBASE_FRAME ==
nullptr
2044 || pANIM_FRAME_DATA ==
nullptr
2045 || pSkeletonFrame ==
nullptr)
return;
2047 for(GLint i = 0; i < NUM_JOINTS; ++i) {
2048 const MD5BaseFrameJoint *baseJoint = &pBASE_FRAME[i];
2049 glm::vec3 animatedPosition = baseJoint->position;
2050 glm::quat animatedOrientation = baseJoint->orientation;
2054 if(pJOINT_INFOS[i].flags & 1 ) {
2055 animatedPosition.x = pANIM_FRAME_DATA[pJOINT_INFOS[i].startIndex + j];
2060 if(pJOINT_INFOS[i].flags & 2 ) {
2061 animatedPosition.y = pANIM_FRAME_DATA[pJOINT_INFOS[i].startIndex + j];
2066 if(pJOINT_INFOS[i].flags & 4 ) {
2067 animatedPosition.z = pANIM_FRAME_DATA[pJOINT_INFOS[i].startIndex + j];
2072 if(pJOINT_INFOS[i].flags & 8 ) {
2073 animatedOrientation.x = pANIM_FRAME_DATA[pJOINT_INFOS[i].startIndex + j];
2078 if(pJOINT_INFOS[i].flags & 16 ) {
2079 animatedOrientation.y = pANIM_FRAME_DATA[pJOINT_INFOS[i].startIndex + j];
2084 if(pJOINT_INFOS[i].flags & 32 ) {
2085 animatedOrientation.z = pANIM_FRAME_DATA[pJOINT_INFOS[i].startIndex + j];
2089 animatedOrientation.w = glm::extractRealComponent(animatedOrientation);
2094 const auto thisJoint =
const_cast<MD5Joint *
>(&pSkeletonFrame[i]);
2096 const GLint parent = pJOINT_INFOS[i].parent;
2097 thisJoint->parent = parent;
2098 strcpy (thisJoint->name, pJOINT_INFOS[i].name);
2101 if( thisJoint->parent == MD5Joint::NULL_JOINT ) {
2102 thisJoint->position = animatedPosition;
2103 thisJoint->orientation = animatedOrientation;
2105 const MD5Joint *parentJoint = &pSkeletonFrame[parent];
2106 glm::vec3 rotatedPosition = glm::rotate(parentJoint->orientation, glm::vec4(animatedPosition, 0.0f));
2109 thisJoint->position = parentJoint->position + rotatedPosition;
2112 thisJoint->orientation = glm::normalize( glm::cross(parentJoint->orientation, animatedOrientation) );
2119 const char *filename,
2120 const GLushort targetAnimationIndex
2122 if (targetAnimationIndex >= _numAnimations) {
2123 fprintf (stderr,
"[.md5anim]: Error: target animation index %u is out of range for currently allocated animations (which is %u)\n", targetAnimationIndex, _numAnimations);
2124 fprintf (stderr,
"[.md5anim]: Hey Developer, if you wish to add an animation to the sequence, use CSCI441::MD5Model::addMD5Anim(const char*)\n");
2131 GLfloat *animFrameData =
nullptr;
2133 GLint numAnimatedComponents;
2134 GLint frameIndex, numFrames, numJoints;
2137 printf(
"[.md5anim]: about to read %s into animation %u\n", filename, targetAnimationIndex );
2139 FILE *fp = fopen( filename,
"rb" );
2141 fprintf (stderr,
"[.md5anim]: Error: couldn't open \"%s\"!\n", filename);
2145 while( !feof(fp) ) {
2147 fgets( buff,
sizeof(buff), fp );
2149 if( sscanf(buff,
" MD5Version %d", &version) == 1 ) {
2150 if( version != 10 ) {
2152 fprintf (stderr,
"[.md5anim]: Error: bad animation version\n");
2156 }
else if( sscanf(buff,
" numFrames %d", &numFrames) == 1 ) {
2158 _animations[targetAnimationIndex]->setNumberOfFrames(numFrames);
2159 }
else if( sscanf(buff,
" numJoints %d", &numJoints) == 1 ) {
2160 if (jointInfos !=
nullptr) {
2161 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. numJoints already specified\n" );
2163 if( numJoints > 0 ) {
2164 _animations[targetAnimationIndex]->setNumberOfJoints(numJoints);
2170 }
else if( sscanf(buff,
" frameRate %d", &_animations[targetAnimationIndex]->frameRate) == 1 ) {
2172 }
else if( sscanf(buff,
" numAnimatedComponents %d", &numAnimatedComponents) == 1 ) {
2173 if (animFrameData !=
nullptr) {
2174 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. numAnimatedComponents already specified\n" );
2176 if( numAnimatedComponents > 0 ) {
2178 animFrameData =
new GLfloat[numAnimatedComponents];
2180 }
else if( strncmp(buff,
"hierarchy {", 11) == 0 ) {
2181 if (jointInfos ==
nullptr) {
2182 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. numJoints not specified prior to hierarchy\n" );
2184 for(i = 0; i < numJoints; ++i) {
2186 fgets( buff,
sizeof(buff), fp );
2189 sscanf(buff,
" %s %d %d %d",
2190 jointInfos[i].name, &jointInfos[i].parent,
2191 &jointInfos[i].flags, &jointInfos[i].startIndex);
2194 }
else if( strncmp(buff,
"bounds {", 8) == 0 ) {
2195 if (_animations[targetAnimationIndex]->getNumberOfFrames() == 0) {
2196 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. numFrames not specified prior to bounds\n" );
2198 for(i = 0; i < _animations[targetAnimationIndex]->getNumberOfFrames(); ++i) {
2200 fgets( buff,
sizeof(buff), fp );
2203 sscanf(buff,
" ( %f %f %f ) ( %f %f %f )",
2204 &_animations[targetAnimationIndex]->getBoundingBox(i).min[0], &_animations[targetAnimationIndex]->getBoundingBox(i).min[1], &_animations[targetAnimationIndex]->getBoundingBox(i).min[2],
2205 &_animations[targetAnimationIndex]->getBoundingBox(i).max[0], &_animations[targetAnimationIndex]->getBoundingBox(i).max[1], &_animations[targetAnimationIndex]->getBoundingBox(i).max[2]);
2208 }
else if( strncmp(buff,
"baseframe {", 10) == 0 ) {
2209 if (baseFrame ==
nullptr) {
2210 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. numJoints not specified prior to baseframe\n" );
2212 for(i = 0; i < numJoints; ++i) {
2214 fgets( buff,
sizeof(buff), fp );
2217 if( sscanf(buff,
" ( %f %f %f ) ( %f %f %f )",
2218 &baseFrame[i].position[0], &baseFrame[i].position[1], &baseFrame[i].position[2],
2219 &baseFrame[i].orientation[0], &baseFrame[i].orientation[1], &baseFrame[i].orientation[2]) == 6 ) {
2221 baseFrame[i].
orientation.w = glm::extractRealComponent(baseFrame[i].orientation);
2225 }
else if(sscanf(buff,
" frame %d", &frameIndex) == 1 ) {
2226 if (animFrameData ==
nullptr) {
2227 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. numAnimatedComponents not specified prior to frame\n" );
2228 }
else if (_animations[targetAnimationIndex]->getNumberOfFrames() == 0) {
2229 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. numFrames not specified prior to frame\n" );
2230 }
else if (baseFrame ==
nullptr) {
2231 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. baseframe not specified prior to frame\n" );
2232 }
else if (jointInfos ==
nullptr) {
2233 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. numJoints not specified prior to frame\n" );
2236 for(i = 0; i < numAnimatedComponents; ++i)
2237 fscanf( fp,
"%f", &animFrameData[i] );
2240 _buildFrameSkeleton(jointInfos, baseFrame, animFrameData,
2241 _animations[targetAnimationIndex]->getSkeletonFrame(frameIndex),
2249 printf(
"[.md5anim]: finished reading %s into animation %u\n", filename, targetAnimationIndex );
2250 printf(
"[.md5anim]: read in %d frames of %d joints with %d animated components\n", _animations[targetAnimationIndex]->getNumberOfFrames(), _animations[targetAnimationIndex]->getNumberOfJoints(), numAnimatedComponents );
2251 printf(
"[.md5anim]: animation's frame rate is %d\n", _animations[targetAnimationIndex]->frameRate );
2254 delete[] animFrameData;
2256 delete[] jointInfos;
2259 _animationInfos[targetAnimationIndex].currFrame = 0;
2260 _animationInfos[targetAnimationIndex].nextFrame = 1;
2262 _animationInfos[targetAnimationIndex].lastTime = 0.0f;
2263 _animationInfos[targetAnimationIndex].maxTime = 1.0f /
static_cast<GLfloat
>(_animations[targetAnimationIndex]->frameRate);
2266 if (_animations[targetAnimationIndex]->getNumberOfJoints() == 0) {
2267 fprintf( stderr,
"[.md5anim]: Error: md5anim file malformed. numJoints never specified\n" );
2269 _skeleton =
new MD5Joint[_animations[targetAnimationIndex]->getNumberOfJoints()];
2272 if( _checkAnimValidity(targetAnimationIndex) ) {
2283 const char* filename
2286 auto newAnimations =
new MD5Animation*[_numAnimations + 1];
2289 for(
int i = 0; i < _numAnimations; ++i ) {
2290 newAnimations[i] = _animations[i];
2291 newAnimationInfos[i] = _animationInfos[i];
2295 delete[] _animations;
2296 delete[] _animationInfos;
2298 _animations = newAnimations;
2299 _animationInfos = newAnimationInfos;
2304 fprintf( stdout,
"[.md5anim]: preparing to read %s into new animation %u\n", filename, (_numAnimations-1) );
2305 const bool readSuccess = readMD5Anim(filename, _numAnimations - 1);
2308 fprintf( stdout,
"[.md5anim]: successfully read %s into new animation %u\n", filename, (_numAnimations-1) );
2310 fprintf( stderr,
"[.md5anim]: Error: could not read %s into new animation %u\n", filename, (_numAnimations-1) );
2316 for (
int i = 0; i < _numAnimations - 1; ++i) {
2317 newAnimations[i] = _animations[i];
2318 newAnimationInfos[i] = _animationInfos[i];
2320 delete _animations[_numAnimations-1];
2322 delete[] _animations;
2323 delete[] _animationInfos;
2325 _animations = newAnimations;
2326 _animationInfos = newAnimationInfos;
2336 const GLushort targetAnimationIndex
2339 if (targetAnimationIndex < _numAnimations) {
2341 _currentAnimationIndex = targetAnimationIndex;
2344 _animationInfos[targetAnimationIndex].currFrame = 0;
2345 _animationInfos[targetAnimationIndex].nextFrame = 1;
2347 _animationInfos[targetAnimationIndex].lastTime = 0.0f;
2348 _animationInfos[targetAnimationIndex].maxTime = 1.0f /
static_cast<GLfloat
>(_animations[targetAnimationIndex]->frameRate);
2355CSCI441::MD5Model::_freeAnim()
2358 _skeleton =
nullptr;
2360 for (
int i = 0; i < _numAnimations; i++) {
2361 delete _animations[i];
2363 delete[] _animations;
2364 _animations =
nullptr;
2366 delete[] _animationInfos;
2367 _animationInfos =
nullptr;
2370inline void CSCI441::MD5Model::_moveFromSrc(MD5Model &src) {
2371 this->_baseSkeleton = src._baseSkeleton;
2372 src._baseSkeleton =
nullptr;
2374 this->_meshes = src._meshes;
2375 src._meshes =
nullptr;
2377 this->_maxVertices = src._maxVertices;
2378 src._maxVertices = 0;
2380 this->_maxTriangles = src._maxTriangles;
2381 src._maxTriangles = 0;
2383 this->_vertexArray = src._vertexArray;
2384 src._vertexArray =
nullptr;
2386 this->_texelArray = src._texelArray;
2387 src._texelArray =
nullptr;
2389 this->_vertexIndicesArray = src._vertexIndicesArray;
2390 src._vertexIndicesArray =
nullptr;
2392 this->_vao = src._vao;
2395 this->_vbo[0] = src._vbo[0];
2396 this->_vbo[1] = src._vbo[1];
2400 this->_skeletonVAO = src._skeletonVAO;
2401 src._skeletonVAO = 0;
2403 this->_skeletonVBO = src._skeletonVBO;
2404 src._skeletonVBO = 0;
2406 this->_skeleton = src._skeleton;
2407 src._skeleton =
nullptr;
2409 this->_animations = src._animations;
2410 src._animations =
nullptr;
2412 this->_numAnimations = src._numAnimations;
2413 src._numAnimations = 0;
2415 this->_currentAnimationIndex = src._currentAnimationIndex;
2416 src._currentAnimationIndex = 0;
2418 this->_isAnimated = src._isAnimated;
2419 src._isAnimated =
false;
2421 this->_animationInfos = src._animationInfos;
2422 src._animationInfos =
nullptr;
2426CSCI441::MD5Model::_interpolateSkeletons(
const GLfloat interp)
2428 const MD5Joint *skeletonA = _animations[_currentAnimationIndex]->getSkeletonFrame(_animationInfos[_currentAnimationIndex].currFrame);
2429 const MD5Joint *skeletonB = _animations[_currentAnimationIndex]->getSkeletonFrame(_animationInfos[_currentAnimationIndex].nextFrame);
2431 for(GLint i = 0; i < _animations[_currentAnimationIndex]->getNumberOfJoints(); ++i) {
2433 _skeleton[i].parent = skeletonA[i].parent;
2436 _skeleton[i].position = glm::mix(skeletonA[i].position, skeletonB[i].position, interp);
2439 _skeleton[i].orientation = glm::slerp(skeletonA[i].orientation, skeletonB[i].orientation, interp);
2448 const GLint maxFrames = _animations[_currentAnimationIndex]->getNumberOfFrames() - 1;
2449 if (maxFrames <= 0)
return;
2451 _animationInfos[_currentAnimationIndex].lastTime += dt;
2454 if( _animationInfos[_currentAnimationIndex].lastTime >= _animationInfos[_currentAnimationIndex].maxTime ) {
2455 _animationInfos[_currentAnimationIndex].currFrame++;
2456 _animationInfos[_currentAnimationIndex].nextFrame++;
2457 _animationInfos[_currentAnimationIndex].lastTime = 0.0;
2459 if( _animationInfos[_currentAnimationIndex].currFrame > maxFrames )
2460 _animationInfos[_currentAnimationIndex].currFrame = 0;
2462 if( _animationInfos[_currentAnimationIndex].nextFrame > maxFrames )
2463 _animationInfos[_currentAnimationIndex].nextFrame = 0;
2467 _interpolateSkeletons( _animationInfos[_currentAnimationIndex].lastTime *
static_cast<GLfloat
>(_animations[_currentAnimationIndex]->frameRate) );
Helper functions to work with OpenGL Textures.
stores an entire animation sequence for a given MD5 Model
Definition: MD5Model.hpp:880
MD5Animation & operator=(MD5Animation &&src) noexcept
reassign object by moving an existing object
Definition: MD5Model.hpp:1055
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:1047
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:892
void setNumberOfFrames(const GLint numFrames)
sets the number of frames and allocates skeletonFrames and boundingBoxes to the associated size
Definition: MD5Model.hpp:899
const MD5Joint * getSkeletonFrame(const GLint frameIndex) const
get the skeleton for a specific animation frame
Definition: MD5Model.hpp:960
GLint frameRate
number of frames per second to draw for the animation
Definition: MD5Model.hpp:886
~MD5Animation()
deallocate animation arrays
Definition: MD5Model.hpp:1018
MD5Joint & getSkeletonFrameJoint(const GLint frameIndex, const GLint jointIndex) const
get the specific joint from a skeleton for a specific animation frame
Definition: MD5Model.hpp:978
MD5BoundingBox & getBoundingBox(const GLint frameIndex) const
get the specific bounding box for a target frame
Definition: MD5Model.hpp:1001
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:933
GLint getNumberOfJoints() const
get the number of joints in each skeleton frame
Definition: MD5Model.hpp:925
stores a Doom3 MD5 Mesh + Animation
Definition: MD5Model.hpp:77
bool addMD5Anim(const char *filename)
adds another MD5 Animation sequence to the model's set of animation
Definition: MD5Model.hpp:2282
void draw() const
draws all the meshes that make up the model
Definition: MD5Model.hpp:1768
GLushort getNumberOfAnimations() const
returns the number of animations that were successfully loaded against the model
Definition: MD5Model.hpp:1305
bool readMD5Model(const char *FILENAME)
parses md5mesh file and allocates corresponding mesh data
Definition: MD5Model.hpp:1530
bool readMD5Anim(const char *filename, GLushort targetAnimationIndex=0)
reads in an animation sequence from an external file
Definition: MD5Model.hpp:2118
bool isAnimated() const
returns if the MD5 Model has an accompanying animation
Definition: MD5Model.hpp:1248
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:1506
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:1906
MD5Model()
initializes an empty MD5 Model
Definition: MD5Model.hpp:1197
MD5Model & operator=(const MD5Model &)=delete
do not allow MD5 models to be copied
void allocVertexArrays(GLuint vPosAttribLoc, GLuint vColorAttribLoc, GLuint vTexCoordAttribLoc)
binds model VBOs to attribute pointer locations
Definition: MD5Model.hpp:1862
void animate(GLfloat dt)
advances the model forward in its animation sequence the corresponding amount of time based on frame ...
Definition: MD5Model.hpp:2446
MD5Model & operator=(MD5Model &&src) noexcept
do not allow MD5 models to be moved
Definition: MD5Model.hpp:1229
void useTargetAnimationIndex(GLushort targetAnimationIndex)
update current animation to be running through
Definition: MD5Model.hpp:2335
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:1223
~MD5Model()
deallocates any used memory on the CPU and GPU
Definition: MD5Model.hpp:1496
void drawSkeleton() const
draws the skeleton joints (as points) and bones (as lines)
Definition: MD5Model.hpp:1946
CSCI441 Helper Functions for OpenGL.
Definition: ArcballCam.hpp:17
stores state of current animation frame
Definition: MD5Model.hpp:1108
GLint currFrame
index of current frame model is in
Definition: MD5Model.hpp:1112
MD5AnimationState(MD5AnimationState &&src) noexcept
construct an object by moving an existing object
Definition: MD5Model.hpp:1153
MD5AnimationState(const MD5AnimationState &OTHER)
construct an object by copying an existing object
Definition: MD5Model.hpp:1135
MD5AnimationState()=default
construct a default object
GLint nextFrame
index of next frame model will move to
Definition: MD5Model.hpp:1116
MD5AnimationState & operator=(MD5AnimationState &&src) noexcept
reassign object by moving an existing object
Definition: MD5Model.hpp:1161
MD5AnimationState & operator=(const MD5AnimationState &OTHER)
reassign object by copying an existing object
Definition: MD5Model.hpp:1143
GLfloat lastTime
time of last frame interpolation
Definition: MD5Model.hpp:1120
GLfloat maxTime
duration of a single frame
Definition: MD5Model.hpp:1125
base frame joint
Definition: MD5Model.hpp:731
glm::quat orientation
joint orientation expressed as a quaternion in object space
Definition: MD5Model.hpp:739
MD5BaseFrameJoint & operator=(const MD5BaseFrameJoint &OTHER)
reassign object by copying an existing object
Definition: MD5Model.hpp:757
MD5BaseFrameJoint()=default
construct a default object
MD5BaseFrameJoint(MD5BaseFrameJoint &&src) noexcept
construct object by moving an existing object
Definition: MD5Model.hpp:767
glm::vec3 position
position of the joint in object space
Definition: MD5Model.hpp:735
MD5BaseFrameJoint(const MD5BaseFrameJoint &OTHER)
construct an object by copying an existing object
Definition: MD5Model.hpp:749
MD5BaseFrameJoint & operator=(MD5BaseFrameJoint &&src) noexcept
reassign object by moving an existing object
Definition: MD5Model.hpp:775
bounding box containing the model during animation
Definition: MD5Model.hpp:806
MD5BoundingBox(const MD5BoundingBox &OTHER)
construct an object by copying an existing object
Definition: MD5Model.hpp:824
MD5BoundingBox & operator=(MD5BoundingBox &&src) noexcept
reassign object by moving an existing object
Definition: MD5Model.hpp:850
glm::vec3 min
minimum dimension bound
Definition: MD5Model.hpp:810
MD5BoundingBox(MD5BoundingBox &&src) noexcept
construct an object by moving an existing object
Definition: MD5Model.hpp:842
glm::vec3 max
maximum dimension bound
Definition: MD5Model.hpp:814
MD5BoundingBox & operator=(const MD5BoundingBox &OTHER)
reassign object by copying an existing object
Definition: MD5Model.hpp:832
MD5BoundingBox()=default
construct a default object
a joint of the MD5 Skeleton
Definition: MD5Model.hpp:83
MD5Joint(const MD5Joint &OTHER)
construct a joint object by copying an existing joint
Definition: MD5Model.hpp:117
char name[MAX_NAME_LENGTH]
joint identifier
Definition: MD5Model.hpp:95
MD5Joint(MD5Joint &&src) noexcept
construct a joint object by moving an existing object
Definition: MD5Model.hpp:135
glm::vec3 position
position of the joint in object space
Definition: MD5Model.hpp:103
MD5Joint & operator=(const MD5Joint &OTHER)
reassign an existing joint object by copying another joint object
Definition: MD5Model.hpp:125
glm::quat orientation
joint orientation expressed as a quaternion in object space
Definition: MD5Model.hpp:107
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:143
GLint parent
index of the parent joint on skeletal tree
Definition: MD5Model.hpp:99
information pertaining to each animation joint
Definition: MD5Model.hpp:641
MD5JointInfo & operator=(MD5JointInfo &&src) noexcept
reassign object by moving an existing object
Definition: MD5Model.hpp:697
GLint startIndex
index of starting parameter
Definition: MD5Model.hpp:661
MD5JointInfo(const MD5JointInfo &OTHER)
construct a joint info object by copying an existing object
Definition: MD5Model.hpp:671
MD5JointInfo(MD5JointInfo &&src) noexcept
construct joint info object by moving an existing object
Definition: MD5Model.hpp:689
GLint parent
index of parent joint on skeletal tree
Definition: MD5Model.hpp:653
char name[MAX_NAME_LENGTH]
joint identifier
Definition: MD5Model.hpp:649
MD5JointInfo & operator=(const MD5JointInfo &OTHER)
reassign object by copying an existing object
Definition: MD5Model.hpp:679
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:657
mesh that comprises the model's skin
Definition: MD5Model.hpp:493
GLint numTriangles
number of triangles in the mesh triangle array
Definition: MD5Model.hpp:546
MD5Texture textures[NUM_TEXTURES]
texture map array
Definition: MD5Model.hpp:517
TextureMap
named entities for different texture maps applied to the model
Definition: MD5Model.hpp:521
@ DIFFUSE
diffuse map
Definition: MD5Model.hpp:525
@ SPECULAR
specular map
Definition: MD5Model.hpp:529
@ NORMAL
normal map
Definition: MD5Model.hpp:533
MD5Mesh(MD5Mesh &&src) noexcept
construct a new mesh by moving an existing object
Definition: MD5Model.hpp:590
MD5Mesh()=default
construct a default mesh object
GLint numVertices
number of vertices in the mesh vertex array
Definition: MD5Model.hpp:542
MD5Mesh & operator=(MD5Mesh &&src) noexcept
reassign mesh object by moving an existing object
Definition: MD5Model.hpp:598
MD5Triangle * triangles
array triangles comprising the mesh
Definition: MD5Model.hpp:509
char shader[MAX_NAME_LENGTH]
base filename for all textures applied to mesh
Definition: MD5Model.hpp:555
MD5Vertex * vertices
array of vertices comprising the mesh
Definition: MD5Model.hpp:505
GLint numWeights
number of weights in the mesh weight array
Definition: MD5Model.hpp:550
~MD5Mesh()
deallocate member arrays
Definition: MD5Model.hpp:564
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:513
MD5Mesh(const MD5Mesh &OTHER)=delete
do not allow meshes to be copied
texture handle for the model
Definition: MD5Model.hpp:415
char filename[MAX_NAME_LENGTH]
filename texture was loaded from
Definition: MD5Model.hpp:427
MD5Texture & operator=(const MD5Texture &OTHER)
reassign texture object by copying an existing object
Definition: MD5Model.hpp:445
MD5Texture & operator=(MD5Texture &&src) noexcept
reassign texture object by moving an existing object
Definition: MD5Model.hpp:463
MD5Texture(const MD5Texture &OTHER)
construct a texture object by copying an existing object
Definition: MD5Model.hpp:437
GLuint texHandle
handle of texture stored on the GPU
Definition: MD5Model.hpp:423
MD5Texture()=default
constructs a default texture object
MD5Texture(MD5Texture &&src) noexcept
construct a texture object by moving an existing object
Definition: MD5Model.hpp:455
a triangle on the mesh
Definition: MD5Model.hpp:259
MD5Triangle & operator=(const MD5Triangle &OTHER)
reassign triangle object by copying an existing triangle
Definition: MD5Model.hpp:285
MD5Triangle(MD5Triangle &&src) noexcept
construct a triangle object by moving an existing triangle
Definition: MD5Model.hpp:295
MD5Triangle & operator=(MD5Triangle &&src) noexcept
reassign triangle object by moving an existing triangle
Definition: MD5Model.hpp:303
MD5Triangle(const MD5Triangle &OTHER)
construct a triangle by copying an existing triangle
Definition: MD5Model.hpp:277
MD5Triangle()=default
construct a default triangle object
GLint index[NUM_VERTICES]
vertex indices that make up triangle
Definition: MD5Model.hpp:267
a vertex on the mesh
Definition: MD5Model.hpp:179
MD5Vertex & operator=(const MD5Vertex &OTHER)
reassign existing vertex object by copying an existing vertex object
Definition: MD5Model.hpp:209
MD5Vertex & operator=(MD5Vertex &&src) noexcept
reassign existing vertex object by moving an existing vertex object
Definition: MD5Model.hpp:227
MD5Vertex(MD5Vertex &&src) noexcept
construct a vertex object by moving an existing vertex
Definition: MD5Model.hpp:219
glm::vec2 texCoord
texture coordinate for vertex
Definition: MD5Model.hpp:183
MD5Vertex(const MD5Vertex &OTHER)
construct a vertex object by copying an existing vertex
Definition: MD5Model.hpp:201
GLint start
index of starting weight
Definition: MD5Model.hpp:187
GLint count
number of weights that determine vertex's position
Definition: MD5Model.hpp:191
MD5Vertex()=default
construct a default vertex object
the weight for a mesh vertex
Definition: MD5Model.hpp:335
MD5Weight(MD5Weight &&src) noexcept
construct a weight object by moving an existing object
Definition: MD5Model.hpp:375
MD5Weight & operator=(MD5Weight &&src) noexcept
reassign an existing weight object by moving another
Definition: MD5Model.hpp:383
MD5Weight & operator=(const MD5Weight &OTHER)
reassign an existing weight object by copying another
Definition: MD5Model.hpp:365
MD5Weight(const MD5Weight &OTHER)
construct a weight object by copying an existing weight
Definition: MD5Model.hpp:357
GLfloat bias
contribution of the weight
Definition: MD5Model.hpp:343
GLint joint
index of joint the weight depends on
Definition: MD5Model.hpp:339
MD5Weight()=default
construct a default weight object
glm::vec3 position
weight's position in object space
Definition: MD5Model.hpp:347