shared_ptr styles all over #4833

This commit is contained in:
Thomas Krijnen
2024-06-10 20:11:24 +02:00
parent f2074d95fd
commit c01263d721
13 changed files with 97 additions and 93 deletions
+18 -18
View File
@@ -66,7 +66,7 @@ void ColladaSerializer::ColladaExporter::ColladaGeometries::write(
const std::string &mesh_id, const std::string &/**<@todo 'default_material_name' unused, remove? */,
const std::vector<double>& positions, const std::vector<double>& normals,
const std::vector<int>& faces, const std::vector<int>& edges,
const std::vector<int>& material_ids, const std::vector<ifcopenshell::geometry::taxonomy::style>& /**<@todo 'materials' unused, remove? */,
const std::vector<int>& material_ids, const std::vector<ifcopenshell::geometry::taxonomy::style::ptr>& /**<@todo 'materials' unused, remove? */,
const std::vector<double>& uvs, const std::vector<std::string>& material_references)
{
openMesh(mesh_id);
@@ -302,24 +302,24 @@ void ColladaSerializer::ColladaExporter::ColladaScene::write() {
}
void ColladaSerializer::ColladaExporter::ColladaMaterials::ColladaEffects::write(
const ifcopenshell::geometry::taxonomy::style &material, const std::string &material_uri)
const ifcopenshell::geometry::taxonomy::style::ptr &material, const std::string &material_uri)
{
openEffect(material_uri + "-fx");
COLLADASW::EffectProfile effect(mSW);
effect.setShaderType(COLLADASW::EffectProfile::LAMBERT);
if (material.diffuse) {
const auto& diffuse = material.diffuse.ccomponents();
if (material->diffuse) {
const auto& diffuse = material->diffuse.ccomponents();
effect.setDiffuse(COLLADASW::ColorOrTexture(COLLADASW::Color(diffuse(0),diffuse(1),diffuse(2))));
}
if (material.specular) {
const auto& specular = material.specular.ccomponents();
if (material->specular) {
const auto& specular = material->specular.ccomponents();
effect.setSpecular(COLLADASW::ColorOrTexture(COLLADASW::Color(specular(0),specular(1),specular(2))));
}
if (material.specularity == material.specularity) {
effect.setShininess(material.specularity);
if (material->specularity == material->specularity) {
effect.setShininess(material->specularity);
}
if (material.transparency == material.transparency) {
const double transparency = material.transparency;
if (material->transparency == material->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.
@@ -334,12 +334,12 @@ void ColladaSerializer::ColladaExporter::ColladaMaterials::ColladaEffects::close
closeLibrary();
}
void ColladaSerializer::ColladaExporter::ColladaMaterials::add(const ifcopenshell::geometry::taxonomy::style& material) {
void ColladaSerializer::ColladaExporter::ColladaMaterials::add(const ifcopenshell::geometry::taxonomy::style::ptr& material) {
if (!contains(material)) {
std::string material_name = material.name;
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);
@@ -350,19 +350,19 @@ void ColladaSerializer::ColladaExporter::ColladaMaterials::add(const ifcopenshel
}
}
std::string ColladaSerializer::ColladaExporter::ColladaMaterials::getMaterialUri(const ifcopenshell::geometry::taxonomy::style& material) {
std::vector<ifcopenshell::geometry::taxonomy::style>::iterator it = std::find(materials.begin(), materials.end(), material);
std::string ColladaSerializer::ColladaExporter::ColladaMaterials::getMaterialUri(const ifcopenshell::geometry::taxonomy::style::ptr& material) {
std::vector<ifcopenshell::geometry::taxonomy::style::ptr>::iterator it = std::find(materials.begin(), materials.end(), material);
ptrdiff_t index = std::distance(materials.begin(), it);
return material_uris.at(index);
}
bool ColladaSerializer::ColladaExporter::ColladaMaterials::contains(const ifcopenshell::geometry::taxonomy::style& material) {
bool ColladaSerializer::ColladaExporter::ColladaMaterials::contains(const ifcopenshell::geometry::taxonomy::style::ptr& material) {
return std::find(materials.begin(), materials.end(), material) != materials.end();
}
void ColladaSerializer::ColladaExporter::ColladaMaterials::write() {
effects.close();
BOOST_FOREACH(const ifcopenshell::geometry::taxonomy::style& material, materials) {
BOOST_FOREACH(const ifcopenshell::geometry::taxonomy::style::ptr& material, materials) {
std::string material_name = getMaterialUri(material);
openMaterial(material_name);
@@ -396,7 +396,7 @@ void ColladaSerializer::ColladaExporter::write(const IfcGeom::TriangulationEleme
collada_id(representation_id);
std::vector<std::string> material_references;
BOOST_FOREACH(const ifcopenshell::geometry::taxonomy::style& material, mesh.materials()) {
BOOST_FOREACH(const ifcopenshell::geometry::taxonomy::style::ptr& material, mesh.materials()) {
materials.add(material);
std::string material_name = materials.getMaterialUri(material);