Blender  V2.93
node_geo_object_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 "UI_interface.h"
20 #include "UI_resources.h"
21 
22 #include "node_geometry_util.hh"
23 
25  {SOCK_OBJECT, N_("Object")},
26  {-1, ""},
27 };
28 
30  {SOCK_VECTOR, N_("Location")},
31  {SOCK_VECTOR, N_("Rotation")},
32  {SOCK_VECTOR, N_("Scale")},
33  {SOCK_GEOMETRY, N_("Geometry")},
34  {-1, ""},
35 };
36 
38 {
39  uiItemR(layout, ptr, "transform_space", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
40 }
41 
42 namespace blender::nodes {
44 {
45  const bNode &bnode = params.node();
46  NodeGeometryObjectInfo *node_storage = (NodeGeometryObjectInfo *)bnode.storage;
47  const bool transform_space_relative = (node_storage->transform_space ==
49 
50  bke::PersistentObjectHandle object_handle = params.extract_input<bke::PersistentObjectHandle>(
51  "Object");
52  Object *object = params.handle_map().lookup(object_handle);
53 
54  float3 location = {0, 0, 0};
55  float3 rotation = {0, 0, 0};
56  float3 scale = {0, 0, 0};
57  GeometrySet geometry_set;
58 
59  const Object *self_object = params.self_object();
60 
61  if (object != nullptr) {
62  float transform[4][4];
63  mul_m4_m4m4(transform, self_object->imat, object->obmat);
64 
65  float quaternion[4];
66  if (transform_space_relative) {
67  mat4_decompose(location, quaternion, scale, transform);
68  }
69  else {
70  mat4_decompose(location, quaternion, scale, object->obmat);
71  }
72  quat_to_eul(rotation, quaternion);
73 
74  if (object != self_object) {
76 
77  if (transform_space_relative) {
78  instances.add_instance(object, transform);
79  }
80  else {
81  float unit_transform[4][4];
82  unit_m4(unit_transform);
83  instances.add_instance(object, unit_transform);
84  }
85  }
86  }
87 
88  params.set_output("Location", location);
89  params.set_output("Rotation", rotation);
90  params.set_output("Scale", scale);
91  params.set_output("Geometry", geometry_set);
92 }
93 
95 {
97  sizeof(NodeGeometryObjectInfo), __func__);
98  data->transform_space = GEO_NODE_TRANSFORM_SPACE_ORIGINAL;
99  node->storage = data;
100 }
101 
102 } // namespace blender::nodes
103 
105 {
106  static bNodeType ntype;
107 
108  geo_node_type_base(&ntype, GEO_NODE_OBJECT_INFO, "Object Info", NODE_CLASS_INPUT, 0);
112  &ntype, "NodeGeometryObjectInfo", node_free_standard_storage, node_copy_standard_storage);
115  nodeRegisterType(&ntype);
116 }
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_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:262
void mat4_decompose(float loc[3], float quat[4], float size[3], const float wmat[4][4])
Definition: math_matrix.c:2265
void unit_m4(float m[4][4])
Definition: rct.c:1140
void quat_to_eul(float eul[3], const float quat[4])
#define UNUSED(x)
#define N_(msgid)
@ SOCK_VECTOR
@ SOCK_GEOMETRY
@ SOCK_OBJECT
@ 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 GEO_NODE_OBJECT_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)
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
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_object_info_exec(GeoNodeExecParams params)
static void geo_node_object_info_node_init(bNodeTree *UNUSED(tree), bNode *node)
static void geo_node_object_info_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
void register_node_type_geo_object_info()
static bNodeSocketTemplate geo_node_object_info_out[]
static bNodeSocketTemplate geo_node_object_info_in[]
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)
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