Blender  V2.93
node_geo_attribute_fill.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #include "UI_interface.h"
18 #include "UI_resources.h"
19 
20 #include "node_geometry_util.hh"
21 
23  {SOCK_GEOMETRY, N_("Geometry")},
24  {SOCK_STRING, N_("Attribute")},
25  {SOCK_VECTOR, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX},
26  {SOCK_FLOAT, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX},
27  {SOCK_RGBA, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX},
28  {SOCK_BOOLEAN, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX},
29  {SOCK_INT, N_("Value"), 0, 0, 0, 0, -10000000.0f, 10000000.0f},
30  {-1, ""},
31 };
32 
34  {SOCK_GEOMETRY, N_("Geometry")},
35  {-1, ""},
36 };
37 
39 {
40  uiLayoutSetPropSep(layout, true);
41  uiLayoutSetPropDecorate(layout, false);
42  uiItemR(layout, ptr, "domain", 0, "", ICON_NONE);
43  uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE);
44 }
45 
47 {
48  node->custom1 = CD_PROP_FLOAT;
49  node->custom2 = ATTR_DOMAIN_AUTO;
50 }
51 
53 {
54  bNodeSocket *socket_value_vector = (bNodeSocket *)BLI_findlink(&node->inputs, 2);
55  bNodeSocket *socket_value_float = socket_value_vector->next;
56  bNodeSocket *socket_value_color4f = socket_value_float->next;
57  bNodeSocket *socket_value_boolean = socket_value_color4f->next;
58  bNodeSocket *socket_value_int32 = socket_value_boolean->next;
59 
60  const CustomDataType data_type = static_cast<CustomDataType>(node->custom1);
61 
62  nodeSetSocketAvailability(socket_value_vector, data_type == CD_PROP_FLOAT3);
63  nodeSetSocketAvailability(socket_value_float, data_type == CD_PROP_FLOAT);
64  nodeSetSocketAvailability(socket_value_color4f, data_type == CD_PROP_COLOR);
65  nodeSetSocketAvailability(socket_value_boolean, data_type == CD_PROP_BOOL);
66  nodeSetSocketAvailability(socket_value_int32, data_type == CD_PROP_INT32);
67 }
68 
69 namespace blender::nodes {
70 
72  StringRef attribute_name)
73 {
74  /* Use the domain of the result attribute if it already exists. */
75  ReadAttributePtr result_attribute = component.attribute_try_get_for_read(attribute_name);
76  if (result_attribute) {
77  return result_attribute->domain();
78  }
79  return ATTR_DOMAIN_POINT;
80 }
81 
83 {
84  const std::string attribute_name = params.get_input<std::string>("Attribute");
85  if (attribute_name.empty()) {
86  return;
87  }
88 
89  const bNode &node = params.node();
90  const CustomDataType data_type = static_cast<CustomDataType>(node.custom1);
91  const AttributeDomain domain = static_cast<AttributeDomain>(node.custom2);
92  const AttributeDomain result_domain = (domain == ATTR_DOMAIN_AUTO) ?
93  get_result_domain(component, attribute_name) :
94  domain;
95 
96  OutputAttributePtr attribute = component.attribute_try_get_for_output(
97  attribute_name, result_domain, data_type);
98  if (!attribute) {
99  return;
100  }
101 
102  switch (data_type) {
103  case CD_PROP_FLOAT: {
104  const float value = params.get_input<float>("Value_001");
105  MutableSpan<float> attribute_span = attribute->get_span_for_write_only<float>();
106  attribute_span.fill(value);
107  break;
108  }
109  case CD_PROP_FLOAT3: {
110  const float3 value = params.get_input<float3>("Value");
111  MutableSpan<float3> attribute_span = attribute->get_span_for_write_only<float3>();
112  attribute_span.fill(value);
113  break;
114  }
115  case CD_PROP_COLOR: {
116  const Color4f value = params.get_input<Color4f>("Value_002");
117  MutableSpan<Color4f> attribute_span = attribute->get_span_for_write_only<Color4f>();
118  attribute_span.fill(value);
119  break;
120  }
121  case CD_PROP_BOOL: {
122  const bool value = params.get_input<bool>("Value_003");
123  MutableSpan<bool> attribute_span = attribute->get_span_for_write_only<bool>();
124  attribute_span.fill(value);
125  break;
126  }
127  case CD_PROP_INT32: {
128  const int value = params.get_input<int>("Value_004");
129  MutableSpan<int> attribute_span = attribute->get_span_for_write_only<int>();
130  attribute_span.fill(value);
131  }
132  default:
133  break;
134  }
135 
136  attribute.apply_span_and_save();
137 }
138 
140 {
141  GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
142 
143  geometry_set = geometry_set_realize_instances(geometry_set);
144 
145  if (geometry_set.has<MeshComponent>()) {
147  }
148  if (geometry_set.has<PointCloudComponent>()) {
150  }
151 
152  params.set_output("Geometry", geometry_set);
153 }
154 
155 } // namespace blender::nodes
156 
158 {
159  static bNodeType ntype;
160 
161  geo_node_type_base(&ntype, GEO_NODE_ATTRIBUTE_FILL, "Attribute Fill", NODE_CLASS_ATTRIBUTE, 0);
167  nodeRegisterType(&ntype);
168 }
AttributeDomain
Definition: BKE_attribute.h:41
@ ATTR_DOMAIN_POINT
Definition: BKE_attribute.h:43
@ ATTR_DOMAIN_AUTO
Definition: BKE_attribute.h:42
void nodeSetSocketAvailability(struct bNodeSocket *sock, bool is_available)
Definition: node.cc:3726
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
void node_type_update(struct bNodeType *ntype, void(*updatefunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4623
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4559
#define NODE_CLASS_ATTRIBUTE
Definition: BKE_node.h:360
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define UNUSED(x)
#define N_(msgid)
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:126
CustomDataType
@ CD_PROP_FLOAT
@ CD_PROP_FLOAT3
@ CD_PROP_COLOR
@ CD_PROP_INT32
@ CD_PROP_BOOL
@ SOCK_INT
@ SOCK_VECTOR
@ SOCK_BOOLEAN
@ SOCK_FLOAT
@ SOCK_GEOMETRY
@ SOCK_STRING
@ SOCK_RGBA
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Separate TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC TEX_NODE_PROC Boolean Random Edge Subdivision Point Object Attribute GEO_NODE_ATTRIBUTE_FILL
#define C
Definition: RandGen.cpp:39
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
void uiLayoutSetPropDecorate(uiLayout *layout, bool is_sep)
fn::GMutableSpan get_span_for_write_only()
OperationNode * node
void * tree
bNodeTree * ntree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
GeometrySet geometry_set_realize_instances(const GeometrySet &geometry_set)
std::unique_ptr< ReadAttribute > ReadAttributePtr
static AttributeDomain get_result_domain(const GeometryComponent &component, StringRef source_name, StringRef result_name)
static void geo_node_attribute_fill_exec(GeoNodeExecParams params)
static void fill_attribute(GeometryComponent &component, const GeoNodeExecParams &params)
static void geo_node_attribute_fill_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
void register_node_type_geo_attribute_fill()
static bNodeSocketTemplate geo_node_attribute_fill_out[]
static bNodeSocketTemplate geo_node_attribute_fill_in[]
static void geo_node_attribute_fill_init(bNodeTree *UNUSED(tree), bNode *node)
static void geo_node_attribute_fill_update(bNodeTree *UNUSED(ntree), bNode *node)
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
GeometryComponent & get_component_for_write(GeometryComponentType component_type)
bool has(const GeometryComponentType component_type) const
Compact definition of a node socket.
Definition: BKE_node.h:95
struct bNodeSocket * next
Defines a node type.
Definition: BKE_node.h:221
NodeGeometryExecFunction geometry_node_execute
Definition: BKE_node.h:327
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:253
PointerRNA * ptr
Definition: wm_files.c:3157