[Bf-blender-cvs] [3d38e0e] PSketch: PSculpt: Code Cleanup - Unify the "pso vs data" divide
Joshua Leung
noreply at git.blender.org
Sun Jan 31 14:29:38 CET 2016
Commit: 3d38e0e22c9f12eb749ee243a697a0c4f0ecb86d
Author: Joshua Leung
Date: Mon Feb 1 01:46:37 2016 +1300
Branches: PSketch
https://developer.blender.org/rB3d38e0e22c9f12eb749ee243a697a0c4f0ecb86d
PSculpt: Code Cleanup - Unify the "pso vs data" divide
===================================================================
M source/blender/editors/armature/pose_sculpt.c
===================================================================
diff --git a/source/blender/editors/armature/pose_sculpt.c b/source/blender/editors/armature/pose_sculpt.c
index 3ca427b..8ec227d 100644
--- a/source/blender/editors/armature/pose_sculpt.c
+++ b/source/blender/editors/armature/pose_sculpt.c
@@ -223,35 +223,6 @@ static void psculpt_brush_header_info(bContext *C)
/* Defines ------------------------------------------------ */
-/* Struct passed to all callback functions */
-typedef struct tPSculptContext {
- /* Relevant context data */
- ViewContext vc;
-
- ARegion *ar;
- View3D *v3d;
- RegionView3D *rv3d;
-
- Scene *scene;
- Object *ob;
-
- /* General Brush Data */
- PSculptBrushData *brush; /* active brush */
-
- const float *mval; /* mouse coordinates (pixels) */
- float rad; /* radius of brush (pixels) */
- float dist; /* distance from brush to item being sculpted (pixels) */
- float fac; /* brush strength (factor 0-1) */
-
- short invert; /* "subtract" mode? */
- bool is_first; /* first run through? */
-
- /* Brush Specific Data */
- float dvec[3]; /* mouse travel vector, or something else */
- float rmat[3][3]; /* rotation matrix to apply to all bones (e.g. trackball) */
-} tPSculptContext;
-
-
/* Affected bones */
typedef struct tAffectedBone {
struct tAffectedBone *next, *prev;
@@ -269,12 +240,33 @@ typedef struct tAffectedBone {
/* Pose Sculpting brush operator data */
typedef struct tPoseSculptingOp {
- tPSculptContext data; /* "context" data to pass to brush callbacks later */
+ /* General Context Data -------------- */
+ ViewContext vc;
+
+ ARegion *ar;
+ View3D *v3d;
+ RegionView3D *rv3d;
Scene *scene;
Object *ob;
+ /* Brush Runtime Data ---------------- */
+
+ /* General Brush Data */
+ PSculptBrushData *brush; /* active brush */
+ ePSculptBrushType brush_type; /* type of brush */
+
+ bool invert; /* does brush have the opposite effect */
+
+ /* Brush Specific Data */
+ float dvec[3]; /* mouse travel vector, or something else */
+ float rmat[3][3]; /* rotation matrix to apply to all bones (e.g. trackball) */
+
+ /* Event Handling -------------------- */
+
+ float mval[2]; /* current mouse position */
float lastmouse[2]; /* previous mouse position */
+
float pressure; /* current mouse pressure */
bool is_first; /* is this the first time we're applying anything? */
@@ -282,6 +274,8 @@ typedef struct tPoseSculptingOp {
wmTimer *timer; /* timer for in-place accumulation of brush effect */
+ /* Bones + Keying ------------------- */
+
GHash *affected_bones; /* list of bones affected by brush */
KeyingSet *ks; /* keyingset to use */
@@ -289,46 +283,24 @@ typedef struct tPoseSculptingOp {
} tPoseSculptingOp;
/* Callback Function Signature */
-typedef void (*PSculptBrushCallback)(tPoseSculptingOp *pso, bPoseChannel *pchan, float sco1[2], float sco2[2]);
-
-/* Init ------------------------------------------------ */
-
-static void psculpt_init_context_data(bContext *C, tPSculptContext *data)
-{
- memset(data, 0, sizeof(*data));
-
- data->scene = CTX_data_scene(C);
- data->ob = CTX_data_active_object(C);
-
- data->brush = psculpt_get_brush(data->scene);
-}
+typedef void (*PSculptBrushCallback)(tPoseSculptingOp *pso, bPoseChannel *pchan, float dist);
-static void psculpt_init_view3d_data(bContext *C, tPSculptContext *data)
-{
- /* init context data */
- psculpt_init_context_data(C, data);
-
- /* hook up 3D View context */
- view3d_set_viewcontext(C, &data->vc);
-}
/* Brush Utilities ---------------------------------------- */
-static float psculpt_brush_calc_influence(tPoseSculptingOp *pso)
+static float psculpt_brush_calc_influence(tPoseSculptingOp *pso, float dist)
{
- tPSculptContext *data = &pso->data;
- PSculptBrushData *brush = data->brush;
+ PSculptBrushData *brush = pso->brush;
float fac = brush->strength;
/* use pressure to modulate strength */
- if (brush->flag & PSCULPT_BRUSH_FLAG_USE_PRESSURE)
- {
+ if (brush->flag & PSCULPT_BRUSH_FLAG_USE_PRESSURE) {
fac *= pso->pressure;
}
/* use distance falloff */
if (brush->flag & PSCULPT_BRUSH_FLAG_USE_FALLOFF) {
- fac *= fabsf(1.0f - data->dist / data->rad);
+ fac *= fabsf(1.0f - dist / brush->size);
}
/* return the new influence */
@@ -779,12 +751,10 @@ static void free_affected_bone(void *tab_p)
/* Brushes ------------------------------------------------ */
/* change selection status of bones - used to define masks */
-static void psculpt_brush_select_apply(tPoseSculptingOp *pso, bPoseChannel *pchan, float UNUSED(sco1[2]), float UNUSED(sco2[2]))
+static void psculpt_brush_select_apply(tPoseSculptingOp *pso, bPoseChannel *pchan, float UNUSED(dist))
{
- tPSculptContext *data = &pso->data;
-
if (pchan->bone) {
- if (data->invert)
+ if (pso->invert)
pchan->bone->flag &= ~BONE_SELECTED;
else
pchan->bone->flag |= BONE_SELECTED;
@@ -794,7 +764,7 @@ static void psculpt_brush_select_apply(tPoseSculptingOp *pso, bPoseChannel *pcha
/* .......................... */
/* "Smooth" brush */
-static void psculpt_brush_smooth_apply(tPoseSculptingOp *pso, bPoseChannel *pchan, float sco1[2], float sco2[2])
+static void psculpt_brush_smooth_apply(tPoseSculptingOp *pso, bPoseChannel *pchan, float dist)
{
}
@@ -802,20 +772,19 @@ static void psculpt_brush_smooth_apply(tPoseSculptingOp *pso, bPoseChannel *pcha
/* .......................... */
/* "Grab" brush - Translate bone */
-static void psculpt_brush_grab_apply(tPoseSculptingOp *pso, bPoseChannel *pchan, float UNUSED(sco1[2]), float UNUSED(sco2[2]))
+static void psculpt_brush_grab_apply(tPoseSculptingOp *pso, bPoseChannel *pchan, float dist)
{
- tPSculptContext *data = &pso->data;
- PSculptBrushData *brush = data->brush;
+ PSculptBrushData *brush = pso->brush;
float imat[4][4], mat[4][4];
float cvec[3];
float fac;
/* strength of push */
- fac = psculpt_brush_calc_influence(pso);
- if (data->invert) fac = -fac;
+ fac = psculpt_brush_calc_influence(pso, dist);
+ if (pso->invert) fac = -fac;
if (brush->flag & PSCULPT_BRUSH_FLAG_GRAB_INITIAL) {
- tAffectedBone *tab = verify_bone_is_affected(pso, pchan, data->is_first);
+ tAffectedBone *tab = verify_bone_is_affected(pso, pchan, pso->is_first);
/* if one couldn't be found or added, then it didn't exist the first time round,
* so we shouldn't proceed (to avoid clobbering additional bones)
@@ -823,7 +792,7 @@ static void psculpt_brush_grab_apply(tPoseSculptingOp *pso, bPoseChannel *pchan,
if (tab == NULL) {
return;
}
- else if (data->is_first) {
+ else if (pso->is_first) {
/* store factor for later */
tab->fac = fac;
}
@@ -834,11 +803,11 @@ static void psculpt_brush_grab_apply(tPoseSculptingOp *pso, bPoseChannel *pchan,
}
/* compute inverse matrix to convert from screen-space to bone space */
- mul_m4_m4m4(mat, data->ob->obmat, pchan->bone->arm_mat);
+ mul_m4_m4m4(mat, pso->ob->obmat, pchan->bone->arm_mat);
invert_m4_m4(imat, mat);
/* apply deforms to bone locations only based on amount mouse moves */
- copy_v3_v3(cvec, data->dvec);
+ copy_v3_v3(cvec, pso->dvec);
mul_mat3_m4_v3(imat, cvec);
mul_v3_fl(cvec, fac);
@@ -862,9 +831,8 @@ static void psculpt_brush_grab_apply(tPoseSculptingOp *pso, bPoseChannel *pchan,
/* "Adjust" Brush - Compute transform to apply to all bones inside the brush */
static void psculpt_brush_calc_trackball(tPoseSculptingOp *pso)
{
- tPSculptContext *data = &pso->data;
- PSculptBrushData *brush = data->brush;
- RegionView3D *rv3d = data->rv3d;
+ PSculptBrushData *brush = pso->brush;
+ RegionView3D *rv3d = pso->rv3d;
float smat[3][3], totmat[3][3];
float mat[3][3], refmat[3][3];
@@ -881,8 +849,8 @@ static void psculpt_brush_calc_trackball(tPoseSculptingOp *pso)
normalize_v3(axis2);
/* From InputTrackBall() in transform_input.c */
- angles[0] = (float)(pso->lastmouse[1] - data->mval[1]);
- angles[1] = (float)(data->mval[0] - pso->lastmouse[0]);
+ angles[0] = (float)(pso->lastmouse[1] - pso->mval[1]);
+ angles[1] = (float)(pso->mval[0] - pso->lastmouse[0]);
mul_v2_fl(angles, 0.01f); /* (mi->factor = 0.01f) */
@@ -894,24 +862,21 @@ static void psculpt_brush_calc_trackball(tPoseSculptingOp *pso)
/* Adjust strength of effect */
unit_m3(refmat);
- interp_m3_m3m3(data->rmat, refmat, mat, brush->strength);
+ interp_m3_m3m3(pso->rmat, refmat, mat, brush->strength);
}
/* "Adjust" Brush - i.e. a simple trackball transform */
-// TODO: on root bones, don't do trackball... do grab instead?
-static void psculpt_brush_adjust_apply(tPoseSculptingOp *pso, bPoseChannel *pchan, float UNUSED(sco1[2]), float UNUSED(sco2[2]))
+static void psculpt_brush_adjust_apply(tPoseSculptingOp *pso, bPoseChannel *pchan, float UNUSED(dist))
{
- tPSculptContext *data = &pso->data;
- pchan_do_rotate(data->ob, pchan, data->rmat);
+ pchan_do_rotate(pso->ob, pchan, pso->rmat);
}
/* .......................... */
/* "Curl" brush - Rotate bone around its non-primary axes */
-static void psculpt_brush_curl_apply(tPoseSculptingOp *pso, bPoseChannel *pchan, float UNUSED(sco1[2]), float UNUSED(sco2[2]))
+static void psculpt_brush_curl_apply(tPoseSculptingOp *pso, bPoseChannel *pchan, float dist)
{
- tPSculptContext *data = &pso->data;
- PSculptBrushData *brush = data->brush;
+ PSculptBrushData *brush = pso->brush;
short locks = pchan->protectflag;
float eul[3] = {0.0f};
float angle = 0.0f;
@@ -925,10 +890,10 @@ static void psculpt_brush_curl_apply(tPoseSculptingOp *pso, bPoseChannel *pchan,
* however is much too strong for controllability. So, leaving it as-is.
* - Rotations are internally represented using radians, which are very sensitive
*/
- angle = psculpt_brush_calc_influence(pso); //printf("%f ", angle);
- angle = DEG2RAD(angle); //printf("%f \n", angle);
+ angle = psculpt_brush_calc_influence(pso, dist); //printf("%f ", angle);
+ angle = DEG2RAD(angle); //printf("%f \n", angle);
- if (data->invert) angle = -angle;
+ if (pso->invert) angle = -angle;
/* rotate on x/z axes, whichever isn't locked */
if (ELEM(brush->xzMode, PSCULPT_BRUSH_DO_XZ, PSCULPT_BRUSH_DO_X) &&
@@ -952,9 +917,8 @@ stat
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list