Jump to content

copying alembic transforms to packed pieces


Recommended Posts

Hello,

I'm working on a project and I'm a bit stuck on matrix transformation. I don't have a strong background in matrix manipulation. Here is what I am trying to do: I have a packed alembic that has been created from an external program. The alembic has a fullpackedtransform intrinsic that contains my translate, rotate, scale and shear data. I want to shatter this alembic geometry, pack the shatter pieces and use the original alembic transform to animate the pieces which will then be input into a rigid body simulation. I'm having trouble extracting the relevant data from the 4x4 matrix on the alembic. I can get my points to translate, but I don't yet understand how to make them rotate. I hope my diagram makes sense. 

transformPieces.jpg

Link to comment
Share on other sites

Ah ha. I've figured this one out. What wonderful late nights in the office can do. For posterity:

To translate the pieces you can use a single point wrangle. You need you pieces (duh) as a input, the animated alembic and a rest alembic (probably the same frame that made the pieces). You extract the 4x4 transforms from anim and rest. Use cracktransform to extract translate, rotate and scale. Offset you piece position by rest translate. Subtract animated rotation from rest rotation, so that your starting rotation is zero. Use the maketransform command with your animated translate, offset rotation and in my case I wanted to ignore scale so that was set to {1,1,1}.

You can set position to your offset position * you new matrix. For each piece rotation you set the "transform" intrinsic to the matrix3 of your new matrix.

// current position
vector old_pos = @P;

// get packed transform matrices
matrix anim = primintrinsic(1, 'packedfulltransform', 0);
matrix rest = primintrinsic(2, 'packedfulltransform', 0);

// extract transforms
vector anim_t, anim_r, anim_s, rest_t, rest_r, rest_s;
cracktransform(0, 0, {0,0,0}, anim, anim_t, anim_r, anim_s);
cracktransform(0, 0, {0,0,0}, rest, rest_t, rest_r, rest_s);

// offset position
vector pos = old_pos - rest_t;

// offest rotation
vector r = anim_r - rest_r;

// create new transform assuming scale
matrix m = maketransform(0, 0, anim_t, r, {1,1,1});
@P = pos * m;

// create new rotation matrix
matrix3 rm = set(m);
setprimintrinsic(0, 'transform', @ptnum, rm, 'set');

 

  • Like 1
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.

×
×
  • Create New...