forked from bartvdbraak/blender
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
This commit is contained in:
parent
6d011d0e27
commit
4d3cdb32d3
@ -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");
|
BMOpSlot *slot_verts_out = BMO_slot_get(op->slots_out, "verts.out");
|
||||||
|
|
||||||
const float dia = BMO_slot_float_get(op->slots_in, "size");
|
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 xtot = max_ii(1, 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 uint ytot = max_ii(1, BMO_slot_int_get(op->slots_in, "y_segments"));
|
||||||
const float xtot_inv2 = 2.0f / (xtot - 1);
|
const float xtot_inv2 = 2.0f / (xtot);
|
||||||
const float ytot_inv2 = 2.0f / (ytot - 1);
|
const float ytot_inv2 = 2.0f / (ytot);
|
||||||
|
|
||||||
const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
|
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");
|
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_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;
|
varr = (BMVert **)slot_verts_out->data.buf;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
vec[2] = 0.0f;
|
vec[2] = 0.0f;
|
||||||
for (y = 0; y < ytot; y++) {
|
for (y = 0; y <= ytot; y++) {
|
||||||
vec[1] = ((y * ytot_inv2) - 1.0f) * dia;
|
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;
|
vec[0] = ((x * xtot_inv2) - 1.0f) * dia;
|
||||||
mul_v3_m4v3(tvec, mat, vec);
|
mul_v3_m4v3(tvec, mat, vec);
|
||||||
varr[i] = BM_vert_create(bm, tvec, NULL, BM_CREATE_NOP);
|
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 (y = 1; y <= ytot; y++) {
|
||||||
for (x = 1; x < xtot; x++) {
|
for (x = 1; x <= xtot; x++) {
|
||||||
BMFace *f;
|
BMFace *f;
|
||||||
|
|
||||||
vquad[0] = varr[XY(x - 1, y - 1)];
|
vquad[0] = varr[XY(x - 1, y - 1)];
|
||||||
@ -805,8 +805,8 @@ void BM_mesh_calc_uvs_grid(BMesh *bm,
|
|||||||
BMLoop *l;
|
BMLoop *l;
|
||||||
BMIter iter, liter;
|
BMIter iter, liter;
|
||||||
|
|
||||||
const float dx = 1.0f / (float)(x_segments - 1);
|
const float dx = 1.0f / (float)(x_segments);
|
||||||
const float dy = 1.0f / (float)(y_segments - 1);
|
const float dy = 1.0f / (float)(y_segments);
|
||||||
const float dx_wrap = 1.0 - (dx / 2.0f);
|
const float dx_wrap = 1.0 - (dx / 2.0f);
|
||||||
float x = 0.0f;
|
float x = 0.0f;
|
||||||
float y = dy;
|
float y = dy;
|
||||||
|
@ -137,8 +137,8 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op)
|
|||||||
"verts.out",
|
"verts.out",
|
||||||
false,
|
false,
|
||||||
"create_grid x_segments=%i y_segments=%i size=%f matrix=%m4 calc_uvs=%b",
|
"create_grid x_segments=%i y_segments=%i size=%f matrix=%m4 calc_uvs=%b",
|
||||||
1,
|
0,
|
||||||
1,
|
0,
|
||||||
RNA_float_get(op->ptr, "size") / 2.0f,
|
RNA_float_get(op->ptr, "size") / 2.0f,
|
||||||
creation_data.mat,
|
creation_data.mat,
|
||||||
calc_uvs)) {
|
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
|
/* 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...). */
|
* you will still reach impossible values (10^12 vertices or so...). */
|
||||||
RNA_def_int(
|
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(
|
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_unit_props_size(ot);
|
||||||
ED_object_add_mesh_props(ot);
|
ED_object_add_mesh_props(ot);
|
||||||
|
Loading…
Reference in New Issue
Block a user