Modifying intrinsic transformation of packed primitives

   6998   2   2
User Avatar
Member
23 posts
Joined: April 2018
Offline
Hello,
I have a problem when modifying the transformation of packed primitives after they are created and placed (I use a “copytopoints” set to “Pack and Instance” to place one at the midpoint of each curve segment)
After a while I figured out how to rotate and scale them afterwards using their intrinsic transformation matrix. Unfortunately, it doesn’t work in every case, some instances get the wrong transformations and I can’t figure out why:



This is my code:
#include <math.h>

//read transformation from spare parameters
vector t, r,s;
t = chv('translate');
r = chv('rotate');
s = chv('scale');

//get intrinsic transforms from packed primitives
matrix3 transformIntrinsic = primintrinsic(0, "transform", @primnum);

//extract orientation vector for each point to use as pivot rotation
vector orientvector = cracktransform(XFORM_TRS, XFORM_XYZ, 1, @P, transformIntrinsic);

//create transformation matrix
matrix m = maketransform( XFORM_SRT, XFORM_XYZ, t, r, s, @P, orientvector);

//multiply with transformation matrix and set as new ntrinsic transforms
transformIntrinsic *= matrix3(m);
setprimintrinsic(0, "transform", @primnum, transformIntrinsic);

(using packedtransform() to apply the transformation works too, but doesn’t make any difference)

I thought the reason could be the polyframe node that I’m using to get the initial placing, since I noticed that in some cases it generates wrong (or no) values, but the result directly after the copytopoints node are correct.
(Actually, I could work around this by modifying the values before instancing them, which can be tested with the switch node in the example file, but I’d rather do it the other way)

Any ideas why it doesn’t work the same for every packed prim?
(I attached my test scene)

Attachments:
OrientPackedPrimitives.png (294.3 KB)
OrientPackedPrimitives_Tree.png (67.8 KB)
OrientingPackedPrims_Test.hip (157.0 KB)

User Avatar
Member
504 posts
Joined: July 2005
Offline
Hi,

it seems to work, if you change the order in cracktransform from XFORM_TRS -> XFORM_SRT (or anything where scale is applied before

rotation).
User Avatar
Member
23 posts
Joined: April 2018
Offline
Aizatulin
Hi,

it seems to work, if you change the order in cracktransform from XFORM_TRS -> XFORM_SRT (or anything where scale is applied before

rotation).
Indeed, that works!
Don't really understand why, but who asks as long as it works..
I guess that with “TRS” it's sometimes missing some information to create the orientation vector (seems also it has something to to with how the objects are originally orientated, if they have rotations in all 3 axis then it works correct, even with TRS.)

Thank you very much for taking the time!
  • Quick Links