added support for .obj objects within the floorplan

include objects within navmesh calculation
include objects within 3d mesh generation
minor changes/fixes
This commit is contained in:
2018-02-17 17:20:43 +01:00
parent 42a3a47317
commit 8358f45674
15 changed files with 770 additions and 114 deletions

View File

@@ -1,9 +1,14 @@
#ifndef NAV_MESH_FACTORY_H
#define NAV_MESH_FACTORY_H
#include <vector>
#include "../floorplan/v2/Floorplan.h"
#include "../floorplan/v2/FloorplanHelper.h"
#include "../geo/ConvexHull2.h"
#include "../wifi/estimate/ray3/OBJPool.h"
#include "NavMesh.h"
#include "NavMeshTriangle.h"
#include "NavMeshFactoryListener.h"
@@ -240,10 +245,19 @@ namespace NM {
// get all obstacles of this floor and remove them from the polygon as well (many will be outside of the added polygon)
for (Floorplan::FloorObstacle* obs : floor->obstacles) {
// line-obstacles
Floorplan::FloorObstacleLine* line = dynamic_cast<Floorplan::FloorObstacleLine*>(obs);
if (line != nullptr) {
nmPoly.remove(getPolygon(line));
}
// object-obstacles
Floorplan::FloorObstacleObject* obj = dynamic_cast<Floorplan::FloorObstacleObject*>(obs);
if (obj != nullptr) {
nmPoly.remove(getPolygon(obj));
}
}
// construct and add
@@ -721,6 +735,23 @@ namespace NM {
return res;
}
/** convert the given 3D object to a polygon outline */
Floorplan::Polygon2 getPolygon(const Floorplan::FloorObstacleObject* obj) const {
Floorplan::Polygon2 res;
std::vector<Point2> src;
Ray3D::Obstacle3D obs = Ray3D::OBJPool::get().getObject(obj->file).rotated_deg(obj->rot).translated(obj->pos);
for (const Triangle3& tria : obs.triangles) {
src.push_back(tria.p1.xy());
src.push_back(tria.p2.xy());
src.push_back(tria.p3.xy());
}
res.points = ConvexHull2::get(src);
return res;
}
/** as line-obstacles have a thickness, we need 4 lines for the intersection test! */
Floorplan::Polygon2 getPolygon(const Floorplan::FloorObstacleDoor* door) const {
const float thickness_m = std::max(0.3f, settings.maxQuality_m); // wall's thickness (make thin walls big enough to be detected)

View File

@@ -241,8 +241,8 @@ namespace NM {
getUV(p, u, v);
const Point3 res = getPoint(u,v);
Assert::isNear(res.x, p.x, 1.0f, "TODO: high difference while mapping from 2D to 3D");
Assert::isNear(res.y, p.y, 1.0f, "TODO: high difference while mapping from 2D to 3D");
Assert::isNear<float>(res.x, p.x, 1.0f, "TODO: high difference while mapping from 2D to 3D");
Assert::isNear<float>(res.y, p.y, 1.0f, "TODO: high difference while mapping from 2D to 3D");
//return res;
return Point3(p.x, p.y, res.z); // only use the new z, keep input as-is