diff options
Diffstat (limited to 'source/blender/editors/curve/editcurve.c')
-rw-r--r-- | source/blender/editors/curve/editcurve.c | 379 |
1 files changed, 186 insertions, 193 deletions
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index 49c75e0b4a1..15f3939b2f6 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -307,12 +307,8 @@ static void keyIndex_delNurb(EditNurb *editnurb, Nurb *nu) static void keyIndex_delNurbList(EditNurb *editnurb, ListBase *nubase) { - Nurb *nu = nubase->first; - - while (nu) { + LISTBASE_FOREACH (Nurb *, nu, nubase) { keyIndex_delNurb(editnurb, nu); - - nu = nu->next; } } @@ -646,250 +642,247 @@ static void calc_shapeKeys(Object *obedit, ListBase *newnurbs) { Curve *cu = (Curve *)obedit->data; - /* are there keys? */ - if (cu->key) { - int a, i; - EditNurb *editnurb = cu->editnurb; - KeyBlock *currkey; - KeyBlock *actkey = BLI_findlink(&cu->key->block, editnurb->shapenr - 1); - BezTriple *bezt, *oldbezt; - BPoint *bp, *oldbp; - Nurb *newnu; - int totvert = BKE_keyblock_curve_element_count(&editnurb->nurbs); + if (cu->key == NULL) { + return; + } + + int a, i; + EditNurb *editnurb = cu->editnurb; + KeyBlock *actkey = BLI_findlink(&cu->key->block, editnurb->shapenr - 1); + BezTriple *bezt, *oldbezt; + BPoint *bp, *oldbp; + Nurb *newnu; + int totvert = BKE_keyblock_curve_element_count(&editnurb->nurbs); - float(*ofs)[3] = NULL; - float *oldkey, *newkey, *ofp; + float(*ofs)[3] = NULL; + float *oldkey, *newkey, *ofp; - /* editing the base key should update others */ - if (cu->key->type == KEY_RELATIVE) { - if (BKE_keyblock_is_basis(cu->key, editnurb->shapenr - 1)) { /* active key is a base */ - int totvec = 0; + /* editing the base key should update others */ + if (cu->key->type == KEY_RELATIVE) { + if (BKE_keyblock_is_basis(cu->key, editnurb->shapenr - 1)) { /* active key is a base */ + int totvec = 0; - /* Calculate needed memory to store offset */ - LISTBASE_FOREACH (Nurb *, nu, &editnurb->nurbs) { + /* Calculate needed memory to store offset */ + LISTBASE_FOREACH (Nurb *, nu, &editnurb->nurbs) { - if (nu->bezt) { - /* Three vects to store handles and one for tilt. */ - totvec += nu->pntsu * 4; - } - else { - totvec += 2 * nu->pntsu * nu->pntsv; - } + if (nu->bezt) { + /* Three vects to store handles and one for tilt. */ + totvec += nu->pntsu * 4; + } + else { + totvec += 2 * nu->pntsu * nu->pntsv; } + } - ofs = MEM_callocN(sizeof(float[3]) * totvec, "currkey->data"); - i = 0; - LISTBASE_FOREACH (Nurb *, nu, &editnurb->nurbs) { - if (nu->bezt) { - bezt = nu->bezt; - a = nu->pntsu; - while (a--) { - oldbezt = getKeyIndexOrig_bezt(editnurb, bezt); + ofs = MEM_callocN(sizeof(float[3]) * totvec, "currkey->data"); + i = 0; + LISTBASE_FOREACH (Nurb *, nu, &editnurb->nurbs) { + if (nu->bezt) { + bezt = nu->bezt; + a = nu->pntsu; + while (a--) { + oldbezt = getKeyIndexOrig_bezt(editnurb, bezt); - if (oldbezt) { - int j; - for (j = 0; j < 3; j++) { - sub_v3_v3v3(ofs[i], bezt->vec[j], oldbezt->vec[j]); - i++; - } - ofs[i][0] = bezt->tilt - oldbezt->tilt; - ofs[i][1] = bezt->radius - oldbezt->radius; + if (oldbezt) { + int j; + for (j = 0; j < 3; j++) { + sub_v3_v3v3(ofs[i], bezt->vec[j], oldbezt->vec[j]); i++; } - else { - i += 4; - } - bezt++; + ofs[i][0] = bezt->tilt - oldbezt->tilt; + ofs[i][1] = bezt->radius - oldbezt->radius; + i++; + } + else { + i += 4; } + bezt++; } - else { - bp = nu->bp; - a = nu->pntsu * nu->pntsv; - while (a--) { - oldbp = getKeyIndexOrig_bp(editnurb, bp); - if (oldbp) { - sub_v3_v3v3(ofs[i], bp->vec, oldbp->vec); - ofs[i + 1][0] = bp->tilt - oldbp->tilt; - ofs[i + 1][1] = bp->radius - oldbp->radius; - } - i += 2; - bp++; + } + else { + bp = nu->bp; + a = nu->pntsu * nu->pntsv; + while (a--) { + oldbp = getKeyIndexOrig_bp(editnurb, bp); + if (oldbp) { + sub_v3_v3v3(ofs[i], bp->vec, oldbp->vec); + ofs[i + 1][0] = bp->tilt - oldbp->tilt; + ofs[i + 1][1] = bp->radius - oldbp->radius; } + i += 2; + bp++; } } } } + } - currkey = cu->key->block.first; - while (currkey) { - const bool apply_offset = (ofs && (currkey != actkey) && - (editnurb->shapenr - 1 == currkey->relative)); - - float *fp = newkey = MEM_callocN(cu->key->elemsize * totvert, "currkey->data"); - ofp = oldkey = currkey->data; - - Nurb *nu = editnurb->nurbs.first; - /* We need to restore to original curve into newnurb, *not* editcurve's nurbs. - * Otherwise, in case we update obdata *without* leaving editmode (e.g. viewport render), - * we would invalidate editcurve. */ - newnu = newnurbs->first; - i = 0; - while (nu) { - if (currkey == actkey) { - const bool restore = actkey != cu->key->refkey; - - if (nu->bezt) { - bezt = nu->bezt; - a = nu->pntsu; - BezTriple *newbezt = newnu->bezt; - while (a--) { - int j; - oldbezt = getKeyIndexOrig_bezt(editnurb, bezt); + LISTBASE_FOREACH (KeyBlock *, currkey, &cu->key->block) { + const bool apply_offset = (ofs && (currkey != actkey) && + (editnurb->shapenr - 1 == currkey->relative)); + + float *fp = newkey = MEM_callocN(cu->key->elemsize * totvert, "currkey->data"); + ofp = oldkey = currkey->data; + + Nurb *nu = editnurb->nurbs.first; + /* We need to restore to original curve into newnurb, *not* editcurve's nurbs. + * Otherwise, in case we update obdata *without* leaving editmode (e.g. viewport render), + * we would invalidate editcurve. */ + newnu = newnurbs->first; + i = 0; + while (nu) { + if (currkey == actkey) { + const bool restore = actkey != cu->key->refkey; - for (j = 0; j < 3; j++, i++) { - copy_v3_v3(&fp[j * 3], bezt->vec[j]); + if (nu->bezt) { + bezt = nu->bezt; + a = nu->pntsu; + BezTriple *newbezt = newnu->bezt; + while (a--) { + int j; + oldbezt = getKeyIndexOrig_bezt(editnurb, bezt); - if (restore && oldbezt) { - copy_v3_v3(newbezt->vec[j], oldbezt->vec[j]); - } - } - fp[9] = bezt->tilt; - fp[10] = bezt->radius; + for (j = 0; j < 3; j++, i++) { + copy_v3_v3(&fp[j * 3], bezt->vec[j]); if (restore && oldbezt) { - newbezt->tilt = oldbezt->tilt; - newbezt->radius = oldbezt->radius; + copy_v3_v3(newbezt->vec[j], oldbezt->vec[j]); } + } + fp[9] = bezt->tilt; + fp[10] = bezt->radius; - fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; - i++; - bezt++; - newbezt++; + if (restore && oldbezt) { + newbezt->tilt = oldbezt->tilt; + newbezt->radius = oldbezt->radius; } - } - else { - bp = nu->bp; - a = nu->pntsu * nu->pntsv; - BPoint *newbp = newnu->bp; - while (a--) { - oldbp = getKeyIndexOrig_bp(editnurb, bp); - copy_v3_v3(fp, bp->vec); + fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; + i++; + bezt++; + newbezt++; + } + } + else { + bp = nu->bp; + a = nu->pntsu * nu->pntsv; + BPoint *newbp = newnu->bp; + while (a--) { + oldbp = getKeyIndexOrig_bp(editnurb, bp); - fp[3] = bp->tilt; - fp[4] = bp->radius; + copy_v3_v3(fp, bp->vec); - if (restore && oldbp) { - copy_v3_v3(newbp->vec, oldbp->vec); - newbp->tilt = oldbp->tilt; - newbp->radius = oldbp->radius; - } + fp[3] = bp->tilt; + fp[4] = bp->radius; - fp += KEYELEM_FLOAT_LEN_BPOINT; - bp++; - newbp++; - i += 2; + if (restore && oldbp) { + copy_v3_v3(newbp->vec, oldbp->vec); + newbp->tilt = oldbp->tilt; + newbp->radius = oldbp->radius; } + + fp += KEYELEM_FLOAT_LEN_BPOINT; + bp++; + newbp++; + i += 2; } } - else { - int index; - const float *curofp; - - if (oldkey) { - if (nu->bezt) { - bezt = nu->bezt; - a = nu->pntsu; + } + else { + int index; + const float *curofp; - while (a--) { - index = getKeyIndexOrig_keyIndex(editnurb, bezt); - if (index >= 0) { - int j; - curofp = ofp + index; + if (oldkey) { + if (nu->bezt) { + bezt = nu->bezt; + a = nu->pntsu; - for (j = 0; j < 3; j++, i++) { - copy_v3_v3(&fp[j * 3], &curofp[j * 3]); + while (a--) { + index = getKeyIndexOrig_keyIndex(editnurb, bezt); + if (index >= 0) { + int j; + curofp = ofp + index; - if (apply_offset) { - add_v3_v3(&fp[j * 3], ofs[i]); - } - } - fp[9] = curofp[9]; - fp[10] = curofp[10]; + for (j = 0; j < 3; j++, i++) { + copy_v3_v3(&fp[j * 3], &curofp[j * 3]); if (apply_offset) { - /* Apply tilt offsets. */ - add_v3_v3(fp + 9, ofs[i]); - i++; + add_v3_v3(&fp[j * 3], ofs[i]); } + } + fp[9] = curofp[9]; + fp[10] = curofp[10]; - fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; + if (apply_offset) { + /* Apply tilt offsets. */ + add_v3_v3(fp + 9, ofs[i]); + i++; } - else { - int j; - for (j = 0; j < 3; j++, i++) { - copy_v3_v3(&fp[j * 3], bezt->vec[j]); - } - fp[9] = bezt->tilt; - fp[10] = bezt->radius; - fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; + fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; + } + else { + int j; + for (j = 0; j < 3; j++, i++) { + copy_v3_v3(&fp[j * 3], bezt->vec[j]); } - bezt++; + fp[9] = bezt->tilt; + fp[10] = bezt->radius; + + fp += KEYELEM_FLOAT_LEN_BEZTRIPLE; } + bezt++; } - else { - bp = nu->bp; - a = nu->pntsu * nu->pntsv; - while (a--) { - index = getKeyIndexOrig_keyIndex(editnurb, bp); + } + else { + bp = nu->bp; + a = nu->pntsu * nu->pntsv; + while (a--) { + index = getKeyIndexOrig_keyIndex(editnurb, bp); - if (index >= 0) { - curofp = ofp + index; - copy_v3_v3(fp, curofp); - fp[3] = curofp[3]; - fp[4] = curofp[4]; + if (index >= 0) { + curofp = ofp + index; + copy_v3_v3(fp, curofp); + fp[3] = curofp[3]; + fp[4] = curofp[4]; - if (apply_offset) { - add_v3_v3(fp, ofs[i]); - add_v3_v3(&fp[3], ofs[i + 1]); - } - } - else { - copy_v3_v3(fp, bp->vec); - fp[3] = bp->tilt; - fp[4] = bp->radius; + if (apply_offset) { + add_v3_v3(fp, ofs[i]); + add_v3_v3(&fp[3], ofs[i + 1]); } - - fp += KEYELEM_FLOAT_LEN_BPOINT; - bp++; - i += 2; } + else { + copy_v3_v3(fp, bp->vec); + fp[3] = bp->tilt; + fp[4] = bp->radius; + } + + fp += KEYELEM_FLOAT_LEN_BPOINT; + bp++; + i += 2; } } } - - nu = nu->next; - newnu = newnu->next; - } - - if (apply_offset) { - /* handles could become malicious after offsets applying */ - calc_keyHandles(&editnurb->nurbs, newkey); } - currkey->totelem = totvert; - if (currkey->data) { - MEM_freeN(currkey->data); - } - currkey->data = newkey; + nu = nu->next; + newnu = newnu->next; + } - currkey = currkey->next; + if (apply_offset) { + /* handles could become malicious after offsets applying */ + calc_keyHandles(&editnurb->nurbs, newkey); } - if (ofs) { - MEM_freeN(ofs); + currkey->totelem = totvert; + if (currkey->data) { + MEM_freeN(currkey->data); } + currkey->data = newkey; + } + + if (ofs) { + MEM_freeN(ofs); } } |