如何获得组的角度,坐标和比例的对象? [英] How to get angle,coords and scale of the object by group?

查看:269
本文介绍了如何获得组的角度,坐标和比例的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在fabricjs中,对象的left,top,angle,scaleX和scaleY在组中是不同的,而不是在组中。当对象不在组中时,我可以基于画布获得正确的属性。是在一个组中,左边或顶部或角度是基于组。

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.

如果我旋转组,组的角度已更改,但是当我使用 group._objects [i] .angle 以获得对象的角度,角度不变。

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.

推荐答案

最近,fabricjs改革了团队转型管理。
使用最新版本并尝试:

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.
*/

此代码取自函数 realizeTransform 在fabric.Group类中。

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

这篇关于如何获得组的角度,坐标和比例的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆