FloorplanMesh: Added material names to mtl file
This commit is contained in:
@@ -123,7 +123,7 @@ namespace Floorplan3D {
|
||||
// write material file
|
||||
for (size_t idx = 0; idx < mats.size(); ++idx) {
|
||||
const Material& mat = mats[idx];
|
||||
res.mtl += "newmtl mat_" + std::to_string(idx) + "\n";
|
||||
res.mtl += "newmtl mat_" + mat.name + "\n";
|
||||
res.mtl += "Ka 0.000 0.000 0.000 \n"; // ambient
|
||||
res.mtl += "Kd " + std::to_string(mat.r/255.0f) + " " + std::to_string(mat.g/255.0f) + " " + std::to_string(mat.b/255.0f) + "\n";
|
||||
res.mtl += "Ks 0.000 0.000 0.000 \n";
|
||||
@@ -166,7 +166,7 @@ namespace Floorplan3D {
|
||||
res.obj += "o elem_" + std::to_string(++nObjs) + "\n";
|
||||
|
||||
// group's material
|
||||
res.obj += "usemtl mat_" + std::to_string(getMaterial(o)) + "\n";
|
||||
res.obj += "usemtl mat_" + getMaterial(o).name + "\n";
|
||||
|
||||
// write the group's faces
|
||||
for (size_t i = 0; i < o.triangles.size(); ++i) {
|
||||
@@ -227,7 +227,7 @@ namespace Floorplan3D {
|
||||
}
|
||||
|
||||
for (const Obstacle3D& obs : elements) {
|
||||
const int matIdx = getMaterial(obs);
|
||||
const int matIdx = getMaterialIdx(obs);
|
||||
const Material& mat = mats[matIdx];
|
||||
for (const Triangle3& tria : obs.triangles) {
|
||||
const Point3 n = cross(tria.p2-tria.p1, tria.p3-tria.p1).normalized();
|
||||
@@ -253,7 +253,10 @@ namespace Floorplan3D {
|
||||
|
||||
struct Material {
|
||||
int r, g, b, a;
|
||||
std::string name;
|
||||
Material(int r, int g, int b, int a) : r(r), g(g), b(b), a(a) {;}
|
||||
|
||||
Material(int r, int g, int b, int a, const std::string& name) : r(r), g(g), b(b), a(a), name(name) {;}
|
||||
};
|
||||
|
||||
|
||||
@@ -282,29 +285,31 @@ namespace Floorplan3D {
|
||||
|
||||
std::vector<Material> mats = {
|
||||
|
||||
Material(255,0,0,255), // error
|
||||
Material(255,0,0,255 , "error"), // 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(0,128,0,255 , "ground_outdoor"), // ground outdoor
|
||||
Material(64,64,64,255 , "ground_indoor"), // ground outdoor
|
||||
Material(105,105,105,255, "stair"), // stair
|
||||
Material(220,220,220,255, "handrail"), // handrail
|
||||
|
||||
Material(200,200,255,96), // door (glass)
|
||||
Material(140,140,140,255), // door (wood)
|
||||
Material(200,200,255,96 , "door_glass"), // door (glass)
|
||||
Material(140,140,140,255, "door_wood"), // 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(135,135,135,255, "concrete"), // concrete
|
||||
Material(240,240,255,96 , "glass"), // glass
|
||||
Material(170,170,255,96 , "glass_metallized"), // glass (metallized)
|
||||
Material(170,120,60,255 , "wood"), // wood
|
||||
Material(200,200,200,255, "drywall"), // drywall
|
||||
Material(255,255,255,255, "metal"), // metal
|
||||
|
||||
Material(255,255,255,255), // object
|
||||
|
||||
Material(235,235,235,255), // default
|
||||
Material(255,255,255,255, "object"), // object
|
||||
|
||||
Material(235,235,235,255, "dafult"), // default
|
||||
|
||||
};
|
||||
|
||||
int getMaterial(const Obstacle3D& o) const {
|
||||
int getMaterialIdx(const Obstacle3D& o) const {
|
||||
|
||||
if (o.type == Floorplan3D::Obstacle3D::Type::ERROR) {return 0;}
|
||||
|
||||
@@ -323,9 +328,16 @@ namespace Floorplan3D {
|
||||
|
||||
if (o.mat == Floorplan::Material::WOOD) {return 10;}
|
||||
if (o.mat == Floorplan::Material::DRYWALL) {return 11;}
|
||||
if (o.mat == Floorplan::Material::METAL) {return 12;}
|
||||
|
||||
return 12;
|
||||
|
||||
return 13;
|
||||
|
||||
}
|
||||
|
||||
const Material& getMaterial(const Obstacle3D& o) const {
|
||||
const int idx = getMaterialIdx(o);
|
||||
return mats[idx];
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user