Skip to content

Commit

Permalink
lil fix, no normalized normals pass vertices as normals, shadows work…
Browse files Browse the repository at this point in the history
… now and less work done by algorithm
  • Loading branch information
martimyc committed Dec 17, 2017
1 parent 69fe4a5 commit 06d77d3
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 29 deletions.
Binary file added Engine/Game/Assets/Skeleton_D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Engine/Game/Assets/Thumbs.db
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion Engine/Game/docks.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Docking Config":{"dock_0":{"label":"Application","id":583488022,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":146,"position y":316,"size x":434,"size y":354,"status":1,"location":"","opended":false,"first":false,"last frame":1654},"dock_1":{"label":"Window","id":2353593579,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":95.852500915527344,"position y":157,"size x":519.8956298828125,"size y":223,"status":1,"location":"","opended":false,"first":false,"last frame":1654},"dock_2":{"label":"Audio","id":3652983185,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":98.336929321289063,"position y":114.64968872070313,"size x":449.135009765625,"size y":169.10829162597656,"status":1,"location":"","opended":false,"first":false,"last frame":1654},"dock_3":{"label":"Camera 3D","id":303086869,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":96.445831298828125,"position y":136.62422180175781,"size x":445.35281372070313,"size y":216.87899780273438,"status":1,"location":"","opended":false,"first":false,"last frame":1654},"dock_4":{"label":"HardWare","id":2816287880,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":95.500282287597656,"position y":174.84077453613281,"size x":485.06582641601563,"size y":342.0382080078125,"status":1,"location":"","opended":false,"first":false,"last frame":1654},"dock_5":{"label":"Draw Modes","id":3318925436,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":117,"position y":103,"size x":263,"size y":161,"status":1,"location":"","opended":false,"first":false,"last frame":1654},"dock_6":{"label":"Renderer 3D","id":244062129,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":101.17356872558594,"position y":193.94906616210938,"size x":454.80831909179688,"size y":205.41403198242188,"status":1,"location":"","opended":false,"first":false,"last frame":1654},"dock_7":{"label":"Console","id":4190041642,"next tab":-1,"prev tab":10,"first child":-1,"second child":-1,"parent":13,"active":false,"position x":0,"position y":648,"size x":1298.1962890625,"size y":252,"status":0,"location":"","opended":true,"first":false,"last frame":1654},"dock_8":{"label":"Scene","id":414761182,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":12,"active":true,"position x":285,"position y":23,"size x":1013.1962890625,"size y":625,"status":0,"location":"","opended":true,"first":false,"last frame":1654},"dock_9":{"label":"Hirarchy","id":1821821033,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":12,"active":true,"position x":0,"position y":23,"size x":285,"size y":625,"status":0,"location":"","opended":true,"first":false,"last frame":1654},"docks num":9,"dock_10":{"label":"Assets","id":2122152120,"next tab":7,"prev tab":-1,"first child":-1,"second child":-1,"parent":13,"active":true,"position x":0,"position y":648,"size x":1298.1962890625,"size y":252,"status":0,"location":"","opended":true,"first":false,"last frame":1654},"docks_num":18,"dock_11":{"label":"Inspector","id":4029469480,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":14,"active":true,"position x":1298.1962890625,"position y":23,"size x":368.8037109375,"size y":877,"status":0,"location":"","opended":true,"first":false,"last frame":1654},"dock_12":{"label":"","id":0,"next tab":-1,"prev tab":-1,"first child":9,"second child":8,"parent":13,"active":true,"position x":0,"position y":23,"size x":1298.1962890625,"size y":625,"status":0,"location":"","opended":false,"first":true,"last frame":0},"dock_13":{"label":"","id":0,"next tab":-1,"prev tab":-1,"first child":12,"second child":10,"parent":14,"active":true,"position x":0,"position y":23,"size x":1298.1962890625,"size y":877,"status":0,"location":"","opended":false,"first":true,"last frame":0},"dock_14":{"label":"","id":0,"next tab":-1,"prev tab":-1,"first child":13,"second child":11,"parent":-1,"active":true,"position x":0,"position y":23,"size x":1667,"size y":877,"status":0,"location":"","opended":false,"first":true,"last frame":0},"dock_15":{"label":"About","id":1949634023,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":287.5574951171875,"position y":146,"size x":369.86563110351563,"size y":250,"status":1,"location":"","opended":false,"first":false,"last frame":1654},"dock_16":{"label":"Timers","id":3786072985,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":256,"position y":58,"size x":204,"size y":126,"status":1,"location":"","opended":false,"first":false,"last frame":1654},"dock_17":{"label":"Matrix Debug","id":427640940,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":1075.2149658203125,"position y":53,"size x":366.739990234375,"size y":437,"status":1,"location":"","opended":false,"first":false,"last frame":1654}}}
{"Docking Config":{"dock_0":{"label":"Application","id":583488022,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":98,"position y":225,"size x":434,"size y":354,"status":1,"location":"","opended":true,"first":false,"last frame":2873},"dock_1":{"label":"Window","id":2353593579,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":95.852500915527344,"position y":157,"size x":519.8956298828125,"size y":223,"status":1,"location":"","opended":false,"first":false,"last frame":2873},"dock_2":{"label":"Audio","id":3652983185,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":98.336929321289063,"position y":114.64968872070313,"size x":449.135009765625,"size y":169.10829162597656,"status":1,"location":"","opended":false,"first":false,"last frame":2873},"dock_3":{"label":"Camera 3D","id":303086869,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":96.445831298828125,"position y":136.62422180175781,"size x":445.35281372070313,"size y":216.87899780273438,"status":1,"location":"","opended":false,"first":false,"last frame":2873},"dock_4":{"label":"HardWare","id":2816287880,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":95.500282287597656,"position y":174.84077453613281,"size x":485.06582641601563,"size y":342.0382080078125,"status":1,"location":"","opended":false,"first":false,"last frame":2873},"dock_5":{"label":"Draw Modes","id":3318925436,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":117,"position y":103,"size x":263,"size y":161,"status":1,"location":"","opended":false,"first":false,"last frame":2873},"dock_6":{"label":"Renderer 3D","id":244062129,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":101.17356872558594,"position y":193.94906616210938,"size x":454.80831909179688,"size y":205.41403198242188,"status":1,"location":"","opended":false,"first":false,"last frame":2873},"dock_7":{"label":"Console","id":4190041642,"next tab":-1,"prev tab":10,"first child":-1,"second child":-1,"parent":13,"active":false,"position x":0,"position y":648,"size x":1298.1962890625,"size y":252,"status":0,"location":"","opended":true,"first":false,"last frame":2873},"dock_8":{"label":"Scene","id":414761182,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":12,"active":true,"position x":285,"position y":23,"size x":1013.1962890625,"size y":625,"status":0,"location":"","opended":true,"first":false,"last frame":2873},"dock_9":{"label":"Hirarchy","id":1821821033,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":12,"active":true,"position x":0,"position y":23,"size x":285,"size y":625,"status":0,"location":"","opended":true,"first":false,"last frame":2873},"docks num":9,"dock_10":{"label":"Assets","id":2122152120,"next tab":7,"prev tab":-1,"first child":-1,"second child":-1,"parent":13,"active":true,"position x":0,"position y":648,"size x":1298.1962890625,"size y":252,"status":0,"location":"","opended":true,"first":false,"last frame":2873},"docks_num":18,"dock_11":{"label":"Inspector","id":4029469480,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":14,"active":true,"position x":1298.1962890625,"position y":23,"size x":368.8037109375,"size y":877,"status":0,"location":"","opended":true,"first":false,"last frame":540},"dock_12":{"label":"","id":0,"next tab":-1,"prev tab":-1,"first child":9,"second child":8,"parent":13,"active":true,"position x":0,"position y":23,"size x":1298.1962890625,"size y":625,"status":0,"location":"","opended":false,"first":true,"last frame":0},"dock_13":{"label":"","id":0,"next tab":-1,"prev tab":-1,"first child":12,"second child":10,"parent":14,"active":true,"position x":0,"position y":23,"size x":1298.1962890625,"size y":877,"status":0,"location":"","opended":false,"first":true,"last frame":0},"dock_14":{"label":"","id":0,"next tab":-1,"prev tab":-1,"first child":13,"second child":11,"parent":-1,"active":true,"position x":0,"position y":23,"size x":1667,"size y":877,"status":0,"location":"","opended":false,"first":true,"last frame":0},"dock_15":{"label":"About","id":1949634023,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":287.5574951171875,"position y":146,"size x":369.86563110351563,"size y":250,"status":1,"location":"","opended":false,"first":false,"last frame":2873},"dock_16":{"label":"Timers","id":3786072985,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":256,"position y":58,"size x":204,"size y":126,"status":1,"location":"","opended":false,"first":false,"last frame":2873},"dock_17":{"label":"Matrix Debug","id":427640940,"next tab":-1,"prev tab":-1,"first child":-1,"second child":-1,"parent":-1,"active":true,"position x":1075.2149658203125,"position y":53,"size x":366.739990234375,"size y":437,"status":1,"location":"","opended":false,"first":false,"last frame":2873}}}
4 changes: 2 additions & 2 deletions Engine/Game/imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Size=1195,211
Collapsed=0

[Application]
Pos=146,316
Pos=98,225
Size=434,354
Collapsed=0

Expand Down Expand Up @@ -174,7 +174,7 @@ Size=132,47
Collapsed=0

[Timers]
Pos=132,273
Pos=228,153
Size=204,126
Collapsed=0

Expand Down
13 changes: 13 additions & 0 deletions Engine/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ void MeshSource::LoadKDT(char ** iterator)
triangle_kdt->Load(iterator);
}

float3 MeshSource::GetVertex(unsigned int vertex_id) const
{
return float3(vertices[vertex_id * 3], vertices[vertex_id * 3 + 1], vertices[vertex_id * 3 + 2]);
}

const GLuint MeshSource::GetVerticesID() const
{
return vertex_id;
Expand Down Expand Up @@ -888,6 +893,14 @@ void Mesh::UnLoad()
source = nullptr;
}

float3 Mesh::GetVertex(unsigned int vertex_id) const
{
if (source != nullptr)
return source->GetVertex(vertex_id);
LOG("Trying to acces non loaded mesh");
return float3::nan;
}

const GLuint Mesh::GetVerticesID() const
{
if (source != nullptr)
Expand Down
6 changes: 3 additions & 3 deletions Engine/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ struct MeshSource
float raycast_ticks_log[KDT_GRAPH_SIZE] = {};
float raycast_checks_log[KDT_GRAPH_SIZE] = {};

friend class Skeleton;

MeshSource();
MeshSource(const MeshSource& copy);
~MeshSource();
Expand All @@ -69,6 +67,7 @@ struct MeshSource

//Getters
//Vertices
float3 GetVertex(unsigned int vertex_id) const;
const GLuint GetVerticesID() const;
const GLuint GetNumVertices() const;
const GLfloat* GetVertices() const;
Expand Down Expand Up @@ -156,7 +155,8 @@ class Mesh : public Resource
void UnLoad();

//Getters
//Vertices
//Vertices
float3 GetVertex(unsigned int vertex_id) const;
const GLuint GetVerticesID() const;
const GLuint GetNumVertices() const;
const GLfloat* GetVertices() const;
Expand Down
37 changes: 17 additions & 20 deletions Engine/Skeleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
#include "Mesh.h"
#include "Skeleton.h"

Skeleton::Skeleton(const std::string & name, const UID & uid) : Resource(RT_SKELETON, name, uid), skeleton(nullptr), deformable_mesh(nullptr)
Skeleton::Skeleton(const std::string & name, const UID & uid) : Resource(RT_SKELETON, name, uid), skeleton(nullptr), deformable_vertices(nullptr)
{}

Skeleton::Skeleton(const std::string & name, Rigg * source) : Resource(RT_SKELETON, name), skeleton(source), deformable_mesh(nullptr)
Skeleton::Skeleton(const std::string & name, Rigg * source) : Resource(RT_SKELETON, name), skeleton(source), deformable_vertices(nullptr)
{}

Skeleton::~Skeleton()
{
delete skeleton;
delete deformable_mesh;
delete[] deformable_vertices;
}

void Skeleton::SetRigg(Rigg* new_rigg)
Expand Down Expand Up @@ -91,25 +91,22 @@ unsigned int Skeleton::GetNumJoints() const

void Skeleton::DeformableMesh(const Mesh * mesh)
{
deformable_mesh = new MeshSource(*mesh->GetSource());
deformable_vertices = new GLfloat[mesh->GetNumVertices() * 3];
}

void Skeleton::UpdateMesh(const Mesh* original)
{
skeleton->GetVertices(original->GetSource(), deformable_mesh->vertices);
skeleton->GetVertices(original, deformable_vertices);

if (deformable_mesh != nullptr)
if (deformable_vertices != nullptr)
{
glBindBuffer(GL_ARRAY_BUFFER, deformable_mesh->vertex_id);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * deformable_mesh->num_vertices * 3,
deformable_mesh->vertices, GL_DYNAMIC_DRAW);

if (deformable_mesh->GetNormals() != nullptr)
{
glBindBuffer(GL_ARRAY_BUFFER, deformable_mesh->normals_id);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * deformable_mesh->num_vertices * 3,
deformable_mesh->vertices, GL_DYNAMIC_DRAW); //pdf said vertices here
}
glBindBuffer(GL_ARRAY_BUFFER, original->GetVerticesID());
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * original->GetNumVertices() * 3,
deformable_vertices, GL_DYNAMIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER, original->GetNormalsID());
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * original->GetNumVertices() * 3,
deformable_vertices, GL_DYNAMIC_DRAW); //pdf said vertices here
}
}

Expand Down Expand Up @@ -164,9 +161,9 @@ unsigned int Skeleton::Rigg::GetNumJoints() const
return num_joints;
}

void Skeleton::Rigg::GetVertices(const MeshSource * original, GLfloat * vertices)
void Skeleton::Rigg::GetVertices(const Mesh * original, GLfloat * vertices)
{
memset(vertices, 0.0f, original->num_vertices * 3 * sizeof(GLfloat));
memset(vertices, 0.0f, original->GetNumVertices() * 3 * sizeof(GLfloat));

root_joint.GetVertices(original, vertices, transform);
}
Expand Down Expand Up @@ -445,15 +442,15 @@ void Skeleton::Rigg::Joint::ChangeTransforms(Animation* anim, double anim_time,
it->ChangeTransforms(anim, anim_time, interpolation);
}

void Skeleton::Rigg::Joint::GetVertices(const MeshSource* original, GLfloat * vertices, const float3x4& parent_mesh)
void Skeleton::Rigg::Joint::GetVertices(const Mesh* original, GLfloat * vertices, const float3x4& parent_mesh)
{
float3x4 mesh_transform(parent_mesh * current_transform);

for (std::vector<Weight>::iterator it = weights.begin(); it != weights.end(); ++it)
{
float3x4 skining_transform(mesh_transform * offset);

float3 vertex = skining_transform.TransformPos(original->vertices[it->vertex_id * 3], original->vertices[it->vertex_id * 3 + 1], original->vertices[it->vertex_id * 3 + 2]);
float3 vertex = skining_transform.TransformPos(original->GetVertex(it->vertex_id));

vertices[it->vertex_id * 3] += vertex.x * it->influence;
vertices[it->vertex_id * 3 + 1] += vertex.y * it->influence;
Expand Down
6 changes: 3 additions & 3 deletions Engine/Skeleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Skeleton : public Resource

void ChangeTransforms(Animation* anim, double anim_time, bool interpolation = true);

void GetVertices(const MeshSource * original, GLfloat * vertices, const float3x4& parent_mesh);
void GetVertices(const Mesh * original, GLfloat * vertices, const float3x4& parent_mesh);
};

Joint root_joint;
Expand All @@ -82,11 +82,11 @@ class Skeleton : public Resource

unsigned int GetNumJoints() const;

void GetVertices(const MeshSource* original, GLfloat* vertices);
void GetVertices(const Mesh* original, GLfloat* vertices);
};

Rigg* skeleton;
MeshSource* deformable_mesh;
GLfloat* deformable_vertices;

friend class SkeletonImporter;

Expand Down

0 comments on commit 06d77d3

Please sign in to comment.