mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +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:
@@ -41,21 +41,21 @@ void WaveFrontOBJSerializer::writeHeader() {
|
||||
mtl_stream << "# File generated by IfcOpenShell " << IFCOPENSHELL_VERSION << std::endl;
|
||||
}
|
||||
|
||||
void WaveFrontOBJSerializer::writeMaterial(const IfcGeom::SurfaceStyle& style) {
|
||||
mtl_stream << "newmtl " << style.Name() << std::endl;
|
||||
if (style.Diffuse()) {
|
||||
const IfcGeom::SurfaceStyle::ColorComponent& diffuse = *style.Diffuse();
|
||||
mtl_stream << "Kd " << diffuse.R() << " " << diffuse.G() << " " << diffuse.B() << std::endl;
|
||||
void WaveFrontOBJSerializer::writeMaterial(const IfcGeomObjects::Material& style) {
|
||||
mtl_stream << "newmtl " << style.name() << std::endl;
|
||||
if (style.hasDiffuse()) {
|
||||
const double* diffuse = style.diffuse();
|
||||
mtl_stream << "Kd " << diffuse[0] << " " << diffuse[1] << " " << diffuse[2] << std::endl;
|
||||
}
|
||||
if (style.Specular()) {
|
||||
const IfcGeom::SurfaceStyle::ColorComponent& specular = *style.Specular();
|
||||
mtl_stream << "Ks " << specular.R() << " " << specular.G() << " " << specular.B() << std::endl;
|
||||
if (style.hasSpecular()) {
|
||||
const double* specular = style.specular();
|
||||
mtl_stream << "Ks " << specular[0] << " " << specular[1] << " " << specular[2] << std::endl;
|
||||
}
|
||||
if (style.Specularity()) {
|
||||
mtl_stream << "Ns " << (*style.Specularity()) << std::endl;
|
||||
if (style.hasSpecularity()) {
|
||||
mtl_stream << "Ns " << style.specularity() << std::endl;
|
||||
}
|
||||
if (style.Transparency()) {
|
||||
const double transparency = 1.0 - *style.Transparency();
|
||||
if (style.hasTransparency()) {
|
||||
const double transparency = 1.0 - style.transparency();
|
||||
if (transparency < 1) {
|
||||
mtl_stream << "Tr " << transparency << std::endl;
|
||||
mtl_stream << "d " << transparency << std::endl;
|
||||
@@ -85,22 +85,22 @@ void WaveFrontOBJSerializer::writeTesselated(const IfcGeomObjects::IfcGeomObject
|
||||
}
|
||||
|
||||
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(); ) {
|
||||
|
||||
const int material_id = *(material_it++);
|
||||
if (material_id != previous_material_id) {
|
||||
const IfcGeom::SurfaceStyle* material_style = 0;
|
||||
IfcGeomObjects::Material material(0);
|
||||
if (material_id >= 0) {
|
||||
material_style = mesh.surface_styles()[material_id];
|
||||
material = mesh.materials()[material_id];
|
||||
} 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;
|
||||
if (materials.find(material_name) == materials.end()) {
|
||||
writeMaterial(*material_style);
|
||||
writeMaterial(material);
|
||||
materials.insert(material_name);
|
||||
}
|
||||
previous_material_id = material_id;
|
||||
|
||||
Reference in New Issue
Block a user