diff --git a/src/serializers/USDSerializer.cpp b/src/serializers/USDSerializer.cpp index 66c7d403d3..34b60b82fc 100644 --- a/src/serializers/USDSerializer.cpp +++ b/src/serializers/USDSerializer.cpp @@ -115,24 +115,6 @@ std::vector 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(angleX * 180.0 / M_PI), - static_cast(angleY * 180.0 / M_PI), - static_cast(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) 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::const_iterator it = mesh.normals().begin(); it != mesh.normals().end();) diff --git a/src/serializers/USDSerializer.h b/src/serializers/USDSerializer.h index 2b782c7114..b14dab06a7 100644 --- a/src/serializers/USDSerializer.h +++ b/src/serializers/USDSerializer.h @@ -71,7 +71,6 @@ private: std::map meshes_; std::vector createMaterials(const std::vector&); - pxr::GfVec3f rotation_degrees_from_matrix(const double*) const; public: USDSerializer(const std::string&, const ifcopenshell::geometry::Settings&, const ifcopenshell::geometry::SerializerSettings&); virtual ~USDSerializer();