Changeset View
Changeset View
Standalone View
Standalone View
source/blender/bmesh/tools/bmesh_bevel.c
| Context not available. | |||||
| BMIter iter; | BMIter iter; | ||||
| EdgeHalf *e; | EdgeHalf *e; | ||||
| float weight, z; | float weight, z; | ||||
| float vert_axis[3]; | |||||
| int i, ccw_test_sum; | int i, ccw_test_sum; | ||||
| int nsel = 0; | int nsel = 0; | ||||
| int ntot = 0; | int ntot = 0; | ||||
| Context not available. | |||||
| bv->vmesh = (VMesh *)BLI_memarena_alloc(bp->mem_arena, sizeof(VMesh)); | bv->vmesh = (VMesh *)BLI_memarena_alloc(bp->mem_arena, sizeof(VMesh)); | ||||
| bv->vmesh->seg = bp->seg; | bv->vmesh->seg = bp->seg; | ||||
| if (bp->vertex_only) { | |||||
| /* if weighted, modify offset by weight */ | |||||
| if (bp->dvert != NULL && bp->vertex_group != -1) { | |||||
| weight = defvert_find_weight(bp->dvert + BM_elem_index_get(v), bp->vertex_group); | |||||
| if (weight <= 0.0f) { | |||||
| BM_elem_flag_disable(v, BM_ELEM_TAG); | |||||
| return NULL; | |||||
| } | |||||
| bv->offset *= weight; | |||||
| } | |||||
| else if (bp->use_weights) { | |||||
| weight = BM_elem_float_data_get(&bm->vdata, v, CD_BWEIGHT); | |||||
| bv->offset *= weight; | |||||
| } | |||||
| } | |||||
| BLI_ghash_insert(bp->vert_hash, v, bv); | BLI_ghash_insert(bp->vert_hash, v, bv); | ||||
| find_bevel_edge_order(bm, bv, first_bme); | find_bevel_edge_order(bm, bv, first_bme); | ||||
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| if (bp->vertex_only) { | |||||
| /* if weighted, modify offset by weight */ | |||||
| if (bp->dvert != NULL && bp->vertex_group != -1) { | |||||
| weight = defvert_find_weight(bp->dvert + BM_elem_index_get(v), bp->vertex_group); | |||||
| if (weight <= 0.0f) { | |||||
| BM_elem_flag_disable(v, BM_ELEM_TAG); | |||||
| return NULL; | |||||
| } | |||||
| bv->offset *= weight; | |||||
| } | |||||
| else if (bp->use_weights) { | |||||
| weight = BM_elem_float_data_get(&bm->vdata, v, CD_BWEIGHT); | |||||
| bv->offset *= weight; | |||||
| } | |||||
| /* Find center axis. Note: Don't use vert normal, can give unwanted results. */ | |||||
| if (ELEM(bp->offset_type, BEVEL_AMT_WIDTH, BEVEL_AMT_DEPTH)) { | |||||
| float edge_dir[3]; | |||||
| for (i = 0, e = bv->edges; i < ntot; i++, e++) { | |||||
| v2 = BM_edge_other_vert(e->e, bv->v); | |||||
| sub_v3_v3v3(edge_dir, bv->v->co, v2->co); | |||||
| normalize_v3(edge_dir); | |||||
| add_v3_v3v3(vert_axis, vert_axis, edge_dir); | |||||
| } | |||||
| mul_v3_fl(vert_axis, 1 / ntot); | |||||
| } | |||||
| } | |||||
| for (i = 0, e = bv->edges; i < ntot; i++, e++) { | for (i = 0, e = bv->edges; i < ntot; i++, e++) { | ||||
| e->next = &bv->edges[(i + 1) % ntot]; | e->next = &bv->edges[(i + 1) % ntot]; | ||||
| e->prev = &bv->edges[(i + ntot - 1) % ntot]; | e->prev = &bv->edges[(i + ntot - 1) % ntot]; | ||||
| Context not available. | |||||
| } | } | ||||
| else if (bp->vertex_only) { | else if (bp->vertex_only) { | ||||
| /* Weight has already been applied to bv->offset, if present. | /* Weight has already been applied to bv->offset, if present. | ||||
| * Transfer to e->offset_[lr]_spec and treat percent as special case */ | * Transfer to e->offset_[lr]_spec according to offset_type. */ | ||||
| if (bp->offset_type == BEVEL_AMT_PERCENT) { | float edge_dir[3]; | ||||
| v2 = BM_edge_other_vert(e->e, bv->v); | switch (bp->offset_type) { | ||||
| e->offset_l_spec = BM_edge_calc_length(e->e) * bv->offset / 100.0f; | case BEVEL_AMT_OFFSET: { | ||||
| } | e->offset_l_spec = bv->offset; | ||||
| else { | break; | ||||
| e->offset_l_spec = bv->offset; | } | ||||
| case BEVEL_AMT_WIDTH: { | |||||
| v2 = BM_edge_other_vert(e->e, bv->v); | |||||
| sub_v3_v3v3(edge_dir, bv->v->co, v2->co); | |||||
| normalize_v3(edge_dir); | |||||
| z = fabsf(2.0f * sinf(angle_normalized_v3v3(vert_axis, edge_dir))); | |||||
| if (z < BEVEL_EPSILON) { | |||||
| e->offset_l_spec = 0.01f * bp->offset; /* undefined behavior, so tiny bevel. */ | |||||
| } | |||||
| else { | |||||
| e->offset_l_spec = bp->offset / z; | |||||
| } | |||||
| break; | |||||
| } | |||||
| case BEVEL_AMT_DEPTH: { | |||||
| v2 = BM_edge_other_vert(e->e, bv->v); | |||||
| sub_v3_v3v3(edge_dir, bv->v->co, v2->co); | |||||
| normalize_v3(edge_dir); | |||||
| z = fabsf(cosf(angle_normalized_v3v3(vert_axis, edge_dir))); | |||||
| if (z < BEVEL_EPSILON) { | |||||
| e->offset_l_spec = 0.01f * bp->offset; /* undefined behavior, so tiny bevel. */ | |||||
| } | |||||
| else { | |||||
| e->offset_l_spec = bp->offset / z; | |||||
| } | |||||
| break; | |||||
| } | |||||
| case BEVEL_AMT_PERCENT: { | |||||
| e->offset_l_spec = BM_edge_calc_length(e->e) * bv->offset / 100.0f; | |||||
| break; | |||||
| } | |||||
| } | } | ||||
| e->offset_r_spec = e->offset_l_spec; | e->offset_r_spec = e->offset_l_spec; | ||||
| } | } | ||||
| Context not available. | |||||