Cleanup: Use attribute API and StringRef in bake code
Ref #122398 Pull Request: https://projects.blender.org/blender/blender/pulls/146547
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include "BLI_listbase.h"
|
||||
#include "BLI_math_geom.h"
|
||||
#include "BLI_path_utils.hh"
|
||||
#include "BLI_string_ref.hh"
|
||||
#include "BLI_string_utf8.h"
|
||||
|
||||
#include "BLT_translation.hh"
|
||||
@@ -97,7 +98,7 @@ struct BakeAPIRender {
|
||||
int normal_space;
|
||||
eBakeNormalSwizzle normal_swizzle[3];
|
||||
|
||||
char uv_layer[MAX_CUSTOMDATA_LAYER_NAME];
|
||||
std::string uv_layer;
|
||||
char custom_cage[MAX_NAME];
|
||||
|
||||
/* Settings for external image saving. */
|
||||
@@ -220,7 +221,7 @@ static bool write_internal_bake_pixels(Image *image,
|
||||
const bool is_noncolor,
|
||||
const bool is_tangent_normal,
|
||||
Mesh const *mesh_eval,
|
||||
char const *uv_layer,
|
||||
const StringRef uv_layer,
|
||||
const float uv_offset[2])
|
||||
{
|
||||
ImBuf *ibuf;
|
||||
@@ -368,7 +369,7 @@ static bool write_external_bake_pixels(const char *filepath,
|
||||
const bool is_noncolor,
|
||||
const bool is_tangent_normal,
|
||||
Mesh const *mesh_eval,
|
||||
char const *uv_layer,
|
||||
const StringRef uv_layer,
|
||||
const float uv_offset[2])
|
||||
{
|
||||
ImBuf *ibuf = nullptr;
|
||||
@@ -1452,13 +1453,16 @@ static wmOperatorStatus bake(const BakeAPIRender *bkr,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (bkr->uv_layer[0] != '\0') {
|
||||
if (!bkr->uv_layer.empty()) {
|
||||
Mesh *mesh = (Mesh *)ob_low->data;
|
||||
if (CustomData_get_named_layer(&mesh->corner_data, CD_PROP_FLOAT2, bkr->uv_layer) == -1) {
|
||||
const bke::AttributeAccessor attributes = mesh->attributes();
|
||||
const std::optional<bke::AttributeMetaData> meta_data = attributes.lookup_meta_data(
|
||||
bkr->uv_layer);
|
||||
if (meta_data != bke::AttributeMetaData{bke::AttrDomain::Corner, bke::AttrType::Float2}) {
|
||||
BKE_reportf(reports,
|
||||
RPT_ERROR,
|
||||
"No UV layer named \"%s\" found in the object \"%s\"",
|
||||
bkr->uv_layer,
|
||||
bkr->uv_layer.c_str(),
|
||||
ob_low->id.name + 2);
|
||||
goto cleanup;
|
||||
}
|
||||
@@ -1904,7 +1908,7 @@ static void bake_init_api_data(wmOperator *op, bContext *C, BakeAPIRender *bkr)
|
||||
bkr->height = RNA_int_get(op->ptr, "height");
|
||||
bkr->identifier = "";
|
||||
|
||||
RNA_string_get(op->ptr, "uv_layer", bkr->uv_layer);
|
||||
bkr->uv_layer = RNA_string_get(op->ptr, "uv_layer");
|
||||
|
||||
RNA_string_get(op->ptr, "cage_object", bkr->custom_cage);
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BLI_string_ref.hh"
|
||||
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
#include "RE_pipeline.h"
|
||||
@@ -100,7 +102,7 @@ void RE_bake_pixels_populate(struct Mesh *mesh,
|
||||
struct BakePixel *pixel_array,
|
||||
size_t pixels_num,
|
||||
const struct BakeTargets *targets,
|
||||
const char *uv_layer);
|
||||
blender::StringRef uv_layer);
|
||||
|
||||
void RE_bake_mask_fill(const BakePixel pixel_array[], size_t pixels_num, char *mask);
|
||||
|
||||
@@ -109,7 +111,7 @@ void RE_bake_margin(struct ImBuf *ibuf,
|
||||
int margin,
|
||||
char margin_type,
|
||||
const Mesh *mesh,
|
||||
char const *uv_layer,
|
||||
blender::StringRef uv_layer,
|
||||
const float uv_offset[2]);
|
||||
|
||||
void RE_bake_normal_world_to_object(const BakePixel pixel_array[],
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
* \ingroup bke
|
||||
*/
|
||||
|
||||
#include "BLI_string_ref.hh"
|
||||
|
||||
struct ImBuf;
|
||||
struct Mesh;
|
||||
|
||||
@@ -23,5 +25,5 @@ void RE_generate_texturemargin_adjacentfaces(struct ImBuf *ibuf,
|
||||
char *mask,
|
||||
int margin,
|
||||
struct Mesh const *me,
|
||||
char const *uv_layer,
|
||||
blender::StringRef uv_layer,
|
||||
const float uv_offset[2]);
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
#include <climits>
|
||||
#include <cstring>
|
||||
|
||||
#include "BLI_string_ref.hh"
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_index_range.hh"
|
||||
@@ -142,7 +143,7 @@ void RE_bake_margin(ImBuf *ibuf,
|
||||
const int margin,
|
||||
const char margin_type,
|
||||
const Mesh *mesh,
|
||||
char const *uv_layer,
|
||||
const blender::StringRef uv_layer,
|
||||
const float uv_offset[2])
|
||||
{
|
||||
/* margin */
|
||||
@@ -711,12 +712,12 @@ void RE_bake_pixels_populate(Mesh *mesh,
|
||||
BakePixel pixel_array[],
|
||||
const size_t pixels_num,
|
||||
const BakeTargets *targets,
|
||||
const char *uv_layer)
|
||||
const blender::StringRef uv_layer)
|
||||
{
|
||||
using namespace blender;
|
||||
const bke::AttributeAccessor attributes = mesh->attributes();
|
||||
VArraySpan<float2> uv_map;
|
||||
if ((uv_layer == nullptr) || (uv_layer[0] == '\0')) {
|
||||
if (uv_layer.is_empty()) {
|
||||
const StringRef active_layer_name = CustomData_get_active_layer_name(&mesh->corner_data,
|
||||
CD_PROP_FLOAT2);
|
||||
uv_map = *attributes.lookup<float2>(active_layer_name, bke::AttrDomain::Corner);
|
||||
|
||||
@@ -571,17 +571,15 @@ void RE_generate_texturemargin_adjacentfaces(ImBuf *ibuf,
|
||||
char *mask,
|
||||
const int margin,
|
||||
const Mesh *mesh,
|
||||
char const *uv_layer,
|
||||
blender::StringRef uv_layer,
|
||||
const float uv_offset[2])
|
||||
{
|
||||
using namespace blender;
|
||||
const blender::StringRef uv_map_name = (uv_layer && uv_layer[0]) ?
|
||||
uv_layer :
|
||||
CustomData_get_active_layer_name(&mesh->corner_data,
|
||||
CD_PROP_FLOAT2);
|
||||
const StringRef name = uv_layer.is_empty() ?
|
||||
CustomData_get_active_layer_name(&mesh->corner_data, CD_PROP_FLOAT2) :
|
||||
uv_layer;
|
||||
const blender::bke::AttributeAccessor attributes = mesh->attributes();
|
||||
const VArraySpan<float2> uv_map = *attributes.lookup<float2>(uv_map_name,
|
||||
bke::AttrDomain::Corner);
|
||||
const VArraySpan<float2> uv_map = *attributes.lookup<float2>(name, bke::AttrDomain::Corner);
|
||||
|
||||
blender::render::texturemargin::generate_margin(ibuf,
|
||||
mask,
|
||||
|
||||
Reference in New Issue
Block a user