Mesh: Replace auto smooth with node group #108014

Merged
Hans Goudey merged 149 commits from HooglyBoogly/blender:refactor-mesh-corner-normals-lazy into main 2023-10-20 16:54:20 +02:00
6 changed files with 10 additions and 54 deletions
Showing only changes of commit d05bba2b61 - Show all commits

View File

@ -870,7 +870,6 @@ static void bm_mesh_loops_calc_normals_for_vert_with_clnors(BMesh *bm,
const short (*clnors_data)[2],
const int cd_loop_clnors_offset,
const bool do_rebuild,
const float split_angle_cos,
/* TLS */
MLoopNorSpaceArray *r_lnors_spacearr,
BLI_Stack *edge_vectors,
@ -889,8 +888,6 @@ static void bm_mesh_loops_calc_normals_for_vert_with_clnors(BMesh *bm,
const bool has_clnors = true;
LinkNode *loops_of_vert = nullptr;
int loops_of_vert_count = 0;
/* When false the caller must have already tagged the edges. */
const bool do_edge_tag = (split_angle_cos != EDGE_TAG_FROM_SPLIT_ANGLE_BYPASS);
/* The loop with the lowest index. */
{
@ -903,10 +900,6 @@ static void bm_mesh_loops_calc_normals_for_vert_with_clnors(BMesh *bm,
continue;
}
if (do_edge_tag) {
bm_edge_tag_from_smooth(fnos, e_curr_iter, split_angle_cos);
}
do { /* Radial loops. */
if (l_curr->v != v) {
continue;
@ -997,8 +990,6 @@ static void bm_mesh_loops_calc_normals_for_vert_without_clnors(
{
const bool has_clnors = false;
const short(*clnors_data)[2] = nullptr;
/* When false the caller must have already tagged the edges. */
const bool do_edge_tag = (split_angle_cos != EDGE_TAG_FROM_SPLIT_ANGLE_BYPASS);
const int cd_loop_clnors_offset = -1;
BMEdge *e_curr_iter;
@ -1011,10 +1002,6 @@ static void bm_mesh_loops_calc_normals_for_vert_without_clnors(
continue;
}
if (do_edge_tag) {
bm_edge_tag_from_smooth(fnos, e_curr_iter, split_angle_cos);
}
do { /* Radial loops. */
if (l_curr->v != v) {
continue;
@ -1071,8 +1058,6 @@ static void bm_mesh_loops_calc_normals__single_threaded(BMesh *bm,
BMIter fiter;
BMFace *f_curr;
const bool has_clnors = clnors_data || (cd_loop_clnors_offset != -1);
/* When false the caller must have already tagged the edges. */
const bool do_edge_tag = (split_angle_cos != EDGE_TAG_FROM_SPLIT_ANGLE_BYPASS);
MLoopNorSpaceArray _lnors_spacearr = {nullptr};
@ -1111,12 +1096,6 @@ static void bm_mesh_loops_calc_normals__single_threaded(BMesh *bm,
}
bm->elem_index_dirty &= ~(BM_FACE | BM_LOOP);
/* Always tag edges based on winding & sharp edge flag
* (even when the auto-smooth angle doesn't need to be calculated). */
if (do_edge_tag) {
bm_mesh_edges_sharp_tag(bm, fnos, has_clnors ? -1.0f : split_angle_cos, false);
}
/* We now know edges that can be smoothed (they are tagged),
* and edges that will be hard (they aren't).
* Now, time to generate the normals.
@ -1228,7 +1207,6 @@ static void bm_mesh_loops_calc_normals_for_vert_with_clnors_fn(
data->clnors_data,
data->cd_loop_clnors_offset,
data->do_rebuild,
data->split_angle_cos,
/* Thread local. */
tls_data->lnors_spacearr,
tls_data->edge_vectors,
@ -1565,15 +1543,8 @@ static void bm_mesh_loops_custom_normals_set(BMesh *bm,
/* Finish computing lnos by accumulating face normals
* in each fan of faces defined by sharp edges. */
bm_mesh_loops_calc_normals(bm,
vcos,
fnos,
cur_lnors,
r_lnors_spacearr,
r_clnors_data,
cd_loop_clnors_offset,
false,
EDGE_TAG_FROM_SPLIT_ANGLE_BYPASS);
bm_mesh_loops_calc_normals(
bm, vcos, fnos, cur_lnors, r_lnors_spacearr, r_clnors_data, cd_loop_clnors_offset, false);
/* Extract new normals from the data layer if necessary. */
float(*custom_lnors)[3] = new_lnors;
@ -1607,15 +1578,8 @@ static void bm_mesh_loops_custom_normals_set(BMesh *bm,
* spacearr/smooth fans matching the given custom lnors. */
BKE_lnor_spacearr_clear(r_lnors_spacearr);
bm_mesh_loops_calc_normals(bm,
vcos,
fnos,
cur_lnors,
r_lnors_spacearr,
r_clnors_data,
cd_loop_clnors_offset,
false,
EDGE_TAG_FROM_SPLIT_ANGLE_BYPASS);
bm_mesh_loops_calc_normals(
bm, vcos, fnos, cur_lnors, r_lnors_spacearr, r_clnors_data, cd_loop_clnors_offset, false);
}
/* And we just have to convert plain object-space custom normals to our
@ -1674,7 +1638,6 @@ void BM_loops_calc_normal_vcos(BMesh *bm,
const int cd_loop_clnors_offset,
const bool do_rebuild)
{
const bool has_clnors = clnors_data || (cd_loop_clnors_offset != -1);
if (use_split_normals) {
bm_mesh_loops_calc_normals(

View File

@ -337,8 +337,6 @@ void mesh_render_data_update_looptris(MeshRenderData *mr,
void mesh_render_data_update_normals(MeshRenderData *mr, const eMRDataType data_flag)
{
Mesh *me = mr->me;
if (mr->extract_type != MR_EXTRACT_BMESH) {
/* Mesh */
mr->vert_normals = mr->me->vert_normals();
HooglyBoogly marked this conversation as resolved Outdated

Looks like there is a "not" missing. Same below.

Looks like there is a "not" missing. Same below.

View File

@ -62,8 +62,7 @@ namespace blender::io::alembic {
static void get_vertices(struct Mesh *mesh, std::vector<Imath::V3f> &points);
static void get_topology(struct Mesh *mesh,
std::vector<int32_t> &poly_verts,
std::vector<int32_t> &loop_counts,
bool &r_has_flat_shaded_poly);
std::vector<int32_t> &loop_counts);
static void get_edge_creases(struct Mesh *mesh,
std::vector<int32_t> &indices,
std::vector<int32_t> &lengths,
@ -71,9 +70,7 @@ static void get_edge_creases(struct Mesh *mesh,
static void get_vert_creases(struct Mesh *mesh,
std::vector<int32_t> &indices,
std::vector<float> &sharpnesses);
static void get_loop_normals(struct Mesh *mesh,
std::vector<Imath::V3f> &normals,
bool has_flat_shaded_poly);
static void get_loop_normals(struct Mesh *mesh, std::vector<Imath::V3f> &normals);
ABCGenericMeshWriter::ABCGenericMeshWriter(const ABCWriterConstructorArgs &args)
: ABCAbstractWriter(args), is_subd_(false)

View File

@ -372,12 +372,12 @@ void OBJMesh::store_normal_coords_and_indices()
for (int poly_index = 0; poly_index < export_mesh_->totpoly; ++poly_index) {
const IndexRange poly = mesh_polys_[poly_index];
bool need_per_loop_normals = lnors != nullptr || !(sharp_faces_[poly_index]);
bool need_per_loop_normals = !corner_normals.is_empty() && !(sharp_faces_[poly_index]);
if (need_per_loop_normals) {
for (const int corner : poly) {
float3 loop_normal;
BLI_assert(corner < export_mesh_->totloop);
copy_v3_v3(loop_normal, lnors[corner]);
copy_v3_v3(loop_normal, corner_normals[corner]);
mul_m3_v3(world_and_axes_normal_transform_, loop_normal);
normalize_v3(loop_normal);
float3 rounded_loop_normal = round_float3_to_n_digits(loop_normal, round_digits);

View File

@ -620,11 +620,10 @@ static void rna_MeshLoop_bitangent_get(PointerRNA *ptr, float *values)
Mesh *me = rna_mesh(ptr);
const int index = rna_MeshLoop_index_get(ptr);
const float(*loop_normals)[3] = BKE_mesh_corner_normals_ensure(me);
const float(*nor)[3] = loop_normals[index];
const float(*vec)[4] = CustomData_get(&me->ldata, index, CD_MLOOPTANGENT);
if (nor && vec) {
cross_v3_v3v3(values, nor[index], vec[index]);
if (vec) {
cross_v3_v3v3(values, loop_normals[index][index], vec[index]);
mul_v3_fl(values, vec[index][3]);
}
else {

View File

@ -51,7 +51,6 @@ static void rna_Mesh_create_normals_split(Mesh *mesh)
static void rna_Mesh_free_normals_split(Mesh *mesh)
{
/* TODO: Deprecation? */
BKE_mesh_normals_tag_dirty(mesh);
}
static void rna_Mesh_calc_tangents(Mesh *mesh, ReportList *reports, const char *uvmap)