Compare commits

...

2 Commits

3 changed files with 21 additions and 6 deletions

View File

@@ -7,6 +7,7 @@
struct model { struct model {
std::vector<vec3> verts; std::vector<vec3> verts;
std::vector<uint16_t> faces; std::vector<uint16_t> faces;
std::vector<vec3> normals;
}; };
#endif #endif

View File

@@ -21,6 +21,14 @@ for index,line in enumerate(content):
content = content[endVerts:] content = content[endVerts:]
break break
normals = []
for index,line in enumerate(content):
if "vt" in line:
normals = content[:index]
content = content[index:]
break
startFaces = 0; startFaces = 0;
faces = [] faces = []
for index,line in enumerate(content): for index,line in enumerate(content):
@@ -31,8 +39,9 @@ for index,line in enumerate(content):
verts = ["vec3(" +",".join(vert.split(" ")[1:4]) + ")" for vert in verts] verts = ["vec3(" +",".join(vert.split(" ")[1:4]) + ")" for vert in verts]
faces = [ ",".join([str(int((d.split("/")[0])) - 1) for d in face.split(" ")[1:4]]) for face in faces] faces = [ ",".join([str(int((d.split("/")[0])) - 1) for d in face.split(" ")[1:4]]) for face in faces]
normals = ["vec3(" + ",".join(normal.split(" ")[1:4]) + ")" for normal in normals]
out = "#include \"model.hpp\" \n const model testModel({" + ",".join(verts) +"},{" + ",".join(faces) + "});" out = "#include \"model.hpp\" \n const model testModel({" + ",".join(verts) +"},{" + ",".join(faces) + "},{" + ",".join(normals) + "});"
with open("testModel.hpp", "w") as f: with open("testModel.hpp", "w") as f:
f.write(out) f.write(out)

View File

@@ -6,7 +6,7 @@ struct polygon {
vec3 points[3]; vec3 points[3];
decimal delta[9]; decimal delta[9];
bool skip = false; bool small = false;
decimal bounding[4]; // min x, max x, min y, max y decimal bounding[4]; // min x, max x, min y, max y
@@ -23,6 +23,8 @@ struct polygon {
delta[i * 3 + 1] = points[n].x() - points[i].x(); delta[i * 3 + 1] = points[n].x() - points[i].x();
delta[i * 3 + 2] = delta[i * 3 + 2] =
points[i].x() * points[n].y() - points[i].y() * points[n].x(); points[i].x() * points[n].y() - points[i].y() * points[n].x();
if (delta[i * 3].i == 0 && delta[i * 3 + 1].i == 0)
small = true;
} }
bounding[0] = points[0].x(); bounding[0] = points[0].x();
bounding[1] = points[0].x(); bounding[1] = points[0].x();
@@ -38,17 +40,20 @@ struct polygon {
if (bounding[3] < points[i].y()) if (bounding[3] < points[i].y())
bounding[3] = points[i].y(); bounding[3] = points[i].y();
} }
/*if ((bounding[1].i - bounding[0].i < 1 << HALF_SHIFT) &&
(bounding[3].i - bounding[2].i < 1 << HALF_SHIFT))
small = true;*/
} }
const bool contains(const vec3 &p) { const bool contains(const vec3 &p) {
// if (skip) // if (skip)
// return false; // return false;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
if (small)
return true;
vec3 d = p; vec3 d = p;
if ((((d.x().i >> SHIFT_AMOUNT) * delta[i * 3].i + if ((d.x() * delta[i * 3] + d.y() * delta[i * 3 + 1] +
(d.y().i >> SHIFT_AMOUNT) * delta[i * 3 + 1].i + delta[i * 3 + 2]) > decimal(0))
delta[i * 3 + 2].i) >>
SHIFT_AMOUNT) > 0)
return false; return false;
} }
return true; return true;