Design task: #93551 This PR replaces the auto smooth option with a geometry nodes modifier that sets the sharp edge attribute. This solves a fair number of long- standing problems related to auto smooth, simplifies the process of normal computation, and allows Blender to automatically choose between face, vertex, and face corner normals based on the sharp edge and face attributes. Versioning adds a geometry node group to objects with meshes that had auto-smooth enabled. The modifier can be applied, which also improves performance. Auto smooth is now unnecessary to get a combination of sharp and smooth edges. In general workflows are changed a bit. Separate procedural and destructive workflows are available. Custom normals can be used immediately without turning on the removed auto smooth option. **Procedural** The node group asset "Smooth by Angle" is the main way to set sharp normals based on the edge angle. It can be accessed directly in the add modifier menu. Of course the modifier can be reordered, muted, or applied like any other, or changed internally like any geometry nodes modifier. **Destructive** Often the sharp edges don't need to be dynamic. This can give better performance since edge angles don't need to be recalculated. In edit mode the two operators "Select Sharp Edges" and "Mark Sharp" can be used. In other modes, the "Shade Smooth by Angle" controls the edge sharpness directly. ### Breaking API Changes - `use_auto_smooth` is removed. Face corner normals are now used automatically if there are mixed smooth vs. not smooth tags. Meshes now always use custom normals if they exist. - In Cycles, the lack of the separate auto smooth state makes normals look triangulated when all faces are shaded smooth. - `auto_smooth_angle` is removed. Replaced by a modifier (or operator) controlling the sharp edge attribute. This means the mesh itself (without an object) doesn't know anything about automatically smoothing by angle anymore. - `create_normals_split`, `calc_normals_split`, and `free_normals_split` are removed, and are replaced by the simpler `Mesh.corner_normals` collection property. Since it gives access to the normals cache, it is automatically updated when relevant data changes. Addons are updated here: https://projects.blender.org/blender/blender-addons/pulls/104609 ### Tests - `geo_node_curves_test_deform_curves_on_surface` has slightly different results because face corner normals are used instead of interpolated vertex normals. - `bf_wavefront_obj_tests` has different export results for one file which mixed sharp and smooth faces without turning on auto smooth. - `cycles_mesh_cpu` has one object which is completely flat shaded. Previously every edge was split before rendering, now it looks triangulated. Pull Request: https://projects.blender.org/blender/blender/pulls/108014
129 lines
4.3 KiB
C
129 lines
4.3 KiB
C
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#pragma once
|
|
|
|
/** \file
|
|
* \ingroup bke
|
|
*
|
|
* The \link edmesh EDBM module \endlink is for editmode bmesh stuff.
|
|
* In contrast, this module is for code shared with blenkernel that's
|
|
* only concerned with low level operations on the #BMEditMesh structure.
|
|
*/
|
|
|
|
#include "DNA_customdata_types.h"
|
|
#include "bmesh.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
struct BMLoop;
|
|
struct BMPartialUpdate;
|
|
struct BMesh;
|
|
struct BMeshCalcTessellation_Params;
|
|
struct BoundBox;
|
|
struct Depsgraph;
|
|
struct Mesh;
|
|
struct Object;
|
|
struct Scene;
|
|
|
|
/**
|
|
* This structure is used for mesh edit-mode.
|
|
*
|
|
* Through this, you get access to both the edit #BMesh, its tessellation,
|
|
* and various data that doesn't belong in the #BMesh struct itself
|
|
* (mostly related to mesh evaluation).
|
|
*
|
|
* The entire modifier system works with this structure, and not #BMesh.
|
|
* #Mesh.edit_bmesh stores a pointer to this structure. */
|
|
typedef struct BMEditMesh {
|
|
struct BMesh *bm;
|
|
|
|
/**
|
|
* Face triangulation (tessellation) is stored as triplets of three loops,
|
|
* which each define a triangle.
|
|
*
|
|
* \see #MLoopTri as the documentation gives useful hints that apply to this data too.
|
|
*/
|
|
struct BMLoop *(*looptris)[3];
|
|
int tottri;
|
|
|
|
/** Selection mode (#SCE_SELECT_VERTEX, #SCE_SELECT_EDGE & #SCE_SELECT_FACE). */
|
|
short selectmode;
|
|
/** The active material (assigned to newly created faces). */
|
|
short mat_nr;
|
|
|
|
/** Temp variables for x-mirror editing (-1 when the layer does not exist). */
|
|
int mirror_cdlayer;
|
|
|
|
/**
|
|
* Enable for evaluated copies, causes the edit-mesh to free the memory, not its contents.
|
|
*/
|
|
char is_shallow_copy;
|
|
|
|
/**
|
|
* ID data is older than edit-mode data.
|
|
* Set #Main.is_memfile_undo_flush_needed when enabling.
|
|
*/
|
|
char needs_flush_to_id;
|
|
|
|
} BMEditMesh;
|
|
|
|
/* editmesh.cc */
|
|
|
|
void BKE_editmesh_looptri_calc_ex(BMEditMesh *em,
|
|
const struct BMeshCalcTessellation_Params *params);
|
|
void BKE_editmesh_looptri_calc(BMEditMesh *em);
|
|
void BKE_editmesh_looptri_calc_with_partial_ex(BMEditMesh *em,
|
|
struct BMPartialUpdate *bmpinfo,
|
|
const struct BMeshCalcTessellation_Params *params);
|
|
void BKE_editmesh_looptri_calc_with_partial(BMEditMesh *em, struct BMPartialUpdate *bmpinfo);
|
|
void BKE_editmesh_looptri_and_normals_calc_with_partial(BMEditMesh *em,
|
|
struct BMPartialUpdate *bmpinfo);
|
|
|
|
/**
|
|
* Performing the face normal calculation at the same time as tessellation
|
|
* gives a reasonable performance boost (approx ~20% faster).
|
|
*/
|
|
void BKE_editmesh_looptri_and_normals_calc(BMEditMesh *em);
|
|
|
|
/**
|
|
* \note The caller is responsible for ensuring triangulation data,
|
|
* typically by calling #BKE_editmesh_looptri_calc.
|
|
*/
|
|
BMEditMesh *BKE_editmesh_create(BMesh *bm);
|
|
BMEditMesh *BKE_editmesh_copy(BMEditMesh *em);
|
|
/**
|
|
* \brief Return the #BMEditMesh for a given object
|
|
*
|
|
* \note this function assumes this is a mesh object,
|
|
* don't add NULL data check here. caller must do that
|
|
*/
|
|
BMEditMesh *BKE_editmesh_from_object(struct Object *ob);
|
|
/**
|
|
* \note Does not free the #BMEditMesh struct itself.
|
|
*/
|
|
void BKE_editmesh_free_data(BMEditMesh *em);
|
|
|
|
float (*BKE_editmesh_vert_coords_alloc(struct Depsgraph *depsgraph,
|
|
struct BMEditMesh *em,
|
|
struct Scene *scene,
|
|
struct Object *ob,
|
|
int *r_vert_len))[3];
|
|
float (*BKE_editmesh_vert_coords_alloc_orco(BMEditMesh *em, int *r_vert_len))[3];
|
|
const float (*BKE_editmesh_vert_coords_when_deformed(struct Depsgraph *depsgraph,
|
|
struct BMEditMesh *em,
|
|
struct Scene *scene,
|
|
struct Object *obedit,
|
|
int *r_vert_len,
|
|
bool *r_is_alloc))[3];
|
|
|
|
void BKE_editmesh_lnorspace_update(BMEditMesh *em);
|
|
struct BoundBox *BKE_editmesh_cage_boundbox_get(struct Object *object, BMEditMesh *em);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|