[Bf-blender-cvs] [0d3751e] temp_custom_loop_normals: Several enhancements:
Bastien Montagne
noreply at git.blender.org
Wed Aug 6 21:36:45 CEST 2014
Commit: 0d3751e6ce58319c00581e1dc60ea9a1a69f5bb3
Author: Bastien Montagne
Date: Tue Jul 29 17:27:35 2014 +0200
Branches: temp_custom_loop_normals
https://developer.blender.org/rB0d3751e6ce58319c00581e1dc60ea9a1a69f5bb3
Several enhancements:
* Add an 'has custom lnors' helper, also available from RNA.
* Add a 'factors' array to set custom lnors func, to make lerp interpolation between custom lnor and auto lnor.
* Add a 'set custom lnors from vert nors' func (also available from RNA).
* Reshuffle a bit clnor CD data handling in UI (now in Normals panel, and you can also add a layer if needed).
===================================================================
M release/scripts/startup/bl_ui/properties_data_mesh.py
M source/blender/blenkernel/BKE_mesh.h
M source/blender/blenkernel/intern/customdata.c
M source/blender/blenkernel/intern/editderivedmesh.c
M source/blender/blenkernel/intern/mesh.c
M source/blender/blenkernel/intern/mesh_evaluate.c
M source/blender/editors/mesh/mesh_data.c
M source/blender/editors/mesh/mesh_intern.h
M source/blender/editors/mesh/mesh_ops.c
M source/blender/makesrna/intern/rna_mesh.c
M source/blender/makesrna/intern/rna_mesh_api.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py
index ff3c03a..0270295 100644
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@ -146,17 +146,26 @@ class DATA_PT_normals(MeshButtonsPanel, Panel):
layout = self.layout
mesh = context.mesh
+ has_clnors = mesh.has_custom_normals
split = layout.split()
col = split.column()
col.prop(mesh, "use_auto_smooth")
sub = col.column()
- sub.active = mesh.use_auto_smooth
+ sub.active = mesh.use_auto_smooth and not has_clnors
sub.prop(mesh, "auto_smooth_angle", text="Angle")
split.prop(mesh, "show_double_sided")
+ row = layout.row()
+ if has_clnors:
+ row.operator("mesh.customdata_add_clear_custom_splitnormals",
+ icon='X', text="Clear Custom Split Normals Data")
+ else:
+ row.operator("mesh.customdata_add_clear_custom_splitnormals",
+ icon='ZOOMIN', text="Add Custom Split Normals Data")
+
class DATA_PT_texture_space(MeshButtonsPanel, Panel):
bl_label = "Texture Space"
@@ -370,7 +379,6 @@ class DATA_PT_customdata(MeshButtonsPanel, Panel):
col.operator("mesh.customdata_clear_mask", icon='X')
col.operator("mesh.customdata_clear_skin", icon='X')
- col.operator("mesh.customdata_clear_custom_splitnormals", icon='X')
col = layout.column()
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index e83811e..8dfc4b4 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -209,6 +209,8 @@ void BKE_lnor_space_add_loop(MLoopsNorSpaces *lnors_spaces, MLoopNorSpace *lnor_
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]);
+bool BKE_mesh_has_custom_loop_normals(struct Mesh *me);
+
void BKE_mesh_normals_loop_split(
struct MVert *mverts, const int numVerts, struct MEdge *medges, const int numEdges,
struct MLoop *mloops, float (*r_loopnors)[3], const int numLoops,
@@ -217,7 +219,11 @@ void BKE_mesh_normals_loop_split(
void BKE_mesh_normals_loop_custom_set(
struct MVert *mverts, const int numVerts, struct MEdge *medges, const int numEdges,
- struct MLoop *mloops, const float (*custom_loopnors)[3], const int numLoops,
+ struct MLoop *mloops, float (*custom_loopnors)[3], const float *custom_loopnors_facs, const int numLoops,
+ struct MPoly *mpolys, const float (*polynors)[3], const int numPolys, float (*r_clnors_data)[2]);
+void BKE_mesh_normals_loop_custom_from_vertices_set(
+ struct MVert *mverts, float (*custom_vertnors)[3], const float *custom_vertnors_facs, const int numVerts,
+ struct MEdge *medges, const int numEdges, struct MLoop *mloops, const int numLoops,
struct MPoly *mpolys, const float (*polynors)[3], const int numPolys, float (*r_clnors_data)[2]);
void BKE_mesh_calc_poly_normal(
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 475cd83..e0116da 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1081,6 +1081,11 @@ static void layerInterp_clnor(void **UNUSED(sources), const float *UNUSED(weight
zero_v2((float *)dest);
}
+static void layerDefault_clnor(void *data, int count)
+{
+ fill_vn_fl((float *)data, count * 2, 0.0f);
+}
+
static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
/* 0: CD_MVERT */
{sizeof(MVert), "MVert", 1, NULL, NULL, NULL, NULL, NULL, NULL},
@@ -1195,7 +1200,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
/* 40: CD_TESSLOOPNORMAL */
{sizeof(short[4][3]), "", 0, NULL, NULL, NULL, NULL, layerSwap_flnor, NULL},
/* 41: CD_CUSTOMLOOPNORMAL */
- {sizeof(float[2]), "vec2f", 1, NULL, NULL, NULL, layerInterp_clnor, NULL, NULL},
+ {sizeof(float[2]), "vec2f", 1, NULL, NULL, NULL, layerInterp_clnor, NULL, layerDefault_clnor},
};
/* note, numbers are from trunk and need updating for bmesh */
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c
index 40dd1ec..41a69b1 100644
--- a/source/blender/blenkernel/intern/editderivedmesh.c
+++ b/source/blender/blenkernel/intern/editderivedmesh.c
@@ -204,9 +204,9 @@ static void emDM_calcLoopNormalsSpaces(DerivedMesh *dm, const float split_angle,
{
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
+ const int numLoops = dm->getNumLoops(dm);
float (*clnor_data)[2] = NULL;
/* XXX All this is really dirty!!! */
if (CustomData_has_layer(ldata, CD_CUSTOMLOOPNORMAL)) {
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 66c383e..7842002 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -414,6 +414,11 @@ void BKE_mesh_update_customdata_pointers(Mesh *me, const bool do_ensure_tess_cd)
me->mloopuv = CustomData_get_layer(&me->ldata, CD_MLOOPUV);
}
+bool BKE_mesh_has_custom_loop_normals(Mesh *me)
+{
+ return CustomData_has_layer(&me->ldata, CD_CUSTOMLOOPNORMAL);
+}
+
/* Note: unlinking is called when me->id.us is 0, question remains how
* much unlinking of Library data in Mesh should be done... probably
* we need a more generic method, like the expand() functions in
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c
index 2897fc8..372a24f 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.c
+++ b/source/blender/blenkernel/intern/mesh_evaluate.c
@@ -889,16 +889,19 @@ void BKE_mesh_normals_loop_split(MVert *mverts, const int numVerts, MEdge *medge
* Compute internal representation of given custom normals (as an array of float[2]).
* It also make sure the mesh matches those custom normals, by setting sharp edges fag as needed to get a
* same custom lnor for all loops sharing a same smooth fan.
+ * If use_vertices if true, custom_loopnors and custom_loopnors_facs are assumed to be per-vertex, not per-loop
+ * (this allows to set whole vert's normals at once, useful in some cases).
*/
-void BKE_mesh_normals_loop_custom_set(MVert *mverts, const int numVerts, MEdge *medges, const int numEdges,
- MLoop *mloops, const float (*custom_loopnors)[3], const int numLoops,
- MPoly *mpolys, const float (*polynors)[3], const int numPolys,
- float (*r_clnors_data)[2])
+static void mesh_normals_loop_custom_set(MVert *mverts, const int numVerts, MEdge *medges, const int numEdges,
+ MLoop *mloops, float (*custom_loopnors)[3],
+ const float *custom_loopnors_facs, const int numLoops,
+ MPoly *mpolys, const float (*polynors)[3], const int numPolys,
+ float (*r_clnors_data)[2], const bool use_vertices)
{
/* We *may* make that poor BKE_mesh_normals_loop_split() even more complex by making it handling that
* feature too, would probably be more efficient in absolute.
* However, this function *is not* performance-critical, since it is mostly expected to be called
- * by io addons when importing custom normals (and perhaps from some editing tools later?).
+ * by io addons when importing custom normals, and modifier (and perhaps from some editing tools later?).
* So better to keep some simplicity here, and just call BKE_mesh_normals_loop_split() twice!
*/
MLoopsNorSpaces lnors_spaces = {NULL};
@@ -943,10 +946,30 @@ void BKE_mesh_normals_loop_custom_set(MVert *mverts, const int numVerts, MEdge *
LinkNode *loops = lnors_spaces.lspaces[i]->loops;
MLoop *prev_ml = NULL;
const float *org_nor = NULL;
+ if (!loops) {
+ MLoop *ml = &mloops[i];
+ const int idx = use_vertices ? (int)ml->v : i;
+ float *nor = custom_loopnors[idx];
+ const float fac = custom_loopnors_facs ? custom_loopnors_facs[idx] : 1.0f;
+
+ if (fac != 1.0f) {
+ /* Note: inplace modification to get final custom lnor! */
+ interp_v3_v3v3_slerp(nor, lnors_spaces.lspaces[i]->vec_lnor, nor, fac);
+ }
+ BLI_BITMAP_ENABLE(done_loops, i);
+ }
+ /* Hidden else, avoids one indentation. ;) */
while (loops) {
const int lidx = GET_INT_FROM_POINTER(loops->link);
- const float *nor = custom_loopnors[lidx];
MLoop *ml = &mloops[lidx];
+ const int idx = use_vertices ? (int)ml->v : lidx;
+ float *nor = custom_loopnors[idx];
+ const float fac = custom_loopnors_facs ? custom_loopnors_facs[idx] : 1.0f;
+
+ if (fac != 1.0f) {
+ /* Note: inplace modification to get final custom lnor! */
+ interp_v3_v3v3_slerp(nor, lnors_spaces.lspaces[lidx]->vec_lnor, nor, fac);
+ }
if (!org_nor) {
org_nor = nor;
@@ -968,7 +991,6 @@ void BKE_mesh_normals_loop_custom_set(MVert *mverts, const int numVerts, MEdge *
loops = loops->next;
BLI_BITMAP_ENABLE(done_loops, lidx);
}
- BLI_BITMAP_ENABLE(done_loops, i); /* in case it's a single-loop case... */
}
}
@@ -999,7 +1021,8 @@ void BKE_mesh_normals_loop_custom_set(MVert *mverts, const int numVerts, MEdge *
zero_v3(avg_nor);
while (loops) {
const int lidx = GET_INT_FROM_POINTER(loops->link);
- const float *nor = custom_loopnors[lidx];
+ const int idx = use_vertices ? (int)mloops[lidx].v : lidx;
+ const float *nor = custom_loopnors[idx];
nbr_nors++;
add_v3_v3(avg_nor, nor);
@@ -1017,7 +1040,8 @@ void BKE_mesh_normals_loop_custom_set(MVert *mverts, const int numVerts, MEdge *
}
}
else {
- BKE_l
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list