[Bf-blender-cvs] [8b08366e326] temp-test-point-cloud-simulation-depsgraph-integration: initial node tree embedding and simulation editor

Jacques Lucke noreply at git.blender.org
Wed Apr 15 18:27:08 CEST 2020


Commit: 8b08366e326556fd2fe2846da62ceea18b02a154
Author: Jacques Lucke
Date:   Tue Mar 31 14:05:58 2020 +0200
Branches: temp-test-point-cloud-simulation-depsgraph-integration
https://developer.blender.org/rB8b08366e326556fd2fe2846da62ceea18b02a154

initial node tree embedding and simulation editor

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

M	release/scripts/startup/bl_ui/space_node.py
M	source/blender/blenkernel/intern/node.c
M	source/blender/blenkernel/intern/simulation.cc
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/makesdna/DNA_simulation_types.h
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesrna/intern/rna_simulation.c
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/release/scripts/startup/bl_ui/space_node.py b/release/scripts/startup/bl_ui/space_node.py
index bdda0ebbe9a..580a531c79c 100644
--- a/release/scripts/startup/bl_ui/space_node.py
+++ b/release/scripts/startup/bl_ui/space_node.py
@@ -151,6 +151,9 @@ class NODE_HT_header(Header):
             if snode_id:
                 layout.prop(snode_id, "use_nodes")
 
+        elif snode.tree_type == 'SimulationNodeTree':
+            layout.prop(snode, "simulation")
+
         else:
             # Custom node tree is edited as independent ID block
             NODE_MT_editor_menus.draw_collapsible(context, layout)
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index cc04d235783..c9755a4da24 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -37,6 +37,7 @@
 #include "DNA_material_types.h"
 #include "DNA_node_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_simulation_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_world_types.h"
 
@@ -2266,6 +2267,8 @@ bNodeTree **BKE_ntree_ptr_from_id(ID *id)
       return &((Scene *)id)->nodetree;
     case ID_LS:
       return &((FreestyleLineStyle *)id)->nodetree;
+    case ID_SIM:
+      return &((Simulation *)id)->nodetree;
     default:
       return NULL;
   }
diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc
index 7610f5f18cd..bda58cda755 100644
--- a/source/blender/blenkernel/intern/simulation.cc
+++ b/source/blender/blenkernel/intern/simulation.cc
@@ -36,8 +36,11 @@
 #include "BKE_lib_query.h"
 #include "BKE_lib_remap.h"
 #include "BKE_main.h"
+#include "BKE_node.h"
 #include "BKE_simulation.h"
 
+#include "NOD_simulation.h"
+
 #include "BLT_translation.h"
 
 static void simulation_init_data(ID *id)
@@ -48,11 +51,20 @@ static void simulation_init_data(ID *id)
   MEMCPY_STRUCT_AFTER(simulation, DNA_struct_default_get(Simulation), id);
 }
 
-static void simulation_copy_data(Main *UNUSED(bmain),
-                                 ID *UNUSED(id_dst),
-                                 const ID *UNUSED(id_src),
-                                 const int UNUSED(flag))
+static void simulation_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag)
 {
+  Simulation *simulation_dst = (Simulation *)id_dst;
+  Simulation *simulation_src = (Simulation *)id_src;
+
+  /* We always need allocation of our private ID data. */
+  const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE;
+
+  if (simulation_src->nodetree) {
+    BKE_id_copy_ex(bmain,
+                   (ID *)simulation_src->nodetree,
+                   (ID **)&simulation_dst->nodetree,
+                   flag_private_id_data);
+  }
 }
 
 static void simulation_make_local(Main *bmain, ID *id, const int flags)
@@ -63,7 +75,14 @@ static void simulation_make_local(Main *bmain, ID *id, const int flags)
 static void simulation_free_data(ID *id)
 {
   Simulation *simulation = (Simulation *)id;
+
   BKE_animdata_free(&simulation->id, false);
+
+  if (simulation->nodetree) {
+    ntreeFreeNestedTree(simulation->nodetree);
+    MEM_freeN(simulation->nodetree);
+    simulation->nodetree = nullptr;
+  }
 }
 
 void *BKE_simulation_add(Main *bmain, const char *name)
@@ -71,6 +90,8 @@ void *BKE_simulation_add(Main *bmain, const char *name)
   Simulation *simulation = (Simulation *)BKE_libblock_alloc(bmain, ID_SIM, name, 0);
 
   simulation_init_data(&simulation->id);
+  bNodeTree *ntree = ntreeAddTree(nullptr, "Simulation Nodetree", ntreeType_Simulation->idname);
+  simulation->nodetree = ntree;
 
   return simulation;
 }
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 76038b94b27..5b6dafe94ac 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -7647,6 +7647,8 @@ static void lib_link_area(FileData *fd, ID *parent_id, ScrArea *area)
         snode->id = newlibadr(fd, parent_id->lib, snode->id);
         snode->from = newlibadr(fd, parent_id->lib, snode->from);
 
+        snode->simulation = newlibadr(fd, parent_id->lib, snode->simulation);
+
         ntree = snode->id ? ntreeFromID(snode->id) : NULL;
         snode->nodetree = ntree ? ntree : newlibadr(fd, parent_id->lib, snode->nodetree);
 
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 3bdca9ca054..672a89a2da4 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3813,6 +3813,12 @@ static void write_simulation(WriteData *wd, Simulation *simulation)
     if (simulation->adt) {
       write_animdata(wd, simulation->adt);
     }
+
+    /* nodetree is integral part of simulation, no libdata */
+    if (simulation->nodetree) {
+      writestruct(wd, DATA, bNodeTree, 1, simulation->nodetree);
+      write_nodetree_nolib(wd, simulation->nodetree);
+    }
   }
 }
 
diff --git a/source/blender/makesdna/DNA_simulation_types.h b/source/blender/makesdna/DNA_simulation_types.h
index 84c22d7f73a..113c301bb9e 100644
--- a/source/blender/makesdna/DNA_simulation_types.h
+++ b/source/blender/makesdna/DNA_simulation_types.h
@@ -27,6 +27,8 @@ typedef struct Simulation {
   ID id;
   struct AnimData *adt; /* animation data (must be immediately after id) */
 
+  struct bNodeTree *nodetree;
+
   int flag;
   int _pad1[1];
 } Simulation;
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 3020e5a1708..422025a134b 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -1352,6 +1352,8 @@ typedef struct SpaceNode {
 
   /** Context, no need to save in file? well... pinning... */
   struct ID *id, *from;
+  struct Simulation *simulation;
+
   /** Menunr: browse id block in header. */
   short flag;
   char _pad1[2];
diff --git a/source/blender/makesrna/intern/rna_simulation.c b/source/blender/makesrna/intern/rna_simulation.c
index 2ffda8a4ea8..789ea299feb 100644
--- a/source/blender/makesrna/intern/rna_simulation.c
+++ b/source/blender/makesrna/intern/rna_simulation.c
@@ -34,11 +34,16 @@
 static void rna_def_simulation(BlenderRNA *brna)
 {
   StructRNA *srna;
+  PropertyRNA *prop;
 
   srna = RNA_def_struct(brna, "Simulation", "ID");
   RNA_def_struct_ui_text(srna, "Simulation", "Simulation data-block");
   RNA_def_struct_ui_icon(srna, ICON_PHYSICS); /* TODO: Use correct icon. */
 
+  prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
+  RNA_def_property_pointer_sdna(prop, NULL, "nodetree");
+  RNA_def_property_ui_text(prop, "Node Tree", "Node tree defining the simulation");
+
   /* common */
   rna_def_animdata_common(srna);
 }
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 302495a72af..e62185ccdb1 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -44,6 +44,7 @@
 #include "DNA_node_types.h"
 #include "DNA_object_types.h"
 #include "DNA_sequence_types.h"
+#include "DNA_simulation_types.h"
 #include "DNA_space_types.h"
 #include "DNA_view3d_types.h"
 #include "DNA_workspace_types.h"
@@ -2165,6 +2166,23 @@ static void rna_SpaceNodeEditor_node_tree_update(const bContext *C, PointerRNA *
   ED_node_tree_update(C);
 }
 
+static void rna_SpaceNodeEditor_simulation_set(PointerRNA *ptr,
+                                               const PointerRNA value,
+                                               struct ReportList *UNUSED(reports))
+{
+  SpaceNode *snode = (SpaceNode *)ptr->data;
+  Simulation *sim = (Simulation *)value.data;
+  if (sim != NULL) {
+    bNodeTree *ntree = sim->nodetree;
+    ED_node_tree_start(snode, ntree, NULL, NULL);
+  }
+  else {
+    ED_node_tree_start(snode, NULL, NULL, NULL);
+  }
+  snode->simulation = sim;
+  snode->id = &sim->id;
+}
+
 static int rna_SpaceNodeEditor_tree_type_get(PointerRNA *ptr)
 {
   SpaceNode *snode = (SpaceNode *)ptr->data;
@@ -6203,6 +6221,12 @@ static void rna_def_space_node(BlenderRNA *brna)
   RNA_def_property_ui_text(
       prop, "ID From", "Data-block from which the edited data-block is linked");
 
+  prop = RNA_def_property(srna, "simulation", PROP_POINTER, PROP_NONE);
+  RNA_def_property_flag(prop, PROP_EDITABLE);
+  RNA_def_property_ui_text(prop, "Simulation", "Simulation that is being edited");
+  RNA_def_property_pointer_funcs(prop, NULL, "rna_SpaceNodeEditor_simulation_set", NULL, NULL);
+  RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE, NULL);
+
   prop = RNA_def_property(srna, "path", PROP_COLLECTION, PROP_NONE);
   RNA_def_property_collection_sdna(prop, NULL, "treepath", NULL);
   RNA_def_property_struct_type(prop, "NodeTreePath");



More information about the Bf-blender-cvs mailing list