mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 10:57:49 +00:00
Proceed with merge
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "WavefrontObjSerializer.h"
|
||||
|
||||
#include "../ifcgeom_schema_agnostic/IfcGeomRenderStyles.h"
|
||||
#include "../ifcgeom/IfcGeomRenderStyles.h"
|
||||
|
||||
#include "../ifcparse/utils.h"
|
||||
|
||||
@@ -59,26 +59,28 @@ void WaveFrontOBJSerializer::writeHeader() {
|
||||
mtl_stream.stream << "# File generated by IfcOpenShell " << IFCOPENSHELL_VERSION << "\n";
|
||||
}
|
||||
|
||||
void WaveFrontOBJSerializer::writeMaterial(const IfcGeom::Material& style)
|
||||
void WaveFrontOBJSerializer::writeMaterial(const ifcopenshell::geometry::taxonomy::style& style)
|
||||
{
|
||||
std::string material_name = (settings().get(SerializerSettings::USE_MATERIAL_NAMES)
|
||||
? style.original_name() : style.name());
|
||||
// std::string material_name = (settings().get(SerializerSettings::USE_MATERIAL_NAMES)
|
||||
// ? style.original_name() : style.name());
|
||||
// @todo original_name
|
||||
std::string material_name = style.name;
|
||||
IfcUtil::sanitate_material_name(material_name);
|
||||
mtl_stream.stream << "newmtl " << material_name << "\n";
|
||||
|
||||
if (style.hasDiffuse()) {
|
||||
const double* diffuse = style.diffuse();
|
||||
mtl_stream.stream << "Kd " << diffuse[0] << " " << diffuse[1] << " " << diffuse[2] << "\n";
|
||||
{
|
||||
auto& diffuse = style.diffuse.ccomponents();
|
||||
mtl_stream.stream << "Kd " << diffuse(0) << " " << diffuse(1) << " " << diffuse(2) << "\n";
|
||||
}
|
||||
if (style.hasSpecular()) {
|
||||
const double* specular = style.specular();
|
||||
mtl_stream.stream << "Ks " << specular[0] << " " << specular[1] << " " << specular[2] << "\n";
|
||||
if (style.specular) {
|
||||
auto& specular = style.specular.ccomponents();
|
||||
mtl_stream.stream << "Ks " << specular(0) << " " << specular(1) << " " << specular(2) << "\n";
|
||||
}
|
||||
if (style.hasSpecularity()) {
|
||||
mtl_stream.stream << "Ns " << style.specularity() << "\n";
|
||||
if (style.specularity == style.specularity) {
|
||||
mtl_stream.stream << "Ns " << style.specularity << "\n";
|
||||
}
|
||||
if (style.hasTransparency()) {
|
||||
const double transparency = 1.0 - style.transparency();
|
||||
if (style.transparency == style.transparency) {
|
||||
const double transparency = 1.0 - style.transparency;
|
||||
if (transparency < 1) {
|
||||
mtl_stream.stream << "d " << transparency << "\n";
|
||||
}
|
||||
@@ -94,7 +96,7 @@ void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement* o)
|
||||
const IfcGeom::Representation::Triangulation& mesh = o->geometry();
|
||||
|
||||
const int vcount = (int)mesh.verts().size() / 3;
|
||||
for ( std::vector<double>::const_iterator it = mesh.verts().begin(); it != mesh.verts().end(); ) {
|
||||
for (auto it = mesh.verts().begin(); it != mesh.verts().end();) {
|
||||
const double x = *(it++);
|
||||
const double y = *(it++);
|
||||
const double z = *(it++);
|
||||
@@ -106,14 +108,14 @@ void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement* o)
|
||||
}
|
||||
}
|
||||
|
||||
for ( std::vector<double>::const_iterator it = mesh.normals().begin(); it != mesh.normals().end(); ) {
|
||||
for (auto it = mesh.normals().begin(); it != mesh.normals().end();) {
|
||||
const double x = *(it++);
|
||||
const double y = *(it++);
|
||||
const double z = *(it++);
|
||||
obj_stream.stream << "vn " << x << " " << y << " " << z << "\n";
|
||||
}
|
||||
|
||||
for (std::vector<double>::const_iterator it = mesh.uvs().begin(); it != mesh.uvs().end();) {
|
||||
for (auto it = mesh.uvs().begin(); it != mesh.uvs().end();) {
|
||||
const double u = *it++;
|
||||
const double v = *it++;
|
||||
obj_stream.stream << "vt " << u << " " << v << "\n";
|
||||
@@ -128,9 +130,11 @@ void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement* o)
|
||||
|
||||
const int material_id = *(material_it++);
|
||||
if (material_id != previous_material_id) {
|
||||
const IfcGeom::Material& material = mesh.materials()[material_id];
|
||||
std::string material_name = (settings().get(SerializerSettings::USE_MATERIAL_NAMES)
|
||||
? material.original_name() : material.name());
|
||||
const ifcopenshell::geometry::taxonomy::style& material = mesh.materials()[material_id];
|
||||
// std::string material_name = (settings().get(SerializerSettings::USE_MATERIAL_NAMES)
|
||||
// ? material.original_name() : material.name());
|
||||
// @todo original_name
|
||||
std::string material_name = material.name;
|
||||
IfcUtil::sanitate_material_name(material_name);
|
||||
obj_stream.stream << "usemtl " << material_name << "\n";
|
||||
if (materials.find(material_name) == materials.end()) {
|
||||
@@ -172,9 +176,11 @@ void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement* o)
|
||||
const int material_id = *(material_it++);
|
||||
|
||||
if (material_id != previous_material_id) {
|
||||
const IfcGeom::Material& material = mesh.materials()[material_id];
|
||||
std::string material_name = (settings().get(SerializerSettings::USE_MATERIAL_NAMES)
|
||||
? material.original_name() : material.name());
|
||||
const ifcopenshell::geometry::taxonomy::style& material = mesh.materials()[material_id];
|
||||
// std::string material_name = (settings().get(SerializerSettings::USE_MATERIAL_NAMES)
|
||||
// ? material.original_name() : material.name());
|
||||
// @todo original_name
|
||||
std::string material_name = material.name;
|
||||
IfcUtil::sanitate_material_name(material_name);
|
||||
obj_stream.stream << "usemtl " << material_name << "\n";
|
||||
if (materials.find(material_name) == materials.end()) {
|
||||
|
||||
Reference in New Issue
Block a user