[Bf-blender-cvs] [4c4d36c25e4] master: Subdiv: Correct corner passed to foreach_loop callback

Sergey Sharybin noreply at git.blender.org
Fri Feb 28 10:45:16 CET 2020


Commit: 4c4d36c25e46fdf82b3639d8bffee66c7bbb9dbd
Author: Sergey Sharybin
Date:   Thu Feb 27 14:37:25 2020 +0100
Branches: master
https://developer.blender.org/rB4c4d36c25e46fdf82b3639d8bffee66c7bbb9dbd

Subdiv: Correct corner passed to foreach_loop callback

Was affecting quad faces. where 0 was always passed for inner
loops and a wrong one for boundary ones.

In the current code this change shouldn't cause any difference
since the corner index is ignored in the actual callback, but
it is required to have his fixed for an upcoming changes.

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

M	source/blender/blenkernel/intern/subdiv_foreach.c

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

diff --git a/source/blender/blenkernel/intern/subdiv_foreach.c b/source/blender/blenkernel/intern/subdiv_foreach.c
index 37e47cc5b10..884b8d74790 100644
--- a/source/blender/blenkernel/intern/subdiv_foreach.c
+++ b/source/blender/blenkernel/intern/subdiv_foreach.c
@@ -1103,6 +1103,23 @@ static void subdiv_foreach_loops_of_poly(SubdivForeachTaskContext *ctx,
                              e3);
 }
 
+static int subdiv_foreach_loops_corner_index(const float u,
+                                             const float v,
+                                             const float du,
+                                             const float dv)
+{
+  if (u + du <= 0.5f && v + dv <= 0.5f) {
+    return 0;
+  }
+  else if (u >= 0.5f && v + dv <= 0.5f) {
+    return 1;
+  }
+  else if (u >= 0.5f && v >= 0.5f) {
+    return 2;
+  }
+  return 3;
+}
+
 static void subdiv_foreach_loops_regular(SubdivForeachTaskContext *ctx,
                                          void *tls,
                                          const MPoly *coarse_poly)
@@ -1146,12 +1163,13 @@ static void subdiv_foreach_loops_regular(SubdivForeachTaskContext *ctx,
       const int e1 = e0 + ptex_inner_resolution;
       const int e2 = e0 + (2 * ptex_inner_resolution - 1);
       const int e3 = e0 + ptex_inner_resolution - 1;
+
       subdiv_foreach_loops_of_poly(ctx,
                                    tls,
                                    subdiv_loop_index,
                                    ptex_face_index,
                                    coarse_poly_index,
-                                   0,
+                                   subdiv_foreach_loops_corner_index(u, v, du, dv),
                                    0,
                                    v0,
                                    e0,
@@ -1265,12 +1283,16 @@ static void subdiv_foreach_loops_regular(SubdivForeachTaskContext *ctx,
       else {
         e2 = start_edge_index + e2_offset + e2_stride * (i - 1);
       }
+
+      const float loop_u = u + delta_u * i;
+      const float loop_v = v + delta_v * i;
+
       subdiv_foreach_loops_of_poly(ctx,
                                    tls,
                                    subdiv_loop_index,
                                    ptex_face_index,
                                    coarse_poly_index,
-                                   corner,
+                                   subdiv_foreach_loops_corner_index(loop_u, loop_v, du, dv),
                                    corner,
                                    v0,
                                    e0,
@@ -1280,8 +1302,8 @@ static void subdiv_foreach_loops_regular(SubdivForeachTaskContext *ctx,
                                    e2,
                                    v3,
                                    e3,
-                                   u + delta_u * i,
-                                   v + delta_v * i,
+                                   loop_u,
+                                   loop_v,
                                    du,
                                    dv);
       v0 = v1;



More information about the Bf-blender-cvs mailing list