Commit Graph

157 Commits

Author SHA1 Message Date
Campbell Barton aec9e0e1b6 Cleanup: spelling, comments 2020-03-29 17:11:41 +11:00
Dalai Felinto 57daecc2cf Cleanup: Armature: Move to IDTypeInfo, and remove unused BKE API. 2020-03-06 16:43:09 +01:00
Bastien Montagne 4bfa256ea4 Refactor ID make local to use a single flag parameter.
Instead of using anonymous booleans flags, also allows to keep the same
behavior in all cases, without needing special handling from calling
code for our beloved oddballs object proxies...
2020-03-04 11:43:31 +01:00
Jacques Lucke 5de56f9596 Cleanup: make remaining blenkernel headers work in C++ 2020-03-02 15:07:49 +01:00
Alexander Gavrilov c23dbcf37d Bones: implement a new Aligned Inherit Scale mode.
Implement one more way of inheriting scale from the parent
bone, as an addition to the choices introduced in D5588.

This new mode inherits parent scale as if the parent and child
were not rotated relative to each other, always applying parent
X scale to child X scale and so forth. It is quite natural for
connected bone chains with coherent roll, like limbs or tentacles,
falling roughly between Average and Fix Shear in how closely
the parent scaling is followed.

Currently this can be achieved by using Inherit Scale: None plus
a Copy Scale with Offset from parent on the child; however, this
is cumbersome, and loses the distinction between true local and
inherited scale in the child's Local space.

This new mode also matches how the Before/After Original mix
modes work in the Copy Transforms constraint.

On the technical side this mode requires adding a right side
scale matrix multiplication into the Local<->Pose conversion,
in addition to the existing two left side matrices used for
location and orientation.

Differential Revision: https://developer.blender.org/D6099
2019-11-21 20:10:07 +03:00
Alexander Gavrilov fcf2a712ec Armature: add Inherit Scale options to remove shear or average the scale.
As an inherent property of matrix-based transformation math, non-
uniform scaling of a parent bone induces shear into the transform
matrix of any rotated child. Such matrices cannot be cleanly
decomposed into a combination of location/rotation/scale, which
causes issues for rigging and animation tools.

Blender bones have options to exclude rotation and/or scale from the
inherited transformation, but don't have any support for removing the
often undesired shear component. That goal requires replacing simple
parenting with a combination of multiple bones and constraints. The
same is true about the goal of inheriting some scale, but completely
avoiding shear.

This patch replaces the old Inherit Scale checkbox with a enum that
supports multiple options:

* Full: inherit all effects of scale, like with enabled Inherit Scale.

* Fix Shear: removes shear from the final inherited transformation.

  The cleanup math is specifically designed to preserve the main
  axis of the bone, its length and total volume, and minimally
  affect roll on average. It however will not prevent reappearance
  of shear due to local rotation of the child or its children.

* Average: inherit uniform scale that represents the parent volume.

  This is the simplest foolproof solution that will inherit some
  scale without ever causing shear.

* None: completely remove scale and shear.

* None (Legacy): old disabled Inherit Scale checkbox.

  This mode does not handle parent shear in any way, so the child
  is likely to end up having both scale and shear. It is retained
  for backward compatibility.

Since many rigging-related addons access the use_inherit_scale
property from Python, it is retained as a backward compatibility
stub that provides the old functionality.

As a side effect of reworking the code, this also fixes a matrix
multiplication order bug in the Inherit Rotation code, which caused
the parent local scale to be applied in world space. In rigger
opinion this option is useless in production rigs, so this fix
should not be a problem.

Reviewers: brecht

Differential Revision: https://developer.blender.org/D5588
2019-09-04 10:34:21 +03:00
Campbell Barton 6eadd40597 Cleanup: redundant struct declarations 2019-08-25 16:45:47 +10:00
Campbell Barton 30582c59cc Armature: add BKE_armature_transform
ED_armature_transform uses edit-mode conversion which re-creates bones.
Needed for efficiently transforming object-data in object-mode.
2019-08-23 11:53:28 +10:00
Campbell Barton adfb9ec87c Cleanup: const args, naming, doxy groups, clang-format 2019-08-23 09:09:38 +10:00
Sergey Sharybin 250995d67b Fix T67507: Set origin on armature moves incorrectly parented objects
Need to copy changes from original armature to evaluated one prior to
BKE_pose_where_is(), otherwise the pose matrix in pose channels will
not be correct.

Can not use dependency graph update here, since we must not re-evaluate
possible dependencies of the changed armature.

Reviewers: brecht

Reviewed By: brecht

Maniphest Tasks: T67507

Differential Revision: https://developer.blender.org/D5331
2019-07-26 10:15:39 +02:00
mano-wii 709f126e81 Fix T59713: Armature layer dots not updated on changes
`layer_used` runtime data, which controls the drawing of dots in the UI was not getting refreshed properly.
This used to happen in the drawing code, but was no longer working for reasons explained in:
{rB2b09062defa093a243b5fe64b099accb07b440a3}

The solution was to update each layer manually in the operators:
* ARMATURE_OT_bone_primitive_add
* ARMATURE_OT_delete
* ARMATURE_OT_dissolve
* ARMATURE_OT_fill
* ARMATURE_OT_merge
* ARMATURE_OT_separate
* ARMATURE_OT_bone_layers
* POSE_OT_bone_layers

Differential Revision: https://developer.blender.org/D5281
2019-07-17 14:17:34 -03:00
Alexander Gavrilov 26d2652d6d Armature: implement universal hash table lookup of Bone objects by name.
Since drivers on Bone properties are really supposed to be stored
in Armature data and access bones via its bones[] collection, this
lookup path should work efficiently.

Mass lookup of bones by name was already done through hashes,
but they were built temporarily every time that was needed. This
simply replaces it with a common hash table computed immediately
after file load, copy, or Edit to Object mode switch.
2019-05-14 21:56:57 +03:00
Campbell Barton 5915d1f453 BKE_pchan: add BKE_pchan_rot_to_mat3
Useful to get the un-scaled rotation from a pose channel.
2019-05-01 13:17:10 +10:00
Alexander Gavrilov ae054af14f Cleanup: rename the curveInX etc bbone DNA fields to curve_in_x etc. 2019-04-23 13:45:04 +03:00
Alexander Gavrilov 624e93bbef B-Bones: split the Scale In/Out properties into X and Y values.
As far as I can tell, there is no technical reason why the B-Bone
segment thickness scaling can't be separated into two axes. The
only downside is the increase in complexity of the B-Bone settings,
but this is inevitable due to the increase in flexibility.

Updating the file is somewhat complicated though, because F-Curves
and drivers have to be duplicated and updated to the new names.

Reviewers: campbellbarton

Subscribers: icappiello, jpbouza

Differential Revision: https://developer.blender.org/D4716
2019-04-23 13:45:03 +03:00
Alexander Gavrilov 638938e5a8 Armature: remove remains of the object-level deformation data cache.
Now that B-Bone shape data is kept in bPoseChannel_Runtime, the
armature level cache only holds one quaternion value per bone.
It can also be moved to runtime, and the structure removed.

This has an additional effect that, as far as I can tell, now
the Armature modifier can run as soon as all of the bones it
actually needs are done, thus making T59848 a purely depsgraph
level problem.
2019-04-18 23:19:44 +03:00
Campbell Barton e12c08e8d1 ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.

For details on usage and instructions for migrating branches
without conflicts, see:

https://wiki.blender.org/wiki/Tools/ClangFormat
2019-04-17 06:21:24 +02:00
Alexander Gavrilov 3731729b96 Depsgraph: fix hard CTD on dependency cycles through POSE_INIT.
As reported in T63582, it can cause chan_array to be not ready.
To reliably avoid crashing, the only easy way seems to be to
create the index during COW -- maybe @sergey has a better idea.
2019-04-14 21:55:30 +03:00
Alexander Gavrilov 51c8a6f491 Fix T37500: implement Bendy bone segment deformation interpolation.
Previously B-Bone deformation mapped every vertex to just one
B-Bone segment. This results in abrupt transformation differences
between the sides of each threshold plane, reducing the quality
of B-Bone deformation and making the use of shape keys impractical.

This commit replaces this approach with a linear blend between
the two closest segment transformations, effectively representing
the B-Bone as two weight-blended plain bones for each vertex.

In order to distribute the interpolation more evenly along the
bone, segment matrices for deformation are now computed at points
between the segments and at the ends of the B-Bone. The computation
also uses the true tangents of the Bezier curve for the orientation.
The nodes at the end of the bone require some special handling to
deal with zero-length Bezier handles caused by a zero ease value.

The Copy Transforms constraint now also smoothly interpolates
rotation and scaling along the bone shape when enabled.

The initial version of the patch was submitted by @Sam200.

Differential Revision: https://developer.blender.org/D4635
2019-04-13 16:27:42 +03:00
Campbell Barton de13d0a80c doxygen: add newline after \file
While \file doesn't need an argument, it can't have another doxy
command after it.
2019-02-18 08:22:12 +11:00
Campbell Barton eef4077f18 Cleanup: remove redundant doxygen \file argument
Move \ingroup onto same line to be more compact and
make it clear the file is in the group.
2019-02-06 15:45:22 +11:00
Campbell Barton 4ef09cf937 Cleanup: remove author/date info from doxy headers 2019-02-02 11:58:24 +11:00
Campbell Barton 65ec7ec524 Cleanup: remove redundant, invalid info from headers
BF-admins agree to remove header information that isn't useful,
to reduce noise.

- BEGIN/END license blocks

  Developers should add non license comments as separate comment blocks.
  No need for separator text.

- Contributors

  This is often invalid, outdated or misleading
  especially when splitting files.

  It's more useful to git-blame to find out who has developed the code.

See P901 for script to perform these edits.
2019-02-02 01:36:28 +11:00
Campbell Barton c0f88ed8a8 Cleanup: sort forward declarations of enum & struct
Done using:
  source/tools/utils_maintenance/c_sort_blocks.py
2019-01-28 21:17:58 +11:00
Campbell Barton 320e7f5322 Cleanup: naming 2018-12-20 17:34:30 +11:00
Alexander Gavrilov 48a3f97b23 RNA: provide access to bone parent transform math from Python.
Applying the effect of bone parent is much more complicated than
simple matrix multiplication because of the various flags like
Inherit Scale. Thus it is reasonable to provide access to this
math from Python for complicated rest pose related manipulations.

The simple case of this is handled by Object.convert_space, so
the new method is only needed for complex tasks.

Differential Revision: https://developer.blender.org/D4053
2018-12-11 20:40:51 +03:00
Sergey Sharybin 5bd485844c Cleanup: Variable naming 2018-12-10 15:54:45 +01:00
Campbell Barton 55b31dd98c Merge branch 'master' into blender2.8 2018-12-02 14:37:04 +11:00
Campbell Barton 335e1b507b Cleanup: BKE b-bone API naming
Use BKE_pchan_bbone prefix.
2018-12-02 14:29:54 +11:00
Alexander Gavrilov a58f0eea4f RNA: expose access to B-Bone shape data from Python.
B-Bone shape is a non-trivial computation, so access to
the results would be useful for Python scripts working with
B-Bones, e.g. rig generation.

This exposes both final segment matrices, and the tangent
vectors computed from the custom handle bones.

Since the handle tangents use the axis+roll orientation math
of edit bones, add matrix conversion static methods to Bone.

Reviewers: campbellbarton

Differential Revision: https://developer.blender.org/D3983
2018-11-27 09:31:34 +03:00
Alexander Gavrilov 1e820898ff Depsgraph: add a new operation node for computing B-Bone segments.
Computing the shape of a B-Bone is a quite expensive operation, and
there are multiple constraints that can access this information in
a variety of useful ways. This means computing the shape once per
bone and saving it is good for performance.

Since the shape may depend on the position of up to two other bones,
often in a "cyclic" manner, this computation has to be a separate
node with its own dependencies.

Reviewers: sergey

Differential Revision: https://developer.blender.org/D3975
2018-11-23 23:19:23 +03:00
Sergey Sharybin ce6d1e890c Cleanup: Use proper module prefix in function names 2018-11-22 16:35:12 +01:00
Sergey Sharybin 4dc639ac99 Speedup rigs with multiple objects deformed by bbones
Previously each of the objects which has armature modifier will
request deformation matricies from bbones. Thing is, all those
deformations are the same and do not depend on object which is
being modified. What's even worse is that this calculation is
not cheap.

This change makes it so bbones deformation is calculated once
and stored in the armature object. After this armature modifiers
simply use it.

With a rigs we've got here dependency graph evaluation time
goes down from 0.02 sec to 0.012 sec.

Possible further optimization is to make bbone deformation
calculated at the time when bone is calculated. This will avoid
an extra threaded loop over all bones.
2018-11-20 15:53:59 +01:00
Sergey Sharybin 7b271d5fc1 Depsgraph: Ensure dependency cycle does not clear runtime memory
If there was a dependency cycle involved, it was possible that pchan
array will be freed before all bones are evaluated. Now clear is
done in a dedicated node, which is never a part of dependency cycle.
2018-11-07 15:06:39 +01:00
Campbell Barton 25a9816c30 Cleanup: use bool 2018-11-05 13:22:49 +11:00
Alexander Gavrilov 748b89f124 Allow changing B-Bone custom handle references from Pose Mode.
@jpbouza was rather upset these were made read-only, and unlike
parents, it's not that hard to allow changing these Bone fields:
all is needed is to carefully refresh the matching fields in the
relevant bPoseChannel objects and properly tag update.

Reviewers: brecht

Differential Revision: https://developer.blender.org/D3870
2018-10-31 20:04:01 +03:00
Alexander Gavrilov a33a4e132e Add and use a utility for computing B-Bone roll from custom handles.
This also fixes a stability problem with the start handle
due to an incorrect matrix multiplication order.
2018-10-05 21:52:01 +03:00
Alexander Gavrilov 65f77ccea1 Fix T56268: display the correct rest shape for B-Bones in Edit Mode.
The rest shape of B-Bones is actually affected by custom handles or
the default connected parent/child mechanism. Ignoring these effects
thus leads to the edit mode shape being different from the actual
rest pose.

This splits the b_bone_spline_setup function that is used to compute
the correct rest and pose shape from pose channels into two parts,
and applies the data structure independent half to edit mode.

In order to access the custom handle settings in Edit Mode, they are
moved to Bone and EditBone, while the bPoseChannel fields are downgraded
in status to a cache for performance. Also, instead of flags, introduce
an enum to specify the handle operation modes, so that new ones could
be added later.

Reviewers: aligorith, brecht

Differential Revision: https://developer.blender.org/D3588
2018-10-04 19:55:44 +03:00
Brecht Van Lommel 253dce07d7 Merge branch 'master' into blender2.8 2018-09-24 17:42:52 +02:00
Brecht Van Lommel 0cff044d84 Spelling fixes in comments and descriptions, patch by luzpaz.
Differential Revision: https://developer.blender.org/D3719
2018-09-24 17:28:40 +02:00
Alexander Gavrilov a5aeca4a64 Fix dependency graph for constraints depending on B-Bone shape.
Some constraints have an option to take the final bezier shape of
the target B-Bone into account. This shape usually depends on two
other bones in addition to the target itself, so the graph should
include the relevant dependencies.

Reviewers: sergey

Differential Revision: https://developer.blender.org/D3591
2018-08-13 19:02:49 +03:00
Sergey Sharybin bb7b1cc884 Fix T56170: Fake dependency cycle in new depsgraph + interleaved armature update + proxy
Make proxy copy result more atomic operation.
2018-07-31 13:24:57 +02:00
Sergey Sharybin 1fd27c2332 Respect ID user count when creating pose on object copy
This solves wrong user counter of custom shape when duplicating bone
few times and then undoing all the duplications.
2018-07-31 11:39:22 +02:00
Bastien Montagne c205de0203 Fix T55973: [2.8] Crash when 'apply pose as rest pose' when bone scale is 0,0,0.
`BKE_pose_rebuild()` should (ideally) always trigger a rebuild of the
depsgraph, since it can add or remove posechannels.

This function now takes a Main parameter to ensure that related
depsgraphes are tagged as dirty (kept it optional, for some corner cases).

We should also probably double-check calls to that function, think in
theory it should only be called from depsgraph itself? But for now...
2018-07-20 10:22:06 +02:00
Campbell Barton 18d87e79e9 Merge branch 'master' into blender2.8 2018-06-29 09:25:40 +02:00
Campbell Barton b372766816 Cleanup: trailing newlines 2018-06-29 09:23:51 +02:00
Campbell Barton 06a1a66a9b Merge branch 'master' into blender2.8 2018-06-17 17:10:19 +02:00
Campbell Barton 6fc8a74886 Cleanup: trailing space for blenkernel 2018-06-17 17:05:51 +02:00
Campbell Barton fa69ce9e3a Cleanup: whitespace, duplicate includes 2018-05-08 16:57:07 +02:00
Sergey Sharybin d8b43a8066 Depsgraph: Make sure evaluated pose channels are pointing to evaluated bones 2018-05-03 16:11:07 +02:00