Fix USD transformations after v0.8 migration

This commit is contained in:
Thomas Krijnen
2024-06-28 20:26:11 +02:00
parent c7232a780a
commit a0458eeb91
2 changed files with 7 additions and 22 deletions
+7 -21
View File
@@ -115,24 +115,6 @@ std::vector<pxr::UsdShadeMaterial> USDSerializer::createMaterials(const std::vec
return materials;
}
pxr::GfVec3f USDSerializer::rotation_degrees_from_matrix(const double* matrix) const {
const double epsilon = 1e-6;
double angleX, angleY, angleZ;
angleX = atan2(-matrix[5], matrix[8]);
if (std::abs(std::abs(matrix[5]) - 1.0) < epsilon) {
angleZ = 0.0;
angleY = atan2(matrix[6], matrix[0]);
} else {
angleZ = atan2(matrix[1], matrix[4]);
angleY = atan2(matrix[2], matrix[8]);
}
return pxr::GfVec3f(static_cast<float>(angleX * 180.0 / M_PI),
static_cast<float>(angleY * 180.0 / M_PI),
static_cast<float>(angleZ * 180.0 / M_PI));
}
void USDSerializer::writeHeader() {
stage_->GetRootLayer()->SetComment("File generated by IfcOpenShell " + std::string(IFCOPENSHELL_VERSION));
}
@@ -143,7 +125,7 @@ void USDSerializer::write(const IfcGeom::TriangulationElement* o) {
const auto verts = mesh.verts();
const auto faces = mesh.faces();
const auto material_ids = mesh.material_ids();
auto m = o->transformation().data()->ccomponents().data();
auto m = o->transformation().data()->ccomponents();
if (material_ids.empty() || verts.empty() || faces.empty())
return;
@@ -167,8 +149,12 @@ void USDSerializer::write(const IfcGeom::TriangulationElement* o) {
usd_mesh.CreateFaceVertexIndicesAttr().Set(usd_utils::toVtArray(faces));
usd_mesh.CreateFaceVertexCountsAttr().Set(pxr::VtArray<int>((int) faces.size() / 3, 3));
usd_mesh.AddTranslateOp().Set(pxr::GfVec3d(m[9], m[10], m[11]));
usd_mesh.AddRotateXYZOp().Set(rotation_degrees_from_matrix(m));
usd_mesh.AddTransformOp().Set(pxr::GfMatrix4d(
m.data()[0], m.data()[1], m.data()[2], m.data()[3],
m.data()[4], m.data()[5], m.data()[6], m.data()[7],
m.data()[8], m.data()[9], m.data()[10], m.data()[11],
m.data()[12], m.data()[13], m.data()[14], m.data()[15]
));
pxr::VtVec3fArray normals;
for (std::vector<double>::const_iterator it = mesh.normals().begin(); it != mesh.normals().end();)
-1
View File
@@ -71,7 +71,6 @@ private:
std::map<std::string, std::string> meshes_;
std::vector<pxr::UsdShadeMaterial> createMaterials(const std::vector<ifcopenshell::geometry::taxonomy::style::ptr>&);
pxr::GfVec3f rotation_degrees_from_matrix(const double*) const;
public:
USDSerializer(const std::string&, const ifcopenshell::geometry::Settings&, const ifcopenshell::geometry::SerializerSettings&);
virtual ~USDSerializer();