Cleanup: Access sharp_face attribute with attribute API
This commit is contained in:
parent
b37e825d89
commit
0b80d5e755
|
@ -15,6 +15,7 @@
|
|||
#include "BLI_math_vector_types.hh"
|
||||
#include "BLI_offset_indices.hh"
|
||||
#include "BLI_span.hh"
|
||||
#include "BLI_virtual_array.hh"
|
||||
|
||||
/*
|
||||
* Shrinkwrap is composed by a set of functions and options that define the type of shrink.
|
||||
|
@ -79,7 +80,7 @@ struct ShrinkwrapTreeData {
|
|||
blender::Span<blender::float3> face_normals;
|
||||
blender::Span<blender::float3> vert_normals;
|
||||
blender::Span<blender::float3> corner_normals;
|
||||
const bool *sharp_faces;
|
||||
blender::VArraySpan<bool> sharp_faces;
|
||||
const ShrinkwrapBoundaryData *boundary;
|
||||
};
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "BKE_DerivedMesh.hh"
|
||||
#include "BKE_attribute.hh"
|
||||
#include "BKE_cdderivedmesh.h"
|
||||
#include "BKE_modifier.hh"
|
||||
#include "BKE_shrinkwrap.hh"
|
||||
|
@ -96,6 +97,7 @@ bool BKE_shrinkwrap_needs_normals(int shrinkType, int shrinkMode)
|
|||
bool BKE_shrinkwrap_init_tree(
|
||||
ShrinkwrapTreeData *data, Mesh *mesh, int shrinkType, int shrinkMode, bool force_normals)
|
||||
{
|
||||
using namespace blender::bke;
|
||||
*data = {};
|
||||
|
||||
if (mesh == nullptr) {
|
||||
|
@ -115,8 +117,8 @@ bool BKE_shrinkwrap_init_tree(
|
|||
data->faces = mesh->faces();
|
||||
data->corner_edges = mesh->corner_edges();
|
||||
data->vert_normals = mesh->vert_normals();
|
||||
data->sharp_faces = static_cast<const bool *>(
|
||||
CustomData_get_layer_named(&mesh->face_data, CD_PROP_BOOL, "sharp_face"));
|
||||
const AttributeAccessor attributes = mesh->attributes();
|
||||
data->sharp_faces = *attributes.lookup<bool>("sharp_face", AttrDomain::Face);
|
||||
|
||||
if (shrinkType == MOD_SHRINKWRAP_NEAREST_VERTEX) {
|
||||
data->bvh = BKE_bvhtree_from_mesh_get(&data->treeData, mesh, BVHTREE_FROM_VERTS, 2);
|
||||
|
@ -1160,7 +1162,7 @@ void BKE_shrinkwrap_compute_smooth_normal(const ShrinkwrapTreeData *tree,
|
|||
const int face_i = tree->mesh->corner_tri_faces()[corner_tri_idx];
|
||||
|
||||
/* Interpolate smooth normals if enabled. */
|
||||
if (!(tree->sharp_faces && tree->sharp_faces[face_i])) {
|
||||
if (tree->sharp_faces.is_empty() || tree->sharp_faces[face_i]) {
|
||||
const int vert_indices[3] = {treeData->corner_verts[tri[0]],
|
||||
treeData->corner_verts[tri[1]],
|
||||
treeData->corner_verts[tri[2]]};
|
||||
|
|
|
@ -1154,15 +1154,15 @@ void ED_mesh_split_faces(Mesh *mesh)
|
|||
const bke::AttributeAccessor attributes = mesh->attributes();
|
||||
const VArray<bool> mesh_sharp_edges = *attributes.lookup_or_default<bool>(
|
||||
"sharp_edge", bke::AttrDomain::Edge, false);
|
||||
const bool *sharp_faces = static_cast<const bool *>(
|
||||
CustomData_get_layer_named(&mesh->face_data, CD_PROP_BOOL, "sharp_face"));
|
||||
const VArraySpan<bool> sharp_faces = *attributes.lookup<bool>("sharp_face",
|
||||
bke::AttrDomain::Face);
|
||||
|
||||
Array<bool> sharp_edges(mesh->edges_num);
|
||||
mesh_sharp_edges.materialize(sharp_edges);
|
||||
|
||||
threading::parallel_for(polys.index_range(), 1024, [&](const IndexRange range) {
|
||||
for (const int face_i : range) {
|
||||
if (sharp_faces && sharp_faces[face_i]) {
|
||||
if (!sharp_faces.is_empty() && sharp_faces[face_i]) {
|
||||
for (const int edge : corner_edges.slice(polys[face_i])) {
|
||||
sharp_edges[edge] = true;
|
||||
}
|
||||
|
|
|
@ -622,13 +622,8 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
|
|||
bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
|
||||
bke::SpanAttributeWriter material_indices = attributes.lookup_or_add_for_write_span<int>(
|
||||
"material_index", bke::AttrDomain::Face);
|
||||
|
||||
bool *sharp_faces = static_cast<bool *>(CustomData_get_layer_named_for_write(
|
||||
&mesh->face_data, CD_PROP_BOOL, "sharp_face", mesh->faces_num));
|
||||
if (!sharp_faces) {
|
||||
sharp_faces = static_cast<bool *>(CustomData_add_layer_named(
|
||||
&mesh->face_data, CD_PROP_BOOL, CD_SET_DEFAULT, mesh->faces_num, "sharp_face"));
|
||||
}
|
||||
bke::SpanAttributeWriter sharp_faces = attributes.lookup_or_add_for_write_span<bool>(
|
||||
"sharp_face", bke::AttrDomain::Face);
|
||||
|
||||
COLLADAFW::MeshPrimitiveArray &prim_arr = collada_mesh->getMeshPrimitives();
|
||||
COLLADAFW::MeshVertexData &nor = collada_mesh->getNormals();
|
||||
|
@ -673,7 +668,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
|
|||
if (mp_has_normals) { /* vertex normals, same implementation as for the triangles */
|
||||
/* The same for vertices normals. */
|
||||
uint vertex_normal_indices[3] = {first_normal, normal_indices[1], normal_indices[2]};
|
||||
sharp_faces[face_index] = is_flat_face(vertex_normal_indices, nor, 3);
|
||||
sharp_faces.span[face_index] = is_flat_face(vertex_normal_indices, nor, 3);
|
||||
normal_indices++;
|
||||
}
|
||||
|
||||
|
@ -743,7 +738,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
|
|||
if (mp_has_normals) {
|
||||
/* If it turns out that we have complete custom normals for each poly
|
||||
* and we want to use custom normals, this will be overridden. */
|
||||
sharp_faces[face_index] = is_flat_face(normal_indices, nor, vcount);
|
||||
sharp_faces.span[face_index] = is_flat_face(normal_indices, nor, vcount);
|
||||
|
||||
if (use_custom_normals) {
|
||||
/* Store the custom normals for later application. */
|
||||
|
|
Loading…
Reference in New Issue