2023-05-31 16:19:06 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2018-06-05 15:59:53 +02:00
|
|
|
#pragma once
|
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2018-06-05 15:59:53 +02:00
|
|
|
*
|
|
|
|
* This file contains access functions for the Mesh.runtime struct.
|
|
|
|
*/
|
|
|
|
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
struct CustomData_MeshMasks;
|
2018-06-05 16:58:08 +02:00
|
|
|
struct Depsgraph;
|
2018-06-21 18:24:32 +02:00
|
|
|
struct KeyBlock;
|
2019-01-28 11:08:24 +01:00
|
|
|
struct Mesh;
|
2018-06-05 16:58:08 +02:00
|
|
|
struct Object;
|
|
|
|
struct Scene;
|
|
|
|
|
2023-12-19 14:57:49 +01:00
|
|
|
/** Return the number of derived triangles (corner_tris). */
|
|
|
|
int BKE_mesh_runtime_corner_tris_len(const Mesh *mesh);
|
2022-11-16 02:15:35 +01:00
|
|
|
|
2023-12-04 21:22:00 +01:00
|
|
|
void BKE_mesh_runtime_ensure_edit_data(Mesh *mesh);
|
2022-11-16 02:15:35 +01:00
|
|
|
|
2021-12-07 07:19:15 +01:00
|
|
|
/**
|
2022-11-16 03:28:39 +01:00
|
|
|
* Clear and free any derived caches associated with the mesh geometry data. Examples include BVH
|
2022-11-16 02:15:35 +01:00
|
|
|
* caches, normals, triangulation, etc. This should be called when replacing a mesh's geometry
|
|
|
|
* directly or making other large changes to topology. It does not need to be called on new meshes.
|
2021-12-07 07:19:15 +01:00
|
|
|
*
|
2022-11-16 02:15:35 +01:00
|
|
|
* For "smaller" changes to meshes like updating positions, consider calling a more specific update
|
2023-12-12 21:38:42 +01:00
|
|
|
* function like #Mesh::tag_positions_changed().
|
2022-11-16 02:15:35 +01:00
|
|
|
*
|
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
|
|
|
* Also note that some derived caches like #CD_TANGENT are stored directly in #CustomData.
|
2022-11-16 02:15:35 +01:00
|
|
|
*/
|
2023-08-03 01:11:28 +02:00
|
|
|
void BKE_mesh_runtime_clear_geometry(Mesh *mesh);
|
2022-11-16 02:15:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Similar to #BKE_mesh_runtime_clear_geometry, but subtly different in that it also clears
|
|
|
|
* data-block level features like evaluated data-blocks and edit mode data. They will be
|
|
|
|
* functionally the same in most cases, but prefer this function if unsure, since it clears
|
|
|
|
* more data.
|
2021-12-07 07:19:15 +01:00
|
|
|
*/
|
2023-08-03 01:11:28 +02:00
|
|
|
void BKE_mesh_runtime_clear_cache(Mesh *mesh);
|
2018-06-05 15:59:53 +02:00
|
|
|
|
2020-12-14 13:00:28 +01:00
|
|
|
/* NOTE: the functions below are defined in DerivedMesh.cc, and are intended to be moved
|
2018-08-21 12:52:41 +02:00
|
|
|
* to a more suitable location when that file is removed.
|
2020-12-14 13:00:28 +01:00
|
|
|
* They should also be renamed to use conventions from BKE, not old DerivedMesh.cc.
|
2018-08-21 12:52:41 +02:00
|
|
|
* For now keep the names similar to avoid confusion. */
|
2021-12-07 07:19:15 +01:00
|
|
|
|
2023-08-03 01:11:28 +02:00
|
|
|
Mesh *mesh_get_eval_deform(Depsgraph *depsgraph,
|
|
|
|
const Scene *scene,
|
|
|
|
Object *ob,
|
|
|
|
const CustomData_MeshMasks *dataMask);
|
|
|
|
|
|
|
|
Mesh *mesh_create_eval_final(Depsgraph *depsgraph,
|
|
|
|
const Scene *scene,
|
|
|
|
Object *ob,
|
|
|
|
const CustomData_MeshMasks *dataMask);
|
|
|
|
|
|
|
|
Mesh *mesh_create_eval_no_deform(Depsgraph *depsgraph,
|
|
|
|
const Scene *scene,
|
|
|
|
Object *ob,
|
|
|
|
const CustomData_MeshMasks *dataMask);
|
|
|
|
Mesh *mesh_create_eval_no_deform_render(Depsgraph *depsgraph,
|
|
|
|
const Scene *scene,
|
|
|
|
Object *ob,
|
|
|
|
const CustomData_MeshMasks *dataMask);
|
|
|
|
|
2023-12-08 22:40:06 +01:00
|
|
|
void BKE_mesh_runtime_eval_to_meshkey(Mesh *me_deformed, Mesh *mesh, KeyBlock *kb);
|
2018-06-25 13:03:56 +02:00
|
|
|
|
2018-06-22 17:54:18 +02:00
|
|
|
#ifndef NDEBUG
|
2024-03-11 16:21:12 +01:00
|
|
|
bool BKE_mesh_runtime_is_valid(Mesh *mesh_eval);
|
2023-12-07 00:35:23 +01:00
|
|
|
#endif /* !NDEBUG */
|