diff options
author | Jacques Lucke <jacques@blender.org> | 2020-04-20 13:56:16 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-04-20 13:56:16 +0300 |
commit | 2b2d3c14fe1a29da0ec01198cec2c0593c38391a (patch) | |
tree | 672442c9086cf193de3378e735ceaf8fbe362d99 /source/blender/blenkernel | |
parent | 8d53e59e32a3c704f0c42e11370cc7812b71b294 (diff) |
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
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lib_query.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.c | 9 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/simulation.cc | 38 |
4 files changed, 52 insertions, 6 deletions
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, }; |