Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/uvedit/uvedit_unwrap_ops.c
| Context not available. | |||||
| float radius = RNA_struct_find_property(op->ptr, "radius") ? RNA_float_get(op->ptr, "radius") : 1.0f; | float radius = RNA_struct_find_property(op->ptr, "radius") ? RNA_float_get(op->ptr, "radius") : 1.0f; | ||||
| float upangledeg, sideangledeg; | float upangledeg, sideangledeg; | ||||
| uv_map_transform_center(scene, v3d, center, obedit, em); | if (center) { | ||||
| uv_map_transform_center(scene, v3d, center, obedit, em); | |||||
mano-wii: In this case this function can be independent. The `center` can be obtained outside | |||||
| } | |||||
| if (direction == VIEW_ON_EQUATOR) { | if (direction == VIEW_ON_EQUATOR) { | ||||
| upangledeg = 90.0f; | upangledeg = 90.0f; | ||||
| 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"); | |||||
mano-wiiUnsubmitted Done Inline ActionsWhy not call cursor_center just like the name of the property? mano-wii: Why not call `cursor_center` just like the name of the property? | |||||
| /* 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. | |||||
| 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); | if (cursor_unwrap) { | ||||
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… | |||||
| uv_map_transform(C, op, NULL, rotmat); | |||||
| copy_v3_v3(center, ED_view3d_cursor3d_get(scene, v3d)); | |||||
mano-wiiUnsubmitted Not Done Inline ActionsBe careful about the value of center being local mano-wii: Be careful about the value of `center` being local | |||||
| } | |||||
| else { | |||||
| uv_map_transform(C, op, center, rotmat); | |||||
| } | |||||
| 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. | |||||
| cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); | cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); | ||||
Done Inline Actionssame as the previous comment mano-wii: same as the previous comment | |||||
| uv_map_transform(C, op, center, rotmat); | if (cursor_unwrap) { | ||||
| uv_map_transform(C, op, NULL, rotmat); | |||||
| copy_v3_v3(center, ED_view3d_cursor3d_get(scene, v3d)); | |||||
| } | |||||
| else { | |||||
| uv_map_transform(C, op, center, rotmat); | |||||
| } | |||||
| 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, 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); | ||||
| } | } | ||||
| /******************* Cube Project operator ****************/ | /******************* Cube Project operator ****************/ | ||||
| void ED_uvedit_unwrap_cube_project(Object *ob, BMesh *bm, float cube_size, bool use_select) | void ED_uvedit_unwrap_cube_project(Object *ob, BMesh *bm, float cube_size, bool use_select, float *offset) | ||||
mano-wiiUnsubmitted Done Inline Actionsconst float offset[3] mano-wii: `const float offset[3]` | |||||
| { | { | ||||
| BMFace *efa; | BMFace *efa; | ||||
| BMLoop *l; | BMLoop *l; | ||||
| Context not available. | |||||
| BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { | BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { | ||||
| luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); | 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]); | if (offset) { | ||||
| luv->uv[1] = 0.5f + 0.5f * cube_size * (loc[coy] + l->v->co[coy]); | luv->uv[0] = 0.5f + 0.5f * cube_size * (loc[cox] + l->v->co[cox] + offset[cox]); | ||||
| luv->uv[1] = 0.5f + 0.5f * cube_size * (loc[coy] + l->v->co[coy] + offset[coy]); | |||||
| } | |||||
| else { | |||||
| luv->uv[0] = 0.5f + 0.5f * cube_size * (loc[cox] + l->v->co[cox]); | |||||
| luv->uv[1] = 0.5f + 0.5f * cube_size * (loc[coy] + l->v->co[coy]); | |||||
| } | |||||
mano-wiiUnsubmitted 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) {… | |||||
| if (first) { | if (first) { | ||||
| dx = floor(luv->uv[0]); | dx = floor(luv->uv[0]); | ||||
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… | |||||
| dy = floor(luv->uv[1]); | dy = floor(luv->uv[1]); | ||||
| Context not available. | |||||
| 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; | |||||
| 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"); | |||||
mano-wiiUnsubmitted Done Inline Actions~cursor_unwrap~ > cursor_center mano-wii: ~cursor_unwrap~ > cursor_center | |||||
| if (cursor_unwrap) { | |||||
| float *cursor_loc = ED_view3d_cursor3d_get(scene, v3d); | |||||
mano-wiiUnsubmitted Not Done Inline ActionsThe value of cursor_loc must be local mano-wii: The value of `cursor_loc` must be local | |||||
| ED_uvedit_unwrap_cube_project(obedit, em->bm, cube_size, true, cursor_loc); | |||||
| } | |||||
| else { | |||||
| ED_uvedit_unwrap_cube_project(obedit, em->bm, cube_size, true, NULL); | |||||
| } | |||||
| 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. | |||||
In this case this function can be independent. The center can be obtained outside