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
18 changed files with 26 additions and 26 deletions
Showing only changes of commit c3fa88c1f2 - Show all commits

View File

@ -1045,8 +1045,8 @@ static void create_mesh(Scene *scene,
const int polys_num = b_mesh.polygons.length();
int numfaces = (!subdivision) ? b_mesh.loop_triangles.length() : b_mesh.polygons.length();
const int numcorners = b_mesh.loops.length();
bool use_loop_normals = b_mesh.normal_domain_all_info() ==
BL::Mesh::normal_domain_all_info_CORNER &&
bool use_loop_normals = b_mesh.normals_domain() ==
BL::Mesh::normals_domain_CORNER &&
(mesh->get_subdivision_type() != Mesh::SUBDIVISION_CATMULL_CLARK);
/* If no faces, create empty mesh. */

View File

@ -93,7 +93,7 @@ static inline BL::Mesh object_to_mesh(BL::BlendData & /*data*/,
* Also in edit mode do we need to make a copy, to ensure data layers like
* UV are not empty. */
if (mesh.is_editmode() ||
(mesh.normal_domain_all_info() == BL::Mesh::normal_domain_all_info_CORNER &&
(mesh.normals_domain() == BL::Mesh::normals_domain_CORNER &&
subdivision_type == Mesh::SUBDIVISION_NONE))
{
BL::Depsgraph depsgraph(PointerRNA_NULL);
@ -119,7 +119,7 @@ static inline BL::Mesh object_to_mesh(BL::BlendData & /*data*/,
#endif
if ((bool)mesh && subdivision_type == Mesh::SUBDIVISION_NONE) {
if (mesh.normal_domain_all_info() == BL::Mesh::normal_domain_all_info_CORNER) {
if (mesh.normals_domain() == BL::Mesh::normals_domain_CORNER) {
mesh.split_faces();
}

View File

@ -449,7 +449,7 @@ static void add_orco_mesh(
static void mesh_calc_modifier_final_normals(const bool sculpt_dyntopo, Mesh *mesh_final)
{
const eAttrDomain domain = eAttrDomain(mesh_final->normal_domain_all_info());
const eAttrDomain domain = eAttrDomain(mesh_final->normals_domain());
/* Needed as `final_datamask` is not preserved outside modifier stack evaluation. */
SubsurfRuntimeData *subsurf_runtime_data = mesh_final->runtime->subsurf_runtime_data;

View File

@ -299,7 +299,7 @@ static void normals_calc_faces_and_verts(const Span<float3> positions,
/** \name Mesh Normal Calculation
* \{ */
int Mesh::normal_domain_all_info() const
int Mesh::normals_domain() const
{
using namespace blender;
using namespace blender::bke;
@ -390,7 +390,7 @@ blender::Span<blender::float3> Mesh::corner_normals() const
this->runtime->corner_normals_cache.ensure([&](Vector<float3> &r_data) {
const OffsetIndices faces = this->faces();
r_data.reinitialize(faces.total_size());
switch (this->normal_domain_all_info()) {
switch (this->normals_domain()) {
case ATTR_DOMAIN_POINT: {
array_utils::gather(this->vert_normals(), this->corner_verts(), r_data.as_mutable_span());
break;

View File

@ -142,7 +142,7 @@ bool BKE_shrinkwrap_init_tree(
if (force_normals || BKE_shrinkwrap_needs_normals(shrinkType, shrinkMode)) {
data->face_normals = reinterpret_cast<const float(*)[3]>(mesh->face_normals().data());
if (mesh->normal_domain_all_info() == ATTR_DOMAIN_CORNER) {
if (mesh->normals_domain() == ATTR_DOMAIN_CORNER) {
data->clnors = reinterpret_cast<const float(*)[3]>(mesh->corner_normals().data());
}
}

View File

@ -87,7 +87,7 @@ static ModifierData *modifier_get_last_enabled_for_mode(const Scene *scene,
bool BKE_subsurf_modifier_use_custom_loop_normals(const SubsurfModifierData *smd, const Mesh *mesh)
{
return smd->flags & eSubsurfModifierFlag_UseCustomNormals &&
mesh->normal_domain_all_info() == ATTR_DOMAIN_CORNER;
mesh->normals_domain() == ATTR_DOMAIN_CORNER;
}
static bool is_subdivision_evaluation_possible_on_gpu()

View File

@ -402,7 +402,7 @@ class VArrayImpl_For_SharpEdge : public VArrayImpl<bool> {
/**
* Returns whether loop normals are required because of mixed sharp and smooth flags.
* Similar to #Mesh::normal_domain_all_info().
* Similar to #Mesh::normals_domain().
*/
static bool bm_loop_normals_required(BMesh *bm)
{
@ -447,7 +447,7 @@ void mesh_render_data_update_normals(MeshRenderData &mr, const eMRDataType data_
mr.face_normals = mr.me->face_normals();
}
if (((data_flag & MR_DATA_LOOP_NOR) &&
ELEM(mr.me->normal_domain_all_info(), ATTR_DOMAIN_CORNER, ATTR_DOMAIN_FACE)) ||
ELEM(mr.me->normals_domain(), ATTR_DOMAIN_CORNER, ATTR_DOMAIN_FACE)) ||
(data_flag & MR_DATA_TAN_LOOP_NOR))
{
mr.loop_normals = mr.me->corner_normals();

View File

@ -2152,7 +2152,7 @@ static bool draw_subdiv_create_requested_buffers(Object *ob,
runtime_data->stats_totloop = draw_cache.num_subdiv_loops;
draw_cache.use_custom_loop_normals = (runtime_data->use_loop_normals) &&
mesh_eval->normal_domain_all_info() == ATTR_DOMAIN_CORNER;
mesh_eval->normals_domain() == ATTR_DOMAIN_CORNER;
if (DRW_ibo_requested(mbc.buff.ibo.tris)) {
draw_subdiv_cache_ensure_mat_offsets(draw_cache, mesh_eval, batch_cache.mat_len);

View File

@ -712,7 +712,7 @@ static Mesh *bake_mesh_new_from_object(Depsgraph *depsgraph,
{
Mesh *me = BKE_mesh_new_from_object(depsgraph, object, false, preserve_origindex);
if (me->normal_domain_all_info() == ATTR_DOMAIN_CORNER) {
if (me->normals_domain() == ATTR_DOMAIN_CORNER) {
ED_mesh_split_faces(me);
}

View File

@ -525,7 +525,7 @@ static void get_loop_normals(const Mesh *mesh, std::vector<Imath::V3f> &normals)
{
normals.clear();
switch (mesh->normal_domain_all_info()) {
switch (mesh->normals_domain()) {
case ATTR_DOMAIN_POINT: {
/* If all faces are smooth shaded, and there are no custom normals, we don't need to
* export normals at all. This is also done by other software, see #71246. */

View File

@ -626,7 +626,7 @@ void GeometryExporter::create_normals(std::vector<Normal> &normals,
"sharp_face", ATTR_DOMAIN_FACE, false);
blender::Span<blender::float3> corner_normals;
if (me->normal_domain_all_info() == ATTR_DOMAIN_CORNER) {
if (me->normals_domain() == ATTR_DOMAIN_CORNER) {
corner_normals = me->corner_normals();
}

View File

@ -232,7 +232,7 @@ void MeshData::write_submeshes(const Mesh *mesh)
const Span<MLoopTri> looptris = mesh->looptris();
Span<float3> corner_normals;
if (mesh->normal_domain_all_info() == ATTR_DOMAIN_CORNER) {
if (mesh->normals_domain() == ATTR_DOMAIN_CORNER) {
corner_normals = mesh->corner_normals();
}

View File

@ -661,7 +661,7 @@ void USDGenericMeshWriter::write_normals(const Mesh *mesh, pxr::UsdGeomMesh usd_
MutableSpan dst_normals(reinterpret_cast<float3 *>(loop_normals.data()), loop_normals.size());
switch (mesh->normal_domain_all_info()) {
switch (mesh->normals_domain()) {
case ATTR_DOMAIN_POINT: {
array_utils::gather(mesh->vert_normals(), mesh->corner_verts(), dst_normals);
break;

View File

@ -368,7 +368,7 @@ void OBJMesh::store_normal_coords_and_indices()
loop_to_normal_index_.fill(-1);
Span<float3> corner_normals;
if (export_mesh_->normal_domain_all_info() == ATTR_DOMAIN_CORNER) {
if (export_mesh_->normals_domain() == ATTR_DOMAIN_CORNER) {
corner_normals = export_mesh_->corner_normals();
}

View File

@ -366,7 +366,7 @@ typedef struct Mesh {
* face corner normals, since there is a 2-4x performance cost increase for each more complex
* domain.
*/
int normal_domain_all_info() const;
int normals_domain() const;
HooglyBoogly marked this conversation as resolved Outdated

I wonder if we could call this normals_domain. I found "all info" more confusing than useful at first.

I wonder if we could call this `normals_domain`. I found "all info" more confusing than useful at first.
/**
* Normal direction of polygons, defined by positions and the winding direction of face corners.
*/
@ -381,7 +381,7 @@ typedef struct Mesh {
* normals, the `sharp_edge` and `sharp_face` attributes, and potentially by custom normals.
*
* \note Because of the large memory requirements of storing normals per face corner, prefer
* using #face_normals() or #vert_normals() when possible (see #normal_domain_all_info()).
* using #face_normals() or #vert_normals() when possible (see #normals_domain()).
*/
blender::Span<blender::float3> corner_normals() const;
#endif

View File

@ -1611,9 +1611,9 @@ int rna_Mesh_loops_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
return true;
}
static int rna_Mesh_normal_domain_all_info_get(PointerRNA *ptr)
static int rna_Mesh_normals_domain_get(PointerRNA *ptr)
{
return rna_mesh(ptr)->normal_domain_all_info();
return rna_mesh(ptr)->normals_domain();
}
static void rna_Mesh_vertex_normals_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
@ -2996,14 +2996,14 @@ static void rna_def_mesh(BlenderRNA *brna)
rna_def_normal_layer_value(brna);
prop = RNA_def_property(srna, "normal_domain_all_info", PROP_ENUM, PROP_NONE);
prop = RNA_def_property(srna, "normals_domain", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, rna_enum_attribute_domain_only_mesh_no_edge_items);
RNA_def_property_ui_text(
prop,
"Normal Domain All Info",
"The attribute domain that gives enough information to represent the mesh's normals");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_enum_funcs(prop, "rna_Mesh_normal_domain_all_info_get", NULL, NULL);
RNA_def_property_enum_funcs(prop, "rna_Mesh_normals_domain_get", NULL, NULL);
prop = RNA_def_property(srna, "vertex_normals", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "MeshNormalValue");

View File

@ -216,7 +216,7 @@ static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh
return result;
}
const bool use_clnors = mmd->flags & eMultiresModifierFlag_UseCustomNormals &&
mesh->normal_domain_all_info() == ATTR_DOMAIN_CORNER;
mesh->normals_domain() == ATTR_DOMAIN_CORNER;
/* NOTE: Orco needs final coordinates on CPU side, which are expected to be
* accessible via mesh vertices. For this reason we do not evaluate multires to
* grids when orco is requested. */

View File

@ -336,7 +336,7 @@ static void compute_normal_outputs(const Mesh &mesh,
const Span<int> looptri_indices,
MutableSpan<float3> r_normals)
{
switch (mesh.normal_domain_all_info()) {
switch (mesh.normals_domain()) {
case ATTR_DOMAIN_POINT: {
const Span<int> corner_verts = mesh.corner_verts();
const Span<MLoopTri> looptris = mesh.looptris();