Blender  V2.93
node_geo_point_scale.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 "BKE_colorband.h"
18 
19 #include "UI_interface.h"
20 #include "UI_resources.h"
21 
22 #include "node_geometry_util.hh"
23 
25  {SOCK_GEOMETRY, N_("Geometry")},
26  {SOCK_STRING, N_("Factor")},
27  {SOCK_VECTOR, N_("Factor"), 1.0f, 1.0f, 1.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_XYZ},
28  {SOCK_FLOAT, N_("Factor"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX},
29  {-1, ""},
30 };
31 
33  {SOCK_GEOMETRY, N_("Geometry")},
34  {-1, ""},
35 };
36 
38 {
39  uiLayoutSetPropSep(layout, true);
40  uiLayoutSetPropDecorate(layout, false);
41  uiItemR(layout, ptr, "input_type", 0, IFACE_("Type"), ICON_NONE);
42 }
43 
44 namespace blender::nodes {
45 
47 {
48  /* Note that scale doesn't necessarily need to be created with a vector type-- it could also use
49  * the highest complexity of the existing attribute's type (if it exists) and the data type used
50  * for the factor. But for it's simpler to simply always use float3, since that is usually
51  * expected anyway. */
52  static const float3 scale_default = float3(1.0f);
53  OutputAttributePtr scale_attribute = component.attribute_try_get_for_output(
54  "scale", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3, &scale_default);
55  if (!scale_attribute) {
56  return;
57  }
58 
59  const bNode &node = params.node();
60  const NodeGeometryPointScale &node_storage = *(const NodeGeometryPointScale *)node.storage;
62  node_storage.input_type;
63  const CustomDataType data_type = (input_type == GEO_NODE_ATTRIBUTE_INPUT_FLOAT) ? CD_PROP_FLOAT :
65 
66  ReadAttributePtr attribute = params.get_input_attribute(
67  "Factor", component, ATTR_DOMAIN_POINT, data_type, nullptr);
68  if (!attribute) {
69  return;
70  }
71 
72  MutableSpan<float3> scale_span = scale_attribute->get_span<float3>();
73  if (data_type == CD_PROP_FLOAT) {
74  Span<float> factors = attribute->get_span<float>();
75  for (const int i : scale_span.index_range()) {
76  scale_span[i] = scale_span[i] * factors[i];
77  }
78  }
79  else if (data_type == CD_PROP_FLOAT3) {
80  Span<float3> factors = attribute->get_span<float3>();
81  for (const int i : scale_span.index_range()) {
82  scale_span[i] = scale_span[i] * factors[i];
83  }
84  }
85 
86  scale_attribute.apply_span_and_save();
87 }
88 
90 {
91  GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
92 
93  geometry_set = geometry_set_realize_instances(geometry_set);
94 
95  if (geometry_set.has<MeshComponent>()) {
97  }
98  if (geometry_set.has<PointCloudComponent>()) {
100  }
101 
102  params.set_output("Geometry", std::move(geometry_set));
103 }
104 
106 {
108  sizeof(NodeGeometryPointScale), __func__);
109 
111  node->storage = data;
112 }
113 
115 {
116  NodeGeometryPointScale &node_storage = *(NodeGeometryPointScale *)node->storage;
117 
119  *node, "Factor", (GeometryNodeAttributeInputMode)node_storage.input_type);
120 }
121 
122 } // namespace blender::nodes
123 
125 {
126  static bNodeType ntype;
127 
128  geo_node_type_base(&ntype, GEO_NODE_POINT_SCALE, "Point Scale", NODE_CLASS_GEOMETRY, 0);
133  &ntype, "NodeGeometryPointScale", node_free_standard_storage, node_copy_standard_storage);
136  nodeRegisterType(&ntype);
137 }
@ ATTR_DOMAIN_POINT
Definition: BKE_attribute.h:43
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_GEOMETRY
Definition: BKE_node.h:359
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:4599
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
#define UNUSED(x)
#define IFACE_(msgid)
#define N_(msgid)
static uint8 component(Color32 c, uint i)
Definition: ColorBlock.cpp:126
CustomDataType
@ CD_PROP_FLOAT
@ CD_PROP_FLOAT3
@ SOCK_VECTOR
@ SOCK_FLOAT
@ SOCK_GEOMETRY
@ SOCK_STRING
GeometryNodeAttributeInputMode
@ GEO_NODE_ATTRIBUTE_INPUT_VECTOR
@ GEO_NODE_ATTRIBUTE_INPUT_FLOAT
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 Attribute Attribute Color Attribute Attribute Vector GEO_NODE_POINT_SCALE
@ PROP_XYZ
Definition: RNA_types.h:148
#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)
constexpr IndexRange index_range() const
Definition: BLI_span.hh:659
OperationNode * node
void * tree
bNodeTree * ntree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
GeometrySet geometry_set_realize_instances(const GeometrySet &geometry_set)
std::unique_ptr< ReadAttribute > ReadAttributePtr
static void execute_on_component(const GeoNodeExecParams &params, GeometryComponent &component)
static void geo_node_point_scale_update(bNodeTree *UNUSED(ntree), bNode *node)
void update_attribute_input_socket_availabilities(bNode &node, const StringRef name, const GeometryNodeAttributeInputMode mode, const bool name_is_available)
static void geo_node_point_scale_exec(GeoNodeExecParams params)
static void geo_node_point_scale_init(bNodeTree *UNUSED(tree), bNode *node)
static bNodeSocketTemplate geo_node_point_scale_out[]
void register_node_type_geo_point_scale()
static bNodeSocketTemplate geo_node_point_scale_in[]
static void geo_node_point_scale_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
void geo_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
void node_copy_standard_storage(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
Definition: node_util.c:67
void node_free_standard_storage(bNode *node)
Definition: node_util.c:55
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
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