[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [60640] branches/vgroup_modifiers: First ( small) step to add more loop normals support:
Bastien Montagne
montagne29 at wanadoo.fr
Wed Oct 9 20:05:06 CEST 2013
Revision: 60640
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60640
Author: mont29
Date: 2013-10-09 18:05:06 +0000 (Wed, 09 Oct 2013)
Log Message:
-----------
First (small) step to add more loop normals support:
*Add a per-object (and object level) option to enable/disable loop normals.
*Compute loop normals at the end of the modifier stack (for both Object and Edit modes).
*Add option to show those loop normals in Edit mode (similar to existing vertiex/face ones).
Notes:
*This is a WIP commit!
*For now, I added the enable/disable loop normal option into viewport's "Item" panel, probably not its final/only location...
*I choose to store the flag at object level, mostly because it's easier to access it in modifier stack evaluation.
Next Steps:
*Extend dm_ensure_display_normals() to create and populate "tesselated loop normals" data (four vectors per face :/ ).
*Use those data in shading.
Modified Paths:
--------------
branches/vgroup_modifiers/release/scripts/startup/bl_ui/space_view3d.py
branches/vgroup_modifiers/source/blender/blenkernel/intern/DerivedMesh.c
branches/vgroup_modifiers/source/blender/editors/space_view3d/drawobject.c
branches/vgroup_modifiers/source/blender/makesdna/DNA_mesh_types.h
branches/vgroup_modifiers/source/blender/makesdna/DNA_object_types.h
branches/vgroup_modifiers/source/blender/makesrna/intern/rna_mesh.c
branches/vgroup_modifiers/source/blender/makesrna/intern/rna_object.c
Modified: branches/vgroup_modifiers/release/scripts/startup/bl_ui/space_view3d.py
===================================================================
--- branches/vgroup_modifiers/release/scripts/startup/bl_ui/space_view3d.py 2013-10-09 17:48:27 UTC (rev 60639)
+++ branches/vgroup_modifiers/release/scripts/startup/bl_ui/space_view3d.py 2013-10-09 18:05:06 UTC (rev 60640)
@@ -2543,6 +2543,13 @@
row = layout.row()
row.label(text="", icon='BONE_DATA')
row.prop(bone, "name", text="")
+ elif ob.type == 'MESH':
+ row = layout.row()
+ row.prop(ob, "use_loop_normals")
+ row = row.row()
+ if not ob.use_loop_normals:
+ row.active = False
+ row.prop(ob, "split_angle", text="")
class VIEW3D_PT_view3d_display(Panel):
@@ -2715,14 +2722,14 @@
col.separator()
col.label(text="Normals:")
- row = col.row()
+ row = col.row(align=True)
- sub = row.row(align=True)
- sub.prop(mesh, "show_normal_vertex", text="", icon='VERTEXSEL')
- sub.prop(mesh, "show_normal_face", text="", icon='FACESEL')
+ row.prop(mesh, "show_normal_vertex", text="", icon='VERTEXSEL')
+ row.prop(mesh, "show_normal_loop", text="", icon='VERTEXSEL')
+ row.prop(mesh, "show_normal_face", text="", icon='FACESEL')
sub = row.row(align=True)
- sub.active = mesh.show_normal_vertex or mesh.show_normal_face
+ sub.active = mesh.show_normal_vertex or mesh.show_normal_face or mesh.show_normal_loop
sub.prop(context.scene.tool_settings, "normal_size", text="Size")
col.separator()
Modified: branches/vgroup_modifiers/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- branches/vgroup_modifiers/source/blender/blenkernel/intern/DerivedMesh.c 2013-10-09 17:48:27 UTC (rev 60639)
+++ branches/vgroup_modifiers/source/blender/blenkernel/intern/DerivedMesh.c 2013-10-09 18:05:06 UTC (rev 60640)
@@ -392,6 +392,52 @@
BLI_assert((dm->dirty & DM_DIRTY_NORMALS) == 0);
}
+static void DM_calc_loop_normals(DerivedMesh *dm, float split_angle)
+{
+ MVert *mverts = dm->getVertArray(dm);
+ MEdge *medges = dm->getEdgeArray(dm);
+ MLoop *mloops = dm->getLoopArray(dm);
+ MPoly *mpolys = dm->getPolyArray(dm);
+
+ CustomData *ldata, *pdata;
+
+ float (*lnors)[3];
+ float (*pnors)[3];
+ bool free_pnors = false;
+
+ const int numVerts = dm->getNumVerts(dm);
+ const int numEdges = dm->getNumEdges(dm);
+ const int numLoops = dm->getNumLoops(dm);
+ const int numPolys = dm->getNumPolys(dm);
+
+ ldata = dm->getLoopDataLayout(dm);
+ if (CustomData_has_layer(ldata, CD_NORMAL)) {
+ lnors = CustomData_get_layer(ldata, CD_NORMAL);
+ }
+ else {
+ lnors = CustomData_add_layer(ldata, CD_NORMAL, CD_CALLOC, NULL, numLoops);
+ }
+
+ DM_ensure_normals(dm);
+ /* Looks like poly normals are actually not computed/stored in dm, so pdata is of no use for us... */
+ pdata = dm->getPolyDataLayout(dm);
+ if (CustomData_has_layer(pdata, CD_NORMAL)) {
+ pnors = CustomData_get_layer(pdata, CD_NORMAL);
+ }
+ else {
+ pnors = MEM_mallocN(sizeof(float[3]) * numPolys, __func__);
+ BKE_mesh_calc_normals_poly(mverts, numVerts, mloops, mpolys, numLoops, numPolys, pnors, false);
+ free_pnors = true;
+ }
+
+ BKE_mesh_normals_loop_split(mverts, numVerts, medges, numEdges, mloops, lnors, numLoops, mpolys, pnors, numPolys,
+ split_angle);
+
+ if (free_pnors) {
+ MEM_freeN(pnors);
+ }
+}
+
/* note: until all modifiers can take MPoly's as input,
* use this at the start of modifiers */
void DM_ensure_tessface(DerivedMesh *dm)
@@ -1846,6 +1892,11 @@
add_orco_dm(ob, NULL, *deform_r, NULL, CD_ORCO);
}
+ if (ob->flag & OB_USE_LOOPNORMALS) {
+ /* Compute loop normals */
+ DM_calc_loop_normals(finaldm, ob->split_angle);
+ }
+
{
/* calculating normals can re-calculate tessfaces in some cases */
#if 0
@@ -2193,6 +2244,14 @@
DM_update_statvis_color(scene, ob, *final_r);
}
+ if (ob->flag & OB_USE_LOOPNORMALS) {
+ /* Compute loop normals */
+ DM_calc_loop_normals(*final_r, ob->split_angle);
+ if (cage_r && *cage_r && *cage_r != *final_r) {
+ DM_calc_loop_normals(*cage_r, ob->split_angle);
+ }
+ }
+
/* --- */
/* BMESH_ONLY, ensure tessface's used for drawing,
* but don't recalculate if the last modifier in the stack gives us tessfaces
Modified: branches/vgroup_modifiers/source/blender/editors/space_view3d/drawobject.c
===================================================================
--- branches/vgroup_modifiers/source/blender/editors/space_view3d/drawobject.c 2013-10-09 17:48:27 UTC (rev 60639)
+++ branches/vgroup_modifiers/source/blender/editors/space_view3d/drawobject.c 2013-10-09 18:05:06 UTC (rev 60640)
@@ -2364,6 +2364,46 @@
#endif
+/* Draw loop normals. */
+static void draw_dm_loop_normals(BMEditMesh *em, Scene *scene, Object *ob, DerivedMesh *dm)
+{
+ /* XXX Would it be worth adding a dm->foreachMappedLoop func just for this? I doubt it... */
+ CustomData *ldata = dm->getLoopDataLayout(dm);
+
+ if (CustomData_has_layer(ldata, CD_NORMAL)) {
+ drawDMNormal_userData data;
+ MLoop *mloops = dm->getLoopArray(dm);
+ MVert *mverts = dm->getVertArray(dm);
+ float (*lnors)[3] = CustomData_get_layer(ldata, CD_NORMAL);
+ int i, totloops = dm->getNumLoops(dm);
+
+ data.em = em;
+ data.normalsize = scene->toolsettings->normalsize;
+
+ calcDrawDMNormalScale(ob, &data);
+
+ glBegin(GL_LINES);
+ for (i = 0; i < totloops; i++, mloops++, lnors++) {
+ float no[3];
+ float *co = mverts[mloops->v].co;
+
+ if (!data.uniform_scale) {
+ mul_v3_m3v3(no, data.tmat, (float *)lnors);
+ normalize_v3(no);
+ mul_m3_v3(data.imat, no);
+ }
+ else {
+ copy_v3_v3(no,(float *)lnors);
+ }
+ mul_v3_fl(no, data.normalsize);
+ add_v3_v3(no, co);
+ glVertex3fv(co);
+ glVertex3fv(no);
+ }
+ glEnd();
+ }
+}
+
/* Draw faces with color set based on selection
* return 2 for the active face so it renders with stipple enabled */
static DMDrawOption draw_dm_faces_sel__setDrawOptions(void *userData, int index)
@@ -3299,6 +3339,10 @@
UI_ThemeColor(TH_VNORMAL);
draw_dm_vert_normals(em, scene, ob, cageDM);
}
+ if ((me->drawflag & ME_DRAW_LNORMALS)) {
+ UI_ThemeColor(TH_VNORMAL);
+ draw_dm_loop_normals(em, scene, ob, cageDM);
+ }
if ((me->drawflag & (ME_DRAWEXTRA_EDGELEN |
ME_DRAWEXTRA_FACEAREA |
Modified: branches/vgroup_modifiers/source/blender/makesdna/DNA_mesh_types.h
===================================================================
--- branches/vgroup_modifiers/source/blender/makesdna/DNA_mesh_types.h 2013-10-09 17:48:27 UTC (rev 60639)
+++ branches/vgroup_modifiers/source/blender/makesdna/DNA_mesh_types.h 2013-10-09 18:05:06 UTC (rev 60640)
@@ -208,6 +208,9 @@
/* draw stats */
#define ME_DRAW_STATVIS (1 << 17)
+/* draw loop normals */
+#define ME_DRAW_LNORMALS (1 << 18)
+
/* Subsurf Type */
#define ME_CC_SUBSURF 0
#define ME_SIMPLE_SUBSURF 1
Modified: branches/vgroup_modifiers/source/blender/makesdna/DNA_object_types.h
===================================================================
--- branches/vgroup_modifiers/source/blender/makesdna/DNA_object_types.h 2013-10-09 17:48:27 UTC (rev 60639)
+++ branches/vgroup_modifiers/source/blender/makesdna/DNA_object_types.h 2013-10-09 18:05:06 UTC (rev 60640)
@@ -264,7 +264,9 @@
struct FluidsimSettings *fluidsimSettings; /* if fluidsim enabled, store additional settings */
struct DerivedMesh *derivedDeform, *derivedFinal;
- int *pad;
+ /* Angle between faces' normals above which an edge is always sharp, used to compute loop normals */
+ float split_angle;
+ int pad_i1;
uint64_t lastDataMask; /* the custom data layer mask that was last used to calculate derivedDeform and derivedFinal */
uint64_t customdata_mask; /* (extra) custom data layer mask to use for creating derivedmesh, set by depsgraph */
unsigned int state; /* bit masks of game controllers that are active */
@@ -444,6 +446,7 @@
/* enable transparent draw */
OB_DRAWTRANSP = 1 << 7,
OB_DRAW_ALL_EDGES = 1 << 8, /* only for meshes currently */
+ OB_DRAW_LOOPSHADING = 1 << 9, /* Use loop normals instead of vertex normals, for shading. */
};
/* empty_drawtype: no flags */
@@ -498,6 +501,8 @@
/* #define OB_RADIO (1 << 11) */ /* deprecated */
#define OB_FROMGROUP (1 << 12)
+#define OB_USE_LOOPNORMALS (1 << 14)
+
/* WARNING - when adding flags check on PSYS_RECALC */
/* ob->recalc (flag bits!) */
enum {
Modified: branches/vgroup_modifiers/source/blender/makesrna/intern/rna_mesh.c
===================================================================
--- branches/vgroup_modifiers/source/blender/makesrna/intern/rna_mesh.c 2013-10-09 17:48:27 UTC (rev 60639)
+++ branches/vgroup_modifiers/source/blender/makesrna/intern/rna_mesh.c 2013-10-09 18:05:06 UTC (rev 60640)
@@ -3140,6 +3140,11 @@
RNA_def_property_ui_text(prop, "Draw Normals", "Display face normals as lines");
RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
+ prop = RNA_def_property(srna, "show_normal_loop", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_DRAW_LNORMALS);
+ RNA_def_property_ui_text(prop, "Draw Loop Normals", "Display vertex-per-face normals as lines");
+ RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
+
prop = RNA_def_property(srna, "show_normal_vertex", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_DRAW_VNORMALS);
RNA_def_property_ui_text(prop, "Draw Vertex Normals", "Display vertex normals as lines");
Modified: branches/vgroup_modifiers/source/blender/makesrna/intern/rna_object.c
===================================================================
--- branches/vgroup_modifiers/source/blender/makesrna/intern/rna_object.c 2013-10-09 17:48:27 UTC (rev 60639)
+++ branches/vgroup_modifiers/source/blender/makesrna/intern/rna_object.c 2013-10-09 18:05:06 UTC (rev 60640)
@@ -40,6 +40,7 @@
#include "DNA_meta_types.h"
#include "BLI_utildefines.h"
+#include "BLI_math.h"
#include "BKE_paint.h"
#include "BKE_editmesh.h"
@@ -2381,6 +2382,21 @@
RNA_def_property_ui_text(prop, "Vertex Groups", "Vertex groups of the object");
rna_def_object_vertex_groups(brna, prop);
+ /* Loop normals */
+ prop = RNA_def_property(srna, "use_loop_normals", PROP_BOOLEAN, PROP_NONE);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list