0

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.

Community
  • 1
  • 1
Eamonn 张
  • 41
  • 1
  • 6

1 Answers1

4

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.

AndreaBogazzi
  • 14,323
  • 3
  • 38
  • 63
  • Thanks a lot,but If I want the right result,I have to set object's originX and originY to 'center'. Here is the fiddle: https://jsfiddle.net/kzh7agh7/1/. And I don't know why the geometry's default value of originX or Y is 'left' and 'top'.but the Path or Group is 'center'?Why don't make their default values all 'center'? – Eamonn 张 Jan 12 '16 at 07:31