Eamonn 张
Eamonn 张

Reputation: 41

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

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.

Upvotes: 0

Views: 1952

Answers (1)

AndreaBogazzi
AndreaBogazzi

Reputation: 14731

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.

Upvotes: 4

Related Questions