Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/uvedit/uvedit_unwrap_ops.c
| Context not available. | |||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = CTX_data_edit_object(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | |||||
| BMEditMesh *em = BKE_editmesh_from_object(obedit); | BMEditMesh *em = BKE_editmesh_from_object(obedit); | ||||
| BMFace *efa; | BMFace *efa; | ||||
| BMLoop *l; | BMLoop *l; | ||||
| Context not available. | |||||
| float center[3], rotmat[4][4]; | float center[3], rotmat[4][4]; | ||||
| int cd_loop_uv_offset; | int cd_loop_uv_offset; | ||||
| const bool cursor_unwrap = RNA_boolean_get(op->ptr, "cursor_center"); | |||||
| /* add uvs if they don't exist yet */ | /* add uvs if they don't exist yet */ | ||||
mano-wii: Why not call `cursor_center` just like the name of the property? | |||||
| if (!ED_uvedit_ensure_uvs(C, scene, obedit)) { | if (!ED_uvedit_ensure_uvs(C, scene, obedit)) { | ||||
| Context not available. | |||||
| cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); | cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); | ||||
| uv_map_transform(C, op, center, rotmat); | uv_map_transform(C, op, center, rotmat); | ||||
| if (cursor_unwrap) { | |||||
| *center = *ED_view3d_cursor3d_get(scene, v3d); | |||||
mano-wiiUnsubmitted Done Inline Actions*center = *ED_view3d_cursor3d_get(scene, v3d);``` is wrong :\ `center` here is only copying the first element of the array (center[0]). Try using `copy_v3_v3(center, ED_view3d_cursor3d_get(scene, v3d))` instead. There is also no need to calculate the previous value of the `center` since it is overwritten by the cursor3d. This is inefficient. You must separate the function that calculates the `center` and only use with `else`. mano-wii: ```*center = *ED_view3d_cursor3d_get(scene, v3d);``` is wrong :\
`center` here is only copying… | |||||
| } | |||||
Not Done Inline ActionsBe careful about the value of center being local mano-wii: Be careful about the value of `center` being local | |||||
| BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | ||||
| if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) | if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) | ||||
| Context not available. | |||||
| /* properties */ | /* properties */ | ||||
| uv_transform_properties(ot, 0); | uv_transform_properties(ot, 0); | ||||
| RNA_def_boolean(ot->srna, "cursor_center", false, "Unwrap from cursor", "Use 3D cursor instead of origin for Unwrapping"); | |||||
| uv_map_clip_correct_properties(ot); | uv_map_clip_correct_properties(ot); | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = CTX_data_edit_object(C); | ||||
| View3D *v3d= CTX_wm_view3d(C); | |||||
| BMEditMesh *em = BKE_editmesh_from_object(obedit); | BMEditMesh *em = BKE_editmesh_from_object(obedit); | ||||
| BMFace *efa; | BMFace *efa; | ||||
| BMLoop *l; | BMLoop *l; | ||||
| Context not available. | |||||
| float center[3], rotmat[4][4]; | float center[3], rotmat[4][4]; | ||||
| int cd_loop_uv_offset; | int cd_loop_uv_offset; | ||||
| const bool cursor_unwrap = RNA_boolean_get(op->ptr, "cursor_center"); | |||||
| /* add uvs if they don't exist yet */ | /* add uvs if they don't exist yet */ | ||||
| if (!ED_uvedit_ensure_uvs(C, scene, obedit)) { | if (!ED_uvedit_ensure_uvs(C, scene, obedit)) { | ||||
| Context not available. | |||||
| uv_map_transform(C, op, center, rotmat); | uv_map_transform(C, op, center, rotmat); | ||||
| if (cursor_unwrap) { | |||||
| *center = *ED_view3d_cursor3d_get(scene, v3d); | |||||
mano-wiiUnsubmitted Done Inline Actionssame as the previous comment mano-wii: same as the previous comment | |||||
| } | |||||
| BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { | ||||
| if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) | if (!BM_elem_flag_test(efa, BM_ELEM_SELECT)) | ||||
| continue; | continue; | ||||
| Context not available. | |||||
| /* properties */ | /* properties */ | ||||
| uv_transform_properties(ot, 1); | uv_transform_properties(ot, 1); | ||||
| RNA_def_boolean(ot->srna, "cursor_center", false, "Unwrap from cursor", "Use 3D cursor instead of origin for Unwrapping"); | |||||
| uv_map_clip_correct_properties(ot); | uv_map_clip_correct_properties(ot); | ||||
| } | } | ||||
Done Inline Actionsconst float offset[3] mano-wii: `const float offset[3]` | |||||
| Context not available. | |||||
| } | } | ||||
Done Inline ActionsThe loc value can be changed before the loop. float loc[3];
if (offset) {
add_v3_v3v3(loc, ob->obmat[3], offset);
}
else {
copy_v3_v3(loc, ob->obmat[3]);
}mano-wii: The `loc` value can be changed before the loop.
Ex.:
```
float loc[3];
if (offset) {… | |||||
| void ED_uvedit_unwrap_cube_project_from_cursor(Object *ob, BMesh *bm, float cube_size, bool use_select, float *off) | |||||
mano-wiiUnsubmitted Done Inline ActionsThis function is very similar to ED_uvedit_unwrap_cube_project. Try to avoid duplicates. This increases the code and makes it difficult to maintain. It is also difficult to say what is this float *off Suggestion: You can add this parameter to ED_uvedit_unwrap_cube_project And put as NULL if it does not have offset. ED_uvedit_unwrap_cube_project(ob, bm, cube_size, NULL); mano-wii: This function is very similar to `ED_uvedit_unwrap_cube_project`. Try to avoid duplicates. This… | |||||
| { | |||||
| BMFace *efa; | |||||
| BMLoop *l; | |||||
| BMIter iter, liter; | |||||
| MLoopUV *luv; | |||||
| float *loc, dx, dy; | |||||
| int cox, coy; | |||||
| int cd_loop_uv_offset; | |||||
| cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV); | |||||
| loc = ob->obmat[3]; | |||||
| /* choose x,y,z axis for projection depending on the largest normal | |||||
| * component, but clusters all together around the center of map. */ | |||||
| BM_ITER_MESH(efa, &iter, bm, BM_FACES_OF_MESH) { | |||||
| int first = 1; | |||||
| /* tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */ | |||||
| if (use_select && !BM_elem_flag_test(efa, BM_ELEM_SELECT)) | |||||
| continue; | |||||
Done Inline Actions~cursor_unwrap~ > cursor_center mano-wii: ~cursor_unwrap~ > cursor_center | |||||
| axis_dominant_v3(&cox, &coy, efa->no); | |||||
| dx = dy = 0; | |||||
Not Done Inline ActionsThe value of cursor_loc must be local mano-wii: The value of `cursor_loc` must be local | |||||
| BM_ITER_ELEM(l, &liter, efa, BM_LOOPS_OF_FACE) { | |||||
| luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); | |||||
| luv->uv[0] = 0.5f + 0.5f * cube_size * (loc[cox] + l->v->co[cox]+off[cox]); | |||||
| luv->uv[1] = 0.5f + 0.5f * cube_size * (loc[coy] + l->v->co[coy]+off[coy]); | |||||
| if (first) { | |||||
| dx = floor(luv->uv[0]); | |||||
| dy = floor(luv->uv[1]); | |||||
| first = 0; | |||||
| } | |||||
| luv->uv[0] -= dx; | |||||
| luv->uv[1] -= dy; | |||||
| } | |||||
| } | |||||
| } | |||||
| static int cube_project_exec(bContext *C, wmOperator *op) | static int cube_project_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | |||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = CTX_data_edit_object(C); | ||||
| BMEditMesh *em = BKE_editmesh_from_object(obedit); | BMEditMesh *em = BKE_editmesh_from_object(obedit); | ||||
| float cube_size = RNA_float_get(op->ptr, "cube_size"); | float cube_size = RNA_float_get(op->ptr, "cube_size"); | ||||
| Context not available. | |||||
| if (!ED_uvedit_ensure_uvs(C, scene, obedit)) { | if (!ED_uvedit_ensure_uvs(C, scene, obedit)) { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| const bool cursor_unwrap = RNA_boolean_get(op->ptr, "cursor_center"); | |||||
| ED_uvedit_unwrap_cube_project(obedit, em->bm, cube_size, true); | if (cursor_unwrap) { | ||||
| float *cursor_loc = ED_view3d_cursor3d_get(scene, v3d); | |||||
| ED_uvedit_unwrap_cube_project_from_cursor(obedit, em->bm, cube_size, true, cursor_loc); | |||||
| } | |||||
| else { | |||||
| ED_uvedit_unwrap_cube_project(obedit, em->bm, cube_size, true); | |||||
| } | |||||
| uv_map_clip_correct(scene, obedit, em, op); | uv_map_clip_correct(scene, obedit, em, op); | ||||
| DAG_id_tag_update(obedit->data, 0); | DAG_id_tag_update(obedit->data, 0); | ||||
| Context not available. | |||||
| /* properties */ | /* properties */ | ||||
| RNA_def_float(ot->srna, "cube_size", 1.0f, 0.0f, FLT_MAX, "Cube Size", "Size of the cube to project on", 0.001f, 100.0f); | RNA_def_float(ot->srna, "cube_size", 1.0f, 0.0f, FLT_MAX, "Cube Size", "Size of the cube to project on", 0.001f, 100.0f); | ||||
| RNA_def_boolean(ot->srna, "cursor_center", false, "Unwrap from cursor", "Use 3D cursor instead of origin for Unwrapping"); | |||||
| uv_map_clip_correct_properties(ot); | uv_map_clip_correct_properties(ot); | ||||
| } | } | ||||
| Context not available. | |||||
Why not call cursor_center just like the name of the property?