Cleanup: Move six mesh-related files to C++
For continued refactoring of the Mesh data structure. See T103343.
This commit is contained in:
@@ -119,7 +119,7 @@ set(SRC
|
||||
intern/customdata.cc
|
||||
intern/customdata_file.c
|
||||
intern/data_transfer.cc
|
||||
intern/deform.c
|
||||
intern/deform.cc
|
||||
intern/displist.cc
|
||||
intern/dynamicpaint.cc
|
||||
intern/editlattice.c
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
* \ingroup bke
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
@@ -46,7 +46,7 @@ bDeformGroup *BKE_object_defgroup_new(Object *ob, const char *name)
|
||||
|
||||
BLI_assert(OB_TYPE_SUPPORT_VGROUP(ob->type));
|
||||
|
||||
defgroup = MEM_callocN(sizeof(bDeformGroup), __func__);
|
||||
defgroup = MEM_cnew<bDeformGroup>(__func__);
|
||||
|
||||
BLI_strncpy(defgroup->name, name, sizeof(defgroup->name));
|
||||
|
||||
@@ -62,31 +62,26 @@ bDeformGroup *BKE_object_defgroup_new(Object *ob, const char *name)
|
||||
|
||||
void BKE_defgroup_copy_list(ListBase *outbase, const ListBase *inbase)
|
||||
{
|
||||
bDeformGroup *defgroup, *defgroupn;
|
||||
|
||||
BLI_listbase_clear(outbase);
|
||||
|
||||
for (defgroup = inbase->first; defgroup; defgroup = defgroup->next) {
|
||||
defgroupn = BKE_defgroup_duplicate(defgroup);
|
||||
LISTBASE_FOREACH (const bDeformGroup *, defgroup, inbase) {
|
||||
bDeformGroup *defgroupn = BKE_defgroup_duplicate(defgroup);
|
||||
BLI_addtail(outbase, defgroupn);
|
||||
}
|
||||
}
|
||||
|
||||
bDeformGroup *BKE_defgroup_duplicate(const bDeformGroup *ingroup)
|
||||
{
|
||||
bDeformGroup *outgroup;
|
||||
|
||||
if (!ingroup) {
|
||||
BLI_assert(0);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
outgroup = MEM_callocN(sizeof(bDeformGroup), "copy deformGroup");
|
||||
bDeformGroup *outgroup = MEM_cnew<bDeformGroup>(__func__);
|
||||
|
||||
/* For now, just copy everything over. */
|
||||
memcpy(outgroup, ingroup, sizeof(bDeformGroup));
|
||||
|
||||
outgroup->next = outgroup->prev = NULL;
|
||||
outgroup->next = outgroup->prev = nullptr;
|
||||
|
||||
return outgroup;
|
||||
}
|
||||
@@ -132,10 +127,10 @@ void BKE_defvert_copy(MDeformVert *dvert_dst, const MDeformVert *dvert_src)
|
||||
}
|
||||
|
||||
if (dvert_src->totweight) {
|
||||
dvert_dst->dw = MEM_dupallocN(dvert_src->dw);
|
||||
dvert_dst->dw = static_cast<MDeformWeight *>(MEM_dupallocN(dvert_src->dw));
|
||||
}
|
||||
else {
|
||||
dvert_dst->dw = NULL;
|
||||
dvert_dst->dw = nullptr;
|
||||
}
|
||||
|
||||
dvert_dst->totweight = dvert_src->totweight;
|
||||
@@ -157,7 +152,7 @@ void BKE_defvert_copy_index(MDeformVert *dvert_dst,
|
||||
dw_dst->weight = dw_src->weight;
|
||||
}
|
||||
else {
|
||||
/* Source was NULL, assign zero (could also remove). */
|
||||
/* Source was nullptr, assign zero (could also remove). */
|
||||
dw_dst = BKE_defvert_find_index(dvert_dst, defgroup_dst);
|
||||
|
||||
if (dw_dst) {
|
||||
@@ -307,7 +302,7 @@ void BKE_defvert_normalize_lock_single(MDeformVert *dvert,
|
||||
}
|
||||
}
|
||||
else {
|
||||
MDeformWeight *dw_lock = NULL;
|
||||
MDeformWeight *dw_lock = nullptr;
|
||||
MDeformWeight *dw;
|
||||
uint i;
|
||||
float tot_weight = 0.0f;
|
||||
@@ -423,7 +418,7 @@ void BKE_defvert_flip_merged(MDeformVert *dvert, const int *flip_map, const int
|
||||
for (dw = dvert->dw, i = 0; i < totweight; dw++, i++) {
|
||||
if (dw->def_nr < flip_map_num) {
|
||||
if (flip_map[dw->def_nr] >= 0) {
|
||||
/* error checkers complain of this but we'll never get NULL return */
|
||||
/* error checkers complain of this but we'll never get nullptr return */
|
||||
dw_cpy = BKE_defvert_ensure_index(dvert, flip_map[dw->def_nr]);
|
||||
dw = &dvert->dw[i]; /* in case array got realloced */
|
||||
|
||||
@@ -441,7 +436,7 @@ void BKE_defvert_flip_merged(MDeformVert *dvert, const int *flip_map, const int
|
||||
bool BKE_object_supports_vertex_groups(const Object *ob)
|
||||
{
|
||||
const ID *id = (const ID *)ob->data;
|
||||
if (id == NULL) {
|
||||
if (id == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -467,7 +462,7 @@ const ListBase *BKE_id_defgroup_list_get(const ID *id)
|
||||
BLI_assert_unreachable();
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static const int *object_defgroup_active_index_get_p(const Object *ob)
|
||||
@@ -487,7 +482,7 @@ static const int *object_defgroup_active_index_get_p(const Object *ob)
|
||||
return &gpd->vertex_group_active_index;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ListBase *BKE_id_defgroup_list_get_mutable(ID *id)
|
||||
@@ -498,38 +493,38 @@ ListBase *BKE_id_defgroup_list_get_mutable(ID *id)
|
||||
|
||||
bDeformGroup *BKE_object_defgroup_find_name(const Object *ob, const char *name)
|
||||
{
|
||||
if (name == NULL || name[0] == '\0') {
|
||||
return NULL;
|
||||
if (name == nullptr || name[0] == '\0') {
|
||||
return nullptr;
|
||||
}
|
||||
const ListBase *defbase = BKE_object_defgroup_list(ob);
|
||||
return BLI_findstring(defbase, name, offsetof(bDeformGroup, name));
|
||||
return static_cast<bDeformGroup *>(BLI_findstring(defbase, name, offsetof(bDeformGroup, name)));
|
||||
}
|
||||
|
||||
int BKE_id_defgroup_name_index(const ID *id, const char *name)
|
||||
{
|
||||
int index;
|
||||
if (!BKE_id_defgroup_name_find(id, name, &index, NULL)) {
|
||||
if (!BKE_id_defgroup_name_find(id, name, &index, nullptr)) {
|
||||
return -1;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
bool BKE_id_defgroup_name_find(const struct ID *id,
|
||||
bool BKE_id_defgroup_name_find(const ID *id,
|
||||
const char *name,
|
||||
int *r_index,
|
||||
struct bDeformGroup **r_group)
|
||||
bDeformGroup **r_group)
|
||||
{
|
||||
if (name == NULL || name[0] == '\0') {
|
||||
if (name == nullptr || name[0] == '\0') {
|
||||
return false;
|
||||
}
|
||||
const ListBase *defbase = BKE_id_defgroup_list_get(id);
|
||||
int index;
|
||||
LISTBASE_FOREACH_INDEX (bDeformGroup *, group, defbase, index) {
|
||||
if (STREQ(name, group->name)) {
|
||||
if (r_index != NULL) {
|
||||
if (r_index != nullptr) {
|
||||
*r_index = index;
|
||||
}
|
||||
if (r_group != NULL) {
|
||||
if (r_group != nullptr) {
|
||||
*r_group = group;
|
||||
}
|
||||
return true;
|
||||
@@ -582,19 +577,19 @@ static int *object_defgroup_unlocked_flip_map_ex(const Object *ob,
|
||||
*r_flip_map_num = defbase_num;
|
||||
|
||||
if (defbase_num == 0) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bDeformGroup *dg;
|
||||
char name_flip[sizeof(dg->name)];
|
||||
int i, flip_num;
|
||||
int *map = MEM_mallocN(defbase_num * sizeof(int), __func__);
|
||||
int *map = static_cast<int *>(MEM_mallocN(defbase_num * sizeof(int), __func__));
|
||||
|
||||
for (i = 0; i < defbase_num; i++) {
|
||||
map[i] = -1;
|
||||
}
|
||||
|
||||
for (dg = defbase->first, i = 0; dg; dg = dg->next, i++) {
|
||||
for (dg = static_cast<bDeformGroup *>(defbase->first), i = 0; dg; dg = dg->next, i++) {
|
||||
if (map[i] == -1) { /* may be calculated previously */
|
||||
|
||||
/* in case no valid value is found, use this */
|
||||
@@ -642,18 +637,17 @@ int *BKE_object_defgroup_flip_map_single(const Object *ob,
|
||||
*r_flip_map_num = defbase_num;
|
||||
|
||||
if (defbase_num == 0) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bDeformGroup *dg;
|
||||
char name_flip[sizeof(dg->name)];
|
||||
int i, flip_num, *map = MEM_mallocN(defbase_num * sizeof(int), __func__);
|
||||
char name_flip[sizeof(bDeformGroup::name)];
|
||||
int i, flip_num, *map = static_cast<int *>(MEM_mallocN(defbase_num * sizeof(int), __func__));
|
||||
|
||||
for (i = 0; i < defbase_num; i++) {
|
||||
map[i] = use_default ? i : -1;
|
||||
}
|
||||
|
||||
dg = BLI_findlink(defbase, defgroup);
|
||||
bDeformGroup *dg = static_cast<bDeformGroup *>(BLI_findlink(defbase, defgroup));
|
||||
|
||||
BLI_string_flip_side_name(name_flip, dg->name, false, sizeof(name_flip));
|
||||
if (!STREQ(name_flip, dg->name)) {
|
||||
@@ -671,7 +665,7 @@ int *BKE_object_defgroup_flip_map_single(const Object *ob,
|
||||
int BKE_object_defgroup_flip_index(const Object *ob, int index, const bool use_default)
|
||||
{
|
||||
const ListBase *defbase = BKE_object_defgroup_list(ob);
|
||||
bDeformGroup *dg = BLI_findlink(defbase, index);
|
||||
bDeformGroup *dg = static_cast<bDeformGroup *>(BLI_findlink(defbase, index));
|
||||
int flip_index = -1;
|
||||
|
||||
if (dg) {
|
||||
@@ -691,7 +685,7 @@ static bool defgroup_find_name_dupe(const char *name, bDeformGroup *dg, Object *
|
||||
const ListBase *defbase = BKE_object_defgroup_list(ob);
|
||||
bDeformGroup *curdef;
|
||||
|
||||
for (curdef = defbase->first; curdef; curdef = curdef->next) {
|
||||
for (curdef = static_cast<bDeformGroup *>(defbase->first); curdef; curdef = curdef->next) {
|
||||
if (dg != curdef) {
|
||||
if (STREQ(curdef->name, name)) {
|
||||
return true;
|
||||
@@ -702,46 +696,42 @@ static bool defgroup_find_name_dupe(const char *name, bDeformGroup *dg, Object *
|
||||
return false;
|
||||
}
|
||||
|
||||
struct DeformGroupUniqueNameData {
|
||||
Object *ob;
|
||||
bDeformGroup *dg;
|
||||
};
|
||||
|
||||
static bool defgroup_unique_check(void *arg, const char *name)
|
||||
{
|
||||
struct {
|
||||
Object *ob;
|
||||
void *dg;
|
||||
} *data = arg;
|
||||
DeformGroupUniqueNameData *data = static_cast<DeformGroupUniqueNameData *>(arg);
|
||||
return defgroup_find_name_dupe(name, data->dg, data->ob);
|
||||
}
|
||||
|
||||
void BKE_object_defgroup_unique_name(bDeformGroup *dg, Object *ob)
|
||||
{
|
||||
struct {
|
||||
Object *ob;
|
||||
void *dg;
|
||||
} data;
|
||||
data.ob = ob;
|
||||
data.dg = dg;
|
||||
|
||||
DeformGroupUniqueNameData data{ob, dg};
|
||||
BLI_uniquename_cb(defgroup_unique_check, &data, DATA_("Group"), '.', dg->name, sizeof(dg->name));
|
||||
}
|
||||
|
||||
float BKE_defvert_find_weight(const struct MDeformVert *dvert, const int defgroup)
|
||||
float BKE_defvert_find_weight(const MDeformVert *dvert, const int defgroup)
|
||||
{
|
||||
MDeformWeight *dw = BKE_defvert_find_index(dvert, defgroup);
|
||||
return dw ? dw->weight : 0.0f;
|
||||
}
|
||||
|
||||
float BKE_defvert_array_find_weight_safe(const struct MDeformVert *dvert,
|
||||
float BKE_defvert_array_find_weight_safe(const MDeformVert *dvert,
|
||||
const int index,
|
||||
const int defgroup)
|
||||
{
|
||||
/* Invalid defgroup index means the vgroup selected is invalid,
|
||||
* does not exist, in that case it is OK to return 1.0
|
||||
* (i.e. maximum weight, as if no vgroup was selected).
|
||||
* But in case of valid defgroup and NULL dvert data pointer, it means that vgroup **is** valid,
|
||||
* and just totally empty, so we shall return '0.0' value then! */
|
||||
* But in case of valid defgroup and nullptr dvert data pointer, it means that vgroup **is**
|
||||
* valid, and just totally empty, so we shall return '0.0' value then! */
|
||||
if (defgroup == -1) {
|
||||
return 1.0f;
|
||||
}
|
||||
if (dvert == NULL) {
|
||||
if (dvert == nullptr) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
@@ -764,7 +754,7 @@ MDeformWeight *BKE_defvert_find_index(const MDeformVert *dvert, const int defgro
|
||||
BLI_assert(0);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MDeformWeight *BKE_defvert_ensure_index(MDeformVert *dvert, const int defgroup)
|
||||
@@ -774,7 +764,7 @@ MDeformWeight *BKE_defvert_ensure_index(MDeformVert *dvert, const int defgroup)
|
||||
/* do this check always, this function is used to check for it */
|
||||
if (!dvert || defgroup < 0) {
|
||||
BLI_assert(0);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
dw_new = BKE_defvert_find_index(dvert, defgroup);
|
||||
@@ -782,7 +772,8 @@ MDeformWeight *BKE_defvert_ensure_index(MDeformVert *dvert, const int defgroup)
|
||||
return dw_new;
|
||||
}
|
||||
|
||||
dw_new = MEM_mallocN(sizeof(MDeformWeight) * (dvert->totweight + 1), "deformWeight");
|
||||
dw_new = static_cast<MDeformWeight *>(
|
||||
MEM_mallocN(sizeof(MDeformWeight) * (dvert->totweight + 1), __func__));
|
||||
if (dvert->dw) {
|
||||
memcpy(dw_new, dvert->dw, sizeof(MDeformWeight) * dvert->totweight);
|
||||
MEM_freeN(dvert->dw);
|
||||
@@ -810,8 +801,8 @@ void BKE_defvert_add_index_notest(MDeformVert *dvert, const int defgroup, const
|
||||
return;
|
||||
}
|
||||
|
||||
dw_new = MEM_callocN(sizeof(MDeformWeight) * (dvert->totweight + 1),
|
||||
"defvert_add_to group, new deformWeight");
|
||||
dw_new = static_cast<MDeformWeight *>(
|
||||
MEM_callocN(sizeof(MDeformWeight) * (dvert->totweight + 1), __func__));
|
||||
if (dvert->dw) {
|
||||
memcpy(dw_new, dvert->dw, sizeof(MDeformWeight) * dvert->totweight);
|
||||
MEM_freeN(dvert->dw);
|
||||
@@ -838,18 +829,19 @@ void BKE_defvert_remove_group(MDeformVert *dvert, MDeformWeight *dw)
|
||||
* this deform weight, and reshuffle the others.
|
||||
*/
|
||||
if (dvert->totweight) {
|
||||
BLI_assert(dvert->dw != NULL);
|
||||
BLI_assert(dvert->dw != nullptr);
|
||||
|
||||
if (i != dvert->totweight) {
|
||||
dvert->dw[i] = dvert->dw[dvert->totweight];
|
||||
}
|
||||
|
||||
dvert->dw = MEM_reallocN(dvert->dw, sizeof(MDeformWeight) * dvert->totweight);
|
||||
dvert->dw = static_cast<MDeformWeight *>(
|
||||
MEM_reallocN(dvert->dw, sizeof(MDeformWeight) * dvert->totweight));
|
||||
}
|
||||
else {
|
||||
/* If there are no other deform weights left then just remove this one. */
|
||||
MEM_freeN(dvert->dw);
|
||||
dvert->dw = NULL;
|
||||
dvert->dw = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -877,7 +869,7 @@ int BKE_defvert_find_shared(const MDeformVert *dvert_a, const MDeformVert *dvert
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool BKE_defvert_is_weight_zero(const struct MDeformVert *dvert, const int defgroup_tot)
|
||||
bool BKE_defvert_is_weight_zero(const MDeformVert *dvert, const int defgroup_tot)
|
||||
{
|
||||
MDeformWeight *dw = dvert->dw;
|
||||
for (int i = dvert->totweight; i != 0; i--, dw++) {
|
||||
@@ -891,14 +883,14 @@ bool BKE_defvert_is_weight_zero(const struct MDeformVert *dvert, const int defgr
|
||||
return true;
|
||||
}
|
||||
|
||||
float BKE_defvert_total_selected_weight(const struct MDeformVert *dv,
|
||||
float BKE_defvert_total_selected_weight(const MDeformVert *dv,
|
||||
int defbase_num,
|
||||
const bool *defbase_sel)
|
||||
{
|
||||
float total = 0.0f;
|
||||
const MDeformWeight *dw = dv->dw;
|
||||
|
||||
if (defbase_sel == NULL) {
|
||||
if (defbase_sel == nullptr) {
|
||||
return total;
|
||||
}
|
||||
|
||||
@@ -913,7 +905,7 @@ float BKE_defvert_total_selected_weight(const struct MDeformVert *dv,
|
||||
return total;
|
||||
}
|
||||
|
||||
float BKE_defvert_multipaint_collective_weight(const struct MDeformVert *dv,
|
||||
float BKE_defvert_multipaint_collective_weight(const MDeformVert *dv,
|
||||
const int defbase_num,
|
||||
const bool *defbase_sel,
|
||||
const int defbase_sel_num,
|
||||
@@ -959,7 +951,7 @@ float BKE_defvert_calc_lock_relative_weight(float weight,
|
||||
}
|
||||
|
||||
float BKE_defvert_lock_relative_weight(const float weight,
|
||||
const struct MDeformVert *dv,
|
||||
const MDeformVert *dv,
|
||||
const int defbase_num,
|
||||
const bool *defbase_locked,
|
||||
const bool *defbase_unlocked)
|
||||
@@ -991,7 +983,8 @@ void BKE_defvert_array_copy(MDeformVert *dst, const MDeformVert *src, int totver
|
||||
|
||||
for (int i = 0; i < totvert; i++) {
|
||||
if (src[i].dw) {
|
||||
dst[i].dw = MEM_mallocN(sizeof(MDeformWeight) * src[i].totweight, "copy_deformWeight");
|
||||
dst[i].dw = static_cast<MDeformWeight *>(
|
||||
MEM_mallocN(sizeof(MDeformWeight) * src[i].totweight, __func__));
|
||||
memcpy(dst[i].dw, src[i].dw, sizeof(MDeformWeight) * src[i].totweight);
|
||||
}
|
||||
}
|
||||
@@ -1059,7 +1052,8 @@ void BKE_defvert_extract_vgroup_to_edgeweights(const MDeformVert *dvert,
|
||||
{
|
||||
if (dvert && defgroup != -1) {
|
||||
int i = edges_num;
|
||||
float *tmp_weights = MEM_mallocN(sizeof(*tmp_weights) * (size_t)verts_num, __func__);
|
||||
float *tmp_weights = static_cast<float *>(
|
||||
MEM_mallocN(sizeof(*tmp_weights) * (size_t)verts_num, __func__));
|
||||
|
||||
BKE_defvert_extract_vgroup_to_vertweights(
|
||||
dvert, defgroup, verts_num, invert_vgroup, tmp_weights);
|
||||
@@ -1087,7 +1081,8 @@ void BKE_defvert_extract_vgroup_to_loopweights(const MDeformVert *dvert,
|
||||
{
|
||||
if (dvert && defgroup != -1) {
|
||||
int i = loops_num;
|
||||
float *tmp_weights = MEM_mallocN(sizeof(*tmp_weights) * (size_t)verts_num, __func__);
|
||||
float *tmp_weights = static_cast<float *>(
|
||||
MEM_mallocN(sizeof(*tmp_weights) * (size_t)verts_num, __func__));
|
||||
|
||||
BKE_defvert_extract_vgroup_to_vertweights(
|
||||
dvert, defgroup, verts_num, invert_vgroup, tmp_weights);
|
||||
@@ -1109,7 +1104,7 @@ void BKE_defvert_extract_vgroup_to_polyweights(const MDeformVert *dvert,
|
||||
const int defgroup,
|
||||
const int verts_num,
|
||||
const MLoop *loops,
|
||||
const int UNUSED(loops_num),
|
||||
const int /*loops_num*/,
|
||||
const MPoly *polys,
|
||||
const int polys_num,
|
||||
const bool invert_vgroup,
|
||||
@@ -1117,7 +1112,8 @@ void BKE_defvert_extract_vgroup_to_polyweights(const MDeformVert *dvert,
|
||||
{
|
||||
if (dvert && defgroup != -1) {
|
||||
int i = polys_num;
|
||||
float *tmp_weights = MEM_mallocN(sizeof(*tmp_weights) * (size_t)verts_num, __func__);
|
||||
float *tmp_weights = static_cast<float *>(
|
||||
MEM_mallocN(sizeof(*tmp_weights) * (size_t)verts_num, __func__));
|
||||
|
||||
BKE_defvert_extract_vgroup_to_vertweights(
|
||||
dvert, defgroup, verts_num, invert_vgroup, tmp_weights);
|
||||
@@ -1131,7 +1127,7 @@ void BKE_defvert_extract_vgroup_to_polyweights(const MDeformVert *dvert,
|
||||
for (; j--; ml++) {
|
||||
w += tmp_weights[ml->v];
|
||||
}
|
||||
r_weights[i] = w / (float)mp->totloop;
|
||||
r_weights[i] = w / float(mp->totloop);
|
||||
}
|
||||
|
||||
MEM_freeN(tmp_weights);
|
||||
@@ -1217,9 +1213,9 @@ static bool data_transfer_layersmapping_vgroups_multisrc_to_dst(ListBase *r_map,
|
||||
Object *ob_dst,
|
||||
const MDeformVert *data_src,
|
||||
MDeformVert *data_dst,
|
||||
const CustomData *UNUSED(cd_src),
|
||||
const CustomData * /*cd_src*/,
|
||||
CustomData *cd_dst,
|
||||
const bool UNUSED(use_dupref_dst),
|
||||
const bool /*use_dupref_dst*/,
|
||||
const int tolayers,
|
||||
const bool *use_layers_src,
|
||||
const int num_layers_src)
|
||||
@@ -1231,7 +1227,7 @@ static bool data_transfer_layersmapping_vgroups_multisrc_to_dst(ListBase *r_map,
|
||||
|
||||
const int tot_dst = BLI_listbase_count(dst_defbase);
|
||||
|
||||
const size_t elem_size = sizeof(*((MDeformVert *)NULL));
|
||||
const size_t elem_size = sizeof(*((MDeformVert *)nullptr));
|
||||
|
||||
switch (tolayers) {
|
||||
case DT_LAYERS_INDEX_DST:
|
||||
@@ -1258,15 +1254,15 @@ static bool data_transfer_layersmapping_vgroups_multisrc_to_dst(ListBase *r_map,
|
||||
}
|
||||
else if (use_delete && idx_dst > idx_src) {
|
||||
while (idx_dst-- > idx_src) {
|
||||
BKE_object_defgroup_remove(ob_dst, dst_defbase->last);
|
||||
BKE_object_defgroup_remove(ob_dst, static_cast<bDeformGroup *>(dst_defbase->last));
|
||||
}
|
||||
}
|
||||
if (r_map) {
|
||||
/* At this stage, we **need** a valid CD_MDEFORMVERT layer on dest!
|
||||
* Again, use_create is not relevant in this case */
|
||||
if (!data_dst) {
|
||||
data_dst = CustomData_add_layer(
|
||||
cd_dst, CD_MDEFORMVERT, CD_SET_DEFAULT, NULL, num_elem_dst);
|
||||
data_dst = static_cast<MDeformVert *>(
|
||||
CustomData_add_layer(cd_dst, CD_MDEFORMVERT, CD_SET_DEFAULT, nullptr, num_elem_dst));
|
||||
}
|
||||
|
||||
while (idx_src--) {
|
||||
@@ -1287,7 +1283,7 @@ static bool data_transfer_layersmapping_vgroups_multisrc_to_dst(ListBase *r_map,
|
||||
0,
|
||||
0,
|
||||
vgroups_datatransfer_interp,
|
||||
NULL);
|
||||
nullptr);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1296,7 +1292,7 @@ static bool data_transfer_layersmapping_vgroups_multisrc_to_dst(ListBase *r_map,
|
||||
|
||||
if (use_delete) {
|
||||
/* Remove all unused dst vgroups first, simpler in this case. */
|
||||
for (dg_dst = dst_defbase->first; dg_dst;) {
|
||||
for (dg_dst = static_cast<bDeformGroup *>(dst_defbase->first); dg_dst;) {
|
||||
bDeformGroup *dg_dst_next = dg_dst->next;
|
||||
|
||||
if (BKE_object_defgroup_name_index(ob_src, dg_dst->name) == -1) {
|
||||
@@ -1306,7 +1302,8 @@ static bool data_transfer_layersmapping_vgroups_multisrc_to_dst(ListBase *r_map,
|
||||
}
|
||||
}
|
||||
|
||||
for (idx_src = 0, dg_src = src_list->first; idx_src < num_layers_src;
|
||||
for (idx_src = 0, dg_src = static_cast<bDeformGroup *>(src_list->first);
|
||||
idx_src < num_layers_src;
|
||||
idx_src++, dg_src = dg_src->next) {
|
||||
if (!use_layers_src[idx_src]) {
|
||||
continue;
|
||||
@@ -1326,8 +1323,8 @@ static bool data_transfer_layersmapping_vgroups_multisrc_to_dst(ListBase *r_map,
|
||||
/* At this stage, we **need** a valid CD_MDEFORMVERT layer on dest!
|
||||
* use_create is not relevant in this case */
|
||||
if (!data_dst) {
|
||||
data_dst = CustomData_add_layer(
|
||||
cd_dst, CD_MDEFORMVERT, CD_SET_DEFAULT, NULL, num_elem_dst);
|
||||
data_dst = static_cast<MDeformVert *>(CustomData_add_layer(
|
||||
cd_dst, CD_MDEFORMVERT, CD_SET_DEFAULT, nullptr, num_elem_dst));
|
||||
}
|
||||
|
||||
data_transfer_layersmapping_add_item(r_map,
|
||||
@@ -1344,7 +1341,7 @@ static bool data_transfer_layersmapping_vgroups_multisrc_to_dst(ListBase *r_map,
|
||||
0,
|
||||
0,
|
||||
vgroups_datatransfer_interp,
|
||||
NULL);
|
||||
nullptr);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1373,13 +1370,13 @@ bool data_transfer_layersmapping_vgroups(ListBase *r_map,
|
||||
{
|
||||
int idx_src, idx_dst;
|
||||
|
||||
const size_t elem_size = sizeof(*((MDeformVert *)NULL));
|
||||
const size_t elem_size = sizeof(*((MDeformVert *)nullptr));
|
||||
|
||||
/* NOTE:
|
||||
* VGroups are a bit hairy, since their layout is defined on object level (ob->defbase),
|
||||
* while their actual data is a (mesh) CD layer.
|
||||
* This implies we may have to handle data layout itself while having NULL data itself,
|
||||
* and even have to support NULL data_src in transfer data code
|
||||
* This implies we may have to handle data layout itself while having nullptr data itself,
|
||||
* and even have to support nullptr data_src in transfer data code
|
||||
* (we always create a data_dst, though).
|
||||
*
|
||||
* NOTE: Above comment is outdated, but this function was written when that was true.
|
||||
@@ -1393,12 +1390,15 @@ bool data_transfer_layersmapping_vgroups(ListBase *r_map,
|
||||
return true;
|
||||
}
|
||||
|
||||
const MDeformVert *data_src = CustomData_get_layer(cd_src, CD_MDEFORMVERT);
|
||||
const MDeformVert *data_src = static_cast<const MDeformVert *>(
|
||||
CustomData_get_layer(cd_src, CD_MDEFORMVERT));
|
||||
|
||||
MDeformVert *data_dst = CustomData_get_layer_for_write(cd_dst, CD_MDEFORMVERT, num_elem_dst);
|
||||
MDeformVert *data_dst = static_cast<MDeformVert *>(
|
||||
CustomData_get_layer_for_write(cd_dst, CD_MDEFORMVERT, num_elem_dst));
|
||||
if (data_dst && use_dupref_dst && r_map) {
|
||||
/* If dest is a derivedmesh, we do not want to overwrite cdlayers of org mesh! */
|
||||
data_dst = CustomData_get_layer_for_write(cd_dst, CD_MDEFORMVERT, num_elem_dst);
|
||||
data_dst = static_cast<MDeformVert *>(
|
||||
CustomData_get_layer_for_write(cd_dst, CD_MDEFORMVERT, num_elem_dst));
|
||||
}
|
||||
|
||||
if (fromlayers == DT_LAYERS_ACTIVE_SRC || fromlayers >= 0) {
|
||||
@@ -1430,7 +1430,7 @@ bool data_transfer_layersmapping_vgroups(ListBase *r_map,
|
||||
if (!use_create) {
|
||||
return true;
|
||||
}
|
||||
dg_src = BLI_findlink(src_defbase, idx_src);
|
||||
dg_src = static_cast<bDeformGroup *>(BLI_findlink(src_defbase, idx_src));
|
||||
BKE_object_defgroup_add_name(ob_dst, dg_src->name);
|
||||
idx_dst = BKE_object_defgroup_active_index_get(ob_dst) - 1;
|
||||
}
|
||||
@@ -1449,7 +1449,7 @@ bool data_transfer_layersmapping_vgroups(ListBase *r_map,
|
||||
}
|
||||
}
|
||||
else if (tolayers == DT_LAYERS_NAME_DST) {
|
||||
bDeformGroup *dg_src = BLI_findlink(src_defbase, idx_src);
|
||||
bDeformGroup *dg_src = static_cast<bDeformGroup *>(BLI_findlink(src_defbase, idx_src));
|
||||
if ((idx_dst = BKE_object_defgroup_name_index(ob_dst, dg_src->name)) == -1) {
|
||||
if (!use_create) {
|
||||
return true;
|
||||
@@ -1466,8 +1466,8 @@ bool data_transfer_layersmapping_vgroups(ListBase *r_map,
|
||||
/* At this stage, we **need** a valid CD_MDEFORMVERT layer on dest!
|
||||
* use_create is not relevant in this case */
|
||||
if (!data_dst) {
|
||||
data_dst = CustomData_add_layer(
|
||||
cd_dst, CD_MDEFORMVERT, CD_SET_DEFAULT, NULL, num_elem_dst);
|
||||
data_dst = static_cast<MDeformVert *>(
|
||||
CustomData_add_layer(cd_dst, CD_MDEFORMVERT, CD_SET_DEFAULT, nullptr, num_elem_dst));
|
||||
}
|
||||
|
||||
data_transfer_layersmapping_add_item(r_map,
|
||||
@@ -1484,12 +1484,12 @@ bool data_transfer_layersmapping_vgroups(ListBase *r_map,
|
||||
0,
|
||||
0,
|
||||
vgroups_datatransfer_interp,
|
||||
NULL);
|
||||
nullptr);
|
||||
}
|
||||
}
|
||||
else {
|
||||
int num_src, num_sel_unused;
|
||||
bool *use_layers_src = NULL;
|
||||
bool *use_layers_src = nullptr;
|
||||
bool ret = false;
|
||||
|
||||
switch (fromlayers) {
|
||||
@@ -1588,7 +1588,7 @@ void BKE_defbase_blend_write(BlendWriter *writer, const ListBase *defbase)
|
||||
|
||||
void BKE_defvert_blend_write(BlendWriter *writer, int count, const MDeformVert *dvlist)
|
||||
{
|
||||
if (dvlist == NULL) {
|
||||
if (dvlist == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1605,22 +1605,23 @@ void BKE_defvert_blend_write(BlendWriter *writer, int count, const MDeformVert *
|
||||
|
||||
void BKE_defvert_blend_read(BlendDataReader *reader, int count, MDeformVert *mdverts)
|
||||
{
|
||||
if (mdverts == NULL) {
|
||||
if (mdverts == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = count; i > 0; i--, mdverts++) {
|
||||
/* Convert to vertex group allocation system. */
|
||||
MDeformWeight *dw;
|
||||
if (mdverts->dw && (dw = BLO_read_get_new_data_address(reader, mdverts->dw))) {
|
||||
if (mdverts->dw &&
|
||||
(dw = static_cast<MDeformWeight *>(BLO_read_get_new_data_address(reader, mdverts->dw)))) {
|
||||
const size_t dw_len = sizeof(MDeformWeight) * mdverts->totweight;
|
||||
void *dw_tmp = MEM_mallocN(dw_len, __func__);
|
||||
memcpy(dw_tmp, dw, dw_len);
|
||||
mdverts->dw = dw_tmp;
|
||||
mdverts->dw = static_cast<MDeformWeight *>(dw_tmp);
|
||||
MEM_freeN(dw);
|
||||
}
|
||||
else {
|
||||
mdverts->dw = NULL;
|
||||
mdverts->dw = nullptr;
|
||||
mdverts->totweight = 0;
|
||||
}
|
||||
}
|
||||
@@ -34,8 +34,8 @@ set(INC_SYS
|
||||
|
||||
set(SRC
|
||||
object_add.cc
|
||||
object_bake.c
|
||||
object_bake_api.c
|
||||
object_bake.cc
|
||||
object_bake_api.cc
|
||||
object_collection.c
|
||||
object_constraint.c
|
||||
object_data_transfer.c
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* \ingroup edobj
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
@@ -56,14 +56,15 @@
|
||||
|
||||
static Image *bake_object_image_get(Object *ob, int mat_nr)
|
||||
{
|
||||
Image *image = NULL;
|
||||
ED_object_get_active_image(ob, mat_nr + 1, &image, NULL, NULL, NULL);
|
||||
Image *image = nullptr;
|
||||
ED_object_get_active_image(ob, mat_nr + 1, &image, nullptr, nullptr, nullptr);
|
||||
return image;
|
||||
}
|
||||
|
||||
static Image **bake_object_image_get_array(Object *ob)
|
||||
{
|
||||
Image **image_array = MEM_mallocN(sizeof(Material *) * ob->totcol, __func__);
|
||||
Image **image_array = static_cast<Image **>(
|
||||
MEM_mallocN(sizeof(Material *) * ob->totcol, __func__));
|
||||
for (int i = 0; i < ob->totcol; i++) {
|
||||
image_array[i] = bake_object_image_get(ob, i);
|
||||
}
|
||||
@@ -74,8 +75,8 @@ static Image **bake_object_image_get_array(Object *ob)
|
||||
|
||||
/* holder of per-object data needed for bake job
|
||||
* needed to make job totally thread-safe */
|
||||
typedef struct MultiresBakerJobData {
|
||||
struct MultiresBakerJobData *next, *prev;
|
||||
struct MultiresBakerJobData {
|
||||
MultiresBakerJobData *next, *prev;
|
||||
/* material aligned image array (for per-face bake image) */
|
||||
struct {
|
||||
Image **array;
|
||||
@@ -84,10 +85,10 @@ typedef struct MultiresBakerJobData {
|
||||
DerivedMesh *lores_dm, *hires_dm;
|
||||
int lvl, tot_lvl;
|
||||
ListBase images;
|
||||
} MultiresBakerJobData;
|
||||
};
|
||||
|
||||
/* data passing to multires-baker job */
|
||||
typedef struct {
|
||||
struct MultiresBakeJob {
|
||||
Scene *scene;
|
||||
ListBase data;
|
||||
/** Clear the images before baking */
|
||||
@@ -108,7 +109,7 @@ typedef struct {
|
||||
int threads;
|
||||
/** User scale used to scale displacement when baking derivative map. */
|
||||
float user_scale;
|
||||
} MultiresBakeJob;
|
||||
};
|
||||
|
||||
static bool multiresbake_check(bContext *C, wmOperator *op)
|
||||
{
|
||||
@@ -178,7 +179,7 @@ static bool multiresbake_check(bContext *C, wmOperator *op)
|
||||
BKE_imageuser_default(&iuser);
|
||||
iuser.tile = tile->tile_number;
|
||||
|
||||
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
|
||||
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, nullptr);
|
||||
|
||||
if (!ibuf) {
|
||||
BKE_report(
|
||||
@@ -187,7 +188,7 @@ static bool multiresbake_check(bContext *C, wmOperator *op)
|
||||
ok = false;
|
||||
}
|
||||
else {
|
||||
if (ibuf->rect == NULL && ibuf->rect_float == NULL) {
|
||||
if (ibuf->rect == nullptr && ibuf->rect_float == nullptr) {
|
||||
ok = false;
|
||||
}
|
||||
|
||||
@@ -200,7 +201,7 @@ static bool multiresbake_check(bContext *C, wmOperator *op)
|
||||
}
|
||||
}
|
||||
|
||||
BKE_image_release_ibuf(ima, ibuf, NULL);
|
||||
BKE_image_release_ibuf(ima, ibuf, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -234,7 +235,7 @@ static DerivedMesh *multiresbake_create_loresdm(Scene *scene, Object *ob, int *l
|
||||
DM_set_only_copy(cddm, &CD_MASK_BAREMESH);
|
||||
tmp_mmd.lvl = mmd->lvl;
|
||||
tmp_mmd.sculptlvl = mmd->lvl;
|
||||
dm = multires_make_derived_from_derived(cddm, &tmp_mmd, scene, ob, 0);
|
||||
dm = multires_make_derived_from_derived(cddm, &tmp_mmd, scene, ob, MultiresFlags(0));
|
||||
|
||||
cddm->release(cddm);
|
||||
|
||||
@@ -261,7 +262,7 @@ static DerivedMesh *multiresbake_create_hiresdm(Scene *scene, Object *ob, int *l
|
||||
|
||||
tmp_mmd.lvl = mmd->totlvl;
|
||||
tmp_mmd.sculptlvl = mmd->totlvl;
|
||||
dm = multires_make_derived_from_derived(cddm, &tmp_mmd, scene, ob, 0);
|
||||
dm = multires_make_derived_from_derived(cddm, &tmp_mmd, scene, ob, MultiresFlags(0));
|
||||
cddm->release(cddm);
|
||||
|
||||
return dm;
|
||||
@@ -287,7 +288,7 @@ static void clear_single_image(Image *image, ClearFlag flag)
|
||||
BKE_imageuser_default(&iuser);
|
||||
iuser.tile = tile->tile_number;
|
||||
|
||||
ImBuf *ibuf = BKE_image_acquire_ibuf(image, &iuser, NULL);
|
||||
ImBuf *ibuf = BKE_image_acquire_ibuf(image, &iuser, nullptr);
|
||||
|
||||
if (flag == CLEAR_TANGENT_NORMAL) {
|
||||
IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? nor_alpha : nor_solid);
|
||||
@@ -301,7 +302,7 @@ static void clear_single_image(Image *image, ClearFlag flag)
|
||||
|
||||
image->id.tag |= LIB_TAG_DOIT;
|
||||
|
||||
BKE_image_release_ibuf(image, ibuf, NULL);
|
||||
BKE_image_release_ibuf(image, ibuf, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -342,7 +343,7 @@ static int multiresbake_image_exec_locked(bContext *C, wmOperator *op)
|
||||
|
||||
if (scene->r.bake_flag & R_BAKE_CLEAR) { /* clear images */
|
||||
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) {
|
||||
ClearFlag clear_flag = 0;
|
||||
ClearFlag clear_flag = ClearFlag(0);
|
||||
|
||||
ob = base->object;
|
||||
// me = (Mesh *)ob->data;
|
||||
@@ -364,7 +365,7 @@ static int multiresbake_image_exec_locked(bContext *C, wmOperator *op)
|
||||
}
|
||||
|
||||
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) {
|
||||
MultiresBakeRender bkr = {NULL};
|
||||
MultiresBakeRender bkr = {nullptr};
|
||||
|
||||
ob = base->object;
|
||||
|
||||
@@ -439,14 +440,13 @@ static void init_multiresbake_job(bContext *C, MultiresBakeJob *bkj)
|
||||
// bkj->reports = op->reports;
|
||||
|
||||
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) {
|
||||
MultiresBakerJobData *data;
|
||||
int lvl;
|
||||
|
||||
ob = base->object;
|
||||
|
||||
multires_flush_sculpt_updates(ob);
|
||||
|
||||
data = MEM_callocN(sizeof(MultiresBakerJobData), "multiresBaker derivedMesh_data");
|
||||
MultiresBakerJobData *data = MEM_cnew<MultiresBakerJobData>(__func__);
|
||||
|
||||
data->ob_image.array = bake_object_image_get_array(ob);
|
||||
data->ob_image.len = ob->totcol;
|
||||
@@ -464,14 +464,14 @@ static void init_multiresbake_job(bContext *C, MultiresBakeJob *bkj)
|
||||
static void multiresbake_startjob(void *bkv, bool *stop, bool *do_update, float *progress)
|
||||
{
|
||||
MultiresBakerJobData *data;
|
||||
MultiresBakeJob *bkj = bkv;
|
||||
MultiresBakeJob *bkj = static_cast<MultiresBakeJob *>(bkv);
|
||||
int baked_objects = 0, tot_obj;
|
||||
|
||||
tot_obj = BLI_listbase_count(&bkj->data);
|
||||
|
||||
if (bkj->bake_clear) { /* clear images */
|
||||
for (data = bkj->data.first; data; data = data->next) {
|
||||
ClearFlag clear_flag = 0;
|
||||
for (data = static_cast<MultiresBakerJobData *>(bkj->data.first); data; data = data->next) {
|
||||
ClearFlag clear_flag = ClearFlag(0);
|
||||
|
||||
if (bkj->mode == RE_BAKE_NORMALS) {
|
||||
clear_flag = CLEAR_TANGENT_NORMAL;
|
||||
@@ -484,8 +484,8 @@ static void multiresbake_startjob(void *bkv, bool *stop, bool *do_update, float
|
||||
}
|
||||
}
|
||||
|
||||
for (data = bkj->data.first; data; data = data->next) {
|
||||
MultiresBakeRender bkr = {NULL};
|
||||
for (data = static_cast<MultiresBakerJobData *>(bkj->data.first); data; data = data->next) {
|
||||
MultiresBakeRender bkr = {nullptr};
|
||||
|
||||
/* copy data stored in job descriptor */
|
||||
bkr.scene = bkj->scene;
|
||||
@@ -526,18 +526,18 @@ static void multiresbake_startjob(void *bkv, bool *stop, bool *do_update, float
|
||||
|
||||
static void multiresbake_freejob(void *bkv)
|
||||
{
|
||||
MultiresBakeJob *bkj = bkv;
|
||||
MultiresBakeJob *bkj = static_cast<MultiresBakeJob *>(bkv);
|
||||
MultiresBakerJobData *data, *next;
|
||||
LinkData *link;
|
||||
|
||||
data = bkj->data.first;
|
||||
data = static_cast<MultiresBakerJobData *>(bkj->data.first);
|
||||
while (data) {
|
||||
next = data->next;
|
||||
data->lores_dm->release(data->lores_dm);
|
||||
data->hires_dm->release(data->hires_dm);
|
||||
|
||||
/* delete here, since this delete will be called from main thread */
|
||||
for (link = data->images.first; link; link = link->next) {
|
||||
for (link = static_cast<LinkData *>(data->images.first); link; link = link->next) {
|
||||
Image *ima = (Image *)link->data;
|
||||
BKE_image_partial_update_mark_full_update(ima);
|
||||
}
|
||||
@@ -556,14 +556,12 @@ static void multiresbake_freejob(void *bkv)
|
||||
static int multiresbake_image_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
MultiresBakeJob *bkr;
|
||||
wmJob *wm_job;
|
||||
|
||||
if (!multiresbake_check(C, op)) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
bkr = MEM_callocN(sizeof(MultiresBakeJob), "MultiresBakeJob data");
|
||||
MultiresBakeJob *bkr = MEM_cnew<MultiresBakeJob>(__func__);
|
||||
init_multiresbake_job(C, bkr);
|
||||
|
||||
if (!bkr->data.first) {
|
||||
@@ -572,15 +570,15 @@ static int multiresbake_image_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
|
||||
/* setup job */
|
||||
wm_job = WM_jobs_get(CTX_wm_manager(C),
|
||||
CTX_wm_window(C),
|
||||
scene,
|
||||
"Multires Bake",
|
||||
WM_JOB_EXCL_RENDER | WM_JOB_PRIORITY | WM_JOB_PROGRESS,
|
||||
WM_JOB_TYPE_OBJECT_BAKE_TEXTURE);
|
||||
wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C),
|
||||
CTX_wm_window(C),
|
||||
scene,
|
||||
"Multires Bake",
|
||||
WM_JOB_EXCL_RENDER | WM_JOB_PRIORITY | WM_JOB_PROGRESS,
|
||||
WM_JOB_TYPE_OBJECT_BAKE_TEXTURE);
|
||||
WM_jobs_customdata_set(wm_job, bkr, multiresbake_freejob);
|
||||
WM_jobs_timer(wm_job, 0.5, NC_IMAGE, 0); /* TODO: only draw bake image, can we enforce this. */
|
||||
WM_jobs_callbacks(wm_job, multiresbake_startjob, NULL, NULL, NULL);
|
||||
WM_jobs_callbacks(wm_job, multiresbake_startjob, nullptr, nullptr, nullptr);
|
||||
|
||||
G.is_break = false;
|
||||
|
||||
@@ -596,7 +594,7 @@ static int multiresbake_image_exec(bContext *C, wmOperator *op)
|
||||
/* ****************** render BAKING ********************** */
|
||||
|
||||
/** Catch escape key to cancel. */
|
||||
static int objects_bake_render_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
|
||||
static int objects_bake_render_modal(bContext *C, wmOperator * /*op*/, const wmEvent *event)
|
||||
{
|
||||
/* no running blender, remove handler and pass through */
|
||||
if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C), WM_JOB_TYPE_OBJECT_BAKE_TEXTURE)) {
|
||||
@@ -620,7 +618,7 @@ static bool is_multires_bake(Scene *scene)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int objects_bake_render_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(_event))
|
||||
static int objects_bake_render_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
|
||||
{
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
int result = OPERATOR_CANCELLED;
|
||||
@@ -65,7 +65,7 @@
|
||||
/* prototypes */
|
||||
static void bake_set_props(wmOperator *op, Scene *scene);
|
||||
|
||||
typedef struct BakeAPIRender {
|
||||
struct BakeAPIRender {
|
||||
/* Data to work on. */
|
||||
Main *main;
|
||||
Scene *scene;
|
||||
@@ -113,13 +113,13 @@ typedef struct BakeAPIRender {
|
||||
ReportList *reports;
|
||||
int result;
|
||||
ScrArea *area;
|
||||
} BakeAPIRender;
|
||||
};
|
||||
|
||||
/* callbacks */
|
||||
|
||||
static void bake_progress_update(void *bjv, float progress)
|
||||
{
|
||||
BakeAPIRender *bj = bjv;
|
||||
BakeAPIRender *bj = static_cast<BakeAPIRender *>(bjv);
|
||||
|
||||
if (bj->progress && *bj->progress != progress) {
|
||||
*bj->progress = progress;
|
||||
@@ -130,7 +130,7 @@ static void bake_progress_update(void *bjv, float progress)
|
||||
}
|
||||
|
||||
/** Catch escape key to cancel. */
|
||||
static int bake_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
|
||||
static int bake_modal(bContext *C, wmOperator * /*op*/, const wmEvent *event)
|
||||
{
|
||||
/* no running blender, remove handler and pass through */
|
||||
if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C), WM_JOB_TYPE_OBJECT_BAKE)) {
|
||||
@@ -151,7 +151,7 @@ static int bake_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
|
||||
* for exec() when there is no render job
|
||||
* NOTE: this won't check for the escape key being pressed, but doing so isn't thread-safe.
|
||||
*/
|
||||
static bool bake_break(void *UNUSED(rjv))
|
||||
static bool bake_break(void * /*rjv*/)
|
||||
{
|
||||
if (G.is_break) {
|
||||
return true;
|
||||
@@ -162,7 +162,7 @@ static bool bake_break(void *UNUSED(rjv))
|
||||
static void bake_update_image(ScrArea *area, Image *image)
|
||||
{
|
||||
if (area && area->spacetype == SPACE_IMAGE) { /* in case the user changed while baking */
|
||||
SpaceImage *sima = area->spacedata.first;
|
||||
SpaceImage *sima = static_cast<SpaceImage *>(area->spacedata.first);
|
||||
if (sima) {
|
||||
sima->image = image;
|
||||
}
|
||||
@@ -186,7 +186,7 @@ static bool write_internal_bake_pixels(Image *image,
|
||||
ImBuf *ibuf;
|
||||
void *lock;
|
||||
bool is_float;
|
||||
char *mask_buffer = NULL;
|
||||
char *mask_buffer = nullptr;
|
||||
const size_t pixels_num = (size_t)width * (size_t)height;
|
||||
|
||||
ImageUser iuser;
|
||||
@@ -199,11 +199,11 @@ static bool write_internal_bake_pixels(Image *image,
|
||||
}
|
||||
|
||||
if (margin > 0 || !is_clear) {
|
||||
mask_buffer = MEM_callocN(sizeof(char) * pixels_num, "Bake Mask");
|
||||
mask_buffer = static_cast<char *>(MEM_callocN(sizeof(char) * pixels_num, "Bake Mask"));
|
||||
RE_bake_mask_fill(pixel_array, pixels_num, mask_buffer);
|
||||
}
|
||||
|
||||
is_float = (ibuf->rect_float != NULL);
|
||||
is_float = (ibuf->rect_float != nullptr);
|
||||
|
||||
/* colormanagement conversions */
|
||||
if (!is_noncolor) {
|
||||
@@ -296,7 +296,7 @@ static bool write_internal_bake_pixels(Image *image,
|
||||
imb_freemipmapImBuf(ibuf);
|
||||
}
|
||||
|
||||
BKE_image_release_ibuf(image, ibuf, NULL);
|
||||
BKE_image_release_ibuf(image, ibuf, nullptr);
|
||||
|
||||
if (mask_buffer) {
|
||||
MEM_freeN(mask_buffer);
|
||||
@@ -332,7 +332,7 @@ static bool write_external_bake_pixels(const char *filepath,
|
||||
char const *uv_layer,
|
||||
const float uv_offset[2])
|
||||
{
|
||||
ImBuf *ibuf = NULL;
|
||||
ImBuf *ibuf = nullptr;
|
||||
bool ok = false;
|
||||
bool is_float;
|
||||
|
||||
@@ -382,10 +382,10 @@ static bool write_external_bake_pixels(const char *filepath,
|
||||
|
||||
/* margins */
|
||||
if (margin > 0) {
|
||||
char *mask_buffer = NULL;
|
||||
char *mask_buffer = nullptr;
|
||||
const size_t pixels_num = (size_t)width * (size_t)height;
|
||||
|
||||
mask_buffer = MEM_callocN(sizeof(char) * pixels_num, "Bake Mask");
|
||||
mask_buffer = static_cast<char *>(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, uv_offset);
|
||||
|
||||
@@ -429,7 +429,7 @@ static bool bake_object_check(const Scene *scene,
|
||||
BKE_view_layer_synced_ensure(scene, view_layer);
|
||||
Base *base = BKE_view_layer_base_find(view_layer, ob);
|
||||
|
||||
if (base == NULL) {
|
||||
if (base == nullptr) {
|
||||
BKE_reportf(reports, RPT_ERROR, "Object \"%s\" is not in view layer", ob->id.name + 2);
|
||||
return false;
|
||||
}
|
||||
@@ -468,11 +468,11 @@ static bool bake_object_check(const Scene *scene,
|
||||
}
|
||||
|
||||
for (int i = 0; i < ob->totcol; i++) {
|
||||
const bNodeTree *ntree = NULL;
|
||||
const bNode *node = NULL;
|
||||
const bNodeTree *ntree = nullptr;
|
||||
const bNode *node = nullptr;
|
||||
const int mat_nr = i + 1;
|
||||
Image *image;
|
||||
ED_object_get_active_image(ob, mat_nr, &image, NULL, &node, &ntree);
|
||||
ED_object_get_active_image(ob, mat_nr, &image, nullptr, &node, &ntree);
|
||||
|
||||
if (image) {
|
||||
|
||||
@@ -514,7 +514,7 @@ static bool bake_object_check(const Scene *scene,
|
||||
}
|
||||
else {
|
||||
Material *mat = BKE_object_material_get(ob, mat_nr);
|
||||
if (mat != NULL) {
|
||||
if (mat != nullptr) {
|
||||
BKE_reportf(reports,
|
||||
RPT_INFO,
|
||||
"No active image found in material \"%s\" (%d) for object \"%s\"",
|
||||
@@ -614,7 +614,8 @@ static bool bake_objects_check(Main *bmain,
|
||||
return false;
|
||||
}
|
||||
|
||||
for (link = selected_objects->first; link; link = link->next) {
|
||||
for (link = static_cast<CollectionPointerLink *>(selected_objects->first); link;
|
||||
link = link->next) {
|
||||
Object *ob_iter = (Object *)link->ptr.data;
|
||||
|
||||
if (ob_iter == ob) {
|
||||
@@ -643,8 +644,10 @@ static bool bake_objects_check(Main *bmain,
|
||||
return false;
|
||||
}
|
||||
|
||||
for (link = selected_objects->first; link; link = link->next) {
|
||||
if (!bake_object_check(scene, view_layer, link->ptr.data, target, reports)) {
|
||||
for (link = static_cast<CollectionPointerLink *>(selected_objects->first); link;
|
||||
link = link->next) {
|
||||
if (!bake_object_check(
|
||||
scene, view_layer, static_cast<Object *>(link->ptr.data), target, reports)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -655,8 +658,7 @@ static bool bake_objects_check(Main *bmain,
|
||||
/* it needs to be called after bake_objects_check since the image tagging happens there */
|
||||
static void bake_targets_clear(Main *bmain, const bool is_tangent)
|
||||
{
|
||||
Image *image;
|
||||
for (image = bmain->images.first; image; image = image->id.next) {
|
||||
LISTBASE_FOREACH (Image *, image, &bmain->images) {
|
||||
if ((image->id.tag & LIB_TAG_DOIT) != 0) {
|
||||
RE_bake_ibuf_clear(image, is_tangent);
|
||||
}
|
||||
@@ -704,17 +706,17 @@ static bool bake_targets_init_image_textures(const BakeAPIRender *bkr,
|
||||
|
||||
/* Allocate material mapping. */
|
||||
targets->materials_num = materials_num;
|
||||
targets->material_to_image = MEM_callocN(sizeof(Image *) * targets->materials_num,
|
||||
"BakeTargets.material_to_image");
|
||||
targets->material_to_image = static_cast<Image **>(
|
||||
MEM_callocN(sizeof(Image *) * targets->materials_num, __func__));
|
||||
|
||||
/* 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;
|
||||
targets->images = nullptr;
|
||||
|
||||
for (int i = 0; i < materials_num; i++) {
|
||||
Image *image;
|
||||
ED_object_get_active_image(ob, i + 1, &image, NULL, NULL, NULL);
|
||||
ED_object_get_active_image(ob, i + 1, &image, nullptr, nullptr, nullptr);
|
||||
|
||||
targets->material_to_image[i] = image;
|
||||
|
||||
@@ -723,8 +725,8 @@ static bool bake_targets_init_image_textures(const BakeAPIRender *bkr,
|
||||
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 = static_cast<BakeImage *>(
|
||||
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++;
|
||||
@@ -878,7 +880,7 @@ static bool bake_targets_output_external(const BakeAPIRender *bkr,
|
||||
bake->im_format.imtype,
|
||||
true,
|
||||
false,
|
||||
NULL);
|
||||
nullptr);
|
||||
|
||||
if (bkr->is_automatic_name) {
|
||||
BLI_path_suffix(name, FILE_MAX, ob->id.name + 2, "_");
|
||||
@@ -949,7 +951,7 @@ static bool bake_targets_init_vertex_colors(Main *bmain,
|
||||
return false;
|
||||
}
|
||||
|
||||
Mesh *me = ob->data;
|
||||
Mesh *me = static_cast<Mesh *>(ob->data);
|
||||
if (!BKE_id_attributes_color_find(&me->id, me->active_color_attribute)) {
|
||||
BKE_report(reports, RPT_ERROR, "No active color attribute to bake to");
|
||||
return false;
|
||||
@@ -958,18 +960,18 @@ static bool bake_targets_init_vertex_colors(Main *bmain,
|
||||
/* Ensure mesh and editmesh topology are in sync. */
|
||||
ED_object_editmode_load(bmain, ob);
|
||||
|
||||
targets->images = MEM_callocN(sizeof(BakeImage), "BakeTargets.images");
|
||||
targets->images = MEM_cnew<BakeImage>(__func__);
|
||||
targets->images_num = 1;
|
||||
|
||||
targets->material_to_image = MEM_callocN(sizeof(int) * ob->totcol,
|
||||
"BakeTargets.material_to_image");
|
||||
targets->material_to_image = static_cast<Image **>(
|
||||
MEM_callocN(sizeof(Image *) * ob->totcol, __func__));
|
||||
targets->materials_num = ob->totcol;
|
||||
|
||||
BakeImage *bk_image = &targets->images[0];
|
||||
bk_image->width = me->totloop;
|
||||
bk_image->height = 1;
|
||||
bk_image->offset = 0;
|
||||
bk_image->image = NULL;
|
||||
bk_image->image = nullptr;
|
||||
|
||||
targets->pixels_num = bk_image->width * bk_image->height;
|
||||
|
||||
@@ -1009,7 +1011,7 @@ static void bake_targets_populate_pixels_color_attributes(BakeTargets *targets,
|
||||
Mesh *me_eval,
|
||||
BakePixel *pixel_array)
|
||||
{
|
||||
Mesh *me = ob->data;
|
||||
Mesh *me = static_cast<Mesh *>(ob->data);
|
||||
const int pixels_num = targets->pixels_num;
|
||||
|
||||
/* Initialize blank pixels. */
|
||||
@@ -1029,7 +1031,7 @@ static void bake_targets_populate_pixels_color_attributes(BakeTargets *targets,
|
||||
|
||||
/* Populate through adjacent triangles, first triangle wins. */
|
||||
const int tottri = poly_to_tri_count(me_eval->totpoly, me_eval->totloop);
|
||||
MLoopTri *looptri = MEM_mallocN(sizeof(*looptri) * tottri, __func__);
|
||||
MLoopTri *looptri = static_cast<MLoopTri *>(MEM_mallocN(sizeof(*looptri) * tottri, __func__));
|
||||
|
||||
const MLoop *loops = BKE_mesh_loops(me_eval);
|
||||
BKE_mesh_recalc_looptri(loops,
|
||||
@@ -1040,8 +1042,10 @@ static void bake_targets_populate_pixels_color_attributes(BakeTargets *targets,
|
||||
looptri);
|
||||
|
||||
/* For mapping back to original mesh in case there are modifiers. */
|
||||
const int *vert_origindex = CustomData_get_layer(&me_eval->vdata, CD_ORIGINDEX);
|
||||
const int *poly_origindex = CustomData_get_layer(&me_eval->pdata, CD_ORIGINDEX);
|
||||
const int *vert_origindex = static_cast<const int *>(
|
||||
CustomData_get_layer(&me_eval->vdata, CD_ORIGINDEX));
|
||||
const int *poly_origindex = static_cast<const int *>(
|
||||
CustomData_get_layer(&me_eval->pdata, CD_ORIGINDEX));
|
||||
const MPoly *orig_polys = BKE_mesh_polys(me);
|
||||
const MLoop *orig_loops = BKE_mesh_loops(me);
|
||||
|
||||
@@ -1053,7 +1057,7 @@ static void bake_targets_populate_pixels_color_attributes(BakeTargets *targets,
|
||||
uint v = loops[l].v;
|
||||
|
||||
/* Map back to original loop if there are modifiers. */
|
||||
if (vert_origindex != NULL && poly_origindex != NULL) {
|
||||
if (vert_origindex != nullptr && poly_origindex != nullptr) {
|
||||
l = find_original_loop(
|
||||
orig_polys, orig_loops, vert_origindex, poly_origindex, lt->poly, v);
|
||||
if (l == ORIGINDEX_NONE || l >= me->totloop) {
|
||||
@@ -1129,11 +1133,11 @@ static void convert_float_color_to_byte_color(const MPropCol *float_colors,
|
||||
|
||||
static bool bake_targets_output_vertex_colors(BakeTargets *targets, Object *ob)
|
||||
{
|
||||
Mesh *me = ob->data;
|
||||
Mesh *me = static_cast<Mesh *>(ob->data);
|
||||
BMEditMesh *em = me->edit_mesh;
|
||||
CustomDataLayer *active_color_layer = BKE_id_attributes_color_find(&me->id,
|
||||
me->active_color_attribute);
|
||||
BLI_assert(active_color_layer != NULL);
|
||||
BLI_assert(active_color_layer != nullptr);
|
||||
const eAttrDomain domain = BKE_id_attribute_domain(&me->id, active_color_layer);
|
||||
|
||||
const int channels_num = targets->channels_num;
|
||||
@@ -1144,10 +1148,12 @@ static bool bake_targets_output_vertex_colors(BakeTargets *targets, Object *ob)
|
||||
const int totvert = me->totvert;
|
||||
const int totloop = me->totloop;
|
||||
|
||||
MPropCol *mcol = MEM_malloc_arrayN(totvert, sizeof(MPropCol), __func__);
|
||||
MPropCol *mcol = static_cast<MPropCol *>(
|
||||
MEM_malloc_arrayN(totvert, sizeof(MPropCol), __func__));
|
||||
|
||||
/* Accumulate float vertex colors in scene linear color space. */
|
||||
int *num_loops_for_vertex = MEM_callocN(sizeof(int) * me->totvert, "num_loops_for_vertex");
|
||||
int *num_loops_for_vertex = static_cast<int *>(
|
||||
MEM_callocN(sizeof(int) * me->totvert, "num_loops_for_vertex"));
|
||||
memset(mcol, 0, sizeof(MPropCol) * me->totvert);
|
||||
|
||||
const MLoop *mloop = BKE_mesh_loops(me);
|
||||
@@ -1177,7 +1183,8 @@ static bool bake_targets_output_vertex_colors(BakeTargets *targets, Object *ob)
|
||||
memcpy(data, &mcol[i], sizeof(MPropCol));
|
||||
}
|
||||
else {
|
||||
convert_float_color_to_byte_color(&mcol[i], 1, is_noncolor, data);
|
||||
convert_float_color_to_byte_color(
|
||||
&mcol[i], 1, is_noncolor, static_cast<MLoopCol *>(data));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -1188,7 +1195,8 @@ static bool bake_targets_output_vertex_colors(BakeTargets *targets, Object *ob)
|
||||
memcpy(active_color_layer->data, mcol, sizeof(MPropCol) * me->totvert);
|
||||
}
|
||||
else {
|
||||
convert_float_color_to_byte_color(mcol, totvert, is_noncolor, active_color_layer->data);
|
||||
convert_float_color_to_byte_color(
|
||||
mcol, totvert, is_noncolor, static_cast<MLoopCol *>(active_color_layer->data));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1218,7 +1226,8 @@ static bool bake_targets_output_vertex_colors(BakeTargets *targets, Object *ob)
|
||||
memcpy(data, &color, sizeof(MPropCol));
|
||||
}
|
||||
else {
|
||||
convert_float_color_to_byte_color(&color, 1, is_noncolor, data);
|
||||
convert_float_color_to_byte_color(
|
||||
&color, 1, is_noncolor, static_cast<MLoopCol *>(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1226,14 +1235,14 @@ static bool bake_targets_output_vertex_colors(BakeTargets *targets, Object *ob)
|
||||
else {
|
||||
/* Copy to mesh. */
|
||||
if (active_color_layer->type == CD_PROP_COLOR) {
|
||||
MPropCol *colors = active_color_layer->data;
|
||||
MPropCol *colors = static_cast<MPropCol *>(active_color_layer->data);
|
||||
for (int i = 0; i < me->totloop; i++) {
|
||||
zero_v4(colors[i].color);
|
||||
bake_result_add_to_rgba(colors[i].color, &result[i * channels_num], channels_num);
|
||||
}
|
||||
}
|
||||
else {
|
||||
MLoopCol *colors = active_color_layer->data;
|
||||
MLoopCol *colors = static_cast<MLoopCol *>(active_color_layer->data);
|
||||
for (int i = 0; i < me->totloop; i++) {
|
||||
MPropCol color;
|
||||
zero_v4(color.color);
|
||||
@@ -1281,8 +1290,8 @@ static bool bake_targets_init(const BakeAPIRender *bkr,
|
||||
|
||||
targets->is_noncolor = is_noncolor_pass(bkr->pass_type);
|
||||
targets->channels_num = RE_pass_depth(bkr->pass_type);
|
||||
targets->result = MEM_callocN(sizeof(float) * targets->channels_num * targets->pixels_num,
|
||||
"bake return pixels");
|
||||
targets->result = static_cast<float *>(MEM_callocN(
|
||||
sizeof(float) * targets->channels_num * targets->pixels_num, "bake return pixels"));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1352,23 +1361,23 @@ static int bake(const BakeAPIRender *bkr,
|
||||
int op_result = OPERATOR_CANCELLED;
|
||||
bool ok = false;
|
||||
|
||||
Object *ob_cage = NULL;
|
||||
Object *ob_cage_eval = NULL;
|
||||
Object *ob_low_eval = NULL;
|
||||
Object *ob_cage = nullptr;
|
||||
Object *ob_cage_eval = nullptr;
|
||||
Object *ob_low_eval = nullptr;
|
||||
|
||||
BakeHighPolyData *highpoly = NULL;
|
||||
BakeHighPolyData *highpoly = nullptr;
|
||||
int tot_highpoly = 0;
|
||||
|
||||
Mesh *me_low_eval = NULL;
|
||||
Mesh *me_cage_eval = NULL;
|
||||
Mesh *me_low_eval = nullptr;
|
||||
Mesh *me_cage_eval = nullptr;
|
||||
|
||||
MultiresModifierData *mmd_low = NULL;
|
||||
MultiresModifierData *mmd_low = nullptr;
|
||||
int mmd_flags_low = 0;
|
||||
|
||||
BakePixel *pixel_array_low = NULL;
|
||||
BakePixel *pixel_array_high = NULL;
|
||||
BakePixel *pixel_array_low = nullptr;
|
||||
BakePixel *pixel_array_high = nullptr;
|
||||
|
||||
BakeTargets targets = {NULL};
|
||||
BakeTargets targets = {nullptr};
|
||||
|
||||
const bool preserve_origindex = (bkr->target == R_BAKE_TARGET_VERTEX_COLORS);
|
||||
|
||||
@@ -1395,8 +1404,9 @@ static int bake(const BakeAPIRender *bkr,
|
||||
CollectionPointerLink *link;
|
||||
tot_highpoly = 0;
|
||||
|
||||
for (link = selected_objects->first; link; link = link->next) {
|
||||
Object *ob_iter = link->ptr.data;
|
||||
for (link = static_cast<CollectionPointerLink *>(selected_objects->first); link;
|
||||
link = link->next) {
|
||||
Object *ob_iter = static_cast<Object *>(link->ptr.data);
|
||||
|
||||
if (ob_iter == ob_low) {
|
||||
continue;
|
||||
@@ -1406,9 +1416,10 @@ static int bake(const BakeAPIRender *bkr,
|
||||
}
|
||||
|
||||
if (bkr->is_cage && bkr->custom_cage[0] != '\0') {
|
||||
ob_cage = BLI_findstring(&bmain->objects, bkr->custom_cage, offsetof(ID, name) + 2);
|
||||
ob_cage = static_cast<Object *>(
|
||||
BLI_findstring(&bmain->objects, bkr->custom_cage, offsetof(ID, name) + 2));
|
||||
|
||||
if (ob_cage == NULL || ob_cage->type != OB_MESH) {
|
||||
if (ob_cage == nullptr || ob_cage->type != OB_MESH) {
|
||||
BKE_report(reports, RPT_ERROR, "No valid cage object");
|
||||
goto cleanup;
|
||||
}
|
||||
@@ -1445,8 +1456,9 @@ static int bake(const BakeAPIRender *bkr,
|
||||
|
||||
/* Populate the pixel array with the face data. Except if we use a cage, then
|
||||
* it is populated later with the cage mesh (smoothed version of the mesh). */
|
||||
pixel_array_low = MEM_mallocN(sizeof(BakePixel) * targets.pixels_num, "bake pixels low poly");
|
||||
if ((bkr->is_selected_to_active && (ob_cage == NULL) && bkr->is_cage) == false) {
|
||||
pixel_array_low = static_cast<BakePixel *>(
|
||||
MEM_mallocN(sizeof(BakePixel) * targets.pixels_num, "bake pixels low poly"));
|
||||
if ((bkr->is_selected_to_active && (ob_cage == nullptr) && bkr->is_cage) == false) {
|
||||
bake_targets_populate_pixels(bkr, &targets, ob_low, me_low_eval, pixel_array_low);
|
||||
}
|
||||
|
||||
@@ -1469,7 +1481,7 @@ static int bake(const BakeAPIRender *bkr,
|
||||
else if (bkr->is_cage) {
|
||||
bool is_changed = false;
|
||||
|
||||
ModifierData *md = ob_low_eval->modifiers.first;
|
||||
ModifierData *md = static_cast<ModifierData *>(ob_low_eval->modifiers.first);
|
||||
while (md) {
|
||||
ModifierData *md_next = md->next;
|
||||
|
||||
@@ -1498,15 +1510,17 @@ static int bake(const BakeAPIRender *bkr,
|
||||
BKE_object_handle_data_update(depsgraph, scene, ob_low_eval);
|
||||
}
|
||||
|
||||
me_cage_eval = BKE_mesh_new_from_object(NULL, ob_low_eval, false, preserve_origindex);
|
||||
me_cage_eval = BKE_mesh_new_from_object(nullptr, ob_low_eval, false, preserve_origindex);
|
||||
bake_targets_populate_pixels(bkr, &targets, ob_low, me_cage_eval, pixel_array_low);
|
||||
}
|
||||
|
||||
highpoly = MEM_callocN(sizeof(BakeHighPolyData) * tot_highpoly, "bake high poly objects");
|
||||
highpoly = static_cast<BakeHighPolyData *>(
|
||||
MEM_callocN(sizeof(BakeHighPolyData) * tot_highpoly, "bake high poly objects"));
|
||||
|
||||
/* populate highpoly array */
|
||||
for (link = selected_objects->first; link; link = link->next) {
|
||||
Object *ob_iter = link->ptr.data;
|
||||
for (link = static_cast<CollectionPointerLink *>(selected_objects->first); link;
|
||||
link = link->next) {
|
||||
Object *ob_iter = static_cast<Object *>(link->ptr.data);
|
||||
|
||||
if (ob_iter == ob_low) {
|
||||
continue;
|
||||
@@ -1518,7 +1532,7 @@ static int bake(const BakeAPIRender *bkr,
|
||||
highpoly[i].ob_eval->visibility_flag &= ~OB_HIDE_RENDER;
|
||||
highpoly[i].ob_eval->base_flag |= (BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT |
|
||||
BASE_ENABLED_RENDER);
|
||||
highpoly[i].me = BKE_mesh_new_from_object(NULL, highpoly[i].ob_eval, false, false);
|
||||
highpoly[i].me = BKE_mesh_new_from_object(nullptr, highpoly[i].ob_eval, false, false);
|
||||
|
||||
/* Low-poly to high-poly transformation matrix. */
|
||||
copy_m4_m4(highpoly[i].obmat, highpoly[i].ob->object_to_world);
|
||||
@@ -1531,7 +1545,7 @@ static int bake(const BakeAPIRender *bkr,
|
||||
|
||||
BLI_assert(i == tot_highpoly);
|
||||
|
||||
if (ob_cage != NULL) {
|
||||
if (ob_cage != nullptr) {
|
||||
ob_cage_eval->visibility_flag |= OB_HIDE_RENDER;
|
||||
ob_cage_eval->base_flag &= ~(BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT |
|
||||
BASE_ENABLED_RENDER);
|
||||
@@ -1540,8 +1554,8 @@ static int bake(const BakeAPIRender *bkr,
|
||||
ob_low_eval->base_flag &= ~(BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT | BASE_ENABLED_RENDER);
|
||||
|
||||
/* populate the pixel arrays with the corresponding face data for each high poly object */
|
||||
pixel_array_high = MEM_mallocN(sizeof(BakePixel) * targets.pixels_num,
|
||||
"bake pixels high poly");
|
||||
pixel_array_high = static_cast<BakePixel *>(
|
||||
MEM_mallocN(sizeof(BakePixel) * targets.pixels_num, "bake pixels high poly"));
|
||||
|
||||
if (!RE_bake_pixels_populate_from_objects(
|
||||
me_low_eval,
|
||||
@@ -1550,7 +1564,7 @@ static int bake(const BakeAPIRender *bkr,
|
||||
highpoly,
|
||||
tot_highpoly,
|
||||
targets.pixels_num,
|
||||
ob_cage != NULL,
|
||||
ob_cage != nullptr,
|
||||
bkr->cage_extrusion,
|
||||
bkr->max_ray_distance,
|
||||
ob_low_eval->object_to_world,
|
||||
@@ -1637,8 +1651,8 @@ static int bake(const BakeAPIRender *bkr,
|
||||
}
|
||||
else {
|
||||
/* From multi-resolution. */
|
||||
Mesh *me_nores = NULL;
|
||||
ModifierData *md = NULL;
|
||||
Mesh *me_nores = nullptr;
|
||||
ModifierData *md = nullptr;
|
||||
int mode;
|
||||
|
||||
BKE_object_eval_reset(ob_low_eval);
|
||||
@@ -1649,7 +1663,7 @@ static int bake(const BakeAPIRender *bkr,
|
||||
md->mode &= ~eModifierMode_Render;
|
||||
|
||||
/* Evaluate modifiers again. */
|
||||
me_nores = BKE_mesh_new_from_object(NULL, ob_low_eval, false, false);
|
||||
me_nores = BKE_mesh_new_from_object(nullptr, ob_low_eval, false, false);
|
||||
bake_targets_populate_pixels(bkr, &targets, ob_low, me_nores, pixel_array_low);
|
||||
}
|
||||
|
||||
@@ -1662,7 +1676,7 @@ static int bake(const BakeAPIRender *bkr,
|
||||
ob_low_eval->object_to_world);
|
||||
|
||||
if (md) {
|
||||
BKE_id_free(NULL, &me_nores->id);
|
||||
BKE_id_free(nullptr, &me_nores->id);
|
||||
md->mode = mode;
|
||||
}
|
||||
}
|
||||
@@ -1694,8 +1708,8 @@ cleanup:
|
||||
|
||||
if (highpoly) {
|
||||
for (int i = 0; i < tot_highpoly; i++) {
|
||||
if (highpoly[i].me != NULL) {
|
||||
BKE_id_free(NULL, &highpoly[i].me->id);
|
||||
if (highpoly[i].me != nullptr) {
|
||||
BKE_id_free(nullptr, &highpoly[i].me->id);
|
||||
}
|
||||
}
|
||||
MEM_freeN(highpoly);
|
||||
@@ -1715,12 +1729,12 @@ cleanup:
|
||||
|
||||
bake_targets_free(&targets);
|
||||
|
||||
if (me_low_eval != NULL) {
|
||||
BKE_id_free(NULL, &me_low_eval->id);
|
||||
if (me_low_eval != nullptr) {
|
||||
BKE_id_free(nullptr, &me_low_eval->id);
|
||||
}
|
||||
|
||||
if (me_cage_eval != NULL) {
|
||||
BKE_id_free(NULL, &me_cage_eval->id);
|
||||
if (me_cage_eval != nullptr) {
|
||||
BKE_id_free(nullptr, &me_cage_eval->id);
|
||||
}
|
||||
|
||||
DEG_graph_free(depsgraph);
|
||||
@@ -1738,12 +1752,12 @@ static void bake_init_api_data(wmOperator *op, bContext *C, BakeAPIRender *bkr)
|
||||
bkr->main = CTX_data_main(C);
|
||||
bkr->view_layer = CTX_data_view_layer(C);
|
||||
bkr->scene = CTX_data_scene(C);
|
||||
bkr->area = screen ? BKE_screen_find_big_area(screen, SPACE_IMAGE, 10) : NULL;
|
||||
bkr->area = screen ? BKE_screen_find_big_area(screen, SPACE_IMAGE, 10) : nullptr;
|
||||
|
||||
bkr->pass_type = RNA_enum_get(op->ptr, "type");
|
||||
bkr->pass_type = eScenePassType(RNA_enum_get(op->ptr, "type"));
|
||||
bkr->pass_filter = RNA_enum_get(op->ptr, "pass_filter");
|
||||
bkr->margin = RNA_int_get(op->ptr, "margin");
|
||||
bkr->margin_type = RNA_enum_get(op->ptr, "margin_type");
|
||||
bkr->margin_type = eBakeMarginType(RNA_enum_get(op->ptr, "margin_type"));
|
||||
|
||||
bkr->save_mode = (eBakeSaveMode)RNA_enum_get(op->ptr, "save_mode");
|
||||
bkr->target = (eBakeTarget)RNA_enum_get(op->ptr, "target");
|
||||
@@ -1759,9 +1773,9 @@ static void bake_init_api_data(wmOperator *op, bContext *C, BakeAPIRender *bkr)
|
||||
bkr->max_ray_distance = RNA_float_get(op->ptr, "max_ray_distance");
|
||||
|
||||
bkr->normal_space = RNA_enum_get(op->ptr, "normal_space");
|
||||
bkr->normal_swizzle[0] = RNA_enum_get(op->ptr, "normal_r");
|
||||
bkr->normal_swizzle[1] = RNA_enum_get(op->ptr, "normal_g");
|
||||
bkr->normal_swizzle[2] = RNA_enum_get(op->ptr, "normal_b");
|
||||
bkr->normal_swizzle[0] = eBakeNormalSwizzle(RNA_enum_get(op->ptr, "normal_r"));
|
||||
bkr->normal_swizzle[1] = eBakeNormalSwizzle(RNA_enum_get(op->ptr, "normal_g"));
|
||||
bkr->normal_swizzle[2] = eBakeNormalSwizzle(RNA_enum_get(op->ptr, "normal_b"));
|
||||
|
||||
bkr->width = RNA_int_get(op->ptr, "width");
|
||||
bkr->height = RNA_int_get(op->ptr, "height");
|
||||
@@ -1800,7 +1814,7 @@ static int bake_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Render *re;
|
||||
int result = OPERATOR_CANCELLED;
|
||||
BakeAPIRender bkr = {NULL};
|
||||
BakeAPIRender bkr = {nullptr};
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
|
||||
G.is_break = false;
|
||||
@@ -1812,7 +1826,7 @@ static int bake_exec(bContext *C, wmOperator *op)
|
||||
re = bkr.render;
|
||||
|
||||
/* setup new render */
|
||||
RE_test_break_cb(re, NULL, bake_break);
|
||||
RE_test_break_cb(re, nullptr, bake_break);
|
||||
|
||||
if (!bake_pass_filter_check(bkr.pass_type, bkr.pass_filter, bkr.reports)) {
|
||||
goto finally;
|
||||
@@ -1843,13 +1857,14 @@ static int bake_exec(bContext *C, wmOperator *op)
|
||||
else {
|
||||
CollectionPointerLink *link;
|
||||
bkr.is_clear = bkr.is_clear && BLI_listbase_is_single(&bkr.selected_objects);
|
||||
for (link = bkr.selected_objects.first; link; link = link->next) {
|
||||
Object *ob_iter = link->ptr.data;
|
||||
result = bake(&bkr, ob_iter, NULL, bkr.reports);
|
||||
for (link = static_cast<CollectionPointerLink *>(bkr.selected_objects.first); link;
|
||||
link = link->next) {
|
||||
Object *ob_iter = static_cast<Object *>(link->ptr.data);
|
||||
result = bake(&bkr, ob_iter, nullptr, bkr.reports);
|
||||
}
|
||||
}
|
||||
|
||||
RE_SetReports(re, NULL);
|
||||
RE_SetReports(re, nullptr);
|
||||
|
||||
finally:
|
||||
G.is_rendering = false;
|
||||
@@ -1857,7 +1872,7 @@ finally:
|
||||
return result;
|
||||
}
|
||||
|
||||
static void bake_startjob(void *bkv, bool *UNUSED(stop), bool *do_update, float *progress)
|
||||
static void bake_startjob(void *bkv, bool * /*stop*/, bool *do_update, float *progress)
|
||||
{
|
||||
BakeAPIRender *bkr = (BakeAPIRender *)bkv;
|
||||
|
||||
@@ -1896,9 +1911,10 @@ static void bake_startjob(void *bkv, bool *UNUSED(stop), bool *do_update, float
|
||||
else {
|
||||
CollectionPointerLink *link;
|
||||
bkr->is_clear = bkr->is_clear && BLI_listbase_is_single(&bkr->selected_objects);
|
||||
for (link = bkr->selected_objects.first; link; link = link->next) {
|
||||
Object *ob_iter = link->ptr.data;
|
||||
bkr->result = bake(bkr, ob_iter, NULL, bkr->reports);
|
||||
for (link = static_cast<CollectionPointerLink *>(bkr->selected_objects.first); link;
|
||||
link = link->next) {
|
||||
Object *ob_iter = static_cast<Object *>(link->ptr.data);
|
||||
bkr->result = bake(bkr, ob_iter, nullptr, bkr->reports);
|
||||
|
||||
if (bkr->result == OPERATOR_CANCELLED) {
|
||||
return;
|
||||
@@ -1906,7 +1922,7 @@ static void bake_startjob(void *bkv, bool *UNUSED(stop), bool *do_update, float
|
||||
}
|
||||
}
|
||||
|
||||
RE_SetReports(bkr->render, NULL);
|
||||
RE_SetReports(bkr->render, nullptr);
|
||||
}
|
||||
|
||||
static void bake_job_complete(void *bkv)
|
||||
@@ -2037,10 +2053,9 @@ static void bake_set_props(wmOperator *op, Scene *scene)
|
||||
}
|
||||
}
|
||||
|
||||
static int bake_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
||||
static int bake_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
|
||||
{
|
||||
wmJob *wm_job;
|
||||
BakeAPIRender *bkr;
|
||||
Render *re;
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
|
||||
@@ -2051,7 +2066,7 @@ static int bake_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
bkr = MEM_mallocN(sizeof(BakeAPIRender), "render bake");
|
||||
BakeAPIRender *bkr = static_cast<BakeAPIRender *>(MEM_mallocN(sizeof(BakeAPIRender), __func__));
|
||||
|
||||
/* init bake render */
|
||||
bake_init_api_data(op, C, bkr);
|
||||
@@ -2059,7 +2074,7 @@ static int bake_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)
|
||||
re = bkr->render;
|
||||
|
||||
/* setup new render */
|
||||
RE_test_break_cb(re, NULL, bake_break);
|
||||
RE_test_break_cb(re, nullptr, bake_break);
|
||||
RE_progress_cb(re, bkr, bake_progress_update);
|
||||
|
||||
/* setup job */
|
||||
@@ -2074,7 +2089,7 @@ static int bake_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)
|
||||
WM_jobs_timer(
|
||||
wm_job, 0.5, (bkr->target == R_BAKE_TARGET_VERTEX_COLORS) ? NC_GEOM | ND_DATA : NC_IMAGE, 0);
|
||||
WM_jobs_callbacks_ex(
|
||||
wm_job, bake_startjob, NULL, NULL, NULL, bake_job_complete, bake_job_canceled);
|
||||
wm_job, bake_startjob, nullptr, nullptr, nullptr, bake_job_complete, bake_job_canceled);
|
||||
|
||||
G.is_break = false;
|
||||
G.is_rendering = true;
|
||||
@@ -2121,7 +2136,7 @@ void OBJECT_OT_bake(wmOperatorType *ot)
|
||||
RNA_def_property_flag(prop, PROP_ENUM_FLAG);
|
||||
RNA_def_string_file_path(ot->srna,
|
||||
"filepath",
|
||||
NULL,
|
||||
nullptr,
|
||||
FILE_MAX,
|
||||
"File Path",
|
||||
"Image filepath to use when saving externally");
|
||||
@@ -2185,7 +2200,7 @@ void OBJECT_OT_bake(wmOperatorType *ot)
|
||||
1.0f);
|
||||
RNA_def_string(ot->srna,
|
||||
"cage_object",
|
||||
NULL,
|
||||
nullptr,
|
||||
MAX_NAME,
|
||||
"Cage Object",
|
||||
"Object to use as cage, instead of calculating the cage from the active object "
|
||||
@@ -2245,7 +2260,7 @@ void OBJECT_OT_bake(wmOperatorType *ot)
|
||||
"Automatically name the output file with the pass type");
|
||||
RNA_def_string(ot->srna,
|
||||
"uv_layer",
|
||||
NULL,
|
||||
nullptr,
|
||||
MAX_CUSTOMDATA_LAYER_NAME_NO_PREFIX,
|
||||
"UV Layer",
|
||||
"UV layer to override active");
|
||||
@@ -29,7 +29,7 @@ set(INC_SYS
|
||||
)
|
||||
|
||||
set(SRC
|
||||
drawobject.c
|
||||
drawobject.cc
|
||||
space_view3d.cc
|
||||
view3d_buttons.c
|
||||
view3d_camera_control.c
|
||||
|
||||
@@ -53,11 +53,11 @@ void ED_draw_object_facemap(Depsgraph *depsgraph,
|
||||
return;
|
||||
}
|
||||
|
||||
const Mesh *me = ob->data;
|
||||
const Mesh *me = static_cast<const Mesh *>(ob->data);
|
||||
{
|
||||
Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
|
||||
const Mesh *me_eval = BKE_object_get_evaluated_mesh(ob_eval);
|
||||
if (me_eval != NULL) {
|
||||
if (me_eval != nullptr) {
|
||||
me = me_eval;
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ void ED_draw_object_facemap(Depsgraph *depsgraph,
|
||||
GPU_front_facing(ob->transflag & OB_NEG_SCALE);
|
||||
|
||||
/* Just to create the data to pass to immediate mode! (sigh) */
|
||||
const int *facemap_data = CustomData_get_layer(&me->pdata, CD_FACEMAP);
|
||||
const int *facemap_data = static_cast<const int *>(CustomData_get_layer(&me->pdata, CD_FACEMAP));
|
||||
if (facemap_data) {
|
||||
GPU_blend(GPU_BLEND_ALPHA);
|
||||
|
||||
@@ -76,7 +76,7 @@ void ED_draw_object_facemap(Depsgraph *depsgraph,
|
||||
int mpoly_len = me->totpoly;
|
||||
int mloop_len = me->totloop;
|
||||
|
||||
facemap_data = CustomData_get_layer(&me->pdata, CD_FACEMAP);
|
||||
facemap_data = static_cast<const int *>(CustomData_get_layer(&me->pdata, CD_FACEMAP));
|
||||
|
||||
/* Make a batch and free it each time for now. */
|
||||
const int looptris_len = poly_to_tri_count(mpoly_len, mloop_len);
|
||||
@@ -100,9 +100,12 @@ void ED_draw_object_facemap(Depsgraph *depsgraph,
|
||||
for (mp = polys, i = 0; i < mpoly_len; i++, mp++) {
|
||||
if (facemap_data[i] == facemap) {
|
||||
for (int j = 2; j < mp->totloop; j++) {
|
||||
copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), positions[loops[mlt->tri[0]].v]);
|
||||
copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), positions[loops[mlt->tri[1]].v]);
|
||||
copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), positions[loops[mlt->tri[2]].v]);
|
||||
copy_v3_v3(static_cast<float *>(GPU_vertbuf_raw_step(&pos_step)),
|
||||
positions[loops[mlt->tri[0]].v]);
|
||||
copy_v3_v3(static_cast<float *>(GPU_vertbuf_raw_step(&pos_step)),
|
||||
positions[loops[mlt->tri[1]].v]);
|
||||
copy_v3_v3(static_cast<float *>(GPU_vertbuf_raw_step(&pos_step)),
|
||||
positions[loops[mlt->tri[2]].v]);
|
||||
vbo_len_used += 3;
|
||||
mlt++;
|
||||
}
|
||||
@@ -120,9 +123,10 @@ void ED_draw_object_facemap(Depsgraph *depsgraph,
|
||||
const MLoop *ml_a = ml_start + 1;
|
||||
const MLoop *ml_b = ml_start + 2;
|
||||
for (int j = 2; j < mp->totloop; j++) {
|
||||
copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), positions[ml_start->v]);
|
||||
copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), positions[ml_a->v]);
|
||||
copy_v3_v3(GPU_vertbuf_raw_step(&pos_step), positions[ml_b->v]);
|
||||
copy_v3_v3(static_cast<float *>(GPU_vertbuf_raw_step(&pos_step)),
|
||||
positions[ml_start->v]);
|
||||
copy_v3_v3(static_cast<float *>(GPU_vertbuf_raw_step(&pos_step)), positions[ml_a->v]);
|
||||
copy_v3_v3(static_cast<float *>(GPU_vertbuf_raw_step(&pos_step)), positions[ml_b->v]);
|
||||
vbo_len_used += 3;
|
||||
|
||||
ml_a++;
|
||||
@@ -136,7 +140,7 @@ void ED_draw_object_facemap(Depsgraph *depsgraph,
|
||||
GPU_vertbuf_data_resize(vbo_pos, vbo_len_used);
|
||||
}
|
||||
|
||||
GPUBatch *draw_batch = GPU_batch_create(GPU_PRIM_TRIS, vbo_pos, NULL);
|
||||
GPUBatch *draw_batch = GPU_batch_create(GPU_PRIM_TRIS, vbo_pos, nullptr);
|
||||
GPU_batch_program_set_builtin(draw_batch, GPU_SHADER_3D_UNIFORM_COLOR);
|
||||
GPU_batch_uniform_4fv(draw_batch, "color", col);
|
||||
GPU_batch_draw(draw_batch);
|
||||
@@ -32,7 +32,7 @@ set(SRC
|
||||
uvedit_rip.c
|
||||
uvedit_select.c
|
||||
uvedit_smart_stitch.c
|
||||
uvedit_unwrap_ops.c
|
||||
uvedit_unwrap_ops.cc
|
||||
|
||||
uvedit_clipboard_graph_iso.hh
|
||||
uvedit_intern.h
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
* \ingroup eduv
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
@@ -18,8 +18,7 @@
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
#include "BLI_alloca.h"
|
||||
#include "BLI_array.h"
|
||||
#include "BLI_array.hh"
|
||||
#include "BLI_linklist.h"
|
||||
#include "BLI_listbase.h"
|
||||
#include "BLI_math.h"
|
||||
@@ -27,6 +26,7 @@
|
||||
#include "BLI_string.h"
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_uvproject.h"
|
||||
#include "BLI_vector.hh"
|
||||
|
||||
#include "BLT_translation.h"
|
||||
|
||||
@@ -77,7 +77,7 @@ static void modifier_unwrap_state(Object *obedit, const Scene *scene, bool *r_us
|
||||
ModifierData *md;
|
||||
bool subsurf = (scene->toolsettings->uvcalc_flag & UVCALC_USESUBSURF) != 0;
|
||||
|
||||
md = obedit->modifiers.first;
|
||||
md = static_cast<ModifierData *>(obedit->modifiers.first);
|
||||
|
||||
/* subsurf will take the modifier settings only if modifier is first or right after mirror */
|
||||
if (subsurf) {
|
||||
@@ -103,7 +103,7 @@ static bool ED_uvedit_ensure_uvs(Object *obedit)
|
||||
BMIter iter;
|
||||
|
||||
if (em && em->bm->totface && !CustomData_has_layer(&em->bm->ldata, CD_PROP_FLOAT2)) {
|
||||
ED_mesh_uv_add(obedit->data, NULL, true, true, NULL);
|
||||
ED_mesh_uv_add(static_cast<Mesh *>(obedit->data), nullptr, true, true, nullptr);
|
||||
}
|
||||
|
||||
/* Happens when there are no faces. */
|
||||
@@ -137,7 +137,7 @@ static bool ED_uvedit_ensure_uvs(Object *obedit)
|
||||
* \{ */
|
||||
|
||||
static void ED_uvedit_udim_params_from_image_space(const SpaceImage *sima,
|
||||
struct UVPackIsland_Params *r_params)
|
||||
UVPackIsland_Params *r_params)
|
||||
{
|
||||
if (!sima) {
|
||||
return; /* Nothing to do. */
|
||||
@@ -147,7 +147,8 @@ static void ED_uvedit_udim_params_from_image_space(const SpaceImage *sima,
|
||||
* the tiled image is considered. */
|
||||
const Image *image = sima->image;
|
||||
if (image && image->source == IMA_SRC_TILED) {
|
||||
ImageTile *active_tile = BLI_findlink(&image->tiles, image->active_tile_index);
|
||||
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;
|
||||
@@ -168,7 +169,7 @@ static void ED_uvedit_udim_params_from_image_space(const SpaceImage *sima,
|
||||
/** \name Parametrizer Conversion
|
||||
* \{ */
|
||||
|
||||
typedef struct UnwrapOptions {
|
||||
struct UnwrapOptions {
|
||||
/** Connectivity based on UV coordinates instead of seams. */
|
||||
bool topology_from_uvs;
|
||||
/** Also use seams as well as UV coordinates (only valid when `topology_from_uvs` is enabled). */
|
||||
@@ -187,12 +188,12 @@ typedef struct UnwrapOptions {
|
||||
bool correct_aspect;
|
||||
/** Treat unselected uvs as if they were pinned. */
|
||||
bool pin_unselected;
|
||||
} UnwrapOptions;
|
||||
};
|
||||
|
||||
typedef struct UnwrapResultInfo {
|
||||
struct UnwrapResultInfo {
|
||||
int count_changed;
|
||||
int count_failed;
|
||||
} UnwrapResultInfo;
|
||||
};
|
||||
|
||||
static bool uvedit_have_selection(const Scene *scene, BMEditMesh *em, const UnwrapOptions *options)
|
||||
{
|
||||
@@ -261,14 +262,14 @@ void ED_uvedit_get_aspect_from_material(Object *ob,
|
||||
return;
|
||||
}
|
||||
Image *ima;
|
||||
ED_object_get_active_image(ob, material_index + 1, &ima, NULL, NULL, NULL);
|
||||
ED_image_get_uv_aspect(ima, NULL, r_aspx, r_aspy);
|
||||
ED_object_get_active_image(ob, material_index + 1, &ima, nullptr, nullptr, nullptr);
|
||||
ED_image_get_uv_aspect(ima, nullptr, r_aspx, r_aspy);
|
||||
}
|
||||
|
||||
void ED_uvedit_get_aspect(Object *ob, float *r_aspx, float *r_aspy)
|
||||
{
|
||||
BMEditMesh *em = BKE_editmesh_from_object(ob);
|
||||
BLI_assert(em != NULL);
|
||||
BLI_assert(em != nullptr);
|
||||
bool sloppy = true;
|
||||
bool selected = false;
|
||||
BMFace *efa = BM_mesh_active_face_get(em->bm, sloppy, selected);
|
||||
@@ -345,11 +346,11 @@ static void construct_param_handle_face_add(ParamHandle *handle,
|
||||
const UnwrapOptions *options,
|
||||
const BMUVOffsets offsets)
|
||||
{
|
||||
ParamKey *vkeys = BLI_array_alloca(vkeys, efa->len);
|
||||
bool *pin = BLI_array_alloca(pin, efa->len);
|
||||
bool *select = BLI_array_alloca(select, efa->len);
|
||||
const float **co = BLI_array_alloca(co, efa->len);
|
||||
float **uv = BLI_array_alloca(uv, efa->len);
|
||||
blender::Array<ParamKey, BM_DEFAULT_NGON_STACK_SIZE> vkeys(efa->len);
|
||||
blender::Array<bool, BM_DEFAULT_NGON_STACK_SIZE> pin(efa->len);
|
||||
blender::Array<bool, BM_DEFAULT_NGON_STACK_SIZE> select(efa->len);
|
||||
blender::Array<const float *, BM_DEFAULT_NGON_STACK_SIZE> co(efa->len);
|
||||
blender::Array<float *, BM_DEFAULT_NGON_STACK_SIZE> uv(efa->len);
|
||||
int i;
|
||||
|
||||
BMIter liter;
|
||||
@@ -370,7 +371,8 @@ static void construct_param_handle_face_add(ParamHandle *handle,
|
||||
}
|
||||
}
|
||||
|
||||
GEO_uv_parametrizer_face_add(handle, face_index, i, vkeys, co, uv, pin, select);
|
||||
GEO_uv_parametrizer_face_add(
|
||||
handle, face_index, i, vkeys.data(), co.data(), uv.data(), pin.data(), select.data());
|
||||
}
|
||||
|
||||
/* Set seams on UV Parametrizer based on options. */
|
||||
@@ -458,7 +460,7 @@ static ParamHandle *construct_param_handle(const Scene *scene,
|
||||
GEO_uv_parametrizer_construct_end(handle,
|
||||
options->fill_holes,
|
||||
options->topology_from_uvs,
|
||||
result_info ? &result_info->count_failed : NULL);
|
||||
result_info ? &result_info->count_failed : nullptr);
|
||||
|
||||
return handle;
|
||||
}
|
||||
@@ -520,7 +522,8 @@ static ParamHandle *construct_param_handle_multi(const Scene *scene,
|
||||
offset += bm->totface;
|
||||
}
|
||||
|
||||
GEO_uv_parametrizer_construct_end(handle, options->fill_holes, options->topology_from_uvs, NULL);
|
||||
GEO_uv_parametrizer_construct_end(
|
||||
handle, options->fill_holes, options->topology_from_uvs, nullptr);
|
||||
|
||||
return handle;
|
||||
}
|
||||
@@ -536,7 +539,7 @@ static void texface_from_original_index(const Scene *scene,
|
||||
BMLoop *l;
|
||||
BMIter liter;
|
||||
|
||||
*r_uv = NULL;
|
||||
*r_uv = nullptr;
|
||||
*r_pin = 0;
|
||||
*r_select = 1;
|
||||
|
||||
@@ -559,7 +562,8 @@ static Mesh *subdivide_edit_mesh(const Object *object,
|
||||
const BMEditMesh *em,
|
||||
const SubsurfModifierData *smd)
|
||||
{
|
||||
Mesh *me_from_em = BKE_mesh_from_bmesh_for_eval_nomain(em->bm, NULL, object->data);
|
||||
Mesh *me_from_em = BKE_mesh_from_bmesh_for_eval_nomain(
|
||||
em->bm, nullptr, static_cast<const Mesh *>(object->data));
|
||||
BKE_mesh_ensure_default_orig_index_customdata(me_from_em);
|
||||
|
||||
SubdivSettings settings = BKE_subsurf_modifier_settings_init(smd, false);
|
||||
@@ -571,9 +575,9 @@ static Mesh *subdivide_edit_mesh(const Object *object,
|
||||
mesh_settings.resolution = (1 << smd->levels) + 1;
|
||||
mesh_settings.use_optimal_display = (smd->flags & eSubsurfModifierFlag_ControlEdges);
|
||||
|
||||
Subdiv *subdiv = BKE_subdiv_update_from_mesh(NULL, &settings, me_from_em);
|
||||
Subdiv *subdiv = BKE_subdiv_update_from_mesh(nullptr, &settings, me_from_em);
|
||||
Mesh *result = BKE_subdiv_to_mesh(subdiv, &mesh_settings, me_from_em);
|
||||
BKE_id_free(NULL, me_from_em);
|
||||
BKE_id_free(nullptr, me_from_em);
|
||||
BKE_subdiv_free(subdiv);
|
||||
return result;
|
||||
}
|
||||
@@ -590,10 +594,9 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene,
|
||||
UnwrapResultInfo *result_info)
|
||||
{
|
||||
/* pointers to modifier data for unwrap control */
|
||||
ModifierData *md;
|
||||
SubsurfModifierData *smd_real;
|
||||
/* Modifier initialization data, will control what type of subdivision will happen. */
|
||||
SubsurfModifierData smd = {{NULL}};
|
||||
SubsurfModifierData smd = {{nullptr}};
|
||||
|
||||
/* Holds a map to edit-faces for every subdivision-surface polygon.
|
||||
* These will be used to get hidden/ selected flags etc. */
|
||||
@@ -616,7 +619,7 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene,
|
||||
}
|
||||
|
||||
/* number of subdivisions to perform */
|
||||
md = ob->modifiers.first;
|
||||
ModifierData *md = static_cast<ModifierData *>(ob->modifiers.first);
|
||||
smd_real = (SubsurfModifierData *)md;
|
||||
|
||||
smd.levels = smd_real->levels;
|
||||
@@ -631,11 +634,15 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene,
|
||||
const MPoly *subsurfedPolys = BKE_mesh_polys(subdiv_mesh);
|
||||
const MLoop *subsurfedLoops = BKE_mesh_loops(subdiv_mesh);
|
||||
|
||||
const int *origVertIndices = CustomData_get_layer(&subdiv_mesh->vdata, CD_ORIGINDEX);
|
||||
const int *origEdgeIndices = CustomData_get_layer(&subdiv_mesh->edata, CD_ORIGINDEX);
|
||||
const int *origPolyIndices = CustomData_get_layer(&subdiv_mesh->pdata, CD_ORIGINDEX);
|
||||
const int *origVertIndices = static_cast<const int *>(
|
||||
CustomData_get_layer(&subdiv_mesh->vdata, CD_ORIGINDEX));
|
||||
const int *origEdgeIndices = static_cast<const int *>(
|
||||
CustomData_get_layer(&subdiv_mesh->edata, CD_ORIGINDEX));
|
||||
const int *origPolyIndices = static_cast<const int *>(
|
||||
CustomData_get_layer(&subdiv_mesh->pdata, CD_ORIGINDEX));
|
||||
|
||||
faceMap = MEM_mallocN(subdiv_mesh->totpoly * sizeof(BMFace *), "unwrap_edit_face_map");
|
||||
faceMap = static_cast<BMFace **>(
|
||||
MEM_mallocN(subdiv_mesh->totpoly * sizeof(BMFace *), "unwrap_edit_face_map"));
|
||||
|
||||
BM_mesh_elem_index_ensure(em->bm, BM_VERT);
|
||||
BM_mesh_elem_table_ensure(em->bm, BM_EDGE | BM_FACE);
|
||||
@@ -645,14 +652,15 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene,
|
||||
faceMap[i] = BM_face_at_index(em->bm, origPolyIndices[i]);
|
||||
}
|
||||
|
||||
edgeMap = MEM_mallocN(subdiv_mesh->totedge * sizeof(BMEdge *), "unwrap_edit_edge_map");
|
||||
edgeMap = static_cast<BMEdge **>(
|
||||
MEM_mallocN(subdiv_mesh->totedge * sizeof(BMEdge *), "unwrap_edit_edge_map"));
|
||||
|
||||
/* map subsurfed edges to original editEdges */
|
||||
for (int i = 0; i < subdiv_mesh->totedge; i++) {
|
||||
/* not all edges correspond to an old edge */
|
||||
edgeMap[i] = (origEdgeIndices[i] != ORIGINDEX_NONE) ?
|
||||
BM_edge_at_index(em->bm, origEdgeIndices[i]) :
|
||||
NULL;
|
||||
nullptr;
|
||||
}
|
||||
|
||||
/* Prepare and feed faces to the solver */
|
||||
@@ -708,7 +716,7 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene,
|
||||
|
||||
/* these are calculated from original mesh too */
|
||||
for (int i = 0; i < subdiv_mesh->totedge; i++) {
|
||||
if ((edgeMap[i] != NULL) && BM_elem_flag_test(edgeMap[i], BM_ELEM_SEAM)) {
|
||||
if ((edgeMap[i] != nullptr) && BM_elem_flag_test(edgeMap[i], BM_ELEM_SEAM)) {
|
||||
const MEdge *edge = &subsurfedEdges[i];
|
||||
ParamKey vkeys[2];
|
||||
vkeys[0] = (ParamKey)edge->v1;
|
||||
@@ -720,12 +728,12 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene,
|
||||
GEO_uv_parametrizer_construct_end(handle,
|
||||
options->fill_holes,
|
||||
options->topology_from_uvs,
|
||||
result_info ? &result_info->count_failed : NULL);
|
||||
result_info ? &result_info->count_failed : nullptr);
|
||||
|
||||
/* cleanup */
|
||||
MEM_freeN(faceMap);
|
||||
MEM_freeN(edgeMap);
|
||||
BKE_id_free(NULL, subdiv_mesh);
|
||||
BKE_id_free(nullptr, subdiv_mesh);
|
||||
|
||||
return handle;
|
||||
}
|
||||
@@ -736,7 +744,7 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene,
|
||||
/** \name Minimize Stretch Operator
|
||||
* \{ */
|
||||
|
||||
typedef struct MinStretch {
|
||||
struct MinStretch {
|
||||
const Scene *scene;
|
||||
Object **objects_edit;
|
||||
uint objects_len;
|
||||
@@ -745,20 +753,19 @@ typedef struct MinStretch {
|
||||
double lasttime;
|
||||
int i, iterations;
|
||||
wmTimer *timer;
|
||||
} MinStretch;
|
||||
};
|
||||
|
||||
static bool minimize_stretch_init(bContext *C, wmOperator *op)
|
||||
{
|
||||
const Scene *scene = CTX_data_scene(C);
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
|
||||
const UnwrapOptions options = {
|
||||
.topology_from_uvs = true,
|
||||
.fill_holes = RNA_boolean_get(op->ptr, "fill_holes"),
|
||||
.only_selected_faces = true,
|
||||
.only_selected_uvs = true,
|
||||
.correct_aspect = true,
|
||||
};
|
||||
UnwrapOptions options{};
|
||||
options.topology_from_uvs = true;
|
||||
options.fill_holes = RNA_boolean_get(op->ptr, "fill_holes");
|
||||
options.only_selected_faces = true;
|
||||
options.only_selected_uvs = true;
|
||||
options.correct_aspect = true;
|
||||
|
||||
uint objects_len = 0;
|
||||
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
|
||||
@@ -769,7 +776,7 @@ static bool minimize_stretch_init(bContext *C, wmOperator *op)
|
||||
return false;
|
||||
}
|
||||
|
||||
MinStretch *ms = MEM_callocN(sizeof(MinStretch), "MinStretch");
|
||||
MinStretch *ms = MEM_cnew<MinStretch>(__func__);
|
||||
ms->scene = scene;
|
||||
ms->objects_edit = objects;
|
||||
ms->objects_len = objects_len;
|
||||
@@ -791,7 +798,7 @@ static bool minimize_stretch_init(bContext *C, wmOperator *op)
|
||||
|
||||
static void minimize_stretch_iteration(bContext *C, wmOperator *op, bool interactive)
|
||||
{
|
||||
MinStretch *ms = op->customdata;
|
||||
MinStretch *ms = static_cast<MinStretch *>(op->customdata);
|
||||
ScrArea *area = CTX_wm_area(C);
|
||||
const Scene *scene = CTX_data_scene(C);
|
||||
ToolSettings *ts = scene->toolsettings;
|
||||
@@ -824,7 +831,7 @@ static void minimize_stretch_iteration(bContext *C, wmOperator *op, bool interac
|
||||
continue;
|
||||
}
|
||||
|
||||
DEG_id_tag_update(obedit->data, ID_RECALC_GEOMETRY);
|
||||
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_GEOMETRY);
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
|
||||
}
|
||||
}
|
||||
@@ -832,14 +839,14 @@ static void minimize_stretch_iteration(bContext *C, wmOperator *op, bool interac
|
||||
|
||||
static void minimize_stretch_exit(bContext *C, wmOperator *op, bool cancel)
|
||||
{
|
||||
MinStretch *ms = op->customdata;
|
||||
MinStretch *ms = static_cast<MinStretch *>(op->customdata);
|
||||
ScrArea *area = CTX_wm_area(C);
|
||||
const Scene *scene = CTX_data_scene(C);
|
||||
ToolSettings *ts = scene->toolsettings;
|
||||
const bool synced_selection = (ts->uv_flag & UV_SYNC_SELECTION) != 0;
|
||||
|
||||
ED_area_status_text(area, NULL);
|
||||
ED_workspace_status_text(C, NULL);
|
||||
ED_area_status_text(area, nullptr);
|
||||
ED_workspace_status_text(C, nullptr);
|
||||
|
||||
if (ms->timer) {
|
||||
WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), ms->timer);
|
||||
@@ -863,13 +870,13 @@ static void minimize_stretch_exit(bContext *C, wmOperator *op, bool cancel)
|
||||
continue;
|
||||
}
|
||||
|
||||
DEG_id_tag_update(obedit->data, ID_RECALC_GEOMETRY);
|
||||
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_GEOMETRY);
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
|
||||
}
|
||||
|
||||
MEM_freeN(ms->objects_edit);
|
||||
MEM_freeN(ms);
|
||||
op->customdata = NULL;
|
||||
op->customdata = nullptr;
|
||||
}
|
||||
|
||||
static int minimize_stretch_exec(bContext *C, wmOperator *op)
|
||||
@@ -889,17 +896,15 @@ static int minimize_stretch_exec(bContext *C, wmOperator *op)
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
static int minimize_stretch_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
||||
static int minimize_stretch_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
|
||||
{
|
||||
MinStretch *ms;
|
||||
|
||||
if (!minimize_stretch_init(C, op)) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
minimize_stretch_iteration(C, op, true);
|
||||
|
||||
ms = op->customdata;
|
||||
MinStretch *ms = static_cast<MinStretch *>(op->customdata);
|
||||
WM_event_add_modal_handler(C, op);
|
||||
ms->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f);
|
||||
|
||||
@@ -908,7 +913,7 @@ static int minimize_stretch_invoke(bContext *C, wmOperator *op, const wmEvent *U
|
||||
|
||||
static int minimize_stretch_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
{
|
||||
MinStretch *ms = op->customdata;
|
||||
MinStretch *ms = static_cast<MinStretch *>(op->customdata);
|
||||
|
||||
switch (event->type) {
|
||||
case EVT_ESCKEY:
|
||||
@@ -1026,13 +1031,12 @@ static int pack_islands_exec(bContext *C, wmOperator *op)
|
||||
const Scene *scene = CTX_data_scene(C);
|
||||
const SpaceImage *sima = CTX_wm_space_image(C);
|
||||
|
||||
const UnwrapOptions options = {
|
||||
.topology_from_uvs = true,
|
||||
.only_selected_faces = true,
|
||||
.only_selected_uvs = true,
|
||||
.fill_holes = false,
|
||||
.correct_aspect = true,
|
||||
};
|
||||
UnwrapOptions options{};
|
||||
options.topology_from_uvs = true;
|
||||
options.only_selected_faces = true;
|
||||
options.only_selected_uvs = true;
|
||||
options.fill_holes = false;
|
||||
options.correct_aspect = true;
|
||||
|
||||
uint objects_len = 0;
|
||||
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
|
||||
@@ -1053,20 +1057,20 @@ static int pack_islands_exec(bContext *C, wmOperator *op)
|
||||
RNA_float_set(op->ptr, "margin", scene->toolsettings->uvcalc_margin);
|
||||
}
|
||||
|
||||
struct UVPackIsland_Params pack_island_params = {
|
||||
.rotate = RNA_boolean_get(op->ptr, "rotate"),
|
||||
.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,
|
||||
.ignore_pinned = false,
|
||||
.pin_unselected = options.pin_unselected,
|
||||
.margin_method = RNA_enum_get(op->ptr, "margin_method"),
|
||||
.margin = RNA_float_get(op->ptr, "margin"),
|
||||
};
|
||||
UVPackIsland_Params pack_island_params{};
|
||||
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");
|
||||
|
||||
struct UVMapUDIM_Params closest_udim_buf;
|
||||
struct UVMapUDIM_Params *closest_udim = NULL;
|
||||
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);
|
||||
}
|
||||
@@ -1079,7 +1083,7 @@ static int pack_islands_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
|
||||
ED_uvedit_pack_islands_multi(
|
||||
scene, objects, objects_len, NULL, closest_udim, &pack_island_params);
|
||||
scene, objects, objects_len, nullptr, closest_udim, &pack_island_params);
|
||||
|
||||
MEM_freeN(objects);
|
||||
return OPERATOR_FINISHED;
|
||||
@@ -1097,7 +1101,7 @@ static const EnumPropertyItem pack_margin_method_items[] = {
|
||||
0,
|
||||
"Fraction",
|
||||
"Specify a precise fraction of final UV output"},
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
{0, nullptr, 0, nullptr, nullptr},
|
||||
};
|
||||
|
||||
void UV_OT_pack_islands(wmOperatorType *ot)
|
||||
@@ -1109,7 +1113,7 @@ void UV_OT_pack_islands(wmOperatorType *ot)
|
||||
0,
|
||||
"Active UDIM",
|
||||
"Pack islands to active UDIM image tile or UDIM grid tile where 2D cursor is located"},
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
{0, nullptr, 0, nullptr, nullptr},
|
||||
};
|
||||
/* identifiers */
|
||||
ot->name = "Pack Islands";
|
||||
@@ -1149,13 +1153,12 @@ static int average_islands_scale_exec(bContext *C, wmOperator *op)
|
||||
ToolSettings *ts = scene->toolsettings;
|
||||
const bool synced_selection = (ts->uv_flag & UV_SYNC_SELECTION) != 0;
|
||||
|
||||
const UnwrapOptions options = {
|
||||
.topology_from_uvs = true,
|
||||
.only_selected_faces = true,
|
||||
.only_selected_uvs = true,
|
||||
.fill_holes = false,
|
||||
.correct_aspect = true,
|
||||
};
|
||||
UnwrapOptions options{};
|
||||
options.topology_from_uvs = true;
|
||||
options.only_selected_faces = true;
|
||||
options.only_selected_uvs = true;
|
||||
options.fill_holes = false;
|
||||
options.correct_aspect = true;
|
||||
|
||||
uint objects_len = 0;
|
||||
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
|
||||
@@ -1183,7 +1186,7 @@ static int average_islands_scale_exec(bContext *C, wmOperator *op)
|
||||
continue;
|
||||
}
|
||||
|
||||
DEG_id_tag_update(obedit->data, ID_RECALC_GEOMETRY);
|
||||
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_GEOMETRY);
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
|
||||
}
|
||||
MEM_freeN(objects);
|
||||
@@ -1217,11 +1220,11 @@ void UV_OT_average_islands_scale(wmOperatorType *ot)
|
||||
static struct {
|
||||
ParamHandle **handles;
|
||||
uint len, len_alloc;
|
||||
} g_live_unwrap = {NULL};
|
||||
} g_live_unwrap = {nullptr};
|
||||
|
||||
void ED_uvedit_live_unwrap_begin(Scene *scene, Object *obedit)
|
||||
{
|
||||
ParamHandle *handle = NULL;
|
||||
ParamHandle *handle = nullptr;
|
||||
BMEditMesh *em = BKE_editmesh_from_object(obedit);
|
||||
const bool abf = (scene->toolsettings->unwrapper == 0);
|
||||
bool use_subsurf;
|
||||
@@ -1232,34 +1235,33 @@ void ED_uvedit_live_unwrap_begin(Scene *scene, Object *obedit)
|
||||
return;
|
||||
}
|
||||
|
||||
const UnwrapOptions options = {
|
||||
.topology_from_uvs = false,
|
||||
.only_selected_faces = false,
|
||||
.only_selected_uvs = false,
|
||||
.fill_holes = (scene->toolsettings->uvcalc_flag & UVCALC_FILLHOLES) != 0,
|
||||
.correct_aspect = (scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT) == 0,
|
||||
};
|
||||
UnwrapOptions options{};
|
||||
options.topology_from_uvs = false;
|
||||
options.only_selected_faces = false;
|
||||
options.only_selected_uvs = false;
|
||||
options.fill_holes = (scene->toolsettings->uvcalc_flag & UVCALC_FILLHOLES) != 0;
|
||||
options.correct_aspect = (scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT) == 0;
|
||||
|
||||
if (use_subsurf) {
|
||||
handle = construct_param_handle_subsurfed(scene, obedit, em, &options, NULL);
|
||||
handle = construct_param_handle_subsurfed(scene, obedit, em, &options, nullptr);
|
||||
}
|
||||
else {
|
||||
handle = construct_param_handle(scene, obedit, em->bm, &options, NULL);
|
||||
handle = construct_param_handle(scene, obedit, em->bm, &options, nullptr);
|
||||
}
|
||||
|
||||
GEO_uv_parametrizer_lscm_begin(handle, true, abf);
|
||||
|
||||
/* Create or increase size of g_live_unwrap.handles array */
|
||||
if (g_live_unwrap.handles == NULL) {
|
||||
if (g_live_unwrap.handles == nullptr) {
|
||||
g_live_unwrap.len_alloc = 32;
|
||||
g_live_unwrap.handles = MEM_mallocN(sizeof(ParamHandle *) * g_live_unwrap.len_alloc,
|
||||
"uvedit_live_unwrap_liveHandles");
|
||||
g_live_unwrap.handles = static_cast<ParamHandle **>(MEM_mallocN(
|
||||
sizeof(ParamHandle *) * g_live_unwrap.len_alloc, "uvedit_live_unwrap_liveHandles"));
|
||||
g_live_unwrap.len = 0;
|
||||
}
|
||||
if (g_live_unwrap.len >= g_live_unwrap.len_alloc) {
|
||||
g_live_unwrap.len_alloc *= 2;
|
||||
g_live_unwrap.handles = MEM_reallocN(g_live_unwrap.handles,
|
||||
sizeof(ParamHandle *) * g_live_unwrap.len_alloc);
|
||||
g_live_unwrap.handles = static_cast<ParamHandle **>(
|
||||
MEM_reallocN(g_live_unwrap.handles, sizeof(ParamHandle *) * g_live_unwrap.len_alloc));
|
||||
}
|
||||
g_live_unwrap.handles[g_live_unwrap.len] = handle;
|
||||
g_live_unwrap.len++;
|
||||
@@ -1269,7 +1271,7 @@ void ED_uvedit_live_unwrap_re_solve(void)
|
||||
{
|
||||
if (g_live_unwrap.handles) {
|
||||
for (int i = 0; i < g_live_unwrap.len; i++) {
|
||||
GEO_uv_parametrizer_lscm_solve(g_live_unwrap.handles[i], NULL, NULL);
|
||||
GEO_uv_parametrizer_lscm_solve(g_live_unwrap.handles[i], nullptr, nullptr);
|
||||
GEO_uv_parametrizer_flush(g_live_unwrap.handles[i]);
|
||||
}
|
||||
}
|
||||
@@ -1286,7 +1288,7 @@ void ED_uvedit_live_unwrap_end(short cancel)
|
||||
GEO_uv_parametrizer_delete(g_live_unwrap.handles[i]);
|
||||
}
|
||||
MEM_freeN(g_live_unwrap.handles);
|
||||
g_live_unwrap.handles = NULL;
|
||||
g_live_unwrap.handles = nullptr;
|
||||
g_live_unwrap.len = 0;
|
||||
g_live_unwrap.len_alloc = 0;
|
||||
}
|
||||
@@ -1334,7 +1336,7 @@ static void uv_map_transform_calc_center_median(BMEditMesh *em, float r_center[3
|
||||
center_accum_num += 1;
|
||||
}
|
||||
}
|
||||
mul_v3_fl(r_center, 1.0f / (float)center_accum_num);
|
||||
mul_v3_fl(r_center, 1.0f / float(center_accum_num));
|
||||
}
|
||||
|
||||
static void uv_map_transform_center(const Scene *scene,
|
||||
@@ -1429,14 +1431,14 @@ static void uv_map_rotation_matrix_ex(float result[4][4],
|
||||
/* Compensate front/side.. against opengl x,y,z world definition.
|
||||
* This is "a sledgehammer to crack a nut" (overkill), a few plus minus 1 will do here.
|
||||
* I wanted to keep the reason here, so we're rotating. */
|
||||
sideangle = (float)M_PI * (sideangledeg + 180.0f) / 180.0f;
|
||||
sideangle = float(M_PI) * (sideangledeg + 180.0f) / 180.0f;
|
||||
rotside[0][0] = cosf(sideangle);
|
||||
rotside[0][1] = -sinf(sideangle);
|
||||
rotside[1][0] = sinf(sideangle);
|
||||
rotside[1][1] = cosf(sideangle);
|
||||
rotside[2][2] = 1.0f;
|
||||
|
||||
upangle = (float)M_PI * upangledeg / 180.0f;
|
||||
upangle = float(M_PI) * upangledeg / 180.0f;
|
||||
rotup[1][1] = cosf(upangle) / radius;
|
||||
rotup[1][2] = -sinf(upangle) / radius;
|
||||
rotup[2][1] = sinf(upangle) / radius;
|
||||
@@ -1490,18 +1492,18 @@ static void uv_transform_properties(wmOperatorType *ot, int radius)
|
||||
0,
|
||||
"Align to Object",
|
||||
"Align according to object transform"},
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
{0, nullptr, 0, nullptr, nullptr},
|
||||
};
|
||||
static const EnumPropertyItem align_items[] = {
|
||||
{POLAR_ZX, "POLAR_ZX", 0, "Polar ZX", "Polar 0 is X"},
|
||||
{POLAR_ZY, "POLAR_ZY", 0, "Polar ZY", "Polar 0 is Y"},
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
{0, nullptr, 0, nullptr, nullptr},
|
||||
};
|
||||
|
||||
static const EnumPropertyItem pole_items[] = {
|
||||
{PINCH, "PINCH", 0, "Pinch", "UVs are pinched at the poles"},
|
||||
{FAN, "FAN", 0, "Fan", "UVs are fanned at the poles"},
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
{0, nullptr, 0, nullptr, nullptr},
|
||||
};
|
||||
|
||||
RNA_def_enum(ot->srna,
|
||||
@@ -1577,9 +1579,8 @@ static void correct_uv_aspect_per_face(Object *ob, BMEditMesh *em)
|
||||
return;
|
||||
}
|
||||
|
||||
float *material_aspect_y = BLI_array_alloca(material_aspect_y, materials_num);
|
||||
blender::Array<float, 16> material_aspect_y(materials_num, -1);
|
||||
/* Lazily initialize aspect ratio for materials. */
|
||||
copy_vn_fl(material_aspect_y, materials_num, -1.0f);
|
||||
|
||||
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_PROP_FLOAT2);
|
||||
|
||||
@@ -1803,8 +1804,8 @@ static void uvedit_unwrap(const Scene *scene,
|
||||
|
||||
GEO_uv_parametrizer_lscm_begin(handle, false, scene->toolsettings->unwrapper == 0);
|
||||
GEO_uv_parametrizer_lscm_solve(handle,
|
||||
result_info ? &result_info->count_changed : NULL,
|
||||
result_info ? &result_info->count_failed : NULL);
|
||||
result_info ? &result_info->count_changed : nullptr,
|
||||
result_info ? &result_info->count_failed : nullptr);
|
||||
GEO_uv_parametrizer_lscm_end(handle);
|
||||
|
||||
GEO_uv_parametrizer_average(handle, true, false, false);
|
||||
@@ -1823,7 +1824,7 @@ static void uvedit_unwrap_multi(const Scene *scene,
|
||||
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
|
||||
Object *obedit = objects[ob_index];
|
||||
uvedit_unwrap(scene, obedit, options, result_info);
|
||||
DEG_id_tag_update(obedit->data, ID_RECALC_GEOMETRY);
|
||||
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_GEOMETRY);
|
||||
WM_main_add_notifier(NC_GEOM | ND_DATA, obedit->data);
|
||||
}
|
||||
}
|
||||
@@ -1831,27 +1832,28 @@ static void uvedit_unwrap_multi(const Scene *scene,
|
||||
void ED_uvedit_live_unwrap(const Scene *scene, Object **objects, int objects_len)
|
||||
{
|
||||
if (scene->toolsettings->edge_mode_live_unwrap) {
|
||||
const UnwrapOptions options = {
|
||||
.topology_from_uvs = false,
|
||||
.only_selected_faces = false,
|
||||
.only_selected_uvs = false,
|
||||
.fill_holes = (scene->toolsettings->uvcalc_flag & UVCALC_FILLHOLES) != 0,
|
||||
.correct_aspect = (scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT) == 0,
|
||||
};
|
||||
uvedit_unwrap_multi(scene, objects, objects_len, &options, NULL);
|
||||
UnwrapOptions options{};
|
||||
options.topology_from_uvs = false;
|
||||
options.only_selected_faces = false;
|
||||
options.only_selected_uvs = false;
|
||||
options.fill_holes = (scene->toolsettings->uvcalc_flag & UVCALC_FILLHOLES) != 0;
|
||||
options.correct_aspect = (scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT) == 0;
|
||||
uvedit_unwrap_multi(scene, objects, objects_len, &options, nullptr);
|
||||
|
||||
const struct UVPackIsland_Params pack_island_params = {
|
||||
.rotate = true,
|
||||
.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,
|
||||
.ignore_pinned = true,
|
||||
.pin_unselected = options.pin_unselected,
|
||||
.margin_method = ED_UVPACK_MARGIN_SCALED,
|
||||
.margin = scene->toolsettings->uvcalc_margin,
|
||||
};
|
||||
ED_uvedit_pack_islands_multi(scene, objects, objects_len, NULL, NULL, &pack_island_params);
|
||||
UVPackIsland_Params pack_island_params{};
|
||||
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,
|
||||
|
||||
ED_uvedit_pack_islands_multi(
|
||||
scene, objects, objects_len, nullptr, nullptr, &pack_island_params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1875,13 +1877,12 @@ static int unwrap_exec(bContext *C, wmOperator *op)
|
||||
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
|
||||
scene, view_layer, CTX_wm_view3d(C), &objects_len);
|
||||
|
||||
UnwrapOptions options = {
|
||||
.topology_from_uvs = false,
|
||||
.only_selected_faces = true,
|
||||
.only_selected_uvs = false,
|
||||
.fill_holes = RNA_boolean_get(op->ptr, "fill_holes"),
|
||||
.correct_aspect = RNA_boolean_get(op->ptr, "correct_aspect"),
|
||||
};
|
||||
UnwrapOptions options{};
|
||||
options.topology_from_uvs = false;
|
||||
options.only_selected_faces = true;
|
||||
options.only_selected_uvs = false;
|
||||
options.fill_holes = RNA_boolean_get(op->ptr, "fill_holes");
|
||||
options.correct_aspect = RNA_boolean_get(op->ptr, "correct_aspect");
|
||||
|
||||
if (CTX_wm_space_image(C)) {
|
||||
/* Inside the UV Editor, only unwrap selected UVs. */
|
||||
@@ -1982,24 +1983,24 @@ static int unwrap_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
|
||||
/* execute unwrap */
|
||||
UnwrapResultInfo result_info = {
|
||||
.count_changed = 0,
|
||||
.count_failed = 0,
|
||||
};
|
||||
UnwrapResultInfo result_info{};
|
||||
result_info.count_changed = 0;
|
||||
result_info.count_failed = 0;
|
||||
uvedit_unwrap_multi(scene, objects, objects_len, &options, &result_info);
|
||||
|
||||
const struct UVPackIsland_Params pack_island_params = {
|
||||
.rotate = true,
|
||||
.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,
|
||||
.ignore_pinned = true,
|
||||
.pin_unselected = options.pin_unselected,
|
||||
.margin_method = RNA_enum_get(op->ptr, "margin_method"),
|
||||
.margin = RNA_float_get(op->ptr, "margin"),
|
||||
};
|
||||
ED_uvedit_pack_islands_multi(scene, objects, objects_len, NULL, NULL, &pack_island_params);
|
||||
UVPackIsland_Params pack_island_params{};
|
||||
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");
|
||||
|
||||
ED_uvedit_pack_islands_multi(scene, objects, objects_len, nullptr, nullptr, &pack_island_params);
|
||||
|
||||
MEM_freeN(objects);
|
||||
|
||||
@@ -2024,7 +2025,7 @@ void UV_OT_unwrap(wmOperatorType *ot)
|
||||
static const EnumPropertyItem method_items[] = {
|
||||
{0, "ANGLE_BASED", 0, "Angle Based", ""},
|
||||
{1, "CONFORMAL", 0, "Conformal", ""},
|
||||
{0, NULL, 0, NULL, NULL},
|
||||
{0, nullptr, 0, nullptr, nullptr},
|
||||
};
|
||||
|
||||
/* identifiers */
|
||||
@@ -2081,10 +2082,10 @@ void UV_OT_unwrap(wmOperatorType *ot)
|
||||
/* Ignore all areas below this, as the UVs get zeroed. */
|
||||
static const float smart_uv_project_area_ignore = 1e-12f;
|
||||
|
||||
typedef struct ThickFace {
|
||||
struct ThickFace {
|
||||
float area;
|
||||
BMFace *efa;
|
||||
} ThickFace;
|
||||
};
|
||||
|
||||
static int smart_uv_project_thickface_area_cmp_fn(const void *tf_a_p, const void *tf_b_p)
|
||||
{
|
||||
@@ -2107,26 +2108,22 @@ static int smart_uv_project_thickface_area_cmp_fn(const void *tf_a_p, const void
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint smart_uv_project_calculate_project_normals(const ThickFace *thick_faces,
|
||||
const uint thick_faces_len,
|
||||
BMesh *bm,
|
||||
const float project_angle_limit_half_cos,
|
||||
const float project_angle_limit_cos,
|
||||
const float area_weight,
|
||||
float (**r_project_normal_array)[3])
|
||||
static blender::Vector<blender::float3> smart_uv_project_calculate_project_normals(
|
||||
const ThickFace *thick_faces,
|
||||
const uint thick_faces_len,
|
||||
BMesh *bm,
|
||||
const float project_angle_limit_half_cos,
|
||||
const float project_angle_limit_cos,
|
||||
const float area_weight)
|
||||
{
|
||||
if (UNLIKELY(thick_faces_len == 0)) {
|
||||
*r_project_normal_array = NULL;
|
||||
return 0;
|
||||
return {};
|
||||
}
|
||||
|
||||
const float *project_normal = thick_faces[0].efa->no;
|
||||
|
||||
const ThickFace **project_thick_faces = NULL;
|
||||
BLI_array_declare(project_thick_faces);
|
||||
|
||||
float(*project_normal_array)[3] = NULL;
|
||||
BLI_array_declare(project_normal_array);
|
||||
blender::Vector<const ThickFace *> project_thick_faces;
|
||||
blender::Vector<blender::float3> project_normal_array;
|
||||
|
||||
BM_mesh_elem_hflag_disable_all(bm, BM_FACE, BM_ELEM_TAG, false);
|
||||
|
||||
@@ -2137,7 +2134,7 @@ static uint smart_uv_project_calculate_project_normals(const ThickFace *thick_fa
|
||||
}
|
||||
|
||||
if (dot_v3v3(thick_faces[f_index].efa->no, project_normal) > project_angle_limit_half_cos) {
|
||||
BLI_array_append(project_thick_faces, &thick_faces[f_index]);
|
||||
project_thick_faces.append(&thick_faces[f_index]);
|
||||
BM_elem_flag_set(thick_faces[f_index].efa, BM_ELEM_TAG, true);
|
||||
}
|
||||
}
|
||||
@@ -2145,22 +2142,19 @@ static uint smart_uv_project_calculate_project_normals(const ThickFace *thick_fa
|
||||
float average_normal[3] = {0.0f, 0.0f, 0.0f};
|
||||
|
||||
if (area_weight <= 0.0f) {
|
||||
for (int f_proj_index = 0; f_proj_index < BLI_array_len(project_thick_faces);
|
||||
f_proj_index++) {
|
||||
for (int f_proj_index = 0; f_proj_index < project_thick_faces.size(); f_proj_index++) {
|
||||
const ThickFace *tf = project_thick_faces[f_proj_index];
|
||||
add_v3_v3(average_normal, tf->efa->no);
|
||||
}
|
||||
}
|
||||
else if (area_weight >= 1.0f) {
|
||||
for (int f_proj_index = 0; f_proj_index < BLI_array_len(project_thick_faces);
|
||||
f_proj_index++) {
|
||||
for (int f_proj_index = 0; f_proj_index < project_thick_faces.size(); f_proj_index++) {
|
||||
const ThickFace *tf = project_thick_faces[f_proj_index];
|
||||
madd_v3_v3fl(average_normal, tf->efa->no, tf->area);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int f_proj_index = 0; f_proj_index < BLI_array_len(project_thick_faces);
|
||||
f_proj_index++) {
|
||||
for (int f_proj_index = 0; f_proj_index < project_thick_faces.size(); f_proj_index++) {
|
||||
const ThickFace *tf = project_thick_faces[f_proj_index];
|
||||
const float area_blend = (tf->area * area_weight) + (1.0f - area_weight);
|
||||
madd_v3_v3fl(average_normal, tf->efa->no, area_blend);
|
||||
@@ -2169,8 +2163,7 @@ static uint smart_uv_project_calculate_project_normals(const ThickFace *thick_fa
|
||||
|
||||
/* Avoid NAN. */
|
||||
if (normalize_v3(average_normal) != 0.0f) {
|
||||
float(*normal)[3] = BLI_array_append_ret(project_normal_array);
|
||||
copy_v3_v3(*normal, average_normal);
|
||||
project_normal_array.append(average_normal);
|
||||
}
|
||||
|
||||
/* Find the most unique angle that points away from other normals. */
|
||||
@@ -2183,7 +2176,7 @@ static uint smart_uv_project_calculate_project_normals(const ThickFace *thick_fa
|
||||
}
|
||||
|
||||
float angle_test = -1.0f;
|
||||
for (int p_index = 0; p_index < BLI_array_len(project_normal_array); p_index++) {
|
||||
for (int p_index = 0; p_index < project_normal_array.size(); p_index++) {
|
||||
angle_test = max_ff(angle_test,
|
||||
dot_v3v3(project_normal_array[p_index], thick_faces[f_index].efa->no));
|
||||
}
|
||||
@@ -2196,22 +2189,20 @@ static uint smart_uv_project_calculate_project_normals(const ThickFace *thick_fa
|
||||
|
||||
if (anble_best < project_angle_limit_cos) {
|
||||
project_normal = thick_faces[angle_best_index].efa->no;
|
||||
BLI_array_clear(project_thick_faces);
|
||||
BLI_array_append(project_thick_faces, &thick_faces[angle_best_index]);
|
||||
project_thick_faces.clear();
|
||||
project_thick_faces.append(&thick_faces[angle_best_index]);
|
||||
BM_elem_flag_enable(thick_faces[angle_best_index].efa, BM_ELEM_TAG);
|
||||
}
|
||||
else {
|
||||
if (BLI_array_len(project_normal_array) >= 1) {
|
||||
if (project_normal_array.size() >= 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BLI_array_free(project_thick_faces);
|
||||
BM_mesh_elem_hflag_disable_all(bm, BM_FACE, BM_ELEM_TAG, false);
|
||||
|
||||
*r_project_normal_array = project_normal_array;
|
||||
return BLI_array_len(project_normal_array);
|
||||
return project_normal_array;
|
||||
}
|
||||
|
||||
static int smart_project_exec(bContext *C, wmOperator *op)
|
||||
@@ -2219,7 +2210,7 @@ static int smart_project_exec(bContext *C, wmOperator *op)
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
|
||||
/* May be NULL. */
|
||||
/* May be nullptr. */
|
||||
View3D *v3d = CTX_wm_view3d(C);
|
||||
|
||||
bool only_selected_uvs = false;
|
||||
@@ -2242,7 +2233,8 @@ static int smart_project_exec(bContext *C, wmOperator *op)
|
||||
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
|
||||
scene, view_layer, v3d, &objects_len);
|
||||
|
||||
Object **objects_changed = MEM_mallocN(sizeof(*objects_changed) * objects_len, __func__);
|
||||
Object **objects_changed = static_cast<Object **>(
|
||||
MEM_mallocN(sizeof(*objects_changed) * objects_len, __func__));
|
||||
uint object_changed_len = 0;
|
||||
|
||||
BMFace *efa;
|
||||
@@ -2260,7 +2252,8 @@ static int smart_project_exec(bContext *C, wmOperator *op)
|
||||
|
||||
const BMUVOffsets offsets = BM_uv_map_get_offsets(em->bm);
|
||||
BLI_assert(offsets.uv >= 0);
|
||||
ThickFace *thick_faces = MEM_mallocN(sizeof(*thick_faces) * em->bm->totface, __func__);
|
||||
ThickFace *thick_faces = static_cast<ThickFace *>(
|
||||
MEM_mallocN(sizeof(*thick_faces) * em->bm->totface, __func__));
|
||||
|
||||
uint thick_faces_len = 0;
|
||||
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
|
||||
@@ -2298,25 +2291,23 @@ static int smart_project_exec(bContext *C, wmOperator *op)
|
||||
thick_faces_len -= 1;
|
||||
}
|
||||
|
||||
float(*project_normal_array)[3] = NULL;
|
||||
int project_normals_len = smart_uv_project_calculate_project_normals(
|
||||
thick_faces,
|
||||
thick_faces_len,
|
||||
em->bm,
|
||||
project_angle_limit_half_cos,
|
||||
project_angle_limit_cos,
|
||||
area_weight,
|
||||
&project_normal_array);
|
||||
blender::Vector<blender::float3> project_normal_array =
|
||||
smart_uv_project_calculate_project_normals(thick_faces,
|
||||
thick_faces_len,
|
||||
em->bm,
|
||||
project_angle_limit_half_cos,
|
||||
project_angle_limit_cos,
|
||||
area_weight);
|
||||
|
||||
if (project_normals_len == 0) {
|
||||
if (project_normal_array.size() == 0) {
|
||||
MEM_freeN(thick_faces);
|
||||
BLI_assert(project_normal_array == NULL);
|
||||
BLI_assert(project_normal_array == nullptr);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* After finding projection vectors, we find the uv positions. */
|
||||
LinkNode **thickface_project_groups = MEM_callocN(
|
||||
sizeof(*thickface_project_groups) * project_normals_len, __func__);
|
||||
LinkNode **thickface_project_groups = static_cast<LinkNode **>(
|
||||
MEM_callocN(sizeof(*thickface_project_groups) * project_normal_array.size(), __func__));
|
||||
|
||||
BLI_memarena_clear(arena);
|
||||
|
||||
@@ -2326,7 +2317,7 @@ static int smart_project_exec(bContext *C, wmOperator *op)
|
||||
float angle_best = dot_v3v3(f_normal, project_normal_array[0]);
|
||||
uint angle_best_index = 0;
|
||||
|
||||
for (int p_index = 1; p_index < project_normals_len; p_index++) {
|
||||
for (int p_index = 1; p_index < project_normal_array.size(); p_index++) {
|
||||
const float angle_test = dot_v3v3(f_normal, project_normal_array[p_index]);
|
||||
if (angle_test > angle_best) {
|
||||
angle_best = angle_test;
|
||||
@@ -2338,8 +2329,8 @@ static int smart_project_exec(bContext *C, wmOperator *op)
|
||||
&thickface_project_groups[angle_best_index], &thick_faces[f_index], arena);
|
||||
}
|
||||
|
||||
for (int p_index = 0; p_index < project_normals_len; p_index++) {
|
||||
if (thickface_project_groups[p_index] == NULL) {
|
||||
for (int p_index = 0; p_index < project_normal_array.size(); p_index++) {
|
||||
if (thickface_project_groups[p_index] == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -2347,7 +2338,7 @@ static int smart_project_exec(bContext *C, wmOperator *op)
|
||||
axis_dominant_v3_to_m3(axis_mat, project_normal_array[p_index]);
|
||||
|
||||
for (LinkNode *list = thickface_project_groups[p_index]; list; list = list->next) {
|
||||
ThickFace *tf = list->link;
|
||||
ThickFace *tf = static_cast<ThickFace *>(list->link);
|
||||
BMIter liter;
|
||||
BMLoop *l;
|
||||
BM_ITER_ELEM (l, &liter, tf->efa, BM_LOOPS_OF_FACE) {
|
||||
@@ -2359,7 +2350,6 @@ static int smart_project_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
|
||||
MEM_freeN(thick_faces);
|
||||
MEM_freeN(project_normal_array);
|
||||
|
||||
/* No need to free the lists in 'thickface_project_groups' values as the 'arena' is used. */
|
||||
MEM_freeN(thickface_project_groups);
|
||||
@@ -2382,16 +2372,17 @@ 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");
|
||||
|
||||
const struct UVPackIsland_Params params = {
|
||||
.rotate = true,
|
||||
.only_selected_uvs = only_selected_uvs,
|
||||
.only_selected_faces = true,
|
||||
.correct_aspect = correct_aspect,
|
||||
.use_seams = true,
|
||||
.margin_method = RNA_enum_get(op->ptr, "margin_method"),
|
||||
.margin = RNA_float_get(op->ptr, "island_margin"),
|
||||
};
|
||||
ED_uvedit_pack_islands_multi(scene, objects_changed, object_changed_len, NULL, NULL, ¶ms);
|
||||
UVPackIsland_Params params{};
|
||||
params.rotate = true;
|
||||
params.only_selected_uvs = only_selected_uvs;
|
||||
params.only_selected_faces = true;
|
||||
params.correct_aspect = correct_aspect;
|
||||
params.use_seams = true;
|
||||
params.margin_method = eUVPackIsland_MarginMethod(RNA_enum_get(op->ptr, "margin_method"));
|
||||
params.margin = RNA_float_get(op->ptr, "island_margin");
|
||||
|
||||
ED_uvedit_pack_islands_multi(
|
||||
scene, objects_changed, object_changed_len, nullptr, nullptr, ¶ms);
|
||||
|
||||
/* #ED_uvedit_pack_islands_multi only supports `per_face_aspect = false`. */
|
||||
const bool per_face_aspect = false;
|
||||
@@ -2424,7 +2415,7 @@ void UV_OT_smart_project(wmOperatorType *ot)
|
||||
prop = RNA_def_float_rotation(ot->srna,
|
||||
"angle_limit",
|
||||
0,
|
||||
NULL,
|
||||
nullptr,
|
||||
DEG2RADF(0.0f),
|
||||
DEG2RADF(90.0f),
|
||||
"Angle Limit",
|
||||
@@ -2469,7 +2460,7 @@ void UV_OT_smart_project(wmOperatorType *ot)
|
||||
|
||||
static int uv_from_view_exec(bContext *C, wmOperator *op);
|
||||
|
||||
static int uv_from_view_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
|
||||
static int uv_from_view_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
|
||||
{
|
||||
View3D *v3d = CTX_wm_view3d(C);
|
||||
RegionView3D *rv3d = CTX_wm_region_view3d(C);
|
||||
@@ -2478,11 +2469,11 @@ static int uv_from_view_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE
|
||||
|
||||
prop = RNA_struct_find_property(op->ptr, "camera_bounds");
|
||||
if (!RNA_property_is_set(op->ptr, prop)) {
|
||||
RNA_property_boolean_set(op->ptr, prop, (camera != NULL));
|
||||
RNA_property_boolean_set(op->ptr, prop, (camera != nullptr));
|
||||
}
|
||||
prop = RNA_struct_find_property(op->ptr, "correct_aspect");
|
||||
if (!RNA_property_is_set(op->ptr, prop)) {
|
||||
RNA_property_boolean_set(op->ptr, prop, (camera == NULL));
|
||||
RNA_property_boolean_set(op->ptr, prop, (camera == nullptr));
|
||||
}
|
||||
|
||||
return uv_from_view_exec(C, op);
|
||||
@@ -2505,7 +2496,7 @@ static int uv_from_view_exec(bContext *C, wmOperator *op)
|
||||
|
||||
const bool use_orthographic = RNA_boolean_get(op->ptr, "orthographic");
|
||||
|
||||
/* NOTE: objects that aren't touched are set to NULL (to skip clipping). */
|
||||
/* NOTE: objects that aren't touched are set to nullptr (to skip clipping). */
|
||||
uint objects_len = 0;
|
||||
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
|
||||
scene, view_layer, v3d, &objects_len);
|
||||
@@ -2551,7 +2542,7 @@ static int uv_from_view_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
else if (camera) {
|
||||
const bool camera_bounds = RNA_boolean_get(op->ptr, "camera_bounds");
|
||||
struct ProjCameraInfo *uci = BLI_uvproject_camera_info(
|
||||
ProjCameraInfo *uci = BLI_uvproject_camera_info(
|
||||
v3d->camera,
|
||||
obedit->object_to_world,
|
||||
camera_bounds ? (scene->r.xsch * scene->r.xasp) : 1.0f,
|
||||
@@ -2592,7 +2583,7 @@ static int uv_from_view_exec(bContext *C, wmOperator *op)
|
||||
|
||||
if (changed) {
|
||||
changed_multi = true;
|
||||
DEG_id_tag_update(obedit->data, ID_RECALC_GEOMETRY);
|
||||
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_GEOMETRY);
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
|
||||
}
|
||||
else {
|
||||
@@ -2624,7 +2615,7 @@ static bool uv_from_view_poll(bContext *C)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (rv3d != NULL);
|
||||
return (rv3d != nullptr);
|
||||
}
|
||||
|
||||
void UV_OT_project_from_view(wmOperatorType *ot)
|
||||
@@ -2657,7 +2648,7 @@ void UV_OT_project_from_view(wmOperatorType *ot)
|
||||
/** \name Reset UV Operator
|
||||
* \{ */
|
||||
|
||||
static int reset_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
static int reset_exec(bContext *C, wmOperator * /*op*/)
|
||||
{
|
||||
const Scene *scene = CTX_data_scene(C);
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
@@ -2682,7 +2673,7 @@ static int reset_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
|
||||
ED_mesh_uv_loop_reset(C, me);
|
||||
|
||||
DEG_id_tag_update(obedit->data, ID_RECALC_GEOMETRY);
|
||||
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_GEOMETRY);
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
|
||||
}
|
||||
MEM_freeN(objects);
|
||||
@@ -2731,7 +2722,7 @@ static void uv_map_mirror(BMFace *efa,
|
||||
float right_u = -1.0e30f;
|
||||
BMLoop *l;
|
||||
BMIter liter;
|
||||
float **uvs = BLI_array_alloca(uvs, efa->len);
|
||||
blender::Array<float *, BM_DEFAULT_NGON_STACK_SIZE> uvs(efa->len);
|
||||
int j;
|
||||
BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, j) {
|
||||
float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
|
||||
@@ -2811,7 +2802,7 @@ static void uv_sphere_project(BMFace *efa,
|
||||
const bool fan,
|
||||
const int cd_loop_uv_offset)
|
||||
{
|
||||
bool *regular = BLI_array_alloca(regular, efa->len);
|
||||
blender::Array<bool, BM_DEFAULT_NGON_STACK_SIZE> regular(efa->len);
|
||||
int i;
|
||||
BMLoop *l;
|
||||
BMIter iter;
|
||||
@@ -2823,7 +2814,7 @@ static void uv_sphere_project(BMFace *efa,
|
||||
regular[i] = map_to_sphere(&luv[0], &luv[1], pv[0], pv[1], pv[2]);
|
||||
}
|
||||
|
||||
uv_map_mirror(efa, regular, fan, cd_loop_uv_offset);
|
||||
uv_map_mirror(efa, regular.data(), fan, cd_loop_uv_offset);
|
||||
}
|
||||
|
||||
static int sphere_project_exec(bContext *C, wmOperator *op)
|
||||
@@ -2860,7 +2851,7 @@ static int sphere_project_exec(bContext *C, wmOperator *op)
|
||||
float center[3], rotmat[3][3];
|
||||
|
||||
uv_map_transform(C, op, rotmat);
|
||||
uv_map_transform_center(scene, v3d, obedit, em, center, NULL);
|
||||
uv_map_transform_center(scene, v3d, obedit, em, center, nullptr);
|
||||
|
||||
const bool fan = RNA_enum_get(op->ptr, "pole");
|
||||
|
||||
@@ -2882,7 +2873,7 @@ static int sphere_project_exec(bContext *C, wmOperator *op)
|
||||
const bool per_face_aspect = true;
|
||||
uv_map_clip_correct(scene, &obedit, 1, op, per_face_aspect, only_selected_uvs);
|
||||
|
||||
DEG_id_tag_update(obedit->data, ID_RECALC_GEOMETRY);
|
||||
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_GEOMETRY);
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
|
||||
}
|
||||
MEM_freeN(objects);
|
||||
@@ -2920,7 +2911,7 @@ static void uv_cylinder_project(BMFace *efa,
|
||||
const bool fan,
|
||||
const int cd_loop_uv_offset)
|
||||
{
|
||||
bool *regular = BLI_array_alloca(regular, efa->len);
|
||||
blender::Array<bool, BM_DEFAULT_NGON_STACK_SIZE> regular(efa->len);
|
||||
int i;
|
||||
BMLoop *l;
|
||||
BMIter iter;
|
||||
@@ -2932,7 +2923,7 @@ static void uv_cylinder_project(BMFace *efa,
|
||||
regular[i] = map_to_tube(&luv[0], &luv[1], pv[0], pv[1], pv[2]);
|
||||
}
|
||||
|
||||
uv_map_mirror(efa, regular, fan, cd_loop_uv_offset);
|
||||
uv_map_mirror(efa, regular.data(), fan, cd_loop_uv_offset);
|
||||
}
|
||||
|
||||
static int cylinder_project_exec(bContext *C, wmOperator *op)
|
||||
@@ -2969,7 +2960,7 @@ static int cylinder_project_exec(bContext *C, wmOperator *op)
|
||||
float center[3], rotmat[3][3];
|
||||
|
||||
uv_map_transform(C, op, rotmat);
|
||||
uv_map_transform_center(scene, v3d, obedit, em, center, NULL);
|
||||
uv_map_transform_center(scene, v3d, obedit, em, center, nullptr);
|
||||
|
||||
const bool fan = RNA_enum_get(op->ptr, "pole");
|
||||
|
||||
@@ -2989,7 +2980,7 @@ static int cylinder_project_exec(bContext *C, wmOperator *op)
|
||||
const bool per_face_aspect = true;
|
||||
uv_map_clip_correct(scene, &obedit, 1, op, per_face_aspect, only_selected_uvs);
|
||||
|
||||
DEG_id_tag_update(obedit->data, ID_RECALC_GEOMETRY);
|
||||
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_GEOMETRY);
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
|
||||
}
|
||||
MEM_freeN(objects);
|
||||
@@ -3101,7 +3092,7 @@ static int cube_project_exec(bContext *C, wmOperator *op)
|
||||
}
|
||||
|
||||
float bounds[2][3];
|
||||
float(*bounds_buf)[3] = NULL;
|
||||
float(*bounds_buf)[3] = nullptr;
|
||||
|
||||
if (!RNA_property_is_set(op->ptr, prop_cube_size)) {
|
||||
bounds_buf = bounds;
|
||||
@@ -3127,7 +3118,7 @@ static int cube_project_exec(bContext *C, wmOperator *op)
|
||||
const bool per_face_aspect = true;
|
||||
uv_map_clip_correct(scene, &obedit, 1, op, per_face_aspect, only_selected_uvs);
|
||||
|
||||
DEG_id_tag_update(obedit->data, ID_RECALC_GEOMETRY);
|
||||
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_GEOMETRY);
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
|
||||
}
|
||||
MEM_freeN(objects);
|
||||
@@ -3169,45 +3160,44 @@ void UV_OT_cube_project(wmOperatorType *ot)
|
||||
|
||||
void ED_uvedit_add_simple_uvs(Main *bmain, const Scene *scene, Object *ob)
|
||||
{
|
||||
Mesh *me = ob->data;
|
||||
Mesh *me = static_cast<Mesh *>(ob->data);
|
||||
bool sync_selection = (scene->toolsettings->uv_flag & UV_SYNC_SELECTION) != 0;
|
||||
|
||||
BMesh *bm = BM_mesh_create(&bm_mesh_allocsize_default,
|
||||
&((struct BMeshCreateParams){
|
||||
.use_toolflags = false,
|
||||
}));
|
||||
BMeshCreateParams create_params{};
|
||||
create_params.use_toolflags = false;
|
||||
BMesh *bm = BM_mesh_create(&bm_mesh_allocsize_default, &create_params);
|
||||
|
||||
/* turn sync selection off,
|
||||
* since we are not in edit mode we need to ensure only the uv flags are tested */
|
||||
scene->toolsettings->uv_flag &= ~UV_SYNC_SELECTION;
|
||||
|
||||
ED_mesh_uv_ensure(me, NULL);
|
||||
ED_mesh_uv_ensure(me, nullptr);
|
||||
|
||||
BMeshFromMeshParams bm_from_me_params{};
|
||||
bm_from_me_params.calc_face_normal = true;
|
||||
bm_from_me_params.calc_vert_normal = true;
|
||||
BM_mesh_bm_from_me(bm, me, &bm_from_me_params);
|
||||
|
||||
BM_mesh_bm_from_me(bm,
|
||||
me,
|
||||
(&(struct BMeshFromMeshParams){
|
||||
.calc_face_normal = true,
|
||||
.calc_vert_normal = true,
|
||||
}));
|
||||
/* Select all UVs for cube_project. */
|
||||
ED_uvedit_select_all(bm);
|
||||
/* A cube size of 2.0 maps [-1..1] vertex coords to [0.0..1.0] in UV coords. */
|
||||
uvedit_unwrap_cube_project(scene, bm, 2.0, false, false, NULL);
|
||||
uvedit_unwrap_cube_project(scene, bm, 2.0, false, false, nullptr);
|
||||
|
||||
/* Pack UVs. */
|
||||
const struct UVPackIsland_Params params = {
|
||||
.rotate = true,
|
||||
.only_selected_uvs = false,
|
||||
.only_selected_faces = false,
|
||||
.correct_aspect = false,
|
||||
.use_seams = true,
|
||||
.margin_method = ED_UVPACK_MARGIN_SCALED,
|
||||
.margin = 0.001f,
|
||||
};
|
||||
ED_uvedit_pack_islands_multi(scene, &ob, 1, &bm, NULL, ¶ms);
|
||||
UVPackIsland_Params params{};
|
||||
params.rotate = true;
|
||||
params.only_selected_uvs = false;
|
||||
params.only_selected_faces = false;
|
||||
params.correct_aspect = false;
|
||||
params.use_seams = true;
|
||||
params.margin_method = ED_UVPACK_MARGIN_SCALED;
|
||||
params.margin = 0.001f;
|
||||
|
||||
ED_uvedit_pack_islands_multi(scene, &ob, 1, &bm, nullptr, ¶ms);
|
||||
|
||||
/* Write back from BMesh to Mesh. */
|
||||
BM_mesh_bm_to_me(bmain, bm, me, (&(struct BMeshToMeshParams){0}));
|
||||
BMeshToMeshParams bm_to_me_params{};
|
||||
BM_mesh_bm_to_me(bmain, bm, me, &bm_to_me_params);
|
||||
BM_mesh_free(bm);
|
||||
|
||||
if (sync_selection) {
|
||||
Reference in New Issue
Block a user