Mesh: Move functions to C++ header
Refactoring mesh code, it has become clear that local cleanups and simplifications are limited by the need to keep a C public API for mesh functions. This change makes code more obvious and makes further refactoring much easier. - Add a new `BKE_mesh.hh` header for a C++ only mesh API - Introduce a new `blender::bke::mesh` namespace, documented here: https://wiki.blender.org/wiki/Source/Objects/Mesh#Namespaces - Move some functions to the new namespace, cleaning up their arguments - Move code to `Array` and `float3` where necessary to use the new API - Define existing inline mesh data access functions to the new header - Keep some C API functions where necessary because of RNA - Move all C++ files to use the new header, which includes the old one In the future it may make sense to split up `BKE_mesh.hh` more, but for now keeping the same name as the existing header keeps things simple. Pull Request: blender/blender#105416
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
#include "BKE_customdata.h"
|
||||
#include "BKE_data_transfer.h"
|
||||
#include "BKE_deform.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_mesh.hh"
|
||||
#include "BKE_mesh_mapping.h"
|
||||
#include "BKE_mesh_remap.h"
|
||||
#include "BKE_mesh_runtime.h"
|
||||
@@ -351,12 +351,6 @@ static void data_transfer_dtdata_type_preprocess(Mesh *me_src,
|
||||
{
|
||||
if (dtdata_type == DT_TYPE_LNOR) {
|
||||
/* Compute custom normals into regular loop normals, which will be used for the transfer. */
|
||||
|
||||
const float(*positions_dst)[3] = BKE_mesh_vert_positions(me_dst);
|
||||
const int num_verts_dst = me_dst->totvert;
|
||||
const blender::Span<MEdge> edges_dst = me_dst->edges();
|
||||
const blender::Span<MPoly> polys_dst = me_dst->polys();
|
||||
const blender::Span<MLoop> loops_dst = me_dst->loops();
|
||||
CustomData *ldata_dst = &me_dst->ldata;
|
||||
|
||||
const bool use_split_nors_dst = (me_dst->flag & ME_AUTOSMOOTH) != 0;
|
||||
@@ -366,17 +360,16 @@ static void data_transfer_dtdata_type_preprocess(Mesh *me_src,
|
||||
BLI_assert(CustomData_get_layer(&me_src->ldata, CD_NORMAL) != nullptr);
|
||||
(void)me_src;
|
||||
|
||||
float(*loop_nors_dst)[3];
|
||||
short(*custom_nors_dst)[2] = static_cast<short(*)[2]>(
|
||||
CustomData_get_layer_for_write(ldata_dst, CD_CUSTOMLOOPNORMAL, me_dst->totloop));
|
||||
|
||||
/* Cache loop nors into a temp CDLayer. */
|
||||
loop_nors_dst = static_cast<float(*)[3]>(
|
||||
blender::float3 *loop_nors_dst = static_cast<blender::float3 *>(
|
||||
CustomData_get_layer_for_write(ldata_dst, CD_NORMAL, me_dst->totloop));
|
||||
const bool do_loop_nors_dst = (loop_nors_dst == nullptr);
|
||||
if (do_loop_nors_dst) {
|
||||
loop_nors_dst = static_cast<float(*)[3]>(
|
||||
CustomData_add_layer(ldata_dst, CD_NORMAL, CD_SET_DEFAULT, nullptr, loops_dst.size()));
|
||||
loop_nors_dst = static_cast<blender::float3 *>(
|
||||
CustomData_add_layer(ldata_dst, CD_NORMAL, CD_SET_DEFAULT, nullptr, me_dst->totloop));
|
||||
CustomData_set_layer_flag(ldata_dst, CD_NORMAL, CD_FLAG_TEMPORARY);
|
||||
}
|
||||
if (dirty_nors_dst || do_loop_nors_dst) {
|
||||
@@ -384,24 +377,20 @@ static void data_transfer_dtdata_type_preprocess(Mesh *me_src,
|
||||
CustomData_get_layer_named(&me_dst->edata, CD_PROP_BOOL, "sharp_edge"));
|
||||
const bool *sharp_faces = static_cast<const bool *>(
|
||||
CustomData_get_layer_named(&me_dst->pdata, CD_PROP_BOOL, "sharp_face"));
|
||||
BKE_mesh_normals_loop_split(positions_dst,
|
||||
BKE_mesh_vert_normals_ensure(me_dst),
|
||||
num_verts_dst,
|
||||
edges_dst.data(),
|
||||
edges_dst.size(),
|
||||
loops_dst.data(),
|
||||
loop_nors_dst,
|
||||
loops_dst.size(),
|
||||
polys_dst.data(),
|
||||
BKE_mesh_poly_normals_ensure(me_dst),
|
||||
polys_dst.size(),
|
||||
use_split_nors_dst,
|
||||
split_angle_dst,
|
||||
sharp_edges,
|
||||
sharp_faces,
|
||||
nullptr,
|
||||
nullptr,
|
||||
custom_nors_dst);
|
||||
blender::bke::mesh::normals_calc_loop(me_dst->vert_positions(),
|
||||
me_dst->edges(),
|
||||
me_dst->polys(),
|
||||
me_dst->loops(),
|
||||
{},
|
||||
me_dst->vert_normals(),
|
||||
me_dst->poly_normals(),
|
||||
sharp_edges,
|
||||
sharp_faces,
|
||||
use_split_nors_dst,
|
||||
split_angle_dst,
|
||||
custom_nors_dst,
|
||||
nullptr,
|
||||
{loop_nors_dst, me_dst->totloop});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -418,47 +407,35 @@ static void data_transfer_dtdata_type_postprocess(Object * /*ob_src*/,
|
||||
if (!changed) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Bake edited destination loop normals into custom normals again. */
|
||||
const float(*positions_dst)[3] = BKE_mesh_vert_positions(me_dst);
|
||||
const int num_verts_dst = me_dst->totvert;
|
||||
const blender::Span<MEdge> edges_dst = me_dst->edges();
|
||||
blender::MutableSpan<MPoly> polys_dst = me_dst->polys_for_write();
|
||||
blender::MutableSpan<MLoop> loops_dst = me_dst->loops_for_write();
|
||||
|
||||
CustomData *ldata_dst = &me_dst->ldata;
|
||||
|
||||
const float(*poly_nors_dst)[3] = BKE_mesh_poly_normals_ensure(me_dst);
|
||||
float(*loop_nors_dst)[3] = static_cast<float(*)[3]>(
|
||||
blender::float3 *loop_nors_dst = static_cast<blender::float3 *>(
|
||||
CustomData_get_layer_for_write(ldata_dst, CD_NORMAL, me_dst->totloop));
|
||||
short(*custom_nors_dst)[2] = static_cast<short(*)[2]>(
|
||||
CustomData_get_layer_for_write(ldata_dst, CD_CUSTOMLOOPNORMAL, me_dst->totloop));
|
||||
|
||||
if (!custom_nors_dst) {
|
||||
custom_nors_dst = static_cast<short(*)[2]>(CustomData_add_layer(
|
||||
ldata_dst, CD_CUSTOMLOOPNORMAL, CD_SET_DEFAULT, nullptr, loops_dst.size()));
|
||||
ldata_dst, CD_CUSTOMLOOPNORMAL, CD_SET_DEFAULT, nullptr, me_dst->totloop));
|
||||
}
|
||||
|
||||
bke::MutableAttributeAccessor attributes = me_dst->attributes_for_write();
|
||||
bke::SpanAttributeWriter<bool> sharp_edges = attributes.lookup_or_add_for_write_span<bool>(
|
||||
"sharp_edge", ATTR_DOMAIN_EDGE);
|
||||
|
||||
const bool *sharp_faces = static_cast<const bool *>(
|
||||
CustomData_get_layer_named(&me_dst->pdata, CD_PROP_BOOL, "sharp_face"));
|
||||
/* Note loop_nors_dst contains our custom normals as transferred from source... */
|
||||
BKE_mesh_normals_loop_custom_set(positions_dst,
|
||||
BKE_mesh_vert_normals_ensure(me_dst),
|
||||
num_verts_dst,
|
||||
edges_dst.data(),
|
||||
edges_dst.size(),
|
||||
loops_dst.data(),
|
||||
loop_nors_dst,
|
||||
loops_dst.size(),
|
||||
polys_dst.data(),
|
||||
poly_nors_dst,
|
||||
static_cast<const bool *>(CustomData_get_layer_named(
|
||||
&me_dst->pdata, CD_PROP_BOOL, "sharp_face")),
|
||||
polys_dst.size(),
|
||||
sharp_edges.span.data(),
|
||||
custom_nors_dst);
|
||||
blender::bke::mesh::normals_loop_custom_set(me_dst->vert_positions(),
|
||||
me_dst->edges(),
|
||||
me_dst->polys(),
|
||||
me_dst->loops(),
|
||||
me_dst->vert_normals(),
|
||||
me_dst->poly_normals(),
|
||||
sharp_faces,
|
||||
sharp_edges.span,
|
||||
{loop_nors_dst, me_dst->totloop},
|
||||
custom_nors_dst);
|
||||
sharp_edges.finish();
|
||||
}
|
||||
}
|
||||
@@ -1715,6 +1692,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph,
|
||||
ray_radius,
|
||||
me_dst,
|
||||
positions_dst,
|
||||
num_verts_dst,
|
||||
loops_dst.data(),
|
||||
polys_dst.data(),
|
||||
polys_dst.size(),
|
||||
|
||||
Reference in New Issue
Block a user