Blender  V3.3
node_shader_script.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2005 Blender Foundation. All rights reserved. */
3 
8 #include "node_shader_util.hh"
9 
10 #include "UI_interface.h"
11 #include "UI_resources.h"
12 
14 
16 {
17  uiLayout *row;
18 
19  row = uiLayoutRow(layout, false);
20  uiItemR(row, ptr, "mode", UI_ITEM_R_SPLIT_EMPTY_NAME | UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
21 
22  row = uiLayoutRow(layout, true);
23 
24  if (RNA_enum_get(ptr, "mode") == NODE_SCRIPT_INTERNAL) {
25  uiItemR(row, ptr, "script", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
26  }
27  else {
28  uiItemR(row, ptr, "filepath", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
29  }
30 
31  uiItemO(row, "", ICON_FILE_REFRESH, "node.shader_script_update");
32 }
33 
35 {
36  uiItemS(layout);
37 
38  node_shader_buts_script(layout, C, ptr);
39 
40 #if 0 /* not implemented yet */
41  if (RNA_enum_get(ptr, "mode") == NODE_SCRIPT_EXTERNAL) {
42  uiItemR(layout, ptr, "use_auto_update", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
43  }
44 #endif
45 }
46 
47 static void init(bNodeTree *UNUSED(ntree), bNode *node)
48 {
49  NodeShaderScript *nss = MEM_cnew<NodeShaderScript>("shader script node");
50  node->storage = nss;
51 }
52 
54 {
55  NodeShaderScript *nss = static_cast<NodeShaderScript *>(node->storage);
56 
57  if (nss) {
58  if (nss->bytecode) {
59  MEM_freeN(nss->bytecode);
60  }
61 
62  MEM_freeN(nss);
63  }
64 }
65 
66 static void node_copy_script(bNodeTree *UNUSED(dest_ntree),
67  bNode *dest_node,
68  const bNode *src_node)
69 {
70  NodeShaderScript *src_nss = static_cast<NodeShaderScript *>(src_node->storage);
71  NodeShaderScript *dest_nss = static_cast<NodeShaderScript *>(MEM_dupallocN(src_nss));
72 
73  if (src_nss->bytecode) {
74  dest_nss->bytecode = static_cast<char *>(MEM_dupallocN(src_nss->bytecode));
75  }
76 
77  dest_node->storage = dest_nss;
78 }
79 
80 } // namespace blender::nodes::node_shader_script_cc
81 
83 {
84  namespace file_ns = blender::nodes::node_shader_script_cc;
85 
86  static bNodeType ntype;
87 
93  &ntype, "NodeShaderScript", file_ns::node_free_script, file_ns::node_copy_script);
94 
95  nodeRegisterType(&ntype);
96 }
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
Definition: node.cc:4426
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define NODE_CLASS_SCRIPT
Definition: BKE_node.h:356
#define UNUSED(x)
#define NODE_SCRIPT_EXTERNAL
#define NODE_SCRIPT_INTERNAL
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces SH_NODE_SCRIPT
#define C
Definition: RandGen.cpp:25
void uiItemS(uiLayout *layout)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
@ UI_ITEM_R_EXPAND
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname)
OperationNode * node
bNodeTree * ntree
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:28
static void node_shader_buts_script_ex(uiLayout *layout, bContext *C, PointerRNA *ptr)
static void node_free_script(bNode *node)
static void node_copy_script(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
static void node_shader_buts_script(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static void init(bNodeTree *UNUSED(ntree), bNode *node)
void register_node_type_sh_script()
void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass)
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5004
Defines a node type.
Definition: BKE_node.h:226
void(* draw_buttons_ex)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:246
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:244
void * storage
PointerRNA * ptr
Definition: wm_files.c:3480