[Bf-blender-cvs] [c4352f44bc8] geometry-nodes: Geometry Nodes: initial Object Info node

Jacques Lucke noreply at git.blender.org
Thu Nov 12 13:30:57 CET 2020


Commit: c4352f44bc8b2e905f5ea1fe79ca23b13f0068f9
Author: Jacques Lucke
Date:   Thu Nov 12 12:24:07 2020 +0100
Branches: geometry-nodes
https://developer.blender.org/rBc4352f44bc8b2e905f5ea1fe79ca23b13f0068f9

Geometry Nodes: initial Object Info node

This node takes an object as input and outputs its location, rotation,
scale and geometry. Right now the loc/rot/scale are extracted from the
objects `obmat`. The geometry is just the mesh in the local space of the
source object.

We will likely need some more control over space transformations
using enums in the node, but those can be added a bit later.

===================================================================

M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/node.c
M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/NOD_geometry.h
M	source/blender/nodes/NOD_static_types.h
A	source/blender/nodes/geometry/nodes/node_geo_object_info.cc

===================================================================

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index 4d53ca8a228..67103489b39 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -485,6 +485,9 @@ def not_implemented_node(idname):
 
 geometry_node_categories = [
     # Geometry Nodes
+    GeometryNodeCategory("GEO_INPUT", "Input", items=[
+        NodeItem("GeometryNodeObjectInfo"),
+    ]),
     GeometryNodeCategory("GEO_MESH", "Mesh", items=[
         NodeItem("GeometryNodeTriangulate"),
         NodeItem("GeometryNodeEdgeSplit"),
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 5ea99b14dbb..07833b93f43 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1347,6 +1347,7 @@ int ntreeTexExecTree(struct bNodeTree *ntree,
 #define GEO_NODE_POINT_DISTRIBUTE 1004
 #define GEO_NODE_POINT_INSTANCE 1005
 #define GEO_NODE_SUBDIVISION_SURFACE 1006
+#define GEO_NODE_OBJECT_INFO 1007
 
 /** \} */
 
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index fd3f111c103..9f3793e76fb 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -4687,6 +4687,7 @@ static void registerGeometryNodes(void)
   register_node_type_geo_boolean();
   register_node_type_geo_point_distribute();
   register_node_type_geo_point_instance();
+  register_node_type_geo_object_info();
 }
 
 static void registerFunctionNodes(void)
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index bf3c259539b..74bdd44cc7a 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -141,6 +141,7 @@ set(SRC
   geometry/nodes/node_geo_common.cc
   geometry/nodes/node_geo_boolean.cc
   geometry/nodes/node_geo_edge_split.cc
+  geometry/nodes/node_geo_object_info.cc
   geometry/nodes/node_geo_subdivision_surface.cc
   geometry/nodes/node_geo_point_distribute.cc
   geometry/nodes/node_geo_point_instance.cc
diff --git a/source/blender/nodes/NOD_geometry.h b/source/blender/nodes/NOD_geometry.h
index 5a38947a2ca..16b99070cba 100644
--- a/source/blender/nodes/NOD_geometry.h
+++ b/source/blender/nodes/NOD_geometry.h
@@ -33,6 +33,7 @@ void register_node_type_geo_subdivision_surface(void);
 void register_node_type_geo_triangulate(void);
 void register_node_type_geo_point_distribute(void);
 void register_node_type_geo_point_instance(void);
+void register_node_type_geo_object_info(void);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 4bc99d0de08..984ba0ebd4e 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -273,7 +273,7 @@ DefNode(GeometryNode, GEO_NODE_SUBDIVISION_SURFACE, 0, "SUBDIVISION_SURFACE", Su
 DefNode(GeometryNode, GEO_NODE_BOOLEAN, def_geo_boolean, "BOOLEAN", Boolean, "Boolean", "")
 DefNode(GeometryNode, GEO_NODE_POINT_DISTRIBUTE, 0, "POINT_DISTRIBUTE", PointDistribute, "Point Distribute", "")
 DefNode(GeometryNode, GEO_NODE_POINT_INSTANCE, 0, "POINT_INSTANCE", PointInstance, "Point Instance", "")
-
+DefNode(GeometryNode, GEO_NODE_OBJECT_INFO, 0, "OBJECT_INFO", ObjectInfo, "Object Info", "")
 
 /* undefine macros */
 #undef DefNode
diff --git a/source/blender/nodes/geometry/nodes/node_geo_object_info.cc b/source/blender/nodes/geometry/nodes/node_geo_object_info.cc
new file mode 100644
index 00000000000..3ee6ae2453a
--- /dev/null
+++ b/source/blender/nodes/geometry/nodes/node_geo_object_info.cc
@@ -0,0 +1,79 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "node_geometry_util.hh"
+
+#include "BKE_mesh.h"
+#include "BKE_mesh_wrapper.h"
+#include "BKE_modifier.h"
+
+static bNodeSocketTemplate geo_node_object_info_in[] = {
+    {SOCK_OBJECT, N_("Object")},
+    {-1, ""},
+};
+
+static bNodeSocketTemplate geo_node_object_info_out[] = {
+    {SOCK_VECTOR, N_("Location")},
+    {SOCK_VECTOR, N_("Rotation")},
+    {SOCK_VECTOR, N_("Scale")},
+    {SOCK_GEOMETRY, N_("Geometry")},
+    {-1, ""},
+};
+
+namespace blender::nodes {
+static void geo_object_info_exec(bNode *UNUSED(node), GeoNodeInputs inputs, GeoNodeOutputs outputs)
+{
+  bke::PersistentObjectHandle object_handle = inputs.extract<bke::PersistentObjectHandle>(
+      "Object");
+  Object *object = inputs.handle_map().lookup(object_handle);
+
+  float3 location = {0, 0, 0};
+  float3 rotation = {0, 0, 0};
+  float3 scale = {0, 0, 0};
+  GeometrySetPtr geometry_set;
+
+  if (object != nullptr) {
+    float quaternion[4];
+    mat4_decompose(location, quaternion, scale, object->obmat);
+    quat_to_eul(rotation, quaternion);
+
+    if (object->type == OB_MESH) {
+      Mesh *mesh = BKE_modifier_get_evaluated_mesh_from_evaluated_object(object, false);
+      if (mesh != nullptr) {
+        BKE_mesh_wrapper_ensure_mdata(mesh);
+        /* Make a copy because the life time of the other mesh might be shorter. */
+        Mesh *copied_mesh = BKE_mesh_copy_for_eval(mesh, false);
+        geometry_set = GeometrySet::create_with_mesh(copied_mesh);
+      }
+    }
+  }
+
+  outputs.set("Location", location);
+  outputs.set("Rotation", rotation);
+  outputs.set("Scale", scale);
+  outputs.set("Geometry", geometry_set);
+}
+}  // namespace blender::nodes
+
+void register_node_type_geo_object_info()
+{
+  static bNodeType ntype;
+
+  geo_node_type_base(&ntype, GEO_NODE_OBJECT_INFO, "Object Info", 0, 0);
+  node_type_socket_templates(&ntype, geo_node_object_info_in, geo_node_object_info_out);
+  ntype.geometry_node_execute = blender::nodes::geo_object_info_exec;
+  nodeRegisterType(&ntype);
+}



More information about the Bf-blender-cvs mailing list