Mesh: Replace auto smooth with node group #108014
|
@ -30,6 +30,14 @@ void sample_point_attribute(const Mesh &mesh,
|
|||
IndexMask mask,
|
||||
GMutableSpan dst);
|
||||
|
||||
void sample_point_normals(const Span<int> corner_verts,
|
||||
const Span<MLoopTri> looptris,
|
||||
const Span<int> looptri_indices,
|
||||
const Span<float3> bary_coords,
|
||||
const Span<float3> src,
|
||||
const IndexMask mask,
|
||||
const MutableSpan<float3> dst);
|
||||
|
||||
void sample_corner_attribute(const Mesh &mesh,
|
||||
Span<int> looptri_indices,
|
||||
Span<float3> bary_coords,
|
||||
|
@ -37,6 +45,13 @@ void sample_corner_attribute(const Mesh &mesh,
|
|||
IndexMask mask,
|
||||
GMutableSpan dst);
|
||||
|
||||
void sample_corner_normals(const Span<MLoopTri> looptris,
|
||||
const Span<int> looptri_indices,
|
||||
const Span<float3> bary_coords,
|
||||
const Span<float3> src,
|
||||
const IndexMask mask,
|
||||
const MutableSpan<float3> dst);
|
||||
|
||||
void sample_face_attribute(const Mesh &mesh,
|
||||
Span<int> looptri_indices,
|
||||
const GVArray &src,
|
||||
|
|
|
@ -13,8 +13,28 @@
|
|||
|
||||
namespace blender::bke::mesh_surface_sample {
|
||||
|
||||
void sample_point_normals(const Span<int> corner_verts,
|
||||
const Span<MLoopTri> looptris,
|
||||
const Span<int> looptri_indices,
|
||||
const Span<float3> bary_coords,
|
||||
const Span<float3> src,
|
||||
const IndexMask mask,
|
||||
const MutableSpan<float3> dst)
|
||||
{
|
||||
for (const int i : mask) {
|
||||
const MLoopTri &tri = looptris[looptri_indices[i]];
|
||||
const float3 &bary_coord = bary_coords[i];
|
||||
const float3 value = attribute_math::mix3(bary_coord,
|
||||
src[corner_verts[tri.tri[0]]],
|
||||
src[corner_verts[tri.tri[1]]],
|
||||
src[corner_verts[tri.tri[2]]]);
|
||||
dst[i] = math::normalize(value);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
BLI_NOINLINE static void sample_point_attribute(const Mesh &mesh,
|
||||
BLI_NOINLINE static void sample_point_attribute(const Span<int> corner_verts,
|
||||
const Span<MLoopTri> looptris,
|
||||
const Span<int> looptri_indices,
|
||||
const Span<float3> bary_coords,
|
||||
const VArray<T> &src,
|
||||
|
@ -25,20 +45,12 @@ BLI_NOINLINE static void sample_point_attribute(const Mesh &mesh,
|
|||
const Span<MLoopTri> looptris = mesh.looptris();
|
||||
|
||||
for (const int i : mask) {
|
||||
const int looptri_index = looptri_indices[i];
|
||||
const MLoopTri &looptri = looptris[looptri_index];
|
||||
const MLoopTri &tri = looptris[looptri_indices[i]];
|
||||
const float3 &bary_coord = bary_coords[i];
|
||||
|
||||
const int v0_index = corner_verts[looptri.tri[0]];
|
||||
const int v1_index = corner_verts[looptri.tri[1]];
|
||||
const int v2_index = corner_verts[looptri.tri[2]];
|
||||
|
||||
const T v0 = src[v0_index];
|
||||
const T v1 = src[v1_index];
|
||||
const T v2 = src[v2_index];
|
||||
|
||||
const T interpolated_value = attribute_math::mix3(bary_coord, v0, v1, v2);
|
||||
dst[i] = interpolated_value;
|
||||
dst[i] = attribute_math::mix3(bary_coord,
|
||||
src[corner_verts[tri.tri[0]]],
|
||||
src[corner_verts[tri.tri[1]]],
|
||||
src[corner_verts[tri.tri[2]]]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,36 +67,46 @@ void sample_point_attribute(const Mesh &mesh,
|
|||
const CPPType &type = src.type();
|
||||
attribute_math::convert_to_static_type(type, [&](auto dummy) {
|
||||
using T = decltype(dummy);
|
||||
sample_point_attribute<T>(
|
||||
mesh, looptri_indices, bary_coords, src.typed<T>(), mask, dst.typed<T>());
|
||||
sample_point_attribute<T>(mesh.corner_verts(),
|
||||
mesh.looptris(),
|
||||
looptri_indices,
|
||||
bary_coords,
|
||||
src.typed<T>(),
|
||||
mask,
|
||||
dst.typed<T>());
|
||||
});
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
BLI_NOINLINE static void sample_corner_attribute(const Mesh &mesh,
|
||||
BLI_NOINLINE static void sample_corner_attribute(const Span<MLoopTri> looptris,
|
||||
const Span<int> looptri_indices,
|
||||
const Span<float3> bary_coords,
|
||||
const VArray<T> &src,
|
||||
const IndexMask mask,
|
||||
const MutableSpan<T> dst)
|
||||
{
|
||||
const Span<MLoopTri> looptris = mesh.looptris();
|
||||
|
||||
for (const int i : mask) {
|
||||
const int looptri_index = looptri_indices[i];
|
||||
const MLoopTri &looptri = looptris[looptri_index];
|
||||
const MLoopTri &tri = looptris[looptri_index];
|
||||
const float3 &bary_coord = bary_coords[i];
|
||||
dst[i] = attribute_math::mix3(bary_coord, src[tri.tri[0]], src[tri.tri[1]], src[tri.tri[2]]);
|
||||
}
|
||||
}
|
||||
|
||||
const int loop_index_0 = looptri.tri[0];
|
||||
const int loop_index_1 = looptri.tri[1];
|
||||
const int loop_index_2 = looptri.tri[2];
|
||||
|
||||
const T v0 = src[loop_index_0];
|
||||
const T v1 = src[loop_index_1];
|
||||
const T v2 = src[loop_index_2];
|
||||
|
||||
const T interpolated_value = attribute_math::mix3(bary_coord, v0, v1, v2);
|
||||
dst[i] = interpolated_value;
|
||||
void sample_corner_normals(const Span<MLoopTri> looptris,
|
||||
const Span<int> looptri_indices,
|
||||
const Span<float3> bary_coords,
|
||||
const Span<float3> src,
|
||||
const IndexMask mask,
|
||||
const MutableSpan<float3> dst)
|
||||
{
|
||||
for (const int i : mask) {
|
||||
const int looptri_index = looptri_indices[i];
|
||||
const MLoopTri &tri = looptris[looptri_index];
|
||||
const float3 &bary_coord = bary_coords[i];
|
||||
const float3 value = attribute_math::mix3(
|
||||
bary_coord, src[tri.tri[0]], src[tri.tri[1]], src[tri.tri[2]]);
|
||||
dst[i] = math::normalize(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -332,16 +332,15 @@ static void compute_normal_outputs(const Mesh &mesh,
|
|||
const Span<int> looptri_indices,
|
||||
MutableSpan<float3> r_normals)
|
||||
{
|
||||
/* TODO: Normalization. */
|
||||
switch (mesh.normal_domain_all_info()) {
|
||||
case ATTR_DOMAIN_POINT: {
|
||||
const Span<float3> vert_normals = mesh.vert_normals();
|
||||
bke::mesh_surface_sample::sample_point_attribute(mesh,
|
||||
looptri_indices,
|
||||
bary_coords,
|
||||
VArray<float3>::ForSpan(vert_normals),
|
||||
IndexMask(looptri_indices.index_range()),
|
||||
r_normals);
|
||||
bke::mesh_surface_sample::sample_point_normals(mesh.corner_verts(),
|
||||
mesh.looptris(),
|
||||
looptri_indices,
|
||||
bary_coords,
|
||||
mesh.vert_normals(),
|
||||
IndexMask(looptri_indices.index_range()),
|
||||
r_normals);
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -355,13 +354,12 @@ static void compute_normal_outputs(const Mesh &mesh,
|
|||
break;
|
||||
}
|
||||
case ATTR_DOMAIN_CORNER: {
|
||||
const Span<float3> corner_normals = mesh.corner_normals();
|
||||
bke::mesh_surface_sample::sample_corner_attribute(mesh,
|
||||
looptri_indices,
|
||||
bary_coords,
|
||||
VArray<float3>::ForSpan(corner_normals),
|
||||
IndexMask(looptri_indices.index_range()),
|
||||
r_normals);
|
||||
bke::mesh_surface_sample::sample_corner_normals(mesh.looptris(),
|
||||
looptri_indices,
|
||||
bary_coords,
|
||||
mesh.corner_normals(),
|
||||
IndexMask(looptri_indices.index_range()),
|
||||
r_normals);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue