2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2005 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2013-04-16 05:46:17 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2013-04-16 05:46:17 +00:00
|
|
|
*/
|
|
|
|
|
|
2013-04-16 05:59:48 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2013-04-16 05:46:17 +00:00
|
|
|
|
2013-04-16 05:59:48 +00:00
|
|
|
#include "DNA_listBase.h"
|
|
|
|
|
#include "DNA_mesh_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_object_types.h"
|
2013-04-16 05:46:17 +00:00
|
|
|
|
2020-02-26 14:24:57 +11:00
|
|
|
#include "BLI_bitmap.h"
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_geom.h"
|
|
|
|
|
#include "BLI_math_vector.h"
|
2013-04-16 05:46:17 +00:00
|
|
|
|
2020-02-26 14:24:57 +11:00
|
|
|
#include "BKE_DerivedMesh.h"
|
2022-05-15 20:27:28 +02:00
|
|
|
#include "BKE_customdata.h"
|
2013-04-16 05:46:17 +00:00
|
|
|
#include "BKE_editmesh.h"
|
2023-07-07 08:19:52 -04:00
|
|
|
#include "BKE_editmesh_cache.hh"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2023-03-12 22:29:15 +01:00
|
|
|
#include "BKE_mesh.hh"
|
2023-08-02 22:14:18 +02:00
|
|
|
#include "BKE_mesh_iterators.hh"
|
|
|
|
|
#include "BKE_mesh_wrapper.hh"
|
2023-10-09 23:41:53 +02:00
|
|
|
#include "BKE_object.hh"
|
2013-04-16 05:46:17 +00:00
|
|
|
|
2023-09-22 03:18:17 +02:00
|
|
|
#include "DEG_depsgraph_query.hh"
|
2022-01-11 15:42:07 +01:00
|
|
|
|
2021-07-13 15:05:39 +10:00
|
|
|
BMEditMesh *BKE_editmesh_create(BMesh *bm)
|
2013-04-16 05:46:17 +00:00
|
|
|
{
|
2022-09-29 18:32:44 -05:00
|
|
|
BMEditMesh *em = MEM_cnew<BMEditMesh>(__func__);
|
2013-04-16 05:46:17 +00:00
|
|
|
em->bm = bm;
|
|
|
|
|
return em;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-16 05:59:48 +00:00
|
|
|
BMEditMesh *BKE_editmesh_copy(BMEditMesh *em)
|
2013-04-16 05:46:17 +00:00
|
|
|
{
|
2022-09-29 18:32:44 -05:00
|
|
|
BMEditMesh *em_copy = MEM_cnew<BMEditMesh>(__func__);
|
2013-04-16 05:46:17 +00:00
|
|
|
*em_copy = *em;
|
|
|
|
|
|
|
|
|
|
em_copy->bm = BM_mesh_copy(em->bm);
|
|
|
|
|
|
|
|
|
|
/* The tessellation is NOT calculated on the copy here,
|
|
|
|
|
* because currently all the callers of this function use
|
2019-08-17 00:54:22 +10:00
|
|
|
* it to make a backup copy of the #BMEditMesh to restore
|
|
|
|
|
* it in the case of errors in an operation. For performance reasons,
|
|
|
|
|
* in that case it makes more sense to do the
|
|
|
|
|
* tessellation only when/if that copy ends up getting used. */
|
2022-09-29 18:32:44 -05:00
|
|
|
em_copy->looptris = nullptr;
|
2013-04-16 05:46:17 +00:00
|
|
|
|
2020-04-08 16:24:33 +10:00
|
|
|
/* Copy various settings. */
|
|
|
|
|
em_copy->selectmode = em->selectmode;
|
|
|
|
|
em_copy->mat_nr = em->mat_nr;
|
|
|
|
|
|
2013-04-16 05:46:17 +00:00
|
|
|
return em_copy;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-16 05:59:48 +00:00
|
|
|
BMEditMesh *BKE_editmesh_from_object(Object *ob)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
/* sanity check */
|
2022-10-03 10:24:08 +11:00
|
|
|
#if 0 /* disable in multi-object edit. */
|
2013-04-16 05:59:48 +00:00
|
|
|
# ifndef NDEBUG
|
2019-02-17 18:05:18 +11:00
|
|
|
if (((Mesh *)ob->data)->edit_mesh) {
|
|
|
|
|
BLI_assert(((Mesh *)ob->data)->edit_mesh->ob == ob);
|
2013-04-16 05:59:48 +00:00
|
|
|
}
|
2018-04-16 16:27:55 +02:00
|
|
|
# endif
|
2013-04-16 05:59:48 +00:00
|
|
|
#endif
|
2019-02-17 18:05:18 +11:00
|
|
|
return ((Mesh *)ob->data)->edit_mesh;
|
2013-04-16 05:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
2021-06-14 22:56:03 +10:00
|
|
|
static void editmesh_tessface_calc_intern(BMEditMesh *em,
|
2022-09-29 18:32:44 -05:00
|
|
|
const BMeshCalcTessellation_Params *params)
|
2013-04-16 05:46:17 +00:00
|
|
|
{
|
2013-11-18 18:20:21 +11:00
|
|
|
/* allocating space before calculating the tessellation */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-16 05:46:17 +00:00
|
|
|
BMesh *bm = em->bm;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-08-17 00:54:22 +10:00
|
|
|
/* This assumes all faces can be scan-filled, which isn't always true,
|
|
|
|
|
* worst case we over allocate a little which is acceptable. */
|
2013-04-16 05:46:17 +00:00
|
|
|
const int looptris_tot = poly_to_tri_count(bm->totface, bm->totloop);
|
|
|
|
|
const int looptris_tot_prev_alloc = em->looptris ?
|
|
|
|
|
(MEM_allocN_len(em->looptris) / sizeof(*em->looptris)) :
|
|
|
|
|
0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-16 05:46:17 +00:00
|
|
|
BMLoop *(*looptris)[3];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-10-03 10:24:08 +11:00
|
|
|
/* This means no reallocations for quad dominant models. */
|
2022-09-29 18:32:44 -05:00
|
|
|
if ((em->looptris != nullptr) &&
|
2022-10-03 10:24:08 +11:00
|
|
|
// (*em->tottri >= looptris_tot))
|
2019-08-17 00:54:22 +10:00
|
|
|
/* Check against allocated size in case we over allocated a little. */
|
2013-04-16 05:46:17 +00:00
|
|
|
((looptris_tot_prev_alloc >= looptris_tot) && (looptris_tot_prev_alloc <= looptris_tot * 2)))
|
|
|
|
|
{
|
|
|
|
|
looptris = em->looptris;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (em->looptris) {
|
2013-04-16 05:46:17 +00:00
|
|
|
MEM_freeN(em->looptris);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2022-09-29 18:32:44 -05:00
|
|
|
looptris = static_cast<BMLoop *(*)[3]>(
|
|
|
|
|
MEM_mallocN(sizeof(*looptris) * looptris_tot, __func__));
|
2013-04-16 05:46:17 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-16 05:46:17 +00:00
|
|
|
em->looptris = looptris;
|
2021-06-01 12:49:22 +10:00
|
|
|
em->tottri = looptris_tot;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-18 18:20:21 +11:00
|
|
|
/* after allocating the em->looptris, we're ready to tessellate */
|
2021-06-14 22:56:03 +10:00
|
|
|
BM_mesh_calc_tessellation_ex(em->bm, em->looptris, params);
|
2013-04-16 05:46:17 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-29 18:32:44 -05:00
|
|
|
void BKE_editmesh_looptri_calc_ex(BMEditMesh *em, const BMeshCalcTessellation_Params *params)
|
2013-04-16 05:46:17 +00:00
|
|
|
{
|
2021-06-14 22:56:03 +10:00
|
|
|
editmesh_tessface_calc_intern(em, params);
|
2013-04-16 05:46:17 +00:00
|
|
|
}
|
|
|
|
|
|
2021-06-14 22:56:03 +10:00
|
|
|
void BKE_editmesh_looptri_calc(BMEditMesh *em)
|
|
|
|
|
{
|
2022-09-29 18:32:44 -05:00
|
|
|
BMeshCalcTessellation_Params params{};
|
|
|
|
|
params.face_normals = false;
|
|
|
|
|
BKE_editmesh_looptri_calc_ex(em, ¶ms);
|
2021-06-14 22:56:03 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_editmesh_looptri_and_normals_calc(BMEditMesh *em)
|
|
|
|
|
{
|
2022-09-29 18:32:44 -05:00
|
|
|
BMeshCalcTessellation_Params looptri_params{};
|
|
|
|
|
looptri_params.face_normals = true;
|
|
|
|
|
BKE_editmesh_looptri_calc_ex(em, &looptri_params);
|
|
|
|
|
BMeshNormalsUpdate_Params normals_params{};
|
|
|
|
|
normals_params.face_normals = false;
|
|
|
|
|
BM_mesh_normals_update_ex(em->bm, &normals_params);
|
2021-06-14 22:56:03 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_editmesh_looptri_calc_with_partial_ex(BMEditMesh *em,
|
2022-09-29 18:32:44 -05:00
|
|
|
BMPartialUpdate *bmpinfo,
|
|
|
|
|
const BMeshCalcTessellation_Params *params)
|
2021-05-28 18:18:13 +10:00
|
|
|
{
|
|
|
|
|
BLI_assert(em->tottri == poly_to_tri_count(em->bm->totface, em->bm->totloop));
|
2022-09-29 18:32:44 -05:00
|
|
|
BLI_assert(em->looptris != nullptr);
|
2021-05-28 18:18:13 +10:00
|
|
|
|
2021-06-14 22:56:03 +10:00
|
|
|
BM_mesh_calc_tessellation_with_partial_ex(em->bm, em->looptris, bmpinfo, params);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-29 18:32:44 -05:00
|
|
|
void BKE_editmesh_looptri_calc_with_partial(BMEditMesh *em, BMPartialUpdate *bmpinfo)
|
2021-06-14 22:56:03 +10:00
|
|
|
{
|
2022-09-29 18:32:44 -05:00
|
|
|
BMeshCalcTessellation_Params looptri_params{};
|
|
|
|
|
looptri_params.face_normals = false;
|
|
|
|
|
BKE_editmesh_looptri_calc_with_partial_ex(em, bmpinfo, &looptri_params);
|
2021-06-14 22:56:03 +10:00
|
|
|
}
|
|
|
|
|
|
2022-09-29 18:32:44 -05:00
|
|
|
void BKE_editmesh_looptri_and_normals_calc_with_partial(BMEditMesh *em, BMPartialUpdate *bmpinfo)
|
2021-06-14 22:56:03 +10:00
|
|
|
{
|
2022-09-29 18:32:44 -05:00
|
|
|
BMeshCalcTessellation_Params looptri_params{};
|
|
|
|
|
looptri_params.face_normals = true;
|
|
|
|
|
BKE_editmesh_looptri_calc_with_partial_ex(em, bmpinfo, &looptri_params);
|
|
|
|
|
BMeshNormalsUpdate_Params normals_params{};
|
|
|
|
|
normals_params.face_normals = false;
|
|
|
|
|
BM_mesh_normals_update_with_partial_ex(em->bm, bmpinfo, &normals_params);
|
2021-05-28 18:18:13 +10:00
|
|
|
}
|
|
|
|
|
|
2021-07-13 15:05:39 +10:00
|
|
|
void BKE_editmesh_free_data(BMEditMesh *em)
|
2014-02-28 20:02:30 +11:00
|
|
|
{
|
2013-04-16 05:46:17 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (em->looptris) {
|
2013-04-16 05:46:17 +00:00
|
|
|
MEM_freeN(em->looptris);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-04-16 05:46:17 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (em->bm) {
|
2013-04-16 05:46:17 +00:00
|
|
|
BM_mesh_free(em->bm);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-04-16 05:46:17 +00:00
|
|
|
}
|
2013-04-18 17:09:56 +00:00
|
|
|
|
2019-12-24 22:32:43 +11:00
|
|
|
struct CageUserData {
|
|
|
|
|
int totvert;
|
|
|
|
|
float (*cos_cage)[3];
|
|
|
|
|
BLI_bitmap *visit_bitmap;
|
|
|
|
|
};
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void cage_mapped_verts_callback(void *user_data,
|
2019-12-24 22:32:43 +11:00
|
|
|
int index,
|
|
|
|
|
const float co[3],
|
2022-10-12 10:27:27 +11:00
|
|
|
const float /*no*/[3])
|
2013-04-18 17:09:56 +00:00
|
|
|
{
|
2023-07-27 12:04:18 +10:00
|
|
|
CageUserData *data = static_cast<CageUserData *>(user_data);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-10-07 22:52:53 +11:00
|
|
|
if ((index >= 0 && index < data->totvert) && !BLI_BITMAP_TEST(data->visit_bitmap, index)) {
|
2019-12-24 22:32:43 +11:00
|
|
|
BLI_BITMAP_ENABLE(data->visit_bitmap, index);
|
|
|
|
|
copy_v3_v3(data->cos_cage[index], co);
|
|
|
|
|
}
|
2013-04-18 17:09:56 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-29 18:32:44 -05:00
|
|
|
float (*BKE_editmesh_vert_coords_alloc(
|
|
|
|
|
Depsgraph *depsgraph, BMEditMesh *em, Scene *scene, Object *ob, int *r_vert_len))[3]
|
2013-04-18 17:09:56 +00:00
|
|
|
{
|
2022-04-13 18:02:21 -05:00
|
|
|
Mesh *cage = editbmesh_get_eval_cage(depsgraph, scene, ob, em, &CD_MASK_BAREMESH);
|
2022-09-29 18:32:44 -05:00
|
|
|
float(*cos_cage)[3] = static_cast<float(*)[3]>(
|
|
|
|
|
MEM_callocN(sizeof(*cos_cage) * em->bm->totvert, __func__));
|
2019-12-24 22:32:43 +11:00
|
|
|
|
2022-04-13 18:02:21 -05:00
|
|
|
/* When initializing cage verts, we only want the first cage coordinate for each vertex,
|
|
|
|
|
* so that e.g. mirror or array use original vertex coordinates and not mirrored or duplicate. */
|
|
|
|
|
BLI_bitmap *visit_bitmap = BLI_BITMAP_NEW(em->bm->totvert, __func__);
|
2019-12-24 22:32:43 +11:00
|
|
|
|
2022-09-29 18:32:44 -05:00
|
|
|
CageUserData data;
|
2019-12-24 22:32:43 +11:00
|
|
|
data.totvert = em->bm->totvert;
|
|
|
|
|
data.cos_cage = cos_cage;
|
|
|
|
|
data.visit_bitmap = visit_bitmap;
|
|
|
|
|
|
|
|
|
|
BKE_mesh_foreach_mapped_vert(cage, cage_mapped_verts_callback, &data, MESH_FOREACH_NOP);
|
|
|
|
|
|
|
|
|
|
MEM_freeN(visit_bitmap);
|
|
|
|
|
|
|
|
|
|
if (r_vert_len) {
|
|
|
|
|
*r_vert_len = em->bm->totvert;
|
2013-04-18 17:09:56 +00:00
|
|
|
}
|
2019-12-24 22:32:43 +11:00
|
|
|
|
|
|
|
|
return cos_cage;
|
2013-04-18 17:09:56 +00:00
|
|
|
}
|
2015-03-29 04:44:05 +11:00
|
|
|
|
2022-09-29 18:32:44 -05:00
|
|
|
const float (*BKE_editmesh_vert_coords_when_deformed(Depsgraph *depsgraph,
|
2020-10-14 14:49:22 +11:00
|
|
|
BMEditMesh *em,
|
2022-09-29 18:32:44 -05:00
|
|
|
Scene *scene,
|
2020-10-14 14:49:22 +11:00
|
|
|
Object *ob,
|
|
|
|
|
int *r_vert_len,
|
|
|
|
|
bool *r_is_alloc))[3]
|
|
|
|
|
{
|
2022-09-29 18:32:44 -05:00
|
|
|
const float(*coords)[3] = nullptr;
|
2020-10-14 14:49:22 +11:00
|
|
|
*r_is_alloc = false;
|
|
|
|
|
|
2022-01-11 15:42:07 +01:00
|
|
|
Object *object_eval = DEG_get_evaluated_object(depsgraph, ob);
|
|
|
|
|
Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(object_eval);
|
2020-10-14 14:49:22 +11:00
|
|
|
|
2023-08-01 21:36:26 -04:00
|
|
|
if (Mesh *mesh_cage = BKE_object_get_editmesh_eval_cage(ob)) {
|
2020-10-14 14:49:22 +11:00
|
|
|
/* Deformed, and we have deformed coords already. */
|
2023-08-01 21:36:26 -04:00
|
|
|
coords = BKE_mesh_wrapper_vert_coords(mesh_cage);
|
2020-10-14 14:49:22 +11:00
|
|
|
}
|
2022-09-29 18:32:44 -05:00
|
|
|
else if ((editmesh_eval_final != nullptr) &&
|
2022-10-12 20:55:26 -05:00
|
|
|
(editmesh_eval_final->runtime->wrapper_type == ME_WRAPPER_TYPE_BMESH))
|
|
|
|
|
{
|
2022-09-29 18:32:44 -05:00
|
|
|
/* If this is an edit-mesh type, leave nullptr as we can use the vertex coords. */
|
2020-10-14 14:49:22 +11:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Constructive modifiers have been used, we need to allocate coordinates. */
|
|
|
|
|
*r_is_alloc = true;
|
|
|
|
|
coords = BKE_editmesh_vert_coords_alloc(depsgraph, em, scene, ob, r_vert_len);
|
|
|
|
|
}
|
|
|
|
|
return coords;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-22 06:28:35 +10:00
|
|
|
float (*BKE_editmesh_vert_coords_alloc_orco(BMEditMesh *em, int *r_vert_len))[3]
|
2015-03-29 04:44:05 +11:00
|
|
|
{
|
2019-11-21 21:03:03 +11:00
|
|
|
return BM_mesh_vert_coords_alloc(em->bm, r_vert_len);
|
2015-03-29 04:44:05 +11:00
|
|
|
}
|
2018-05-25 22:24:24 +05:30
|
|
|
|
Mesh: Replace auto smooth with node group
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
2023-10-20 16:54:08 +02:00
|
|
|
void BKE_editmesh_lnorspace_update(BMEditMesh *em)
|
2018-05-25 22:24:24 +05:30
|
|
|
{
|
Mesh: Replace auto smooth with node group
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
2023-10-20 16:54:08 +02:00
|
|
|
BM_lnorspace_update(em->bm);
|
2019-05-20 12:15:52 -04:00
|
|
|
}
|
2019-09-23 14:36:45 +02:00
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
BoundBox *BKE_editmesh_cage_boundbox_get(Object *object, BMEditMesh * /*em*/)
|
2019-09-23 14:36:45 +02:00
|
|
|
{
|
2022-09-29 18:32:44 -05:00
|
|
|
if (object->runtime.editmesh_bb_cage == nullptr) {
|
2019-09-23 14:36:45 +02:00
|
|
|
float min[3], max[3];
|
|
|
|
|
INIT_MINMAX(min, max);
|
2022-01-11 15:42:07 +01:00
|
|
|
if (object->runtime.editmesh_eval_cage) {
|
|
|
|
|
BKE_mesh_wrapper_minmax(object->runtime.editmesh_eval_cage, min, max);
|
2019-09-23 14:36:45 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-29 18:32:44 -05:00
|
|
|
object->runtime.editmesh_bb_cage = MEM_cnew<BoundBox>("BMEditMesh.bb_cage");
|
2022-01-11 15:42:07 +01:00
|
|
|
BKE_boundbox_init_from_minmax(object->runtime.editmesh_bb_cage, min, max);
|
2019-09-23 14:36:45 +02:00
|
|
|
}
|
|
|
|
|
|
2022-01-11 15:42:07 +01:00
|
|
|
return object->runtime.editmesh_bb_cage;
|
2019-09-23 14:36:45 +02:00
|
|
|
}
|