[Bf-blender-cvs] [26cc225ed84] refactor-mesh-corner-normals-lazy: Merge branch 'master' into refactor-mesh-corner-normals-lazy
Hans Goudey
noreply at git.blender.org
Wed Dec 14 16:42:21 CET 2022
Commit: 26cc225ed844c98cfc738e9bf3c763b4af093f53
Author: Hans Goudey
Date: Tue Dec 13 18:48:03 2022 -0600
Branches: refactor-mesh-corner-normals-lazy
https://developer.blender.org/rB26cc225ed844c98cfc738e9bf3c763b4af093f53
Merge branch 'master' into refactor-mesh-corner-normals-lazy
===================================================================
===================================================================
diff --cc source/blender/blenkernel/intern/data_transfer.cc
index c0a82aac25a,382736ae502..cc914599005
--- a/source/blender/blenkernel/intern/data_transfer.cc
+++ b/source/blender/blenkernel/intern/data_transfer.cc
@@@ -1,5 -1,5 +1,3 @@@
--/* SPDX-License-Identifier: GPL-2.0-or-later
-- * Copyright 2014 Blender Foundation. All rights reserved. */
/** \file
* \ingroup bke
@@@ -330,11 -331,14 +328,12 @@@ static void data_transfer_dtdata_type_p
CustomData *ldata_dst = &me_dst->ldata;
const float(*poly_nors_dst)[3] = BKE_mesh_poly_normals_ensure(me_dst);
- float(*loop_nors_dst)[3] = static_cast<float(*)[3]>(
- CustomData_get_layer(ldata_dst, CD_NORMAL));
- short(*custom_nors_dst)[2] = static_cast<short(*)[2]>(
- CustomData_get_layer(ldata_dst, CD_CUSTOMLOOPNORMAL));
++ float(*loop_nors_dst)[3] = CustomData_get_layer(ldata_dst, CD_NORMAL);
+ short(*custom_nors_dst)[2] = CustomData_get_layer(ldata_dst, CD_CUSTOMLOOPNORMAL);
if (!custom_nors_dst) {
- custom_nors_dst = static_cast<short(*)[2]>(CustomData_add_layer(
- ldata_dst, CD_CUSTOMLOOPNORMAL, CD_SET_DEFAULT, nullptr, num_loops_dst));
+ custom_nors_dst = CustomData_add_layer(
+ ldata_dst, CD_CUSTOMLOOPNORMAL, CD_SET_DEFAULT, NULL, num_loops_dst);
}
/* Note loop_nors_dst contains our custom normals as transferred from source... */
diff --cc source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
index 32409d644ed,181180267db..3b2d70f9d4f
--- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
+++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
@@@ -173,17 -181,20 +181,14 @@@ int OBJMesh::ith_smooth_group(const in
return poly_smooth_groups_[poly_index];
}
-void OBJMesh::ensure_mesh_normals() const
-{
- /* Const cast can be removed when calculating face corner normals lazily is possible. */
- BKE_mesh_calc_normals_split(const_cast<Mesh *>(export_mesh_));
-}
-
void OBJMesh::calc_smooth_groups(const bool use_bitflags)
{
- const Span<MEdge> edges = export_mesh_eval_->edges();
- const Span<MPoly> polys = export_mesh_eval_->polys();
- const Span<MLoop> loops = export_mesh_eval_->loops();
- poly_smooth_groups_ = BKE_mesh_calc_smoothgroups(edges.data(),
- edges.size(),
- polys.data(),
- polys.size(),
- loops.data(),
- loops.size(),
+ poly_smooth_groups_ = BKE_mesh_calc_smoothgroups(mesh_edges_.data(),
+ mesh_edges_.size(),
+ mesh_polys_.data(),
+ mesh_polys_.size(),
+ mesh_loops_.data(),
+ mesh_loops_.size(),
&tot_smooth_groups_,
use_bitflags);
}
@@@ -381,13 -382,13 +376,13 @@@ void OBJMesh::store_normal_coords_and_i
int cur_normal_index = 0;
Map<float3, int> normal_to_index;
/* We don't know how many unique normals there will be, but this is a guess. */
- normal_to_index.reserve(export_mesh_eval_->totpoly);
- loop_to_normal_index_.resize(export_mesh_eval_->totloop);
+ normal_to_index.reserve(export_mesh_->totpoly);
+ loop_to_normal_index_.resize(export_mesh_->totloop);
loop_to_normal_index_.fill(-1);
- /* TODO: Only get loop normals when they're necessary. */
- const float(*lnors)[3] = BKE_mesh_corner_normals_ensure(export_mesh_eval_);
+ const float(*lnors)[3] = static_cast<const float(*)[3]>(
- CustomData_get_layer(&export_mesh_->ldata, CD_NORMAL));
- for (int poly_index = 0; poly_index < export_mesh_->totpoly; ++poly_index) {
- const MPoly &mpoly = mesh_polys_[poly_index];
++ CustomData_get_layer(&export_mesh_eval_->ldata, CD_NORMAL));
+ for (int poly_index = 0; poly_index < export_mesh_eval_->totpoly; ++poly_index) {
+ const MPoly &mpoly = polys[poly_index];
bool need_per_loop_normals = lnors != nullptr || (mpoly.flag & ME_SMOOTH);
if (need_per_loop_normals) {
for (int loop_of_poly = 0; loop_of_poly < mpoly.totloop; ++loop_of_poly) {
diff --cc source/blender/modifiers/intern/MOD_displace.cc
index a8d10d6ccb4,527bbeae0e5..fc12a9c2aad
--- a/source/blender/modifiers/intern/MOD_displace.cc
+++ b/source/blender/modifiers/intern/MOD_displace.cc
@@@ -307,8 -308,13 +307,12 @@@ static void displaceModifier_do(Displac
CustomData *ldata = &mesh->ldata;
if (CustomData_has_layer(ldata, CD_CUSTOMLOOPNORMAL)) {
- const float(*clnors)[3] = BKE_mesh_corner_normals_ensure(mesh);
+ if (!CustomData_has_layer(ldata, CD_NORMAL)) {
+ BKE_mesh_calc_normals_split(mesh);
+ }
+
- float(*clnors)[3] = static_cast<float(*)[3]>(CustomData_get_layer(ldata, CD_NORMAL));
- vert_clnors = static_cast<float(*)[3]>(
- MEM_malloc_arrayN(verts_num, sizeof(*vert_clnors), __func__));
++ float(*clnors)[3] = CustomData_get_layer(ldata, CD_NORMAL);
+ vert_clnors = MEM_malloc_arrayN(verts_num, sizeof(*vert_clnors), __func__);
BKE_mesh_normals_loop_to_vertex(
verts_num, BKE_mesh_loops(mesh), mesh->totloop, (const float(*)[3])clnors, vert_clnors);
}
diff --cc source/blender/modifiers/intern/MOD_triangulate.cc
index 9ac9a7d86da,c8543473a9a..5bae6090758
--- a/source/blender/modifiers/intern/MOD_triangulate.cc
+++ b/source/blender/modifiers/intern/MOD_triangulate.cc
@@@ -73,8 -74,14 +71,14 @@@ static Mesh *triangulate_mesh(Mesh *mes
BM_mesh_free(bm);
if (keep_clnors) {
- BKE_mesh_set_custom_normals(result, CustomData_get_layer(&result->ldata, CD_NORMAL));
- CustomData_free_layers(&result->ldata, CD_NORMAL, result->totloop);
- float(*lnors)[3] = static_cast<float(*)[3]>(CustomData_get_layer(&result->ldata, CD_NORMAL));
- BLI_assert(lnors != nullptr);
++ float(*lnors)[3] = CustomData_get_layer(&result->ldata, CD_NORMAL);
++ BLI_assert(lnors != NULL);
+
+ BKE_mesh_set_custom_normals(result, lnors);
+
+ /* Do some cleanup, we do not want those temp data to stay around. */
+ CustomData_set_layer_flag(&mesh->ldata, CD_NORMAL, CD_FLAG_TEMPORARY);
+ CustomData_set_layer_flag(&result->ldata, CD_NORMAL, CD_FLAG_TEMPORARY);
}
edges_num = result->totedge;
diff --cc source/blender/render/intern/bake.cc
index 082a5f18e41,5a66b5b4dca..dfc4e20ab6a
--- a/source/blender/render/intern/bake.cc
+++ b/source/blender/render/intern/bake.cc
@@@ -479,15 -480,18 +480,15 @@@ static TriTessFace *mesh_calc_tri_tessf
BKE_mesh_recalc_looptri(loops, polys, verts, me->totloop, me->totpoly, looptri);
}
- const TSpace *tspace = NULL;
- const float(*loop_normals)[3] = NULL;
+ const TSpace *tspace = nullptr;
+ const float(*loop_normals)[3] = nullptr;
if (tangent) {
- BKE_mesh_ensure_normals_for_display(me_eval);
- BKE_mesh_calc_normals_split(me_eval);
- BKE_mesh_calc_loop_tangents(me_eval, true, nullptr, 0);
+ BKE_mesh_calc_loop_tangents(me_eval, true, NULL, 0);
- tspace = CustomData_get_layer(&me_eval->ldata, CD_TANGENT);
+ tspace = static_cast<const TSpace *>(CustomData_get_layer(&me_eval->ldata, CD_TANGENT));
BLI_assert(tspace);
- loop_normals = static_cast<const float(*)[3]>(
- CustomData_get_layer(&me_eval->ldata, CD_NORMAL));
+ loop_normals = BKE_mesh_corner_normals_ensure(me_eval);
}
const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(me);
diff --cc source/blender/render/intern/multires_bake.cc
index 1ed4d86c5e9,7f3c9c5db50..df0d5756cf0
--- a/source/blender/render/intern/multires_bake.cc
+++ b/source/blender/render/intern/multires_bake.cc
@@@ -1,5 -1,5 +1,3 @@@
--/* SPDX-License-Identifier: GPL-2.0-or-later
-- * Copyright 2012 Blender Foundation. All rights reserved. */
/** \file
* \ingroup render
@@@ -516,8 -515,8 +513,8 @@@ static void do_multires_bake(MultiresBa
0,
vert_normals,
poly_normals,
- corner_normals,
+ (const float(*)[3])dm->getLoopDataArray(dm, CD_NORMAL),
- (const float(*)[3])dm->getVertDataArray(dm, CD_ORCO), /* May be nullptr. */
+ (const float(*)[3])dm->getVertDataArray(dm, CD_ORCO), /* may be nullptr */
/* result */
&dm->loopData,
dm->getNumLoops(dm),
More information about the Bf-blender-cvs
mailing list