mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 21:42:19 +00:00
try to reduce memory footprint
This commit is contained in:
@@ -197,20 +197,20 @@ void ColladaSerializer::ColladaExporter::ColladaScene::add(
|
||||
// If this is not the first parent, get the relative placement
|
||||
if (parentNodes.size() > 0)
|
||||
{
|
||||
auto m4 = ifcopenshell::geometry::taxonomy::matrix4(*matrixStack.top().data().components * *transformation.data().components);
|
||||
auto m4 = ifcopenshell::geometry::taxonomy::matrix4(matrixStack.top().data().ccomponents() * transformation.data().ccomponents());
|
||||
relative_trsf = new ifcopenshell::geometry::Transformation(transformation.settings(), m4);
|
||||
transformation_towrite = relative_trsf;
|
||||
}
|
||||
|
||||
// @todo verify
|
||||
|
||||
const double* m = transformation_towrite->data().components->data();
|
||||
const auto& m = transformation_towrite->data().ccomponents();
|
||||
|
||||
double matrix_array[4][4] = {
|
||||
{ m[0], m[4], m[8], m[12] },
|
||||
{ m[1], m[5], m[9], m[13] },
|
||||
{ m[2], m[6], m[10], m[14] },
|
||||
{ m[3], m[7], m[11], m[15] }
|
||||
{ m(0), m(4), m(8), m(12) },
|
||||
{ m(1), m(5), m(9), m(13) },
|
||||
{ m(2), m(6), m(10), m(14) },
|
||||
{ m(3), m(7), m(11), m(15) }
|
||||
};
|
||||
|
||||
/// @todo: TFK: Rather than applying this offset to all leafs (which might be undesirable) should this offset be applied to a node higher up in the hierarchy?
|
||||
@@ -251,19 +251,19 @@ void ColladaSerializer::ColladaExporter::ColladaScene::addParent(const ifcopensh
|
||||
// If this is not the first parent, get the relative placement
|
||||
if (parentNodes.size() > 0)
|
||||
{
|
||||
auto m4 = ifcopenshell::geometry::taxonomy::matrix4(*matrixStack.top().data().components * *parent_trsf.data().components);
|
||||
auto m4 = ifcopenshell::geometry::taxonomy::matrix4(matrixStack.top().data().ccomponents() * parent_trsf.data().ccomponents());
|
||||
relative_trsf = new ifcopenshell::geometry::Transformation(parent_trsf.settings(), m4);
|
||||
transformation_towrite = relative_trsf;
|
||||
}
|
||||
|
||||
// @todo verify
|
||||
|
||||
const double* parentMatrix = transformation_towrite->data().components->data();
|
||||
const auto& parentMatrix = transformation_towrite->data().ccomponents();
|
||||
|
||||
double matrix_array[4][4] = {
|
||||
{ (double)parentMatrix[0], (double)parentMatrix[3], (double)parentMatrix[6], (double)parentMatrix[9] },
|
||||
{ (double)parentMatrix[1], (double)parentMatrix[4], (double)parentMatrix[7], (double)parentMatrix[10] },
|
||||
{ (double)parentMatrix[2], (double)parentMatrix[5], (double)parentMatrix[8], (double)parentMatrix[11] },
|
||||
{ (double)parentMatrix(0), (double)parentMatrix(3), (double)parentMatrix(6), (double)parentMatrix(9) },
|
||||
{ (double)parentMatrix(1), (double)parentMatrix(4), (double)parentMatrix(7), (double)parentMatrix(10) },
|
||||
{ (double)parentMatrix(2), (double)parentMatrix(5), (double)parentMatrix(8), (double)parentMatrix(11) },
|
||||
{ 0, 0, 0, 1 }
|
||||
};
|
||||
|
||||
@@ -280,7 +280,7 @@ void ColladaSerializer::ColladaExporter::ColladaScene::addParent(const ifcopensh
|
||||
current_node->addMatrix(matrix_array);
|
||||
|
||||
// Add the node to the parent stack
|
||||
matrixStack.push(ifcopenshell::geometry::Transformation(parent_trsf.settings(), ifcopenshell::geometry::taxonomy::matrix4(parent_trsf.data().components->inverse())));
|
||||
matrixStack.push(ifcopenshell::geometry::Transformation(parent_trsf.settings(), ifcopenshell::geometry::taxonomy::matrix4(parent_trsf.data().ccomponents().inverse())));
|
||||
parentNodes.push(current_node);
|
||||
serializer->parentStackId.push(parent.id());
|
||||
}
|
||||
@@ -319,19 +319,17 @@ void ColladaSerializer::ColladaExporter::ColladaMaterials::ColladaEffects::write
|
||||
openEffect(material_uri + "-fx");
|
||||
COLLADASW::EffectProfile effect(mSW);
|
||||
effect.setShaderType(COLLADASW::EffectProfile::LAMBERT);
|
||||
if (material.diffuse) {
|
||||
const auto& diffuse = *material.diffuse.get().components;
|
||||
effect.setDiffuse(COLLADASW::ColorOrTexture(COLLADASW::Color(diffuse[0],diffuse[1],diffuse[2])));
|
||||
}
|
||||
if (material.specular) {
|
||||
const auto& specular = *material.specular.get().components;
|
||||
const auto& diffuse = material.diffuse.ccomponents();
|
||||
effect.setDiffuse(COLLADASW::ColorOrTexture(COLLADASW::Color(diffuse[0],diffuse[1],diffuse[2])));
|
||||
if (material.specular.components_) {
|
||||
const auto& specular = material.specular.ccomponents();
|
||||
effect.setSpecular(COLLADASW::ColorOrTexture(COLLADASW::Color(specular[0],specular[1],specular[2])));
|
||||
}
|
||||
if (material.specularity) {
|
||||
effect.setShininess(*material.specularity);
|
||||
if (material.has_specularity()) {
|
||||
effect.setShininess(material.specularity);
|
||||
}
|
||||
if (material.transparency) {
|
||||
const double transparency = *material.transparency;
|
||||
if (material.has_transparency()) {
|
||||
const double transparency = material.transparency;
|
||||
if (transparency > 0) {
|
||||
// The default opacity mode for Collada is A_ONE, which apparently indicates a
|
||||
// transparency value of 1 to be fully opaque. Hence transparency is inverted.
|
||||
@@ -352,10 +350,10 @@ void ColladaSerializer::ColladaExporter::ColladaMaterials::add(const ifcopenshel
|
||||
|
||||
// @todo apparently material.name is unitialized in some cases now.
|
||||
|
||||
std::string material_name = material.name.get_value_or("missing-material");
|
||||
std::string material_name = material.name;
|
||||
|
||||
if (material_name.empty()) {
|
||||
material_name = "missing-material-" + *material.name;
|
||||
material_name = "missing-material-" + material.name;
|
||||
}
|
||||
|
||||
collada_id(material_name);
|
||||
|
||||
@@ -80,7 +80,7 @@ void GltfSerializer::writeHeader() {
|
||||
|
||||
int GltfSerializer::writeMaterial(const ifcopenshell::geometry::taxonomy::style& style) {
|
||||
// @todo is it safe to always dereference this optional?
|
||||
const std::string& name = *style.name;
|
||||
const std::string& name = style.name;
|
||||
|
||||
auto it = materials_.find(name);
|
||||
if (it != materials_.end()) {
|
||||
@@ -92,18 +92,16 @@ int GltfSerializer::writeMaterial(const ifcopenshell::geometry::taxonomy::style&
|
||||
|
||||
std::array<double, 4> base;
|
||||
base.fill(1.0);
|
||||
if (style.diffuse) {
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
base[i] = (*style.diffuse->components)[i];
|
||||
}
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
base[i] = style.diffuse.ccomponents()(i);
|
||||
}
|
||||
if (style.transparency) {
|
||||
base[3] = 1. - *style.transparency;
|
||||
if (style.has_transparency()) {
|
||||
base[3] = 1. - style.transparency;
|
||||
}
|
||||
|
||||
json_["materials"].push_back({ {"pbrMetallicRoughness", {{"baseColorFactor", base}, {"metallicFactor", 0}}} });
|
||||
|
||||
if (style.transparency && *style.transparency > 1.e-9) {
|
||||
if (style.has_transparency() && style.transparency > 1.e-9) {
|
||||
json_["materials"].back()["alphaMode"] = "BLEND";
|
||||
}
|
||||
|
||||
@@ -167,14 +165,14 @@ void GltfSerializer::write(const ifcopenshell::geometry::TriangulationElement* o
|
||||
|
||||
node_array_.push_back(json_["nodes"].size());
|
||||
|
||||
const double* m = o->transformation().data().components->data();
|
||||
const auto& m = o->transformation().data().ccomponents();
|
||||
|
||||
// nb: note that this applies the Y-UP transform.
|
||||
const std::array<double, 16> matrix_flat = {
|
||||
m[ 0], m[ 2], -m[ 1], m[ 3],
|
||||
m[ 4], m[ 6], -m[ 5], m[ 7],
|
||||
m[ 8], m[10], -m[ 9], m[11],
|
||||
m[12], m[14], -m[13], m[15]
|
||||
m( 0), m( 2), -m( 1), m( 3),
|
||||
m( 4), m( 6), -m( 5), m( 7),
|
||||
m( 8), m(10), -m( 9), m(11),
|
||||
m(12), m(14), -m(13), m(15)
|
||||
};
|
||||
|
||||
static const std::array<double, 16> identity_matrix = {1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
|
||||
|
||||
@@ -490,7 +490,7 @@ void SvgSerializer::setFile(IfcParse::IfcFile* f) {
|
||||
auto item = mapping_->map(*product->get("ObjectPlacement"));
|
||||
if (item) {
|
||||
auto matrix = (ifcopenshell::geometry::taxonomy::matrix4*) item;
|
||||
const double& Z = (*matrix->components)(3, 2);
|
||||
const double& Z = matrix->ccomponents()(3, 2);
|
||||
setSectionHeight(Z + 1.);
|
||||
Logger::Warning("No building storeys encountered, used for reference:", product);
|
||||
return;
|
||||
|
||||
@@ -61,24 +61,21 @@ void WaveFrontOBJSerializer::writeHeader() {
|
||||
void WaveFrontOBJSerializer::writeMaterial(const ifcopenshell::geometry::taxonomy::style& style)
|
||||
{
|
||||
// @todo original_name
|
||||
std::string material_name = *(settings().get(SerializerSettings::USE_MATERIAL_NAMES)
|
||||
? style.name : style.name);
|
||||
std::string material_name = style.name;
|
||||
IfcUtil::sanitate_material_name(material_name);
|
||||
mtl_stream << "newmtl " << material_name << "\n";
|
||||
|
||||
if (style.diffuse) {
|
||||
auto diffuse = style.diffuse->components;
|
||||
mtl_stream << "Kd " << diffuse[0] << " " << diffuse[1] << " " << diffuse[2] << "\n";
|
||||
const auto& diffuse = style.diffuse.ccomponents();
|
||||
mtl_stream << "Kd " << diffuse(0) << " " << diffuse(1) << " " << diffuse(2) << "\n";
|
||||
if (style.specular.components_) {
|
||||
const auto& specular = style.specular.ccomponents();
|
||||
mtl_stream << "Ks " << specular(0) << " " << specular(1) << " " << specular(2) << "\n";
|
||||
}
|
||||
if (style.specular) {
|
||||
auto specular = style.specular->components;
|
||||
mtl_stream << "Ks " << specular[0] << " " << specular[1] << " " << specular[2] << "\n";
|
||||
if (style.has_specularity()) {
|
||||
mtl_stream << "Ns " << style.specularity << "\n";
|
||||
}
|
||||
if (style.specularity) {
|
||||
mtl_stream << "Ns " << *style.specularity << "\n";
|
||||
}
|
||||
if (style.transparency) {
|
||||
const double transparency = 1.0 - *style.transparency;
|
||||
if (style.has_transparency()) {
|
||||
const double transparency = 1.0 - style.transparency;
|
||||
if (transparency < 1) {
|
||||
mtl_stream << "d " << transparency << "\n";
|
||||
}
|
||||
@@ -124,8 +121,7 @@ void WaveFrontOBJSerializer::write(const ifcopenshell::geometry::TriangulationEl
|
||||
if (material_id != previous_material_id) {
|
||||
const ifcopenshell::geometry::taxonomy::style& material = mesh.materials()[material_id];
|
||||
// @todo original_name
|
||||
std::string material_name = *(settings().get(SerializerSettings::USE_MATERIAL_NAMES)
|
||||
? material.name : material.name);
|
||||
std::string material_name = material.name;
|
||||
IfcUtil::sanitate_material_name(material_name);
|
||||
obj_stream << "usemtl " << material_name << "\n";
|
||||
if (materials.find(material_name) == materials.end()) {
|
||||
@@ -169,8 +165,7 @@ void WaveFrontOBJSerializer::write(const ifcopenshell::geometry::TriangulationEl
|
||||
if (material_id != previous_material_id) {
|
||||
const ifcopenshell::geometry::taxonomy::style& material = mesh.materials()[material_id];
|
||||
// @todo original_name
|
||||
std::string material_name = *(settings().get(SerializerSettings::USE_MATERIAL_NAMES)
|
||||
? material.name : material.name);
|
||||
std::string material_name = material.name;
|
||||
IfcUtil::sanitate_material_name(material_name);
|
||||
obj_stream << "usemtl " << material_name << "\n";
|
||||
if (materials.find(material_name) == materials.end()) {
|
||||
|
||||
@@ -131,7 +131,7 @@ boost::optional<std::string> format_attribute(ifcopenshell::geometry::abstract_m
|
||||
std::stringstream stream;
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
const double trsf_value = (*matrix->components)(j, i);
|
||||
const double trsf_value = matrix->ccomponents()(j, i);
|
||||
stream << trsf_value;
|
||||
if (i < 3 && j < 3) {
|
||||
stream << " ";
|
||||
|
||||
Reference in New Issue
Block a user