Yes, for items of the PathItem class such as Path and CompoundPath it is true that transformations are baked in rather than stored separately in a matrix.
This is how things were done in Scriptographer, mainly due to limitations defined by Illustrator. To use a separate matrix object at the moment, you can wrap your items in a Symbol and then place it in the project using Symbol#place(), resulting in a PlacedSymbol that has its own matrix (similar to instances of MovieClips in flash).
I am considering lifting this limitation and also giving a matrix to PathItem, with an added method for 'baking' the transformation into the item's segment list, and resetting it to the identity matrix.
This would make things much easier for such cases and one would not have to use Symbols all the time.
Jürg
But once every object will have its own transformation matrix, things can become messy in different ways, e.g. when nesting in groups and layers, hit-testing, etc. So before adding this we're thinking long and hard about how to do it in a way that will not lead to unforeseen complexities.
I completely agree about the limitations of using symbols for this.
Jürg
var lastScale = 1;
function onFrame(event) {
var scale = (Math.sin(event.time * 2) + 1) / 2;
raster.scale(scale / lastScale);
lastScale = scale;
}
In this example, we're remembering the scale in a local variable - but you could also save it as a property on the item.
But, I agree that it would be nicer to have a scale property that you could just change on the item..
Cheers,
Stewart
We are indeed planning on offering nested matrices / transformations the way you describe it for all items.
But this is quite a big change from the current architecture with lots of implications, so it's something we have to plan and think through carefully. Drawing is one part, and probably the easier, the other is handling segment points and bounding boxes, hit testing, etc. For example a Path nested inside a Group and a Layer, both with matrices applied. In what coordinate space do you write and read the coordinates of its segment points? The easier approach would be in local ones. But then there needs to be a set of functions on each item that allows conversion from local to global coordinates, and back, adding complexity. In some ways we quite like how currently it's all provided in global coordinates and any matrix is immediately applied to all nested items and paths. From a programmer's point of view, especially from someone who is about to learn to code, this is much simpler. Except for the issues outlined in the original email below. So we need to consider this change well, since the implications are huge. It's not a matter of not understanding the involved techniques, it's a hesitation regarding such a fundamental architectural change.
Another approach could be to allow the nesting of matrices but to make segment points seem global while internally they are stored in local coordinates. This would mean it would all look and fell the same as now, but it would allow the overriding of any previously set matrix. We already have read-only properties on Matrix for rotation and scaling, these could easily become writable. e.g.
path.matrix.rotation = 45; // Reset the path's rotation regardless of the previous state of its transformation matrix.
There could be a shortcut on Path too:
path.rotation = 45;
Lots to think about…
Jürg
-mike.
----------------------------------------------------------------
michal migurski- mi...@stamen.com
415.558.1610
I'm curious to hear how you expect the coordinates of a path to behave if for example it is transformed by multiple nested matrices. Would you expect segment manipulation to happen in local coordinates? What about hit-testing or editing points / handles them with the mouse?
The hard part is not implementing nested matrices but getting all these details right. At the moment it's all nicely straight forward, which is a big plus too.
Jürg
Just a heads up to let you know that Paper.js now supports affine transformations on all objects other than Path, and these can be nested, just like we're used to from other platforms, e.g. Flash.
Paper.js now also supports item level mouse events.
We will write more about this once the new release is up.
Jürg
On 12 Aug 2011, at 17:58, Michal Migurski wrote: