[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30707] branches/soc-2010-nicolasbishop: = = VPaint ==
Nicholas Bishop
nicholasbishop at gmail.com
Sun Jul 25 07:01:58 CEST 2010
Revision: 30707
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30707
Author: nicholasbishop
Date: 2010-07-25 07:01:55 +0200 (Sun, 25 Jul 2010)
Log Message:
-----------
== VPaint ==
Enabled textures for vpaint brushes. Not all of the texture options work yet.
Modified Paths:
--------------
branches/soc-2010-nicolasbishop/release/scripts/ui/space_view3d_toolbar.py
branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h
branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_stroke.c
branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_utils.c
branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c
branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/sculpt.c
Modified: branches/soc-2010-nicolasbishop/release/scripts/ui/space_view3d_toolbar.py
===================================================================
--- branches/soc-2010-nicolasbishop/release/scripts/ui/space_view3d_toolbar.py 2010-07-25 02:56:39 UTC (rev 30706)
+++ branches/soc-2010-nicolasbishop/release/scripts/ui/space_view3d_toolbar.py 2010-07-25 05:01:55 UTC (rev 30707)
@@ -795,6 +795,7 @@
def poll(self, context):
settings = self.paint_settings(context)
return (settings and settings.brush and (context.sculpt_object or
+ context.vertex_paint_object or
context.texture_paint_object))
def draw(self, context):
@@ -808,7 +809,7 @@
col.template_ID_preview(brush, "texture", new="texture.new", rows=3, cols=8)
- if context.sculpt_object:
+ if context.sculpt_object or context.vertex_paint_object:
#XXX duplicated from properties_texture.py
wide_ui = context.region.width > narrowui
Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h 2010-07-25 02:56:39 UTC (rev 30706)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_intern.h 2010-07-25 05:01:55 UTC (rev 30707)
@@ -32,6 +32,7 @@
#include "BLI_pbvh.h"
struct bContext;
+struct Brush;
struct Scene;
struct Object;
struct Mesh;
@@ -61,6 +62,7 @@
int paint_stroke_modal(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
int paint_stroke_exec(struct bContext *C, struct wmOperator *op);
struct ViewContext *paint_stroke_view_context(struct PaintStroke *stroke);
+void paint_stroke_projection_mat(struct PaintStroke *stroke, float (**pmat)[4]);
void *paint_stroke_mode_data(struct PaintStroke *stroke);
void paint_stroke_set_mode_data(struct PaintStroke *stroke, void *mode_data);
@@ -136,6 +138,12 @@
struct MultiresModifierData *paint_multires_active(struct Scene *scene, struct Object *ob);
+float brush_tex_strength(struct ViewContext *vc,
+ float pmat[4][4], struct Brush *br,
+ float co[3], float mask, const float len,
+ float pixel_radius, float radius3d,
+ float special_rotation, float tex_mouse[2]);
+
/* stroke operator */
typedef enum wmBrushStrokeMode {
WM_BRUSHSTROKE_NORMAL,
Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_stroke.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_stroke.c 2010-07-25 02:56:39 UTC (rev 30706)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_stroke.c 2010-07-25 05:01:55 UTC (rev 30707)
@@ -64,6 +64,7 @@
/* Cached values */
ViewContext vc;
+ float project_mat[4][4];
bglMats mats;
Brush *brush;
@@ -805,6 +806,7 @@
PaintStroke *stroke = op->customdata;
view3d_set_viewcontext(C, &vc); // XXX
+ view3d_get_object_project_mat(vc.rv3d, vc.obact, stroke->project_mat);
/* Tablet */
if(event->custom == EVT_DATA_TABLET) {
@@ -1045,6 +1047,11 @@
return &stroke->vc;
}
+void paint_stroke_projection_mat(PaintStroke *stroke, float (**pmat)[4])
+{
+ *pmat = &stroke->project_mat;
+}
+
void *paint_stroke_mode_data(struct PaintStroke *stroke)
{
return stroke->mode_data;
Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_utils.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_utils.c 2010-07-25 02:56:39 UTC (rev 30706)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_utils.c 2010-07-25 05:01:55 UTC (rev 30707)
@@ -36,6 +36,9 @@
#include "WM_api.h"
#include "WM_types.h"
+#include "RE_render_ext.h"
+#include "RE_shader_ext.h"
+
#include "paint_intern.h"
/* 3D Paint */
@@ -453,3 +456,115 @@
if(pbvh)
BLI_pbvh_update(pbvh, PBVH_UpdateRedraw, NULL);
}
+
+float get_tex_pixel(Brush* br, float u, float v)
+{
+ TexResult texres;
+ float co[3];
+ int hasrgb;
+
+ co[0] = u;
+ co[1] = v;
+ co[2] = 0;
+
+ memset(&texres, 0, sizeof(TexResult));
+ hasrgb = multitex_ext(br->mtex.tex, co, NULL, NULL, 1, &texres);
+
+ if (hasrgb & TEX_RGB)
+ texres.tin = (0.35*texres.tr + 0.45*texres.tg + 0.2*texres.tb)*texres.ta;
+
+ return texres.tin;
+}
+
+/* return a multiplier for brush strength at a coordinate,
+ incorporating texture, curve control, and masking
+
+ TODO: pulled almost directly from sculpt, still needs
+ to be prettied up
+*/
+float brush_tex_strength(ViewContext *vc,
+ float pmat[4][4], Brush *br,
+ float co[3], float mask, const float len,
+ float pixel_radius, float radius3d,
+ float special_rotation, float tex_mouse[2])
+{
+ MTex *mtex = &br->mtex;
+ float avg= 1;
+
+ if(!mtex->tex) {
+ avg= 1;
+ }
+ else if(mtex->brush_map_mode == MTEX_MAP_MODE_3D) {
+ float jnk;
+
+ /* Get strength by feeding the vertex
+ location directly into a texture */
+ externtex(mtex, co, &avg,
+ &jnk, &jnk, &jnk, &jnk);
+ }
+ else {
+ float rotation = -mtex->rot;
+ float x, y, point_2d[3];
+ float radius;
+
+ view3d_project_float(vc->ar, co, point_2d, pmat);
+
+ /* if fixed mode, keep coordinates relative to mouse */
+ if(mtex->brush_map_mode == MTEX_MAP_MODE_FIXED) {
+ rotation += special_rotation;
+
+ point_2d[0] -= tex_mouse[0];
+ point_2d[1] -= tex_mouse[1];
+
+ radius = pixel_radius; // use pressure adjusted size for fixed mode
+
+ x = point_2d[0];
+ y = point_2d[1];
+ }
+ else /* else (mtex->brush_map_mode == MTEX_MAP_MODE_TILED),
+ leave the coordinates relative to the screen */
+ {
+ radius = brush_size(br); // use unadjusted size for tiled mode
+
+ x = point_2d[0] - vc->ar->winrct.xmin;
+ y = point_2d[1] - vc->ar->winrct.ymin;
+ }
+
+ x /= vc->ar->winx;
+ y /= vc->ar->winy;
+
+ if (mtex->brush_map_mode == MTEX_MAP_MODE_TILED) {
+ x -= 0.5f;
+ y -= 0.5f;
+ }
+
+ x *= vc->ar->winx / radius;
+ y *= vc->ar->winy / radius;
+
+ /* it is probably worth optimizing for those cases where
+ the texture is not rotated by skipping the calls to
+ atan2, sqrtf, sin, and cos. */
+ if (rotation > 0.001 || rotation < -0.001) {
+ const float angle = atan2(y, x) + rotation;
+ const float flen = sqrtf(x*x + y*y);
+
+ x = flen * cos(angle);
+ y = flen * sin(angle);
+ }
+
+ x *= br->mtex.size[0];
+ y *= br->mtex.size[1];
+
+ x += br->mtex.ofs[0];
+ y += br->mtex.ofs[1];
+
+ avg = get_tex_pixel(br, x, y);
+ }
+
+ avg += br->texture_sample_bias;
+
+ avg *= brush_curve_strength(br, len, radius3d); /* Falloff curve */
+ avg*= 1 - mask;
+
+ return avg;
+}
Modified: branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c
===================================================================
--- branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c 2010-07-25 02:56:39 UTC (rev 30706)
+++ branches/soc-2010-nicolasbishop/source/blender/editors/sculpt_paint/paint_vertex.c 2010-07-25 05:01:55 UTC (rev 30707)
@@ -1688,10 +1688,25 @@
}
}
+static float tex_strength(Brush *brush, PaintStroke *stroke,
+ float co[3], float mask, float len,
+ float radius3d)
+{
+ ViewContext *vc = paint_stroke_view_context(stroke);
+ float (*pmat)[4];
+ float tex_mouse[2] = {0,0}; /* TODO */
+
+ paint_stroke_projection_mat(stroke, &pmat);
+
+ return brush_tex_strength(vc, pmat, brush, co, 0, len,
+ brush->size, radius3d, 0,
+ tex_mouse);
+}
+
/* apply paint at specified coordinate
returns 1 if paint was applied, 0 otherwise */
-static int vpaint_paint_coord(VPaint *vp, VPaintData *vpd, float co[3],
- float col[4], float orig_col[4],
+static int vpaint_paint_coord(VPaint *vp, PaintStroke *stroke,
+ float co[3], float col[4],
float center[3], float radius,
float radius_squared)
{
@@ -1704,8 +1719,7 @@
dist = sqrtf(dist_squared);
strength = brush->alpha *
- brush_curve_strength(brush, dist,
- radius);
+ tex_strength(brush, stroke, co, 0, dist, radius);
vpaint_blend(brush, col, strength);
@@ -1715,8 +1729,9 @@
return 0;
}
-static void vpaint_nodes_grids(VPaint *vp, VPaintData *vpd, DMGridData **grids,
- GridKey *gridkey, int *grid_indices, int totgrid,
+static void vpaint_nodes_grids(VPaint *vp, PaintStroke *stroke,
+ DMGridData **grids, GridKey *gridkey,
+ int *grid_indices, int totgrid,
int gridsize, int active, float center[3],
float radius)
{
@@ -1734,9 +1749,8 @@
float *co = GRIDELEM_CO(elem, gridkey);
float *gridcol = GRIDELEM_COLOR(elem, gridkey)[active];
- vpaint_paint_coord(vp, vpd, co,
+ vpaint_paint_coord(vp, stroke, co,
gridcol,
- NULL, /* TODO */
center, radius,
radius_squared);
}
@@ -1744,7 +1758,7 @@
}
}
-static void vpaint_nodes_faces(VPaint *vp, VPaintData *vpd, MFace *mface,
+static void vpaint_nodes_faces(VPaint *vp, PaintStroke *stroke, MFace *mface,
MVert *mvert, CustomData *fdata,
int *face_indices, int totface, float center[3],
float radius)
@@ -1775,7 +1789,7 @@
fcol[2] = mcol[cndx].r / 255.0f;
fcol[3] = mcol[cndx].a / 255.0f;
- vpaint_paint_coord(vp, vpd, co, fcol, NULL /* TODO */, center,
+ vpaint_paint_coord(vp, stroke, co, fcol, center,
radius, radius_squared);
mcol[cndx].b = fcol[0] * 255.0f;
@@ -1804,7 +1818,8 @@
return -1;
}
-static void vpaint_nodes(VPaint *vp, VPaintData *vpd, PBVH *pbvh,
+static void vpaint_nodes(VPaint *vp, PaintStroke *stroke,
+ PBVH *pbvh,
PBVHNode **nodes, int totnode,
float center[3], float radius)
{
@@ -1834,14 +1849,14 @@
gridkey);
if(active != -1) {
- vpaint_nodes_grids(vp, vpd, grids, gridkey,
+ vpaint_nodes_grids(vp, stroke, grids, gridkey,
grid_indices, totgrid,
gridsize, active, center,
radius);
}
}
else {
- vpaint_nodes_faces(vp, vpd, mface, mvert, fdata,
+ vpaint_nodes_faces(vp, stroke, mface, mvert, fdata,
face_indices, totface, center,
radius);
}
@@ -1977,7 +1992,6 @@
PointerRNA *itemptr)
{
VPaint *vp= CTX_data_tool_settings(C)->vpaint;
- VPaintData *vpd = paint_stroke_mode_data(stroke);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list