[Bf-blender-cvs] [e89b2b12213] master: Mesh: Skip some domain interpolations for single values

Iliya Katueshenock noreply at git.blender.org
Wed Oct 5 19:43:24 CEST 2022


Commit: e89b2b12213580315e55c693ee5384a39c554688
Author: Iliya Katueshenock
Date:   Wed Oct 5 12:31:01 2022 -0500
Branches: master
https://developer.blender.org/rBe89b2b12213580315e55c693ee5384a39c554688

Mesh: Skip some domain interpolations for single values

Completely skip the work of interpolating domains for single values
for many to and from combinations. Similar to 535f50e5a6a248b7aa74b59,
but slightly more complex because of the possibility of loose elements
on some mesh domains.

>From D16054, with added comments.

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

M	source/blender/blenkernel/intern/geometry_component_mesh.cc

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

diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc b/source/blender/blenkernel/intern/geometry_component_mesh.cc
index 827fef8b6d0..228c27cedf7 100644
--- a/source/blender/blenkernel/intern/geometry_component_mesh.cc
+++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc
@@ -765,6 +765,30 @@ static GVArray adapt_mesh_domain_edge_to_face(const Mesh &mesh, const GVArray &v
 
 }  // namespace blender::bke
 
+static bool can_simple_adapt_for_single(const eAttrDomain from_domain, const eAttrDomain to_domain)
+{
+  /* For some domain combinations, a single value will always map directly. For others, there may
+   * be loose elements on the result domain that should have the default value rather than the
+   * single value from the source. */
+  switch (from_domain) {
+    case ATTR_DOMAIN_POINT:
+      /* All other domains are always connected to points. */
+      return true;
+    case ATTR_DOMAIN_EDGE:
+      /* There may be loose vertices not connected to edges. */
+      return ELEM(to_domain, ATTR_DOMAIN_FACE, ATTR_DOMAIN_CORNER);
+    case ATTR_DOMAIN_FACE:
+      /* There may be loose vertices or edges not connected to faces. */
+      return to_domain == ATTR_DOMAIN_CORNER;
+    case ATTR_DOMAIN_CORNER:
+      /* Only faces are always connected to corners. */
+      return to_domain == ATTR_DOMAIN_FACE;
+    default:
+      BLI_assert_unreachable();
+      return false;
+  }
+}
+
 static blender::GVArray adapt_mesh_attribute_domain(const Mesh &mesh,
                                                     const blender::GVArray &varray,
                                                     const eAttrDomain from_domain,
@@ -779,6 +803,14 @@ static blender::GVArray adapt_mesh_attribute_domain(const Mesh &mesh,
   if (from_domain == to_domain) {
     return varray;
   }
+  if (varray.is_single()) {
+    if (can_simple_adapt_for_single(from_domain, to_domain)) {
+      BUFFER_FOR_CPP_TYPE_VALUE(varray.type(), value);
+      varray.get_internal_single(value);
+      return blender::GVArray::ForSingle(
+          varray.type(), mesh.attributes().domain_size(to_domain), value);
+    }
+  }
 
   switch (from_domain) {
     case ATTR_DOMAIN_CORNER: {



More information about the Bf-blender-cvs mailing list