How force Fabric.js polygon to update his points correctly after modify #10428
-
I’m using the latest version of Fabric.js, and I have a problem with a polygon. As we know, in Fabric.js, the points field of a polygon doesn’t update after modification (it always contains the initial points). I want to recalculate the polygon's points after modification to get the current position of each point. To achieve this, I use the trick with calcTransformMatrix (the points are calculated correctly), and then I assign the new points to the existing polygon. The problem occurs when I try to scale or rotate a polygon with updated points—this leads to crashes and bugs, and I don’t know why. Here is demo code: After dragging, when we try to scale or rotate, we can see weird behavior. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @TheSinOfGreed! I just battled with a similar issue with Polygons and their points. Here's what worked for me. I utilized controlsUtils to generate polygon point controls, then, instead of polygon.setBoundingBox(true), add the option "exactBoundingBox: true" to your initial Polygon options.
I have a polygon that changes between default controls (using controlsUtils.createObjectDefaultControls()) and polyControls with a mousedblclick listener on the Polygon. When using defaultControls, I set exactBoundingBox to false, then set it back to true when I switch back over to poly controls. |
Beta Was this translation helpful? Give feedback.
Hi @TheSinOfGreed!
I just battled with a similar issue with Polygons and their points. Here's what worked for me.
I utilized controlsUtils to generate polygon point controls, then, instead of polygon.setBoundingBox(true), add the option "exactBoundingBox: true" to your initial Polygon options.
I have a polygon that changes between default controls (using controlsUtils.createObjectDefaultControls()) and polyContro…