[Bf-blender-cvs] [f8cbd00] testbuild: Squashed commit of current WIP custom split normals work.
Bastien Montagne
noreply at git.blender.org
Tue Jul 22 20:04:59 CEST 2014
Commit: f8cbd0006e5e5bf1e76c378529cda9acef099bba
Author: Bastien Montagne
Date: Tue Jul 22 20:01:03 2014 +0200
Branches: testbuild
https://developer.blender.org/rBf8cbd0006e5e5bf1e76c378529cda9acef099bba
Squashed commit of current WIP custom split normals work.
Obviously incomplete, just to test new 'testbuild' feature of buildbot. ;)
===================================================================
M release/scripts/startup/bl_ui/properties_data_mesh.py
M release/scripts/startup/bl_ui/properties_data_modifier.py
M source/blender/blenkernel/BKE_DerivedMesh.h
M source/blender/blenkernel/BKE_cdderivedmesh.h
M source/blender/blenkernel/BKE_mesh.h
M source/blender/blenkernel/intern/cdderivedmesh.c
M source/blender/blenkernel/intern/customdata.c
M source/blender/blenkernel/intern/editderivedmesh.c
M source/blender/blenkernel/intern/mesh_evaluate.c
M source/blender/blenkernel/intern/subsurf_ccg.c
M source/blender/bmesh/intern/bmesh_mesh.c
M source/blender/bmesh/intern/bmesh_mesh.h
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/makesdna/DNA_customdata_types.h
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/makesrna/RNA_access.h
M source/blender/makesrna/intern/rna_mesh.c
M source/blender/makesrna/intern/rna_mesh_api.c
M source/blender/makesrna/intern/rna_modifier.c
M source/blender/modifiers/CMakeLists.txt
M source/blender/modifiers/MOD_modifiertypes.h
A source/blender/modifiers/intern/MOD_setsplitnormal.c
M source/blender/modifiers/intern/MOD_util.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py
index 909c6ab..ff3c03a 100644
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@ -370,6 +370,7 @@ 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/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 5769db5..d4d36f9 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1222,6 +1222,34 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
col.prop(md, "material_offset", text="Material Offset")
+ def SET_SPLIT_NORMAL(self, layout, ob, md):
+ has_vgroup = bool(md.vertex_group)
+ needs_object_geom = (md.mode == 'OBJECT')
+ needs_object_center = (md.mode in {'BOX', 'ELLIPSOID'})
+ has_object_center = bool(md.object_center)
+
+ row = layout.row(align=True)
+ row.prop(md, "mode", expand=True)
+
+ split = layout.split()
+
+ col = split.column()
+ col.active = needs_object_geom
+ col.prop(md, "object_geometry", text="")
+
+ row = col.row(align=True)
+ row.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
+ sub = row.row(align=True)
+ sub.active = has_vgroup
+ sub.prop(md, "use_invert_vertex_group", text="", icon='ARROW_LEFTRIGHT')
+
+ col = split.column()
+ col.active = needs_object_center
+ col.prop(md, "object_center", text="")
+ row = col.row()
+ row.active = has_object_center
+ row.prop(md, "use_bbox_center")
+
if __name__ == "__main__": # only for live edit.
bpy.utils.register_module(__name__)
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h
index 868d976..58b07d1 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -88,6 +88,7 @@ struct MTFace;
struct Object;
struct Scene;
struct Mesh;
+struct MLoopsNorSpaces;
struct BMEditMesh;
struct KeyBlock;
struct ModifierData;
@@ -198,6 +199,9 @@ struct DerivedMesh {
/** Calculate loop (split) normals */
void (*calcLoopNormals)(DerivedMesh *dm, const float split_angle);
+ /** Calculate loop (split) normals, and returns split loop normal spaces. */
+ void (*calcLoopNormalsSpaces)(DerivedMesh *dm, const float split_angle, struct MLoopsNorSpaces *r_lnors_spaces);
+
/** Recalculates mesh tessellation */
void (*recalcTessellation)(DerivedMesh *dm);
diff --git a/source/blender/blenkernel/BKE_cdderivedmesh.h b/source/blender/blenkernel/BKE_cdderivedmesh.h
index dffc2b6..03e6aff 100644
--- a/source/blender/blenkernel/BKE_cdderivedmesh.h
+++ b/source/blender/blenkernel/BKE_cdderivedmesh.h
@@ -40,6 +40,7 @@
struct DerivedMesh;
struct BMEditMesh;
struct Mesh;
+struct MLoopsNorSpaces;
struct Object;
/* creates a new CDDerivedMesh */
@@ -101,6 +102,8 @@ void CDDM_calc_normals(struct DerivedMesh *dm);
void CDDM_calc_normals_tessface(struct DerivedMesh *dm);
void CDDM_calc_loop_normals(struct DerivedMesh *dm, const float split_angle);
+void CDDM_calc_loop_normals_spaces(struct DerivedMesh *dm, const float split_angle,
+ struct MLoopsNorSpaces *r_lnors_spaces);
/* calculates edges for a CDDerivedMesh (from face data)
* this completely replaces the current edge data in the DerivedMesh
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index d0c268d..e83811e 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -36,6 +36,8 @@ struct BoundBox;
struct DispList;
struct EdgeHash;
struct ListBase;
+struct LinkNode;
+struct MemArena;
struct BMEditMesh;
struct BMesh;
struct Main;
@@ -173,10 +175,6 @@ void BKE_mesh_calc_normals_tessface(
struct MVert *mverts, int numVerts,
struct MFace *mfaces, int numFaces,
float (*r_faceNors)[3]);
-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,
- struct MPoly *mpolys, float (*polynors)[3], const int numPolys, float split_angle);
void BKE_mesh_loop_tangents_ex(
struct MVert *mverts, const int numVerts, struct MLoop *mloops, float (*r_looptangent)[4], float (*loopnors)[3],
struct MLoopUV *loopuv, const int numLoops, struct MPoly *mpolys, const int numPolys,
@@ -184,6 +182,44 @@ void BKE_mesh_loop_tangents_ex(
void BKE_mesh_loop_tangents(
struct Mesh *mesh, const char *uvmap, float (*r_looptangents)[4], struct ReportList *reports);
+/* XXX This is ugly! */
+#include "BLI_linklist.h"
+#include "BLI_memarena.h"
+#include "BLI_stack.h"
+
+typedef struct MLoopNorSpace {
+ float vec_lnor[3]; /* Automatically computed loop normal. */
+ float vec_ref[3]; /* Reference vector, orthogonal to vec_lnor. */
+ float vec_ortho[3]; /* Third vector, orthogonal to vec_lnor and vec_ref. */
+ float ref_alpha; /* Reference angle, around vec_ortho, in ]0, pi] range (0.0 marks that space as invalid). */
+ float ref_beta; /* Reference angle, around vec_lnor, in ]0, 2pi] range (0.0 marks that space as invalid). */
+ LinkNode *loops; /* All indices (uint_in_ptr) of loops using this lnor space (i.e. smooth fan of loops). */
+} MLoopNorSpace;
+typedef struct MLoopsNorSpaces {
+ MLoopNorSpace **lspaces;
+ MemArena *mem;
+} 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],
+ struct BLI_Stack *edge_vectors);
+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,
+ struct MLoop *mloops, float (*r_loopnors)[3], const int numLoops,
+ struct MPoly *mpolys, const float (*polynors)[3], const int numPolys, float split_angle,
+ MLoopsNorSpaces *r_lnors_spaces, const float (*clnors_data)[2], int *r_loop_to_poly);
+
+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 MPoly *mpolys, const float (*polynors)[3], const int numPolys, float (*r_clnors_data)[2]);
+
void BKE_mesh_calc_poly_normal(
struct MPoly *mpoly, struct MLoop *loopstart,
struct MVert *mvarray, float no[3]);
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index ca4a4b3..e964db9 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -1889,6 +1889,7 @@ static CDDerivedMesh *cdDM_create(const char *desc)
dm->calcNormals = CDDM_calc_normals;
dm->calcLoopNormals = CDDM_calc_loop_normals;
+ dm->calcLoopNormalsSpaces = CDDM_calc_loop_normals_spaces;
dm->recalcTessellation = CDDM_recalc_tessellation;
dm->getVertCos = cdDM_getVertCos;
@@ -2507,6 +2508,11 @@ void CDDM_calc_normals(DerivedMesh *dm)
void CDDM_calc_loop_normals(DerivedMesh *dm, const float split_angle)
{
+ CDDM_calc_loop_normals_spaces(dm, split_angle, NULL);
+}
+
+void CDDM_calc_loop_normals_spaces(DerivedMesh *dm, const float split_angle, MLoopsNorSpaces *r_lnors_spaces)
+{
MVert *mverts = dm->getVertArray(dm);
MEdge *medges = dm->getEdgeArray(dm);
MLoop *mloops = dm->getLoopArray(dm);
@@ -2542,10 +2548,39 @@ void CDDM_calc_loop_normals(DerivedMesh *dm, const float split_angle)
dm->dirty &= ~DM_DIRTY_NORMALS;
- BKE_mesh_normals_loop_split(mverts, numVerts, medges, numEdges, mloops, lnors, numLoops,
- mpolys, pnors, numPolys, split_angle);
-}
+ {
+ const float (*clnor_data)[2] = CustomData_get_layer(ldata, CD_CUSTOMLOOPNORMAL);
+ BKE_mesh_normals_loop_split(mverts, numVerts, medges, numEdges, mloops, lnors, numLoops,
+ mpolys, (const float (*)[3])pnors, numPolys, split_angle,
+ r_lnors_spaces, clnor_data, NULL);
+#if 0
+ if (r_lnors_spaces) {
+ int i;
+ for (i = 0; i < numLoops; i++) {
+ if (r_lnors_spaces->lspaces[i]->ref_alpha != 0.0f) {
+ LinkNode *loops = r_lnors_spaces->lspaces[i]->loops;
+ printf("Loop %d uses lnor space %p:\n", i, r_lnors_spaces->lspaces[i]);
+ print_v3("\tfinal lnor", lnors[i]);
+ print_v3("\tauto lnor", r_lnors_spaces->lspaces[i]->vec_lnor);
+ print_v3("\tref_vec", r_lnors_spaces->lspaces[i]->vec_ref);
+ printf("\talpha: %f\n\tbeta: %f\n\tloops: %p\n", r_lnors_spaces->lspaces[i]->ref_alpha,
+ r_lnors_spaces->lspaces[i]->ref_beta, r_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);
+ }
+ }
+ }
+#endif
+ }
+}
void CDDM_calc_normals_tessface(DerivedMesh *dm)
{
diff --git a/source/blender/blenkernel
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list