[Bf-blender-cvs] [ef22ff0f798] greasepencil-object: GPencil: Redesign Grab evaluation transform calculation
Antonioya
noreply at git.blender.org
Thu May 23 18:54:42 CEST 2019
Commit: ef22ff0f7986fefebc5b4c3ad86763196ce30b38
Author: Antonioya
Date: Thu May 23 17:01:14 2019 +0200
Branches: greasepencil-object
https://developer.blender.org/rBef22ff0f7986fefebc5b4c3ad86763196ce30b38
GPencil: Redesign Grab evaluation transform calculation
Still problems with single points strokes
===================================================================
M source/blender/editors/gpencil/gpencil_brush.c
===================================================================
diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index f214d11232c..e2771db47d8 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -134,6 +134,9 @@ typedef struct tGP_BrushEditData {
/* - effect vector (e.g. 2D/3D translation for grab brush) */
float dvec[3];
+ /* rotation for derived data */
+ float rot;
+
/* - multiframe falloff factor */
float mf_falloff;
@@ -159,7 +162,7 @@ typedef struct tGP_BrushEditData {
/* Callback for performing some brush operation on a single point */
typedef bool (*GP_BrushApplyCb)(tGP_BrushEditData *gso,
bGPDstroke *gps,
- float rotation[3],
+ float rotation,
int pt_index,
const int radius,
const int co[2]);
@@ -311,7 +314,7 @@ static float gp_brush_influence_calc(tGP_BrushEditData *gso, const int radius, c
* smooth-brush implementation to test the algorithm for stroke smoothing. */
static bool gp_brush_smooth_apply(tGP_BrushEditData *gso,
bGPDstroke *gps,
- float UNUSED(rot[3]),
+ float UNUSED(rot),
int pt_index,
const int radius,
const int co[2])
@@ -350,7 +353,7 @@ static bool gp_brush_smooth_apply(tGP_BrushEditData *gso,
/* Make lines thicker or thinner by the specified amounts */
static bool gp_brush_thickness_apply(tGP_BrushEditData *gso,
bGPDstroke *gps,
- float UNUSED(rot[3]),
+ float UNUSED(rot),
int pt_index,
const int radius,
const int co[2])
@@ -394,7 +397,7 @@ static bool gp_brush_thickness_apply(tGP_BrushEditData *gso,
/* Make color more or less transparent by the specified amounts */
static bool gp_brush_strength_apply(tGP_BrushEditData *gso,
bGPDstroke *gps,
- float UNUSED(rot[3]),
+ float UNUSED(rot),
int pt_index,
const int radius,
const int co[2])
@@ -441,9 +444,7 @@ typedef struct tGPSB_Grab_StrokeData {
/* array of influence weights for each of the included points */
float *weights;
/* angles to calc transformation */
- float *rot_x;
- float *rot_y;
- float *rot_z;
+ float *rot;
/* capacity of the arrays */
int capacity;
@@ -471,9 +472,7 @@ static void gp_brush_grab_stroke_init(tGP_BrushEditData *gso, bGPDstroke *gps)
memset(data->points, 0, sizeof(int) * data->capacity);
memset(data->weights, 0, sizeof(float) * data->capacity);
- memset(data->rot_x, 0, sizeof(float) * data->capacity);
- memset(data->rot_y, 0, sizeof(float) * data->capacity);
- memset(data->rot_z, 0, sizeof(float) * data->capacity);
+ memset(data->rot, 0, sizeof(float) * data->capacity);
}
else {
/* Create new instance */
@@ -484,9 +483,7 @@ static void gp_brush_grab_stroke_init(tGP_BrushEditData *gso, bGPDstroke *gps)
data->points = MEM_callocN(sizeof(int) * data->capacity, "GP Stroke Grab Indices");
data->weights = MEM_callocN(sizeof(float) * data->capacity, "GP Stroke Grab Weights");
- data->rot_x = MEM_callocN(sizeof(float) * data->capacity, "GP Stroke Grab X");
- data->rot_y = MEM_callocN(sizeof(float) * data->capacity, "GP Stroke Grab Y");
- data->rot_z = MEM_callocN(sizeof(float) * data->capacity, "GP Stroke Grab Z");
+ data->rot = MEM_callocN(sizeof(float) * data->capacity, "GP Stroke Grab X");
/* hook up to the cache */
BLI_ghash_insert(gso->stroke_customdata, gps, data);
@@ -496,7 +493,7 @@ static void gp_brush_grab_stroke_init(tGP_BrushEditData *gso, bGPDstroke *gps)
/* store references to stroke points in the initial stage */
static bool gp_brush_grab_store_points(tGP_BrushEditData *gso,
bGPDstroke *gps,
- float rot[3],
+ float rot,
int pt_index,
const int radius,
const int co[2])
@@ -510,9 +507,7 @@ static bool gp_brush_grab_store_points(tGP_BrushEditData *gso,
/* insert this point into the set of affected points */
data->points[data->size] = pt_index;
data->weights[data->size] = inf;
- data->rot_x[data->size] = rot[0];
- data->rot_y[data->size] = rot[1];
- data->rot_z[data->size] = rot[2];
+ data->rot[data->size] = rot;
data->size++;
/* done */
@@ -536,6 +531,16 @@ static void gp_brush_grab_calc_dvec(tGP_BrushEditData *gso)
mval_f[0] = (float)(gso->mval[0] - gso->mval_prev[0]);
mval_f[1] = (float)(gso->mval[1] - gso->mval_prev[1]);
+ /* apply derived data transformation */
+ if (gso->rot != 0.0f) {
+ const float cval = cos(gso->rot);
+ const float sval = sin(gso->rot);
+ float r[2];
+ r[0] = (mval_f[0] * cval) - (mval_f[1] * sval);
+ r[1] = (mval_f[0] * sval) + (mval_f[1] * cval);
+ copy_v2_v2(mval_f, r);
+ }
+
ED_view3d_win_to_delta(gso->ar, mval_f, gso->dvec, zfac);
}
else {
@@ -554,10 +559,6 @@ static void gp_brush_grab_apply_cached(tGP_BrushEditData *gso,
{
tGPSB_Grab_StrokeData *data = BLI_ghash_lookup(gso->stroke_customdata, gps);
int i;
- float loc[3], scale[3];
- float derived_mat[4][4];
- zero_v3(loc);
- ARRAY_SET_ITEMS(scale, 1.0f, 1.0f, 1.0f);
/* Apply dvec to all of the stored points */
for (i = 0; i < data->size; i++) {
@@ -565,21 +566,11 @@ static void gp_brush_grab_apply_cached(tGP_BrushEditData *gso,
float delta[3] = {0.0f};
/* get derived transformation */
- float rot[3];
- float transform[3];
- rot[0] = data->rot_x[i];
- rot[1] = data->rot_y[i];
- rot[2] = data->rot_z[i];
- printf("%f, %f, %f\n", RAD2DEG(rot[0]), RAD2DEG(rot[1]), RAD2DEG(rot[2]));
-
- loc_eul_size_to_mat4(derived_mat, loc, rot, scale);
+ gso->rot = data->rot[i];
gp_brush_grab_calc_dvec(gso);
- mul_v3_mat3_m4v3(transform, derived_mat, gso->dvec);
- print_v3("Dvec", gso->dvec);
- print_v3("Transf", transform);
/* adjust the amount of displacement to apply */
- mul_v3_v3fl(delta, transform, data->weights[i]);
+ mul_v3_v3fl(delta, gso->dvec, data->weights[i]);
float fpt[3];
float save_pt[3];
@@ -607,9 +598,7 @@ static void gp_brush_grab_stroke_free(void *ptr)
/* free arrays */
MEM_SAFE_FREE(data->points);
MEM_SAFE_FREE(data->weights);
- MEM_SAFE_FREE(data->rot_x);
- MEM_SAFE_FREE(data->rot_y);
- MEM_SAFE_FREE(data->rot_z);
+ MEM_SAFE_FREE(data->rot);
/* ... and this item itself, since it was also allocated */
MEM_freeN(data);
@@ -620,7 +609,7 @@ static void gp_brush_grab_stroke_free(void *ptr)
/* NOTE: Depends on gp_brush_grab_calc_dvec() */
static bool gp_brush_push_apply(tGP_BrushEditData *gso,
bGPDstroke *gps,
- float UNUSED(rot[3]),
+ float UNUSED(rot),
int pt_index,
const int radius,
const int co[2])
@@ -687,7 +676,7 @@ static void gp_brush_calc_midpoint(tGP_BrushEditData *gso)
/* Shrink distance between midpoint and this point... */
static bool gp_brush_pinch_apply(tGP_BrushEditData *gso,
bGPDstroke *gps,
- float UNUSED(rot[3]),
+ float UNUSED(rot),
int pt_index,
const int radius,
const int co[2])
@@ -743,7 +732,7 @@ static bool gp_brush_pinch_apply(tGP_BrushEditData *gso,
static bool gp_brush_twist_apply(tGP_BrushEditData *gso,
bGPDstroke *gps,
- float UNUSED(rot[3]),
+ float UNUSED(rot),
int pt_index,
const int radius,
const int co[2])
@@ -825,7 +814,7 @@ static bool gp_brush_twist_apply(tGP_BrushEditData *gso,
/* Apply some random jitter to the point */
static bool gp_brush_randomize_apply(tGP_BrushEditData *gso,
bGPDstroke *gps,
- float UNUSED(rot[3]),
+ float UNUSED(rot),
int pt_index,
const int radius,
const int co[2])
@@ -944,7 +933,7 @@ static bool gp_brush_randomize_apply(tGP_BrushEditData *gso,
/* Change weight paint for vertex groups */
static bool gp_brush_weight_apply(tGP_BrushEditData *gso,
bGPDstroke *gps,
- float UNUSED(rot[3]),
+ float UNUSED(rot),
int pt_index,
const int radius,
const int co[2])
@@ -1175,6 +1164,7 @@ static void gp_brush_clone_adjust(tGP_BrushEditData *gso)
size_t snum;
/* Compute the amount of movement to apply (overwrites dvec) */
+ gso->rot = 0.0f;
gp_brush_grab_calc_dvec(gso);
/* For each of the stored strokes, apply the offset to each point */
@@ -1484,41 +1474,51 @@ static void gpsculpt_brush_init_stroke(tGP_BrushEditData *gso)
}
/* Apply ----------------------------------------------- */
-static void gpsculpt_transform_rot_get(bGPDstroke *gps_derived,
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list