Changeset View
Changeset View
Standalone View
Standalone View
source/blender/bmesh/operators/bmo_primitive.c
| Show First 20 Lines • Show All 848 Lines • ▼ Show 20 Lines | if (x >= dx_wrap) { | ||||
| x = 0.0f; | x = 0.0f; | ||||
| y += dy; | y += dy; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op) | void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op) | ||||
| { | { | ||||
| const float dia = BMO_slot_float_get(op->slots_in, "diameter"); | const float rad = BMO_slot_float_get(op->slots_in, "radius"); | ||||
| const int seg = BMO_slot_int_get(op->slots_in, "u_segments"); | const int seg = BMO_slot_int_get(op->slots_in, "u_segments"); | ||||
| const int tot = BMO_slot_int_get(op->slots_in, "v_segments"); | const int tot = BMO_slot_int_get(op->slots_in, "v_segments"); | ||||
| 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"); | ||||
| BMOperator bmop, prevop; | BMOperator bmop, prevop; | ||||
| BMVert *eve, *preveve; | BMVert *eve, *preveve; | ||||
| Show All 10 Lines | void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op) | ||||
| /* one segment first */ | /* one segment first */ | ||||
| for (a = 0; a <= tot; a++) { | for (a = 0; a <= tot; a++) { | ||||
| /* Going in this direction, then edge extruding, makes normals face outward */ | /* Going in this direction, then edge extruding, makes normals face outward */ | ||||
| /* Calculate with doubles for higher precision, see: T87779. */ | /* Calculate with doubles for higher precision, see: T87779. */ | ||||
| const float phi = M_PI * ((double)a / (double)tot); | const float phi = M_PI * ((double)a / (double)tot); | ||||
| vec[0] = 0.0; | vec[0] = 0.0; | ||||
| vec[1] = dia * sinf(phi); | vec[1] = rad * sinf(phi); | ||||
| vec[2] = dia * cosf(phi); | vec[2] = rad * cosf(phi); | ||||
| eve = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); | eve = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); | ||||
| BMO_vert_flag_enable(bm, eve, VERT_MARK); | BMO_vert_flag_enable(bm, eve, VERT_MARK); | ||||
| if (a != 0) { | if (a != 0) { | ||||
| e = BM_edge_create(bm, preveve, eve, NULL, BM_CREATE_NOP); | e = BM_edge_create(bm, preveve, eve, NULL, BM_CREATE_NOP); | ||||
| BMO_edge_flag_enable(bm, e, EDGE_ORIG); | BMO_edge_flag_enable(bm, e, EDGE_ORIG); | ||||
| } | } | ||||
| Show All 22 Lines | void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op) | ||||
| if (a) { | if (a) { | ||||
| BMO_op_finish(bm, &bmop); | BMO_op_finish(bm, &bmop); | ||||
| } | } | ||||
| { | { | ||||
| float len, len2, vec2[3]; | float len, len2, vec2[3]; | ||||
| len = 2 * dia * sinf(phid / 2.0f); | len = 2 * rad * sinf(phid / 2.0f); | ||||
| /* Length of one segment in shortest parallel. */ | /* Length of one segment in shortest parallel. */ | ||||
| vec[0] = dia * sinf(phid); | vec[0] = rad * sinf(phid); | ||||
| vec[1] = 0.0f; | vec[1] = 0.0f; | ||||
| vec[2] = dia * cosf(phid); | vec[2] = rad * cosf(phid); | ||||
| mul_v3_m3v3(vec2, cmat, vec); | mul_v3_m3v3(vec2, cmat, vec); | ||||
| len2 = len_v3v3(vec, vec2); | len2 = len_v3v3(vec, vec2); | ||||
| /* use shortest segment length divided by 3 as merge threshold */ | /* use shortest segment length divided by 3 as merge threshold */ | ||||
| BMO_op_callf( | BMO_op_callf( | ||||
| bm, op->flag, "remove_doubles verts=%fv dist=%f", VERT_MARK, min_ff(len, len2) / 3.0f); | bm, op->flag, "remove_doubles verts=%fv dist=%f", VERT_MARK, min_ff(len, len2) / 3.0f); | ||||
| } | } | ||||
| Show All 30 Lines | BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) { | ||||
| } | } | ||||
| } | } | ||||
| BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "verts.out", BM_VERT, VERT_MARK); | BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "verts.out", BM_VERT, VERT_MARK); | ||||
| } | } | ||||
| void bmo_create_icosphere_exec(BMesh *bm, BMOperator *op) | void bmo_create_icosphere_exec(BMesh *bm, BMOperator *op) | ||||
| { | { | ||||
| const float dia = BMO_slot_float_get(op->slots_in, "diameter"); | const float rad = BMO_slot_float_get(op->slots_in, "radius"); | ||||
| const float dia_div = dia / 200.0f; | const float rad_div = rad / 200.0f; | ||||
| const int subdiv = BMO_slot_int_get(op->slots_in, "subdivisions"); | const int subdiv = BMO_slot_int_get(op->slots_in, "subdivisions"); | ||||
| 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"); | ||||
| BMVert *eva[12]; | BMVert *eva[12]; | ||||
| BMVert *v; | BMVert *v; | ||||
| BMIter liter; | BMIter liter; | ||||
| BMIter viter; | BMIter viter; | ||||
| BMLoop *l; | BMLoop *l; | ||||
| float vec[3], mat[4][4] /* , phi, phid */; | float vec[3], mat[4][4] /* , phi, phid */; | ||||
| int a; | int a; | ||||
| BMO_slot_mat4_get(op->slots_in, "matrix", mat); | BMO_slot_mat4_get(op->slots_in, "matrix", mat); | ||||
| /* phid = 2.0f * (float)M_PI / subdiv; */ /* UNUSED */ | /* phid = 2.0f * (float)M_PI / subdiv; */ /* UNUSED */ | ||||
| /* phi = 0.25f * (float)M_PI; */ /* UNUSED */ | /* phi = 0.25f * (float)M_PI; */ /* UNUSED */ | ||||
| for (a = 0; a < 12; a++) { | for (a = 0; a < 12; a++) { | ||||
| vec[0] = dia_div * icovert[a][0]; | vec[0] = rad_div * icovert[a][0]; | ||||
| vec[1] = dia_div * icovert[a][1]; | vec[1] = rad_div * icovert[a][1]; | ||||
| vec[2] = dia_div * icovert[a][2]; | vec[2] = rad_div * icovert[a][2]; | ||||
| eva[a] = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); | eva[a] = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); | ||||
| BMO_vert_flag_enable(bm, eva[a], VERT_MARK); | BMO_vert_flag_enable(bm, eva[a], VERT_MARK); | ||||
| } | } | ||||
| int uvi = 0; | int uvi = 0; | ||||
| for (a = 0; a < 20; a++) { | for (a = 0; a < 20; a++) { | ||||
| BMFace *f; | BMFace *f; | ||||
| Show All 28 Lines | if (subdiv > 1) { | ||||
| BMO_op_initf(bm, | BMO_op_initf(bm, | ||||
| &bmop, | &bmop, | ||||
| op->flag, | op->flag, | ||||
| "subdivide_edges edges=%fe " | "subdivide_edges edges=%fe " | ||||
| "smooth=%f " | "smooth=%f " | ||||
| "cuts=%i " | "cuts=%i " | ||||
| "use_grid_fill=%b use_sphere=%b", | "use_grid_fill=%b use_sphere=%b", | ||||
| EDGE_MARK, | EDGE_MARK, | ||||
| dia, | rad, | ||||
| (1 << (subdiv - 1)) - 1, | (1 << (subdiv - 1)) - 1, | ||||
| true, | true, | ||||
| true); | true); | ||||
| BMO_op_exec(bm, &bmop); | BMO_op_exec(bm, &bmop); | ||||
| BMO_slot_buffer_flag_enable(bm, bmop.slots_out, "geom.out", BM_VERT, VERT_MARK); | BMO_slot_buffer_flag_enable(bm, bmop.slots_out, "geom.out", BM_VERT, VERT_MARK); | ||||
| BMO_slot_buffer_flag_enable(bm, bmop.slots_out, "geom.out", BM_EDGE, EDGE_MARK); | BMO_slot_buffer_flag_enable(bm, bmop.slots_out, "geom.out", BM_EDGE, EDGE_MARK); | ||||
| BMO_op_finish(bm, &bmop); | BMO_op_finish(bm, &bmop); | ||||
| ▲ Show 20 Lines • Show All 334 Lines • ▼ Show 20 Lines | void BM_mesh_calc_uvs_circle( | ||||
| } | } | ||||
| } | } | ||||
| void bmo_create_cone_exec(BMesh *bm, BMOperator *op) | void bmo_create_cone_exec(BMesh *bm, BMOperator *op) | ||||
| { | { | ||||
| BMVert *v1, *v2, *lastv1 = NULL, *lastv2 = NULL, *cent1, *cent2, *firstv1, *firstv2; | BMVert *v1, *v2, *lastv1 = NULL, *lastv2 = NULL, *cent1, *cent2, *firstv1, *firstv2; | ||||
| BMFace *f; | BMFace *f; | ||||
| float vec[3], mat[4][4]; | float vec[3], mat[4][4]; | ||||
| const float dia1 = BMO_slot_float_get(op->slots_in, "diameter1"); | const float rad1 = BMO_slot_float_get(op->slots_in, "radius1"); | ||||
| const float dia2 = BMO_slot_float_get(op->slots_in, "diameter2"); | const float rad2 = BMO_slot_float_get(op->slots_in, "radius2"); | ||||
| const float depth_half = 0.5f * BMO_slot_float_get(op->slots_in, "depth"); | const float depth_half = 0.5f * BMO_slot_float_get(op->slots_in, "depth"); | ||||
| int segs = BMO_slot_int_get(op->slots_in, "segments"); | int segs = BMO_slot_int_get(op->slots_in, "segments"); | ||||
| const bool cap_ends = BMO_slot_bool_get(op->slots_in, "cap_ends"); | const bool cap_ends = BMO_slot_bool_get(op->slots_in, "cap_ends"); | ||||
| const bool cap_tris = BMO_slot_bool_get(op->slots_in, "cap_tris"); | const bool cap_tris = BMO_slot_bool_get(op->slots_in, "cap_tris"); | ||||
| 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"); | ||||
| Show All 21 Lines | void bmo_create_cone_exec(BMesh *bm, BMOperator *op) | ||||
| } | } | ||||
| const int side_faces_len = segs - 1; | const int side_faces_len = segs - 1; | ||||
| BMFace **side_faces = MEM_mallocN(sizeof(*side_faces) * side_faces_len, __func__); | BMFace **side_faces = MEM_mallocN(sizeof(*side_faces) * side_faces_len, __func__); | ||||
| for (int i = 0; i < segs; i++) { | for (int i = 0; i < segs; i++) { | ||||
| /* Calculate with doubles for higher precision, see: T87779. */ | /* Calculate with doubles for higher precision, see: T87779. */ | ||||
| const float phi = (2.0 * M_PI) * ((double)i / (double)segs); | const float phi = (2.0 * M_PI) * ((double)i / (double)segs); | ||||
| vec[0] = rad1 * sinf(phi); | |||||
| vec[0] = dia1 * sinf(phi); | vec[1] = rad1 * cosf(phi); | ||||
| vec[1] = dia1 * cosf(phi); | |||||
| vec[2] = -depth_half; | vec[2] = -depth_half; | ||||
| mul_m4_v3(mat, vec); | mul_m4_v3(mat, vec); | ||||
| v1 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); | v1 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); | ||||
| vec[0] = dia2 * sinf(phi); | vec[0] = rad2 * sinf(phi); | ||||
| vec[1] = dia2 * cosf(phi); | vec[1] = rad2 * cosf(phi); | ||||
| vec[2] = depth_half; | vec[2] = depth_half; | ||||
| mul_m4_v3(mat, vec); | mul_m4_v3(mat, vec); | ||||
| v2 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); | v2 = BM_vert_create(bm, vec, NULL, BM_CREATE_NOP); | ||||
| BMO_vert_flag_enable(bm, v1, VERT_MARK); | BMO_vert_flag_enable(bm, v1, VERT_MARK); | ||||
| BMO_vert_flag_enable(bm, v2, VERT_MARK); | BMO_vert_flag_enable(bm, v2, VERT_MARK); | ||||
| if (i) { | if (i) { | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | void bmo_create_cone_exec(BMesh *bm, BMOperator *op) | ||||
| } | } | ||||
| f = BM_face_create_quad_tri(bm, v1, v2, firstv2, firstv1, NULL, BM_CREATE_NOP); | f = BM_face_create_quad_tri(bm, v1, v2, firstv2, firstv1, NULL, BM_CREATE_NOP); | ||||
| if (calc_uvs) { | if (calc_uvs) { | ||||
| BMO_face_flag_enable(bm, f, FACE_MARK); | BMO_face_flag_enable(bm, f, FACE_MARK); | ||||
| } | } | ||||
| if (calc_uvs) { | if (calc_uvs) { | ||||
| BM_mesh_calc_uvs_cone(bm, mat, dia2, dia1, segs, cap_ends, FACE_MARK, cd_loop_uv_offset); | BM_mesh_calc_uvs_cone(bm, mat, rad2, rad1, segs, cap_ends, FACE_MARK, cd_loop_uv_offset); | ||||
| } | } | ||||
| /* Collapse vertices at the first end. */ | /* Collapse vertices at the first end. */ | ||||
| if (dia1 == 0.0f) { | if (rad1 == 0.0f) { | ||||
| if (cap_ends) { | if (cap_ends) { | ||||
| BM_vert_kill(bm, cent1); | BM_vert_kill(bm, cent1); | ||||
| } | } | ||||
| for (int i = 0; i < side_faces_len; i++) { | for (int i = 0; i < side_faces_len; i++) { | ||||
| f = side_faces[i]; | f = side_faces[i]; | ||||
| BMLoop *l = BM_FACE_FIRST_LOOP(f); | BMLoop *l = BM_FACE_FIRST_LOOP(f); | ||||
| BM_edge_collapse(bm, l->prev->e, l->prev->v, true, true); | BM_edge_collapse(bm, l->prev->e, l->prev->v, true, true); | ||||
| } | } | ||||
| } | } | ||||
| /* Collapse vertices at the second end. */ | /* Collapse vertices at the second end. */ | ||||
| if (dia2 == 0.0f) { | if (rad2 == 0.0f) { | ||||
| if (cap_ends) { | if (cap_ends) { | ||||
| BM_vert_kill(bm, cent2); | BM_vert_kill(bm, cent2); | ||||
| } | } | ||||
| for (int i = 0; i < side_faces_len; i++) { | for (int i = 0; i < side_faces_len; i++) { | ||||
| f = side_faces[i]; | f = side_faces[i]; | ||||
| BMLoop *l = BM_FACE_FIRST_LOOP(f); | BMLoop *l = BM_FACE_FIRST_LOOP(f); | ||||
| BM_edge_collapse(bm, l->next->e, l->next->v, true, true); | BM_edge_collapse(bm, l->next->e, l->next->v, true, true); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 256 Lines • Show Last 20 Lines | |||||