Skip to content

Commit 4298267

Browse files
added support for AC3D
1 parent 7093aa3 commit 4298267

6 files changed

Lines changed: 680 additions & 1 deletion

File tree

generate.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,23 @@ namespace Generate
138138
return Mesh(std::move(triangles), texture);
139139
}
140140

141+
inline Mesh convexPolygon(shared_ptr<Texture> texture, vector<tuple<VectorF, TextureCoord>> vertices)
142+
{
143+
if(vertices.size() < 3)
144+
return Mesh();
145+
vector<Triangle> triangles;
146+
triangles.reserve(vertices.size() - 2);
147+
tuple<VectorF, TextureCoord> v1 = vertices[0];
148+
for(size_t i = 1, j = 2; j < vertices.size(); i++, j++)
149+
{
150+
tuple<VectorF, TextureCoord> v2 = vertices[i], v3 = vertices[j];
151+
triangles.push_back(Triangle(get<0>(v1), get<1>(v1),
152+
get<0>(v2), get<1>(v2),
153+
get<0>(v3), get<1>(v3)));
154+
}
155+
return Mesh(std::move(triangles), texture);
156+
}
157+
141158
/// make a box from <0, 0, 0> to <1, 1, 1>
142159
inline Mesh unitBox(TextureDescriptor nx, TextureDescriptor px, TextureDescriptor ny, TextureDescriptor py, TextureDescriptor nz, TextureDescriptor pz)
143160
{

lib3d.cbp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<Option object_output="obj/Debug/" />
1212
<Option type="1" />
1313
<Option compiler="gcc" />
14+
<Option parameters="test_objects/f16/f16.ac" />
1415
<Compiler>
1516
<Add option="-g" />
1617
<Add option="`sdl2-config --cflags` `pkg-config libavcodec libavformat libavutil libswscale MagickWand --cflags`" />

main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ int main(int argc, char **argv)
9696
string fileName = argc > 1 ? argv[1] : "";
9797
if(fileName != "")
9898
{
99-
shared_ptr<ModelLoader> loader = ModelLoader::loadOBJ(fileName, [](string msg){cout << "model load : warning : " << msg << endl;});
99+
shared_ptr<ModelLoader> loader = ModelLoader::load(fileName, [](string msg){cout << "model load : warning : " << msg << endl;});
100100
model = loader->loadAll();
101101
cout << "model has " << model->triangleCount() << " triangles." << endl;
102102
}

material.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "image.h"
55
#include "vector.h"
66
#include <vector>
7+
#include <functional> // std::hash
78

89
using namespace std;
910

@@ -88,6 +89,33 @@ struct Material
8889
return !operator ==(rt);
8990
}
9091
};
92+
93+
namespace std
94+
{
95+
template <>
96+
struct hash<Material>
97+
{
98+
private:
99+
hash<float> hash_float;
100+
hash<shared_ptr<Texture>> hash_texture;
101+
public:
102+
size_t operator ()(const Material &m) const
103+
{
104+
size_t retval = hash_float(m.ambient.r);
105+
retval += hash_float(m.ambient.g);
106+
retval += hash_float(m.ambient.b);
107+
retval += hash_float(m.ambient.a);
108+
retval += hash_float(m.diffuse.r);
109+
retval += hash_float(m.diffuse.g);
110+
retval += hash_float(m.diffuse.b);
111+
retval += hash_float(m.diffuse.a);
112+
retval += hash_float(m.opacity);
113+
retval += hash_texture(m.texture);
114+
return retval;
115+
}
116+
};
117+
}
118+
91119
#if 0
92120
template <>
93121
struct LightListLiteral<>

0 commit comments

Comments
 (0)