style cleanup: mainly whitespace around operators and indentation - paint/sculpt tools

This commit is contained in:
Campbell Barton 2012-03-28 03:47:33 +00:00
parent 274e243a67
commit c9f677d24d
11 changed files with 1982 additions and 1978 deletions

@ -76,26 +76,26 @@ typedef struct Snapshot {
int curve_changed_timestamp;
} Snapshot;
static int same_snap(Snapshot* snap, Brush* brush, ViewContext* vc)
static int same_snap(Snapshot *snap, Brush *brush, ViewContext *vc)
{
MTex* mtex = &brush->mtex;
MTex *mtex = &brush->mtex;
return (((mtex->tex) &&
equals_v3v3(mtex->ofs, snap->ofs) &&
equals_v3v3(mtex->size, snap->size) &&
mtex->rot == snap->rot) &&
equals_v3v3(mtex->ofs, snap->ofs) &&
equals_v3v3(mtex->size, snap->size) &&
mtex->rot == snap->rot) &&
/* make brush smaller shouldn't cause a resample */
((mtex->brush_map_mode == MTEX_MAP_MODE_FIXED &&
(brush_size(vc->scene, brush) <= snap->brush_size)) ||
(brush_size(vc->scene, brush) == snap->brush_size)) &&
/* make brush smaller shouldn't cause a resample */
((mtex->brush_map_mode == MTEX_MAP_MODE_FIXED &&
(brush_size(vc->scene, brush) <= snap->brush_size)) ||
(brush_size(vc->scene, brush) == snap->brush_size)) &&
(mtex->brush_map_mode == snap->brush_map_mode) &&
(vc->ar->winx == snap->winx) &&
(vc->ar->winy == snap->winy));
(mtex->brush_map_mode == snap->brush_map_mode) &&
(vc->ar->winx == snap->winx) &&
(vc->ar->winy == snap->winy));
}
static void make_snap(Snapshot* snap, Brush* brush, ViewContext* vc)
static void make_snap(Snapshot *snap, Brush *brush, ViewContext *vc)
{
if (brush->mtex.tex) {
snap->brush_map_mode = brush->mtex.brush_map_mode;
@ -105,8 +105,8 @@ static void make_snap(Snapshot* snap, Brush* brush, ViewContext* vc)
}
else {
snap->brush_map_mode = -1;
snap->ofs[0]= snap->ofs[1]= snap->ofs[2]= -1;
snap->size[0]= snap->size[1]= snap->size[2]= -1;
snap->ofs[0] = snap->ofs[1] = snap->ofs[2] = -1;
snap->size[0] = snap->size[1] = snap->size[2] = -1;
snap->rot = -1;
}
@ -115,7 +115,7 @@ static void make_snap(Snapshot* snap, Brush* brush, ViewContext* vc)
snap->winy = vc->ar->winy;
}
static int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
static int load_tex(Sculpt *sd, Brush *br, ViewContext *vc)
{
static GLuint overlay_texture = 0;
static int init = 0;
@ -124,7 +124,7 @@ static int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
static Snapshot snap;
static int old_size = -1;
GLubyte* buffer = NULL;
GLubyte *buffer = NULL;
int size;
int j;
@ -137,13 +137,13 @@ static int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
if (br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED && !br->mtex.tex) return 0;
refresh =
!overlay_texture ||
(br->mtex.tex &&
(!br->mtex.tex->preview ||
br->mtex.tex->preview->changed_timestamp[0] != tex_changed_timestamp)) ||
!br->curve ||
br->curve->changed_timestamp != curve_changed_timestamp ||
!same_snap(&snap, br, vc);
!overlay_texture ||
(br->mtex.tex &&
(!br->mtex.tex->preview ||
br->mtex.tex->preview->changed_timestamp[0] != tex_changed_timestamp)) ||
!br->curve ||
br->curve->changed_timestamp != curve_changed_timestamp ||
!same_snap(&snap, br, vc);
if (refresh) {
if (br->mtex.tex && br->mtex.tex->preview)
@ -161,7 +161,7 @@ static int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
for (s >>= 1; s > 0; s >>= 1)
r++;
size = (1<<r);
size = (1 << r);
if (size < 256)
size = 256;
@ -183,26 +183,26 @@ static int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
old_size = size;
}
buffer = MEM_mallocN(sizeof(GLubyte)*size*size, "load_tex");
buffer = MEM_mallocN(sizeof(GLubyte) * size * size, "load_tex");
#pragma omp parallel for schedule(static) if (sd->flags & SCULPT_USE_OPENMP)
for (j= 0; j < size; j++) {
for (j = 0; j < size; j++) {
int i;
float y;
float len;
for (i= 0; i < size; i++) {
for (i = 0; i < size; i++) {
// largely duplicated from tex_strength
const float rotation = -br->mtex.rot;
float radius = brush_size(vc->scene, br);
int index = j*size + i;
int index = j * size + i;
float x;
float avg;
x = (float)i/size;
y = (float)j/size;
x = (float)i / size;
y = (float)j / size;
x -= 0.5f;
y -= 0.5f;
@ -216,7 +216,7 @@ static int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
y *= 2;
}
len = sqrtf(x*x + y*y);
len = sqrtf(x * x + y * y);
if ((br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED) || len <= 1) {
/* it is probably worth optimizing for those cases where
@ -240,9 +240,9 @@ static int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
avg += br->texture_sample_bias;
if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED)
avg *= brush_curve_strength(br, len, 1); /* Falloff curve */
avg *= brush_curve_strength(br, len, 1); /* Falloff curve */
buffer[index] = 255 - (GLubyte)(255*avg);
buffer[index] = 255 - (GLubyte)(255 * avg);
}
else {
buffer[index] = 0;
@ -254,7 +254,7 @@ static int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
glGenTextures(1, &overlay_texture);
}
else {
size= old_size;
size = old_size;
}
glBindTexture(GL_TEXTURE_2D, overlay_texture);
@ -287,8 +287,8 @@ static int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
}
static int project_brush_radius(ViewContext *vc,
float radius,
const float location[3])
float radius,
const float location[3])
{
float view[3], nonortho[3], ortho[3], offset[3], p1[2], p2[2];
@ -328,9 +328,9 @@ static int project_brush_radius(ViewContext *vc,
return len_v2v2(p1, p2);
}
static int sculpt_get_brush_geometry(bContext* C, ViewContext *vc,
int x, int y, int* pixel_radius,
float location[3])
static int sculpt_get_brush_geometry(bContext *C, ViewContext *vc,
int x, int y, int *pixel_radius,
float location[3])
{
Scene *scene = CTX_data_scene(C);
Paint *paint = paint_get_active(scene);
@ -342,11 +342,11 @@ static int sculpt_get_brush_geometry(bContext* C, ViewContext *vc,
window[1] = y + vc->ar->winrct.ymin;
if (vc->obact->sculpt && vc->obact->sculpt->pbvh &&
sculpt_stroke_get_location(C, location, window)) {
sculpt_stroke_get_location(C, location, window)) {
*pixel_radius =
project_brush_radius(vc,
brush_unprojected_radius(scene, brush),
location);
project_brush_radius(vc,
brush_unprojected_radius(scene, brush),
location);
if (*pixel_radius == 0)
*pixel_radius = brush_size(scene, brush);
@ -356,8 +356,8 @@ static int sculpt_get_brush_geometry(bContext* C, ViewContext *vc,
hit = 1;
}
else {
Sculpt* sd = CTX_data_tool_settings(C)->sculpt;
Brush* brush = paint_brush(&sd->paint);
Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
Brush *brush = paint_brush(&sd->paint);
*pixel_radius = brush_size(scene, brush);
hit = 0;
@ -370,26 +370,26 @@ static int sculpt_get_brush_geometry(bContext* C, ViewContext *vc,
* have on brush strength */
/* TODO: sculpt only for now */
static void paint_draw_alpha_overlay(Sculpt *sd, Brush *brush,
ViewContext *vc, int x, int y)
ViewContext *vc, int x, int y)
{
rctf quad;
/* check for overlay mode */
if (!(brush->flag & BRUSH_TEXTURE_OVERLAY) ||
!(ELEM(brush->mtex.brush_map_mode, MTEX_MAP_MODE_FIXED, MTEX_MAP_MODE_TILED)))
!(ELEM(brush->mtex.brush_map_mode, MTEX_MAP_MODE_FIXED, MTEX_MAP_MODE_TILED)))
return;
/* save lots of GL state
* TODO: check on whether all of these are needed? */
glPushAttrib(GL_COLOR_BUFFER_BIT|
GL_CURRENT_BIT|
GL_DEPTH_BUFFER_BIT|
GL_ENABLE_BIT|
GL_LINE_BIT|
GL_POLYGON_BIT|
GL_STENCIL_BUFFER_BIT|
GL_TRANSFORM_BIT|
GL_VIEWPORT_BIT|
glPushAttrib(GL_COLOR_BUFFER_BIT |
GL_CURRENT_BIT |
GL_DEPTH_BUFFER_BIT |
GL_ENABLE_BIT |
GL_LINE_BIT |
GL_POLYGON_BIT |
GL_STENCIL_BUFFER_BIT |
GL_TRANSFORM_BIT |
GL_VIEWPORT_BIT |
GL_TEXTURE_BIT);
if (load_tex(sd, brush, vc)) {
@ -408,26 +408,26 @@ static void paint_draw_alpha_overlay(Sculpt *sd, Brush *brush,
glTranslatef(0.5, 0.5, 0);
glRotatef((double)RAD2DEGF((brush->flag & BRUSH_RAKE) ?
sd->last_angle : sd->special_rotation),
0.0, 0.0, 1.0);
0.0, 0.0, 1.0);
glTranslatef(-0.5f, -0.5f, 0);
/* scale based on tablet pressure */
if (sd->draw_pressure && brush_use_size_pressure(vc->scene, brush)) {
glTranslatef(0.5f, 0.5f, 0);
glScalef(1.0f/sd->pressure_value, 1.0f/sd->pressure_value, 1);
glScalef(1.0f / sd->pressure_value, 1.0f / sd->pressure_value, 1);
glTranslatef(-0.5f, -0.5f, 0);
}
if (sd->draw_anchored) {
const float *aim = sd->anchored_initial_mouse;
const rcti *win = &vc->ar->winrct;
quad.xmin = aim[0]-sd->anchored_size - win->xmin;
quad.ymin = aim[1]-sd->anchored_size - win->ymin;
quad.xmax = aim[0]+sd->anchored_size - win->xmin;
quad.ymax = aim[1]+sd->anchored_size - win->ymin;
quad.xmin = aim[0] - sd->anchored_size - win->xmin;
quad.ymin = aim[1] - sd->anchored_size - win->ymin;
quad.xmax = aim[0] + sd->anchored_size - win->xmin;
quad.ymax = aim[1] + sd->anchored_size - win->ymin;
}
else {
const int radius= brush_size(vc->scene, brush);
const int radius = brush_size(vc->scene, brush);
quad.xmin = x - radius;
quad.ymin = y - radius;
quad.xmax = x + radius;
@ -468,7 +468,7 @@ static void paint_draw_alpha_overlay(Sculpt *sd, Brush *brush,
/* Special actions taken when paint cursor goes over mesh */
/* TODO: sculpt only for now */
static void paint_cursor_on_hit(Sculpt *sd, Brush *brush, ViewContext *vc,
const float location[3])
const float location[3])
{
float unprojected_radius, projected_radius;
@ -486,7 +486,7 @@ static void paint_cursor_on_hit(Sculpt *sd, Brush *brush, ViewContext *vc,
/* convert brush radius from 2D to 3D */
unprojected_radius = paint_calc_object_space_radius(vc, location,
projected_radius);
projected_radius);
/* scale 3D brush radius by pressure */
if (sd->draw_pressure && brush_use_size_pressure(vc->scene, brush))
@ -541,11 +541,11 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
const float dx = sd->last_x - x;
const float dy = sd->last_y - y;
if (dx*dx + dy*dy >= r*r) {
if (dx * dx + dy * dy >= r * r) {
sd->last_angle = atan2(dx, dy);
sd->last_x = u*sd->last_x + v*x;
sd->last_y = u*sd->last_y + v*y;
sd->last_x = u * sd->last_x + v * x;
sd->last_y = u * sd->last_y + v * y;
}
}
@ -562,10 +562,10 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
/* TODO: no way currently to know state of pen flip or
* invert key modifier without starting a stroke */
if ((!(brush->flag & BRUSH_INVERTED) ^
!(brush->flag & BRUSH_DIR_IN)) &&
ELEM5(brush->sculpt_tool, SCULPT_TOOL_DRAW,
SCULPT_TOOL_INFLATE, SCULPT_TOOL_CLAY,
SCULPT_TOOL_PINCH, SCULPT_TOOL_CREASE))
!(brush->flag & BRUSH_DIR_IN)) &&
ELEM5(brush->sculpt_tool, SCULPT_TOOL_DRAW,
SCULPT_TOOL_INFLATE, SCULPT_TOOL_CLAY,
SCULPT_TOOL_PINCH, SCULPT_TOOL_CREASE))
outline_col = brush->sub_col;
/* only do if brush is over the mesh */
@ -588,7 +588,7 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
/* draw brush outline */
glTranslatef(translation[0], translation[1], 0);
glutil_draw_lined_arc(0.0, M_PI*2.0, final_radius, 40);
glutil_draw_lined_arc(0.0, M_PI * 2.0, final_radius, 40);
glTranslatef(-translation[0], -translation[1], 0);
/* restore GL state */

@ -84,24 +84,24 @@ static int planes_contain_v3(float (*planes)[4], int totplane, const float p[3])
/* return true if the element should be hidden/shown */
static int is_effected(PartialVisArea area,
float planes[4][4],
const float co[3])
float planes[4][4],
const float co[3])
{
if (area == PARTIALVIS_ALL)
return 1;
else {
int inside = planes_contain_v3(planes, 4, co);
return ((inside && area == PARTIALVIS_INSIDE) ||
(!inside && area == PARTIALVIS_OUTSIDE));
(!inside && area == PARTIALVIS_OUTSIDE));
}
}
static void partialvis_update_mesh(Object *ob,
PBVH *pbvh,
PBVHNode *node,
PartialVisAction action,
PartialVisArea area,
float planes[4][4])
PBVH *pbvh,
PBVHNode *node,
PartialVisAction action,
PartialVisArea area,
float planes[4][4])
{
MVert *mvert;
int *vert_indices;
@ -137,11 +137,11 @@ static void partialvis_update_mesh(Object *ob,
/* Hide or show elements in multires grids with a special GridFlags
customdata layer. */
static void partialvis_update_grids(Object *ob,
PBVH *pbvh,
PBVHNode *node,
PartialVisAction action,
PartialVisArea area,
float planes[4][4])
PBVH *pbvh,
PBVHNode *node,
PartialVisAction action,
PartialVisArea area,
float planes[4][4])
{
DMGridData **grids;
BLI_bitmap *grid_hidden;
@ -150,8 +150,8 @@ static void partialvis_update_grids(Object *ob,
/* get PBVH data */
BLI_pbvh_node_get_grids(pbvh, node,
&grid_indices, &totgrid, NULL, &gridsize,
&grids, NULL);
&grid_indices, &totgrid, NULL, &gridsize,
&grids, NULL);
grid_hidden = BLI_pbvh_grid_hidden(pbvh);
sculpt_undo_push_node(ob, node, SCULPT_UNDO_HIDDEN);
@ -163,15 +163,15 @@ static void partialvis_update_grids(Object *ob,
BLI_bitmap gh = grid_hidden[g];
if (!gh) {
switch(action) {
case PARTIALVIS_HIDE:
/* create grid flags data */
gh = grid_hidden[g] = BLI_BITMAP_NEW(gridsize * gridsize,
"partialvis_update_grids");
break;
case PARTIALVIS_SHOW:
/* entire grid is visible, nothing to show */
continue;
switch (action) {
case PARTIALVIS_HIDE:
/* create grid flags data */
gh = grid_hidden[g] = BLI_BITMAP_NEW(gridsize * gridsize,
"partialvis_update_grids");
break;
case PARTIALVIS_SHOW:
/* entire grid is visible, nothing to show */
continue;
}
}
else if (action == PARTIALVIS_SHOW && area == PARTIALVIS_ALL) {
@ -192,7 +192,7 @@ static void partialvis_update_grids(Object *ob,
if (is_effected(area, planes, co)) {
/* set or clear the hide flag */
BLI_BITMAP_MODIFY(gh, y * gridsize + x,
action == PARTIALVIS_HIDE);
action == PARTIALVIS_HIDE);
any_changed = 1;
}
@ -230,12 +230,12 @@ static void rect_from_props(rcti *rect, PointerRNA *ptr)
}
static void clip_planes_from_rect(bContext *C,
float clip_planes[4][4],
const rcti *rect)
float clip_planes[4][4],
const rcti *rect)
{
ViewContext vc;
BoundBox bb;
bglMats mats= {{0}};
bglMats mats = {{0}};
view3d_operator_needs_opengl(C);
view3d_set_viewcontext(C, &vc);
@ -249,23 +249,23 @@ static void clip_planes_from_rect(bContext *C,
that lie at least partially outside the volume. If showing all, get
all nodes. */
static void get_pbvh_nodes(PBVH *pbvh,
PBVHNode ***nodes,
int *totnode,
float clip_planes[4][4],
PartialVisArea mode)
PBVHNode ***nodes,
int *totnode,
float clip_planes[4][4],
PartialVisArea mode)
{
BLI_pbvh_SearchCallback cb;
/* select search callback */
switch(mode) {
case PARTIALVIS_INSIDE:
cb = BLI_pbvh_node_planes_contain_AABB;
break;
case PARTIALVIS_OUTSIDE:
cb = BLI_pbvh_node_planes_exclude_AABB;
break;
case PARTIALVIS_ALL:
cb = NULL;
switch (mode) {
case PARTIALVIS_INSIDE:
cb = BLI_pbvh_node_planes_contain_AABB;
break;
case PARTIALVIS_OUTSIDE:
cb = BLI_pbvh_node_planes_exclude_AABB;
break;
case PARTIALVIS_ALL:
cb = NULL;
}
BLI_pbvh_search_gather(pbvh, cb, clip_planes, nodes, totnode);
@ -301,23 +301,23 @@ static int hide_show_exec(bContext *C, wmOperator *op)
pbvh_type = BLI_pbvh_type(pbvh);
/* start undo */
switch(action) {
case PARTIALVIS_HIDE:
sculpt_undo_push_begin("Hide area");
break;
case PARTIALVIS_SHOW:
sculpt_undo_push_begin("Show area");
break;
switch (action) {
case PARTIALVIS_HIDE:
sculpt_undo_push_begin("Hide area");
break;
case PARTIALVIS_SHOW:
sculpt_undo_push_begin("Show area");
break;
}
for (i = 0; i < totnode; i++) {
switch(pbvh_type) {
case PBVH_FACES:
partialvis_update_mesh(ob, pbvh, nodes[i], action, area, clip_planes);
break;
case PBVH_GRIDS:
partialvis_update_grids(ob, pbvh, nodes[i], action, area, clip_planes);
break;
switch (pbvh_type) {
case PBVH_FACES:
partialvis_update_mesh(ob, pbvh, nodes[i], action, area, clip_planes);
break;
case PBVH_GRIDS:
partialvis_update_grids(ob, pbvh, nodes[i], action, area, clip_planes);
break;
}
}
@ -331,8 +331,8 @@ static int hide_show_exec(bContext *C, wmOperator *op)
sculpt but it looks wrong when entering editmode otherwise) */
if (pbvh_type == PBVH_FACES) {
mesh_flush_hidden_from_verts(me->mvert, me->mloop,
me->medge, me->totedge,
me->mpoly, me->totpoly);
me->medge, me->totedge,
me->mpoly, me->totpoly);
}
ED_region_tag_redraw(ar);
@ -381,9 +381,9 @@ void PAINT_OT_hide_show(struct wmOperatorType *ot)
/* rna */
RNA_def_enum(ot->srna, "action", action_items, PARTIALVIS_HIDE,
"Action", "Whether to hide or show vertices");
"Action", "Whether to hide or show vertices");
RNA_def_enum(ot->srna, "area", area_items, PARTIALVIS_INSIDE,
"Area", "Which vertices to hide or show");
"Area", "Which vertices to hide or show");
RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX);
RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX);

File diff suppressed because it is too large Load Diff

@ -83,23 +83,23 @@ static void BRUSH_OT_add(wmOperatorType *ot)
ot->exec = brush_add_exec;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
static int brush_scale_size_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
Paint *paint= paint_get_active(scene);
struct Brush *brush= paint_brush(paint);
Paint *paint = paint_get_active(scene);
struct Brush *brush = paint_brush(paint);
// Object *ob= CTX_data_active_object(C);
float scalar= RNA_float_get(op->ptr, "scalar");
float scalar = RNA_float_get(op->ptr, "scalar");
if (brush) {
// pixel radius
{
const int old_size= brush_size(scene, brush);
int size= (int)(scalar*old_size);
const int old_size = brush_size(scene, brush);
int size = (int)(scalar * old_size);
if (old_size == size) {
if (scalar > 1) {
@ -116,10 +116,10 @@ static int brush_scale_size_exec(bContext *C, wmOperator *op)
// unprojected radius
{
float unprojected_radius= scalar*brush_unprojected_radius(scene, brush);
float unprojected_radius = scalar * brush_unprojected_radius(scene, brush);
if (unprojected_radius < 0.001f) // XXX magic number
unprojected_radius= 0.001f;
unprojected_radius = 0.001f;
brush_set_unprojected_radius(scene, brush, unprojected_radius);
}
@ -139,7 +139,7 @@ static void BRUSH_OT_scale_size(wmOperatorType *ot)
ot->exec = brush_scale_size_exec;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
RNA_def_float(ot->srna, "scalar", 1, 0, 2, "Scalar", "Factor to scale brush size by", 0, 2);
}
@ -166,7 +166,7 @@ static void PAINT_OT_vertex_color_set(wmOperatorType *ot)
ot->poll = vertex_paint_mode_poll;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op))
@ -195,7 +195,7 @@ static void BRUSH_OT_reset(wmOperatorType *ot)
ot->exec = brush_reset_exec;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
static int brush_tool(const Brush *brush, size_t tool_offset)
@ -208,16 +208,17 @@ static Brush *brush_tool_cycle(Main *bmain, Brush *brush_orig, const int tool, c
{
struct Brush *brush;
if (!brush_orig && !(brush_orig= bmain->brush.first)) {
if (!brush_orig && !(brush_orig = bmain->brush.first)) {
return NULL;
}
/* get the next brush with the active tool */
for (brush= brush_orig->id.next ? brush_orig->id.next : bmain->brush.first;
brush != brush_orig;
brush= brush->id.next ? brush->id.next : bmain->brush.first) {
for (brush = brush_orig->id.next ? brush_orig->id.next : bmain->brush.first;
brush != brush_orig;
brush = brush->id.next ? brush->id.next : bmain->brush.first)
{
if ((brush->ob_mode & ob_mode) &&
(brush_tool(brush, tool_offset) == tool)) {
(brush_tool(brush, tool_offset) == tool)) {
return brush;
}
}
@ -227,13 +228,13 @@ static Brush *brush_tool_cycle(Main *bmain, Brush *brush_orig, const int tool, c
static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool, const size_t tool_offset, const int ob_mode)
{
struct Brush *brush, *brush_orig= paint_brush(paint);
struct Brush *brush, *brush_orig = paint_brush(paint);
brush= brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);
brush = brush_tool_cycle(bmain, brush_orig, tool, tool_offset, ob_mode);
if (brush) {
paint_brush_set(paint, brush);
WM_main_add_notifier(NC_BRUSH|NA_EDITED, brush);
WM_main_add_notifier(NC_BRUSH | NA_EDITED, brush);
return OPERATOR_FINISHED;
}
else {
@ -246,46 +247,46 @@ static int brush_generic_tool_set(Main *bmain, Paint *paint, const int tool, con
static int brush_select_exec(bContext *C, wmOperator *op)
{
Main *bmain= CTX_data_main(C);
ToolSettings *toolsettings= CTX_data_tool_settings(C);
Paint *paint= NULL;
int tool, paint_mode= RNA_enum_get(op->ptr, "paint_mode");
Main *bmain = CTX_data_main(C);
ToolSettings *toolsettings = CTX_data_tool_settings(C);
Paint *paint = NULL;
int tool, paint_mode = RNA_enum_get(op->ptr, "paint_mode");
size_t tool_offset;
if (paint_mode == OB_MODE_ACTIVE) {
/* select current paint mode */
paint_mode = CTX_data_active_object(C)->mode &
(OB_MODE_SCULPT|
OB_MODE_VERTEX_PAINT|
OB_MODE_WEIGHT_PAINT|
OB_MODE_TEXTURE_PAINT);
(OB_MODE_SCULPT |
OB_MODE_VERTEX_PAINT |
OB_MODE_WEIGHT_PAINT |
OB_MODE_TEXTURE_PAINT);
}
switch(paint_mode) {
case OB_MODE_SCULPT:
paint= &toolsettings->sculpt->paint;
tool_offset= offsetof(Brush, sculpt_tool);
tool= RNA_enum_get(op->ptr, "sculpt_tool");
break;
case OB_MODE_VERTEX_PAINT:
paint= &toolsettings->vpaint->paint;
tool_offset= offsetof(Brush, vertexpaint_tool);
tool= RNA_enum_get(op->ptr, "vertex_paint_tool");
break;
case OB_MODE_WEIGHT_PAINT:
paint= &toolsettings->wpaint->paint;
/* vertexpaint_tool is used for weight paint mode */
tool_offset= offsetof(Brush, vertexpaint_tool);
tool= RNA_enum_get(op->ptr, "weight_paint_tool");
break;
case OB_MODE_TEXTURE_PAINT:
paint= &toolsettings->imapaint.paint;
tool_offset= offsetof(Brush, imagepaint_tool);
tool= RNA_enum_get(op->ptr, "texture_paint_tool");
break;
default:
/* invalid paint mode */
return OPERATOR_CANCELLED;
switch (paint_mode) {
case OB_MODE_SCULPT:
paint = &toolsettings->sculpt->paint;
tool_offset = offsetof(Brush, sculpt_tool);
tool = RNA_enum_get(op->ptr, "sculpt_tool");
break;
case OB_MODE_VERTEX_PAINT:
paint = &toolsettings->vpaint->paint;
tool_offset = offsetof(Brush, vertexpaint_tool);
tool = RNA_enum_get(op->ptr, "vertex_paint_tool");
break;
case OB_MODE_WEIGHT_PAINT:
paint = &toolsettings->wpaint->paint;
/* vertexpaint_tool is used for weight paint mode */
tool_offset = offsetof(Brush, vertexpaint_tool);
tool = RNA_enum_get(op->ptr, "weight_paint_tool");
break;
case OB_MODE_TEXTURE_PAINT:
paint = &toolsettings->imapaint.paint;
tool_offset = offsetof(Brush, imagepaint_tool);
tool = RNA_enum_get(op->ptr, "texture_paint_tool");
break;
default:
/* invalid paint mode */
return OPERATOR_CANCELLED;
}
return brush_generic_tool_set(bmain, paint, tool, tool_offset, paint_mode);
@ -299,7 +300,8 @@ static void PAINT_OT_brush_select(wmOperatorType *ot)
{OB_MODE_VERTEX_PAINT, "VERTEX_PAINT", ICON_VPAINT_HLT, "Vertex Paint", ""},
{OB_MODE_WEIGHT_PAINT, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""},
{OB_MODE_TEXTURE_PAINT, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""},
{0, NULL, 0, NULL, NULL}};
{0, NULL, 0, NULL, NULL}
};
/* identifiers */
ot->name = "Brush Select";
@ -310,7 +312,7 @@ static void PAINT_OT_brush_select(wmOperatorType *ot)
ot->exec = brush_select_exec;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* props */
RNA_def_enum(ot->srna, "paint_mode", paint_mode_items, OB_MODE_ACTIVE, "Paint Mode", "");
@ -321,28 +323,28 @@ static void PAINT_OT_brush_select(wmOperatorType *ot)
}
static wmKeyMapItem *keymap_brush_select(wmKeyMap *keymap, int paint_mode,
int tool, int keymap_type,
int keymap_modifier)
int tool, int keymap_type,
int keymap_modifier)
{
wmKeyMapItem *kmi;
kmi = WM_keymap_add_item(keymap, "PAINT_OT_brush_select",
keymap_type, KM_PRESS, keymap_modifier, 0);
keymap_type, KM_PRESS, keymap_modifier, 0);
RNA_enum_set(kmi->ptr, "paint_mode", paint_mode);
switch(paint_mode) {
case OB_MODE_SCULPT:
RNA_enum_set(kmi->ptr, "sculpt_tool", tool);
break;
case OB_MODE_VERTEX_PAINT:
RNA_enum_set(kmi->ptr, "vertex_paint_tool", tool);
break;
case OB_MODE_WEIGHT_PAINT:
RNA_enum_set(kmi->ptr, "weight_paint_tool", tool);
break;
case OB_MODE_TEXTURE_PAINT:
RNA_enum_set(kmi->ptr, "texture_paint_tool", tool);
break;
switch (paint_mode) {
case OB_MODE_SCULPT:
RNA_enum_set(kmi->ptr, "sculpt_tool", tool);
break;
case OB_MODE_VERTEX_PAINT:
RNA_enum_set(kmi->ptr, "vertex_paint_tool", tool);
break;
case OB_MODE_WEIGHT_PAINT:
RNA_enum_set(kmi->ptr, "weight_paint_tool", tool);
break;
case OB_MODE_TEXTURE_PAINT:
RNA_enum_set(kmi->ptr, "texture_paint_tool", tool);
break;
}
return kmi;
@ -351,12 +353,12 @@ static wmKeyMapItem *keymap_brush_select(wmKeyMap *keymap, int paint_mode,
static int brush_uv_sculpt_tool_set_exec(bContext *C, wmOperator *op)
{
Brush *brush;
Scene *scene= CTX_data_scene(C);
Scene *scene = CTX_data_scene(C);
ToolSettings *ts = scene->toolsettings;
ts->uv_sculpt_tool = RNA_enum_get(op->ptr, "tool");
brush = ts->uvsculpt->paint.brush;
/* To update toolshelf */
WM_event_add_notifier(C, NC_BRUSH|NA_EDITED, brush);
WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
return OPERATOR_FINISHED;
}
@ -444,7 +446,7 @@ static void ed_keymap_paint_brush_switch(wmKeyMap *keymap, const char *mode)
/* index 0-9 (zero key is tenth), shift key for index 10-19 */
for (i = 0; i < 20; i++) {
kmi = WM_keymap_add_item(keymap, "BRUSH_OT_active_index_set",
ZEROKEY + ((i + 1) % 10), KM_PRESS, i < 10 ? 0 : KM_SHIFT, 0);
ZEROKEY + ((i + 1) % 10), KM_PRESS, i < 10 ? 0 : KM_SHIFT, 0);
RNA_string_set(kmi->ptr, "mode", mode);
RNA_int_set(kmi->ptr, "index", i);
}
@ -458,7 +460,7 @@ static void ed_keymap_paint_brush_size(wmKeyMap *keymap, const char *UNUSED(path
RNA_float_set(kmi->ptr, "scalar", 0.9);
kmi = WM_keymap_add_item(keymap, "BRUSH_OT_scale_size", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
RNA_float_set(kmi->ptr, "scalar", 10.0/9.0); // 1.1111....
RNA_float_set(kmi->ptr, "scalar", 10.0 / 9.0); // 1.1111....
}
typedef enum {
@ -468,7 +470,7 @@ typedef enum {
} RCFlags;
static void set_brush_rc_path(PointerRNA *ptr, const char *brush_path,
const char *output_name, const char *input_name)
const char *output_name, const char *input_name)
{
char *path;
@ -478,8 +480,8 @@ static void set_brush_rc_path(PointerRNA *ptr, const char *brush_path,
}
static void set_brush_rc_props(PointerRNA *ptr, const char *paint,
const char *prop, const char *secondary_prop,
RCFlags flags)
const char *prop, const char *secondary_prop,
RCFlags flags)
{
const char *ups_path = "tool_settings.unified_paint_settings";
char *brush_path;
@ -512,7 +514,7 @@ static void set_brush_rc_props(PointerRNA *ptr, const char *paint,
}
static void ed_keymap_paint_brush_radial_control(wmKeyMap *keymap, const char *paint,
RCFlags flags)
RCFlags flags)
{
wmKeyMapItem *kmi;
@ -561,8 +563,8 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
/* Partial visibility, sculpt-only for now */
paint_partial_visibility_keys(keymap);
for (i=0; i<=5; i++)
RNA_int_set(WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", ZEROKEY+i, KM_PRESS, KM_CTRL, 0)->ptr, "level", i);
for (i = 0; i <= 5; i++)
RNA_int_set(WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", ZEROKEY + i, KM_PRESS, KM_CTRL, 0)->ptr, "level", i);
/* multires switch */
kmi = WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", PAGEUPKEY, KM_PRESS, 0, 0);
@ -605,7 +607,7 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "PAINT_OT_sample_color", RIGHTMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap,
"PAINT_OT_vertex_color_set",KKEY, KM_PRESS, KM_SHIFT, 0);
"PAINT_OT_vertex_color_set", KKEY, KM_PRESS, KM_SHIFT, 0);
ed_keymap_paint_brush_switch(keymap, "vertex_paint");
ed_keymap_paint_brush_size(keymap, "tool_settings.vertex_paint.brush.size");
@ -625,7 +627,7 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
WM_keymap_verify_item(keymap, "PAINT_OT_weight_sample_group", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap,
"PAINT_OT_weight_set", KKEY, KM_PRESS, KM_SHIFT, 0);
"PAINT_OT_weight_set", KKEY, KM_PRESS, KM_SHIFT, 0);
ed_keymap_paint_brush_switch(keymap, "weight_paint");
ed_keymap_paint_brush_size(keymap, "tool_settings.weight_paint.brush.size");
@ -649,7 +651,7 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "VIEW3D_OT_select_border", BKEY, KM_PRESS, 0, 0);
kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
RNA_boolean_set(kmi->ptr, "deselect", FALSE);
kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT|KM_CTRL, 0);
kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT | KM_CTRL, 0);
RNA_boolean_set(kmi->ptr, "deselect", TRUE);
WM_keymap_add_item(keymap, "VIEW3D_OT_select_circle", CKEY, KM_PRESS, 0, 0);
@ -664,7 +666,7 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
ed_keymap_paint_brush_switch(keymap, "image_paint");
ed_keymap_paint_brush_size(keymap, "tool_settings.image_paint.brush.size");
ed_keymap_paint_brush_radial_control(keymap, "image_paint", RC_COLOR|RC_ZOOM);
ed_keymap_paint_brush_radial_control(keymap, "image_paint", RC_COLOR | RC_ZOOM);
kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", MKEY, KM_PRESS, 0, 0); /* mask toggle */
RNA_string_set(kmi->ptr, "data_path", "image_paint_object.data.use_paint_mask");

@ -98,7 +98,7 @@ static void paint_draw_smooth_stroke(bContext *C, int x, int y, void *customdata
if (stroke && brush && (brush->flag & BRUSH_SMOOTH_STROKE)) {
ARegion *ar = CTX_wm_region(C);
sdrawline(x, y, (int)stroke->last_mouse_position[0] - ar->winrct.xmin,
(int)stroke->last_mouse_position[1] - ar->winrct.ymin);
(int)stroke->last_mouse_position[1] - ar->winrct.ymin);
}
glDisable(GL_BLEND);
@ -113,7 +113,7 @@ static float event_tablet_data(wmEvent *event, int *pen_flip)
float pressure = 1;
if (event->custom == EVT_DATA_TABLET) {
wmTabletData *wmtab= event->customdata;
wmTabletData *wmtab = event->customdata;
erasor = (wmtab->Active == EVT_TABLET_ERASER);
pressure = (wmtab->Active != EVT_TABLET_NONE) ? wmtab->Pressure : 1;
@ -197,7 +197,7 @@ static int paint_smooth_stroke(PaintStroke *stroke, float output[2], wmEvent *ev
/* If the mouse is moving within the radius of the last move,
* don't update the mouse position. This allows sharp turns. */
if (dx*dx + dy*dy < stroke->brush->smooth_stroke_radius * stroke->brush->smooth_stroke_radius)
if (dx * dx + dy * dy < stroke->brush->smooth_stroke_radius * stroke->brush->smooth_stroke_radius)
return 0;
output[0] = event->x * v + stroke->last_mouse_position[0] * u;
@ -228,14 +228,14 @@ static int paint_space_stroke(bContext *C, wmOperator *op, wmEvent *event, const
const Scene *scene = CTX_data_scene(C);
int steps;
int i;
float pressure= 1.0f;
float pressure = 1.0f;
/* XXX mysterious :) what has 'use size' do with this here... if you don't check for it, pressure fails */
if (brush_use_size_pressure(scene, stroke->brush))
pressure = event_tablet_data(event, NULL);
if (pressure > FLT_EPSILON) {
scale = (brush_size(scene, stroke->brush)*pressure*stroke->brush->spacing/50.0f) / length;
scale = (brush_size(scene, stroke->brush) * pressure * stroke->brush->spacing / 50.0f) / length;
if (scale > FLT_EPSILON) {
mul_v2_fl(vec, scale);
@ -256,10 +256,10 @@ static int paint_space_stroke(bContext *C, wmOperator *op, wmEvent *event, const
/**** Public API ****/
PaintStroke *paint_stroke_new(bContext *C,
StrokeGetLocation get_location,
StrokeTestStart test_start,
StrokeUpdateStep update_step,
StrokeDone done, int event_type)
StrokeGetLocation get_location,
StrokeTestStart test_start,
StrokeUpdateStep update_step,
StrokeDone done, int event_type)
{
PaintStroke *stroke = MEM_callocN(sizeof(PaintStroke), "PaintStroke");
@ -271,7 +271,7 @@ PaintStroke *paint_stroke_new(bContext *C,
stroke->test_start = test_start;
stroke->update_step = update_step;
stroke->done = done;
stroke->event_type= event_type; /* for modal, return event */
stroke->event_type = event_type; /* for modal, return event */
return stroke;
}
@ -293,7 +293,7 @@ int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event)
{
PaintStroke *stroke = op->customdata;
float mouse[2];
int first= 0;
int first = 0;
// let NDOF motion pass through to the 3D view so we can paint and rotate simultaneously!
// this isn't perfect... even when an extra MOUSEMOVE is spoofed, the stroke discards it
@ -309,13 +309,13 @@ int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event)
if (stroke->stroke_started) {
stroke->smooth_stroke_cursor =
WM_paint_cursor_activate(CTX_wm_manager(C), paint_poll, paint_draw_smooth_stroke, stroke);
WM_paint_cursor_activate(CTX_wm_manager(C), paint_poll, paint_draw_smooth_stroke, stroke);
if (stroke->brush->flag & BRUSH_AIRBRUSH)
stroke->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, stroke->brush->rate);
}
first= 1;
first = 1;
//ED_region_tag_redraw(ar);
}
@ -331,7 +331,7 @@ int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event)
MEM_freeN(stroke);
return OPERATOR_FINISHED;
}
else if ( (first) ||
else if ((first) ||
(ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) ||
(event->type == TIMER && (event->customdata == stroke->timer)) )
{
@ -347,7 +347,7 @@ int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event)
}
}
else {
;//ED_region_tag_redraw(ar);
; //ED_region_tag_redraw(ar);
}
}
}
@ -355,10 +355,10 @@ int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event)
/* we want the stroke to have the first daub at the start location
* instead of waiting till we have moved the space distance */
if (first &&
stroke->stroke_started &&
paint_space_stroke_enabled(stroke->brush) &&
!(stroke->brush->flag & BRUSH_ANCHORED) &&
!(stroke->brush->flag & BRUSH_SMOOTH_STROKE))
stroke->stroke_started &&
paint_space_stroke_enabled(stroke->brush) &&
!(stroke->brush->flag & BRUSH_ANCHORED) &&
!(stroke->brush->flag & BRUSH_SMOOTH_STROKE))
{
paint_brush_stroke_add_step(C, op, event, mouse);
}
@ -374,7 +374,7 @@ int paint_stroke_exec(bContext *C, wmOperator *op)
if (stroke->stroke_started == 0) {
/* XXX stroke->last_mouse_position is unset, this may cause problems */
stroke->test_start(C, op, NULL);
stroke->stroke_started= 1;
stroke->stroke_started = 1;
}
RNA_BEGIN(op->ptr, itemptr, "stroke") {
@ -424,6 +424,6 @@ int paint_poll(bContext *C)
Object *ob = CTX_data_active_object(C);
return p && ob && paint_brush(p) &&
CTX_wm_area(C)->spacetype == SPACE_VIEW3D &&
CTX_wm_region(C)->regiontype == RGN_TYPE_WINDOW;
CTX_wm_area(C)->spacetype == SPACE_VIEW3D &&
CTX_wm_region(C)->regiontype == RGN_TYPE_WINDOW;
}

@ -45,7 +45,7 @@
#include "paint_intern.h"
#define MAXUNDONAME 64
#define MAXUNDONAME 64
typedef struct UndoElem {
struct UndoElem *next, *prev;
@ -94,31 +94,31 @@ static void undo_stack_push_begin(UndoStack *stack, const char *name, UndoRestor
/* remove all undos after (also when stack->current==NULL) */
while (stack->elems.last != stack->current) {
uel= stack->elems.last;
uel = stack->elems.last;
undo_elem_free(stack, uel);
BLI_freelinkN(&stack->elems, uel);
}
/* make new */
stack->current= uel= MEM_callocN(sizeof(UndoElem), "undo file");
uel->restore= restore;
uel->free= free;
stack->current = uel = MEM_callocN(sizeof(UndoElem), "undo file");
uel->restore = restore;
uel->free = free;
BLI_addtail(&stack->elems, uel);
/* name can be a dynamic string */
BLI_strncpy(uel->name, name, sizeof(uel->name));
/* limit amount to the maximum amount*/
nr= 0;
uel= stack->elems.last;
nr = 0;
uel = stack->elems.last;
while (uel) {
nr++;
if (nr==U.undosteps) break;
uel= uel->prev;
if (nr == U.undosteps) break;
uel = uel->prev;
}
if (uel) {
while (stack->elems.first!=uel) {
UndoElem *first= stack->elems.first;
while (stack->elems.first != uel) {
UndoElem *first = stack->elems.first;
undo_elem_free(stack, first);
BLI_freelinkN(&stack->elems, first);
}
@ -132,19 +132,19 @@ static void undo_stack_push_end(UndoStack *stack)
if (U.undomemory != 0) {
/* limit to maximum memory (afterwards, we can't know in advance) */
totmem= 0;
maxmem= ((uintptr_t)U.undomemory)*1024*1024;
totmem = 0;
maxmem = ((uintptr_t)U.undomemory) * 1024 * 1024;
uel= stack->elems.last;
uel = stack->elems.last;
while (uel) {
totmem+= uel->undosize;
if (totmem>maxmem) break;
uel= uel->prev;
totmem += uel->undosize;
if (totmem > maxmem) break;
uel = uel->prev;
}
if (uel) {
while (stack->elems.first!=uel) {
UndoElem *first= stack->elems.first;
while (stack->elems.first != uel) {
UndoElem *first = stack->elems.first;
undo_elem_free(stack, first);
BLI_freelinkN(&stack->elems, first);
}
@ -156,24 +156,24 @@ static int undo_stack_step(bContext *C, UndoStack *stack, int step, const char *
{
UndoElem *undo;
if (step==1) {
if (stack->current==NULL);
if (step == 1) {
if (stack->current == NULL) ;
else {
if (!name || strcmp(stack->current->name, name) == 0) {
if (G.f & G_DEBUG) printf("undo %s\n", stack->current->name);
undo_restore(C, stack, stack->current);
stack->current= stack->current->prev;
stack->current = stack->current->prev;
return 1;
}
}
}
else if (step==-1) {
if ((stack->current!=NULL && stack->current->next==NULL) || stack->elems.first==NULL);
else if (step == -1) {
if ((stack->current != NULL && stack->current->next == NULL) || stack->elems.first == NULL) ;
else {
if (!name || strcmp(stack->current->name, name) == 0) {
undo= (stack->current && stack->current->next)? stack->current->next: stack->elems.first;
undo = (stack->current && stack->current->next) ? stack->current->next : stack->elems.first;
undo_restore(C, stack, undo);
stack->current= undo;
stack->current = undo;
if (G.f & G_DEBUG) printf("redo %s\n", undo->name);
return 1;
}
@ -187,11 +187,11 @@ static void undo_stack_free(UndoStack *stack)
{
UndoElem *uel;
for (uel=stack->elems.first; uel; uel=uel->next)
for (uel = stack->elems.first; uel; uel = uel->next)
undo_elem_free(stack, uel);
BLI_freelistN(&stack->elems);
stack->current= NULL;
stack->current = NULL;
}
/* Exported Functions */
@ -249,13 +249,13 @@ int ED_undo_paint_valid(int type, const char *name)
UndoStack *stack;
if (type == UNDO_PAINT_IMAGE)
stack= &ImageUndoStack;
stack = &ImageUndoStack;
else if (type == UNDO_PAINT_MESH)
stack= &MeshUndoStack;
stack = &MeshUndoStack;
else
return 0;
if (stack->current==NULL);
if (stack->current == NULL) ;
else {
if (name && strcmp(stack->current->name, name) == 0)
return 1;

@ -71,11 +71,11 @@
* its minimum and maximum corners) into a screen-space rectangle,
* returns zero if the result is empty */
int paint_convert_bb_to_rect(rcti *rect,
const float bb_min[3],
const float bb_max[3],
const ARegion *ar,
RegionView3D *rv3d,
Object *ob)
const float bb_min[3],
const float bb_max[3],
const ARegion *ar,
RegionView3D *rv3d,
Object *ob)
{
float projection_mat[4][4];
int i, j, k;
@ -115,10 +115,10 @@ int paint_convert_bb_to_rect(rcti *rect,
* screen_rect from screen into object-space (essentially converting a
* 2D screens-space bounding box into four 3D planes) */
void paint_calc_redraw_planes(float planes[4][4],
const ARegion *ar,
RegionView3D *rv3d,
Object *ob,
const rcti *screen_rect)
const ARegion *ar,
RegionView3D *rv3d,
Object *ob,
const rcti *screen_rect)
{
BoundBox bb;
bglMats mats;
@ -145,14 +145,14 @@ void projectf(bglMats *mats, const float v[3], float p[2])
{
double ux, uy, uz;
gluProject(v[0],v[1],v[2], mats->modelview, mats->projection,
(GLint *)mats->viewport, &ux, &uy, &uz);
p[0]= ux;
p[1]= uy;
gluProject(v[0], v[1], v[2], mats->modelview, mats->projection,
(GLint *)mats->viewport, &ux, &uy, &uz);
p[0] = ux;
p[1] = uy;
}
float paint_calc_object_space_radius(ViewContext *vc, const float center[3],
float pixel_radius)
float pixel_radius)
{
Object *ob = vc->obact;
float delta[3], scale, loc[3];
@ -162,17 +162,17 @@ float paint_calc_object_space_radius(ViewContext *vc, const float center[3],
initgrabz(vc->rv3d, loc[0], loc[1], loc[2]);
mval_f[0]= pixel_radius;
mval_f[1]= 0.0f;
mval_f[0] = pixel_radius;
mval_f[1] = 0.0f;
ED_view3d_win_to_delta(vc->ar, mval_f, delta);
scale= fabsf(mat4_to_scale(ob->obmat));
scale= (scale == 0.0f)? 1.0f: scale;
scale = fabsf(mat4_to_scale(ob->obmat));
scale = (scale == 0.0f) ? 1.0f : scale;
return len_v3(delta)/scale;
return len_v3(delta) / scale;
}
float paint_get_tex_pixel(Brush* br, float u, float v)
float paint_get_tex_pixel(Brush *br, float u, float v)
{
TexResult texres;
float co[3];
@ -186,7 +186,7 @@ float paint_get_tex_pixel(Brush* br, float u, float v)
hasrgb = multitex_ext(br->mtex.tex, co, NULL, NULL, 0, &texres);
if (hasrgb & TEX_RGB)
texres.tin = (0.35f*texres.tr + 0.45f*texres.tg + 0.2f*texres.tb)*texres.ta;
texres.tin = (0.35f * texres.tr + 0.45f * texres.tg + 0.2f * texres.tb) * texres.ta;
return texres.tin;
}
@ -196,7 +196,7 @@ float paint_get_tex_pixel(Brush* br, float u, float v)
static void imapaint_project(Object *ob, float model[][4], float proj[][4], const float co[3], float pco[4])
{
copy_v3_v3(pco, co);
pco[3]= 1.0f;
pco[3] = 1.0f;
mul_m4_v3(ob->obmat, pco);
mul_m4_v3(model, pco);
@ -225,16 +225,16 @@ static void imapaint_tri_weights(Object *ob,
imapaint_project(ob, model, proj, v3, pv3);
/* do inverse view mapping, see gluProject man page */
h[0]= (co[0] - view[0])*2.0f/view[2] - 1;
h[1]= (co[1] - view[1])*2.0f/view[3] - 1;
h[2]= 1.0f;
h[0] = (co[0] - view[0]) * 2.0f / view[2] - 1;
h[1] = (co[1] - view[1]) * 2.0f / view[3] - 1;
h[2] = 1.0f;
/* solve for (w1,w2,w3)/perspdiv in:
* h * perspdiv = Project * Model * (w1 * v1 + w2 * v2 + w3 * v3) */
wmat[0][0]= pv1[0]; wmat[1][0]= pv2[0]; wmat[2][0]= pv3[0];
wmat[0][1]= pv1[1]; wmat[1][1]= pv2[1]; wmat[2][1]= pv3[1];
wmat[0][2]= pv1[3]; wmat[1][2]= pv2[3]; wmat[2][2]= pv3[3];
wmat[0][0] = pv1[0]; wmat[1][0] = pv2[0]; wmat[2][0] = pv3[0];
wmat[0][1] = pv1[1]; wmat[1][1] = pv2[1]; wmat[2][1] = pv3[1];
wmat[0][2] = pv1[3]; wmat[1][2] = pv2[3]; wmat[2][2] = pv3[3];
invert_m3_m3(invwmat, wmat);
mul_m3_v3(invwmat, h);
@ -242,9 +242,9 @@ static void imapaint_tri_weights(Object *ob,
copy_v3_v3(w, h);
/* w is still divided by perspdiv, make it sum to one */
divw= w[0] + w[1] + w[2];
divw = w[0] + w[1] + w[2];
if (divw != 0.0f) {
mul_v3_fl(w, 1.0f/divw);
mul_v3_fl(w, 1.0f / divw);
}
}
@ -264,7 +264,7 @@ void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, const in
/* test all faces in the derivedmesh with the original index of the picked face */
for (a = 0; a < numfaces; a++) {
findex= index ? index[a]: a;
findex = index ? index[a] : a;
if (findex == faceindex) {
dm->getTessFace(dm, a, &mf);
@ -275,36 +275,36 @@ void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, const in
if (mf.v4)
dm->getVert(dm, mf.v4, &mv[3]);
tf= &tface[a];
tf = &tface[a];
p[0]= xy[0];
p[1]= xy[1];
p[0] = xy[0];
p[1] = xy[1];
if (mf.v4) {
/* the triangle with the largest absolute values is the one
* with the most negative weights */
imapaint_tri_weights(ob, mv[0].co, mv[1].co, mv[3].co, p, w);
absw= fabs(w[0]) + fabs(w[1]) + fabs(w[2]);
absw = fabs(w[0]) + fabs(w[1]) + fabs(w[2]);
if (absw < minabsw) {
uv[0]= tf->uv[0][0]*w[0] + tf->uv[1][0]*w[1] + tf->uv[3][0]*w[2];
uv[1]= tf->uv[0][1]*w[0] + tf->uv[1][1]*w[1] + tf->uv[3][1]*w[2];
uv[0] = tf->uv[0][0] * w[0] + tf->uv[1][0] * w[1] + tf->uv[3][0] * w[2];
uv[1] = tf->uv[0][1] * w[0] + tf->uv[1][1] * w[1] + tf->uv[3][1] * w[2];
minabsw = absw;
}
imapaint_tri_weights(ob, mv[1].co, mv[2].co, mv[3].co, p, w);
absw= fabs(w[0]) + fabs(w[1]) + fabs(w[2]);
absw = fabs(w[0]) + fabs(w[1]) + fabs(w[2]);
if (absw < minabsw) {
uv[0]= tf->uv[1][0]*w[0] + tf->uv[2][0]*w[1] + tf->uv[3][0]*w[2];
uv[1]= tf->uv[1][1]*w[0] + tf->uv[2][1]*w[1] + tf->uv[3][1]*w[2];
uv[0] = tf->uv[1][0] * w[0] + tf->uv[2][0] * w[1] + tf->uv[3][0] * w[2];
uv[1] = tf->uv[1][1] * w[0] + tf->uv[2][1] * w[1] + tf->uv[3][1] * w[2];
minabsw = absw;
}
}
else {
imapaint_tri_weights(ob, mv[0].co, mv[1].co, mv[2].co, p, w);
absw= fabs(w[0]) + fabs(w[1]) + fabs(w[2]);
absw = fabs(w[0]) + fabs(w[1]) + fabs(w[2]);
if (absw < minabsw) {
uv[0]= tf->uv[0][0]*w[0] + tf->uv[1][0]*w[1] + tf->uv[2][0]*w[2];
uv[1]= tf->uv[0][1]*w[0] + tf->uv[1][1]*w[1] + tf->uv[2][1]*w[2];
uv[0] = tf->uv[0][0] * w[0] + tf->uv[1][0] * w[1] + tf->uv[2][0] * w[2];
uv[1] = tf->uv[0][1] * w[0] + tf->uv[1][1] * w[1] + tf->uv[2][1] * w[2];
minabsw = absw;
}
}
@ -333,7 +333,7 @@ int imapaint_pick_face(ViewContext *vc, const int mval[2], unsigned int *index,
}
/* used for both 3d view and image window */
void paint_sample_color(Scene *scene, ARegion *ar, int x, int y) /* frontbuf */
void paint_sample_color(Scene *scene, ARegion *ar, int x, int y) /* frontbuf */
{
Brush *br = paint_brush(paint_get_active(scene));
unsigned int col;
@ -343,15 +343,15 @@ void paint_sample_color(Scene *scene, ARegion *ar, int x, int y) /* frontbuf */
CLAMP(y, 0, ar->winy);
glReadBuffer(GL_FRONT);
glReadPixels(x+ar->winrct.xmin, y+ar->winrct.ymin, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col);
glReadPixels(x + ar->winrct.xmin, y + ar->winrct.ymin, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col);
glReadBuffer(GL_BACK);
cp = (char *)&col;
if (br) {
br->rgb[0]= cp[0]/255.0f;
br->rgb[1]= cp[1]/255.0f;
br->rgb[2]= cp[2]/255.0f;
br->rgb[0] = cp[0] / 255.0f;
br->rgb[1] = cp[1] / 255.0f;
br->rgb[2] = cp[2] / 255.0f;
}
}
@ -388,7 +388,7 @@ void BRUSH_OT_curve_preset(wmOperatorType *ot)
ot->exec = brush_curve_preset_exec;
ot->poll = brush_curve_preset_poll;
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
RNA_def_enum(ot->srna, "shape", prop_shape_items, CURVE_PRESET_SMOOTH, "Mode", "");
}
@ -411,12 +411,12 @@ void PAINT_OT_face_select_linked(wmOperatorType *ot)
ot->exec = paint_select_linked_exec;
ot->poll = facemask_paint_poll;
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
static int paint_select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
int mode= RNA_boolean_get(op->ptr, "extend") ? 1:0;
int mode = RNA_boolean_get(op->ptr, "extend") ? 1 : 0;
paintface_select_linked(C, CTX_data_active_object(C), event->mval, mode);
ED_region_tag_redraw(CTX_wm_region(C));
return OPERATOR_FINISHED;
@ -431,7 +431,7 @@ void PAINT_OT_face_select_linked_pick(wmOperatorType *ot)
ot->invoke = paint_select_linked_pick_invoke;
ot->poll = facemask_paint_poll;
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the existing selection");
}
@ -439,7 +439,7 @@ void PAINT_OT_face_select_linked_pick(wmOperatorType *ot)
static int face_select_all_exec(bContext *C, wmOperator *op)
{
Object *ob= CTX_data_active_object(C);
Object *ob = CTX_data_active_object(C);
paintface_deselect_all_visible(ob, RNA_enum_get(op->ptr, "action"), TRUE);
ED_region_tag_redraw(CTX_wm_region(C));
return OPERATOR_FINISHED;
@ -455,7 +455,7 @@ void PAINT_OT_face_select_all(wmOperatorType *ot)
ot->exec = face_select_all_exec;
ot->poll = facemask_paint_poll;
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
WM_operator_properties_select_all(ot);
}
@ -463,7 +463,7 @@ void PAINT_OT_face_select_all(wmOperatorType *ot)
static int vert_select_all_exec(bContext *C, wmOperator *op)
{
Object *ob= CTX_data_active_object(C);
Object *ob = CTX_data_active_object(C);
paintvert_deselect_all_visible(ob, RNA_enum_get(op->ptr, "action"), TRUE);
ED_region_tag_redraw(CTX_wm_region(C));
return OPERATOR_FINISHED;
@ -479,14 +479,14 @@ void PAINT_OT_vert_select_all(wmOperatorType *ot)
ot->exec = vert_select_all_exec;
ot->poll = vert_paint_poll;
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
WM_operator_properties_select_all(ot);
}
static int vert_select_inverse_exec(bContext *C, wmOperator *UNUSED(op))
{
Object *ob= CTX_data_active_object(C);
Object *ob = CTX_data_active_object(C);
paintvert_deselect_all_visible(ob, SEL_INVERT, TRUE);
ED_region_tag_redraw(CTX_wm_region(C));
return OPERATOR_FINISHED;
@ -501,11 +501,11 @@ void PAINT_OT_vert_select_inverse(wmOperatorType *ot)
ot->exec = vert_select_inverse_exec;
ot->poll = vert_paint_poll;
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
static int face_select_inverse_exec(bContext *C, wmOperator *UNUSED(op))
{
Object *ob= CTX_data_active_object(C);
Object *ob = CTX_data_active_object(C);
paintface_deselect_all_visible(ob, SEL_INVERT, TRUE);
ED_region_tag_redraw(CTX_wm_region(C));
return OPERATOR_FINISHED;
@ -521,13 +521,13 @@ void PAINT_OT_face_select_inverse(wmOperatorType *ot)
ot->exec = face_select_inverse_exec;
ot->poll = facemask_paint_poll;
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
static int face_select_hide_exec(bContext *C, wmOperator *op)
{
const int unselected= RNA_boolean_get(op->ptr, "unselected");
Object *ob= CTX_data_active_object(C);
const int unselected = RNA_boolean_get(op->ptr, "unselected");
Object *ob = CTX_data_active_object(C);
paintface_hide(ob, unselected);
ED_region_tag_redraw(CTX_wm_region(C));
return OPERATOR_FINISHED;
@ -542,14 +542,14 @@ void PAINT_OT_face_select_hide(wmOperatorType *ot)
ot->exec = face_select_hide_exec;
ot->poll = facemask_paint_poll;
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected objects");
}
static int face_select_reveal_exec(bContext *C, wmOperator *UNUSED(op))
{
Object *ob= CTX_data_active_object(C);
Object *ob = CTX_data_active_object(C);
paintface_reveal(ob);
ED_region_tag_redraw(CTX_wm_region(C));
return OPERATOR_FINISHED;
@ -564,7 +564,7 @@ void PAINT_OT_face_select_reveal(wmOperatorType *ot)
ot->exec = face_select_reveal_exec;
ot->poll = facemask_paint_poll;
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected objects");
}

@ -130,14 +130,15 @@ int vertex_paint_mode_poll(bContext *C)
int vertex_paint_poll(bContext *C)
{
if (vertex_paint_mode_poll(C) &&
paint_brush(&CTX_data_tool_settings(C)->vpaint->paint)) {
paint_brush(&CTX_data_tool_settings(C)->vpaint->paint))
{
ScrArea *sa = CTX_wm_area(C);
if (sa->spacetype == SPACE_VIEW3D) {
ARegion *ar = CTX_wm_region(C);
if (ar->regiontype == RGN_TYPE_WINDOW)
return 1;
}
}
}
return 0;
}
@ -321,7 +322,7 @@ void do_shared_vertexcol(Mesh *me, int do_tessface)
}
}
static void make_vertexcol(Object *ob) /* single ob */
static void make_vertexcol(Object *ob) /* single ob */
{
Mesh *me;
if (!ob || ob->id.lib) return;
@ -387,7 +388,7 @@ static int wpaint_mirror_vgroup_ensure(Object *ob, const int vgroup_active)
}
if (curdef == NULL) {
int olddef = ob->actdef; /* tsk, ED_vgroup_add sets the active defgroup */
int olddef = ob->actdef; /* tsk, ED_vgroup_add sets the active defgroup */
curdef = ED_vgroup_add_name(ob, name);
ob->actdef = olddef;
}
@ -418,7 +419,7 @@ static void copy_vpaint_prev(VPaint *vp, unsigned int *lcol, int tot)
}
static void copy_wpaint_prev (VPaint *wp, MDeformVert *dverts, int dcount)
static void copy_wpaint_prev(VPaint *wp, MDeformVert *dverts, int dcount)
{
if (wp->wpaint_prev) {
free_dverts(wp->wpaint_prev, wp->tot);
@ -427,9 +428,9 @@ static void copy_wpaint_prev (VPaint *wp, MDeformVert *dverts, int dcount)
if (dverts && dcount) {
wp->wpaint_prev = MEM_mallocN (sizeof(MDeformVert) * dcount, "wpaint prev");
wp->wpaint_prev = MEM_mallocN(sizeof(MDeformVert) * dcount, "wpaint prev");
wp->tot = dcount;
copy_dverts (wp->wpaint_prev, dverts, dcount);
copy_dverts(wp->wpaint_prev, dverts, dcount);
}
}
@ -445,7 +446,7 @@ void vpaint_fill(Object *ob, unsigned int paintcol)
if (me == NULL || me->totpoly == 0) return;
if (!me->mloopcol) make_vertexcol(ob);
if (!me->mloopcol) return; /* possible we can't make mcol's */
if (!me->mloopcol) return; /* possible we can't make mcol's */
selected = (me->editflag & ME_EDIT_PAINT_MASK);
@ -512,7 +513,7 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight)
dw_prev->weight = dw->weight; /* set the undo weight */
dw->weight = paintweight;
if (me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */
if (me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */
int j = mesh_get_x_mirror_vert(ob, vidx);
if (j >= 0) {
/* copy, not paint again */
@ -568,7 +569,7 @@ void vpaint_dogamma(Scene *scene)
for (a = 0; a < 256; a++) {
fac = ((float)a) / 255.0;
fac = vp->mul * pow( fac, igam);
fac = vp->mul * pow(fac, igam);
temp = 255.9 * fac;
@ -581,9 +582,9 @@ void vpaint_dogamma(Scene *scene)
cp = (unsigned char *)me->mcol;
while (a--) {
cp[1] = gamtab[ cp[1] ];
cp[2] = gamtab[ cp[2] ];
cp[3] = gamtab[ cp[3] ];
cp[1] = gamtab[cp[1]];
cp[2] = gamtab[cp[2]];
cp[3] = gamtab[cp[3]];
cp += 4;
}
@ -799,13 +800,13 @@ static unsigned int vpaint_blend(VPaint *vp, unsigned int col, unsigned int colo
co = (char *)&colorig;
for (a = 0; a < 4; a++) {
if ( ct[a] < co[a] ) {
if ( cp[a] < ct[a] ) cp[a] = ct[a];
else if ( cp[a] > co[a] ) cp[a] = co[a];
if (ct[a] < co[a]) {
if (cp[a] < ct[a]) cp[a] = ct[a];
else if (cp[a] > co[a]) cp[a] = co[a];
}
else {
if ( cp[a] < co[a] ) cp[a] = co[a];
else if ( cp[a] > ct[a] ) cp[a] = ct[a];
if (cp[a] < co[a]) cp[a] = co[a];
else if (cp[a] > ct[a]) cp[a] = ct[a];
}
}
}
@ -853,7 +854,7 @@ static int sample_backbuf_area(ViewContext *vc, int *indexar, int totface, int x
/* whats _dl mean? */
static float calc_vp_strength_dl(VPaint *vp, ViewContext *vc, const float *vert_nor,
const float mval[2], const float brush_size_pressure)
const float mval[2], const float brush_size_pressure)
{
Brush *brush = paint_brush(&vp->paint);
float dist_squared;
@ -918,7 +919,7 @@ BLI_INLINE float wval_sub(const float weight, const float paintval, const float
return weight - (paintval * alpha);
}
BLI_INLINE float wval_mul(const float weight, const float paintval, const float alpha)
{ /* first mul, then blend the fac */
{ /* first mul, then blend the fac */
return ((1.0f - alpha) + (alpha * paintval)) * weight;
}
BLI_INLINE float wval_lighten(const float weight, const float paintval, const float alpha)
@ -962,7 +963,7 @@ static float wpaint_blend(VPaint *wp, float weight, float weight_prev,
int tool = brush->vertexpaint_tool;
if (do_flip) {
switch(tool) {
switch (tool) {
case PAINT_BLEND_MIX:
paintval = 1.f - paintval; break;
case PAINT_BLEND_ADD:
@ -1066,7 +1067,7 @@ static int weight_sample_invoke(bContext *C, wmOperator *op, wmEvent *event)
if (change) {
/* not really correct since the brush didnt change, but redraws the toolbar */
WM_main_add_notifier(NC_BRUSH|NA_EDITED, NULL); /* ts->wpaint->paint.brush */
WM_main_add_notifier(NC_BRUSH | NA_EDITED, NULL); /* ts->wpaint->paint.brush */
return OPERATOR_FINISHED;
}
@ -1169,7 +1170,7 @@ static int weight_sample_group_exec(bContext *C, wmOperator *op)
vc.obact->actdef = type + 1;
DAG_id_tag_update(&vc.obact->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, vc.obact);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, vc.obact);
return OPERATOR_FINISHED;
}
@ -1218,7 +1219,7 @@ static void do_weight_paint_normalize_all(MDeformVert *dvert, const int defbase_
for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) {
if (dw->def_nr < defbase_tot && vgroup_validmap[dw->def_nr]) {
dw->weight *= fac;
dw->weight *= fac;
}
}
}
@ -1315,7 +1316,7 @@ static char has_locked_group(MDeformVert *dvert, const int defbase_tot,
}
/*
* gen_lck_flags gets the status of "flag" for each bDeformGroup
*in ob->defbase and returns an array containing them
* in ob->defbase and returns an array containing them
*/
static char *gen_lock_flags(Object *ob, int defbase_tot)
{
@ -1443,7 +1444,7 @@ static float redistribute_change(MDeformVert *ndv, const int defbase_tot,
change_status[ndw->def_nr] = changeto;
total_valid--;
}
else {/* a perfectly valid change occurred to ndw->weight */
else { /* a perfectly valid change occurred to ndw->weight */
totchange -= change;
ndw->weight += change;
}
@ -1731,11 +1732,12 @@ static int get_first_selected_nonzero_weight(MDeformVert *dvert, const int defba
static char *wpaint_make_validmap(Object *ob);
static void do_weight_paint_vertex(/* vars which remain the same for every vert */
VPaint *wp, Object *ob, const WeightPaintInfo *wpi,
/* vars which change on each stroke */
const unsigned int index, float alpha, float paintweight
)
static void do_weight_paint_vertex(
/* vars which remain the same for every vert */
VPaint *wp, Object *ob, const WeightPaintInfo *wpi,
/* vars which change on each stroke */
const unsigned int index, float alpha, float paintweight
)
{
Mesh *me = ob->data;
MDeformVert *dv = &me->dvert[index];
@ -1915,7 +1917,7 @@ static void do_weight_paint_vertex(/* vars which remain the same for every vert
if (tdw->weight != tdw_prev->weight) {
oldChange = tdw->weight / tdw_prev->weight;
testw = tdw_prev->weight * change;
if ( testw > tdw_prev->weight ) {
if (testw > tdw_prev->weight) {
if (change > oldChange) {
/* reset the weights and use the new change */
defvert_reset_to_prev(wp->wpaint_prev + index, dv);
@ -1955,7 +1957,7 @@ static void do_weight_paint_vertex(/* vars which remain the same for every vert
dw = defvert_find_index(dv, vgroup);
#else
dw = NULL; /* UNUSED after assignment, set to NULL to ensuyre we don't
* use again, we thats needed un-ifdef the line above */
* use again, we thats needed un-ifdef the line above */
(void)dw; /* quiet warnigns */
#endif
@ -1972,7 +1974,7 @@ static void do_weight_paint_vertex(/* vars which remain the same for every vert
/* *************** set wpaint operator ****************** */
static int set_wpaint(bContext *C, wmOperator *UNUSED(op)) /* toggle */
static int set_wpaint(bContext *C, wmOperator *UNUSED(op)) /* toggle */
{
Object *ob = CTX_data_active_object(C);
Scene *scene = CTX_data_scene(C);
@ -2018,7 +2020,7 @@ static int set_wpaint(bContext *C, wmOperator *UNUSED(op)) /* toggle */
mesh_mirrtopo_table(NULL, 'e');
}
WM_event_add_notifier(C, NC_SCENE|ND_MODE, scene);
WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene);
return OPERATOR_FINISHED;
}
@ -2048,7 +2050,7 @@ void PAINT_OT_weight_paint_toggle(wmOperatorType *ot)
ot->poll = paint_poll_test;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
@ -2089,7 +2091,7 @@ static char *wpaint_make_validmap(Object *ob)
/* now loop through the armature modifiers and identify deform bones */
for (md = ob->modifiers.first; md; md = !md->next && step1 ? (step1 = 0), modifiers_getVirtualModifierList(ob) : md->next) {
if (!(md->mode & (eModifierMode_Realtime|eModifierMode_Virtual)))
if (!(md->mode & (eModifierMode_Realtime | eModifierMode_Virtual)))
continue;
if (md->type == eModifierType_Armature) {
@ -2149,7 +2151,7 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *UNUSED
/* if nothing was added yet, we make dverts and a vertex deform group */
if (!me->dvert) {
ED_vgroup_data_create(&me->id);
WM_event_add_notifier(C, NC_GEOM|ND_DATA, me);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
}
/* this happens on a Bone select, when no vgroup existed yet */
@ -2163,7 +2165,7 @@ static int wpaint_stroke_test_start(bContext *C, wmOperator *op, wmEvent *UNUSED
if (pchan) {
bDeformGroup *dg = defgroup_find_name(ob, pchan->name);
if (dg == NULL) {
dg = ED_vgroup_add_name(ob, pchan->name); /* sets actdef */
dg = ED_vgroup_add_name(ob, pchan->name); /* sets actdef */
}
else {
int actdef = 1 + BLI_findindex(&ob->defbase, dg);
@ -2403,7 +2405,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
if (me->dvert[vidx].flag) {
alpha = calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos + 6 * vidx,
mval, brush_size_pressure, brush_alpha_pressure);
mval, brush_size_pressure, brush_alpha_pressure);
if (alpha) {
do_weight_paint_vertex(wp, ob, &wpi, vidx, alpha, paintweight);
}
@ -2503,7 +2505,7 @@ void PAINT_OT_weight_paint(wmOperatorType *ot)
ot->cancel = wpaint_cancel;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
}
@ -2529,13 +2531,13 @@ void PAINT_OT_weight_set(wmOperatorType *ot)
ot->poll = mask_paint_poll; /* it was facemask_paint_poll */
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
/* ************ set / clear vertex paint mode ********** */
static int set_vpaint(bContext *C, wmOperator *op) /* toggle */
static int set_vpaint(bContext *C, wmOperator *op) /* toggle */
{
Object *ob = CTX_data_active_object(C);
Scene *scene = CTX_data_scene(C);
@ -2576,7 +2578,7 @@ static int set_vpaint(bContext *C, wmOperator *op) /* toggle */
/* update modifier stack for mapping requirements */
DAG_id_tag_update(&me->id, 0);
WM_event_add_notifier(C, NC_SCENE|ND_MODE, scene);
WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene);
return OPERATOR_FINISHED;
}
@ -2593,7 +2595,7 @@ void PAINT_OT_vertex_paint_toggle(wmOperatorType *ot)
ot->poll = paint_poll_test;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
@ -2737,17 +2739,17 @@ static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob,
int brush_alpha_pressure_i;
if ((vp->flag & VP_COLINDEX && mface->mat_nr != ob->actcol - 1) ||
((me->editflag & ME_EDIT_PAINT_MASK) && !(mface->flag & ME_FACE_SEL)))
((me->editflag & ME_EDIT_PAINT_MASK) && !(mface->flag & ME_FACE_SEL)))
return;
if (brush->vertexpaint_tool == PAINT_BLEND_BLUR) {
unsigned int fcol1 = mcol_blend( mcol[0], mcol[1], 128);
unsigned int fcol1 = mcol_blend(mcol[0], mcol[1], 128);
if (mface->v4) {
unsigned int fcol2 = mcol_blend( mcol[2], mcol[3], 128);
vpd->paintcol = mcol_blend( fcol1, fcol2, 128);
unsigned int fcol2 = mcol_blend(mcol[2], mcol[3], 128);
vpd->paintcol = mcol_blend(fcol1, fcol2, 128);
}
else {
vpd->paintcol = mcol_blend( mcol[2], fcol1, 170);
vpd->paintcol = mcol_blend(mcol[2], fcol1, 170);
}
}
@ -2974,8 +2976,8 @@ static int vpaint_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
op->customdata = paint_stroke_new(C, NULL, vpaint_stroke_test_start,
vpaint_stroke_update_step,
vpaint_stroke_done, event->type);
vpaint_stroke_update_step,
vpaint_stroke_done, event->type);
/* add modal handler */
WM_event_add_modal_handler(C, op);
@ -3006,7 +3008,7 @@ void PAINT_OT_vertex_paint(wmOperatorType *ot)
ot->cancel = vpaint_cancel;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
}
@ -3031,7 +3033,7 @@ static int weight_from_bones_exec(bContext *C, wmOperator *op)
create_vgroups_from_armature(op->reports, scene, ob, armob, type, (me->editflag & ME_EDIT_MIRROR_X));
DAG_id_tag_update(&me->id, 0);
WM_event_add_notifier(C, NC_GEOM|ND_DATA, me);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
return OPERATOR_FINISHED;
}
@ -3053,7 +3055,7 @@ void PAINT_OT_weight_from_bones(wmOperatorType *ot)
ot->poll = weight_from_bones_poll;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "Method to use for assigning weights");

File diff suppressed because it is too large Load Diff

@ -71,7 +71,7 @@
static void update_cb(PBVHNode *node, void *rebuild)
{
BLI_pbvh_node_mark_update(node);
if (*((int*)rebuild))
if (*((int *)rebuild))
BLI_pbvh_node_mark_rebuild_draw(node);
BLI_pbvh_node_fully_hidden_set(node, 0);
}
@ -89,10 +89,10 @@ static void sculpt_undo_restore_deformed(SculptSession *ss, SculptUndoNode *unod
static int sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoNode *unode)
{
Scene *scene= CTX_data_scene(C);
Sculpt *sd= CTX_data_tool_settings(C)->sculpt;
Object *ob= CTX_data_active_object(C);
SculptSession *ss= ob->sculpt;
Scene *scene = CTX_data_scene(C);
Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
Object *ob = CTX_data_active_object(C);
SculptSession *ss = ob->sculpt;
MVert *mvert;
int *index, i, j;
@ -102,14 +102,14 @@ static int sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoNo
if (ss->kb && strcmp(ss->kb->name, unode->shapeName)) {
/* shape key has been changed before calling undo operator */
Key *key= ob_get_key(ob);
KeyBlock *kb= key_get_named_keyblock(key, unode->shapeName);
Key *key = ob_get_key(ob);
KeyBlock *kb = key_get_named_keyblock(key, unode->shapeName);
if (kb) {
ob->shapenr= BLI_findindex(&key->block, kb) + 1;
ob->shapenr = BLI_findindex(&key->block, kb) + 1;
sculpt_update_mesh_elements(scene, sd, ob, 0);
WM_event_add_notifier(C, NC_OBJECT|ND_DATA, ob);
WM_event_add_notifier(C, NC_OBJECT | ND_DATA, ob);
}
else {
/* key has been removed -- skip this undo node */
@ -117,14 +117,14 @@ static int sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoNo
}
}
index= unode->index;
mvert= ss->mvert;
index = unode->index;
mvert = ss->mvert;
if (ss->kb) {
float (*vertCos)[3];
vertCos= key_to_vertcos(ob, ss->kb);
vertCos = key_to_vertcos(ob, ss->kb);
for (i=0; i<unode->totvert; i++) {
for (i = 0; i < unode->totvert; i++) {
if (ss->modifiers_active) sculpt_undo_restore_deformed(ss, unode, i, index[i], vertCos[index[i]]);
else {
if (unode->orig_co) swap_v3_v3(vertCos[index[i]], unode->orig_co[i]);
@ -142,7 +142,7 @@ static int sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoNo
MEM_freeN(vertCos);
}
else {
for (i=0; i<unode->totvert; i++) {
for (i = 0; i < unode->totvert; i++) {
if (ss->modifiers_active) sculpt_undo_restore_deformed(ss, unode, i, index[i], mvert[index[i]].co);
else {
if (unode->orig_co) swap_v3_v3(mvert[index[i]].co, unode->orig_co[i]);
@ -158,14 +158,14 @@ static int sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoNo
float (*co)[3];
int gridsize;
grids= dm->getGridData(dm);
gridsize= dm->getGridSize(dm);
grids = dm->getGridData(dm);
gridsize = dm->getGridSize(dm);
co = unode->co;
for (j=0; j<unode->totgrid; j++) {
grid= grids[unode->grids[j]];
for (j = 0; j < unode->totgrid; j++) {
grid = grids[unode->grids[j]];
for (i=0; i<gridsize*gridsize; i++, co++)
for (i = 0; i < gridsize * gridsize; i++, co++)
swap_v3_v3(grid[i].co, co[0]);
}
}
@ -174,21 +174,21 @@ static int sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoNo
}
static int sculpt_undo_restore_hidden(bContext *C, DerivedMesh *dm,
SculptUndoNode *unode)
SculptUndoNode *unode)
{
Object *ob = CTX_data_active_object(C);
SculptSession *ss = ob->sculpt;
int i;
if (unode->maxvert) {
MVert *mvert= ss->mvert;
MVert *mvert = ss->mvert;
for (i=0; i<unode->totvert; i++) {
for (i = 0; i < unode->totvert; i++) {
MVert *v = &mvert[unode->index[i]];
int uval= BLI_BITMAP_GET(unode->vert_hidden, i);
int uval = BLI_BITMAP_GET(unode->vert_hidden, i);
BLI_BITMAP_MODIFY(unode->vert_hidden, i,
v->flag & ME_HIDE);
v->flag & ME_HIDE);
if (uval)
v->flag |= ME_HIDE;
else
@ -200,10 +200,10 @@ static int sculpt_undo_restore_hidden(bContext *C, DerivedMesh *dm,
else if (unode->maxgrid && dm->getGridData) {
BLI_bitmap *grid_hidden = dm->getGridHidden(dm);
for (i=0; i<unode->totgrid; i++) {
for (i = 0; i < unode->totgrid; i++) {
SWAP(BLI_bitmap,
unode->grid_hidden[i],
grid_hidden[unode->grids[i]]);
unode->grid_hidden[i],
grid_hidden[unode->grids[i]]);
}
}
@ -220,12 +220,12 @@ static void sculpt_undo_restore(bContext *C, ListBase *lb)
SculptSession *ss = ob->sculpt;
SculptUndoNode *unode;
MultiresModifierData *mmd;
int update= 0, rebuild= 1;
int update = 0, rebuild = 1;
sculpt_update_mesh_elements(scene, sd, ob, 0);
for (unode=lb->first; unode; unode=unode->next) {
if (!(strcmp(unode->idname, ob->id.name)==0))
for (unode = lb->first; unode; unode = unode->next) {
if (!(strcmp(unode->idname, ob->id.name) == 0))
continue;
/* check if undo data matches current data well enough to
@ -236,48 +236,48 @@ static void sculpt_undo_restore(bContext *C, ListBase *lb)
}
else if (unode->maxgrid && dm->getGridData) {
if ((dm->getNumGrids(dm) != unode->maxgrid) ||
(dm->getGridSize(dm) != unode->gridsize))
(dm->getGridSize(dm) != unode->gridsize))
continue;
}
else {
continue;
}
switch(unode->type) {
case SCULPT_UNDO_COORDS:
if (sculpt_undo_restore_coords(C, dm, unode))
update= 1;
break;
case SCULPT_UNDO_HIDDEN:
if (sculpt_undo_restore_hidden(C, dm, unode))
rebuild= 1;
break;
switch (unode->type) {
case SCULPT_UNDO_COORDS:
if (sculpt_undo_restore_coords(C, dm, unode))
update = 1;
break;
case SCULPT_UNDO_HIDDEN:
if (sculpt_undo_restore_hidden(C, dm, unode))
rebuild = 1;
break;
}
}
if (update || rebuild) {
int tag_update= 0;
int tag_update = 0;
/* we update all nodes still, should be more clever, but also
* needs to work correct when exiting/entering sculpt mode and
* the nodes get recreated, though in that case it could do all */
BLI_pbvh_search_callback(ss->pbvh, NULL, NULL, update_cb, &rebuild);
BLI_pbvh_update(ss->pbvh, PBVH_UpdateBB|PBVH_UpdateOriginalBB|PBVH_UpdateRedraw, NULL);
BLI_pbvh_update(ss->pbvh, PBVH_UpdateBB | PBVH_UpdateOriginalBB | PBVH_UpdateRedraw, NULL);
if ((mmd=sculpt_multires_active(scene, ob))) {
if ((mmd = sculpt_multires_active(scene, ob))) {
if (rebuild)
multires_mark_as_modified(ob, MULTIRES_HIDDEN_MODIFIED);
else
multires_mark_as_modified(ob, MULTIRES_COORDS_MODIFIED);
}
tag_update= ((Mesh*)ob->data)->id.us > 1;
tag_update = ((Mesh *)ob->data)->id.us > 1;
if (ss->modifiers_active) {
Mesh *mesh= ob->data;
Mesh *mesh = ob->data;
mesh_calc_normals_mapping(mesh->mvert, mesh->totvert, mesh->mloop, mesh->mpoly, mesh->totloop, mesh->totpoly, NULL, NULL, 0, NULL, NULL);
free_sculptsession_deformMats(ss);
tag_update|= 1;
tag_update |= 1;
}
if (tag_update)
@ -293,7 +293,7 @@ static void sculpt_undo_free(ListBase *lb)
SculptUndoNode *unode;
int i;
for (unode=lb->first; unode; unode=unode->next) {
for (unode = lb->first; unode; unode = unode->next) {
if (unode->co)
MEM_freeN(unode->co);
if (unode->no)
@ -309,7 +309,7 @@ static void sculpt_undo_free(ListBase *lb)
if (unode->vert_hidden)
MEM_freeN(unode->vert_hidden);
if (unode->grid_hidden) {
for (i=0; i<unode->totgrid; i++) {
for (i = 0; i < unode->totgrid; i++) {
if (unode->grid_hidden[i])
MEM_freeN(unode->grid_hidden[i]);
}
@ -320,13 +320,13 @@ static void sculpt_undo_free(ListBase *lb)
SculptUndoNode *sculpt_undo_get_node(PBVHNode *node)
{
ListBase *lb= undo_paint_push_get_list(UNDO_PAINT_MESH);
ListBase *lb = undo_paint_push_get_list(UNDO_PAINT_MESH);
SculptUndoNode *unode;
if (!lb)
return NULL;
for (unode=lb->first; unode; unode=unode->next)
for (unode = lb->first; unode; unode = unode->next)
if (unode->node == node)
return unode;
@ -334,19 +334,19 @@ SculptUndoNode *sculpt_undo_get_node(PBVHNode *node)
}
static void sculpt_undo_alloc_and_store_hidden(PBVH *pbvh,
SculptUndoNode *unode)
SculptUndoNode *unode)
{
PBVHNode *node= unode->node;
PBVHNode *node = unode->node;
BLI_bitmap *grid_hidden;
int i, *grid_indices, totgrid;
grid_hidden= BLI_pbvh_grid_hidden(pbvh);
grid_hidden = BLI_pbvh_grid_hidden(pbvh);
BLI_pbvh_node_get_grids(pbvh, node, &grid_indices, &totgrid,
NULL, NULL, NULL, NULL);
NULL, NULL, NULL, NULL);
unode->grid_hidden= MEM_mapallocN(sizeof(BLI_bitmap) * totgrid,
"unode->grid_hidden");
unode->grid_hidden = MEM_mapallocN(sizeof(BLI_bitmap) * totgrid,
"unode->grid_hidden");
for (i = 0; i < totgrid; i++) {
if (grid_hidden[grid_indices[i]])
@ -357,59 +357,59 @@ static void sculpt_undo_alloc_and_store_hidden(PBVH *pbvh,
}
static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node,
SculptUndoType type)
SculptUndoType type)
{
ListBase *lb= undo_paint_push_get_list(UNDO_PAINT_MESH);
ListBase *lb = undo_paint_push_get_list(UNDO_PAINT_MESH);
SculptUndoNode *unode;
SculptSession *ss= ob->sculpt;
SculptSession *ss = ob->sculpt;
int totvert, allvert, totgrid, maxgrid, gridsize, *grids;
unode= MEM_callocN(sizeof(SculptUndoNode), "SculptUndoNode");
unode = MEM_callocN(sizeof(SculptUndoNode), "SculptUndoNode");
BLI_strncpy(unode->idname, ob->id.name, sizeof(unode->idname));
unode->type= type;
unode->node= node;
unode->type = type;
unode->node = node;
BLI_pbvh_node_num_verts(ss->pbvh, node, &totvert, &allvert);
BLI_pbvh_node_get_grids(ss->pbvh, node, &grids, &totgrid,
&maxgrid, &gridsize, NULL, NULL);
&maxgrid, &gridsize, NULL, NULL);
unode->totvert= totvert;
unode->totvert = totvert;
/* we will use this while sculpting, is mapalloc slow to access then? */
/* general TODO, fix count_alloc */
switch(type) {
case SCULPT_UNDO_COORDS:
unode->co= MEM_mapallocN(sizeof(float)*3*allvert, "SculptUndoNode.co");
unode->no= MEM_mapallocN(sizeof(short)*3*allvert, "SculptUndoNode.no");
undo_paint_push_count_alloc(UNDO_PAINT_MESH, (sizeof(float)*3 + sizeof(short)*3 + sizeof(int))*allvert);
break;
case SCULPT_UNDO_HIDDEN:
if (maxgrid)
sculpt_undo_alloc_and_store_hidden(ss->pbvh, unode);
else
unode->vert_hidden= BLI_BITMAP_NEW(allvert, "SculptUndoNode.vert_hidden");
switch (type) {
case SCULPT_UNDO_COORDS:
unode->co = MEM_mapallocN(sizeof(float) * 3 * allvert, "SculptUndoNode.co");
unode->no = MEM_mapallocN(sizeof(short) * 3 * allvert, "SculptUndoNode.no");
undo_paint_push_count_alloc(UNDO_PAINT_MESH, (sizeof(float) * 3 + sizeof(short) * 3 + sizeof(int)) * allvert);
break;
case SCULPT_UNDO_HIDDEN:
if (maxgrid)
sculpt_undo_alloc_and_store_hidden(ss->pbvh, unode);
else
unode->vert_hidden = BLI_BITMAP_NEW(allvert, "SculptUndoNode.vert_hidden");
break;
break;
}
BLI_addtail(lb, unode);
if (maxgrid) {
/* multires */
unode->maxgrid= maxgrid;
unode->totgrid= totgrid;
unode->gridsize= gridsize;
unode->grids= MEM_mapallocN(sizeof(int)*totgrid, "SculptUndoNode.grids");
unode->maxgrid = maxgrid;
unode->totgrid = totgrid;
unode->gridsize = gridsize;
unode->grids = MEM_mapallocN(sizeof(int) * totgrid, "SculptUndoNode.grids");
}
else {
/* regular mesh */
unode->maxvert= ss->totvert;
unode->index= MEM_mapallocN(sizeof(int)*allvert, "SculptUndoNode.index");
unode->maxvert = ss->totvert;
unode->index = MEM_mapallocN(sizeof(int) * allvert, "SculptUndoNode.index");
}
if (ss->modifiers_active)
unode->orig_co= MEM_callocN(allvert*sizeof(*unode->orig_co), "undoSculpt orig_cos");
unode->orig_co = MEM_callocN(allvert * sizeof(*unode->orig_co), "undoSculpt orig_cos");
return unode;
}
@ -432,12 +432,12 @@ static void sculpt_undo_store_coords(Object *ob, SculptUndoNode *unode)
static void sculpt_undo_store_hidden(Object *ob, SculptUndoNode *unode)
{
PBVH *pbvh= ob->sculpt->pbvh;
PBVHNode *node= unode->node;
PBVH *pbvh = ob->sculpt->pbvh;
PBVHNode *node = unode->node;
if (unode->grids) {
/* already stored during allocation */
}
}
else {
MVert *mvert;
int *vert_indices, allvert;
@ -447,13 +447,13 @@ static void sculpt_undo_store_hidden(Object *ob, SculptUndoNode *unode)
BLI_pbvh_node_get_verts(pbvh, node, &vert_indices, &mvert);
for (i = 0; i < allvert; i++) {
BLI_BITMAP_MODIFY(unode->vert_hidden, i,
mvert[vert_indices[i]].flag & ME_HIDE);
mvert[vert_indices[i]].flag & ME_HIDE);
}
}
}
SculptUndoNode *sculpt_undo_push_node(Object *ob, PBVHNode *node,
SculptUndoType type)
SculptUndoType type)
{
SculptSession *ss = ob->sculpt;
SculptUndoNode *unode;
@ -461,41 +461,41 @@ SculptUndoNode *sculpt_undo_push_node(Object *ob, PBVHNode *node,
/* list is manipulated by multiple threads, so we lock */
BLI_lock_thread(LOCK_CUSTOM1);
if ((unode= sculpt_undo_get_node(node))) {
if ((unode = sculpt_undo_get_node(node))) {
BLI_unlock_thread(LOCK_CUSTOM1);
return unode;
}
unode= sculpt_undo_alloc_node(ob, node, type);
unode = sculpt_undo_alloc_node(ob, node, type);
BLI_unlock_thread(LOCK_CUSTOM1);
/* copy threaded, hopefully this is the performance critical part */
switch(type) {
case SCULPT_UNDO_COORDS:
sculpt_undo_store_coords(ob, unode);
break;
case SCULPT_UNDO_HIDDEN:
sculpt_undo_store_hidden(ob, unode);
break;
switch (type) {
case SCULPT_UNDO_COORDS:
sculpt_undo_store_coords(ob, unode);
break;
case SCULPT_UNDO_HIDDEN:
sculpt_undo_store_hidden(ob, unode);
break;
}
if (unode->grids) {
int totgrid, *grids;
BLI_pbvh_node_get_grids(ss->pbvh, node, &grids, &totgrid,
NULL, NULL, NULL, NULL);
memcpy(unode->grids, grids, sizeof(int)*totgrid);
NULL, NULL, NULL, NULL);
memcpy(unode->grids, grids, sizeof(int) * totgrid);
}
else {
int *vert_indices, allvert;
BLI_pbvh_node_num_verts(ss->pbvh, node, NULL, &allvert);
BLI_pbvh_node_get_verts(ss->pbvh, node, &vert_indices, NULL);
memcpy(unode->index, vert_indices, sizeof(int)*unode->totvert);
memcpy(unode->index, vert_indices, sizeof(int) * unode->totvert);
}
/* store active shape key */
if (ss->kb) BLI_strncpy(unode->shapeName, ss->kb->name, sizeof(ss->kb->name));
else unode->shapeName[0]= '\0';
else unode->shapeName[0] = '\0';
return unode;
}
@ -503,24 +503,24 @@ SculptUndoNode *sculpt_undo_push_node(Object *ob, PBVHNode *node,
void sculpt_undo_push_begin(const char *name)
{
undo_paint_push_begin(UNDO_PAINT_MESH, name,
sculpt_undo_restore, sculpt_undo_free);
sculpt_undo_restore, sculpt_undo_free);
}
void sculpt_undo_push_end(void)
{
ListBase *lb= undo_paint_push_get_list(UNDO_PAINT_MESH);
ListBase *lb = undo_paint_push_get_list(UNDO_PAINT_MESH);
SculptUndoNode *unode;
/* we don't need normals in the undo stack */
for (unode=lb->first; unode; unode=unode->next) {
for (unode = lb->first; unode; unode = unode->next) {
if (unode->no) {
MEM_freeN(unode->no);
unode->no= NULL;
unode->no = NULL;
}
if (unode->layer_disp) {
MEM_freeN(unode->layer_disp);
unode->layer_disp= NULL;
unode->layer_disp = NULL;
}
}

@ -68,7 +68,7 @@
#include "UI_view2d.h"
#define MARK_BOUNDARY 1
#define MARK_BOUNDARY 1
typedef struct UvAdjacencyElement {
/* pointer to original uvelement */
@ -86,7 +86,7 @@ typedef struct UvEdge {
char flag;
}UvEdge;
typedef struct UVInitialStrokeElement{
typedef struct UVInitialStrokeElement {
/* index to unique uv */
int uv;
@ -97,7 +97,7 @@ typedef struct UVInitialStrokeElement{
float initial_uv[2];
}UVInitialStrokeElement;
typedef struct UVInitialStroke{
typedef struct UVInitialStroke {
/* Initial Selection,for grab brushes for instance */
UVInitialStrokeElement *initialSelection;
@ -110,7 +110,7 @@ typedef struct UVInitialStroke{
/* custom data for uv smoothing brush */
typedef struct UvSculptData{
typedef struct UvSculptData {
/* Contains the first of each set of coincident uvs.
* These will be used to perform smoothing on and propagate the changes
* to their coincident uvs */
@ -146,10 +146,10 @@ typedef struct UvSculptData{
/*********** Improved Laplacian Relaxation Operator ************************/
/* original code by Raul Fernandez Hernandez "farsthary" *
* adapted to uv smoothing by Antony Riakiatakis *
***************************************************************************/
* adapted to uv smoothing by Antony Riakiatakis *
***************************************************************************/
typedef struct Temp_UvData{
typedef struct Temp_UvData {
float sum_co[2], p[2], b[2], sum_b[2];
int ncounter;
}Temp_UVData;
@ -169,7 +169,7 @@ void HC_relaxation_iteration_uv(BMEditMesh *em, UvSculptData *sculptdata, float
/* counting neighbors */
for (i = 0; i < sculptdata->totalUvEdges; i++) {
UvEdge *tmpedge = sculptdata->uvedges+i;
UvEdge *tmpedge = sculptdata->uvedges + i;
tmp_uvdata[tmpedge->uv1].ncounter++;
tmp_uvdata[tmpedge->uv2].ncounter++;
@ -178,16 +178,16 @@ void HC_relaxation_iteration_uv(BMEditMesh *em, UvSculptData *sculptdata, float
}
for (i = 0; i < sculptdata->totalUniqueUvs; i++) {
copy_v2_v2(diff,tmp_uvdata[i].sum_co);
mul_v2_fl(diff,1.f/tmp_uvdata[i].ncounter);
copy_v2_v2(tmp_uvdata[i].p,diff);
copy_v2_v2(diff, tmp_uvdata[i].sum_co);
mul_v2_fl(diff, 1.f / tmp_uvdata[i].ncounter);
copy_v2_v2(tmp_uvdata[i].p, diff);
tmp_uvdata[i].b[0] = diff[0] - sculptdata->uv[i].uv[0];
tmp_uvdata[i].b[1] = diff[1] - sculptdata->uv[i].uv[1];
}
for (i = 0; i < sculptdata->totalUvEdges; i++) {
UvEdge *tmpedge = sculptdata->uvedges+i;
UvEdge *tmpedge = sculptdata->uvedges + i;
add_v2_v2(tmp_uvdata[tmpedge->uv1].sum_b, tmp_uvdata[tmpedge->uv2].b);
add_v2_v2(tmp_uvdata[tmpedge->uv2].sum_b, tmp_uvdata[tmpedge->uv1].b);
}
@ -205,10 +205,10 @@ void HC_relaxation_iteration_uv(BMEditMesh *em, UvSculptData *sculptdata, float
if ((dist = dot_v2v2(diff, diff)) <= radius) {
UvElement *element;
float strength;
strength = alpha*brush_curve_strength(brush, sqrt(dist), radius_root);
strength = alpha * brush_curve_strength(brush, sqrt(dist), radius_root);
sculptdata->uv[i].uv[0] = (1.0-strength)*sculptdata->uv[i].uv[0] + strength*(tmp_uvdata[i].p[0] - 0.5f*(tmp_uvdata[i].b[0] + tmp_uvdata[i].sum_b[0]/tmp_uvdata[i].ncounter));
sculptdata->uv[i].uv[1] = (1.0-strength)*sculptdata->uv[i].uv[1] + strength*(tmp_uvdata[i].p[1] - 0.5f*(tmp_uvdata[i].b[1] + tmp_uvdata[i].sum_b[1]/tmp_uvdata[i].ncounter));
sculptdata->uv[i].uv[0] = (1.0 - strength) * sculptdata->uv[i].uv[0] + strength * (tmp_uvdata[i].p[0] - 0.5f * (tmp_uvdata[i].b[0] + tmp_uvdata[i].sum_b[0] / tmp_uvdata[i].ncounter));
sculptdata->uv[i].uv[1] = (1.0 - strength) * sculptdata->uv[i].uv[1] + strength * (tmp_uvdata[i].p[1] - 0.5f * (tmp_uvdata[i].b[1] + tmp_uvdata[i].sum_b[1] / tmp_uvdata[i].ncounter));
for (element = sculptdata->uv[i].element; element; element = element->next) {
MLoopUV *luv;
@ -241,7 +241,7 @@ static void laplacian_relaxation_iteration_uv(BMEditMesh *em, UvSculptData *scul
/* counting neighbors */
for (i = 0; i < sculptdata->totalUvEdges; i++) {
UvEdge *tmpedge = sculptdata->uvedges+i;
UvEdge *tmpedge = sculptdata->uvedges + i;
tmp_uvdata[tmpedge->uv1].ncounter++;
tmp_uvdata[tmpedge->uv2].ncounter++;
@ -253,7 +253,7 @@ static void laplacian_relaxation_iteration_uv(BMEditMesh *em, UvSculptData *scul
* needed since we translate along the UV plane always.*/
for (i = 0; i < sculptdata->totalUniqueUvs; i++) {
copy_v2_v2(tmp_uvdata[i].p, tmp_uvdata[i].sum_co);
mul_v2_fl(tmp_uvdata[i].p, 1.f/tmp_uvdata[i].ncounter);
mul_v2_fl(tmp_uvdata[i].p, 1.f / tmp_uvdata[i].ncounter);
}
for (i = 0; i < sculptdata->totalUniqueUvs; i++) {
@ -269,10 +269,10 @@ static void laplacian_relaxation_iteration_uv(BMEditMesh *em, UvSculptData *scul
if ((dist = dot_v2v2(diff, diff)) <= radius) {
UvElement *element;
float strength;
strength = alpha*brush_curve_strength(brush, sqrt(dist), radius_root);
strength = alpha * brush_curve_strength(brush, sqrt(dist), radius_root);
sculptdata->uv[i].uv[0] = (1.0-strength)*sculptdata->uv[i].uv[0] + strength*tmp_uvdata[i].p[0];
sculptdata->uv[i].uv[1] = (1.0-strength)*sculptdata->uv[i].uv[1] + strength*tmp_uvdata[i].p[1];
sculptdata->uv[i].uv[0] = (1.0 - strength) * sculptdata->uv[i].uv[0] + strength * tmp_uvdata[i].p[0];
sculptdata->uv[i].uv[1] = (1.0 - strength) * sculptdata->uv[i].uv[1] + strength * tmp_uvdata[i].p[1];
for (element = sculptdata->uv[i].element; element; element = element->next) {
MLoopUV *luv;
@ -310,7 +310,7 @@ static void uv_sculpt_stroke_apply(bContext *C, wmOperator *op, wmEvent *event,
Brush *brush = paint_brush(sculptdata->uvsculpt);
ToolSettings *toolsettings = CTX_data_tool_settings(C);
tool = sculptdata->tool;
invert = sculptdata->invert? -1 : 1;
invert = sculptdata->invert ? -1 : 1;
alpha = brush_alpha(scene, brush);
UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
@ -318,11 +318,11 @@ static void uv_sculpt_stroke_apply(bContext *C, wmOperator *op, wmEvent *event,
ED_space_image_size(sima, &width, &height);
ED_space_image_zoom(sima, ar, &zoomx, &zoomy);
radius = brush_size(scene, brush)/(width*zoomx);
aspectRatio = width/(float)height;
radius = brush_size(scene, brush) / (width * zoomx);
aspectRatio = width / (float)height;
/* We will compare squares to save some computation */
radius = radius*radius;
radius = radius * radius;
radius_root = sqrt(radius);
/*
@ -344,11 +344,11 @@ static void uv_sculpt_stroke_apply(bContext *C, wmOperator *op, wmEvent *event,
if ((dist = dot_v2v2(diff, diff)) <= radius) {
UvElement *element;
float strength;
strength = alpha*brush_curve_strength(brush, sqrt(dist), radius_root);
strength = alpha * brush_curve_strength(brush, sqrt(dist), radius_root);
normalize_v2(diff);
sculptdata->uv[i].uv[0] -= strength*diff[0]*0.001;
sculptdata->uv[i].uv[1] -= strength*diff[1]*0.001;
sculptdata->uv[i].uv[0] -= strength * diff[0] * 0.001;
sculptdata->uv[i].uv[1] -= strength * diff[1] * 0.001;
for (element = sculptdata->uv[i].element; element; element = element->next) {
MLoopUV *luv;
@ -386,12 +386,12 @@ static void uv_sculpt_stroke_apply(bContext *C, wmOperator *op, wmEvent *event,
float diff[2];
sub_v2_v2v2(diff, co, sculptdata->initial_stroke->init_coord);
for (i = 0; i < sculptdata->initial_stroke->totalInitialSelected; i++ ) {
for (i = 0; i < sculptdata->initial_stroke->totalInitialSelected; i++) {
UvElement *element;
int uvindex = sculptdata->initial_stroke->initialSelection[i].uv;
float strength = sculptdata->initial_stroke->initialSelection[i].strength;
sculptdata->uv[uvindex].uv[0] = sculptdata->initial_stroke->initialSelection[i].initial_uv[0] + strength*diff[0];
sculptdata->uv[uvindex].uv[1] = sculptdata->initial_stroke->initialSelection[i].initial_uv[1] + strength*diff[1];
sculptdata->uv[uvindex].uv[0] = sculptdata->initial_stroke->initialSelection[i].initial_uv[0] + strength * diff[0];
sculptdata->uv[uvindex].uv[1] = sculptdata->initial_stroke->initialSelection[i].initial_uv[1] + strength * diff[1];
for (element = sculptdata->uv[uvindex].element; element; element = element->next) {
MLoopUV *luv;
@ -445,12 +445,11 @@ static int uv_element_offset_from_face_get(UvElementMap *map, BMFace *efa, BMLoo
}
static unsigned int uv_edge_hash(const void *key)
static unsigned int uv_edge_hash(const void *key)
{
UvEdge *edge = (UvEdge *)key;
return
BLI_ghashutil_inthash(SET_INT_IN_POINTER(edge->uv2)) +
BLI_ghashutil_inthash(SET_INT_IN_POINTER(edge->uv1));
return (BLI_ghashutil_inthash(SET_INT_IN_POINTER(edge->uv2)) +
BLI_ghashutil_inthash(SET_INT_IN_POINTER(edge->uv1)));
}
static int uv_edge_compare(const void *a, const void *b)
@ -478,7 +477,7 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, wmEvent
if (data) {
int counter = 0, i;
ARegion *ar= CTX_wm_region(C);
ARegion *ar = CTX_wm_region(C);
float co[2];
BMFace *efa;
MLoopUV *luv;
@ -487,14 +486,14 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, wmEvent
UvEdge *edges;
GHash *edgeHash;
GHashIterator* ghi;
GHashIterator *ghi;
int do_island_optimization = !(ts->uv_sculpt_settings & UV_SCULPT_ALL_ISLANDS);
int island_index = 0;
/* Holds, for each UvElement in elementMap, a pointer to its unique uv.*/
int *uniqueUv;
data->tool = (RNA_enum_get(op->ptr, "mode") == BRUSH_STROKE_SMOOTH)? UV_SCULPT_TOOL_RELAX : ts->uv_sculpt_tool;
data->invert = (RNA_enum_get(op->ptr, "mode") == BRUSH_STROKE_INVERT)? 1 : 0;
data->tool = (RNA_enum_get(op->ptr, "mode") == BRUSH_STROKE_SMOOTH) ? UV_SCULPT_TOOL_RELAX : ts->uv_sculpt_tool;
data->invert = (RNA_enum_get(op->ptr, "mode") == BRUSH_STROKE_INVERT) ? 1 : 0;
data->uvsculpt = &ts->uvsculpt->paint;
@ -528,7 +527,7 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, wmEvent
if (do_island_optimization) {
UvElement *element;
NearestHit hit;
Image *ima= CTX_data_edit_image(C);
Image *ima = CTX_data_edit_image(C);
uv_find_nearest_vert(scene, ima, em, co, NULL, &hit);
element = ED_uv_element_get(data->elementMap, hit.efa, hit.l);
@ -539,17 +538,17 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, wmEvent
/* Count 'unique' uvs */
for (i = 0; i < data->elementMap->totalUVs; i++) {
if (data->elementMap->buf[i].separate
&& (!do_island_optimization || data->elementMap->buf[i].island == island_index)) {
&& (!do_island_optimization || data->elementMap->buf[i].island == island_index)) {
counter++;
}
}
/* Allocate the unique uv buffers */
data->uv = MEM_mallocN(sizeof(*data->uv)*counter, "uv_brush_unique_uvs");
uniqueUv = MEM_mallocN(sizeof(*uniqueUv)*data->elementMap->totalUVs, "uv_brush_unique_uv_map");
data->uv = MEM_mallocN(sizeof(*data->uv) * counter, "uv_brush_unique_uvs");
uniqueUv = MEM_mallocN(sizeof(*uniqueUv) * data->elementMap->totalUVs, "uv_brush_unique_uv_map");
edgeHash = BLI_ghash_new(uv_edge_hash, uv_edge_compare, "uv_brush_edge_hash");
/* we have at most totalUVs edges */
edges = MEM_mallocN(sizeof(*edges)*data->elementMap->totalUVs, "uv_brush_all_edges");
edges = MEM_mallocN(sizeof(*edges) * data->elementMap->totalUVs, "uv_brush_all_edges");
if (!data->uv || !uniqueUv || !edgeHash || !edges) {
if (edges) {
MEM_freeN(edges);
@ -634,7 +633,7 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, wmEvent
MEM_freeN(uniqueUv);
/* Allocate connectivity data, we allocate edges once */
data->uvedges = MEM_mallocN(sizeof(*data->uvedges)*BLI_ghash_size(edgeHash), "uv_brush_edge_connectivity_data");
data->uvedges = MEM_mallocN(sizeof(*data->uvedges) * BLI_ghash_size(edgeHash), "uv_brush_edge_connectivity_data");
if (!data->uvedges) {
BLI_ghash_free(edgeHash, NULL, NULL);
MEM_freeN(edges);
@ -686,9 +685,9 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, wmEvent
ED_space_image_size(sima, &width, &height);
ED_space_image_zoom(sima, ar, &zoomx, &zoomy);
aspectRatio = width/(float)height;
radius /= (width*zoomx);
radius = radius*radius;
aspectRatio = width / (float)height;
radius /= (width * zoomx);
radius = radius * radius;
radius_root = sqrt(radius);
/* Allocate selection stack */
@ -696,7 +695,7 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, wmEvent
if (!data->initial_stroke) {
uv_sculpt_stroke_exit(C, op);
}
data->initial_stroke->initialSelection = MEM_mallocN(sizeof(*data->initial_stroke->initialSelection)*data->totalUniqueUvs, "uv_sculpt_initial_selection");
data->initial_stroke->initialSelection = MEM_mallocN(sizeof(*data->initial_stroke->initialSelection) * data->totalUniqueUvs, "uv_sculpt_initial_selection");
if (!data->initial_stroke->initialSelection) {
uv_sculpt_stroke_exit(C, op);
}
@ -715,7 +714,7 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, wmEvent
diff[1] /= aspectRatio;
if ((dist = dot_v2v2(diff, diff)) <= radius) {
float strength;
strength = alpha*brush_curve_strength(brush, sqrt(dist), radius_root);
strength = alpha * brush_curve_strength(brush, sqrt(dist), radius_root);
data->initial_stroke->initialSelection[counter].uv = i;
data->initial_stroke->initialSelection[counter].strength = strength;
@ -742,7 +741,7 @@ static int uv_sculpt_stroke_invoke(bContext *C, wmOperator *op, wmEvent *event)
uv_sculpt_stroke_apply(C, op, event, obedit);
data->timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.001f);
data->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.001f);
if (!data->timer) {
uv_sculpt_stroke_exit(C, op);
@ -759,7 +758,7 @@ static int uv_sculpt_stroke_modal(bContext *C, wmOperator *op, wmEvent *event)
UvSculptData *data = (UvSculptData *)op->customdata;
Object *obedit = CTX_data_edit_object(C);
switch(event->type) {
switch (event->type) {
case LEFTMOUSE:
case MIDDLEMOUSE:
case RIGHTMOUSE:
@ -779,7 +778,7 @@ static int uv_sculpt_stroke_modal(bContext *C, wmOperator *op, wmEvent *event)
}
ED_region_tag_redraw(CTX_wm_region(C));
WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
DAG_id_tag_update(obedit->data, 0);
return OPERATOR_RUNNING_MODAL;
}
@ -804,7 +803,7 @@ void SCULPT_OT_uv_sculpt_stroke(wmOperatorType *ot)
ot->poll = uv_sculpt_poll;
/* flags */
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* props */
RNA_def_enum(ot->srna, "mode", stroke_mode_items, BRUSH_STROKE_NORMAL, "Mode", "Stroke Mode");