Commit: 9c102058e10bdac48efdfb311392ad332be72a5f
Author: Jacques Lucke
Date:   Tue Dec 3 11:51:47 2019 +0100
Branches: functions
https://developer.blender.org/rB9c102058e10bdac48efdfb311392ad332be72a5f

new Get Image Color on Surface node

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

M       release/scripts/startup/nodes/function_nodes/object_mesh.py
M       source/blender/functions/CMakeLists.txt
M       
source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
M       source/blender/functions/intern/multi_functions/mixed.cc
M       source/blender/functions/intern/multi_functions/mixed.h

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

diff --git a/release/scripts/startup/nodes/function_nodes/object_mesh.py 
b/release/scripts/startup/nodes/function_nodes/object_mesh.py
index 514348fcc60..a505c9e1962 100644
--- a/release/scripts/startup/nodes/function_nodes/object_mesh.py
+++ b/release/scripts/startup/nodes/function_nodes/object_mesh.py
@@ -1,6 +1,7 @@
 import bpy
 from bpy.props import *
 from .. base import FunctionNode
+from .. node_builder import NodeBuilder
 
 class ObjectMeshNode(bpy.types.Node, FunctionNode):
     bl_idname = "fn_ObjectMeshNode"
@@ -52,4 +53,21 @@ class GetWeightOnSurfaceNode(bpy.types.Node, FunctionNode):
         builder.fixed_output("weight", "Weight", "Float")
     
     def draw(self, layout):
-        layout.prop(self, "vertex_group_name", text="", icon="GROUP_VERTEX")
\ No newline at end of file
+        layout.prop(self, "vertex_group_name", text="", icon="GROUP_VERTEX")
+
+
+class GetImageColorOnSurfaceNode(bpy.types.Node, FunctionNode):
+    bl_idname = "fn_GetImageColorOnSurfaceNode"
+    bl_label = "Get Image Color on Surface"
+
+    image: PointerProperty(
+        name="Image",
+        type=bpy.types.Image,
+    )
+
+    def declaration(self, builder: NodeBuilder):
+        builder.fixed_input("location", "Location", "Surface Location")
+        builder.fixed_output("color", "Color", "Color")
+
+    def draw(self, layout):
+        layout.prop(self, "image", text="")
\ No newline at end of file
diff --git a/source/blender/functions/CMakeLists.txt 
b/source/blender/functions/CMakeLists.txt
index 81c31b155ec..3c23d7244c1 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -6,9 +6,10 @@ set(INC
   ../blenkernel
   ../depsgraph
   ../windowmanager
+  ../imbuf
   ../../../intern/guardedalloc
 )
-
+ 
 set(INC_SYS
   ${LLVM_INCLUDE_DIRS}
   ${PYTHON_INCLUDE_DIRS}
diff --git 
a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
 
b/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
index e1cb56d7424..14ca7251ab7 100644
--- 
a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
+++ 
b/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
@@ -71,6 +71,12 @@ static void 
INSERT_get_weight_on_surface(VNodeMFNetworkBuilder &builder)
   
builder.set_constructed_matching_fn<MF_GetWeightOnSurface>(std::move(group_name));
 }
 
+static void INSERT_get_image_color_on_surface(VNodeMFNetworkBuilder &builder)
+{
+  Image *image = (Image *)RNA_pointer_get(builder.rna(), "image").data;
+  builder.set_constructed_matching_fn<MF_GetImageColorOnSurface>(image);
+}
+
 static void INSERT_particle_is_in_group(VNodeMFNetworkBuilder &builder)
 {
   builder.set_constructed_matching_fn<MF_ParticleIsInGroup>();
@@ -173,60 +179,69 @@ static void build_variadic_math_fn(VNodeMFNetworkBuilder 
&builder,
 
 static void INSERT_add_floats(VNodeMFNetworkBuilder &builder)
 {
-  build_variadic_math_fn(builder, +[](float a, float b) -> float { return a + 
b; }, 0.0f);
+  build_variadic_math_fn(
+      builder, +[](float a, float b) -> float { return a + b; }, 0.0f);
 }
 
 static void INSERT_multiply_floats(VNodeMFNetworkBuilder &builder)
 {
-  build_variadic_math_fn(builder, +[](float a, float b) -> float { return a * 
b; }, 1.0f);
+  build_variadic_math_fn(
+      builder, +[](float a, float b) -> float { return a * b; }, 1.0f);
 }
 
 static void INSERT_minimum_floats(VNodeMFNetworkBuilder &builder)
 {
-  build_variadic_math_fn(builder, +[](float a, float b) -> float { return 
std::min(a, b); }, 0.0f);
+  build_variadic_math_fn(
+      builder, +[](float a, float b) -> float { return std::min(a, b); }, 
0.0f);
 }
 
 static void INSERT_maximum_floats(VNodeMFNetworkBuilder &builder)
 {
-  build_variadic_math_fn(builder, +[](float a, float b) -> float { return 
std::max(a, b); }, 0.0f);
+  build_variadic_math_fn(
+      builder, +[](float a, float b) -> float { return std::max(a, b); }, 
0.0f);
 }
 
 static void INSERT_subtract_floats(VNodeMFNetworkBuilder &builder)
 {
-  build_math_fn(builder, +[](float a, float b) -> float { return a - b; });
+  build_math_fn(
+      builder, +[](float a, float b) -> float { return a - b; });
 }
 
 static void INSERT_divide_floats(VNodeMFNetworkBuilder &builder)
 {
-  build_math_fn(builder, +[](float a, float b) -> float { return (b != 0.0f) ? 
a / b : 0.0f; });
+  build_math_fn(
+      builder, +[](float a, float b) -> float { return (b != 0.0f) ? a / b : 
0.0f; });
 }
 
 static void INSERT_power_floats(VNodeMFNetworkBuilder &builder)
 {
-  build_math_fn(builder, +[](float a, float b) -> float {
-    return (a >= 0.0f) ? (float)std::pow(a, b) : 0.0f;
-  });
+  build_math_fn(
+      builder,
+      +[](float a, float b) -> float { return (a >= 0.0f) ? (float)std::pow(a, 
b) : 0.0f; });
 }
 
 static void INSERT_sqrt_float(VNodeMFNetworkBuilder &builder)
 {
-  build_math_fn(builder,
-                +[](float a) -> float { return (a >= 0.0f) ? 
(float)std::sqrt(a) : 0.0f; });
+  build_math_fn(
+      builder, +[](float a) -> float { return (a >= 0.0f) ? 
(float)std::sqrt(a) : 0.0f; });
 }
 
 static void INSERT_abs_float(VNodeMFNetworkBuilder &builder)
 {
-  build_math_fn(builder, +[](float a) -> float { return std::abs(a); });
+  build_math_fn(
+      builder, +[](float a) -> float { return std::abs(a); });
 }
 
 static void INSERT_sine_float(VNodeMFNetworkBuilder &builder)
 {
-  build_math_fn(builder, +[](float a) -> float { return std::sin(a); });
+  build_math_fn(
+      builder, +[](float a) -> float { return std::sin(a); });
 }
 
 static void INSERT_cosine_float(VNodeMFNetworkBuilder &builder)
 {
-  build_math_fn(builder, +[](float a) -> float { return std::cos(a); });
+  build_math_fn(
+      builder, +[](float a) -> float { return std::cos(a); });
 }
 
 static void INSERT_add_vectors(VNodeMFNetworkBuilder &builder)
@@ -241,7 +256,8 @@ static void INSERT_multiply_vectors(VNodeMFNetworkBuilder 
&builder)
 
 static void INSERT_subtract_vectors(VNodeMFNetworkBuilder &builder)
 {
-  build_math_fn(builder, +[](float3 a, float3 b) -> float3 { return a - b; });
+  build_math_fn(
+      builder, +[](float3 a, float3 b) -> float3 { return a - b; });
 }
 
 static void INSERT_divide_vectors(VNodeMFNetworkBuilder &builder)
@@ -256,7 +272,8 @@ static void 
INSERT_vector_cross_product(VNodeMFNetworkBuilder &builder)
 
 static void INSERT_reflect_vector(VNodeMFNetworkBuilder &builder)
 {
-  build_math_fn(builder, +[](float3 a, float3 b) { return 
a.reflected(b.normalized()); });
+  build_math_fn(
+      builder, +[](float3 a, float3 b) { return a.reflected(b.normalized()); 
});
 }
 
 static void INSERT_project_vector(VNodeMFNetworkBuilder &builder)
@@ -276,22 +293,26 @@ static void INSERT_vector_distance(VNodeMFNetworkBuilder 
&builder)
 
 static void INSERT_boolean_and(VNodeMFNetworkBuilder &builder)
 {
-  build_variadic_math_fn(builder, +[](bool a, bool b) { return a && b; }, 
true);
+  build_variadic_math_fn(
+      builder, +[](bool a, bool b) { return a && b; }, true);
 }
 
 static void INSERT_boolean_or(VNodeMFNetworkBuilder &builder)
 {
-  build_variadic_math_fn(builder, +[](bool a, bool b) { return a || b; }, 
false);
+  build_variadic_math_fn(
+      builder, +[](bool a, bool b) { return a || b; }, false);
 }
 
 static void INSERT_boolean_not(VNodeMFNetworkBuilder &builder)
 {
-  build_math_fn(builder, +[](bool a) -> bool { return !a; });
+  build_math_fn(
+      builder, +[](bool a) -> bool { return !a; });
 }
 
 static void INSERT_compare(VNodeMFNetworkBuilder &builder)
 {
-  build_math_fn(builder, +[](float a, float b) -> bool { return a < b; });
+  build_math_fn(
+      builder, +[](float a, float b) -> bool { return a < b; });
 }
 
 static void INSERT_perlin_noise(VNodeMFNetworkBuilder &builder)
@@ -365,6 +386,8 @@ void 
add_inlined_tree_node_mapping_info(VTreeMultiFunctionMappings &mappings)
   mappings.xnode_inserters.add_new("fn_ObjectMeshNode", 
INSERT_object_mesh_info);
   mappings.xnode_inserters.add_new("fn_GetPositionOnSurfaceNode", 
INSERT_get_position_on_surface);
   mappings.xnode_inserters.add_new("fn_GetWeightOnSurfaceNode", 
INSERT_get_weight_on_surface);
+  mappings.xnode_inserters.add_new("fn_GetImageColorOnSurfaceNode",
+                                   INSERT_get_image_color_on_surface);
   mappings.xnode_inserters.add_new("fn_IsInGroupNode", 
INSERT_particle_is_in_group);
   mappings.xnode_inserters.add_new("fn_TextLengthNode", INSERT_text_length);
   mappings.xnode_inserters.add_new("fn_VertexInfoNode", INSERT_vertex_info);
diff --git a/source/blender/functions/intern/multi_functions/mixed.cc 
b/source/blender/functions/intern/multi_functions/mixed.cc
index 37f90595534..6969bc0d649 100644
--- a/source/blender/functions/intern/multi_functions/mixed.cc
+++ b/source/blender/functions/intern/multi_functions/mixed.cc
@@ -14,7 +14,11 @@
 #include "DNA_object_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
+#include "DNA_customdata_types.h"
 
+#include "IMB_imbuf_types.h"
+
+#include "BKE_customdata.h"
 #include "BKE_surface_location.h"
 #include "BKE_mesh_runtime.h"
 #include "BKE_deform.h"
@@ -22,8 +26,10 @@
 namespace FN {
 
 using BKE::SurfaceLocation;
+using BLI::float2;
 using BLI::float3;
 using BLI::float4x4;
+using BLI::rgba_b;
 using BLI::rgba_f;
 using BLI::TemporaryArray;
 
@@ -354,7 +360,7 @@ void MF_GetWeightOnSurface::call(MFMask mask, MFParams 
params, MFContext context
       continue;
     }
 
-    Object *object = 
persistent_surfaces_opt->data->lookup((uint32_t)location.surface_id());
+    Object *object = 
persistent_surfaces_opt->data->lookup(location.surface_id());
     if (object == nullptr) {
       r_weights[i] = 0.0f;
       continue;
@@ -389,6 +395,95 @@ void MF_GetWeightOnSurface::call(MFMask mask, MFParams 
params, MFContext context
   }
 }
 
+MF_GetImageColorOnSurface::MF_GetImageColorOnSurface(Image *image) : 
m_image(image)
+{
+  MFSignatureBuilder signature("Get Image Color on Surface");
+  signature.single_input<SurfaceLocation>("Surface Location");
+  signature.single_output<rgba_f>("Color");
+  this->set_signature(signature);
+}
+
+static void get_colors_on_surface(MFMask mask,
+                                  MFParams params,


@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to