[Bf-blender-cvs] [d0eafffed40] functions: Initial Falloff implementation
Jacques Lucke
noreply at git.blender.org
Fri Sep 6 16:55:35 CEST 2019
Commit: d0eafffed409c57faebf2489353c6d0adefe07cd
Author: Jacques Lucke
Date: Fri Sep 6 11:21:53 2019 +0200
Branches: functions
https://developer.blender.org/rBd0eafffed409c57faebf2489353c6d0adefe07cd
Initial Falloff implementation
===================================================================
M release/scripts/startup/nodes/bparticle_nodes/gravity_force.py
A release/scripts/startup/nodes/function_nodes/falloffs.py
M release/scripts/startup/nodes/sockets.py
M release/scripts/startup/nodes/types.py
A source/blender/blenkernel/BKE_falloff.hpp
M source/blender/blenkernel/CMakeLists.txt
M source/blender/functions/CMakeLists.txt
M source/blender/functions/FN_functions.hpp
M source/blender/functions/FN_types.hpp
M source/blender/functions/backends/cpp/cpp_type_info.hpp
M source/blender/functions/backends/llvm/llvm_type_info.hpp
M source/blender/functions/frontends/data_flow_nodes/mappings/node_inserters.cpp
M source/blender/functions/frontends/data_flow_nodes/mappings/socket_loaders.cpp
M source/blender/functions/frontends/data_flow_nodes/mappings/type_mappings.cpp
A source/blender/functions/functions/falloffs.cpp
A source/blender/functions/functions/falloffs.hpp
M source/blender/functions/functions/lists.cpp
A source/blender/functions/types/falloff.cpp
A source/blender/functions/types/falloff.hpp
M source/blender/functions/types/initialization.cpp
M source/blender/simulations/bparticles/forces.cpp
M source/blender/simulations/bparticles/forces.hpp
M source/blender/simulations/bparticles/node_frontend.cpp
===================================================================
diff --git a/release/scripts/startup/nodes/bparticle_nodes/gravity_force.py b/release/scripts/startup/nodes/bparticle_nodes/gravity_force.py
index 8a0691f0061..f83eb7ba0aa 100644
--- a/release/scripts/startup/nodes/bparticle_nodes/gravity_force.py
+++ b/release/scripts/startup/nodes/bparticle_nodes/gravity_force.py
@@ -9,4 +9,5 @@ class GravityForceNode(bpy.types.Node, BParticlesNode):
def declaration(self, builder: NodeBuilder):
builder.fixed_input("direction", "Direction", "Vector", default=(0, 0, -1))
+ builder.fixed_input("falloff", "Falloff", "Falloff")
builder.particle_effector_output("force", "Force")
diff --git a/release/scripts/startup/nodes/function_nodes/falloffs.py b/release/scripts/startup/nodes/function_nodes/falloffs.py
new file mode 100644
index 00000000000..f63014b0bff
--- /dev/null
+++ b/release/scripts/startup/nodes/function_nodes/falloffs.py
@@ -0,0 +1,13 @@
+import bpy
+from .. node_builder import NodeBuilder
+from .. base import FunctionNode
+
+class PointDistanceFalloffNode(bpy.types.Node, FunctionNode):
+ bl_idname = "fn_PointDistanceFalloffNode"
+ bl_label = "Point Distance Falloff"
+
+ def declaration(self, builder: NodeBuilder):
+ builder.fixed_input("point", "Point", "Vector")
+ builder.fixed_input("min_distance", "Min Distance", "Float")
+ builder.fixed_input("max_distance", "Max Distance", "Float", default=1)
+ builder.fixed_output("falloff", "Falloff", "Falloff")
diff --git a/release/scripts/startup/nodes/sockets.py b/release/scripts/startup/nodes/sockets.py
index e10c5538833..9b8bc29ae47 100644
--- a/release/scripts/startup/nodes/sockets.py
+++ b/release/scripts/startup/nodes/sockets.py
@@ -154,6 +154,28 @@ class TextSocket(bpy.types.NodeSocket, DataSocket):
def restore_state(self, state):
self.value = state
+class FalloffSocket(bpy.types.NodeSocket, DataSocket):
+ bl_idname = "fn_FalloffSocket"
+ bl_label = "Falloff Socket"
+ data_type = "Falloff"
+ color = (0.2, 0.8, 0.2, 1)
+
+ value: FloatProperty(
+ name="Value",
+ default=1.0,
+ soft_min=0.0,
+ soft_max=1.0,
+ )
+
+ def draw_property(self, layout, node, text):
+ layout.prop(self, "value", text=text, slider=True)
+
+ def get_state(self):
+ return self.value
+
+ def restore_state(self, state):
+ self.value = state
+
def create_simple_data_socket(idname, data_type, color):
return type(idname, (bpy.types.NodeSocket, DataSocket),
{
@@ -177,6 +199,8 @@ 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))
+FalloffListSocket = create_simple_data_socket(
+ "fn_FalloffListSocket", "Falloff List", (0.2, 0.8, 0.2, 0.5))
class ExecuteSocket(bpy.types.NodeSocket, BaseSocket):
bl_idname = "bp_ExecuteSocket"
diff --git a/release/scripts/startup/nodes/types.py b/release/scripts/startup/nodes/types.py
index 6ad800d983f..3883080c461 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.FalloffSocket, s.FalloffListSocket)
type_infos.insert_conversion_group(["Boolean", "Integer", "Float"])
diff --git a/source/blender/blenkernel/BKE_falloff.hpp b/source/blender/blenkernel/BKE_falloff.hpp
new file mode 100644
index 00000000000..f1f96398624
--- /dev/null
+++ b/source/blender/blenkernel/BKE_falloff.hpp
@@ -0,0 +1,82 @@
+#pragma once
+
+#include "BKE_attributes_ref.hpp"
+
+namespace BKE {
+
+class Falloff {
+ public:
+ virtual ~Falloff()
+ {
+ }
+ virtual Falloff *clone() const = 0;
+
+ /**
+ * The indices are expected to be sorted. Also no index must exist more than once.
+ */
+ virtual void compute(AttributesRef attributes,
+ ArrayRef<uint> indices,
+ MutableArrayRef<float> r_weights) = 0;
+};
+
+class ConstantFalloff : public Falloff {
+ private:
+ float m_weight;
+
+ public:
+ ConstantFalloff(float weight) : m_weight(weight)
+ {
+ }
+
+ Falloff *clone() const
+ {
+ return new ConstantFalloff(m_weight);
+ }
+
+ void compute(AttributesRef UNUSED(attributes),
+ ArrayRef<uint> indices,
+ MutableArrayRef<float> r_weights)
+ {
+ for (uint index : indices) {
+ r_weights[index] = m_weight;
+ }
+ }
+};
+
+class PointDistanceFalloff : public Falloff {
+ private:
+ float3 m_point;
+ float m_min_distance;
+ float m_max_distance;
+
+ public:
+ PointDistanceFalloff(float3 point, float min_distance, float max_distance)
+ : m_point(point), m_min_distance(min_distance), m_max_distance(max_distance)
+ {
+ }
+
+ Falloff *clone() const
+ {
+ return new PointDistanceFalloff(m_point, m_min_distance, m_max_distance);
+ }
+
+ void compute(AttributesRef attributes, ArrayRef<uint> indices, MutableArrayRef<float> r_weights)
+ {
+ auto positions = attributes.get<float3>("Position");
+ float distance_diff = m_max_distance - m_min_distance;
+
+ for (uint index : indices) {
+ float3 position = positions[index];
+ float distance = float3::distance(position, m_point);
+
+ float weight = 0;
+ if (distance_diff > 0) {
+ weight = 1.0f - (distance - m_min_distance) / distance_diff;
+ CLAMP(weight, 0.0f, 1.0f);
+ }
+ r_weights[index] = weight;
+ }
+ }
+};
+
+} // namespace BKE
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index f20b138d36b..d268f06cf63 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -271,6 +271,7 @@ set(SRC
BKE_editmesh_cache.h
BKE_editmesh_tangent.h
BKE_effect.h
+ BKE_falloff.hpp
BKE_fcurve.h
BKE_fluidsim.h
BKE_font.h
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index 0658650b4e3..b1c6fa3cc49 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -112,6 +112,8 @@ set(SRC
types/external.cpp
types/string_type.hpp
types/string_type.cpp
+ types/falloff.hpp
+ types/falloff.cpp
types/types-c.h
types/types-c.cpp
types/tuple_access-c.h
@@ -123,6 +125,8 @@ set(SRC
functions/random.cpp
functions/scalar_math.hpp
functions/scalar_math.cpp
+ functions/falloffs.hpp
+ functions/falloffs.cpp
functions/vectors.hpp
functions/vectors.cpp
functions/lists.hpp
diff --git a/source/blender/functions/FN_functions.hpp b/source/blender/functions/FN_functions.hpp
index 17e0078f5de..4f20f252fa7 100644
--- a/source/blender/functions/FN_functions.hpp
+++ b/source/blender/functions/FN_functions.hpp
@@ -15,3 +15,4 @@
#include "functions/array_execution.hpp"
#include "functions/boolean.hpp"
#include "functions/string.hpp"
+#include "functions/falloffs.hpp"
diff --git a/source/blender/functions/FN_types.hpp b/source/blender/functions/FN_types.hpp
index 1f347997202..5b42f5e4db0 100644
--- a/source/blender/functions/FN_types.hpp
+++ b/source/blender/functions/FN_types.hpp
@@ -4,6 +4,7 @@
#include "types/lists.hpp"
#include "types/numeric.hpp"
#include "types/boolean.hpp"
+#include "types/falloff.hpp"
#include "types/external.hpp"
#include "types/string_type.hpp"
#include "types/initialization.hpp"
diff --git a/source/blender/functions/backends/cpp/cpp_type_info.hpp b/source/blender/functions/backends/cpp/cpp_type_info.hpp
index 3c11753834e..86eda883e86 100644
--- a/source/blender/functions/backends/cpp/cpp_type_info.hpp
+++ b/source/blender/functions/backends/cpp/cpp_type_info.hpp
@@ -187,4 +187,75 @@ template<typename T> class CPPTypeInfoForType : public CPPTypeInfo {
#endif
};
+/**
+ * The class has to have a clone() method.
+ */
+template<typename T> class OwningPointerWrapper {
+ private:
+ T *m_ptr;
+
+ public:
+ OwningPointerWrapper() : m_ptr(nullptr)
+ {
+ }
+
+ OwningPointerWrapper(T *ptr) : m_ptr(ptr)
+ {
+ }
+
+ OwningPointerWrapper(const OwningPointerWrapper &other)
+ {
+ if (other.m_ptr == nullptr) {
+ m_ptr = nullptr;
+ }
+ else {
+ m_ptr = other.m_ptr->clone();
+ }
+ }
+
+ OwningPointerWrapper(OwningPointerWrapper &&other)
+ {
+ m_ptr = other.m_ptr;
+ other.m_ptr = nullptr;
+ }
+
+ OwningPointerWrapper &operator=(const OwningPointerWrapper &other)
+ {
+ if (this == &other) {
+ return *this;
+ }
+
+ this->~OwningPointerWrapper();
+ new (this) OwningPointerWrapper(other);
+ return *this;
+ }
+
+ OwningPointerWrapper &operator=(OwningPointerWrapper &&other)
+ {
+ if (this == &other) {
+ return *this;
+ }
+
+ this->~OwningPointerWrapper();
+ new (this) OwningPointerWrapper(std::move(other));
+ return *this;
+ }
+
+ T *ptr()
+ {
+ return m_ptr;
+ }
+
+ T *operator->()
+ {
+ return m_ptr;
+ }
+
+ std::unique_ptr<T> get_unique_copy() const
+ {
+ T *value = m_ptr->clone();
+ return std::unique_ptr<T>(value);
+ }
+};
+
} /* namespace FN */
diff --git a/source/blender/functions/backends/llvm/llvm_type_info.hpp b/source/blender/functions/backends/llvm/llvm_type_info.hpp
index 0c9533a6266..b6dc0d77d85 100644
--- a/source/blender/functions/backends/llvm/llvm_type_info.hpp
+++ b/source/blender/functions/backends/llvm/llvm_type_info.hpp
@@ -139,6 +139,79 @@ class PointerLLVMTypeInfo : public LLVMTypeInfo {
llvm::Value *build_load_ir__relocate(CodeBuilder &builder, llvm::Value *address) const override;
};
+/**
+ * The type has to implement a clone() method.
+ */
+template<typename T> class OwningPointerLLVMTypeInfo : public LLVMTypeInfo {
+ private:
+ static T *copy_value(const T *value)
+ {
+ if (value == nullptr) {
+ return nullptr;
+ }
+ else {
+ return value->clone();
+ }
+ }
+
+ static void free_value(T *value)
+ {
+ if (value != nullptr) {
+ delete
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list