Blender V4.5
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 layout->prop(ptr, "point_source", UI_ITEM_R_EXPAND, std::nullopt, ICON_NONE);
35 layout->prop(ptr, "object", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, 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", std::nullopt, ICON_NONE);
41 }
42
43 layout->prop(ptr, "space", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
44 layout->prop(ptr, "radius", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
45 layout->prop(ptr, "interpolation", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
46 layout->prop(ptr, "resolution", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
47 if (shader_point_density->point_source == SHD_POINTDENSITY_SOURCE_PSYS) {
48 layout->prop(
49 ptr, "particle_color_source", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
50 }
51 else {
52 layout->prop(ptr, "vertex_color_source", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
53 if (shader_point_density->ob_color_source == SHD_POINTDENSITY_COLOR_VERTWEIGHT) {
54 if (ob_ptr.data) {
56 layout, ptr, "vertex_attribute_name", &ob_ptr, "vertex_groups", "", ICON_NONE);
57 }
58 }
59 if (shader_point_density->ob_color_source == SHD_POINTDENSITY_COLOR_VERTCOL) {
60 if (obdata_ptr.data) {
61 uiItemPointerR(layout,
62 ptr,
63 "vertex_attribute_name",
64 &obdata_ptr,
65 "color_attributes",
66 "",
67 ICON_GROUP_VCOL);
68 }
69 }
70 }
71}
72
73static void node_shader_init_tex_pointdensity(bNodeTree * /*ntree*/, bNode *node)
74{
76 point_density->resolution = 100;
77 point_density->radius = 0.3f;
78 point_density->space = SHD_POINTDENSITY_SPACE_OBJECT;
80 node->storage = point_density;
81}
82
84{
86 PointDensity *pd = &point_density->pd;
89 *pd = dna::shallow_zero_initialize();
90 MEM_freeN(point_density);
91}
92
93static void node_shader_copy_tex_pointdensity(bNodeTree * /*dst_ntree*/,
94 bNode *dest_node,
95 const bNode *src_node)
96{
97 dest_node->storage = MEM_dupallocN(src_node->storage);
98 NodeShaderTexPointDensity *point_density = (NodeShaderTexPointDensity *)dest_node->storage;
99 PointDensity *pd = &point_density->pd;
100 *pd = dna::shallow_zero_initialize();
101}
102
103} // namespace blender::nodes::node_shader_tex_pointdensity_cc
104
105/* node type definition */
107{
109
110 static blender::bke::bNodeType ntype;
111
112 sh_node_type_base(&ntype, "ShaderNodeTexPointDensity", SH_NODE_TEX_POINTDENSITY);
113 ntype.ui_name = "Point Density";
114 ntype.ui_description =
115 "Generate a volumetric point for each particle or vertex of another object";
116 ntype.enum_name_legacy = "TEX_POINTDENSITY";
118 ntype.declare = file_ns::node_declare;
119 ntype.draw_buttons = file_ns::node_shader_buts_tex_pointdensity;
120 ntype.initfunc = file_ns::node_shader_init_tex_pointdensity;
122 "NodeShaderTexPointDensity",
123 file_ns::node_shader_free_tex_pointdensity,
124 file_ns::node_shader_copy_tex_pointdensity);
125
127}
#define NODE_CLASS_TEXTURE
Definition BKE_node.hh:443
#define SH_NODE_TEX_POINTDENSITY
void BKE_texture_pointdensity_free_data(struct PointDensity *pd)
Definition texture.cc:642
@ SHD_POINTDENSITY_SPACE_OBJECT
@ SHD_POINTDENSITY_COLOR_PARTAGE
@ SHD_POINTDENSITY_COLOR_VERTWEIGHT
@ SHD_POINTDENSITY_COLOR_VERTCOL
@ SHD_POINTDENSITY_SOURCE_PSYS
@ UI_ITEM_R_SPLIT_EMPTY_NAME
@ UI_ITEM_R_EXPAND
void uiItemPointerR(uiLayout *layout, PointerRNA *ptr, blender::StringRefNull propname, PointerRNA *searchptr, blender::StringRefNull searchpropname, std::optional< blender::StringRefNull > name, int icon)
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void * MEM_dupallocN(const void *vmemh)
Definition mallocn.cc:143
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:5603
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, std::string idname, const std::optional< int16_t > legacy_type)
PointerRNA RNA_id_pointer_create(ID *id)
Definition DNA_ID.h:404
void * data
Definition RNA_types.hh:53
struct ID * id
void * storage
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:277
const char * enum_name_legacy
Definition BKE_node.hh:235
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:355
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
void RE_point_density_free(PointDensity *pd)
PointerRNA * ptr
Definition wm_files.cc:4227