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