ShukantPal / pixi-essentials

The best goodies for performant, enterprise-level applications built on PixiJS
https://api.pixijs.io
MIT License
283 stars 37 forks source link

[Feature][Transformer] Ability to hook into transformer operations #64

Open Thanzex opened 2 years ago

Thanzex commented 2 years ago

Hi again! I will refer to movement/scale/rotation/skew as operations for brevity.

As of right now, the Transformer handles all inputs and operations by itself, but it would be nice to be able to handle some more interesting cases. Here are the main options i'm missing, forgive me if they are already present and I simply did not find them.

  1. Getting the group transformations. As far as I can tell right now Transformer handles all the input and directly applies the operation to the group members, it would be useful to have a way to get the applied transformations.
  2. Setting the group transformations. Since Transformer applies its changes directly to the target objects, it does not expose a way to easily set any parameter from the outside. This could be very useful in cases in which thanks to (1) we save somewhere the operations we performed to a group and then retrieve and set those same operations to a new Transformer, without having wokny wireframes.
  3. Being able to hook inside the transform process.

It would be very useful to have a callback after the changes are computed but before the actual transform is performed, to be able to handle some more interesting logic.

Some use cases that would be enabled are:

Ideally, one such callback would take as input the delta of the current frame and the delta since the beginning of the event and be able to make any change to the operation. Please excuse the very crude example.

interface IScale {
    x: number
    y: number
}

interface IDelta {
    x: number
    y: number
    scale: IScale
    angle: number
}

interface IChangeCallback {
    operation: string
    frame: IDelta
    total: IDelta
}

type IChangeCallbackFunc = (IChangeCallback) => IChangeCallback;

Let me know what you think about it

ShukantPal commented 2 years ago

Hi @Thanzex, I would suggest you override prependTransform: https://github.com/ShukantPal/pixi-essentials/blob/70a16f9befc9d3b7ee799b8cea4bd11c8454b26f/packages/transformer/src/Transformer.ts#L1407

It emits a transformchange event already but if you want to change the applied transform itself, you would need to override it. Let me know if you need additional consulting services.

rougsig commented 1 year ago

But prependTransform it private