RNA: support setting default values for custom properties.

NLA requires a usable default value for all properties that
are to be animated via it, without any exceptions. This is
the real cause of T36496: using the default of 0 for a scale
related custom property obviously doesn't work.

Thus, to really fix this it is necessary to support configurable
default values for custom properties, which are very frequently
used in rigs for auxiliary settings. For common use it is enough
to support this for scalar float and integer properties.

The default can be set via the custom property configuration
popup, or a right click menu option. In addition, to help in
updating old rigs, an operator that saves current values as
defaults for all object and bone properties is added.

Reviewers: campbellbarton, brecht

Differential Revision: https://developer.blender.org/D4084
This commit is contained in:
Alexander Gavrilov
2018-12-15 22:37:12 +03:00
parent 908a274240
commit 61c941f040
8 changed files with 350 additions and 9 deletions

View File

@@ -943,6 +943,49 @@ class LoadReferenceImage(LoadImageAsEmpty, Operator):
pass
class OBJECT_OT_assign_property_defaults(Operator):
"""Assign the current values of custom properties as their defaults, for use as part of the rest pose state in NLA track mixing"""
bl_idname = "object.assign_property_defaults"
bl_label = "Assign Custom Property Values as Default"
bl_options = {'UNDO', 'REGISTER'}
process_data: BoolProperty(name="Process data properties", default=True)
process_bones: BoolProperty(name="Process bone properties", default=True)
@classmethod
def poll(cls, context):
obj = context.active_object
return obj is not None and obj.library is None and obj.mode in {'POSE', 'OBJECT'}
@staticmethod
def assign_defaults(obj):
from rna_prop_ui import rna_idprop_ui_prop_default_set
rna_properties = {'_RNA_UI'} | {prop.identifier for prop in obj.bl_rna.properties if prop.is_runtime}
for prop, value in obj.items():
if prop not in rna_properties:
rna_idprop_ui_prop_default_set(obj, prop, value)
def execute(self, context):
obj = context.active_object
self.assign_defaults(obj)
if self.process_bones and obj.pose:
for pbone in obj.pose.bones:
self.assign_defaults(pbone)
if self.process_data and obj.data and obj.data.library is None:
self.assign_defaults(obj.data)
if self.process_bones and isinstance(obj.data, bpy.types.Armature):
for bone in obj.data.bones:
self.assign_defaults(bone)
return {'FINISHED'}
classes = (
ClearAllRestrictRender,
DupliOffsetFromCursor,
@@ -958,4 +1001,5 @@ classes = (
SubdivisionSet,
TransformsToDeltas,
TransformsToDeltasAnim,
OBJECT_OT_assign_property_defaults,
)