[Bf-blender-cvs] [a908d95d9f6] functions: extract surface hook functions to separate file
Jacques Lucke
noreply at git.blender.org
Wed Dec 11 15:27:59 CET 2019
Commit: a908d95d9f6bf045a7c44d0219fbf19f2fb11337
Author: Jacques Lucke
Date: Wed Dec 11 14:48:40 2019 +0100
Branches: functions
https://developer.blender.org/rBa908d95d9f6bf045a7c44d0219fbf19f2fb11337
extract surface hook functions to separate file
===================================================================
M source/blender/functions/CMakeLists.txt
M source/blender/functions/FN_multi_functions.h
M source/blender/functions/intern/multi_functions/mixed.cc
M source/blender/functions/intern/multi_functions/mixed.h
A source/blender/functions/intern/multi_functions/surface_hook.cc
A source/blender/functions/intern/multi_functions/surface_hook.h
A source/blender/functions/intern/multi_functions/util.h
===================================================================
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index 7e274d38d34..67ad5e6405e 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -26,6 +26,7 @@ set(SRC
intern/multi_functions/lists.cc
intern/multi_functions/mixed.cc
intern/multi_functions/network.cc
+ intern/multi_functions/surface_hook.cc
intern/inlined_tree_multi_function_network/builder.cc
intern/inlined_tree_multi_function_network/generate.cc
intern/inlined_tree_multi_function_network/mappings_nodes.cc
@@ -66,6 +67,8 @@ set(SRC
intern/multi_functions/lists.h
intern/multi_functions/mixed.h
intern/multi_functions/network.h
+ intern/multi_functions/surface_hook.h
+ intern/multi_functions/util.h
intern/inlined_tree_multi_function_network/builder.h
intern/inlined_tree_multi_function_network/mappings.h
intern/cpp_types.h
diff --git a/source/blender/functions/FN_multi_functions.h b/source/blender/functions/FN_multi_functions.h
index c45360605b4..3acc1379493 100644
--- a/source/blender/functions/FN_multi_functions.h
+++ b/source/blender/functions/FN_multi_functions.h
@@ -4,5 +4,6 @@
#include "intern/multi_functions/lists.h"
#include "intern/multi_functions/mixed.h"
#include "intern/multi_functions/network.h"
+#include "intern/multi_functions/surface_hook.h"
#endif /* __FN_MULTI_FUNCTIONS_H__ */
diff --git a/source/blender/functions/intern/multi_functions/mixed.cc b/source/blender/functions/intern/multi_functions/mixed.cc
index 29c28d49b98..313d536284d 100644
--- a/source/blender/functions/intern/multi_functions/mixed.cc
+++ b/source/blender/functions/intern/multi_functions/mixed.cc
@@ -19,7 +19,7 @@
#include "IMB_imbuf_types.h"
#include "BKE_customdata.h"
-#include "BKE_surface_hook.h"
+
#include "BKE_mesh_runtime.h"
#include "BKE_deform.h"
#include "BKE_id_data_cache.h"
@@ -28,7 +28,6 @@ namespace FN {
using BKE::ImageIDHandle;
using BKE::ObjectIDHandle;
-using BKE::SurfaceHook;
using BLI::float2;
using BLI::float3;
using BLI::float4x4;
@@ -37,43 +36,6 @@ using BLI::rgba_f;
using BLI::TemporaryArray;
using BLI::TemporaryVector;
-template<typename T, typename FuncT, typename EqualFuncT = std::equal_to<T>>
-void group_indices_by_same_value(ArrayRef<uint> indices,
- VirtualListRef<T> values,
- const FuncT &func,
- EqualFuncT equal = std::equal_to<T>())
-{
- if (indices.size() == 0) {
- return;
- }
- if (values.is_single_element()) {
- const T &value = values[indices[0]];
- func(value, indices);
- return;
- }
-
- Vector<T> seen_values;
-
- for (uint i : indices.index_iterator()) {
- uint index = indices[i];
-
- const T &value = values[index];
- if (seen_values.as_ref().any([&](const T &seen_value) { return equal(value, seen_value); })) {
- continue;
- }
- seen_values.append(value);
-
- TemporaryVector<uint> indices_with_value;
- for (uint j : indices.drop_front(i)) {
- if (equal(values[j], value)) {
- indices_with_value.append(j);
- }
- }
-
- func(value, indices_with_value.as_ref());
- }
-}
-
MF_CombineColor::MF_CombineColor()
{
MFSignatureBuilder signature("Combine Color");
@@ -261,324 +223,6 @@ void MF_ObjectVertexPositions::call(MFMask mask, MFParams params, MFContext cont
}
}
-MF_GetPositionOnSurface::MF_GetPositionOnSurface()
-{
- MFSignatureBuilder signature("Get Position on Surface");
- signature.single_input<SurfaceHook>("Surface Hook");
- signature.single_output<float3>("Position");
- this->set_signature(signature);
-}
-
-void MF_GetPositionOnSurface::call(MFMask mask, MFParams params, MFContext context) const
-{
- VirtualListRef<SurfaceHook> surface_hooks = params.readonly_single_input<SurfaceHook>(
- 0, "Surface Hook");
- MutableArrayRef<float3> r_positions = params.uninitialized_single_output<float3>(1, "Position");
-
- float3 fallback = {0, 0, 0};
-
- auto *id_handle_lookup = context.try_find_global<BKE::IDHandleLookup>();
- if (id_handle_lookup == nullptr) {
- r_positions.fill_indices(mask.indices(), fallback);
- return;
- }
-
- group_indices_by_same_value(
- mask.indices(),
- surface_hooks,
- [&](SurfaceHook base_hook, ArrayRef<uint> indices_on_same_surface) {
- if (base_hook.type() != BKE::SurfaceHookType::MeshObject) {
- r_positions.fill_indices(indices_on_same_surface, fallback);
- return;
- }
-
- Object *object = id_handle_lookup->lookup(base_hook.object_handle());
- if (object == nullptr) {
- r_positions.fill_indices(indices_on_same_surface, fallback);
- return;
- }
-
- Mesh *mesh = (Mesh *)object->data;
- const MLoopTri *triangles = BKE_mesh_runtime_looptri_ensure(mesh);
- int triangle_amount = BKE_mesh_runtime_looptri_len(mesh);
-
- for (uint i : indices_on_same_surface) {
- SurfaceHook hook = surface_hooks[i];
-
- if (hook.triangle_index() >= triangle_amount) {
- r_positions[i] = fallback;
- continue;
- }
-
- const MLoopTri &triangle = triangles[hook.triangle_index()];
- float3 v1 = mesh->mvert[mesh->mloop[triangle.tri[0]].v].co;
- float3 v2 = mesh->mvert[mesh->mloop[triangle.tri[1]].v].co;
- float3 v3 = mesh->mvert[mesh->mloop[triangle.tri[2]].v].co;
-
- float3 position;
- interp_v3_v3v3v3(position, v1, v2, v3, hook.bary_coords());
- float4x4 local_to_world = object->obmat;
- position = local_to_world.transform_position(position);
-
- r_positions[i] = position;
- }
- },
- SurfaceHook::on_same_surface);
-}
-
-MF_GetNormalOnSurface::MF_GetNormalOnSurface()
-{
- MFSignatureBuilder signature("Get Normal on Surface");
- signature.single_input<SurfaceHook>("Surface Hook");
- signature.single_output<float3>("Normal");
- this->set_signature(signature);
-}
-
-static float3 short_normal_to_float3(const short normal[3])
-{
- return float3(
- (float)normal[0] / 32767.0f, (float)normal[1] / 32767.0f, (float)normal[2] / 32767.0f);
-}
-
-void MF_GetNormalOnSurface::call(MFMask mask, MFParams params, MFContext context) const
-{
- VirtualListRef<SurfaceHook> surface_hooks = params.readonly_single_input<SurfaceHook>(
- 0, "Surface Hook");
- MutableArrayRef<float3> r_normals = params.uninitialized_single_output<float3>(1, "Normal");
-
- float3 fallback = {0, 0, 1};
-
- auto *id_handle_lookup = context.try_find_global<BKE::IDHandleLookup>();
- if (id_handle_lookup == nullptr) {
- r_normals.fill_indices(mask.indices(), fallback);
- return;
- }
-
- group_indices_by_same_value(
- mask.indices(),
- surface_hooks,
- [&](SurfaceHook base_hook, ArrayRef<uint> indices_on_same_surface) {
- if (base_hook.type() != BKE::SurfaceHookType::MeshObject) {
- r_normals.fill_indices(indices_on_same_surface, fallback);
- return;
- }
-
- Object *object = id_handle_lookup->lookup(base_hook.object_handle());
- if (object == nullptr) {
- r_normals.fill_indices(indices_on_same_surface, fallback);
- return;
- }
-
- Mesh *mesh = (Mesh *)object->data;
- const MLoopTri *triangles = BKE_mesh_runtime_looptri_ensure(mesh);
- int triangle_amount = BKE_mesh_runtime_looptri_len(mesh);
-
- for (uint i : indices_on_same_surface) {
- SurfaceHook hook = surface_hooks[i];
-
- if (hook.triangle_index() >= triangle_amount) {
- r_normals[i] = fallback;
- continue;
- }
-
- const MLoopTri &triangle = triangles[hook.triangle_index()];
- float3 v1 = short_normal_to_float3(mesh->mvert[mesh->mloop[triangle.tri[0]].v].no);
- float3 v2 = short_normal_to_float3(mesh->mvert[mesh->mloop[triangle.tri[1]].v].no);
- float3 v3 = short_normal_to_float3(mesh->mvert[mesh->mloop[triangle.tri[2]].v].no);
-
- float3 position;
- interp_v3_v3v3v3(position, v1, v2, v3, hook.bary_coords());
- float4x4 local_to_world = object->obmat;
- position = local_to_world.transform_direction(position);
-
- r_normals[i] = position;
- }
- },
- SurfaceHook::on_same_surface);
-}
-
-MF_GetWeightOnSurface::MF_GetWeightOnSurface(std::string vertex_group_name)
- : m_vertex_group_name(std::move(vertex_group_name))
-{
- MFSignatureBuilder signature("Get Weight on Surface");
- signature.single_input<SurfaceHook>("Surface Hook");
- signature.single_output<float>("Weight");
- this->set_signature(signature);
-}
-
-void MF_GetWeightOnSurface::call(MFMask mask, MFParams params, MFContext context) const
-{
- VirtualListRef<SurfaceHook> surface_hooks = params.readonly_single_input<SurfaceHook>(
- 0, "Surface Hook");
- MutableArrayRef<float> r_weights = params.uninitialized_single_output<float>(1, "Weight");
-
- float fallback = 0.0f;
-
- auto *id_handle_lookup = context.try_find_global<BKE::IDHandleLookup>();
- if (id_handle_lookup == nullptr) {
- r_weights.fill_indices(mask.indices(), fallback);
- return;
- }
-
- group_indices_by_same_value(
- mask.indices(),
- surface_hooks,
- [&](SurfaceHook base_hook, ArrayRef<uint> indices_on_same_surface) {
- if (base_hook.type() != BKE::SurfaceHookType::MeshObject) {
- r_weights.fill_indices(indices_on_same_surface, fallback);
- return;
- }
-
- Object *object = id_handle_lookup->lookup(base_hook.object_handle());
- if (object == nullptr) {
- r_weights.fill_indices(indices_on_same_surface, fallback);
- return;
- }
-
- Mesh *mesh = (Mesh *)object->data;
- const MLoopTri *triangles = BKE_mesh_runtime_looptri_ensure(mesh);
- int triangle_amount = BKE_mesh_runtime_looptri_len(mesh);
-
- MDeformVert *vertex_weights = mesh->dvert;
- int group_index = defgroup_name_index(object, m_vertex_group_name.data());
- if (group_index == -1 || vertex_weights == nullptr) {
- r_weights.fill_indices(indices_on_same_surface,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list