diff --git a/packages/bounds/package.json b/packages/bounds/package.json index 0941a5bf..ef54251f 100644 --- a/packages/bounds/package.json +++ b/packages/bounds/package.json @@ -32,10 +32,10 @@ }, "homepage": "https://github.com/SukantPal/pixi-essentials#readme", "peerDependencies": { - "@pixi/math": "^7.0.0" + "pixi.js": "^8.0.5" }, "devDependencies": { - "@pixi/math": "^7.0.0", + "pixi.js": "^8.0.5", "@pixi-build-tools/rollup-configurator": "^1.0.10", "tslib": "~2.0.1", "typescript": "~4.9.5", diff --git a/packages/bounds/src/AxisAlignedBounds.ts b/packages/bounds/src/AxisAlignedBounds.ts index b5cc6cf5..c95e497e 100644 --- a/packages/bounds/src/AxisAlignedBounds.ts +++ b/packages/bounds/src/AxisAlignedBounds.ts @@ -1,4 +1,5 @@ -import { Point } from '@pixi/math'; +// import { Point } from '@pixi/math'; +import { Point } from 'pixi.js'; /** * Rectangle object is an area defined by its position, as indicated by its top-left corner diff --git a/packages/bounds/src/OrientedBounds.ts b/packages/bounds/src/OrientedBounds.ts index 00fecb36..cb44612c 100644 --- a/packages/bounds/src/OrientedBounds.ts +++ b/packages/bounds/src/OrientedBounds.ts @@ -1,5 +1,17 @@ -import { AxisAlignedBounds } from './AxisAlignedBounds'; -import { Matrix, ObservablePoint, Point } from '@pixi/math'; +import { AxisAlignedBounds } from "./AxisAlignedBounds"; +// import { Matrix, ObservablePoint, Point } from '@pixi/math'; +import { Matrix, ObservablePoint, Point, Observer } from "pixi.js"; + +class CustomObserver implements Observer { + callback: () => void; + constructor(callback: () => void) { + this.callback = callback; + } + + _onUpdate() { + this.callback(); + } +} const tempPoint = new Point(); @@ -12,244 +24,242 @@ const tempPoint = new Point(); * * @public */ -export class OrientedBounds -{ - public innerBounds: AxisAlignedBounds; - public currentID: number; - public dirtyID: number; - - protected _rotation: number; - protected _center: Point; - protected _hull: [Point, Point, Point, Point]; - protected _matrix: Matrix; - - /** - * @param innerBounds - * @param angle - */ - constructor(innerBounds: AxisAlignedBounds, angle?: number); - - /** - * @param x - * @param y - * @param width - * @param height - * @param angle - */ - constructor(x?: number, y?: number, width?: number, height?: number, angle?: number); - - constructor(x: number | AxisAlignedBounds = 0, y = 0, width = 0, height = 0, angle = 0) - { - if (x instanceof AxisAlignedBounds) - { - angle = y || 0; - - y = x.y; - width = x.width; - height = x.height; - - x = x.x; - } - - /** - * The unrotated version of this bounding box. - */ - this.innerBounds = new AxisAlignedBounds(x, y, width, height); - - this._rotation = angle; - this._center = new ObservablePoint(this.updateCenter, this); - this._hull = [new Point(), new Point(), new Point(), new Point()]; - this._matrix = new Matrix(); - - this.currentID = -1; - this.dirtyID = 0; - } - - /** - * The angle, in radians, by which this bounding box is tilted. - */ - get rotation(): number - { - return this._rotation; - } - - set rotation(value: number) - { - this._rotation = value; - this.dirtyID++; - } - - /** - * The center of this bounding box. - * - * The center of this and {@code this.innerBounds} will always coincide. - */ - get center(): Point - { - if (this.isDirty()) this.update(); - - return this._center; - } - - set center(value: Point) - { - // this.updateCenter will automatically be fired! - this.center.copyFrom(value); - } - - /** - * The four-corners of this bounding, in clockwise order starting from the top-left. - * - * @readonly - */ - get hull(): [Point, Point, Point, Point] - { - if (this.isDirty()) this.update(); - - return this._hull; - } - - /** - * The top-left corner of this bounding box. The returned instance should not be modified directly. - * - * @readonly - */ - get topLeft(): Point - { - if (this.isDirty()) this.update(); - - return this._hull[0]; - } - - /** - * The top-right corner of this bounding box. The returned instance should not be modified directly. - * - * @readonly - */ - get topRight(): Point - { - if (this.isDirty()) this.update(); - - return this._hull[1]; - } - - /** - * The bottom-right corner of this bounding box. The returned instance should not be modified directly. - */ - get bottomRight(): Point - { - if (this.isDirty()) this.update(); - - return this._hull[2]; - } - - /** - * The bottom-left corner of this bounding box. The returned instance should not be modified directly. - */ - get bottomLeft(): Point - { - if (this.isDirty()) this.update(); - - return this._hull[3]; - } - - /** - * Checks whether the given {@code bounds} are equal to this. - * - * @param bounds - */ - equals(bounds: OrientedBounds): boolean - { - if (!bounds) return false; - - return this.innerBounds.equals(bounds.innerBounds) - && this.rotation === bounds.rotation; +export class OrientedBounds { + public innerBounds: AxisAlignedBounds; + public currentID: number; + public dirtyID: number; + + protected _rotation: number; + protected _center: Point; + protected _hull: [Point, Point, Point, Point]; + protected _matrix: Matrix; + + /** + * @param innerBounds + * @param angle + */ + constructor(innerBounds: AxisAlignedBounds, angle?: number); + + /** + * @param x + * @param y + * @param width + * @param height + * @param angle + */ + constructor( + x?: number, + y?: number, + width?: number, + height?: number, + angle?: number + ); + + constructor( + x: number | AxisAlignedBounds = 0, + y = 0, + width = 0, + height = 0, + angle = 0 + ) { + if (x instanceof AxisAlignedBounds) { + angle = y || 0; + + y = x.y; + width = x.width; + height = x.height; + + x = x.x; } /** - * Whether this bounding box contains the given point - * - * @param point + * The unrotated version of this bounding box. */ - contains(point: Point | number, y?: number): boolean - { - if (typeof point === 'number') - { - point = tempPoint.set(point, y); - } - - // Point in the coordinate space of inner bounds - const localPoint = this._matrix.applyInverse(point, tempPoint); - - return this.innerBounds.contains(localPoint.x, localPoint.y); - } - - /** - * Copies {@code bounds} into this instance. - * - * @param bounds - */ - copyFrom(bounds: OrientedBounds): this - { - this.innerBounds.copyFrom(bounds.innerBounds); - this.rotation = bounds.rotation; - this.dirtyID++; - - return this; + this.innerBounds = new AxisAlignedBounds(x, y, width, height); + + this._rotation = angle; + let observer = new CustomObserver(this.updateCenter.bind(this)); + // this._center = new ObservablePoint(this.updateCenter, this); + this._center = new ObservablePoint(observer, 0, 0); + this._hull = [new Point(), new Point(), new Point(), new Point()]; + this._matrix = new Matrix(); + + this.currentID = -1; + this.dirtyID = 0; + } + + /** + * The angle, in radians, by which this bounding box is tilted. + */ + get rotation(): number { + return this._rotation; + } + + set rotation(value: number) { + this._rotation = value; + this.dirtyID++; + } + + /** + * The center of this bounding box. + * + * The center of this and {@code this.innerBounds} will always coincide. + */ + get center(): Point { + if (this.isDirty()) this.update(); + + return this._center; + } + + set center(value: Point) { + // this.updateCenter will automatically be fired! + this.center.copyFrom(value); + } + + /** + * The four-corners of this bounding, in clockwise order starting from the top-left. + * + * @readonly + */ + get hull(): [Point, Point, Point, Point] { + if (this.isDirty()) this.update(); + + return this._hull; + } + + /** + * The top-left corner of this bounding box. The returned instance should not be modified directly. + * + * @readonly + */ + get topLeft(): Point { + if (this.isDirty()) this.update(); + + return this._hull[0]; + } + + /** + * The top-right corner of this bounding box. The returned instance should not be modified directly. + * + * @readonly + */ + get topRight(): Point { + if (this.isDirty()) this.update(); + + return this._hull[1]; + } + + /** + * The bottom-right corner of this bounding box. The returned instance should not be modified directly. + */ + get bottomRight(): Point { + if (this.isDirty()) this.update(); + + return this._hull[2]; + } + + /** + * The bottom-left corner of this bounding box. The returned instance should not be modified directly. + */ + get bottomLeft(): Point { + if (this.isDirty()) this.update(); + + return this._hull[3]; + } + + /** + * Checks whether the given {@code bounds} are equal to this. + * + * @param bounds + */ + equals(bounds: OrientedBounds): boolean { + if (!bounds) return false; + + return ( + this.innerBounds.equals(bounds.innerBounds) && + this.rotation === bounds.rotation + ); + } + + /** + * Whether this bounding box contains the given point + * + * @param point + */ + contains(point: Point | number, y?: number): boolean { + if (typeof point === "number") { + point = tempPoint.set(point, y); } - /** - * Whether any internal state needs to be recalculated. - */ - protected isDirty(): boolean - { - return this.currentID !== this.dirtyID + this.innerBounds.dirtyID; - } - - /** - * This will recalculate the center, orientation matrix, and the hull vertices. It should be called only if - * {@code this.isDirty} returns true. - */ - protected update(): void - { - const innerBounds = this.innerBounds; - const angle = this._rotation; - - const center = this._center; - const [topLeft, topRight, bottomRight, bottomLeft] = this._hull; - const matrix = this._matrix; - - // Calculate center - // Do not set [x|y] so to prevent this.updateCenter from being fired! - (center as any)._x = innerBounds.x + (innerBounds.width / 2); - (center as any)._y = innerBounds.y + (innerBounds.height / 2); - - // Calculate orientation matrix - matrix.identity() - .translate(-center.x, -center.y) - .rotate(angle) - .translate(center.x, center.y); - - // Calculate hull vertices - matrix.apply(innerBounds.topLeft, topLeft); - matrix.apply(innerBounds.topRight, topRight); - matrix.apply(innerBounds.bottomRight, bottomRight); - matrix.apply(innerBounds.bottomLeft, bottomLeft); - - // Update currentID so isDirty() is false - this.currentID = this.dirtyID + this.innerBounds.dirtyID; - } - - /** - * This will translate {@link OrientedBounds#innerBounds} after {@link OrientedBounds#center} is - * changed to ensure consistency. - */ - private updateCenter(): void - { - const center = this.center; - const innerBounds = this.innerBounds; - - innerBounds.x = center.x - (innerBounds.width / 2); - innerBounds.y = center.y - (innerBounds.height / 2); - } + // Point in the coordinate space of inner bounds + const localPoint = this._matrix.applyInverse(point, tempPoint); + + return this.innerBounds.contains(localPoint.x, localPoint.y); + } + + /** + * Copies {@code bounds} into this instance. + * + * @param bounds + */ + copyFrom(bounds: OrientedBounds): this { + this.innerBounds.copyFrom(bounds.innerBounds); + this.rotation = bounds.rotation; + this.dirtyID++; + + return this; + } + + /** + * Whether any internal state needs to be recalculated. + */ + protected isDirty(): boolean { + return this.currentID !== this.dirtyID + this.innerBounds.dirtyID; + } + + /** + * This will recalculate the center, orientation matrix, and the hull vertices. It should be called only if + * {@code this.isDirty} returns true. + */ + protected update(): void { + const innerBounds = this.innerBounds; + const angle = this._rotation; + + const center = this._center; + const [topLeft, topRight, bottomRight, bottomLeft] = this._hull; + const matrix = this._matrix; + + // Calculate center + // Do not set [x|y] so to prevent this.updateCenter from being fired! + (center as any)._x = innerBounds.x + innerBounds.width / 2; + (center as any)._y = innerBounds.y + innerBounds.height / 2; + + // Calculate orientation matrix + matrix + .identity() + .translate(-center.x, -center.y) + .rotate(angle) + .translate(center.x, center.y); + + // Calculate hull vertices + matrix.apply(innerBounds.topLeft, topLeft); + matrix.apply(innerBounds.topRight, topRight); + matrix.apply(innerBounds.bottomRight, bottomRight); + matrix.apply(innerBounds.bottomLeft, bottomLeft); + + // Update currentID so isDirty() is false + this.currentID = this.dirtyID + this.innerBounds.dirtyID; + } + + /** + * This will translate {@link OrientedBounds#innerBounds} after {@link OrientedBounds#center} is + * changed to ensure consistency. + */ + private updateCenter(): void { + const center = this.center; + const innerBounds = this.innerBounds; + + innerBounds.x = center.x - innerBounds.width / 2; + innerBounds.y = center.y - innerBounds.height / 2; + } } diff --git a/packages/object-pool/package.json b/packages/object-pool/package.json index e24d4f50..f69cf8b9 100644 --- a/packages/object-pool/package.json +++ b/packages/object-pool/package.json @@ -42,11 +42,11 @@ }, "peerDependencies": { "@pixi/settings": "^7.0.0", - "@pixi/ticker": "^7.0.0" + "pixi.js": "^8.0.5" }, "devDependencies": { "@microsoft/api-extractor": "7.7.13", - "@pixi/ticker": "^7.0.0", + "pixi.js": "^8.0.5", "@pixi-build-tools/rollup-configurator": "^1.0.10", "tslib": "~2.0.1", "typescript": "~4.9.5", diff --git a/packages/object-pool/src/ObjectPool.ts b/packages/object-pool/src/ObjectPool.ts index dd6584ad..94015bfd 100644 --- a/packages/object-pool/src/ObjectPool.ts +++ b/packages/object-pool/src/ObjectPool.ts @@ -1,4 +1,5 @@ -import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; +// import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from 'pixi.js'; import { AverageProvider } from './AverageProvider'; /** diff --git a/packages/transformer/package.json b/packages/transformer/package.json index 949453ca..84ac6918 100644 --- a/packages/transformer/package.json +++ b/packages/transformer/package.json @@ -35,11 +35,7 @@ "@pixi-essentials/object-pool": "~1.0.1" }, "peerDependencies": { - "@pixi/core": "^7.0.0", - "@pixi/display": "^7.0.0", - "@pixi/events": "^7.0.0", - "@pixi/graphics": "^7.0.0", - "@pixi/math": "^7.0.0" + "pixi.js": "^8.0.5" }, "devDependencies": { "@pixi-essentials/eslint-config": "~1.0.0", diff --git a/packages/transformer/src/Transformer.ts b/packages/transformer/src/Transformer.ts index 7a2c0232..b2297f11 100644 --- a/packages/transformer/src/Transformer.ts +++ b/packages/transformer/src/Transformer.ts @@ -1,6 +1,6 @@ -import {Renderer, utils} from '@pixi/core'; -import { DisplayObject, Container } from '@pixi/display'; -import { Point, Matrix, Transform, Rectangle } from '@pixi/math'; +// import {Renderer, utils} from '@pixi/core'; +// import { DisplayObject, Container } from '@pixi/display'; +// import { Point, Matrix, Transform, Rectangle } from '@pixi/math'; import { OrientedBounds } from '@pixi-essentials/bounds'; import { ObjectPoolFactory } from '@pixi-essentials/object-pool'; import { TransformerHandle } from './TransformerHandle'; @@ -10,12 +10,29 @@ import { decomposeTransform } from './utils/decomposeTransform'; import { multiplyTransform } from './utils/multiplyTransform'; import type { ITransformerHandleStyle } from './TransformerHandle'; +// import { +// Cursor, +// FederatedEventTarget, +// FederatedPointerEvent, +// IFederatedDisplayObject, +// } from "@pixi/events"; + import { - Cursor, - FederatedEventTarget, + Renderer, + Container, + Point, + Matrix, + Transform, + Rectangle, FederatedPointerEvent, - IFederatedDisplayObject, -} from "@pixi/events"; + Cursor, + FederatedEventTarget + } from "pixi.js"; + + import { + DisplayObject, + IFederatedDisplayObject + } from "."; // Preallocated objects const tempTransform = new Transform(); @@ -320,7 +337,7 @@ const Container_ = Container as unknown as { new(): Container & IFederatedDisplayObject & Omit - & utils.EventEmitter; + & EventEmitter; }; /** @@ -1112,14 +1129,14 @@ export class Transformer extends Container_ * @override * @param renderer */ - render(renderer: Renderer): void + render(/* renderer: Renderer */): void // V8 { if (this.renderable && this.visible && (!this.lazyMode || this.lazyDirty)) { this.draw(); } - super.render(renderer); + // super.render(renderer); } /** Recalculates the transformer's geometry. This is called on each render. */ @@ -1133,12 +1150,12 @@ export class Transformer extends Container_ if (this.boundingBoxes !== 'none') { - this.wireframe.lineStyle(thickness, color); + this.wireframe.stroke({ width: thickness, color: color }); } if (this.translateEnabled) { - this.wireframe.beginFill(0xffffff, 1e-4); + this.wireframe.fill({ color: 0xffffff, alpha: 1e-4 }); } for (let i = 0, j = targets.length; i < j && this.boundingBoxes === 'all'; i++) @@ -1162,8 +1179,10 @@ export class Transformer extends Container_ if (this.boxRotationEnabled) { this.wireframe.closePath() - .beginFill(0xffffff, 1e-4) - .lineStyle(); + // .beginFill(0xffffff, 1e-4) + .fill({ color: 0xffffff, alpha: 1e-4 }) + .stroke(); + // .lineStyle(); this.wireframe.drawBoxRotationTolerance(); } @@ -1171,8 +1190,10 @@ export class Transformer extends Container_ { this.wireframe .closePath() - .beginFill(0xfff0ff, 1e-4) - .lineStyle(); + .fill({ color: 0xfff0ff, alpha: 1e-4 }) + .stroke(); + // .beginFill(0xfff0ff, 1e-4) + // .lineStyle(); this.wireframe.drawBoxScalingTolerance(groupBounds); } @@ -1271,9 +1292,11 @@ export class Transformer extends Container_ center.set(cx, cy); this.wireframe - .beginFill(this.wireframeStyle.color) - .drawCircle(center.x, center.y, this.wireframeStyle.thickness * 2) - .endFill(); + // .beginFill(this.wireframeStyle.color) + // .drawCircle(center.x, center.y, this.wireframeStyle.thickness * 2) + // .endFill(); + .fill(this.wireframeStyle.color) + .circle(center.x, center.y, this.wireframeStyle.thickness * 2); this.wireframe .moveTo(center.x, center.y) .lineTo(handles.skewHorizontal.x, handles.skewHorizontal.y) @@ -1616,15 +1639,28 @@ export class Transformer extends Container_ */ static calculateOrientedBounds(displayObject: DisplayObject, bounds?: OrientedBounds): OrientedBounds { - const parent = !displayObject.parent ? displayObject.enableTempParent() : displayObject.parent; - - displayObject.updateTransform(); - displayObject.disableTempParent(parent); + // const parent = !displayObject.parent ? displayObject.enableTempParent() : displayObject.parent; // V8 + + // displayObject.updateTransform(); + displayObject.updateTransform({ + x: displayObject.x, + y: displayObject.y, + pivotX: displayObject.pivot.x, + pivotY: displayObject.pivot.y, + scaleX: displayObject.scale.x, + scaleY: displayObject.scale.y, + skewX: displayObject.skew.x, + skewY: displayObject.skew.y, + rotation: displayObject.rotation, + }); + + + // displayObject.disableTempParent(parent); // Decompose displayObject.worldTransform to get its (world) rotation decomposeTransform(tempTransform, displayObject.worldTransform); - tempTransform.updateLocalTransform(); + // tempTransform.updateLocalTransform(); // V8 const angle = tempTransform.rotation; const corners = Transformer.calculateTransformedCorners(displayObject, displayObject.worldTransform, tempCorners); @@ -1682,10 +1718,22 @@ export class Transformer extends Container_ // Update worldTransform if (!skipUpdate) { - const parent = !displayObject.parent ? displayObject.enableTempParent() : displayObject.parent; - - displayObject.updateTransform(); - displayObject.disableTempParent(parent); + // const parent = !displayObject.parent ? displayObject.enableTempParent() : displayObject.parent; // V8 + + // displayObject.updateTransform(); + // displayObject.disableTempParent(parent); + + displayObject.updateTransform({ + x: displayObject.x, + y: displayObject.y, + pivotX: displayObject.pivot.x, + pivotY: displayObject.pivot.y, + scaleX: displayObject.scale.x, + scaleY: displayObject.scale.y, + skewX: displayObject.skew.x, + skewY: displayObject.skew.y, + rotation: displayObject.rotation, + }); } Transformer.calculateTransformedCorners(displayObject, displayObject.worldTransform, frames, i * 4); diff --git a/packages/transformer/src/TransformerHandle.ts b/packages/transformer/src/TransformerHandle.ts index 2722333e..b183e3ad 100644 --- a/packages/transformer/src/TransformerHandle.ts +++ b/packages/transformer/src/TransformerHandle.ts @@ -1,10 +1,21 @@ -import { Graphics } from '@pixi/graphics'; -import { Point } from '@pixi/math'; -import { Renderer } from '@pixi/core'; +// import { Graphics } from '@pixi/graphics'; +// import { Point } from '@pixi/math'; +// import { Renderer } from '@pixi/core'; -import type {Container} from '@pixi/display'; +// import type {Container} from '@pixi/display'; import type { Handle, Transformer } from './Transformer'; -import {FederatedEventTarget, FederatedPointerEvent, IFederatedDisplayObject} from "@pixi/events"; +// import {FederatedEventTarget, FederatedPointerEvent, IFederatedDisplayObject} from "@pixi/events"; + +import { + Graphics, + Point, + Container, + FederatedEventTarget, + FederatedPointerEvent, + Ticker, + } from "pixi.js"; + + import { IFederatedDisplayObject } from "."; /** @see TransformerHandle#style */ export interface ITransformerHandleStyle @@ -105,6 +116,8 @@ export class TransformerHandle extends Graphics_ this.onpointermove = this.onPointerMove; this.onpointerup = this.onPointerUp; this.onpointerupoutside = this.onPointerUp; + + Ticker.shared.add(this.render, this); // V8 } get handle(): Handle @@ -130,7 +143,7 @@ export class TransformerHandle extends Graphics_ this._dirty = true; } - render(renderer: Renderer): void + render(/* renderer: Renderer */): void { if (this._dirty) { @@ -139,7 +152,7 @@ export class TransformerHandle extends Graphics_ this._dirty = false; } - super.render(renderer); + // super.render(renderer); } /** @@ -153,19 +166,19 @@ export class TransformerHandle extends Graphics_ const radius = style.radius; this.clear() - .lineStyle(style.outlineThickness, style.outlineColor) - .beginFill(style.color); + // .lineStyle(style.outlineThickness, style.outlineColor) + // .beginFill(style.color); if (style.shape === 'square') { - this.drawRect(-radius / 2, -radius / 2, radius, radius); + this.rect(-radius / 2, -radius / 2, radius, radius); } else if (style.shape === 'tooth') { switch (handle) { case 'middleLeft': - this.drawPolygon([ + this.poly([ -radius / 2, -radius / 2, -radius / 2, radius / 2, radius / 2, radius / 2, @@ -174,7 +187,7 @@ export class TransformerHandle extends Graphics_ ]); break; case 'topCenter': - this.drawPolygon([ + this.poly([ -radius / 2, -radius / 2, radius / 2, -radius / 2, radius / 2, radius / 2, @@ -183,7 +196,7 @@ export class TransformerHandle extends Graphics_ ]); break; case 'middleRight': - this.drawPolygon([ + this.poly([ -radius / 2, radius / 2, -radius * 1.1, 0, -radius / 2, -radius / 2, @@ -192,7 +205,7 @@ export class TransformerHandle extends Graphics_ ]); break; case 'bottomCenter': - this.drawPolygon([ + this.poly([ 0, -radius * 1.1, radius / 2, -radius / 2, radius / 2, radius / 2, @@ -201,19 +214,23 @@ export class TransformerHandle extends Graphics_ ]); break; case 'rotator': - this.drawCircle(0, 0, radius / Math.sqrt(2)); + this.circle(0, 0, radius / Math.sqrt(2)); break; default: - this.drawRect(-radius / 2, -radius / 2, radius, radius); + this.rect(-radius / 2, -radius / 2, radius, radius); break; } } else { - this.drawCircle(0, 0, radius); + this.circle(0, 0, radius); } - this.endFill(); + this.stroke({ + width: style.outlineThickness, + color: style.outlineColor, + }).fill(style.color); + // this.endFill(); } /** diff --git a/packages/transformer/src/TransformerWireframe.ts b/packages/transformer/src/TransformerWireframe.ts index f29e8db9..24398c88 100644 --- a/packages/transformer/src/TransformerWireframe.ts +++ b/packages/transformer/src/TransformerWireframe.ts @@ -1,12 +1,14 @@ -import { Graphics } from '@pixi/graphics'; +// import { Graphics } from '@pixi/graphics'; import { HANDLE_TO_CURSOR } from './Transformer'; import { ObjectPoolFactory } from '@pixi-essentials/object-pool'; -import { Matrix, Point } from '@pixi/math'; +// import { Matrix, Point } from '@pixi/math'; import { distanceToLine } from './utils/distanceToLine'; import type { AxisAlignedBounds, OrientedBounds } from '@pixi-essentials/bounds'; import type { Handle, Transformer } from './Transformer'; -import {FederatedEventTarget} from "@pixi/events"; +// import {FederatedEventTarget} from "@pixi/events"; + +import { Graphics, Matrix, Point, FederatedEventTarget } from "pixi.js"; const pointPool = ObjectPoolFactory.build(Point); const tempHull = [new Point(), new Point(), new Point(), new Point()]; @@ -223,7 +225,7 @@ export class TransformerWireframe extends Graphics_ } // Fill polygon with ultra-low alpha to capture pointer events. - this.drawPolygon(hull); + this.poly(hull); } /** @@ -272,9 +274,10 @@ export class TransformerWireframe extends Graphics_ const boxScalingHandle = this.boxScalingHandles[i]; boxScalingHandle.clear() - .beginFill(0xffffff, 1e-4) - .drawPolygon(innerStart, outerStart, outerEnd, innerEnd) - .endFill(); + // .beginFill(0xffffff, 1e-4) + .fill({ color: 0xffffff, alpha: 1e-4 }) + .poly(innerStart, outerStart, outerEnd, innerEnd) + // .endFill(); } } @@ -326,7 +329,7 @@ export class TransformerWireframe extends Graphics_ boxRotationTemp[j + 1] = tempPoint.y + position.y; } - this.drawPolygon(boxRotationTemp.slice()); + this.poly(boxRotationTemp.slice()); } } diff --git a/packages/transformer/src/index.ts b/packages/transformer/src/index.ts index 58ac7382..9664d566 100644 --- a/packages/transformer/src/index.ts +++ b/packages/transformer/src/index.ts @@ -1,3 +1,5 @@ +import { Container, IFederatedContainer } from "pixi.js"; + export { Transformer } from './Transformer'; export { TransformerHandle } from './TransformerHandle'; export { TransformerWireframe } from './TransformerWireframe'; @@ -12,3 +14,11 @@ export type { ITransformerCursors, } from './Transformer'; export type { ITransformerHandleStyle } from './TransformerHandle'; + +export interface IFederatedDisplayObject extends IFederatedContainer {} + +export class DisplayObject extends Container { + constructor() { + super(); + } +} \ No newline at end of file diff --git a/packages/transformer/src/utils/decomposeTransform.ts b/packages/transformer/src/utils/decomposeTransform.ts index 57e7ef1d..0573b16e 100644 --- a/packages/transformer/src/utils/decomposeTransform.ts +++ b/packages/transformer/src/utils/decomposeTransform.ts @@ -1,4 +1,5 @@ -import type {Transform, Matrix, Point} from '@pixi/math'; +// import type {Transform, Matrix, Point} from '@pixi/math'; +import type {Transform, Matrix, Point} from 'pixi.js'; /** * Decomposes the matrix into transform, while preserving rotation & the pivot. diff --git a/packages/transformer/src/utils/distanceToLine.ts b/packages/transformer/src/utils/distanceToLine.ts index 936a1e45..178efee2 100644 --- a/packages/transformer/src/utils/distanceToLine.ts +++ b/packages/transformer/src/utils/distanceToLine.ts @@ -1,4 +1,5 @@ -import { Point } from '@pixi/math'; +// import { Point } from '@pixi/math'; +import { Point } from 'pixi.js'; /** * Calculates the distance of (x,y) from the line through l0 and l1. diff --git a/packages/transformer/src/utils/multiplyTransform.ts b/packages/transformer/src/utils/multiplyTransform.ts index 1249aab4..aad68d6d 100644 --- a/packages/transformer/src/utils/multiplyTransform.ts +++ b/packages/transformer/src/utils/multiplyTransform.ts @@ -1,7 +1,9 @@ -import { Matrix } from '@pixi/math'; -import { decomposeTransform } from './decomposeTransform'; +// import { Matrix } from '@pixi/math'; +import { Matrix, Container, Transform } from "pixi.js"; +import { decomposeTransform } from "./decomposeTransform"; -import type { DisplayObject } from '@pixi/display'; +// import type { DisplayObject } from '@pixi/display'; +interface DisplayObject extends Container {} const tempMatrix = new Matrix(); const tempParentMatrix = new Matrix(); @@ -14,24 +16,37 @@ const tempParentMatrix = new Matrix(); * @param transform * @param skipUpdate */ -export function multiplyTransform(displayObject: DisplayObject, transform: Matrix, skipUpdate?: boolean): void -{ - if (!skipUpdate) - { - const parent = !displayObject.parent ? displayObject.enableTempParent() : displayObject.parent; +export function multiplyTransform( + displayObject: DisplayObject, + transform: Matrix, + skipUpdate?: boolean +): void { + // if (!skipUpdate) + // { + // const parent = !displayObject.parent ? displayObject.enableTempParent() : displayObject.parent; - displayObject.updateTransform(); - displayObject.disableTempParent(parent); - } + // displayObject.updateTransform(); + // displayObject.disableTempParent(parent); + // } - const worldTransform = displayObject.worldTransform; - const parentTransform = displayObject.parent - ? tempParentMatrix.copyFrom(displayObject.parent.worldTransform) - : Matrix.IDENTITY; + const worldTransform = displayObject.worldTransform; + const parentTransform = displayObject.parent + ? tempParentMatrix.copyFrom(displayObject.parent.worldTransform) + : Matrix.IDENTITY; - tempMatrix.copyFrom(worldTransform); - tempMatrix.prepend(transform); - tempMatrix.prepend(parentTransform.invert());// gets new "local" transform + tempMatrix.copyFrom(worldTransform); + tempMatrix.prepend(transform); + tempMatrix.prepend(parentTransform.invert()); // gets new "local" transform - decomposeTransform(displayObject.transform, tempMatrix); + // decomposeTransform(displayObject.transform, tempMatrix); + decomposeTransform( + { + position: displayObject.position, + scale: displayObject.scale, + pivot: displayObject.pivot, + skew: displayObject.skew, + rotation: displayObject.rotation, + } as Transform, + tempMatrix + ); } diff --git a/packages/transformer/src/utils/skewTransform.ts b/packages/transformer/src/utils/skewTransform.ts index 3f1515a7..df4b325e 100644 --- a/packages/transformer/src/utils/skewTransform.ts +++ b/packages/transformer/src/utils/skewTransform.ts @@ -1,4 +1,5 @@ -import { Matrix } from '@pixi/math'; +// import { Matrix } from '@pixi/math'; +import { Matrix } from 'pixi.js'; const tempMatrix = new Matrix();