mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-11 22:31:55 +00:00
Add an adapter for IfcGeom::SurfaceStyle so that IfcGeomObjects (and most notably the Python wrapper) need not to be aware of boost::optional
Expose shading and rendering styles to the Python wrapper as well
This commit is contained in:
@@ -49,7 +49,7 @@ void ColladaSerializer::ColladaExporter::ColladaGeometries::addFloatSource(const
|
|||||||
source.finish();
|
source.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColladaSerializer::ColladaExporter::ColladaGeometries::write(const std::string mesh_id, const std::string& default_material_name, const std::vector<float>& positions, const std::vector<float>& normals, const std::vector<int>& indices, const std::vector<int> material_ids, const std::vector<const IfcGeom::SurfaceStyle*>& materials) {
|
void ColladaSerializer::ColladaExporter::ColladaGeometries::write(const std::string mesh_id, const std::string& default_material_name, const std::vector<float>& positions, const std::vector<float>& normals, const std::vector<int>& indices, const std::vector<int> material_ids, const std::vector<IfcGeomObjects::Material>& materials) {
|
||||||
openMesh(mesh_id);
|
openMesh(mesh_id);
|
||||||
|
|
||||||
// The normals vector can be empty for example when the WELD_VERTICES setting is used.
|
// The normals vector can be empty for example when the WELD_VERTICES setting is used.
|
||||||
@@ -78,7 +78,7 @@ void ColladaSerializer::ColladaExporter::ColladaGeometries::write(const std::str
|
|||||||
COLLADASW::Triangles triangles(mSW);
|
COLLADASW::Triangles triangles(mSW);
|
||||||
triangles.setMaterial(collada_id(previous_material_id == -1
|
triangles.setMaterial(collada_id(previous_material_id == -1
|
||||||
? default_material_name
|
? default_material_name
|
||||||
: materials[previous_material_id]->Name()));
|
: materials[previous_material_id].name()));
|
||||||
triangles.setCount(num_triangles);
|
triangles.setCount(num_triangles);
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
triangles.getInputList().push_back(COLLADASW::Input(COLLADASW::InputSemantic::VERTEX,"#" + mesh_id + COLLADASW::LibraryGeometries::VERTICES_ID_SUFFIX, offset++ ) );
|
triangles.getInputList().push_back(COLLADASW::Input(COLLADASW::InputSemantic::VERTEX,"#" + mesh_id + COLLADASW::LibraryGeometries::VERTICES_ID_SUFFIX, offset++ ) );
|
||||||
@@ -153,23 +153,23 @@ void ColladaSerializer::ColladaExporter::ColladaScene::write() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColladaSerializer::ColladaExporter::ColladaMaterials::ColladaEffects::write(const IfcGeom::SurfaceStyle* style) {
|
void ColladaSerializer::ColladaExporter::ColladaMaterials::ColladaEffects::write(const IfcGeomObjects::Material& material) {
|
||||||
openEffect(collada_id(style->Name()) + "-fx");
|
openEffect(collada_id(material.name()) + "-fx");
|
||||||
COLLADASW::EffectProfile effect(mSW);
|
COLLADASW::EffectProfile effect(mSW);
|
||||||
effect.setShaderType(COLLADASW::EffectProfile::LAMBERT);
|
effect.setShaderType(COLLADASW::EffectProfile::LAMBERT);
|
||||||
if (style->Diffuse()) {
|
if (material.hasDiffuse()) {
|
||||||
const IfcGeom::SurfaceStyle::ColorComponent& diffuse = *style->Diffuse();
|
const double* diffuse = material.diffuse();
|
||||||
effect.setDiffuse(COLLADASW::ColorOrTexture(COLLADASW::Color(diffuse.R(),diffuse.G(),diffuse.B())));
|
effect.setDiffuse(COLLADASW::ColorOrTexture(COLLADASW::Color(diffuse[0],diffuse[1],diffuse[2])));
|
||||||
}
|
}
|
||||||
if (style->Specular()) {
|
if (material.hasSpecular()) {
|
||||||
const IfcGeom::SurfaceStyle::ColorComponent& specular = *style->Specular();
|
const double* specular = material.specular();
|
||||||
effect.setSpecular(COLLADASW::ColorOrTexture(COLLADASW::Color(specular.R(),specular.G(),specular.B())));
|
effect.setSpecular(COLLADASW::ColorOrTexture(COLLADASW::Color(specular[0],specular[1],specular[2])));
|
||||||
}
|
}
|
||||||
if (style->Specularity()) {
|
if (material.hasSpecularity()) {
|
||||||
effect.setShininess(*style->Specularity());
|
effect.setShininess(material.specularity());
|
||||||
}
|
}
|
||||||
if (style->Transparency()) {
|
if (material.hasTransparency()) {
|
||||||
const double transparency = *style->Transparency();
|
const double transparency = material.transparency();
|
||||||
if (transparency > 0) {
|
if (transparency > 0) {
|
||||||
effect.setTransparency(transparency);
|
effect.setTransparency(transparency);
|
||||||
}
|
}
|
||||||
@@ -182,21 +182,21 @@ void ColladaSerializer::ColladaExporter::ColladaMaterials::ColladaEffects::close
|
|||||||
closeLibrary();
|
closeLibrary();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColladaSerializer::ColladaExporter::ColladaMaterials::add(const IfcGeom::SurfaceStyle* style) {
|
void ColladaSerializer::ColladaExporter::ColladaMaterials::add(const IfcGeomObjects::Material& material) {
|
||||||
if (!contains(style)) {
|
if (!contains(material)) {
|
||||||
effects.write(style);
|
effects.write(material);
|
||||||
surface_styles.push_back(style);
|
materials.push_back(material);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ColladaSerializer::ColladaExporter::ColladaMaterials::contains(const IfcGeom::SurfaceStyle* style) {
|
bool ColladaSerializer::ColladaExporter::ColladaMaterials::contains(const IfcGeomObjects::Material& material) {
|
||||||
return std::find(surface_styles.begin(), surface_styles.end(), style) != surface_styles.end();
|
return std::find(materials.begin(), materials.end(), material) != materials.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColladaSerializer::ColladaExporter::ColladaMaterials::write() {
|
void ColladaSerializer::ColladaExporter::ColladaMaterials::write() {
|
||||||
effects.close();
|
effects.close();
|
||||||
for (auto it = surface_styles.begin(); it != surface_styles.end(); ++it) {
|
for (auto it = materials.begin(); it != materials.end(); ++it) {
|
||||||
const std::string& material_name = collada_id((*it)->Name());
|
const std::string& material_name = collada_id((*it).name());
|
||||||
openMaterial(material_name);
|
openMaterial(material_name);
|
||||||
addInstanceEffect("#" + material_name + "-fx");
|
addInstanceEffect("#" + material_name + "-fx");
|
||||||
closeLibrary();
|
closeLibrary();
|
||||||
@@ -214,22 +214,22 @@ void ColladaSerializer::ColladaExporter::startDocument() {
|
|||||||
asset.add();
|
asset.add();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColladaSerializer::ColladaExporter::writeTesselated(const std::string& guid, const std::string& name, const std::string& type, int obj_id, const std::vector<float>& matrix, const std::vector<float>& vertices, const std::vector<float>& normals, const std::vector<int>& indices, const std::vector<int>& material_ids, const std::vector<const IfcGeom::SurfaceStyle*>& _materials) {
|
void ColladaSerializer::ColladaExporter::writeTesselated(const std::string& guid, const std::string& name, const std::string& type, int obj_id, const std::vector<float>& matrix, const std::vector<float>& vertices, const std::vector<float>& normals, const std::vector<int>& indices, const std::vector<int>& material_ids, const std::vector<IfcGeomObjects::Material>& _materials) {
|
||||||
const IfcGeom::SurfaceStyle* default_for_type = IfcGeom::get_default_style(type);
|
const IfcGeomObjects::Material default_for_type = IfcGeomObjects::Material(IfcGeom::get_default_style(type));
|
||||||
std::vector<std::string> material_references;
|
std::vector<std::string> material_references;
|
||||||
const bool needs_default = std::find(material_ids.begin(), material_ids.end(), -1) != material_ids.end();
|
const bool needs_default = std::find(material_ids.begin(), material_ids.end(), -1) != material_ids.end();
|
||||||
if (needs_default) {
|
if (needs_default) {
|
||||||
if (!materials.contains(default_for_type)) {
|
if (!materials.contains(default_for_type)) {
|
||||||
materials.add(default_for_type);
|
materials.add(default_for_type);
|
||||||
}
|
}
|
||||||
material_references.push_back(collada_id(default_for_type->Name()));
|
material_references.push_back(collada_id(default_for_type.name()));
|
||||||
}
|
}
|
||||||
for (std::vector<const IfcGeom::SurfaceStyle*>::const_iterator it = _materials.begin(); it != _materials.end(); ++it) {
|
for (std::vector<IfcGeomObjects::Material>::const_iterator it = _materials.begin(); it != _materials.end(); ++it) {
|
||||||
const IfcGeom::SurfaceStyle* const surface_style_pointer = *it;
|
const IfcGeomObjects::Material& material = *it;
|
||||||
if (!materials.contains(surface_style_pointer)) {
|
if (!materials.contains(material)) {
|
||||||
materials.add(surface_style_pointer);
|
materials.add(material);
|
||||||
}
|
}
|
||||||
material_references.push_back(collada_id(surface_style_pointer->Name()));
|
material_references.push_back(collada_id(material.name()));
|
||||||
}
|
}
|
||||||
deferreds.push_back(DeferredObject(guid, name, type, obj_id, matrix, vertices, normals, indices, material_ids, _materials, material_references));
|
deferreds.push_back(DeferredObject(guid, name, type, obj_id, matrix, vertices, normals, indices, material_ids, _materials, material_references));
|
||||||
}
|
}
|
||||||
@@ -271,7 +271,7 @@ void ColladaSerializer::writeHeader() {
|
|||||||
|
|
||||||
void ColladaSerializer::writeTesselated(const IfcGeomObjects::IfcGeomObject* o) {
|
void ColladaSerializer::writeTesselated(const IfcGeomObjects::IfcGeomObject* o) {
|
||||||
const IfcGeomObjects::IfcRepresentationTriangulation& mesh = o->mesh();
|
const IfcGeomObjects::IfcRepresentationTriangulation& mesh = o->mesh();
|
||||||
exporter.writeTesselated(o->guid(), o->name(), o->type(), o->id(), o->matrix(), mesh.verts(), mesh.normals(), mesh.faces(), mesh.materials(), mesh.surface_styles());
|
exporter.writeTesselated(o->guid(), o->name(), o->type(), o->id(), o->matrix(), mesh.verts(), mesh.normals(), mesh.faces(), mesh.material_ids(), mesh.materials());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColladaSerializer::finalize() {
|
void ColladaSerializer::finalize() {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ private:
|
|||||||
: COLLADASW::LibraryGeometries(&stream)
|
: COLLADASW::LibraryGeometries(&stream)
|
||||||
{}
|
{}
|
||||||
void addFloatSource(const std::string& mesh_id, const std::string& suffix, const std::vector<float>& floats, const char* coords = "XYZ");
|
void addFloatSource(const std::string& mesh_id, const std::string& suffix, const std::vector<float>& floats, const char* coords = "XYZ");
|
||||||
void write(const std::string mesh_id, const std::string& default_material_name, const std::vector<float>& positions, const std::vector<float>& normals, const std::vector<int>& indices, const std::vector<int> material_ids, const std::vector<const IfcGeom::SurfaceStyle*>& materials);
|
void write(const std::string mesh_id, const std::string& default_material_name, const std::vector<float>& positions, const std::vector<float>& normals, const std::vector<int>& indices, const std::vector<int> material_ids, const std::vector<IfcGeomObjects::Material>& materials);
|
||||||
void close();
|
void close();
|
||||||
};
|
};
|
||||||
class ColladaScene : public COLLADASW::LibraryVisualScenes
|
class ColladaScene : public COLLADASW::LibraryVisualScenes
|
||||||
@@ -76,18 +76,18 @@ private:
|
|||||||
explicit ColladaEffects(COLLADASW::StreamWriter& stream)
|
explicit ColladaEffects(COLLADASW::StreamWriter& stream)
|
||||||
: COLLADASW::LibraryEffects(&stream)
|
: COLLADASW::LibraryEffects(&stream)
|
||||||
{}
|
{}
|
||||||
void write(const IfcGeom::SurfaceStyle* style);
|
void write(const IfcGeomObjects::Material& material);
|
||||||
void close();
|
void close();
|
||||||
};
|
};
|
||||||
std::vector<const IfcGeom::SurfaceStyle*> surface_styles;
|
std::vector<IfcGeomObjects::Material> materials;
|
||||||
ColladaEffects effects;
|
ColladaEffects effects;
|
||||||
public:
|
public:
|
||||||
explicit ColladaMaterials(COLLADASW::StreamWriter& stream)
|
explicit ColladaMaterials(COLLADASW::StreamWriter& stream)
|
||||||
: COLLADASW::LibraryMaterials(&stream)
|
: COLLADASW::LibraryMaterials(&stream)
|
||||||
, effects(stream)
|
, effects(stream)
|
||||||
{}
|
{}
|
||||||
void add(const IfcGeom::SurfaceStyle* style);
|
void add(const IfcGeomObjects::Material& material);
|
||||||
bool contains(const IfcGeom::SurfaceStyle* style);
|
bool contains(const IfcGeomObjects::Material& material);
|
||||||
void write();
|
void write();
|
||||||
};
|
};
|
||||||
class DeferredObject {
|
class DeferredObject {
|
||||||
@@ -99,11 +99,11 @@ private:
|
|||||||
const std::vector<float> normals;
|
const std::vector<float> normals;
|
||||||
const std::vector<int> indices;
|
const std::vector<int> indices;
|
||||||
const std::vector<int> material_ids;
|
const std::vector<int> material_ids;
|
||||||
const std::vector<const IfcGeom::SurfaceStyle*> materials;
|
const std::vector<IfcGeomObjects::Material> materials;
|
||||||
const std::vector<std::string> material_references;
|
const std::vector<std::string> material_references;
|
||||||
DeferredObject(const std::string& guid, const std::string& name, const std::string& type, int obj_id, const std::vector<float>& matrix, const std::vector<float>& vertices,
|
DeferredObject(const std::string& guid, const std::string& name, const std::string& type, int obj_id, const std::vector<float>& matrix, const std::vector<float>& vertices,
|
||||||
const std::vector<float>& normals, const std::vector<int>& indices, const std::vector<int>& material_ids,
|
const std::vector<float>& normals, const std::vector<int>& indices, const std::vector<int>& material_ids,
|
||||||
const std::vector<const IfcGeom::SurfaceStyle*>& materials, const std::vector<std::string>& material_references)
|
const std::vector<IfcGeomObjects::Material>& materials, const std::vector<std::string>& material_references)
|
||||||
: guid(guid)
|
: guid(guid)
|
||||||
, name(name)
|
, name(name)
|
||||||
, type(type)
|
, type(type)
|
||||||
@@ -134,7 +134,7 @@ private:
|
|||||||
std::vector<DeferredObject> deferreds;
|
std::vector<DeferredObject> deferreds;
|
||||||
virtual ~ColladaExporter() {}
|
virtual ~ColladaExporter() {}
|
||||||
void startDocument();
|
void startDocument();
|
||||||
void writeTesselated(const std::string& guid, const std::string& name, const std::string& type, int obj_id, const std::vector<float>& matrix, const std::vector<float>& vertices, const std::vector<float>& normals, const std::vector<int>& indices, const std::vector<int>& material_ids, const std::vector<const IfcGeom::SurfaceStyle*>& materials);
|
void writeTesselated(const std::string& guid, const std::string& name, const std::string& type, int obj_id, const std::vector<float>& matrix, const std::vector<float>& vertices, const std::vector<float>& normals, const std::vector<int>& indices, const std::vector<int>& material_ids, const std::vector<IfcGeomObjects::Material>& materials);
|
||||||
void endDocument();
|
void endDocument();
|
||||||
};
|
};
|
||||||
ColladaExporter exporter;
|
ColladaExporter exporter;
|
||||||
|
|||||||
@@ -41,21 +41,21 @@ void WaveFrontOBJSerializer::writeHeader() {
|
|||||||
mtl_stream << "# File generated by IfcOpenShell " << IFCOPENSHELL_VERSION << std::endl;
|
mtl_stream << "# File generated by IfcOpenShell " << IFCOPENSHELL_VERSION << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaveFrontOBJSerializer::writeMaterial(const IfcGeom::SurfaceStyle& style) {
|
void WaveFrontOBJSerializer::writeMaterial(const IfcGeomObjects::Material& style) {
|
||||||
mtl_stream << "newmtl " << style.Name() << std::endl;
|
mtl_stream << "newmtl " << style.name() << std::endl;
|
||||||
if (style.Diffuse()) {
|
if (style.hasDiffuse()) {
|
||||||
const IfcGeom::SurfaceStyle::ColorComponent& diffuse = *style.Diffuse();
|
const double* diffuse = style.diffuse();
|
||||||
mtl_stream << "Kd " << diffuse.R() << " " << diffuse.G() << " " << diffuse.B() << std::endl;
|
mtl_stream << "Kd " << diffuse[0] << " " << diffuse[1] << " " << diffuse[2] << std::endl;
|
||||||
}
|
}
|
||||||
if (style.Specular()) {
|
if (style.hasSpecular()) {
|
||||||
const IfcGeom::SurfaceStyle::ColorComponent& specular = *style.Specular();
|
const double* specular = style.specular();
|
||||||
mtl_stream << "Ks " << specular.R() << " " << specular.G() << " " << specular.B() << std::endl;
|
mtl_stream << "Ks " << specular[0] << " " << specular[1] << " " << specular[2] << std::endl;
|
||||||
}
|
}
|
||||||
if (style.Specularity()) {
|
if (style.hasSpecularity()) {
|
||||||
mtl_stream << "Ns " << (*style.Specularity()) << std::endl;
|
mtl_stream << "Ns " << style.specularity() << std::endl;
|
||||||
}
|
}
|
||||||
if (style.Transparency()) {
|
if (style.hasTransparency()) {
|
||||||
const double transparency = 1.0 - *style.Transparency();
|
const double transparency = 1.0 - style.transparency();
|
||||||
if (transparency < 1) {
|
if (transparency < 1) {
|
||||||
mtl_stream << "Tr " << transparency << std::endl;
|
mtl_stream << "Tr " << transparency << std::endl;
|
||||||
mtl_stream << "d " << transparency << std::endl;
|
mtl_stream << "d " << transparency << std::endl;
|
||||||
@@ -85,22 +85,22 @@ void WaveFrontOBJSerializer::writeTesselated(const IfcGeomObjects::IfcGeomObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
int previous_material_id = -2;
|
int previous_material_id = -2;
|
||||||
std::vector<int>::const_iterator material_it = mesh.materials().begin();
|
std::vector<int>::const_iterator material_it = mesh.material_ids().begin();
|
||||||
|
|
||||||
for ( std::vector<int>::const_iterator it = mesh.faces().begin(); it != mesh.faces().end(); ) {
|
for ( std::vector<int>::const_iterator it = mesh.faces().begin(); it != mesh.faces().end(); ) {
|
||||||
|
|
||||||
const int material_id = *(material_it++);
|
const int material_id = *(material_it++);
|
||||||
if (material_id != previous_material_id) {
|
if (material_id != previous_material_id) {
|
||||||
const IfcGeom::SurfaceStyle* material_style = 0;
|
IfcGeomObjects::Material material(0);
|
||||||
if (material_id >= 0) {
|
if (material_id >= 0) {
|
||||||
material_style = mesh.surface_styles()[material_id];
|
material = mesh.materials()[material_id];
|
||||||
} else {
|
} else {
|
||||||
material_style = IfcGeom::get_default_style(o->type());
|
material = IfcGeomObjects::Material(IfcGeom::get_default_style(o->type()));
|
||||||
}
|
}
|
||||||
const std::string material_name = material_style->Name();
|
const std::string material_name = material.name();
|
||||||
obj_stream << "usemtl " << material_name << std::endl;
|
obj_stream << "usemtl " << material_name << std::endl;
|
||||||
if (materials.find(material_name) == materials.end()) {
|
if (materials.find(material_name) == materials.end()) {
|
||||||
writeMaterial(*material_style);
|
writeMaterial(material);
|
||||||
materials.insert(material_name);
|
materials.insert(material_name);
|
||||||
}
|
}
|
||||||
previous_material_id = material_id;
|
previous_material_id = material_id;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public:
|
|||||||
virtual ~WaveFrontOBJSerializer() {}
|
virtual ~WaveFrontOBJSerializer() {}
|
||||||
bool ready();
|
bool ready();
|
||||||
void writeHeader();
|
void writeHeader();
|
||||||
void writeMaterial(const IfcGeom::SurfaceStyle& style);
|
void writeMaterial(const IfcGeomObjects::Material& style);
|
||||||
void writeTesselated(const IfcGeomObjects::IfcGeomObject* o);
|
void writeTesselated(const IfcGeomObjects::IfcGeomObject* o);
|
||||||
void writeShapeModel(const IfcGeomObjects::IfcGeomShapeModelObject* o) {}
|
void writeShapeModel(const IfcGeomObjects::IfcGeomShapeModelObject* o) {}
|
||||||
void finalize() {}
|
void finalize() {}
|
||||||
|
|||||||
@@ -46,12 +46,12 @@
|
|||||||
#include "../ifcgeom/IfcGeom.h"
|
#include "../ifcgeom/IfcGeom.h"
|
||||||
|
|
||||||
// Welds vertices that belong to different faces
|
// Welds vertices that belong to different faces
|
||||||
bool weld_vertices = true;
|
static bool weld_vertices = true;
|
||||||
|
|
||||||
bool convert_back_units = false;
|
static bool convert_back_units = false;
|
||||||
bool use_faster_booleans = false;
|
static bool use_faster_booleans = false;
|
||||||
bool disable_subtractions = false;
|
static bool disable_subtractions = false;
|
||||||
bool disable_triangulation = false;
|
static bool disable_triangulation = false;
|
||||||
|
|
||||||
int IfcGeomObjects::IfcRepresentationTriangulation::addvert(int material_index, const gp_XYZ& p) {
|
int IfcGeomObjects::IfcRepresentationTriangulation::addvert(int material_index, const gp_XYZ& p) {
|
||||||
const float X = convert_back_units ? (float) (p.X() / IfcGeom::GetValue(IfcGeom::GV_LENGTH_UNIT)) : (float)p.X();
|
const float X = convert_back_units ? (float) (p.X() / IfcGeom::GetValue(IfcGeom::GV_LENGTH_UNIT)) : (float)p.X();
|
||||||
@@ -71,8 +71,8 @@ int IfcGeomObjects::IfcRepresentationTriangulation::addvert(int material_index,
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool use_world_coords = false;
|
static bool use_world_coords = false;
|
||||||
bool use_brep_data = false;
|
static bool use_brep_data = false;
|
||||||
|
|
||||||
static IfcParse::IfcFile* ifc_file = 0;
|
static IfcParse::IfcFile* ifc_file = 0;
|
||||||
|
|
||||||
@@ -111,12 +111,13 @@ IfcGeomObjects::IfcRepresentationTriangulation::IfcRepresentationTriangulation(c
|
|||||||
|
|
||||||
int surface_style_id = -1;
|
int surface_style_id = -1;
|
||||||
if (it->hasStyle()) {
|
if (it->hasStyle()) {
|
||||||
std::vector<const IfcGeom::SurfaceStyle*>::const_iterator jt = std::find(_surface_styles.begin(), _surface_styles.end(), &it->Style());
|
Material adapter(&it->Style());
|
||||||
if (jt == _surface_styles.end()) {
|
std::vector<Material>::const_iterator jt = std::find(_materials.begin(), _materials.end(), adapter);
|
||||||
surface_style_id = _surface_styles.size();
|
if (jt == _materials.end()) {
|
||||||
_surface_styles.push_back(&it->Style());
|
surface_style_id = _materials.size();
|
||||||
|
_materials.push_back(adapter);
|
||||||
} else {
|
} else {
|
||||||
surface_style_id = jt - _surface_styles.begin();
|
surface_style_id = jt - _materials.begin();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +201,7 @@ IfcGeomObjects::IfcRepresentationTriangulation::IfcRepresentationTriangulation(c
|
|||||||
_faces.push_back(dict[n2]);
|
_faces.push_back(dict[n2]);
|
||||||
_faces.push_back(dict[n3]);
|
_faces.push_back(dict[n3]);
|
||||||
|
|
||||||
_materials.push_back(surface_style_id);
|
_material_ids.push_back(surface_style_id);
|
||||||
|
|
||||||
addedge(n1,n2,edgecount,edges_temp);
|
addedge(n1,n2,edgecount,edges_temp);
|
||||||
addedge(n2,n3,edgecount,edges_temp);
|
addedge(n2,n3,edgecount,edges_temp);
|
||||||
@@ -258,20 +259,20 @@ IfcGeomObjects::IfcGeomObject::IfcGeomObject(
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
// A container and iterator for IfcShapeRepresentations
|
// A container and iterator for IfcShapeRepresentations
|
||||||
Ifc2x3::IfcShapeRepresentation::list shapereps;
|
static Ifc2x3::IfcShapeRepresentation::list shapereps;
|
||||||
Ifc2x3::IfcShapeRepresentation::it shaperep_iterator;
|
static Ifc2x3::IfcShapeRepresentation::it shaperep_iterator;
|
||||||
|
|
||||||
// The object is fetched beforehand to be positive an entity actually exists
|
// The object is fetched beforehand to be positive an entity actually exists
|
||||||
IfcGeomObjects::IfcGeomObject* current_geom_obj = 0;
|
static IfcGeomObjects::IfcGeomObject* current_geom_obj = 0;
|
||||||
IfcGeomObjects::IfcGeomShapeModelObject* current_shape_model_obj = 0;
|
static IfcGeomObjects::IfcGeomShapeModelObject* current_shape_model_obj = 0;
|
||||||
IfcGeomObjects::IfcGeomBrepDataObject* current_brep_data_obj = 0;
|
static IfcGeomObjects::IfcGeomBrepDataObject* current_brep_data_obj = 0;
|
||||||
|
|
||||||
// A container and iterator for IfcBuildingElements for the current IfcShapeRepresentation referenced by *shaperep_iterator
|
// A container and iterator for IfcBuildingElements for the current IfcShapeRepresentation referenced by *shaperep_iterator
|
||||||
Ifc2x3::IfcProduct::list entities;
|
static Ifc2x3::IfcProduct::list entities;
|
||||||
Ifc2x3::IfcProduct::it ifcproduct_iterator;
|
static Ifc2x3::IfcProduct::it ifcproduct_iterator;
|
||||||
|
|
||||||
int done;
|
static int done;
|
||||||
int total;
|
static int total;
|
||||||
|
|
||||||
// Move the the next IfcShapeRepresentation
|
// Move the the next IfcShapeRepresentation
|
||||||
void _nextShape() {
|
void _nextShape() {
|
||||||
@@ -501,7 +502,7 @@ bool IfcGeomObjects::Next() {
|
|||||||
return try_and_create_representations_for_current_entity();
|
return try_and_create_representations_for_current_entity();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<IfcGeomObjects::IfcObject*> returned_objects;
|
static std::vector<IfcGeomObjects::IfcObject*> returned_objects;
|
||||||
bool IfcGeomObjects::CleanUp() {
|
bool IfcGeomObjects::CleanUp() {
|
||||||
// TODO: Correctly implement destructor for IfcFile
|
// TODO: Correctly implement destructor for IfcFile
|
||||||
delete ifc_file;
|
delete ifc_file;
|
||||||
@@ -537,12 +538,18 @@ const IfcGeomObjects::IfcObject* IfcGeomObjects::GetObject(int id) {
|
|||||||
return ifc_object;
|
return ifc_object;
|
||||||
}
|
}
|
||||||
const IfcGeomObjects::IfcGeomObject* IfcGeomObjects::Get() {
|
const IfcGeomObjects::IfcGeomObject* IfcGeomObjects::Get() {
|
||||||
|
if (disable_triangulation) {
|
||||||
|
throw std::runtime_error("No triangulation available");
|
||||||
|
}
|
||||||
return current_geom_obj;
|
return current_geom_obj;
|
||||||
}
|
}
|
||||||
const IfcGeomObjects::IfcGeomShapeModelObject* IfcGeomObjects::GetShapeModel() {
|
const IfcGeomObjects::IfcGeomShapeModelObject* IfcGeomObjects::GetShapeModel() {
|
||||||
return current_shape_model_obj;
|
return current_shape_model_obj;
|
||||||
}
|
}
|
||||||
const IfcGeomObjects::IfcGeomBrepDataObject* IfcGeomObjects::GetBrepData() {
|
const IfcGeomObjects::IfcGeomBrepDataObject* IfcGeomObjects::GetBrepData() {
|
||||||
|
if (!use_brep_data) {
|
||||||
|
throw std::runtime_error("No BRep data available");
|
||||||
|
}
|
||||||
return current_brep_data_obj;
|
return current_brep_data_obj;
|
||||||
}
|
}
|
||||||
double UnitPrefixToValue( Ifc2x3::IfcSIPrefix::IfcSIPrefix v ) {
|
double UnitPrefixToValue( Ifc2x3::IfcSIPrefix::IfcSIPrefix v ) {
|
||||||
@@ -676,6 +683,7 @@ void IfcGeomObjects::Settings(int setting, bool value) {
|
|||||||
break;
|
break;
|
||||||
case USE_BREP_DATA:
|
case USE_BREP_DATA:
|
||||||
use_brep_data = value;
|
use_brep_data = value;
|
||||||
|
disable_triangulation = value;
|
||||||
break;
|
break;
|
||||||
case FASTER_BOOLEANS:
|
case FASTER_BOOLEANS:
|
||||||
use_faster_booleans = value;
|
use_faster_booleans = value;
|
||||||
@@ -706,6 +714,20 @@ IfcParse::IfcFile* IfcGeomObjects::GetFile() {
|
|||||||
return ifc_file;
|
return ifc_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static double black[3] = {0,0,0};
|
||||||
|
|
||||||
|
IfcGeomObjects::Material::Material(const IfcGeom::SurfaceStyle* style) : style(style) {}
|
||||||
|
bool IfcGeomObjects::Material::hasDiffuse() const { return style->Diffuse(); }
|
||||||
|
bool IfcGeomObjects::Material::hasSpecular() const { return style->Specular(); }
|
||||||
|
bool IfcGeomObjects::Material::hasTransparency() const { return style->Transparency(); }
|
||||||
|
bool IfcGeomObjects::Material::hasSpecularity() const { return style->Specularity(); }
|
||||||
|
const double* IfcGeomObjects::Material::diffuse() const { if (hasDiffuse()) return &((*style->Diffuse()).R()); else return black; }
|
||||||
|
const double* IfcGeomObjects::Material::specular() const { if (hasSpecular()) return &((*style->Specular()).R()); else return black; }
|
||||||
|
double IfcGeomObjects::Material::transparency() const { if (hasTransparency()) return *style->Transparency(); else return 0; }
|
||||||
|
double IfcGeomObjects::Material::specularity() const { if (hasSpecularity()) return *style->Specularity(); else return 0; }
|
||||||
|
const std::string IfcGeomObjects::Material::name() const { return style->Name(); }
|
||||||
|
bool IfcGeomObjects::Material::operator==(const IfcGeomObjects::Material& other) const { return style == other.style; }
|
||||||
|
|
||||||
int IfcGeomObjects::IfcRepresentationBrepData::id() const { return _id; }
|
int IfcGeomObjects::IfcRepresentationBrepData::id() const { return _id; }
|
||||||
const std::string& IfcGeomObjects::IfcRepresentationBrepData::brep_data() const { return _brep_data; }
|
const std::string& IfcGeomObjects::IfcRepresentationBrepData::brep_data() const { return _brep_data; }
|
||||||
|
|
||||||
@@ -714,8 +736,8 @@ const std::vector<float>& IfcGeomObjects::IfcRepresentationTriangulation::verts(
|
|||||||
const std::vector<int>& IfcGeomObjects::IfcRepresentationTriangulation::faces() const { return _faces; }
|
const std::vector<int>& IfcGeomObjects::IfcRepresentationTriangulation::faces() const { return _faces; }
|
||||||
const std::vector<int>& IfcGeomObjects::IfcRepresentationTriangulation::edges() const { return _edges; }
|
const std::vector<int>& IfcGeomObjects::IfcRepresentationTriangulation::edges() const { return _edges; }
|
||||||
const std::vector<float>& IfcGeomObjects::IfcRepresentationTriangulation::normals() const { return _normals; }
|
const std::vector<float>& IfcGeomObjects::IfcRepresentationTriangulation::normals() const { return _normals; }
|
||||||
const std::vector<int>& IfcGeomObjects::IfcRepresentationTriangulation::materials() const { return _materials; }
|
const std::vector<int>& IfcGeomObjects::IfcRepresentationTriangulation::material_ids() const { return _material_ids; }
|
||||||
const std::vector<const IfcGeom::SurfaceStyle*>& IfcGeomObjects::IfcRepresentationTriangulation::surface_styles() const { return _surface_styles; }
|
const std::vector<IfcGeomObjects::Material>& IfcGeomObjects::IfcRepresentationTriangulation::materials() const { return _materials; }
|
||||||
|
|
||||||
int IfcGeomObjects::IfcObject::id() const { return _id; }
|
int IfcGeomObjects::IfcObject::id() const { return _id; }
|
||||||
int IfcGeomObjects::IfcObject::parent_id() const { return _parent_id; }
|
int IfcGeomObjects::IfcObject::parent_id() const { return _parent_id; }
|
||||||
@@ -727,3 +749,4 @@ const std::vector<float>& IfcGeomObjects::IfcObject::matrix() const { return _ma
|
|||||||
const IfcGeomObjects::IfcRepresentationShapeModel& IfcGeomObjects::IfcGeomShapeModelObject::mesh() const { return *_mesh; }
|
const IfcGeomObjects::IfcRepresentationShapeModel& IfcGeomObjects::IfcGeomShapeModelObject::mesh() const { return *_mesh; }
|
||||||
const IfcGeomObjects::IfcRepresentationTriangulation& IfcGeomObjects::IfcGeomObject::mesh() const { return *_mesh; }
|
const IfcGeomObjects::IfcRepresentationTriangulation& IfcGeomObjects::IfcGeomObject::mesh() const { return *_mesh; }
|
||||||
const IfcGeomObjects::IfcRepresentationBrepData& IfcGeomObjects::IfcGeomBrepDataObject::mesh() const { return *_mesh; }
|
const IfcGeomObjects::IfcRepresentationBrepData& IfcGeomObjects::IfcGeomBrepDataObject::mesh() const { return *_mesh; }
|
||||||
|
|
||||||
|
|||||||
@@ -113,6 +113,25 @@ namespace IfcGeomObjects {
|
|||||||
typedef std::map<VertKey,int> VertKeyMap;
|
typedef std::map<VertKey,int> VertKeyMap;
|
||||||
typedef std::pair<int,int> Edge;
|
typedef std::pair<int,int> Edge;
|
||||||
|
|
||||||
|
class Material {
|
||||||
|
private:
|
||||||
|
const IfcGeom::SurfaceStyle* style;
|
||||||
|
public:
|
||||||
|
explicit Material(const IfcGeom::SurfaceStyle* style);
|
||||||
|
// Material(const Material& other);
|
||||||
|
// Material& operator=(const Material& other);
|
||||||
|
bool hasDiffuse() const;
|
||||||
|
bool hasSpecular() const;
|
||||||
|
bool hasTransparency() const;
|
||||||
|
bool hasSpecularity() const;
|
||||||
|
const double* diffuse() const;
|
||||||
|
const double* specular() const;
|
||||||
|
double transparency() const;
|
||||||
|
double specularity() const;
|
||||||
|
const std::string name() const;
|
||||||
|
bool operator==(const Material& other) const;
|
||||||
|
};
|
||||||
|
|
||||||
class IfcRepresentationShapeModel {
|
class IfcRepresentationShapeModel {
|
||||||
private:
|
private:
|
||||||
unsigned int id;
|
unsigned int id;
|
||||||
@@ -152,8 +171,8 @@ namespace IfcGeomObjects {
|
|||||||
std::vector<int> _faces;
|
std::vector<int> _faces;
|
||||||
std::vector<int> _edges;
|
std::vector<int> _edges;
|
||||||
std::vector<float> _normals;
|
std::vector<float> _normals;
|
||||||
std::vector<int> _materials;
|
std::vector<int> _material_ids;
|
||||||
std::vector<const IfcGeom::SurfaceStyle*> _surface_styles;
|
std::vector<Material> _materials;
|
||||||
VertKeyMap welds;
|
VertKeyMap welds;
|
||||||
public:
|
public:
|
||||||
int id() const;
|
int id() const;
|
||||||
@@ -161,8 +180,8 @@ namespace IfcGeomObjects {
|
|||||||
const std::vector<int>& faces() const;
|
const std::vector<int>& faces() const;
|
||||||
const std::vector<int>& edges() const;
|
const std::vector<int>& edges() const;
|
||||||
const std::vector<float>& normals() const;
|
const std::vector<float>& normals() const;
|
||||||
const std::vector<int>& materials() const;
|
const std::vector<int>& material_ids() const;
|
||||||
const std::vector<const IfcGeom::SurfaceStyle*>& surface_styles() const;
|
const std::vector<Material>& materials() const;
|
||||||
IfcRepresentationTriangulation(const IfcRepresentationShapeModel& s);
|
IfcRepresentationTriangulation(const IfcRepresentationShapeModel& s);
|
||||||
virtual ~IfcRepresentationTriangulation() {}
|
virtual ~IfcRepresentationTriangulation() {}
|
||||||
private:
|
private:
|
||||||
|
|||||||
+37
-1
@@ -19,12 +19,30 @@
|
|||||||
|
|
||||||
%include "std_vector.i"
|
%include "std_vector.i"
|
||||||
%include "std_string.i"
|
%include "std_string.i"
|
||||||
|
%include "exception.i"
|
||||||
|
|
||||||
|
%typemap(out) const double* {
|
||||||
|
// This is only used for RGB colours, hence the size of 3
|
||||||
|
$result = PyTuple_New(3);
|
||||||
|
for (int i = 0; i < 3; ++i) {
|
||||||
|
PyTuple_SetItem($result, i, PyFloat_FromDouble($1[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%exception {
|
||||||
|
try {
|
||||||
|
$action
|
||||||
|
} catch(std::runtime_error& e) {
|
||||||
|
SWIG_exception(SWIG_RuntimeError, e.what());
|
||||||
|
} catch(...) {
|
||||||
|
SWIG_exception(SWIG_RuntimeError, "An unknown error occurred");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
%include "Interface.h"
|
%include "Interface.h"
|
||||||
|
|
||||||
%module IfcImport %{
|
%module IfcImport %{
|
||||||
#include "Interface.h"
|
#include "Interface.h"
|
||||||
using namespace IfcGeom;
|
|
||||||
using namespace IfcGeomObjects;
|
using namespace IfcGeomObjects;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
@@ -37,6 +55,7 @@
|
|||||||
faces = property(faces)
|
faces = property(faces)
|
||||||
edges = property(edges)
|
edges = property(edges)
|
||||||
normals = property(normals)
|
normals = property(normals)
|
||||||
|
material_ids = property(material_ids)
|
||||||
materials = property(materials)
|
materials = property(materials)
|
||||||
def __repr__(self): return "RepresentationTriangulation #%d"%self.id
|
def __repr__(self): return "RepresentationTriangulation #%d"%self.id
|
||||||
%}
|
%}
|
||||||
@@ -84,7 +103,24 @@
|
|||||||
%}
|
%}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
%extend IfcGeomObjects::Material {
|
||||||
|
%pythoncode %{
|
||||||
|
if _newclass:
|
||||||
|
# Hide the getters with read-only property implementations
|
||||||
|
has_diffuse = property(hasDiffuse)
|
||||||
|
has_specular = property(hasSpecular)
|
||||||
|
has_transparency = property(hasTransparency)
|
||||||
|
has_specularity = property(hasSpecularity)
|
||||||
|
diffuse = property(diffuse)
|
||||||
|
specular = property(specular)
|
||||||
|
transparency = property(transparency)
|
||||||
|
specularity = property(specularity)
|
||||||
|
def __repr__(self): return "Material"
|
||||||
|
%}
|
||||||
|
};
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
%template(IntVector) vector<int>;
|
%template(IntVector) vector<int>;
|
||||||
%template(FloatVector) vector<float>;
|
%template(FloatVector) vector<float>;
|
||||||
|
%template(MaterialVector) vector<IfcGeomObjects::Material>;
|
||||||
};
|
};
|
||||||
+19
-8
@@ -17,11 +17,6 @@
|
|||||||
* *
|
* *
|
||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
namespace IfcGeom {
|
|
||||||
class SurfaceStyle {
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace IfcGeomObjects {
|
namespace IfcGeomObjects {
|
||||||
|
|
||||||
const int WELD_VERTICES = 1;
|
const int WELD_VERTICES = 1;
|
||||||
@@ -33,6 +28,21 @@ namespace IfcGeomObjects {
|
|||||||
const int FORCE_CCW_FACE_ORIENTATION = 7;
|
const int FORCE_CCW_FACE_ORIENTATION = 7;
|
||||||
const int DISABLE_OPENING_SUBTRACTIONS = 8;
|
const int DISABLE_OPENING_SUBTRACTIONS = 8;
|
||||||
|
|
||||||
|
class Material {
|
||||||
|
private:
|
||||||
|
void* style;
|
||||||
|
public:
|
||||||
|
bool hasDiffuse() const;
|
||||||
|
bool hasSpecular() const;
|
||||||
|
bool hasTransparency() const;
|
||||||
|
bool hasSpecularity() const;
|
||||||
|
const double* diffuse() const;
|
||||||
|
const double* specular() const;
|
||||||
|
double transparency() const;
|
||||||
|
double specularity() const;
|
||||||
|
const std::string name() const;
|
||||||
|
};
|
||||||
|
|
||||||
class IfcRepresentationTriangulation {
|
class IfcRepresentationTriangulation {
|
||||||
private:
|
private:
|
||||||
int _id;
|
int _id;
|
||||||
@@ -40,8 +50,8 @@ namespace IfcGeomObjects {
|
|||||||
std::vector<int> _faces;
|
std::vector<int> _faces;
|
||||||
std::vector<int> _edges;
|
std::vector<int> _edges;
|
||||||
std::vector<float> _normals;
|
std::vector<float> _normals;
|
||||||
std::vector<int> _materials;
|
std::vector<int> _material_ids;
|
||||||
std::vector<const IfcGeom::SurfaceStyle*> _surface_styles;
|
std::vector<Material> _materials;
|
||||||
|
|
||||||
IfcRepresentationTriangulation();
|
IfcRepresentationTriangulation();
|
||||||
IfcRepresentationTriangulation(const IfcRepresentationTriangulation&);
|
IfcRepresentationTriangulation(const IfcRepresentationTriangulation&);
|
||||||
@@ -53,7 +63,8 @@ namespace IfcGeomObjects {
|
|||||||
const std::vector<int>& faces() const;
|
const std::vector<int>& faces() const;
|
||||||
const std::vector<int>& edges() const;
|
const std::vector<int>& edges() const;
|
||||||
const std::vector<float>& normals() const;
|
const std::vector<float>& normals() const;
|
||||||
const std::vector<int>& materials() const;
|
const std::vector<int>& material_ids() const;
|
||||||
|
const std::vector<Material>& materials() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class IfcRepresentationBrepData {
|
class IfcRepresentationBrepData {
|
||||||
|
|||||||
Reference in New Issue
Block a user