Blender V4.5
curves_draw.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "DNA_curve_types.h"
6
7#include "BLI_math_matrix.h"
8#include "BLI_math_rotation.h"
9#include "BLI_math_vector.h"
10#include "BLI_mempool.h"
11
12#include "BLT_translation.hh"
13
14#include "BKE_attribute.hh"
15#include "BKE_context.hh"
16#include "BKE_curves.hh"
17#include "BKE_object_types.hh"
18#include "BKE_report.hh"
19#include "BKE_screen.hh"
20
21#include "DEG_depsgraph.hh"
22
23#include "WM_api.hh"
24
25#include "ED_curves.hh"
26#include "ED_screen.hh"
27#include "ED_space_api.hh"
28#include "ED_view3d.hh"
29
30#include "GPU_batch.hh"
31#include "GPU_batch_presets.hh"
32#include "GPU_immediate.hh"
33#include "GPU_immediate_util.hh"
34#include "GPU_matrix.hh"
35#include "GPU_state.hh"
36
37#include "UI_resources.hh"
38
39#include "RNA_access.hh"
40#include "RNA_define.hh"
41#include "RNA_enum_types.hh"
42#include "RNA_prototypes.hh"
43
44extern "C" {
45#include "curve_fit_nd.h"
46}
47
48namespace blender::ed::curves {
49
50/* Distance between input samples */
51#define STROKE_SAMPLE_DIST_MIN_PX 1
52#define STROKE_SAMPLE_DIST_MAX_PX 3
53
54/* Distance between start/end points to consider cyclic */
55#define STROKE_CYCLIC_DIST_PX 8
56
57/* -------------------------------------------------------------------- */
60
61struct StrokeElem {
62 float mval[2];
65
66 /* Surface normal, may be zeroed. */
67 float normal_world[3];
68 float normal_local[3];
69
70 float pressure;
71};
72
77
83
84 /* projecting 2D into 3D space */
85 struct {
86 /* use a plane or project to the surface */
88 float plane[4];
89
90 /* use 'rv3d->depths', note that this will become 'damaged' while drawing, but that's OK. */
92
93 /* offset projection by this value */
95 float offset[3]; /* world-space */
99
100 /* cursor sampling */
101 struct {
102 /* use substeps, needed for nicely interpolating depth */
105
106 struct {
107 float min, max, range;
109
110 struct {
111 float mval[2];
112 /* Used in case we can't calculate the depth. */
114
116
119
123
124 /* StrokeElem */
126
128};
129
130static float stroke_elem_radius_from_pressure(const CurveDrawData *cdd, const float pressure)
131{
132 return ((pressure * cdd->radius.range) + cdd->radius.min) * cdd->bevel_radius;
133}
134
135static float stroke_elem_radius(const CurveDrawData *cdd, const StrokeElem *selem)
136{
137 return stroke_elem_radius_from_pressure(cdd, selem->pressure);
138}
139
140static void stroke_elem_pressure_set(const CurveDrawData *cdd, StrokeElem *selem, float pressure)
141{
142 if ((cdd->project.surface_offset != 0.0f) && !cdd->project.use_surface_offset_absolute &&
143 !is_zero_v3(selem->normal_local))
144 {
145 const float adjust = stroke_elem_radius_from_pressure(cdd, pressure) -
147 madd_v3_v3fl(selem->location_local, selem->normal_local, adjust);
149 selem->location_world, cdd->vc.obedit->object_to_world().ptr(), selem->location_local);
150 }
151 selem->pressure = pressure;
152}
153
154static void stroke_elem_interp(StrokeElem *selem_out,
155 const StrokeElem *selem_a,
156 const StrokeElem *selem_b,
157 float t)
158{
159 interp_v2_v2v2(selem_out->mval, selem_a->mval, selem_b->mval, t);
160 interp_v3_v3v3(selem_out->location_world, selem_a->location_world, selem_b->location_world, t);
161 interp_v3_v3v3(selem_out->location_local, selem_a->location_local, selem_b->location_local, t);
162 selem_out->pressure = interpf(selem_a->pressure, selem_b->pressure, t);
163}
164
168static bool stroke_elem_project(const CurveDrawData *cdd,
169 const int mval_i[2],
170 const float mval_fl[2],
171 float surface_offset,
172 const float radius,
173 float r_location_world[3],
174 float r_normal_world[3])
175{
176 ARegion *region = cdd->vc.region;
177
178 bool is_location_world_set = false;
179
180 /* project to 'location_world' */
181 if (cdd->project.use_plane) {
182 /* get the view vector to 'location' */
183 if (ED_view3d_win_to_3d_on_plane(region, cdd->project.plane, mval_fl, true, r_location_world))
184 {
185 if (r_normal_world) {
186 zero_v3(r_normal_world);
187 }
188 is_location_world_set = true;
189 }
190 }
191 else {
192 const ViewDepths *depths = cdd->depths;
193 if (depths && (uint(mval_i[0]) < depths->w) && (uint(mval_i[1]) < depths->h)) {
194 float depth_fl = 1.0f;
195 ED_view3d_depth_read_cached(depths, mval_i, 0, &depth_fl);
196 const double depth = double(depth_fl);
197 if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
198 if (ED_view3d_depth_unproject_v3(region, mval_i, depth, r_location_world)) {
199 is_location_world_set = true;
200 if (r_normal_world) {
201 zero_v3(r_normal_world);
202 }
203
204 if (surface_offset != 0.0f) {
205 const float offset = cdd->project.use_surface_offset_absolute ? 1.0f : radius;
206 float normal[3];
207 if (ED_view3d_depth_read_cached_normal(region, depths, mval_i, normal)) {
208 madd_v3_v3fl(r_location_world, normal, offset * surface_offset);
209 if (r_normal_world) {
210 copy_v3_v3(r_normal_world, normal);
211 }
212 }
213 }
214 }
215 }
216 }
217 }
218
219 if (is_location_world_set) {
220 if (cdd->project.use_offset) {
221 add_v3_v3(r_location_world, cdd->project.offset);
222 }
223 }
224
225 return is_location_world_set;
226}
227
229 const int mval_i[2],
230 const float mval_fl[2],
231 const float surface_offset,
232 const float radius,
233 const float location_fallback_depth[3],
234 float r_location_world[3],
235 float r_location_local[3],
236 float r_normal_world[3],
237 float r_normal_local[3])
238{
239 bool is_depth_found = stroke_elem_project(
240 cdd, mval_i, mval_fl, surface_offset, radius, r_location_world, r_normal_world);
241 if (is_depth_found == false) {
243 cdd->vc.v3d, cdd->vc.region, location_fallback_depth, mval_fl, r_location_world);
244 zero_v3(r_normal_local);
245 }
246 mul_v3_m4v3(r_location_local, cdd->vc.obedit->world_to_object().ptr(), r_location_world);
247
248 if (!is_zero_v3(r_normal_world)) {
249 copy_v3_v3(r_normal_local, r_normal_world);
250 mul_transposed_mat3_m4_v3(cdd->vc.obedit->object_to_world().ptr(), r_normal_local);
251 normalize_v3(r_normal_local);
252 }
253 else {
254 zero_v3(r_normal_local);
255 }
256
257 return is_depth_found;
258}
259
264 const float location_fallback_depth[3],
265 StrokeElem *selem)
266{
267 const int mval_i[2] = {int(selem->mval[0]), int(selem->mval[1])};
268 const float radius = stroke_elem_radius(cdd, selem);
270 mval_i,
271 selem->mval,
273 radius,
274 location_fallback_depth,
275 selem->location_world,
276 selem->location_local,
277 selem->normal_world,
278 selem->normal_local);
279}
280
282
283/* -------------------------------------------------------------------- */
286
288{
289 PointerRNA itemptr;
290 RNA_collection_add(op->ptr, "stroke", &itemptr);
291
292 RNA_float_set_array(&itemptr, "mouse", selem->mval);
293 RNA_float_set_array(&itemptr, "location", selem->location_world);
294 RNA_float_set(&itemptr, "pressure", selem->pressure);
295}
296
298{
299 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
300
301 StrokeElem *selem = static_cast<StrokeElem *>(BLI_mempool_calloc(cdd->stroke_elem_pool));
302
303 RNA_float_get_array(itemptr, "mouse", selem->mval);
304 RNA_float_get_array(itemptr, "location", selem->location_world);
306 selem->location_local, cdd->vc.obedit->world_to_object().ptr(), selem->location_world);
307 selem->pressure = RNA_float_get(itemptr, "pressure");
308}
309
311{
312 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
313
314 BLI_mempool_iter iter;
315 const StrokeElem *selem;
316
318 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
319 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)))
320 {
322 }
323}
324
326{
327 RNA_BEGIN (op->ptr, itemptr, "stroke") {
329 }
330 RNA_END;
331}
332
334
335static void curve_draw_stroke_3d(const bContext * /*C*/, ARegion * /*region*/, void *arg)
336{
337 wmOperator *op = static_cast<wmOperator *>(arg);
338 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
339
340 const int stroke_len = BLI_mempool_len(cdd->stroke_elem_pool);
341
342 if (stroke_len == 0) {
343 return;
344 }
345
346 Object *obedit = cdd->vc.obedit;
347
348 /* Disabled: not representative in enough cases, and curves draw shape is not per object yet.
349 * In the future this could be enabled when the object's draw shape is "strand" or "3D". */
350 if (false && cdd->bevel_radius > 0.0f) {
351 BLI_mempool_iter iter;
352 const StrokeElem *selem;
353
354 const float location_zero[3] = {0};
355 const float *location_prev = location_zero;
356
357 float color[3];
359
360 gpu::Batch *sphere = GPU_batch_preset_sphere(0);
362 GPU_batch_uniform_3fv(sphere, "color", color);
363
364 /* scale to edit-mode space */
366 GPU_matrix_mul(obedit->object_to_world().ptr());
367
369 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
370 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)))
371 {
372 GPU_matrix_translate_3f(selem->location_local[0] - location_prev[0],
373 selem->location_local[1] - location_prev[1],
374 selem->location_local[2] - location_prev[2]);
375
376 const float radius = stroke_elem_radius(cdd, selem);
377
379 GPU_matrix_scale_1f(radius);
380 GPU_batch_draw(sphere);
382
383 location_prev = selem->location_local;
384 }
385
387 }
388
389 if (stroke_len > 1) {
390 float(*coord_array)[3] = static_cast<float(*)[3]>(
391 MEM_mallocN(sizeof(*coord_array) * stroke_len, __func__));
392
393 {
394 BLI_mempool_iter iter;
395 const StrokeElem *selem;
396 int i;
398 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)), i = 0; selem;
399 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)), i++)
400 {
401 copy_v3_v3(coord_array[i], selem->location_world);
402 }
403 }
404
405 {
409
412 GPU_line_smooth(true);
413 GPU_line_width(3.0f);
414
415 imm_cpack(0x0);
416 immBegin(GPU_PRIM_LINE_STRIP, stroke_len);
417 for (int i = 0; i < stroke_len; i++) {
418 immVertex3fv(pos, coord_array[i]);
419 }
420 immEnd();
421
422 GPU_line_width(1.0f);
423
424 imm_cpack(0xffffffff);
425 immBegin(GPU_PRIM_LINE_STRIP, stroke_len);
426 for (int i = 0; i < stroke_len; i++) {
427 immVertex3fv(pos, coord_array[i]);
428 }
429 immEnd();
430
431 /* Reset defaults */
434 GPU_line_smooth(false);
435
437 }
438
439 MEM_freeN(coord_array);
440 }
441}
442
443static void curve_draw_event_add(wmOperator *op, const wmEvent *event)
444{
445 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
446 Object *obedit = cdd->vc.obedit;
447
448 invert_m4_m4(obedit->runtime->world_to_object.ptr(), obedit->object_to_world().ptr());
449
450 StrokeElem *selem = static_cast<StrokeElem *>(BLI_mempool_calloc(cdd->stroke_elem_pool));
451
452 ARRAY_SET_ITEMS(selem->mval, event->mval[0], event->mval[1]);
453
454 /* handle pressure sensitivity (which is supplied by tablets or otherwise 1.0) */
455 selem->pressure = event->tablet.pressure;
456
457 bool is_depth_found = stroke_elem_project_fallback_elem(
458 cdd, cdd->prev.location_world_valid, selem);
459
460 if (is_depth_found) {
461 /* use the depth if a fallback wasn't used */
463 }
465
466 float len_sq = len_squared_v2v2(cdd->prev.mval, selem->mval);
467 copy_v2_v2(cdd->prev.mval, selem->mval);
468
469 if (cdd->sample.use_substeps && cdd->prev.selem) {
470 const StrokeElem selem_target = *selem;
471 StrokeElem *selem_new_last = selem;
472 if (len_sq >= square_f(STROKE_SAMPLE_DIST_MAX_PX)) {
473 int n = int(ceil(sqrt(double(len_sq)))) / STROKE_SAMPLE_DIST_MAX_PX;
474
475 for (int i = 1; i < n; i++) {
476 StrokeElem *selem_new = selem_new_last;
477 stroke_elem_interp(selem_new, cdd->prev.selem, &selem_target, float(i) / n);
478
479 const bool is_depth_found_substep = stroke_elem_project_fallback_elem(
480 cdd, cdd->prev.location_world_valid, selem_new);
481 if (is_depth_found == false) {
482 if (is_depth_found_substep) {
484 }
485 }
486
487 selem_new_last = static_cast<StrokeElem *>(BLI_mempool_calloc(cdd->stroke_elem_pool));
488 }
489 }
490 selem = selem_new_last;
491 *selem_new_last = selem_target;
492 }
493
494 cdd->prev.selem = selem;
495
497}
498
499static void curve_draw_event_add_first(wmOperator *op, const wmEvent *event)
500{
501 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
503
504 /* add first point */
505 curve_draw_event_add(op, event);
506
509 {
510 RegionView3D *rv3d = cdd->vc.rv3d;
511
512 cdd->project.use_depth = false;
513 cdd->project.use_plane = true;
514
515 float normal[3] = {0.0f};
516 if (ELEM(cps->surface_plane,
519 {
520 if (ED_view3d_depth_read_cached_normal(cdd->vc.region, cdd->depths, event->mval, normal)) {
522 float cross_a[3], cross_b[3];
523 cross_v3_v3v3(cross_a, rv3d->viewinv[2], normal);
524 cross_v3_v3v3(cross_b, normal, cross_a);
525 copy_v3_v3(normal, cross_b);
526 }
527 }
528 }
529
530 /* CURVE_PAINT_SURFACE_PLANE_VIEW or fallback */
531 if (is_zero_v3(normal)) {
532 copy_v3_v3(normal, rv3d->viewinv[2]);
533 }
534
535 normalize_v3_v3(cdd->project.plane, normal);
537
538 /* Special case for when we only have offset applied on the first-hit,
539 * the remaining stroke must be offset too. */
540 if (cdd->project.surface_offset != 0.0f) {
541 const float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])};
542
543 float location_no_offset[3];
544
545 if (stroke_elem_project(cdd, event->mval, mval_fl, 0.0f, 0.0f, location_no_offset, nullptr))
546 {
547 sub_v3_v3v3(cdd->project.offset, cdd->prev.location_world_valid, location_no_offset);
548 if (!is_zero_v3(cdd->project.offset)) {
549 cdd->project.use_offset = true;
550 }
551 }
552 }
553 /* end special case */
554 }
555
556 cdd->init_event_type = event->type;
558}
559
561{
562 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
563 if (cdd) {
564 if (cdd->draw_handle_view) {
567 }
568
569 if (cdd->stroke_elem_pool) {
571 }
572
573 if (cdd->depths) {
575 }
576 MEM_freeN(cdd);
577 op->customdata = nullptr;
578 }
579}
580
581static bool curve_draw_init(bContext *C, wmOperator *op, bool is_invoke)
582{
583 BLI_assert(op->customdata == nullptr);
584
586
588
589 if (is_invoke) {
591 if (ELEM(nullptr, cdd->vc.region, cdd->vc.rv3d, cdd->vc.v3d, cdd->vc.win, cdd->vc.scene)) {
592 MEM_freeN(cdd);
593 BKE_report(op->reports, RPT_ERROR, "Unable to access 3D viewport");
594 return false;
595 }
596 }
597 else {
598 cdd->vc.bmain = CTX_data_main(C);
599 cdd->vc.depsgraph = depsgraph;
600 cdd->vc.scene = CTX_data_scene(C);
603
604 /* Using an empty stroke complicates logic later,
605 * it's simplest to disallow early on (see: #94085). */
606 if (RNA_collection_is_empty(op->ptr, "stroke")) {
607 MEM_freeN(cdd);
608 BKE_report(op->reports, RPT_ERROR, "The \"stroke\" cannot be empty");
609 return false;
610 }
611 }
612
613 op->customdata = cdd;
614 cdd->bevel_radius = 1.0f;
615 cdd->is_curve_2d = RNA_boolean_get(op->ptr, "is_curve_2d");
616
618
619 cdd->curve_type = cps->curve_type;
620
621 cdd->radius.min = cps->radius_min;
622 cdd->radius.max = cps->radius_max;
623 cdd->radius.range = cps->radius_max - cps->radius_min;
627
629
630 return true;
631}
632
635 const CurveDrawData *cdd,
636 const int curve_index,
637 const bool is_cyclic,
638 const uint cubic_spline_len,
639 const int dims,
640 const int radius_index,
641 const float radius_max,
642 const float *cubic_spline,
643 const uint *corners_index,
644 const uint corners_index_len)
645{
646 curves.resize(curves.points_num() + cubic_spline_len, curve_index + 1);
647
648 MutableSpan<float3> positions = curves.positions_for_write();
649 MutableSpan<float3> handle_positions_l = curves.handle_positions_left_for_write();
650 MutableSpan<float3> handle_positions_r = curves.handle_positions_right_for_write();
651 MutableSpan<int8_t> handle_types_l = curves.handle_types_left_for_write();
652 MutableSpan<int8_t> handle_types_r = curves.handle_types_right_for_write();
653
654 const IndexRange new_points = curves.points_by_curve()[curve_index];
655
657 "radius", bke::AttrDomain::Point);
658
659 const float *co = cubic_spline;
660
661 for (const int64_t i : new_points) {
662 const float *handle_l = co + (dims * 0);
663 const float *pt = co + (dims * 1);
664 const float *handle_r = co + (dims * 2);
665
666 copy_v3_v3(handle_positions_l[i], handle_l);
667 copy_v3_v3(positions[i], pt);
668 copy_v3_v3(handle_positions_r[i], handle_r);
669
670 const float radius = (radius_index != -1) ?
671 (pt[radius_index] * cdd->radius.range) + cdd->radius.min :
672 radius_max;
673 radii.span[i] = radius;
674
675 handle_types_l[i] = BEZIER_HANDLE_ALIGN;
676 handle_types_r[i] = BEZIER_HANDLE_ALIGN;
677 co += (dims * 3);
678 }
679
680 if (corners_index) {
681 /* ignore the first and last */
682 uint i_start = 0, i_end = corners_index_len;
683
684 if ((corners_index_len >= 2) && !is_cyclic) {
685 i_start += 1;
686 i_end -= 1;
687 }
688
689 for (const auto i : IndexRange(i_start, i_end - i_start)) {
690 const int64_t corner_i = new_points[corners_index[i]];
691 handle_types_l[corner_i] = BEZIER_HANDLE_FREE;
692 handle_types_r[corner_i] = BEZIER_HANDLE_FREE;
693 }
694 }
695
696 radii.finish();
697}
698
701 const CurveDrawData *cdd,
702 const int curve_index,
703 const bool is_cyclic,
704 const uint cubic_spline_len,
705 const int dims,
706 const int radius_index,
707 const float radius_max,
708 const float *cubic_spline)
709{
710 const int point_num = (cubic_spline_len - 2) * 3 + 4 + (is_cyclic ? 2 : 0);
711 curves.resize(curves.points_num() + point_num, curve_index + 1);
712
713 MutableSpan<float3> positions = curves.positions_for_write();
714 MutableSpan<float> weights = curves.nurbs_weights_for_write();
715
716 const IndexRange new_points = curves.points_by_curve()[curve_index];
717
719 "radius", bke::AttrDomain::Point);
720 /* If cyclic shows to first left handle else first control point. */
721 const float *pt = cubic_spline + (is_cyclic ? 0 : dims);
722
723 for (const int64_t i : new_points) {
724 const float radius = (radius_index != -1) ?
725 (pt[radius_index] * cdd->radius.range) + cdd->radius.min :
726 radius_max;
727 copy_v3_v3(positions[i], pt);
728 weights[i] = 1.0f;
729 radii.span[i] = radius;
730
731 pt += dims;
732 }
733
734 radii.finish();
735}
736
738{
739 if (op->customdata == nullptr) {
740 if (!curve_draw_init(C, op, false)) {
741 return OPERATOR_CANCELLED;
742 }
743 }
744
745 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
746
748 Object *obedit = cdd->vc.obedit;
749
750 int stroke_len = BLI_mempool_len(cdd->stroke_elem_pool);
751
752 invert_m4_m4(obedit->runtime->world_to_object.ptr(), obedit->object_to_world().ptr());
753
754 if (BLI_mempool_len(cdd->stroke_elem_pool) == 0) {
756 stroke_len = BLI_mempool_len(cdd->stroke_elem_pool);
757 }
758
759 /* error in object local space */
760 const int fit_method = RNA_enum_get(op->ptr, "fit_method");
761 const float error_threshold = RNA_float_get(op->ptr, "error_threshold");
762 const float corner_angle = RNA_float_get(op->ptr, "corner_angle");
763 const bool use_cyclic = RNA_boolean_get(op->ptr, "use_cyclic");
764 const bool bezier_as_nurbs = RNA_boolean_get(op->ptr, "bezier_as_nurbs");
765 bool is_cyclic = (stroke_len > 2) && use_cyclic;
766
767 const float radius_min = cps->radius_min;
768 const float radius_max = cps->radius_max;
769 const float radius_range = cps->radius_max - cps->radius_min;
770
771 Curves *curves_id = static_cast<Curves *>(obedit->data);
772 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
773 const int curve_index = curves.curves_num();
774
775 const bool use_pressure_radius = (cps->flag & CURVE_PAINT_FLAG_PRESSURE_RADIUS) ||
776 ((cps->radius_taper_start != 0.0f) ||
777 (cps->radius_taper_end != 0.0f));
778
779 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
781 remove_selection_attributes(attributes, selection_attribute_names);
782
783 if (cdd->curve_type == CU_BEZIER) {
784 /* Allow to interpolate multiple channels */
785 int dims = 3;
786 const int radius_index = use_pressure_radius ? dims++ : -1;
787
788 float *coords = MEM_malloc_arrayN<float>(stroke_len * dims, __func__);
789
790 float *cubic_spline = nullptr;
791 uint cubic_spline_len = 0;
792
793 {
794 BLI_mempool_iter iter;
795 const StrokeElem *selem;
796 float *co = coords;
797
799 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
800 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)), co += dims)
801 {
802 copy_v3_v3(co, selem->location_local);
803 if (radius_index != -1) {
804 co[radius_index] = selem->pressure;
805 }
806
807 /* remove doubles */
808 if ((co != coords) && UNLIKELY(memcmp(co, co - dims, sizeof(float) * dims) == 0)) {
809 co -= dims;
810 stroke_len--;
811 }
812 }
813 }
814
815 uint *corners = nullptr;
816 uint corners_len = 0;
817
818 if ((fit_method == CURVE_PAINT_FIT_METHOD_SPLIT) && (corner_angle < float(M_PI))) {
819 /* this could be configurable... */
820 const float corner_radius_min = error_threshold / 8;
821 const float corner_radius_max = error_threshold * 2;
822 const uint samples_max = 16;
823
824 curve_fit_corners_detect_fl(coords,
825 stroke_len,
826 dims,
827 corner_radius_min,
828 corner_radius_max,
829 samples_max,
830 corner_angle,
831 &corners,
832 &corners_len);
833 }
834
835 uint *corners_index = nullptr;
836 uint corners_index_len = 0;
837 uint calc_flag = CURVE_FIT_CALC_HIGH_QUALIY;
838
839 if ((stroke_len > 2) && use_cyclic) {
840 calc_flag |= CURVE_FIT_CALC_CYCLIC;
841 }
842 else {
843 /* Might need this update if stroke_len <= 2 after removing doubles. */
844 is_cyclic = false;
845 }
846
847 int result;
848 if (fit_method == CURVE_PAINT_FIT_METHOD_REFIT) {
849 result = curve_fit_cubic_to_points_refit_fl(coords,
850 stroke_len,
851 dims,
852 error_threshold,
853 calc_flag,
854 nullptr,
855 0,
856 corner_angle,
857 &cubic_spline,
858 &cubic_spline_len,
859 nullptr,
860 &corners_index,
861 &corners_index_len);
862 }
863 else {
864 result = curve_fit_cubic_to_points_fl(coords,
865 stroke_len,
866 dims,
867 error_threshold,
868 calc_flag,
869 corners,
870 corners_len,
871 &cubic_spline,
872 &cubic_spline_len,
873 nullptr,
874 &corners_index,
875 &corners_index_len);
876 }
877
878 MEM_freeN(coords);
879 if (corners) {
880 free(corners);
881 }
882
883 if (result == 0) {
884 int8_t knots_mode;
885 int8_t order;
886 CurveType curve_type;
887 if (bezier_as_nurbs) {
888 bool is_cyclic_curve = calc_flag & CURVE_FIT_CALC_CYCLIC;
890 attributes,
891 cdd,
892 curve_index,
893 is_cyclic_curve,
894 cubic_spline_len,
895 dims,
896 radius_index,
897 radius_max,
898 cubic_spline);
899 order = 4;
900 knots_mode = is_cyclic_curve ? NURBS_KNOT_MODE_BEZIER : NURBS_KNOT_MODE_ENDPOINT_BEZIER;
901 curve_type = CURVE_TYPE_NURBS;
902 }
903 else {
905 attributes,
906 cdd,
907 curve_index,
908 is_cyclic,
909 cubic_spline_len,
910 dims,
911 radius_index,
912 radius_max,
913 cubic_spline,
914 corners_index,
915 corners_index_len);
916 order = 0;
917 knots_mode = 0;
918 curve_type = CURVE_TYPE_BEZIER;
919 }
920 curves.nurbs_knots_modes_for_write()[curve_index] = knots_mode;
921 curves.nurbs_orders_for_write()[curve_index] = order;
922 curves.fill_curve_types(IndexRange(curve_index, 1), curve_type);
923
924 /* If Bezier curve is being added, loop through all three names, otherwise through ones in
925 * `selection_attribute_names`. */
926 for (const StringRef selection_name :
927 (bezier_as_nurbs ? selection_attribute_names :
929 {
930 bke::AttributeWriter<bool> selection = attributes.lookup_or_add_for_write<bool>(
931 selection_name, bke::AttrDomain::Curve);
932 if (selection_name == ".selection" || !bezier_as_nurbs) {
933 selection.varray.set(curve_index, true);
934 }
935 selection.finish();
936 }
937
938 if (attributes.contains("resolution")) {
939 curves.resolution_for_write()[curve_index] = 12;
940 }
942 attributes,
945 "radius",
946 "handle_left",
947 "handle_right",
948 "handle_type_left",
949 "handle_type_right",
950 "nurbs_weight",
951 ".selection",
952 ".selection_handle_left",
953 ".selection_handle_right"}),
954 curves.points_by_curve()[curve_index]);
956 attributes,
959 "resolution",
960 "cyclic",
961 "nurbs_order",
962 "knots_mode",
963 ".selection",
964 ".selection_handle_left",
965 ".selection_handle_right"}),
966 IndexRange(curve_index, 1));
967 }
968
969 if (corners_index) {
970 free(corners_index);
971 }
972
973 if (cubic_spline) {
974 free(cubic_spline);
975 }
976 }
977 else { /* CU_POLY */
978 curves.resize(curves.points_num() + stroke_len, curve_index + 1);
979 curves.fill_curve_types(IndexRange(curve_index, 1), CURVE_TYPE_POLY);
980
981 MutableSpan<float3> positions = curves.positions_for_write();
983 "radius", bke::AttrDomain::Point);
984
985 const IndexRange new_points = curves.points_by_curve()[curve_index];
986
987 IndexRange::Iterator points_iter = new_points.begin();
988
989 BLI_mempool_iter iter;
991 for (const auto *selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
992 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)), points_iter++)
993 {
994 const int64_t i = *points_iter;
995 copy_v3_v3(positions[i], selem->location_local);
996 if (cdd->is_curve_2d) {
997 positions[i][2] = 0.0f;
998 }
999
1000 radii.span[i] = use_pressure_radius ? (selem->pressure * radius_range) + radius_min :
1001 cps->radius_max;
1002 }
1003
1004 radii.finish();
1005
1006 bke::AttributeWriter<bool> selection = attributes.lookup_or_add_for_write<bool>(
1007 ".selection", bke::AttrDomain::Curve);
1008 selection.varray.set(curve_index, true);
1009 selection.finish();
1010
1011 /* Creates ".selection_handle_left" and ".selection_handle_right" attributes, otherwise all
1012 * existing Bezier handles would be treated as selected. */
1013 for (const StringRef selection_name : get_curves_bezier_selection_attribute_names(curves)) {
1014 bke::AttributeWriter<bool> selection = attributes.lookup_or_add_for_write<bool>(
1015 selection_name, bke::AttrDomain::Curve);
1016 selection.finish();
1017 }
1018
1020 attributes,
1023 "radius",
1024 ".selection",
1025 ".selection_handle_left",
1026 ".selection_handle_right"}),
1027 new_points);
1029 attributes,
1032 {"curve_type", ".selection", ".selection_handle_left", ".selection_handle_right"}),
1033 IndexRange(curve_index, 1));
1034 }
1035
1036 if (is_cyclic) {
1037 curves.cyclic_for_write()[curve_index] = true;
1038 }
1039
1041 DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
1042
1043 curve_draw_exit(op);
1044
1045 return OPERATOR_FINISHED;
1046}
1047
1049{
1050 if (RNA_struct_property_is_set(op->ptr, "stroke")) {
1051 return curves_draw_exec(C, op);
1052 }
1053
1054 if (!curve_draw_init(C, op, true)) {
1055 return OPERATOR_CANCELLED;
1056 }
1057
1058 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
1059
1061
1062 const bool is_modal = RNA_boolean_get(op->ptr, "wait_for_input");
1063
1064 /* Fallback (in case we can't find the depth on first test). */
1065 {
1066 const float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])};
1067 float center[3];
1068 negate_v3_v3(center, cdd->vc.rv3d->ofs);
1069 ED_view3d_win_to_3d(cdd->vc.v3d, cdd->vc.region, center, mval_fl, cdd->prev.location_world);
1071 }
1072
1076
1077 {
1078 View3D *v3d = cdd->vc.v3d;
1079 RegionView3D *rv3d = cdd->vc.rv3d;
1080 Object *obedit = cdd->vc.obedit;
1081
1082 const float *plane_no = nullptr;
1083 const float *plane_co = nullptr;
1084
1085 if (cdd->is_curve_2d) {
1086 /* 2D overrides other options */
1087 plane_co = obedit->object_to_world().location();
1088 plane_no = obedit->object_to_world().ptr()[2];
1089 cdd->project.use_plane = true;
1090 }
1091 else {
1092 if ((cps->depth_mode == CURVE_PAINT_PROJECT_SURFACE) && (v3d->shading.type > OB_WIRE)) {
1093 /* needed or else the draw matrix can be incorrect */
1095
1098 depth_mode = V3D_DEPTH_SELECTED_ONLY;
1099 }
1100
1102 cdd->vc.region,
1103 cdd->vc.v3d,
1104 nullptr,
1105 depth_mode,
1106 false,
1107 &cdd->depths);
1108
1109 if (cdd->depths != nullptr) {
1110 cdd->project.use_depth = true;
1111 }
1112 else {
1113 BKE_report(op->reports, RPT_WARNING, "Unable to access depth buffer, using view plane");
1114 cdd->project.use_depth = false;
1115 }
1116 }
1117
1118 /* use view plane (when set or as a fallback when surface can't be found) */
1119 if (cdd->project.use_depth == false) {
1120 plane_co = cdd->vc.scene->cursor.location;
1121 plane_no = rv3d->viewinv[2];
1122 cdd->project.use_plane = true;
1123 }
1124
1125 if (cdd->project.use_depth && (cdd->curve_type != CU_POLY)) {
1126 cdd->sample.use_substeps = true;
1127 }
1128 }
1129
1130 if (cdd->project.use_plane) {
1131 normalize_v3_v3(cdd->project.plane, plane_no);
1132 cdd->project.plane[3] = -dot_v3v3(cdd->project.plane, plane_co);
1133 }
1134 }
1135
1136 if (is_modal == false) {
1137 curve_draw_event_add_first(op, event);
1138 }
1139
1140 /* add temp handler */
1142
1144}
1145
1146static void curve_draw_cancel(bContext * /*C*/, wmOperator *op)
1147{
1148 curve_draw_exit(op);
1149}
1150
1155{
1156 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
1158 PropertyRNA *prop;
1159
1160 prop = RNA_struct_find_property(op->ptr, "fit_method");
1161 if (!RNA_property_is_set(op->ptr, prop)) {
1162 RNA_property_enum_set(op->ptr, prop, cps->fit_method);
1163 }
1164
1165 prop = RNA_struct_find_property(op->ptr, "corner_angle");
1166 if (!RNA_property_is_set(op->ptr, prop)) {
1167 const float corner_angle = (cps->flag & CURVE_PAINT_FLAG_CORNERS_DETECT) ? cps->corner_angle :
1168 float(M_PI);
1169 RNA_property_float_set(op->ptr, prop, corner_angle);
1170 }
1171
1172 prop = RNA_struct_find_property(op->ptr, "error_threshold");
1173 if (!RNA_property_is_set(op->ptr, prop)) {
1174
1175 /* Error isn't set so we'll have to calculate it from the pixel values. */
1176 BLI_mempool_iter iter;
1177 const StrokeElem *selem, *selem_prev;
1178
1179 float len_3d = 0.0f, len_2d = 0.0f;
1180 float scale_px; /* pixel to local space scale */
1181
1182 int i = 0;
1184 selem_prev = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter));
1185 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
1186 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)), i++)
1187 {
1188 len_3d += len_v3v3(selem->location_local, selem_prev->location_local);
1189 len_2d += len_v2v2(selem->mval, selem_prev->mval);
1190 selem_prev = selem;
1191 }
1192 scale_px = ((len_3d > 0.0f) && (len_2d > 0.0f)) ? (len_3d / len_2d) : 0.0f;
1193 float error_threshold = (cps->error_threshold * UI_SCALE_FAC) * scale_px;
1194 RNA_property_float_set(op->ptr, prop, error_threshold);
1195 }
1196
1197 prop = RNA_struct_find_property(op->ptr, "use_cyclic");
1198 if (!RNA_property_is_set(op->ptr, prop)) {
1199 bool use_cyclic = false;
1200
1201 if (BLI_mempool_len(cdd->stroke_elem_pool) > 2) {
1202 BLI_mempool_iter iter;
1203 const StrokeElem *selem, *selem_first, *selem_last;
1204
1206 selem_first = selem_last = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter));
1207 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
1208 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)))
1209 {
1210 selem_last = selem;
1211 }
1212
1213 if (len_squared_v2v2(selem_first->mval, selem_last->mval) <=
1215 {
1216 use_cyclic = true;
1217 }
1218 }
1219
1220 RNA_property_boolean_set(op->ptr, prop, use_cyclic);
1221 }
1222
1223 if ((cps->radius_taper_start != 0.0f) || (cps->radius_taper_end != 0.0f)) {
1224 /* NOTE: we could try to de-duplicate the length calculations above. */
1225 const int stroke_len = BLI_mempool_len(cdd->stroke_elem_pool);
1226
1227 BLI_mempool_iter iter;
1228 StrokeElem *selem, *selem_prev;
1229
1230 float *lengths = MEM_malloc_arrayN<float>(stroke_len, __func__);
1231 StrokeElem **selem_array = static_cast<StrokeElem **>(
1232 MEM_mallocN(sizeof(*selem_array) * stroke_len, __func__));
1233 lengths[0] = 0.0f;
1234
1235 float len_3d = 0.0f;
1236
1237 int i = 1;
1239 selem_prev = static_cast<StrokeElem *>(BLI_mempool_iterstep(&iter));
1240 selem_array[0] = selem_prev;
1241 for (selem = static_cast<StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
1242 selem = static_cast<StrokeElem *>(BLI_mempool_iterstep(&iter)), i++)
1243 {
1244 const float len_3d_segment = len_v3v3(selem->location_local, selem_prev->location_local);
1245 len_3d += len_3d_segment;
1246 lengths[i] = len_3d;
1247 selem_array[i] = selem;
1248 selem_prev = selem;
1249 }
1250
1251 if (cps->radius_taper_start != 0.0f) {
1252 const float len_taper_max = cps->radius_taper_start * len_3d;
1253 for (i = 0; i < stroke_len && lengths[i] < len_taper_max; i++) {
1254 const float pressure_new = selem_array[i]->pressure * (lengths[i] / len_taper_max);
1255 stroke_elem_pressure_set(cdd, selem_array[i], pressure_new);
1256 }
1257 }
1258
1259 if (cps->radius_taper_end != 0.0f) {
1260 const float len_taper_max = cps->radius_taper_end * len_3d;
1261 const float len_taper_min = len_3d - len_taper_max;
1262 for (i = stroke_len - 1; i > 0 && lengths[i] > len_taper_min; i--) {
1263 const float pressure_new = selem_array[i]->pressure *
1264 ((len_3d - lengths[i]) / len_taper_max);
1265 stroke_elem_pressure_set(cdd, selem_array[i], pressure_new);
1266 }
1267 }
1268
1269 MEM_freeN(lengths);
1270 MEM_freeN(selem_array);
1271 }
1272}
1273
1275{
1277 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
1278
1279 UNUSED_VARS(C, op);
1280
1281 if (event->type == cdd->init_event_type) {
1282 if (event->val == KM_RELEASE) {
1284
1286
1288
1289 curves_draw_exec(C, op);
1290
1291 return OPERATOR_FINISHED;
1292 }
1293 }
1294 else if (ELEM(event->type, EVT_ESCKEY, RIGHTMOUSE)) {
1296 curve_draw_cancel(C, op);
1297 return OPERATOR_CANCELLED;
1298 }
1299 else if (ELEM(event->type, LEFTMOUSE)) {
1300 if (event->val == KM_PRESS) {
1301 curve_draw_event_add_first(op, event);
1302 }
1303 }
1304 else if (ISMOUSE_MOTION(event->type)) {
1305 if (cdd->state == CURVE_DRAW_PAINTING) {
1306 const float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])};
1308 curve_draw_event_add(op, event);
1309 }
1310 }
1311 }
1312
1313 return ret;
1314}
1315
1317{
1318 ot->name = "Draw Curves";
1319 ot->idname = __func__;
1320 ot->description = "Draw a freehand curve";
1321
1322 ot->exec = curves_draw_exec;
1323 ot->invoke = curves_draw_invoke;
1324 ot->modal = curves_draw_modal;
1326
1327 /* flags */
1328 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1329
1330 /* properties */
1331 PropertyRNA *prop;
1332
1333 prop = RNA_def_float_distance(ot->srna,
1334 "error_threshold",
1335 0.0f,
1336 0.0f,
1337 10.0f,
1338 "Error",
1339 "Error distance threshold (in object units)",
1340 0.0001f,
1341 10.0f);
1343 RNA_def_property_ui_range(prop, 0.0, 10, 1, 4);
1344
1345 RNA_def_enum(ot->srna,
1346 "fit_method",
1349 "Fit Method",
1350 "");
1351
1353 ot->srna, "corner_angle", DEG2RADF(70.0f), 0.0f, M_PI, "Corner Angle", "", 0.0f, M_PI);
1355
1356 prop = RNA_def_boolean(ot->srna, "use_cyclic", true, "Cyclic", "");
1358
1359 prop = RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
1361
1362 prop = RNA_def_boolean(ot->srna, "wait_for_input", true, "Wait for Input", "");
1364
1365 prop = RNA_def_boolean(ot->srna, "is_curve_2d", false, "Curve 2D", "");
1367
1368 prop = RNA_def_boolean(ot->srna, "bezier_as_nurbs", false, "As NURBS", "");
1370}
1371
1372} // namespace blender::ed::curves
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
Object * CTX_data_edit_object(const bContext *C)
Main * CTX_data_main(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
Low-level operations for curves.
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:126
#define BLI_assert(a)
Definition BLI_assert.h:46
void BLI_kdtree_nd_ free(KDTree *tree)
MINLINE float square_f(float a)
MINLINE float interpf(float target, float origin, float t)
#define DEG2RADF(_deg)
#define M_PI
void mul_transposed_mat3_m4_v3(const float M[4][4], float r[3])
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
void interp_v2_v2v2(float r[2], const float a[2], const float b[2], float t)
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void negate_v3_v3(float r[3], const float a[3])
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void zero_v3(float r[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE float normalize_v3(float n[3])
void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter) ATTR_NONNULL()
void * BLI_mempool_iterstep(BLI_mempool_iter *iter) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
BLI_mempool * BLI_mempool_create(unsigned int esize, unsigned int elem_num, unsigned int pchunk, unsigned int flag) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
int BLI_mempool_len(const BLI_mempool *pool) ATTR_NONNULL(1)
void * BLI_mempool_calloc(BLI_mempool *pool) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1)
void BLI_mempool_destroy(BLI_mempool *pool) ATTR_NONNULL(1)
@ BLI_MEMPOOL_ALLOW_ITER
unsigned int uint
#define UNUSED_VARS(...)
#define ARRAY_SET_ITEMS(...)
#define UNLIKELY(x)
#define ELEM(...)
#define BLT_I18NCONTEXT_AMOUNT
void DEG_id_tag_update(ID *id, unsigned int flags)
@ CU_BEZIER
@ CU_POLY
CurveType
@ CURVE_TYPE_BEZIER
@ CURVE_TYPE_NURBS
@ CURVE_TYPE_POLY
@ BEZIER_HANDLE_FREE
@ BEZIER_HANDLE_ALIGN
@ NURBS_KNOT_MODE_BEZIER
@ NURBS_KNOT_MODE_ENDPOINT_BEZIER
@ OB_WIRE
@ CURVE_PAINT_PROJECT_SURFACE
@ CURVE_PAINT_SURFACE_PLANE_NORMAL_SURFACE
@ CURVE_PAINT_SURFACE_PLANE_NORMAL_VIEW
@ CURVE_PAINT_FIT_METHOD_REFIT
@ CURVE_PAINT_FIT_METHOD_SPLIT
@ CURVE_PAINT_FLAG_DEPTH_STROKE_ENDPOINTS
@ CURVE_PAINT_FLAG_DEPTH_STROKE_OFFSET_ABS
@ CURVE_PAINT_FLAG_CORNERS_DETECT
@ CURVE_PAINT_FLAG_PRESSURE_RADIUS
@ CURVE_PAINT_FLAG_DEPTH_ONLY_SELECTED
#define UI_SCALE_FAC
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ OPERATOR_RUNNING_MODAL
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:639
void * ED_region_draw_cb_activate(ARegionType *art, void(*draw)(const bContext *, ARegion *, void *), void *customdata, int type)
#define REGION_DRAW_POST_VIEW
bool ED_region_draw_cb_exit(ARegionType *art, void *handle)
bool ED_view3d_depth_read_cached(const ViewDepths *vd, const int mval[2], int margin, float *r_depth)
void ED_view3d_depth_override(Depsgraph *depsgraph, ARegion *region, View3D *v3d, Object *obact, eV3DDepthOverrideMode mode, bool use_overlay, ViewDepths **r_depths)
void ED_view3d_win_to_3d(const View3D *v3d, const ARegion *region, const float depth_pt[3], const float mval[2], float r_out[3])
ViewContext ED_view3d_viewcontext_init(bContext *C, Depsgraph *depsgraph)
bool ED_view3d_depth_read_cached_normal(const ARegion *region, const ViewDepths *depths, const int mval[2], float r_normal[3])
void ED_view3d_depths_free(ViewDepths *depths)
eV3DDepthOverrideMode
Definition ED_view3d.hh:188
@ V3D_DEPTH_ALL
Definition ED_view3d.hh:190
@ V3D_DEPTH_SELECTED_ONLY
Definition ED_view3d.hh:198
bool ED_view3d_win_to_3d_on_plane(const ARegion *region, const float plane[4], const float mval[2], bool do_clip, float r_out[3])
void view3d_operator_needs_gpu(const bContext *C)
bool ED_view3d_depth_unproject_v3(const ARegion *region, const int mval[2], double depth, float r_location_world[3])
#define GPU_batch_uniform_3fv(batch, name, val)
Definition GPU_batch.hh:308
void GPU_batch_program_set_builtin(blender::gpu::Batch *batch, eGPUBuiltinShader shader_id)
void GPU_batch_draw(blender::gpu::Batch *batch)
blender::gpu::Batch * GPU_batch_preset_sphere(int lod) ATTR_WARN_UNUSED_RESULT
void immEnd()
void immUnbindProgram()
void immBindBuiltinProgram(eGPUBuiltinShader shader_id)
GPUVertFormat * immVertexFormat()
void immVertex3fv(uint attr_id, const float data[3])
void immBegin(GPUPrimType, uint vertex_len)
void imm_cpack(uint x)
void GPU_matrix_push()
#define GPU_matrix_mul(x)
void GPU_matrix_scale_1f(float factor)
void GPU_matrix_translate_3f(float x, float y, float z)
void GPU_matrix_pop()
@ GPU_PRIM_LINE_STRIP
@ GPU_SHADER_3D_UNIFORM_COLOR
@ GPU_BLEND_NONE
Definition GPU_state.hh:85
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:87
void GPU_blend(eGPUBlend blend)
Definition gpu_state.cc:42
void GPU_line_width(float width)
Definition gpu_state.cc:166
void GPU_line_smooth(bool enable)
Definition gpu_state.cc:78
@ GPU_DEPTH_LESS_EQUAL
Definition GPU_state.hh:114
@ GPU_DEPTH_NONE
Definition GPU_state.hh:111
void GPU_depth_test(eGPUDepthTest test)
Definition gpu_state.cc:68
@ GPU_FETCH_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, blender::StringRef name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
#define RNA_BEGIN(sptr, itemptr, propname)
#define RNA_END
@ PROP_SKIP_SAVE
Definition RNA_types.hh:330
@ PROP_HIDDEN
Definition RNA_types.hh:324
@ PROP_ANGLE
Definition RNA_types.hh:240
#define C
Definition RandGen.cpp:29
void UI_GetThemeColor3fv(int colorid, float col[3])
@ TH_WIRE
#define NC_GEOM
Definition WM_types.hh:390
#define ND_DATA
Definition WM_types.hh:506
@ KM_PRESS
Definition WM_types.hh:308
@ KM_RELEASE
Definition WM_types.hh:309
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
BPy_StructRNA * depsgraph
long long int int64_t
bool contains(StringRef attribute_id) const
GAttributeWriter lookup_or_add_for_write(StringRef attribute_id, AttrDomain domain, eCustomDataType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
GSpanAttributeWriter lookup_or_add_for_write_only_span(StringRef attribute_id, AttrDomain domain, eCustomDataType data_type)
#define STROKE_CYCLIC_DIST_PX
#define STROKE_SAMPLE_DIST_MIN_PX
#define STROKE_SAMPLE_DIST_MAX_PX
static bool is_cyclic(const Nurb *nu)
uint pos
#define ceil
#define sqrt
format
void * MEM_mallocN(size_t len, const char *str)
Definition mallocn.cc:128
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:133
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
auto attribute_filter_from_skip_ref(const Span< StringRef > skip)
void fill_attribute_range_default(MutableAttributeAccessor dst_attributes, AttrDomain domain, const AttributeFilter &attribute_filter, IndexRange range)
static bool stroke_elem_project_fallback(const CurveDrawData *cdd, const int mval_i[2], const float mval_fl[2], const float surface_offset, const float radius, const float location_fallback_depth[3], float r_location_world[3], float r_location_local[3], float r_normal_world[3], float r_normal_local[3])
static void curve_draw_stroke_from_operator_elem(wmOperator *op, PointerRNA *itemptr)
void CURVES_OT_draw(wmOperatorType *ot)
static void create_Bezier(bke::CurvesGeometry &curves, bke::MutableAttributeAccessor &attributes, const CurveDrawData *cdd, const int curve_index, const bool is_cyclic, const uint cubic_spline_len, const int dims, const int radius_index, const float radius_max, const float *cubic_spline, const uint *corners_index, const uint corners_index_len)
void remove_selection_attributes(bke::MutableAttributeAccessor &attributes, Span< StringRef > selection_attribute_names)
static void create_NURBS(bke::CurvesGeometry &curves, bke::MutableAttributeAccessor &attributes, const CurveDrawData *cdd, const int curve_index, const bool is_cyclic, const uint cubic_spline_len, const int dims, const int radius_index, const float radius_max, const float *cubic_spline)
static bool stroke_elem_project(const CurveDrawData *cdd, const int mval_i[2], const float mval_fl[2], float surface_offset, const float radius, float r_location_world[3], float r_normal_world[3])
static wmOperatorStatus curves_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool curve_draw_init(bContext *C, wmOperator *op, bool is_invoke)
static void curve_draw_exit(wmOperator *op)
Span< StringRef > get_curves_bezier_selection_attribute_names(const bke::CurvesGeometry &curves)
bool editable_curves_in_edit_mode_poll(bContext *C)
static void curve_draw_stroke_from_operator(wmOperator *op)
static void curve_draw_stroke_to_operator(wmOperator *op)
static void curve_draw_event_add(wmOperator *op, const wmEvent *event)
static void curve_draw_cancel(bContext *, wmOperator *op)
Span< StringRef > get_curves_selection_attribute_names(const bke::CurvesGeometry &curves)
static void curve_draw_event_add_first(wmOperator *op, const wmEvent *event)
static float stroke_elem_radius(const CurveDrawData *cdd, const StrokeElem *selem)
static float stroke_elem_radius_from_pressure(const CurveDrawData *cdd, const float pressure)
static void stroke_elem_interp(StrokeElem *selem_out, const StrokeElem *selem_a, const StrokeElem *selem_b, float t)
static void curve_draw_stroke_3d(const bContext *, ARegion *, void *arg)
Span< StringRef > get_curves_all_selection_attribute_names()
static wmOperatorStatus curves_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus curves_draw_exec(bContext *C, wmOperator *op)
static void curve_draw_stroke_to_operator_elem(wmOperator *op, const StrokeElem *selem)
static bool stroke_elem_project_fallback_elem(const CurveDrawData *cdd, const float location_fallback_depth[3], StrokeElem *selem)
static void stroke_elem_pressure_set(const CurveDrawData *cdd, StrokeElem *selem, float pressure)
static void curve_draw_exec_precalc(wmOperator *op)
vector project(vector v, vector v_proj)
Definition node_math.h:59
return ret
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool RNA_collection_is_empty(PointerRNA *ptr, const char *name)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
void RNA_collection_add(PointerRNA *ptr, const char *name, PointerRNA *r_value)
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
float RNA_float_get(PointerRNA *ptr, const char *name)
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_float_distance(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)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_collection_runtime(StructOrFunctionRNA *cont_, const char *identifier, StructRNA *type, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
const EnumPropertyItem rna_enum_curve_fit_method_items[]
Definition rna_scene.cc:245
ARegionRuntimeHandle * runtime
CurvesGeometry geometry
Definition DNA_ID.h:404
ObjectRuntimeHandle * runtime
float viewinv[4][4]
struct ToolSettings * toolsettings
View3DCursor cursor
struct CurvePaintSettings curve_paint_settings
View3DShading shading
RegionView3D * rv3d
Definition ED_view3d.hh:80
ARegion * region
Definition ED_view3d.hh:77
Scene * scene
Definition ED_view3d.hh:73
Main * bmain
Definition ED_view3d.hh:67
wmWindow * win
Definition ED_view3d.hh:79
ViewLayer * view_layer
Definition ED_view3d.hh:74
View3D * v3d
Definition ED_view3d.hh:78
Object * obedit
Definition ED_view3d.hh:76
Depsgraph * depsgraph
Definition ED_view3d.hh:72
unsigned short w
Definition ED_view3d.hh:86
double depth_range[2]
Definition ED_view3d.hh:90
unsigned short h
Definition ED_view3d.hh:86
struct blender::ed::curves::CurveDrawData::@365265160006023152172257310217306010206137013173 prev
struct blender::ed::curves::CurveDrawData::@276072357045201012345345174065231345006163120323 radius
struct blender::ed::curves::CurveDrawData::@036040310350073216202326007002146267106306257306 sample
struct blender::ed::curves::CurveDrawData::@323351144070373022106163024031165221142052176357 project
wmEventType type
Definition WM_types.hh:754
short val
Definition WM_types.hh:756
int mval[2]
Definition WM_types.hh:760
struct ReportList * reports
struct PointerRNA * ptr
i
Definition text_draw.cc:230
void WM_cursor_modal_set(wmWindow *win, int val)
void WM_cursor_modal_restore(wmWindow *win)
@ WM_CURSOR_PAINT_BRUSH
Definition wm_cursors.hh:34
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
#define ISMOUSE_MOTION(event_type)
@ RIGHTMOUSE
@ LEFTMOUSE
@ EVT_ESCKEY
wmOperatorType * ot
Definition wm_files.cc:4226