worked on 3D model stuff

minor changes
This commit is contained in:
2018-02-12 16:57:08 +01:00
parent 2a923dfabc
commit 42a3a47317
3 changed files with 164 additions and 12 deletions

View File

@@ -1,8 +1,6 @@
#ifndef STATS_HISTOGRAM_H
#define STATS_HISTOGRAM_H
#define WITH_DEBUG_PLOT
#ifdef WITH_DEBUG_PLOT
#include <KLib/misc/gnuplot/Gnuplot.h>
#include <KLib/misc/gnuplot/GnuplotPlot.h>
@@ -49,7 +47,9 @@ namespace Stats {
const int idx = binIdx(x);
counts.at(idx) += 1;
++cnt;
if (cnt % 200 == 0) {showPlot();}
#ifdef WITH_DEBUG_PLOT
if (cnt % 200 == 0) {showPlot();}
#endif
}
void clear() {

View File

@@ -9,13 +9,26 @@ namespace Ray3D {
class Cube : public Mesh {
public:
private:
/** ctor */
Cube() {
unitCube(true);
//unitCube(true);
}
public:
// Cube (const Point3 p1, const Point3 p2, const Point3 p3, const Point3 p4, const float h) {
//// const Point3 ph(0,0,h);
//// addQuad(p1+ph, p2+ph, p3+ph, p4+ph); // top
//// addQuad(p4, p3, p2, p1); // bottom
//// addQuad(p3+ph, p2+ph, p2, p3); // right
//// addQuad(p1+ph, p4+ph, p4, p1); // left
//// addQuad(p2+ph, p1+ph, p1, p2); // front
//// addQuad(p4+ph, p3+ph, p3, p4); // back
// addQuad();
// }
/** ctor with position, size and rotation */
Cube(const Point3 pos, const Point3 size, const Point3 rot_deg, const bool topAndBottom = true) {
unitCube(topAndBottom);
@@ -37,6 +50,30 @@ namespace Ray3D {
return res;
}
static Cube unit() {
return Cube();
}
/** cube from 8 vertices (upper 4, lower 4) */
static Cube fromVertices(const Point3 pt1, const Point3 pt2, const Point3 pt3, const Point3 pt4, const Point3 pb1, const Point3 pb2, const Point3 pb3, const Point3 pb4) {
Cube cube;
cube.addQuad(pt1, pt2, pt3, pt4); // top
cube.addQuad(pb4, pb3, pb2, pb1); // bottom
cube.addQuad(pt3, pt2, pb2, pb3); // right
cube.addQuad(pt1, pt4, pb4, pb1); // left
cube.addQuad(pt2, pt1, pb1, pb2); // front
cube.addQuad(pt4, pt3, pb3, pb4); // back
return cube;
}
/** cube from 8 vertices (upper 4, lower 4) */
static Cube fromBottomAndHeight(const Point3 pb1, const Point3 pb2, const Point3 pb3, const Point3 pb4, const float h) {
const Point3 ph(0,0,h);
return Cube::fromVertices(pb1+ph, pb2+ph, pb3+ph, pb4+ph, pb1, pb2, pb3, pb4);
}
private:
/** build unit-cube faces */

View File

@@ -21,6 +21,7 @@ namespace Ray3D {
bool exportCeilings = true;
bool exportObstacles = true;
bool exportStairs = true;
bool fancyStairs = true;
bool exportHandrails = true;
bool exportDoors = true;
bool doorsOpen = true;
@@ -303,7 +304,7 @@ namespace Ray3D {
const float sz = door->height / 2.01f; // prevent overlaps
const Point3 size(sx, sy, sz);
Cube cube;
Cube cube = Cube::unit();
cube.transform(mat);
cube.transform(pos, size, rot);
res.triangles = cube.getTriangles();
@@ -328,7 +329,7 @@ namespace Ray3D {
// the doors
const int numDoors = 3;
Cube cube;
Cube cube = Cube::unit();
cube.transform(Matrix4::getTranslation(1,0,0));
for (int i = 0; i < numDoors; ++i) {
const int deg = 45 + (360*i / numDoors);
@@ -434,23 +435,137 @@ namespace Ray3D {
}
/** convert a line obstacle to 3D triangles */
Obstacle3D getStairs(const Floorplan::Floor* f, const Floorplan::Stair* s) {
Obstacle3D res(Obstacle3D::Type::STAIR, Floorplan::Material::CONCRETE);
std::vector<Floorplan::Quad3> quads = Floorplan::getQuads(s->getParts(), f);
for (const Floorplan::Quad3& quad : quads) {
const Triangle3 t1(quad.p1, quad.p2, quad.p3);
const Triangle3 t2(quad.p3, quad.p4, quad.p1);
res.triangles.push_back(t1);
res.triangles.push_back(t2);
if (quad.isLeveled()) {
const float h = 0.2;
const Point3 ph(0,0,h);
const Cube cube = Cube::fromBottomAndHeight(quad.p1-ph, quad.p2-ph, quad.p3-ph, quad.p4-ph, 0.2);
const std::vector<Triangle3> tmp = cube.getTriangles();
res.triangles.insert(res.triangles.end(), tmp.begin(), tmp.end());
} else {
const Point3 dir1 = quad.p3 - quad.p2;
const Point3 dir2 = quad.p4 - quad.p1;
float stepH = 0.20;
const float totalH = quad.p3.z - quad.p1.z;
const int numStairs = std::round(totalH / stepH);
stepH = totalH / numStairs;
for (int i = 0; i < numStairs; ++i) {
//const float y1 = quad.p1.z + (stepH * i);
//const float y2 = y1 + stepH;
Point3 p1b = quad.p1 + dir1 * (i+0) / numStairs; p1b.z -= stepH;
Point3 p2b = quad.p2 + dir2 * (i+0) / numStairs; p2b.z -= stepH;
const Point3 p3t = quad.p2 + dir2 * (i+1) / numStairs;
const Point3 p4t = quad.p1 + dir1 * (i+1) / numStairs;
const Point3 p1t(p1b.x, p1b.y, p4t.z);
const Point3 p2t(p2b.x, p2b.y, p3t.z);
const Point3 p3b(p3t.x, p3t.y, p2b.z+stepH);
const Point3 p4b(p4t.x, p4t.y, p1b.z+stepH);
const Cube cube = Cube::fromVertices(p1t, p2t, p3t, p4t, p1b, p2b, p3b, p4b);
const std::vector<Triangle3> tmp = cube.getTriangles();
res.triangles.insert(res.triangles.end(), tmp.begin(), tmp.end());
}
}
}
return res;
}
/** convert a line obstacle to 3D triangles */
/*
Obstacle3D getStairs(const Floorplan::Floor* f, const Floorplan::Stair* s) {
Obstacle3D res(Obstacle3D::Type::STAIR, Floorplan::Material::CONCRETE);
std::vector<Floorplan::Quad3> quads = Floorplan::getQuads(s->getParts(), f);
for (const Floorplan::Quad3& quad : quads) {
if (!fancyStairs || quad.isLeveled()) {
const Triangle3 t1(quad.p1, quad.p2, quad.p3);
const Triangle3 t2(quad.p3, quad.p4, quad.p1);
res.triangles.push_back(t1);
res.triangles.push_back(t2);
} else {
const Point3 dir1 = quad.p3 - quad.p2;
const Point3 dir2 = quad.p4 - quad.p1;
const float stepH = 0.20;
const float totalH = quad.p3.z - quad.p1.z;
const int numStairs = std::round(totalH / stepH);
for (int i = 0; i < numStairs; ++i) {
//const float y1 = quad.p1.z + (stepH * i);
//const float y2 = y1 + stepH;
const Point3 p1 = quad.p1 + dir1 * (i+0) / numStairs;
const Point3 p2 = quad.p2 + dir2 * (i+0) / numStairs;
const Point3 p3 = quad.p2 + dir2 * (i+1) / numStairs;
const Point3 p4 = quad.p1 + dir1 * (i+1) / numStairs;
//const Point3 p14(p4.x, p4.y, p1.z);
//const Point3 p23(p3.x, p3.y, p2.z);
const Point3 p14(p1.x, p1.y, p4.z);
const Point3 p23(p2.x, p2.y, p3.z);
// up
const Triangle3 t1(p1, p2, p23);
const Triangle3 t2(p23, p14, p1);
res.triangles.push_back(t1);
res.triangles.push_back(t2);
// group
const Triangle3 t3(p14, p23, p3);
const Triangle3 t4(p3, p4, p14);
res.triangles.push_back(t3);
res.triangles.push_back(t4);
// side s
const Triangle3 s1(p2, p3, p23);
const Triangle3 s2(p1, p14, p4);
res.triangles.push_back(s1);
res.triangles.push_back(s2);
// facing down
const Triangle3 d1(quad.p1, quad.p3, quad.p2);
const Triangle3 d2(quad.p3, quad.p1, quad.p4);
res.triangles.push_back(d1);
res.triangles.push_back(d2);
}
}
}
return res;
}
*/
static Obstacle3D::Type getType(const Floorplan::FloorObstacleLine* l) {
switch (l->type) {