How to get angle,coords and scale of the object by group?

心已入冬 提交于 2019-12-08 11:58:22

问题


in fabricjs,the object's left,top,angle,scaleX and scaleY is different in a group and not in a group.I can get the right attributes based on canvas when a object is not in a group.but once this object is in a group,the left or top or angle I get is based on group.

if I rotate a group,the angle of the group has changed but when I use group._objects[i].angleto get the angle of the object,the angle doesn't changed.

How to get the canvas-relative position of an object that is in a group? this question solved the left top problem,but how to get the angle and the scale by group? Thanks for reading.


回答1:


Recently fabricjs got an overhaul of group transformation management. Use latest version and try this:

//object is your desired object inside the group.
var matrix = object.calcTransformMatrix(),
    options = fabric.util.qrDecompose(matrix);
//options will be an object with following properties.
/*
  options.translateX //left position
  options.translateY //top position
  options.scaleX
  options.scaleY
  options.skewX
  options.skewY
  options.angle // angle in degrees.
*/

This code is taken from the function realizeTransform in fabric.Group class.



来源:https://stackoverflow.com/questions/34388625/how-to-get-angle-coords-and-scale-of-the-object-by-group

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!