Changeset View
Changeset View
Standalone View
Standalone View
source/blender/bmesh/operators/bmo_primitive.c
| Show First 20 Lines • Show All 713 Lines • ▼ Show 20 Lines | 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(1, 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(1, 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); | const float xtot_inv2 = 2.0f / (xtot); | ||||
| const float ytot_inv2 = 2.0f / (ytot); | 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_PROP_FLOAT2); | ||||
| 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 **varr; | BMVert **varr; | ||||
| BMVert *vquad[4]; | BMVert *vquad[4]; | ||||
| float mat[4][4]; | float mat[4][4]; | ||||
| float vec[3], tvec[3]; | float vec[3], tvec[3]; | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | void BM_mesh_calc_uvs_grid(BMesh *bm, | ||||
| BLI_assert(cd_loop_uv_offset != -1); | BLI_assert(cd_loop_uv_offset != -1); | ||||
| BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { | BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { | ||||
| if (!BMO_face_flag_test(bm, f, oflag)) { | if (!BMO_face_flag_test(bm, f, oflag)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| BM_ITER_ELEM_INDEX (l, &liter, f, BM_LOOPS_OF_FACE, loop_index) { | BM_ITER_ELEM_INDEX (l, &liter, f, BM_LOOPS_OF_FACE, loop_index) { | ||||
| MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); | float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset); | ||||
| switch (loop_index) { | switch (loop_index) { | ||||
| case 0: | case 0: | ||||
| y -= dy; | y -= dy; | ||||
| break; | break; | ||||
| case 1: | case 1: | ||||
| x += dx; | x += dx; | ||||
| break; | break; | ||||
| case 2: | case 2: | ||||
| y += dy; | y += dy; | ||||
| break; | break; | ||||
| case 3: | case 3: | ||||
| x -= dx; | x -= dx; | ||||
| break; | break; | ||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| luv->uv[0] = x; | luv[0] = x; | ||||
| luv->uv[1] = y; | luv[1] = y; | ||||
| } | } | ||||
| x += dx; | x += dx; | ||||
| if (x >= dx_wrap) { | 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 rad = BMO_slot_float_get(op->slots_in, "radius"); | 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_PROP_FLOAT2); | ||||
| 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; | ||||
| BMEdge *e; | BMEdge *e; | ||||
| BMIter iter; | BMIter iter; | ||||
| const float axis[3] = {0, 0, 1}; | const float axis[3] = {0, 0, 1}; | ||||
| float vec[3], mat[4][4], cmat[3][3]; | float vec[3], mat[4][4], cmat[3][3]; | ||||
| ▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| void bmo_create_icosphere_exec(BMesh *bm, BMOperator *op) | void bmo_create_icosphere_exec(BMesh *bm, BMOperator *op) | ||||
| { | { | ||||
| const float rad = BMO_slot_float_get(op->slots_in, "radius"); | const float rad = BMO_slot_float_get(op->slots_in, "radius"); | ||||
| const float rad_div = rad / 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_PROP_FLOAT2); | ||||
| 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 */; | ||||
| Show All 28 Lines | BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { | ||||
| BMO_edge_flag_enable(bm, l->e, EDGE_MARK); | BMO_edge_flag_enable(bm, l->e, EDGE_MARK); | ||||
| } | } | ||||
| /* Set the UVs here, the iteration order of the faces is not guaranteed, | /* Set the UVs here, the iteration order of the faces is not guaranteed, | ||||
| * so it's best to set the UVs right after the face is created. */ | * so it's best to set the UVs right after the face is created. */ | ||||
| if (calc_uvs) { | if (calc_uvs) { | ||||
| int loop_index; | int loop_index; | ||||
| BM_ITER_ELEM_INDEX (l, &liter, f, BM_LOOPS_OF_FACE, loop_index) { | BM_ITER_ELEM_INDEX (l, &liter, f, BM_LOOPS_OF_FACE, loop_index) { | ||||
| MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); | float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset); | ||||
| luv->uv[0] = icouvs[uvi][0]; | luv[0] = icouvs[uvi][0]; | ||||
| luv->uv[1] = icouvs[uvi][1]; | luv[1] = icouvs[uvi][1]; | ||||
| uvi++; | uvi++; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (subdiv > 1) { | if (subdiv > 1) { | ||||
| BMOperator bmop; | BMOperator bmop; | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | if (f->len == 3) { | ||||
| avgx += l->v->co[0]; | avgx += l->v->co[0]; | ||||
| avgy += l->v->co[1]; | avgy += l->v->co[1]; | ||||
| } | } | ||||
| } | } | ||||
| avgx /= 3.0f; | avgx /= 3.0f; | ||||
| avgy /= 3.0f; | avgy /= 3.0f; | ||||
| BM_ITER_ELEM_INDEX (l, &iter, f, BM_LOOPS_OF_FACE, loop_index) { | BM_ITER_ELEM_INDEX (l, &iter, f, BM_LOOPS_OF_FACE, loop_index) { | ||||
| MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); | float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset); | ||||
| float x = l->v->co[0]; | float x = l->v->co[0]; | ||||
| float y = l->v->co[1]; | float y = l->v->co[1]; | ||||
| float z = l->v->co[2]; | float z = l->v->co[2]; | ||||
| float len = len_v3(l->v->co); | float len = len_v3(l->v->co); | ||||
| /* Use neighboring point to compute angle for poles. */ | /* Use neighboring point to compute angle for poles. */ | ||||
| float theta; | float theta; | ||||
| if (f->len == 3 && fabsf(x) < 0.0001f && fabsf(y) < 0.0001f) { | if (f->len == 3 && fabsf(x) < 0.0001f && fabsf(y) < 0.0001f) { | ||||
| theta = atan2f(avgy, avgx); | theta = atan2f(avgy, avgx); | ||||
| } | } | ||||
| else { | else { | ||||
| theta = atan2f(y, x); | theta = atan2f(y, x); | ||||
| } | } | ||||
| /* Shift borderline coordinates to the left. */ | /* Shift borderline coordinates to the left. */ | ||||
| if (fabsf(theta - (float)M_PI) < 0.0001f) { | if (fabsf(theta - (float)M_PI) < 0.0001f) { | ||||
| theta = -M_PI; | theta = -M_PI; | ||||
| } | } | ||||
| float phi = saacos(z / len); | float phi = saacos(z / len); | ||||
| luv->uv[0] = 0.5f + theta / ((float)M_PI * 2); | luv[0] = 0.5f + theta / ((float)M_PI * 2); | ||||
| luv->uv[1] = 1.0f - phi / (float)M_PI; | luv[1] = 1.0f - phi / (float)M_PI; | ||||
| uvs[loop_index] = luv->uv; | uvs[loop_index] = luv; | ||||
| } | } | ||||
| /* Fix awkwardly-wrapping UVs */ | /* Fix awkwardly-wrapping UVs */ | ||||
| loop_index_max_x = 0; | loop_index_max_x = 0; | ||||
| for (loop_index = 1; loop_index < f->len; loop_index++) { | for (loop_index = 1; loop_index < f->len; loop_index++) { | ||||
| if (uvs[loop_index][0] > uvs[loop_index_max_x][0]) { | if (uvs[loop_index][0] > uvs[loop_index_max_x][0]) { | ||||
| loop_index_max_x = loop_index; | loop_index_max_x = loop_index; | ||||
| } | } | ||||
| Show All 29 Lines | void BM_mesh_calc_uvs_sphere(BMesh *bm, const short oflag, const int cd_loop_uv_offset) | ||||
| int loop_index; | int loop_index; | ||||
| float minx = 1.0f; | float minx = 1.0f; | ||||
| BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { | BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { | ||||
| if (!BMO_face_flag_test(bm, f, oflag)) { | if (!BMO_face_flag_test(bm, f, oflag)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| BM_ITER_ELEM_INDEX (l, &iter2, f, BM_LOOPS_OF_FACE, loop_index) { | BM_ITER_ELEM_INDEX (l, &iter2, f, BM_LOOPS_OF_FACE, loop_index) { | ||||
| MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); | float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset); | ||||
| if (luv->uv[0] < minx) { | if (luv[0] < minx) { | ||||
| minx = luv->uv[0]; | minx = luv[0]; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { | BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) { | ||||
| if (!BMO_face_flag_test(bm, f, oflag)) { | if (!BMO_face_flag_test(bm, f, oflag)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| BM_ITER_ELEM_INDEX (l, &iter2, f, BM_LOOPS_OF_FACE, loop_index) { | BM_ITER_ELEM_INDEX (l, &iter2, f, BM_LOOPS_OF_FACE, loop_index) { | ||||
| MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); | float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset); | ||||
| luv->uv[0] -= minx; | luv[0] -= minx; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void bmo_create_monkey_exec(BMesh *bm, BMOperator *op) | void bmo_create_monkey_exec(BMesh *bm, BMOperator *op) | ||||
| { | { | ||||
| BMVert **tv = MEM_mallocN(sizeof(*tv) * monkeynv * 2, "tv"); | BMVert **tv = MEM_mallocN(sizeof(*tv) * monkeynv * 2, "tv"); | ||||
| float mat[4][4]; | float mat[4][4]; | ||||
| int i; | int i; | ||||
| BMO_slot_mat4_get(op->slots_in, "matrix", mat); | BMO_slot_mat4_get(op->slots_in, "matrix", mat); | ||||
| 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_PROP_FLOAT2); | ||||
| 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"); | ||||
| for (i = 0; i < monkeynv; i++) { | for (i = 0; i < monkeynv; i++) { | ||||
| float v[3]; | float v[3]; | ||||
| /* rotate to face in the -Y axis */ | /* rotate to face in the -Y axis */ | ||||
| v[0] = (monkeyv[i][0] + 127) / 128.0; | v[0] = (monkeyv[i][0] + 127) / 128.0; | ||||
| v[2] = monkeyv[i][1] / 128.0; | v[2] = monkeyv[i][1] / 128.0; | ||||
| Show All 37 Lines | BMFace *f_new_b = BM_face_create_quad_tri( | ||||
| BM_CREATE_NOP); | BM_CREATE_NOP); | ||||
| /* Set the UVs here, the iteration order of the faces is not guaranteed, | /* Set the UVs here, the iteration order of the faces is not guaranteed, | ||||
| * so it's best to set the UVs right after the face is created. */ | * so it's best to set the UVs right after the face is created. */ | ||||
| if (calc_uvs) { | if (calc_uvs) { | ||||
| BMLoop *l; | BMLoop *l; | ||||
| BMIter liter; | BMIter liter; | ||||
| BM_ITER_ELEM (l, &liter, f_new_a, BM_LOOPS_OF_FACE) { | BM_ITER_ELEM (l, &liter, f_new_a, BM_LOOPS_OF_FACE) { | ||||
| MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); | float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset); | ||||
| luv->uv[0] = monkeyuvs[uvi * 2 + 0]; | luv[0] = monkeyuvs[uvi * 2 + 0]; | ||||
| luv->uv[1] = monkeyuvs[uvi * 2 + 1]; | luv[1] = monkeyuvs[uvi * 2 + 1]; | ||||
| uvi++; | uvi++; | ||||
| } | } | ||||
| BM_ITER_ELEM (l, &liter, f_new_b, BM_LOOPS_OF_FACE) { | BM_ITER_ELEM (l, &liter, f_new_b, BM_LOOPS_OF_FACE) { | ||||
| MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); | float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset); | ||||
| luv->uv[0] = monkeyuvs[uvi * 2 + 0]; | luv[0] = monkeyuvs[uvi * 2 + 0]; | ||||
| luv->uv[1] = monkeyuvs[uvi * 2 + 1]; | luv[1] = monkeyuvs[uvi * 2 + 1]; | ||||
| uvi++; | uvi++; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| MEM_freeN(tv); | MEM_freeN(tv); | ||||
| 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_circle_exec(BMesh *bm, BMOperator *op) | void bmo_create_circle_exec(BMesh *bm, BMOperator *op) | ||||
| { | { | ||||
| const float radius = BMO_slot_float_get(op->slots_in, "radius"); | const float radius = BMO_slot_float_get(op->slots_in, "radius"); | ||||
| const int segs = BMO_slot_int_get(op->slots_in, "segments"); | const 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_PROP_FLOAT2); | ||||
| 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 *v1, *lastv1 = NULL, *cent1, *firstv1 = NULL; | BMVert *v1, *lastv1 = NULL, *cent1, *firstv1 = NULL; | ||||
| float vec[3], mat[4][4]; | float vec[3], mat[4][4]; | ||||
| int a; | int a; | ||||
| if (!segs) { | if (!segs) { | ||||
| return; | return; | ||||
| ▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | void BM_mesh_calc_uvs_circle( | ||||
| invert_m4_m4(inv_mat, mat); | invert_m4_m4(inv_mat, mat); | ||||
| BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { | BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { | ||||
| if (!BMO_face_flag_test(bm, f, oflag)) { | if (!BMO_face_flag_test(bm, f, oflag)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { | BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { | ||||
| MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); | float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset); | ||||
| float uv_vco[3]; | float uv_vco[3]; | ||||
| copy_v3_v3(uv_vco, l->v->co); | copy_v3_v3(uv_vco, l->v->co); | ||||
| /* transform back into the unit circle flat on the Z-axis */ | /* transform back into the unit circle flat on the Z-axis */ | ||||
| mul_m4_v3(inv_mat, uv_vco); | mul_m4_v3(inv_mat, uv_vco); | ||||
| /* then just take those coords for UVs */ | /* then just take those coords for UVs */ | ||||
| luv->uv[0] = uv_center + uv_scale * uv_vco[0]; | luv[0] = uv_center + uv_scale * uv_vco[0]; | ||||
| luv->uv[1] = uv_center + uv_scale * uv_vco[1]; | luv[1] = uv_center + uv_scale * uv_vco[1]; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| 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 rad1 = BMO_slot_float_get(op->slots_in, "radius1"); | const float rad1 = BMO_slot_float_get(op->slots_in, "radius1"); | ||||
| const float rad2 = BMO_slot_float_get(op->slots_in, "radius2"); | 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_PROP_FLOAT2); | ||||
| 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"); | ||||
| if (!segs) { | if (!segs) { | ||||
| return; | return; | ||||
| } | } | ||||
| BMO_slot_mat4_get(op->slots_in, "matrix", mat); | BMO_slot_mat4_get(op->slots_in, "matrix", mat); | ||||
| ▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | void BM_mesh_calc_uvs_cone(BMesh *bm, | ||||
| BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { | BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { | ||||
| if (!BMO_face_flag_test(bm, f, oflag)) { | if (!BMO_face_flag_test(bm, f, oflag)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (f->len == 4 && radius_top && radius_bottom) { | if (f->len == 4 && radius_top && radius_bottom) { | ||||
| /* side face - so unwrap it in a rectangle */ | /* side face - so unwrap it in a rectangle */ | ||||
| BM_ITER_ELEM_INDEX (l, &liter, f, BM_LOOPS_OF_FACE, loop_index) { | BM_ITER_ELEM_INDEX (l, &liter, f, BM_LOOPS_OF_FACE, loop_index) { | ||||
| MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); | float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset); | ||||
| switch (loop_index) { | switch (loop_index) { | ||||
| case 0: | case 0: | ||||
| /* Continue in the last position */ | /* Continue in the last position */ | ||||
| break; | break; | ||||
| case 1: | case 1: | ||||
| y += uv_height; | y += uv_height; | ||||
| break; | break; | ||||
| case 2: | case 2: | ||||
| x -= uv_width; | x -= uv_width; | ||||
| break; | break; | ||||
| case 3: | case 3: | ||||
| y -= uv_height; | y -= uv_height; | ||||
| break; | break; | ||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| luv->uv[0] = x; | luv[0] = x; | ||||
| luv->uv[1] = y; | luv[1] = y; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* Top or bottom face - so unwrap it by transforming | /* Top or bottom face - so unwrap it by transforming | ||||
| * back to a circle and using the X/Y coords. */ | * back to a circle and using the X/Y coords. */ | ||||
| BM_face_normal_update(f); | BM_face_normal_update(f); | ||||
| BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { | BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { | ||||
| MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); | float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset); | ||||
| float uv_vco[3]; | float uv_vco[3]; | ||||
| mul_v3_m4v3(uv_vco, inv_mat, l->v->co); | mul_v3_m4v3(uv_vco, inv_mat, l->v->co); | ||||
| if (dot_v3v3(f->no, local_up) > 0.0f) { /* if this is a top face of the cone */ | if (dot_v3v3(f->no, local_up) > 0.0f) { /* if this is a top face of the cone */ | ||||
| luv->uv[0] = uv_center_x_top + uv_vco[0] * uv_scale_top; | luv[0] = uv_center_x_top + uv_vco[0] * uv_scale_top; | ||||
| luv->uv[1] = uv_center_y + uv_vco[1] * uv_scale_top; | luv[1] = uv_center_y + uv_vco[1] * uv_scale_top; | ||||
| } | } | ||||
| else { | else { | ||||
| luv->uv[0] = uv_center_x_bottom + uv_vco[0] * uv_scale_bottom; | luv[0] = uv_center_x_bottom + uv_vco[0] * uv_scale_bottom; | ||||
| luv->uv[1] = uv_center_y + uv_vco[1] * uv_scale_bottom; | luv[1] = uv_center_y + uv_vco[1] * uv_scale_bottom; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void bmo_create_cube_exec(BMesh *bm, BMOperator *op) | void bmo_create_cube_exec(BMesh *bm, BMOperator *op) | ||||
| { | { | ||||
| BMVert *verts[8]; | BMVert *verts[8]; | ||||
| float mat[4][4]; | float mat[4][4]; | ||||
| float off = BMO_slot_float_get(op->slots_in, "size") / 2.0f; | float off = BMO_slot_float_get(op->slots_in, "size") / 2.0f; | ||||
| 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_PROP_FLOAT2); | ||||
| 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"); | ||||
| /* rotation order set to match 'BM_mesh_calc_uvs_cube' */ | /* rotation order set to match 'BM_mesh_calc_uvs_cube' */ | ||||
| const char faces[6][4] = { | const char faces[6][4] = { | ||||
| {0, 1, 3, 2}, | {0, 1, 3, 2}, | ||||
| {2, 3, 7, 6}, | {2, 3, 7, 6}, | ||||
| {6, 7, 5, 4}, | {6, 7, 5, 4}, | ||||
| {4, 5, 1, 0}, | {4, 5, 1, 0}, | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
| void BM_mesh_calc_uvs_cube(BMesh *bm, const short oflag) | void BM_mesh_calc_uvs_cube(BMesh *bm, const short oflag) | ||||
| { | { | ||||
| BMFace *f; | BMFace *f; | ||||
| BMLoop *l; | BMLoop *l; | ||||
| BMIter fiter, liter; | BMIter fiter, liter; | ||||
| const float width = 0.25f; | const float width = 0.25f; | ||||
| 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_PROP_FLOAT2); | ||||
| float x = 0.375f; | float x = 0.375f; | ||||
| float y = 0.0f; | float y = 0.0f; | ||||
| int loop_index; | int loop_index; | ||||
| BLI_assert(cd_loop_uv_offset != -1); /* the caller can ensure that we have UVs */ | BLI_assert(cd_loop_uv_offset != -1); /* the caller can ensure that we have UVs */ | ||||
| BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { | BM_ITER_MESH (f, &fiter, bm, BM_FACES_OF_MESH) { | ||||
| if (!BMO_face_flag_test(bm, f, oflag)) { | if (!BMO_face_flag_test(bm, f, oflag)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| BM_ITER_ELEM_INDEX (l, &liter, f, BM_LOOPS_OF_FACE, loop_index) { | BM_ITER_ELEM_INDEX (l, &liter, f, BM_LOOPS_OF_FACE, loop_index) { | ||||
| MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); | float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset); | ||||
| luv->uv[0] = x; | luv[0] = x; | ||||
| luv->uv[1] = y; | luv[1] = y; | ||||
| switch (loop_index) { | switch (loop_index) { | ||||
| case 0: | case 0: | ||||
| x += width; | x += width; | ||||
| break; | break; | ||||
| case 1: | case 1: | ||||
| y += width; | y += width; | ||||
| break; | break; | ||||
| Show All 24 Lines | |||||