Compensating transform from the Instance Object

   2458   2   1
User Avatar
Member
79 posts
Joined: Feb. 2008
Offline
Hello,

We have this problem with instances:

If you transform the instance object, all the instances transforms as well. I want to prevent that from happening.

Maybe there's a simpler way to achieve this, so please let me know if that's the case, but what I decided to do was to basically multiply the transformation matrix of the instance by the invert of the transformation matrix from it's instance object. That way, it would compensate the transformation and assume the instance object is always in a neutral transform.

So I wrote this VEX code:

@instance = "/obj/PigHead_Transformed";

matrix m = instance(@P, 0, @scale, 0, @orient, 0);
matrix m2 = invert( optransform(@instance) );
m = m2 * m;

vector trans = cracktransform(0, 0, 0, { 0, 0, 0 }, m);
vector rot = cracktransform(0, 0, 1, { 0, 0, 0 }, m);
vector scale1 = cracktransform(0, 0, 2, { 0, 0, 0 }, m);

@P = trans;
@scale = scale1;
@orient = quaternion((matrix3)m);


…and I'm having issues when I rotate my instance object. It looks like there's an issue with the transform order as it looks like the scale is done relative to the orientation. I tried various transformation order on the instance object transform and on the cracktransform function, but I could never get the instances transform to match the desired result.

Can someone help me figure out what I'm doing wrong?

Thanks.

Attachments:
InstanceInvertMatrix.JPG (59.6 KB)
compensateInstanceMasterTransform_wip01.hip (432.1 KB)

User Avatar
Staff
5161 posts
Joined: July 2005
Offline
I think you just need to add the “Instance Transform” parameter to the instance object, via Edit Parameter Interface, Render Properties, Mantra > Instance. Then turn it off.
User Avatar
Member
79 posts
Joined: Feb. 2008
Offline
Oh boy… that was well hidden. That's definitely the best way to go about this issue, but I'm still wondering what's wrong with my math? If I need to multiply some transform matrices in the future, how do I make sure they give me the desired result?
  • Quick Links