Blender  V2.93
editcurve_add.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #include "DNA_anim_types.h"
25 #include "DNA_object_types.h"
26 #include "DNA_scene_types.h"
27 
28 #include "MEM_guardedalloc.h"
29 
30 #include "BLI_blenlib.h"
31 #include "BLI_math.h"
32 
33 #include "BLT_translation.h"
34 
35 #include "BKE_context.h"
36 #include "BKE_curve.h"
37 
38 #include "DEG_depsgraph.h"
39 
40 #include "RNA_access.h"
41 
42 #include "WM_api.h"
43 #include "WM_types.h"
44 
45 #include "ED_curve.h"
46 #include "ED_object.h"
47 #include "ED_screen.h"
48 #include "ED_view3d.h"
49 
50 #include "curve_intern.h"
51 
52 static const float nurbcircle[8][2] = {
53  {0.0, -1.0},
54  {-1.0, -1.0},
55  {-1.0, 0.0},
56  {-1.0, 1.0},
57  {0.0, 1.0},
58  {1.0, 1.0},
59  {1.0, 0.0},
60  {1.0, -1.0},
61 };
62 
63 /************ add primitive, used by object/ module ****************/
64 
65 static const char *get_curve_defname(int type)
66 {
67  int stype = type & CU_PRIMITIVE;
68 
69  if ((type & CU_TYPE) == CU_BEZIER) {
70  switch (stype) {
71  case CU_PRIM_CURVE:
72  return CTX_DATA_(BLT_I18NCONTEXT_ID_CURVE, "BezierCurve");
73  case CU_PRIM_CIRCLE:
74  return CTX_DATA_(BLT_I18NCONTEXT_ID_CURVE, "BezierCircle");
75  case CU_PRIM_PATH:
76  return CTX_DATA_(BLT_I18NCONTEXT_ID_CURVE, "CurvePath");
77  default:
78  return CTX_DATA_(BLT_I18NCONTEXT_ID_CURVE, "Curve");
79  }
80  }
81  else {
82  switch (stype) {
83  case CU_PRIM_CURVE:
84  return CTX_DATA_(BLT_I18NCONTEXT_ID_CURVE, "NurbsCurve");
85  case CU_PRIM_CIRCLE:
86  return CTX_DATA_(BLT_I18NCONTEXT_ID_CURVE, "NurbsCircle");
87  case CU_PRIM_PATH:
88  return CTX_DATA_(BLT_I18NCONTEXT_ID_CURVE, "NurbsPath");
89  default:
90  return CTX_DATA_(BLT_I18NCONTEXT_ID_CURVE, "Curve");
91  }
92  }
93 }
94 
95 static const char *get_surf_defname(int type)
96 {
97  int stype = type & CU_PRIMITIVE;
98 
99  switch (stype) {
100  case CU_PRIM_CURVE:
101  return CTX_DATA_(BLT_I18NCONTEXT_ID_CURVE, "SurfCurve");
102  case CU_PRIM_CIRCLE:
103  return CTX_DATA_(BLT_I18NCONTEXT_ID_CURVE, "SurfCircle");
104  case CU_PRIM_PATCH:
105  return CTX_DATA_(BLT_I18NCONTEXT_ID_CURVE, "SurfPatch");
106  case CU_PRIM_SPHERE:
107  return CTX_DATA_(BLT_I18NCONTEXT_ID_CURVE, "SurfSphere");
108  case CU_PRIM_DONUT:
109  return CTX_DATA_(BLT_I18NCONTEXT_ID_CURVE, "SurfTorus");
110  default:
111  return CTX_DATA_(BLT_I18NCONTEXT_ID_CURVE, "Surface");
112  }
113 }
114 
116  bContext *C, Object *obedit, float mat[4][4], int type, int newob)
117 {
118  static int xzproj = 0; /* this function calls itself... */
119  ListBase *editnurb = object_editcurve_get(obedit);
121  Nurb *nu = NULL;
122  BezTriple *bezt;
123  BPoint *bp;
124  Curve *cu = (Curve *)obedit->data;
125  float vec[3], zvec[3] = {0.0f, 0.0f, 1.0f};
126  float umat[4][4], viewmat[4][4];
127  float fac;
128  int a, b;
129  const float grid = 1.0f;
130  const int cutype = (type & CU_TYPE); /* poly, bezier, nurbs, etc */
131  const int stype = (type & CU_PRIMITIVE);
132 
133  unit_m4(umat);
134  unit_m4(viewmat);
135 
136  if (rv3d) {
137  copy_m4_m4(viewmat, rv3d->viewmat);
138  copy_v3_v3(zvec, rv3d->viewinv[2]);
139  }
140 
141  BKE_nurbList_flag_set(editnurb, SELECT, false);
142 
143  /* these types call this function to return a Nurb */
144  if (!ELEM(stype, CU_PRIM_TUBE, CU_PRIM_DONUT)) {
145  nu = (Nurb *)MEM_callocN(sizeof(Nurb), "addNurbprim");
146  nu->type = cutype;
147  nu->resolu = cu->resolu;
148  nu->resolv = cu->resolv;
149  }
150 
151  switch (stype) {
152  case CU_PRIM_CURVE: /* curve */
153  nu->resolu = cu->resolu;
154  if (cutype == CU_BEZIER) {
155  nu->pntsu = 2;
156  nu->bezt = (BezTriple *)MEM_callocN(sizeof(BezTriple) * nu->pntsu, "addNurbprim1");
157  bezt = nu->bezt;
158  bezt->h1 = bezt->h2 = HD_ALIGN;
159  bezt->f1 = bezt->f2 = bezt->f3 = SELECT;
160  bezt->radius = 1.0;
161 
162  bezt->vec[1][0] += -grid;
163  bezt->vec[0][0] += -1.5f * grid;
164  bezt->vec[0][1] += -0.5f * grid;
165  bezt->vec[2][0] += -0.5f * grid;
166  bezt->vec[2][1] += 0.5f * grid;
167  for (a = 0; a < 3; a++) {
168  mul_m4_v3(mat, bezt->vec[a]);
169  }
170 
171  bezt++;
172  bezt->h1 = bezt->h2 = HD_ALIGN;
173  bezt->f1 = bezt->f2 = bezt->f3 = SELECT;
174  bezt->radius = bezt->weight = 1.0;
175 
176  bezt->vec[0][0] = 0;
177  bezt->vec[0][1] = 0;
178  bezt->vec[1][0] = grid;
179  bezt->vec[1][1] = 0;
180  bezt->vec[2][0] = grid * 2;
181  bezt->vec[2][1] = 0;
182  for (a = 0; a < 3; a++) {
183  mul_m4_v3(mat, bezt->vec[a]);
184  }
185 
187  }
188  else {
189 
190  nu->pntsu = 4;
191  nu->pntsv = 1;
192  nu->orderu = 4;
193  nu->bp = (BPoint *)MEM_callocN(sizeof(BPoint) * nu->pntsu, "addNurbprim3");
194 
195  bp = nu->bp;
196  for (a = 0; a < 4; a++, bp++) {
197  bp->vec[3] = 1.0;
198  bp->f1 = SELECT;
199  bp->radius = bp->weight = 1.0;
200  }
201 
202  bp = nu->bp;
203  bp->vec[0] += -1.5f * grid;
204  bp++;
205  bp->vec[0] += -grid;
206  bp->vec[1] += grid;
207  bp++;
208  bp->vec[0] += grid;
209  bp->vec[1] += grid;
210  bp++;
211  bp->vec[0] += 1.5f * grid;
212 
213  bp = nu->bp;
214  for (a = 0; a < 4; a++, bp++) {
215  mul_m4_v3(mat, bp->vec);
216  }
217 
218  if (cutype == CU_NURBS) {
219  nu->knotsu = NULL; /* nurbs_knot_calc_u allocates */
221  }
222  }
223  break;
224  case CU_PRIM_PATH: /* 5 point path */
225  nu->pntsu = 5;
226  nu->pntsv = 1;
227  nu->orderu = 5;
228  nu->flagu = CU_NURB_ENDPOINT; /* endpoint */
229  nu->resolu = cu->resolu;
230  nu->bp = (BPoint *)MEM_callocN(sizeof(BPoint) * nu->pntsu, "addNurbprim3");
231 
232  bp = nu->bp;
233  for (a = 0; a < 5; a++, bp++) {
234  bp->vec[3] = 1.0;
235  bp->f1 = SELECT;
236  bp->radius = bp->weight = 1.0;
237  }
238 
239  bp = nu->bp;
240  bp->vec[0] += -2.0f * grid;
241  bp++;
242  bp->vec[0] += -grid;
243  bp++;
244  bp++;
245  bp->vec[0] += grid;
246  bp++;
247  bp->vec[0] += 2.0f * grid;
248 
249  bp = nu->bp;
250  for (a = 0; a < 5; a++, bp++) {
251  mul_m4_v3(mat, bp->vec);
252  }
253 
254  if (cutype == CU_NURBS) {
255  nu->knotsu = NULL; /* nurbs_knot_calc_u allocates */
257  }
258 
259  break;
260  case CU_PRIM_CIRCLE: /* circle */
261  nu->resolu = cu->resolu;
262 
263  if (cutype == CU_BEZIER) {
264  nu->pntsu = 4;
265  nu->bezt = (BezTriple *)MEM_callocN(sizeof(BezTriple) * nu->pntsu, "addNurbprim1");
266  nu->flagu = CU_NURB_CYCLIC;
267  bezt = nu->bezt;
268 
269  bezt->h1 = bezt->h2 = HD_AUTO;
270  bezt->f1 = bezt->f2 = bezt->f3 = SELECT;
271  bezt->vec[1][0] += -grid;
272  for (a = 0; a < 3; a++) {
273  mul_m4_v3(mat, bezt->vec[a]);
274  }
275  bezt->radius = bezt->weight = 1.0;
276 
277  bezt++;
278  bezt->h1 = bezt->h2 = HD_AUTO;
279  bezt->f1 = bezt->f2 = bezt->f3 = SELECT;
280  bezt->vec[1][1] += grid;
281  for (a = 0; a < 3; a++) {
282  mul_m4_v3(mat, bezt->vec[a]);
283  }
284  bezt->radius = bezt->weight = 1.0;
285 
286  bezt++;
287  bezt->h1 = bezt->h2 = HD_AUTO;
288  bezt->f1 = bezt->f2 = bezt->f3 = SELECT;
289  bezt->vec[1][0] += grid;
290  for (a = 0; a < 3; a++) {
291  mul_m4_v3(mat, bezt->vec[a]);
292  }
293  bezt->radius = bezt->weight = 1.0;
294 
295  bezt++;
296  bezt->h1 = bezt->h2 = HD_AUTO;
297  bezt->f1 = bezt->f2 = bezt->f3 = SELECT;
298  bezt->vec[1][1] += -grid;
299  for (a = 0; a < 3; a++) {
300  mul_m4_v3(mat, bezt->vec[a]);
301  }
302  bezt->radius = bezt->weight = 1.0;
303 
305  }
306  else if (cutype == CU_NURBS) { /* nurb */
307  nu->pntsu = 8;
308  nu->pntsv = 1;
309  nu->orderu = 4;
310  nu->bp = (BPoint *)MEM_callocN(sizeof(BPoint) * nu->pntsu, "addNurbprim6");
311  nu->flagu = CU_NURB_CYCLIC;
312  bp = nu->bp;
313 
314  for (a = 0; a < 8; a++) {
315  bp->f1 = SELECT;
316  if (xzproj == 0) {
317  bp->vec[0] += nurbcircle[a][0] * grid;
318  bp->vec[1] += nurbcircle[a][1] * grid;
319  }
320  else {
321  bp->vec[0] += 0.25f * nurbcircle[a][0] * grid - 0.75f * grid;
322  bp->vec[2] += 0.25f * nurbcircle[a][1] * grid;
323  }
324  if (a & 1) {
325  bp->vec[3] = 0.25 * M_SQRT2;
326  }
327  else {
328  bp->vec[3] = 1.0;
329  }
330  mul_m4_v3(mat, bp->vec);
331  bp->radius = bp->weight = 1.0;
332 
333  bp++;
334  }
335 
337  }
338  break;
339  case CU_PRIM_PATCH: /* 4x4 patch */
340  if (cutype == CU_NURBS) { /* nurb */
341 
342  nu->pntsu = 4;
343  nu->pntsv = 4;
344  nu->orderu = 4;
345  nu->orderv = 4;
346  nu->flag = CU_SMOOTH;
347  nu->bp = (BPoint *)MEM_callocN(sizeof(BPoint) * (4 * 4), "addNurbprim6");
348  nu->flagu = 0;
349  nu->flagv = 0;
350  bp = nu->bp;
351 
352  for (a = 0; a < 4; a++) {
353  for (b = 0; b < 4; b++) {
354  bp->f1 = SELECT;
355  fac = (float)a - 1.5f;
356  bp->vec[0] += fac * grid;
357  fac = (float)b - 1.5f;
358  bp->vec[1] += fac * grid;
359  if ((a == 1 || a == 2) && (b == 1 || b == 2)) {
360  bp->vec[2] += grid;
361  }
362  mul_m4_v3(mat, bp->vec);
363  bp->vec[3] = 1.0;
364  bp++;
365  }
366  }
367 
370  }
371  break;
372  case CU_PRIM_TUBE: /* Cylinder */
373  if (cutype == CU_NURBS) {
374  nu = ED_curve_add_nurbs_primitive(C, obedit, mat, CU_NURBS | CU_PRIM_CIRCLE, 0);
375  nu->resolu = cu->resolu;
376  nu->flag = CU_SMOOTH;
377  BLI_addtail(editnurb, nu); /* temporal for extrude and translate */
378  vec[0] = vec[1] = 0.0;
379  vec[2] = -grid;
380 
381  mul_mat3_m4_v3(mat, vec);
382 
383  ed_editnurb_translate_flag(editnurb, SELECT, vec, CU_IS_2D(cu));
384  ed_editnurb_extrude_flag(cu->editnurb, SELECT);
385  mul_v3_fl(vec, -2.0f);
386  ed_editnurb_translate_flag(editnurb, SELECT, vec, CU_IS_2D(cu));
387 
388  BLI_remlink(editnurb, nu);
389 
390  a = nu->pntsu * nu->pntsv;
391  bp = nu->bp;
392  while (a-- > 0) {
393  bp->f1 |= SELECT;
394  bp++;
395  }
396  }
397  break;
398  case CU_PRIM_SPHERE: /* sphere */
399  if (cutype == CU_NURBS) {
400  const float tmp_cent[3] = {0.0f, 0.0f, 0.0f};
401  const float tmp_vec[3] = {0.0f, 0.0f, 1.0f};
402 
403  nu->pntsu = 5;
404  nu->pntsv = 1;
405  nu->orderu = 3;
406  nu->resolu = cu->resolu;
407  nu->resolv = cu->resolv;
408  nu->flag = CU_SMOOTH;
409  nu->bp = (BPoint *)MEM_callocN(sizeof(BPoint) * nu->pntsu, "addNurbprim6");
410  nu->flagu = 0;
411  bp = nu->bp;
412 
413  for (a = 0; a < 5; a++) {
414  bp->f1 = SELECT;
415  bp->vec[0] += nurbcircle[a][0] * grid;
416  bp->vec[2] += nurbcircle[a][1] * grid;
417  if (a & 1) {
418  bp->vec[3] = 0.5 * M_SQRT2;
419  }
420  else {
421  bp->vec[3] = 1.0;
422  }
423  mul_m4_v3(mat, bp->vec);
424  bp++;
425  }
426  nu->flagu = CU_NURB_BEZIER;
428 
429  BLI_addtail(editnurb, nu); /* temporal for spin */
430 
431  if (newob && (U.flag & USER_ADD_VIEWALIGNED) == 0) {
432  ed_editnurb_spin(umat, NULL, obedit, tmp_vec, tmp_cent);
433  }
434  else if ((U.flag & USER_ADD_VIEWALIGNED)) {
435  ed_editnurb_spin(viewmat, NULL, obedit, zvec, mat[3]);
436  }
437  else {
438  ed_editnurb_spin(umat, NULL, obedit, tmp_vec, mat[3]);
439  }
440 
442 
443  a = nu->pntsu * nu->pntsv;
444  bp = nu->bp;
445  while (a-- > 0) {
446  bp->f1 |= SELECT;
447  bp++;
448  }
449  BLI_remlink(editnurb, nu);
450  }
451  break;
452  case CU_PRIM_DONUT: /* torus */
453  if (cutype == CU_NURBS) {
454  const float tmp_cent[3] = {0.0f, 0.0f, 0.0f};
455  const float tmp_vec[3] = {0.0f, 0.0f, 1.0f};
456 
457  xzproj = 1;
458  nu = ED_curve_add_nurbs_primitive(C, obedit, mat, CU_NURBS | CU_PRIM_CIRCLE, 0);
459  xzproj = 0;
460  nu->resolu = cu->resolu;
461  nu->resolv = cu->resolv;
462  nu->flag = CU_SMOOTH;
463  BLI_addtail(editnurb, nu); /* temporal for spin */
464 
465  /* same as above */
466  if (newob && (U.flag & USER_ADD_VIEWALIGNED) == 0) {
467  ed_editnurb_spin(umat, NULL, obedit, tmp_vec, tmp_cent);
468  }
469  else if ((U.flag & USER_ADD_VIEWALIGNED)) {
470  ed_editnurb_spin(viewmat, NULL, obedit, zvec, mat[3]);
471  }
472  else {
473  ed_editnurb_spin(umat, NULL, obedit, tmp_vec, mat[3]);
474  }
475 
476  BLI_remlink(editnurb, nu);
477 
478  a = nu->pntsu * nu->pntsv;
479  bp = nu->bp;
480  while (a-- > 0) {
481  bp->f1 |= SELECT;
482  bp++;
483  }
484  }
485  break;
486 
487  default: /* should never happen */
488  BLI_assert(!"invalid nurbs type");
489  return NULL;
490  }
491 
492  BLI_assert(nu != NULL);
493 
494  if (nu) { /* should always be set */
495  nu->flag |= CU_SMOOTH;
496  cu->actnu = BLI_listbase_count(editnurb);
497  cu->actvert = CU_ACT_NONE;
498 
499  if (CU_IS_2D(cu)) {
501  }
502  }
503 
504  return nu;
505 }
506 
507 static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf)
508 {
509  struct Main *bmain = CTX_data_main(C);
511  ViewLayer *view_layer = CTX_data_view_layer(C);
512  Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
513  ListBase *editnurb;
514  Nurb *nu;
515  bool newob = false;
516  bool enter_editmode;
517  ushort local_view_bits;
518  float dia;
519  float loc[3], rot[3];
520  float mat[4][4];
521 
523 
525  C, op, 'Z', loc, rot, NULL, &enter_editmode, &local_view_bits, NULL)) {
526  return OPERATOR_CANCELLED;
527  }
528 
529  if (!isSurf) { /* adding curve */
530  if (obedit == NULL || obedit->type != OB_CURVE) {
531  const char *name = get_curve_defname(type);
532  Curve *cu;
533 
534  obedit = ED_object_add_type(C, OB_CURVE, name, loc, rot, true, local_view_bits);
535  newob = true;
536 
537  cu = (Curve *)obedit->data;
538  cu->flag |= CU_DEFORM_FILL;
539 
540  if (type & CU_PRIM_PATH) {
541  cu->flag |= CU_PATH | CU_3D;
542  }
543  }
544  else {
546  }
547  }
548  else { /* adding surface */
549  if (obedit == NULL || obedit->type != OB_SURF) {
550  const char *name = get_surf_defname(type);
551  obedit = ED_object_add_type(C, OB_SURF, name, loc, rot, true, local_view_bits);
552  newob = true;
553  }
554  else {
556  }
557  }
558 
559  ED_object_new_primitive_matrix(C, obedit, loc, rot, mat);
560  dia = RNA_float_get(op->ptr, "radius");
561  mul_mat3_m4_fl(mat, dia);
562 
563  nu = ED_curve_add_nurbs_primitive(C, obedit, mat, type, newob);
564  editnurb = object_editcurve_get(obedit);
565  BLI_addtail(editnurb, nu);
566 
567  /* userdef */
568  if (newob && !enter_editmode) {
570  }
571 
573 
574  return OPERATOR_FINISHED;
575 }
576 
577 static int curve_prim_add(bContext *C, wmOperator *op, int type)
578 {
579  return curvesurf_prim_add(C, op, type, 0);
580 }
581 
582 static int surf_prim_add(bContext *C, wmOperator *op, int type)
583 {
584  return curvesurf_prim_add(C, op, type, 1);
585 }
586 
587 /* ******************** Curves ******************* */
588 
590 {
591  return curve_prim_add(C, op, CU_BEZIER | CU_PRIM_CURVE);
592 }
593 
595 {
596  /* identifiers */
597  ot->name = "Add Bezier";
598  ot->description = "Construct a Bezier Curve";
599  ot->idname = "CURVE_OT_primitive_bezier_curve_add";
600 
601  /* api callbacks */
604 
605  /* flags */
607 
610 }
611 
613 {
614  return curve_prim_add(C, op, CU_BEZIER | CU_PRIM_CIRCLE);
615 }
616 
618 {
619  /* identifiers */
620  ot->name = "Add Bezier Circle";
621  ot->description = "Construct a Bezier Circle";
622  ot->idname = "CURVE_OT_primitive_bezier_circle_add";
623 
624  /* api callbacks */
627 
628  /* flags */
630 
633 }
634 
636 {
637  return curve_prim_add(C, op, CU_NURBS | CU_PRIM_CURVE);
638 }
639 
641 {
642  /* identifiers */
643  ot->name = "Add Nurbs Curve";
644  ot->description = "Construct a Nurbs Curve";
645  ot->idname = "CURVE_OT_primitive_nurbs_curve_add";
646 
647  /* api callbacks */
650 
651  /* flags */
653 
656 }
657 
659 {
660  return curve_prim_add(C, op, CU_NURBS | CU_PRIM_CIRCLE);
661 }
662 
664 {
665  /* identifiers */
666  ot->name = "Add Nurbs Circle";
667  ot->description = "Construct a Nurbs Circle";
668  ot->idname = "CURVE_OT_primitive_nurbs_circle_add";
669 
670  /* api callbacks */
673 
674  /* flags */
676 
679 }
680 
682 {
683  return curve_prim_add(C, op, CU_NURBS | CU_PRIM_PATH);
684 }
685 
687 {
688  /* identifiers */
689  ot->name = "Add Path";
690  ot->description = "Construct a Path";
691  ot->idname = "CURVE_OT_primitive_nurbs_path_add";
692 
693  /* api callbacks */
696 
697  /* flags */
699 
702 }
703 
704 /* **************** NURBS surfaces ********************** */
706 {
707  return surf_prim_add(C, op, CU_PRIM_CURVE | CU_NURBS);
708 }
709 
711 {
712  /* identifiers */
713  ot->name = "Add Surface Curve";
714  ot->description = "Construct a Nurbs surface Curve";
715  ot->idname = "SURFACE_OT_primitive_nurbs_surface_curve_add";
716 
717  /* api callbacks */
720 
721  /* flags */
723 
726 }
727 
729 {
730  return surf_prim_add(C, op, CU_PRIM_CIRCLE | CU_NURBS);
731 }
732 
734 {
735  /* identifiers */
736  ot->name = "Add Surface Circle";
737  ot->description = "Construct a Nurbs surface Circle";
738  ot->idname = "SURFACE_OT_primitive_nurbs_surface_circle_add";
739 
740  /* api callbacks */
743 
744  /* flags */
746 
749 }
750 
752 {
753  return surf_prim_add(C, op, CU_PRIM_PATCH | CU_NURBS);
754 }
755 
757 {
758  /* identifiers */
759  ot->name = "Add Surface Patch";
760  ot->description = "Construct a Nurbs surface Patch";
761  ot->idname = "SURFACE_OT_primitive_nurbs_surface_surface_add";
762 
763  /* api callbacks */
766 
767  /* flags */
769 
772 }
773 
775 {
776  return surf_prim_add(C, op, CU_PRIM_TUBE | CU_NURBS);
777 }
778 
780 {
781  /* identifiers */
782  ot->name = "Add Surface Cylinder";
783  ot->description = "Construct a Nurbs surface Cylinder";
784  ot->idname = "SURFACE_OT_primitive_nurbs_surface_cylinder_add";
785 
786  /* api callbacks */
789 
790  /* flags */
792 
795 }
796 
798 {
799  return surf_prim_add(C, op, CU_PRIM_SPHERE | CU_NURBS);
800 }
801 
803 {
804  /* identifiers */
805  ot->name = "Add Surface Sphere";
806  ot->description = "Construct a Nurbs surface Sphere";
807  ot->idname = "SURFACE_OT_primitive_nurbs_surface_sphere_add";
808 
809  /* api callbacks */
812 
813  /* flags */
815 
818 }
819 
821 {
822  return surf_prim_add(C, op, CU_PRIM_DONUT | CU_NURBS);
823 }
824 
826 {
827  /* identifiers */
828  ot->name = "Add Surface Torus";
829  ot->description = "Construct a Nurbs surface Torus";
830  ot->idname = "SURFACE_OT_primitive_nurbs_surface_torus_add";
831 
832  /* api callbacks */
835 
836  /* flags */
838 
841 }
typedef float(TangentPoint)[2]
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1044
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
void BKE_nurb_handles_calc(struct Nurb *nu)
Definition: curve.c:4092
void BKE_nurb_knot_calc_v(struct Nurb *nu)
Definition: curve.c:1308
#define CU_IS_2D(cu)
Definition: BKE_curve.h:83
void BKE_nurb_project_2d(struct Nurb *nu)
Definition: curve.c:748
void BKE_nurb_knot_calc_u(struct Nurb *nu)
Definition: curve.c:1303
void BKE_nurbList_flag_set(ListBase *editnurb, uint8_t flag, bool set)
Definition: curve.c:4475
#define BLI_assert(a)
Definition: BLI_assert.h:58
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:133
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define M_SQRT2
Definition: BLI_math_base.h:47
void mul_mat3_m4_fl(float R[4][4], float f)
Definition: math_matrix.c:982
void unit_m4(float m[4][4])
Definition: rct.c:1140
void mul_mat3_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:794
void mul_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:732
void copy_m4_m4(float m1[4][4], const float m2[4][4])
Definition: math_matrix.c:95
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned short ushort
Definition: BLI_sys_types.h:84
#define ELEM(...)
#define BLT_I18NCONTEXT_ID_CURVE
#define CTX_DATA_(context, msgid)
void DEG_id_tag_update(struct ID *id, int flag)
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:611
@ CU_PRIM_SPHERE
@ CU_PRIM_CURVE
@ CU_BEZIER
@ CU_PRIMITIVE
@ CU_TYPE
@ CU_PRIM_DONUT
@ CU_PRIM_TUBE
@ CU_PRIM_CIRCLE
@ CU_NURBS
@ CU_PRIM_PATCH
@ CU_PRIM_PATH
@ CU_SMOOTH
#define CU_ACT_NONE
@ CU_NURB_CYCLIC
@ CU_NURB_ENDPOINT
@ CU_NURB_BEZIER
@ HD_AUTO
@ HD_ALIGN
@ CU_3D
@ CU_PATH
@ CU_DEFORM_FILL
Object is a sort of wrapper for general info.
@ OB_SURF
@ OB_CURVE
#define OBEDIT_FROM_VIEW_LAYER(view_layer)
@ USER_ADD_VIEWALIGNED
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
float ED_object_new_primitive_matrix(struct bContext *C, struct Object *obedit, const float loc[3], const float rot[3], float primmat[4][4])
Definition: object_add.c:334
@ EM_FREEDATA
Definition: ED_object.h:204
bool ED_object_editmode_exit_ex(struct Main *bmain, struct Scene *scene, struct Object *obedit, int flag)
Definition: object_edit.c:676
struct Object * ED_object_add_type(struct bContext *C, const int type, const char *name, const float loc[3], const float rot[3], const bool enter_editmode, const unsigned short local_view_bits) ATTR_NONNULL(1) ATTR_RETURNS_NONNULL
Definition: object_add.c:659
void ED_object_add_generic_props(struct wmOperatorType *ot, bool do_editmode)
Definition: object_add.c:397
bool ED_object_add_generic_get_opts(struct bContext *C, struct wmOperator *op, const char view_align_axis, float loc[3], float rot[3], float scale[3], bool *enter_editmode, unsigned short *local_view_bits, bool *is_view_aligned)
Definition: object_add.c:455
void ED_object_add_unit_props_radius(struct wmOperatorType *ot)
Definition: object_add.c:392
bool ED_operator_scene_editable(struct bContext *C)
Definition: screen_ops.c:192
struct RegionView3D * ED_view3d_context_rv3d(struct bContext *C)
Definition: space_view3d.c:89
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
#define C
Definition: RandGen.cpp:39
#define ND_DRAW
Definition: WM_types.h:362
@ OPTYPE_UNDO
Definition: WM_types.h:155
@ OPTYPE_REGISTER
Definition: WM_types.h:153
#define NC_OBJECT
Definition: WM_types.h:280
unsigned int U
Definition: btGjkEpa3.h:78
#define SELECT
bool ed_editnurb_extrude_flag(struct EditNurb *editnurb, const uint8_t flag)
Definition: editcurve.c:2005
bool ed_editnurb_spin(float viewmat[4][4], struct View3D *v3d, struct Object *obedit, const float axis[3], const float cent[3])
Definition: editcurve.c:4931
void ed_editnurb_translate_flag(struct ListBase *editnurb, uint8_t flag, const float vec[3], bool is_2d)
Definition: editcurve.c:1708
Scene scene
ListBase * object_editcurve_get(Object *ob)
Definition: editcurve.c:89
static int add_primitive_nurbs_surface_sphere_exec(bContext *C, wmOperator *op)
void CURVE_OT_primitive_nurbs_path_add(wmOperatorType *ot)
void SURFACE_OT_primitive_nurbs_surface_sphere_add(wmOperatorType *ot)
static int add_primitive_bezier_exec(bContext *C, wmOperator *op)
static int add_primitive_bezier_circle_exec(bContext *C, wmOperator *op)
static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf)
void CURVE_OT_primitive_bezier_curve_add(wmOperatorType *ot)
static int add_primitive_nurbs_circle_exec(bContext *C, wmOperator *op)
static int add_primitive_nurbs_curve_exec(bContext *C, wmOperator *op)
static int add_primitive_nurbs_surface_cylinder_exec(bContext *C, wmOperator *op)
void CURVE_OT_primitive_bezier_circle_add(wmOperatorType *ot)
void SURFACE_OT_primitive_nurbs_surface_torus_add(wmOperatorType *ot)
static int add_primitive_curve_path_exec(bContext *C, wmOperator *op)
void CURVE_OT_primitive_nurbs_circle_add(wmOperatorType *ot)
static int add_primitive_nurbs_surface_curve_exec(bContext *C, wmOperator *op)
void SURFACE_OT_primitive_nurbs_surface_surface_add(wmOperatorType *ot)
static const char * get_curve_defname(int type)
Definition: editcurve_add.c:65
void CURVE_OT_primitive_nurbs_curve_add(wmOperatorType *ot)
static int curve_prim_add(bContext *C, wmOperator *op, int type)
static const char * get_surf_defname(int type)
Definition: editcurve_add.c:95
void SURFACE_OT_primitive_nurbs_surface_cylinder_add(wmOperatorType *ot)
static int surf_prim_add(bContext *C, wmOperator *op, int type)
static int add_primitive_nurbs_surface_torus_exec(bContext *C, wmOperator *op)
static int add_primitive_nurbs_surface_surface_exec(bContext *C, wmOperator *op)
Nurb * ED_curve_add_nurbs_primitive(bContext *C, Object *obedit, float mat[4][4], int type, int newob)
void SURFACE_OT_primitive_nurbs_surface_curve_add(wmOperatorType *ot)
static const float nurbcircle[8][2]
Definition: editcurve_add.c:52
static int add_primitive_nurbs_surface_circle_exec(bContext *C, wmOperator *op)
void SURFACE_OT_primitive_nurbs_surface_circle_add(wmOperatorType *ot)
#define rot(x, k)
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
static unsigned a[3]
Definition: RandGen.cpp:92
float RNA_float_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6355
Definition: BKE_main.h:116
char name[1024]
Definition: BKE_main.h:118
void * data
const char * name
Definition: WM_types.h:721
const char * idname
Definition: WM_types.h:723
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:776
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
struct PointerRNA * ptr
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition: wm_files.c:3156
void WM_operator_view3d_unit_defaults(struct bContext *C, struct wmOperator *op)
Definition: wm_operators.c:915