Commit: 7931716b69069e666666b43e8196bd7ec9f6e9c2
Author: Omar Emara
Date:   Mon Mar 14 15:34:27 2022 +0200
Branches: temp-viewport-compositor-compiler
https://developer.blender.org/rB7931716b69069e666666b43e8196bd7ec9f6e9c2

Viewport Compositor: Add default input acessors

Add input accessors that returns a default values if the input is not a
single value.

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

M       source/blender/nodes/NOD_compositor_execute.hh
M       source/blender/nodes/composite/nodes/node_composite_transform.cc
M       source/blender/nodes/intern/node_compositor_execute.cc

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

diff --git a/source/blender/nodes/NOD_compositor_execute.hh 
b/source/blender/nodes/NOD_compositor_execute.hh
index d9b928337da..16b8a53236a 100644
--- a/source/blender/nodes/NOD_compositor_execute.hh
+++ b/source/blender/nodes/NOD_compositor_execute.hh
@@ -298,6 +298,15 @@ class Result {
    * uninitialized value is returned. */
   float4 get_color_value() const;
 
+  /* Same as get_float_value but returns a default value if the result is not 
a single value. */
+  float get_float_value_default(float default_value) const;
+
+  /* Same as get_vector_value but returns a default value if the result is not 
a single value. */
+  float3 get_vector_value_default(const float3 &default_value) const;
+
+  /* Same as get_color_value but returns a default value if the result is not 
a single value. */
+  float4 get_color_value_default(const float4 &default_value) const;
+
   /* If the result is a single value result of type float, set its float value 
and upload it to the
    * texture. Otherwise, an undefined behavior is invoked. */
   void set_float_value(float value);
diff --git a/source/blender/nodes/composite/nodes/node_composite_transform.cc 
b/source/blender/nodes/composite/nodes/node_composite_transform.cc
index 9a4fdbebca2..c8029678531 100644
--- a/source/blender/nodes/composite/nodes/node_composite_transform.cc
+++ b/source/blender/nodes/composite/nodes/node_composite_transform.cc
@@ -70,10 +70,10 @@ class TransformOperation : public NodeOperation {
 
   void execute() override
   {
-    const float2 translation = float2(get_input("X").get_float_value(),
-                                      get_input("Y").get_float_value());
-    const float rotation = get_input("Angle").get_float_value();
-    const float2 scale = float2(get_input("Scale").get_float_value());
+    const float2 translation = 
float2(get_input("X").get_float_value_default(0.0f),
+                                      
get_input("Y").get_float_value_default(0.0f));
+    const float rotation = get_input("Angle").get_float_value_default(0.0f);
+    const float2 scale = 
float2(get_input("Scale").get_float_value_default(1.0f));
 
     const Transformation2D transformation = 
Transformation2D::from_translation_rotation_scale(
         translation, rotation, scale);
diff --git a/source/blender/nodes/intern/node_compositor_execute.cc 
b/source/blender/nodes/intern/node_compositor_execute.cc
index 87b25f64b1f..ad88c9a407b 100644
--- a/source/blender/nodes/intern/node_compositor_execute.cc
+++ b/source/blender/nodes/intern/node_compositor_execute.cc
@@ -231,6 +231,30 @@ float4 Result::get_color_value() const
   return float4(value_);
 }
 
+float Result::get_float_value_default(float default_value) const
+{
+  if (is_single_value()) {
+    return get_float_value();
+  }
+  return default_value;
+}
+
+float3 Result::get_vector_value_default(const float3 &default_value) const
+{
+  if (is_single_value()) {
+    return get_vector_value();
+  }
+  return default_value;
+}
+
+float4 Result::get_color_value_default(const float4 &default_value) const
+{
+  if (is_single_value()) {
+    return get_color_value();
+  }
+  return default_value;
+}
+
 void Result::set_float_value(float value)
 {
   *value_ = value;

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to