Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/rigify
diff options
context:
space:
mode:
authorAlexander Gavrilov <angavrilov@gmail.com>2021-07-20 12:18:03 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2021-07-20 12:18:10 +0300
commite4d9cf84d00a6d223af3c89073858547090217ef (patch)
treeb161fc6f8d494afed440b04442e1c88123f8485d /rigify
parent1adb56d8b01cf1327f58c6fb8b1ccc8b7efd76ad (diff)
Rigify: clear driver errors after generation.
In the process of re-generating a rig, drivers that reference it from other objects can temporarily become invalid. This sets an error flag in the driver, stopping its evaluation, so the error doesn't clear out even when it becomes valid again. To fix stuck drivers, loop over all objects in the file after generation and refresh their drivers by fake modification.
Diffstat (limited to 'rigify')
-rw-r--r--rigify/generate.py4
-rw-r--r--rigify/utils/mechanism.py34
2 files changed, 38 insertions, 0 deletions
diff --git a/rigify/generate.py b/rigify/generate.py
index c6c9f3a9..aa9a9a84 100644
--- a/rigify/generate.py
+++ b/rigify/generate.py
@@ -29,6 +29,7 @@ from .utils.layers import ORG_LAYER, MCH_LAYER, DEF_LAYER, ROOT_LAYER
from .utils.naming import ORG_PREFIX, MCH_PREFIX, DEF_PREFIX, ROOT_NAME, make_original_name
from .utils.widgets import WGT_PREFIX
from .utils.widgets_special import create_root_widget
+from .utils.mechanism import refresh_all_drivers
from .utils.misc import gamma_correct, select_object
from .utils.collections import ensure_widget_collection, list_layer_collections, filter_layer_collections_by_object
from .utils.rig import get_rigify_type
@@ -540,6 +541,9 @@ class Generator(base_generate.BaseGenerator):
child.parent_bone = sub_parent
child.matrix_world = mat
+ # Clear any transient errors in drivers
+ refresh_all_drivers()
+
#----------------------------------
# Restore active collection
view_layer.active_layer_collection = self.layer_collection
diff --git a/rigify/utils/mechanism.py b/rigify/utils/mechanism.py
index 413d8a00..92e161f6 100644
--- a/rigify/utils/mechanism.py
+++ b/rigify/utils/mechanism.py
@@ -21,6 +21,8 @@
import bpy
import re
+from bpy.types import bpy_prop_collection, Material
+
from rna_prop_ui import rna_idprop_ui_create, rna_idprop_ui_prop_get
from rna_prop_ui import rna_idprop_quote_path as quote_property
@@ -519,6 +521,38 @@ def copy_custom_properties_with_ui(rig, src, dest_bone, *, ui_controls=None, **o
#=============================================
+# Driver management
+#=============================================
+
+def refresh_drivers(obj):
+ """Cause all drivers belonging to the object to be re-evaluated, clearing any errors."""
+
+ # Refresh object's own drivers if any
+ anim_data = getattr(obj, 'animation_data', None)
+
+ if anim_data:
+ for fcu in anim_data.drivers:
+ # Make a fake change to the driver
+ fcu.driver.type = fcu.driver.type
+
+ # Material node trees aren't in any lists
+ if isinstance(obj, Material):
+ refresh_drivers(obj.node_tree)
+
+
+def refresh_all_drivers():
+ """Cause all drivers in the file to be re-evaluated, clearing any errors."""
+
+ # Iterate over all datablocks in the file
+ for attr in dir(bpy.data):
+ coll = getattr(bpy.data, attr, None)
+
+ if isinstance(coll, bpy_prop_collection):
+ for item in coll:
+ refresh_drivers(item)
+
+
+#=============================================
# Utility mixin
#=============================================