Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bab419d197 |
@@ -0,0 +1,9 @@
|
||||
#include "COLLADA.h"
|
||||
|
||||
COLLADA::COLLADA(const char* filename)
|
||||
{
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.LoadFile(filename);
|
||||
tinyxml2::XMLElement* xml = doc.FirstChildElement("COLLADA");
|
||||
m_GeometryLibrary = GeometryLibrary(xml->FirstChildElement("library_geometries"));
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include "GeometryLibrary.h"
|
||||
class COLLADA
|
||||
{
|
||||
private:
|
||||
GeometryLibrary m_GeometryLibrary;
|
||||
//ImagesLibrary m_ImagesLibrary;
|
||||
//EffectsLibrary m_EffectsLibrary;
|
||||
//MaterialLibrary m_MaterialLibrary;
|
||||
//ControllerLibrary m_ControllerLibrary;
|
||||
//AnimationLibrary m_AnimationLibrary;
|
||||
VisualSceneLibrary m_VisualSceneLibrary;
|
||||
|
||||
public:
|
||||
COLLADA() = default;
|
||||
COLLADA(const char* filename);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "GeometryLibrary.h"
|
||||
|
||||
GeometryLibrary::GeometryLibrary(tinyxml2::XMLElement* xml)
|
||||
{
|
||||
auto xm = xml;
|
||||
auto g = Geometry(xml->FirstChildElement("geometry"));
|
||||
m_Geometries.push_back(g);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "geometry.h"
|
||||
|
||||
class GeometryLibrary
|
||||
{
|
||||
std::vector<Geometry> m_Geometries;
|
||||
|
||||
public:
|
||||
GeometryLibrary() = default;
|
||||
GeometryLibrary(tinyxml2::XMLElement * xml);
|
||||
};
|
||||
|
||||
class VisualSceneLibrary
|
||||
{
|
||||
Visualscene m_visual_scene;
|
||||
|
||||
public:
|
||||
VisualSceneLibrary() = default;
|
||||
VisualSceneLibrary(tinyxml2::XMLElement* xml);
|
||||
};
|
||||
|
||||
@@ -115,8 +115,11 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="COLLADA.cpp" />
|
||||
<ClCompile Include="ColladaModel.cpp" />
|
||||
<ClCompile Include="data.cpp" />
|
||||
<ClCompile Include="geometry.cpp" />
|
||||
<ClCompile Include="GeometryLibrary.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="model.cpp" />
|
||||
<ClCompile Include="renderer.cpp" />
|
||||
@@ -125,8 +128,11 @@
|
||||
<ClCompile Include="util_window.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="COLLADA.h" />
|
||||
<ClInclude Include="ColladaModel.h" />
|
||||
<ClInclude Include="data.h" />
|
||||
<ClInclude Include="geometry.h" />
|
||||
<ClInclude Include="GeometryLibrary.h" />
|
||||
<ClInclude Include="model.h" />
|
||||
<ClInclude Include="renderer.h" />
|
||||
<ClInclude Include="tgaimage.h" />
|
||||
|
||||
@@ -39,6 +39,15 @@
|
||||
<ClCompile Include="tinyxml2.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="COLLADA.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GeometryLibrary.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="data.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="util_window.h">
|
||||
@@ -62,5 +71,14 @@
|
||||
<ClInclude Include="tinyxml2.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="COLLADA.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GeometryLibrary.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="data.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,187 @@
|
||||
#include "data.h"
|
||||
|
||||
Float_Array::Float_Array(tinyxml2::XMLElement* xml)
|
||||
{
|
||||
xml->QueryIntAttribute("count", (int*)&m_Count);
|
||||
|
||||
const char* ch;
|
||||
xml->QueryStringAttribute("count", &ch);
|
||||
std::string s(ch);
|
||||
m_ID = s;
|
||||
|
||||
std::stringstream str(xml->GetText());
|
||||
m_Floats = new float[m_Count];
|
||||
|
||||
for (int i = 0; i < m_Count; i++)
|
||||
{
|
||||
str >> m_Floats[i];
|
||||
}
|
||||
float f = m_Floats[55358];
|
||||
}
|
||||
|
||||
Name_Array::Name_Array(tinyxml2::XMLElement* xml)
|
||||
{
|
||||
xml->QueryIntAttribute("count", (int*)&m_Count);
|
||||
|
||||
const char* ch;
|
||||
xml->QueryStringAttribute("count", &ch);
|
||||
std::string s(ch);
|
||||
m_ID = s;
|
||||
|
||||
std::stringstream str(xml->GetText());
|
||||
for (int i = 0; i < m_Count; i++)
|
||||
{
|
||||
str >> m_Names[i];
|
||||
}
|
||||
}
|
||||
|
||||
Param::Param(tinyxml2::XMLElement* xml)
|
||||
{
|
||||
const char* ch;
|
||||
xml->QueryStringAttribute("name", &ch);
|
||||
std::string s(ch);
|
||||
m_Name = s;
|
||||
|
||||
const char* ch1;
|
||||
xml->QueryStringAttribute("type", &ch1);
|
||||
std::string s1(ch1);
|
||||
m_Type = s1;
|
||||
}
|
||||
|
||||
Accessor::Accessor(tinyxml2::XMLElement* xml)
|
||||
{
|
||||
const char* ch;
|
||||
xml->QueryStringAttribute("source", &ch);
|
||||
std::string s(ch);
|
||||
m_Source = s;
|
||||
|
||||
xml->QueryIntAttribute("count", (int*)&m_Count);
|
||||
|
||||
xml->QueryIntAttribute("stride", (int*)&m_Stride);
|
||||
|
||||
for (tinyxml2::XMLElement* child = xml->FirstChildElement("param"); child != NULL; child = child->NextSiblingElement("param"))
|
||||
{
|
||||
Param p(child);
|
||||
m_Params.push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
Technique_Common::Technique_Common(tinyxml2::XMLElement* xml)
|
||||
{
|
||||
m_Accessor = Accessor(xml->FirstChildElement("accessor"));
|
||||
}
|
||||
|
||||
Source::Source(tinyxml2::XMLElement* xml)
|
||||
{
|
||||
const char* ch;
|
||||
xml->QueryStringAttribute("id", &ch);
|
||||
std::string s(ch);
|
||||
m_ID = s;
|
||||
|
||||
tinyxml2::XMLElement* fa = xml->FirstChildElement("float_array");
|
||||
if (fa != NULL)
|
||||
{
|
||||
m_Float_Array = Float_Array(fa);
|
||||
}
|
||||
|
||||
tinyxml2::XMLElement* na = xml->FirstChildElement("Name_array");
|
||||
if (na != NULL)
|
||||
{
|
||||
m_Name_Array = Name_Array(na);
|
||||
}
|
||||
|
||||
m_TechniqueCommon = Technique_Common(xml->FirstChildElement("technique_common"));
|
||||
}
|
||||
|
||||
Input::Input(tinyxml2::XMLElement* xml)
|
||||
{
|
||||
const char* ch;
|
||||
xml->QueryStringAttribute("semantic", &ch);
|
||||
std::string s(ch);
|
||||
m_Semantic = s;
|
||||
|
||||
const char* ch1;
|
||||
xml->QueryStringAttribute("source", &ch1);
|
||||
std::string s1(ch1);
|
||||
m_Source = s1;
|
||||
|
||||
if (xml->FindAttribute("offset"))
|
||||
{
|
||||
const char* ch2;
|
||||
xml->QueryStringAttribute("offset", &ch2);
|
||||
std::string s2(ch2);
|
||||
m_Offset = s2;
|
||||
}
|
||||
|
||||
if (xml->FindAttribute("set"))
|
||||
{
|
||||
const char* ch3;
|
||||
xml->QueryStringAttribute("set", &ch3);
|
||||
std::string s3(ch3);
|
||||
m_Set = s3;
|
||||
}
|
||||
}
|
||||
|
||||
Vertices::Vertices(tinyxml2::XMLElement* xml)
|
||||
{
|
||||
const char* ch;
|
||||
xml->QueryStringAttribute("id", &ch);
|
||||
std::string s(ch);
|
||||
m_ID = s;
|
||||
|
||||
for (tinyxml2::XMLElement* child = xml->FirstChildElement("input"); child != NULL; child = child->NextSiblingElement("input"))
|
||||
{
|
||||
Input in(child);
|
||||
m_Inputs.push_back(in);
|
||||
}
|
||||
}
|
||||
|
||||
P::P(tinyxml2::XMLElement* xml, unsigned int count)
|
||||
{
|
||||
m_Count = count;
|
||||
std::stringstream str(xml->GetText());
|
||||
m_Indices = new unsigned short[count * 9];
|
||||
for (int i = 0; i < count * 9; i++)
|
||||
{
|
||||
str >> m_Indices[i];
|
||||
}
|
||||
}
|
||||
|
||||
Triangles::Triangles(tinyxml2::XMLElement* xml)
|
||||
{
|
||||
xml->QueryIntAttribute("count", (int*)&m_Count);
|
||||
|
||||
const char* ch;
|
||||
xml->QueryStringAttribute("count", &ch);
|
||||
std::string s(ch);
|
||||
m_Material = s;
|
||||
|
||||
for (tinyxml2::XMLElement* child = xml->FirstChildElement("input"); child != NULL; child = child->NextSiblingElement("input"))
|
||||
{
|
||||
Input in(child);
|
||||
m_Inputs.push_back(in);
|
||||
}
|
||||
|
||||
tinyxml2::XMLElement* mp = xml->FirstChildElement("p");
|
||||
if (mp != NULL)
|
||||
{
|
||||
m_P = P(mp, m_Count);
|
||||
}
|
||||
}
|
||||
|
||||
Mesh::Mesh(tinyxml2::XMLElement* xml)
|
||||
{
|
||||
for (tinyxml2::XMLElement* child = xml->FirstChildElement("source"); child != NULL; child = child->NextSiblingElement("source"))
|
||||
{
|
||||
Source sc(child);
|
||||
m_Sources.push_back(sc);
|
||||
}
|
||||
|
||||
m_Vertices = Vertices(xml->FirstChildElement("vertices"));
|
||||
|
||||
for (tinyxml2::XMLElement* child = xml->FirstChildElement("triangles"); child != NULL; child = child->NextSiblingElement("triangles"))
|
||||
{
|
||||
Triangles tr(child);
|
||||
m_Triangles.push_back(tr);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "tinyxml2.h"
|
||||
//----------------------------------------------//
|
||||
class Float_Array
|
||||
{
|
||||
unsigned int m_Count;
|
||||
std::string m_ID;
|
||||
float* m_Floats;
|
||||
|
||||
public:
|
||||
Float_Array() = default;
|
||||
Float_Array(tinyxml2::XMLElement* xml);
|
||||
};
|
||||
//----------------------------------------------//
|
||||
class Name_Array
|
||||
{
|
||||
unsigned int m_Count;
|
||||
std::string m_ID;
|
||||
std::string* m_Names;
|
||||
public:
|
||||
Name_Array() = default;
|
||||
Name_Array(tinyxml2::XMLElement* xml);
|
||||
};
|
||||
//----------------------------------------------//
|
||||
class Param
|
||||
{
|
||||
std::string m_Name;
|
||||
std::string m_Type;
|
||||
public:
|
||||
Param() = default;
|
||||
Param(tinyxml2::XMLElement* xml);
|
||||
};
|
||||
//----------------------------------------------//
|
||||
class Accessor
|
||||
{
|
||||
std::string m_Source;
|
||||
unsigned int m_Count;
|
||||
unsigned int m_Stride;
|
||||
std::vector<Param> m_Params;
|
||||
public:
|
||||
Accessor () = default;
|
||||
Accessor(tinyxml2::XMLElement* xml);
|
||||
};
|
||||
//----------------------------------------------//
|
||||
class Technique_Common
|
||||
{
|
||||
Accessor m_Accessor;
|
||||
public:
|
||||
Technique_Common() = default;
|
||||
Technique_Common(tinyxml2::XMLElement* xml);
|
||||
};
|
||||
//----------------------------------------------//
|
||||
class Source
|
||||
{
|
||||
std::string m_ID;
|
||||
Float_Array m_Float_Array;
|
||||
Name_Array m_Name_Array;
|
||||
Technique_Common m_TechniqueCommon;
|
||||
public:
|
||||
Source() = default;
|
||||
Source(tinyxml2::XMLElement* xml);
|
||||
};
|
||||
//----------------------------------------------//
|
||||
class Input
|
||||
{
|
||||
std::string m_Semantic;
|
||||
std::string m_Source;
|
||||
std::string m_Offset;
|
||||
std::string m_Set;
|
||||
public:
|
||||
Input() = default;
|
||||
Input(tinyxml2::XMLElement* xml);
|
||||
};
|
||||
//----------------------------------------------//
|
||||
class Vertices
|
||||
{
|
||||
std::string m_ID;
|
||||
std::vector<Input> m_Inputs;
|
||||
public:
|
||||
Vertices() = default;
|
||||
Vertices(tinyxml2::XMLElement* xml);
|
||||
};
|
||||
//----------------------------------------------//
|
||||
class P
|
||||
{
|
||||
unsigned int m_Count;
|
||||
unsigned short* m_Indices;
|
||||
public:
|
||||
P() = default;
|
||||
P(tinyxml2::XMLElement* xml, unsigned int count);
|
||||
};
|
||||
//----------------------------------------------//
|
||||
class Triangles
|
||||
{
|
||||
unsigned int m_Count;
|
||||
std::string m_Material;
|
||||
std::vector<Input> m_Inputs;
|
||||
P m_P;
|
||||
public:
|
||||
Triangles() = default;
|
||||
Triangles(tinyxml2::XMLElement* xml);
|
||||
};
|
||||
//----------------------------------------------//
|
||||
class Mesh
|
||||
{
|
||||
std::vector<Source> m_Sources;
|
||||
Vertices m_Vertices;
|
||||
std::vector<Triangles> m_Triangles;
|
||||
public:
|
||||
Mesh() = default;
|
||||
Mesh(tinyxml2::XMLElement* xml);
|
||||
};
|
||||
//----------------------------------------------//
|
||||
class Node
|
||||
{
|
||||
std::string m_ID;
|
||||
std::string m_name;
|
||||
std::string m_type;
|
||||
std::string m_sid;
|
||||
public:
|
||||
Node() = default;
|
||||
Node(tinyxml2::XMLElement* xml);
|
||||
};
|
||||
//----------------------------------------------//
|
||||
class Matrix
|
||||
{
|
||||
std::string m_sid;
|
||||
public:
|
||||
Node() = default;
|
||||
Node(tinyxml2::XMLElement* xml);
|
||||
};
|
||||
//----------------------------------------------//
|
||||
@@ -5,3 +5,7 @@ template <> template <> vec<3,float>::vec(const vec<3,int> &v) : x(v.x),y(v.y)
|
||||
template <> template <> vec<2,int> ::vec(const vec<2,float> &v) : x(int(v.x+.5f)),y(int(v.y+.5f)) {}
|
||||
template <> template <> vec<2,float>::vec(const vec<2,int> &v) : x(v.x),y(v.y) {}
|
||||
|
||||
Geometry::Geometry(tinyxml2::XMLElement* xml)
|
||||
{
|
||||
m_Mesh = Mesh(xml->FirstChildElement("mesh"));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include "data.h"
|
||||
|
||||
template<size_t DimCols,size_t DimRows,typename T> class mat;
|
||||
|
||||
@@ -233,5 +234,46 @@ typedef vec<3, float> Vec3f;
|
||||
typedef vec<3, int> Vec3i;
|
||||
typedef vec<4, float> Vec4f;
|
||||
typedef mat<4,4,float> Matrix;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Geometry
|
||||
{
|
||||
Mesh m_Mesh;
|
||||
public:
|
||||
Geometry() = default;
|
||||
Geometry(tinyxml2::XMLElement * xml);
|
||||
};
|
||||
|
||||
class Visualscene
|
||||
{
|
||||
node m_Mesh;
|
||||
public:
|
||||
Visualscene() = default;
|
||||
Visualscene(tinyxml2::XMLElement* xml);
|
||||
};
|
||||
#endif //__GEOMETRY_H__
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "util_window.h"
|
||||
#include <ctime>
|
||||
#include "ColladaModel.h"
|
||||
#include "COLLADA.h"
|
||||
|
||||
const TGAColor white = TGAColor(255, 255, 255, 255);
|
||||
const TGAColor red = TGAColor(255, 0, 0, 255);
|
||||
@@ -188,6 +189,7 @@ Matrix lookat(Vec3f eye, Vec3f center, Vec3f up) {
|
||||
|
||||
void render()
|
||||
{
|
||||
COLLADA C("sssssssssssss.dae");
|
||||
ColladaModel* model = new ColladaModel("african_head.dae");
|
||||
Matrix ViewPort = viewport(screen_width / 8, screen_height / 8, screen_width * 3 / 4, screen_height * 3 / 4);
|
||||
Matrix Projection = Matrix::identity();
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user