diff options
Diffstat (limited to 'source/blender/editors/object')
-rw-r--r-- | source/blender/editors/object/object_add.cc | 2 | ||||
-rw-r--r-- | source/blender/editors/object/object_bake.c | 67 | ||||
-rw-r--r-- | source/blender/editors/object/object_bake_api.c | 144 | ||||
-rw-r--r-- | source/blender/editors/object/object_data_transfer.c | 6 | ||||
-rw-r--r-- | source/blender/editors/object/object_modifier.cc | 2 | ||||
-rw-r--r-- | source/blender/editors/object/object_remesh.cc | 17 | ||||
-rw-r--r-- | source/blender/editors/object/object_transform.cc | 11 |
7 files changed, 144 insertions, 105 deletions
diff --git a/source/blender/editors/object/object_add.cc b/source/blender/editors/object/object_add.cc index b3c5879b4d0..508d452bfe4 100644 --- a/source/blender/editors/object/object_add.cc +++ b/source/blender/editors/object/object_add.cc @@ -1638,7 +1638,7 @@ struct CollectionAddInfo { ushort local_view_bits; /* The transform that should be applied to the collection, determined through operator properties * if set (e.g. to place the collection under the cursor), otherwise through context (e.g. 3D - * cursor location). */ + * cursor location). */ float loc[3], rot[3]; }; diff --git a/source/blender/editors/object/object_bake.c b/source/blender/editors/object/object_bake.c index d469efbd0a1..1483c24ac70 100644 --- a/source/blender/editors/object/object_bake.c +++ b/source/blender/editors/object/object_bake.c @@ -172,28 +172,35 @@ static bool multiresbake_check(bContext *C, wmOperator *op) ok = false; } else { - ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL); + LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { + ImageUser iuser; + BKE_imageuser_default(&iuser); + iuser.tile = tile->tile_number; - if (!ibuf) { - BKE_report(op->reports, RPT_ERROR, "Baking should happen to image with image buffer"); + ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL); - ok = false; - } - else { - if (ibuf->rect == NULL && ibuf->rect_float == NULL) { - ok = false; - } + if (!ibuf) { + BKE_report( + op->reports, RPT_ERROR, "Baking should happen to image with image buffer"); - if (ibuf->rect_float && !(ELEM(ibuf->channels, 0, 4))) { ok = false; } - - if (!ok) { - BKE_report(op->reports, RPT_ERROR, "Baking to unsupported image type"); + else { + if (ibuf->rect == NULL && ibuf->rect_float == NULL) { + ok = false; + } + + if (ibuf->rect_float && !(ELEM(ibuf->channels, 0, 4))) { + ok = false; + } + + if (!ok) { + BKE_report(op->reports, RPT_ERROR, "Baking to unsupported image type"); + } } - } - BKE_image_release_ibuf(ima, ibuf, NULL); + BKE_image_release_ibuf(ima, ibuf, NULL); + } } } } @@ -274,21 +281,27 @@ static void clear_single_image(Image *image, ClearFlag flag) const float disp_solid[4] = {0.5f, 0.5f, 0.5f, 1.0f}; if ((image->id.tag & LIB_TAG_DOIT) == 0) { - ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL); + LISTBASE_FOREACH (ImageTile *, tile, &image->tiles) { + ImageUser iuser; + BKE_imageuser_default(&iuser); + iuser.tile = tile->tile_number; - if (flag == CLEAR_TANGENT_NORMAL) { - IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? nor_alpha : nor_solid); - } - else if (flag == CLEAR_DISPLACEMENT) { - IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? disp_alpha : disp_solid); - } - else { - IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? vec_alpha : vec_solid); - } + ImBuf *ibuf = BKE_image_acquire_ibuf(image, &iuser, NULL); - image->id.tag |= LIB_TAG_DOIT; + if (flag == CLEAR_TANGENT_NORMAL) { + IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? nor_alpha : nor_solid); + } + else if (flag == CLEAR_DISPLACEMENT) { + IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? disp_alpha : disp_solid); + } + else { + IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? vec_alpha : vec_solid); + } + + image->id.tag |= LIB_TAG_DOIT; - BKE_image_release_ibuf(image, ibuf, NULL); + BKE_image_release_ibuf(image, ibuf, NULL); + } } } diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c index 3060a1ecf62..a7379d7e492 100644 --- a/source/blender/editors/object/object_bake_api.c +++ b/source/blender/editors/object/object_bake_api.c @@ -19,6 +19,7 @@ #include "BLI_fileops.h" #include "BLI_listbase.h" #include "BLI_path_util.h" +#include "BLI_string.h" #include "BKE_context.h" #include "BKE_global.h" @@ -165,6 +166,7 @@ static void bake_update_image(ScrArea *area, Image *image) } static bool write_internal_bake_pixels(Image *image, + const int image_tile_number, BakePixel pixel_array[], float *buffer, const int width, @@ -174,7 +176,8 @@ static bool write_internal_bake_pixels(Image *image, const bool is_clear, const bool is_noncolor, Mesh const *mesh_eval, - char const *uv_layer) + char const *uv_layer, + const float uv_offset[2]) { ImBuf *ibuf; void *lock; @@ -182,7 +185,10 @@ static bool write_internal_bake_pixels(Image *image, char *mask_buffer = NULL; const size_t pixels_num = (size_t)width * (size_t)height; - ibuf = BKE_image_acquire_ibuf(image, NULL, &lock); + ImageUser iuser; + BKE_imageuser_default(&iuser); + iuser.tile = image_tile_number; + ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock); if (!ibuf) { return false; @@ -270,7 +276,7 @@ static bool write_internal_bake_pixels(Image *image, /* margins */ if (margin > 0) { - RE_bake_margin(ibuf, mask_buffer, margin, margin_type, mesh_eval, uv_layer); + RE_bake_margin(ibuf, mask_buffer, margin, margin_type, mesh_eval, uv_layer, uv_offset); } ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID; @@ -303,10 +309,8 @@ static void bake_targets_refresh(BakeTargets *targets) if (ima) { BKE_image_partial_update_mark_full_update(ima); - LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) { - BKE_image_free_gputextures(ima); - DEG_id_tag_update(&ima->id, 0); - } + BKE_image_free_gputextures(ima); + DEG_id_tag_update(&ima->id, 0); } } } @@ -321,7 +325,8 @@ static bool write_external_bake_pixels(const char *filepath, ImageFormatData *im_format, const bool is_noncolor, Mesh const *mesh_eval, - char const *uv_layer) + char const *uv_layer, + const float uv_offset[2]) { ImBuf *ibuf = NULL; bool ok = false; @@ -378,7 +383,7 @@ static bool write_external_bake_pixels(const char *filepath, mask_buffer = MEM_callocN(sizeof(char) * pixels_num, "Bake Mask"); RE_bake_mask_fill(pixel_array, pixels_num, mask_buffer); - RE_bake_margin(ibuf, mask_buffer, margin, margin_type, mesh_eval, uv_layer); + RE_bake_margin(ibuf, mask_buffer, margin, margin_type, mesh_eval, uv_layer, uv_offset); if (mask_buffer) { MEM_freeN(mask_buffer); @@ -443,7 +448,7 @@ static bool bake_object_check(ViewLayer *view_layer, if (target == R_BAKE_TARGET_VERTEX_COLORS) { MPropCol *mcol = CustomData_get_layer(&me->vdata, CD_PROP_COLOR); const bool mcol_valid = (mcol != NULL); - MLoopCol *mloopcol = CustomData_get_layer(&me->ldata, CD_MLOOPCOL); + MLoopCol *mloopcol = CustomData_get_layer(&me->ldata, CD_PROP_BYTE_COLOR); if (mloopcol == NULL && !mcol_valid) { BKE_reportf(reports, RPT_ERROR, @@ -467,7 +472,6 @@ static bool bake_object_check(ViewLayer *view_layer, ED_object_get_active_image(ob, mat_nr, &image, NULL, &node, &ntree); if (image) { - ImBuf *ibuf; if (node) { if (BKE_node_is_connected_to_output(ntree, node)) { @@ -482,21 +486,27 @@ static bool bake_object_check(ViewLayer *view_layer, } } - void *lock; - ibuf = BKE_image_acquire_ibuf(image, NULL, &lock); + LISTBASE_FOREACH (ImageTile *, tile, &image->tiles) { + ImageUser iuser; + BKE_imageuser_default(&iuser); + iuser.tile = tile->tile_number; - if (ibuf) { - BKE_image_release_ibuf(image, ibuf, lock); - } - else { - BKE_reportf(reports, - RPT_ERROR, - "Uninitialized image \"%s\" from object \"%s\"", - image->id.name + 2, - ob->id.name + 2); + void *lock; + ImBuf *ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock); + + if (ibuf) { + BKE_image_release_ibuf(image, ibuf, lock); + } + else { + BKE_reportf(reports, + RPT_ERROR, + "Uninitialized image \"%s\" from object \"%s\"", + image->id.name + 2, + ob->id.name + 2); - BKE_image_release_ibuf(image, ibuf, lock); - return false; + BKE_image_release_ibuf(image, ibuf, lock); + return false; + } } } else { @@ -687,36 +697,35 @@ static bool bake_targets_init_image_textures(const BakeAPIRender *bkr, } } - /* Over-allocate in case there is more materials than images. */ + /* Allocate material mapping. */ targets->materials_num = materials_num; - targets->images = MEM_callocN(sizeof(BakeImage) * targets->materials_num, "BakeTargets.images"); - targets->material_to_image = MEM_callocN(sizeof(int) * targets->materials_num, + targets->material_to_image = MEM_callocN(sizeof(Image *) * targets->materials_num, "BakeTargets.material_to_image"); /* Error handling and tag (in case multiple materials share the same image). */ BKE_main_id_tag_idcode(bkr->main, ID_IM, LIB_TAG_DOIT, false); + targets->images = NULL; + for (int i = 0; i < materials_num; i++) { Image *image; ED_object_get_active_image(ob, i + 1, &image, NULL, NULL, NULL); - /* Some materials have no image, we just ignore those cases. */ - if (image == NULL) { - targets->material_to_image[i] = -1; - } - else if (image->id.tag & LIB_TAG_DOIT) { - for (int j = 0; j < i; j++) { - if (targets->images[j].image == image) { - targets->material_to_image[i] = j; - break; - } + targets->material_to_image[i] = image; + + /* Some materials have no image, we just ignore those cases. + * Also setup each image only once. */ + if (image && !(image->id.tag & LIB_TAG_DOIT)) { + LISTBASE_FOREACH (ImageTile *, tile, &image->tiles) { + /* Add bake image. */ + targets->images = MEM_recallocN(targets->images, + sizeof(BakeImage) * (targets->images_num + 1)); + targets->images[targets->images_num].image = image; + targets->images[targets->images_num].tile_number = tile->tile_number; + targets->images_num++; } - } - else { - targets->material_to_image[i] = targets->images_num; - targets->images[targets->images_num].image = image; + image->id.tag |= LIB_TAG_DOIT; - targets->images_num++; } } @@ -735,13 +744,19 @@ static bool bake_targets_init_internal(const BakeAPIRender *bkr, /* Saving to image datablocks. */ for (int i = 0; i < targets->images_num; i++) { BakeImage *bk_image = &targets->images[i]; + + ImageUser iuser; + BKE_imageuser_default(&iuser); + iuser.tile = bk_image->tile_number; + void *lock; - ImBuf *ibuf = BKE_image_acquire_ibuf(bk_image->image, NULL, &lock); + ImBuf *ibuf = BKE_image_acquire_ibuf(bk_image->image, &iuser, &lock); if (ibuf) { bk_image->width = ibuf->x; bk_image->height = ibuf->y; bk_image->offset = targets->pixels_num; + BKE_image_get_tile_uv(bk_image->image, bk_image->tile_number, bk_image->uv_offset); targets->pixels_num += (size_t)ibuf->x * (size_t)ibuf->y; } @@ -768,6 +783,7 @@ static bool bake_targets_output_internal(const BakeAPIRender *bkr, for (int i = 0; i < targets->images_num; i++) { BakeImage *bk_image = &targets->images[i]; const bool ok = write_internal_bake_pixels(bk_image->image, + bk_image->tile_number, pixel_array + bk_image->offset, targets->result + bk_image->offset * targets->channels_num, @@ -778,7 +794,8 @@ static bool bake_targets_output_internal(const BakeAPIRender *bkr, bkr->is_clear, targets->is_noncolor, mesh_eval, - bkr->uv_layer); + bkr->uv_layer, + bk_image->uv_offset); /* might be read by UI to set active image for display */ bake_update_image(bkr->area, bk_image->image); @@ -815,7 +832,6 @@ static bool bake_targets_init_external(const BakeAPIRender *bkr, bk_image->width = bkr->width; bk_image->height = bkr->height; bk_image->offset = targets->pixels_num; - bk_image->image = NULL; targets->pixels_num += (size_t)bkr->width * (size_t)bkr->height; @@ -827,7 +843,7 @@ static bool bake_targets_init_external(const BakeAPIRender *bkr, if (!bkr->is_split_materials) { /* saving a single image */ for (int i = 0; i < targets->materials_num; i++) { - targets->material_to_image[i] = 0; + targets->material_to_image[i] = targets->images[0].image; } } @@ -865,25 +881,26 @@ static bool bake_targets_output_external(const BakeAPIRender *bkr, } if (bkr->is_split_materials) { - if (bk_image->image) { - BLI_path_suffix(name, FILE_MAX, bk_image->image->id.name + 2, "_"); + if (ob_eval->mat[i]) { + BLI_path_suffix(name, FILE_MAX, ob_eval->mat[i]->id.name + 2, "_"); + } + else if (mesh_eval->mat[i]) { + BLI_path_suffix(name, FILE_MAX, mesh_eval->mat[i]->id.name + 2, "_"); } else { - if (ob_eval->mat[i]) { - BLI_path_suffix(name, FILE_MAX, ob_eval->mat[i]->id.name + 2, "_"); - } - else if (mesh_eval->mat[i]) { - BLI_path_suffix(name, FILE_MAX, mesh_eval->mat[i]->id.name + 2, "_"); - } - else { - /* if everything else fails, use the material index */ - char tmp[5]; - sprintf(tmp, "%d", i % 1000); - BLI_path_suffix(name, FILE_MAX, tmp, "_"); - } + /* if everything else fails, use the material index */ + char tmp[5]; + sprintf(tmp, "%d", i % 1000); + BLI_path_suffix(name, FILE_MAX, tmp, "_"); } } + if (bk_image->tile_number) { + char tmp[FILE_MAX]; + SNPRINTF(tmp, "%d", bk_image->tile_number); + BLI_path_suffix(name, FILE_MAX, tmp, "_"); + } + /* save it externally */ const bool ok = write_external_bake_pixels(name, pixel_array + bk_image->offset, @@ -896,7 +913,8 @@ static bool bake_targets_output_external(const BakeAPIRender *bkr, &bake->im_format, targets->is_noncolor, mesh_eval, - bkr->uv_layer); + bkr->uv_layer, + bk_image->uv_offset); if (!ok) { BKE_reportf(reports, RPT_ERROR, "Problem saving baked map in \"%s\"", name); @@ -927,7 +945,7 @@ static bool bake_targets_init_vertex_colors(BakeTargets *targets, Object *ob, Re Mesh *me = ob->data; MPropCol *mcol = CustomData_get_layer(&me->vdata, CD_PROP_COLOR); const bool mcol_valid = (mcol != NULL); - MLoopCol *mloopcol = CustomData_get_layer(&me->ldata, CD_MLOOPCOL); + MLoopCol *mloopcol = CustomData_get_layer(&me->ldata, CD_PROP_BYTE_COLOR); if (mloopcol == NULL && !mcol_valid) { BKE_report(reports, RPT_ERROR, "No vertex colors layer found to bake to"); return false; @@ -1081,7 +1099,7 @@ static bool bake_targets_output_vertex_colors(BakeTargets *targets, Object *ob) Mesh *me = ob->data; MPropCol *mcol = CustomData_get_layer(&me->vdata, CD_PROP_COLOR); const bool mcol_valid = (mcol != NULL); - MLoopCol *mloopcol = CustomData_get_layer(&me->ldata, CD_MLOOPCOL); + MLoopCol *mloopcol = CustomData_get_layer(&me->ldata, CD_PROP_BYTE_COLOR); const int channels_num = targets->channels_num; const float *result = targets->result; diff --git a/source/blender/editors/object/object_data_transfer.c b/source/blender/editors/object/object_data_transfer.c index 23d2327fe72..dfe858e5bd9 100644 --- a/source/blender/editors/object/object_data_transfer.c +++ b/source/blender/editors/object/object_data_transfer.c @@ -89,7 +89,7 @@ static void dt_add_vcol_layers(CustomData *cdata, EnumPropertyItem **r_item, int *r_totitem) { - int types[2] = {CD_PROP_COLOR, CD_MLOOPCOL}; + int types[2] = {CD_PROP_COLOR, CD_PROP_BYTE_COLOR}; for (int i = 0; i < 2; i++) { CustomDataType type = types[i]; @@ -196,14 +196,14 @@ static const EnumPropertyItem *dt_layers_select_src_itemf(bContext *C, cddata_masks.vmask |= CD_MASK_PROP_COLOR; } if (data_type & (DT_TYPE_MLOOPCOL_VERT)) { - cddata_masks.vmask |= CD_MASK_MLOOPCOL; + cddata_masks.vmask |= CD_MASK_PROP_BYTE_COLOR; } if (data_type & (DT_TYPE_MPROPCOL_LOOP)) { cddata_masks.lmask |= CD_MASK_PROP_COLOR; } if (data_type & (DT_TYPE_MLOOPCOL_LOOP)) { - cddata_masks.lmask |= CD_MASK_MLOOPCOL; + cddata_masks.lmask |= CD_MASK_PROP_BYTE_COLOR; } Mesh *me_eval = mesh_get_eval_final(depsgraph, scene_eval, ob_src_eval, &cddata_masks); diff --git a/source/blender/editors/object/object_modifier.cc b/source/blender/editors/object/object_modifier.cc index f7543c97903..8b2dbd4a865 100644 --- a/source/blender/editors/object/object_modifier.cc +++ b/source/blender/editors/object/object_modifier.cc @@ -855,7 +855,7 @@ bool ED_object_modifier_apply(Main *bmain, Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); ModifierData *md_eval = (ob_eval) ? BKE_modifiers_findby_name(ob_eval, md->name) : md; - /* allow apply of a not-realtime modifier, by first re-enabling realtime. */ + /* Allow apply of a non-real-time modifier, by first re-enabling real-time. */ int prev_mode = md_eval->mode; md_eval->mode |= eModifierMode_Realtime; diff --git a/source/blender/editors/object/object_remesh.cc b/source/blender/editors/object/object_remesh.cc index 966df0668ca..ba2efa6e517 100644 --- a/source/blender/editors/object/object_remesh.cc +++ b/source/blender/editors/object/object_remesh.cc @@ -40,6 +40,7 @@ #include "BKE_report.h" #include "BKE_scene.h" #include "BKE_shrinkwrap.h" +#include "BKE_unit.h" #include "DEG_depsgraph.h" #include "DEG_depsgraph_build.h" @@ -282,7 +283,7 @@ static void voxel_size_parallel_lines_draw(uint pos3d, immEnd(); } -static void voxel_size_edit_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void *arg) +static void voxel_size_edit_draw(const bContext *C, ARegion *UNUSED(ar), void *arg) { VoxelSizeEditCustomData *cd = static_cast<VoxelSizeEditCustomData *>(arg); @@ -338,8 +339,15 @@ static void voxel_size_edit_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), short fstyle_points = fstyle->points; char str[VOXEL_SIZE_EDIT_MAX_STR_LEN]; short strdrawlen = 0; - - BLI_snprintf(str, VOXEL_SIZE_EDIT_MAX_STR_LEN, "%.4f", cd->voxel_size); + Scene *scene = CTX_data_scene(C); + UnitSettings *unit = &scene->unit; + BKE_unit_value_as_string(str, + VOXEL_SIZE_EDIT_MAX_STR_LEN, + (double)(cd->voxel_size * unit->scale_length), + 4, + B_UNIT_LENGTH, + unit, + true); strdrawlen = BLI_strlen_utf8(str); immUnbindProgram(); @@ -885,9 +893,6 @@ static void quadriflow_start_job(void *customdata, short *stop, short *do_update BKE_mesh_nomain_to_mesh(new_mesh, mesh, ob, &CD_MASK_MESH, true); if (qj->smooth_normals) { - if (qj->use_mesh_symmetry) { - BKE_mesh_calc_normals(static_cast<Mesh *>(ob->data)); - } BKE_mesh_smooth_flag_set(static_cast<Mesh *>(ob->data), true); } diff --git a/source/blender/editors/object/object_transform.cc b/source/blender/editors/object/object_transform.cc index 976fe683f95..da3df159c33 100644 --- a/source/blender/editors/object/object_transform.cc +++ b/source/blender/editors/object/object_transform.cc @@ -884,9 +884,6 @@ static int apply_objects_internal(bContext *C, /* adjust data */ BKE_mesh_transform(me, mat, true); - - /* If normal layers exist, they are now dirty. */ - BKE_mesh_normals_tag_dirty(me); } else if (ob->type == OB_ARMATURE) { bArmature *arm = static_cast<bArmature *>(ob->data); @@ -1173,6 +1170,12 @@ void OBJECT_OT_transform_apply(wmOperatorType *ot) RNA_def_property_flag(prop, PROP_SKIP_SAVE); } +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Apply Parent Inverse Operator + * \{ */ + static int object_parent_inverse_apply_exec(bContext *C, wmOperator *UNUSED(op)) { CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) { @@ -1194,7 +1197,7 @@ void OBJECT_OT_parent_inverse_apply(wmOperatorType *ot) { /* identifiers */ ot->name = "Apply Parent Inverse"; - ot->description = "Apply the object's parent inverse to the its data"; + ot->description = "Apply the object's parent inverse to its data"; ot->idname = "OBJECT_OT_parent_inverse_apply"; /* api callbacks */ |