Commit: aafe1034bbe53b1e63996ec6eec6689ec9e80c8e
Author: Jacques Lucke
Date:   Tue Feb 12 19:12:32 2019 +0100
Branches: functions
https://developer.blender.org/rBaafe1034bbe53b1e63996ec6eec6689ec9e80c8e

store node tree pointer in modifier

Unfortunately, there are still issues with the COW system resulting in a crash.

===================================================================

M       release/scripts/startup/bl_ui/properties_data_modifier.py
M       source/blender/makesdna/DNA_modifier_types.h
M       source/blender/makesrna/intern/rna_modifier.c
M       source/blender/modifiers/intern/MOD_functiondeform.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py 
b/release/scripts/startup/bl_ui/properties_data_modifier.py
index ab277ff8ec4..8ec1feb14ad 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1636,6 +1636,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
     def FUNCTION_DEFORM(self,layout, ob, md):
         layout.prop(md, "control1")
         layout.prop(md, "control2")
+        layout.prop(md, "function_tree")
 
 
 class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
diff --git a/source/blender/makesdna/DNA_modifier_types.h 
b/source/blender/makesdna/DNA_modifier_types.h
index ab7f24ddbf0..2ddc8a22c6b 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1947,6 +1947,7 @@ typedef struct FunctionDeformModifierData {
        ModifierData modifier;
        float control1;
        int control2;
+       struct bNodeTree *function_tree;
 } FunctionDeformModifierData;
 
 #endif  /* __DNA_MODIFIER_TYPES_H__ */
diff --git a/source/blender/makesrna/intern/rna_modifier.c 
b/source/blender/makesrna/intern/rna_modifier.c
index f2fae8a7909..5d5e996216a 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -5077,6 +5077,11 @@ static void rna_def_modifier_function_deform(BlenderRNA 
*brna)
 
        prop = RNA_def_int(srna, "control2", 0, INT_MIN, INT_MAX, "Control 2", 
"", -10, 10);
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+       prop = RNA_def_property(srna, "function_tree", PROP_POINTER, PROP_NONE);
+       RNA_def_property_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Function Tree", "Function node tree");
+       RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
 }
 
 void RNA_def_modifier(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_functiondeform.c 
b/source/blender/modifiers/intern/MOD_functiondeform.c
index 79b93ac4bfb..421a572b2fa 100644
--- a/source/blender/modifiers/intern/MOD_functiondeform.c
+++ b/source/blender/modifiers/intern/MOD_functiondeform.c
@@ -36,6 +36,7 @@
 #include "BKE_mesh.h"
 #include "BKE_modifier.h"
 #include "BKE_scene.h"
+#include "BKE_library_query.h"
 
 #include "BKE_global.h"
 #include "BKE_main.h"
@@ -51,14 +52,11 @@
 
 #include "FN_functions.h"
 
-static bNodeTree *get_node_tree(void)
+static FnFunction get_current_function(FunctionDeformModifierData *fdmd)
 {
-       return (bNodeTree *)G.main->nodetree.first;
-}
-
-static FnFunction get_current_function(void)
-{
-       return FN_testing(get_node_tree());
+       bNodeTree *tree = fdmd->function_tree;
+       if (tree == NULL) return NULL;
+       return FN_testing(tree);
 }
 
 static void do_deformation(
@@ -66,8 +64,11 @@ static void do_deformation(
         float (*vertexCos)[3],
         int numVerts)
 {
-       FnFunction fn = get_current_function();
-       // FnFunction fn = FN_get_generated_function();
+       FnFunction fn = get_current_function(fdmd);
+       if (fn == NULL) {
+               return;
+       }
+
        FnCallable fn_call = FN_function_get_callable(fn);
        BLI_assert(fn_call);
 
@@ -124,10 +125,22 @@ static bool dependsOnTime(ModifierData *UNUSED(md))
 
 static void updateDepsgraph(ModifierData *md, const 
ModifierUpdateDepsgraphContext *ctx)
 {
-       FunctionDeformModifierData *UNUSED(fdmd) = (FunctionDeformModifierData 
*)md;
+       FunctionDeformModifierData *fdmd = (FunctionDeformModifierData *)md;
+
+       FnFunction fn = get_current_function(fdmd);
+       if (fn) {
+               FN_function_update_dependencies(fn, ctx->node);
+               FN_function_free(fn);
+       }
+}
+
+static void foreachIDLink(
+        ModifierData *md, Object *ob,
+        IDWalkFunc walk, void *userData)
+{
+       FunctionDeformModifierData *fdmd = (FunctionDeformModifierData *)md;
 
-       FnFunction fn = get_current_function();
-       FN_function_update_dependencies(fn, ctx->node);
+       walk(userData, ob, (ID **)&fdmd->function_tree, IDWALK_CB_USER);
 }
 
 
@@ -159,6 +172,6 @@ ModifierTypeInfo modifierType_FunctionDeform = {
        /* dependsOnTime */     dependsOnTime,
        /* dependsOnNormals */  NULL,
        /* foreachObjectLink */ NULL,
-       /* foreachIDLink */     NULL,
+       /* foreachIDLink */     foreachIDLink,
        /* foreachTexLink */    NULL,
 };
\ No newline at end of file

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to