[Bf-blender-cvs] [c35feef5071] functions: new node to get the vertices of a mesh

Jacques Lucke noreply at git.blender.org
Tue Jul 16 18:20:22 CEST 2019


Commit: c35feef50719cd39c97f679107b3bc976837ff70
Author: Jacques Lucke
Date:   Tue Jul 16 15:36:22 2019 +0200
Branches: functions
https://developer.blender.org/rBc35feef50719cd39c97f679107b3bc976837ff70

new node to get the vertices of a mesh

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

A	release/scripts/startup/nodes/function_nodes/object_mesh.py
M	source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
M	source/blender/functions/functions/object_input.cpp
M	source/blender/functions/functions/object_input.hpp
M	source/blender/functions/types/lists.hpp

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

diff --git a/release/scripts/startup/nodes/function_nodes/object_mesh.py b/release/scripts/startup/nodes/function_nodes/object_mesh.py
new file mode 100644
index 00000000000..14dde09f618
--- /dev/null
+++ b/release/scripts/startup/nodes/function_nodes/object_mesh.py
@@ -0,0 +1,11 @@
+import bpy
+from bpy.props import *
+from .. base import FunctionNode
+
+class ObjectMeshNode(bpy.types.Node, FunctionNode):
+    bl_idname = "fn_ObjectMeshNode"
+    bl_label = "Object Mesh"
+
+    def declaration(self, builder):
+        builder.fixed_input("object", "Object", "Object")
+        builder.fixed_output("vertex_locations", "Vertex Locations", "Vector List")
diff --git a/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp b/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
index 2a82fc615ea..18052154f61 100644
--- a/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
@@ -282,6 +282,7 @@ void register_node_inserters(GraphInserters &inserters)
   inserters.reg_node_function("fn_RandomNumberNode", Functions::GET_FN_random_number);
   inserters.reg_node_function("fn_MapRangeNode", Functions::GET_FN_map_range);
   inserters.reg_node_function("fn_FloatRangeNode", Functions::GET_FN_float_range);
+  inserters.reg_node_function("fn_ObjectMeshNode", Functions::GET_FN_object_mesh_vertices);
 
   inserters.reg_node_inserter("fn_SeparateVectorNode", INSERT_separate_vector);
   inserters.reg_node_inserter("fn_CombineVectorNode", INSERT_combine_vector);
diff --git a/source/blender/functions/functions/object_input.cpp b/source/blender/functions/functions/object_input.cpp
index 23f06965bcb..66d9b14d94a 100644
--- a/source/blender/functions/functions/object_input.cpp
+++ b/source/blender/functions/functions/object_input.cpp
@@ -5,6 +5,8 @@
 
 #include "BLI_lazy_init.hpp"
 #include "DNA_object_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
 
 namespace FN {
 namespace Functions {
@@ -44,5 +46,49 @@ BLI_LAZY_INIT(SharedFunction, GET_FN_object_location)
   return fn;
 }
 
+class ObjectMeshVertices : public TupleCallBody {
+  void call(Tuple &fn_in, Tuple &fn_out, ExecutionContext &UNUSED(ctx)) const override
+  {
+    Object *object = fn_in.get<Object *>(0);
+    if (object == nullptr || object->type != OB_MESH) {
+      auto empty_list = SharedFloat3List::New();
+      fn_out.move_in(0, empty_list);
+      return;
+    }
+
+    Mesh *mesh = (Mesh *)object->data;
+
+    auto vertices = SharedFloat3List::New(mesh->totvert);
+    ArrayRef<float3> vertices_ref = vertices->as_array_ref();
+
+    float4x4 transform = object->obmat;
+
+    for (uint i = 0; i < mesh->totvert; i++) {
+      vertices_ref[i] = transform.transform_position(mesh->mvert[i].co);
+    }
+    fn_out.move_in(0, vertices);
+  }
+};
+
+class ObjectMeshDeps : public DepsBody {
+  void build_deps(FunctionDepsBuilder &builder) const
+  {
+    auto objects = builder.get_input_objects(0);
+    builder.add_geometry_dependency(objects);
+    builder.add_transform_dependency(objects);
+  }
+};
+
+BLI_LAZY_INIT(SharedFunction, GET_FN_object_mesh_vertices)
+{
+  FunctionBuilder builder;
+  builder.add_input("Object", GET_TYPE_object());
+  builder.add_output("Vertex Locations", GET_TYPE_float3_list());
+  auto fn = builder.build("Object Mesh Vertices");
+  fn->add_body<ObjectMeshVertices>();
+  fn->add_body<ObjectMeshDeps>();
+  return fn;
+}
+
 }  // namespace Functions
 }  // namespace FN
diff --git a/source/blender/functions/functions/object_input.hpp b/source/blender/functions/functions/object_input.hpp
index 5e4beb2adbf..013b37f277b 100644
--- a/source/blender/functions/functions/object_input.hpp
+++ b/source/blender/functions/functions/object_input.hpp
@@ -6,5 +6,7 @@ namespace FN {
 namespace Functions {
 
 SharedFunction &GET_FN_object_location();
-}
+SharedFunction &GET_FN_object_mesh_vertices();
+
+}  // namespace Functions
 }  // namespace FN
diff --git a/source/blender/functions/types/lists.hpp b/source/blender/functions/types/lists.hpp
index b04dd4f9901..cbfdb6c7f2f 100644
--- a/source/blender/functions/types/lists.hpp
+++ b/source/blender/functions/types/lists.hpp
@@ -40,6 +40,11 @@ template<typename T> class List : public BLI::SharedImmutable {
     return m_data;
   }
 
+  ArrayRef<T> as_array_ref() const
+  {
+    return m_data;
+  }
+
   void append(T value)
   {
     this->assert_mutable();
@@ -72,12 +77,12 @@ template<typename T> class List : public BLI::SharedImmutable {
     return m_data.size();
   }
 
-  T operator[](int index) const
+  T operator[](uint index) const
   {
     return m_data[index];
   }
 
-  T &operator[](int index)
+  T &operator[](uint index)
   {
     this->assert_mutable();
     return m_data[index];



More information about the Bf-blender-cvs mailing list