Add docs for how object's stored transforms work #23

Open
Nathan Vegdahl wants to merge 4 commits from nathanvegdahl/blender-developer-docs:stored_object_transforms into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Showing only changes of commit dbac7ff490 - Show all commits

View File

@ -137,7 +137,7 @@ be more or less complex. Steps in **bold** are rather mandatory.
## Stored Transforms ## Stored Transforms
Each object has a set of source-of-truth (i.e. not derived or cached) transforms Each object has a set of source-of-truth (i.e. not derived or cached) transforms
stored directly in its DNA, in the `Object` struct in `DNA_object_types.h`. stored directly in its DNA, in the `Object` struct in *DNA_object_types.h*.
These specify the aspects of an object's transforms that are independent of These specify the aspects of an object's transforms that are independent of
other objects in the scene, and which do not result from constraints, etc. other objects in the scene, and which do not result from constraints, etc.
@ -157,23 +157,15 @@ After the base transform, there are the delta transforms, stored in the `dloc`,
`drot`, and `dscale` properties. These can also be set by the user, and `drot`, and `dscale` properties. These can also be set by the user, and
effectively define a "rest position" for the object. effectively define a "rest position" for the object.
`loc`/`rot`/`scale` and `dloc`/`drot`/`dscale` are combined into a whole `loc`/`dloc`, `rot`/`drot`, and `scale`/`dscale` are first combined as pairs
transform as follows: (e.g. `loc` with `dloc`), and then assembled together into a transform matrix
afterward.
1. `loc` and `dloc` are simply added together as vectors.
2. `rot` and `drot` are combined by first creating a 3x3 matrix for each, and
then multiplying them together. The multiplication order is equivalent to
first applying `rot`'s rotation to the object and then applying `drot`'s
rotation.
3. `scale` and `dscale` are simply component-wise multiplied together.
4. Finally, the results of the previous steps are all combined together into a
single transform matrix.
> NOTE: Quaternion and axis-angle rotation modes also have corresponding `d*` > NOTE: Quaternion and axis-angle rotation modes also have corresponding `d*`
> properties for delta transforms, for when the object is in those respective > properties for delta transforms, for when the object is in those respective
> rotation modes. They are applied the same way as `drot`. > rotation modes. They are applied the same way as `drot`.
The relevant code for this is in `blenkernel/intern/object.cc` in the functions The relevant code for this is in *blenkernel/intern/object.cc* in the functions
`BKE_object_scale_to_mat3`, `BKE_object_rot_to_mat3`, `BKE_object_to_mat3`, and `BKE_object_scale_to_mat3`, `BKE_object_rot_to_mat3`, `BKE_object_to_mat3`, and
`BKE_object_to_mat4`. `BKE_object_to_mat4`.
@ -194,5 +186,5 @@ automatically set to the inverse of the parent's transform *at the time the
parent-child relationship is created*. It is specifically *not* updated to parent-child relationship is created*. It is specifically *not* updated to
continuously match the parent's inverse. continuously match the parent's inverse.
The relevant code for this is in `blenkernel/intern/object.cc` in the function The relevant code for applying this transform is in *blenkernel/intern/object.cc* in the function
`BKE_object_apply_mat4_ex`. `BKE_object_apply_mat4_ex`.