[Bf-blender-cvs] [4d3cdb32d39] master: Fix T86168: Add primitive Grid. Wrong number of subdivisions

Pratik Borhade noreply at git.blender.org
Tue Mar 16 13:11:12 CET 2021


Commit: 4d3cdb32d399335dba72c180309c0d34f93cd533
Author: Pratik Borhade
Date:   Tue Mar 16 23:08:35 2021 +1100
Branches: master
https://developer.blender.org/rB4d3cdb32d399335dba72c180309c0d34f93cd533

Fix T86168: Add primitive Grid. Wrong number of subdivisions

Changes to increase subdivision by one along both axis (X and Y)

For example with x_segment = 3 and y_segment = 3.
There should be 16 vertices ((3 + 1) * (3 + 1)) for correct
number of subdivisions. Currently they are 3 * 3 = 9 vertices.

Ref D10699

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

M	source/blender/bmesh/operators/bmo_primitive.c
M	source/blender/editors/mesh/editmesh_add.c

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

diff --git a/source/blender/bmesh/operators/bmo_primitive.c b/source/blender/bmesh/operators/bmo_primitive.c
index 535df52c1e1..a0a31ab6154 100644
--- a/source/blender/bmesh/operators/bmo_primitive.c
+++ b/source/blender/bmesh/operators/bmo_primitive.c
@@ -728,10 +728,10 @@ void bmo_create_grid_exec(BMesh *bm, BMOperator *op)
   BMOpSlot *slot_verts_out = BMO_slot_get(op->slots_out, "verts.out");
 
   const float dia = BMO_slot_float_get(op->slots_in, "size");
-  const uint xtot = max_ii(2, BMO_slot_int_get(op->slots_in, "x_segments"));
-  const uint ytot = max_ii(2, BMO_slot_int_get(op->slots_in, "y_segments"));
-  const float xtot_inv2 = 2.0f / (xtot - 1);
-  const float ytot_inv2 = 2.0f / (ytot - 1);
+  const uint xtot = max_ii(1, BMO_slot_int_get(op->slots_in, "x_segments"));
+  const uint ytot = max_ii(1, BMO_slot_int_get(op->slots_in, "y_segments"));
+  const float xtot_inv2 = 2.0f / (xtot);
+  const float ytot_inv2 = 2.0f / (ytot);
 
   const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
   const bool calc_uvs = (cd_loop_uv_offset != -1) && BMO_slot_bool_get(op->slots_in, "calc_uvs");
@@ -746,14 +746,14 @@ void bmo_create_grid_exec(BMesh *bm, BMOperator *op)
 
   BMO_slot_mat4_get(op->slots_in, "matrix", mat);
 
-  BMO_slot_buffer_alloc(op, op->slots_out, "verts.out", xtot * ytot);
+  BMO_slot_buffer_alloc(op, op->slots_out, "verts.out", (xtot + 1) * (ytot + 1));
   varr = (BMVert **)slot_verts_out->data.buf;
 
   i = 0;
   vec[2] = 0.0f;
-  for (y = 0; y < ytot; y++) {
+  for (y = 0; y <= ytot; y++) {
     vec[1] = ((y * ytot_inv2) - 1.0f) * dia;
-    for (x = 0; x < xtot; x++) {
+    for (x = 0; x <= xtot; x++) {
       vec[0] = ((x * xtot_inv2) - 1.0f) * dia;
       mul_v3_m4v3(tvec, mat, vec);
       varr[i] = BM_vert_create(bm, tvec, NULL, BM_CREATE_NOP);
@@ -762,10 +762,10 @@ void bmo_create_grid_exec(BMesh *bm, BMOperator *op)
     }
   }
 
-#define XY(_x, _y) ((_x) + ((_y) * (xtot)))
+#define XY(_x, _y) ((_x) + ((_y) * (xtot + 1)))
 
-  for (y = 1; y < ytot; y++) {
-    for (x = 1; x < xtot; x++) {
+  for (y = 1; y <= ytot; y++) {
+    for (x = 1; x <= xtot; x++) {
       BMFace *f;
 
       vquad[0] = varr[XY(x - 1, y - 1)];
@@ -805,8 +805,8 @@ void BM_mesh_calc_uvs_grid(BMesh *bm,
   BMLoop *l;
   BMIter iter, liter;
 
-  const float dx = 1.0f / (float)(x_segments - 1);
-  const float dy = 1.0f / (float)(y_segments - 1);
+  const float dx = 1.0f / (float)(x_segments);
+  const float dy = 1.0f / (float)(y_segments);
   const float dx_wrap = 1.0 - (dx / 2.0f);
   float x = 0.0f;
   float y = dy;
diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c
index 582ff01173a..18e231893d4 100644
--- a/source/blender/editors/mesh/editmesh_add.c
+++ b/source/blender/editors/mesh/editmesh_add.c
@@ -137,8 +137,8 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op)
           "verts.out",
           false,
           "create_grid x_segments=%i y_segments=%i size=%f matrix=%m4 calc_uvs=%b",
-          1,
-          1,
+          0,
+          0,
           RNA_float_get(op->ptr, "size") / 2.0f,
           creation_data.mat,
           calc_uvs)) {
@@ -531,9 +531,9 @@ void MESH_OT_primitive_grid_add(wmOperatorType *ot)
   /* Note that if you use MESH_ADD_VERTS_MAXI for both x and y at the same time
    * you will still reach impossible values (10^12 vertices or so...). */
   RNA_def_int(
-      ot->srna, "x_subdivisions", 10, 2, MESH_ADD_VERTS_MAXI, "X Subdivisions", "", 2, 1000);
+      ot->srna, "x_subdivisions", 10, 1, MESH_ADD_VERTS_MAXI, "X Subdivisions", "", 1, 1000);
   RNA_def_int(
-      ot->srna, "y_subdivisions", 10, 2, MESH_ADD_VERTS_MAXI, "Y Subdivisions", "", 2, 1000);
+      ot->srna, "y_subdivisions", 10, 1, MESH_ADD_VERTS_MAXI, "Y Subdivisions", "", 1, 1000);
 
   ED_object_add_unit_props_size(ot);
   ED_object_add_mesh_props(ot);



More information about the Bf-blender-cvs mailing list