Branch compiling
This commit is contained in:
parent
9bfd8525fc
commit
1442711908
|
@ -895,7 +895,7 @@ static std::optional<BL::IntAttribute> find_material_index_attribute(BL::Mesh b_
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
static std::optional<BL::IntAttribute> find_sharp_face_attribute(BL::Mesh b_mesh)
|
||||
static std::optional<BL::BoolAttribute> find_sharp_face_attribute(BL::Mesh b_mesh)
|
||||
{
|
||||
for (BL::Attribute &b_attribute : b_mesh.attributes) {
|
||||
if (b_attribute.domain() != BL::Attribute::domain_FACE) {
|
||||
|
@ -1011,13 +1011,10 @@ static void create_mesh(Scene *scene,
|
|||
return 0;
|
||||
};
|
||||
|
||||
|
||||
/* create faces */
|
||||
const MPoly *polys = static_cast<const MPoly *>(b_mesh.polygons[0].ptr.data);
|
||||
if (!subdivision) {
|
||||
for (BL::MeshLoopTriangle &t : b_mesh.loop_triangles) {
|
||||
const int poly_index = t.polygon_index();
|
||||
const MPoly &b_poly = polys[poly_index];
|
||||
int3 vi = get_int3(t.vertices());
|
||||
|
||||
int shader = get_material_index(poly_index);
|
||||
|
@ -1041,13 +1038,14 @@ static void create_mesh(Scene *scene,
|
|||
else {
|
||||
vector<int> vi;
|
||||
|
||||
const MPoly *polys = static_cast<const MPoly *>(b_mesh.polygons[0].ptr.data);
|
||||
const MLoop *loops = static_cast<const MLoop *>(b_mesh.loops[0].ptr.data);
|
||||
|
||||
for (int i = 0; i < numfaces; i++) {
|
||||
const MPoly &b_poly = polys[i];
|
||||
int n = b_poly.totloop;
|
||||
int shader = get_material_index(i);
|
||||
bool smooth = !get_face_sharp(poly_index) || use_loop_normals;
|
||||
bool smooth = !get_face_sharp(i) || use_loop_normals;
|
||||
|
||||
vi.resize(n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
|
|
|
@ -24,6 +24,9 @@ struct MFace;
|
|||
|
||||
#ifdef __cplusplus
|
||||
|
||||
void BKE_mesh_sharp_faces_to_flags(struct Mesh *mesh);
|
||||
void BKE_mesh_sharp_faces_from_flags(struct Mesh *mesh);
|
||||
|
||||
/**
|
||||
* Move face sets to the legacy type from a generic type.
|
||||
*/
|
||||
|
|
|
@ -322,6 +322,7 @@ bool BKE_mesh_calc_islands_loop_poly_uvmap(struct MVert *verts,
|
|||
int *BKE_mesh_calc_smoothgroups(const struct MEdge *medge,
|
||||
int totedge,
|
||||
const struct MPoly *mpoly,
|
||||
const bool *sharp_faces,
|
||||
int totpoly,
|
||||
const struct MLoop *mloop,
|
||||
int totloop,
|
||||
|
|
|
@ -3212,18 +3212,8 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds,
|
|||
float size[3];
|
||||
float cell_size_scaled[3];
|
||||
|
||||
/* Assign material + flags to new mesh.
|
||||
* If there are no faces in original mesh, keep materials and flags unchanged. */
|
||||
MPoly *mpoly;
|
||||
MPoly mp_example = {0};
|
||||
mpoly = BKE_mesh_polys_for_write(orgmesh);
|
||||
if (mpoly) {
|
||||
mp_example = *mpoly;
|
||||
}
|
||||
|
||||
const int *orig_material_indices = BKE_mesh_material_indices(orgmesh);
|
||||
const short mp_mat_nr = orig_material_indices ? orig_material_indices[0] : 0;
|
||||
const char mp_flag = mp_example.flag;
|
||||
|
||||
int i;
|
||||
int num_verts, num_faces;
|
||||
|
@ -3339,7 +3329,6 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds,
|
|||
for (i = 0; i < num_faces; i++, mpolys++, mloops += 3) {
|
||||
/* Initialize from existing face. */
|
||||
material_indices[i] = mp_mat_nr;
|
||||
mpolys->flag = mp_flag;
|
||||
|
||||
mpolys->loopstart = i * 3;
|
||||
mpolys->totloop = 3;
|
||||
|
|
|
@ -2298,6 +2298,8 @@ void BKE_keyblock_mesh_calc_normals(const KeyBlock *kb,
|
|||
mesh->totloop,
|
||||
polys,
|
||||
poly_normals,
|
||||
static_cast<const bool *>(CustomData_get_layer_named(
|
||||
&mesh->pdata, CD_PROP_BOOL, "sharp_face")),
|
||||
mesh->totpoly,
|
||||
(mesh->flag & ME_AUTOSMOOTH) != 0,
|
||||
mesh->smoothresh,
|
||||
|
|
|
@ -254,6 +254,7 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
|
|||
BKE_mesh_legacy_convert_hide_layers_to_flags(mesh);
|
||||
BKE_mesh_legacy_convert_selection_layers_to_flags(mesh);
|
||||
BKE_mesh_legacy_convert_material_indices_to_mpoly(mesh);
|
||||
BKE_mesh_sharp_faces_to_flags(mesh);
|
||||
BKE_mesh_legacy_bevel_weight_from_layers(mesh);
|
||||
BKE_mesh_legacy_face_set_from_generic(mesh, poly_layers);
|
||||
BKE_mesh_legacy_edge_crease_from_layers(mesh);
|
||||
|
@ -1850,6 +1851,8 @@ void BKE_mesh_calc_normals_split_ex(Mesh *mesh,
|
|||
loops.size(),
|
||||
polys.data(),
|
||||
BKE_mesh_poly_normals_ensure(mesh),
|
||||
static_cast<const bool *>(CustomData_get_layer_named(
|
||||
&mesh->pdata, CD_PROP_BOOL, "sharp_face")),
|
||||
polys.size(),
|
||||
use_split_normals,
|
||||
split_angle,
|
||||
|
|
|
@ -402,15 +402,12 @@ static void copy_vert_attributes(Mesh *dest_mesh,
|
|||
|
||||
/* Similar to copy_vert_attributes but for poly attributes. */
|
||||
static void copy_poly_attributes(Mesh *dest_mesh,
|
||||
MPoly *mp,
|
||||
const MPoly *orig_mp,
|
||||
const Mesh *orig_me,
|
||||
int mp_index,
|
||||
int index_in_orig_me,
|
||||
Span<short> material_remap,
|
||||
MutableSpan<int> dst_material_indices)
|
||||
{
|
||||
mp->flag = orig_mp->flag;
|
||||
CustomData *target_cd = &dest_mesh->pdata;
|
||||
const CustomData *source_cd = &orig_me->pdata;
|
||||
for (int source_layer_i = 0; source_layer_i < source_cd->totlayer; ++source_layer_i) {
|
||||
|
@ -760,8 +757,6 @@ static Mesh *imesh_to_mesh(IMesh *im, MeshesToIMeshInfo &mim)
|
|||
}
|
||||
|
||||
copy_poly_attributes(result,
|
||||
mp,
|
||||
orig_mp,
|
||||
orig_me,
|
||||
fi,
|
||||
index_in_orig_me,
|
||||
|
|
|
@ -440,6 +440,12 @@ static void convert_mfaces_to_mpolys(ID *id,
|
|||
material_indices = static_cast<int *>(CustomData_add_layer_named(
|
||||
pdata, CD_PROP_INT32, CD_SET_DEFAULT, nullptr, totpoly, "material_index"));
|
||||
}
|
||||
bool *sharp_faces = static_cast<bool *>(
|
||||
CustomData_get_layer_named(pdata, CD_PROP_BOOL, "sharp_face"));
|
||||
if (sharp_faces == nullptr) {
|
||||
sharp_faces = static_cast<bool *>(CustomData_add_layer_named(
|
||||
pdata, CD_PROP_BOOL, CD_SET_DEFAULT, nullptr, totpoly, "sharp_face"));
|
||||
}
|
||||
|
||||
numTex = CustomData_number_of_layers(fdata, CD_MTFACE);
|
||||
numCol = CustomData_number_of_layers(fdata, CD_MCOL);
|
||||
|
@ -484,7 +490,7 @@ static void convert_mfaces_to_mpolys(ID *id,
|
|||
mp->totloop = mf->v4 ? 4 : 3;
|
||||
|
||||
material_indices[i] = mf->mat_nr;
|
||||
mp->flag = mf->flag;
|
||||
sharp_faces[i] = (mf->flag & ME_SMOOTH) == 0;
|
||||
|
||||
#define ML(v1, v2) \
|
||||
{ \
|
||||
|
@ -966,6 +972,8 @@ static int mesh_tessface_calc(Mesh &mesh,
|
|||
mloop = (const MLoop *)CustomData_get_layer(ldata, CD_MLOOP);
|
||||
const int *material_indices = static_cast<const int *>(
|
||||
CustomData_get_layer_named(pdata, CD_PROP_INT32, "material_index"));
|
||||
const bool *sharp_faces = static_cast<const bool *>(
|
||||
CustomData_get_layer_named(pdata, CD_PROP_BOOL, "sharp_face"));
|
||||
|
||||
/* Allocate the length of `totfaces`, avoid many small reallocation's,
|
||||
* if all faces are triangles it will be correct, `quads == 2x` allocations. */
|
||||
|
@ -1005,7 +1013,7 @@ static int mesh_tessface_calc(Mesh &mesh,
|
|||
lidx[2] = l3; \
|
||||
lidx[3] = 0; \
|
||||
mf->mat_nr = material_indices ? material_indices[poly_index] : 0; \
|
||||
mf->flag = mp->flag; \
|
||||
mf->flag = (sharp_faces && sharp_faces[poly_index]) ? 0 : ME_SMOOTH; \
|
||||
mf->edcode = 0; \
|
||||
(void)0
|
||||
|
||||
|
@ -1028,7 +1036,7 @@ static int mesh_tessface_calc(Mesh &mesh,
|
|||
lidx[2] = l3; \
|
||||
lidx[3] = l4; \
|
||||
mf->mat_nr = material_indices ? material_indices[poly_index] : 0; \
|
||||
mf->flag = mp->flag; \
|
||||
mf->flag = (sharp_faces && sharp_faces[poly_index]) ? 0 : ME_SMOOTH; \
|
||||
mf->edcode = TESSFACE_IS_QUAD; \
|
||||
(void)0
|
||||
|
||||
|
@ -1114,7 +1122,6 @@ static int mesh_tessface_calc(Mesh &mesh,
|
|||
lidx[3] = 0;
|
||||
|
||||
mf->mat_nr = material_indices ? material_indices[poly_index] : 0;
|
||||
mf->flag = mp->flag;
|
||||
mf->edcode = 0;
|
||||
|
||||
mface_index++;
|
||||
|
@ -1205,6 +1212,57 @@ void BKE_mesh_tessface_ensure(struct Mesh *mesh)
|
|||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Sharp Edge Conversion
|
||||
* \{ */
|
||||
|
||||
void BKE_mesh_sharp_faces_to_flags(Mesh *mesh)
|
||||
{
|
||||
using namespace blender;
|
||||
MutableSpan<MPoly> polys = mesh->polys_for_write();
|
||||
if (const bool *sharp_faces = static_cast<const bool *>(
|
||||
CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face"))) {
|
||||
threading::parallel_for(polys.index_range(), 4096, [&](const IndexRange range) {
|
||||
for (const int i : range) {
|
||||
SET_FLAG_FROM_TEST(polys[i].flag_legacy, !sharp_faces[i], ME_SMOOTH);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
for (const int i : polys.index_range()) {
|
||||
polys[i].flag_legacy |= ME_SMOOTH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BKE_mesh_sharp_faces_from_flags(Mesh *mesh)
|
||||
{
|
||||
using namespace blender;
|
||||
using namespace blender::bke;
|
||||
const Span<MPoly> polys = mesh->polys();
|
||||
MutableAttributeAccessor attributes = mesh->attributes_for_write();
|
||||
if (attributes.contains("sharp_face")) {
|
||||
return;
|
||||
}
|
||||
if (std::any_of(polys.begin(), polys.end(), [](const MPoly &poly) {
|
||||
return !(poly.flag_legacy & ME_SMOOTH);
|
||||
})) {
|
||||
SpanAttributeWriter<bool> sharp_faces = attributes.lookup_or_add_for_write_only_span<bool>(
|
||||
"sharp_face", ATTR_DOMAIN_FACE);
|
||||
threading::parallel_for(polys.index_range(), 4096, [&](const IndexRange range) {
|
||||
for (const int i : range) {
|
||||
sharp_faces.span[i] = !(polys[i].flag_legacy & ME_SMOOTH);
|
||||
}
|
||||
});
|
||||
sharp_faces.finish();
|
||||
}
|
||||
else {
|
||||
attributes.remove("sharp_face");
|
||||
}
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Face Set Conversion
|
||||
* \{ */
|
||||
|
@ -1367,7 +1425,7 @@ void BKE_mesh_legacy_convert_hide_layers_to_flags(Mesh *mesh)
|
|||
".hide_poly", ATTR_DOMAIN_FACE, false);
|
||||
threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) {
|
||||
for (const int i : range) {
|
||||
SET_FLAG_FROM_TEST(polys[i].flag, hide_poly[i], ME_HIDE);
|
||||
SET_FLAG_FROM_TEST(polys[i].flag_legacy, hide_poly[i], ME_HIDE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1406,13 +1464,14 @@ void BKE_mesh_legacy_convert_flags_to_hide_layers(Mesh *mesh)
|
|||
}
|
||||
|
||||
const Span<MPoly> polys = mesh->polys();
|
||||
if (std::any_of(
|
||||
polys.begin(), polys.end(), [](const MPoly &poly) { return poly.flag & ME_HIDE; })) {
|
||||
if (std::any_of(polys.begin(), polys.end(), [](const MPoly &poly) {
|
||||
return poly.flag_legacy & ME_HIDE;
|
||||
})) {
|
||||
SpanAttributeWriter<bool> hide_poly = attributes.lookup_or_add_for_write_only_span<bool>(
|
||||
".hide_poly", ATTR_DOMAIN_FACE);
|
||||
threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) {
|
||||
for (const int i : range) {
|
||||
hide_poly.span[i] = polys[i].flag & ME_HIDE;
|
||||
hide_poly.span[i] = polys[i].flag_legacy & ME_HIDE;
|
||||
}
|
||||
});
|
||||
hide_poly.finish();
|
||||
|
@ -1494,7 +1553,7 @@ void BKE_mesh_legacy_convert_selection_layers_to_flags(Mesh *mesh)
|
|||
".select_poly", ATTR_DOMAIN_FACE, false);
|
||||
threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) {
|
||||
for (const int i : range) {
|
||||
SET_FLAG_FROM_TEST(polys[i].flag, select_poly[i], ME_FACE_SEL);
|
||||
SET_FLAG_FROM_TEST(polys[i].flag_legacy, select_poly[i], ME_FACE_SEL);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1533,13 +1592,14 @@ void BKE_mesh_legacy_convert_flags_to_selection_layers(Mesh *mesh)
|
|||
}
|
||||
|
||||
const Span<MPoly> polys = mesh->polys();
|
||||
if (std::any_of(
|
||||
polys.begin(), polys.end(), [](const MPoly &poly) { return poly.flag & ME_FACE_SEL; })) {
|
||||
if (std::any_of(polys.begin(), polys.end(), [](const MPoly &poly) {
|
||||
return poly.flag_legacy & ME_FACE_SEL;
|
||||
})) {
|
||||
SpanAttributeWriter<bool> select_poly = attributes.lookup_or_add_for_write_only_span<bool>(
|
||||
".select_poly", ATTR_DOMAIN_FACE);
|
||||
threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) {
|
||||
for (const int i : range) {
|
||||
select_poly.span[i] = (polys[i].flag & ME_FACE_SEL) != 0;
|
||||
select_poly.span[i] = (polys[i].flag_legacy & ME_FACE_SEL) != 0;
|
||||
}
|
||||
});
|
||||
select_poly.finish();
|
||||
|
|
|
@ -630,17 +630,18 @@ Vector<Vector<int>> build_edge_to_loop_map_resizable(const Span<MLoop> loops, co
|
|||
/**
|
||||
* Callback deciding whether the given poly/loop/edge define an island boundary or not.
|
||||
*/
|
||||
using MeshRemap_CheckIslandBoundary = bool (*)(const MPoly *mpoly,
|
||||
using MeshRemap_CheckIslandBoundary = bool (*)(const int poly_index,
|
||||
const bool *sharp_faces,
|
||||
const MLoop *mloop,
|
||||
const MEdge *medge,
|
||||
const int edge_user_count,
|
||||
const MPoly *mpoly_array,
|
||||
const MeshElemMap *edge_poly_map,
|
||||
void *user_data);
|
||||
|
||||
static void poly_edge_loop_islands_calc(const MEdge *medge,
|
||||
const int totedge,
|
||||
const MPoly *mpoly,
|
||||
const bool *sharp_faces,
|
||||
const int totpoly,
|
||||
const MLoop *mloop,
|
||||
const int totloop,
|
||||
|
@ -735,7 +736,8 @@ static void poly_edge_loop_islands_calc(const MEdge *medge,
|
|||
const MeshElemMap *map_ele = &edge_poly_map[me_idx];
|
||||
const int *p = map_ele->indices;
|
||||
int i = map_ele->count;
|
||||
if (!edge_boundary_check(mp, ml, me, i, mpoly, map_ele, edge_boundary_check_data)) {
|
||||
if (!edge_boundary_check(
|
||||
poly, sharp_faces, ml, me, i, map_ele, edge_boundary_check_data)) {
|
||||
for (; i--; p++) {
|
||||
/* if we meet other non initialized its a bug */
|
||||
BLI_assert(ELEM(poly_groups[*p], 0, poly_group_id));
|
||||
|
@ -833,22 +835,23 @@ static void poly_edge_loop_islands_calc(const MEdge *medge,
|
|||
}
|
||||
}
|
||||
|
||||
static bool poly_is_island_boundary_smooth_cb(const MPoly *mp,
|
||||
static bool poly_is_island_boundary_smooth_cb(const int poly_index,
|
||||
const bool *sharp_faces,
|
||||
const MLoop * /*ml*/,
|
||||
const MEdge *me,
|
||||
const int edge_user_count,
|
||||
const MPoly *mpoly_array,
|
||||
const MeshElemMap *edge_poly_map,
|
||||
void * /*user_data*/)
|
||||
{
|
||||
auto poly_is_smooth = [&](const int i) { return !(sharp_faces && sharp_faces[i]); };
|
||||
|
||||
/* Edge is sharp if one of its polys is flat, or edge itself is sharp,
|
||||
* or edge is not used by exactly two polygons. */
|
||||
if ((mp->flag & ME_SMOOTH) && !(me->flag & ME_SHARP) && (edge_user_count == 2)) {
|
||||
if ((poly_is_smooth(poly_index)) && !(me->flag & ME_SHARP) && (edge_user_count == 2)) {
|
||||
/* In that case, edge appears to be smooth, but we need to check its other poly too. */
|
||||
const MPoly *mp_other = (mp == &mpoly_array[edge_poly_map->indices[0]]) ?
|
||||
&mpoly_array[edge_poly_map->indices[1]] :
|
||||
&mpoly_array[edge_poly_map->indices[0]];
|
||||
return (mp_other->flag & ME_SMOOTH) == 0;
|
||||
const int mp_other = (poly_index == edge_poly_map->indices[0]) ? edge_poly_map->indices[1] :
|
||||
edge_poly_map->indices[0];
|
||||
return !poly_is_smooth(mp_other);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -856,6 +859,7 @@ static bool poly_is_island_boundary_smooth_cb(const MPoly *mp,
|
|||
int *BKE_mesh_calc_smoothgroups(const MEdge *medge,
|
||||
const int totedge,
|
||||
const MPoly *mpoly,
|
||||
const bool *sharp_faces,
|
||||
const int totpoly,
|
||||
const MLoop *mloop,
|
||||
const int totloop,
|
||||
|
@ -867,6 +871,7 @@ int *BKE_mesh_calc_smoothgroups(const MEdge *medge,
|
|||
poly_edge_loop_islands_calc(medge,
|
||||
totedge,
|
||||
mpoly,
|
||||
sharp_faces,
|
||||
totpoly,
|
||||
mloop,
|
||||
totloop,
|
||||
|
@ -1009,11 +1014,11 @@ struct MeshCheckIslandBoundaryUv {
|
|||
const MeshElemMap *edge_loop_map;
|
||||
};
|
||||
|
||||
static bool mesh_check_island_boundary_uv(const MPoly * /*mp*/,
|
||||
static bool mesh_check_island_boundary_uv(const int /*poly_index*/,
|
||||
const bool * /*sharp_faces*/,
|
||||
const MLoop *ml,
|
||||
const MEdge *me,
|
||||
const int /*edge_user_count*/,
|
||||
const MPoly * /*mpoly_array*/,
|
||||
const MeshElemMap * /*edge_poly_map*/,
|
||||
void *user_data)
|
||||
{
|
||||
|
@ -1109,6 +1114,7 @@ static bool mesh_calc_islands_loop_poly_uv(const MVert * /*verts*/,
|
|||
poly_edge_loop_islands_calc(edges,
|
||||
totedge,
|
||||
polys,
|
||||
nullptr,
|
||||
totpoly,
|
||||
loops,
|
||||
totloop,
|
||||
|
|
|
@ -414,6 +414,8 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd,
|
|||
totloop,
|
||||
BKE_mesh_polys(result),
|
||||
BKE_mesh_poly_normals_ensure(result),
|
||||
static_cast<const bool *>(CustomData_get_layer_named(
|
||||
&result->pdata, CD_PROP_BOOL, "sharp_face")),
|
||||
totpoly,
|
||||
true,
|
||||
mesh->smoothresh,
|
||||
|
|
|
@ -1377,6 +1377,8 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
|
|||
numloops_dst,
|
||||
polys_dst,
|
||||
poly_nors_dst,
|
||||
static_cast<const bool *>(CustomData_get_layer_named(
|
||||
&mesh_dst->pdata, CD_PROP_BOOL, "sharp_face")),
|
||||
numpolys_dst,
|
||||
use_split_nors_dst,
|
||||
split_angle_dst,
|
||||
|
|
|
@ -172,7 +172,7 @@ static bool face_materials_match(const PBVH *pbvh,
|
|||
|
||||
static bool grid_materials_match(const DMFlagMat *f1, const DMFlagMat *f2)
|
||||
{
|
||||
return ((f1->flag & ME_SMOOTH) == (f2->flag & ME_SMOOTH) && (f1->mat_nr == f2->mat_nr));
|
||||
return (f1->sharp == f2->sharp) && (f1->mat_nr == f2->mat_nr);
|
||||
}
|
||||
|
||||
/* Adapted from BLI_kdopbvh.c */
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
typedef struct CCGMaterialFromMeshData {
|
||||
const Mesh *mesh;
|
||||
const MPoly *polys;
|
||||
const bool *sharp_faces;
|
||||
const int *material_indices;
|
||||
} CCGMaterialFromMeshData;
|
||||
|
||||
|
@ -24,9 +24,8 @@ static DMFlagMat subdiv_ccg_material_flags_eval(
|
|||
{
|
||||
CCGMaterialFromMeshData *data = (CCGMaterialFromMeshData *)material_flags_evaluator->user_data;
|
||||
BLI_assert(coarse_face_index < data->mesh->totpoly);
|
||||
const MPoly *poly = &data->polys[coarse_face_index];
|
||||
DMFlagMat material_flags;
|
||||
material_flags.flag = poly->flag;
|
||||
material_flags.sharp = data->sharp_faces && data->sharp_faces[coarse_face_index];
|
||||
material_flags.mat_nr = data->material_indices ? data->material_indices[coarse_face_index] : 0;
|
||||
return material_flags;
|
||||
}
|
||||
|
@ -45,7 +44,9 @@ void BKE_subdiv_ccg_material_flags_init_from_mesh(
|
|||
data->mesh = mesh;
|
||||
data->material_indices = (const int *)CustomData_get_layer_named(
|
||||
&mesh->pdata, CD_PROP_INT32, "material_index");
|
||||
data->polys = BKE_mesh_polys(mesh);
|
||||
data->sharp_faces = (const bool *)CustomData_get_layer_named(
|
||||
&mesh->pdata, CD_PROP_BOOL, "sharp_face");
|
||||
|
||||
material_flags_evaluator->eval_material_flags = subdiv_ccg_material_flags_eval;
|
||||
material_flags_evaluator->free = subdiv_ccg_material_flags_free;
|
||||
material_flags_evaluator->user_data = data;
|
||||
|
|
|
@ -1122,20 +1122,17 @@ static void ccgDM_copyFinalPolyArray(DerivedMesh *dm, MPoly *mpoly)
|
|||
int gridSize = ccgSubSurf_getGridSize(ss);
|
||||
/* int edgeSize = ccgSubSurf_getEdgeSize(ss); */ /* UNUSED */
|
||||
int i = 0, k = 0;
|
||||
DMFlagMat *faceFlags = ccgdm->faceFlags;
|
||||
|
||||
totface = ccgSubSurf_getNumFaces(ss);
|
||||
for (index = 0; index < totface; index++) {
|
||||
CCGFace *f = ccgdm->faceMap[index].face;
|
||||
int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f);
|
||||
int flag = (faceFlags) ? faceFlags[index].flag : ME_SMOOTH;
|
||||
|
||||
for (S = 0; S < numVerts; S++) {
|
||||
for (y = 0; y < gridSize - 1; y++) {
|
||||
for (x = 0; x < gridSize - 1; x++) {
|
||||
MPoly *mp = &mpoly[i];
|
||||
|
||||
mp->flag = flag;
|
||||
mp->loopstart = k;
|
||||
mp->totloop = 4;
|
||||
|
||||
|
@ -1599,9 +1596,9 @@ static void set_ccgdm_all_geometry(CCGDerivedMesh *ccgdm,
|
|||
|
||||
medge = dm->getEdgeArray(dm);
|
||||
|
||||
const MPoly *mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY);
|
||||
const int *material_indices = CustomData_get_layer_named(
|
||||
&dm->polyData, CD_MPOLY, "material_index");
|
||||
const bool *sharp_faces = CustomData_get_layer_named(&dm->polyData, CD_PROP_BOOL, "sharp_face");
|
||||
const int *base_polyOrigIndex = CustomData_get_layer(&dm->polyData, CD_ORIGINDEX);
|
||||
|
||||
int *vertOrigIndex = DM_get_vert_data_layer(&ccgdm->dm, CD_ORIGINDEX);
|
||||
|
@ -1629,7 +1626,7 @@ static void set_ccgdm_all_geometry(CCGDerivedMesh *ccgdm,
|
|||
ccgdm->faceMap[index].startEdge = edgeNum;
|
||||
ccgdm->faceMap[index].startFace = faceNum;
|
||||
|
||||
faceFlags->flag = mpoly ? mpoly[origIndex].flag : 0;
|
||||
faceFlags->sharp = sharp_faces ? sharp_faces[origIndex] : false;
|
||||
faceFlags->mat_nr = material_indices ? material_indices[origIndex] : 0;
|
||||
faceFlags++;
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ static void version_mesh_legacy_to_struct_of_array_format(Mesh &mesh)
|
|||
BKE_mesh_legacy_convert_flags_to_selection_layers(&mesh);
|
||||
BKE_mesh_legacy_convert_flags_to_hide_layers(&mesh);
|
||||
BKE_mesh_legacy_convert_mpoly_to_material_indices(&mesh);
|
||||
BKE_mesh_sharp_faces_from_flags(&mesh);
|
||||
BKE_mesh_legacy_bevel_weight_to_layers(&mesh);
|
||||
BKE_mesh_legacy_face_set_to_generic(&mesh);
|
||||
BKE_mesh_legacy_edge_crease_to_layers(&mesh);
|
||||
|
|
|
@ -378,6 +378,7 @@ void mesh_render_data_update_normals(MeshRenderData *mr, const eMRDataType data_
|
|||
mr->loop_len,
|
||||
mr->mpoly,
|
||||
mr->poly_normals,
|
||||
mr->sharp_faces,
|
||||
mr->poly_len,
|
||||
is_auto_smooth,
|
||||
split_angle,
|
||||
|
|
|
@ -372,8 +372,6 @@ struct PBVHBatches {
|
|||
{
|
||||
uint vert_per_grid = square_i(args->ccg_key.grid_size - 1) * 4;
|
||||
uint vert_count = args->totprim * vert_per_grid;
|
||||
const bool *sharp_faces = static_cast<const bool *>(
|
||||
CustomData_get_layer_named(args->pdata, CD_PROP_BOOL, "sharp_face"));
|
||||
|
||||
int existing_num = GPU_vertbuf_get_vertex_len(vbo.vert_buf);
|
||||
void *existing_data = GPU_vertbuf_get_data(vbo.vert_buf);
|
||||
|
@ -412,7 +410,7 @@ struct PBVHBatches {
|
|||
foreach_grids([&](int /*x*/, int /*y*/, int grid_index, CCGElem *elems[4], int /*i*/) {
|
||||
float3 no(0.0f, 0.0f, 0.0f);
|
||||
|
||||
const bool smooth = args->grid_flag_mats[grid_index].flag & ME_SMOOTH;
|
||||
const bool smooth = !args->grid_flag_mats[grid_index].sharp;
|
||||
|
||||
if (smooth) {
|
||||
no = CCG_elem_no(&args->ccg_key, elems[0]);
|
||||
|
@ -1069,8 +1067,6 @@ struct PBVHBatches {
|
|||
{
|
||||
int *mat_index = static_cast<int *>(
|
||||
CustomData_get_layer_named(args->pdata, CD_PROP_INT32, "material_index"));
|
||||
const bool *sharp_faces = static_cast<const bool *>(
|
||||
CustomData_get_layer_named(args->pdata, CD_PROP_BOOL, "sharp_face"));
|
||||
|
||||
if (mat_index && args->totprim) {
|
||||
int poly_index = BKE_subdiv_ccg_grid_to_face_index(args->subdiv_ccg, args->grid_indices[0]);
|
||||
|
@ -1092,7 +1088,7 @@ struct PBVHBatches {
|
|||
|
||||
for (int i : IndexRange(args->totprim)) {
|
||||
int grid_index = args->grid_indices[i];
|
||||
bool smooth = args->grid_flag_mats[grid_index].flag & ME_SMOOTH;
|
||||
bool smooth = !args->grid_flag_mats[grid_index].sharp;
|
||||
BLI_bitmap *gh = args->grid_hidden[grid_index];
|
||||
|
||||
for (int y = 0; y < gridsize - 1; y += skip) {
|
||||
|
|
|
@ -120,6 +120,7 @@ static void extract_tan_init_common(const MeshRenderData *mr,
|
|||
mr->mloop,
|
||||
mr->mlooptri,
|
||||
mr->tri_len,
|
||||
mr->sharp_faces,
|
||||
cd_ldata,
|
||||
calc_active_tangent,
|
||||
r_tangent_names,
|
||||
|
|
|
@ -791,6 +791,8 @@ static int mesh_customdata_custom_splitnormals_add_exec(bContext *C, wmOperator
|
|||
loops.size(),
|
||||
polys.data(),
|
||||
BKE_mesh_poly_normals_ensure(me),
|
||||
static_cast<const bool *>(CustomData_get_layer_named(
|
||||
&me->pdata, CD_PROP_BOOL, "sharp_face")),
|
||||
polys.size(),
|
||||
me->smoothresh);
|
||||
}
|
||||
|
@ -1460,6 +1462,8 @@ void ED_mesh_split_faces(Mesh *mesh)
|
|||
loops.size(),
|
||||
polys.data(),
|
||||
BKE_mesh_poly_normals_ensure(mesh),
|
||||
static_cast<const bool *>(CustomData_get_layer_named(
|
||||
&mesh->pdata, CD_PROP_BOOL, "sharp_face")),
|
||||
polys.size(),
|
||||
split_angle);
|
||||
|
||||
|
|
|
@ -1728,7 +1728,6 @@ static float project_paint_uvpixel_mask(const ProjPaintState *ps,
|
|||
if (ps->do_mask_normal) {
|
||||
const MLoopTri *lt = &ps->mlooptri_eval[tri_index];
|
||||
const int lt_vtri[3] = {PS_LOOPTRI_AS_VERT_INDEX_3(ps, lt)};
|
||||
const MPoly *mp = &ps->mpoly_eval[lt->poly];
|
||||
float no[3], angle_cos;
|
||||
|
||||
if (!(ps->sharp_faces_eval && ps->sharp_faces_eval[lt->poly])) {
|
||||
|
|
|
@ -623,6 +623,12 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
|
|||
MaterialIdPrimitiveArrayMap mat_prim_map;
|
||||
|
||||
int *material_indices = BKE_mesh_material_indices_for_write(me);
|
||||
bool *sharp_faces = (bool *)CustomData_duplicate_referenced_layer_named(
|
||||
&me->pdata, CD_PROP_BOOL, "material_index", me->totpoly);
|
||||
if (sharp_faces) {
|
||||
sharp_faces = (bool *)CustomData_add_layer_named(
|
||||
&me->pdata, CD_PROP_BOOL, CD_SET_DEFAULT, NULL, me->totpoly, "sharp_face");
|
||||
}
|
||||
|
||||
COLLADAFW::MeshPrimitiveArray &prim_arr = collada_mesh->getMeshPrimitives();
|
||||
COLLADAFW::MeshVertexData &nor = collada_mesh->getNormals();
|
||||
|
@ -665,13 +671,14 @@ 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]};
|
||||
if (!is_flat_face(vertex_normal_indices, nor, 3)) {
|
||||
mpoly->flag |= ME_SMOOTH;
|
||||
if (is_flat_face(vertex_normal_indices, nor, 3)) {
|
||||
*sharp_faces = true;
|
||||
}
|
||||
normal_indices++;
|
||||
}
|
||||
|
||||
mpoly++;
|
||||
sharp_faces++;
|
||||
if (material_indices) {
|
||||
material_indices++;
|
||||
}
|
||||
|
@ -738,7 +745,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
|
|||
/* If it turns out that we have complete custom normals for each MPoly
|
||||
* and we want to use custom normals, this will be overridden. */
|
||||
if (!is_flat_face(normal_indices, nor, vcount)) {
|
||||
mpoly->flag |= ME_SMOOTH;
|
||||
*sharp_faces = true;
|
||||
}
|
||||
|
||||
if (use_custom_normals) {
|
||||
|
@ -775,6 +782,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
|
|||
}
|
||||
|
||||
mpoly++;
|
||||
sharp_faces++;
|
||||
if (material_indices) {
|
||||
material_indices++;
|
||||
}
|
||||
|
|
|
@ -196,14 +196,17 @@ void OBJMesh::ensure_mesh_normals() const
|
|||
|
||||
void OBJMesh::calc_smooth_groups(const bool use_bitflags)
|
||||
{
|
||||
poly_smooth_groups_ = BKE_mesh_calc_smoothgroups(mesh_edges_.data(),
|
||||
mesh_edges_.size(),
|
||||
mesh_polys_.data(),
|
||||
mesh_polys_.size(),
|
||||
mesh_loops_.data(),
|
||||
mesh_loops_.size(),
|
||||
&tot_smooth_groups_,
|
||||
use_bitflags);
|
||||
poly_smooth_groups_ = BKE_mesh_calc_smoothgroups(
|
||||
mesh_edges_.data(),
|
||||
mesh_edges_.size(),
|
||||
mesh_polys_.data(),
|
||||
static_cast<const bool *>(
|
||||
CustomData_get_layer_named(&export_mesh_->pdata, CD_PROP_BOOL, "sharp_face")),
|
||||
mesh_polys_.size(),
|
||||
mesh_loops_.data(),
|
||||
mesh_loops_.size(),
|
||||
&tot_smooth_groups_,
|
||||
use_bitflags);
|
||||
}
|
||||
|
||||
void OBJMesh::calc_poly_order()
|
||||
|
|
|
@ -93,19 +93,20 @@ typedef struct MPoly {
|
|||
int totloop;
|
||||
/** Deprecated material index. Now stored in the "material_index" attribute, but kept for IO. */
|
||||
short mat_nr_legacy;
|
||||
char flag, _pad;
|
||||
char flag_legacy, _pad;
|
||||
} MPoly;
|
||||
|
||||
/** #MPoly.flag */
|
||||
enum {
|
||||
#ifdef DNA_DEPRECATED_ALLOW
|
||||
enum {
|
||||
/** Deprecated smooth shading status. Now stored reversed in "sharp_face" attribute. */
|
||||
ME_SMOOTH = (1 << 0),
|
||||
/** Deprecated selection status. Now stored in ".select_poly" attribute. */
|
||||
ME_FACE_SEL = (1 << 1),
|
||||
#endif
|
||||
/** Deprecated hide status. Now stored in ".hide_poly" attribute. */
|
||||
/* ME_HIDE = (1 << 4), */
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Mesh Face Corners.
|
||||
|
|
|
@ -108,6 +108,7 @@ DNA_STRUCT_RENAME_ELEM(Object_Runtime, crazyspace_num_verts, crazyspace_verts_nu
|
|||
DNA_STRUCT_RENAME_ELEM(MEdge, bweight, bweight_legacy)
|
||||
DNA_STRUCT_RENAME_ELEM(MEdge, crease, crease_legacy)
|
||||
DNA_STRUCT_RENAME_ELEM(MPoly, mat_nr, mat_nr_legacy)
|
||||
DNA_STRUCT_RENAME_ELEM(MPoly, flag, flag_legacy)
|
||||
DNA_STRUCT_RENAME_ELEM(MVert, bweight, bweight_legacy)
|
||||
DNA_STRUCT_RENAME_ELEM(MVert, flag, flag_legacy)
|
||||
DNA_STRUCT_RENAME_ELEM(ParticleSettings, child_nbr, child_percent)
|
||||
|
|
|
@ -1536,14 +1536,13 @@ static int rna_MeshLoopTriangle_material_index_get(PointerRNA *ptr)
|
|||
|
||||
static bool rna_MeshLoopTriangle_use_smooth_get(PointerRNA *ptr)
|
||||
{
|
||||
const Mesh *me = rna_mesh(ptr);
|
||||
const bool *sharp_faces = (const bool *)CustomData_get_layer_named(
|
||||
&mesh->pdata, CD_PROP_BOOL, "sharp_face");
|
||||
&me->pdata, CD_PROP_BOOL, "sharp_face");
|
||||
if (!sharp_faces) {
|
||||
return true;
|
||||
}
|
||||
const Mesh *me = rna_mesh(ptr);
|
||||
const MLoopTri *ltri = (MLoopTri *)ptr->data;
|
||||
const MPoly *polys = BKE_mesh_polys(me);
|
||||
return sharp_faces[ltri->poly];
|
||||
}
|
||||
|
||||
|
|
|
@ -91,14 +91,16 @@ static void rna_Mesh_calc_smooth_groups(
|
|||
Mesh *mesh, bool use_bitflags, int *r_poly_group_len, int **r_poly_group, int *r_group_total)
|
||||
{
|
||||
*r_poly_group_len = mesh->totpoly;
|
||||
*r_poly_group = BKE_mesh_calc_smoothgroups(BKE_mesh_edges(mesh),
|
||||
mesh->totedge,
|
||||
BKE_mesh_polys(mesh),
|
||||
mesh->totpoly,
|
||||
BKE_mesh_loops(mesh),
|
||||
mesh->totloop,
|
||||
r_group_total,
|
||||
use_bitflags);
|
||||
*r_poly_group = BKE_mesh_calc_smoothgroups(
|
||||
BKE_mesh_edges(mesh),
|
||||
mesh->totedge,
|
||||
BKE_mesh_polys(mesh),
|
||||
(const bool *)CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face"),
|
||||
mesh->totpoly,
|
||||
BKE_mesh_loops(mesh),
|
||||
mesh->totloop,
|
||||
r_group_total,
|
||||
use_bitflags);
|
||||
}
|
||||
|
||||
static void rna_Mesh_normals_split_custom_do(Mesh *mesh,
|
||||
|
|
|
@ -339,6 +339,8 @@ static void normalEditModifier_do_radial(NormalEditModifierData *enmd,
|
|||
loops_num,
|
||||
mpoly,
|
||||
poly_normals,
|
||||
static_cast<const bool *>(CustomData_get_layer_named(
|
||||
&mesh->pdata, CD_PROP_BOOL, "sharp_face")),
|
||||
polys_num,
|
||||
clnors);
|
||||
|
||||
|
@ -455,6 +457,8 @@ static void normalEditModifier_do_directional(NormalEditModifierData *enmd,
|
|||
loops_num,
|
||||
mpoly,
|
||||
poly_normals,
|
||||
static_cast<const bool *>(CustomData_get_layer_named(
|
||||
&mesh->pdata, CD_PROP_BOOL, "sharp_face")),
|
||||
polys_num,
|
||||
clnors);
|
||||
|
||||
|
@ -559,6 +563,8 @@ static Mesh *normalEditModifier_do(NormalEditModifierData *enmd,
|
|||
loops_num,
|
||||
polys,
|
||||
poly_normals,
|
||||
static_cast<const bool *>(CustomData_get_layer_named(
|
||||
&result->pdata, CD_PROP_BOOL, "sharp_face")),
|
||||
polys_num,
|
||||
true,
|
||||
result->smoothresh,
|
||||
|
|
|
@ -1081,7 +1081,6 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
|
|||
CustomData_copy_data(
|
||||
&mesh->pdata, &result->pdata, (int)pidx, (int)((polys_num * stride) + i), 1);
|
||||
mp->loopstart = (int)(j + (loops_num * stride));
|
||||
mp->flag = mpoly[pidx].flag;
|
||||
|
||||
/* notice we use 'mp->totloop' which is later overwritten,
|
||||
* we could lookup the original face but there's no point since this is a copy
|
||||
|
|
|
@ -2300,7 +2300,6 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
|
|||
dst_material_index[poly_index] = most_mat_nr +
|
||||
(g->is_orig_closed || !do_rim ? 0 : mat_ofs_rim);
|
||||
CLAMP(dst_material_index[poly_index], 0, mat_nr_max);
|
||||
mpoly[poly_index].flag = orig_mpoly[most_mat_nr_face].flag;
|
||||
poly_index++;
|
||||
|
||||
for (uint k = 0; g2->valid && k < j; g2++) {
|
||||
|
@ -2376,7 +2375,6 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
|
|||
dst_material_index[poly_index] =
|
||||
(src_material_index ? src_material_index[orig_face_index] : 0) + mat_ofs_rim;
|
||||
CLAMP(dst_material_index[poly_index], 0, mat_nr_max);
|
||||
mpoly[poly_index].flag = face->flag;
|
||||
poly_index++;
|
||||
|
||||
int loop1 = -1;
|
||||
|
@ -2569,7 +2567,6 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
|
|||
0) +
|
||||
(fr->reversed != do_flip ? mat_ofs : 0);
|
||||
CLAMP(dst_material_index[poly_index], 0, mat_nr_max);
|
||||
mpoly[poly_index].flag = fr->face->flag;
|
||||
if (fr->reversed != do_flip) {
|
||||
for (int l = (int)k - 1; l >= 0; l--) {
|
||||
if (shell_defgrp_index != -1) {
|
||||
|
|
|
@ -84,6 +84,7 @@ struct WeightedNormalData {
|
|||
|
||||
const MPoly *mpoly;
|
||||
const float (*poly_normals)[3];
|
||||
const bool *sharp_faces;
|
||||
const int *poly_strength;
|
||||
|
||||
const MDeformVert *dvert;
|
||||
|
@ -233,6 +234,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
|
|||
loops_num,
|
||||
mpoly,
|
||||
poly_normals,
|
||||
wn_data->sharp_faces,
|
||||
polys_num,
|
||||
true,
|
||||
split_angle,
|
||||
|
@ -365,6 +367,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
|
|||
loops_num,
|
||||
mpoly,
|
||||
poly_normals,
|
||||
wn_data->sharp_faces,
|
||||
polys_num,
|
||||
clnors);
|
||||
}
|
||||
|
@ -396,6 +399,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
|
|||
loops_num,
|
||||
mpoly,
|
||||
poly_normals,
|
||||
wn_data->sharp_faces,
|
||||
polys_num,
|
||||
clnors);
|
||||
|
||||
|
@ -415,6 +419,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
|
|||
loops_num,
|
||||
mpoly,
|
||||
poly_normals,
|
||||
wn_data->sharp_faces,
|
||||
polys_num,
|
||||
true,
|
||||
split_angle,
|
||||
|
@ -439,6 +444,7 @@ static void apply_weights_vertex_normal(WeightedNormalModifierData *wnmd,
|
|||
loops_num,
|
||||
mpoly,
|
||||
poly_normals,
|
||||
wn_data->sharp_faces,
|
||||
polys_num,
|
||||
clnors);
|
||||
}
|
||||
|
@ -642,6 +648,8 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
|
|||
|
||||
wn_data.mpoly = mpoly;
|
||||
wn_data.poly_normals = BKE_mesh_poly_normals_ensure(mesh);
|
||||
wn_data.sharp_faces = static_cast<const bool *>(
|
||||
CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face"));
|
||||
wn_data.poly_strength = static_cast<const int *>(CustomData_get_layer_named(
|
||||
&result->pdata, CD_PROP_INT32, MOD_WEIGHTEDNORMALS_FACEWEIGHT_CDLAYER_ID));
|
||||
|
||||
|
|
|
@ -163,7 +163,6 @@ static MPoly new_poly(const int loopstart, const int totloop)
|
|||
MPoly poly;
|
||||
poly.loopstart = loopstart;
|
||||
poly.totloop = totloop;
|
||||
poly.flag = 0;
|
||||
return poly;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue