[Bf-blender-cvs] [6e828316b35] functions: compute barycentric weights more centrally
Jacques Lucke
noreply at git.blender.org
Wed Sep 4 19:43:35 CEST 2019
Commit: 6e828316b35ce582e3d0c36687e9d95b1780baca
Author: Jacques Lucke
Date: Wed Sep 4 15:02:39 2019 +0200
Branches: functions
https://developer.blender.org/rB6e828316b35ce582e3d0c36687e9d95b1780baca
compute barycentric weights more centrally
===================================================================
M source/blender/simulations/CMakeLists.txt
A source/blender/simulations/bparticles/action_contexts.cpp
M source/blender/simulations/bparticles/action_contexts.hpp
M source/blender/simulations/bparticles/particle_function_input_providers.cpp
===================================================================
diff --git a/source/blender/simulations/CMakeLists.txt b/source/blender/simulations/CMakeLists.txt
index f59673b8f1c..784ecedf222 100644
--- a/source/blender/simulations/CMakeLists.txt
+++ b/source/blender/simulations/CMakeLists.txt
@@ -31,6 +31,7 @@ set(SRC
bparticles/action_interface.hpp
bparticles/action_interface.cpp
bparticles/action_contexts.hpp
+ bparticles/action_contexts.cpp
bparticles/events.hpp
bparticles/events.cpp
bparticles/emitter_interface.hpp
diff --git a/source/blender/simulations/bparticles/action_contexts.cpp b/source/blender/simulations/bparticles/action_contexts.cpp
new file mode 100644
index 00000000000..39d626c0aae
--- /dev/null
+++ b/source/blender/simulations/bparticles/action_contexts.cpp
@@ -0,0 +1,41 @@
+#include "DNA_object_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+
+#include "BKE_mesh_runtime.h"
+
+#include "BLI_math_geom.h"
+
+#include "action_contexts.hpp"
+
+namespace BParticles {
+
+void MeshSurfaceContext::compute_barycentric_coords(ArrayRef<uint> pindices)
+{
+ BLI_assert(m_object->type == OB_MESH);
+ uint size = m_local_positions.size();
+ float3 *barycentric_coords_buffer = (float3 *)BLI_temporary_allocate(sizeof(float3) * size);
+
+ Mesh *mesh = (Mesh *)m_object->data;
+ const MLoopTri *triangles = BKE_mesh_runtime_looptri_ensure(mesh);
+
+ for (uint pindex : pindices) {
+ uint triangle_index = m_looptri_indices[pindex];
+ const MLoopTri &triangle = triangles[triangle_index];
+ float3 position = m_local_positions[pindex];
+
+ 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 weights;
+ interp_weights_tri_v3(weights, v1, v2, v3, position);
+
+ barycentric_coords_buffer[pindex] = weights;
+ }
+
+ m_barycentric_coords = ArrayRef<float3>(barycentric_coords_buffer, size);
+ m_buffers_to_free.append(barycentric_coords_buffer);
+}
+
+} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/action_contexts.hpp b/source/blender/simulations/bparticles/action_contexts.hpp
index aad23a431c9..63462d43720 100644
--- a/source/blender/simulations/bparticles/action_contexts.hpp
+++ b/source/blender/simulations/bparticles/action_contexts.hpp
@@ -19,6 +19,7 @@ class MeshSurfaceContext : public ActionContext {
ArrayRef<float3> m_world_normals;
ArrayRef<uint> m_looptri_indices;
ArrayRef<float3> m_world_surface_velocities;
+ ArrayRef<float3> m_barycentric_coords;
public:
MeshSurfaceContext(Object *object,
@@ -36,6 +37,7 @@ class MeshSurfaceContext : public ActionContext {
m_looptri_indices(looptri_indices),
m_world_surface_velocities(world_surface_velocities)
{
+ this->compute_barycentric_coords(Range<uint>(0, m_local_positions.size()).as_array_ref());
}
MeshSurfaceContext(Object *object,
@@ -67,6 +69,8 @@ class MeshSurfaceContext : public ActionContext {
m_buffers_to_free.extend(
{world_transforms_buffer, world_normals_buffer, surface_velocities_buffer});
+
+ this->compute_barycentric_coords(pindices);
}
~MeshSurfaceContext()
@@ -113,6 +117,14 @@ class MeshSurfaceContext : public ActionContext {
{
return m_world_surface_velocities;
}
+
+ ArrayRef<float3> barycentric_coords() const
+ {
+ return m_barycentric_coords;
+ }
+
+ private:
+ void compute_barycentric_coords(ArrayRef<uint> pindices);
};
-}; // namespace BParticles
+} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/particle_function_input_providers.cpp b/source/blender/simulations/bparticles/particle_function_input_providers.cpp
index 9e95b13b5f0..157b87ae51d 100644
--- a/source/blender/simulations/bparticles/particle_function_input_providers.cpp
+++ b/source/blender/simulations/bparticles/particle_function_input_providers.cpp
@@ -106,43 +106,31 @@ Optional<ParticleFunctionInputArray> SurfaceImageInputProvider::get(
Mesh *mesh = (Mesh *)object->data;
const MLoopTri *triangles = BKE_mesh_runtime_looptri_ensure(mesh);
+ ArrayRef<float3> barycentric_coords = surface_info->barycentric_coords();
int uv_layer_index = CustomData_get_active_layer(&mesh->ldata, CD_MLOOPUV);
BLI_assert(uv_layer_index >= 0);
MLoopUV *uv_layer = (MLoopUV *)CustomData_get(&mesh->ldata, uv_layer_index, CD_MLOOPUV);
BLI_assert(uv_layer != nullptr);
- ArrayRef<float3> local_positions = surface_info->local_positions();
-
rgba_b *pixel_buffer = (rgba_b *)m_ibuf->rect;
- rgba_f *colors_buffer = (rgba_f *)BLI_temporary_allocate(sizeof(rgba_f) *
- local_positions.size());
- MutableArrayRef<rgba_f> colors{colors_buffer, local_positions.size()};
+ uint size = interface.attributes().size();
+ rgba_f *colors_buffer = (rgba_f *)BLI_temporary_allocate(sizeof(rgba_f) * size);
+ MutableArrayRef<rgba_f> colors{colors_buffer, size};
for (uint pindex : interface.pindices()) {
- float3 local_position = local_positions[pindex];
-
uint triangle_index = surface_info->looptri_indices()[pindex];
const MLoopTri &triangle = triangles[triangle_index];
- uint loop1 = triangle.tri[0];
- uint loop2 = triangle.tri[1];
- uint loop3 = triangle.tri[2];
-
- float3 v1 = mesh->mvert[mesh->mloop[loop1].v].co;
- float3 v2 = mesh->mvert[mesh->mloop[loop2].v].co;
- float3 v3 = mesh->mvert[mesh->mloop[loop3].v].co;
-
- float2 uv1 = uv_layer[loop1].uv;
- float2 uv2 = uv_layer[loop2].uv;
- float2 uv3 = uv_layer[loop3].uv;
-
- float3 vertex_weights;
- interp_weights_tri_v3(vertex_weights, v1, v2, v3, local_position);
+ float2 uv1 = uv_layer[triangle.tri[0]].uv;
+ float2 uv2 = uv_layer[triangle.tri[1]].uv;
+ float2 uv3 = uv_layer[triangle.tri[2]].uv;
float2 uv;
+ float3 vertex_weights = barycentric_coords[pindex];
interp_v2_v2v2v2(uv, uv1, uv2, uv3, vertex_weights);
+
uv = uv.clamped_01();
uint x = uv.x * (m_ibuf->x - 1);
uint y = uv.y * (m_ibuf->y - 1);
@@ -167,31 +155,22 @@ static BLI_NOINLINE Optional<ParticleFunctionInputArray> compute_vertex_weights(
}
const MLoopTri *triangles = BKE_mesh_runtime_looptri_ensure(mesh);
+ ArrayRef<float3> barycentric_coords = surface_info->barycentric_coords();
- float *weight_buffer = (float *)BLI_temporary_allocate(sizeof(float) *
- interface.attributes().size());
- MutableArrayRef<float> weights(weight_buffer, interface.attributes().size());
+ uint size = interface.attributes().size();
+ float *weight_buffer = (float *)BLI_temporary_allocate(sizeof(float) * size);
+ MutableArrayRef<float> weights(weight_buffer, size);
for (uint pindex : interface.pindices()) {
uint source_index = surface_info_mapping[pindex];
- float3 local_position = surface_info->local_positions()[source_index];
uint triangle_index = surface_info->looptri_indices()[source_index];
- const MLoopTri &triangle = triangles[triangle_index];
-
- uint loop1 = triangle.tri[0];
- uint loop2 = triangle.tri[1];
- uint loop3 = triangle.tri[2];
+ float3 bary_weights = barycentric_coords[source_index];
- uint vert1 = mesh->mloop[loop1].v;
- uint vert2 = mesh->mloop[loop2].v;
- uint vert3 = mesh->mloop[loop3].v;
-
- float3 v1 = mesh->mvert[vert1].co;
- float3 v2 = mesh->mvert[vert2].co;
- float3 v3 = mesh->mvert[vert3].co;
+ const MLoopTri &triangle = triangles[triangle_index];
- float3 bary_weights;
- interp_weights_tri_v3(bary_weights, v1, v2, v3, local_position);
+ uint vert1 = mesh->mloop[triangle.tri[0]].v;
+ uint vert2 = mesh->mloop[triangle.tri[1]].v;
+ uint vert3 = mesh->mloop[triangle.tri[2]].v;
float3 corner_weights{defvert_find_weight(vertex_weights + vert1, group_index),
defvert_find_weight(vertex_weights + vert2, group_index),
More information about the Bf-blender-cvs
mailing list