[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11036] trunk/blender/source/blender: == Sculpt Mode ==

Nicholas Bishop nicholasbishop at gmail.com
Mon Jun 25 00:28:36 CEST 2007


Revision: 11036
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11036
Author:   nicholasbishop
Date:     2007-06-25 00:28:28 +0200 (Mon, 25 Jun 2007)

Log Message:
-----------
== Sculpt Mode ==

Added a new input control that smooths the brush stroke.

This option controlled by the menu item Sculpt>Input Control>Smooth Stroke. When enabled, the brush has a delayed effect on the model; a green line is drawn to indicate the smoothed path of the stroke. After ~200 pixels, the first half of the stroke will be applied to the model; the process then repeats, with a new segment of the stroke being applied to the model after every 200 pixels. On mouse up, any remaining portion of the stroke will be applied.

Other changes:
* Added a flags field to SculptData; currently only used for smooth stroke but other flags can be moved into it
* Moved the damaged_rects/verts into SculptSession
* Simplified brush application by moving init_editdata into do_symmetrical_brush_actions
* Removed Averaging from sculpt Input menu; smooth stroke should take its place

TODO:
* Fix display of the smooth line in Partial Redraw mode
* Make the smoothing and delay factors adjustable
* Optimize the stroke application (currently using the old 'dot' style of applying the brush)

Modified Paths:
--------------
    trunk/blender/source/blender/include/BDR_sculptmode.h
    trunk/blender/source/blender/makesdna/DNA_scene_types.h
    trunk/blender/source/blender/src/drawview.c
    trunk/blender/source/blender/src/header_view3d.c
    trunk/blender/source/blender/src/sculptmode.c

Added Paths:
-----------
    trunk/blender/source/blender/src/sculptmode-stroke.c

Modified: trunk/blender/source/blender/include/BDR_sculptmode.h
===================================================================
--- trunk/blender/source/blender/include/BDR_sculptmode.h	2007-06-24 20:03:55 UTC (rev 11035)
+++ trunk/blender/source/blender/include/BDR_sculptmode.h	2007-06-24 22:28:28 UTC (rev 11036)
@@ -30,13 +30,15 @@
 #ifndef BDR_SCULPTMODE_H
 #define BDR_SCULPTMODE_H
 
+#include "DNA_listBase.h"
+#include "DNA_vec_types.h"
 /* For bglMats */
 #include "BIF_glutil.h"
-
 #include "transform.h"
 
 struct uiBlock;
 struct BrushData;
+struct EditData;
 struct IndexNode;
 struct KeyBlock;
 struct Mesh;
@@ -45,6 +47,7 @@
 struct Scene;
 struct ScrArea;
 struct SculptData;
+struct SculptStroke;
 
 typedef enum PropsetMode {
 	PropsetNone = 0,
@@ -75,6 +78,11 @@
 	struct ListBase *vertex_users;
 	struct IndexNode *vertex_users_mem;
 	int vertex_users_size;
+
+	/* Used temporarily per-stroke */
+	float *vertexcosnos;
+	ListBase damaged_rects;
+	ListBase damaged_verts;
 	
 	/* Used to cache the render of the active texture */
 	unsigned int texcache_w, texcache_h, *texcache;
@@ -83,6 +91,8 @@
 	
 	/* For rotating around a pivot point */
 	vec3f pivot;
+
+	struct SculptStroke *stroke;
 } SculptSession;
 
 SculptSession *sculpt_session(void);
@@ -102,15 +112,26 @@
 void sculptmode_selectbrush_menu(void);
 void sculptmode_draw_mesh(int);
 void sculpt_paint_brush(char clear);
+void sculpt_stroke_draw();
 
 struct BrushData *sculptmode_brush(void);
 float tex_angle(void);
+void do_symmetrical_brush_actions(struct EditData *e, short *, short *);
 
 void sculptmode_update_tex(void);
 char sculpt_modifiers_active(struct Object *ob);
 void sculpt(void);
 void set_sculptmode(void);
 
+/* Stroke */
+void sculpt_stroke_new(const int max);
+void sculpt_stroke_free();
+void sculpt_stroke_add_point(const short x, const short y);
+void sculpt_stroke_apply(struct EditData *);
+void sculpt_stroke_apply_all(struct EditData *e);
+void sculpt_stroke_draw();
+
+
 /* Partial Mesh Visibility */
 struct PartialVisibility *sculptmode_copy_pmv(struct PartialVisibility *);
 void sculptmode_pmv_free(struct PartialVisibility *);

Modified: trunk/blender/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_scene_types.h	2007-06-24 20:03:55 UTC (rev 11035)
+++ trunk/blender/source/blender/makesdna/DNA_scene_types.h	2007-06-24 22:28:28 UTC (rev 11036)
@@ -388,6 +388,7 @@
 	char texsep;
 
 	char averaging;
+	char flags;
 	
 	char draw_flag;
 	
@@ -397,6 +398,8 @@
 	/* Symmetry is separate from the other BrushData because the same
 	   settings are always used for all brush types */
 	char symm;
+
+	char pad[7];
 } SculptData;
 
 typedef struct Scene {
@@ -603,6 +606,8 @@
 #define FFMPEG_MULTIPLEX_AUDIO  1
 #define FFMPEG_AUTOSPLIT_OUTPUT 2
 
+/* SculptData.flags */
+#define SCULPT_INPUT_SMOOTH 1
 /* SculptData.brushtype */
 #define DRAW_BRUSH 1
 #define SMOOTH_BRUSH 2

Modified: trunk/blender/source/blender/src/drawview.c
===================================================================
--- trunk/blender/source/blender/src/drawview.c	2007-06-24 20:03:55 UTC (rev 11035)
+++ trunk/blender/source/blender/src/drawview.c	2007-06-24 22:28:28 UTC (rev 11036)
@@ -2920,6 +2920,10 @@
 		PropsetData *pd= sculpt_session()->propset;
 		short r1=100, r2=100, r3=100;
 		short mouse[2];
+
+		if(sculpt_data()->flags & SCULPT_INPUT_SMOOTH)
+			sculpt_stroke_draw();
+
 		if(pd) {
 			if(pd->mode == PropsetSize) {
 				r1= sculptmode_brush()->size;

Modified: trunk/blender/source/blender/src/header_view3d.c
===================================================================
--- trunk/blender/source/blender/src/header_view3d.c	2007-06-24 20:03:55 UTC (rev 11035)
+++ trunk/blender/source/blender/src/header_view3d.c	2007-06-24 22:28:28 UTC (rev 11036)
@@ -4186,9 +4186,7 @@
 	
 	switch(event) {
 	case 0:
-		val= sd->averaging;
-		if(button(&val,1,10,"Averaging:")==0) return;
-		sd->averaging= val;
+		sd->flags ^= SCULPT_INPUT_SMOOTH;
 		break;
 	case 1:
 		val= sd->tablet_size;
@@ -4262,11 +4260,12 @@
 {
 	uiBlock *block;
 	short yco= 0, menuwidth= 120;
+	SculptData *sd= &G.scene->sculptdata;
 
 	block= uiNewBlock(&curarea->uiblocks, "view3d_sculpt_inputmenu", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
 	uiBlockSetButmFunc(block, do_view3d_sculpt_inputmenu, NULL);
 
-	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Averaging", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
+	uiDefIconTextBut(block, BUTM, 1, ((sd->flags & SCULPT_INPUT_SMOOTH) ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT), "Smooth Stroke", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "");
 	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Tablet Size Adjust", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 1, "");	
 	uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Tablet Strength Adjust", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 2, "");
 	
@@ -4287,7 +4286,7 @@
 	
 	uiDefIconTextBut(block, BUTM, 1, ICON_MENU_PANEL, "Sculpt Properties|N", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 14, "");
 	uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
-	uiDefIconTextBlockBut(block, view3d_sculpt_inputmenu, NULL, ICON_RIGHTARROW_THIN, "Input Devices", 0, yco-=20, 120, 19, "");
+	uiDefIconTextBlockBut(block, view3d_sculpt_inputmenu, NULL, ICON_RIGHTARROW_THIN, "Input Settings", 0, yco-=20, 120, 19, "");
 	uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
 	uiDefIconTextBut(block, BUTM, 1, ((sd->draw_flag & SCULPTDRAW_BRUSH) ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT), "Display Brush", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 13, "");
 	uiDefIconTextBut(block, BUTM, 1, ((sd->draw_flag & SCULPTDRAW_FAST) ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT), "Partial Redraw", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");

Added: trunk/blender/source/blender/src/sculptmode-stroke.c
===================================================================
--- trunk/blender/source/blender/src/sculptmode-stroke.c	                        (rev 0)
+++ trunk/blender/source/blender/src/sculptmode-stroke.c	2007-06-24 22:28:28 UTC (rev 11036)
@@ -0,0 +1,280 @@
+/*
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software  Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2007 by Nicholas Bishop
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ * Storage and manipulation of sculptmode brush strokes.
+ *
+ */
+
+#include "MEM_guardedalloc.h"
+#include "DNA_listBase.h"
+#include "BLI_blenlib.h"
+#include "BIF_gl.h"
+#include "BDR_sculptmode.h"
+#include <math.h>
+
+/* Temporary storage of input stroke control points */
+typedef struct StrokePoint {
+	struct StrokePoint *next, *prev;
+	short x, y;
+} StrokePoint;
+typedef struct SculptStroke {
+	short (*loc)[2];
+	int max;
+	int index;
+	float length;
+	ListBase final;
+	StrokePoint *final_mem;
+} SculptStroke;
+
+void sculpt_stroke_new(const int max)
+{
+	SculptSession *ss = sculpt_session();
+
+	ss->stroke = MEM_callocN(sizeof(SculptStroke), "SculptStroke");
+	ss->stroke->loc = MEM_callocN(sizeof(short) * 2 * max, "SculptStroke.loc");
+	ss->stroke->max = max;
+	ss->stroke->index = -1;
+}
+
+void sculpt_stroke_free()
+{
+	SculptSession *ss = sculpt_session();
+	if(ss && ss->stroke) {
+		if(ss->stroke->loc) MEM_freeN(ss->stroke->loc);
+		if(ss->stroke->final_mem) MEM_freeN(ss->stroke->final_mem);
+
+		MEM_freeN(ss->stroke);
+		ss->stroke = NULL;
+	}
+}
+
+void sculpt_stroke_add_point(const short x, const short y)
+{
+	SculptStroke *stroke = sculpt_session()->stroke;
+	const int next = stroke->index + 1;
+
+	if(stroke->index == -1) {
+		stroke->loc[0][0] = x;
+		stroke->loc[0][1] = y;
+		stroke->index = 0;
+	}
+	else if(next < stroke->max) {
+		const int dx = x - stroke->loc[stroke->index][0];
+		const int dy = y - stroke->loc[stroke->index][1];
+		stroke->loc[next][0] = x;
+		stroke->loc[next][1] = y;
+		stroke->length += sqrt(dx*dx + dy*dy);
+		stroke->index = next;
+	}
+}
+
+void sculpt_stroke_smooth(SculptStroke *stroke)
+{
+	/* Apply smoothing (exclude the first and last points)*/
+	StrokePoint *p = stroke->final.first;
+	if(p && p->next && p->next->next) {
+		for(p = p->next->next; p && p->next && p->next->next; p = p->next) {
+			p->x = p->prev->prev->x*0.1 + p->prev->x*0.2 + p->x*0.4 + p->next->x*0.2 + p->next->next->x*0.1;
+			p->y = p->prev->prev->y*0.1 + p->prev->y*0.2 + p->y*0.4 + p->next->y*0.2 + p->next->next->y*0.1;
+		}
+	}	
+}
+
+void sculpt_stroke_create_final()
+{
+	SculptStroke *stroke = sculpt_session()->stroke;
+
+	if(stroke) {
+		StrokePoint *p, *pnext;
+		int i;
+
+		/* Copy loc into final */
+		if(stroke->final_mem)
+			MEM_freeN(stroke->final_mem);
+		stroke->final_mem = MEM_callocN(sizeof(StrokePoint) * (stroke->index + 1) * 2, "SculptStroke.final");
+		stroke->final.first = stroke->final.last = NULL;
+		for(i = 0; i <= stroke->index; ++i) {
+			p = &stroke->final_mem[i];
+			p->x = stroke->loc[i][0];
+			p->y = stroke->loc[i][1];
+			BLI_addtail(&stroke->final, p);
+		}
+
+		/* Remove shortest edges */
+		for(p = ((StrokePoint*)stroke->final.first)->next; p && p->next; p = pnext) {
+			const int dx = p->x - p->prev->x;
+			const int dy = p->y - p->prev->y;
+			const float len = sqrt(dx*dx + dy*dy);
+			pnext = p->next;
+			if(len < 10) {
+				BLI_remlink(&stroke->final, p);
+			}
+		}
+
+		sculpt_stroke_smooth(stroke);
+
+		/* Subdivide edges */
+		for(p = stroke->final.first; p && p->next; p = pnext) {
+			StrokePoint *np = &stroke->final_mem[i++];
+
+			pnext = p->next;
+			np->x = (p->x + p->next->x) / 2;
+			np->y = (p->y + p->next->y) / 2;
+			BLI_insertlink(&stroke->final, p, np);
+		}
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list