importing data

This commit is contained in:
Youssef Assem
2019-12-16 02:06:28 +02:00
parent 9057c94af9
commit 23dd149d48
10 changed files with 1871 additions and 16 deletions
+47 -10
View File
@@ -6,7 +6,7 @@
#define PI 3.14159265358979323846 #define PI 3.14159265358979323846
#define DEG2RAD PI/180 #define DEG2RAD PI/180
ColladaModel::ColladaModel(const char* filename) : faces_(), vertices_(), normals_(), rootjoint(rootindex,roottransform) ColladaModel::ColladaModel(const char* filename) : faces_(), vertices_(), normals_(), rootjoint(rootindex, roottransform)
{ {
Transform = Matrix::identity(); Transform = Matrix::identity();
Rotation = Matrix::identity(); Rotation = Matrix::identity();
@@ -15,11 +15,14 @@ ColladaModel::ColladaModel(const char* filename) : faces_(), vertices_(), normal
tinyxml2::XMLDocument doc; tinyxml2::XMLDocument doc;
doc.LoadFile(filename); doc.LoadFile(filename);
load_texture(filename, "_diffuse.tga", diffusemap_);
load_texture(filename, "_nm_tangent.tga", normalmap_);
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////faces////////////////////////////////////////////////// ////////////////////////////////////////////////faces//////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
face_count = 0; face_count = 0;
tinyxml2::XMLElement* xml_face = doc.FirstChildElement("COLLADA")->FirstChildElement("library_geometries")->FirstChildElement("geometry")->FirstChildElement("mesh")->FirstChildElement("triangles"); tinyxml2::XMLElement* xml_face = doc.FirstChildElement("COLLADA")->FirstChildElement("library_geometries")->FirstChildElement()->FirstChildElement()->FirstChildElement("triangles");
xml_face->QueryIntAttribute("count", &face_count); //get count xml_face->QueryIntAttribute("count", &face_count); //get count
std::stringstream str_triangle(xml_face->FirstChildElement("p")->GetText()); //get values as a string std::stringstream str_triangle(xml_face->FirstChildElement("p")->GetText()); //get values as a string
@@ -54,7 +57,7 @@ ColladaModel::ColladaModel(const char* filename) : faces_(), vertices_(), normal
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////normal//////////////////////////////////////////////////// /////////////////////////////////////////////normal////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
normal_count = 0; int normal_count = 0;
tinyxml2::XMLElement* xml_normal = doc.FirstChildElement("COLLADA")->FirstChildElement("library_geometries")->FirstChildElement("geometry")->FirstChildElement("mesh")->FirstChildElement("source")->NextSiblingElement()->FirstChildElement("float_array"); tinyxml2::XMLElement* xml_normal = doc.FirstChildElement("COLLADA")->FirstChildElement("library_geometries")->FirstChildElement("geometry")->FirstChildElement("mesh")->FirstChildElement("source")->NextSiblingElement()->FirstChildElement("float_array");
xml_normal->QueryIntAttribute("count", &normal_count); xml_normal->QueryIntAttribute("count", &normal_count);
std::stringstream str_normal(xml_normal->GetText()); std::stringstream str_normal(xml_normal->GetText());
@@ -68,9 +71,9 @@ ColladaModel::ColladaModel(const char* filename) : faces_(), vertices_(), normal
normals_.push_back(temp); normals_.push_back(temp);
} }
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////textcoord/////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////// int texcoord_count = 0;
texcoord_count = 0;
tinyxml2::XMLElement* xml_texture = doc.FirstChildElement("COLLADA")->FirstChildElement("library_geometries")->FirstChildElement("geometry")->FirstChildElement("mesh")->FirstChildElement("source")->NextSiblingElement()->NextSiblingElement()->FirstChildElement("float_array"); tinyxml2::XMLElement* xml_texture = doc.FirstChildElement("COLLADA")->FirstChildElement("library_geometries")->FirstChildElement("geometry")->FirstChildElement("mesh")->FirstChildElement("source")->NextSiblingElement()->NextSiblingElement()->FirstChildElement("float_array");
xml_texture->QueryIntAttribute("count", &texcoord_count); xml_texture->QueryIntAttribute("count", &texcoord_count);
std::stringstream str_texcoord(xml_texture->GetText()); std::stringstream str_texcoord(xml_texture->GetText());
@@ -80,11 +83,45 @@ ColladaModel::ColladaModel(const char* filename) : faces_(), vertices_(), normal
Vec2f temp; Vec2f temp;
str_texcoord >> temp.x; str_texcoord >> temp.x;
str_texcoord >> temp.y; str_texcoord >> temp.y;
textureco_.push_back(temp); texturecos_.push_back(temp);
} }
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
int vertexweights_count = 0;
tinyxml2::XMLElement* xml_vertexweights = doc.FirstChildElement("COLLADA")->FirstChildElement("library_controllers")->FirstChildElement()->FirstChildElement()->FirstChildElement("vertex_weights");
xml_vertexweights->QueryIntAttribute("count", &vertexweights_count);
std::stringstream str_vertexweights(xml_vertexweights->FirstChildElement("vcount")->GetText());
std::stringstream str_vertexweights1(xml_vertexweights->FirstChildElement("v")->GetText());
load_texture(filename, "_diffuse.tga", diffusemap_); for (int i = 0; i < vertexweights_count; i++)
load_texture(filename, "_nm_tangent.tga", normalmap_); {
int temp;
Vec2i temp1;
vertexweights_.push_back(std::vector<Vec2i>());
str_vertexweights >> temp;
for (int j = 0; j < temp; j++)
{
str_vertexweights1 >> temp1.x;
str_vertexweights1 >> temp1.y;
vertexweights_[i].push_back(temp1);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
int weight_count = 0;
tinyxml2::XMLElement* xml_weight = doc.FirstChildElement("COLLADA")->FirstChildElement("library_controllers")->FirstChildElement()->FirstChildElement()->FirstChildElement("source")->NextSiblingElement()->NextSiblingElement()->FirstChildElement();
xml_weight->QueryIntAttribute("count", &weight_count);
std::stringstream str_weight(xml_weight->GetText());
for (int i = 0; i < weight_count; i++)
{
float temp;
str_weight >> temp;
weights_.push_back(temp);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -163,7 +200,7 @@ Vec3f ColladaModel::normal(Vec2f uvf) {
} }
Vec2f ColladaModel::uv(int iface, int nthvert) { Vec2f ColladaModel::uv(int iface, int nthvert) {
return textureco_[faces_[iface][nthvert][2]]; return texturecos_[faces_[iface][nthvert][2]];
} }
float ColladaModel::specular(Vec2f uvf) { float ColladaModel::specular(Vec2f uvf) {
@@ -181,7 +218,7 @@ Joint ColladaModel::getrootjoint()
return rootjoint; return rootjoint;
} }
void ColladaModel::doanimation(Animator animation) void ColladaModel::doanimation(Animation animation)
{ {
animator.doanimation(animation); animator.doanimation(animation);
} }
+10 -4
View File
@@ -8,6 +8,7 @@
#include "tgaimage.h" #include "tgaimage.h"
#include "joint.h" #include "joint.h"
#include "animator.h" #include "animator.h"
#include "animation.h"
#include <cerrno> #include <cerrno>
#include <cstdlib> #include <cstdlib>
@@ -23,8 +24,8 @@ class ColladaModel {
private: private:
int face_count; int face_count;
int vertex_count; int vertex_count;
int normal_count; //int normal_count;
int texcoord_count; //int texcoord_count;
int joint_count; int joint_count;
Joint rootjoint; Joint rootjoint;
@@ -36,7 +37,12 @@ private:
std::vector<std::vector<Vec3i> > faces_; //vertex/normal/uv std::vector<std::vector<Vec3i> > faces_; //vertex/normal/uv
std::vector<Vec3f> vertices_; std::vector<Vec3f> vertices_;
std::vector<Vec3f> normals_; std::vector<Vec3f> normals_;
std::vector<Vec2f> textureco_; std::vector<Vec2f> texturecos_;
std::vector<std::vector<Vec2i>> vertexweights_; //joint/weight
std::vector<Vec3i> jointIDs_;
std::vector<float> weights_;
TGAImage diffusemap_; TGAImage diffusemap_;
TGAImage normalmap_; TGAImage normalmap_;
@@ -75,7 +81,7 @@ public:
///////////////////////////// /////////////////////////////
Joint getrootjoint(); Joint getrootjoint();
void doanimation(Animator animation); void doanimation(Animation animation);
void updateanimator(); void updateanimator();
+2
View File
@@ -115,6 +115,7 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="animation.cpp" />
<ClCompile Include="animator.cpp" /> <ClCompile Include="animator.cpp" />
<ClCompile Include="camera.cpp" /> <ClCompile Include="camera.cpp" />
<ClCompile Include="colladamodel.cpp" /> <ClCompile Include="colladamodel.cpp" />
@@ -129,6 +130,7 @@
<ClCompile Include="util_window.cpp" /> <ClCompile Include="util_window.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="animation.h" />
<ClInclude Include="animator.h" /> <ClInclude Include="animator.h" />
<ClInclude Include="colladamodel.h" /> <ClInclude Include="colladamodel.h" />
<ClInclude Include="geometry.h" /> <ClInclude Include="geometry.h" />
+6
View File
@@ -51,6 +51,9 @@
<ClCompile Include="animator.cpp"> <ClCompile Include="animator.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="animation.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="util_window.h"> <ClInclude Include="util_window.h">
@@ -86,5 +89,8 @@
<ClInclude Include="animator.h"> <ClInclude Include="animator.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="animation.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>
+1
View File
@@ -0,0 +1 @@
#include "animation.h"
+5
View File
@@ -0,0 +1,5 @@
#pragma once
class Animation
{
};
+8
View File
@@ -1 +1,9 @@
#include "animator.h" #include "animator.h"
void Animator::doanimation(Animation animation)
{
}
void Animator::update()
{
}
+6
View File
@@ -1,5 +1,11 @@
#pragma once #pragma once
#include "animator.h"
#include "animation.h"
class Animator class Animator
{ {
public:
void doanimation(Animation animation);
void update();
}; };
+3 -2
View File
@@ -3,6 +3,7 @@
#include "util_window.h" #include "util_window.h"
#include "camera.h" #include "camera.h"
#include "util_renderer.h" #include "util_renderer.h"
#include "colladamodel.h"
#define HORIZONTAL_CAMERA_SPEED 0.1 #define HORIZONTAL_CAMERA_SPEED 0.1
#define VERTICAL_CAMERA_SPEED 0.1 #define VERTICAL_CAMERA_SPEED 0.1
@@ -25,7 +26,7 @@ Matrix ViewPort = Matrix::identity();
Matrix ModelView = Matrix::identity(); Matrix ModelView = Matrix::identity();
Matrix Projection = Matrix::identity(); Matrix Projection = Matrix::identity();
Model* model = new Model("african_head.obj"); ColladaModel* model = new ColladaModel("sssssssssssss.dae");
Camera camera; Camera camera;
Vec3f light_dir = Vec3f(1, 1, 1).normalize(); Vec3f light_dir = Vec3f(1, 1, 1).normalize();
@@ -58,7 +59,7 @@ struct TextureShader : public IShader {
virtual Vec4f vertex(int iface, int nthvert) { virtual Vec4f vertex(int iface, int nthvert) {
varying_uv_coords.set_col(nthvert, model->uv(iface, nthvert)); varying_uv_coords.set_col(nthvert, model->uv(iface, nthvert));
Vec4f gl_Vertex = embed<4>(model->vert(iface, nthvert)); Vec4f gl_Vertex = embed<4>(model->vertix(iface, nthvert));
return ViewPort * Projection * ModelView * gl_Vertex; // transform it to screen coordinates return ViewPort * Projection * ModelView * gl_Vertex; // transform it to screen coordinates
} }
File diff suppressed because one or more lines are too long