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:
authorBastien Montagne <b.mont29@gmail.com>2020-02-06 18:24:19 +0300
committerBastien Montagne <b.mont29@gmail.com>2020-02-06 20:55:20 +0300
commit921d74dd365661c52dd91dd12d29314ffd9f26ab (patch)
tree4b414b051ab5f1a0888e8e025a15c61619f79321 /source/blender/blenkernel/intern/node.c
parent49b66ad9147a41523eab6b4e579d282d66b9a70a (diff)
NodeTree: Add access to the address of an ID's nodetree pointer.
Diffstat (limited to 'source/blender/blenkernel/intern/node.c')
-rw-r--r--source/blender/blenkernel/intern/node.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index 75e0d044c7c..94c06e46cb9 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -2242,27 +2242,37 @@ void ntreeSetOutput(bNodeTree *ntree)
* might be different for editor or for "real" use... */
}
-/* Returns the private NodeTree object of the datablock, if it has one. */
-bNodeTree *ntreeFromID(const ID *id)
+/** Get address of potential nodetree pointer of given ID.
+ *
+ * \warning Using this function directly is potentially dangerous, if you don't know or are not
+ * sure, please use `ntreeFromID()` instead. */
+bNodeTree **BKE_ntree_ptr_from_id(ID *id)
{
switch (GS(id->name)) {
case ID_MA:
- return ((const Material *)id)->nodetree;
+ return &((Material *)id)->nodetree;
case ID_LA:
- return ((const Light *)id)->nodetree;
+ return &((Light *)id)->nodetree;
case ID_WO:
- return ((const World *)id)->nodetree;
+ return &((World *)id)->nodetree;
case ID_TE:
- return ((const Tex *)id)->nodetree;
+ return &((Tex *)id)->nodetree;
case ID_SCE:
- return ((const Scene *)id)->nodetree;
+ return &((Scene *)id)->nodetree;
case ID_LS:
- return ((const FreestyleLineStyle *)id)->nodetree;
+ return &((FreestyleLineStyle *)id)->nodetree;
default:
return NULL;
}
}
+/* Returns the private NodeTree object of the datablock, if it has one. */
+bNodeTree *ntreeFromID(ID *id)
+{
+ bNodeTree **nodetree = BKE_ntree_ptr_from_id(id);
+ return (nodetree != NULL) ? *nodetree : NULL;
+}
+
/* Finds and returns the datablock that privately owns the given tree, or NULL. */
ID *BKE_node_tree_find_owner_ID(Main *bmain, struct bNodeTree *ntree)
{