Blender  V2.93
node_geo_collection_info.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 "BLI_math_matrix.h"
18 
19 #include "DNA_collection_types.h"
20 
21 #include "UI_interface.h"
22 #include "UI_resources.h"
23 
24 #include "node_geometry_util.hh"
25 
27  {SOCK_COLLECTION, N_("Collection")},
28  {-1, ""},
29 };
30 
32  {SOCK_GEOMETRY, N_("Geometry")},
33  {-1, ""},
34 };
35 
37 {
38  uiItemR(layout, ptr, "transform_space", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
39 }
40 
41 namespace blender::nodes {
42 
44 {
45  bke::PersistentCollectionHandle collection_handle =
46  params.extract_input<bke::PersistentCollectionHandle>("Collection");
47  Collection *collection = params.handle_map().lookup(collection_handle);
48 
49  GeometrySet geometry_set_out;
50 
51  if (collection == nullptr) {
52  params.set_output("Geometry", geometry_set_out);
53  return;
54  }
55 
56  const bNode &bnode = params.node();
58  const bool transform_space_relative = (node_storage->transform_space ==
60 
61  InstancedData instance;
63  instance.data.collection = collection;
64 
65  InstancesComponent &instances = geometry_set_out.get_component_for_write<InstancesComponent>();
66 
67  float transform_mat[4][4];
68  unit_m4(transform_mat);
69  const Object *self_object = params.self_object();
70 
71  if (transform_space_relative) {
72  copy_v3_v3(transform_mat[3], collection->instance_offset);
73 
74  mul_m4_m4_pre(transform_mat, self_object->imat);
75  }
76  instances.add_instance(instance, transform_mat, -1);
77 
78  params.set_output("Geometry", geometry_set_out);
79 }
80 
82 {
84  sizeof(NodeGeometryCollectionInfo), __func__);
85  data->transform_space = GEO_NODE_TRANSFORM_SPACE_ORIGINAL;
86  node->storage = data;
87 }
88 
89 } // namespace blender::nodes
90 
92 {
93  static bNodeType ntype;
94 
95  geo_node_type_base(&ntype, GEO_NODE_COLLECTION_INFO, "Collection Info", NODE_CLASS_INPUT, 0);
98  node_type_storage(&ntype,
99  "NodeGeometryCollectionInfo",
104  nodeRegisterType(&ntype);
105 }
@ INSTANCE_DATA_TYPE_COLLECTION
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4559
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
#define NODE_CLASS_INPUT
Definition: BKE_node.h:334
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
void mul_m4_m4_pre(float R[4][4], const float A[4][4])
Definition: math_matrix.c:375
void unit_m4(float m[4][4])
Definition: rct.c:1140
MINLINE void copy_v3_v3(float r[3], const float a[3])
#define UNUSED(x)
#define N_(msgid)
Object groups, one object can be in many groups at once.
@ SOCK_COLLECTION
@ SOCK_GEOMETRY
@ GEO_NODE_TRANSFORM_SPACE_RELATIVE
@ GEO_NODE_TRANSFORM_SPACE_ORIGINAL
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 Point Attribute Sample GEO_NODE_COLLECTION_INFO
#define C
Definition: RandGen.cpp:39
@ UI_ITEM_R_EXPAND
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
void add_instance(Object *object, blender::float4x4 transform, const int id=-1)
OperationNode * node
void * tree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
static void geo_node_collection_info_node_init(bNodeTree *UNUSED(tree), bNode *node)
static void geo_node_collection_info_exec(GeoNodeExecParams params)
static void geo_node_collection_info_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
void register_node_type_geo_collection_info()
static bNodeSocketTemplate geo_node_collection_info_in[]
static bNodeSocketTemplate geo_node_collection_info_out[]
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)
InstancedDataType type
union InstancedData::@19 data
struct Collection * collection
float imat[4][4]
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
void * storage
PointerRNA * ptr
Definition: wm_files.c:3157