Scale an entity to oblique direction


I’m trying to implement a specific scaling (affine transformation) function to make a lozenge shape based on plane or cube.

Where could I start to implement this? It seems like I can’t modify a matrix of an entity directly.

I guess you could write a matrix directly into the world transformation matrix of a pc.Entity (subclassed from pc.GraphNode). You can retrieve a reference to this matrix with getWorldTransform. You’re not normally supposed to write to this matrix - should be considered read-only. Normally, when the scene hierarchy is synchronized every frame, the world transform matrices are calculated from the local transform and the parent transform. But if the transform you want to scale (or any ancestor transform) is not dirtied every frame, it’s OK. Hmm. This is a bit hacky! :wink:

To do skewed scaling, I think you have to modify the fourth column of the matrix, which is normally 0, 0, 0, 1, I believe. But I’m not sure!

Hi will,
I’ve tried to edit data which obtained from getWorldTransform like below.

  obj.getWorldTransform().setScale(2, 2, 2);
  var m = obj.getWorldTransform().data;
  m[12] = 1.2;
  m[13] = 0.5;
  m[14] = 1.3;
  m[15] = 1.4;

But nothing happened. However, when I try normal way to scale an entity like below it is working.

obj.setLocalScale(2, 2, 2);

So, I guess Playcanvas blocks to modify the matrix directly.
And I wonder how can I bypass it.