From 4cbf10f0450b31d0d48a0410093da17db89adb3b Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Sun, 23 Nov 2025 23:05:46 +0100 Subject: [PATCH] Part: Add bakeInTransform method for TopoShape This method can be used to bake in transform directly into geometry. Normally the setTransform or setPlacement methods only store additional positional data within the shape without changing the actual geometry. So if we have some geometry placed at 0,0,0 and we want to have few copies of that shape the goemetry stays intact but additional transform is stored. This method can be used to alter the gometry and reset the transform to identity. It helps with model stability, as not every method correctly handles that additional transform metadata. --- src/Mod/Part/App/TopoShape.cpp | 24 ++++++++++++++++++++++++ src/Mod/Part/App/TopoShape.h | 1 + 2 files changed, 25 insertions(+) diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index b706dae74e..a3852749d7 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -3267,6 +3267,30 @@ void TopoShape::transformGeometry(const Base::Matrix4D& rclMat) } } +void TopoShape::bakeInTransform() +{ + if (getShape().IsNull()) { + return; + } + + if (shapeType() != TopAbs_COMPOUND) { + transformGeometry(getTransform()); + setTransform(Base::Matrix4D {}); + return; + } + + TopoShape result; + std::vector shapes; + + for (auto& subshape : getSubTopoShapes()) { + subshape.bakeInTransform(); + shapes.push_back(subshape); + } + + result.makeCompound(shapes); + *this = result; +} + TopoDS_Shape TopoShape::transformGShape(const Base::Matrix4D& rclTrf, bool copy) const { if (this->_Shape.IsNull()) { diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 3f716f4640..f5733222f2 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -668,6 +668,7 @@ public: /** @name Manipulation*/ //@{ void transformGeometry(const Base::Matrix4D& rclMat) override; + void bakeInTransform(); TopoDS_Shape transformGShape(const Base::Matrix4D&, bool copy = false) const; bool transformShape(const Base::Matrix4D&, bool copy, bool checkScale = false); TopoDS_Shape mirror(const gp_Ax2&) const;