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
4 changed files with 28 additions and 49 deletions
Showing only changes of commit a2ce5f5ec6 - Show all commits

View File

@ -574,8 +574,6 @@ void ED_mesh_polys_remove(struct Mesh *mesh, struct ReportList *reports, int cou
void ED_mesh_geometry_clear(struct Mesh *mesh);
void ED_mesh_update(struct Mesh *mesh, struct bContext *C, bool calc_edges, bool calc_edges_loose);
bool *ED_mesh_uv_map_vert_select_layer_ensure(struct Mesh *mesh, int uv_map_index);
bool *ED_mesh_uv_map_edge_select_layer_ensure(struct Mesh *mesh, int uv_map_index);
bool *ED_mesh_uv_map_pin_layer_ensure(struct Mesh *mesh, int uv_map_index);
@ -583,8 +581,6 @@ const bool *ED_mesh_uv_map_vert_select_layer_get(const struct Mesh *mesh, int uv
const bool *ED_mesh_uv_map_edge_select_layer_get(const struct Mesh *mesh, int uv_map_index);
const bool *ED_mesh_uv_map_pin_layer_get(const struct Mesh *mesh, int uv_map_index);
bool ED_mesh_edge_is_loose(const struct Mesh *mesh, int index);
void ED_mesh_uv_ensure(struct Mesh *me, const char *name);
int ED_mesh_uv_add(
struct Mesh *me, const char *name, bool active_set, bool do_init, struct ReportList *reports);

View File

@ -779,33 +779,6 @@ void MESH_OT_customdata_custom_splitnormals_clear(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
void ED_mesh_update(Mesh *mesh, bContext *C, bool calc_edges, bool calc_edges_loose)
{
if (calc_edges || ((mesh->totpoly || mesh->totface) && mesh->totedge == 0)) {
BKE_mesh_calc_edges(mesh, calc_edges, true);
}
if (calc_edges_loose) {
mesh->runtime->loose_edges_cache.tag_dirty();
}
/* Default state is not to have tessface's so make sure this is the case. */
BKE_mesh_tessface_clear(mesh);
mesh->runtime->vert_normals_dirty = true;
mesh->runtime->poly_normals_dirty = true;
DEG_id_tag_update(&mesh->id, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, mesh);
}
bool ED_mesh_edge_is_loose(const Mesh *mesh, const int index)
{
using namespace blender;
const bke::LooseEdgeCache &loose_edges = mesh->loose_edges();
return loose_edges.count > 0 && loose_edges.is_loose_bits[index];
}
static void mesh_add_verts(Mesh *mesh, int len)
{
using namespace blender;

View File

@ -1405,7 +1405,8 @@ static bool rna_MeshEdge_is_loose_get(PointerRNA *ptr)
{
const Mesh *mesh = rna_mesh(ptr);
const int index = rna_MeshEdge_index_get(ptr);
return ED_mesh_edge_is_loose(mesh, index);
const blender::bke::LooseEdgeCache &loose_edges = mesh->loose_edges();
return loose_edges.count > 0 && loose_edges.is_loose_bits[index];
}
static int rna_MeshLoopTriangle_material_index_get(PointerRNA *ptr)

View File

@ -94,18 +94,6 @@ static void rna_Mesh_calc_smooth_groups(
use_bitflags);
}
static void rna_Mesh_normals_split_custom_do(Mesh *mesh,
float (*custom_loop_or_vert_normals)[3],
const bool use_verts)
{
if (use_verts) {
BKE_mesh_set_custom_normals_from_verts(mesh, custom_loop_or_vert_normals);
}
else {
BKE_mesh_set_custom_normals(mesh, custom_loop_or_vert_normals);
}
}
static void rna_Mesh_normals_split_custom_set(Mesh *mesh,
ReportList *reports,
int normals_len,
@ -113,7 +101,6 @@ static void rna_Mesh_normals_split_custom_set(Mesh *mesh,
{
float(*loop_normals)[3] = (float(*)[3])normals;
const int numloops = mesh->totloop;
if (normals_len != numloops * 3) {
BKE_reportf(reports,
RPT_ERROR,
@ -123,7 +110,7 @@ static void rna_Mesh_normals_split_custom_set(Mesh *mesh,
return;
}
rna_Mesh_normals_split_custom_do(mesh, loop_normals, false);
BKE_mesh_set_custom_normals(mesh, loop_normals);
DEG_id_tag_update(&mesh->id, 0);
}
@ -135,7 +122,6 @@ static void rna_Mesh_normals_split_custom_set_from_vertices(Mesh *mesh,
{
float(*vert_normals)[3] = (float(*)[3])normals;
const int numverts = mesh->totvert;
if (normals_len != numverts * 3) {
BKE_reportf(reports,
RPT_ERROR,
@ -145,7 +131,7 @@ static void rna_Mesh_normals_split_custom_set_from_vertices(Mesh *mesh,
return;
}
rna_Mesh_normals_split_custom_do(mesh, vert_normals, true);
BKE_mesh_set_custom_normals_from_verts(mesh, vert_normals);
DEG_id_tag_update(&mesh->id, 0);
}
@ -170,6 +156,29 @@ static void rna_Mesh_flip_normals(Mesh *mesh)
DEG_id_tag_update(&mesh->id, 0);
}
static void rna_Mesh_update(Mesh *mesh,
bContext *C,
const bool calc_edges,
const bool calc_edges_loose)
{
if (calc_edges || ((mesh->totpoly || mesh->totface) && mesh->totedge == 0)) {
BKE_mesh_calc_edges(mesh, calc_edges, true);
}
if (calc_edges_loose) {
mesh->runtime->loose_edges_cache.tag_dirty();
}
/* Default state is not to have tessface's so make sure this is the case. */
BKE_mesh_tessface_clear(mesh);
mesh->runtime->vert_normals_dirty = true;
mesh->runtime->poly_normals_dirty = true;
DEG_id_tag_update(&mesh->id, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, mesh);
}
static void rna_Mesh_update_gpu_tag(Mesh *mesh)
{
BKE_mesh_batch_cache_dirty_tag(mesh, BKE_MESH_BATCH_DIRTY_ALL);
@ -273,7 +282,7 @@ void RNA_api_mesh(StructRNA *srna)
RNA_def_property_multi_array(parm, 2, normals_array_dim);
RNA_def_parameter_flags(parm, PROP_DYNAMIC, PARM_REQUIRED);
func = RNA_def_function(srna, "update", "ED_mesh_update");
func = RNA_def_function(srna, "update", "rna_Mesh_update");
RNA_def_boolean(func, "calc_edges", 0, "Calculate Edges", "Force recalculation of edges");
RNA_def_boolean(func,
"calc_edges_loose",