[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [52129] trunk/blender/source/blender/ editors/gpencil: Whitespace tweaks and Bugfixes
Joshua Leung
aligorith at gmail.com
Mon Nov 12 04:26:41 CET 2012
Revision: 52129
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52129
Author: aligorith
Date: 2012-11-12 03:26:40 +0000 (Mon, 12 Nov 2012)
Log Message:
-----------
Whitespace tweaks and Bugfixes
* Fixed memory leak, where temp buffers for tGpTimingData were not freed
* Fixed crash when there was no active object when converting to paths
Modified Paths:
--------------
trunk/blender/source/blender/editors/gpencil/gpencil_edit.c
trunk/blender/source/blender/editors/gpencil/gpencil_paint.c
Modified: trunk/blender/source/blender/editors/gpencil/gpencil_edit.c
===================================================================
--- trunk/blender/source/blender/editors/gpencil/gpencil_edit.c 2012-11-12 03:23:47 UTC (rev 52128)
+++ trunk/blender/source/blender/editors/gpencil/gpencil_edit.c 2012-11-12 03:26:40 UTC (rev 52129)
@@ -471,7 +471,7 @@
mvalf[1] = (float)pt->y / 100.0f * ar->winy;
}
}
-
+
/* convert screen coordinate to 3d coordinates
* - method taken from editview.c - mouse_cursor()
*/
@@ -504,19 +504,22 @@
double inittime;
} tGpTimingData;
+/* init point buffers for timing data */
static void _gp_timing_data_set_nbr(tGpTimingData *gtd, int nbr)
{
float *tmp;
BLI_assert(nbr > gtd->num_points);
-
+
+ /* distances */
tmp = gtd->dists;
gtd->dists = MEM_callocN(sizeof(float) * nbr, __func__);
if (tmp) {
memcpy(gtd->dists, tmp, sizeof(float) * gtd->num_points);
MEM_freeN(tmp);
}
-
+
+ /* times */
tmp = gtd->times;
gtd->times = MEM_callocN(sizeof(float) * nbr, __func__);
if (tmp) {
@@ -527,6 +530,7 @@
gtd->num_points = nbr;
}
+/* add stroke point to timing buffers */
static void gp_timing_data_add_point(tGpTimingData *gtd, double stroke_inittime, float time, float delta_dist)
{
if (time < 0.0f) {
@@ -534,13 +538,16 @@
gtd->tot_time = -(gtd->times[gtd->cur_point] = -(((float)(stroke_inittime - gtd->inittime)) + time));
gtd->gap_tot_time += gtd->times[gtd->cur_point] - gtd->times[gtd->cur_point - 1];
}
- else
+ else {
gtd->tot_time = (gtd->times[gtd->cur_point] = (((float)(stroke_inittime - gtd->inittime)) + time));
- gtd->dists[gtd->cur_point] = (gtd->tot_dist += delta_dist);
+ }
+
+ gtd->tot_dist += delta_dist;
+ gtd->dists[gtd->cur_point] = gtd->tot_dist;
gtd->cur_point++;
}
-/* In frames! Binary search for FCurve keys have a threshold of 0.01, so we can’t set
+/* In frames! Binary search for FCurve keys have a threshold of 0.01, so we can't set
* arbitrarily close points - this is esp. important with NoGaps mode!
*/
#define MIN_TIME_DELTA 0.02f
@@ -550,7 +557,7 @@
float tot_gaps_time, float delta_time, float *next_delta_time)
{
int j;
-
+
for (j = idx + 1; j < gtd->num_points; j++) {
if (gtd->times[j] < 0) {
gtd->times[j] = -gtd->times[j];
@@ -572,10 +579,12 @@
/* This code ensures that if the first gaps have been shorter than average gap_duration,
* next gaps will tend to be longer (i.e. try to recover the lateness), and vice-versa!
*/
- delta = delta_time - (gtd->gap_duration * *nbr_done_gaps);
+ delta = delta_time - (gtd->gap_duration * (*nbr_done_gaps));
+
/* Clamp min between [-gap_randomness, 0.0], with lower delta giving higher min */
min = -gtd->gap_randomness - delta;
CLAMP(min, -gtd->gap_randomness, 0.0f);
+
/* Clamp max between [0.0, gap_randomness], with lower delta giving higher max */
max = gtd->gap_randomness - delta;
CLAMP(max, 0.0f, gtd->gap_randomness);
@@ -655,11 +664,11 @@
/* This one should *never* be negative! */
end_stroke_time = time_start + ((gtd->times[end_stroke_idx] + delta_time) / gtd->tot_time * time_range);
}
-
+
/* Simple proportional stuff... */
cu->ctime = gtd->dists[i] / gtd->tot_dist * cu->pathlen;
cfra = time_start + ((gtd->times[i] + delta_time) / gtd->tot_time * time_range);
-
+
/* And now, the checks about timing... */
if (i == start_stroke_idx) {
/* If first point of a stroke, be sure it's enough ahead of last valid keyframe, and
@@ -709,45 +718,44 @@
FCurve *fcu;
PointerRNA ptr;
PropertyRNA *prop = NULL;
-
int nbr_gaps = 0, i;
-
+
if (gtd->mode == GP_STROKECONVERT_TIMING_NONE)
return;
-
+
/* gap_duration and gap_randomness are in frames, but we need seconds!!! */
gtd->gap_duration = FRA2TIME(gtd->gap_duration);
gtd->gap_randomness = FRA2TIME(gtd->gap_randomness);
-
+
/* Enable path! */
cu->flag |= CU_PATH;
cu->pathlen = gtd->frame_range;
-
- /* Get or create default action to add F-Curve+keyframe to */
- act = verify_adt_action((ID*)cu, TRUE);
- /* Create RNA stuff */
- RNA_id_pointer_create((ID*)cu, &ptr);
+
+ /* Get RNA pointer to read/write path time values */
+ RNA_id_pointer_create((ID *)cu, &ptr);
prop = RNA_struct_find_property(&ptr, "eval_time");
- /* Get or create fcurve */
+
+ /* Ensure we have an F-Curve to add keyframes to */
+ act = verify_adt_action((ID *)cu, TRUE);
fcu = verify_fcurve(act, NULL, &ptr, "eval_time", 0, TRUE);
-
+
if (G.debug & G_DEBUG) {
printf("%s: tot len: %f\t\ttot time: %f\n", __func__, gtd->tot_dist, gtd->tot_time);
for (i = 0; i < gtd->num_points; i++) {
printf("\tpoint %d:\t\tlen: %f\t\ttime: %f\n", i, gtd->dists[i], gtd->times[i]);
}
}
-
+
if (gtd->mode == GP_STROKECONVERT_TIMING_LINEAR) {
float cfra;
-
+
/* Linear extrapolation! */
fcu->extend = FCURVE_EXTRAPOLATE_LINEAR;
-
+
cu->ctime = 0.0f;
cfra = (float)gtd->start_frame;
insert_keyframe_direct(reports, ptr, prop, fcu, cfra, INSERTKEY_FAST);
-
+
cu->ctime = cu->pathlen;
if (gtd->realtime) {
cfra += (float)TIME2FRA(gtd->tot_time); /* Seconds to frames */
@@ -760,34 +768,33 @@
else {
/* Use actual recorded timing! */
float time_range;
-
+
/* CustomGaps specific */
float tot_gaps_time = 0.0f;
-
- /* Pre-process gaps, in case we don't want to keep their org timing */
+
+ /* Pre-process gaps, in case we don't want to keep their original timing */
if (gtd->mode == GP_STROKECONVERT_TIMING_CUSTOMGAP) {
gp_stroke_path_animation_preprocess_gaps(gtd, &nbr_gaps, &tot_gaps_time);
}
-
+
if (gtd->realtime) {
time_range = (float)TIME2FRA(gtd->tot_time); /* Seconds to frames */
}
else {
time_range = (float)(gtd->end_frame - gtd->start_frame);
}
-
+
if (G.debug & G_DEBUG) {
- printf("Starting keying!\n");
+ printf("GP Stroke Path Conversion: Starting keying!\n");
}
-
+
gp_stroke_path_animation_add_keyframes(reports, ptr, prop, fcu, cu, gtd, time_range,
nbr_gaps, tot_gaps_time);
-
}
-
+
/* As we used INSERTKEY_FAST mode, we need to recompute all curve's handles now */
calchandles_fcurve(fcu);
-
+
if (G.debug & G_DEBUG) {
printf("%s: \ntot len: %f\t\ttot time: %f\n", __func__, gtd->tot_dist, gtd->tot_time);
for (i = 0; i < gtd->num_points; i++) {
@@ -795,11 +802,11 @@
}
printf("\n\n");
}
-
+
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
-
+
/* send updates */
- DAG_id_tag_update((ID*)cu, 0);
+ DAG_id_tag_update(&cu->id, 0);
}
#undef MIN_TIME_DELTA
@@ -813,14 +820,15 @@
float minmax_weights[2], float rad_fac, int stitch, tGpTimingData *gtd)
{
bGPDspoint *pt;
- Nurb *nu = curnu ? *curnu : NULL;
+ Nurb *nu = (curnu) ? *curnu : NULL;
BPoint *bp, *prev_bp = NULL;
+ const int do_gtd = (gtd->mode != GP_STROKECONVERT_TIMING_NONE);
int i, old_nbp = 0;
- const int do_gtd = (gtd->mode != GP_STROKECONVERT_TIMING_NONE);
/* create new 'nurb' or extend current one within the curve */
if (nu) {
old_nbp = nu->pntsu;
+
/* If stitch, the first point of this stroke is already present in current nu.
* Else, we have to add to additional points to make the zero-radius link between strokes.
*/
@@ -837,9 +845,9 @@
nu->resolu = cu->resolu;
nu->resolv = cu->resolv;
nu->knotsu = NULL;
-
+
nu->bp = (BPoint *)MEM_callocN(sizeof(BPoint) * nu->pntsu, "bpoints");
-
+
stitch = FALSE; /* Security! */
}
@@ -861,11 +869,12 @@
float delta_time;
prev_bp = NULL;
- if (old_nbp > 1 && gps->prev && gps->prev->totpoints > 1) {
+ if ((old_nbp > 1) && gps->prev && (gps->prev->totpoints > 1)) {
/* Only use last curve segment if previous stroke was not a single-point one! */
prev_bp = nu->bp + old_nbp - 2;
}
bp = nu->bp + old_nbp - 1;
+
/* XXX We do this twice... Not sure it's worth to bother about this! */
gp_strokepoint_convertcoords(C, gps, gps->points, p, subrect);
if (prev_bp) {
@@ -874,6 +883,7 @@
else {
interp_v3_v3v3(p1, bp->vec, p, GAP_DFAC);
}
+
if (gps->totpoints > 1) {
/* XXX We do this twice... Not sure it's worth to bother about this! */
gp_strokepoint_convertcoords(C, gps, gps->points + 1, next_p, subrect);
@@ -882,7 +892,7 @@
else {
interp_v3_v3v3(p2, p, bp->vec, GAP_DFAC);
}
-
+
/* First point */
bp++;
copy_v3_v3(bp->vec, p1);
@@ -898,7 +908,7 @@
}
gp_timing_data_add_point(gtd, gtd->inittime, delta_time, len_v3v3((bp - 1)->vec, p1));
}
-
+
/* Second point */
bp++;
copy_v3_v3(bp->vec, p2);
@@ -915,25 +925,26 @@
}
gp_timing_data_add_point(gtd, gps->inittime, delta_time, len_v3v3(p1, p2));
}
-
+
old_nbp += 2;
}
if (old_nbp && do_gtd) {
prev_bp = nu->bp + old_nbp - 1;
}
+
/* add points */
- for (i = stitch ? 1 : 0, pt = gps->points + (stitch ? 1 : 0), bp = nu->bp + old_nbp;
+ for (i = (stitch) ? 1 : 0, pt = gps->points + ((stitch) ? 1 : 0), bp = nu->bp + old_nbp;
i < gps->totpoints;
i++, pt++, bp++)
{
float p3d[3];
float width = pt->pressure * gpl->thickness * WIDTH_CORR_FAC;
-
+
/* get coordinates to add at */
gp_strokepoint_convertcoords(C, gps, pt, p3d, subrect);
copy_v3_v3(bp->vec, p3d);
bp->vec[3] = 1.0f;
-
+
/* set settings */
bp->f1 = SELECT;
bp->radius = width * rad_fac;
@@ -945,14 +956,14 @@
else if (bp->weight > minmax_weights[1]) {
minmax_weights[1] = bp->weight;
}
-
+
/* Update timing data */
if (do_gtd) {
- gp_timing_data_add_point(gtd, gps->inittime, pt->time, prev_bp ? len_v3v3(prev_bp->vec, p3d) : 0.0f);
+ gp_timing_data_add_point(gtd, gps->inittime, pt->time, (prev_bp) ? len_v3v3(prev_bp->vec, p3d) : 0.0f);
}
prev_bp = bp;
}
-
+
/* add nurb to curve */
if (!curnu || !*curnu) {
BLI_addtail(&cu->nurb, nu);
@@ -960,7 +971,7 @@
if (curnu) {
*curnu = nu;
}
-
+
BKE_nurb_knot_calc_u(nu);
}
@@ -968,7 +979,7 @@
{
View3D *v3d = CTX_wm_view3d(C);
ARegion *ar = CTX_wm_region(C);
-
+
if (v3d) {
RegionView3D *rv3d = ar->regiondata;
@@ -979,7 +990,7 @@
return 1;
}
}
-
+
return 0;
}
@@ -988,12 +999,12 @@
float minmax_weights[2], float rad_fac, int stitch, tGpTimingData *gtd)
{
bGPDspoint *pt;
- Nurb *nu = curnu ? *curnu : NULL;
+ Nurb *nu = (curnu) ? *curnu : NULL;
BezTriple *bezt, *prev_bezt = NULL;
int i, tot, old_nbezt = 0;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list