Skip to content

Commit

Permalink
CPU skinning bugifx
Browse files Browse the repository at this point in the history
Resolve twice multiplied Model2World issue
  • Loading branch information
wolfrev0 committed Sep 7, 2023
1 parent 6997069 commit a2fecd5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Memory Leak https://github.com/glfw/glfw/issues/2093

## TODO
* Model animation
- Draw bone tree(Draw line from bone to its parent)
- CPU Skinning
- GPU Skinning
* Use shader instead fixed function pipeline (https://learnopengl.com/Lighting/Basic-Lighting)
* GPU skinning(https://community.khronos.org/t/skinning-on-the-gpu-vs-the-cpu/73169/8)
Expand Down
24 changes: 12 additions & 12 deletions src/game/entity/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ Entity::~Entity(){
delete child;
}

void Entity::draw(Mat44 parent2world, std::vector<RenderRequest>& render_q)const{
void Entity::draw(const Mat44& world2camera, Mat44 parent2world, std::vector<RenderRequest>& render_q)const{
for(auto i: children){
i->draw(parent2world*local2parent(), render_q);
i->draw(world2camera, parent2world*local2parent(), render_q);
}

for(auto mesh:meshes){
Expand All @@ -223,23 +223,23 @@ void Entity::draw(Mat44 parent2world, std::vector<RenderRequest>& render_q)const
normals_cur[i]=mesh->normals[i];
}
render_q.emplace_back(
parent2world*local2parent(),
world2camera*local2parent(),
mesh->primitive_type,
vertices_cur,
normals_cur,
mesh->texcoord,
mesh->faces,
mesh->material->getTextureID());
}
//bone tree
render_q.emplace_back(
parent2world,
PrimitiveType::lines,
std::vector<Vec3>{{0,0,0},position()},
std::vector<Vec3>{},
std::vector<Vec3>{},
std::vector<std::vector<uint>>{},
unsigned(-1));
// //bone tree
// render_q.emplace_back(
// world2camera*parent2world,
// PrimitiveType::lines,
// std::vector<Vec3>{{0,0,0},position()},
// std::vector<Vec3>{},
// std::vector<Vec3>{},
// std::vector<std::vector<uint>>{},
// unsigned(-1));
}

void Entity::update(float delta_time){
Expand Down
2 changes: 1 addition & 1 deletion src/game/entity/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct Entity{
return ret;
}

void draw(Mat44 parent2world, std::vector<RenderRequest>& render_q)const;
void draw(const Mat44& world2camera, Mat44 parent2world, std::vector<RenderRequest>& render_q)const;
void update(float delta_time);

void(*onUpdate)(Entity* self, float delta_time)=nullptr;
Expand Down
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ void init(){
});

auto dv = Entity::loadFromFile("models/dancing_vampire/dancing_vampire.dae");
dv->scale({0.1, 0.1, 0.1});
dv->position({10,-1,0});
dv->scale({0.05, 0.05, 0.05});
dv->position({-6,-1,0});
dv->onUpdate=[](Entity*self, float delta_time){
};
entity_root->adopt(dv);
Expand Down Expand Up @@ -119,7 +119,7 @@ void render(){
if(!camera)
throw "No camera selected";
vector<RenderRequest> render_q;
entity_root->draw(camera->world2local(), render_q);
entity_root->draw(camera->world2local(), Mat44::identity(), render_q);
renderer->render(render_q);
}

Expand Down

0 comments on commit a2fecd5

Please sign in to comment.