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:
authorJacques Lucke <jacques@blender.org>2020-04-20 13:56:16 +0300
committerJacques Lucke <jacques@blender.org>2020-04-20 13:56:16 +0300
commit2b2d3c14fe1a29da0ec01198cec2c0593c38391a (patch)
tree672442c9086cf193de3378e735ceaf8fbe362d99 /source/blender/blenkernel/intern/simulation.cc
parent8d53e59e32a3c704f0c42e11370cc7812b71b294 (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/intern/simulation.cc')
-rw-r--r--source/blender/blenkernel/intern/simulation.cc38
1 files changed, 33 insertions, 5 deletions
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,
};