[Bf-blender-cvs] [4d02a826489] temp-vert-normals-cleanup: Merge branch 'master' into temp-vert-normals-cleanup

Hans Goudey noreply at git.blender.org
Sat Nov 20 18:31:43 CET 2021


Commit: 4d02a826489183afd4e436ae195e07a22d73cd5e
Author: Hans Goudey
Date:   Sat Nov 20 12:31:37 2021 -0500
Branches: temp-vert-normals-cleanup
https://developer.blender.org/rB4d02a826489183afd4e436ae195e07a22d73cd5e

Merge branch 'master' into temp-vert-normals-cleanup

===================================================================



===================================================================

diff --cc source/blender/blenkernel/intern/geometry_component_mesh.cc
index 1d45063271c,86a52b420b6..6642309203d
--- a/source/blender/blenkernel/intern/geometry_component_mesh.cc
+++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc
@@@ -1188,12 -1181,25 +1181,10 @@@ class NormalAttributeProvider final : p
    {
      const MeshComponent &mesh_component = static_cast<const MeshComponent &>(component);
      const Mesh *mesh = mesh_component.get_for_read();
--    if (mesh == nullptr) {
++    if (mesh == nullptr || mesh->totpoly == 0) {
        return {};
      }
--
-     Span<float3> face_normals{(float3 *)BKE_mesh_ensure_face_normals(mesh), mesh->totpoly};
-     return std::make_unique<fn::GVArray_For_GSpan>(face_normals);
 -    /* Use existing normals if possible. */
 -    if (!(mesh->runtime.cd_dirty_poly & CD_MASK_NORMAL) &&
 -        CustomData_has_layer(&mesh->pdata, CD_NORMAL)) {
 -      const void *data = CustomData_get_layer(&mesh->pdata, CD_NORMAL);
 -
 -      return VArray<float3>::ForSpan(Span<float3>((const float3 *)data, mesh->totpoly));
 -    }
 -
 -    Array<float3> normals(mesh->totpoly);
 -    for (const int i : IndexRange(mesh->totpoly)) {
 -      const MPoly *poly = &mesh->mpoly[i];
 -      BKE_mesh_calc_poly_normal(poly, &mesh->mloop[poly->loopstart], mesh->mvert, normals[i]);
 -    }
 -
 -    return VArray<float3>::ForContainer(std::move(normals));
++    return VArray<float3>::ForSpan({(float3 *)BKE_mesh_ensure_face_normals(mesh), mesh->totpoly});
    }
  
    WriteAttributeLookup try_get_for_write(GeometryComponent &UNUSED(component)) const final
diff --cc source/blender/blenloader/intern/versioning_300.c
index 3a2b204d59f,125f3be0dd1..6c51bfe1327
--- a/source/blender/blenloader/intern/versioning_300.c
+++ b/source/blender/blenloader/intern/versioning_300.c
@@@ -56,8 -58,8 +59,9 @@@
  #include "BKE_fcurve_driver.h"
  #include "BKE_idprop.h"
  #include "BKE_lib_id.h"
+ #include "BKE_lib_override.h"
  #include "BKE_main.h"
 +#include "BKE_mesh.h"
  #include "BKE_modifier.h"
  #include "BKE_node.h"
  
diff --cc source/blender/nodes/geometry/nodes/node_geo_input_normal.cc
index 5965989dc5f,6c95ad73bf7..1faaf30efad
--- a/source/blender/nodes/geometry/nodes/node_geo_input_normal.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_input_normal.cc
@@@ -31,59 -31,116 +31,59 @@@ static void geo_node_input_normal_decla
    b.add_output<decl::Vector>(N_("Normal")).field_source();
  }
  
- static GVArrayPtr mesh_face_normals_gvarray(const Mesh &mesh)
 -static VArray<float3> mesh_face_normals(const Mesh &mesh,
 -                                        const Span<MVert> verts,
 -                                        const Span<MPoly> polys,
 -                                        const Span<MLoop> loops,
 -                                        const IndexMask mask)
++static GVArray mesh_face_normals_gvarray(const Mesh &mesh)
  {
-   Span<float3> face_normals{(float3 *)BKE_mesh_ensure_face_normals(&mesh), mesh.totpoly};
-   return std::make_unique<fn::GVArray_For_GSpan>(face_normals);
 -  /* Use existing normals to avoid unnecessarily recalculating them, if possible. */
 -  if (!(mesh.runtime.cd_dirty_poly & CD_MASK_NORMAL) &&
 -      CustomData_has_layer(&mesh.pdata, CD_NORMAL)) {
 -    const void *data = CustomData_get_layer(&mesh.pdata, CD_NORMAL);
 -
 -    return VArray<float3>::ForSpan({(const float3 *)data, polys.size()});
 -  }
 -
 -  auto normal_fn = [verts, polys, loops](const int i) -> float3 {
 -    float3 normal;
 -    const MPoly &poly = polys[i];
 -    BKE_mesh_calc_poly_normal(&poly, &loops[poly.loopstart], verts.data(), normal);
 -    return normal;
 -  };
 -
 -  return VArray<float3>::ForFunc(mask.min_array_size(), normal_fn);
++  return VArray<float3>::ForSpan({(float3 *)BKE_mesh_ensure_face_normals(&mesh), mesh.totpoly});
  }
  
- static GVArrayPtr mesh_vert_normals_gvarray(const Mesh &mesh)
 -static VArray<float3> mesh_vertex_normals(const Mesh &mesh,
 -                                          const Span<MVert> verts,
 -                                          const Span<MPoly> polys,
 -                                          const Span<MLoop> loops,
 -                                          const IndexMask mask)
++static GVArray mesh_vert_normals_gvarray(const Mesh &mesh)
  {
-   Span<float3> vert_normals{(float3 *)BKE_mesh_ensure_vertex_normals(&mesh), mesh.totvert};
-   return std::make_unique<fn::GVArray_For_GSpan>(vert_normals);
 -  /* Use existing normals to avoid unnecessarily recalculating them, if possible. */
 -  if (!(mesh.runtime.cd_dirty_vert & CD_MASK_NORMAL) &&
 -      CustomData_has_layer(&mesh.vdata, CD_NORMAL)) {
 -    const void *data = CustomData_get_layer(&mesh.pdata, CD_NORMAL);
 -
 -    return VArray<float3>::ForSpan({(const float3 *)data, mesh.totvert});
 -  }
 -
 -  /* If the normals are dirty, they must be recalculated for the output of this node's field
 -   * source. Ideally vertex normals could be calculated lazily on a const mesh, but that's not
 -   * possible at the moment, so we take ownership of the results. Sadly we must also create a copy
 -   * of MVert to use the mesh normals API. This can be improved by adding mutex-protected lazy
 -   * calculation of normals on meshes.
 -   *
 -   * Use mask.min_array_size() to avoid calculating a final chunk of data if possible. */
 -  Array<MVert> temp_verts(verts);
 -  Array<float3> normals(verts.size()); /* Use full size for accumulation from faces. */
 -  BKE_mesh_calc_normals_poly_and_vertex(temp_verts.data(),
 -                                        mask.min_array_size(),
 -                                        loops.data(),
 -                                        loops.size(),
 -                                        polys.data(),
 -                                        polys.size(),
 -                                        nullptr,
 -                                        (float(*)[3])normals.data());
 -
 -  return VArray<float3>::ForContainer(std::move(normals));
++  return VArray<float3>::ForSpan({(float3 *)BKE_mesh_ensure_vertex_normals(&mesh), mesh.totvert});
  }
  
- static const GVArray *construct_mesh_normals_gvarray(const MeshComponent &mesh_component,
+ static VArray<float3> construct_mesh_normals_gvarray(const MeshComponent &mesh_component,
                                                       const Mesh &mesh,
                                                       const IndexMask mask,
                                                       const AttributeDomain domain,
-                                                      ResourceScope &scope)
+                                                      ResourceScope &UNUSED(scope))
  {
 -  Span<MVert> verts{mesh.mvert, mesh.totvert};
 -  Span<MEdge> edges{mesh.medge, mesh.totedge};
 -  Span<MPoly> polys{mesh.mpoly, mesh.totpoly};
 -  Span<MLoop> loops{mesh.mloop, mesh.totloop};
 -
    switch (domain) {
      case ATTR_DOMAIN_FACE: {
-       return scope.add_value(mesh_face_normals_gvarray(mesh)).get();
 -      return mesh_face_normals(mesh, verts, polys, loops, mask);
++      return VArray<float3>::ForSpan(
++          {(float3 *)BKE_mesh_ensure_face_normals(&mesh), mesh.totpoly});
      }
      case ATTR_DOMAIN_POINT: {
-       return scope.add_value(mesh_vert_normals_gvarray(mesh)).get();
 -      return mesh_vertex_normals(mesh, verts, polys, loops, mask);
++      return VArray<float3>::ForSpan(
++          {(float3 *)BKE_mesh_ensure_vertex_normals(&mesh), mesh.totvert});
      }
      case ATTR_DOMAIN_EDGE: {
        /* In this case, start with vertex normals and convert to the edge domain, since the
 -       * conversion from edges to vertices is very simple. Use the full mask since the edges
 -       * might use the vertex normal from any index. */
 -      GVArray vert_normals = mesh_vertex_normals(
 -          mesh, verts, polys, loops, IndexRange(verts.size()));
 -      Span<float3> vert_normals_span = vert_normals.get_internal_span().typed<float3>();
 +       * conversion from edges to vertices is very simple. Use "manual" domain interpolation
 +       * instead of the GeometryComponent API to avoid calculating unnecessary values and to
 +       * allow normalizing the result much more simply. */
 +      Span<float3> vert_normals{(float3 *)BKE_mesh_ensure_vertex_normals(&mesh), mesh.totvert};
        Array<float3> edge_normals(mask.min_array_size());
 -
 -      /* Use "manual" domain interpolation instead of the GeometryComponent API to avoid
 -       * calculating unnecessary values and to allow normalizing the result much more simply. */
 +      Span<MEdge> edges{mesh.medge, mesh.totedge};
        for (const int i : mask) {
          const MEdge &edge = edges[i];
 -        edge_normals[i] = float3::interpolate(
 -                              vert_normals_span[edge.v1], vert_normals_span[edge.v2], 0.5f)
 -                              .normalized();
 +        edge_normals[i] =
 +            float3::interpolate(vert_normals[edge.v1], vert_normals[edge.v2], 0.5f).normalized();
        }
  
-       return &scope.construct<fn::GVArray_For_ArrayContainer<Array<float3>>>(
-           std::move(edge_normals));
+       return VArray<float3>::ForContainer(std::move(edge_normals));
      }
      case ATTR_DOMAIN_CORNER: {
        /* The normals on corners are just the mesh's face normals, so start with the face normal
 -       * array and copy the face normal for each of its corners. */
 -      VArray<float3> face_normals = mesh_face_normals(
 -          mesh, verts, polys, loops, IndexRange(polys.size()));
 -
 -      /* In this case using the mesh component's generic domain interpolation is fine, the data
 -       * will still be normalized, since the face normal is just copied to every corner. */
 -      return mesh_component.attribute_try_adapt_domain<float3>(
 -          std::move(face_normals), ATTR_DOMAIN_FACE, ATTR_DOMAIN_CORNER);
 +       * array and copy the face normal for each of its corners. In this case using the mesh
 +       * component's generic domain interpolation is fine, the data will still be normalized,
 +       * since the face normal is just copied to every corner. */
-       GVArrayPtr loop_normals = mesh_component.att

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list