importing data
This commit is contained in:
@@ -15,11 +15,14 @@ ColladaModel::ColladaModel(const char* filename) : faces_(), vertices_(), normal
|
||||
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.LoadFile(filename);
|
||||
|
||||
load_texture(filename, "_diffuse.tga", diffusemap_);
|
||||
load_texture(filename, "_nm_tangent.tga", normalmap_);
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////faces//////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
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
|
||||
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_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");
|
||||
xml_normal->QueryIntAttribute("count", &normal_count);
|
||||
std::stringstream str_normal(xml_normal->GetText());
|
||||
@@ -68,9 +71,9 @@ ColladaModel::ColladaModel(const char* filename) : faces_(), vertices_(), normal
|
||||
normals_.push_back(temp);
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////textcoord/////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
texcoord_count = 0;
|
||||
int texcoord_count = 0;
|
||||
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);
|
||||
std::stringstream str_texcoord(xml_texture->GetText());
|
||||
@@ -80,11 +83,45 @@ ColladaModel::ColladaModel(const char* filename) : faces_(), vertices_(), normal
|
||||
Vec2f temp;
|
||||
str_texcoord >> temp.x;
|
||||
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_);
|
||||
load_texture(filename, "_nm_tangent.tga", normalmap_);
|
||||
for (int i = 0; i < vertexweights_count; i++)
|
||||
{
|
||||
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) {
|
||||
return textureco_[faces_[iface][nthvert][2]];
|
||||
return texturecos_[faces_[iface][nthvert][2]];
|
||||
}
|
||||
|
||||
float ColladaModel::specular(Vec2f uvf) {
|
||||
@@ -181,7 +218,7 @@ Joint ColladaModel::getrootjoint()
|
||||
return rootjoint;
|
||||
}
|
||||
|
||||
void ColladaModel::doanimation(Animator animation)
|
||||
void ColladaModel::doanimation(Animation animation)
|
||||
{
|
||||
animator.doanimation(animation);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "tgaimage.h"
|
||||
#include "joint.h"
|
||||
#include "animator.h"
|
||||
#include "animation.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstdlib>
|
||||
@@ -23,8 +24,8 @@ class ColladaModel {
|
||||
private:
|
||||
int face_count;
|
||||
int vertex_count;
|
||||
int normal_count;
|
||||
int texcoord_count;
|
||||
//int normal_count;
|
||||
//int texcoord_count;
|
||||
int joint_count;
|
||||
|
||||
Joint rootjoint;
|
||||
@@ -36,7 +37,12 @@ private:
|
||||
std::vector<std::vector<Vec3i> > faces_; //vertex/normal/uv
|
||||
std::vector<Vec3f> vertices_;
|
||||
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 normalmap_;
|
||||
@@ -75,7 +81,7 @@ public:
|
||||
/////////////////////////////
|
||||
Joint getrootjoint();
|
||||
|
||||
void doanimation(Animator animation);
|
||||
void doanimation(Animation animation);
|
||||
|
||||
void updateanimator();
|
||||
|
||||
|
||||
@@ -115,6 +115,7 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="animation.cpp" />
|
||||
<ClCompile Include="animator.cpp" />
|
||||
<ClCompile Include="camera.cpp" />
|
||||
<ClCompile Include="colladamodel.cpp" />
|
||||
@@ -129,6 +130,7 @@
|
||||
<ClCompile Include="util_window.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="animation.h" />
|
||||
<ClInclude Include="animator.h" />
|
||||
<ClInclude Include="colladamodel.h" />
|
||||
<ClInclude Include="geometry.h" />
|
||||
|
||||
@@ -51,6 +51,9 @@
|
||||
<ClCompile Include="animator.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="animation.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="util_window.h">
|
||||
@@ -86,5 +89,8 @@
|
||||
<ClInclude Include="animator.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="animation.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1 @@
|
||||
#include "animation.h"
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
class Animation
|
||||
{
|
||||
};
|
||||
|
||||
@@ -1 +1,9 @@
|
||||
#include "animator.h"
|
||||
|
||||
void Animator::doanimation(Animation animation)
|
||||
{
|
||||
}
|
||||
|
||||
void Animator::update()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
#pragma once
|
||||
#include "animator.h"
|
||||
#include "animation.h"
|
||||
|
||||
class Animator
|
||||
{
|
||||
public:
|
||||
void doanimation(Animation animation);
|
||||
void update();
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "util_window.h"
|
||||
#include "camera.h"
|
||||
#include "util_renderer.h"
|
||||
#include "colladamodel.h"
|
||||
|
||||
#define HORIZONTAL_CAMERA_SPEED 0.1
|
||||
#define VERTICAL_CAMERA_SPEED 0.1
|
||||
@@ -25,7 +26,7 @@ Matrix ViewPort = Matrix::identity();
|
||||
Matrix ModelView = Matrix::identity();
|
||||
Matrix Projection = Matrix::identity();
|
||||
|
||||
Model* model = new Model("african_head.obj");
|
||||
ColladaModel* model = new ColladaModel("sssssssssssss.dae");
|
||||
Camera camera;
|
||||
|
||||
Vec3f light_dir = Vec3f(1, 1, 1).normalize();
|
||||
@@ -58,7 +59,7 @@ struct TextureShader : public IShader {
|
||||
|
||||
virtual Vec4f vertex(int iface, int 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
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user