132 lines
3.8 KiB
C++
132 lines
3.8 KiB
C++
/*
|
||
* © Copyright 2014 – Urheberrechtshinweis
|
||
* Alle Rechte vorbehalten / All Rights Reserved
|
||
*
|
||
* Programmcode ist urheberrechtlich geschuetzt.
|
||
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
|
||
* Keine Verwendung ohne explizite Genehmigung.
|
||
* (vgl. § 106 ff UrhG / § 97 UrhG)
|
||
*/
|
||
|
||
#include "FloorplanRendererModel.h"
|
||
|
||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||
#include <Indoor/navMesh/NavMesh.h>
|
||
#include <Indoor/navMesh/NavMeshFactory.h>
|
||
#include <Indoor/navMesh/NavMeshFactoryListener.h>
|
||
#include <Indoor/floorplan/3D/Builder.h>
|
||
|
||
#include "RenderTriangle.h"
|
||
|
||
struct Material {
|
||
int r, g, b, a;
|
||
Material(int r, int g, int b, int a) : r(r), g(g), b(b), a(a) {;}
|
||
};
|
||
|
||
const std::vector<Material> mats = {
|
||
|
||
Material(255,0,0,255), // error
|
||
|
||
Material(0,128,0,255), // ground outdoor
|
||
Material(64,64,64,255), // ground outdoor
|
||
Material(105,105,105,255), // stair
|
||
Material(220,220,220,255), // handrail
|
||
|
||
Material(200,200,255,96), // door (glass)
|
||
Material(140,140,140,255), // door (wood)
|
||
|
||
Material(135,135,135,255), // concrete
|
||
Material(240,240,255,96), // glass
|
||
Material(170,170,255,96), // glass (metallized)
|
||
Material(170,120,60,255), // wood
|
||
Material(200,200,200,255), // drywall
|
||
|
||
Material(255,255,255,255), // object
|
||
|
||
Material(235,235,235,255), // default
|
||
|
||
};
|
||
|
||
int FloorplanRendererModel::getMaterial(const Floorplan3D::Obstacle3D& o) const {
|
||
|
||
if (o.type == Floorplan3D::Obstacle3D::Type::ERROR) {return 0;}
|
||
|
||
if (o.type == Floorplan3D::Obstacle3D::Type::GROUND_OUTDOOR) {return 1;}
|
||
if (o.type == Floorplan3D::Obstacle3D::Type::GROUND_INDOOR) {return 2;}
|
||
if (o.type == Floorplan3D::Obstacle3D::Type::STAIR) {return 3;}
|
||
if (o.type == Floorplan3D::Obstacle3D::Type::HANDRAIL) {return 4;}
|
||
if (o.type == Floorplan3D::Obstacle3D::Type::OBJECT) {return 12;}
|
||
|
||
if (o.type == Floorplan3D::Obstacle3D::Type::DOOR && o.mat == Floorplan::Material::GLASS) {return 5;}
|
||
if (o.type == Floorplan3D::Obstacle3D::Type::DOOR) {return 6;}
|
||
|
||
if (o.mat == Floorplan::Material::CONCRETE) {return 7;}
|
||
if (o.mat == Floorplan::Material::GLASS) {return 8;}
|
||
if (o.mat == Floorplan::Material::METALLIZED_GLAS) {return 9;}
|
||
|
||
if (o.mat == Floorplan::Material::WOOD) {return 10;}
|
||
if (o.mat == Floorplan::Material::DRYWALL) {return 11;}
|
||
|
||
return 12;
|
||
|
||
}
|
||
|
||
|
||
FloorplanRendererModel::FloorplanRendererModel() {
|
||
;
|
||
}
|
||
|
||
Floorplan3D::FloorplanMesh& FloorplanRendererModel::getMesh() {
|
||
return mesh;
|
||
}
|
||
|
||
BBox3 FloorplanRendererModel::getBBox() const {
|
||
return bbox;
|
||
}
|
||
|
||
const RenderTriangle& FloorplanRendererModel::getTriaSolid() {
|
||
return triaSolid;
|
||
}
|
||
|
||
const RenderTriangle& FloorplanRendererModel::getTriaTransp() {
|
||
return triaTransp;
|
||
}
|
||
|
||
void FloorplanRendererModel::rebuild(Floorplan::IndoorMap* im) {
|
||
|
||
// rebuild the mesh
|
||
//Ray3D::ModelFactory fac(im);
|
||
|
||
//mesh = fac.getMesh();
|
||
|
||
|
||
triaTransp.clear();
|
||
triaSolid.clear();
|
||
|
||
// rebuild the mesh
|
||
try {
|
||
Floorplan3D::Builder fac(im);
|
||
fac.exportDoors = showDoors;
|
||
mesh = fac.getMesh();
|
||
for (const Floorplan3D::Obstacle3D& obs : mesh.elements) {
|
||
const int matID = getMaterial(obs);
|
||
const Material& mat = mats[matID];
|
||
for (const Triangle3& tria : obs.triangles) {
|
||
const Point3 n = cross(tria.p2-tria.p1, tria.p3-tria.p1).normalized();
|
||
if (mat.a != 255) {
|
||
triaTransp.addTriangle(tria.p1, tria.p2, tria.p3, n, mat.r/255.0f, mat.g/255.0f, mat.b/255.0f, mat.a/255.0f);
|
||
} else {
|
||
triaSolid.addTriangle(tria.p1, tria.p2, tria.p3, n, mat.r/255.0f, mat.g/255.0f, mat.b/255.0f, mat.a/255.0f);
|
||
}
|
||
}
|
||
}
|
||
|
||
// update bbox
|
||
bbox = mesh.getBBox();
|
||
|
||
}
|
||
catch(const std::exception& e) {
|
||
std::cout << "Can't create 3D view. Failed to get mesh from model factory with error: '" << e.what() << "'" << std::endl;
|
||
}
|
||
}
|