[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56106] trunk/blender: display options to help with 3d printing.
Campbell Barton
ideasman42 at gmail.com
Wed Apr 17 11:27:27 CEST 2013
Revision: 56106
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56106
Author: campbellbarton
Date: 2013-04-17 09:27:23 +0000 (Wed, 17 Apr 2013)
Log Message:
-----------
display options to help with 3d printing.
editmesh debug info,
- overhang (with axis angle options)
- wall thickness (with min/max distance)
- self-intersections.
access below 'Mesh Display' panel.
Modified Paths:
--------------
trunk/blender/release/scripts/startup/bl_ui/space_view3d.py
trunk/blender/source/blender/blenkernel/BKE_editmesh.h
trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c
trunk/blender/source/blender/blenkernel/intern/editderivedmesh.c
trunk/blender/source/blender/blenkernel/intern/editmesh.c
trunk/blender/source/blender/blenkernel/intern/scene.c
trunk/blender/source/blender/blenloader/intern/readfile.c
trunk/blender/source/blender/editors/include/ED_mesh.h
trunk/blender/source/blender/makesdna/DNA_mesh_types.h
trunk/blender/source/blender/makesdna/DNA_scene_types.h
trunk/blender/source/blender/makesrna/intern/rna_mesh.c
trunk/blender/source/blender/makesrna/intern/rna_scene.c
Modified: trunk/blender/release/scripts/startup/bl_ui/space_view3d.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_view3d.py 2013-04-17 07:47:00 UTC (rev 56105)
+++ trunk/blender/release/scripts/startup/bl_ui/space_view3d.py 2013-04-17 09:27:23 UTC (rev 56106)
@@ -2607,6 +2607,44 @@
layout.prop(mesh, "show_extra_indices")
+class VIEW3D_PT_view3d_meshstatvis(Panel):
+ bl_space_type = 'VIEW_3D'
+ bl_region_type = 'UI'
+ bl_label = "Mesh Debug"
+
+ @classmethod
+ def poll(cls, context):
+ # The active object check is needed because of local-mode
+ return (context.active_object and (context.mode == 'EDIT_MESH'))
+
+ def draw_header(self, context):
+ mesh = context.active_object.data
+
+ self.layout.prop(mesh, "show_statvis", text="")
+
+ def draw(self, context):
+ layout = self.layout
+
+ mesh = context.active_object.data
+ statvis = context.tool_settings.statvis
+ layout.active = mesh.show_statvis
+
+ layout.prop(statvis, "type")
+ statvis_type = statvis.type
+ if statvis_type == 'OVERHANG':
+ row = layout.row(align=True)
+ row.prop(statvis, "overhang_min", text="")
+ row.prop(statvis, "overhang_max", text="")
+ layout.prop(statvis, "overhang_axis", expand=True)
+ elif statvis_type == 'THICKNESS':
+ row = layout.row(align=True)
+ row.prop(statvis, "thickness_min", text="")
+ row.prop(statvis, "thickness_max", text="")
+ layout.prop(statvis, "thickness_samples")
+ elif statvis_type == 'INTERSECT':
+ pass
+
+
class VIEW3D_PT_view3d_curvedisplay(Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
Modified: trunk/blender/source/blender/blenkernel/BKE_editmesh.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_editmesh.h 2013-04-17 07:47:00 UTC (rev 56105)
+++ trunk/blender/source/blender/blenkernel/BKE_editmesh.h 2013-04-17 09:27:23 UTC (rev 56106)
@@ -30,6 +30,8 @@
struct BMLoop;
struct BMFace;
struct Mesh;
+struct DerivedMesh;
+struct MeshStatVis;
/* ok: the EDBM module is for editmode bmesh stuff. in contrast, the
* BMEdit module is for code shared with blenkernel that concerns
@@ -61,6 +63,8 @@
CustomDataMask lastDataMask;
unsigned char (*derivedVertColor)[4];
int derivedVertColorLen;
+ unsigned char (*derivedFaceColor)[4];
+ int derivedFaceColorLen;
/* index tables, to map indices to elements via
* EDBM_index_arrays_init and associated functions. don't
@@ -89,5 +93,8 @@
BMEditMesh *BKE_editmesh_from_object(struct Object *ob);
void BKE_editmesh_free(BMEditMesh *em);
void BKE_editmesh_update_linked_customdata(BMEditMesh *em);
+void BKE_editmesh_statvis_calc(BMEditMesh *em, struct DerivedMesh *dm,
+ struct MeshStatVis *statvis,
+ unsigned char (*r_face_colors)[4]);
#endif /* __BKE_EDITMESH_H__ */
Modified: trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c 2013-04-17 07:47:00 UTC (rev 56105)
+++ trunk/blender/source/blender/blenkernel/intern/DerivedMesh.c 2013-04-17 09:27:23 UTC (rev 56106)
@@ -1204,6 +1204,14 @@
int i;
if (em) {
+
+ /* no need to store both */
+ if (em->derivedFaceColor) {
+ MEM_freeN(em->derivedFaceColor);
+ em->derivedFaceColor = NULL;
+ em->derivedFaceColorLen = 0;
+ }
+
if (em->derivedVertColor && em->derivedVertColorLen == numVerts) {
wtcol_v = em->derivedVertColor;
}
@@ -1283,7 +1291,31 @@
}
}
+static void DM_update_statvis_color(Scene *scene, Object *ob, DerivedMesh *dm)
+{
+ BMEditMesh *em = BKE_editmesh_from_object(ob);
+ int numFaces = em->bm->totface;
+ unsigned char (*wtcol_f)[4];
+ /* no need to store both */
+ if (em->derivedVertColor) {
+ MEM_freeN(em->derivedVertColor);
+ em->derivedVertColor = NULL;
+ em->derivedVertColorLen = 0;
+ }
+
+ if (em->derivedFaceColor && em->derivedFaceColorLen == numFaces) {
+ wtcol_f = em->derivedFaceColor;
+ }
+ else {
+ if (em->derivedFaceColor) MEM_freeN(em->derivedFaceColor);
+ wtcol_f = em->derivedFaceColor = MEM_mallocN(sizeof(*wtcol_f) * numFaces, __func__);
+ em->derivedFaceColorLen = numFaces;
+ }
+
+ BKE_editmesh_statvis_calc(em, dm, &scene->toolsettings->statvis, wtcol_f);
+}
+
static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape_uid)
{
KeyBlock *kb;
@@ -1939,6 +1971,7 @@
#endif
const int do_final_wmcol = FALSE;
int do_init_wmcol = ((((Mesh *)ob->data)->drawflag & ME_DRAWEIGHT) && !do_final_wmcol);
+ int do_init_statvis = ((((Mesh *)ob->data)->drawflag & ME_DRAW_STATVIS) && !do_init_wmcol);
modifiers_clearErrors(ob);
@@ -2127,6 +2160,8 @@
/* In this case, we should never have weight-modifying modifiers in stack... */
if (do_init_wmcol)
DM_update_weight_mcol(ob, *final_r, draw_flag, NULL, 0, NULL);
+ if (do_init_statvis)
+ DM_update_statvis_color(scene, ob, *final_r);
}
else {
/* this is just a copy of the editmesh, no need to calc normals */
@@ -2136,6 +2171,8 @@
/* In this case, we should never have weight-modifying modifiers in stack... */
if (do_init_wmcol)
DM_update_weight_mcol(ob, *final_r, draw_flag, NULL, 0, NULL);
+ if (do_init_statvis)
+ DM_update_statvis_color(scene, ob, *final_r);
}
/* --- */
Modified: trunk/blender/source/blender/blenkernel/intern/editderivedmesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/editderivedmesh.c 2013-04-17 07:47:00 UTC (rev 56105)
+++ trunk/blender/source/blender/blenkernel/intern/editderivedmesh.c 2013-04-17 09:27:23 UTC (rev 56106)
@@ -44,12 +44,15 @@
#include "GL/glew.h"
#include "BLI_math.h"
+#include "BLI_jitter.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_mesh.h"
#include "BKE_editmesh.h"
+#include "BKE_editmesh_bvh.h"
#include "DNA_mesh_types.h"
+#include "DNA_scene_types.h"
#include "DNA_object_types.h"
#include "MEM_guardedalloc.h"
@@ -320,8 +323,10 @@
const int skip_normals = !glIsEnabled(GL_LIGHTING); /* could be passed as an arg */
MLoopCol *lcol[3] = {NULL} /* , dummylcol = {0} */;
- unsigned char(*color_vert_array)[4] = (((Mesh *)em->ob->data)->drawflag & ME_DRAWEIGHT) ? em->derivedVertColor : NULL;
+ unsigned char(*color_vert_array)[4] = (((Mesh *)em->ob->data)->drawflag & ME_DRAWEIGHT) ? em->derivedVertColor : NULL;
+ unsigned char(*color_face_array)[4] = (((Mesh *)em->ob->data)->drawflag & ME_DRAW_STATVIS) ? em->derivedFaceColor : NULL;
bool has_vcol_preview = (color_vert_array != NULL) && !skip_normals;
+ bool has_fcol_preview = (color_face_array != NULL) && !skip_normals;
bool has_vcol_any = has_vcol_preview;
/* GL_ZERO is used to detect if drawing has started or not */
@@ -336,6 +341,11 @@
/* call again below is ok */
if (has_vcol_preview) {
BM_mesh_elem_index_ensure(bm, BM_VERT);
+ }
+ if (has_fcol_preview) {
+ BM_mesh_elem_index_ensure(bm, BM_FACE);
+ }
+ if (has_vcol_preview || has_fcol_preview) {
flag |= DM_DRAW_ALWAYS_SMOOTH;
glDisable(GL_LIGHTING); /* grr */
}
@@ -370,8 +380,8 @@
glPolygonStipple(stipple_quarttone);
}
- if (has_vcol_preview) bmdm_get_tri_colpreview(ltri, lcol, color_vert_array);
-
+ if (has_vcol_preview) bmdm_get_tri_colpreview(ltri, lcol, color_vert_array);
+ else if (has_fcol_preview) glColor3ubv((const GLubyte *)&(color_face_array[BM_elem_index_get(efa)]));
if (skip_normals) {
if (poly_type != poly_prev) {
if (poly_prev != GL_ZERO) glEnd();
@@ -455,7 +465,8 @@
glPolygonStipple(stipple_quarttone);
}
- if (has_vcol_preview) bmdm_get_tri_colpreview(ltri, lcol, color_vert_array);
+ if (has_vcol_preview) bmdm_get_tri_colpreview(ltri, lcol, color_vert_array);
+ else if (has_fcol_preview) glColor3ubv((const GLubyte *)&(color_face_array[BM_elem_index_get(efa)]));
if (skip_normals) {
if (poly_type != poly_prev) {
@@ -1530,3 +1541,289 @@
return (DerivedMesh *)bmdm;
}
+
+
+
+/* -------------------------------------------------------------------- */
+/* StatVis Functions */
+
+static void axis_from_enum_v3(float v[3], const char axis)
+{
+ zero_v3(v);
+ if (axis < 3) v[axis] = 1.0f;
+ else v[axis - 3] = -1.0f;
+}
+
+static void statvis_calc_overhang(
+ BMEditMesh *em,
+ float (*polyNos)[3],
+ /* values for calculating */
+ const float min, const float max, const char axis,
+ /* result */
+ unsigned char (*r_face_colors)[4])
+{
+ BMIter iter;
+ BMesh *bm = em->bm;
+ BMFace *f;
+ float dir[3];
+ int index;
+ const float minmax_irange = 1.0f / (max - min);
+
+ /* fallback */
+ const char col_fallback[4] = {64, 64, 64, 255};
+
+ BLI_assert(min <= max);
+
+ axis_from_enum_v3(dir, axis);
+
+ /* now convert into global space */
+ BM_ITER_MESH_INDEX (f, &iter, bm, BM_FACES_OF_MESH, index) {
+ float fac = angle_normalized_v3v3(polyNos ? polyNos[index] : f->no, dir) / (float)M_PI;
+
+ /* remap */
+ if (fac >= min && fac <= max) {
+ float fcol[3];
+ fac = (fac - min) * minmax_irange;
+ fac = 1.0f - fac;
+ CLAMP(fac, 0.0f, 1.0f);
+ weight_to_rgb(fcol, fac);
+ rgb_float_to_uchar(r_face_colors[index], fcol);
+ }
+ else {
+ copy_v4_v4_char((char *)r_face_colors[index], (const char *)col_fallback);
+ }
+ }
+}
+
+/* so we can use jitter values for face interpolation */
+static void uv_from_jitter_v2(float uv[2])
+{
+ uv[0] += 0.5f;
+ uv[1] += 0.5f;
+ if (uv[0] + uv[1] > 1.0f) {
+ uv[0] = 1.0f - uv[0];
+ uv[1] = 1.0f - uv[1];
+ }
+
+ CLAMP(uv[0], 0.0f, 1.0f);
+ CLAMP(uv[1], 0.0f, 1.0f);
+}
+
+static void statvis_calc_thickness(
+ BMEditMesh *em,
+ float (*vertexCos)[3],
+ /* values for calculating */
+ const float min, const float max, const int samples,
+ /* result */
+ unsigned char (*r_face_colors)[4])
+{
+ const float eps_offset = FLT_EPSILON * 10.0f;
+ float *face_dists = (float *)r_face_colors; /* cheating */
+ const bool use_jit = samples < 32;
+ float jit_ofs[32][2];
+ BMesh *bm = em->bm;
+ const int tottri = em->tottri;
+ const float minmax_irange = 1.0f / (max - min);
+ int i;
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list