How to get loc, rot, size relative to parent object

The following code does exactly what i need and it works perfectly for all situations i can imagine. However i wonder if that is the best way to do it:

void BCMatrix::set_transform(Object *ob)
    Matrix obmat_local;
    BKE_object_matrix_local_get(ob, obmat_local);
    copy_m4_m4(this->matrix, obmat_local);
    mat4_decompose(this->loc, this->q, this->size, obmat_local);
    quat_to_compatible_eul(this->rot, ob->rot, this->q);	


Is it possible to use ob->loc, ob->rot, ob->size instead of decomposing the local matrix? The problems show up as soon as i work on object hierarchies with parent inverse matrix data. For that case i can not figure out how to convert these values correctly so that i get the same results as from the code above.

Does it make sense at all to try this? If so where can i see an example for how to do that?

Just to clarify what exactly you want to be getting, as there are big differences to how you can approach these:

  1. Do you need the final (drivers + constraints affected) transforms relative to the parent (i.e. in parent space), or just the object’s local transform?
  2. Do you need the transform in any particular representation (i.e. always euler / quat / etc.)?

However, what you have seems to be ok. Was initially a bit surprised to see the mat4_decompose, but that’s probably because it didn’t exist when I last did this stuff :slight_smile:

The context: This is part of an animation sampler that steps over an animation and records object locations at given sample frames.

The reason for my question: I have the impression that the object matrix is somehow derived from the loc,rot,size data. So i would like to use the original and not the derivative data here if that makes sense.

  1. I need the transforms relative to the parent object.
  2. For the begin i am totally happy if i can get the same values as the method creates now. But i am also trying to be more flexible here, and for example allow “export as defined in user interface”. Like for example when an animation uses Quaternions, then export quaternion data, when it uses Euler, then export euler (in the correct mode)…

Ok, so the current pipeline looks something like:
Loc/Rot/Scale Properties -> Drivers -> Local Matrix -> Parenting -> Constraints -> Final Matrix

If you only care about the values the user inputs, then you can just read off the properties (checking on what the rotmode property says). (There’s a slight complication for object locations though due to the inverse parenting stuff, as the location data will be in global space still - Ton explained the reasons to me once, but I keep forgetting. We should really document that sometime though)

I’m still a bit confused if this is what you want here though… we may be using different terminology here.

Ok, the magic word was “Pipeline” here! Now it makes sense to me! i just did not know the exact nature of the connection between Loc/Rot/Scale and the Matrix data.

So to recap: The loc/rot/scale properties are at the begin of the pipeline, while the Matrix is at the end where all drivers and constraints have been applied. And that is actually the perfect location to get what i need for exporting. So i its all set and done :sunny: