Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added skeletal animation system #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"C_Cpp.default.configurationProvider": "vector-of-bool.cmake-tools"
}
6 changes: 3 additions & 3 deletions dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ add_definitions(-DASSIMP_BUILD_NO_MD2_EXPORTER)
set( ASSIMP_BUILD_MD3_IMPORTER OFF CACHE BOOL "Build importer" )
add_definitions(-DASSIMP_BUILD_NO_MD3_EXPORTER)

set( ASSIMP_BUILD_MD5_IMPORTER OFF CACHE BOOL "Build importer" )
set( ASSIMP_BUILD_MD5_IMPORTER ON CACHE BOOL "Build importer" )
add_definitions(-DASSIMP_BUILD_NO_MD5_EXPORTER)

set( ASSIMP_BUILD_MDC_IMPORTER OFF CACHE BOOL "Build importer" )
Expand Down Expand Up @@ -155,7 +155,7 @@ add_definitions(-DASSIMP_BUILD_NO_TERRAGEN_EXPORTER)
set( ASSIMP_BUILD_3D_IMPORTER OFF CACHE BOOL "Build importer" )
add_definitions(-DASSIMP_BUILD_NO_3D_EXPORTER)

set( ASSIMP_BUILD_X_IMPORTER OFF CACHE BOOL "Build importer" )
set( ASSIMP_BUILD_X_IMPORTER ON CACHE BOOL "Build importer" )
add_definitions(-DASSIMP_BUILD_NO_XFILE_EXPORTER)

set( ASSIMP_BUILD_GLTF_IMPORTER OFF CACHE BOOL "Build importer" )
Expand All @@ -179,4 +179,4 @@ set(BUILD_UNIT_TESTS OFF CACHE BOOL "Do not build unit tests for bullet.")
set(BUILD_BULLET2_DEMOS OFF CACHE BOOL "no bullet2 demos.")
set(BUILD_CPU_DEMOS OFF CACHE BOOL "no bullet demos.")
set(BUILD_BULLET3 OFF CACHE BOOL "no bullet 3.")
add_subdirectory(bullet3)
add_subdirectory(bullet3)
7 changes: 6 additions & 1 deletion src/engine/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ Mesh::Mesh(std::string identifier, Vertex vertices[], int vertSize, unsigned int
{
auto it = m_meshCache.find(identifier);

if (it == m_meshCache.end() || !(m_meshData = it->second.lock())) {
if (it == m_meshCache.end() || !(m_meshData = it->second.lock()))
{
m_meshData = std::make_shared<MeshData>(vertices, vertSize, indices, indexSize);
m_meshCache[identifier] = m_meshData;
}
}
void Mesh::reasign(std::string identifier, Vertex vertices[], int vertSize, unsigned int indices[], int indexSize) //Added by Majid
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to find out why reasign was added, as its not really used for animation from what i see

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, I want to add skeletal animation to your Engine, but after some work, I figure out that the animations apply to the entities implemented by some shaders. I use "reasign" and also "recreateMesh" to apply animations (change mesh vertexes) but It should be implemented by shader. I will work on it in the future and try to implement it through shader

{
m_meshData = std::make_shared<MeshData>(vertices, vertSize, indices, indexSize);
}

Mesh::~Mesh(void)
{
Expand Down
1 change: 1 addition & 0 deletions src/engine/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Mesh
{
public:
Mesh(std::string identifier, Vertex vertices[], int vertSize, unsigned int indices[], int indexSize);
void reasign(std::string identifier, Vertex vertices[], int vertSize, unsigned int indices[], int indexSize); //Added by Majid

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*reassign

virtual ~Mesh(void);

void render(void) const;
Expand Down
59 changes: 50 additions & 9 deletions src/engine/MeshData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ MeshData::~MeshData(void)

void MeshData::createMesh(Vertex *vertices, int vertSize, unsigned int *indices, int indexSize)
{
m_vertSize = vertSize;
m_vertSize = vertSize;
m_indexSize = indexSize;

#if !defined(GLES2)
Expand All @@ -40,13 +40,54 @@ void MeshData::createMesh(Vertex *vertices, int vertSize, unsigned int *indices,
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);

glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)sizeof(glm::vec3));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *)sizeof(glm::vec3));

glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(sizeof(glm::vec3) + sizeof(glm::vec2)));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *)(sizeof(glm::vec3) + sizeof(glm::vec2)));

glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(sizeof(glm::vec3) + sizeof(glm::vec2) + sizeof(glm::vec3)));
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *)(sizeof(glm::vec3) + sizeof(glm::vec2) + sizeof(glm::vec3)));

glBindVertexArray(0);
#endif
}

void MeshData::recreateMesh(Vertex *vertices, int vertSize, unsigned int *indices, int indexSize) //Added by Majid
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as this, what was recreateMesh added for, is it useful?

{
glDeleteBuffers(1, &m_vbo);
glDeleteBuffers(1, &m_ibo);
#if !defined(GLES2)
glDeleteVertexArrays(1, &m_vao);
#endif

m_vertSize = vertSize;
m_indexSize = indexSize;

#if !defined(GLES2)
glGenVertexArrays(1, &m_vao);
glBindVertexArray(m_vao);
#endif

glGenBuffers(1, &m_vbo);
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
glBufferData(GL_ARRAY_BUFFER, vertSize * sizeof(Vertex), vertices, GL_STATIC_DRAW);

glGenBuffers(1, &m_ibo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexSize * sizeof(unsigned int), indices, GL_STATIC_DRAW);

#if !defined(GLES2)
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);

glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *)sizeof(glm::vec3));

glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *)(sizeof(glm::vec3) + sizeof(glm::vec2)));

glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *)(sizeof(glm::vec3) + sizeof(glm::vec2) + sizeof(glm::vec3)));

glBindVertexArray(0);
#endif
Expand All @@ -61,24 +102,24 @@ void MeshData::render(void) const
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);

glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)sizeof(glm::vec3));
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *)sizeof(glm::vec3));

glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(sizeof(glm::vec3) + sizeof(glm::vec2)));
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *)(sizeof(glm::vec3) + sizeof(glm::vec2)));

glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(sizeof(glm::vec3) + sizeof(glm::vec2) + sizeof(glm::vec3)));
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *)(sizeof(glm::vec3) + sizeof(glm::vec2) + sizeof(glm::vec3)));

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ibo);
glDrawElements(GL_TRIANGLES, m_indexSize, GL_UNSIGNED_INT, (void*)0);
glDrawElements(GL_TRIANGLES, m_indexSize, GL_UNSIGNED_INT, (void *)0);

glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
glDisableVertexAttribArray(3);
#else
glBindVertexArray(m_vao);
glDrawElements(GL_TRIANGLES, m_indexSize, GL_UNSIGNED_INT, (void*)0);
glDrawElements(GL_TRIANGLES, m_indexSize, GL_UNSIGNED_INT, (void *)0);
glBindVertexArray(0);
#endif
}
9 changes: 5 additions & 4 deletions src/engine/MeshData.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#pragma once

#if defined(GLES2)
#include <GLES2/gl2.h>
#include <GLES2/gl2.h>
#elif defined(GLES3)
#include <GLES3/gl3.h>
#include <GLES3/gl3.h>
#else
#include <GL/glew.h>
#include <GL/glew.h>
#endif

#include "Vertex.h"
Expand All @@ -22,7 +22,8 @@ class MeshData
void render(void) const;

private:
void createMesh(Vertex vertices[], int vertSize, unsigned int indices[], int indexSize);
void createMesh(Vertex *vertices, int vertSize, unsigned int *indices, int indexSize);
void recreateMesh(Vertex *vertices, int vertSize, unsigned int *indices, int indexSize); //Added by Majid

#if !defined(GLES2)
GLuint m_vao;
Expand Down
Loading