[Bf-blender-cvs] [ce5e63c] temp_custom_loop_normals: Some cleanup, and add same 'proof-of-concept' code to bmesh, so that we can visualize custom loops normals in 3DView!
Bastien Montagne
noreply at git.blender.org
Wed Aug 6 21:36:33 CEST 2014
Commit: ce5e63c4de48696f6b3e0f776dbd3ebb52c9f5d7
Author: Bastien Montagne
Date: Wed Jun 4 21:15:44 2014 +0200
Branches: temp_custom_loop_normals
https://developer.blender.org/rBce5e63c4de48696f6b3e0f776dbd3ebb52c9f5d7
Some cleanup, and add same 'proof-of-concept' code to bmesh,
so that we can visualize custom loops normals in 3DView!
Still many ugly things here, esp. in includes...
===================================================================
M source/blender/blenkernel/BKE_mesh.h
M source/blender/blenkernel/intern/cdderivedmesh.c
M source/blender/blenkernel/intern/editderivedmesh.c
M source/blender/blenkernel/intern/mesh_evaluate.c
M source/blender/bmesh/intern/bmesh_mesh.c
M source/blender/bmesh/intern/bmesh_mesh.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 6869539..cedaf9c 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -198,6 +198,11 @@ typedef struct MLoopsNorSpaces {
} MLoopsNorSpaces;
void BKE_init_loops_normal_spaces(MLoopsNorSpaces *lnors_spaces, const int numLoops);
void BKE_free_loops_normal_spaces(MLoopsNorSpaces *lnors_spaces);
+MLoopNorSpace *BKE_lnor_space_create(MLoopsNorSpaces *lnors_spaces);
+void BKE_lnor_space_define(MLoopNorSpace *lnor_space, const float lnor[3], float vec_ref[3], float vec_other[3]);
+void BKE_lnor_space_add_loop(MLoopsNorSpaces *lnors_spaces, MLoopNorSpace *lnor_space, const int ml_index, const bool add_to_list);
+void BKE_lnor_space_custom_data_to_normal(MLoopNorSpace *lnor_space, float r_custom_lnor[3], const float clnor_data[2]);
+void BKE_lnor_space_custom_normal_to_data(MLoopNorSpace *lnor_space, const float custom_lnor[3], float r_clnor_data[2]);
void BKE_mesh_normals_loop_split(
struct MVert *mverts, const int numVerts, struct MEdge *medges, const int numEdges,
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index e7af8ef..3ddaa84 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -2555,7 +2555,7 @@ void CDDM_calc_loop_normals(DerivedMesh *dm, const float split_angle)
BKE_mesh_normals_loop_split(mverts, numVerts, medges, numEdges, mloops, lnors, numLoops,
mpolys, pnors, numPolys, split_angle, &lnors_spaces, clnor_data);
for (i = 0; i < numLoops; i++) {
- if (lnors_spaces.lspaces[i]) {
+ if (lnors_spaces.lspaces[i]->angle != 0.0f) {
LinkNode *loops = lnors_spaces.lspaces[i]->loops;
printf("Loop %d uses lnor space %p:\n", i, lnors_spaces.lspaces[i]);
print_v3("\tfinal lnor:", lnors[i]);
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c
index 40a4bc2..681a540 100644
--- a/source/blender/blenkernel/intern/editderivedmesh.c
+++ b/source/blender/blenkernel/intern/editderivedmesh.c
@@ -192,7 +192,39 @@ static void emDM_calcLoopNormals(DerivedMesh *dm, const float split_angle)
loopNos = dm->getLoopDataArray(dm, CD_NORMAL);
}
- BM_loops_calc_normal_vcos(bm, vertexCos, vertexNos, polyNos, split_angle, loopNos);
+ {
+ MLoopsNorSpaces lnors_spaces = {NULL};
+ int i;
+ const int numLoops = dm->getNumLoops(dm);
+ float (*clnor_data)[2] = MEM_mallocN(sizeof(*clnor_data) * (size_t)numLoops, __func__);
+
+ for (i = 0; i < numLoops; i++) {
+ clnor_data[i][0] = 0.7f;
+ clnor_data[i][1] = 0.5f;
+ }
+
+ BM_loops_calc_normal_vcos(bm, vertexCos, vertexNos, polyNos, split_angle, loopNos, &lnors_spaces, clnor_data);
+ for (i = 0; i < numLoops; i++) {
+ if (lnors_spaces.lspaces[i]->angle != 0.0f) {
+ LinkNode *loops = lnors_spaces.lspaces[i]->loops;
+ printf("Loop %d uses lnor space %p:\n", i, lnors_spaces.lspaces[i]);
+ print_v3("\tfinal lnor:", loopNos[i]);
+ print_v3("\tauto lnor:", lnors_spaces.lspaces[i]->vec_lnor);
+ print_v3("\tref_vec:", lnors_spaces.lspaces[i]->vec_ref);
+ printf("\tangle: %f\n\tloops: %p\n", lnors_spaces.lspaces[i]->angle, lnors_spaces.lspaces[i]->loops);
+ printf("\t\t(shared with loops");
+ while(loops) {
+ printf(" %d", GET_INT_FROM_POINTER(loops->link));
+ loops = loops->next;
+ }
+ printf(")\n");
+ }
+ else {
+ printf("Loop %d has no lnor space\n", i);
+ }
+ }
+ BKE_free_loops_normal_spaces(&lnors_spaces);
+ }
}
static void emDM_recalcTessellation(DerivedMesh *UNUSED(dm))
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c
index 01dfffc..ff3afec 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.c
+++ b/source/blender/blenkernel/intern/mesh_evaluate.c
@@ -329,7 +329,7 @@ void BKE_free_loops_normal_spaces(MLoopsNorSpaces *lnors_spaces)
lnors_spaces->mem = NULL;
}
-static MLoopNorSpace *lnor_space_create(MLoopsNorSpaces *lnors_spaces)
+MLoopNorSpace *BKE_lnor_space_create(MLoopsNorSpaces *lnors_spaces)
{
return BLI_memarena_calloc(lnors_spaces->mem, sizeof(MLoopNorSpace));
}
@@ -338,7 +338,7 @@ static MLoopNorSpace *lnor_space_create(MLoopsNorSpaces *lnors_spaces)
* Beware, this modifies ref_vec and other_vec in place!
* Might set *lnor_space to NULL in case no valid space can be generated.
*/
-static void lnor_space_define(MLoopNorSpace *lnor_space, const float lnor[3], float vec_ref[3], float vec_other[3])
+void BKE_lnor_space_define(MLoopNorSpace *lnor_space, const float lnor[3], float vec_ref[3], float vec_other[3])
{
float tvec[3], dtp;
const float pi2 = (float)M_PI * 2.0f;
@@ -382,20 +382,19 @@ static void lnor_space_define(MLoopNorSpace *lnor_space, const float lnor[3], fl
}
}
-static void lnor_space_add_loop(MLoopsNorSpaces *lnors_spaces, MLoopNorSpace *lnor_space, MLoop *ml, int ml_index)
+void BKE_lnor_space_add_loop(MLoopsNorSpaces *lnors_spaces, MLoopNorSpace *lnor_space, const int ml_index, const bool add_to_list)
{
if (lnor_space == NULL) {
return;
}
lnors_spaces->lspaces[ml_index] = lnor_space;
- if (ml && lnor_space) {
+ if (add_to_list && lnor_space) {
BLI_linklist_prepend_arena(&lnor_space->loops, SET_INT_IN_POINTER(ml_index), lnors_spaces->mem);
}
}
-static void BKE_lnor_space_custom_data_to_normal(MLoopNorSpace *lnor_space, float r_custom_lnor[3],
- const float clnor_data[2])
+void BKE_lnor_space_custom_data_to_normal(MLoopNorSpace *lnor_space, float r_custom_lnor[3], const float clnor_data[2])
{
/* NOP custom normal data or invalid lnor space, return. */
if (clnor_data[0] == 1.0f || lnor_space->angle == 0.0f) {
@@ -422,12 +421,11 @@ static void BKE_lnor_space_custom_data_to_normal(MLoopNorSpace *lnor_space, floa
}
}
-static void BKE_lnor_space_custom_normal_to_data(MLoopNorSpace *lnor_space, const float custom_lnor[3],
- float r_custom_data[2])
+void BKE_lnor_space_custom_normal_to_data(MLoopNorSpace *lnor_space, const float custom_lnor[3], float r_clnor_data[2])
{
if (equals_v3v3(lnor_space->vec_lnor, custom_lnor)) {
- r_custom_data[0] = 1.0f;
- r_custom_data[1] = 0.0f;
+ r_clnor_data[0] = 1.0f;
+ r_clnor_data[1] = 0.0f;
return;
}
@@ -435,10 +433,10 @@ static void BKE_lnor_space_custom_normal_to_data(MLoopNorSpace *lnor_space, cons
const float co = dot_v3v3(lnor_space->vec_ref, custom_lnor);
const float pi2 = (float)M_PI * 2.0f;
- r_custom_data[0] = dot_v3v3(lnor_space->vec_lnor, custom_lnor);
+ r_clnor_data[0] = dot_v3v3(lnor_space->vec_lnor, custom_lnor);
if (co > (1.0f - 1e-6f)) {
- r_custom_data[1] = 0.0f;
+ r_clnor_data[1] = 0.0f;
}
else {
float phi = saacos(co);
@@ -448,10 +446,10 @@ static void BKE_lnor_space_custom_normal_to_data(MLoopNorSpace *lnor_space, cons
}
if (phi > lnor_space->angle) {
- r_custom_data[1] = -(pi2 - phi) / (pi2 - lnor_space->angle);
+ r_clnor_data[1] = -(pi2 - phi) / (pi2 - lnor_space->angle);
}
else {
- r_custom_data[1] = phi / lnor_space->angle;
+ r_clnor_data[1] = phi / lnor_space->angle;
}
}
}
@@ -596,7 +594,7 @@ void BKE_mesh_normals_loop_split(MVert *mverts, const int numVerts, MEdge *medge
const int *e2l_curr = edge_to_loops[ml_curr->e];
const int *e2l_prev = edge_to_loops[ml_prev->e];
- if (!IS_EDGE_SHARP(e2l_curr) && (!sharp_verts || sharp_verts[ml_curr->v])) {
+ if (!IS_EDGE_SHARP(e2l_curr) && (!r_lnor_spaces || sharp_verts[ml_curr->v])) {
/* A smooth edge, and we are not generating lnor_spaces, or the related vertex is sharp.
* We skip it because it is either:
* - in the middle of a 'smooth fan' already computed (or that will be as soon as we hit
@@ -617,7 +615,7 @@ void BKE_mesh_normals_loop_split(MVert *mverts, const int numVerts, MEdge *medge
/* If needed, generate this (simple!) lnor space. */
if (r_lnor_spaces) {
float vec_curr[3], vec_prev[3];
- MLoopNorSpace *lnor_space = lnor_space_create(r_lnor_spaces);
+ MLoopNorSpace *lnor_space = BKE_lnor_space_create(r_lnor_spaces);
{
const unsigned int mv_pivot_index = ml_curr->v; /* The vertex we are "fanning" around! */
@@ -633,9 +631,9 @@ void BKE_mesh_normals_loop_split(MVert *mverts, const int numVerts, MEdge *medge
normalize_v3(vec_prev);
}
- lnor_space_define(lnor_space, *lnors, vec_curr, vec_prev);
+ BKE_lnor_space_define(lnor_space, *lnors, vec_curr, vec_prev);
/* We know there is only one loop in this space, no need to create a linklist in this case... */
- lnor_space_add_loop(r_lnor_spaces, lnor_space, NULL, ml_curr_index);
+ BKE_lnor_space_add_loop(r_lnor_spaces, lnor_space, ml_curr_index, false);
if (clnors_data) {
BKE_lnor_space_custom_data_to_normal(lnor_space, *lnors, clnors_data[ml_curr_index]);
@@ -669,7 +667,7 @@ void BKE_mesh_normals_loop_split(MVert *mverts, const int numVerts, MEdge *medge
/* mlfan_vert_index: the loop of our current edge might not be the loop of our current vertex! */
int mlfan_curr_index, mlfan_vert_index, mpfan_curr_index;
- MLoopNorSpace *lnor_space = r_lnor_spaces ? lnor_space_create(r_lnor_spaces) : NULL;
+ MLoopNorSpace *lnor_space = r_lnor_spaces ? BKE_lnor_space_create(r_lnor_spaces) : NULL;
e2lfan_curr = e2l_prev;
mlfan_curr = ml_prev;
@@ -722,7 +720,7 @@ void BKE_mesh_normals_loop_split(MVert *mverts, const int numVerts, MEdge *medge
if (r_lnor_spaces) {
/* Assign current lnor space to current 'vertex' loop. */
- lnor_space_add_loop(r_lnor_spaces, lnor_space, &mloops[mlfan_vert_index], mlfan_vert_index);
+ BKE_lnor_space_add_loop(r_lnor_spaces, lnor_space, mlfan_vert_index, true);
}
if (IS_EDGE_SHARP(e2lfan_curr) || (me_curr == me_org)) {
@@ -780,7 +778,7 @@ void BKE_mesh_normals_loop_split(MVert *mverts, const int numVerts, MEdge *medge
/* If we are generating lnor spaces, we can now define the one for this fan. */
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list