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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gavrilov <angavrilov@gmail.com>2019-08-22 15:40:10 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2019-08-22 15:46:37 +0300
commit8f578150eaf494a03bed7389046e44f2bdf7d748 (patch)
tree5370042609d04907eff0a154e8a4b6ae858af182 /source/blender/editors/animation/drivers.c
parent443586f34d3a0730c67b5d8787e519bec2af3656 (diff)
Fix T68971: Copy As New Driver from Material node creates a bad reference.
NodeTree structures of materials and some other data blocks are effectively node group data block objects that are contained inside the parent block. Thus, direct references to them are only valid while blender is running, and are lost on save. Fix Copy As New Driver to create a reference that goes through the owner data block, by adding a new runtime field to bNodeTree.
Diffstat (limited to 'source/blender/editors/animation/drivers.c')
-rw-r--r--source/blender/editors/animation/drivers.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c
index e341a16378c..bf2056a7ec6 100644
--- a/source/blender/editors/animation/drivers.c
+++ b/source/blender/editors/animation/drivers.c
@@ -846,6 +846,36 @@ bool ANIM_driver_vars_paste(ReportList *reports, FCurve *fcu, bool replace)
/* -------------------------------------------------- */
+/** Compute an ID pointer and path to property valid for use in a driver.
+ * Corrects for ID references that are not independent (e.g. material NodeTree). */
+bool ANIM_get_target_ID_and_path_to_property(
+ PointerRNA *ptr, PropertyRNA *prop, int index, ID **r_id, char **r_path)
+{
+ int dim = RNA_property_array_dimension(ptr, prop, NULL);
+ char *path = RNA_path_from_ID_to_property_index(ptr, prop, dim, index);
+ ID *id = ptr->id.data;
+
+ if (!path) {
+ return false;
+ }
+
+ if (GS(id->name) == ID_NT) {
+ bNodeTree *node_tree = (bNodeTree *)id;
+
+ if (node_tree->owner) {
+ id = node_tree->owner;
+
+ char *new_path = BLI_sprintfN("node_tree%s%s", path[0] == '[' ? "" : ".", path);
+ MEM_freeN(path);
+ path = new_path;
+ }
+ }
+
+ *r_id = id;
+ *r_path = path;
+ return true;
+}
+
/* Create a driver & variable that reads the specified property,
* and store it in the buffers for Paste Driver and Paste Variables. */
void ANIM_copy_as_driver(struct ID *target_id, const char *target_path, const char *var_name)