Blender V5.3
editcurve.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10
11#include "DNA_anim_types.h"
12#include "DNA_key_types.h"
13#include "DNA_object_types.h"
14#include "DNA_scene_types.h"
15
16#include "MEM_guardedalloc.h"
17
18#include "BLI_array_utils_c.hh"
19#include "BLI_ghash.hh"
21#include "BLI_math_geom_c.hh"
22#include "BLI_math_matrix_c.hh"
24#include "BLI_math_vector_c.hh"
25#include "BLI_set.hh"
26#include "BLI_span.hh"
27#include "BLI_string.hh"
28#include "BLI_string_utf8.hh"
29
30#include "BLT_translation.hh"
31
32#include "BKE_action.hh"
33#include "BKE_anim_data.hh"
34#include "BKE_context.hh"
35#include "BKE_curve.hh"
36#include "BKE_displist.h"
37#include "BKE_fcurve.hh"
38#include "BKE_global.hh"
39#include "BKE_key.hh"
40#include "BKE_layer.hh"
41#include "BKE_lib_id.hh"
42#include "BKE_main.hh"
43#include "BKE_modifier.hh"
44#include "BKE_object_types.hh"
45#include "BKE_report.hh"
46
47#include "ANIM_action.hh"
48#include "ANIM_animdata.hh"
49
50#include "DEG_depsgraph.hh"
53
54#include "WM_api.hh"
55#include "WM_types.hh"
56
57#include "ED_curve.hh"
58#include "ED_object.hh"
59#include "ED_outliner.hh"
60#include "ED_screen.hh"
61#include "ED_select_utils.hh"
62#include "ED_transform.hh"
64#include "ED_view3d.hh"
65
66#include "curve_intern.hh"
67
68extern "C" {
69#include "curve_fit_nd.h"
70}
71
72#include "UI_interface.hh"
74#include "UI_resources.hh"
75
76#include "RNA_access.hh"
77#include "RNA_define.hh"
78#include "RNA_enum_types.hh"
79
80namespace blender {
81
82void selectend_nurb(Object *obedit, enum eEndPoint_Types selfirst, bool doswap, bool selstatus);
83static void adduplicateflagNurb(Object *obedit,
84 View3D *v3d,
85 ListBaseT<Nurb> *newnurb,
86 const eBezTriple_Flag flag,
87 const bool split);
88static bool curve_delete_segments(Object *obedit, View3D *v3d, const bool split);
89static bool curve_delete_vertices(Object *obedit, View3D *v3d);
90
91/* -------------------------------------------------------------------- */
94
95ListBaseT<Nurb> *object_editcurve_get(Object *ob)
96{
97 if (ob && ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
98 Curve *cu = id_cast<Curve *>(ob->data);
99 return &cu->editnurb->nurbs;
100 }
101 return nullptr;
102}
103
105{
106 BLI_assert(cu->editnurb);
107
108 return BKE_keyblock_find_by_index(cu->key, cu->editnurb->shapenr - 1);
109}
110
112
113/* -------------------------------------------------------------------- */
116
117#if 0
118void printknots(Object *obedit)
119{
120 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
121 Nurb *nu;
122 int a, num;
123
124 for (nu = editnurb->first; nu; nu = nu->next) {
125 if (ED_curve_nurb_select_check(nu) && nu->type == CU_NURBS) {
126 if (nu->knotsu) {
127 num = KNOTSU(nu);
128 for (a = 0; a < num; a++) {
129 printf("knotu %d: %f\n", a, nu->knotsu[a]);
130 }
131 }
132 if (nu->knotsv) {
133 num = KNOTSV(nu);
134 for (a = 0; a < num; a++) {
135 printf("knotv %d: %f\n", a, nu->knotsv[a]);
136 }
137 }
138 }
139 }
140}
141#endif
142
144
145/* -------------------------------------------------------------------- */
148
150 void *cv, int key_index, int nu_index, int pt_index, int vertex_index)
151{
152 CVKeyIndex *cvIndex = MEM_new_zeroed<CVKeyIndex>(__func__);
153
154 cvIndex->orig_cv = cv;
155 cvIndex->key_index = key_index;
156 cvIndex->nu_index = nu_index;
157 cvIndex->pt_index = pt_index;
158 cvIndex->vertex_index = vertex_index;
159 cvIndex->switched = false;
160
161 return cvIndex;
162}
163
164static void init_editNurb_keyIndex(EditNurb *editnurb, ListBaseT<Nurb> *origBase)
165{
166 Nurb *nu = editnurb->nurbs.first();
167 Nurb *orignu = origBase->first();
168 BezTriple *bezt, *origbezt;
169 BPoint *bp, *origbp;
170 CVKeyIndex *keyIndex;
171 int a, key_index = 0, nu_index = 0, pt_index = 0, vertex_index = 0;
172
173 if (editnurb->keyindex) {
174 return;
175 }
176
177 auto *gh = MEM_new<CVKeyIndexMap>("editNurb keyIndex");
178
179 while (orignu) {
180 if (orignu->bezt) {
181 a = orignu->pntsu;
182 bezt = nu->bezt;
183 origbezt = orignu->bezt;
184 pt_index = 0;
185 while (a--) {
186 /* We cannot keep *any* reference to curve obdata,
187 * it might be replaced and freed while editcurve remain in use
188 * (in viewport render case e.g.). Note that we could use a pool to avoid
189 * lots of allocations here, but... not really a problem for now. */
190 BezTriple *origbezt_cpy = MEM_new_uninitialized<BezTriple>(__func__);
191 *origbezt_cpy = *origbezt;
192 keyIndex = init_cvKeyIndex(origbezt_cpy, key_index, nu_index, pt_index, vertex_index);
193 gh->add(bezt, keyIndex);
194 key_index += KEYELEM_FLOAT_LEN_BEZTRIPLE;
195 vertex_index += 3;
196 bezt++;
197 origbezt++;
198 pt_index++;
199 }
200 }
201 else {
202 a = orignu->pntsu * orignu->pntsv;
203 bp = nu->bp;
204 origbp = orignu->bp;
205 pt_index = 0;
206 while (a--) {
207 /* We cannot keep *any* reference to curve obdata,
208 * it might be replaced and freed while editcurve remain in use
209 * (in viewport render case e.g.). Note that we could use a pool to avoid
210 * lots of malloc's here, but... not really a problem for now. */
211 BPoint *origbp_cpy = MEM_new_uninitialized<BPoint>(__func__);
212 *origbp_cpy = *origbp;
213 keyIndex = init_cvKeyIndex(origbp_cpy, key_index, nu_index, pt_index, vertex_index);
214 gh->add(bp, keyIndex);
215 key_index += KEYELEM_FLOAT_LEN_BPOINT;
216 bp++;
217 origbp++;
218 pt_index++;
219 vertex_index++;
220 }
221 }
222
223 nu = nu->next;
224 orignu = orignu->next;
225 nu_index++;
226 }
227
228 editnurb->keyindex = gh;
229}
230
231static CVKeyIndex *getCVKeyIndex(EditNurb *editnurb, const void *cv)
232{
233 return editnurb->keyindex->lookup_default(cv, nullptr);
234}
235
236static CVKeyIndex *popCVKeyIndex(EditNurb *editnurb, const void *cv)
237{
238 return editnurb->keyindex->pop_default(cv, nullptr);
239}
240
241static BezTriple *getKeyIndexOrig_bezt(EditNurb *editnurb, const BezTriple *bezt)
242{
243 CVKeyIndex *index = getCVKeyIndex(editnurb, bezt);
244
245 if (!index) {
246 return nullptr;
247 }
248
249 return static_cast<BezTriple *>(index->orig_cv);
250}
251
253{
254 CVKeyIndex *index = getCVKeyIndex(editnurb, bp);
255
256 if (!index) {
257 return nullptr;
258 }
259
260 return static_cast<BPoint *>(index->orig_cv);
261}
262
263static int getKeyIndexOrig_keyIndex(EditNurb *editnurb, void *cv)
264{
265 CVKeyIndex *index = getCVKeyIndex(editnurb, cv);
266
267 if (!index) {
268 return -1;
269 }
270
271 return index->key_index;
272}
273
274static void keyIndex_delBezt(EditNurb *editnurb, BezTriple *bezt)
275{
276 if (!editnurb->keyindex) {
277 return;
278 }
279
281}
282
283static void keyIndex_delBP(EditNurb *editnurb, BPoint *bp)
284{
285 if (!editnurb->keyindex) {
286 return;
287 }
288
290}
291
292static void keyIndex_delNurb(EditNurb *editnurb, Nurb *nu)
293{
294 int a;
295
296 if (!editnurb->keyindex) {
297 return;
298 }
299
300 if (nu->bezt) {
301 const BezTriple *bezt = nu->bezt;
302 a = nu->pntsu;
303
304 while (a--) {
306 bezt++;
307 }
308 }
309 else {
310 const BPoint *bp = nu->bp;
311 a = nu->pntsu * nu->pntsv;
312
313 while (a--) {
315 bp++;
316 }
317 }
318}
319
320static void keyIndex_delNurbList(EditNurb *editnurb, ListBaseT<Nurb> *nubase)
321{
322 for (Nurb &nu : *nubase) {
323 keyIndex_delNurb(editnurb, &nu);
324 }
325}
326
327static void keyIndex_updateCV(EditNurb *editnurb, char *cv, char *newcv, int count, int size)
328{
329 int i;
331
332 if (editnurb->keyindex == nullptr) {
333 /* No shape keys - updating not needed */
334 return;
335 }
336
337 for (i = 0; i < count; i++) {
338 index = popCVKeyIndex(editnurb, cv);
339
340 if (index) {
341 editnurb->keyindex->add(newcv, index);
342 }
343
344 newcv += size;
345 cv += size;
346 }
347}
348
349static void keyIndex_updateBezt(EditNurb *editnurb, BezTriple *bezt, BezTriple *newbezt, int count)
350{
351 keyIndex_updateCV(editnurb,
352 reinterpret_cast<char *>(bezt),
353 reinterpret_cast<char *>(newbezt),
354 count,
355 sizeof(BezTriple));
356}
357
358static void keyIndex_updateBP(EditNurb *editnurb, BPoint *bp, BPoint *newbp, int count)
359{
360 keyIndex_updateCV(editnurb,
361 reinterpret_cast<char *>(bp),
362 reinterpret_cast<char *>(newbp),
363 count,
364 sizeof(BPoint));
365}
366
368{
369 if (nu->bezt) {
370 keyIndex_updateBezt(editnurb, nu->bezt, newnu->bezt, newnu->pntsu);
371 }
372 else {
373 keyIndex_updateBP(editnurb, nu->bp, newnu->bp, newnu->pntsu * newnu->pntsv);
374 }
375}
376
377static void keyIndex_swap(EditNurb *editnurb, void *a, void *b)
378{
379 CVKeyIndex *index1 = popCVKeyIndex(editnurb, a);
380 CVKeyIndex *index2 = popCVKeyIndex(editnurb, b);
381
382 if (index2) {
383 editnurb->keyindex->add(a, index2);
384 }
385 if (index1) {
386 editnurb->keyindex->add(b, index1);
387 }
388}
389
390static void keyIndex_switchDirection(EditNurb *editnurb, Nurb *nu)
391{
392 int a;
393 CVKeyIndex *index1, *index2;
394
395 if (nu->bezt) {
396 BezTriple *bezt1, *bezt2;
397
398 a = nu->pntsu;
399
400 bezt1 = nu->bezt;
401 bezt2 = bezt1 + (a - 1);
402
403 if (a & 1) {
404 a++;
405 }
406
407 a /= 2;
408
409 while (a--) {
410 index1 = getCVKeyIndex(editnurb, bezt1);
411 index2 = getCVKeyIndex(editnurb, bezt2);
412
413 if (index1) {
414 index1->switched = !index1->switched;
415 }
416
417 if (bezt1 != bezt2) {
418 keyIndex_swap(editnurb, bezt1, bezt2);
419
420 if (index2) {
421 index2->switched = !index2->switched;
422 }
423 }
424
425 bezt1++;
426 bezt2--;
427 }
428 }
429 else {
430 BPoint *bp1, *bp2;
431
432 if (nu->pntsv == 1) {
433 a = nu->pntsu;
434 bp1 = nu->bp;
435 bp2 = bp1 + (a - 1);
436 a /= 2;
437 while (bp1 != bp2 && a > 0) {
438 index1 = getCVKeyIndex(editnurb, bp1);
439 index2 = getCVKeyIndex(editnurb, bp2);
440
441 if (index1) {
442 index1->switched = !index1->switched;
443 }
444
445 if (bp1 != bp2) {
446 if (index2) {
447 index2->switched = !index2->switched;
448 }
449
450 keyIndex_swap(editnurb, bp1, bp2);
451 }
452
453 a--;
454 bp1++;
455 bp2--;
456 }
457 }
458 else {
459 int b;
460
461 for (b = 0; b < nu->pntsv; b++) {
462
463 bp1 = &nu->bp[b * nu->pntsu];
464 a = nu->pntsu;
465 bp2 = bp1 + (a - 1);
466 a /= 2;
467
468 while (bp1 != bp2 && a > 0) {
469 index1 = getCVKeyIndex(editnurb, bp1);
470 index2 = getCVKeyIndex(editnurb, bp2);
471
472 if (index1) {
473 index1->switched = !index1->switched;
474 }
475
476 if (bp1 != bp2) {
477 if (index2) {
478 index2->switched = !index2->switched;
479 }
480
481 keyIndex_swap(editnurb, bp1, bp2);
482 }
483
484 a--;
485 bp1++;
486 bp2--;
487 }
488 }
489 }
490 }
491}
492
493static void switch_keys_direction(Curve *cu, Nurb *actnu)
494{
495 EditNurb *editnurb = cu->editnurb;
496 ListBaseT<Nurb> *nubase = &editnurb->nurbs;
497 float *fp;
498 int a;
499
500 for (KeyBlock &currkey : cu->key->block) {
501 fp = static_cast<float *>(currkey.data);
502
503 for (Nurb &nu : *nubase) {
504 if (nu.bezt) {
505 BezTriple *bezt = nu.bezt;
506 a = nu.pntsu;
507 if (&nu == actnu) {
508 while (a--) {
509 if (getKeyIndexOrig_bezt(editnurb, bezt)) {
510 swap_v3_v3(fp, fp + 6);
511 *(fp + 9) = -*(fp + 9);
513 }
514 bezt++;
515 }
516 }
517 else {
519 }
520 }
521 else {
522 BPoint *bp = nu.bp;
523 a = nu.pntsu * nu.pntsv;
524 if (&nu == actnu) {
525 while (a--) {
526 if (getKeyIndexOrig_bp(editnurb, bp)) {
527 *(fp + 3) = -*(fp + 3);
529 }
530 bp++;
531 }
532 }
533 else {
534 fp += a * KEYELEM_FLOAT_LEN_BPOINT;
535 }
536 }
537 }
538 }
539}
540
542{
543 EditNurb *editnurb = cu->editnurb;
544
545 if (!editnurb->keyindex) {
546 /* no shape keys - nothing to do */
547 return;
548 }
549
550 keyIndex_switchDirection(editnurb, nu);
551 if (cu->key) {
552 switch_keys_direction(cu, nu);
553 }
554}
555
557{
558 CVKeyIndexMap *gh = MEM_new<CVKeyIndexMap>("dupli_keyIndex gh");
559 gh->reserve(keyindex->size());
560
561 for (const auto &item : keyindex->items()) {
562 const void *cv = item.key;
563 CVKeyIndex *index = item.value;
564 CVKeyIndex *newIndex = MEM_new_uninitialized<CVKeyIndex>("dupli_keyIndexHash index");
565
566 memcpy(newIndex, index, sizeof(CVKeyIndex));
567 newIndex->orig_cv = MEM_dupalloc_void(index->orig_cv);
568
569 gh->add(cv, newIndex);
570 }
571
572 return gh;
573}
574
575static void key_to_bezt(float *key, BezTriple *basebezt, BezTriple *bezt)
576{
577 memcpy(bezt, basebezt, sizeof(BezTriple));
578 memcpy(bezt->vec, key, sizeof(float[9]));
579 bezt->tilt = key[9];
580 bezt->radius = key[10];
581}
582
583static void bezt_to_key(BezTriple *bezt, float *key)
584{
585 memcpy(key, bezt->vec, sizeof(float[9]));
586 key[9] = bezt->tilt;
587 key[10] = bezt->radius;
588}
589
590static void calc_keyHandles(ListBaseT<Nurb> *nurb, float *key)
591{
592 int a;
593 float *fp = key;
594 BezTriple *bezt;
595
596 for (Nurb &nu : *nurb) {
597 if (nu.bezt) {
598 if (nu.pntsu < 2) {
599 /* Single point, no need to calculate handles, proceed to th next Nurb. */
600 fp += nu.pntsu * KEYELEM_FLOAT_LEN_BEZTRIPLE;
601 continue;
602 }
603
604 BezTriple *prevp, *nextp;
605 BezTriple cur, prev, next;
606 float *startfp, *prevfp, *nextfp;
607
608 bezt = nu.bezt;
609 a = nu.pntsu;
610 startfp = fp;
611
612 if (nu.flagu & CU_NURB_CYCLIC) {
613 prevp = bezt + (a - 1);
614 prevfp = fp + (KEYELEM_FLOAT_LEN_BEZTRIPLE * (a - 1));
615 }
616 else {
617 prevp = nullptr;
618 prevfp = nullptr;
619 }
620
621 nextp = bezt + 1;
622 nextfp = fp + KEYELEM_FLOAT_LEN_BEZTRIPLE;
623
624 while (a--) {
625 key_to_bezt(fp, bezt, &cur);
626
627 if (nextp) {
628 key_to_bezt(nextfp, nextp, &next);
629 }
630 if (prevp) {
631 key_to_bezt(prevfp, prevp, &prev);
632 }
633
634 BKE_nurb_handle_calc(&cur, prevp ? &prev : nullptr, nextp ? &next : nullptr, false, 0);
635 bezt_to_key(&cur, fp);
636
637 prevp = bezt;
638 prevfp = fp;
639 if (a == 1) {
640 if (nu.flagu & CU_NURB_CYCLIC) {
641 nextp = nu.bezt;
642 nextfp = startfp;
643 }
644 else {
645 nextp = nullptr;
646 nextfp = nullptr;
647 }
648 }
649 else {
650 nextp++;
652 }
653
654 bezt++;
656 }
657 }
658 else {
659 a = nu.pntsu * nu.pntsv;
660 fp += a * KEYELEM_FLOAT_LEN_BPOINT;
661 }
662 }
663}
664
665static void calc_shapeKeys(Object *obedit, ListBaseT<Nurb> *newnurbs)
666{
667 Curve *cu = id_cast<Curve *>(obedit->data);
668
669 if (cu->key == nullptr) {
670 return;
671 }
672
673 int a, i;
674 EditNurb *editnurb = cu->editnurb;
675 KeyBlock *actkey = static_cast<KeyBlock *>(BLI_findlink(&cu->key->block, editnurb->shapenr - 1));
676 BezTriple *bezt, *oldbezt;
677 BPoint *bp, *oldbp;
678 Nurb *newnu;
679 int totvert = BKE_keyblock_curve_element_count(&editnurb->nurbs);
680
681 float (*ofs)[3] = nullptr;
682 std::optional<Array<bool>> dependent;
683 const float *oldkey, *ofp;
684 float *newkey;
685
686 /* editing the base key should update others */
687 if (cu->key->type == KEY_RELATIVE) {
688 dependent = BKE_keyblock_get_dependent_keys(cu->key, editnurb->shapenr - 1);
689
690 if (dependent) { /* active key is a base */
691 int totvec = 0;
692
693 /* Calculate needed memory to store offset */
694 for (Nurb &nu : editnurb->nurbs) {
695
696 if (nu.bezt) {
697 /* Three vectors to store handles and one for tilt. */
698 totvec += nu.pntsu * 4;
699 }
700 else {
701 totvec += 2 * nu.pntsu * nu.pntsv;
702 }
703 }
704
705 ofs = MEM_new_array_zeroed<float[3]>(totvec, "currkey->data");
706 i = 0;
707 for (Nurb &nu : editnurb->nurbs) {
708 if (nu.bezt) {
709 bezt = nu.bezt;
710 a = nu.pntsu;
711 while (a--) {
712 oldbezt = getKeyIndexOrig_bezt(editnurb, bezt);
713
714 if (oldbezt) {
715 int j;
716 for (j = 0; j < 3; j++) {
717 sub_v3_v3v3(ofs[i], bezt->vec[j], oldbezt->vec[j]);
718 i++;
719 }
720 ofs[i][0] = bezt->tilt - oldbezt->tilt;
721 ofs[i][1] = bezt->radius - oldbezt->radius;
722 i++;
723 }
724 else {
725 i += 4;
726 }
727 bezt++;
728 }
729 }
730 else {
731 bp = nu.bp;
732 a = nu.pntsu * nu.pntsv;
733 while (a--) {
734 oldbp = getKeyIndexOrig_bp(editnurb, bp);
735 if (oldbp) {
736 sub_v3_v3v3(ofs[i], bp->vec, oldbp->vec);
737 ofs[i + 1][0] = bp->tilt - oldbp->tilt;
738 ofs[i + 1][1] = bp->radius - oldbp->radius;
739 }
740 i += 2;
741 bp++;
742 }
743 }
744 }
745 }
746 }
747
748 for (const auto [currkey_i, currkey] : cu->key->block.enumerate()) {
749 const bool apply_offset = (ofs && (&currkey != actkey) && (*dependent)[currkey_i]);
750
751 float *fp = newkey = static_cast<float *>(
752 MEM_new_zeroed(cu->key->elemsize * totvert, "currkey->data"));
753 ofp = oldkey = static_cast<float *>(currkey.data);
754
755 Nurb *nu = editnurb->nurbs.first();
756 /* We need to restore to original curve into newnurb, *not* editcurve's nurbs.
757 * Otherwise, in case we update obdata *without* leaving editmode (e.g. viewport render),
758 * we would invalidate editcurve. */
759 newnu = newnurbs->first();
760 i = 0;
761 while (nu) {
762 if (&currkey == actkey) {
763 const bool restore = actkey != cu->key->refkey;
764
765 if (nu->bezt) {
766 bezt = nu->bezt;
767 a = nu->pntsu;
768 BezTriple *newbezt = newnu->bezt;
769 while (a--) {
770 int j;
771 oldbezt = getKeyIndexOrig_bezt(editnurb, bezt);
772
773 for (j = 0; j < 3; j++, i++) {
774 copy_v3_v3(&fp[j * 3], bezt->vec[j]);
775
776 if (restore && oldbezt) {
777 copy_v3_v3(newbezt->vec[j], oldbezt->vec[j]);
778 }
779 }
780 fp[9] = bezt->tilt;
781 fp[10] = bezt->radius;
782
783 if (restore && oldbezt) {
784 newbezt->tilt = oldbezt->tilt;
785 newbezt->radius = oldbezt->radius;
786 }
787
789 i++;
790 bezt++;
791 newbezt++;
792 }
793 }
794 else {
795 bp = nu->bp;
796 a = nu->pntsu * nu->pntsv;
797 BPoint *newbp = newnu->bp;
798 while (a--) {
799 oldbp = getKeyIndexOrig_bp(editnurb, bp);
800
801 copy_v3_v3(fp, bp->vec);
802
803 fp[3] = bp->tilt;
804 fp[4] = bp->radius;
805
806 if (restore && oldbp) {
807 copy_v3_v3(newbp->vec, oldbp->vec);
808 newbp->tilt = oldbp->tilt;
809 newbp->radius = oldbp->radius;
810 }
811
813 bp++;
814 newbp++;
815 i += 2;
816 }
817 }
818 }
819 else {
820 int index;
821 const float *curofp;
822
823 if (oldkey) {
824 if (nu->bezt) {
825 bezt = nu->bezt;
826 a = nu->pntsu;
827
828 while (a--) {
829 index = getKeyIndexOrig_keyIndex(editnurb, bezt);
830 if (index >= 0) {
831 int j;
832 curofp = ofp + index;
833
834 for (j = 0; j < 3; j++, i++) {
835 copy_v3_v3(&fp[j * 3], &curofp[j * 3]);
836
837 if (apply_offset) {
838 add_v3_v3(&fp[j * 3], ofs[i]);
839 }
840 }
841 fp[9] = curofp[9];
842 fp[10] = curofp[10];
843
844 if (apply_offset) {
845 /* Apply tilt offsets. */
846 add_v3_v3(fp + 9, ofs[i]);
847 i++;
848 }
849
851 }
852 else {
853 int j;
854 for (j = 0; j < 3; j++, i++) {
855 copy_v3_v3(&fp[j * 3], bezt->vec[j]);
856 }
857 fp[9] = bezt->tilt;
858 fp[10] = bezt->radius;
859
861 }
862 bezt++;
863 }
864 }
865 else {
866 bp = nu->bp;
867 a = nu->pntsu * nu->pntsv;
868 while (a--) {
869 index = getKeyIndexOrig_keyIndex(editnurb, bp);
870
871 if (index >= 0) {
872 curofp = ofp + index;
873 copy_v3_v3(fp, curofp);
874 fp[3] = curofp[3];
875 fp[4] = curofp[4];
876
877 if (apply_offset) {
878 add_v3_v3(fp, ofs[i]);
879 add_v3_v3(&fp[3], ofs[i + 1]);
880 }
881 }
882 else {
883 copy_v3_v3(fp, bp->vec);
884 fp[3] = bp->tilt;
885 fp[4] = bp->radius;
886 }
887
889 bp++;
890 i += 2;
891 }
892 }
893 }
894 }
895
896 nu = nu->next;
897 newnu = newnu->next;
898 }
899
900 if (apply_offset) {
901 /* handles could become malicious after offsets applying */
902 calc_keyHandles(&editnurb->nurbs, newkey);
903 }
904
905 currkey.totelem = totvert;
906 if (currkey.data) {
907 MEM_delete_void(currkey.data);
908 }
909 currkey.data = newkey;
910 }
911
912 MEM_SAFE_DELETE(ofs);
913}
914
916
917/* -------------------------------------------------------------------- */
920
921static bool curve_is_animated(Curve *cu)
922{
923 AnimData *ad = BKE_animdata_from_id(&cu->id);
924
925 return ad && (ad->action || ad->drivers.first_);
926}
927
931static void fcurve_path_rename(const char *orig_rna_path,
932 const char *rna_path,
933 const Span<FCurve *> orig_curves,
934 Set<FCurve *> &processed_fcurves)
935{
936 const int len = strlen(orig_rna_path);
937
938 for (FCurve *fcu : orig_curves) {
939 if (processed_fcurves.contains(fcu)) {
940 continue;
941 }
942 if (!STREQLEN(fcu->rna_path().c_str(), orig_rna_path, len)) {
943 continue;
944 }
945
946 processed_fcurves.add(fcu);
947
948 const char *suffix = fcu->rna_path().c_str() + len;
949 char *new_rna_path = BLI_sprintfN("%s%s", rna_path, suffix);
950 fcu->rna_path_set_move(new_rna_path);
951 }
952}
953
960[[nodiscard]] static Vector<FCurve *> curve_rename_fcurves(Curve *cu, Span<FCurve *> orig_curves)
961{
962 if (orig_curves.is_empty()) {
963 /* If there is no animation data to operate on, better stop now. */
964 return {};
965 }
966
967 int a, pt_index;
968 EditNurb *editnurb = cu->editnurb;
969 CVKeyIndex *keyIndex;
970 char rna_path[64], orig_rna_path[64];
971
972 Set<FCurve *> processed_fcurves;
973 Vector<FCurve *> fcurves_to_remove;
974
975 for (const auto [nu_index, nu] : editnurb->nurbs.enumerate()) {
976 if (nu.bezt) {
977 BezTriple *bezt = nu.bezt;
978 a = nu.pntsu;
979 pt_index = 0;
980
981 while (a--) {
982 SNPRINTF_UTF8(rna_path, "splines[%d].bezier_points[%d]", nu_index, pt_index);
983
984 keyIndex = getCVKeyIndex(editnurb, bezt);
985 if (keyIndex) {
986 SNPRINTF_UTF8(orig_rna_path,
987 "splines[%d].bezier_points[%d]",
988 keyIndex->nu_index,
989 keyIndex->pt_index);
990
991 if (keyIndex->switched) {
992 char handle_path[64], orig_handle_path[64];
993 SNPRINTF_UTF8(orig_handle_path, "%s.handle_left", orig_rna_path);
994 SNPRINTF_UTF8(handle_path, "%s.handle_right", rna_path);
995 fcurve_path_rename(orig_handle_path, handle_path, orig_curves, processed_fcurves);
996
997 SNPRINTF_UTF8(orig_handle_path, "%s.handle_right", orig_rna_path);
998 SNPRINTF_UTF8(handle_path, "%s.handle_left", rna_path);
999 fcurve_path_rename(orig_handle_path, handle_path, orig_curves, processed_fcurves);
1000 }
1001
1002 fcurve_path_rename(orig_rna_path, rna_path, orig_curves, processed_fcurves);
1003
1004 keyIndex->nu_index = nu_index;
1005 keyIndex->pt_index = pt_index;
1006 }
1007 else {
1008 /* In this case, the bezier point exists. It just hasn't been indexed yet (which seems to
1009 * happen on entering edit mode, so points added after that may not have such an index
1010 * yet) */
1011
1012 /* This is a no-op when it comes to the manipulation of F-Curves. It does find the
1013 * relevant F-Curves to place them in `processed_fcurves`, which will prevent them from
1014 * being deleted later on. */
1015 fcurve_path_rename(rna_path, rna_path, orig_curves, processed_fcurves);
1016 }
1017
1018 bezt++;
1019 pt_index++;
1020 }
1021 }
1022 else {
1023 BPoint *bp = nu.bp;
1024 a = nu.pntsu * nu.pntsv;
1025 pt_index = 0;
1026
1027 while (a--) {
1028 SNPRINTF_UTF8(rna_path, "splines[%d].points[%d]", nu_index, pt_index);
1029
1030 keyIndex = getCVKeyIndex(editnurb, bp);
1031 if (keyIndex) {
1033 orig_rna_path, "splines[%d].points[%d]", keyIndex->nu_index, keyIndex->pt_index);
1034 fcurve_path_rename(orig_rna_path, rna_path, orig_curves, processed_fcurves);
1035
1036 keyIndex->nu_index = nu_index;
1037 keyIndex->pt_index = pt_index;
1038 }
1039 else {
1040 /* In this case, the bezier point exists. It just hasn't been indexed yet (which seems to
1041 * happen on entering edit mode, so points added after that may not have such an index
1042 * yet) */
1043
1044 /* This is a no-op when it comes to the manipulation of F-Curves. It does find the
1045 * relevant F-Curves to place them in `processed_fcurves`, which will prevent them from
1046 * being deleted later on. */
1047 fcurve_path_rename(rna_path, rna_path, orig_curves, processed_fcurves);
1048 }
1049
1050 bp++;
1051 pt_index++;
1052 }
1053 }
1054 }
1055
1056 /* remove paths for removed control points
1057 * need this to make further step with copying non-cv related curves copying
1058 * not touching cv's f-curves */
1059 for (FCurve *fcu : orig_curves) {
1060 if (processed_fcurves.contains(fcu)) {
1061 continue;
1062 }
1063
1064 if (STRPREFIX(fcu->rna_path().c_str(), "splines")) {
1065 const char *ch = strchr(fcu->rna_path().c_str(), '.');
1066
1067 if (ch && (STRPREFIX(ch, ".bezier_points") || STRPREFIX(ch, ".points"))) {
1068 fcurves_to_remove.append(fcu);
1069 processed_fcurves.add(fcu);
1070 }
1071 }
1072 }
1073
1074 for (const auto [nu_index, nu] : editnurb->nurbs.enumerate()) {
1075 keyIndex = nullptr;
1076 if (nu.pntsu) {
1077 if (nu.bezt) {
1078 keyIndex = getCVKeyIndex(editnurb, &nu.bezt[0]);
1079 }
1080 else {
1081 keyIndex = getCVKeyIndex(editnurb, &nu.bp[0]);
1082 }
1083 }
1084
1085 if (keyIndex) {
1086 SNPRINTF_UTF8(rna_path, "splines[%d]", nu_index);
1087 SNPRINTF_UTF8(orig_rna_path, "splines[%d]", keyIndex->nu_index);
1088 fcurve_path_rename(orig_rna_path, rna_path, orig_curves, processed_fcurves);
1089 }
1090 }
1091
1092 /* the remainders in orig_curves can be copied back (like follow path) */
1093 /* (if it's not path to spline) */
1094 for (FCurve *fcu : orig_curves) {
1095 if (processed_fcurves.contains(fcu)) {
1096 continue;
1097 }
1098 if (STRPREFIX(fcu->rna_path().c_str(), "splines")) {
1099 fcurves_to_remove.append(fcu);
1100 /* Not strictly necessary, because `orig_curves` shouldn't contain any duplicates, and this
1101 * is the last loop that can add anything to `fcurves_to_remove`. However, the line below
1102 * ensures the correctness even when new code would get added to the end of this function. */
1103 processed_fcurves.add(fcu);
1104 }
1105 }
1106
1107 return fcurves_to_remove;
1108}
1109
1111{
1112 AnimData *adt = BKE_animdata_from_id(&cu->id);
1113 EditNurb *editnurb = cu->editnurb;
1114
1115 if (!editnurb->keyindex) {
1116 return 0;
1117 }
1118
1119 if (!curve_is_animated(cu)) {
1120 return 0;
1121 }
1122
1123 if (adt->action != nullptr) {
1124 animrig::Action &action = adt->action->wrap();
1125
1126 Span<FCurve *> fcurves_to_process = animrig::fcurves_for_assigned_action(adt);
1127
1128 Vector<FCurve *> fcurves_to_remove = curve_rename_fcurves(cu, fcurves_to_process);
1129 for (FCurve *fcurve : fcurves_to_remove) {
1130 const bool remove_ok = animrig::action_fcurve_remove(action, *fcurve);
1131 BLI_assert(remove_ok);
1132 UNUSED_VARS_NDEBUG(remove_ok);
1133 }
1134
1136 }
1137
1138 {
1139 Vector<FCurve *> fcurves_to_process = listbase_to_vector<FCurve>(adt->drivers);
1140 Vector<FCurve *> fcurves_to_remove = curve_rename_fcurves(cu, fcurves_to_process);
1141 for (FCurve *driver : fcurves_to_remove) {
1142 BLI_remlink(&adt->drivers, driver);
1143 BKE_fcurve_free(driver);
1144 }
1146 }
1147
1148 /* TODO(sergey): Only update if something actually changed. */
1150
1151 return 1;
1152}
1153
1155
1156/* -------------------------------------------------------------------- */
1159
1160static int *init_index_map(Object *obedit, int *r_old_totvert)
1161{
1162 Curve *curve = id_cast<Curve *>(obedit->data);
1163 EditNurb *editnurb = curve->editnurb;
1164 CVKeyIndex *keyIndex;
1165 int *old_to_new_map;
1166
1167 int old_totvert = 0;
1168 for (Nurb &nu : curve->nurb) {
1169 if (nu.bezt) {
1170 old_totvert += nu.pntsu * 3;
1171 }
1172 else {
1173 old_totvert += nu.pntsu * nu.pntsv;
1174 }
1175 }
1176
1177 old_to_new_map = MEM_new_array_uninitialized<int>(old_totvert, "curve old to new index map");
1178 for (int i = 0; i < old_totvert; i++) {
1179 old_to_new_map[i] = -1;
1180 }
1181
1182 int vertex_index = 0;
1183 for (Nurb &nu : editnurb->nurbs) {
1184 if (nu.bezt) {
1185 BezTriple *bezt = nu.bezt;
1186 int a = nu.pntsu;
1187
1188 while (a--) {
1189 keyIndex = getCVKeyIndex(editnurb, bezt);
1190 if (keyIndex && keyIndex->vertex_index + 2 < old_totvert) {
1191 if (keyIndex->switched) {
1192 old_to_new_map[keyIndex->vertex_index] = vertex_index + 2;
1193 old_to_new_map[keyIndex->vertex_index + 1] = vertex_index + 1;
1194 old_to_new_map[keyIndex->vertex_index + 2] = vertex_index;
1195 }
1196 else {
1197 old_to_new_map[keyIndex->vertex_index] = vertex_index;
1198 old_to_new_map[keyIndex->vertex_index + 1] = vertex_index + 1;
1199 old_to_new_map[keyIndex->vertex_index + 2] = vertex_index + 2;
1200 }
1201 }
1202 vertex_index += 3;
1203 bezt++;
1204 }
1205 }
1206 else {
1207 BPoint *bp = nu.bp;
1208 int a = nu.pntsu * nu.pntsv;
1209
1210 while (a--) {
1211 keyIndex = getCVKeyIndex(editnurb, bp);
1212 if (keyIndex) {
1213 old_to_new_map[keyIndex->vertex_index] = vertex_index;
1214 }
1215 vertex_index++;
1216 bp++;
1217 }
1218 }
1219 }
1220
1221 *r_old_totvert = old_totvert;
1222 return old_to_new_map;
1223}
1224
1225static void remap_hooks_and_vertex_parents(Main *bmain, Object *obedit)
1226{
1227 Curve *curve = id_cast<Curve *>(obedit->data);
1228 EditNurb *editnurb = curve->editnurb;
1229 int *old_to_new_map = nullptr;
1230 int old_totvert;
1231
1232 if (editnurb->keyindex == nullptr) {
1233 /* TODO(sergey): Happens when separating curves, this would lead to
1234 * the wrong indices in the hook modifier, address this together with
1235 * other indices issues.
1236 */
1237 return;
1238 }
1239
1240 for (Object &object : bmain->objects) {
1241 int index;
1242 if ((object.parent) && (object.parent->data == id_cast<const ID *>(curve)) &&
1243 ELEM(object.partype, PARVERT1, PARVERT3))
1244 {
1245 if (old_to_new_map == nullptr) {
1246 old_to_new_map = init_index_map(obedit, &old_totvert);
1247 }
1248
1249 if (object.par1 < old_totvert) {
1250 index = old_to_new_map[object.par1];
1251 if (index != -1) {
1252 object.par1 = index;
1253 }
1254 }
1255 if (object.par2 < old_totvert) {
1256 index = old_to_new_map[object.par2];
1257 if (index != -1) {
1258 object.par2 = index;
1259 }
1260 }
1261 if (object.par3 < old_totvert) {
1262 index = old_to_new_map[object.par3];
1263 if (index != -1) {
1264 object.par3 = index;
1265 }
1266 }
1267 }
1268 if (object.data == id_cast<const ID *>(curve)) {
1269 for (ModifierData &md : object.modifiers) {
1270 if (md.type == eModifierType_Hook) {
1271 HookModifierData *hmd = reinterpret_cast<HookModifierData *>(&md);
1272 int i, j;
1273
1274 if (old_to_new_map == nullptr) {
1275 old_to_new_map = init_index_map(obedit, &old_totvert);
1276 }
1277
1278 for (i = j = 0; i < hmd->indexar_num; i++) {
1279 if (hmd->indexar[i] < old_totvert) {
1280 index = old_to_new_map[hmd->indexar[i]];
1281 if (index != -1) {
1282 hmd->indexar[j++] = index;
1283 }
1284 }
1285 else {
1286 j++;
1287 }
1288 }
1289
1290 hmd->indexar_num = j;
1291 }
1292 }
1293 }
1294 }
1295 if (old_to_new_map != nullptr) {
1296 MEM_delete(old_to_new_map);
1297 }
1298}
1299
1301{
1302 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
1303
1304 if (obedit == nullptr) {
1305 return;
1306 }
1307
1308 if (ELEM(obedit->type, OB_CURVES_LEGACY, OB_SURF)) {
1309 Curve *cu = id_cast<Curve *>(obedit->data);
1310 ListBaseT<Nurb> newnurb = {nullptr, nullptr}, oldnurb = cu->nurb;
1311
1312 remap_hooks_and_vertex_parents(bmain, obedit);
1313
1314 for (Nurb &nu : *editnurb) {
1315 Nurb *newnu = BKE_nurb_duplicate(&nu);
1316 BLI_addtail(&newnurb, newnu);
1317
1318 if (nu.type == CU_NURBS) {
1320 }
1321 }
1322
1323 /* We have to pass also new copied nurbs, since we want to restore original curve
1324 * (without edited shape-key) on obdata, but *not* on editcurve itself
1325 * (ED_curve_editnurb_load call does not always implies freeing
1326 * of editcurve, e.g. when called to generate render data). */
1327 calc_shapeKeys(obedit, &newnurb);
1328
1329 cu->nurb = newnurb;
1330
1331 ED_curve_updateAnimPaths(bmain, id_cast<Curve *>(obedit->data));
1332
1333 BKE_nurbList_free(&oldnurb);
1334 }
1335}
1336
1338{
1339 Curve *cu = id_cast<Curve *>(obedit->data);
1340 EditNurb *editnurb = cu->editnurb;
1341 KeyBlock *actkey;
1342
1343 if (ELEM(obedit->type, OB_CURVES_LEGACY, OB_SURF)) {
1344 actkey = BKE_keyblock_from_object(obedit);
1345
1346 if (actkey) {
1347/* TODO(@ideasman42): undo_system: investigate why this was needed. */
1348#if 0
1349 undo_editmode_clear();
1350#endif
1351 }
1352
1353 if (editnurb) {
1354 BKE_nurbList_free(&editnurb->nurbs);
1356 }
1357 else {
1358 editnurb = MEM_new<EditNurb>("editnurb");
1359 cu->editnurb = editnurb;
1360 }
1361
1362 for (Nurb &nu : cu->nurb) {
1363 Nurb *newnu = BKE_nurb_duplicate(&nu);
1364 BLI_addtail(&editnurb->nurbs, newnu);
1365 }
1366
1367 /* Animation could be added in edit-mode even if there was no animdata in
1368 * object mode hence we always need CVs index be created. */
1369 init_editNurb_keyIndex(editnurb, &cu->nurb);
1370
1371 if (actkey) {
1372 editnurb->shapenr = obedit->shapenr;
1373 /* Apply shape-key to new nurbs of editnurb, not those of original curve
1374 * (and *after* we generated keyIndex), else we do not have valid 'original' data
1375 * to properly restore curve when leaving edit-mode. */
1376 BKE_keyblock_convert_to_curve(actkey, cu, &editnurb->nurbs);
1377 }
1378 }
1379}
1380
1382{
1383 Curve *cu = id_cast<Curve *>(obedit->data);
1384
1386}
1387
1389
1390/* -------------------------------------------------------------------- */
1393
1395{
1396 Main *bmain = CTX_data_main(C);
1397 Scene *scene = CTX_data_scene(C);
1398 ViewLayer *view_layer = CTX_data_view_layer(C);
1399 View3D *v3d = CTX_wm_view3d(C);
1400
1401 struct {
1402 int changed;
1403 int unselected;
1404 int error_vertex_keys;
1405 int error_generic;
1406 } status = {0};
1407
1408 WM_cursor_wait(true);
1409
1411 *bmain, scene, view_layer, CTX_wm_view3d(C));
1412 for (Base *oldbase : bases) {
1413 Base *newbase;
1414 Object *oldob, *newob;
1415 Curve *oldcu, *newcu;
1416 EditNurb *newedit;
1417 ListBaseT<Nurb> newnurb = {nullptr, nullptr};
1418
1419 oldob = oldbase->object;
1420 oldcu = id_cast<Curve *>(oldob->data);
1421
1422 if (oldcu->key) {
1423 status.error_vertex_keys++;
1424 continue;
1425 }
1426
1427 if (!ED_curve_select_check(v3d, oldcu->editnurb)) {
1428 status.unselected++;
1429 continue;
1430 }
1431
1432 /* 1. Duplicate geometry and check for valid selection for separate. */
1433 adduplicateflagNurb(oldob, v3d, &newnurb, BEZT_FLAG_SELECT, true);
1434
1435 if (newnurb.is_empty()) {
1436 status.error_generic++;
1437 continue;
1438 }
1439
1440 /* 2. Duplicate the object and data. */
1441
1442 /* Take into account user preferences for duplicating actions. */
1443 const eDupli_ID_Flags dupflag = eDupli_ID_Flags(U.dupflag & USER_DUP_ACT);
1444
1445 newbase = ed::object::add_duplicate(bmain, scene, view_layer, oldbase, dupflag);
1447
1448 newob = newbase->object;
1449 newcu = id_cast<Curve *>(newob->data = BKE_id_copy(bmain, &oldcu->id));
1450 newcu->editnurb = nullptr;
1451 id_us_min(&oldcu->id); /* Because new curve is a copy: reduce user count. */
1452
1453 /* 3. Put new object in editmode, clear it and set separated nurbs. */
1455 newedit = newcu->editnurb;
1456 BKE_nurbList_free(&newedit->nurbs);
1458 BLI_movelisttolist(&newedit->nurbs, &newnurb);
1459
1460 /* 4. Put old object out of editmode and delete separated geometry. */
1461 ED_curve_editnurb_load(bmain, newob);
1463 curve_delete_segments(oldob, v3d, true);
1464
1465 DEG_id_tag_update(&oldob->id, ID_RECALC_GEOMETRY); /* This is the original one. */
1466 DEG_id_tag_update(&newob->id, ID_RECALC_GEOMETRY); /* This is the separated one. */
1467
1470 status.changed++;
1471 }
1472 WM_cursor_wait(false);
1473
1474 if (status.unselected == bases.size()) {
1475 BKE_report(op->reports, RPT_ERROR, "No point was selected");
1476 return OPERATOR_CANCELLED;
1477 }
1478
1479 const int tot_errors = status.error_vertex_keys + status.error_generic;
1480 if (tot_errors > 0) {
1481
1482 /* Some curves changed, but some curves failed: don't explain why it failed. */
1483 if (status.changed) {
1484 BKE_reportf(op->reports, RPT_INFO, "%d curve(s) could not be separated", tot_errors);
1485 return OPERATOR_FINISHED;
1486 }
1487
1488 /* All curves failed: If there is more than one error give a generic error report. */
1489 if (((status.error_vertex_keys ? 1 : 0) + (status.error_generic ? 1 : 0)) > 1) {
1490 BKE_report(op->reports, RPT_ERROR, "Could not separate selected curve(s)");
1491 }
1492
1493 /* All curves failed due to the same error. */
1494 if (status.error_vertex_keys) {
1495 BKE_report(op->reports, RPT_ERROR, "Cannot separate curves with shape keys");
1496 }
1497 else {
1498 BLI_assert(status.error_generic);
1499 BKE_report(op->reports, RPT_ERROR, "Cannot separate current selection");
1500 }
1501 return OPERATOR_CANCELLED;
1502 }
1503
1505
1506 return OPERATOR_FINISHED;
1507}
1508
1510{
1511 /* identifiers */
1512 ot->name = "Separate";
1513 ot->idname = "CURVE_OT_separate";
1514 ot->description = "Separate selected points from connected unselected points into a new object";
1515
1516 /* API callbacks. */
1517 ot->exec = separate_exec;
1519
1520 /* flags */
1522}
1523
1525
1526/* -------------------------------------------------------------------- */
1529
1531{
1532 Main *bmain = CTX_data_main(C);
1533 const Scene *scene = CTX_data_scene(C);
1534 ViewLayer *view_layer = CTX_data_view_layer(C);
1535 View3D *v3d = CTX_wm_view3d(C);
1536 bool changed = false;
1537 int count_failed = 0;
1538
1540 *bmain, scene, view_layer, CTX_wm_view3d(C));
1541 for (Object *obedit : objects) {
1542 Curve *cu = id_cast<Curve *>(obedit->data);
1543
1544 if (!ED_curve_select_check(v3d, cu->editnurb)) {
1545 continue;
1546 }
1547
1548 ListBaseT<Nurb> newnurb = {nullptr, nullptr};
1549
1550 adduplicateflagNurb(obedit, v3d, &newnurb, BEZT_FLAG_SELECT, true);
1551
1552 if (newnurb.is_empty()) {
1553 count_failed += 1;
1554 continue;
1555 }
1556
1557 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
1558 const int len_orig = editnurb->count();
1559
1560 curve_delete_segments(obedit, v3d, true);
1561 cu->actnu -= len_orig - editnurb->count();
1562 BLI_movelisttolist(editnurb, &newnurb);
1563
1564 if (ED_curve_updateAnimPaths(bmain, id_cast<Curve *>(obedit->data))) {
1566 }
1567
1568 changed = true;
1569 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
1570 DEG_id_tag_update(obedit->data, 0);
1571 }
1572
1573 if (changed == false) {
1574 if (count_failed != 0) {
1575 BKE_report(op->reports, RPT_ERROR, "Cannot split current selection");
1576 }
1577 return OPERATOR_CANCELLED;
1578 }
1579 return OPERATOR_FINISHED;
1580}
1581
1583{
1584 /* identifiers */
1585 ot->name = "Split";
1586 ot->idname = "CURVE_OT_split";
1587 ot->description = "Split off selected points from connected unselected points";
1588
1589 /* API callbacks. */
1590 ot->exec = curve_split_exec;
1592
1593 /* flags */
1595}
1596
1598
1599/* -------------------------------------------------------------------- */
1602
1603/* return true if U direction is selected and number of selected columns v */
1604static bool isNurbselU(Nurb *nu, int *v, eBezTriple_Flag flag)
1605{
1606 BPoint *bp;
1607 int a, b, sel;
1608
1609 *v = 0;
1610
1611 for (b = 0, bp = nu->bp; b < nu->pntsv; b++) {
1612 sel = 0;
1613 for (a = 0; a < nu->pntsu; a++, bp++) {
1614 if (bp->f1 & flag) {
1615 sel++;
1616 }
1617 }
1618 if (sel == nu->pntsu) {
1619 (*v)++;
1620 }
1621 else if (sel >= 1) {
1622 *v = 0;
1623 return false;
1624 }
1625 }
1626
1627 return true;
1628}
1629
1630/* return true if V direction is selected and number of selected rows u */
1631static bool isNurbselV(Nurb *nu, int *u, eBezTriple_Flag flag)
1632{
1633 BPoint *bp;
1634 int a, b, sel;
1635
1636 *u = 0;
1637
1638 for (a = 0; a < nu->pntsu; a++) {
1639 bp = &nu->bp[a];
1640 sel = 0;
1641 for (b = 0; b < nu->pntsv; b++, bp += nu->pntsu) {
1642 if (bp->f1 & flag) {
1643 sel++;
1644 }
1645 }
1646 if (sel == nu->pntsv) {
1647 (*u)++;
1648 }
1649 else if (sel >= 1) {
1650 *u = 0;
1651 return false;
1652 }
1653 }
1654
1655 return true;
1656}
1657
1658static void rotateflagNurb(ListBaseT<Nurb> *editnurb,
1659 eBezTriple_Flag flag,
1660 const float cent[3],
1661 const float rotmat[3][3])
1662{
1663 /* all verts with (flag & 'flag') rotate */
1664 BPoint *bp;
1665 int a;
1666
1667 for (Nurb &nu : *editnurb) {
1668 if (nu.type == CU_NURBS) {
1669 bp = nu.bp;
1670 a = nu.pntsu * nu.pntsv;
1671
1672 while (a--) {
1673 if (bp->f1 & flag) {
1674 sub_v3_v3(bp->vec, cent);
1675 mul_m3_v3(rotmat, bp->vec);
1676 add_v3_v3(bp->vec, cent);
1677 }
1678 bp++;
1679 }
1680 }
1681 }
1682}
1683
1684void ed_editnurb_translate_flag(ListBaseT<Nurb> *editnurb,
1685 eBezTriple_Flag flag,
1686 const float vec[3],
1687 bool is_2d)
1688{
1689 /* all verts with ('flag' & flag) translate */
1690 BezTriple *bezt;
1691 BPoint *bp;
1692 int a;
1693
1694 for (Nurb &nu : *editnurb) {
1695 if (nu.type == CU_BEZIER) {
1696 a = nu.pntsu;
1697 bezt = nu.bezt;
1698 while (a--) {
1699 if (bezt->f1 & flag) {
1700 add_v3_v3(bezt->vec[0], vec);
1701 }
1702 if (bezt->f2 & flag) {
1703 add_v3_v3(bezt->vec[1], vec);
1704 }
1705 if (bezt->f3 & flag) {
1706 add_v3_v3(bezt->vec[2], vec);
1707 }
1708 bezt++;
1709 }
1710 }
1711 else {
1712 a = nu.pntsu * nu.pntsv;
1713 bp = nu.bp;
1714 while (a--) {
1715 if (bp->f1 & flag) {
1716 add_v3_v3(bp->vec, vec);
1717 }
1718 bp++;
1719 }
1720 }
1721
1722 if (is_2d) {
1724 }
1725 }
1726}
1727
1728static void weightflagNurb(ListBaseT<Nurb> *editnurb, short flag, float w)
1729{
1730 BPoint *bp;
1731 int a;
1732
1733 for (Nurb &nu : *editnurb) {
1734 if (nu.type == CU_NURBS) {
1735 a = nu.pntsu * nu.pntsv;
1736 bp = nu.bp;
1737 while (a--) {
1738 if (bp->f1 & flag) {
1739 /* a mode used to exist for replace/multiple but is was unused */
1740 bp->vec[3] *= w;
1741 }
1742 bp++;
1743 }
1744 }
1745 }
1746}
1747
1749{
1750 Curve *cu = id_cast<Curve *>(obedit->data);
1751 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
1752 BPoint *bp, *bpn, *newbp;
1753 int a, b, newu, newv;
1754
1755 BLI_assert(obedit->type == OB_SURF);
1756
1757 for (Nurb &nu : editnurb->items_mutable()) {
1758 /* is entire nurb selected */
1759 bp = nu.bp;
1760 a = nu.pntsu * nu.pntsv;
1761 while (a) {
1762 a--;
1763 if (bp->f1 & SELECT) {
1764 /* pass */
1765 }
1766 else {
1767 break;
1768 }
1769 bp++;
1770 }
1771 if (a == 0) {
1772 if (cu->actnu == BLI_findindex(editnurb, &nu)) {
1773 cu->actnu = CU_ACT_NONE;
1774 }
1775
1776 BLI_remlink(editnurb, &nu);
1777 keyIndex_delNurb(cu->editnurb, &nu);
1778 BKE_nurb_free(&nu);
1779 }
1780 else {
1781 if (isNurbselU(&nu, &newv, BEZT_FLAG_SELECT)) {
1782 /* U direction selected */
1783 newv = nu.pntsv - newv;
1784 if (newv != nu.pntsv) {
1785 /* delete */
1786 bp = nu.bp;
1787 bpn = newbp = MEM_new_array_uninitialized<BPoint>(newv * nu.pntsu, "deleteNurb");
1788 for (b = 0; b < nu.pntsv; b++) {
1789 if ((bp->f1 & SELECT) == 0) {
1790 memcpy(bpn, bp, nu.pntsu * sizeof(BPoint));
1791 keyIndex_updateBP(cu->editnurb, bp, bpn, nu.pntsu);
1792 bpn += nu.pntsu;
1793 }
1794 else {
1795 keyIndex_delBP(cu->editnurb, bp);
1796 }
1797 bp += nu.pntsu;
1798 }
1799 nu.pntsv = newv;
1800 MEM_delete(nu.bp);
1801 nu.bp = newbp;
1803
1805 }
1806 }
1807 else if (isNurbselV(&nu, &newu, BEZT_FLAG_SELECT)) {
1808 /* V direction selected */
1809 newu = nu.pntsu - newu;
1810 if (newu != nu.pntsu) {
1811 /* delete */
1812 bp = nu.bp;
1813 bpn = newbp = MEM_new_array_uninitialized<BPoint>(newu * nu.pntsv, "deleteNurb");
1814 for (b = 0; b < nu.pntsv; b++) {
1815 for (a = 0; a < nu.pntsu; a++, bp++) {
1816 if ((bp->f1 & SELECT) == 0) {
1817 *bpn = *bp;
1818 keyIndex_updateBP(cu->editnurb, bp, bpn, 1);
1819 bpn++;
1820 }
1821 else {
1822 keyIndex_delBP(cu->editnurb, bp);
1823 }
1824 }
1825 }
1826 MEM_delete(nu.bp);
1827 nu.bp = newbp;
1828 if (newu == 1 && nu.pntsv > 1) { /* make a U spline */
1829 nu.pntsu = nu.pntsv;
1830 nu.pntsv = 1;
1831 std::swap(nu.orderu, nu.orderv);
1833 MEM_SAFE_DELETE(nu.knotsv);
1834 }
1835 else {
1836 nu.pntsu = newu;
1838 }
1840 }
1841 }
1842 }
1843 }
1844}
1845
1846static void ed_curve_delete_selected(Object *obedit, View3D *v3d)
1847{
1848 Curve *cu = id_cast<Curve *>(obedit->data);
1849 EditNurb *editnurb = cu->editnurb;
1850 ListBaseT<Nurb> *nubase = &editnurb->nurbs;
1851 BezTriple *bezt, *bezt1;
1852 BPoint *bp, *bp1;
1853 int a, type, nuindex = 0;
1854
1855 /* first loop, can we remove entire pieces? */
1856 for (Nurb &nu : nubase->items_mutable()) {
1857 bool nu_deleted = false;
1858
1859 if (nu.type == CU_BEZIER) {
1860 bezt = nu.bezt;
1861 a = nu.pntsu;
1862 if (a) {
1863 while (a) {
1864 if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)) {
1865 /* pass */
1866 }
1867 else {
1868 break;
1869 }
1870 a--;
1871 bezt++;
1872 }
1873 if (a == 0) {
1874 if (cu->actnu == nuindex) {
1875 cu->actnu = CU_ACT_NONE;
1876 }
1877
1878 BLI_remlink(nubase, &nu);
1879 keyIndex_delNurb(editnurb, &nu);
1880 BKE_nurb_free(&nu);
1881 nu_deleted = true;
1882 }
1883 }
1884 }
1885 else {
1886 bp = nu.bp;
1887 a = nu.pntsu * nu.pntsv;
1888 if (a) {
1889 while (a) {
1890 if (bp->f1 & SELECT) {
1891 /* pass */
1892 }
1893 else {
1894 break;
1895 }
1896 a--;
1897 bp++;
1898 }
1899 if (a == 0) {
1900 if (cu->actnu == nuindex) {
1901 cu->actnu = CU_ACT_NONE;
1902 }
1903
1904 BLI_remlink(nubase, &nu);
1905 keyIndex_delNurb(editnurb, &nu);
1906 BKE_nurb_free(&nu);
1907 nu_deleted = true;
1908 }
1909 }
1910 }
1911
1912/* Never allow the order to exceed the number of points
1913 * NOTE: this is ok but changes unselected nurbs, disable for now. */
1914#if 0
1915 if (!nu_deleted && (nu.type == CU_NURBS)) {
1916 clamp_nurb_order_u(&nu);
1917 }
1918#else
1919 UNUSED_VARS(nu_deleted);
1920#endif
1921 nuindex++;
1922 }
1923 /* 2nd loop, delete small pieces: just for curves */
1924 for (Nurb &nu : nubase->items_mutable()) {
1925 type = 0;
1926 if (nu.type == CU_BEZIER) {
1927 bezt = nu.bezt;
1928 for (a = 0; a < nu.pntsu; a++) {
1929 if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)) {
1930 memmove(bezt, bezt + 1, (nu.pntsu - a - 1) * sizeof(BezTriple));
1931 keyIndex_delBezt(editnurb, bezt);
1932 keyIndex_updateBezt(editnurb, bezt + 1, bezt, nu.pntsu - a - 1);
1933 nu.pntsu--;
1934 a--;
1935 type = 1;
1936 }
1937 else {
1938 bezt++;
1939 }
1940 }
1941 if (type) {
1942 bezt1 = MEM_new_array_uninitialized<BezTriple>((nu.pntsu), "delNurb");
1943 memcpy(bezt1, nu.bezt, (nu.pntsu) * sizeof(BezTriple));
1944 keyIndex_updateBezt(editnurb, nu.bezt, bezt1, nu.pntsu);
1945 MEM_delete(nu.bezt);
1946 nu.bezt = bezt1;
1948 }
1949 }
1950 else if (nu.pntsv == 1) {
1951 bp = nu.bp;
1952
1953 for (a = 0; a < nu.pntsu; a++) {
1954 if (bp->f1 & SELECT) {
1955 memmove(bp, bp + 1, (nu.pntsu - a - 1) * sizeof(BPoint));
1956 keyIndex_delBP(editnurb, bp);
1957 keyIndex_updateBP(editnurb, bp + 1, bp, nu.pntsu - a - 1);
1958 nu.pntsu--;
1959 a--;
1960 type = 1;
1961 }
1962 else {
1963 bp++;
1964 }
1965 }
1966 if (type) {
1967 bp1 = MEM_new_array_uninitialized<BPoint>(nu.pntsu, "delNurb2");
1968 memcpy(bp1, nu.bp, (nu.pntsu) * sizeof(BPoint));
1969 keyIndex_updateBP(editnurb, nu.bp, bp1, nu.pntsu);
1970 MEM_delete(nu.bp);
1971 nu.bp = bp1;
1972
1973/* Never allow the order to exceed the number of points
1974 * NOTE: this is ok but changes unselected nurbs, disable for now. */
1975#if 0
1976 if (nu->type == CU_NURBS) {
1977 clamp_nurb_order_u(nu);
1978 }
1979#endif
1980 }
1983 }
1984 }
1985}
1986
1987static void select_bpoints(BPoint *bp,
1988 const int stride,
1989 const int count,
1990 const bool selstatus,
1991 const eBezTriple_Flag flag,
1992 const bool hidden)
1993{
1994 for (int i = 0; i < count; i++) {
1995 select_bpoint(bp, selstatus, flag, hidden);
1996 bp += stride;
1997 }
1998}
1999
2007static int sel_to_copy_ints(const BPoint *bp,
2008 const int next_j,
2009 const int max_j,
2010 const int next_i,
2011 const int max_i,
2012 const uint8_t flag,
2013 int copy_intervals[],
2014 int *interval_count,
2015 bool *out_is_first_sel)
2016{
2017 const BPoint *bp_j = bp;
2018
2019 int selected_leg_count = 0;
2020 int ins = 0;
2021 int selected_in_prev_leg = -1;
2022 int not_full = -1;
2023
2024 bool is_first_sel = false;
2025 bool is_last_sel = false;
2026
2027 for (int j = 0; j < max_j; j++, bp_j += next_j) {
2028 const BPoint *bp_j_i = bp_j;
2029 int selected_in_curr_leg = 0;
2030 for (int i = 0; i < max_i; i++, bp_j_i += next_i) {
2031 if (bp_j_i->f1 & flag) {
2032 selected_in_curr_leg++;
2033 }
2034 }
2035 if (selected_in_curr_leg == max_i) {
2036 selected_leg_count++;
2037 if (j == 0) {
2038 is_first_sel = true;
2039 }
2040 else if (j + 1 == max_j) {
2041 is_last_sel = true;
2042 }
2043 }
2044 else if (not_full == -1) {
2045 not_full = selected_in_curr_leg;
2046 }
2047 /* We have partially selected leg in opposite dimension if condition is met. */
2048 else if (not_full != selected_in_curr_leg) {
2049 return -1;
2050 }
2051 /* Extrusion area starts/ends if met. */
2052 if (selected_in_prev_leg != selected_in_curr_leg) {
2053 copy_intervals[ins] = selected_in_curr_leg == max_i || j == 0 ? j : j - 1;
2054 ins++;
2055 selected_in_prev_leg = selected_in_curr_leg;
2056 }
2057 copy_intervals[ins] = j;
2058 }
2059 if (selected_leg_count &&
2060 /* Prevents leading and trailing unselected legs if all selected.
2061 * Unless it is extrusion from point or curve. */
2062 (selected_leg_count < max_j || max_j == 1))
2063 {
2064 /* Prepend unselected leg if more than one leg selected at the starting edge.
2065 * max_j == 1 handles extrusion from point to curve and from curve to surface cases. */
2066 if (is_first_sel && (copy_intervals[0] < copy_intervals[1] || max_j == 1)) {
2067 memmove(copy_intervals + 1, copy_intervals, (ins + 1) * sizeof(copy_intervals[0]));
2068 copy_intervals[0] = 0;
2069 ins++;
2070 is_first_sel = false;
2071 }
2072 /* Append unselected leg if more than one leg selected at the end. */
2073 if (is_last_sel && copy_intervals[ins - 1] < copy_intervals[ins]) {
2074 copy_intervals[ins + 1] = copy_intervals[ins];
2075 ins++;
2076 }
2077 }
2078 *interval_count = ins;
2079 *out_is_first_sel = ins > 1 ? is_first_sel : false;
2080 return selected_leg_count;
2081}
2082
2083struct NurbDim {
2086};
2087
2089{
2090 NurbDim ret = {0, 0};
2091 for (Nurb &nu : editnurb->nurbs) {
2092 ret.pntsu = std::max(nu.pntsu, ret.pntsu);
2093 ret.pntsv = std::max(nu.pntsv, ret.pntsv);
2094 }
2095 return ret;
2096}
2097
2099{
2100 const NurbDim max = editnurb_find_max_points_num(editnurb);
2101 /* One point induces at most one interval. Except single point case, it can give + 1.
2102 * Another +1 is for first element of the first interval. */
2103 int *const intvls_u = MEM_new_array_uninitialized<int>(max.pntsu + 2, "extrudeNurb0");
2104 int *const intvls_v = MEM_new_array_uninitialized<int>(max.pntsv + 2, "extrudeNurb1");
2105 bool ok = false;
2106
2107 for (Nurb &nu : editnurb->nurbs) {
2108 int intvl_cnt_u;
2109 bool is_first_sel_u;
2110
2111 /* Calculate selected U legs and intervals for their extrusion. */
2112 const int selected_us = sel_to_copy_ints(
2113 nu.bp, 1, nu.pntsu, nu.pntsu, nu.pntsv, flag, intvls_u, &intvl_cnt_u, &is_first_sel_u);
2114 if (selected_us == -1) {
2115 continue;
2116 }
2117 int intvl_cnt_v;
2118 bool is_first_sel_v;
2119
2120 const bool is_point = nu.pntsu == 1;
2121 const bool is_curve = nu.pntsv == 1;
2122 const bool extrude_every_u_point = selected_us == nu.pntsu;
2123 if (is_point || (is_curve && !extrude_every_u_point)) {
2124 intvls_v[0] = intvls_v[1] = 0;
2125 intvl_cnt_v = 1;
2126 is_first_sel_v = false;
2127 }
2128 else {
2129 const int selected_vs = sel_to_copy_ints(
2130 nu.bp, nu.pntsu, nu.pntsv, 1, nu.pntsu, flag, intvls_v, &intvl_cnt_v, &is_first_sel_v);
2131 if (selected_vs == -1) {
2132 continue;
2133 }
2134 }
2135
2136 const int new_pntsu = nu.pntsu + intvl_cnt_u - 1;
2137 const int new_pntsv = nu.pntsv + intvl_cnt_v - 1;
2138 BPoint *const new_bp = MEM_new_array_uninitialized<BPoint>(new_pntsu * new_pntsv,
2139 "extrudeNurb2");
2140 BPoint *new_bp_v = new_bp;
2141
2142 bool selected_v = is_first_sel_v;
2143 for (int j = 1; j <= intvl_cnt_v; j++, selected_v = !selected_v) {
2144 BPoint *old_bp_v = nu.bp + intvls_v[j - 1] * nu.pntsu;
2145 for (int v_j = intvls_v[j - 1]; v_j <= intvls_v[j];
2146 v_j++, new_bp_v += new_pntsu, old_bp_v += nu.pntsu)
2147 {
2148 BPoint *new_bp_u_v = new_bp_v;
2149 bool selected_u = is_first_sel_u;
2150 for (int i = 1; i <= intvl_cnt_u; i++, selected_u = !selected_u) {
2151 const int copy_from = intvls_u[i - 1];
2152 const int copy_to = intvls_u[i];
2153 const int copy_count = copy_to - copy_from + 1;
2154 const bool sel_status = selected_u || selected_v ? true : false;
2155 ED_curve_bpcpy(editnurb, new_bp_u_v, old_bp_v + copy_from, copy_count);
2156 select_bpoints(new_bp_u_v, 1, copy_count, sel_status, flag, HIDDEN);
2157 new_bp_u_v += copy_count;
2158 }
2159 }
2160 }
2161
2162 MEM_delete(nu.bp);
2163 nu.bp = new_bp;
2164 nu.pntsu = new_pntsu;
2165 if (nu.pntsv == 1 && new_pntsv > 1) {
2166 nu.orderv = 2;
2167 }
2168 nu.pntsv = new_pntsv;
2169 BLI_assert(nu.pntsu >= 1 && nu.pntsv >= 1);
2172
2173 ok = true;
2174 }
2175 MEM_delete(intvls_u);
2176 MEM_delete(intvls_v);
2177 return ok;
2178}
2179
2180static void calc_duplicate_actnurb(const ListBaseT<Nurb> *editnurb,
2181 const ListBaseT<Nurb> *newnurb,
2182 Curve *cu)
2183{
2184 cu->actnu = editnurb->count() + newnurb->count();
2185}
2186
2187static bool calc_duplicate_actvert(const ListBaseT<Nurb> *editnurb,
2188 const ListBaseT<Nurb> *newnurb,
2189 Curve *cu,
2190 int start,
2191 int end,
2192 int vert)
2193{
2194 if (cu->actvert == -1) {
2195 calc_duplicate_actnurb(editnurb, newnurb, cu);
2196 return true;
2197 }
2198
2199 if ((start <= cu->actvert) && (end > cu->actvert)) {
2200 calc_duplicate_actnurb(editnurb, newnurb, cu);
2201 cu->actvert = vert;
2202 return true;
2203 }
2204 return false;
2205}
2206
2207static void adduplicateflagNurb(Object *obedit,
2208 View3D *v3d,
2209 ListBaseT<Nurb> *newnurb,
2210 const eBezTriple_Flag flag,
2211 const bool split)
2212{
2213 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
2214 Nurb *newnu;
2215 BezTriple *bezt, *bezt1;
2216 BPoint *bp, *bp1, *bp2, *bp3;
2217 Curve *cu = id_cast<Curve *>(obedit->data);
2218 int a, b, c, starta, enda, diffa, cyclicu, cyclicv, newu, newv;
2219 char *usel;
2220
2221 for (const auto [i, nu] : (editnurb)->enumerate()) {
2222 cyclicu = cyclicv = 0;
2223 if (nu.type == CU_BEZIER) {
2224 for (a = 0, bezt = nu.bezt; a < nu.pntsu; a++, bezt++) {
2225 enda = -1;
2226 starta = a;
2227 while ((bezt->f1 & flag) || (bezt->f2 & flag) || (bezt->f3 & flag)) {
2228 if (!split) {
2229 select_beztriple(bezt, false, flag, HIDDEN);
2230 }
2231 enda = a;
2232 if (a >= nu.pntsu - 1) {
2233 break;
2234 }
2235 a++;
2236 bezt++;
2237 }
2238 if (enda >= starta) {
2239 newu = diffa = enda - starta + 1; /* set newu and diffa, may use both */
2240
2241 if (starta == 0 && newu != nu.pntsu && (nu.flagu & CU_NURB_CYCLIC)) {
2242 cyclicu = newu;
2243 }
2244 else {
2245 if (enda == nu.pntsu - 1) {
2246 newu += cyclicu;
2247 }
2248 if (i == cu->actnu) {
2250 editnurb, newnurb, cu, starta, starta + diffa, cu->actvert - starta);
2251 }
2252
2253 newnu = BKE_nurb_copy(&nu, newu, 1);
2254 memcpy(newnu->bezt, &nu.bezt[starta], diffa * sizeof(BezTriple));
2255 if (newu != diffa) {
2256 memcpy(&newnu->bezt[diffa], nu.bezt, cyclicu * sizeof(BezTriple));
2257 if (i == cu->actnu) {
2259 editnurb, newnurb, cu, 0, cyclicu, newu - cyclicu + cu->actvert);
2260 }
2261 cyclicu = 0;
2262 }
2263
2264 if (newu != nu.pntsu) {
2265 newnu->flagu &= ~CU_NURB_CYCLIC;
2266 }
2267
2268 for (b = 0, bezt1 = newnu->bezt; b < newnu->pntsu; b++, bezt1++) {
2269 select_beztriple(bezt1, true, flag, HIDDEN);
2270 }
2271
2272 BLI_addtail(newnurb, newnu);
2273 }
2274 }
2275 }
2276
2277 if (cyclicu != 0) {
2278 if (i == cu->actnu) {
2279 calc_duplicate_actvert(editnurb, newnurb, cu, 0, cyclicu, cu->actvert);
2280 }
2281
2282 newnu = BKE_nurb_copy(&nu, cyclicu, 1);
2283 memcpy(newnu->bezt, nu.bezt, cyclicu * sizeof(BezTriple));
2284 newnu->flagu &= ~CU_NURB_CYCLIC;
2285
2286 for (b = 0, bezt1 = newnu->bezt; b < newnu->pntsu; b++, bezt1++) {
2287 select_beztriple(bezt1, true, flag, HIDDEN);
2288 }
2289
2290 BLI_addtail(newnurb, newnu);
2291 }
2292 }
2293 else if (nu.pntsv == 1) { /* because UV Nurb has a different method for dupli */
2294 for (a = 0, bp = nu.bp; a < nu.pntsu; a++, bp++) {
2295 enda = -1;
2296 starta = a;
2297 while (bp->f1 & flag) {
2298 if (!split) {
2299 select_bpoint(bp, false, flag, HIDDEN);
2300 }
2301 enda = a;
2302 if (a >= nu.pntsu - 1) {
2303 break;
2304 }
2305 a++;
2306 bp++;
2307 }
2308 if (enda >= starta) {
2309 newu = diffa = enda - starta + 1; /* set newu and diffa, may use both */
2310
2311 if (starta == 0 && newu != nu.pntsu && (nu.flagu & CU_NURB_CYCLIC)) {
2312 cyclicu = newu;
2313 }
2314 else {
2315 if (enda == nu.pntsu - 1) {
2316 newu += cyclicu;
2317 }
2318 if (i == cu->actnu) {
2320 editnurb, newnurb, cu, starta, starta + diffa, cu->actvert - starta);
2321 }
2322
2323 newnu = BKE_nurb_copy(&nu, newu, 1);
2324 memcpy(newnu->bp, &nu.bp[starta], diffa * sizeof(BPoint));
2325 if (newu != diffa) {
2326 memcpy(&newnu->bp[diffa], nu.bp, cyclicu * sizeof(BPoint));
2327 if (i == cu->actnu) {
2329 editnurb, newnurb, cu, 0, cyclicu, newu - cyclicu + cu->actvert);
2330 }
2331 cyclicu = 0;
2332 }
2333
2334 if (newu != nu.pntsu) {
2335 newnu->flagu &= ~CU_NURB_CYCLIC;
2336 }
2337
2338 for (b = 0, bp1 = newnu->bp; b < newnu->pntsu; b++, bp1++) {
2339 select_bpoint(bp1, true, flag, HIDDEN);
2340 }
2341
2342 BLI_addtail(newnurb, newnu);
2343 }
2344 }
2345 }
2346
2347 if (cyclicu != 0) {
2348 if (i == cu->actnu) {
2349 calc_duplicate_actvert(editnurb, newnurb, cu, 0, cyclicu, cu->actvert);
2350 }
2351
2352 newnu = BKE_nurb_copy(&nu, cyclicu, 1);
2353 memcpy(newnu->bp, nu.bp, cyclicu * sizeof(BPoint));
2354 newnu->flagu &= ~CU_NURB_CYCLIC;
2355
2356 for (b = 0, bp1 = newnu->bp; b < newnu->pntsu; b++, bp1++) {
2357 select_bpoint(bp1, true, flag, HIDDEN);
2358 }
2359
2360 BLI_addtail(newnurb, newnu);
2361 }
2362 }
2363 else {
2364 if (ED_curve_nurb_select_check(v3d, &nu)) {
2365 /* A rectangular area in nurb has to be selected and if splitting
2366 * must be in U or V direction. */
2367 usel = MEM_new_array_zeroed<char>(nu.pntsu, "adduplicateN3");
2368 bp = nu.bp;
2369 for (a = 0; a < nu.pntsv; a++) {
2370 for (b = 0; b < nu.pntsu; b++, bp++) {
2371 if (bp->f1 & flag) {
2372 usel[b]++;
2373 }
2374 }
2375 }
2376 newu = 0;
2377 newv = 0;
2378 for (a = 0; a < nu.pntsu; a++) {
2379 if (usel[a]) {
2380 if (ELEM(newv, 0, usel[a])) {
2381 newv = usel[a];
2382 newu++;
2383 }
2384 else {
2385 newv = 0;
2386 break;
2387 }
2388 }
2389 }
2390 MEM_delete(usel);
2391
2392 if ((newu == 0 || newv == 0) || (split && !isNurbselU(&nu, &newv, BEZT_FLAG_SELECT) &&
2393 !isNurbselV(&nu, &newu, BEZT_FLAG_SELECT)))
2394 {
2395 if (G.debug & G_DEBUG) {
2396 printf("Can't duplicate Nurb\n");
2397 }
2398 }
2399 else {
2400 for (a = 0, bp1 = nu.bp; a < nu.pntsu * nu.pntsv; a++, bp1++) {
2401 newv = newu = 0;
2402
2403 if ((bp1->f1 & flag) && !(bp1->f1 & SURF_SEEN)) {
2404 /* point selected, now loop over points in U and V directions */
2405 for (b = a % nu.pntsu, bp2 = bp1; b < nu.pntsu; b++, bp2++) {
2406 if (bp2->f1 & flag) {
2407 newu++;
2408 for (c = a / nu.pntsu, bp3 = bp2; c < nu.pntsv; c++, bp3 += nu.pntsu) {
2409 if (bp3->f1 & flag) {
2410 /* flag as seen so skipped on future iterations */
2411 bp3->f1 |= SURF_SEEN;
2412 if (newu == 1) {
2413 newv++;
2414 }
2415 }
2416 else {
2417 break;
2418 }
2419 }
2420 }
2421 else {
2422 break;
2423 }
2424 }
2425 }
2426
2427 if ((newu + newv) > 2) {
2428 /* ignore single points */
2429 if (a == 0) {
2430 /* check if need to save cyclic selection and continue if so */
2431 if (newu == nu.pntsu && (nu.flagv & CU_NURB_CYCLIC)) {
2432 cyclicv = newv;
2433 }
2434 if (newv == nu.pntsv && (nu.flagu & CU_NURB_CYCLIC)) {
2435 cyclicu = newu;
2436 }
2437 if (cyclicu != 0 || cyclicv != 0) {
2438 continue;
2439 }
2440 }
2441
2442 if (a + newu == nu.pntsu && cyclicu != 0) {
2443 /* cyclic in U direction */
2444 newnu = BKE_nurb_copy(&nu, newu + cyclicu, newv);
2445 for (b = 0; b < newv; b++) {
2446 memcpy(&newnu->bp[b * newnu->pntsu],
2447 &nu.bp[b * nu.pntsu + a],
2448 newu * sizeof(BPoint));
2449 memcpy(&newnu->bp[b * newnu->pntsu + newu],
2450 &nu.bp[b * nu.pntsu],
2451 cyclicu * sizeof(BPoint));
2452 }
2453
2454 if (cu->actnu == i) {
2455 if (cu->actvert == -1) {
2456 calc_duplicate_actnurb(editnurb, newnurb, cu);
2457 }
2458 else {
2459 for (b = 0, diffa = 0; b < newv; b++, diffa += nu.pntsu - newu) {
2460 starta = b * nu.pntsu + a;
2461 if (calc_duplicate_actvert(editnurb,
2462 newnurb,
2463 cu,
2464 cu->actvert,
2465 starta,
2466 cu->actvert % nu.pntsu + newu + b * newnu->pntsu))
2467 {
2468 /* actvert in cyclicu selection */
2469 break;
2470 }
2471 if (calc_duplicate_actvert(editnurb,
2472 newnurb,
2473 cu,
2474 starta,
2475 starta + newu,
2476 cu->actvert - starta + b * newnu->pntsu))
2477 {
2478 /* actvert in 'current' iteration selection */
2479 break;
2480 }
2481 }
2482 }
2483 }
2484 cyclicu = cyclicv = 0;
2485 }
2486 else if ((a / nu.pntsu) + newv == nu.pntsv && cyclicv != 0) {
2487 /* cyclic in V direction */
2488 newnu = BKE_nurb_copy(&nu, newu, newv + cyclicv);
2489 memcpy(newnu->bp, &nu.bp[a], newu * newv * sizeof(BPoint));
2490 memcpy(&newnu->bp[newu * newv], nu.bp, newu * cyclicv * sizeof(BPoint));
2491
2492 /* check for actvert in cyclicv selection */
2493 if (cu->actnu == i) {
2495 editnurb, newnurb, cu, cu->actvert, a, (newu * newv) + cu->actvert);
2496 }
2497 cyclicu = cyclicv = 0;
2498 }
2499 else {
2500 newnu = BKE_nurb_copy(&nu, newu, newv);
2501 for (b = 0; b < newv; b++) {
2502 memcpy(&newnu->bp[b * newu], &nu.bp[b * nu.pntsu + a], newu * sizeof(BPoint));
2503 }
2504 }
2505
2506 /* general case if not handled by cyclicu or cyclicv */
2507 if (cu->actnu == i) {
2508 if (cu->actvert == -1) {
2509 calc_duplicate_actnurb(editnurb, newnurb, cu);
2510 }
2511 else {
2512 for (b = 0, diffa = 0; b < newv; b++, diffa += nu.pntsu - newu) {
2513 starta = b * nu.pntsu + a;
2515 editnurb,
2516 newnurb,
2517 cu,
2518 starta,
2519 starta + newu,
2520 cu->actvert - (a / nu.pntsu * nu.pntsu + diffa + (starta % nu.pntsu))))
2521 {
2522 break;
2523 }
2524 }
2525 }
2526 }
2527 BLI_addtail(newnurb, newnu);
2528
2529 if (newu != nu.pntsu) {
2530 newnu->flagu &= ~CU_NURB_CYCLIC;
2531 }
2532 if (newv != nu.pntsv) {
2533 newnu->flagv &= ~CU_NURB_CYCLIC;
2534 }
2535 }
2536 }
2537
2538 if (cyclicu != 0 || cyclicv != 0) {
2539 /* copy start of a cyclic surface, or copying all selected points */
2540 newu = cyclicu == 0 ? nu.pntsu : cyclicu;
2541 newv = cyclicv == 0 ? nu.pntsv : cyclicv;
2542
2543 newnu = BKE_nurb_copy(&nu, newu, newv);
2544 for (b = 0; b < newv; b++) {
2545 memcpy(&newnu->bp[b * newu], &nu.bp[b * nu.pntsu], newu * sizeof(BPoint));
2546 }
2547
2548 /* Check for `actvert` in the unused cyclic-UV selection. */
2549 if (cu->actnu == i) {
2550 if (cu->actvert == -1) {
2551 calc_duplicate_actnurb(editnurb, newnurb, cu);
2552 }
2553 else {
2554 for (b = 0, diffa = 0; b < newv; b++, diffa += nu.pntsu - newu) {
2555 starta = b * nu.pntsu;
2556 if (calc_duplicate_actvert(editnurb,
2557 newnurb,
2558 cu,
2559 starta,
2560 starta + newu,
2561 cu->actvert - (diffa + (starta % nu.pntsu))))
2562 {
2563 break;
2564 }
2565 }
2566 }
2567 }
2568 BLI_addtail(newnurb, newnu);
2569
2570 if (newu != nu.pntsu) {
2571 newnu->flagu &= ~CU_NURB_CYCLIC;
2572 }
2573 if (newv != nu.pntsv) {
2574 newnu->flagv &= ~CU_NURB_CYCLIC;
2575 }
2576 }
2577
2578 for (b = 0, bp1 = nu.bp; b < nu.pntsu * nu.pntsv; b++, bp1++) {
2579 bp1->f1 &= ~SURF_SEEN;
2580 if (!split) {
2581 select_bpoint(bp1, false, flag, HIDDEN);
2582 }
2583 }
2584 }
2585 }
2586 }
2587 }
2588
2589 if (newnurb->is_empty() == false) {
2590 for (Nurb &nu : *newnurb) {
2591 if (nu.type == CU_BEZIER) {
2592 if (split) {
2593 /* recalc first and last */
2594 BKE_nurb_handle_calc_simple(&nu, &nu.bezt[0]);
2595 BKE_nurb_handle_calc_simple(&nu, &nu.bezt[nu.pntsu - 1]);
2596 }
2597 }
2598 else {
2599 /* knots done after duplicate as pntsu may change */
2602
2603 if (obedit->type == OB_SURF) {
2604 for (a = 0, bp = nu.bp; a < nu.pntsu * nu.pntsv; a++, bp++) {
2605 bp->f1 &= ~SURF_SEEN;
2606 }
2607
2610 }
2611 }
2612 }
2613 }
2614}
2615
2617
2618/* -------------------------------------------------------------------- */
2621
2623{
2624 Main *bmain = CTX_data_main(C);
2625 const Scene *scene = CTX_data_scene(C);
2626 ViewLayer *view_layer = CTX_data_view_layer(C);
2627 View3D *v3d = CTX_wm_view3d(C);
2628
2630 *bmain, scene, view_layer, CTX_wm_view3d(C));
2631 for (Object *obedit : objects) {
2632 Curve *cu = id_cast<Curve *>(obedit->data);
2633
2634 if (!ED_curve_select_check(v3d, cu->editnurb)) {
2635 continue;
2636 }
2637
2638 EditNurb *editnurb = cu->editnurb;
2639
2640 for (const auto [i, nu] : editnurb->nurbs.enumerate()) {
2641 if (ED_curve_nurb_select_check(v3d, &nu)) {
2644 if ((i == cu->actnu) && (cu->actvert != CU_ACT_NONE)) {
2645 cu->actvert = (nu.pntsu - 1) - cu->actvert;
2646 }
2647 }
2648 }
2649
2650 if (ED_curve_updateAnimPaths(bmain, id_cast<Curve *>(obedit->data))) {
2652 }
2653
2654 DEG_id_tag_update(obedit->data, 0);
2655 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
2656 }
2657 return OPERATOR_FINISHED;
2658}
2659
2661{
2662 /* identifiers */
2663 ot->name = "Switch Direction";
2664 ot->description = "Switch direction of selected splines";
2665 ot->idname = "CURVE_OT_switch_direction";
2666
2667 /* API callbacks. */
2670
2671 /* flags */
2673}
2674
2676
2677/* -------------------------------------------------------------------- */
2680
2682{
2683 const Main *bmain = CTX_data_main(C);
2684 const Scene *scene = CTX_data_scene(C);
2685 ViewLayer *view_layer = CTX_data_view_layer(C);
2687 *bmain, scene, view_layer, CTX_wm_view3d(C));
2688
2689 for (Object *obedit : objects) {
2690 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
2691 BezTriple *bezt;
2692 BPoint *bp;
2693 float weight = RNA_float_get(op->ptr, "weight");
2694 int a;
2695
2696 for (Nurb &nu : *editnurb) {
2697 if (nu.bezt) {
2698 for (bezt = nu.bezt, a = 0; a < nu.pntsu; a++, bezt++) {
2699 if (bezt->f2 & SELECT) {
2700 bezt->weight = weight;
2701 }
2702 }
2703 }
2704 else if (nu.bp) {
2705 for (bp = nu.bp, a = 0; a < nu.pntsu * nu.pntsv; a++, bp++) {
2706 if (bp->f1 & SELECT) {
2707 bp->weight = weight;
2708 }
2709 }
2710 }
2711 }
2712
2713 DEG_id_tag_update(obedit->data, 0);
2714 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
2715 }
2716
2717 return OPERATOR_FINISHED;
2718}
2719
2721{
2722 /* identifiers */
2723 ot->name = "Set Goal Weight";
2724 ot->description = "Set softbody goal weight for selected points";
2725 ot->idname = "CURVE_OT_spline_weight_set";
2726
2727 /* API callbacks. */
2731
2732 /* flags */
2734
2735 /* properties */
2736 RNA_def_float_factor(ot->srna, "weight", 1.0f, 0.0f, 1.0f, "Weight", "", 0.0f, 1.0f);
2737}
2738
2740
2741/* -------------------------------------------------------------------- */
2744
2746{
2747 const Main *bmain = CTX_data_main(C);
2748 const Scene *scene = CTX_data_scene(C);
2749 ViewLayer *view_layer = CTX_data_view_layer(C);
2751 *bmain, scene, view_layer, CTX_wm_view3d(C));
2752
2753 int totobjects = 0;
2754
2755 for (Object *obedit : objects) {
2756
2758 continue;
2759 }
2760
2761 totobjects++;
2762
2763 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
2764 BezTriple *bezt;
2765 BPoint *bp;
2766 float radius = RNA_float_get(op->ptr, "radius");
2767 int a;
2768
2769 for (Nurb &nu : *editnurb) {
2770 if (nu.bezt) {
2771 for (bezt = nu.bezt, a = 0; a < nu.pntsu; a++, bezt++) {
2772 if (bezt->f2 & SELECT) {
2773 bezt->radius = radius;
2774 }
2775 }
2776 }
2777 else if (nu.bp) {
2778 for (bp = nu.bp, a = 0; a < nu.pntsu * nu.pntsv; a++, bp++) {
2779 if (bp->f1 & SELECT) {
2780 bp->radius = radius;
2781 }
2782 }
2783 }
2784 }
2785
2786 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
2787 DEG_id_tag_update(obedit->data, 0);
2788 }
2789
2790 return totobjects ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
2791}
2792
2794{
2795 /* identifiers */
2796 ot->name = "Set Curve Radius";
2797 ot->description = "Set per-point radius which is used for bevel tapering";
2798 ot->idname = "CURVE_OT_radius_set";
2799
2800 /* API callbacks. */
2801 ot->exec = set_radius_exec;
2804
2805 /* flags */
2807
2808 /* properties */
2810 ot->srna, "radius", 1.0f, 0.0f, OBJECT_ADD_SIZE_MAXF, "Radius", "", 0.0001f, 10.0f);
2811}
2812
2814
2815/* -------------------------------------------------------------------- */
2818
2820 const BezTriple *bezt_orig_prev,
2821 const BezTriple *bezt_orig_next,
2822 float factor)
2823{
2824 BLI_assert(IN_RANGE_INCL(factor, 0.0f, 1.0f));
2825
2826 for (int i = 0; i < 3; i++) {
2827 /* get single dimension pos of the mid handle */
2828 float val_old = bezt->vec[1][i];
2829
2830 /* get the weights of the previous/next mid handles and calc offset */
2831 float val_new = (bezt_orig_prev->vec[1][i] * 0.5f) + (bezt_orig_next->vec[1][i] * 0.5f);
2832 float offset = (val_old * (1.0f - factor)) + (val_new * factor) - val_old;
2833
2834 /* offset midpoint and 2 handles */
2835 bezt->vec[1][i] += offset;
2836 bezt->vec[0][i] += offset;
2837 bezt->vec[2][i] += offset;
2838 }
2839}
2840
2844static void smooth_single_bp(BPoint *bp,
2845 const BPoint *bp_orig_prev,
2846 const BPoint *bp_orig_next,
2847 float factor)
2848{
2849 BLI_assert(IN_RANGE_INCL(factor, 0.0f, 1.0f));
2850
2851 for (int i = 0; i < 3; i++) {
2852 float val_old, val_new, offset;
2853
2854 val_old = bp->vec[i];
2855 val_new = (bp_orig_prev->vec[i] * 0.5f) + (bp_orig_next->vec[i] * 0.5f);
2856 offset = (val_old * (1.0f - factor)) + (val_new * factor) - val_old;
2857
2858 bp->vec[i] += offset;
2859 }
2860}
2861
2863{
2864 const float factor = 1.0f / 6.0f;
2865 const Main *bmain = CTX_data_main(C);
2866 const Scene *scene = CTX_data_scene(C);
2867 ViewLayer *view_layer = CTX_data_view_layer(C);
2869 *bmain, scene, view_layer, CTX_wm_view3d(C));
2870
2871 int totobjects = 0;
2872
2873 for (Object *obedit : objects) {
2874
2876 continue;
2877 }
2878
2879 totobjects++;
2880
2881 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
2882
2883 int a, a_end;
2884
2885 for (Nurb &nu : *editnurb) {
2886 if (nu.bezt) {
2887 /* duplicate the curve to use in weight calculation */
2888 const BezTriple *bezt_orig = MEM_dupalloc(nu.bezt);
2889 BezTriple *bezt;
2890 bool changed = false;
2891
2892 /* check whether its cyclic or not, and set initial & final conditions */
2893 if (nu.flagu & CU_NURB_CYCLIC) {
2894 a = 0;
2895 a_end = nu.pntsu;
2896 }
2897 else {
2898 a = 1;
2899 a_end = nu.pntsu - 1;
2900 }
2901
2902 /* for all the curve points */
2903 for (; a < a_end; a++) {
2904 /* respect selection */
2905 bezt = &nu.bezt[a];
2906 if (bezt->f2 & SELECT) {
2907 const BezTriple *bezt_orig_prev, *bezt_orig_next;
2908
2909 bezt_orig_prev = &bezt_orig[mod_i(a - 1, nu.pntsu)];
2910 bezt_orig_next = &bezt_orig[mod_i(a + 1, nu.pntsu)];
2911
2912 smooth_single_bezt(bezt, bezt_orig_prev, bezt_orig_next, factor);
2913
2914 changed = true;
2915 }
2916 }
2917 MEM_delete(bezt_orig);
2918 if (changed) {
2920 }
2921 }
2922 else if (nu.bp) {
2923 /* Same as above, keep these the same! */
2924 const BPoint *bp_orig = MEM_dupalloc(nu.bp);
2925 BPoint *bp;
2926
2927 if (nu.flagu & CU_NURB_CYCLIC) {
2928 a = 0;
2929 a_end = nu.pntsu;
2930 }
2931 else {
2932 a = 1;
2933 a_end = nu.pntsu - 1;
2934 }
2935
2936 for (; a < a_end; a++) {
2937 bp = &nu.bp[a];
2938 if (bp->f1 & SELECT) {
2939 const BPoint *bp_orig_prev, *bp_orig_next;
2940
2941 bp_orig_prev = &bp_orig[mod_i(a - 1, nu.pntsu)];
2942 bp_orig_next = &bp_orig[mod_i(a + 1, nu.pntsu)];
2943
2944 smooth_single_bp(bp, bp_orig_prev, bp_orig_next, factor);
2945 }
2946 }
2947 MEM_delete(bp_orig);
2948 }
2949 }
2950
2951 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
2952 DEG_id_tag_update(obedit->data, 0);
2953 }
2954
2955 return totobjects ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
2956}
2957
2959{
2960 /* identifiers */
2961 ot->name = "Smooth";
2962 ot->description = "Flatten angles of selected points";
2963 ot->idname = "CURVE_OT_smooth";
2964
2965 /* API callbacks. */
2966 ot->exec = smooth_exec;
2968
2969 /* flags */
2971}
2972
2974
2975/* -------------------------------------------------------------------- */
2982
2983static void curve_smooth_value(ListBaseT<Nurb> *editnurb,
2984 const int bezt_offsetof,
2985 const int bp_offset)
2986{
2987 BezTriple *bezt;
2988 BPoint *bp;
2989 int a;
2990
2991 /* use for smoothing */
2992 int last_sel;
2993 int start_sel, end_sel; /* selection indices, inclusive */
2994 float start_rad, end_rad, fac, range;
2995
2996 for (Nurb &nu : *editnurb) {
2997 if (nu.bezt) {
2998#define BEZT_VALUE(bezt) (*((float *)((char *)(bezt) + bezt_offsetof)))
2999
3000 for (last_sel = 0; last_sel < nu.pntsu; last_sel++) {
3001 /* loop over selection segments of a curve, smooth each */
3002
3003 /* Start BezTriple code,
3004 * this is duplicated below for points, make sure these functions stay in sync */
3005 start_sel = -1;
3006 for (bezt = &nu.bezt[last_sel], a = last_sel; a < nu.pntsu; a++, bezt++) {
3007 if (bezt->f2 & SELECT) {
3008 start_sel = a;
3009 break;
3010 }
3011 }
3012 /* in case there are no other selected verts */
3013 end_sel = start_sel;
3014 for (bezt = &nu.bezt[start_sel + 1], a = start_sel + 1; a < nu.pntsu; a++, bezt++) {
3015 if ((bezt->f2 & SELECT) == 0) {
3016 break;
3017 }
3018 end_sel = a;
3019 }
3020
3021 if (start_sel == -1) {
3022 last_sel = nu.pntsu; /* next... */
3023 }
3024 else {
3025 last_sel = end_sel; /* before we modify it */
3026
3027 /* now blend between start and end sel */
3028 start_rad = end_rad = FLT_MAX;
3029
3030 if (start_sel == end_sel) {
3031 /* simple, only 1 point selected */
3032 if (start_sel > 0) {
3033 start_rad = BEZT_VALUE(&nu.bezt[start_sel - 1]);
3034 }
3035 if (start_sel + 1 < nu.pntsu) {
3036 end_rad = BEZT_VALUE(&nu.bezt[start_sel + 1]);
3037 }
3038
3039 if (start_rad != FLT_MAX && end_rad >= FLT_MAX) {
3040 BEZT_VALUE(&nu.bezt[start_sel]) = (start_rad + end_rad) / 2.0f;
3041 }
3042 else if (start_rad != FLT_MAX) {
3043 BEZT_VALUE(&nu.bezt[start_sel]) = start_rad;
3044 }
3045 else if (end_rad != FLT_MAX) {
3046 BEZT_VALUE(&nu.bezt[start_sel]) = end_rad;
3047 }
3048 }
3049 else {
3050 /* if endpoints selected, then use them */
3051 if (start_sel == 0) {
3052 start_rad = BEZT_VALUE(&nu.bezt[start_sel]);
3053 start_sel++; /* we don't want to edit the selected endpoint */
3054 }
3055 else {
3056 start_rad = BEZT_VALUE(&nu.bezt[start_sel - 1]);
3057 }
3058 if (end_sel == nu.pntsu - 1) {
3059 end_rad = BEZT_VALUE(&nu.bezt[end_sel]);
3060 end_sel--; /* we don't want to edit the selected endpoint */
3061 }
3062 else {
3063 end_rad = BEZT_VALUE(&nu.bezt[end_sel + 1]);
3064 }
3065
3066 /* Now Blend between the points */
3067 range = float(end_sel - start_sel) + 2.0f;
3068 for (bezt = &nu.bezt[start_sel], a = start_sel; a <= end_sel; a++, bezt++) {
3069 fac = float(1 + a - start_sel) / range;
3070 BEZT_VALUE(bezt) = start_rad * (1.0f - fac) + end_rad * fac;
3071 }
3072 }
3073 }
3074 }
3075#undef BEZT_VALUE
3076 }
3077 else if (nu.bp) {
3078#define BP_VALUE(bp) (*((float *)((char *)(bp) + bp_offset)))
3079
3080 /* Same as above, keep these the same! */
3081 for (last_sel = 0; last_sel < nu.pntsu; last_sel++) {
3082 /* loop over selection segments of a curve, smooth each */
3083
3084 /* Start BezTriple code,
3085 * this is duplicated below for points, make sure these functions stay in sync */
3086 start_sel = -1;
3087 for (bp = &nu.bp[last_sel], a = last_sel; a < nu.pntsu; a++, bp++) {
3088 if (bp->f1 & SELECT) {
3089 start_sel = a;
3090 break;
3091 }
3092 }
3093 /* in case there are no other selected verts */
3094 end_sel = start_sel;
3095 for (bp = &nu.bp[start_sel + 1], a = start_sel + 1; a < nu.pntsu; a++, bp++) {
3096 if ((bp->f1 & SELECT) == 0) {
3097 break;
3098 }
3099 end_sel = a;
3100 }
3101
3102 if (start_sel == -1) {
3103 last_sel = nu.pntsu; /* next... */
3104 }
3105 else {
3106 last_sel = end_sel; /* before we modify it */
3107
3108 /* now blend between start and end sel */
3109 start_rad = end_rad = FLT_MAX;
3110
3111 if (start_sel == end_sel) {
3112 /* simple, only 1 point selected */
3113 if (start_sel > 0) {
3114 start_rad = BP_VALUE(&nu.bp[start_sel - 1]);
3115 }
3116 if (start_sel + 1 < nu.pntsu) {
3117 end_rad = BP_VALUE(&nu.bp[start_sel + 1]);
3118 }
3119
3120 if (start_rad != FLT_MAX && end_rad != FLT_MAX) {
3121 BP_VALUE(&nu.bp[start_sel]) = (start_rad + end_rad) / 2;
3122 }
3123 else if (start_rad != FLT_MAX) {
3124 BP_VALUE(&nu.bp[start_sel]) = start_rad;
3125 }
3126 else if (end_rad != FLT_MAX) {
3127 BP_VALUE(&nu.bp[start_sel]) = end_rad;
3128 }
3129 }
3130 else {
3131 /* if endpoints selected, then use them */
3132 if (start_sel == 0) {
3133 start_rad = BP_VALUE(&nu.bp[start_sel]);
3134 start_sel++; /* we don't want to edit the selected endpoint */
3135 }
3136 else {
3137 start_rad = BP_VALUE(&nu.bp[start_sel - 1]);
3138 }
3139 if (end_sel == nu.pntsu - 1) {
3140 end_rad = BP_VALUE(&nu.bp[end_sel]);
3141 end_sel--; /* we don't want to edit the selected endpoint */
3142 }
3143 else {
3144 end_rad = BP_VALUE(&nu.bp[end_sel + 1]);
3145 }
3146
3147 /* Now Blend between the points */
3148 range = float(end_sel - start_sel) + 2.0f;
3149 for (bp = &nu.bp[start_sel], a = start_sel; a <= end_sel; a++, bp++) {
3150 fac = float(1 + a - start_sel) / range;
3151 BP_VALUE(bp) = start_rad * (1.0f - fac) + end_rad * fac;
3152 }
3153 }
3154 }
3155 }
3156#undef BP_VALUE
3157 }
3158 }
3159}
3160
3162
3163/* -------------------------------------------------------------------- */
3166
3168{
3169 const Main *bmain = CTX_data_main(C);
3170 const Scene *scene = CTX_data_scene(C);
3171 ViewLayer *view_layer = CTX_data_view_layer(C);
3173 *bmain, scene, view_layer, CTX_wm_view3d(C));
3174
3175 for (Object *obedit : objects) {
3176 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
3177
3178 curve_smooth_value(editnurb, offsetof(BezTriple, weight), offsetof(BPoint, weight));
3179
3180 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
3181 DEG_id_tag_update(obedit->data, 0);
3182 }
3183
3184 return OPERATOR_FINISHED;
3185}
3186
3188{
3189 /* identifiers */
3190 ot->name = "Smooth Curve Weight";
3191 ot->description = "Interpolate weight of selected points";
3192 ot->idname = "CURVE_OT_smooth_weight";
3193
3194 /* API callbacks. */
3197
3198 /* flags */
3200}
3201
3203
3204/* -------------------------------------------------------------------- */
3207
3209{
3210 const Main *bmain = CTX_data_main(C);
3211 const Scene *scene = CTX_data_scene(C);
3212 ViewLayer *view_layer = CTX_data_view_layer(C);
3213
3215 *bmain, scene, view_layer, CTX_wm_view3d(C));
3216
3217 int totobjects = 0;
3218
3219 for (Object *obedit : objects) {
3220
3222 continue;
3223 }
3224
3225 totobjects++;
3226
3227 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
3228
3229 curve_smooth_value(editnurb, offsetof(BezTriple, radius), offsetof(BPoint, radius));
3230
3231 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
3232 DEG_id_tag_update(obedit->data, 0);
3233 }
3234
3235 return totobjects ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
3236}
3237
3239{
3240 /* identifiers */
3241 ot->name = "Smooth Curve Radius";
3242 ot->description = "Interpolate radii of selected points";
3243 ot->idname = "CURVE_OT_smooth_radius";
3244
3245 /* API callbacks. */
3248
3249 /* flags */
3251}
3252
3254
3255/* -------------------------------------------------------------------- */
3258
3260{
3261 const Main *bmain = CTX_data_main(C);
3262 const Scene *scene = CTX_data_scene(C);
3263 ViewLayer *view_layer = CTX_data_view_layer(C);
3265 *bmain, scene, view_layer, CTX_wm_view3d(C));
3266
3267 int totobjects = 0;
3268
3269 for (Object *obedit : objects) {
3270
3272 continue;
3273 }
3274
3275 totobjects++;
3276
3277 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
3278
3279 curve_smooth_value(editnurb, offsetof(BezTriple, tilt), offsetof(BPoint, tilt));
3280
3281 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
3282 DEG_id_tag_update(obedit->data, 0);
3283 }
3284
3285 return totobjects ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
3286}
3287
3289{
3290 /* identifiers */
3291 ot->name = "Smooth Curve Tilt";
3292 ot->description = "Interpolate tilt of selected points";
3293 ot->idname = "CURVE_OT_smooth_tilt";
3294
3295 /* API callbacks. */
3298
3299 /* flags */
3301}
3302
3304
3305/* -------------------------------------------------------------------- */
3308
3310{
3311 const Main *bmain = CTX_data_main(C);
3312 const Scene *scene = CTX_data_scene(C);
3313 ViewLayer *view_layer = CTX_data_view_layer(C);
3314 View3D *v3d = CTX_wm_view3d(C);
3315
3316 const bool invert = RNA_boolean_get(op->ptr, "unselected");
3317
3319 *bmain, scene, view_layer, CTX_wm_view3d(C));
3320 for (Object *obedit : objects) {
3321 Curve *cu = id_cast<Curve *>(obedit->data);
3322
3323 if (!(invert || ED_curve_select_check(v3d, cu->editnurb))) {
3324 continue;
3325 }
3326
3327 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
3328 BPoint *bp;
3329 BezTriple *bezt;
3330 int a, sel;
3331
3332 for (Nurb &nu : *editnurb) {
3333 if (nu.type == CU_BEZIER) {
3334 bezt = nu.bezt;
3335 a = nu.pntsu;
3336 sel = 0;
3337 while (a--) {
3338 if (invert == 0 && BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)) {
3340 bezt->hide = 1;
3341 }
3342 else if (invert && !BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)) {
3344 bezt->hide = 1;
3345 }
3346 if (bezt->hide) {
3347 sel++;
3348 }
3349 bezt++;
3350 }
3351 if (sel == nu.pntsu) {
3352 nu.hide = 1;
3353 }
3354 }
3355 else {
3356 bp = nu.bp;
3357 a = nu.pntsu * nu.pntsv;
3358 sel = 0;
3359 while (a--) {
3360 if (invert == 0 && (bp->f1 & SELECT)) {
3362 bp->hide = 1;
3363 }
3364 else if (invert && (bp->f1 & SELECT) == 0) {
3366 bp->hide = 1;
3367 }
3368 if (bp->hide) {
3369 sel++;
3370 }
3371 bp++;
3372 }
3373 if (sel == nu.pntsu * nu.pntsv) {
3374 nu.hide = 1;
3375 }
3376 }
3377 }
3378
3380 WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
3381 BKE_curve_nurb_vert_active_validate(id_cast<Curve *>(obedit->data));
3382 }
3383 return OPERATOR_FINISHED;
3384}
3385
3387{
3388 /* identifiers */
3389 ot->name = "Hide Selected";
3390 ot->idname = "CURVE_OT_hide";
3391 ot->description = "Hide (un)selected control points";
3392
3393 /* API callbacks. */
3394 ot->exec = hide_exec;
3396
3397 /* flags */
3399
3400 /* props */
3402 ot->srna, "unselected", false, "Unselected", "Hide unselected rather than selected");
3403}
3404
3406
3407/* -------------------------------------------------------------------- */
3410
3412{
3413 const Main *bmain = CTX_data_main(C);
3414 const Scene *scene = CTX_data_scene(C);
3415 ViewLayer *view_layer = CTX_data_view_layer(C);
3416 const bool select = RNA_boolean_get(op->ptr, "select");
3417 bool changed_multi = false;
3418
3420 *bmain, scene, view_layer, CTX_wm_view3d(C));
3421 for (Object *obedit : objects) {
3422 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
3423 BPoint *bp;
3424 BezTriple *bezt;
3425 int a;
3426 bool changed = false;
3427
3428 for (Nurb &nu : *editnurb) {
3429 nu.hide = 0;
3430 if (nu.type == CU_BEZIER) {
3431 bezt = nu.bezt;
3432 a = nu.pntsu;
3433 while (a--) {
3434 if (bezt->hide) {
3436 bezt->hide = 0;
3437 changed = true;
3438 }
3439 bezt++;
3440 }
3441 }
3442 else {
3443 bp = nu.bp;
3444 a = nu.pntsu * nu.pntsv;
3445 while (a--) {
3446 if (bp->hide) {
3448 bp->hide = 0;
3449 changed = true;
3450 }
3451 bp++;
3452 }
3453 }
3454 }
3455
3456 if (changed) {
3457 DEG_id_tag_update(obedit->data,
3459 WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
3460 changed_multi = true;
3461 }
3462 }
3463 return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
3464}
3465
3467{
3468 /* identifiers */
3469 ot->name = "Reveal Hidden";
3470 ot->idname = "CURVE_OT_reveal";
3471 ot->description = "Reveal hidden control points";
3472
3473 /* API callbacks. */
3474 ot->exec = reveal_exec;
3476
3477 /* flags */
3479
3480 RNA_def_boolean(ot->srna, "select", true, "Select", "");
3481}
3482
3484
3485/* -------------------------------------------------------------------- */
3488
3489static void interp_bpoint(BPoint *bp_target,
3490 const BPoint *bp_a,
3491 const BPoint *bp_b,
3492 const float factor)
3493{
3494 interp_v4_v4v4(bp_target->vec, bp_a->vec, bp_b->vec, factor);
3495 bp_target->tilt = interpf(bp_a->tilt, bp_b->tilt, factor);
3496 bp_target->weight = interpf(bp_a->weight, bp_b->weight, factor);
3497 bp_target->radius = interpf(bp_a->radius, bp_b->radius, factor);
3498}
3499
3505static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts)
3506{
3507 Curve *cu = id_cast<Curve *>(obedit->data);
3508 EditNurb *editnurb = cu->editnurb;
3509 BezTriple *bezt, *beztnew, *beztn;
3510 BPoint *bp, *prevbp, *bpnew, *bpn;
3511 float vec[15];
3512 int a, b, sel, amount, *usel, *vsel;
3513 float factor;
3514
3515 // printf("*** subdivideNurb: entering subdivide\n");
3516
3517 for (Nurb &nu : editnurb->nurbs) {
3518 amount = 0;
3519 if (nu.type == CU_BEZIER) {
3520 BezTriple *nextbezt;
3521
3522 /*
3523 * Insert a point into a 2D Bezier curve.
3524 * Endpoints are preserved. Otherwise, all selected and inserted points are
3525 * newly created. Old points are discarded.
3526 */
3527 /* count */
3528 a = nu.pntsu;
3529 bezt = nu.bezt;
3530 while (a--) {
3531 nextbezt = BKE_nurb_bezt_get_next(&nu, bezt);
3532 if (nextbezt == nullptr) {
3533 break;
3534 }
3535
3536 if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt) && BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, nextbezt))
3537 {
3538 amount += number_cuts;
3539 }
3540 bezt++;
3541 }
3542
3543 if (amount) {
3544 /* insert */
3545 beztnew = MEM_new_array_uninitialized<BezTriple>((amount + nu.pntsu), "subdivNurb");
3546 beztn = beztnew;
3547 a = nu.pntsu;
3548 bezt = nu.bezt;
3549 while (a--) {
3550 memcpy(beztn, bezt, sizeof(BezTriple));
3551 keyIndex_updateBezt(editnurb, bezt, beztn, 1);
3552 beztn++;
3553
3554 nextbezt = BKE_nurb_bezt_get_next(&nu, bezt);
3555 if (nextbezt == nullptr) {
3556 break;
3557 }
3558
3559 if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt) &&
3560 BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, nextbezt))
3561 {
3562 float prevvec[3][3];
3563 float prev_tilt = bezt->tilt;
3564 float prev_radius = bezt->radius;
3565 float prev_weight = bezt->weight;
3566
3567 memcpy(prevvec, bezt->vec, sizeof(float[9]));
3568
3569 for (int i = 0; i < number_cuts; i++) {
3570 factor = 1.0f / (number_cuts + 1 - i);
3571
3572 memcpy(beztn, nextbezt, sizeof(BezTriple));
3573
3574 /* midpoint subdividing */
3575 interp_v3_v3v3(vec, prevvec[1], prevvec[2], factor);
3576 interp_v3_v3v3(vec + 3, prevvec[2], nextbezt->vec[0], factor);
3577 interp_v3_v3v3(vec + 6, nextbezt->vec[0], nextbezt->vec[1], factor);
3578
3579 interp_v3_v3v3(vec + 9, vec, vec + 3, factor);
3580 interp_v3_v3v3(vec + 12, vec + 3, vec + 6, factor);
3581
3582 /* change handle of prev beztn */
3583 copy_v3_v3((beztn - 1)->vec[2], vec);
3584 /* new point */
3585 copy_v3_v3(beztn->vec[0], vec + 9);
3586 interp_v3_v3v3(beztn->vec[1], vec + 9, vec + 12, factor);
3587 copy_v3_v3(beztn->vec[2], vec + 12);
3588 /* handle of next bezt */
3589 if (a == 0 && i == number_cuts - 1 && (nu.flagu & CU_NURB_CYCLIC)) {
3590 copy_v3_v3(beztnew->vec[0], vec + 6);
3591 }
3592 else {
3593 copy_v3_v3(nextbezt->vec[0], vec + 6);
3594 }
3595
3596 beztn->tilt = prev_tilt = interpf(nextbezt->tilt, prev_tilt, factor);
3597 beztn->radius = prev_radius = interpf(nextbezt->radius, prev_radius, factor);
3598 beztn->weight = prev_weight = interpf(nextbezt->weight, prev_weight, factor);
3599
3600 memcpy(prevvec, beztn->vec, sizeof(float[9]));
3601
3602 beztn++;
3603 }
3604 }
3605
3606 bezt++;
3607 }
3608
3609 MEM_delete(nu.bezt);
3610 nu.bezt = beztnew;
3611 nu.pntsu += amount;
3612
3614 }
3615 } /* End of 'if (nu->type == CU_BEZIER)' */
3616 else if (nu.pntsv == 1) {
3617 BPoint *nextbp;
3618
3619 /* NOTE(@nzc): All flat lines (ie. co-planar), except flat Nurbs. Flat NURB curves
3620 * are handled together with the regular NURB plane division, as it
3621 * should be. I split it off just now, let's see if it is stable. */
3622
3623 /* Count. */
3624 a = nu.pntsu;
3625 bp = nu.bp;
3626 while (a--) {
3627 nextbp = BKE_nurb_bpoint_get_next(&nu, bp);
3628 if (nextbp == nullptr) {
3629 break;
3630 }
3631
3632 if ((bp->f1 & SELECT) && (nextbp->f1 & SELECT)) {
3633 amount += number_cuts;
3634 }
3635 bp++;
3636 }
3637
3638 if (amount) {
3639 /* insert */
3640 bpnew = MEM_new_array_uninitialized<BPoint>((amount + nu.pntsu), "subdivNurb2");
3641 bpn = bpnew;
3642
3643 a = nu.pntsu;
3644 bp = nu.bp;
3645
3646 while (a--) {
3647 /* Copy "old" point. */
3648 memcpy(bpn, bp, sizeof(BPoint));
3649 keyIndex_updateBP(editnurb, bp, bpn, 1);
3650 bpn++;
3651
3652 nextbp = BKE_nurb_bpoint_get_next(&nu, bp);
3653 if (nextbp == nullptr) {
3654 break;
3655 }
3656
3657 if ((bp->f1 & SELECT) && (nextbp->f1 & SELECT)) {
3658 // printf("*** subdivideNurb: insert 'linear' point\n");
3659 for (int i = 0; i < number_cuts; i++) {
3660 factor = float(i + 1) / (number_cuts + 1);
3661
3662 memcpy(bpn, nextbp, sizeof(BPoint));
3663 interp_bpoint(bpn, bp, nextbp, factor);
3664 bpn++;
3665 }
3666 }
3667 bp++;
3668 }
3669
3670 MEM_delete(nu.bp);
3671 nu.bp = bpnew;
3672 nu.pntsu += amount;
3673
3674 if (nu.type & CU_NURBS) {
3676 }
3677 }
3678 } /* End of 'else if (nu->pntsv == 1)' */
3679 else if (nu.type == CU_NURBS) {
3680 /* This is a very strange test ... */
3721 /* selection-arrays */
3722 usel = MEM_new_array_zeroed<int>(nu.pntsu, "subivideNurb3");
3723 vsel = MEM_new_array_zeroed<int>(nu.pntsv, "subivideNurb3");
3724 sel = 0;
3725
3726 /* Count the number of selected points. */
3727 bp = nu.bp;
3728 for (a = 0; a < nu.pntsv; a++) {
3729 for (b = 0; b < nu.pntsu; b++) {
3730 if (bp->f1 & SELECT) {
3731 usel[b]++;
3732 vsel[a]++;
3733 sel++;
3734 }
3735 bp++;
3736 }
3737 }
3738 if (sel == (nu.pntsu * nu.pntsv)) { /* subdivide entire nurb */
3739 /* Global subdivision is a special case of partial
3740 * subdivision. Strange it is considered separately... */
3741
3742 /* count of nodes (after subdivision) along U axis */
3743 int countu = nu.pntsu + (nu.pntsu - 1) * number_cuts;
3744
3745 /* total count of nodes after subdivision */
3746 int tot = ((number_cuts + 1) * nu.pntsu - number_cuts) *
3747 ((number_cuts + 1) * nu.pntsv - number_cuts);
3748
3749 bpn = bpnew = MEM_new_array_uninitialized<BPoint>(tot, "subdivideNurb4");
3750 bp = nu.bp;
3751 /* first subdivide rows */
3752 for (a = 0; a < nu.pntsv; a++) {
3753 for (b = 0; b < nu.pntsu; b++) {
3754 *bpn = *bp;
3755 keyIndex_updateBP(editnurb, bp, bpn, 1);
3756 bpn++;
3757 bp++;
3758 if (b < nu.pntsu - 1) {
3759 prevbp = bp - 1;
3760 for (int i = 0; i < number_cuts; i++) {
3761 factor = float(i + 1) / (number_cuts + 1);
3762 *bpn = *bp;
3763 interp_bpoint(bpn, prevbp, bp, factor);
3764 bpn++;
3765 }
3766 }
3767 }
3768 bpn += number_cuts * countu;
3769 }
3770 /* now insert new */
3771 bpn = bpnew + ((number_cuts + 1) * nu.pntsu - number_cuts);
3772 bp = bpnew + (number_cuts + 1) * ((number_cuts + 1) * nu.pntsu - number_cuts);
3773 prevbp = bpnew;
3774 for (a = 1; a < nu.pntsv; a++) {
3775
3776 for (b = 0; b < (number_cuts + 1) * nu.pntsu - number_cuts; b++) {
3777 BPoint *tmp = bpn;
3778 for (int i = 0; i < number_cuts; i++) {
3779 factor = float(i + 1) / (number_cuts + 1);
3780 *tmp = *bp;
3781 interp_bpoint(tmp, prevbp, bp, factor);
3782 tmp += countu;
3783 }
3784 bp++;
3785 prevbp++;
3786 bpn++;
3787 }
3788 bp += number_cuts * countu;
3789 bpn += number_cuts * countu;
3790 prevbp += number_cuts * countu;
3791 }
3792 MEM_delete(nu.bp);
3793 nu.bp = bpnew;
3794 nu.pntsu = (number_cuts + 1) * nu.pntsu - number_cuts;
3795 nu.pntsv = (number_cuts + 1) * nu.pntsv - number_cuts;
3798 } /* End of 'if (sel == nu->pntsu * nu->pntsv)' (subdivide entire NURB) */
3799 else {
3800 /* subdivide in v direction? */
3801 sel = 0;
3802 for (a = 0; a < nu.pntsv - 1; a++) {
3803 if (vsel[a] == nu.pntsu && vsel[a + 1] == nu.pntsu) {
3804 sel += number_cuts;
3805 }
3806 }
3807
3808 if (sel) { /* V direction. */
3809 bpn = bpnew = MEM_new_array_uninitialized<BPoint>((sel + nu.pntsv) * nu.pntsu,
3810 "subdivideNurb4");
3811 bp = nu.bp;
3812 for (a = 0; a < nu.pntsv; a++) {
3813 for (b = 0; b < nu.pntsu; b++) {
3814 *bpn = *bp;
3815 keyIndex_updateBP(editnurb, bp, bpn, 1);
3816 bpn++;
3817 bp++;
3818 }
3819 if ((a < nu.pntsv - 1) && vsel[a] == nu.pntsu && vsel[a + 1] == nu.pntsu) {
3820 for (int i = 0; i < number_cuts; i++) {
3821 factor = float(i + 1) / (number_cuts + 1);
3822 prevbp = bp - nu.pntsu;
3823 for (b = 0; b < nu.pntsu; b++) {
3824 /*
3825 * This simple bisection must be replaces by a
3826 * subtle resampling of a number of points. Our
3827 * task is made slightly easier because each
3828 * point in our curve is a separate data
3829 * node. (is it?)
3830 */
3831 *bpn = *prevbp;
3832 interp_bpoint(bpn, prevbp, bp, factor);
3833 bpn++;
3834
3835 prevbp++;
3836 bp++;
3837 }
3838 bp -= nu.pntsu;
3839 }
3840 }
3841 }
3842 MEM_delete(nu.bp);
3843 nu.bp = bpnew;
3844 nu.pntsv += sel;
3846 }
3847 else {
3848 /* or in u direction? */
3849 sel = 0;
3850 for (a = 0; a < nu.pntsu - 1; a++) {
3851 if (usel[a] == nu.pntsv && usel[a + 1] == nu.pntsv) {
3852 sel += number_cuts;
3853 }
3854 }
3855
3856 if (sel) { /* U direction. */
3857 /* Inserting U points is sort of 'default' Flat curves only get
3858 * U points inserted in them. */
3859 bpn = bpnew = MEM_new_array_uninitialized<BPoint>((sel + nu.pntsu) * nu.pntsv,
3860 "subdivideNurb4");
3861 bp = nu.bp;
3862 for (a = 0; a < nu.pntsv; a++) {
3863 for (b = 0; b < nu.pntsu; b++) {
3864 *bpn = *bp;
3865 keyIndex_updateBP(editnurb, bp, bpn, 1);
3866 bpn++;
3867 bp++;
3868 if ((b < nu.pntsu - 1) && usel[b] == nu.pntsv && usel[b + 1] == nu.pntsv) {
3869 /*
3870 * One thing that bugs me here is that the
3871 * orders of things are not the same as in
3872 * the JW piece. Also, this implies that we
3873 * handle at most 3rd order curves? I miss
3874 * some symmetry here...
3875 */
3876 for (int i = 0; i < number_cuts; i++) {
3877 factor = float(i + 1) / (number_cuts + 1);
3878 prevbp = bp - 1;
3879 *bpn = *prevbp;
3880 interp_bpoint(bpn, prevbp, bp, factor);
3881 bpn++;
3882 }
3883 }
3884 }
3885 }
3886 MEM_delete(nu.bp);
3887 nu.bp = bpnew;
3888 nu.pntsu += sel;
3889 BKE_nurb_knot_calc_u(&nu); /* shift knots forward */
3890 }
3891 }
3892 }
3893 MEM_delete(usel);
3894 MEM_delete(vsel);
3895
3896 } /* End of `if (nu->type == CU_NURBS)`. */
3897 }
3898}
3899
3901{
3902 const int number_cuts = RNA_int_get(op->ptr, "number_cuts");
3903
3904 Main *bmain = CTX_data_main(C);
3905 const Scene *scene = CTX_data_scene(C);
3906 ViewLayer *view_layer = CTX_data_view_layer(C);
3907 View3D *v3d = CTX_wm_view3d(C);
3908
3910 *bmain, scene, view_layer, CTX_wm_view3d(C));
3911 for (Object *obedit : objects) {
3912 Curve *cu = id_cast<Curve *>(obedit->data);
3913
3914 if (!ED_curve_select_check(v3d, cu->editnurb)) {
3915 continue;
3916 }
3917
3918 subdividenurb(obedit, v3d, number_cuts);
3919
3920 if (ED_curve_updateAnimPaths(bmain, cu)) {
3922 }
3923
3925 DEG_id_tag_update(obedit->data, 0);
3926 }
3927
3928 return OPERATOR_FINISHED;
3929}
3930
3932{
3933 PropertyRNA *prop;
3934
3935 /* identifiers */
3936 ot->name = "Subdivide";
3937 ot->description = "Subdivide selected segments";
3938 ot->idname = "CURVE_OT_subdivide";
3939
3940 /* API callbacks. */
3941 ot->exec = subdivide_exec;
3943
3944 /* flags */
3946
3947 prop = RNA_def_int(ot->srna, "number_cuts", 1, 1, 1000, "Number of Cuts", "", 1, 10);
3948 /* Avoid re-using last var because it can cause _very_ high poly meshes
3949 * and annoy users (or worse crash). */
3951}
3952
3954
3955/* -------------------------------------------------------------------- */
3958
3960{
3961 const Main *bmain = CTX_data_main(C);
3962 const Scene *scene = CTX_data_scene(C);
3963 ViewLayer *view_layer = CTX_data_view_layer(C);
3965 *bmain, scene, view_layer, CTX_wm_view3d(C));
3967
3968 for (Object *obedit : objects) {
3969 Main *bmain = CTX_data_main(C);
3970 View3D *v3d = CTX_wm_view3d(C);
3971 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
3972 bool changed = false;
3973 bool changed_size = false;
3974 const bool use_handles = RNA_boolean_get(op->ptr, "use_handles");
3975 const int type = RNA_enum_get(op->ptr, "type");
3976
3977 for (Nurb &nu : *editnurb) {
3978 if (ED_curve_nurb_select_check(v3d, &nu)) {
3979 const int pntsu_prev = nu.pntsu;
3980 const char *err_msg = nullptr;
3981 if (BKE_nurb_type_convert(&nu, eNurbType(type), use_handles, &err_msg)) {
3982 changed = true;
3983 if (pntsu_prev != nu.pntsu) {
3984 changed_size = true;
3985 }
3986 }
3987 else {
3988 BKE_report(op->reports, RPT_ERROR, err_msg);
3989 }
3990 }
3991 }
3992
3993 if (changed) {
3994 if (ED_curve_updateAnimPaths(bmain, id_cast<Curve *>(obedit->data))) {
3996 }
3997
3998 DEG_id_tag_update(obedit->data, 0);
3999 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
4000
4001 if (changed_size) {
4002 Curve *cu = id_cast<Curve *>(obedit->data);
4003 cu->actvert = CU_ACT_NONE;
4004 }
4005
4006 ret_value = OPERATOR_FINISHED;
4007 }
4008 }
4009
4010 return ret_value;
4011}
4012
4014{
4015 static const EnumPropertyItem type_items[] = {
4016 {CU_POLY, "POLY", 0, "Poly", ""},
4017 {CU_BEZIER, "BEZIER", 0, "Bézier", ""},
4018 {CU_NURBS, "NURBS", 0, "NURBS", ""},
4019 {0, nullptr, 0, nullptr, nullptr},
4020 };
4021
4022 /* identifiers */
4023 ot->name = "Set Spline Type";
4024 ot->description = "Set type of active spline";
4025 ot->idname = "CURVE_OT_spline_type_set";
4026
4027 /* API callbacks. */
4029 ot->invoke = WM_menu_invoke;
4031
4032 /* flags */
4034
4035 /* properties */
4036 ot->prop = RNA_def_enum(ot->srna, "type", type_items, CU_POLY, "Type", "Spline type");
4038 "use_handles",
4039 false,
4040 "Handles",
4041 "Use handles when converting Bézier curves into polygons");
4042}
4043
4045
4046/* -------------------------------------------------------------------- */
4049
4051{
4052 const Main *bmain = CTX_data_main(C);
4053 const Scene *scene = CTX_data_scene(C);
4054 ViewLayer *view_layer = CTX_data_view_layer(C);
4055 View3D *v3d = CTX_wm_view3d(C);
4056 const eBezTriple_Handle handle_type = eBezTriple_Handle(RNA_enum_get(op->ptr, "type"));
4057 const bool hide_handles = (v3d && (v3d->overlay.handle_display == CURVE_HANDLE_NONE));
4058 const eNurbHandleTest_Mode handle_mode = hide_handles ? NURB_HANDLE_TEST_KNOT_ONLY :
4060
4062 *bmain, scene, view_layer, CTX_wm_view3d(C));
4063 for (Object *obedit : objects) {
4064 Curve *cu = id_cast<Curve *>(obedit->data);
4065
4066 if (!ED_curve_select_check(v3d, cu->editnurb)) {
4067 continue;
4068 }
4069
4070 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
4071 BKE_nurbList_handles_set(editnurb, handle_mode, handle_type);
4072
4073 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
4074 DEG_id_tag_update(obedit->data, 0);
4075 }
4076 return OPERATOR_FINISHED;
4077}
4078
4080{
4081 /* keep in sync with graphkeys_handle_type_items */
4082 static const EnumPropertyItem editcurve_handle_type_items[] = {
4083 {HD_AUTO, "AUTOMATIC", ICON_HANDLE_AUTO, "Automatic", ""},
4084 {HD_VECT, "VECTOR", ICON_HANDLE_VECTOR, "Vector", ""},
4085 {5, "ALIGNED", ICON_HANDLE_ALIGNED, "Aligned", ""},
4086 {6, "FREE_ALIGN", ICON_HANDLE_FREE, "Free", ""},
4087 {3, "TOGGLE_FREE_ALIGN", 0, "Toggle Free/Align", ""},
4088 {0, nullptr, 0, nullptr, nullptr},
4089 };
4090
4091 /* identifiers */
4092 ot->name = "Set Handle Type";
4093 ot->description = "Set type of handles for selected control points";
4094 ot->idname = "CURVE_OT_handle_type_set";
4095
4096 /* API callbacks. */
4097 ot->invoke = WM_menu_invoke;
4100
4101 /* flags */
4103
4104 /* properties */
4105 ot->prop = RNA_def_enum(ot->srna, "type", editcurve_handle_type_items, 1, "Type", "Spline type");
4106}
4107
4109
4110/* -------------------------------------------------------------------- */
4113
4115{
4116 const Main *bmain = CTX_data_main(C);
4117 const Scene *scene = CTX_data_scene(C);
4118 ViewLayer *view_layer = CTX_data_view_layer(C);
4119 View3D *v3d = CTX_wm_view3d(C);
4120
4121 const bool calc_length = RNA_boolean_get(op->ptr, "calc_length");
4122
4124 *bmain, scene, view_layer, CTX_wm_view3d(C));
4125
4126 int totobjects = 0;
4127
4128 for (Object *obedit : objects) {
4129 Curve *cu = id_cast<Curve *>(obedit->data);
4130
4131 if (!ED_curve_select_check(v3d, cu->editnurb)) {
4132 continue;
4133 }
4134
4136 continue;
4137 }
4138
4139 totobjects++;
4140
4141 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
4142 BKE_nurbList_handles_recalculate(editnurb, calc_length, BEZT_FLAG_SELECT);
4143
4144 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
4145 DEG_id_tag_update(obedit->data, 0);
4146 }
4147 return totobjects ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
4148}
4149
4151{
4152 /* identifiers */
4153 ot->name = "Recalculate Handles";
4154 ot->description = "Recalculate the direction of selected handles";
4155 ot->idname = "CURVE_OT_normals_make_consistent";
4156
4157 /* API callbacks. */
4160
4161 /* flags */
4163
4164 /* props */
4165 RNA_def_boolean(ot->srna, "calc_length", false, "Length", "Recalculate handle length");
4166}
4167
4169
4170/* -------------------------------------------------------------------- */
4175
4176static void switchdirection_knots(float *base, int tot)
4177{
4178 float *fp1, *fp2, *tempf;
4179 int a;
4180
4181 if (base == nullptr || tot == 0) {
4182 return;
4183 }
4184
4185 /* reverse knots */
4186 a = tot;
4187 fp1 = base;
4188 fp2 = fp1 + (a - 1);
4189 a /= 2;
4190 while (fp1 != fp2 && a > 0) {
4191 std::swap(*fp1, *fp2);
4192 a--;
4193 fp1++;
4194 fp2--;
4195 }
4196
4197 /* and make in increasing order again */
4198 a = tot - 1;
4199 fp1 = base;
4200 fp2 = tempf = MEM_new_array_uninitialized<float>(tot, "switchdirect");
4201 while (a--) {
4202 fp2[0] = fabsf(fp1[1] - fp1[0]);
4203 fp1++;
4204 fp2++;
4205 }
4206 fp2[0] = 0.0f;
4207
4208 a = tot - 1;
4209 fp1 = base;
4210 fp2 = tempf;
4211 fp1[0] = 0.0;
4212 fp1++;
4213 while (a--) {
4214 fp1[0] = fp1[-1] + fp2[0];
4215 fp1++;
4216 fp2++;
4217 }
4218 MEM_delete(tempf);
4219}
4220
4222{
4223 BPoint *bp1, *bp2, *temp;
4224 int u, v;
4225
4226 std::swap(nu->pntsu, nu->pntsv);
4227 std::swap(nu->orderu, nu->orderv);
4228 std::swap(nu->resolu, nu->resolv);
4229 std::swap(nu->flagu, nu->flagv);
4230
4231 std::swap(nu->knotsu, nu->knotsv);
4233
4234 temp = MEM_dupalloc(nu->bp);
4235 bp1 = nu->bp;
4236 for (v = 0; v < nu->pntsv; v++) {
4237 for (u = 0; u < nu->pntsu; u++, bp1++) {
4238 bp2 = temp + (nu->pntsu - u - 1) * (nu->pntsv) + v;
4239 *bp1 = *bp2;
4240 }
4241 }
4242
4243 MEM_delete(temp);
4244}
4245
4246static bool is_u_selected(Nurb *nu, int u)
4247{
4248 BPoint *bp;
4249 int v;
4250
4251 /* what about resolu == 2? */
4252 bp = &nu->bp[u];
4253 for (v = 0; v < nu->pntsv - 1; v++, bp += nu->pntsu) {
4254 if ((v != 0) && (bp->f1 & SELECT)) {
4255 return true;
4256 }
4257 }
4258
4259 return false;
4260}
4261
4262struct NurbSort {
4265 float vec[3];
4266};
4267
4269 ListBaseT<Nurb> *editnurb,
4270 ListBaseT<NurbSort> *nsortbase)
4271{
4272 ListBaseT<NurbSort> nbase = {nullptr, nullptr};
4273 NurbSort *nus, *nustest, *headdo, *taildo;
4274 BPoint *bp;
4275 float dist, headdist, taildist;
4276 int a;
4277
4278 for (Nurb &nu : *editnurb) {
4279 if (ED_curve_nurb_select_check(v3d, &nu)) {
4280
4281 nus = MEM_new_zeroed<NurbSort>("sort");
4282 BLI_addhead(&nbase, nus);
4283 nus->nu = &nu;
4284
4285 bp = nu.bp;
4286 a = nu.pntsu;
4287 while (a--) {
4288 add_v3_v3(nus->vec, bp->vec);
4289 bp++;
4290 }
4291 mul_v3_fl(nus->vec, 1.0f / float(nu.pntsu));
4292 }
4293 }
4294
4295 /* just add the first one */
4296 nus = nbase.first();
4297 BLI_remlink(&nbase, nus);
4298 BLI_addtail(nsortbase, nus);
4299
4300 /* now add, either at head or tail, the closest one */
4301 while (nbase.first_) {
4302
4303 headdist = taildist = 1.0e30;
4304 headdo = taildo = nullptr;
4305
4306 nustest = nbase.first();
4307 while (nustest) {
4308 dist = len_v3v3(nustest->vec, (nsortbase->first())->vec);
4309
4310 if (dist < headdist) {
4311 headdist = dist;
4312 headdo = nustest;
4313 }
4314 dist = len_v3v3(nustest->vec, (nsortbase->last())->vec);
4315
4316 if (dist < taildist) {
4317 taildist = dist;
4318 taildo = nustest;
4319 }
4320 nustest = nustest->next;
4321 }
4322
4323 if (headdist < taildist) {
4324 BLI_remlink(&nbase, headdo);
4325 BLI_addhead(nsortbase, headdo);
4326 }
4327 else {
4328 BLI_remlink(&nbase, taildo);
4329 BLI_addtail(nsortbase, taildo);
4330 }
4331 }
4332}
4333
4334enum {
4339};
4340
4341static bool merge_2_nurb(Curve *cu, ListBaseT<Nurb> *editnurb, Nurb *nu1, Nurb *nu2)
4342{
4343 BPoint *bp, *bp1, *bp2, *temp;
4344 float len1, len2;
4345 int origu, u, v;
4346
4347 /* first nurbs will be changed to make u = resolu-1 selected */
4348 /* 2nd nurbs will be changed to make u = 0 selected */
4349
4350 /* first nurbs: u = resolu-1 selected */
4351
4352 if (is_u_selected(nu1, nu1->pntsu - 1)) {
4353 /* pass */
4354 }
4355 else {
4356 /* For 2D curves blender uses (orderv = 0). It doesn't make any sense mathematically. */
4357 /* but after rotating (orderu = 0) will be confusing. */
4358 if (nu1->orderv == 0) {
4359 nu1->orderv = 1;
4360 }
4361
4363 if (is_u_selected(nu1, nu1->pntsu - 1)) {
4364 /* pass */
4365 }
4366 else {
4368 if (is_u_selected(nu1, nu1->pntsu - 1)) {
4369 /* pass */
4370 }
4371 else {
4373 if (is_u_selected(nu1, nu1->pntsu - 1)) {
4374 /* pass */
4375 }
4376 else {
4377 /* rotate again, now its OK! */
4378 if (nu1->pntsv != 1) {
4380 }
4381 return true;
4382 }
4383 }
4384 }
4385 }
4386
4387 /* 2nd nurbs: u = 0 selected */
4388 if (is_u_selected(nu2, 0)) {
4389 /* pass */
4390 }
4391 else {
4392 if (nu2->orderv == 0) {
4393 nu2->orderv = 1;
4394 }
4396 if (is_u_selected(nu2, 0)) {
4397 /* pass */
4398 }
4399 else {
4401 if (is_u_selected(nu2, 0)) {
4402 /* pass */
4403 }
4404 else {
4406 if (is_u_selected(nu2, 0)) {
4407 /* pass */
4408 }
4409 else {
4410 /* rotate again, now its OK! */
4411 if (nu1->pntsu == 1) {
4413 }
4414 if (nu2->pntsv != 1) {
4416 }
4417 return true;
4418 }
4419 }
4420 }
4421 }
4422
4423 if (nu1->pntsv != nu2->pntsv) {
4424 return false;
4425 }
4426
4427 /* ok, now nu1 has the rightmost column and nu2 the leftmost column selected */
4428 /* maybe we need a 'v' flip of nu2? */
4429
4430 bp1 = &nu1->bp[nu1->pntsu - 1];
4431 bp2 = nu2->bp;
4432 len1 = 0.0;
4433
4434 for (v = 0; v < nu1->pntsv; v++, bp1 += nu1->pntsu, bp2 += nu2->pntsu) {
4435 len1 += len_v3v3(bp1->vec, bp2->vec);
4436 }
4437
4438 bp1 = &nu1->bp[nu1->pntsu - 1];
4439 bp2 = &nu2->bp[nu2->pntsu * (nu2->pntsv - 1)];
4440 len2 = 0.0;
4441
4442 for (v = 0; v < nu1->pntsv; v++, bp1 += nu1->pntsu, bp2 -= nu2->pntsu) {
4443 len2 += len_v3v3(bp1->vec, bp2->vec);
4444 }
4445
4446 /* merge */
4447 origu = nu1->pntsu;
4448 nu1->pntsu += nu2->pntsu;
4449 if (nu1->orderu < 3 && nu1->orderu < nu1->pntsu) {
4450 nu1->orderu++;
4451 }
4452 if (nu1->orderv < 3 && nu1->orderv < nu1->pntsv) {
4453 nu1->orderv++;
4454 }
4455 temp = nu1->bp;
4456 nu1->bp = MEM_new_array_uninitialized<BPoint>(nu1->pntsu * nu1->pntsv, "mergeBP");
4457
4458 bp = nu1->bp;
4459 bp1 = temp;
4460
4461 for (v = 0; v < nu1->pntsv; v++) {
4462
4463 /* switch direction? */
4464 if (len1 < len2) {
4465 bp2 = &nu2->bp[v * nu2->pntsu];
4466 }
4467 else {
4468 bp2 = &nu2->bp[(nu1->pntsv - v - 1) * nu2->pntsu];
4469 }
4470
4471 for (u = 0; u < nu1->pntsu; u++, bp++) {
4472 if (u < origu) {
4473 keyIndex_updateBP(cu->editnurb, bp1, bp, 1);
4474 *bp = *bp1;
4475 bp1++;
4477 }
4478 else {
4479 keyIndex_updateBP(cu->editnurb, bp2, bp, 1);
4480 *bp = *bp2;
4481 bp2++;
4482 }
4483 }
4484 }
4485
4486 if (nu1->type == CU_NURBS) {
4487 /* merge knots */
4489
4490 /* make knots, for merged curved for example */
4492 }
4493
4494 MEM_delete(temp);
4495 BLI_remlink(editnurb, nu2);
4496 BKE_nurb_free(nu2);
4497 return true;
4498}
4499
4500static int merge_nurb(View3D *v3d, Object *obedit)
4501{
4502 Curve *cu = id_cast<Curve *>(obedit->data);
4503 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
4504 NurbSort *nus1, *nus2;
4505 bool ok = true;
4506 ListBaseT<NurbSort> nsortbase = {nullptr, nullptr};
4507
4508 make_selection_list_nurb(v3d, editnurb, &nsortbase);
4509
4510 if (nsortbase.first_ == nsortbase.last()) {
4511 nsortbase.free_no_destruct();
4513 }
4514
4515 nus1 = nsortbase.first();
4516 nus2 = nus1->next;
4517
4518 /* resolution match, to avoid uv rotations */
4519 if (nus1->nu->pntsv == 1) {
4520 if (ELEM(nus1->nu->pntsu, nus2->nu->pntsu, nus2->nu->pntsv)) {
4521 /* pass */
4522 }
4523 else {
4524 ok = false;
4525 }
4526 }
4527 else if (nus2->nu->pntsv == 1) {
4528 if (ELEM(nus2->nu->pntsu, nus1->nu->pntsu, nus1->nu->pntsv)) {
4529 /* pass */
4530 }
4531 else {
4532 ok = false;
4533 }
4534 }
4535 else if (nus1->nu->pntsu == nus2->nu->pntsu || nus1->nu->pntsv == nus2->nu->pntsv) {
4536 /* pass */
4537 }
4538 else if (nus1->nu->pntsu == nus2->nu->pntsv || nus1->nu->pntsv == nus2->nu->pntsu) {
4539 /* pass */
4540 }
4541 else {
4542 ok = false;
4543 }
4544
4545 if (ok == false) {
4546 nsortbase.free_no_destruct();
4548 }
4549
4550 while (nus2) {
4551 /* There is a change a few curves merged properly, but not all.
4552 * In this case we still update the curve, yet report the error. */
4553 ok &= merge_2_nurb(cu, editnurb, nus1->nu, nus2->nu);
4554 nus2 = nus2->next;
4555 }
4556
4557 nsortbase.free_no_destruct();
4558 BKE_curve_nurb_active_set(id_cast<Curve *>(obedit->data), nullptr);
4559
4561}
4562
4564{
4565 Main *bmain = CTX_data_main(C);
4566 const Scene *scene = CTX_data_scene(C);
4567 ViewLayer *view_layer = CTX_data_view_layer(C);
4568 View3D *v3d = CTX_wm_view3d(C);
4569
4570 struct {
4571 int changed;
4572 int unselected;
4573 int error_selected_few;
4574 int error_resolution;
4575 int error_generic;
4576 } status = {0};
4577
4579 *bmain, scene, view_layer, CTX_wm_view3d(C));
4580 for (Object *obedit : objects) {
4581 Curve *cu = id_cast<Curve *>(obedit->data);
4582
4583 if (!ED_curve_select_check(v3d, cu->editnurb)) {
4584 status.unselected++;
4585 continue;
4586 }
4587
4588 ListBaseT<Nurb> *nubase = object_editcurve_get(obedit);
4589 Nurb *nu, *nu1 = nullptr, *nu2 = nullptr;
4590 BPoint *bp;
4591 bool ok = false;
4592
4593 /* first decide if this is a surface merge! */
4594 if (obedit->type == OB_SURF) {
4595 nu = nubase->first();
4596 }
4597 else {
4598 nu = nullptr;
4599 }
4600
4601 while (nu) {
4602 const int nu_select_num = ED_curve_nurb_select_count(v3d, nu);
4603 if (nu_select_num) {
4604
4605 if (nu->pntsu > 1 && nu->pntsv > 1) {
4606 break;
4607 }
4608
4609 if (nu_select_num > 1) {
4610 break;
4611 }
4612 /* only 1 selected, not first or last, a little complex, but intuitive */
4613 if (nu->pntsv == 1) {
4614 if ((nu->bp->f1 & SELECT) || (nu->bp[nu->pntsu - 1].f1 & SELECT)) {
4615 /* pass */
4616 }
4617 else {
4618 break;
4619 }
4620 }
4621 }
4622 nu = nu->next;
4623 }
4624
4625 if (nu) {
4626 int merge_result = merge_nurb(v3d, obedit);
4627 switch (merge_result) {
4628 case CURVE_MERGE_OK:
4629 status.changed++;
4630 goto curve_merge_tag_object;
4632 status.error_resolution++;
4633 goto curve_merge_tag_object;
4635 status.error_selected_few++;
4636 break;
4638 status.error_resolution++;
4639 break;
4640 }
4641 continue;
4642 }
4643
4644 /* find both nurbs and points, nu1 will be put behind nu2 */
4645 for (Nurb &nu : *nubase) {
4646 if (nu.pntsu == 1) {
4647 nu.flagu &= ~CU_NURB_CYCLIC;
4648 }
4649
4650 if ((nu.flagu & CU_NURB_CYCLIC) == 0) { /* not cyclic */
4651 if (nu.type == CU_BEZIER) {
4652 if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, &(nu.bezt[nu.pntsu - 1]))) {
4653 /* Last point is selected, preferred for nu2 */
4654 if (nu2 == nullptr) {
4655 nu2 = &nu;
4656 }
4657 else if (nu1 == nullptr) {
4658 nu1 = &nu;
4659
4660 /* Just in case both of first/last CV are selected check
4661 * whether we really need to switch the direction.
4662 */
4663 if (!BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, nu1->bezt)) {
4666 }
4667 }
4668 }
4669 else if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, nu.bezt)) {
4670 /* First point is selected, preferred for nu1 */
4671 if (nu1 == nullptr) {
4672 nu1 = &nu;
4673 }
4674 else if (nu2 == nullptr) {
4675 nu2 = &nu;
4676
4677 /* Just in case both of first/last CV are selected check
4678 * whether we really need to switch the direction.
4679 */
4680 if (!BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, &(nu.bezt[nu2->pntsu - 1]))) {
4683 }
4684 }
4685 }
4686 }
4687 else if (nu.pntsv == 1) {
4688 /* Same logic as above: if first point is selected spline is
4689 * preferred for nu1, if last point is selected spline is
4690 * preferred for u2u.
4691 */
4692
4693 bp = nu.bp;
4694 if (bp[nu.pntsu - 1].f1 & SELECT) {
4695 if (nu2 == nullptr) {
4696 nu2 = &nu;
4697 }
4698 else if (nu1 == nullptr) {
4699 nu1 = &nu;
4700
4701 if ((bp->f1 & SELECT) == 0) {
4704 }
4705 }
4706 }
4707 else if (bp->f1 & SELECT) {
4708 if (nu1 == nullptr) {
4709 nu1 = &nu;
4710 }
4711 else if (nu2 == nullptr) {
4712 nu2 = &nu;
4713
4714 if ((bp[nu.pntsu - 1].f1 & SELECT) == 0) {
4717 }
4718 }
4719 }
4720 }
4721 }
4722
4723 if (nu1 && nu2) {
4724 /* Got second spline, no need to loop over rest of the splines. */
4725 break;
4726 }
4727 }
4728
4729 if ((nu1 && nu2) && (nu1 != nu2)) {
4730 if (nu1->type == nu2->type) {
4731 if (nu1->type == CU_BEZIER) {
4732 BezTriple *bezt = MEM_new_array_uninitialized<BezTriple>((nu1->pntsu + nu2->pntsu),
4733 "addsegmentN");
4734 ED_curve_beztcpy(cu->editnurb, bezt, nu2->bezt, nu2->pntsu);
4735 ED_curve_beztcpy(cu->editnurb, bezt + nu2->pntsu, nu1->bezt, nu1->pntsu);
4736
4737 MEM_delete(nu1->bezt);
4738 nu1->bezt = bezt;
4739 nu1->pntsu += nu2->pntsu;
4740 BLI_remlink(nubase, nu2);
4741 keyIndex_delNurb(cu->editnurb, nu2);
4742 BKE_nurb_free(nu2);
4743 nu2 = nullptr;
4745 }
4746 else {
4747 bp = MEM_new_array_uninitialized<BPoint>((nu1->pntsu + nu2->pntsu), "addsegmentN2");
4748 ED_curve_bpcpy(cu->editnurb, bp, nu2->bp, nu2->pntsu);
4749 ED_curve_bpcpy(cu->editnurb, bp + nu2->pntsu, nu1->bp, nu1->pntsu);
4750 MEM_delete(nu1->bp);
4751 nu1->bp = bp;
4752
4753 // a = nu1->pntsu + nu1->orderu; /* UNUSED */
4754
4755 nu1->pntsu += nu2->pntsu;
4756 BLI_remlink(nubase, nu2);
4757
4758 /* now join the knots */
4759 if (nu1->type == CU_NURBS) {
4760 MEM_SAFE_DELETE(nu1->knotsu);
4761
4763 }
4764 keyIndex_delNurb(cu->editnurb, nu2);
4765 BKE_nurb_free(nu2);
4766 nu2 = nullptr;
4767 }
4768
4769 BKE_curve_nurb_active_set(cu, nu1); /* for selected */
4770 ok = true;
4771 }
4772 }
4773 else if ((nu1 && !nu2) || (!nu1 && nu2)) {
4774 if (nu2) {
4775 std::swap(nu1, nu2);
4776 }
4777
4778 if (!(nu1->flagu & CU_NURB_CYCLIC) && nu1->pntsu > 1) {
4779 if (nu1->type == CU_BEZIER && BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, nu1->bezt) &&
4780 BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, &nu1->bezt[nu1->pntsu - 1]))
4781 {
4782 nu1->flagu |= CU_NURB_CYCLIC;
4784 ok = true;
4785 }
4786 else if (ELEM(nu1->type, CU_NURBS, CU_POLY) && nu1->bp->f1 & SELECT &&
4787 (nu1->bp[nu1->pntsu - 1].f1 & SELECT))
4788 {
4789 nu1->flagu |= CU_NURB_CYCLIC;
4791 ok = true;
4792 }
4793 }
4794 }
4795
4796 if (!ok) {
4797 status.error_generic++;
4798 continue;
4799 }
4800
4801 if (ED_curve_updateAnimPaths(bmain, id_cast<Curve *>(obedit->data))) {
4803 }
4804
4805 status.changed++;
4806
4807 curve_merge_tag_object:
4808 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
4809 DEG_id_tag_update(obedit->data, 0);
4810 }
4811
4812 if (status.unselected == objects.size()) {
4813 BKE_report(op->reports, RPT_ERROR, "No points were selected");
4814 return OPERATOR_CANCELLED;
4815 }
4816
4817 const int tot_errors = status.error_selected_few + status.error_resolution +
4818 status.error_generic;
4819 if (tot_errors > 0) {
4820 /* Some curves changed, but some curves failed: don't explain why it failed. */
4821 if (status.changed) {
4822 BKE_reportf(op->reports, RPT_INFO, "%d curves could not make segments", tot_errors);
4823 return OPERATOR_FINISHED;
4824 }
4825
4826 /* All curves failed: If there is more than one error give a generic error report. */
4827 if (((status.error_selected_few ? 1 : 0) + (status.error_resolution ? 1 : 0) +
4828 (status.error_generic ? 1 : 0)) > 1)
4829 {
4830 BKE_report(op->reports, RPT_ERROR, "Could not make new segments");
4831 }
4832
4833 /* All curves failed due to the same error. */
4834 if (status.error_selected_few) {
4835 BKE_report(op->reports, RPT_ERROR, "Too few selections to merge");
4836 }
4837 else if (status.error_resolution) {
4838 BKE_report(op->reports, RPT_ERROR, "Resolution does not match");
4839 }
4840 else {
4841 BLI_assert(status.error_generic);
4842 BKE_report(op->reports, RPT_ERROR, "Cannot make segment");
4843 }
4844 return OPERATOR_CANCELLED;
4845 }
4846
4847 return OPERATOR_FINISHED;
4848}
4849
4851{
4852 /* identifiers */
4853 ot->name = "Make Segment";
4854 ot->idname = "CURVE_OT_make_segment";
4855 ot->description = "Join two curves by their selected ends";
4856
4857 /* API callbacks. */
4858 ot->exec = make_segment_exec;
4860
4861 /* flags */
4863}
4864
4866
4867/* -------------------------------------------------------------------- */
4870
4872 const int mval[2],
4873 const int dist_px,
4874 const SelectPick_Params &params)
4875{
4876 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
4877 Nurb *nu;
4878 BezTriple *bezt = nullptr;
4879 BPoint *bp = nullptr;
4880 Base *basact = nullptr;
4881 short hand;
4882 bool changed = false;
4883
4885 ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
4886 copy_v2_v2_int(vc.mval, mval);
4887
4888 const bool use_handle_select = (vc.v3d->overlay.handle_display != CURVE_HANDLE_NONE);
4889
4890 bool found = ED_curve_pick_vert_ex(&vc, true, dist_px, &nu, &bezt, &bp, &hand, &basact);
4891
4892 if (params.sel_op == SEL_OP_SET) {
4893 if ((found && params.select_passthrough) &&
4894 (((bezt ? uint8_t((&bezt->f1)[hand]) : bp->f1) & SELECT) != 0))
4895 {
4896 found = false;
4897 }
4898 else if (found || params.deselect_all) {
4899 /* Deselect everything. */
4901 *vc.bmain, vc.scene, vc.view_layer, vc.v3d);
4902 for (Object *ob_iter : objects) {
4903 ED_curve_deselect_all((id_cast<Curve *>(ob_iter->data))->editnurb);
4905 WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob_iter->data);
4906 }
4907 changed = true;
4908 }
4909 }
4910
4911 if (found) {
4912 Object *obedit = basact->object;
4913 Curve *cu = id_cast<Curve *>(obedit->data);
4914 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
4915 const void *vert = BKE_curve_vert_active_get(cu);
4916
4917 switch (params.sel_op) {
4918 case SEL_OP_ADD: {
4919 if (bezt) {
4920 if (hand == 1) {
4921 if (use_handle_select) {
4922 bezt->f2 |= BEZT_FLAG_SELECT;
4923 }
4924 else {
4926 }
4927 }
4928 else {
4929 if (hand == 0) {
4930 bezt->f1 |= BEZT_FLAG_SELECT;
4931 }
4932 else {
4933 bezt->f3 |= BEZT_FLAG_SELECT;
4934 }
4935 }
4936 BKE_curve_nurb_vert_active_set(cu, nu, bezt);
4937 }
4938 else {
4941 }
4942 break;
4943 }
4944 case SEL_OP_SUB: {
4945 if (bezt) {
4946 if (hand == 1) {
4947 if (use_handle_select) {
4948 bezt->f2 &= ~BEZT_FLAG_SELECT;
4949 }
4950 else {
4952 }
4953 if (bezt == vert) {
4954 cu->actvert = CU_ACT_NONE;
4955 }
4956 }
4957 else if (hand == 0) {
4958 bezt->f1 &= ~BEZT_FLAG_SELECT;
4959 }
4960 else {
4961 bezt->f3 &= ~BEZT_FLAG_SELECT;
4962 }
4963 }
4964 else {
4966 if (bp == vert) {
4967 cu->actvert = CU_ACT_NONE;
4968 }
4969 }
4970 break;
4971 }
4972 case SEL_OP_XOR: {
4973 if (bezt) {
4974 if (hand == 1) {
4975 if (bezt->f2 & SELECT) {
4976 if (use_handle_select) {
4977 bezt->f2 &= ~BEZT_FLAG_SELECT;
4978 }
4979 else {
4981 }
4982 if (bezt == vert) {
4983 cu->actvert = CU_ACT_NONE;
4984 }
4985 }
4986 else {
4987 if (use_handle_select) {
4988 bezt->f2 |= BEZT_FLAG_SELECT;
4989 }
4990 else {
4992 }
4993 BKE_curve_nurb_vert_active_set(cu, nu, bezt);
4994 }
4995 }
4996 else if (hand == 0) {
4997 bezt->f1 ^= BEZT_FLAG_SELECT;
4998 }
4999 else {
5000 bezt->f3 ^= BEZT_FLAG_SELECT;
5001 }
5002 }
5003 else {
5004 if (bp->f1 & SELECT) {
5006 if (bp == vert) {
5007 cu->actvert = CU_ACT_NONE;
5008 }
5009 }
5010 else {
5013 }
5014 }
5015 break;
5016 }
5017 case SEL_OP_SET: {
5018 BKE_nurbList_flag_set(editnurb, BEZT_FLAG_SELECT, false);
5019
5020 if (bezt) {
5021
5022 if (hand == 1) {
5023 if (use_handle_select) {
5024 bezt->f2 |= BEZT_FLAG_SELECT;
5025 }
5026 else {
5028 }
5029 }
5030 else {
5031 if (hand == 0) {
5032 bezt->f1 |= BEZT_FLAG_SELECT;
5033 }
5034 else {
5035 bezt->f3 |= BEZT_FLAG_SELECT;
5036 }
5037 }
5038 BKE_curve_nurb_vert_active_set(cu, nu, bezt);
5039 }
5040 else {
5043 }
5044 break;
5045 }
5046 case SEL_OP_AND: {
5047 BLI_assert_unreachable(); /* Doesn't make sense for picking. */
5048 break;
5049 }
5050 }
5051
5052 if (nu != BKE_curve_nurb_active_get(cu)) {
5053 cu->actvert = CU_ACT_NONE;
5055 }
5056
5057 /* Change active material on object. */
5059
5061 if (BKE_view_layer_active_base_get(vc.view_layer) != basact) {
5063 }
5064
5067
5068 changed = true;
5069 }
5070
5071 return changed || found;
5072}
5073
5075
5076/* -------------------------------------------------------------------- */
5079
5081 float viewmat[4][4], View3D *v3d, Object *obedit, const float axis[3], const float cent[3])
5082{
5083 Curve *cu = id_cast<Curve *>(obedit->data);
5084 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
5085 float cmat[3][3], tmat[3][3], imat[3][3];
5086 float bmat[3][3], rotmat[3][3], scalemat1[3][3], scalemat2[3][3];
5087 float persmat[3][3], persinv[3][3];
5088 bool ok, changed = false;
5089 int a;
5090
5091 copy_m3_m4(persmat, viewmat);
5092 invert_m3_m3(persinv, persmat);
5093
5094 /* imat and center and size */
5095 copy_m3_m4(bmat, obedit->object_to_world().ptr());
5096 invert_m3_m3(imat, bmat);
5097
5098 axis_angle_to_mat3(cmat, axis, M_PI_4);
5099 mul_m3_m3m3(tmat, cmat, bmat);
5100 mul_m3_m3m3(rotmat, imat, tmat);
5101
5102 unit_m3(scalemat1);
5103 scalemat1[0][0] = M_SQRT2;
5104 scalemat1[1][1] = M_SQRT2;
5105
5106 mul_m3_m3m3(tmat, persmat, bmat);
5107 mul_m3_m3m3(cmat, scalemat1, tmat);
5108 mul_m3_m3m3(tmat, persinv, cmat);
5109 mul_m3_m3m3(scalemat1, imat, tmat);
5110
5111 unit_m3(scalemat2);
5112 scalemat2[0][0] /= float(M_SQRT2);
5113 scalemat2[1][1] /= float(M_SQRT2);
5114
5115 mul_m3_m3m3(tmat, persmat, bmat);
5116 mul_m3_m3m3(cmat, scalemat2, tmat);
5117 mul_m3_m3m3(tmat, persinv, cmat);
5118 mul_m3_m3m3(scalemat2, imat, tmat);
5119
5120 ok = true;
5121
5122 for (a = 0; a < 7; a++) {
5124
5125 if (ok == false) {
5126 return changed;
5127 }
5128
5129 changed = true;
5130
5131 rotateflagNurb(editnurb, BEZT_FLAG_SELECT, cent, rotmat);
5132
5133 if ((a & 1) == 0) {
5134 rotateflagNurb(editnurb, BEZT_FLAG_SELECT, cent, scalemat1);
5135 weightflagNurb(editnurb, SELECT, 0.5 * M_SQRT2);
5136 }
5137 else {
5138 rotateflagNurb(editnurb, BEZT_FLAG_SELECT, cent, scalemat2);
5139 weightflagNurb(editnurb, SELECT, 2.0 / M_SQRT2);
5140 }
5141 }
5142
5143 if (ok) {
5144 for (Nurb &nu : *editnurb) {
5145 if (ED_curve_nurb_select_check(v3d, &nu)) {
5146 nu.orderv = 3;
5147 /* It is challenging to create a good approximation of a circle with uniform knots vector
5148 * (which is forced in Blender for cyclic NURBS curves). Here a NURBS circle is constructed
5149 * by connecting four Bezier arcs. */
5152 }
5153 }
5154 }
5155
5156 return changed;
5157}
5158
5160{
5161 Main *bmain = CTX_data_main(C);
5162 const Scene *scene = CTX_data_scene(C);
5163 ViewLayer *view_layer = CTX_data_view_layer(C);
5164 View3D *v3d = CTX_wm_view3d(C);
5166 float cent[3], axis[3], viewmat[4][4];
5167 bool changed = false;
5168 int count_failed = 0;
5169
5170 RNA_float_get_array(op->ptr, "center", cent);
5171 RNA_float_get_array(op->ptr, "axis", axis);
5172
5173 if (rv3d) {
5174 copy_m4_m4(viewmat, rv3d->viewmat);
5175 }
5176 else {
5177 unit_m4(viewmat);
5178 }
5179
5181 *bmain, scene, view_layer, CTX_wm_view3d(C));
5182 for (Object *obedit : objects) {
5183 Curve *cu = id_cast<Curve *>(obedit->data);
5184
5185 if (!ED_curve_select_check(v3d, cu->editnurb)) {
5186 continue;
5187 }
5188
5189 invert_m4_m4(obedit->runtime->world_to_object.ptr(), obedit->object_to_world().ptr());
5190 mul_m4_v3(obedit->world_to_object().ptr(), cent);
5191
5192 if (!ed_editnurb_spin(viewmat, v3d, obedit, axis, cent)) {
5193 count_failed += 1;
5194 continue;
5195 }
5196
5197 changed = true;
5198 if (ED_curve_updateAnimPaths(bmain, cu)) {
5200 }
5201
5202 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
5203 DEG_id_tag_update(obedit->data, 0);
5204 }
5205
5206 if (changed == false) {
5207 if (count_failed != 0) {
5208 BKE_report(op->reports, RPT_ERROR, "Cannot spin");
5209 }
5210 return OPERATOR_CANCELLED;
5211 }
5212 return OPERATOR_FINISHED;
5213}
5214
5216{
5217 Scene *scene = CTX_data_scene(C);
5219 float axis[3] = {0.0f, 0.0f, 1.0f};
5220
5221 if (rv3d) {
5222 copy_v3_v3(axis, rv3d->viewinv[2]);
5223 }
5224
5225 RNA_float_set_array(op->ptr, "center", scene->cursor.location);
5226 RNA_float_set_array(op->ptr, "axis", axis);
5227
5228 return spin_exec(C, op);
5229}
5230
5232{
5233 /* identifiers */
5234 ot->name = "Spin";
5235 ot->idname = "CURVE_OT_spin";
5236 ot->description = "Extrude selected boundary row around pivot point and current view axis";
5237
5238 /* API callbacks. */
5239 ot->exec = spin_exec;
5240 ot->invoke = spin_invoke;
5242
5243 /* flags */
5245
5247 "center",
5248 3,
5249 nullptr,
5252 "Center",
5253 "Center in global view space",
5254 -1000.0f,
5255 1000.0f);
5257 ot->srna, "axis", 3, nullptr, -1.0f, 1.0f, "Axis", "Axis in global view space", -1.0f, 1.0f);
5258}
5259
5261
5262/* -------------------------------------------------------------------- */
5265
5266static bool ed_editcurve_extrude(Curve *cu, EditNurb *editnurb, View3D *v3d)
5267{
5268 bool changed = false;
5269
5270 Nurb *cu_actnu;
5271 union {
5272 BezTriple *bezt;
5273 BPoint *bp;
5274 void *p;
5275 } cu_actvert;
5276
5277 if (editnurb->nurbs.is_empty()) {
5278 return changed;
5279 }
5280
5281 BKE_curve_nurb_vert_active_get(cu, &cu_actnu, &cu_actvert.p);
5282 int act_offset = 0;
5283
5284 for (Nurb &nu : editnurb->nurbs) {
5285 BLI_assert(nu.pntsu > 0);
5286 int i;
5287 int pnt_len = nu.pntsu;
5288 int new_points = 0;
5289 int offset = 0;
5290 bool is_prev_selected = false;
5291 bool duplic_first = false;
5292 bool duplic_last = false;
5293 if (nu.type == CU_BEZIER) {
5294 BezTriple *bezt, *bezt_prev = nullptr;
5295 BezTriple bezt_stack;
5296 bool is_cyclic = false;
5297 if (pnt_len == 1) {
5298 /* Single point extrusion.
5299 * Keep `is_prev_selected` false to force extrude. */
5300 bezt_prev = &nu.bezt[0];
5301 }
5302 else if (nu.flagu & CU_NURB_CYCLIC) {
5303 is_cyclic = true;
5304 bezt_prev = &nu.bezt[pnt_len - 1];
5305 is_prev_selected = BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt_prev);
5306 }
5307 else {
5308 duplic_first = BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, &nu.bezt[0]) &&
5310
5311 duplic_last = BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, &nu.bezt[pnt_len - 2]) &&
5312 BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, &nu.bezt[pnt_len - 1]);
5313
5314 if (duplic_first) {
5315 bezt_stack = nu.bezt[0];
5316 BEZT_DESEL_ALL(&bezt_stack);
5317 bezt_prev = &bezt_stack;
5318 }
5319 if (duplic_last) {
5320 new_points++;
5321 }
5322 }
5323 i = pnt_len;
5324 for (bezt = &nu.bezt[0]; i--; bezt++) {
5325 bool is_selected = BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt);
5326 if (bezt_prev && is_prev_selected != is_selected) {
5327 new_points++;
5328 }
5329 if (bezt == cu_actvert.bezt) {
5330 act_offset = new_points;
5331 }
5332 bezt_prev = bezt;
5333 is_prev_selected = is_selected;
5334 }
5335
5336 if (new_points) {
5337 if (pnt_len == 1) {
5338 /* Single point extrusion.
5339 * Set `is_prev_selected` as false to force extrude. */
5340 BLI_assert(bezt_prev == &nu.bezt[0]);
5341 is_prev_selected = false;
5342 }
5343 else if (is_cyclic) {
5344 BLI_assert(bezt_prev == &nu.bezt[pnt_len - 1]);
5345 BLI_assert(is_prev_selected == BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt_prev));
5346 }
5347 else if (duplic_first) {
5348 bezt_prev = &bezt_stack;
5349 is_prev_selected = false;
5350 }
5351 else {
5352 bezt_prev = nullptr;
5353 }
5354 BezTriple *bezt_src, *bezt_dst, *bezt_src_iter, *bezt_dst_iter;
5355 const int new_len = pnt_len + new_points;
5356
5357 bezt_src = nu.bezt;
5358 bezt_dst = MEM_new_array_uninitialized<BezTriple>(new_len, __func__);
5359 bezt_src_iter = &bezt_src[0];
5360 bezt_dst_iter = &bezt_dst[0];
5361 i = 0;
5362 for (bezt = &nu.bezt[0]; i < pnt_len; i++, bezt++) {
5363 bool is_selected = BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt);
5364 /* While this gets de-selected, selecting here ensures newly created verts are selected.
5365 * without this, the vertices are copied but only the handles are transformed.
5366 * which seems buggy from a user perspective. */
5367 if (is_selected) {
5368 bezt->f2 |= BEZT_FLAG_SELECT;
5369 }
5370 if (bezt_prev && is_prev_selected != is_selected) {
5371 int count = i - offset + 1;
5372 if (is_prev_selected) {
5373 ED_curve_beztcpy(editnurb, bezt_dst_iter, bezt_src_iter, count - 1);
5374 ED_curve_beztcpy(editnurb, &bezt_dst_iter[count - 1], bezt_prev, 1);
5375 }
5376 else {
5377 ED_curve_beztcpy(editnurb, bezt_dst_iter, bezt_src_iter, count);
5378 }
5379 ED_curve_beztcpy(editnurb, &bezt_dst_iter[count], bezt, 1);
5380 BEZT_DESEL_ALL(&bezt_dst_iter[count - 1]);
5381
5382 bezt_dst_iter += count + 1;
5383 bezt_src_iter += count;
5384 offset = i + 1;
5385 }
5386 bezt_prev = bezt;
5387 is_prev_selected = is_selected;
5388 }
5389
5390 int remain = pnt_len - offset;
5391 if (remain) {
5392 ED_curve_beztcpy(editnurb, bezt_dst_iter, bezt_src_iter, remain);
5393 }
5394
5395 if (duplic_last) {
5396 ED_curve_beztcpy(editnurb, &bezt_dst[new_len - 1], &bezt_src[pnt_len - 1], 1);
5397 BEZT_DESEL_ALL(&bezt_dst[new_len - 1]);
5398 }
5399
5400 MEM_delete(nu.bezt);
5401 nu.bezt = bezt_dst;
5402 nu.pntsu += new_points;
5403 changed = true;
5404 }
5405 }
5406 else {
5407 BPoint *bp, *bp_prev = nullptr;
5408 BPoint bp_stack;
5409 if (pnt_len == 1) {
5410 /* Single point extrusion.
5411 * Reference a `prev_bp` to force extrude. */
5412 bp_prev = &nu.bp[0];
5413 }
5414 else {
5415 duplic_first = (nu.bp[0].f1 & SELECT) && (nu.bp[1].f1 & SELECT);
5416 duplic_last = (nu.bp[pnt_len - 2].f1 & SELECT) && (nu.bp[pnt_len - 1].f1 & SELECT);
5417 if (duplic_first) {
5418 bp_stack = nu.bp[0];
5419 bp_stack.f1 &= ~SELECT;
5420 bp_prev = &bp_stack;
5421 }
5422 if (duplic_last) {
5423 new_points++;
5424 }
5425 }
5426
5427 i = pnt_len;
5428 for (bp = &nu.bp[0]; i--; bp++) {
5429 bool is_selected = (bp->f1 & SELECT) != 0;
5430 if (bp_prev && is_prev_selected != is_selected) {
5431 new_points++;
5432 }
5433 if (bp == cu_actvert.bp) {
5434 act_offset = new_points;
5435 }
5436 bp_prev = bp;
5437 is_prev_selected = is_selected;
5438 }
5439
5440 if (new_points) {
5441 BPoint *bp_src, *bp_dst, *bp_src_iter, *bp_dst_iter;
5442 const int new_len = pnt_len + new_points;
5443
5444 is_prev_selected = false;
5445 if (pnt_len == 1) {
5446 /* Single point extrusion.
5447 * Keep `is_prev_selected` false to force extrude. */
5448 BLI_assert(bp_prev == &nu.bp[0]);
5449 }
5450 else if (duplic_first) {
5451 bp_prev = &bp_stack;
5452 is_prev_selected = false;
5453 }
5454 else {
5455 bp_prev = nullptr;
5456 }
5457 bp_src = nu.bp;
5458 bp_dst = MEM_new_array_uninitialized<BPoint>(new_len, __func__);
5459 bp_src_iter = &bp_src[0];
5460 bp_dst_iter = &bp_dst[0];
5461 i = 0;
5462 for (bp = &nu.bp[0]; i < pnt_len; i++, bp++) {
5463 bool is_selected = (bp->f1 & SELECT) != 0;
5464 if (bp_prev && is_prev_selected != is_selected) {
5465 int count = i - offset + 1;
5466 if (is_prev_selected) {
5467 ED_curve_bpcpy(editnurb, bp_dst_iter, bp_src_iter, count - 1);
5468 ED_curve_bpcpy(editnurb, &bp_dst_iter[count - 1], bp_prev, 1);
5469 }
5470 else {
5471 ED_curve_bpcpy(editnurb, bp_dst_iter, bp_src_iter, count);
5472 }
5473 ED_curve_bpcpy(editnurb, &bp_dst_iter[count], bp, 1);
5474 bp_dst_iter[count - 1].f1 &= ~SELECT;
5475
5476 bp_dst_iter += count + 1;
5477 bp_src_iter += count;
5478 offset = i + 1;
5479 }
5480 bp_prev = bp;
5481 is_prev_selected = is_selected;
5482 }
5483
5484 int remain = pnt_len - offset;
5485 if (remain) {
5486 ED_curve_bpcpy(editnurb, bp_dst_iter, bp_src_iter, remain);
5487 }
5488
5489 if (duplic_last) {
5490 ED_curve_bpcpy(editnurb, &bp_dst[new_len - 1], &bp_src[pnt_len - 1], 1);
5491 bp_dst[new_len - 1].f1 &= ~SELECT;
5492 }
5493
5494 MEM_delete(nu.bp);
5495 nu.bp = bp_dst;
5496 nu.pntsu += new_points;
5497
5499 changed = true;
5500 }
5501 }
5502 }
5503
5504 cu->actvert += act_offset;
5505
5506 return changed;
5507}
5508
5510
5511/* -------------------------------------------------------------------- */
5514
5515int ed_editcurve_addvert(Curve *cu, EditNurb *editnurb, View3D *v3d, const float location_init[3])
5516{
5517 float center[3];
5518 float temp[3];
5519 uint verts_len;
5520 bool changed = false;
5521
5522 zero_v3(center);
5523 verts_len = 0;
5524
5525 for (Nurb &nu : editnurb->nurbs) {
5526 int i;
5527 if (nu.type == CU_BEZIER) {
5528 BezTriple *bezt;
5529
5530 for (i = 0, bezt = nu.bezt; i < nu.pntsu; i++, bezt++) {
5531 if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)) {
5532 add_v3_v3(center, bezt->vec[1]);
5533 verts_len += 1;
5534 }
5535 }
5536 }
5537 else {
5538 BPoint *bp;
5539
5540 for (i = 0, bp = nu.bp; i < nu.pntsu; i++, bp++) {
5541 if (bp->f1 & SELECT) {
5542 add_v3_v3(center, bp->vec);
5543 verts_len += 1;
5544 }
5545 }
5546 }
5547 }
5548
5549 if (verts_len && ed_editcurve_extrude(cu, editnurb, v3d)) {
5550 float ofs[3];
5551 int i;
5552
5553 mul_v3_fl(center, 1.0f / float(verts_len));
5554 sub_v3_v3v3(ofs, location_init, center);
5555
5556 if (CU_IS_2D(cu)) {
5557 ofs[2] = 0.0f;
5558 }
5559
5560 for (Nurb &nu : editnurb->nurbs) {
5561 if (nu.type == CU_BEZIER) {
5562 BezTriple *bezt;
5563 for (i = 0, bezt = nu.bezt; i < nu.pntsu; i++, bezt++) {
5564 if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)) {
5565 add_v3_v3(bezt->vec[0], ofs);
5566 add_v3_v3(bezt->vec[1], ofs);
5567 add_v3_v3(bezt->vec[2], ofs);
5568
5569 if (((nu.flagu & CU_NURB_CYCLIC) == 0) && ELEM(i, 0, nu.pntsu - 1)) {
5571 }
5572 }
5573 }
5574
5576 }
5577 else {
5578 BPoint *bp;
5579
5580 for (i = 0, bp = nu.bp; i < nu.pntsu; i++, bp++) {
5581 if (bp->f1 & SELECT) {
5582 add_v3_v3(bp->vec, ofs);
5583 }
5584 }
5585 }
5586 }
5587 changed = true;
5588 }
5589 else {
5590 float location[3];
5591
5592 copy_v3_v3(location, location_init);
5593
5594 if (CU_IS_2D(cu)) {
5595 location[2] = 0.0f;
5596 }
5597
5598 /* nothing selected: create a new curve */
5600
5601 Nurb *nurb_new;
5602 if (!nu) {
5603 /* Bezier as default. */
5604 nurb_new = MEM_new<Nurb>("BLI_editcurve_addvert new_bezt_nurb 2");
5605 nurb_new->type = CU_BEZIER;
5606 nurb_new->resolu = cu->resolu;
5607 nurb_new->orderu = 4;
5608 nurb_new->flag |= CU_SMOOTH;
5609 BKE_nurb_bezierPoints_add(nurb_new, 1);
5610 }
5611 else {
5612 /* Copy the active nurb settings. */
5613 nurb_new = BKE_nurb_copy(nu, 1, 1);
5614 if (nu->bezt) {
5615 memcpy(nurb_new->bezt, nu->bezt, sizeof(BezTriple));
5616 }
5617 else {
5618 memcpy(nurb_new->bp, nu->bp, sizeof(BPoint));
5619 }
5620 }
5621
5622 if (nurb_new->type == CU_BEZIER) {
5623 BezTriple *bezt_new = nurb_new->bezt;
5624
5625 BEZT_SEL_ALL(bezt_new);
5626
5627 bezt_new->h1 = HD_AUTO;
5628 bezt_new->h2 = HD_AUTO;
5629
5630 temp[0] = 1.0f;
5631 temp[1] = 0.0f;
5632 temp[2] = 0.0f;
5633
5634 copy_v3_v3(bezt_new->vec[1], location);
5635 sub_v3_v3v3(bezt_new->vec[0], location, temp);
5636 add_v3_v3v3(bezt_new->vec[2], location, temp);
5637 }
5638 else {
5639 BPoint *bp_new = nurb_new->bp;
5640
5641 bp_new->f1 |= SELECT;
5642
5643 copy_v3_v3(bp_new->vec, location);
5644
5645 BKE_nurb_knot_calc_u(nurb_new);
5646 }
5647
5648 BLI_addtail(&editnurb->nurbs, nurb_new);
5649 changed = true;
5650 }
5651
5652 return changed;
5653}
5654
5656{
5657 Main *bmain = CTX_data_main(C);
5658 Object *obedit = CTX_data_edit_object(C);
5659 View3D *v3d = CTX_wm_view3d(C);
5660 Curve *cu = id_cast<Curve *>(obedit->data);
5661 EditNurb *editnurb = cu->editnurb;
5662 float location[3];
5663 float imat[4][4];
5664
5665 RNA_float_get_array(op->ptr, "location", location);
5666
5667 invert_m4_m4(imat, obedit->object_to_world().ptr());
5668 mul_m4_v3(imat, location);
5669
5670 if (ed_editcurve_addvert(cu, editnurb, v3d, location)) {
5671 if (ED_curve_updateAnimPaths(bmain, id_cast<Curve *>(obedit->data))) {
5673 }
5674
5677
5678 DEG_id_tag_update(obedit->data, 0);
5679
5680 return OPERATOR_FINISHED;
5681 }
5682 return OPERATOR_CANCELLED;
5683}
5684
5686{
5687 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
5688 ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
5689
5690 if (vc.rv3d && !RNA_struct_property_is_set(op->ptr, "location")) {
5691 Curve *cu;
5692 float location[3];
5693 const bool use_proj = ((vc.scene->toolsettings->snap_flag & SCE_SNAP) &&
5696
5697 Nurb *nu;
5698 BezTriple *bezt;
5699 BPoint *bp;
5700
5701 cu = id_cast<Curve *>(vc.obedit->data);
5702
5703 ED_curve_nurb_vert_selected_find(cu, vc.v3d, &nu, &bezt, &bp);
5704
5705 if (bezt) {
5706 mul_v3_m4v3(location, vc.obedit->object_to_world().ptr(), bezt->vec[1]);
5707 }
5708 else if (bp) {
5709 mul_v3_m4v3(location, vc.obedit->object_to_world().ptr(), bp->vec);
5710 }
5711 else {
5712 copy_v3_v3(location, vc.scene->cursor.location);
5713 }
5714
5715 ED_view3d_win_to_3d_int(vc.v3d, vc.region, location, event->mval, location);
5716
5717 if (use_proj) {
5718 const float mval[2] = {float(event->mval[0]), float(event->mval[1])};
5719
5721
5723 params.snap_target_select = (vc.obedit != nullptr) ? SCE_SNAP_TARGET_NOT_ACTIVE :
5727 vc.depsgraph,
5728 vc.region,
5729 vc.v3d,
5731 &params,
5732 nullptr,
5733 mval,
5734 nullptr,
5735 nullptr,
5736 location,
5737 nullptr);
5738
5740 }
5741
5742 if (CU_IS_2D(cu)) {
5743 const float eps = 1e-6f;
5744
5745 /* get the view vector to 'location' */
5746 float view_dir[3];
5747 ED_view3d_global_to_vector(vc.rv3d, location, view_dir);
5748
5749 /* get the plane */
5750 const float *plane_co = vc.obedit->object_to_world().location();
5751 float plane_no[3];
5752 /* only normalize to avoid precision errors */
5753 normalize_v3_v3(plane_no, vc.obedit->object_to_world()[2]);
5754
5755 if (fabsf(dot_v3v3(view_dir, plane_no)) < eps) {
5756 /* can't project on an aligned plane. */
5757 }
5758 else {
5759 float lambda;
5760 if (isect_ray_plane_v3_factor(location, view_dir, plane_co, plane_no, &lambda)) {
5761 /* check if we're behind the viewport */
5762 float location_test[3];
5763 madd_v3_v3v3fl(location_test, location, view_dir, lambda);
5764 if ((vc.rv3d->is_persp == false) ||
5765 (mul_project_m4_v3_zfac(vc.rv3d->persmat, location_test) > 0.0f))
5766 {
5767 copy_v3_v3(location, location_test);
5768 }
5769 }
5770 }
5771 }
5772
5773 RNA_float_set_array(op->ptr, "location", location);
5774 }
5775
5776 /* Support dragging to move after extrude, see: #114282. */
5777 wmOperatorStatus retval = add_vertex_exec(C, op);
5778 if (retval & OPERATOR_FINISHED) {
5779 retval |= OPERATOR_PASS_THROUGH;
5780 }
5781 return WM_operator_flag_only_pass_through_on_press(retval, event);
5782}
5783
5785{
5786 /* identifiers */
5787 ot->name = "Extrude to Cursor or Add";
5788 ot->idname = "CURVE_OT_vertex_add";
5789 ot->description = "Add a new control point (linked to only selected end-curve one, if any)";
5790
5791 /* API callbacks. */
5792 ot->exec = add_vertex_exec;
5795
5796 /* flags */
5798
5799 /* properties */
5801 "location",
5802 3,
5803 nullptr,
5806 "Location",
5807 "Location to add new vertex at",
5808 -1.0e4f,
5809 1.0e4f);
5810}
5811
5813
5814/* -------------------------------------------------------------------- */
5817
5819{
5820 Main *bmain = CTX_data_main(C);
5821 const Scene *scene = CTX_data_scene(C);
5822 ViewLayer *view_layer = CTX_data_view_layer(C);
5823 View3D *v3d = CTX_wm_view3d(C);
5824
5826 *bmain, scene, view_layer, CTX_wm_view3d(C));
5827 for (Object *obedit : objects) {
5828 Curve *cu = id_cast<Curve *>(obedit->data);
5829 EditNurb *editnurb = cu->editnurb;
5830 bool changed = false;
5831
5832 if (!ED_curve_select_check(v3d, cu->editnurb)) {
5833 continue;
5834 }
5835
5836 if (obedit->type == OB_CURVES_LEGACY) {
5837 changed = ed_editcurve_extrude(cu, editnurb, v3d);
5838 }
5839 else {
5840 changed = ed_editnurb_extrude_flag(editnurb, BEZT_FLAG_SELECT);
5841 }
5842
5843 if (changed) {
5844 if (ED_curve_updateAnimPaths(bmain, id_cast<Curve *>(obedit->data))) {
5846 }
5847
5848 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
5849 DEG_id_tag_update(obedit->data, 0);
5850 }
5851 }
5852 return OPERATOR_FINISHED;
5853}
5854
5856{
5857 /* identifiers */
5858 ot->name = "Extrude";
5859 ot->description = "Extrude selected control point(s)";
5860 ot->idname = "CURVE_OT_extrude";
5861
5862 /* API callbacks. */
5865
5866 /* flags */
5868
5869 /* to give to transform */
5870 RNA_def_enum(ot->srna,
5871 "mode",
5874 "Mode",
5875 "");
5876}
5877
5879
5880/* -------------------------------------------------------------------- */
5883
5884bool curve_toggle_cyclic(View3D *v3d, ListBaseT<Nurb> *editnurb, int direction)
5885{
5886 BezTriple *bezt;
5887 BPoint *bp;
5888 int a;
5889 bool changed = false;
5890
5891 for (Nurb &nu : *editnurb) {
5892 if (nu.pntsu > 1 || nu.pntsv > 1) {
5893 if (nu.type == CU_POLY) {
5894 a = nu.pntsu;
5895 bp = nu.bp;
5896 while (a--) {
5897 if (bp->f1 & SELECT) {
5898 nu.flagu ^= CU_NURB_CYCLIC;
5899 changed = true;
5900 break;
5901 }
5902 bp++;
5903 }
5904 }
5905 else if (nu.type == CU_BEZIER) {
5906 a = nu.pntsu;
5907 bezt = nu.bezt;
5908 while (a--) {
5909 if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)) {
5910 nu.flagu ^= CU_NURB_CYCLIC;
5911 changed = true;
5912 break;
5913 }
5914 bezt++;
5915 }
5917 }
5918 else if (nu.pntsv == 1 && nu.type == CU_NURBS) {
5919 if (nu.knotsu) { /* if check_valid_nurb_u fails the knotsu can be nullptr */
5920 a = nu.pntsu;
5921 bp = nu.bp;
5922 while (a--) {
5923 if (bp->f1 & SELECT) {
5924 nu.flagu ^= CU_NURB_CYCLIC;
5925 /* 1==u type is ignored for cyclic curves */
5927 changed = true;
5928 break;
5929 }
5930 bp++;
5931 }
5932 }
5933 }
5934 else if (nu.type == CU_NURBS) {
5935 a = nu.pntsu * nu.pntsv;
5936 bp = nu.bp;
5937 while (a--) {
5938
5939 if (bp->f1 & SELECT) {
5940 if (direction == 0 && nu.pntsu > 1) {
5941 nu.flagu ^= CU_NURB_CYCLIC;
5942 /* 1==u type is ignored for cyclic curves */
5944 changed = true;
5945 }
5946 if (direction == 1 && nu.pntsv > 1) {
5947 nu.flagv ^= CU_NURB_CYCLIC;
5948 /* 2==v type is ignored for cyclic curves */
5950 changed = true;
5951 }
5952 break;
5953 }
5954 bp++;
5955 }
5956 }
5957 }
5958 }
5959 return changed;
5960}
5961
5963{
5964 const int direction = RNA_enum_get(op->ptr, "direction");
5965 View3D *v3d = CTX_wm_view3d(C);
5966 const Main *bmain = CTX_data_main(C);
5967 const Scene *scene = CTX_data_scene(C);
5968 ViewLayer *view_layer = CTX_data_view_layer(C);
5969 bool changed_multi = false;
5970
5972 *bmain, scene, view_layer, CTX_wm_view3d(C));
5973 for (Object *obedit : objects) {
5974 Curve *cu = id_cast<Curve *>(obedit->data);
5975
5976 if (!ED_curve_select_check(v3d, cu->editnurb)) {
5977 continue;
5978 }
5979
5980 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
5981 if (curve_toggle_cyclic(v3d, editnurb, direction)) {
5982 changed_multi = true;
5983 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
5984 DEG_id_tag_update(obedit->data, 0);
5985 }
5986 }
5987
5988 return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
5989}
5990
5992 wmOperator *op,
5993 const wmEvent * /*event*/)
5994{
5995 Object *obedit = CTX_data_edit_object(C);
5996 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
5997
5998 if (obedit->type == OB_SURF) {
5999 for (Nurb &nu : *editnurb) {
6000 if (nu.pntsu > 1 || nu.pntsv > 1) {
6001 if (nu.type == CU_NURBS) {
6002 ui::PopupMenu *pup = ui::popup_menu_begin(C, IFACE_("Direction"), ICON_NONE);
6003 ui::Layout &layout = *popup_menu_layout(pup);
6004 layout.op_enum(op->type->idname, "direction");
6005 popup_menu_end(C, pup);
6006 return OPERATOR_INTERFACE;
6007 }
6008 }
6009 }
6010 }
6011
6012 return toggle_cyclic_exec(C, op);
6013}
6014
6016{
6017 static const EnumPropertyItem direction_items[] = {
6018 {0, "CYCLIC_U", 0, "Cyclic U", ""},
6019 {1, "CYCLIC_V", 0, "Cyclic V", ""},
6020 {0, nullptr, 0, nullptr, nullptr},
6021 };
6022
6023 /* identifiers */
6024 ot->name = "Toggle Cyclic";
6025 ot->description = "Make active spline closed/open loop";
6026 ot->idname = "CURVE_OT_cyclic_toggle";
6027
6028 /* API callbacks. */
6032
6033 /* flags */
6035
6036 /* properties */
6037 RNA_def_enum(ot->srna,
6038 "direction",
6039 direction_items,
6040 0,
6041 "Direction",
6042 "Direction to make surface cyclic in");
6043}
6044
6046
6047/* -------------------------------------------------------------------- */
6050
6052{
6053 const Main *bmain = CTX_data_main(C);
6054 const Scene *scene = CTX_data_scene(C);
6055 ViewLayer *view_layer = CTX_data_view_layer(C);
6056 View3D *v3d = CTX_wm_view3d(C);
6057
6058 bool changed = false;
6059 int count_failed = 0;
6060
6062 *bmain, scene, view_layer, CTX_wm_view3d(C));
6063 for (Object *obedit : objects) {
6064 Curve *cu = id_cast<Curve *>(obedit->data);
6065
6066 if (!ED_curve_select_check(v3d, cu->editnurb)) {
6067 continue;
6068 }
6069
6070 ListBaseT<Nurb> newnurb = {nullptr, nullptr};
6071 adduplicateflagNurb(obedit, v3d, &newnurb, BEZT_FLAG_SELECT, false);
6072
6073 if (newnurb.is_empty()) {
6074 count_failed += 1;
6075 continue;
6076 }
6077
6078 changed = true;
6079 BLI_movelisttolist(object_editcurve_get(obedit), &newnurb);
6082 }
6083
6084 if (changed == false) {
6085 if (count_failed != 0) {
6086 BKE_report(op->reports, RPT_ERROR, "Cannot duplicate current selection");
6087 }
6088 return OPERATOR_CANCELLED;
6089 }
6090 return OPERATOR_FINISHED;
6091}
6092
6094{
6095 /* identifiers */
6096 ot->name = "Duplicate Curve";
6097 ot->description = "Duplicate selected control points";
6098 ot->idname = "CURVE_OT_duplicate";
6099
6100 /* API callbacks. */
6101 ot->exec = duplicate_exec;
6103
6104 /* flags */
6106}
6107
6109
6110/* -------------------------------------------------------------------- */
6113
6114static bool curve_delete_vertices(Object *obedit, View3D *v3d)
6115{
6116 if (obedit->type == OB_SURF) {
6118 }
6119 else {
6120 ed_curve_delete_selected(obedit, v3d);
6121 }
6122
6123 return true;
6124}
6125
6126static bool curve_delete_segments(Object *obedit, View3D *v3d, const bool split)
6127{
6128 Curve *cu = id_cast<Curve *>(obedit->data);
6129 EditNurb *editnurb = cu->editnurb;
6130 ListBaseT<Nurb> *nubase = &editnurb->nurbs, newnurb = {nullptr, nullptr};
6131 Nurb *nu1;
6132 BezTriple *bezt, *bezt1, *bezt2;
6133 BPoint *bp, *bp1, *bp2;
6134 int a, b, starta, enda, cut, cyclicut;
6135
6136 for (Nurb &nu : *nubase) {
6137 nu1 = nullptr;
6138 starta = enda = cut = -1;
6139 cyclicut = 0;
6140
6141 if (nu.type == CU_BEZIER) {
6142 for (a = 0, bezt = nu.bezt; a < nu.pntsu; a++, bezt++) {
6143 if (!BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)) {
6144 enda = a;
6145 if (starta == -1) {
6146 starta = a;
6147 }
6148 if (a < nu.pntsu - 1) {
6149 continue;
6150 }
6151 }
6152 else if (a < nu.pntsu - 1 && !BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt + 1)) {
6153 /* if just single selected point then continue */
6154 continue;
6155 }
6156
6157 if (starta >= 0) {
6158 /* got selected segment, now check where and copy */
6159 if (starta <= 1 && a == nu.pntsu - 1) {
6160 /* copying all points in spline */
6161 if (starta == 1 && enda != a) {
6162 nu.flagu &= ~CU_NURB_CYCLIC;
6163 }
6164
6165 starta = 0;
6166 enda = a;
6167 cut = enda - starta + 1;
6168 nu1 = BKE_nurb_copy(&nu, cut, 1);
6169 }
6170 else if (starta == 0) {
6171 /* if start of curve copy next end point */
6172 enda++;
6173 cut = enda - starta + 1;
6174 bezt1 = &nu.bezt[nu.pntsu - 1];
6175 bezt2 = &nu.bezt[nu.pntsu - 2];
6176
6177 if ((nu.flagu & CU_NURB_CYCLIC) && BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt1) &&
6178 BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt2))
6179 {
6180 /* check if need to join start of spline to end */
6181 nu1 = BKE_nurb_copy(&nu, cut + 1, 1);
6182 ED_curve_beztcpy(editnurb, &nu1->bezt[1], nu.bezt, cut);
6183 starta = nu.pntsu - 1;
6184 cut = 1;
6185 }
6186 else {
6187 if (nu.flagu & CU_NURB_CYCLIC) {
6188 cyclicut = cut;
6189 }
6190 else {
6191 nu1 = BKE_nurb_copy(&nu, cut, 1);
6192 }
6193 }
6194 }
6195 else if (enda == nu.pntsu - 1) {
6196 /* if end of curve copy previous start point */
6197 starta--;
6198 cut = enda - starta + 1;
6199 bezt1 = nu.bezt;
6200 bezt2 = &nu.bezt[1];
6201
6202 if ((nu.flagu & CU_NURB_CYCLIC) && BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt1) &&
6203 BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt2))
6204 {
6205 /* check if need to join start of spline to end */
6206 nu1 = BKE_nurb_copy(&nu, cut + 1, 1);
6207 ED_curve_beztcpy(editnurb, &nu1->bezt[cut], nu.bezt, 1);
6208 }
6209 else if (cyclicut != 0) {
6210 /* if cyclicut exists it is a cyclic spline, start and end should be connected */
6211 nu1 = BKE_nurb_copy(&nu, cut + cyclicut, 1);
6212 ED_curve_beztcpy(editnurb, &nu1->bezt[cut], nu.bezt, cyclicut);
6213 cyclicut = 0;
6214 }
6215 else {
6216 nu1 = BKE_nurb_copy(&nu, cut, 1);
6217 }
6218 }
6219 else {
6220 /* mid spline selection, copy adjacent start and end */
6221 starta--;
6222 enda++;
6223 cut = enda - starta + 1;
6224 nu1 = BKE_nurb_copy(&nu, cut, 1);
6225 }
6226
6227 if (nu1 != nullptr) {
6228 ED_curve_beztcpy(editnurb, nu1->bezt, &nu.bezt[starta], cut);
6229 BLI_addtail(&newnurb, nu1);
6230
6231 if (starta != 0 || enda != nu.pntsu - 1) {
6232 nu1->flagu &= ~CU_NURB_CYCLIC;
6233 }
6234 nu1 = nullptr;
6235 }
6236 starta = enda = -1;
6237 }
6238 }
6239
6240 if (!split && cut != -1 && nu.pntsu > 2 && !(nu.flagu & CU_NURB_CYCLIC)) {
6241 /* start and points copied if connecting segment was deleted and not cyclic spline */
6242 bezt1 = nu.bezt;
6243 bezt2 = &nu.bezt[1];
6244
6245 if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt1) && BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt2)) {
6246 nu1 = BKE_nurb_copy(&nu, 1, 1);
6247 ED_curve_beztcpy(editnurb, nu1->bezt, bezt1, 1);
6248 BLI_addtail(&newnurb, nu1);
6249 }
6250
6251 bezt1 = &nu.bezt[nu.pntsu - 1];
6252 bezt2 = &nu.bezt[nu.pntsu - 2];
6253
6254 if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt1) && BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt2)) {
6255 nu1 = BKE_nurb_copy(&nu, 1, 1);
6256 ED_curve_beztcpy(editnurb, nu1->bezt, bezt1, 1);
6257 BLI_addtail(&newnurb, nu1);
6258 }
6259 }
6260 }
6261 else if (nu.pntsv >= 1) {
6262 int u, v;
6263
6264 if (isNurbselV(&nu, &u, BEZT_FLAG_SELECT)) {
6265 for (a = 0, bp = nu.bp; a < nu.pntsu; a++, bp++) {
6266 if (!(bp->f1 & SELECT)) {
6267 enda = a;
6268 if (starta == -1) {
6269 starta = a;
6270 }
6271 if (a < nu.pntsu - 1) {
6272 continue;
6273 }
6274 }
6275 else if (a < nu.pntsu - 1 && !((bp + 1)->f1 & SELECT)) {
6276 /* if just single selected point then continue */
6277 continue;
6278 }
6279
6280 if (starta >= 0) {
6281 /* got selected segment, now check where and copy */
6282 if (starta <= 1 && a == nu.pntsu - 1) {
6283 /* copying all points in spline */
6284 if (starta == 1 && enda != a) {
6285 nu.flagu &= ~CU_NURB_CYCLIC;
6286 }
6287
6288 starta = 0;
6289 enda = a;
6290 cut = enda - starta + 1;
6291 nu1 = BKE_nurb_copy(&nu, cut, nu.pntsv);
6292 }
6293 else if (starta == 0) {
6294 /* if start of curve copy next end point */
6295 enda++;
6296 cut = enda - starta + 1;
6297 bp1 = &nu.bp[nu.pntsu - 1];
6298 bp2 = &nu.bp[nu.pntsu - 2];
6299
6300 if ((nu.flagu & CU_NURB_CYCLIC) && (bp1->f1 & SELECT) && (bp2->f1 & SELECT)) {
6301 /* check if need to join start of spline to end */
6302 nu1 = BKE_nurb_copy(&nu, cut + 1, nu.pntsv);
6303 for (b = 0; b < nu.pntsv; b++) {
6305 editnurb, &nu1->bp[b * nu1->pntsu + 1], &nu.bp[b * nu.pntsu], cut);
6306 }
6307 starta = nu.pntsu - 1;
6308 cut = 1;
6309 }
6310 else {
6311 if (nu.flagu & CU_NURB_CYCLIC) {
6312 cyclicut = cut;
6313 }
6314 else {
6315 nu1 = BKE_nurb_copy(&nu, cut, nu.pntsv);
6316 }
6317 }
6318 }
6319 else if (enda == nu.pntsu - 1) {
6320 /* if end of curve copy previous start point */
6321 starta--;
6322 cut = enda - starta + 1;
6323 bp1 = nu.bp;
6324 bp2 = &nu.bp[1];
6325
6326 if ((nu.flagu & CU_NURB_CYCLIC) && (bp1->f1 & SELECT) && (bp2->f1 & SELECT)) {
6327 /* check if need to join start of spline to end */
6328 nu1 = BKE_nurb_copy(&nu, cut + 1, nu.pntsv);
6329 for (b = 0; b < nu.pntsv; b++) {
6331 editnurb, &nu1->bp[b * nu1->pntsu + cut], &nu.bp[b * nu.pntsu], 1);
6332 }
6333 }
6334 else if (cyclicut != 0) {
6335 /* if cyclicut exists it is a cyclic spline, start and end should be connected */
6336 nu1 = BKE_nurb_copy(&nu, cut + cyclicut, nu.pntsv);
6337 for (b = 0; b < nu.pntsv; b++) {
6339 editnurb, &nu1->bp[b * nu1->pntsu + cut], &nu.bp[b * nu.pntsu], cyclicut);
6340 }
6341 }
6342 else {
6343 nu1 = BKE_nurb_copy(&nu, cut, nu.pntsv);
6344 }
6345 }
6346 else {
6347 /* mid spline selection, copy adjacent start and end */
6348 starta--;
6349 enda++;
6350 cut = enda - starta + 1;
6351 nu1 = BKE_nurb_copy(&nu, cut, nu.pntsv);
6352 }
6353
6354 if (nu1 != nullptr) {
6355 for (b = 0; b < nu.pntsv; b++) {
6357 editnurb, &nu1->bp[b * nu1->pntsu], &nu.bp[b * nu.pntsu + starta], cut);
6358 }
6359 BLI_addtail(&newnurb, nu1);
6360
6361 if (starta != 0 || enda != nu.pntsu - 1) {
6362 nu1->flagu &= ~CU_NURB_CYCLIC;
6363 }
6364 nu1 = nullptr;
6365 }
6366 starta = enda = -1;
6367 }
6368 }
6369
6370 if (!split && cut != -1 && nu.pntsu > 2 && !(nu.flagu & CU_NURB_CYCLIC)) {
6371 /* start and points copied if connecting segment was deleted and not cyclic spline */
6372 bp1 = nu.bp;
6373 bp2 = &nu.bp[1];
6374
6375 if ((bp1->f1 & SELECT) && (bp2->f1 & SELECT)) {
6376 nu1 = BKE_nurb_copy(&nu, 1, nu.pntsv);
6377 for (b = 0; b < nu.pntsv; b++) {
6378 ED_curve_bpcpy(editnurb, &nu1->bp[b], &nu.bp[b * nu.pntsu], 1);
6379 }
6380 BLI_addtail(&newnurb, nu1);
6381 }
6382
6383 bp1 = &nu.bp[nu.pntsu - 1];
6384 bp2 = &nu.bp[nu.pntsu - 2];
6385
6386 if ((bp1->f1 & SELECT) && (bp2->f1 & SELECT)) {
6387 nu1 = BKE_nurb_copy(&nu, 1, nu.pntsv);
6388 for (b = 0; b < nu.pntsv; b++) {
6389 ED_curve_bpcpy(editnurb, &nu1->bp[b], &nu.bp[b * nu.pntsu + nu.pntsu - 1], 1);
6390 }
6391 BLI_addtail(&newnurb, nu1);
6392 }
6393 }
6394 }
6395 else if (isNurbselU(&nu, &v, BEZT_FLAG_SELECT)) {
6396 for (a = 0, bp = nu.bp; a < nu.pntsv; a++, bp += nu.pntsu) {
6397 if (!(bp->f1 & SELECT)) {
6398 enda = a;
6399 if (starta == -1) {
6400 starta = a;
6401 }
6402 if (a < nu.pntsv - 1) {
6403 continue;
6404 }
6405 }
6406 else if (a < nu.pntsv - 1 && !((bp + nu.pntsu)->f1 & SELECT)) {
6407 /* if just single selected point then continue */
6408 continue;
6409 }
6410
6411 if (starta >= 0) {
6412 /* got selected segment, now check where and copy */
6413 if (starta <= 1 && a == nu.pntsv - 1) {
6414 /* copying all points in spline */
6415 if (starta == 1 && enda != a) {
6416 nu.flagv &= ~CU_NURB_CYCLIC;
6417 }
6418
6419 starta = 0;
6420 enda = a;
6421 cut = enda - starta + 1;
6422 nu1 = BKE_nurb_copy(&nu, nu.pntsu, cut);
6423 }
6424 else if (starta == 0) {
6425 /* if start of curve copy next end point */
6426 enda++;
6427 cut = enda - starta + 1;
6428 bp1 = &nu.bp[nu.pntsv * nu.pntsu - nu.pntsu];
6429 bp2 = &nu.bp[nu.pntsv * nu.pntsu - (nu.pntsu * 2)];
6430
6431 if ((nu.flagv & CU_NURB_CYCLIC) && (bp1->f1 & SELECT) && (bp2->f1 & SELECT)) {
6432 /* check if need to join start of spline to end */
6433 nu1 = BKE_nurb_copy(&nu, nu.pntsu, cut + 1);
6434 ED_curve_bpcpy(editnurb, &nu1->bp[nu.pntsu], nu.bp, cut * nu.pntsu);
6435 starta = nu.pntsv - 1;
6436 cut = 1;
6437 }
6438 else {
6439 if (nu.flagv & CU_NURB_CYCLIC) {
6440 cyclicut = cut;
6441 }
6442 else {
6443 nu1 = BKE_nurb_copy(&nu, nu.pntsu, cut);
6444 }
6445 }
6446 }
6447 else if (enda == nu.pntsv - 1) {
6448 /* if end of curve copy previous start point */
6449 starta--;
6450 cut = enda - starta + 1;
6451 bp1 = nu.bp;
6452 bp2 = &nu.bp[nu.pntsu];
6453
6454 if ((nu.flagv & CU_NURB_CYCLIC) && (bp1->f1 & SELECT) && (bp2->f1 & SELECT)) {
6455 /* check if need to join start of spline to end */
6456 nu1 = BKE_nurb_copy(&nu, nu.pntsu, cut + 1);
6457 ED_curve_bpcpy(editnurb, &nu1->bp[cut * nu.pntsu], nu.bp, nu.pntsu);
6458 }
6459 else if (cyclicut != 0) {
6460 /* if cyclicut exists it is a cyclic spline, start and end should be connected */
6461 nu1 = BKE_nurb_copy(&nu, nu.pntsu, cut + cyclicut);
6462 ED_curve_bpcpy(editnurb, &nu1->bp[cut * nu.pntsu], nu.bp, nu.pntsu * cyclicut);
6463 cyclicut = 0;
6464 }
6465 else {
6466 nu1 = BKE_nurb_copy(&nu, nu.pntsu, cut);
6467 }
6468 }
6469 else {
6470 /* mid spline selection, copy adjacent start and end */
6471 starta--;
6472 enda++;
6473 cut = enda - starta + 1;
6474 nu1 = BKE_nurb_copy(&nu, nu.pntsu, cut);
6475 }
6476
6477 if (nu1 != nullptr) {
6478 ED_curve_bpcpy(editnurb, nu1->bp, &nu.bp[starta * nu.pntsu], cut * nu.pntsu);
6479 BLI_addtail(&newnurb, nu1);
6480
6481 if (starta != 0 || enda != nu.pntsv - 1) {
6482 nu1->flagv &= ~CU_NURB_CYCLIC;
6483 }
6484 nu1 = nullptr;
6485 }
6486 starta = enda = -1;
6487 }
6488 }
6489
6490 if (!split && cut != -1 && nu.pntsv > 2 && !(nu.flagv & CU_NURB_CYCLIC)) {
6491 /* start and points copied if connecting segment was deleted and not cyclic spline */
6492 bp1 = nu.bp;
6493 bp2 = &nu.bp[nu.pntsu];
6494
6495 if ((bp1->f1 & SELECT) && (bp2->f1 & SELECT)) {
6496 nu1 = BKE_nurb_copy(&nu, nu.pntsu, 1);
6497 ED_curve_bpcpy(editnurb, nu1->bp, nu.bp, nu.pntsu);
6498 BLI_addtail(&newnurb, nu1);
6499 }
6500
6501 bp1 = &nu.bp[nu.pntsu * nu.pntsv - nu.pntsu];
6502 bp2 = &nu.bp[nu.pntsu * nu.pntsv - (nu.pntsu * 2)];
6503
6504 if ((bp1->f1 & SELECT) && (bp2->f1 & SELECT)) {
6505 nu1 = BKE_nurb_copy(&nu, nu.pntsu, 1);
6506 ED_curve_bpcpy(editnurb, nu1->bp, &nu.bp[nu.pntsu * nu.pntsv - nu.pntsu], nu.pntsu);
6507 BLI_addtail(&newnurb, nu1);
6508 }
6509 }
6510 }
6511 else {
6512 /* selection not valid, just copy nurb to new list */
6513 nu1 = BKE_nurb_copy(&nu, nu.pntsu, nu.pntsv);
6514 ED_curve_bpcpy(editnurb, nu1->bp, nu.bp, nu.pntsu * nu.pntsv);
6515 BLI_addtail(&newnurb, nu1);
6516 }
6517 }
6518 }
6519
6520 for (Nurb &nu : newnurb) {
6521 if (nu.type == CU_BEZIER) {
6522 if (split) {
6523 /* deselect for split operator */
6524 for (b = 0, bezt1 = nu.bezt; b < nu.pntsu; b++, bezt1++) {
6526 }
6527 }
6528
6530 }
6531 else {
6532 if (split) {
6533 /* deselect for split operator */
6534 for (b = 0, bp1 = nu.bp; b < nu.pntsu * nu.pntsv; b++, bp1++) {
6536 }
6537 }
6538
6541
6542 if (nu.pntsv > 1) {
6545 }
6546 }
6547 }
6548
6549 keyIndex_delNurbList(editnurb, nubase);
6550 BKE_nurbList_free(nubase);
6551 BLI_movelisttolist(nubase, &newnurb);
6552
6553 return true;
6554}
6555
6557{
6558 Main *bmain = CTX_data_main(C);
6559 View3D *v3d = CTX_wm_view3d(C);
6561 const Scene *scene = CTX_data_scene(C);
6562 ViewLayer *view_layer = CTX_data_view_layer(C);
6564 *bmain, scene, view_layer, CTX_wm_view3d(C));
6565 bool changed_multi = false;
6566
6567 for (Object *obedit : objects) {
6568 Curve *cu = id_cast<Curve *>(obedit->data);
6569 bool changed = false;
6570
6571 if (!ED_curve_select_check(v3d, cu->editnurb)) {
6572 continue;
6573 }
6574
6575 if (type == CURVE_VERTEX) {
6576 changed = curve_delete_vertices(obedit, v3d);
6577 }
6578 else if (type == CURVE_SEGMENT) {
6579 changed = curve_delete_segments(obedit, v3d, false);
6580 cu->actnu = CU_ACT_NONE;
6581 }
6582 else {
6583 BLI_assert(0);
6584 }
6585
6586 if (changed) {
6587 changed_multi = true;
6588 cu->actvert = CU_ACT_NONE;
6589
6590 if (ED_curve_updateAnimPaths(bmain, id_cast<Curve *>(obedit->data))) {
6592 }
6593
6594 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
6595 DEG_id_tag_update(obedit->data, 0);
6596 }
6597 }
6598
6599 if (changed_multi) {
6600 return OPERATOR_FINISHED;
6601 }
6602 return OPERATOR_CANCELLED;
6603}
6604
6606 {CURVE_VERTEX, "VERT", 0, "Vertices", ""},
6607 {CURVE_SEGMENT, "SEGMENT", 0, "Segments", ""},
6608 {0, nullptr, 0, nullptr, nullptr},
6609};
6610
6612 PointerRNA * /*ptr*/,
6613 PropertyRNA * /*prop*/,
6614 bool *r_free)
6615{
6616 EnumPropertyItem *item = nullptr;
6617 int totitem = 0;
6618
6619 if (!C) { /* needed for docs and i18n tools */
6621 }
6622
6625 RNA_enum_item_end(&item, &totitem);
6626 *r_free = true;
6627
6628 return item;
6629}
6630
6632{
6633 PropertyRNA *prop;
6634
6635 /* identifiers */
6636 ot->name = "Delete";
6637 ot->description = "Delete selected control points or segments";
6638 ot->idname = "CURVE_OT_delete";
6639
6640 /* API callbacks. */
6641 ot->exec = curve_delete_exec;
6642 ot->invoke = WM_menu_invoke;
6644
6645 /* flags */
6647
6648 /* properties */
6649 prop = RNA_def_enum(
6650 ot->srna, "type", curve_delete_type_items, 0, "Type", "Which elements to delete");
6653 ot->prop = prop;
6654}
6655
6657
6658/* -------------------------------------------------------------------- */
6661
6662static bool test_bezt_is_sel_any(const void *bezt_v, void *user_data)
6663{
6664 View3D *v3d = static_cast<View3D *>(user_data);
6665 const BezTriple *bezt = static_cast<const BezTriple *>(bezt_v);
6666 return BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt);
6667}
6668
6670 BezTriple *bezt_next,
6671 const Nurb *nu,
6672 const Curve *cu,
6673 const uint span_len,
6674 const uint span_step[2])
6675{
6676 int i_span_edge_len = span_len + 1;
6677 const int dims = 3;
6678
6679 const int points_len = ((cu->resolu - 1) * i_span_edge_len) + 1;
6680 float *points = MEM_new_array_uninitialized<float>(points_len * dims, __func__);
6681 float *points_stride = points;
6682 const int points_stride_len = (cu->resolu - 1);
6683
6684 for (int segment = 0; segment < i_span_edge_len; segment++) {
6685 BezTriple *bezt_a = &nu->bezt[mod_i((span_step[0] + segment) - 1, nu->pntsu)];
6686 BezTriple *bezt_b = &nu->bezt[mod_i((span_step[0] + segment), nu->pntsu)];
6687
6688 for (int axis = 0; axis < dims; axis++) {
6689 BKE_curve_forward_diff_bezier(bezt_a->vec[1][axis],
6690 bezt_a->vec[2][axis],
6691 bezt_b->vec[0][axis],
6692 bezt_b->vec[1][axis],
6693 points_stride + axis,
6694 points_stride_len,
6695 dims * sizeof(float));
6696 }
6697
6698 points_stride += dims * points_stride_len;
6699 }
6700
6701 BLI_assert(points_stride + dims == points + (points_len * dims));
6702
6703 float tan_l[3], tan_r[3], error_sq_dummy;
6704 uint error_index_dummy;
6705
6706 sub_v3_v3v3(tan_l, bezt_prev->vec[1], bezt_prev->vec[2]);
6707 normalize_v3(tan_l);
6708 sub_v3_v3v3(tan_r, bezt_next->vec[0], bezt_next->vec[1]);
6709 normalize_v3(tan_r);
6710
6711 curve_fit_cubic_to_points_single_fl(points,
6712 points_len,
6713 nullptr,
6714 dims,
6716 tan_l,
6717 tan_r,
6718 bezt_prev->vec[2],
6719 bezt_next->vec[0],
6720 &error_sq_dummy,
6721 &error_index_dummy);
6722
6723 if (!ELEM(bezt_prev->h2, HD_FREE, HD_ALIGN)) {
6724 bezt_prev->h2 = (bezt_prev->h2 == HD_VECT) ? HD_FREE : HD_ALIGN;
6725 }
6726 if (!ELEM(bezt_next->h1, HD_FREE, HD_ALIGN)) {
6727 bezt_next->h1 = (bezt_next->h1 == HD_VECT) ? HD_FREE : HD_ALIGN;
6728 }
6729
6730 MEM_delete(points);
6731}
6732
6734{
6735 Main *bmain = CTX_data_main(C);
6736 const Scene *scene = CTX_data_scene(C);
6737 ViewLayer *view_layer = CTX_data_view_layer(C);
6738 View3D *v3d = CTX_wm_view3d(C);
6739
6741 *bmain, scene, view_layer, CTX_wm_view3d(C));
6742 for (Object *obedit : objects) {
6743 Curve *cu = id_cast<Curve *>(obedit->data);
6744
6745 if (!ED_curve_select_check(v3d, cu->editnurb)) {
6746 continue;
6747 }
6748
6749 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
6750
6751 for (Nurb &nu : *editnurb) {
6752 if ((nu.type == CU_BEZIER) && (nu.pntsu > 2)) {
6753 uint span_step[2] = {uint(nu.pntsu), uint(nu.pntsu)};
6754 uint span_len;
6755
6756 while (BLI_array_iter_span(nu.bezt,
6757 nu.pntsu,
6758 (nu.flagu & CU_NURB_CYCLIC) != 0,
6759 false,
6761 v3d,
6762 span_step,
6763 &span_len))
6764 {
6765 BezTriple *bezt_prev = &nu.bezt[mod_i(span_step[0] - 1, nu.pntsu)];
6766 BezTriple *bezt_next = &nu.bezt[mod_i(span_step[1] + 1, nu.pntsu)];
6767
6768 ed_dissolve_bez_segment(bezt_prev, bezt_next, &nu, cu, span_len, span_step);
6769 }
6770 }
6771 }
6772
6773 ed_curve_delete_selected(obedit, v3d);
6774
6775 cu->actnu = cu->actvert = CU_ACT_NONE;
6776
6777 if (ED_curve_updateAnimPaths(bmain, id_cast<Curve *>(obedit->data))) {
6779 }
6780
6781 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
6782 DEG_id_tag_update(obedit->data, 0);
6783 }
6784 return OPERATOR_FINISHED;
6785}
6786
6788{
6789 /* identifiers */
6790 ot->name = "Dissolve Vertices";
6791 ot->description = "Delete selected control points, correcting surrounding handles";
6792 ot->idname = "CURVE_OT_dissolve_verts";
6793
6794 /* API callbacks. */
6797
6798 /* flags */
6800}
6801
6803
6804/* -------------------------------------------------------------------- */
6807
6808static bool nurb_bezt_flag_any(const Nurb *nu, const char flag_test)
6809{
6810 const BezTriple *bezt;
6811 int i;
6812
6813 for (i = nu->pntsu, bezt = nu->bezt; i--; bezt++) {
6814 if (bezt->f2 & flag_test) {
6815 return true;
6816 }
6817 }
6818
6819 return false;
6820}
6821
6823{
6824 Main *bmain = CTX_data_main(C);
6825 const float error_sq_max = FLT_MAX;
6826 float ratio = RNA_float_get(op->ptr, "ratio");
6827 bool all_supported_multi = true;
6828
6829 const Scene *scene = CTX_data_scene(C);
6830 ViewLayer *view_layer = CTX_data_view_layer(C);
6832 *bmain, scene, view_layer, CTX_wm_view3d(C));
6833 for (Object *obedit : objects) {
6834 Curve *cu = id_cast<Curve *>(obedit->data);
6835 bool all_supported = true;
6836 bool changed = false;
6837
6838 {
6839 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
6840
6841 for (Nurb &nu : *editnurb) {
6842 if (nu.type == CU_BEZIER) {
6843 if ((nu.pntsu > 2) && nurb_bezt_flag_any(&nu, SELECT)) {
6844 const int error_target_len = max_ii(2, nu.pntsu * ratio);
6845 if (error_target_len != nu.pntsu) {
6846 BKE_curve_decimate_nurb(&nu, cu->resolu, error_sq_max, error_target_len);
6847 changed = true;
6848 }
6849 }
6850 }
6851 else {
6852 all_supported = false;
6853 }
6854 }
6855 }
6856
6857 if (all_supported == false) {
6858 all_supported_multi = false;
6859 }
6860
6861 if (changed) {
6862 cu->actnu = cu->actvert = CU_ACT_NONE;
6863 if (ED_curve_updateAnimPaths(bmain, id_cast<Curve *>(obedit->data))) {
6865 }
6866
6867 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
6868 DEG_id_tag_update(obedit->data, 0);
6869 }
6870 }
6871
6872 if (all_supported_multi == false) {
6873 BKE_report(op->reports, RPT_WARNING, "Only Bézier curves are supported");
6874 }
6875
6876 return OPERATOR_FINISHED;
6877}
6878
6880{
6881 /* identifiers */
6882 ot->name = "Decimate Curve";
6883 ot->description = "Simplify selected curves";
6884 ot->idname = "CURVE_OT_decimate";
6885
6886 /* API callbacks. */
6889
6890 /* flags */
6892
6893 /* properties */
6894 RNA_def_float_factor(ot->srna, "ratio", 1.0f, 0.0f, 1.0f, "Ratio", "", 0.0f, 1.0f);
6895}
6896
6898
6899/* -------------------------------------------------------------------- */
6902
6904{
6905 View3D *v3d = CTX_wm_view3d(C);
6906 const Main *bmain = CTX_data_main(C);
6907 const Scene *scene = CTX_data_scene(C);
6908 ViewLayer *view_layer = CTX_data_view_layer(C);
6909 int clear = STREQ(op->idname, "CURVE_OT_shade_flat");
6911 *bmain, scene, view_layer, CTX_wm_view3d(C));
6913
6914 for (Object *obedit : objects) {
6915 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
6916
6917 if (obedit->type != OB_CURVES_LEGACY) {
6918 continue;
6919 }
6920
6921 for (Nurb &nu : *editnurb) {
6922 if (ED_curve_nurb_select_check(v3d, &nu)) {
6923 if (!clear) {
6924 nu.flag |= CU_SMOOTH;
6925 }
6926 else {
6927 nu.flag &= ~CU_SMOOTH;
6928 }
6929 }
6930 }
6931
6932 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
6933 DEG_id_tag_update(obedit->data, 0);
6934 ret_value = OPERATOR_FINISHED;
6935 }
6936
6937 return ret_value;
6938}
6939
6941{
6942 /* identifiers */
6943 ot->name = "Shade Smooth";
6944 ot->idname = "CURVE_OT_shade_smooth";
6945 ot->description = "Set shading to smooth";
6946
6947 /* API callbacks. */
6948 ot->exec = shade_smooth_exec;
6950
6951 /* flags */
6953}
6954
6956{
6957 /* identifiers */
6958 ot->name = "Shade Flat";
6959 ot->idname = "CURVE_OT_shade_flat";
6960 ot->description = "Set shading to flat";
6961
6962 /* API callbacks. */
6963 ot->exec = shade_smooth_exec;
6965
6966 /* flags */
6968}
6969
6971
6972/* -------------------------------------------------------------------- */
6975
6977{
6978 Main *bmain = CTX_data_main(C);
6979 Scene *scene = CTX_data_scene(C);
6980 Object *ob_active = CTX_data_active_object(C);
6981 Curve *cu;
6982 BezTriple *bezt;
6983 BPoint *bp;
6984 ListBaseT<Nurb> tempbase;
6985 float imat[4][4], cmat[4][4];
6986 int a;
6987 bool ok = false;
6988
6989 CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) {
6990 if (ob_iter == ob_active) {
6991 ok = true;
6992 break;
6993 }
6994 }
6996
6997 /* that way the active object is always selected */
6998 if (ok == false) {
6999 BKE_report(op->reports, RPT_WARNING, "Active object is not a selected curve");
7000 return OPERATOR_CANCELLED;
7001 }
7002
7003 tempbase.clear_no_delete();
7004 /* Inverse transform for all selected curves in this object,
7005 * See object_join_exec for detailed comment on why the safe version is used. */
7006 invert_m4_m4_safe_ortho(imat, ob_active->object_to_world().ptr());
7007
7008 Curve *cu_active = id_cast<Curve *>(ob_active->data);
7009
7010 CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) {
7011 if (ob_iter->type == ob_active->type) {
7012 if (ob_iter != ob_active) {
7013
7014 cu = id_cast<Curve *>(ob_iter->data);
7015
7016 if (cu->nurb.first_) {
7017 /* watch it: switch order here really goes wrong */
7018 mul_m4_m4m4(cmat, imat, ob_iter->object_to_world().ptr());
7019
7020 /* Compensate for different bevel depth. */
7021 bool do_radius = false;
7022 float compensate_radius = 0.0f;
7023 if (cu->bevel_radius != 0.0f && cu_active->bevel_radius != 0.0f) {
7024 float compensate_scale = mat4_to_scale(cmat);
7025 compensate_radius = cu->bevel_radius / cu_active->bevel_radius * compensate_scale;
7026 do_radius = true;
7027 }
7028
7029 for (Nurb &nu : cu->nurb) {
7030 Nurb *newnu = BKE_nurb_duplicate(&nu);
7031 if (ob_active->totcol) { /* TODO: merge material lists. */
7032 CLAMP(newnu->mat_nr, 0, ob_active->totcol - 1);
7033 }
7034 else {
7035 newnu->mat_nr = 0;
7036 }
7037 BLI_addtail(&tempbase, newnu);
7038
7039 if ((bezt = newnu->bezt)) {
7040 a = newnu->pntsu;
7041 while (a--) {
7042 /* Compensate for different bevel depth. */
7043 if (do_radius) {
7044 bezt->radius *= compensate_radius;
7045 }
7046
7047 mul_m4_v3(cmat, bezt->vec[0]);
7048 mul_m4_v3(cmat, bezt->vec[1]);
7049 mul_m4_v3(cmat, bezt->vec[2]);
7050 bezt++;
7051 }
7052 BKE_nurb_handles_calc(newnu);
7053 }
7054 if ((bp = newnu->bp)) {
7055 a = newnu->pntsu * nu.pntsv;
7056 while (a--) {
7057 mul_m4_v3(cmat, bp->vec);
7058 bp++;
7059 }
7060 }
7061 }
7062 }
7063
7064 ed::object::base_free_and_unlink(bmain, scene, ob_iter);
7065 }
7066 }
7067 }
7069
7070 cu = id_cast<Curve *>(ob_active->data);
7071 BLI_movelisttolist(&cu->nurb, &tempbase);
7072
7073 if (ob_active->type == OB_CURVES_LEGACY && CU_IS_2D(cu)) {
7074 /* Account for mixed 2D/3D curves when joining */
7076 }
7077
7078 DEG_relations_tag_update(bmain); /* because we removed object(s), call before editmode! */
7079
7082
7085
7086 return OPERATOR_FINISHED;
7087}
7088
7090
7091/* -------------------------------------------------------------------- */
7094
7096{
7097 const Main *bmain = CTX_data_main(C);
7098 const Scene *scene = CTX_data_scene(C);
7099 ViewLayer *view_layer = CTX_data_view_layer(C);
7100 View3D *v3d = CTX_wm_view3d(C);
7101
7103 *bmain, scene, view_layer, CTX_wm_view3d(C));
7104
7105 int totobjects = 0;
7106
7107 for (Object *obedit : objects) {
7108 Curve *cu = id_cast<Curve *>(obedit->data);
7109
7110 if (!ED_curve_select_check(v3d, cu->editnurb)) {
7111 continue;
7112 }
7113
7115 continue;
7116 }
7117
7118 totobjects++;
7119
7120 ListBaseT<Nurb> *editnurb = object_editcurve_get(obedit);
7121 BezTriple *bezt;
7122 BPoint *bp;
7123 int a;
7124
7125 for (Nurb &nu : *editnurb) {
7126 if (nu.bezt) {
7127 bezt = nu.bezt;
7128 a = nu.pntsu;
7129 while (a--) {
7130 if (BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)) {
7131 bezt->tilt = 0.0;
7132 }
7133 bezt++;
7134 }
7135 }
7136 else if (nu.bp) {
7137 bp = nu.bp;
7138 a = nu.pntsu * nu.pntsv;
7139 while (a--) {
7140 if (bp->f1 & SELECT) {
7141 bp->tilt = 0.0f;
7142 }
7143 bp++;
7144 }
7145 }
7146 }
7147
7148 WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
7149 DEG_id_tag_update(obedit->data, 0);
7150 }
7151 return totobjects ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
7152}
7153
7155{
7156 /* identifiers */
7157 ot->name = "Clear Tilt";
7158 ot->idname = "CURVE_OT_tilt_clear";
7159 ot->description = "Clear the tilt of selected control points";
7160
7161 /* API callbacks. */
7162 ot->exec = clear_tilt_exec;
7164
7165 /* flags */
7167}
7168
7169void ED_curve_beztcpy(EditNurb *editnurb, BezTriple *dst, BezTriple *src, int count)
7170{
7171 memcpy(dst, src, count * sizeof(BezTriple));
7172 keyIndex_updateBezt(editnurb, src, dst, count);
7173}
7174
7175void ED_curve_bpcpy(EditNurb *editnurb, BPoint *dst, BPoint *src, int count)
7176{
7177 memcpy(dst, src, count * sizeof(BPoint));
7178 keyIndex_updateBP(editnurb, src, dst, count);
7179}
7180
7182
7183/* -------------------------------------------------------------------- */
7186
7188{
7189 Object *object = CTX_data_active_object(C);
7190
7191 return object && ELEM(object->type, OB_CURVES_LEGACY, OB_SURF, OB_FONT);
7192}
7193
7195{
7196 /* Need to ensure the dependency graph is fully evaluated, so the display list is at a correct
7197 * state. */
7198 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
7199 (void)depsgraph;
7200
7201 Object *object = CTX_data_active_object(C);
7202 Object *object_eval = DEG_get_evaluated(depsgraph, object);
7203 Curve *curve = id_cast<Curve *>(object->data);
7204 float min[3], max[3], texspace_size[3], texspace_location[3];
7205 int a;
7206
7207 BLI_assert(object_eval->runtime->curve_cache != nullptr);
7208
7211
7212 mid_v3_v3v3(texspace_location, min, max);
7213
7214 texspace_size[0] = (max[0] - min[0]) / 2.0f;
7215 texspace_size[1] = (max[1] - min[1]) / 2.0f;
7216 texspace_size[2] = (max[2] - min[2]) / 2.0f;
7217
7218 for (a = 0; a < 3; a++) {
7219 if (texspace_size[a] == 0.0f) {
7220 texspace_size[a] = 1.0f;
7221 }
7222 else if (texspace_size[a] > 0.0f && texspace_size[a] < 0.00001f) {
7223 texspace_size[a] = 0.00001f;
7224 }
7225 else if (texspace_size[a] < 0.0f && texspace_size[a] > -0.00001f) {
7226 texspace_size[a] = -0.00001f;
7227 }
7228 }
7229
7230 copy_v3_v3(curve->texspace_location, texspace_location);
7231 copy_v3_v3(curve->texspace_size, texspace_size);
7232
7234
7237
7238 return OPERATOR_FINISHED;
7239}
7240
7242{
7243 /* identifiers */
7244 ot->name = "Match Texture Space";
7245 ot->idname = "CURVE_OT_match_texture_space";
7246 ot->description = "Match texture space to object's bounding box";
7247
7248 /* API callbacks. */
7251
7252 /* flags */
7254}
7255
7257
7258} // namespace blender
Functions and classes to work with Actions.
Functions to work with AnimData.
Blender kernel action and pose functionality.
#define CTX_DATA_BEGIN(C, Type, instance, member)
#define CTX_DATA_END
#define KNOTSU(nu)
Definition BKE_curve.hh:78
#define CU_IS_2D(cu)
Definition BKE_curve.hh:93
#define KNOTSV(nu)
Definition BKE_curve.hh:80
display list (or rather multi purpose list) stuff.
#define SELECT
Definition BKE_mask.hh:19
Generic array manipulation API.
#define BLI_array_iter_span(arr, arr_len, use_wrap, use_delimit_bounds, test_fn, user_data, span_step, r_span_len)
#define M_SQRT2
#define M_PI_4
#define SNPRINTF_UTF8(dst, format,...)
#define IFACE_(msgid)
#define SURF_SEEN
#define CU_ACT_NONE
#define BEZT_ISSEL_ANY_HIDDENHANDLES(v3d, bezt)
#define BEZT_SEL_ALL(bezt)
#define BEZT_DESEL_ALL(bezt)
#define KEYELEM_FLOAT_LEN_BEZTRIPLE
#define KEYELEM_FLOAT_LEN_BPOINT
Object is a sort of wrapper for general info.
#define OBJECT_ADD_SIZE_MAXF
Definition ED_object.hh:332
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define NC_GEOM
Definition WM_types.hh:406
#define ND_DRAW
Definition WM_types.hh:502
#define ND_OB_ACTIVE
Definition WM_types.hh:459
#define ND_DATA
Definition WM_types.hh:552
#define NC_SCENE
Definition WM_types.hh:391
#define ND_LAYER_CONTENT
Definition WM_types.hh:472
#define ND_SELECT
Definition WM_types.hh:551
#define ND_KEYS
Definition WM_types.hh:504
#define NC_OBJECT
Definition WM_types.hh:392
#define CLAMP(a, b, c)
#define STRPREFIX(a, b)
#define INIT_MINMAX(min, max)
#define BLI_assert_unreachable()
#define UNUSED_VARS(...)
#define STREQLEN(a, b, n)
#define UNUSED_VARS_NDEBUG(...)
#define ELEM(...)
#define IN_RANGE_INCL(a, b, c)
#define STREQ(a, b)
btScalar max
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
bool add(const Key &key, const Value &value)
Definition BLI_map.hh:295
Value lookup_default(const Key &key, const Value &default_value) const
Definition BLI_map.hh:570
int64_t size() const
Definition BLI_map.hh:976
void reserve(int64_t n)
Definition BLI_map.hh:1028
Value pop_default(const Key &key, const Value &default_value)
Definition BLI_map.hh:439
ItemIterator items() const &
Definition BLI_map.hh:902
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
constexpr bool is_empty() const
Definition BLI_span.hh:264
int64_t size() const
void append(const T &value)
#define printf
#define offsetof(t, d)
#define BEZT_VALUE(bezt)
#define BP_VALUE(bp)
#define FLT_MAX
#define FLT_EPSILON
float2x2 invert(float2x2 mat)
bool flag_test(uint flag, uint val)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
bool action_fcurve_remove(Action &action, FCurve &fcu)
Span< FCurve * > fcurves_for_assigned_action(AnimData *adt)
Definition animdata.cc:349
bool shape_key_report_if_locked(const Object *obedit, ReportList *reports)
void base_activate(bContext *C, Base *base)
Base * add_duplicate(Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base, eDupli_ID_Flags dupflag)
bool material_active_index_set(Object *ob, int index)
void base_free_and_unlink(Main *bmain, Scene *scene, Object *ob)
void snap_object_context_destroy(SnapObjectContext *sctx)
SnapObjectContext * snap_object_context_create()
eSnapMode snap_object_project_view3d(SnapObjectContext *sctx, Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const eSnapMode snap_to, const SnapObjectParams *params, const float init_co[3], const float mval[2], const float prev_co[3], float *dist_px, float r_loc[3], float r_no[3])
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
Definition abc_util.cc:68
PopupMenu * popup_menu_begin(bContext *C, const char *title, int icon) ATTR_NONNULL()
BMesh Iterators.
bool isect_ray_plane_v3_factor(const float ray_origin[3], const float ray_direction[3], const float plane_co[3], const float plane_no[3], float *r_lambda)
MINLINE void madd_v3_v3v3fl(float r[3], const float a[3], const float b[3], float f)
static wmOperatorStatus hide_exec(bContext *C, wmOperator *op)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_curve_nurb_vert_active_set(Curve *cu, const Nurb *nu, const void *vert)
Definition curve.cc:5048
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
void mul_m3_v3(const float M[3][3], float r[3])
static wmOperatorStatus toggle_cyclic_exec(bContext *C, wmOperator *op)
static wmOperatorStatus add_vertex_exec(bContext *C, wmOperator *op)
void BKE_curve_editNurb_free(Curve *cu)
Definition curve.cc:378
void ED_curve_bpcpy(EditNurb *editnurb, BPoint *dst, BPoint *src, int count)
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
MINLINE int mod_i(int i, int n)
Nurb * BKE_curve_nurb_active_get(Curve *cu)
Definition curve.cc:5022
static wmOperatorStatus shade_smooth_exec(bContext *C, wmOperator *op)
static wmOperatorStatus separate_exec(bContext *C, wmOperator *op)
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
static wmOperatorStatus smooth_exec(bContext *C, wmOperator *op)
int RNA_enum_get(PointerRNA *ptr, const char *name)
static wmOperatorStatus add_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void CURVE_OT_make_segment(wmOperatorType *ot)
@ RPT_WARNING
Definition BKE_report.hh:40
void ED_curve_editnurb_load(Main *bmain, Object *obedit)
void CURVE_OT_match_texture_space(wmOperatorType *ot)
void CURVE_OT_duplicate(wmOperatorType *ot)
static wmOperatorStatus curve_decimate_exec(bContext *C, wmOperator *op)
ViewContext ED_view3d_viewcontext_init(bContext *C, Depsgraph *depsgraph)
wmOperatorStatus WM_operator_flag_only_pass_through_on_press(wmOperatorStatus retval, const wmEvent *event)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
static void keyIndex_delBP(EditNurb *editnurb, BPoint *bp)
Definition editcurve.cc:283
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static const EnumPropertyItem * rna_curve_delete_type_itemf(bContext *C, PointerRNA *, PropertyRNA *, bool *r_free)
static wmOperatorStatus clear_tilt_exec(bContext *C, wmOperator *op)
static wmOperatorStatus switch_direction_exec(bContext *C, wmOperator *)
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
void copy_m3_m4(float m1[3][3], const float m2[4][4])
void CURVE_OT_tilt_clear(wmOperatorType *ot)
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
void CURVE_OT_vertex_add(wmOperatorType *ot)
static wmOperatorStatus make_segment_exec(bContext *C, wmOperator *op)
void CURVE_OT_extrude(wmOperatorType *ot)
static void rotate_direction_nurb(Nurb *nu)
bool ed_editnurb_extrude_flag(EditNurb *editnurb, eBezTriple_Flag flag)
void interp_v4_v4v4(float r[4], const float a[4], const float b[4], float t)
float mat4_to_scale(const float mat[4][4])
bool invert_m3_m3(float inverse[3][3], const float mat[3][3])
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
void ED_curve_nurb_vert_selected_find(Curve *cu, View3D *v3d, Nurb **r_nu, BezTriple **r_bezt, BPoint **r_bp)
void BKE_nurbList_free(ListBaseT< Nurb > *lb)
Definition curve.cc:619
MINLINE float mul_project_m4_v3_zfac(const float mat[4][4], const float co[3]) ATTR_WARN_UNUSED_RESULT
static void switch_keys_direction(Curve *cu, Nurb *actnu)
Definition editcurve.cc:493
static void key_to_bezt(float *key, BezTriple *basebezt, BezTriple *bezt)
Definition editcurve.cc:575
static wmOperatorStatus set_radius_exec(bContext *C, wmOperator *op)
static void make_selection_list_nurb(View3D *v3d, ListBaseT< Nurb > *editnurb, ListBaseT< NurbSort > *nsortbase)
KeyBlock * BKE_keyblock_from_object(Object *ob)
Definition key.cc:1407
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void BKE_keyblock_convert_to_curve(KeyBlock *kb, Curve *cu, ListBaseT< Nurb > *nurb)
Definition key.cc:1658
int ED_curve_updateAnimPaths(Main *bmain, Curve *cu)
bool ED_operator_editcurve(bContext *C)
static BezTriple * getKeyIndexOrig_bezt(EditNurb *editnurb, const BezTriple *bezt)
Definition editcurve.cc:241
static void keyIndex_delBezt(EditNurb *editnurb, BezTriple *bezt)
Definition editcurve.cc:274
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
static wmOperatorStatus curve_smooth_weight_exec(bContext *C, wmOperator *)
char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
static bool curve_delete_vertices(Object *obedit, View3D *v3d)
bool BKE_nurb_order_clamp_u(Nurb *nu)
Definition curve.cc:4828
void ED_curve_keyindex_update_nurb(EditNurb *editnurb, Nurb *nu, Nurb *newnu)
Definition editcurve.cc:367
void axis_angle_to_mat3(float R[3][3], const float axis[3], float angle)
void CURVE_OT_cyclic_toggle(wmOperatorType *ot)
void void void BLI_movelisttolist(ListBase *dst, ListBase *src) ATTR_NONNULL(1
Definition listbase.cc:32
int RNA_int_get(PointerRNA *ptr, const char *name)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void view3d_operator_needs_gpu(const bContext *C)
void CURVE_OT_smooth_weight(wmOperatorType *ot)
void ED_curve_beztcpy(EditNurb *editnurb, BezTriple *dst, BezTriple *src, int count)
Base * BKE_view_layer_active_base_get(ViewLayer *view_layer)
MINLINE int max_ii(int a, int b)
ATTR_WARN_UNUSED_RESULT const BMVert * v
void CURVE_OT_spin(wmOperatorType *ot)
eNurbHandleTest_Mode
Definition BKE_curve.hh:63
@ NURB_HANDLE_TEST_KNOT_OR_EACH
Definition BKE_curve.hh:70
@ NURB_HANDLE_TEST_KNOT_ONLY
Definition BKE_curve.hh:75
static wmOperatorStatus curve_smooth_tilt_exec(bContext *C, wmOperator *op)
void BKE_nurbList_flag_set(ListBaseT< Nurb > *editnurb, eBezTriple_Flag flag, bool set)
Definition curve.cc:4376
static int getKeyIndexOrig_keyIndex(EditNurb *editnurb, void *cv)
Definition editcurve.cc:263
void ED_curve_editnurb_free(Object *obedit)
static wmOperatorStatus curve_smooth_radius_exec(bContext *C, wmOperator *op)
RegionView3D * ED_view3d_context_rv3d(bContext *C)
static void select_bpoints(BPoint *bp, const int stride, const int count, const bool selstatus, const eBezTriple_Flag flag, const bool hidden)
@ CURVE_MERGE_OK
@ CURVE_MERGE_ERR_FEW_SELECTION
@ CURVE_MERGE_ERR_RESOLUTION_ALL
@ CURVE_MERGE_ERR_RESOLUTION_SOME
void BKE_nurb_project_2d(Nurb *nu)
Definition curve.cc:707
void BKE_nurbList_handles_set(ListBaseT< Nurb > *editnurb, eNurbHandleTest_Mode handle_mode, eBezTriple_Handle code)
Definition curve.cc:4228
void MEM_delete_void(void *vmemh)
void ED_view3d_global_to_vector(const RegionView3D *rv3d, const float coord[3], float r_out[3])
void BKE_nurb_handle_calc(BezTriple *bezt, BezTriple *prev, BezTriple *next, bool is_fcurve, char smoothing)
Definition curve.cc:3975
ViewLayer * CTX_data_view_layer(const bContext *C)
void ED_outliner_select_sync_from_object_tag(bContext *C)
void BKE_curve_nurb_vert_active_validate(Curve *cu)
Definition curve.cc:5092
std::optional< Array< bool > > BKE_keyblock_get_dependent_keys(const Key *key, int index)
Definition key.cc:1875
MINLINE void mul_v3_fl(float r[3], float f)
static bool curve_delete_segments(Object *obedit, View3D *v3d, const bool split)
static void ed_surf_delete_selected(Object *obedit)
Vector< T * > listbase_to_vector(ListBase &list)
void BKE_curve_nurb_active_set(Curve *cu, const Nurb *nu)
Definition curve.cc:5010
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
static NurbDim editnurb_find_max_points_num(const EditNurb *editnurb)
static void keyIndex_swap(EditNurb *editnurb, void *a, void *b)
Definition editcurve.cc:377
void CURVE_OT_decimate(wmOperatorType *ot)
void BKE_nurb_knot_calc_v(Nurb *nu)
Definition curve.cc:1219
void CURVE_OT_delete(wmOperatorType *ot)
Global G
Definition blender.cc:57
MINLINE void sub_v3_v3(float r[3], const float a[3])
static void keyIndex_updateBezt(EditNurb *editnurb, BezTriple *bezt, BezTriple *newbezt, int count)
Definition editcurve.cc:349
static void switchdirection_knots(float *base, int tot)
static bool match_texture_space_poll(bContext *C)
static int sel_to_copy_ints(const BPoint *bp, const int next_j, const int max_j, const int next_i, const int max_i, const uint8_t flag, int copy_intervals[], int *interval_count, bool *out_is_first_sel)
void BKE_nurb_bezierPoints_add(Nurb *nu, int number)
Definition curve.cc:900
PropertyRNA * RNA_def_float_factor(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void mul_m4_v3(const float M[4][4], float r[3])
void CURVE_OT_normals_make_consistent(wmOperatorType *ot)
AnimData * BKE_animdata_from_id(const ID *id)
Definition anim_data.cc:93
static wmOperatorStatus spin_invoke(bContext *C, wmOperator *op, const wmEvent *)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
KeyBlock * BKE_keyblock_find_by_index(Key *key, int index)
Definition key.cc:1425
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
void CURVE_OT_smooth_tilt(wmOperatorType *ot)
@ SCE_SNAP_TARGET_NOT_ACTIVE
void CURVE_OT_dissolve_verts(wmOperatorType *ot)
bool ED_curve_nurb_select_check(const View3D *v3d, const Nurb *nu)
void CURVE_OT_subdivide(wmOperatorType *ot)
static wmOperatorStatus subdivide_exec(bContext *C, wmOperator *op)
static bool test_bezt_is_sel_any(const void *bezt_v, void *user_data)
void * MEM_dupalloc_void(const void *vmemh) ATTR_WARN_UNUSED_RESULT
KeyBlock * ED_curve_get_edit_shape_key(const Curve *cu)
Definition editcurve.cc:104
void CURVE_OT_hide(wmOperatorType *ot)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static void curve_smooth_value(ListBaseT< Nurb > *editnurb, const int bezt_offsetof, const int bp_offset)
static void smooth_single_bp(BPoint *bp, const BPoint *bp_orig_prev, const BPoint *bp_orig_next, float factor)
void CURVE_OT_spline_weight_set(wmOperatorType *ot)
void BKE_nurb_handles_calc(Nurb *nu)
Definition curve.cc:3992
void CURVE_OT_radius_set(wmOperatorType *ot)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
void DEG_id_tag_update(ID *id, unsigned int flags)
MINLINE void swap_v3_v3(float a[3], float b[3])
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
wmOperatorStatus ED_curve_join_objects_exec(bContext *C, wmOperator *op)
BMesh const char void * data
static void keyIndex_delNurbList(EditNurb *editnurb, ListBaseT< Nurb > *nubase)
Definition editcurve.cc:320
void BKE_curve_editNurb_keyIndex_delCV(CVKeyIndexMap *keyindex, const void *cv)
Definition curve.cc:358
static void rotateflagNurb(ListBaseT< Nurb > *editnurb, eBezTriple_Flag flag, const float cent[3], const float rotmat[3][3])
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
static void remap_hooks_and_vertex_parents(Main *bmain, Object *obedit)
static bool ed_editcurve_extrude(Curve *cu, EditNurb *editnurb, View3D *v3d)
void CURVE_OT_switch_direction(wmOperatorType *ot)
static wmOperatorStatus curve_extrude_exec(bContext *C, wmOperator *)
static wmOperatorStatus toggle_cyclic_invoke(bContext *C, wmOperator *op, const wmEvent *)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
void ed_editnurb_translate_flag(ListBaseT< Nurb > *editnurb, eBezTriple_Flag flag, const float vec[3], bool is_2d)
Object * CTX_data_edit_object(const bContext *C)
static void interp_bpoint(BPoint *bp_target, const BPoint *bp_a, const BPoint *bp_b, const float factor)
unsigned char uint8_t
Definition BKE_text.h:79
@ SCE_SNAP_INDIVIDUAL_PROJECT
static bool isNurbselU(Nurb *nu, int *v, eBezTriple_Flag flag)
static void keyIndex_updateCV(EditNurb *editnurb, char *cv, char *newcv, int count, int size)
Definition editcurve.cc:327
static Vector< FCurve * > curve_rename_fcurves(Curve *cu, Span< FCurve * > orig_curves)
Definition editcurve.cc:960
wmOperatorStatus WM_operator_props_popup(bContext *C, wmOperator *op, const wmEvent *)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
void BKE_displist_minmax(const ListBaseT< DispList > *dispbase, float min[3], float max[3])
Definition displist.cc:1741
bool ED_operator_editsurfcurve(bContext *C)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
void unit_m4(float m[4][4])
CVKeyIndexMap * ED_curve_keyindex_hash_duplicate(CVKeyIndexMap *keyindex)
Definition editcurve.cc:556
static wmOperatorStatus set_goal_weight_exec(bContext *C, wmOperator *op)
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts)
void RNA_enum_items_add_value(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item, int value)
BezTriple * BKE_nurb_bezt_get_next(Nurb *nu, BezTriple *bezt)
Definition curve.cc:946
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
bool ED_curve_editnurb_select_pick(bContext *C, const int mval[2], const int dist_px, const SelectPick_Params &params)
ATTR_WARN_UNUSED_RESULT const size_t num
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void CURVE_OT_smooth_radius(wmOperatorType *ot)
static void init_editNurb_keyIndex(EditNurb *editnurb, ListBaseT< Nurb > *origBase)
Definition editcurve.cc:164
void CURVE_OT_separate(wmOperatorType *ot)
ListBaseT< Nurb > * object_editcurve_get(Object *ob)
Definition editcurve.cc:95
static CVKeyIndex * popCVKeyIndex(EditNurb *editnurb, const void *cv)
Definition editcurve.cc:236
MINLINE void zero_v3(float r[3])
void CURVE_OT_split(wmOperatorType *ot)
static void keyIndex_switchDirection(EditNurb *editnurb, Nurb *nu)
Definition editcurve.cc:390
static int merge_nurb(View3D *v3d, Object *obedit)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
static wmOperatorStatus curve_dissolve_exec(bContext *C, wmOperator *)
static wmOperatorStatus reveal_exec(bContext *C, wmOperator *op)
static wmOperatorStatus curve_split_exec(bContext *C, wmOperator *op)
static void keyIndex_delNurb(EditNurb *editnurb, Nurb *nu)
Definition editcurve.cc:292
Nurb * BKE_nurb_duplicate(const Nurb *nu)
Definition curve.cc:631
const EnumPropertyItem rna_enum_transform_mode_type_items[]
MINLINE float normalize_v3_v3(float r[3], const float a[3])
static const EnumPropertyItem curve_delete_type_items[]
static wmOperatorStatus curve_delete_exec(bContext *C, wmOperator *op)
static void smooth_single_bezt(BezTriple *bezt, const BezTriple *bezt_orig_prev, const BezTriple *bezt_orig_next, float factor)
void CURVE_OT_shade_smooth(wmOperatorType *ot)
static bool nurb_bezt_flag_any(const Nurb *nu, const char flag_test)
void BKE_nurbList_handles_recalculate(ListBaseT< Nurb > *editnurb, bool calc_length, eBezTriple_Flag flag)
Definition curve.cc:4319
MINLINE float normalize_v3(float n[3])
static void ed_curve_delete_selected(Object *obedit, View3D *v3d)
MINLINE void add_v3_v3(float r[3], const float a[3])
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
void BKE_fcurve_free(FCurve *fcu)
PropertyRNA * RNA_def_float_vector_xyz(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
static wmOperatorStatus duplicate_exec(bContext *C, wmOperator *op)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
int ed_editcurve_addvert(Curve *cu, EditNurb *editnurb, View3D *v3d, const float location_init[3])
Main * CTX_data_main(const bContext *C)
void unit_m3(float m[3][3])
void CURVE_OT_reveal(wmOperatorType *ot)
void BKE_curve_editNurb_keyIndex_free(CVKeyIndexMap **keyindex)
Definition curve.cc:366
bool BKE_curve_nurb_vert_active_get(Curve *cu, Nurb **r_nu, void **r_vert)
Definition curve.cc:5065
int BKE_keyblock_curve_element_count(const ListBaseT< Nurb > *nurb)
Definition key.cc:1528
static bool calc_duplicate_actvert(const ListBaseT< Nurb > *editnurb, const ListBaseT< Nurb > *newnurb, Curve *cu, int start, int end, int vert)
bool select_beztriple(BezTriple *bezt, bool selstatus, eBezTriple_Flag flag, eVisible_Types hidden)
void CURVE_OT_smooth(wmOperatorType *ot)
void BKE_nurb_handle_calc_simple_auto(Nurb *nu, BezTriple *bezt)
Definition curve.cc:4031
static BPoint * getKeyIndexOrig_bp(EditNurb *editnurb, BPoint *bp)
Definition editcurve.cc:252
bool ED_curve_pick_vert_ex(ViewContext *vc, bool select, int dist_px, Nurb **r_nurb, BezTriple **r_bezt, BPoint **r_bp, short *r_handle, Base **r_base)
bool ED_curve_select_check(const View3D *v3d, const EditNurb *editnurb)
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
Vector< Object * > BKE_view_layer_array_from_objects_in_edit_mode_unique_data(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
void CURVE_OT_shade_flat(wmOperatorType *ot)
static wmOperatorStatus set_spline_type_exec(bContext *C, wmOperator *op)
void ED_curve_editnurb_make(Object *obedit)
bool BKE_nurb_type_convert(Nurb *nu, eNurbType type, bool use_handles, const char **r_err_msg)
Definition curve.cc:4848
static CVKeyIndex * init_cvKeyIndex(void *cv, int key_index, int nu_index, int pt_index, int vertex_index)
Definition editcurve.cc:149
@ CU_TEXSPACE_FLAG_AUTO
Vector< Base * > BKE_view_layer_array_from_bases_in_edit_mode_unique_data(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
static bool isNurbselV(Nurb *nu, int *u, eBezTriple_Flag flag)
MINLINE float interpf(float target, float origin, float t)
void ED_view3d_win_to_3d_int(const View3D *v3d, const ARegion *region, const float depth_pt[3], const int mval[2], float r_out[3])
bool select_bpoint(BPoint *bp, bool selstatus, eBezTriple_Flag flag, bool hidden)
void DEG_relations_tag_update(Main *bmain)
static void fcurve_path_rename(const char *orig_rna_path, const char *rna_path, const Span< FCurve * > orig_curves, Set< FCurve * > &processed_fcurves)
Definition editcurve.cc:931
Scene * CTX_data_scene(const bContext *C)
static wmOperatorStatus match_texture_space_exec(bContext *C, wmOperator *)
void BKE_nurb_handle_calc_simple(Nurb *nu, BezTriple *bezt)
Definition curve.cc:4022
static CVKeyIndex * getCVKeyIndex(EditNurb *editnurb, const void *cv)
Definition editcurve.cc:231
void CURVE_OT_spline_type_set(wmOperatorType *ot)
BPoint * BKE_nurb_bpoint_get_next(Nurb *nu, BPoint *bp)
Definition curve.cc:967
static void keyIndex_updateBP(EditNurb *editnurb, BPoint *bp, BPoint *newbp, int count)
Definition editcurve.cc:358
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_DEPENDS_ON_CURSOR
Definition WM_types.hh:228
static wmOperatorStatus set_handle_type_exec(bContext *C, wmOperator *op)
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
void copy_m4_m4(float m1[4][4], const float m2[4][4])
void CURVE_OT_handle_type_set(wmOperatorType *ot)
static void bezt_to_key(BezTriple *bezt, float *key)
Definition editcurve.cc:583
int ED_curve_nurb_select_count(const View3D *v3d, const Nurb *nu)
void * BKE_curve_vert_active_get(Curve *cu)
Definition curve.cc:5028
static void weightflagNurb(ListBaseT< Nurb > *editnurb, short flag, float w)
bool ED_curve_deselect_all(EditNurb *editnurb)
void BKE_nurb_knot_calc_u(Nurb *nu)
Definition curve.cc:1214
bool ed_editnurb_spin(float viewmat[4][4], View3D *v3d, Object *obedit, const float axis[3], const float cent[3])
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
bool ED_operator_editsurf(bContext *C)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
static int * init_index_map(Object *obedit, int *r_old_totvert)
static void calc_keyHandles(ListBaseT< Nurb > *nurb, float *key)
Definition editcurve.cc:590
Nurb * BKE_nurb_copy(Nurb *src, int pntsu, int pntsv)
Definition curve.cc:671
static bool merge_2_nurb(Curve *cu, ListBaseT< Nurb > *editnurb, Nurb *nu1, Nurb *nu2)
void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride)
Definition curve.cc:1696
static void calc_duplicate_actnurb(const ListBaseT< Nurb > *editnurb, const ListBaseT< Nurb > *newnurb, Curve *cu)
static bool curve_is_animated(Curve *cu)
Definition editcurve.cc:921
void WM_cursor_wait(bool val)
ID * BKE_id_copy(Main *bmain, const ID *id)
Definition lib_id.cc:856
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
Object * CTX_data_active_object(const bContext *C)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void id_us_min(ID *id)
Definition lib_id.cc:441
void BKE_curve_decimate_nurb(Nurb *nu, unsigned int resolu, float error_sq_max, unsigned int error_target_len)
static bool is_u_selected(Nurb *nu, int u)
float RNA_float_get(PointerRNA *ptr, const char *name)
static void adduplicateflagNurb(Object *obedit, View3D *v3d, ListBaseT< Nurb > *newnurb, const eBezTriple_Flag flag, const bool split)
static wmOperatorStatus spin_exec(bContext *C, wmOperator *op)
View3D * CTX_wm_view3d(const bContext *C)
Map< const void *, struct CVKeyIndex * > CVKeyIndexMap
void invert_m4_m4_safe_ortho(float inverse[4][4], const float mat[4][4])
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
static void calc_shapeKeys(Object *obedit, ListBaseT< Nurb > *newnurbs)
Definition editcurve.cc:665
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void keyData_switchDirectionNurb(Curve *cu, Nurb *nu)
Definition editcurve.cc:541
void ed_dissolve_bez_segment(BezTriple *bezt_prev, BezTriple *bezt_next, const Nurb *nu, const Curve *cu, const uint span_len, const uint span_step[2])
bool curve_toggle_cyclic(View3D *v3d, ListBaseT< Nurb > *editnurb, int direction)
bool BKE_nurb_order_clamp_v(Nurb *nu)
Definition curve.cc:4838
void BKE_nurb_direction_switch(Nurb *nu)
Definition curve.cc:4444
void selectend_nurb(Object *obedit, enum eEndPoint_Types selfirst, bool doswap, bool selstatus)
void BKE_nurb_free(Nurb *nu)
Definition curve.cc:593
void BKE_curve_dimension_update(Curve *cu)
Definition curve.cc:459
static wmOperatorStatus curve_normals_make_consistent_exec(bContext *C, wmOperator *op)
const btScalar eps
Definition poly34.cpp:11
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
const NodeType * type
Definition graph/node.h:179
ListBaseT< FCurve > drivers
struct Object * object
eBezTriple_Flag f2
eBezTriple_Handle h2
eBezTriple_Flag f3
eBezTriple_Flag f1
eBezTriple_Handle h1
ListBaseT< DispList > disp
Definition BKE_curve.hh:44
ListBaseT< Nurb > nurb
EditNurb * editnurb
float texspace_location[3]
struct Key * key
CVKeyIndexMap * keyindex
ListBaseT< Nurb > nurbs
KeyBlock * refkey
ListBaseT< KeyBlock > block
ShapekeyContainerType type
ListBaseT< Object > objects
Definition BKE_main.hh:388
BezTriple * bezt
eNurbKnotFlag flagu
eNurbKnotFlag flagv
struct Nurb * next
bke::ObjectRuntime * runtime
View3DCursor cursor
struct ToolSettings * toolsettings
eHandleDisplay handle_display
View3DOverlay overlay
ViewLayer * view_layer
Definition ED_view3d.hh:80
RegionView3D * rv3d
Definition ED_view3d.hh:86
Depsgraph * depsgraph
Definition ED_view3d.hh:78
void op_enum(StringRefNull opname, StringRefNull propname, IDProperty *properties, wm::OpCallContext context, eUI_Item_Flag flag, const int active=-1)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
struct ReportList * reports
struct wmOperatorType * type