[Bf-blender-cvs] [28a70ff15c4] functions: new surface location data type

Jacques Lucke noreply at git.blender.org
Sat Nov 30 16:40:11 CET 2019


Commit: 28a70ff15c461631c62c9c28702438521461b043
Author: Jacques Lucke
Date:   Wed Nov 27 17:06:58 2019 +0100
Branches: functions
https://developer.blender.org/rB28a70ff15c461631c62c9c28702438521461b043

new surface location data type

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

M	release/scripts/startup/nodes/sockets.py
M	release/scripts/startup/nodes/types.py
A	source/blender/blenkernel/BKE_surface_location.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/functions/intern/cpp_types.cc
M	source/blender/functions/intern/inlined_tree_multi_function_network/mappings_sockets.cc

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

diff --git a/release/scripts/startup/nodes/sockets.py b/release/scripts/startup/nodes/sockets.py
index 59d60fe4cac..cae9fa23c61 100644
--- a/release/scripts/startup/nodes/sockets.py
+++ b/release/scripts/startup/nodes/sockets.py
@@ -177,6 +177,10 @@ ColorListSocket = create_simple_data_socket(
     "fn_ColorListSocket", "Color List", (0.8, 0.8, 0.2, 0.5))
 TextListSocket = create_simple_data_socket(
     "fn_TextListSocket", "Text List", (0.8, 0.8, 0.8, 0.5))
+SurfaceLocationSocket = create_simple_data_socket(
+    "fn_SurfaceLocationSocket", "Surface Location", (0.2, 0.8, 0.2, 1.0))
+SurfaceLocationListSocket = create_simple_data_socket(
+    "fn_SurfaceLocationListSocket", "Surface Location List", (0.2, 0.8, 0.2, 0.5))
 
 class ExecuteSocket(bpy.types.NodeSocket, BaseSocket):
     bl_idname = "fn_ExecuteSocket"
diff --git a/release/scripts/startup/nodes/types.py b/release/scripts/startup/nodes/types.py
index 6ad800d983f..6125c6674c7 100644
--- a/release/scripts/startup/nodes/types.py
+++ b/release/scripts/startup/nodes/types.py
@@ -10,5 +10,6 @@ type_infos.insert_data_type(s.BooleanSocket, s.BooleanListSocket)
 type_infos.insert_data_type(s.ObjectSocket, s.ObjectListSocket)
 type_infos.insert_data_type(s.ColorSocket, s.ColorListSocket)
 type_infos.insert_data_type(s.TextSocket, s.TextListSocket)
+type_infos.insert_data_type(s.SurfaceLocationSocket, s.SurfaceLocationListSocket)
 
 type_infos.insert_conversion_group(["Boolean", "Integer", "Float"])
diff --git a/source/blender/blenkernel/BKE_surface_location.h b/source/blender/blenkernel/BKE_surface_location.h
new file mode 100644
index 00000000000..9093ca0779e
--- /dev/null
+++ b/source/blender/blenkernel/BKE_surface_location.h
@@ -0,0 +1,35 @@
+#ifndef __BKE_SURFACE_LOCATION_H__
+#define __BKE_SURFACE_LOCATION_H__
+
+#include "BLI_utildefines.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * References a point on a surface. If the surface moves, the point moves with it. The surface is
+ * identified by an integer.
+ *
+ * For now, only points on triangle meshes are supported, support for curves could be added too.
+ */
+typedef struct SurfaceLocation {
+  /**
+   * Identifies the surface that is being referenced. This is usually a hash of the name of an
+   * object. The location is invalid, if this id is negative.
+   */
+  int32_t surface_id;
+
+  /* Index of the triangle that contains the referenced location. */
+  uint32_t triangle_index;
+
+  /* Barycentric coordinates of the referenced location inside the triangle. */
+  float weight1, weight2, weight3;
+
+} SurfaceLocation;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BKE_SURFACE_LOCATION_H__ */
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 5733753bbf1..01120ea369c 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -355,6 +355,7 @@ set(SRC
   BKE_subdiv_mesh.h
   BKE_subdiv_topology.h
   BKE_subsurf.h
+  BKE_surface_location.h
   BKE_text.h
   BKE_text_suggestions.h
   BKE_texture.h
diff --git a/source/blender/functions/intern/cpp_types.cc b/source/blender/functions/intern/cpp_types.cc
index d1d48cb0101..55838287076 100644
--- a/source/blender/functions/intern/cpp_types.cc
+++ b/source/blender/functions/intern/cpp_types.cc
@@ -5,6 +5,8 @@
 
 #include "BLI_math_cxx.h"
 
+#include "BKE_surface_location.h"
+
 namespace FN {
 
 void init_cpp_types()
@@ -99,5 +101,6 @@ MAKE_CPP_TYPE(int32, int32_t)
 MAKE_CPP_TYPE(rgba_f, BLI::rgba_f)
 MAKE_CPP_TYPE(float3, BLI::float3)
 MAKE_CPP_TYPE(string, std::string)
+MAKE_CPP_TYPE(SurfaceLocation, SurfaceLocation)
 
 }  // namespace FN
diff --git a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_sockets.cc b/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_sockets.cc
index 3e2f18a7183..883f57e9b87 100644
--- a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_sockets.cc
+++ b/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_sockets.cc
@@ -3,6 +3,8 @@
 
 #include "BLI_math_cxx.h"
 
+#include "BKE_surface_location.h"
+
 #include "FN_multi_functions.h"
 
 namespace FN {
@@ -56,6 +58,13 @@ static void INSERT_text_socket(VSocketMFNetworkBuilder &builder)
   builder.set_constant_value(std::move(text));
 }
 
+static void INSERT_surface_location_socket(VSocketMFNetworkBuilder &builder)
+{
+  SurfaceLocation location;
+  location.surface_id = -1;
+  builder.set_constant_value(location);
+}
+
 template<typename T> static void INSERT_empty_list_socket(VSocketMFNetworkBuilder &builder)
 {
   const MultiFunction &fn = builder.network_builder().construct_fn<FN::MF_EmptyList<T>>();
@@ -95,10 +104,11 @@ static std::pair<MFBuilderInputSocket *, MFBuilderOutputSocket *> INSERT_element
 template<typename T>
 static void add_basic_type(VTreeMultiFunctionMappings &mappings,
                            StringRef base_name,
+                           StringRef base_name_without_spaces,
                            InsertVSocketFunction base_inserter)
 {
-  std::string base_idname = "fn_" + base_name + "Socket";
-  std::string list_idname = "fn_" + base_name + "ListSocket";
+  std::string base_idname = "fn_" + base_name_without_spaces + "Socket";
+  std::string list_idname = "fn_" + base_name_without_spaces + "ListSocket";
   std::string list_name = base_name + " List";
 
   mappings.cpp_type_by_type_name.add_new(base_name, &CPP_TYPE<T>());
@@ -112,6 +122,14 @@ static void add_basic_type(VTreeMultiFunctionMappings &mappings,
   mappings.type_name_from_cpp_type.add_new(&CPP_TYPE<T>(), base_name);
 }
 
+template<typename T>
+static void add_basic_type(VTreeMultiFunctionMappings &mappings,
+                           StringRef base_name,
+                           InsertVSocketFunction base_inserter)
+{
+  add_basic_type<T>(mappings, base_name, base_name, base_inserter);
+}
+
 template<typename FromT, typename ToT>
 static void add_implicit_conversion(VTreeMultiFunctionMappings &mappings)
 {
@@ -146,6 +164,8 @@ void add_inlined_tree_socket_mapping_info(VTreeMultiFunctionMappings &mappings)
   add_basic_type<std::string>(mappings, "Text", INSERT_text_socket);
   add_basic_type<bool>(mappings, "Boolean", INSERT_bool_socket);
   add_basic_type<BLI::rgba_f>(mappings, "Color", INSERT_color_socket);
+  add_basic_type<SurfaceLocation>(
+      mappings, "Surface Location", "SurfaceLocation", INSERT_surface_location_socket);
 
   add_bidirectional_implicit_conversion<float, int32_t>(mappings);
   add_bidirectional_implicit_conversion<float, bool>(mappings);



More information about the Bf-blender-cvs mailing list