Compare commits
2 Commits
7c55eb3be4
...
939d1e6b1e
| Author | SHA1 | Date | |
|---|---|---|---|
| 939d1e6b1e | |||
| eec4a0d44b |
@@ -7,6 +7,7 @@
|
||||
struct model {
|
||||
std::vector<vec3> verts;
|
||||
std::vector<uint16_t> faces;
|
||||
std::vector<vec3> normals;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
11
parseObj.py
11
parseObj.py
@@ -21,6 +21,14 @@ for index,line in enumerate(content):
|
||||
content = content[endVerts:]
|
||||
break
|
||||
|
||||
|
||||
normals = []
|
||||
for index,line in enumerate(content):
|
||||
if "vt" in line:
|
||||
normals = content[:index]
|
||||
content = content[index:]
|
||||
break
|
||||
|
||||
startFaces = 0;
|
||||
faces = []
|
||||
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]
|
||||
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:
|
||||
f.write(out)
|
||||
|
||||
15
polygon.hpp
15
polygon.hpp
@@ -6,7 +6,7 @@ struct polygon {
|
||||
|
||||
vec3 points[3];
|
||||
decimal delta[9];
|
||||
bool skip = false;
|
||||
bool small = false;
|
||||
|
||||
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 + 2] =
|
||||
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[1] = points[0].x();
|
||||
@@ -38,17 +40,20 @@ struct polygon {
|
||||
if (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) {
|
||||
// if (skip)
|
||||
// return false;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (small)
|
||||
return true;
|
||||
vec3 d = p;
|
||||
if ((((d.x().i >> SHIFT_AMOUNT) * delta[i * 3].i +
|
||||
(d.y().i >> SHIFT_AMOUNT) * delta[i * 3 + 1].i +
|
||||
delta[i * 3 + 2].i) >>
|
||||
SHIFT_AMOUNT) > 0)
|
||||
if ((d.x() * delta[i * 3] + d.y() * delta[i * 3 + 1] +
|
||||
delta[i * 3 + 2]) > decimal(0))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user