Sculpt/Paint:
More cleanups: moved a function declaration to the correct module, removed old/incorrect comments, marked more things with TODO where appropriate, refactored copy-pasted function, de-duplicated code.
This commit is contained in:
@@ -56,6 +56,9 @@ int brush_texture_delete(struct Brush *brush);
|
||||
int brush_clone_image_set_nr(struct Brush *brush, int nr);
|
||||
int brush_clone_image_delete(struct Brush *brush);
|
||||
|
||||
/* jitter */
|
||||
void brush_jitter_pos(struct Brush *brush, float *pos, float *jitterpos);
|
||||
|
||||
/* brush curve */
|
||||
void brush_curve_preset(struct Brush *b, /*enum CurveMappingPreset*/int preset);
|
||||
float brush_curve_strength_clamp(struct Brush *br, float p, const float len);
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
struct ARegion;
|
||||
struct bContext;
|
||||
struct bglMats;
|
||||
struct Brush;
|
||||
struct ListBase;
|
||||
struct Mesh;
|
||||
@@ -99,6 +100,7 @@ void PAINT_OT_image_from_view(struct wmOperatorType *ot);
|
||||
|
||||
|
||||
/* paint_utils.c */
|
||||
void projectf(struct bglMats *mats, const float v[3], float p[2]);
|
||||
float paint_calc_object_space_radius(struct ViewContext *vc, float center[3], float pixel_radius);
|
||||
float paint_get_tex_pixel(struct Brush* br, float u, float v);
|
||||
int imapaint_pick_face(struct ViewContext *vc, struct Mesh *me, int *mval, unsigned int *index);
|
||||
|
||||
@@ -51,8 +51,9 @@
|
||||
#include "ED_view3d.h"
|
||||
|
||||
#include "paint_intern.h"
|
||||
#include "sculpt_intern.h" // XXX, for expedience in getting this working, refactor later (or this just shows that this needs unification)
|
||||
|
||||
/* still needed for sculpt_stroke_get_location, should be
|
||||
removed eventually (TODO) */
|
||||
#include "sculpt_intern.h"
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
@@ -321,18 +322,6 @@ static int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Convert a point in model coordinates to 2D screen coordinates. */
|
||||
// XXX duplicated from sculpt.c, deal with this later.
|
||||
static 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;
|
||||
}
|
||||
|
||||
static int project_brush_radius(RegionView3D* rv3d, float radius, float location[3], bglMats* mats)
|
||||
{
|
||||
float view[3], nonortho[3], ortho[3], offset[3], p1[2], p2[2];
|
||||
@@ -385,8 +374,11 @@ int sculpt_get_brush_geometry(bContext* C, int x, int y, int* pixel_radius,
|
||||
window[0] = x + stroke->vc.ar->winrct.xmin;
|
||||
window[1] = y + stroke->vc.ar->winrct.ymin;
|
||||
|
||||
if(stroke->vc.obact->sculpt && stroke->vc.obact->sculpt->pbvh && sculpt_stroke_get_location(C, stroke, location, window)) {
|
||||
*pixel_radius = project_brush_radius(stroke->vc.rv3d, brush_unprojected_radius(stroke->brush), location, &stroke->mats);
|
||||
if(stroke->vc.obact->sculpt && stroke->vc.obact->sculpt->pbvh &&
|
||||
sculpt_stroke_get_location(C, stroke, location, window)) {
|
||||
*pixel_radius = project_brush_radius(stroke->vc.rv3d,
|
||||
brush_unprojected_radius(stroke->brush),
|
||||
location, &stroke->mats);
|
||||
|
||||
if (*pixel_radius == 0)
|
||||
*pixel_radius = brush_size(stroke->brush);
|
||||
@@ -646,47 +638,52 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
|
||||
glDisable(GL_LINE_SMOOTH);
|
||||
}
|
||||
|
||||
/* Put the location of the next stroke dot into the stroke RNA and apply it to the mesh */
|
||||
static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *event, float mouse_in[2])
|
||||
/* if this is a tablet event, return tablet pressure and set *pen_flip
|
||||
to 1 if the eraser tool is being used, 0 otherwise */
|
||||
static float event_tablet_data(wmEvent *event, int *pen_flip)
|
||||
{
|
||||
Paint *paint = paint_get_active(CTX_data_scene(C)); // XXX
|
||||
Brush *brush = paint_brush(paint); // XXX
|
||||
int erasor = 0;
|
||||
float pressure = 1;
|
||||
|
||||
float mouse[3];
|
||||
|
||||
PointerRNA itemptr;
|
||||
|
||||
float location[3];
|
||||
|
||||
float pressure;
|
||||
int pen_flip;
|
||||
|
||||
ViewContext vc; // XXX
|
||||
|
||||
PaintStroke *stroke = op->customdata;
|
||||
|
||||
view3d_set_viewcontext(C, &vc); // XXX
|
||||
|
||||
/* Tablet */
|
||||
if(event->custom == EVT_DATA_TABLET) {
|
||||
wmTabletData *wmtab= event->customdata;
|
||||
|
||||
erasor = (wmtab->Active == EVT_TABLET_ERASER);
|
||||
pressure = (wmtab->Active != EVT_TABLET_NONE) ? wmtab->Pressure : 1;
|
||||
pen_flip = (wmtab->Active == EVT_TABLET_ERASER);
|
||||
}
|
||||
else {
|
||||
pressure = 1;
|
||||
pen_flip = 0;
|
||||
}
|
||||
|
||||
// XXX: temporary check for sculpt mode until things are more unified
|
||||
if (vc.obact->sculpt) {
|
||||
if(pen_flip)
|
||||
(*pen_flip) = erasor;
|
||||
|
||||
return pressure;
|
||||
}
|
||||
|
||||
/* Put the location of the next stroke dot into the stroke RNA and apply it to the mesh */
|
||||
static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *event, float mouse_in[2])
|
||||
{
|
||||
Paint *paint = paint_get_active(CTX_data_scene(C));
|
||||
Brush *brush = paint_brush(paint);
|
||||
PaintStroke *stroke = op->customdata;
|
||||
float mouse[3];
|
||||
PointerRNA itemptr;
|
||||
float location[3];
|
||||
float pressure;
|
||||
int pen_flip;
|
||||
|
||||
/* see if tablet affects event */
|
||||
pressure = event_tablet_data(event, &pen_flip);
|
||||
|
||||
/* TODO: as sculpt and other paint modes are unified, this
|
||||
separation will go away */
|
||||
if(stroke->vc.obact->sculpt) {
|
||||
float delta[3];
|
||||
|
||||
brush_jitter_pos(brush, mouse_in, mouse);
|
||||
|
||||
// XXX: meh, this is round about because brush_jitter_pos isn't written in the best way to be reused here
|
||||
if (brush->flag & BRUSH_JITTER_PRESSURE) {
|
||||
/* XXX: meh, this is round about because
|
||||
brush_jitter_pos isn't written in the best way to
|
||||
be reused here */
|
||||
if(brush->flag & BRUSH_JITTER_PRESSURE) {
|
||||
sub_v3_v3v3(delta, mouse, mouse_in);
|
||||
mul_v3_fl(delta, pressure);
|
||||
add_v3_v3v3(mouse, mouse_in, delta);
|
||||
@@ -695,7 +692,7 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *ev
|
||||
else
|
||||
copy_v3_v3(mouse, mouse_in);
|
||||
|
||||
/* XXX: can remove the if statement once all modes have this */
|
||||
/* TODO: can remove the if statement once all modes have this */
|
||||
if(stroke->get_location)
|
||||
stroke->get_location(C, stroke, location, mouse);
|
||||
else
|
||||
@@ -704,10 +701,10 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *ev
|
||||
/* Add to stroke */
|
||||
RNA_collection_add(op->ptr, "stroke", &itemptr);
|
||||
|
||||
RNA_float_set_array(&itemptr, "location", location);
|
||||
RNA_float_set_array(&itemptr, "mouse", mouse);
|
||||
RNA_boolean_set (&itemptr, "pen_flip", pen_flip);
|
||||
RNA_float_set (&itemptr, "pressure", pressure);
|
||||
RNA_float_set_array(&itemptr, "location", location);
|
||||
RNA_float_set_array(&itemptr, "mouse", mouse);
|
||||
RNA_boolean_set(&itemptr, "pen_flip", pen_flip);
|
||||
RNA_float_set(&itemptr, "pressure", pressure);
|
||||
|
||||
stroke->last_mouse_position[0] = mouse[0];
|
||||
stroke->last_mouse_position[1] = mouse[1];
|
||||
@@ -769,15 +766,9 @@ static int paint_space_stroke(bContext *C, wmOperator *op, wmEvent *event, const
|
||||
if(length > FLT_EPSILON) {
|
||||
int steps;
|
||||
int i;
|
||||
float pressure = 1;
|
||||
|
||||
// XXX duplicate code
|
||||
if(event->custom == EVT_DATA_TABLET) {
|
||||
wmTabletData *wmtab= event->customdata;
|
||||
if(wmtab->Active != EVT_TABLET_NONE)
|
||||
pressure = brush_use_size_pressure(stroke->brush) ? wmtab->Pressure : 1;
|
||||
}
|
||||
float pressure;
|
||||
|
||||
pressure = event_tablet_data(event, NULL);
|
||||
scale = (brush_size(stroke->brush)*pressure*stroke->brush->spacing/50.0f) / length;
|
||||
mul_v2_fl(vec, scale);
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "RNA_define.h"
|
||||
|
||||
#include "BIF_gl.h"
|
||||
/* TODO: remove once projectf goes away */
|
||||
#include "BIF_glutil.h"
|
||||
|
||||
#include "RE_shader_ext.h"
|
||||
|
||||
@@ -35,6 +37,19 @@
|
||||
|
||||
#include "paint_intern.h"
|
||||
|
||||
/* convert a point in model coordinates to 2D screen coordinates */
|
||||
/* TODO: can be deleted once all calls are replaced with
|
||||
view3d_project_float() */
|
||||
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;
|
||||
}
|
||||
|
||||
float paint_calc_object_space_radius(ViewContext *vc, float center[3],
|
||||
float pixel_radius)
|
||||
{
|
||||
|
||||
@@ -59,7 +59,6 @@
|
||||
#include "BKE_paint.h"
|
||||
#include "BKE_report.h"
|
||||
|
||||
#include "BIF_gl.h"
|
||||
#include "BIF_glutil.h"
|
||||
|
||||
#include "WM_api.h"
|
||||
@@ -84,10 +83,6 @@
|
||||
#include <omp.h>
|
||||
#endif
|
||||
|
||||
/* ==== FORWARD DEFINITIONS =====
|
||||
*
|
||||
*/
|
||||
|
||||
void ED_sculpt_force_update(bContext *C)
|
||||
{
|
||||
Object *ob= CTX_data_active_object(C);
|
||||
@@ -151,10 +146,6 @@ int sculpt_modifiers_active(Scene *scene, Object *ob)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ===== STRUCTS =====
|
||||
*
|
||||
*/
|
||||
|
||||
typedef enum StrokeFlags {
|
||||
CLIP_X = 1,
|
||||
CLIP_Y = 2,
|
||||
@@ -225,22 +216,6 @@ typedef struct StrokeCache {
|
||||
float plane_trim_squared;
|
||||
} StrokeCache;
|
||||
|
||||
/* ===== OPENGL =====
|
||||
*
|
||||
* Simple functions to get data from the GL
|
||||
*/
|
||||
|
||||
/* Convert a point in model coordinates to 2D screen coordinates. */
|
||||
static 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;
|
||||
}
|
||||
|
||||
/*** BVH Tree ***/
|
||||
|
||||
/* Get a screen-space rectangle of the modified area */
|
||||
|
||||
@@ -55,7 +55,6 @@ void sculpt_radialcontrol_start(int mode);
|
||||
struct MultiresModifierData *sculpt_multires_active(struct Scene *scene, struct Object *ob);
|
||||
|
||||
struct Brush *sculptmode_brush(void);
|
||||
//void do_symmetrical_brush_actions(struct Sculpt *sd, struct wmOperator *wm, struct BrushAction *a, short *, short *);
|
||||
|
||||
void sculpt(Sculpt *sd);
|
||||
|
||||
@@ -70,9 +69,6 @@ void sculpt_stroke_apply(struct Sculpt *sd, struct SculptStroke *);
|
||||
void sculpt_stroke_apply_all(struct Sculpt *sd, struct SculptStroke *);
|
||||
int sculpt_stroke_get_location(bContext *C, struct PaintStroke *stroke, float out[3], float mouse[2]);
|
||||
|
||||
/* Partial Mesh Visibility */
|
||||
void sculptmode_pmv(int mode);
|
||||
|
||||
/* Undo */
|
||||
|
||||
typedef struct SculptUndoNode {
|
||||
@@ -110,6 +106,4 @@ void sculpt_undo_push_end(void);
|
||||
int sculpt_modifiers_active(Scene *scene, Object *ob);
|
||||
void sculpt_vertcos_to_key(Object *ob, KeyBlock *kb, float (*vertCos)[3]);
|
||||
|
||||
void brush_jitter_pos(struct Brush *brush, float *pos, float *jitterpos);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user