[Bf-blender-cvs] [413f652] temp_custom_loop_normals: Fix stupid code to get CD custom lnors data in BMesh!
Bastien Montagne
noreply at git.blender.org
Wed Aug 6 21:36:40 CEST 2014
Commit: 413f652000ee47cc726d39b8cde0d43e75e622bc
Author: Bastien Montagne
Date: Thu Jul 24 21:20:35 2014 +0200
Branches: temp_custom_loop_normals
https://developer.blender.org/rB413f652000ee47cc726d39b8cde0d43e75e622bc
Fix stupid code to get CD custom lnors data in BMesh!
===================================================================
M source/blender/blenkernel/intern/editderivedmesh.c
M source/blender/bmesh/intern/bmesh_mesh.c
M source/blender/bmesh/intern/bmesh_mesh.h
===================================================================
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c
index 5966279..40dd1ec 100644
--- a/source/blender/blenkernel/intern/editderivedmesh.c
+++ b/source/blender/blenkernel/intern/editderivedmesh.c
@@ -177,6 +177,8 @@ static void emDM_calcLoopNormals(DerivedMesh *dm, const float split_angle)
emDM_calcLoopNormalsSpaces(dm, split_angle, NULL);
}
+//#define DEBUG_CLNORS
+
static void emDM_calcLoopNormalsSpaces(DerivedMesh *dm, const float split_angle, MLoopsNorSpaces *r_lnors_spaces)
{
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
@@ -200,11 +202,13 @@ static void emDM_calcLoopNormalsSpaces(DerivedMesh *dm, const float split_angle,
}
{
- /* XXX All this is really dirty!!! */
- const int numLoops = dm->getNumLoops(dm);
- float (*clnor_data)[2] = NULL;
CustomData *ldata = dm->getLoopDataLayout(dm);
+ const int cd_loop_clnors_offset = CustomData_get_offset(ldata, CD_CUSTOMLOOPNORMAL);
+ const int numLoops = dm->getNumLoops(dm);
+#ifdef DEBUG_CLNORS
+ float (*clnor_data)[2] = NULL;
+ /* XXX All this is really dirty!!! */
if (CustomData_has_layer(ldata, CD_CUSTOMLOOPNORMAL)) {
float (*clnor)[2] = clnor_data = MEM_mallocN(sizeof(float[2]) * (size_t)numLoops, __func__);
BMIter iter;
@@ -214,17 +218,16 @@ static void emDM_calcLoopNormalsSpaces(DerivedMesh *dm, const float split_angle,
BMLoop *l_iter, *l_first;
l_iter = l_first = BM_FACE_FIRST_LOOP(efa);
do {
- //const float dummy[2] = {0.5f, 0.5f};
copy_v2_v2(*clnor, CustomData_bmesh_get(ldata, l_iter->head.data, CD_CUSTOMLOOPNORMAL));
- //copy_v2_v2(*clnor, dummy);
++clnor;
} while ((l_iter = l_iter->next) != l_first);
}
}
+#endif
BM_loops_calc_normal_vcos(bm, vertexCos, vertexNos, polyNos, split_angle, loopNos,
- r_lnors_spaces, (const float (*)[2])clnor_data);
-#if 0
+ r_lnors_spaces, cd_loop_clnors_offset);
+#ifdef DEBUG_CLNORS
if (r_lnors_spaces) {
int i;
for (i = 0; i < numLoops; i++) {
@@ -249,9 +252,9 @@ static void emDM_calcLoopNormalsSpaces(DerivedMesh *dm, const float split_angle,
}
}
}
-#endif
MEM_SAFE_FREE(clnor_data);
+#endif
}
}
diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c
index 8321e04..81652dd 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.c
+++ b/source/blender/bmesh/intern/bmesh_mesh.c
@@ -520,12 +520,14 @@ static void bm_mesh_edges_sharp_tag(BMesh *bm, const float (*vnos)[3], const flo
bm->elem_index_dirty &= ~(BM_EDGE | BM_VERT);
}
-/* BMesh version of BKE_mesh_normals_loop_split() in mesh_evaluate.c */
+/* BMesh version of BKE_mesh_normals_loop_split() in mesh_evaluate.c
+ * Use -1 as 'no custom lnors' tag for cd_loop_clnors_offset. */
static void bm_mesh_loops_calc_normals(BMesh *bm, const float (*vcos)[3], const float (*fnos)[3], float (*r_lnos)[3],
- MLoopsNorSpaces *r_lnors_spaces, const float (*clnors_data)[2])
+ MLoopsNorSpaces *r_lnors_spaces, const int cd_loop_clnors_offset)
{
BMIter fiter;
BMFace *f_curr;
+ const bool has_clnors = cd_loop_clnors_offset != -1;
MLoopsNorSpaces _lnors_spaces = {NULL};
@@ -545,7 +547,7 @@ static void bm_mesh_loops_calc_normals(BMesh *bm, const float (*vcos)[3], const
BM_mesh_elem_index_ensure(bm, htype);
}
- if (!r_lnors_spaces && clnors_data) {
+ if (!r_lnors_spaces && has_clnors) {
/* We need to compute lnor spaces if some custom lnor data are given to us! */
r_lnors_spaces = &_lnors_spaces;
}
@@ -604,8 +606,10 @@ static void bm_mesh_loops_calc_normals(BMesh *bm, const float (*vcos)[3], const
/* We know there is only one loop in this space, no need to create a linklist in this case... */
BKE_lnor_space_add_loop(r_lnors_spaces, lnor_space, l_curr_index, false);
- if (clnors_data) {
- BKE_lnor_space_custom_data_to_normal(lnor_space, r_lnos[l_curr_index], clnors_data[l_curr_index]);
+ if (has_clnors) {
+ const float (*clnor)[2] = CustomData_bmesh_get_layer_n(&bm->ldata, l_curr->head.data,
+ cd_loop_clnors_offset);
+ BKE_lnor_space_custom_data_to_normal(lnor_space, r_lnos[l_curr_index], *clnor);
}
}
}
@@ -728,9 +732,11 @@ static void bm_mesh_loops_calc_normals(BMesh *bm, const float (*vcos)[3], const
BKE_lnor_space_define(lnor_space, lnor, vec_org, vec_next, edge_vectors);
- if (clnors_data) {
+ if (has_clnors) {
/* We know all custom data of those loops are the same (else, it's a bug!). */
- BKE_lnor_space_custom_data_to_normal(lnor_space, lnor, clnors_data[lfan_pivot_index]);
+ const float (*clnor)[2] = CustomData_bmesh_get_layer_n(&bm->ldata, lfan_pivot->head.data,
+ cd_loop_clnors_offset);
+ BKE_lnor_space_custom_data_to_normal(lnor_space, lnor, *clnor);
}
}
@@ -773,13 +779,13 @@ static void bm_mesh_loops_calc_normals(BMesh *bm, const float (*vcos)[3], const
* first)!
*/
void BM_mesh_loop_normals_update(BMesh *bm, const float split_angle, float (*r_lnos)[3],
- MLoopsNorSpaces *r_lnors_spaces, const float (*clnors_data)[2])
+ MLoopsNorSpaces *r_lnors_spaces, const int cd_loop_clnors_offset)
{
/* Tag smooth edges and set lnos from vnos when they might be completely smooth... */
bm_mesh_edges_sharp_tag(bm, NULL, NULL, split_angle, r_lnos);
/* Finish computing lnos by accumulating face normals in each fan of faces defined by sharp edges. */
- bm_mesh_loops_calc_normals(bm, NULL, NULL, r_lnos, r_lnors_spaces, clnors_data);
+ bm_mesh_loops_calc_normals(bm, NULL, NULL, r_lnos, r_lnors_spaces, cd_loop_clnors_offset);
}
#endif
@@ -791,13 +797,13 @@ void BM_mesh_loop_normals_update(BMesh *bm, const float split_angle, float (*r_l
*/
void BM_loops_calc_normal_vcos(BMesh *bm, const float (*vcos)[3], const float (*vnos)[3], const float (*fnos)[3],
const float split_angle, float (*r_lnos)[3],
- MLoopsNorSpaces *r_lnors_spaces, const float (*clnors_data)[2])
+ MLoopsNorSpaces *r_lnors_spaces, const int cd_loop_clnors_offset)
{
/* Tag smooth edges and set lnos from vnos when they might be completely smooth... */
bm_mesh_edges_sharp_tag(bm, vnos, fnos, split_angle, r_lnos);
/* Finish computing lnos by accumulating face normals in each fan of faces defined by sharp edges. */
- bm_mesh_loops_calc_normals(bm, vcos, fnos, r_lnos, r_lnors_spaces, clnors_data);
+ bm_mesh_loops_calc_normals(bm, vcos, fnos, r_lnos, r_lnors_spaces, cd_loop_clnors_offset);
}
static void UNUSED_FUNCTION(bm_mdisps_space_set)(Object *ob, BMesh *bm, int from, int to)
diff --git a/source/blender/bmesh/intern/bmesh_mesh.h b/source/blender/bmesh/intern/bmesh_mesh.h
index 67aa2a7..29a989b 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.h
+++ b/source/blender/bmesh/intern/bmesh_mesh.h
@@ -42,7 +42,7 @@ void BM_mesh_normals_update(BMesh *bm);
void BM_verts_calc_normal_vcos(BMesh *bm, const float (*fnos)[3], const float (*vcos)[3], float (*vnos)[3]);
void BM_loops_calc_normal_vcos(BMesh *bm, const float (*vcos)[3], const float (*vnos)[3], const float (*pnos)[3],
const float split_angle, float (*r_lnos)[3],
- struct MLoopsNorSpaces *r_lnors_spaces, const float (*clnors_data)[2]);
+ struct MLoopsNorSpaces *r_lnors_spaces, const int cd_loop_clnors_offset);
void bmesh_edit_begin(BMesh *bm, const BMOpTypeFlag type_flag);
void bmesh_edit_end(BMesh *bm, const BMOpTypeFlag type_flag);
More information about the Bf-blender-cvs
mailing list