Transformer
class Transformer extends PIXI.Container
Transformer
provides an interactive interface for editing the transforms in a group. It supports translating,
scaling, rotating, and skewing display-objects both through interaction and code.
A transformer operates in world-space, and it is best to not position, scale, rotate, or skew one. If you do so, the
wireframe itself will not distort (i.e. will adapt against your transforms). However, the wireframe may become
thinner/thicker and the handles will scale & rotate. For example, setting transformer.scale.set(2)
will make the handles
twice as big, but will not scale the wireframe (assuming the display-object group itself has not been
scaled up).
To enable scaling via dragging the edges of the wireframe, set boxScalingEnabled
to true
.
NOTE: The transformer needs to capture all interaction events that would otherwise go to the display-objects in the group. Hence, it must be placed after them in the scene graph.
Constructor
new Transformer(options: Partial<ITransformerOptions>) → {}
Handle | Type | Notes |
---|---|---|
rotator | Rotate | |
boxRotateTopLeft | Rotate | Invisible |
boxRotateTopRight | Rotate | Invisible |
boxRotateBottomLeft | Rotate | Invisible |
boxRotateBottomRight | Rotate | Invisible |
topLeft | Scale | |
topCenter | Scale | |
topRight | Scale | |
middleLeft | Scale | |
middleCenter | Scale | This cannot be enabled! |
middleRight | Scale | |
bottomLeft | Scale | |
bottomCenter | Scale | |
bottomRight | Scale | |
skewHorizontal | Skew | Applies vertical shear. Handle segment is horizontal at skew.y = 0! |
skewVertical | Skew | Applied horizontal shear. Handle segment is vertical at skew.x = 0! |
Name | Type | Description |
---|---|---|
options | Partial<ITransformerOptions> |
Summary
Properties from Transformer
"all" | "groupOnly" | "none" |
Specify which bounding boxes should be drawn in the wireframe. |
boolean |
Set this to enable rotation at the four corners |
number |
The thickness of the box rotation area |
boolean |
Set this to enable scaling by dragging at the edges of the bounding box |
number |
The padding around the bounding-box to capture dragging on the edges. |
boolean |
This will prevent the wireframe's center from shifting on scaling. |
|
|
ITransformerCursors |
Cursors to use in the transformer |
Array<Handle> |
The list of enabled handles, if applied manually. |
PIXI.DisplayObject[] |
The group of display-objects under transformation. |
Partial<ITransformerHandleStyle> |
The currently applied handle style. If you have edited the transformer handles directly, this may be inaccurate. |
boolean |
Set this when you want the transformer to redraw when using lazyMode. |
boolean |
Flags whether the transformer should not redraw each frame (good for performance) |
boolean |
Lock aspect ratio when using one of the corner handles. |
PIXI.Matrix |
|
boolean |
This will enable the rotate handles. |
This will rotate the group such that the handle will come to |
|
number[] |
The angles at which rotation should snap. |
number |
The maximum angular difference for snapping rotation. |
boolean |
This will enable the scale handles. |
This will scale the group such that the scale handle will come under |
|
boolean |
This will enable the skew handles. |
This will skew the group such that the skew handle would move to the |
|
number |
The distance of skewing handles from the group's center. |
number[] |
The angles at which both the horizontal & vertical skew handles should snap. |
number |
The maximum angular difference for snapping skew handles. |
PIXI.Container | null |
The root object in your scene in which objects can move. |
"translate" | "scale" | "rotate" | "skew" | "none" |
|
boolean |
This will reset the rotation angle after the user finishes rotating a group with more than one display-object. |
boolean |
This will enable translation on dragging the transformer. By default, it is turned on. |
This will translate the group by |
|
Partial<ITransformerStyle> |
The currently applied wireframe style. |
Handle[] |
|
Partial<ITransformerHandleStyle> |
The style applied on transformer handles |
boolean |
|
boolean |
|
boolean |
|
number |
The horizontal skew value. Rotating the group by 𝜽 will also change this value by 𝜽. |
number |
The vertical skew value. Rotating the group by 𝜽 will also change this value by 𝜽. |
Handle |
The currently grabbed handle. This can be used to get the type of transformation. |
"translate" | "scale" | "rotate" | "skew" | "none" |
The current type of transform being applied by the user. |
Partial<ITransformerStyle> |
The wireframe style applied on the transformer |
OrientedBounds |
The last calculated bounds of the whole group being transformed |
{ [H in undefined Handle] }: TransformerHandle |
Object mapping handle-names to the handle display-objects. |
TransformerWireframe |
Draws the bounding boxes |
Methods from Transformer
OrientedBounds |
Calculates the oriented bounding box of a group of display-objects at a specific angle. |
OrientedBounds |
|
PIXI.Point[] |
|
OrientedBounds |
|
PIXI.Point |
|
void |
This will update the transformer's geometry and render it to the canvas. |
void |
|
void |
Recalculates the transformer's geometry. This is called on each render. |
void |
Draw the handles and any remaining parts of the wireframe. |
void |
Called on the |
void |
Called on the |
void |
Called on the |
Public Properties
boundingBoxes: "all" | "groupOnly" | "none" = "all"
Specify which bounding boxes should be drawn in the wireframe.
"groupOnly" won't show individual bounding boxes. "none" will not render anything visible.
boxRotationEnabled: boolean
Set this to enable rotation at the four corners
boxRotationTolerance: number
The thickness of the box rotation area
boxScalingEnabled: boolean
Set this to enable scaling by dragging at the edges of the bounding box
boxScalingTolerance: number
The padding around the bounding-box to capture dragging on the edges.
centeredScaling: boolean
This will prevent the wireframe's center from shifting on scaling.
commitGroup
This is called after the user finishes dragging a handle. If this.transientGroupTilt is enabled, it will reset the rotation of this group (if more than one display-object is grouped).
enabledHandles: Array<Handle>
The list of enabled handles, if applied manually.
group: PIXI.DisplayObject[]
The group of display-objects under transformation.
handleStyle: Partial<ITransformerHandleStyle>
The currently applied handle style. If you have edited the transformer handles directly, this may be inaccurate.
lazyDirty: boolean
Set this when you want the transformer to redraw when using lazyMode.
lazyMode: boolean = false
Flags whether the transformer should not redraw each frame (good for performance)
lockAspectRatio: boolean
Lock aspect ratio when using one of the corner handles.
projectionTransform: PIXI.Matrix
This is used when the display-object group are rendered through a projection transformation (i.e. are disconnected from the transformer in the scene graph). The transformer project itself into their frame-of-reference using this transform.
Specifically, the projection-transform converts points from the group's world space to the transformer's world space. If you are not applying a projection on the transformer itself, this means it is the group's world-to-screen transformation.
rotateGroup
This will rotate the group such that the handle will come to pointerPosition
.
Name | Type | Description |
---|---|---|
handle |
the rotator handle was dragged |
|
pointerPosition |
the new pointer position, in screen space |
rotationSnapTolerance: number
The maximum angular difference for snapping rotation.
scaleGroup
This will scale the group such that the scale handle will come under pointerPosition
.
Name | Type | Description |
---|---|---|
handle |
the scaling handle that was dragged |
|
pointerPosition |
the new pointer position, in screen space |
skewGroup
This will skew the group such that the skew handle would move to the pointerPosition
.
Name | Type | Description |
---|---|---|
handle | ||
pointerPosition |
pointer position, in screen space |
skewRadius: number
The distance of skewing handles from the group's center.
skewSnaps: number[]
The angles at which both the horizontal & vertical skew handles should snap.
skewSnapTolerance: number
The maximum angular difference for snapping skew handles.
stage: PIXI.Container | null
The root object in your scene in which objects can move.
Transformer
will subscribe to this object for pointermove
events, if provided. This
should be used when:
- moveWhenInside is enabled on the interaction plugin.
- moveOnAll is not turned off when using the new EventSystem.
Otherwise, the transformer will receive not pointermove
events when the user drags fast enough that
the cursor leaves the transformer's bounds.
The stage must be fully interactive in the area you want objects to move. Generally, this is the whole canvas:
stage.interactive = true;
stage.hitArea = renderer.screen;// or pass custom rect for the canvas dimensions
transformType: "translate" | "scale" | "rotate" | "skew" | "none"
This is the type of transformation being applied by the user on the group. It can be inaccurate if you call one of
translateGroup
, scaleGroup
, rotateGroup
, skewGroup
without calling commitGroup
afterwards.
transientGroupTilt: boolean = true
This will reset the rotation angle after the user finishes rotating a group with more than one display-object.
translateEnabled: boolean = true
This will enable translation on dragging the transformer. By default, it is turned on.
translateGroup
This will translate the group by delta
in their world-space.
NOTE: There is no handle that provides translation. The user drags the transformer directly.
Name | Type | Description |
---|---|---|
delta |
wireframeStyle: Partial<ITransformerStyle>
The currently applied wireframe style.
Protected Properties
protected _enabledHandles: Handle[]
protected _handleStyle: Partial<ITransformerHandleStyle>
The style applied on transformer handles
protected _skewX: number
The horizontal skew value. Rotating the group by 𝜽 will also change this value by 𝜽.
protected _skewY: number
The vertical skew value. Rotating the group by 𝜽 will also change this value by 𝜽.
protected _transformHandle: Handle
The currently grabbed handle. This can be used to get the type of transformation.
protected _transformType: "translate" | "scale" | "rotate" | "skew" | "none"
The current type of transform being applied by the user.
protected _wireframeStyle: Partial<ITransformerStyle>
The wireframe style applied on the transformer
protected groupBounds: OrientedBounds
The last calculated bounds of the whole group being transformed
protected handles: { [H in undefined Handle] }: TransformerHandle
Object mapping handle-names to the handle display-objects.
Public Methods
static calculateGroupOrientedBounds(group: PIXI.DisplayObject[], rotation: number, bounds: OrientedBounds, skipUpdate: boolean) → {OrientedBounds}
Calculates the oriented bounding box of a group of display-objects at a specific angle.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
group | PIXI.DisplayObject[] | |||
rotation | number | |||
bounds | OrientedBounds |
<optional> |
||
skipUpdate | boolean | false |
Type | Description |
---|---|
OrientedBounds |
static calculateOrientedBounds(displayObject: PIXI.DisplayObject, bounds: OrientedBounds) → {OrientedBounds}
Calculates the oriented bounding box of the display-object. This would not bending with any skew applied on the display-object, i.e. it is guaranteed to be rectangular.
Name | Type | Attributes | Description |
---|---|---|---|
displayObject | PIXI.DisplayObject | ||
bounds | OrientedBounds |
<optional> |
the bounds instance to set |
Type | Description |
---|---|
OrientedBounds |
static calculateTransformedCorners(displayObject: PIXI.DisplayObject, transform: PIXI.Matrix, corners: PIXI.Point[], index: number) → {PIXI.Point[]}
Calculates the positions of the four corners of the display-object. The quadrilateral formed by these points will be the tightest fit around it.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
displayObject | PIXI.DisplayObject |
The display object whose corners are to be calculated |
||
transform | PIXI.Matrix |
The transform applied on the display-object. By default, this is its world-transform |
||
corners | PIXI.Point[] |
<optional> |
Optional array of four points to put the result into |
|
index | number | 0 |
Optional index into "corners" |
Type | Description |
---|---|
PIXI.Point[] |
an array of four points holding the positions of the corners |
getGroupBounds(forceUpdate: boolean) → {OrientedBounds}
Name | Type | Default | Description |
---|---|---|---|
forceUpdate | boolean | false |
forces a recalculation of the group bounds |
Type | Description |
---|---|
OrientedBounds |
the oriented bounding box of the wireframe |
projectToLocal(input: PIXI.Point, output: PIXI.Point) → {PIXI.Point}
Projects input
from the group's world space into the transformer's local space, and puts the result
into output
.
Name | Type | Attributes | Description |
---|---|---|---|
input | PIXI.Point | ||
output | PIXI.Point |
<optional> |
Type | Description |
---|---|
PIXI.Point |
the output |
render(renderer: PIXI.Renderer) → {void}
This will update the transformer's geometry and render it to the canvas.
Name | Type | Description |
---|---|---|
renderer | PIXI.Renderer |
Type | Description |
---|---|
void |
renderCanvas(renderer: PIXI.CanvasRenderer) → {void}
Renders the object using the Canvas renderer
Name | Type | Description |
---|---|---|
renderer | PIXI.CanvasRenderer |
The renderer |
Type | Description |
---|---|
void |
Protected Methods
protected draw() → {void}
Recalculates the transformer's geometry. This is called on each render.
Type | Description |
---|---|
void |
protected drawHandles(groupBounds: OrientedBounds) → {void}
Draw the handles and any remaining parts of the wireframe.
Name | Type | Description |
---|---|---|
groupBounds | OrientedBounds |
Type | Description |
---|---|
void |
protected onPointerDown(e: PIXI.InteractionEvent) → {void}
Called on the pointerdown
event. You must call the super implementation.
Name | Type | Description |
---|---|---|
e | PIXI.InteractionEvent |
Type | Description |
---|---|
void |
protected onPointerMove(e: PIXI.InteractionEvent) → {void}
Called on the pointermove
event. You must call the super implementation.
Name | Type | Description |
---|---|---|
e | PIXI.InteractionEvent |
Type | Description |
---|---|
void |
protected onPointerUp(e: PIXI.InteractionEvent) → {void}
Called on the pointerup
and pointerupoutside
events. You must call the super implementation.
Name | Type | Description |
---|---|---|
e | PIXI.InteractionEvent |
Type | Description |
---|---|
void |