Proceed with merge

This commit is contained in:
Thomas Krijnen
2023-03-21 20:15:01 +01:00
parent cfb0eda067
commit c78b2893de
194 changed files with 105325 additions and 7785 deletions
+42 -44
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<IfcGeom::Material>& /**<@todo 'materials' unused, remove? */,
const std::vector<int>& material_ids, const std::vector<ifcopenshell::geometry::taxonomy::style>& /**<@todo 'materials' unused, remove? */,
const std::vector<double>& uvs, const std::vector<std::string>& material_references)
{
openMesh(mesh_id);
@@ -194,27 +194,25 @@ void ColladaSerializer::ColladaExporter::ColladaScene::add(
// The matrix attribute of an entity is basically a 4x3 representation of its ObjectPlacement.
// Note that this placement is absolute, ie it is multiplied with all parent placements.
IfcGeom::Transformation* relative_trsf = 0;
const IfcGeom::Transformation* transformation_towrite = &transformation;
auto transformation_towrite = transformation.data().ccomponents();
// If this is not the first parent, get the relative placement
if (parentNodes.size() > 0)
{
relative_trsf = new IfcGeom::Transformation(matrixStack.top().multiplied(transformation));
transformation_towrite = relative_trsf;
// @todo check order
transformation_towrite = matrixStack.top().ccomponents() * transformation_towrite;
}
const std::vector<double>& posmatrix = transformation_towrite->matrix().data();
const auto& posmatrix = transformation_towrite;
// @todo check
double matrix_array[4][4] = {
{ (double)posmatrix[0], (double)posmatrix[3], (double)posmatrix[6], (double)posmatrix[9] },
{ (double)posmatrix[1], (double)posmatrix[4], (double)posmatrix[7], (double)posmatrix[10] },
{ (double)posmatrix[2], (double)posmatrix[5], (double)posmatrix[8], (double)posmatrix[11] },
{ 0, 0, 0, 1 }
{ (double)posmatrix(0,0), (double)posmatrix(0,1), (double)posmatrix(0,2), (double)posmatrix(0,3) },
{ (double)posmatrix(1,0), (double)posmatrix(1,1), (double)posmatrix(1,2), (double)posmatrix(1,3) },
{ (double)posmatrix(2,0), (double)posmatrix(2,1), (double)posmatrix(2,2), (double)posmatrix(2,3) },
{ (double)posmatrix(3,0), (double)posmatrix(3,1), (double)posmatrix(3,2), (double)posmatrix(3,3) }
};
delete relative_trsf;
node.start();
node.addMatrix(matrix_array);
COLLADASW::InstanceGeometry instanceGeometry(mSW);
@@ -240,23 +238,21 @@ void ColladaSerializer::ColladaExporter::ColladaScene::addParent(const IfcGeom::
const IfcGeom::Transformation& parent_trsf = parent.transformation();
IfcGeom::Transformation* relative_trsf = 0;
const IfcGeom::Transformation* transformation_towrite = &parent_trsf;
auto transformation_towrite = parent_trsf.data().ccomponents();
// If this is not the first parent, get the relative placement
if (parentNodes.size() > 0)
{
relative_trsf = new IfcGeom::Transformation(matrixStack.top().multiplied(parent_trsf));
transformation_towrite = relative_trsf;
if (parentNodes.size() > 0) {
// @todo check order
transformation_towrite = matrixStack.top().ccomponents() * transformation_towrite;
}
const std::vector<double>& parentMatrix = transformation_towrite->matrix().data();
const auto& posmatrix = transformation_towrite;
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] },
{ 0, 0, 0, 1 }
{ (double)posmatrix(0,0), (double)posmatrix(1,0), (double)posmatrix(2,0), (double)posmatrix(3,0) },
{ (double)posmatrix(0,1), (double)posmatrix(1,1), (double)posmatrix(2,1), (double)posmatrix(3,1) },
{ (double)posmatrix(0,2), (double)posmatrix(1,2), (double)posmatrix(2,2), (double)posmatrix(3,2) },
{ (double)posmatrix(0,3), (double)posmatrix(1,3), (double)posmatrix(2,3), (double)posmatrix(3,3) }
};
std::string name = serializer->object_id(&parent);
@@ -272,7 +268,7 @@ void ColladaSerializer::ColladaExporter::ColladaScene::addParent(const IfcGeom::
current_node->addMatrix(matrix_array);
// Add the node to the parent stack
matrixStack.push(parent_trsf.inverted());
matrixStack.push(ifcopenshell::geometry::taxonomy::matrix4(parent_trsf.data().ccomponents().inverse()));
parentNodes.push(current_node);
serializer->parentStackId.push(parent.id());
}
@@ -306,24 +302,24 @@ void ColladaSerializer::ColladaExporter::ColladaScene::write() {
}
void ColladaSerializer::ColladaExporter::ColladaMaterials::ColladaEffects::write(
const IfcGeom::Material &material, const std::string &material_uri)
const ifcopenshell::geometry::taxonomy::style &material, const std::string &material_uri)
{
openEffect(material_uri + "-fx");
COLLADASW::EffectProfile effect(mSW);
effect.setShaderType(COLLADASW::EffectProfile::LAMBERT);
if (material.hasDiffuse()) {
const double* diffuse = material.diffuse();
effect.setDiffuse(COLLADASW::ColorOrTexture(COLLADASW::Color(diffuse[0],diffuse[1],diffuse[2])));
if (material.diffuse) {
const auto& diffuse = material.diffuse.ccomponents();
effect.setDiffuse(COLLADASW::ColorOrTexture(COLLADASW::Color(diffuse(0),diffuse(1),diffuse(2))));
}
if (material.hasSpecular()) {
const double* specular = material.specular();
effect.setSpecular(COLLADASW::ColorOrTexture(COLLADASW::Color(specular[0],specular[1],specular[2])));
if (material.specular) {
const auto& specular = material.specular.ccomponents();
effect.setSpecular(COLLADASW::ColorOrTexture(COLLADASW::Color(specular(0),specular(1),specular(2))));
}
if (material.hasSpecularity()) {
effect.setShininess(material.specularity());
if (material.specularity == material.specularity) {
effect.setShininess(material.specularity);
}
if (material.hasTransparency()) {
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.
@@ -338,13 +334,15 @@ void ColladaSerializer::ColladaExporter::ColladaMaterials::ColladaEffects::close
closeLibrary();
}
void ColladaSerializer::ColladaExporter::ColladaMaterials::add(const IfcGeom::Material& material) {
void ColladaSerializer::ColladaExporter::ColladaMaterials::add(const ifcopenshell::geometry::taxonomy::style& material) {
if (!contains(material)) {
std::string material_name = (serializer->settings().get(SerializerSettings::USE_MATERIAL_NAMES)
? material.original_name() : material.name());
// std::string material_name = (serializer->settings().get(SerializerSettings::USE_MATERIAL_NAMES)
// ? material.original_name() : material.name());
// @todo
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);
@@ -355,19 +353,19 @@ void ColladaSerializer::ColladaExporter::ColladaMaterials::add(const IfcGeom::Ma
}
}
std::string ColladaSerializer::ColladaExporter::ColladaMaterials::getMaterialUri(const IfcGeom::Material& material) {
std::vector<IfcGeom::Material>::iterator it = std::find(materials.begin(), materials.end(), material);
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);
ptrdiff_t index = std::distance(materials.begin(), it);
return material_uris.at(index);
}
bool ColladaSerializer::ColladaExporter::ColladaMaterials::contains(const IfcGeom::Material& material) {
bool ColladaSerializer::ColladaExporter::ColladaMaterials::contains(const ifcopenshell::geometry::taxonomy::style& material) {
return std::find(materials.begin(), materials.end(), material) != materials.end();
}
void ColladaSerializer::ColladaExporter::ColladaMaterials::write() {
effects.close();
BOOST_FOREACH(const IfcGeom::Material& material, materials) {
BOOST_FOREACH(const ifcopenshell::geometry::taxonomy::style& material, materials) {
std::string material_name = getMaterialUri(material);
openMaterial(material_name);
@@ -401,7 +399,7 @@ void ColladaSerializer::ColladaExporter::write(const IfcGeom::TriangulationEleme
collada_id(representation_id);
std::vector<std::string> material_references;
BOOST_FOREACH(const IfcGeom::Material& material, mesh.materials()) {
BOOST_FOREACH(const ifcopenshell::geometry::taxonomy::style& material, mesh.materials()) {
materials.add(material);
std::string material_name = materials.getMaterialUri(material);