adjusted 3D modeling for walls

refactoring
new helper classes / methods
This commit is contained in:
2018-07-22 13:47:07 +02:00
parent da06bacb6b
commit 8ea7b7f3b6
13 changed files with 693 additions and 104 deletions

View File

@@ -10,6 +10,11 @@
#include "Tube.h"
#include "Cylinder.h"
#include "FloorplanMesh.h"
#include "FloorPos.h"
#include "Walls.h"
#include "WallsViaCubes.h"
#include "WallsViaCuttedQuads.h"
#include "OBJPool.h"
@@ -23,7 +28,7 @@ namespace Ray3D {
public:
bool exportCeilings = true;
bool exportObstacles = true;
bool exportObstacles = true;
bool exportStairs = true;
bool fancyStairs = true;
bool exportHandrails = true;
@@ -39,6 +44,9 @@ namespace Ray3D {
/** the to-be-exported map */
const Floorplan::IndoorMap* map;
//Walls* walls = new WallsViaCubes();
Walls* walls = new WallsViaCuttedQuads();
public:
@@ -82,6 +90,9 @@ namespace Ray3D {
if (!f->enabled) {continue;}
// reset wall-factory
walls->clear();
// triangulize the floor itself (floor/ceiling)
if (exportCeilings) {
std::vector<Obstacle3D> tmp = getFloor(f);
@@ -96,12 +107,14 @@ namespace Ray3D {
}
}
// append all created walls
const std::vector<Obstacle3D>& oWalls = walls->get();
res.insert(res.end(),oWalls.begin(), oWalls.end());
// stairs
if (f->stairs.enabled) {
for (const Floorplan::Stair* stair : f->stairs) {
if (exportStairs) {res.push_back(getStairs(f, stair));}
}
}
@@ -265,7 +278,8 @@ namespace Ray3D {
case Floorplan::ObstacleType::WINDOW:
return getWindow(f, fol, aboveDoor);
case Floorplan::ObstacleType::WALL:
return getWall(f, fol, aboveDoor);
addWall(f, fol, aboveDoor);
return Obstacle3D();
default:
throw Exception("invalid obstacle type");
}
@@ -273,7 +287,8 @@ namespace Ray3D {
}
Obstacle3D getWindow(const Floorplan::Floor* f, const Floorplan::FloorObstacleLine* fol, const Floorplan::FloorObstacleDoor* aboveDoor) const {
return getWall(f, fol, aboveDoor);
//return getWall(f, fol, aboveDoor);
return Obstacle3D();
}
Obstacle3D getPillar(const Floorplan::Floor* f, const Floorplan::FloorObstacleCircle* foc) const {
@@ -297,39 +312,8 @@ namespace Ray3D {
}
Obstacle3D getWall(const Floorplan::Floor* f, const Floorplan::FloorObstacleLine* fol, const Floorplan::FloorObstacleDoor* aboveDoor) const {
FloorPos fpos(f);
const float thickness_m = fol->thickness_m;
const Point2 from = (!aboveDoor) ? (fol->from) : (aboveDoor->from);
const Point2 to = (!aboveDoor) ? (fol->to) : (aboveDoor->to);
const Point2 cen2 = (from+to)/2;
const float rad = std::atan2(to.y - from.y, to.x - from.x);
const float deg = rad * 180 / M_PI;
// cube's destination center
const float _height = (fol->height_m > 0) ? (fol->height_m) : (fpos.height); // use either floor's height or user height
const double height = (!aboveDoor) ? (_height) : (fpos.height - aboveDoor->height);
const double cenZ = (!aboveDoor) ? (fpos.z1 + height/2) : (fpos.z1 + aboveDoor->height + height/2);// (fpos.z2 - (fpos.height - aboveDoor->height) / 2);
const Point3 pos(cen2.x, cen2.y, cenZ);
// div by 2.01 to prevent overlapps and z-fighting
const float sx = from.getDistance(to) / 2;
const float sy = thickness_m / 2;
const float sz = height / 2.01f; // prevent overlaps
const Point3 size(sx, sy, sz);
const Point3 rot(0,0,deg);
// build
Cube cube(pos, size, rot, cubeParts);
// done
Obstacle3D res(getType(fol), fol->material);
res.triangles = cube.getTriangles();
return res;
void addWall(const Floorplan::Floor* f, const Floorplan::FloorObstacleLine* fol, const Floorplan::FloorObstacleDoor* aboveDoor) const {
walls->add(f, fol, aboveDoor);
}
/** 3D Obstacle from .obj 3D mesh */
@@ -351,26 +335,6 @@ namespace Ray3D {
obs = obs.translated(foo->pos + Point3(0,0,fpos.z1));
obs.type = Obstacle3D::Type::OBJECT;
// std::vector<Triangle3> trias;
// for (const OBJReader::Face& face : reader.getData().faces) {
// Point3 p1 = face.vnt[0].vertex;
// Point3 p2 = face.vnt[1].vertex;
// Point3 p3 = face.vnt[2].vertex;
// p1 = p1.rot(foo->rot.x/180.0f*M_PI, foo->rot.y/180.0f*M_PI, foo->rot.z/180.0f*M_PI);
// p2 = p2.rot(foo->rot.x/180.0f*M_PI, foo->rot.y/180.0f*M_PI, foo->rot.z/180.0f*M_PI);
// p3 = p3.rot(foo->rot.x/180.0f*M_PI, foo->rot.y/180.0f*M_PI, foo->rot.z/180.0f*M_PI);
// p1 += foo->pos; p1.z += fpos.z1;
// p2 += foo->pos; p2.z += fpos.z1;
// p3 += foo->pos; p3.z += fpos.z1;
// const Triangle3 tria(p1, p2, p3);
// trias.push_back(tria);
// }
// // done
// Obstacle3D res(Obstacle3D::Type::OBJECT, Floorplan::Material::WOOD);
// res.triangles = trias;
// return res;
return obs;
}
@@ -672,30 +636,6 @@ namespace Ray3D {
}
*/
static Obstacle3D::Type getType(const Floorplan::FloorObstacleLine* l) {
switch (l->type) {
case Floorplan::ObstacleType::WALL: return Obstacle3D::Type::WALL;
case Floorplan::ObstacleType::WINDOW: return Obstacle3D::Type::WINDOW;
case Floorplan::ObstacleType::HANDRAIL: return Obstacle3D::Type::HANDRAIL;
default: return Obstacle3D::Type::UNKNOWN;
}
}
static Obstacle3D::Type getType(const Floorplan::FloorObstacleCircle* c) {
(void) c;
return Obstacle3D::Type::WALL;
}
/** used to model ceiling thickness */
struct FloorPos {
float fh;
float z1;
float z2;
float height;
FloorPos(const Floorplan::Floor* f) : fh(0.01), z1(f->getStartingZ()), z2(f->getEndingZ()-fh), height(z2-z1) {;}
};
};
}