Refactor: Tweak mesh render data normals update
Move the responsibility of deciding whether to calculate face corner normals closer to the buffers and iteration, in preparation for replacing the `data_flag` and `iter_flag` abstractions from the extractors system.
This commit is contained in:
@@ -528,7 +528,18 @@ static void mesh_extract_render_data_node_exec(void *__restrict task_data)
|
||||
const eMRIterType iter_type = update_task_data->iter_type;
|
||||
const eMRDataType data_flag = update_task_data->data_flag;
|
||||
|
||||
mesh_render_data_update_normals(mr, data_flag);
|
||||
const bool request_face_normals = (data_flag & (MR_DATA_POLY_NOR | MR_DATA_LOOP_NOR |
|
||||
MR_DATA_TAN_LOOP_NOR)) != 0;
|
||||
const bool request_corner_normals = (data_flag & MR_DATA_LOOP_NOR) != 0;
|
||||
const bool force_corner_normals = (data_flag & MR_DATA_TAN_LOOP_NOR) != 0;
|
||||
|
||||
if (request_face_normals) {
|
||||
mesh_render_data_update_face_normals(mr);
|
||||
}
|
||||
if ((request_corner_normals && !mr.use_simplify_normals) || force_corner_normals) {
|
||||
mesh_render_data_update_corner_normals(mr);
|
||||
}
|
||||
|
||||
mesh_render_data_update_loose_geom(mr, *update_task_data->cache, iter_type, data_flag);
|
||||
}
|
||||
|
||||
@@ -888,7 +899,7 @@ void mesh_buffer_cache_create_requested_subdiv(MeshBatchCache &cache,
|
||||
return;
|
||||
}
|
||||
|
||||
mesh_render_data_update_normals(mr, MR_DATA_TAN_LOOP_NOR);
|
||||
mesh_render_data_update_corner_normals(mr);
|
||||
mesh_render_data_update_loose_geom(
|
||||
mr, mbc, MR_ITER_LOOSE_EDGE | MR_ITER_LOOSE_VERT, MR_DATA_LOOSE_GEOM);
|
||||
DRW_subdivide_loose_geom(subdiv_cache, mbc);
|
||||
|
||||
@@ -493,43 +493,35 @@ static bke::MeshNormalDomain bmesh_normals_domain(BMesh *bm)
|
||||
return bke::MeshNormalDomain::Corner;
|
||||
}
|
||||
|
||||
void mesh_render_data_update_normals(MeshRenderData &mr, const eMRDataType data_flag)
|
||||
void mesh_render_data_update_corner_normals(MeshRenderData &mr)
|
||||
{
|
||||
if (mr.extract_type != MR_EXTRACT_BMESH) {
|
||||
/* Mesh */
|
||||
if (data_flag & (MR_DATA_POLY_NOR | MR_DATA_LOOP_NOR | MR_DATA_TAN_LOOP_NOR)) {
|
||||
mr.face_normals = mr.mesh->face_normals();
|
||||
}
|
||||
if (((data_flag & MR_DATA_LOOP_NOR) && !mr.use_simplify_normals &&
|
||||
mr.normals_domain == bke::MeshNormalDomain::Corner) ||
|
||||
(data_flag & MR_DATA_TAN_LOOP_NOR))
|
||||
{
|
||||
mr.corner_normals = mr.mesh->corner_normals();
|
||||
}
|
||||
mr.corner_normals = mr.mesh->corner_normals();
|
||||
}
|
||||
else {
|
||||
/* #BMesh */
|
||||
if (data_flag & MR_DATA_POLY_NOR) {
|
||||
/* Use #BMFace.no instead. */
|
||||
}
|
||||
if (((data_flag & MR_DATA_LOOP_NOR) && !mr.use_simplify_normals &&
|
||||
mr.normals_domain == bke::MeshNormalDomain::Corner) ||
|
||||
(data_flag & MR_DATA_TAN_LOOP_NOR))
|
||||
{
|
||||
mr.bm_loop_normals.reinitialize(mr.corners_num);
|
||||
const int clnors_offset = CustomData_get_offset(&mr.bm->ldata, CD_CUSTOMLOOPNORMAL);
|
||||
BM_loops_calc_normal_vcos(mr.bm,
|
||||
mr.bm_vert_coords,
|
||||
mr.bm_vert_normals,
|
||||
mr.bm_face_normals,
|
||||
true,
|
||||
mr.bm_loop_normals,
|
||||
nullptr,
|
||||
nullptr,
|
||||
clnors_offset,
|
||||
false);
|
||||
mr.corner_normals = mr.bm_loop_normals;
|
||||
}
|
||||
mr.bm_loop_normals.reinitialize(mr.corners_num);
|
||||
const int clnors_offset = CustomData_get_offset(&mr.bm->ldata, CD_CUSTOMLOOPNORMAL);
|
||||
BM_loops_calc_normal_vcos(mr.bm,
|
||||
mr.bm_vert_coords,
|
||||
mr.bm_vert_normals,
|
||||
mr.bm_face_normals,
|
||||
true,
|
||||
mr.bm_loop_normals,
|
||||
nullptr,
|
||||
nullptr,
|
||||
clnors_offset,
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
void mesh_render_data_update_face_normals(MeshRenderData &mr)
|
||||
{
|
||||
if (mr.extract_type != MR_EXTRACT_BMESH) {
|
||||
/* Eager calculation of face normals can reduce waiting on the lazy cache's lock. */
|
||||
mr.face_normals = mr.mesh->face_normals();
|
||||
}
|
||||
else {
|
||||
/* Use #BMFace.no instead. */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -289,7 +289,8 @@ MeshRenderData *mesh_render_data_create(Object &object,
|
||||
bool use_hide,
|
||||
const ToolSettings *ts);
|
||||
void mesh_render_data_free(MeshRenderData *mr);
|
||||
void mesh_render_data_update_normals(MeshRenderData &mr, eMRDataType data_flag);
|
||||
void mesh_render_data_update_corner_normals(MeshRenderData &mr);
|
||||
void mesh_render_data_update_face_normals(MeshRenderData &mr);
|
||||
void mesh_render_data_update_loose_geom(MeshRenderData &mr,
|
||||
MeshBufferCache &cache,
|
||||
eMRIterType iter_type,
|
||||
|
||||
@@ -116,8 +116,8 @@ static void extract_tan_init_common(const MeshRenderData &mr,
|
||||
calc_active_tangent,
|
||||
r_tangent_names,
|
||||
tan_len,
|
||||
mr.face_normals,
|
||||
mr.corner_normals,
|
||||
mr.bm_face_normals,
|
||||
mr.bm_loop_normals,
|
||||
orco,
|
||||
r_loop_data,
|
||||
mr.corners_num,
|
||||
|
||||
Reference in New Issue
Block a user