main sync #3

Merged
Patrick Busch merged 318 commits from blender/blender:main into main 2023-03-17 15:52:21 +01:00
4 changed files with 55 additions and 42 deletions
Showing only changes of commit b06edc2897 - Show all commits

View File

@ -141,8 +141,7 @@ static bool ED_uvedit_ensure_uvs(Object *obedit)
/** \name UDIM Access
* \{ */
static void ED_uvedit_udim_params_from_image_space(const SpaceImage *sima,
UVPackIsland_Params *r_params)
void blender::geometry::UVPackIsland_Params::setUDIMOffsetFromSpaceImage(const SpaceImage *sima)
{
if (!sima) {
return; /* Nothing to do. */
@ -155,8 +154,8 @@ static void ED_uvedit_udim_params_from_image_space(const SpaceImage *sima,
ImageTile *active_tile = static_cast<ImageTile *>(
BLI_findlink(&image->tiles, image->active_tile_index));
if (active_tile) {
r_params->udim_base_offset[0] = (active_tile->tile_number - 1001) % 10;
r_params->udim_base_offset[1] = (active_tile->tile_number - 1001) / 10;
udim_base_offset[0] = (active_tile->tile_number - 1001) % 10;
udim_base_offset[1] = (active_tile->tile_number - 1001) / 10;
}
return;
}
@ -164,8 +163,8 @@ static void ED_uvedit_udim_params_from_image_space(const SpaceImage *sima,
/* TODO: Support storing an active UDIM when there are no tiles present.
* Until then, use 2D cursor to find the active tile index for the UDIM grid. */
if (uv_coords_isect_udim(sima->image, sima->tile_grid_shape, sima->cursor)) {
r_params->udim_base_offset[0] = floorf(sima->cursor[0]);
r_params->udim_base_offset[1] = floorf(sima->cursor[1]);
udim_base_offset[0] = floorf(sima->cursor[0]);
udim_base_offset[1] = floorf(sima->cursor[1]);
}
}
/** \} */
@ -195,6 +194,15 @@ struct UnwrapOptions {
bool pin_unselected;
};
void blender::geometry::UVPackIsland_Params::setFromUnwrapOptions(const UnwrapOptions &options)
{
only_selected_uvs = options.only_selected_uvs;
only_selected_faces = options.only_selected_faces;
use_seams = !options.topology_from_uvs || options.topology_from_uvs_use_seams;
correct_aspect = options.correct_aspect;
pin_unselected = options.pin_unselected;
}
static bool uvedit_have_selection(const Scene *scene, BMEditMesh *em, const UnwrapOptions *options)
{
BMFace *efa;
@ -1250,7 +1258,7 @@ static float uv_nearest_grid_tile_distance(const int udim_grid[2],
static bool island_has_pins(const Scene *scene,
FaceIsland *island,
const UVPackIsland_Params *params)
const blender::geometry::UVPackIsland_Params *params)
{
const bool pin_unselected = params->pin_unselected;
const bool only_selected_faces = params->only_selected_faces;
@ -1291,7 +1299,7 @@ static void uvedit_pack_islands_multi(const Scene *scene,
const int objects_len,
BMesh **bmesh_override,
const UVMapUDIM_Params *closest_udim,
const UVPackIsland_Params *params)
const blender::geometry::UVPackIsland_Params *params)
{
blender::Vector<FaceIsland *> island_vector;
@ -1502,14 +1510,10 @@ static int pack_islands_exec(bContext *C, wmOperator *op)
RNA_float_set(op->ptr, "margin", scene->toolsettings->uvcalc_margin);
}
UVPackIsland_Params pack_island_params{};
blender::geometry::UVPackIsland_Params pack_island_params;
pack_island_params.setFromUnwrapOptions(options);
pack_island_params.rotate = RNA_boolean_get(op->ptr, "rotate");
pack_island_params.only_selected_uvs = options.only_selected_uvs;
pack_island_params.only_selected_faces = options.only_selected_faces;
pack_island_params.use_seams = !options.topology_from_uvs || options.topology_from_uvs_use_seams;
pack_island_params.correct_aspect = options.correct_aspect;
pack_island_params.ignore_pinned = false;
pack_island_params.pin_unselected = options.pin_unselected;
pack_island_params.margin_method = eUVPackIsland_MarginMethod(
RNA_enum_get(op->ptr, "margin_method"));
pack_island_params.margin = RNA_float_get(op->ptr, "margin");
@ -1517,7 +1521,7 @@ static int pack_islands_exec(bContext *C, wmOperator *op)
UVMapUDIM_Params closest_udim_buf;
UVMapUDIM_Params *closest_udim = nullptr;
if (udim_source == PACK_UDIM_SRC_ACTIVE) {
ED_uvedit_udim_params_from_image_space(sima, &pack_island_params);
pack_island_params.setUDIMOffsetFromSpaceImage(sima);
}
else if (sima) {
BLI_assert(udim_source == PACK_UDIM_SRC_CLOSEST);
@ -2290,15 +2294,10 @@ void ED_uvedit_live_unwrap(const Scene *scene, Object **objects, int objects_len
options.correct_aspect = (scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT) == 0;
uvedit_unwrap_multi(scene, objects, objects_len, &options, nullptr);
UVPackIsland_Params pack_island_params{};
blender::geometry::UVPackIsland_Params pack_island_params;
pack_island_params.setFromUnwrapOptions(options);
pack_island_params.rotate = true;
pack_island_params.only_selected_uvs = options.only_selected_uvs;
pack_island_params.only_selected_faces = options.only_selected_faces;
pack_island_params.use_seams = !options.topology_from_uvs ||
options.topology_from_uvs_use_seams;
pack_island_params.correct_aspect = options.correct_aspect;
pack_island_params.ignore_pinned = true;
pack_island_params.pin_unselected = options.pin_unselected;
pack_island_params.margin_method = ED_UVPACK_MARGIN_SCALED;
pack_island_params.margin = scene->toolsettings->uvcalc_margin;
@ -2436,14 +2435,10 @@ static int unwrap_exec(bContext *C, wmOperator *op)
int count_failed = 0;
uvedit_unwrap_multi(scene, objects, objects_len, &options, &count_changed, &count_failed);
UVPackIsland_Params pack_island_params{};
blender::geometry::UVPackIsland_Params pack_island_params;
pack_island_params.setFromUnwrapOptions(options);
pack_island_params.rotate = true;
pack_island_params.only_selected_uvs = options.only_selected_uvs;
pack_island_params.only_selected_faces = options.only_selected_faces;
pack_island_params.use_seams = !options.topology_from_uvs || options.topology_from_uvs_use_seams;
pack_island_params.correct_aspect = options.correct_aspect;
pack_island_params.ignore_pinned = true;
pack_island_params.pin_unselected = options.pin_unselected;
pack_island_params.margin_method = eUVPackIsland_MarginMethod(
RNA_enum_get(op->ptr, "margin_method"));
pack_island_params.margin = RNA_float_get(op->ptr, "margin");
@ -2819,7 +2814,7 @@ static int smart_project_exec(bContext *C, wmOperator *op)
/* Depsgraph refresh functions are called here. */
const bool correct_aspect = RNA_boolean_get(op->ptr, "correct_aspect");
UVPackIsland_Params params{};
blender::geometry::UVPackIsland_Params params;
params.rotate = true;
params.only_selected_uvs = only_selected_uvs;
params.only_selected_faces = true;
@ -3808,7 +3803,7 @@ void ED_uvedit_add_simple_uvs(Main *bmain, const Scene *scene, Object *ob)
uvedit_unwrap_cube_project(scene, bm, 2.0, false, false, nullptr);
/* Pack UVs. */
UVPackIsland_Params params{};
blender::geometry::UVPackIsland_Params params;
params.rotate = true;
params.only_selected_uvs = false;
params.only_selected_faces = false;

View File

@ -3,6 +3,7 @@
#include "BLI_math_matrix.hh"
#include "BLI_span.hh"
#include "DNA_space_types.h"
#include "DNA_vec_types.h"
#pragma once
@ -11,14 +12,25 @@
* \ingroup geo
*/
struct UnwrapOptions;
enum eUVPackIsland_MarginMethod {
ED_UVPACK_MARGIN_SCALED = 0, /* Use scale of existing UVs to multiply margin. */
ED_UVPACK_MARGIN_ADD, /* Just add the margin, ignoring any UV scale. */
ED_UVPACK_MARGIN_FRACTION, /* Specify a precise fraction of final UV output. */
};
namespace blender::geometry {
/** See also #UnwrapOptions. */
struct UVPackIsland_Params {
class UVPackIsland_Params {
public:
/** Reasonable defaults. */
UVPackIsland_Params();
void setFromUnwrapOptions(const UnwrapOptions &options);
void setUDIMOffsetFromSpaceImage(const SpaceImage *sima);
/** Islands can be rotated to improve packing. */
bool rotate;
/** (In UV Editor) only pack islands which have one or more selected UVs. */
@ -41,8 +53,6 @@ struct UVPackIsland_Params {
float udim_base_offset[2];
};
namespace blender::geometry {
class PackIsland {
public:
rctf bounds_rect;

View File

@ -22,6 +22,22 @@
namespace blender::geometry {
UVPackIsland_Params::UVPackIsland_Params()
{
/* TEMPORARY, set every thing to "zero" for backwards compatibility. */
rotate = false;
only_selected_uvs = false;
only_selected_faces = false;
use_seams = false;
correct_aspect = false;
ignore_pinned = false;
pin_unselected = false;
margin = 0.001f;
margin_method = ED_UVPACK_MARGIN_SCALED;
udim_base_offset[0] = 0.0f;
udim_base_offset[1] = 0.0f;
}
/* Compact representation for AABB packers. */
class UVAABBIsland {
public:

View File

@ -4179,18 +4179,10 @@ void uv_parametrizer_pack(ParamHandle *handle, float margin, bool do_rotate, boo
pack_island->bounds_rect.ymax = maxv[1];
}
UVPackIsland_Params params{};
UVPackIsland_Params params;
params.rotate = do_rotate;
params.only_selected_uvs = false;
params.only_selected_faces = false;
params.use_seams = false;
params.correct_aspect = false;
params.ignore_pinned = false;
params.pin_unselected = false;
params.margin = margin;
params.margin_method = ED_UVPACK_MARGIN_SCALED;
params.udim_base_offset[0] = 0.0f;
params.udim_base_offset[1] = 0.0f;
float scale[2] = {1.0f, 1.0f};
pack_islands(pack_island_vector, params, scale);