Jump to content

Pixijs editor


Handzo
 Share

Recommended Posts

Hello! I wanna make graphical editor base on pixijs! And I have several problems.

1) Scene consists of multiple PIXI.Graphics (component). Each component has bounding box shown when you edit component. If you drag bounding box corner the component should scale up/down (standard behaviour for graphical editor). Each component may consists of several components. I've managed to make it work. But if I flip horizontally several components. All calculations work abnormally. Same thing with rotation;

{
  name: "root",
  scale: { x: -1 },
  children: [
    {
      name: "comp1",
  	  scale: { x: -1 },
      children: [
        {
          name: "comp2",
  		  scale: { x: -1 },
        }
      ]
    }
  ]
}

All works as suppose to as long as all components have scale.x > 0 and scale.y > 0. Otherwise I have to get scale sign up to stage. Any suggestions? Maybe I should use transform directly?
2)  I need to draw bounding box on top of all components. Currently I am using pixi-layers. Each component has bounding box (PIXI.Graphics) as component child. And component.parentLayer = boundsLayer. It works, but I don't think it is best solution.

Link to comment
Share on other sites

  • 2 weeks later...

Still can not solve the problem with rotation. Example:

RotateGrip instance attached to Component (PIXI.Graphics) which I to want to rotate;

class RotateGrip extends PIXI.Graphics {
    constructor() {
        super();
 
        this._isRotating = false;
        this.interactive = true;
        this.on('pointerdown', this.onRotateStart, this);
        this.on('pointerup', this.onRotateEnd, this);
        this.on('pointerupoutside', this.onRotateEnd, this);
    }
 
    onRotateStart(event) {      
        if (this._isRotating)
            return;
        this._isRotating = true;
        this.on('pointermove', this.onRotate, this);
        
        this.globalPivot = this.parent.toGlobal(this.parent.pivot);
        this.prevPoint = event.data.global;
        this.prevPoint.x -= this.globalPivot.x;
        this.prevPoint.y -= this.globalPivot.y;
    }
 
    onRotateEnd() {
        if (!this._isRotating)
            return;
        this._isRotating = false;
        this.off('pointermove', this.onRotate, this);
    }
 
    onRotate(event) {
        if (!this._isRotating)
            return;
 
        // current position relative to global parent pivot
        const p = event.data.global;
        p.x -= this.globalPivot.x;
        p.y -= this.globalPivot.y;
 
        // angle between prevPoint and p vectors
        const angle = Math.atan2(-this.startPoint.y, this.startPoint.x) - Math.atan2(-p.y, p.x);
 
        // rotate matrix around globalPivot
        const m = this.parent.worldTransform.clone();
        m.translate(-this.globalPivot.x, -this.globalPivot.y);
        m.rotate(angle);
        m.translate(this.globalPivot.x, this.globalPivot.y);
 
        this.parent.transform.setFromMatrix(m);
      
      	this.prevPoint.x = p.x;
      	this.prevPoint.y = p.y;
    }
}

It doesn't work as I thought it should.

1) I'm getting halved angle. It works if I will do m.rotate(angle*2) I can't figure out why);

2) If I have such structure:

{
  root: {
    scale: { x: -0,5, y: -0.5 },
    children: [
      component: {
      	children: [
      	  RotateGrip: {}
    	]
      }
    ]
  }
}

I'm rotating 'component' object  with my RotatgeGrip,

// rotate matrix around globalPivot
const m = this.parent.worldTransform.clone();
m.translate(-this.globalPivot.x, -this.globalPivot.y);
m.rotate(angle);
m.translate(this.globalPivot.x, this.globalPivot.y);

// matrix m scale factor = 0.05, if I decompose it to parent transform
// scale factor applies to localTransorm as well, Math.abs(this.parent.scale.x) === 0.5 and Math.abs(this.parent.scale.y) === 0.5
this.parent.transform.setFromMatrix(m);

Is there any way to apply rotation ignoring scale?

Edited by Handzo
Link to comment
Share on other sites

I solve problems but it leads me to another one. I have global rotation angle, how do I get sign of rotation. scale affects on rotation sign. And components, which have ascendents flipped by xAxis or yAxis, rotating in wrong direction

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...