Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/uvedit/uvedit_clipboard.cc
| Show First 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | for (int island_index = 0; island_index < element_map->total_islands; island_index++) { | ||||
| graph.append(build_iso_graph(element_map, island_index, cd_loop_uv_offset)); | graph.append(build_iso_graph(element_map, island_index, cd_loop_uv_offset)); | ||||
| /* TODO: Consider iterating over `BM_uv_element_map_ensure_unique_index` instead. */ | /* TODO: Consider iterating over `BM_uv_element_map_ensure_unique_index` instead. */ | ||||
| for (int j = 0; j < element_map->island_total_uvs[island_index]; j++) { | for (int j = 0; j < element_map->island_total_uvs[island_index]; j++) { | ||||
| UvElement *element = element_map->storage + element_map->island_indices[island_index] + j; | UvElement *element = element_map->storage + element_map->island_indices[island_index] + j; | ||||
| if (!element->separate) { | if (!element->separate) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| MLoopUV *luv = static_cast<MLoopUV *>(BM_ELEM_CD_GET_VOID_P(element->l, cd_loop_uv_offset)); | float *luv = BM_ELEM_CD_GET_FLOAT_P(element->l, cd_loop_uv_offset); | ||||
| uv.append(std::make_pair(luv->uv[0], luv->uv[1])); | uv.append(std::make_pair(luv[0], luv[1])); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Write UVs back to an island. */ | /* Write UVs back to an island. */ | ||||
| void UV_ClipboardBuffer::write_uvs(UvElementMap *element_map, | void UV_ClipboardBuffer::write_uvs(UvElementMap *element_map, | ||||
| int island_index, | int island_index, | ||||
| const int cd_loop_uv_offset, | const int cd_loop_uv_offset, | ||||
| const blender::Vector<int> &label) | const blender::Vector<int> &label) | ||||
| { | { | ||||
| BLI_assert(label.size() == element_map->island_total_unique_uvs[island_index]); | BLI_assert(label.size() == element_map->island_total_unique_uvs[island_index]); | ||||
| /* TODO: Consider iterating over `BM_uv_element_map_ensure_unique_index` instead. */ | /* TODO: Consider iterating over `BM_uv_element_map_ensure_unique_index` instead. */ | ||||
| int unique_uv = 0; | int unique_uv = 0; | ||||
| for (int j = 0; j < element_map->island_total_uvs[island_index]; j++) { | for (int j = 0; j < element_map->island_total_uvs[island_index]; j++) { | ||||
| int k = element_map->island_indices[island_index] + j; | int k = element_map->island_indices[island_index] + j; | ||||
| UvElement *element = element_map->storage + k; | UvElement *element = element_map->storage + k; | ||||
| if (!element->separate) { | if (!element->separate) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| BLI_assert(0 <= unique_uv); | BLI_assert(0 <= unique_uv); | ||||
| BLI_assert(unique_uv < label.size()); | BLI_assert(unique_uv < label.size()); | ||||
| const std::pair<float, float> &source_uv = uv_clipboard->uv[label[unique_uv]]; | const std::pair<float, float> &source_uv = uv_clipboard->uv[label[unique_uv]]; | ||||
| while (element) { | while (element) { | ||||
| MLoopUV *luv = static_cast<MLoopUV *>(BM_ELEM_CD_GET_VOID_P(element->l, cd_loop_uv_offset)); | float *luv = BM_ELEM_CD_GET_FLOAT_P(element->l, cd_loop_uv_offset); | ||||
| luv->uv[0] = source_uv.first; | luv[0] = source_uv.first; | ||||
| luv->uv[1] = source_uv.second; | luv[1] = source_uv.second; | ||||
| element = element->next; | element = element->next; | ||||
| if (!element || element->separate) { | if (!element || element->separate) { | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| unique_uv++; | unique_uv++; | ||||
| } | } | ||||
| BLI_assert(unique_uv == label.size()); | BLI_assert(unique_uv == label.size()); | ||||
| ▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | static int uv_copy_exec(bContext *C, wmOperator * /*op*/) | ||||
| for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | ||||
| Object *ob = objects[ob_index]; | Object *ob = objects[ob_index]; | ||||
| BMEditMesh *em = BKE_editmesh_from_object(ob); | BMEditMesh *em = BKE_editmesh_from_object(ob); | ||||
| const bool use_seams = false; | const bool use_seams = false; | ||||
| UvElementMap *element_map = BM_uv_element_map_create( | UvElementMap *element_map = BM_uv_element_map_create( | ||||
| em->bm, scene, true, false, use_seams, true); | em->bm, scene, true, false, use_seams, true); | ||||
| if (element_map) { | if (element_map) { | ||||
| const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); | const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_PROP_FLOAT2); | ||||
| uv_clipboard->append(element_map, cd_loop_uv_offset); | uv_clipboard->append(element_map, cd_loop_uv_offset); | ||||
| } | } | ||||
| BM_uv_element_map_free(element_map); | BM_uv_element_map_free(element_map); | ||||
| } | } | ||||
| MEM_freeN(objects); | MEM_freeN(objects); | ||||
| /* TODO: Serialize `UvClipboard` to system clipboard. */ | /* TODO: Serialize `UvClipboard` to system clipboard. */ | ||||
| Show All 14 Lines | static int uv_paste_exec(bContext *C, wmOperator * /*op*/) | ||||
| Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs( | Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs( | ||||
| scene, view_layer, ((View3D *)nullptr), &objects_len); | scene, view_layer, ((View3D *)nullptr), &objects_len); | ||||
| for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | ||||
| Object *ob = objects[ob_index]; | Object *ob = objects[ob_index]; | ||||
| BMEditMesh *em = BKE_editmesh_from_object(ob); | BMEditMesh *em = BKE_editmesh_from_object(ob); | ||||
| const bool use_seams = false; | const bool use_seams = false; | ||||
| const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); | const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_PROP_FLOAT2); | ||||
| UvElementMap *dest_element_map = BM_uv_element_map_create( | UvElementMap *dest_element_map = BM_uv_element_map_create( | ||||
| em->bm, scene, true, false, use_seams, true); | em->bm, scene, true, false, use_seams, true); | ||||
| if (!dest_element_map) { | if (!dest_element_map) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines | |||||