Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 组移动后解除组合图形位置不符合预期 #61

Closed
JessYan0913 opened this issue Mar 8, 2024 · 1 comment · Fixed by #62
Closed

[BUG] 组移动后解除组合图形位置不符合预期 #61

JessYan0913 opened this issue Mar 8, 2024 · 1 comment · Fixed by #62
Assignees

Comments

@JessYan0913
Copy link
Owner

Bug Report / 缺陷报告

问题描述 / Describe the bug

图形成组后移动组,再解除成组后,成组图形恢复原位。理想情况应该是原地解除组合。

复现步骤 / To Reproduce

Kapture 2024-03-08 at 21 47 32

期望行为 / Expected behavior

Kapture 2024-03-08 at 21 45 39

截图 / Screenshots

桌面设备信息 / Desktop (please complete the following information):

  • OS: MacBook
  • Browser: Chrome
  • Pictode Version: 1.0.1

移动设备信息 / Smartphone (please complete the following information):

附加上下文 / Additional context

@JessYan0913 JessYan0913 self-assigned this Mar 8, 2024
@JessYan0913
Copy link
Owner Author

JessYan0913 commented Mar 10, 2024

image

在源代码中对于将组内组件移动到父级的操作并没有对组内成员进行任何变换操作,这导致组内成员的变换矩阵依然是加入组之前的。

根据调试发现,将图形添加到组内,对组进行平移变换的时候并不会改变组内成员的变换信息。

成组前:

image

成组后:

image

根据对比发现成组后,对组的变换并不影响组内成员的变换信息。

原本我是想通过矩阵乘法将组的变换应用到组内成员,从而计算出组内成员的最新变换信息,再将计算出来的变换信息应用到组内成员。

后来发现KonvaNodegetAbsoluteTransform正是图形对于某个坐标系的真实变换,所以解除组时我们只需要通过这个函数来获取组内成员的真实变换,然后再将真实变换应用回组。

public _decomposeGroup(group: Konva.Group): KonvaNode[] {
    const parent = group.getParent() ?? this.mainLayer;
    const resolve = [...group.getChildren()].map((child) => {
      const { x, y, scaleX, scaleY, rotation } = child.getAbsoluteTransform(parent).copy().decompose();
      child.moveTo(parent);
      child.position({ x, y });
      child.scale({ x: scaleX, y: scaleY });
      child.rotation(rotation);
      return child;
    });
    this._remove(group);
    return resolve;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant