[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11040] trunk/blender/source/blender/src/ sculptmode-stroke.c: == Sculpt Mode ==
Nicholas Bishop
nicholasbishop at gmail.com
Mon Jun 25 13:07:13 CEST 2007
Revision: 11040
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11040
Author: nicholasbishop
Date: 2007-06-25 13:07:12 +0200 (Mon, 25 Jun 2007)
Log Message:
-----------
== Sculpt Mode ==
Refactored and improved sculptmode-stroke.c.
* With smooth stroke on, the Spacing value is now taken into account (if zero, the default value of two is still used)
Modified Paths:
--------------
trunk/blender/source/blender/src/sculptmode-stroke.c
Modified: trunk/blender/source/blender/src/sculptmode-stroke.c
===================================================================
--- trunk/blender/source/blender/src/sculptmode-stroke.c 2007-06-25 04:55:09 UTC (rev 11039)
+++ trunk/blender/source/blender/src/sculptmode-stroke.c 2007-06-25 11:07:12 UTC (rev 11040)
@@ -32,6 +32,7 @@
#include "MEM_guardedalloc.h"
#include "DNA_listBase.h"
+#include "DNA_scene_types.h"
#include "BLI_blenlib.h"
#include "BIF_gl.h"
#include "BDR_sculptmode.h"
@@ -49,6 +50,7 @@
float length;
ListBase final;
StrokePoint *final_mem;
+ float offset;
} SculptStroke;
void sculpt_stroke_new(const int max)
@@ -105,7 +107,7 @@
}
}
-void sculpt_stroke_create_final()
+static void sculpt_stroke_create_final()
{
SculptStroke *stroke = sculpt_session()->stroke;
@@ -126,13 +128,15 @@
}
/* 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);
+ if(stroke->final.first) {
+ 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);
+ }
}
}
@@ -159,48 +163,72 @@
return sqrt(dx*dx + dy*dy);
}
-void sculpt_stroke_apply(struct EditData *e)
+float sculpt_stroke_final_length(SculptStroke *stroke)
{
- SculptStroke *stroke = sculpt_session()->stroke;
+ StrokePoint *p;
+ float len = 0;
+ for(p = stroke->final.first; p && p->next; ++p)
+ len += sculpt_stroke_seglen(p, p->next);
+ return len;
+}
- if(stroke) {
- sculpt_stroke_create_final();
+/* If partial is nonzero, cuts off apply after that length has been processed */
+static StrokePoint *sculpt_stroke_apply_generic(SculptStroke *stroke, struct EditData *e, const int partial)
+{
+ const int sdspace = sculpt_data()->spacing;
+ const short spacing = sdspace > 0 ? sdspace : 2;
+ const int dots = sculpt_stroke_final_length(stroke) / spacing;
+ int i;
+ StrokePoint *p = stroke->final.first;
+ float startloc = stroke->offset;
- if(stroke->length > 200) {
- const short spacing = 2;
- const int dots = stroke->length / spacing;
- int i;
- StrokePoint *p = stroke->final.first;
- float startloc = 0;
+ for(i = 0; i < dots && p && p->next; ++i) {
+ const float dotloc = spacing * i;
+ short co[2];
+ float len = sculpt_stroke_seglen(p, p->next);
+ float u, v;
- for(i = 0; i < dots && p && p->next; ++i) {
- const float dotloc = spacing * i;
- short co[2];
- float len = sculpt_stroke_seglen(p, p->next);
- float u, v;
-
- /* Find edge containing dot */
- while(dotloc > startloc + len && p && p->next && p->next->next) {
- p = p->next;
- startloc += len;
- len = sculpt_stroke_seglen(p, p->next);
- }
+ /* Find edge containing dot */
+ while(dotloc > startloc + len && p && p->next && p->next->next) {
+ p = p->next;
+ startloc += len;
+ len = sculpt_stroke_seglen(p, p->next);
+ }
- if(!p || !p->next) break;
+ if(!p || !p->next || dotloc > startloc + len)
+ break;
+ if(partial && startloc > partial) {
+ /* Calculate offset for next stroke segment */
+ stroke->offset = startloc + len - dotloc;
+ break;
+ }
- u = (dotloc - startloc) / len;
- v = 1 - u;
+ u = (dotloc - startloc) / len;
+ v = 1 - u;
- co[0] = p->x*u + p->next->x*v;
- co[1] = p->y*u + p->next->y*v;
+ co[0] = p->x*v + p->next->x*u;
+ co[1] = p->y*v + p->next->y*u;
- if(startloc > 100)
- break;
+ do_symmetrical_brush_actions(e, co, NULL);
+ }
- do_symmetrical_brush_actions(e, co, NULL);
- }
+ return p ? p->next : NULL;
+}
+void sculpt_stroke_apply(struct EditData *e)
+{
+ SculptStroke *stroke = sculpt_session()->stroke;
+ /* TODO: make these values user-modifiable? */
+ const int partial_len = 100;
+ const int min_len = 200;
+
+ if(stroke) {
+ sculpt_stroke_create_final();
+
+ if(sculpt_stroke_final_length(stroke) > min_len) {
+ StrokePoint *p = sculpt_stroke_apply_generic(stroke, e, partial_len);
+
/* Replace remaining values in stroke->loc with remaining stroke->final values */
stroke->index = -1;
stroke->length = 0;
@@ -223,36 +251,7 @@
sculpt_stroke_create_final();
if(stroke) {
- const short spacing = 2;
- const int dots = stroke->length / spacing;
- int i;
- StrokePoint *p = stroke->final.first;
- float startloc = 0;
-
- for(i = 0; i < dots && p && p->next; ++i) {
- const float dotloc = spacing * i;
- short co[2];
- float len = sculpt_stroke_seglen(p, p->next);
- float u, v;
-
- /* Find edge containing dot */
- while(dotloc > startloc + len && p && p->next && p->next->next) {
- p = p->next;
- startloc += len;
- len = sculpt_stroke_seglen(p, p->next);
- }
-
- if(!p || !p->next) break;
-
-
- u = (dotloc - startloc) / len;
- v = 1 - u;
-
- co[0] = p->x*u + p->next->x*v;
- co[1] = p->y*u + p->next->y*v;
-
- do_symmetrical_brush_actions(e, co, NULL);
- }
+ sculpt_stroke_apply_generic(stroke, e, 0);
}
}
More information about the Bf-blender-cvs
mailing list