|
@@ -9,43 +9,49 @@ import { Group } from "konva/lib/Group";
|
|
|
import { Rect } from "konva/lib/shapes/Rect";
|
|
|
import { Transform } from "konva/lib/Util";
|
|
|
import { MathUtils } from "three";
|
|
|
+import { nextTick } from "vue";
|
|
|
|
|
|
export class EditPoi<T extends PoiAttrib = PoiAttrib> extends Poi<T> {
|
|
|
initShape() {
|
|
|
const group = super.initShape() as Group;
|
|
|
const rect = group.findOne<Rect>(".rect");
|
|
|
- const parent = rect.parent;
|
|
|
const tf = new Transformer({
|
|
|
visible: false,
|
|
|
- name: "tf",
|
|
|
- resizeEnabled: false,
|
|
|
- nodes: [rect],
|
|
|
+ name: "tf" + this.attrib.id,
|
|
|
+ resizeEnabled: true,
|
|
|
+ nodes: [group],
|
|
|
});
|
|
|
- parent.add(tf);
|
|
|
+ setTimeout(() => {
|
|
|
+ const parent = group.parent;
|
|
|
+ parent.add(tf);
|
|
|
+ }, 100);
|
|
|
|
|
|
- const initRect = {
|
|
|
- rotation: rect.rotation(),
|
|
|
- position: { ...rect.position() },
|
|
|
- scale: { ...rect.scale() },
|
|
|
- };
|
|
|
+ // const initRect = {
|
|
|
+ // rotation: rect.rotation(),
|
|
|
+ // position: { ...rect.position() },
|
|
|
+ // scale: { ...rect.scale() },
|
|
|
+ // };
|
|
|
let needUpdate = false;
|
|
|
- rect.on("transformstart", () => {
|
|
|
+ group.on("transformstart", () => {
|
|
|
needUpdate = false;
|
|
|
console.log("start");
|
|
|
this.container.bus.emit("dataChangeBefore");
|
|
|
});
|
|
|
- rect.on("transform", () => {
|
|
|
- const rotation = tf.rotation();
|
|
|
- rect.rotation(initRect.rotation);
|
|
|
- rect.position(initRect.position);
|
|
|
- rect.scale(initRect.scale);
|
|
|
- if ((this.attrib.rotate || 0) !== rotation) {
|
|
|
- needUpdate = true;
|
|
|
- this.attrib.rotate = rotation;
|
|
|
- this.diffRedraw();
|
|
|
- }
|
|
|
+ group.on("transform", () => {
|
|
|
+ // const rotation = rect.rotation();
|
|
|
+ // const scale = rect.scale();
|
|
|
+ // const position = rect.position();
|
|
|
+ const dec = group.getTransform().decompose();
|
|
|
+ needUpdate = true;
|
|
|
+ this.attrib.rotate = dec.rotation;
|
|
|
+ this.attrib.scaleX = dec.scaleX;
|
|
|
+ this.attrib.scaleY = dec.scaleY;
|
|
|
+ this.attrib.x = dec.x;
|
|
|
+ this.attrib.y = dec.y;
|
|
|
+ this.diffRedraw();
|
|
|
+ tf.forceUpdate();
|
|
|
});
|
|
|
- rect.on("transformend", () => {
|
|
|
+ group.on("transformend", () => {
|
|
|
if (needUpdate) {
|
|
|
this.container.bus.emit("dataChange");
|
|
|
}
|