[Bf-blender-cvs] [2b2d3c14fe1] master: Simulations: Embed simulation node tree in simulation data block
Jacques Lucke
noreply at git.blender.org
Mon Apr 20 13:12:09 CEST 2020
Commit: 2b2d3c14fe1a29da0ec01198cec2c0593c38391a
Author: Jacques Lucke
Date: Mon Apr 20 12:56:16 2020 +0200
Branches: master
https://developer.blender.org/rB2b2d3c14fe1a29da0ec01198cec2c0593c38391a
Simulations: Embed simulation node tree in simulation data block
This adds an embedded node tree to the simulation data block dna.
The UI in the `Simulation Editor` has been updated to show a list
of simulation data blocks, instead of individual node trees.
The new `SpaceNodeEditor.simulation` property wraps the existing
`SpaceNodeEditor.id` property. It allows scripts to get and set
the simulation data block that is being edited.
Reviewers: brecht, mont29
Differential Revision: https://developer.blender.org/D7301
===================================================================
M release/scripts/startup/bl_operators/__init__.py
A release/scripts/startup/bl_operators/simulation.py
M release/scripts/startup/bl_ui/space_node.py
M release/scripts/startup/nodeitems_builtins.py
M source/blender/blenkernel/BKE_node.h
M source/blender/blenkernel/intern/lib_query.c
M source/blender/blenkernel/intern/node.c
M source/blender/blenkernel/intern/simulation.cc
M source/blender/blenloader/intern/writefile.c
M source/blender/makesdna/DNA_simulation_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_operators/__init__.py b/release/scripts/startup/bl_operators/__init__.py
index 5af2bd22222..d7df29f1769 100644
--- a/release/scripts/startup/bl_operators/__init__.py
+++ b/release/scripts/startup/bl_operators/__init__.py
@@ -42,6 +42,7 @@ _modules = [
"rigidbody",
"screen_play_rendered_anim",
"sequencer",
+ "simulation",
"userpref",
"uvcalc_follow_active",
"uvcalc_lightmap",
diff --git a/release/scripts/startup/bl_operators/simulation.py b/release/scripts/startup/bl_operators/simulation.py
new file mode 100644
index 00000000000..5d9c9476318
--- /dev/null
+++ b/release/scripts/startup/bl_operators/simulation.py
@@ -0,0 +1,39 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+import bpy
+
+class NewSimulation(bpy.types.Operator):
+ """Create a new simulation data block and edit it in the opened simulation editor"""
+
+ bl_idname = "simulation.new"
+ bl_label = "New Simulation"
+ bl_options = {'REGISTER', 'UNDO'}
+
+ @classmethod
+ def poll(cls, context):
+ return context.area.type == 'NODE_EDITOR' and context.space_data.tree_type == 'SimulationNodeTree'
+
+ def execute(self, context):
+ simulation = bpy.data.simulations.new("Simulation")
+ context.space_data.simulation = simulation
+ return {'FINISHED'}
+
+classes = (
+ NewSimulation,
+)
diff --git a/release/scripts/startup/bl_ui/space_node.py b/release/scripts/startup/bl_ui/space_node.py
index bdda0ebbe9a..b5926692324 100644
--- a/release/scripts/startup/bl_ui/space_node.py
+++ b/release/scripts/startup/bl_ui/space_node.py
@@ -151,6 +151,14 @@ class NODE_HT_header(Header):
if snode_id:
layout.prop(snode_id, "use_nodes")
+ elif snode.tree_type == 'SimulationNodeTree':
+ row = layout.row(align=True)
+ row.prop(snode, "simulation", text="")
+ row.operator("simulation.new", text="", icon='ADD')
+ simulation = snode.simulation
+ if simulation:
+ row.prop(snode.simulation, "use_fake_user", text="")
+
else:
# Custom node tree is edited as independent ID block
NODE_MT_editor_menus.draw_collapsible(context, layout)
diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index 969a1ca1bd7..4396e00dfd3 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -58,6 +58,13 @@ class TextureNodeCategory(SortedNodeCategory):
context.space_data.tree_type == 'TextureNodeTree')
+class SimulationNodeCategory(SortedNodeCategory):
+ @classmethod
+ def poll(cls, context):
+ return (context.space_data.type == 'NODE_EDITOR' and
+ context.space_data.tree_type == 'SimulationNodeTree')
+
+
# menu entry for node group tools
def group_tools_draw(self, layout, context):
layout.operator("node.group_make")
@@ -70,6 +77,7 @@ node_tree_group_type = {
'CompositorNodeTree': 'CompositorNodeGroup',
'ShaderNodeTree': 'ShaderNodeGroup',
'TextureNodeTree': 'TextureNodeGroup',
+ 'SimulationNodeTree': 'SimulationNodeGroup',
}
@@ -467,17 +475,28 @@ texture_node_categories = [
]),
]
+simulation_node_categories = [
+ # Simulation Nodes
+ SimulationNodeCategory("SIM_GROUP", "Group", items=node_group_items),
+ SimulationNodeCategory("SIM_LAYOUT", "Layout", items=[
+ NodeItem("NodeFrame"),
+ NodeItem("NodeReroute"),
+ ]),
+]
+
def register():
nodeitems_utils.register_node_categories('SHADER', shader_node_categories)
nodeitems_utils.register_node_categories('COMPOSITING', compositor_node_categories)
nodeitems_utils.register_node_categories('TEXTURE', texture_node_categories)
+ nodeitems_utils.register_node_categories('SIMULATION', simulation_node_categories)
def unregister():
nodeitems_utils.unregister_node_categories('SHADER')
nodeitems_utils.unregister_node_categories('COMPOSITING')
nodeitems_utils.unregister_node_categories('TEXTURE')
+ nodeitems_utils.unregister_node_categories('SIMULATION')
if __name__ == "__main__":
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 38fe974c228..9d7caeb845f 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -852,6 +852,7 @@ struct NodeTreeIterStore {
struct Light *light;
struct World *world;
struct FreestyleLineStyle *linestyle;
+ struct Simulation *simulation;
};
void BKE_node_tree_iter_init(struct NodeTreeIterStore *ntreeiter, struct Main *bmain);
diff --git a/source/blender/blenkernel/intern/lib_query.c b/source/blender/blenkernel/intern/lib_query.c
index 302ed065e5d..17d26e777b6 100644
--- a/source/blender/blenkernel/intern/lib_query.c
+++ b/source/blender/blenkernel/intern/lib_query.c
@@ -1286,6 +1286,15 @@ static void library_foreach_ID_link(Main *bmain,
}
break;
}
+ case ID_SIM: {
+ Simulation *simulation = (Simulation *)id;
+ if (simulation->nodetree) {
+ /* nodetree **are owned by IDs**, treat them as mere sub-data and not real ID! */
+ library_foreach_ID_as_subdata_link(
+ (ID **)&simulation->nodetree, callback, user_data, flag, &data);
+ }
+ break;
+ }
/* Nothing needed for those... */
case ID_IM:
@@ -1295,7 +1304,6 @@ static void library_foreach_ID_link(Main *bmain,
case ID_PAL:
case ID_PC:
case ID_CF:
- case ID_SIM:
break;
/* Deprecated. */
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index 3f1de388db6..ec12cd9b83f 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"
@@ -2267,6 +2268,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;
}
@@ -4200,6 +4203,7 @@ void BKE_node_tree_iter_init(struct NodeTreeIterStore *ntreeiter, struct Main *b
ntreeiter->light = bmain->lights.first;
ntreeiter->world = bmain->worlds.first;
ntreeiter->linestyle = bmain->linestyles.first;
+ ntreeiter->simulation = bmain->simulations.first;
}
bool BKE_node_tree_iter_step(struct NodeTreeIterStore *ntreeiter,
bNodeTree **r_nodetree,
@@ -4240,6 +4244,11 @@ bool BKE_node_tree_iter_step(struct NodeTreeIterStore *ntreeiter,
*r_id = (ID *)ntreeiter->linestyle;
ntreeiter->linestyle = ntreeiter->linestyle->id.next;
}
+ else if (ntreeiter->simulation) {
+ *r_nodetree = ntreeiter->simulation->nodetree;
+ *r_id = (ID *)ntreeiter->simulation;
+ ntreeiter->simulation = ntreeiter->simulation->id.next;
+ }
else {
return false;
}
diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc
index a751e376f0f..fd0bbe7103f 100644
--- a/source/blender/blenkernel/intern/simulation.cc
+++ b/source/blender/blenkernel/intern/simulation.cc
@@ -37,8 +37,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)
@@ -47,13 +50,38 @@ static void simulation_init_data(ID *id)
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(simulation, id));
MEMCPY_STRUCT_AFTER(simulation, DNA_struct_default_get(Simulation), id);
+
+ bNodeTree *ntree = ntreeAddTree(nullptr, "Simulation Nodetree", ntreeType_Simulation->idname);
+ simulation->nodetree = ntree;
+}
+
+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_copy_data(Main *UNUSED(bmain),
- ID *UNUSED(id_dst),
- const ID *UNUSED(id_src),
- const int UNUSED(flag))
+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)
@@ -77,6 +105,6 @@ IDTypeInfo IDType_ID_SIM = {
/* init_data */ simulation_init_data,
/* copy_data */ simulation_copy_data,
- /* free_data */ nullptr,
+ /* free_data */ simulation_free_data,
/* make_local */ nullptr,
};
diff
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list