[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38917] branches/soc-2011-onion: preliminary work on actually painting using BruahLib.

Jason Wilkins Jason.A.Wilkins at gmail.com
Tue Aug 2 09:17:16 CEST 2011


Revision: 38917
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38917
Author:   jwilkins
Date:     2011-08-02 07:17:15 +0000 (Tue, 02 Aug 2011)
Log Message:
-----------
preliminary work on actually painting using BruahLib.  I've hard-coded the 'pen' brush from MyPaint for now until I have a method for importing MyPaint brushes.

Modified Paths:
--------------
    branches/soc-2011-onion/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_brushlib.cpp
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_brushlib.h
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_bspace.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_intern.h
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_stroke.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_stroke.h
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_vertex.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt.c
    branches/soc-2011-onion/source/blender/editors/sculpt_paint/sculpt_tools.c
    branches/soc-2011-onion/source/blender/makesdna/DNA_brush_types.h
    branches/soc-2011-onion/source/blender/makesrna/intern/rna_brush.c

Modified: branches/soc-2011-onion/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2011-onion/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2011-08-02 07:08:22 UTC (rev 38916)
+++ branches/soc-2011-onion/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2011-08-02 07:17:15 UTC (rev 38917)
@@ -904,6 +904,8 @@
 
             col.prop(brush, "stroke_method", text="")
 
+            col.prop(brush, "use_brushlib")
+
             # Airbrush
 
             if db:

Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_brushlib.cpp
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_brushlib.cpp	2011-08-02 07:08:22 UTC (rev 38916)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_brushlib.cpp	2011-08-02 07:17:15 UTC (rev 38917)
@@ -36,17 +36,18 @@
 
 #include "paint_brushlib.h"
 
+extern "C" {
 #include "MEM_sys_types.h"
 #include "BLI_rand.h"
 
 #include <stdio.h>
 #include <math.h>
 #include <float.h>
+}
 
 
-
 /* BrushLib uses glib, but Blender does not,
-   so here is a thin wrapper so Blender can continue to not use glib */
+   so here is a thin shim so Blender can continue to not use glib */
 #if !WITH_GLIB
 
 typedef double gdouble;
@@ -138,13 +139,13 @@
 #define not !
 #endif
 
-float hypotf(float a, float b)
+static inline float hypotf(float a, float b)
 {
 	return sqrtf(a*a + b*b);
 }
 
 #ifndef isfinite
-#define isfinite(A) ((A) < -DBL_MAX || (A) > DBL_MAX)
+#define isfinite(A) ((A) >= -DBL_MAX && (A) <= DBL_MAX)
 #endif
 
 #endif // _MSC_VER
@@ -160,9 +161,9 @@
 class BlenderSurface : public Surface {
 public:
 
-	void set_context(struct bContext *C, struct PaintStroke *stroke)
+	void set_context(const struct bContext *C, struct PaintStroke *stroke)
 	{
-		BlenderSurface::C= C;
+		BlenderSurface::C= const_cast<bContext *>(C);
 		BlenderSurface::stroke= stroke;
 	}
 
@@ -344,17 +345,89 @@
 	}
 };
 
-struct BrushLibBrush *paint_brushlib_new_brush()
+
+struct BrushLibBrush *paint_brushlib_new_brush(float x, float y)
 {
-	return reinterpret_cast<BrushLibBrush *>(new Brush());
+	Brush *brush= new Brush();
+
+	brush->set_base_value(BRUSH_OPAQUE, 1.0);
+	brush->set_base_value(BRUSH_OPAQUE_MULTIPLY, 0.0);
+	brush->set_mapping_n(BRUSH_OPAQUE_MULTIPLY, INPUT_PRESSURE, 4);
+	brush->set_mapping_point(BRUSH_OPAQUE_MULTIPLY, INPUT_PRESSURE, 0, 0.000000, 0.000000);
+	brush->set_mapping_point(BRUSH_OPAQUE_MULTIPLY, INPUT_PRESSURE, 1, 0.015000, 0.000000);
+	brush->set_mapping_point(BRUSH_OPAQUE_MULTIPLY, INPUT_PRESSURE, 2, 0.015000, 1.000000);
+	brush->set_mapping_point(BRUSH_OPAQUE_MULTIPLY, INPUT_PRESSURE, 3, 1.000000, 1.000000);
+	brush->set_base_value(BRUSH_OPAQUE_LINEARIZE, 0.0);
+	brush->set_base_value(BRUSH_RADIUS_LOGARITHMIC, 0.96);
+	brush->set_mapping_n(BRUSH_RADIUS_LOGARITHMIC, INPUT_PRESSURE, 2);
+	brush->set_mapping_point(BRUSH_RADIUS_LOGARITHMIC, INPUT_PRESSURE, 0, 0.000000, 0.000000);
+	brush->set_mapping_point(BRUSH_RADIUS_LOGARITHMIC, INPUT_PRESSURE, 1, 1.000000, 0.500000);
+	brush->set_mapping_n(BRUSH_RADIUS_LOGARITHMIC, INPUT_SPEED1, 2);
+	brush->set_mapping_point(BRUSH_RADIUS_LOGARITHMIC, INPUT_SPEED1, 0, 0.000000, -0.000000);
+	brush->set_mapping_point(BRUSH_RADIUS_LOGARITHMIC, INPUT_SPEED1, 1, 1.000000, -0.210000);
+	brush->set_base_value(BRUSH_HARDNESS, 0.5);
+	brush->set_mapping_n(BRUSH_HARDNESS, INPUT_PRESSURE, 2);
+	brush->set_mapping_point(BRUSH_HARDNESS, INPUT_PRESSURE, 0, 0.000000, 0.000000);
+	brush->set_mapping_point(BRUSH_HARDNESS, INPUT_PRESSURE, 1, 1.000000, 0.050000);
+	brush->set_mapping_n(BRUSH_HARDNESS, INPUT_SPEED1, 2);
+	brush->set_mapping_point(BRUSH_HARDNESS, INPUT_SPEED1, 0, 0.000000, -0.000000);
+	brush->set_mapping_point(BRUSH_HARDNESS, INPUT_SPEED1, 1, 1.000000, -0.090000);
+	brush->set_base_value(BRUSH_DABS_PER_BASIC_RADIUS, 0.0);
+	brush->set_base_value(BRUSH_DABS_PER_ACTUAL_RADIUS, 2.2);
+	brush->set_base_value(BRUSH_DABS_PER_SECOND, 0.0);
+	brush->set_base_value(BRUSH_RADIUS_BY_RANDOM, 0.0);
+	brush->set_base_value(BRUSH_SPEED1_SLOWNESS, 0.04);
+	brush->set_base_value(BRUSH_SPEED2_SLOWNESS, 0.8);
+	brush->set_base_value(BRUSH_SPEED1_GAMMA, 2.87);
+	brush->set_base_value(BRUSH_SPEED2_GAMMA, 4.0);
+	brush->set_base_value(BRUSH_OFFSET_BY_RANDOM, 0.0);
+	brush->set_base_value(BRUSH_OFFSET_BY_SPEED, 0.0);
+	brush->set_base_value(BRUSH_OFFSET_BY_SPEED_SLOWNESS, 1.0);
+	brush->set_base_value(BRUSH_SLOW_TRACKING, 0.65);
+	brush->set_base_value(BRUSH_SLOW_TRACKING_PER_DAB, 0.8);
+	brush->set_base_value(BRUSH_TRACKING_NOISE, 0.0);
+	brush->set_base_value(BRUSH_COLOR_H, 0.0);
+	brush->set_base_value(BRUSH_COLOR_S, 0.0);
+	brush->set_base_value(BRUSH_COLOR_V, 0.0);
+	brush->set_base_value(BRUSH_CHANGE_COLOR_H, 0.0);
+	brush->set_base_value(BRUSH_CHANGE_COLOR_L, 0.0);
+	brush->set_base_value(BRUSH_CHANGE_COLOR_HSL_S, 0.0);
+	brush->set_base_value(BRUSH_CHANGE_COLOR_V, 0.0);
+	brush->set_base_value(BRUSH_CHANGE_COLOR_HSV_S, 0.0);
+	brush->set_base_value(BRUSH_SMUDGE, 0.0);
+	brush->set_base_value(BRUSH_SMUDGE_LENGTH, 0.5);
+	brush->set_base_value(BRUSH_ERASER, 0.0);
+	brush->set_base_value(BRUSH_STROKE_THRESHOLD, 0.0);
+	brush->set_base_value(BRUSH_STROKE_DURATION_LOGARITHMIC, 4.0);
+	brush->set_base_value(BRUSH_STROKE_HOLDTIME, 0.0);
+	brush->set_base_value(BRUSH_CUSTOM_INPUT, 0.0);
+	brush->set_base_value(BRUSH_CUSTOM_INPUT_SLOWNESS, 0.0);
+	brush->set_base_value(BRUSH_ELLIPTICAL_DAB_RATIO, 1.0);
+	brush->set_base_value(BRUSH_ELLIPTICAL_DAB_ANGLE, 90.0);
+	brush->set_base_value(BRUSH_DIRECTION_FILTER, 2.0);
+
+	brush->set_state(STATE_X, x);
+	brush->set_state(STATE_Y, y);
+
+	return reinterpret_cast<BrushLibBrush *>(brush);
 }
 
+void paint_brushlib_set_radius(
+	struct BrushLibBrush *brushlib_brush,
+	float radius2d)
+{
+	Brush* brush= reinterpret_cast<Brush *>(brushlib_brush);
+	brush->set_base_value(BRUSH_RADIUS_LOGARITHMIC, logf(radius2d));
+}
+
 void paint_brushlib_free_brush(struct BrushLibBrush *brush)
 {
 	delete reinterpret_cast<Brush *>(brush);
 }
 
-int paint_brushlib_stroke_to(
+int paint_brushlib_brush_stroke_to(
+	const struct bContext *C,
+	struct PaintStroke *stroke,
 	struct BrushLibBrush *brushlib_brush,
 	struct BrushLibSurface *brushlib_surface,
 	float x,
@@ -365,8 +438,10 @@
 	float dtime)
 {
 	Brush   *brush=   reinterpret_cast<Brush *>   (brushlib_brush);
-	Surface *surface= reinterpret_cast<Surface *> (brushlib_surface);
+	BlenderSurface *surface= reinterpret_cast<BlenderSurface *> (brushlib_surface);
 
+	surface->set_context(C, stroke);
+
 	return brush->stroke_to(surface, x, y, pressure, xtilt, ytilt, dtime);
 }
 
@@ -385,13 +460,77 @@
 	return reinterpret_cast<BrushLibSurface *>(new ImaPaintSurface());
 }
 
-void brushlib_surface_set_context(
-	struct BrushLibSurface *brushlib_surface,
-	bContext *C,
-	struct PaintStroke *stroke)
+
+/* these are defined here as stubs until later */
+
+int sculpt_draw_dab(
+	struct bContext *C,
+	struct PaintStroke *stroke,
+	float x,
+	float y, 
+	float radius, 
+	float color_r,
+	float color_g,
+	float color_b,
+	float opaque,
+	float hardness,
+	float alpha_eraser,
+	float aspect_ratio,
+	float angle,
+	float lock_alpha)
 {
-	BlenderSurface *blender_surface=
-		reinterpret_cast<BlenderSurface *>(brushlib_surface);
+	return 0;
+}
 
-	blender_surface->set_context(C, stroke);
+void sculpt_get_color(
+	struct bContext *C,
+	struct PaintStroke *stroke,
+	float x,
+	float y, 
+	float radius, 
+	float * color_r,
+	float * color_g,
+	float * color_b,
+	float * color_a)
+{
+	*color_r= 0;
+	*color_g= 0;
+	*color_b= 0;
+	*color_a= 0;
 }
+
+int imapaint_draw_dab(
+	struct bContext *C,
+	struct PaintStroke *stroke,
+	float x,
+	float y, 
+	float radius, 
+	float color_r,
+	float color_g,
+	float color_b,
+	float opaque,
+	float hardness,
+	float alpha_eraser,
+	float aspect_ratio,
+	float angle,
+	float lock_alpha)
+{
+	return 0;
+}
+
+void imapaint_get_color(
+	struct bContext *C,
+	struct PaintStroke *stroke,
+	float x,
+	float y, 
+	float radius, 
+	float * color_r,
+	float * color_g,
+	float * color_b,
+	float * color_a)
+{
+	*color_r= 0;
+	*color_g= 0;
+	*color_b= 0;
+	*color_a= 0;
+}

Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_brushlib.h
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_brushlib.h	2011-08-02 07:08:22 UTC (rev 38916)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_brushlib.h	2011-08-02 07:17:15 UTC (rev 38917)
@@ -34,6 +34,8 @@
  *  \ingroup edsculpt
  */
 
+#if WITH_BRUSHLIB
+
 #ifndef PAINT_BRUSHLIB_H
 #define PAINT_BRUSHLIB_H
 
@@ -125,11 +127,13 @@
 /* BrushLibBrush and BrushLibSurface are opaque handles
    There is no struct definition */
 
-struct BrushLibBrush *paint_brushlib_new_brush(void);
-
+struct BrushLibBrush *paint_brushlib_new_brush(float x, float y);
+void paint_brushlib_set_radius(struct BrushLibBrush *brush, float radius2d);
 void paint_brushlib_free_brush(struct BrushLibBrush *brush);
 
-int paint_brushlib_stroke_to(
+int paint_brushlib_brush_stroke_to(
+	const struct bContext *C,
+	struct PaintStroke *stroke,
 	struct BrushLibBrush *brushlib_brush,
 	struct BrushLibSurface *brushlib_surface,
 	float x,
@@ -145,13 +149,10 @@
 
 struct BrushLibSurface *imapaint_brushlib_surface_new(void);
 
-void paint_brushlib_surface_set_context(
-	struct BrushLibSurface *brushlib_surface,
-	bContext *C,
-	struct PaintStroke *stroke);
-
 #ifdef __cplusplus
 }
 #endif
 
-#endif
+#endif // PAINT_BRUSHLIB_H
+
+#endif // WITH_BRUSHLIB

Modified: branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_bspace.c
===================================================================
--- branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_bspace.c	2011-08-02 07:08:22 UTC (rev 38916)
+++ branches/soc-2011-onion/source/blender/editors/sculpt_paint/paint_bspace.c	2011-08-02 07:17:15 UTC (rev 38917)
@@ -306,14 +306,16 @@
 	const struct bContext *C,
 	struct BrushSpace *out,
 	const struct PaintStroke *stroke,
-	StrokeGetLocation get_location)
+	StrokeGetLocation get_location,
+	const float mouse[2],
+	float radius2d)
 {
 	struct Object *ob= CTX_data_active_object(C);
 	struct Paint *paint= paint_get_active(CTX_data_scene(C));
 	struct Brush *brush= paint_brush(paint);
 
 	/* mouse */
-	copy_v2_v2(out->mouse, paint_stroke_mouse(stroke));
+	copy_v2_v2(out->mouse, mouse);
 
 	/* location */

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list