Blender V4.3
node_shader_tex_pointdensity.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2015 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "node_shader_util.hh"
6
7#include "BKE_texture.h"
8
9#include "RE_texture.h"
10
11#include "RNA_access.hh"
12
13#include "UI_interface.hh"
14#include "UI_resources.hh"
15
17
19{
20 b.add_input<decl::Vector>("Vector").hide_value();
21 b.add_output<decl::Color>("Color");
22 b.add_output<decl::Float>("Density");
23}
24
26{
27 bNode *node = (bNode *)ptr->data;
28 NodeShaderTexPointDensity *shader_point_density = (NodeShaderTexPointDensity *)node->storage;
29 Object *ob = (Object *)node->id;
30
31 PointerRNA ob_ptr = RNA_id_pointer_create((ID *)ob);
32 PointerRNA obdata_ptr = RNA_id_pointer_create(ob ? (ID *)ob->data : nullptr);
33
34 uiItemR(layout, ptr, "point_source", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
35 uiItemR(layout, ptr, "object", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
36
37 if (node->id && shader_point_density->point_source == SHD_POINTDENSITY_SOURCE_PSYS) {
38 PointerRNA dataptr = RNA_id_pointer_create((ID *)node->id);
40 layout, ptr, "particle_system", &dataptr, "particle_systems", nullptr, ICON_NONE);
41 }
42
43 uiItemR(layout, ptr, "space", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
44 uiItemR(layout, ptr, "radius", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
45 uiItemR(layout, ptr, "interpolation", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
46 uiItemR(layout, ptr, "resolution", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
47 if (shader_point_density->point_source == SHD_POINTDENSITY_SOURCE_PSYS) {
48 uiItemR(layout, ptr, "particle_color_source", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
49 }
50 else {
51 uiItemR(layout, ptr, "vertex_color_source", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
52 if (shader_point_density->ob_color_source == SHD_POINTDENSITY_COLOR_VERTWEIGHT) {
53 if (ob_ptr.data) {
55 layout, ptr, "vertex_attribute_name", &ob_ptr, "vertex_groups", "", ICON_NONE);
56 }
57 }
58 if (shader_point_density->ob_color_source == SHD_POINTDENSITY_COLOR_VERTCOL) {
59 if (obdata_ptr.data) {
61 layout, ptr, "vertex_attribute_name", &obdata_ptr, "vertex_colors", "", ICON_NONE);
62 }
63 }
64 }
65}
66
67static void node_shader_init_tex_pointdensity(bNodeTree * /*ntree*/, bNode *node)
68{
69 NodeShaderTexPointDensity *point_density = static_cast<NodeShaderTexPointDensity *>(
70 MEM_callocN(sizeof(NodeShaderTexPointDensity), __func__));
71 point_density->resolution = 100;
72 point_density->radius = 0.3f;
73 point_density->space = SHD_POINTDENSITY_SPACE_OBJECT;
75 node->storage = point_density;
76}
77
79{
80 NodeShaderTexPointDensity *point_density = (NodeShaderTexPointDensity *)node->storage;
81 PointDensity *pd = &point_density->pd;
84 *pd = dna::shallow_zero_initialize();
85 MEM_freeN(point_density);
86}
87
88static void node_shader_copy_tex_pointdensity(bNodeTree * /*dst_ntree*/,
89 bNode *dest_node,
90 const bNode *src_node)
91{
92 dest_node->storage = MEM_dupallocN(src_node->storage);
93 NodeShaderTexPointDensity *point_density = (NodeShaderTexPointDensity *)dest_node->storage;
94 PointDensity *pd = &point_density->pd;
95 *pd = dna::shallow_zero_initialize();
96}
97
98} // namespace blender::nodes::node_shader_tex_pointdensity_cc
99
100/* node type definition */
102{
104
105 static blender::bke::bNodeType ntype;
106
108 ntype.declare = file_ns::node_declare;
109 ntype.draw_buttons = file_ns::node_shader_buts_tex_pointdensity;
110 ntype.initfunc = file_ns::node_shader_init_tex_pointdensity;
112 "NodeShaderTexPointDensity",
113 file_ns::node_shader_free_tex_pointdensity,
114 file_ns::node_shader_copy_tex_pointdensity);
115
117}
#define SH_NODE_TEX_POINTDENSITY
Definition BKE_node.hh:975
#define NODE_CLASS_TEXTURE
Definition BKE_node.hh:414
void BKE_texture_pointdensity_free_data(struct PointDensity *pd)
Definition texture.cc:652
@ SHD_POINTDENSITY_COLOR_PARTAGE
@ SHD_POINTDENSITY_COLOR_VERTWEIGHT
@ SHD_POINTDENSITY_COLOR_VERTCOL
@ SHD_POINTDENSITY_SOURCE_PSYS
@ SHD_POINTDENSITY_SPACE_OBJECT
void uiItemPointerR(uiLayout *layout, PointerRNA *ptr, const char *propname, PointerRNA *searchptr, const char *searchpropname, const char *name, int icon)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
@ UI_ITEM_R_EXPAND
local_group_size(16, 16) .push_constant(Type b
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
void *(* MEM_callocN)(size_t len, const char *str)
Definition mallocn.cc:42
void *(* MEM_dupallocN)(const void *vmemh)
Definition mallocn.cc:39
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void node_shader_init_tex_pointdensity(bNodeTree *, bNode *node)
static void node_shader_buts_tex_pointdensity(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_shader_copy_tex_pointdensity(bNodeTree *, bNode *dest_node, const bNode *src_node)
void register_node_type_sh_tex_pointdensity()
void sh_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
PointerRNA RNA_id_pointer_create(ID *id)
Definition DNA_ID.h:413
void * data
Definition RNA_types.hh:42
void * storage
Defines a node type.
Definition BKE_node.hh:218
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
void RE_point_density_free(PointDensity *pd)
PointerRNA * ptr
Definition wm_files.cc:4126