Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/curve/editcurve.c
| Show First 20 Lines • Show All 1,159 Lines • ▼ Show 20 Lines | int ED_curve_updateAnimPaths(Curve *cu) | ||||
| curve_rename_fcurves(cu, &adt->drivers); | curve_rename_fcurves(cu, &adt->drivers); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| /* ********************* LOAD and MAKE *************** */ | /* ********************* LOAD and MAKE *************** */ | ||||
| static int *initialize_index_map(Object *obedit, int *r_old_totvert) | static int *initialize_index_map(Object *obedit, int *r_old_totvert, bool reverse) | ||||
| { | { | ||||
| Curve *curve = (Curve *) obedit->data; | Curve *curve = (Curve *) obedit->data; | ||||
| EditNurb *editnurb = curve->editnurb; | EditNurb *editnurb = curve->editnurb; | ||||
| Nurb *nu; | Nurb *nu; | ||||
| CVKeyIndex *keyIndex; | CVKeyIndex *keyIndex; | ||||
| int *old_to_new_map; | int *old_to_new_map; | ||||
| int old_totvert, i; | int old_totvert, i; | ||||
| int vertex_index; | int vertex_index; | ||||
| Show All 18 Lines | static int *initialize_index_map(Object *obedit, int *r_old_totvert, bool reverse) | ||||
| { | { | ||||
| if (nu->bezt) { | if (nu->bezt) { | ||||
| BezTriple *bezt = nu->bezt; | BezTriple *bezt = nu->bezt; | ||||
| int a = nu->pntsu; | int a = nu->pntsu; | ||||
| while (a--) { | while (a--) { | ||||
| keyIndex = getCVKeyIndex(editnurb, bezt); | keyIndex = getCVKeyIndex(editnurb, bezt); | ||||
| if (keyIndex) { | if (keyIndex) { | ||||
| if (reverse) { | |||||
| if (keyIndex->switched) { | |||||
| old_to_new_map[vertex_index] = keyIndex->vertex_index + 2; | |||||
| old_to_new_map[vertex_index + 1] = keyIndex->vertex_index + 1; | |||||
| old_to_new_map[vertex_index + 2] = keyIndex->vertex_index; | |||||
| } | |||||
| else { | |||||
| old_to_new_map[vertex_index] = keyIndex->vertex_index; | |||||
| old_to_new_map[vertex_index + 1] = keyIndex->vertex_index + 1; | |||||
| old_to_new_map[vertex_index + 2] = keyIndex->vertex_index + 2; | |||||
| } | |||||
| } | |||||
| else { | |||||
| if (keyIndex->switched) { | if (keyIndex->switched) { | ||||
| old_to_new_map[keyIndex->vertex_index] = vertex_index + 2; | old_to_new_map[keyIndex->vertex_index] = vertex_index + 2; | ||||
| old_to_new_map[keyIndex->vertex_index + 1] = vertex_index + 1; | old_to_new_map[keyIndex->vertex_index + 1] = vertex_index + 1; | ||||
| old_to_new_map[keyIndex->vertex_index + 2] = vertex_index; | old_to_new_map[keyIndex->vertex_index + 2] = vertex_index; | ||||
| } | } | ||||
| else { | else { | ||||
| old_to_new_map[keyIndex->vertex_index] = vertex_index; | old_to_new_map[keyIndex->vertex_index] = vertex_index; | ||||
| old_to_new_map[keyIndex->vertex_index + 1] = vertex_index + 1; | old_to_new_map[keyIndex->vertex_index + 1] = vertex_index + 1; | ||||
| old_to_new_map[keyIndex->vertex_index + 2] = vertex_index + 2; | old_to_new_map[keyIndex->vertex_index + 2] = vertex_index + 2; | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| vertex_index += 3; | vertex_index += 3; | ||||
| bezt++; | bezt++; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| BPoint *bp = nu->bp; | BPoint *bp = nu->bp; | ||||
| int a = nu->pntsu * nu->pntsv; | int a = nu->pntsu * nu->pntsv; | ||||
| while (a--) { | while (a--) { | ||||
| keyIndex = getCVKeyIndex(editnurb, bp); | keyIndex = getCVKeyIndex(editnurb, bp); | ||||
| if (keyIndex) { | if (keyIndex) { | ||||
| if (reverse) { | |||||
| old_to_new_map[vertex_index] = keyIndex->vertex_index; | |||||
| } | |||||
| else { | |||||
| old_to_new_map[keyIndex->vertex_index] = vertex_index; | old_to_new_map[keyIndex->vertex_index] = vertex_index; | ||||
| } | } | ||||
| } | |||||
| vertex_index++; | vertex_index++; | ||||
| bp++; | bp++; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| *r_old_totvert = old_totvert; | *r_old_totvert = old_totvert; | ||||
| return old_to_new_map; | return old_to_new_map; | ||||
| } | } | ||||
| static void remap_hooks_and_vertex_parents(Object *obedit) | static void remap_hooks_and_vertex_parents(Object *obedit, bool reverse) | ||||
| { | { | ||||
| Object *object; | Object *object; | ||||
| Curve *curve = (Curve *) obedit->data; | Curve *curve = (Curve *) obedit->data; | ||||
| int *old_to_new_map = NULL; | int *old_to_new_map = NULL; | ||||
| int old_totvert; | int old_totvert; | ||||
| for (object = G.main->object.first; object; object = object->id.next) { | for (object = G.main->object.first; object; object = object->id.next) { | ||||
| ModifierData *md; | ModifierData *md; | ||||
| int index; | int index; | ||||
| if ((object->parent) && | if ((object->parent) && | ||||
| (object->parent->data == curve) && | (object->parent->data == curve) && | ||||
| ELEM(object->partype, PARVERT1, PARVERT3)) | ELEM(object->partype, PARVERT1, PARVERT3)) | ||||
| { | { | ||||
| if (old_to_new_map == NULL) { | if (old_to_new_map == NULL) { | ||||
| old_to_new_map = initialize_index_map(obedit, &old_totvert); | old_to_new_map = initialize_index_map(obedit, | ||||
| &old_totvert, | |||||
| reverse); | |||||
| } | } | ||||
| if (object->par1 < old_totvert) { | if (object->par1 < old_totvert) { | ||||
| index = old_to_new_map[object->par1]; | index = old_to_new_map[object->par1]; | ||||
| if (index != -1) { | if (index != -1) { | ||||
| object->par1 = index; | object->par1 = index; | ||||
| } | } | ||||
| } | } | ||||
| Show All 12 Lines | for (object = G.main->object.first; object; object = object->id.next) { | ||||
| } | } | ||||
| if (object->data == curve) { | if (object->data == curve) { | ||||
| for (md = object->modifiers.first; md; md = md->next) { | for (md = object->modifiers.first; md; md = md->next) { | ||||
| if (md->type == eModifierType_Hook) { | if (md->type == eModifierType_Hook) { | ||||
| HookModifierData *hmd = (HookModifierData *) md; | HookModifierData *hmd = (HookModifierData *) md; | ||||
| int i, j; | int i, j; | ||||
| if (old_to_new_map == NULL) { | if (old_to_new_map == NULL) { | ||||
| old_to_new_map = initialize_index_map(obedit, &old_totvert); | old_to_new_map = initialize_index_map(obedit, | ||||
| &old_totvert, | |||||
| reverse); | |||||
| } | } | ||||
| for (i = j = 0; i < hmd->totindex; i++) { | for (i = j = 0; i < hmd->totindex; i++) { | ||||
| if (hmd->indexar[i] < old_totvert) { | if (hmd->indexar[i] < old_totvert) { | ||||
| index = old_to_new_map[hmd->indexar[i]]; | index = old_to_new_map[hmd->indexar[i]]; | ||||
| if (index != -1) { | if (index != -1) { | ||||
| hmd->indexar[j++] = index; | hmd->indexar[j++] = index; | ||||
| } | } | ||||
| Show All 20 Lines | void load_editNurb(Object *obedit) | ||||
| if (obedit == NULL) return; | if (obedit == NULL) return; | ||||
| if (ELEM(obedit->type, OB_CURVE, OB_SURF)) { | if (ELEM(obedit->type, OB_CURVE, OB_SURF)) { | ||||
| Curve *cu = obedit->data; | Curve *cu = obedit->data; | ||||
| Nurb *nu, *newnu; | Nurb *nu, *newnu; | ||||
| ListBase newnurb = {NULL, NULL}, oldnurb = cu->nurb; | ListBase newnurb = {NULL, NULL}, oldnurb = cu->nurb; | ||||
| remap_hooks_and_vertex_parents(obedit); | |||||
| for (nu = editnurb->first; nu; nu = nu->next) { | for (nu = editnurb->first; nu; nu = nu->next) { | ||||
| newnu = BKE_nurb_duplicate(nu); | newnu = BKE_nurb_duplicate(nu); | ||||
| BLI_addtail(&newnurb, newnu); | BLI_addtail(&newnurb, newnu); | ||||
| if (nu->type == CU_NURBS) { | if (nu->type == CU_NURBS) { | ||||
| BKE_nurb_order_clamp_u(nu); | BKE_nurb_order_clamp_u(nu); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 5,538 Lines • ▼ Show 20 Lines | void CURVE_OT_tilt_clear(wmOperatorType *ot) | ||||
| ot->poll = ED_operator_editcurve; | ot->poll = ED_operator_editcurve; | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; | ||||
| } | } | ||||
| /****************** undo for curves ****************/ | /****************** undo for curves ****************/ | ||||
| static void undoCurve_to_editCurve(void *ucu, void *UNUSED(edata), void *cu_v) | static void undoCurve_to_editCurve(void *ucu, void *edata, void *cu_v) | ||||
| { | { | ||||
| Object *obedit = (Object *) edata; | |||||
| Curve *cu = cu_v; | Curve *cu = cu_v; | ||||
| UndoCurve *undoCurve = ucu; | UndoCurve *undoCurve = ucu; | ||||
| ListBase *undobase = &undoCurve->nubase; | ListBase *undobase = &undoCurve->nubase; | ||||
| ListBase *editbase = BKE_curve_editNurbs_get(cu); | ListBase *editbase = BKE_curve_editNurbs_get(cu); | ||||
| Nurb *nu, *newnu; | Nurb *nu, *newnu; | ||||
| EditNurb *editnurb = cu->editnurb; | EditNurb *editnurb = cu->editnurb; | ||||
| AnimData *ad = BKE_animdata_from_id(&cu->id); | AnimData *ad = BKE_animdata_from_id(&cu->id); | ||||
| remap_hooks_and_vertex_parents(obedit, true); | |||||
| BKE_nurbList_free(editbase); | BKE_nurbList_free(editbase); | ||||
| if (undoCurve->undoIndex) { | if (undoCurve->undoIndex) { | ||||
| BLI_ghash_free(editnurb->keyindex, NULL, MEM_freeN); | BLI_ghash_free(editnurb->keyindex, NULL, MEM_freeN); | ||||
| editnurb->keyindex = dupli_keyIndexHash(undoCurve->undoIndex); | editnurb->keyindex = dupli_keyIndexHash(undoCurve->undoIndex); | ||||
| } | } | ||||
| if (ad) { | if (ad) { | ||||
| Show All 17 Lines | for (nu = undobase->first; nu; nu = nu->next) { | ||||
| BLI_addtail(editbase, newnu); | BLI_addtail(editbase, newnu); | ||||
| } | } | ||||
| cu->actvert = undoCurve->actvert; | cu->actvert = undoCurve->actvert; | ||||
| cu->actnu = undoCurve->actnu; | cu->actnu = undoCurve->actnu; | ||||
| ED_curve_updateAnimPaths(cu); | ED_curve_updateAnimPaths(cu); | ||||
| } | } | ||||
| static void *editCurve_to_undoCurve(void *UNUSED(edata), void *cu_v) | static void *editCurve_to_undoCurve(void *edata, void *cu_v) | ||||
| { | { | ||||
| Object *obedit = (Object *) edata; | |||||
| Curve *cu = cu_v; | Curve *cu = cu_v; | ||||
| ListBase *nubase = BKE_curve_editNurbs_get(cu); | ListBase *nubase = BKE_curve_editNurbs_get(cu); | ||||
| UndoCurve *undoCurve; | UndoCurve *undoCurve; | ||||
| EditNurb *editnurb = cu->editnurb, tmpEditnurb; | EditNurb *editnurb = cu->editnurb, tmpEditnurb; | ||||
| Nurb *nu, *newnu; | Nurb *nu, *newnu; | ||||
| AnimData *ad = BKE_animdata_from_id(&cu->id); | AnimData *ad = BKE_animdata_from_id(&cu->id); | ||||
| undoCurve = MEM_callocN(sizeof(UndoCurve), "undoCurve"); | undoCurve = MEM_callocN(sizeof(UndoCurve), "undoCurve"); | ||||
| Show All 19 Lines | for (nu = nubase->first; nu; nu = nu->next) { | ||||
| } | } | ||||
| BLI_addtail(&undoCurve->nubase, newnu); | BLI_addtail(&undoCurve->nubase, newnu); | ||||
| } | } | ||||
| undoCurve->actvert = cu->actvert; | undoCurve->actvert = cu->actvert; | ||||
| undoCurve->actnu = cu->actnu; | undoCurve->actnu = cu->actnu; | ||||
| remap_hooks_and_vertex_parents(obedit, false); | |||||
| return undoCurve; | return undoCurve; | ||||
| } | } | ||||
| static void free_undoCurve(void *ucv) | static void free_undoCurve(void *ucv) | ||||
| { | { | ||||
| UndoCurve *undoCurve = ucv; | UndoCurve *undoCurve = ucv; | ||||
| BKE_nurbList_free(&undoCurve->nubase); | BKE_nurbList_free(&undoCurve->nubase); | ||||
| ▲ Show 20 Lines • Show All 115 Lines • Show Last 20 Lines | |||||