Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPratik Borhade <PratikPB2123>2021-03-16 15:08:35 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-03-16 15:10:32 +0300
commit4d3cdb32d399335dba72c180309c0d34f93cd533 (patch)
tree8e82883720decd501a0e0773112182c219cbcd9c
parent6d011d0e27d79b9c9fc7570770f5af958706e63a (diff)
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
-rw-r--r--source/blender/bmesh/operators/bmo_primitive.c24
-rw-r--r--source/blender/editors/mesh/editmesh_add.c8
2 files changed, 16 insertions, 16 deletions
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);