Blender  V2.93
node_geo_point_translate.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_("Translation")},
25  {SOCK_VECTOR, N_("Translation"), 0.0f, 0.0f, 0.0f, 1.0f, -FLT_MAX, FLT_MAX, PROP_TRANSLATION},
26  {-1, ""},
27 };
28 
30  {SOCK_GEOMETRY, N_("Geometry")},
31  {-1, ""},
32 };
33 
35 {
36  uiLayoutSetPropSep(layout, true);
37  uiLayoutSetPropDecorate(layout, false);
38  uiItemR(layout, ptr, "input_type", 0, IFACE_("Type"), ICON_NONE);
39 }
40 
41 namespace blender::nodes {
42 
44 {
45  OutputAttributePtr position_attribute = component.attribute_try_get_for_output(
46  "position", ATTR_DOMAIN_POINT, CD_PROP_FLOAT3);
47  if (!position_attribute) {
48  return;
49  }
50  ReadAttributePtr attribute = params.get_input_attribute(
51  "Translation", component, ATTR_DOMAIN_POINT, CD_PROP_FLOAT3, nullptr);
52  if (!attribute) {
53  return;
54  }
55 
56  Span<float3> data = attribute->get_span<float3>();
57  MutableSpan<float3> scale_span = position_attribute->get_span<float3>();
58  for (const int i : scale_span.index_range()) {
59  scale_span[i] = scale_span[i] + data[i];
60  }
61 
62  position_attribute.apply_span_and_save();
63 }
64 
66 {
67  GeometrySet geometry_set = params.extract_input<GeometrySet>("Geometry");
68 
69  geometry_set = geometry_set_realize_instances(geometry_set);
70 
71  if (geometry_set.has<MeshComponent>()) {
73  }
74  if (geometry_set.has<PointCloudComponent>()) {
76  }
77 
78  params.set_output("Geometry", std::move(geometry_set));
79 }
80 
82 {
84  sizeof(NodeGeometryPointTranslate), __func__);
85 
87  node->storage = data;
88 }
89 
91 {
92  NodeGeometryPointTranslate &node_storage = *(NodeGeometryPointTranslate *)node->storage;
93 
95  *node, "Translation", (GeometryNodeAttributeInputMode)node_storage.input_type);
96 }
97 
98 } // namespace blender::nodes
99 
101 {
102  static bNodeType ntype;
103 
104  geo_node_type_base(&ntype, GEO_NODE_POINT_TRANSLATE, "Point Translate", NODE_CLASS_GEOMETRY, 0);
108  node_type_storage(&ntype,
109  "NodeGeometryPointTranslate",
114  nodeRegisterType(&ntype);
115 }
@ 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
#define GEO_NODE_POINT_TRANSLATE
Definition: BKE_node.h:1395
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
@ CD_PROP_FLOAT3
@ SOCK_VECTOR
@ SOCK_GEOMETRY
@ SOCK_STRING
GeometryNodeAttributeInputMode
@ GEO_NODE_ATTRIBUTE_INPUT_VECTOR
@ PROP_TRANSLATION
Definition: RNA_types.h:140
#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)
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 geo_node_point_translate_update(bNodeTree *UNUSED(ntree), bNode *node)
static void geo_node_point_translate_init(bNodeTree *UNUSED(tree), bNode *node)
static void execute_on_component(const GeoNodeExecParams &params, GeometryComponent &component)
void update_attribute_input_socket_availabilities(bNode &node, const StringRef name, const GeometryNodeAttributeInputMode mode, const bool name_is_available)
static void geo_node_point_translate_exec(GeoNodeExecParams params)
static bNodeSocketTemplate geo_node_point_translate_out[]
void register_node_type_geo_point_translate()
static bNodeSocketTemplate geo_node_point_translate_in[]
static void geo_node_point_translate_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