[Bf-blender-cvs] [be5ac09] testbuild: Squashed commit of custom split normals branch.
Bastien Montagne
noreply at git.blender.org
Fri Nov 14 04:30:00 CET 2014
Commit: be5ac0929fc1496866aa69c55b18b2f5574b80e0
Author: Bastien Montagne
Date: Fri Aug 22 15:12:02 2014 +0200
Branches: testbuild
https://developer.blender.org/rBbe5ac0929fc1496866aa69c55b18b2f5574b80e0
Squashed commit of custom split normals branch.
===================================================================
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.c
M source/blender/blenkernel/intern/mesh_evaluate.c
M source/blender/blenkernel/intern/subsurf_ccg.c
M source/blender/blenlib/BLI_bitmap.h
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/editors/space_outliner/outliner_draw.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..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"
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index efc430d..cda5eaa 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1225,6 +1225,32 @@ 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_bbox_center = (md.mode == 'ELLIPSOID') and not md.target
+ needs_use_current_clnors = (md.mode == 'SPLIT_NORMALS')
+
+ row = layout.row()
+ row.prop(md, "mode", expand=True)
+
+ split = layout.split()
+
+ col = split.column()
+ col.prop(md, "target", text="")
+ sub = col.row()
+ sub.active = needs_object_bbox_center
+ sub.prop(md, "use_bbox_center")
+
+ col = split.column()
+ 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')
+ sub = col.row()
+ sub.active = needs_use_current_clnors
+ sub.prop(md, "use_current_custom_split_normals")
+
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 c8fa3a4..393d326 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 b0ade7b..1b790f83 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 */
@@ -107,6 +108,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..d616021 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -36,6 +36,9 @@ struct BoundBox;
struct DispList;
struct EdgeHash;
struct ListBase;
+struct LinkNode;
+struct BLI_Stack;
+struct MemArena;
struct BMEditMesh;
struct BMesh;
struct Main;
@@ -173,10 +176,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 +183,52 @@ 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! But other solution is to include those in each file using BKE_mesh.h :/ */
+#include "BLI_linklist.h"
+#include "BLI_memarena.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;
+ LinkNode *loops_pool; /* Allocated once, avoids to call BLI_linklist_prepend_arena() for each loop! */
+ 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 short clnor_data[2]);
+void BKE_lnor_space_custom_normal_to_data(MLoopNorSpace *lnor_space, const float custom_lnor[3], short 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,
+ struct MPoly *mpolys, const float (*polynors)[3], const int numPolys, float split_angle,
+ MLoopsNorSpaces *r_lnors_spaces, short (*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, float (*custom_loopnors)[3], const float *custom_loopnors_facs, const int numLoops,
+ struct MPoly *mpolys, const float (*polynors)[3], const int numPolys,
+ short (*r_clnors_data)[2], const bool use_clnors_data);
+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, short (*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 4369ef1..7901845 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,13 @@ 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);
+}
+
+//#define DEBUG_CLNORS
+
+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,11 +2550,40 @@ 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);
+ {
+ short (*clnor_data)[2] = Custo
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list