From 921d74dd365661c52dd91dd12d29314ffd9f26ab Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 6 Feb 2020 16:24:19 +0100 Subject: NodeTree: Add access to the address of an ID's nodetree pointer. --- source/blender/blenkernel/intern/node.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'source/blender/blenkernel/intern/node.c') 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) { -- cgit v1.2.3