我无法在 paperjs 中将转换矩阵从一层复制到另一层

  • 本文关键字:一层 复制 paperjs 转换 paperjs
  • 更新时间 :
  • 英文 :


我需要在paperjs中复制比例并将属性从一个项目转换为另一个项目。

我试过使用

itemA.copyAttributes(itemB, false)

但这似乎没有任何作用?

我也试过

itemA.transform(itemB.matrix)

这又行不通。我可以使用以下行复制翻译

itemA.position.x = itemB.position.x
itemA.position.x = itemB.position.x

但是我不知道如何复制比例,任何想法

能够将转换从一个项目复制到另一个项目的一个技巧是将 item.applyMatrix 设置为 false
这将具有将项目平移、缩放和旋转存储到属性中的效果,而不是将它们应用于其几何图形。
然后,您将能够将它们应用于另一个项目。

这是演示解决方案的草图。

// Create an orange filled square.
var squareA = new Path.Rectangle({
    from: view.center - 200,
    to: view.center - 100,
    fillColor: 'orange',
    // Notice that matrix is not applied, this will allow us to copy scaling and rotation later.
    applyMatrix: false
});
// Create a blue stroked square by cloning the orange one.
squareB = squareA.clone();
squareB.strokeColor = 'blue';
squareB.fillColor = null;
// Transform the orange square.
squareA.translate(100, 100);
squareA.scale(2);
squareA.rotate(80);
// Replicate transformations to blue stroked square by copying individual values.
squareB.position = squareA.position;
squareB.scaling = squareA.scaling;
squareB.rotation = squareA.rotation;

最新更新