Blender V5.3
editcurve_paint.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
8
9#include "DNA_object_types.h"
10#include "DNA_scene_types.h"
11
12#include "MEM_guardedalloc.h"
13
14#include "BLI_listbase.hh"
15#include "BLI_math_matrix_c.hh"
17#include "BLI_math_vector_c.hh"
18#include "BLI_mempool.hh"
19
20#include "BLT_translation.hh"
21
22#include "BKE_context.hh"
23#include "BKE_curve.hh"
24#include "BKE_fcurve.hh"
25#include "BKE_object_types.hh"
26#include "BKE_report.hh"
27#include "BKE_screen.hh"
28
29#include "DEG_depsgraph.hh"
30
31#include "WM_api.hh"
32#include "WM_types.hh"
33
34#include "ED_curve.hh"
35#include "ED_screen.hh"
36#include "ED_space_api.hh"
37#include "ED_view3d.hh"
38
39#include "GPU_batch.hh"
40#include "GPU_batch_presets.hh"
41#include "GPU_immediate.hh"
42#include "GPU_immediate_util.hh"
43#include "GPU_matrix.hh"
44#include "GPU_state.hh"
45
46#include "curve_intern.hh"
47
48#include "UI_resources.hh"
49
50#include "RNA_access.hh"
51#include "RNA_define.hh"
52#include "RNA_prototypes.hh"
53
54#include "RNA_enum_types.hh"
55
56namespace blender {
57
58#define USE_SPLINE_FIT
59
60#ifdef USE_SPLINE_FIT
61extern "C" {
62# include "curve_fit_nd.h"
63}
64#endif
65
66/* Distance between input samples */
67#define STROKE_SAMPLE_DIST_MIN_PX 1
68#define STROKE_SAMPLE_DIST_MAX_PX 3
69
70/* Distance between start/end points to consider cyclic */
71#define STROKE_CYCLIC_DIST_PX 8
72
73/* -------------------------------------------------------------------- */
76
77struct StrokeElem {
78 float mval[2];
81
82 /* Surface normal, may be zeroed. */
83 float normal_world[3];
84 float normal_local[3];
85
86 float pressure;
87};
88
93
97
98 /* projecting 2D into 3D space */
99 struct {
100 /* use a plane or project to the surface */
101 bool use_plane;
102 float plane[4];
103
104 /* use 'rv3d->depths', note that this will become 'damaged' while drawing, but that's OK. */
105 bool use_depth;
106
107 /* offset projection by this value */
108 bool use_offset;
109 float offset[3]; /* world-space */
110 float surface_offset;
113
114 /* cursor sampling */
115 struct {
116 /* use substeps, needed for nicely interpolating depth */
117 bool use_substeps;
119
120 struct {
121 float min, max, range;
123
124 struct {
125 float mval[2];
126 /* Used in case we can't calculate the depth. */
127 float location_world[3];
128
129 float location_world_valid[3];
130
131 const StrokeElem *selem;
133
137
138 /* StrokeElem */
140
142};
143
144static float stroke_elem_radius_from_pressure(const CurveDrawData *cdd, const float pressure)
145{
146 const Curve *cu = id_cast<const Curve *>(cdd->vc.obedit->data);
147 return ((pressure * cdd->radius.range) + cdd->radius.min) * cu->bevel_radius;
148}
149
150static float stroke_elem_radius(const CurveDrawData *cdd, const StrokeElem *selem)
151{
152 return stroke_elem_radius_from_pressure(cdd, selem->pressure);
153}
154
155static void stroke_elem_pressure_set(const CurveDrawData *cdd, StrokeElem *selem, float pressure)
156{
157 if ((cdd->project.surface_offset != 0.0f) && !cdd->project.use_surface_offset_absolute &&
158 !is_zero_v3(selem->normal_local))
159 {
160 const float adjust = stroke_elem_radius_from_pressure(cdd, pressure) -
162 madd_v3_v3fl(selem->location_local, selem->normal_local, adjust);
164 selem->location_world, cdd->vc.obedit->object_to_world().ptr(), selem->location_local);
165 }
166 selem->pressure = pressure;
167}
168
169static void stroke_elem_interp(StrokeElem *selem_out,
170 const StrokeElem *selem_a,
171 const StrokeElem *selem_b,
172 float t)
173{
174 interp_v2_v2v2(selem_out->mval, selem_a->mval, selem_b->mval, t);
175 interp_v3_v3v3(selem_out->location_world, selem_a->location_world, selem_b->location_world, t);
176 interp_v3_v3v3(selem_out->location_local, selem_a->location_local, selem_b->location_local, t);
177 selem_out->pressure = interpf(selem_a->pressure, selem_b->pressure, t);
178}
179
183static bool stroke_elem_project(const CurveDrawData *cdd,
184 const int mval_i[2],
185 const float mval_fl[2],
186 float surface_offset,
187 const float radius,
188 float r_location_world[3],
189 float r_normal_world[3])
190{
191 ARegion *region = cdd->vc.region;
192
193 bool is_location_world_set = false;
194
195 /* project to 'location_world' */
196 if (cdd->project.use_plane) {
197 /* get the view vector to 'location' */
198 if (ED_view3d_win_to_3d_on_plane(region, cdd->project.plane, mval_fl, true, r_location_world))
199 {
200 if (r_normal_world) {
201 zero_v3(r_normal_world);
202 }
203 is_location_world_set = true;
204 }
205 }
206 else {
207 const ViewDepths *depths = cdd->depths;
208 if (depths && (uint(mval_i[0]) < depths->w) && (uint(mval_i[1]) < depths->h)) {
209 float depth_fl = 1.0f;
210 ED_view3d_depth_read_cached(depths, mval_i, 0, &depth_fl);
211 const double depth = double(depth_fl);
212 if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
213 if (ED_view3d_depth_unproject_v3(region, mval_i, depth, r_location_world)) {
214 is_location_world_set = true;
215 if (r_normal_world) {
216 zero_v3(r_normal_world);
217 }
218
219 if (surface_offset != 0.0f) {
220 const float offset = cdd->project.use_surface_offset_absolute ? 1.0f : radius;
221 float normal[3];
222 if (ED_view3d_depth_read_cached_normal(region, depths, mval_i, normal)) {
223 madd_v3_v3fl(r_location_world, normal, offset * surface_offset);
224 if (r_normal_world) {
225 copy_v3_v3(r_normal_world, normal);
226 }
227 }
228 }
229 }
230 }
231 }
232 }
233
234 if (is_location_world_set) {
235 if (cdd->project.use_offset) {
236 add_v3_v3(r_location_world, cdd->project.offset);
237 }
238 }
239
240 return is_location_world_set;
241}
242
244 const int mval_i[2],
245 const float mval_fl[2],
246 const float surface_offset,
247 const float radius,
248 const float location_fallback_depth[3],
249 float r_location_world[3],
250 float r_location_local[3],
251 float r_normal_world[3],
252 float r_normal_local[3])
253{
254 bool is_depth_found = stroke_elem_project(
255 cdd, mval_i, mval_fl, surface_offset, radius, r_location_world, r_normal_world);
256 if (is_depth_found == false) {
258 cdd->vc.v3d, cdd->vc.region, location_fallback_depth, mval_fl, r_location_world);
259 zero_v3(r_normal_local);
260 }
261 mul_v3_m4v3(r_location_local, cdd->vc.obedit->world_to_object().ptr(), r_location_world);
262
263 if (!is_zero_v3(r_normal_world)) {
264 copy_v3_v3(r_normal_local, r_normal_world);
265 mul_transposed_mat3_m4_v3(cdd->vc.obedit->object_to_world().ptr(), r_normal_local);
266 normalize_v3(r_normal_local);
267 }
268 else {
269 zero_v3(r_normal_local);
270 }
271
272 return is_depth_found;
273}
274
279 const float location_fallback_depth[3],
280 StrokeElem *selem)
281{
282 const int mval_i[2] = {int(selem->mval[0]), int(selem->mval[1])};
283 const float radius = stroke_elem_radius(cdd, selem);
285 mval_i,
286 selem->mval,
287 cdd->project.surface_offset,
288 radius,
289 location_fallback_depth,
290 selem->location_world,
291 selem->location_local,
292 selem->normal_world,
293 selem->normal_local);
294}
295
297
298/* -------------------------------------------------------------------- */
301
303{
304 PointerRNA itemptr;
305 RNA_collection_add(op->ptr, "stroke", &itemptr);
306
307 RNA_float_set_array(&itemptr, "mouse", selem->mval);
308 RNA_float_set_array(&itemptr, "location", selem->location_world);
309 RNA_float_set(&itemptr, "pressure", selem->pressure);
310}
311
313{
314 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
315
316 StrokeElem *selem = static_cast<StrokeElem *>(BLI_mempool_calloc(cdd->stroke_elem_pool));
317
318 RNA_float_get_array(itemptr, "mouse", selem->mval);
319 RNA_float_get_array(itemptr, "location", selem->location_world);
321 selem->location_local, cdd->vc.obedit->world_to_object().ptr(), selem->location_world);
322 selem->pressure = RNA_float_get(itemptr, "pressure");
323}
324
326{
327 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
328
329 BLI_mempool_iter iter;
330 const StrokeElem *selem;
331
333 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
334 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)))
335 {
337 }
338}
339
341{
342 RNA_BEGIN (op->ptr, itemptr, "stroke") {
344 }
345 RNA_END;
346}
347
349
350/* -------------------------------------------------------------------- */
353
354static void curve_draw_stroke_3d(const bContext * /*C*/, ARegion * /*region*/, void *arg)
355{
356 wmOperator *op = static_cast<wmOperator *>(arg);
357 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
358
359 const int stroke_len = BLI_mempool_len(cdd->stroke_elem_pool);
360
361 if (stroke_len == 0) {
362 return;
363 }
364
365 Object *obedit = cdd->vc.obedit;
366 Curve *cu = id_cast<Curve *>(obedit->data);
367
368 if (cu->bevel_radius > 0.0f) {
369 BLI_mempool_iter iter;
370 const StrokeElem *selem;
371
372 const float location_zero[3] = {0};
373 const float *location_prev = location_zero;
374
375 float color[3];
377
378 gpu::Batch *sphere = GPU_batch_preset_sphere(0);
380 GPU_batch_uniform_3fv(sphere, "color", color);
381
382 /* scale to edit-mode space */
384 GPU_matrix_mul(obedit->object_to_world().ptr());
385
387 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
388 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)))
389 {
390 GPU_matrix_translate_3f(selem->location_local[0] - location_prev[0],
391 selem->location_local[1] - location_prev[1],
392 selem->location_local[2] - location_prev[2]);
393
394 const float radius = stroke_elem_radius(cdd, selem);
395
397 GPU_matrix_scale_1f(radius);
398 GPU_batch_draw(sphere);
400
401 location_prev = selem->location_local;
402 }
403
405 }
406
407 if (stroke_len > 1) {
408 float (*coord_array)[3] = MEM_new_array_uninitialized<float[3]>(stroke_len, __func__);
409
410 {
411 BLI_mempool_iter iter;
412 const StrokeElem *selem;
413 int i;
415 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)), i = 0; selem;
416 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)), i++)
417 {
418 copy_v3_v3(coord_array[i], selem->location_world);
419 }
420 }
421
422 {
423 GPUVertFormat *format = immVertexFormat();
424 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
426
429 GPU_line_smooth(true);
430 GPU_line_width(3.0f);
431
432 imm_cpack(0x0);
433 immBegin(GPU_PRIM_LINE_STRIP, stroke_len);
434 for (int i = 0; i < stroke_len; i++) {
435 immVertex3fv(pos, coord_array[i]);
436 }
437 immEnd();
438
439 GPU_line_width(1.0f);
440
441 imm_cpack(0xffffffff);
442 immBegin(GPU_PRIM_LINE_STRIP, stroke_len);
443 for (int i = 0; i < stroke_len; i++) {
444 immVertex3fv(pos, coord_array[i]);
445 }
446 immEnd();
447
448 /* Reset defaults */
451 GPU_line_smooth(false);
452
454 }
455
456 MEM_delete(coord_array);
457 }
458}
459
460static void curve_draw_event_add(wmOperator *op, const wmEvent *event)
461{
462 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
463 Object *obedit = cdd->vc.obedit;
464
465 invert_m4_m4(obedit->runtime->world_to_object.ptr(), obedit->object_to_world().ptr());
466
467 StrokeElem *selem = static_cast<StrokeElem *>(BLI_mempool_calloc(cdd->stroke_elem_pool));
468
469 ARRAY_SET_ITEMS(selem->mval, event->mval[0], event->mval[1]);
470
471 /* handle pressure sensitivity (which is supplied by tablets or otherwise 1.0) */
472 selem->pressure = event->tablet.pressure;
473
474 bool is_depth_found = stroke_elem_project_fallback_elem(
475 cdd, cdd->prev.location_world_valid, selem);
476
477 if (is_depth_found) {
478 /* use the depth if a fallback wasn't used */
479 copy_v3_v3(cdd->prev.location_world_valid, selem->location_world);
480 }
481 copy_v3_v3(cdd->prev.location_world, selem->location_world);
482
483 float len_sq = len_squared_v2v2(cdd->prev.mval, selem->mval);
484 copy_v2_v2(cdd->prev.mval, selem->mval);
485
486 if (cdd->sample.use_substeps && cdd->prev.selem) {
487 const StrokeElem selem_target = *selem;
488 StrokeElem *selem_new_last = selem;
489 if (len_sq >= square_f(STROKE_SAMPLE_DIST_MAX_PX)) {
490 int n = int(ceil(sqrt(double(len_sq)))) / STROKE_SAMPLE_DIST_MAX_PX;
491
492 for (int i = 1; i < n; i++) {
493 StrokeElem *selem_new = selem_new_last;
494 stroke_elem_interp(selem_new, cdd->prev.selem, &selem_target, float(i) / n);
495
496 const bool is_depth_found_substep = stroke_elem_project_fallback_elem(
497 cdd, cdd->prev.location_world_valid, selem_new);
498 if (is_depth_found == false) {
499 if (is_depth_found_substep) {
500 copy_v3_v3(cdd->prev.location_world_valid, selem_new->location_world);
501 }
502 }
503
504 selem_new_last = static_cast<StrokeElem *>(BLI_mempool_calloc(cdd->stroke_elem_pool));
505 }
506 }
507 selem = selem_new_last;
508 *selem_new_last = selem_target;
509 }
510
511 cdd->prev.selem = selem;
512
514}
515
516static void curve_draw_event_add_first(wmOperator *op, const wmEvent *event)
517{
518 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
520
521 /* add first point */
522 curve_draw_event_add(op, event);
523
524 if ((cps->depth_mode == CURVE_PAINT_PROJECT_SURFACE) && cdd->project.use_depth &&
526 {
527 RegionView3D *rv3d = cdd->vc.rv3d;
528
529 cdd->project.use_depth = false;
530 cdd->project.use_plane = true;
531
532 float normal[3] = {0.0f};
533 if (ELEM(cps->surface_plane,
536 {
537 if (ED_view3d_depth_read_cached_normal(cdd->vc.region, cdd->depths, event->mval, normal)) {
539 float cross_a[3], cross_b[3];
540 cross_v3_v3v3(cross_a, rv3d->viewinv[2], normal);
541 cross_v3_v3v3(cross_b, normal, cross_a);
542 copy_v3_v3(normal, cross_b);
543 }
544 }
545 }
546
547 /* CURVE_PAINT_SURFACE_PLANE_VIEW or fallback */
548 if (is_zero_v3(normal)) {
549 copy_v3_v3(normal, rv3d->viewinv[2]);
550 }
551
552 normalize_v3_v3(cdd->project.plane, normal);
553 cdd->project.plane[3] = -dot_v3v3(cdd->project.plane, cdd->prev.location_world_valid);
554
555 /* Special case for when we only have offset applied on the first-hit,
556 * the remaining stroke must be offset too. */
557 if (cdd->project.surface_offset != 0.0f) {
558 const float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])};
559
560 float location_no_offset[3];
561
562 if (stroke_elem_project(cdd, event->mval, mval_fl, 0.0f, 0.0f, location_no_offset, nullptr))
563 {
564 sub_v3_v3v3(cdd->project.offset, cdd->prev.location_world_valid, location_no_offset);
565 if (!is_zero_v3(cdd->project.offset)) {
566 cdd->project.use_offset = true;
567 }
568 }
569 }
570 /* end special case */
571 }
572
573 cdd->init_event_type = event->type;
575}
576
577static bool curve_draw_init(bContext *C, wmOperator *op, bool is_invoke)
578{
579 BLI_assert(op->customdata == nullptr);
580
582 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
583
584 if (is_invoke) {
585 cdd->vc = ED_view3d_viewcontext_init(C, depsgraph);
586 if (ELEM(nullptr, cdd->vc.region, cdd->vc.rv3d, cdd->vc.v3d, cdd->vc.win, cdd->vc.scene)) {
587 MEM_delete(cdd);
588 BKE_report(op->reports, RPT_ERROR, "Unable to access 3D viewport");
589 return false;
590 }
591 }
592 else {
593 cdd->vc.bmain = CTX_data_main(C);
594 cdd->vc.depsgraph = depsgraph;
595 cdd->vc.scene = CTX_data_scene(C);
598
599 /* Using an empty stroke complicates logic later,
600 * it's simplest to disallow early on (see: #94085). */
601 if (RNA_collection_is_empty(op->ptr, "stroke")) {
602 MEM_delete(cdd);
603 BKE_report(op->reports, RPT_ERROR, "The \"stroke\" cannot be empty");
604 return false;
605 }
606 }
607
608 op->customdata = cdd;
609
611
612 cdd->curve_type = cps->curve_type;
613
614 cdd->radius.min = cps->radius_min;
615 cdd->radius.max = cps->radius_max;
616 cdd->radius.range = cps->radius_max - cps->radius_min;
617 cdd->project.surface_offset = cps->surface_offset;
618 cdd->project.use_surface_offset_absolute = (cps->flag &
620
622
623 return true;
624}
625
627{
628 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
629 if (cdd) {
630 if (cdd->draw_handle_view) {
633 }
634
635 if (cdd->stroke_elem_pool) {
637 }
638
639 if (cdd->depths) {
641 }
642 MEM_delete(cdd);
643 op->customdata = nullptr;
644 }
645}
646
651{
652 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
654 PropertyRNA *prop;
655
656 prop = RNA_struct_find_property(op->ptr, "fit_method");
657 if (!RNA_property_is_set(op->ptr, prop)) {
658 RNA_property_enum_set(op->ptr, prop, cps->fit_method);
659 }
660
661 prop = RNA_struct_find_property(op->ptr, "corner_angle");
662 if (!RNA_property_is_set(op->ptr, prop)) {
663 const float corner_angle = (cps->flag & CURVE_PAINT_FLAG_CORNERS_DETECT) ? cps->corner_angle :
664 float(M_PI);
665 RNA_property_float_set(op->ptr, prop, corner_angle);
666 }
667
668 prop = RNA_struct_find_property(op->ptr, "error_threshold");
669 if (!RNA_property_is_set(op->ptr, prop)) {
670
671 /* Error isn't set so we'll have to calculate it from the pixel values. */
672 BLI_mempool_iter iter;
673 const StrokeElem *selem, *selem_prev;
674
675 float len_3d = 0.0f, len_2d = 0.0f;
676 float scale_px; /* pixel to local space scale */
677
679 selem_prev = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter));
680 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
681 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)))
682 {
683 len_3d += len_v3v3(selem->location_local, selem_prev->location_local);
684 len_2d += len_v2v2(selem->mval, selem_prev->mval);
685 selem_prev = selem;
686 }
687 scale_px = ((len_3d > 0.0f) && (len_2d > 0.0f)) ? (len_3d / len_2d) : 0.0f;
688 float error_threshold = (cps->error_threshold * UI_SCALE_FAC) * scale_px;
689 RNA_property_float_set(op->ptr, prop, error_threshold);
690 }
691
692 prop = RNA_struct_find_property(op->ptr, "use_cyclic");
693 if (!RNA_property_is_set(op->ptr, prop)) {
694 bool use_cyclic = false;
695
696 if (BLI_mempool_len(cdd->stroke_elem_pool) > 2) {
697 BLI_mempool_iter iter;
698 const StrokeElem *selem, *selem_first, *selem_last;
699
701 selem_first = selem_last = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter));
702 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
703 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)))
704 {
705 selem_last = selem;
706 }
707
708 if (len_squared_v2v2(selem_first->mval, selem_last->mval) <=
710 {
711 use_cyclic = true;
712 }
713 }
714
715 RNA_property_boolean_set(op->ptr, prop, use_cyclic);
716 }
717
718 if ((cps->radius_taper_start != 0.0f) || (cps->radius_taper_end != 0.0f)) {
719 /* NOTE: we could try to de-duplicate the length calculations above. */
720 const int stroke_len = BLI_mempool_len(cdd->stroke_elem_pool);
721
722 BLI_mempool_iter iter;
723 StrokeElem *selem, *selem_prev;
724
725 float *lengths = MEM_new_array_uninitialized<float>(stroke_len, __func__);
726 StrokeElem **selem_array = MEM_new_array_uninitialized<StrokeElem *>(stroke_len, __func__);
727 lengths[0] = 0.0f;
728
729 float len_3d = 0.0f;
730
731 int i = 1;
733 selem_prev = static_cast<StrokeElem *>(BLI_mempool_iterstep(&iter));
734 selem_array[0] = selem_prev;
735 for (selem = static_cast<StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
736 selem = static_cast<StrokeElem *>(BLI_mempool_iterstep(&iter)), i++)
737 {
738 const float len_3d_segment = len_v3v3(selem->location_local, selem_prev->location_local);
739 len_3d += len_3d_segment;
740 lengths[i] = len_3d;
741 selem_array[i] = selem;
742 selem_prev = selem;
743 }
744
745 if (cps->radius_taper_start != 0.0f) {
746 const float len_taper_max = cps->radius_taper_start * len_3d;
747 for (i = 0; i < stroke_len && lengths[i] < len_taper_max; i++) {
748 const float pressure_new = selem_array[i]->pressure * (lengths[i] / len_taper_max);
749 stroke_elem_pressure_set(cdd, selem_array[i], pressure_new);
750 }
751 }
752
753 if (cps->radius_taper_end != 0.0f) {
754 const float len_taper_max = cps->radius_taper_end * len_3d;
755 const float len_taper_min = len_3d - len_taper_max;
756 for (i = stroke_len - 1; i > 0 && lengths[i] > len_taper_min; i--) {
757 const float pressure_new = selem_array[i]->pressure *
758 ((len_3d - lengths[i]) / len_taper_max);
759 stroke_elem_pressure_set(cdd, selem_array[i], pressure_new);
760 }
761 }
762
763 MEM_delete(lengths);
764 MEM_delete(selem_array);
765 }
766}
767
769{
770 if (op->customdata == nullptr) {
771 if (!curve_draw_init(C, op, false)) {
772 return OPERATOR_CANCELLED;
773 }
774 }
775
776 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
777
779 Object *obedit = cdd->vc.obedit;
780 Curve *cu = id_cast<Curve *>(obedit->data);
781 ListBaseT<Nurb> *nurblist = object_editcurve_get(obedit);
782
783 int stroke_len = BLI_mempool_len(cdd->stroke_elem_pool);
784
785 const bool is_3d = (cu->flag & CU_3D) != 0;
786 invert_m4_m4(obedit->runtime->world_to_object.ptr(), obedit->object_to_world().ptr());
787
788 if (BLI_mempool_len(cdd->stroke_elem_pool) == 0) {
790 stroke_len = BLI_mempool_len(cdd->stroke_elem_pool);
791 }
792
793 /* Deselect all existing curves. */
795
796 const float radius_min = cps->radius_min;
797 const float radius_max = cps->radius_max;
798 const float radius_range = cps->radius_max - cps->radius_min;
799
800 Nurb *nu = MEM_new<Nurb>(__func__);
801 nu->pntsv = 0;
802 nu->resolu = cu->resolu;
803 nu->resolv = cu->resolv;
804 nu->flag |= CU_SMOOTH;
805
806 const bool use_pressure_radius = (cps->flag & CURVE_PAINT_FLAG_PRESSURE_RADIUS) ||
807 ((cps->radius_taper_start != 0.0f) ||
808 (cps->radius_taper_end != 0.0f));
809
810 if (cdd->curve_type == CU_BEZIER) {
811 nu->type = CU_BEZIER;
812
813#ifdef USE_SPLINE_FIT
814
815 /* Allow to interpolate multiple channels */
816 int dims = 3;
817 struct {
818 int radius;
819 } coords_indices;
820 coords_indices.radius = use_pressure_radius ? dims++ : -1;
821
822 float *coords = MEM_new_array_uninitialized<float>(stroke_len * dims, __func__);
823
824 float *cubic_spline = nullptr;
825 uint cubic_spline_len = 0;
826
827 /* error in object local space */
828 const int fit_method = RNA_enum_get(op->ptr, "fit_method");
829 const float error_threshold = RNA_float_get(op->ptr, "error_threshold");
830 const float corner_angle = RNA_float_get(op->ptr, "corner_angle");
831 const bool use_cyclic = RNA_boolean_get(op->ptr, "use_cyclic");
832
833 {
834 BLI_mempool_iter iter;
835 const StrokeElem *selem;
836 float *co = coords;
837
839 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
840 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)), co += dims)
841 {
842 copy_v3_v3(co, selem->location_local);
843 if (coords_indices.radius != -1) {
844 co[coords_indices.radius] = selem->pressure;
845 }
846
847 /* remove doubles */
848 if ((co != coords) && UNLIKELY(memcmp(co, co - dims, sizeof(float) * dims) == 0)) {
849 co -= dims;
850 stroke_len--;
851 }
852 }
853 }
854
855 uint *corners = nullptr;
856 uint corners_len = 0;
857
858 if ((fit_method == CURVE_PAINT_FIT_METHOD_SPLIT) && (corner_angle < float(M_PI))) {
859 /* this could be configurable... */
860 const float corner_radius_min = error_threshold / 8;
861 const float corner_radius_max = error_threshold * 2;
862 const uint samples_max = 16;
863
864 curve_fit_corners_detect_fl(coords,
865 stroke_len,
866 dims,
867 corner_radius_min,
868 corner_radius_max,
869 samples_max,
870 corner_angle,
871 &corners,
872 &corners_len);
873 }
874
875 uint *corners_index = nullptr;
876 uint corners_index_len = 0;
877 uint calc_flag = CURVE_FIT_CALC_HIGH_QUALITY;
878
879 if ((stroke_len > 2) && use_cyclic) {
880 calc_flag |= CURVE_FIT_CALC_CYCLIC;
881 }
882
883 int result;
884 if (fit_method == CURVE_PAINT_FIT_METHOD_REFIT) {
885 result = curve_fit_cubic_to_points_refit_fl(coords,
886 stroke_len,
887 dims,
888 error_threshold,
889 calc_flag,
890 nullptr,
891 0,
892 corner_angle,
893 &cubic_spline,
894 &cubic_spline_len,
895 nullptr,
896 &corners_index,
897 &corners_index_len);
898 }
899 else {
900 result = curve_fit_cubic_to_points_fl(coords,
901 stroke_len,
902 dims,
903 error_threshold,
904 calc_flag,
905 corners,
906 corners_len,
907 &cubic_spline,
908 &cubic_spline_len,
909 nullptr,
910 &corners_index,
911 &corners_index_len);
912 }
913
914 MEM_delete(coords);
915 if (corners) {
916 free(corners);
917 }
918
919 if (result == 0) {
920 nu->pntsu = cubic_spline_len;
921 nu->bezt = MEM_new_array_zeroed<BezTriple>(nu->pntsu, __func__);
922
923 float *co = cubic_spline;
924 BezTriple *bezt = nu->bezt;
925 for (int j = 0; j < cubic_spline_len; j++, bezt++, co += (dims * 3)) {
926 const float *handle_l = co + (dims * 0);
927 const float *pt = co + (dims * 1);
928 const float *handle_r = co + (dims * 2);
929
930 copy_v3_v3(bezt->vec[0], handle_l);
931 copy_v3_v3(bezt->vec[1], pt);
932 copy_v3_v3(bezt->vec[2], handle_r);
933
934 if (coords_indices.radius != -1) {
935 bezt->radius = (pt[coords_indices.radius] * cdd->radius.range) + cdd->radius.min;
936 }
937 else {
938 bezt->radius = radius_max;
939 }
940
941 bezt->h1 = bezt->h2 = HD_ALIGN; /* will set to free in second pass */
942 bezt->f1 = bezt->f2 = bezt->f3 = BEZT_FLAG_SELECT;
943 }
944
945 if (corners_index) {
946 /* ignore the first and last */
947 uint i_start = 0, i_end = corners_index_len;
948
949 if ((corners_index_len >= 2) && (calc_flag & CURVE_FIT_CALC_CYCLIC) == 0) {
950 i_start += 1;
951 i_end -= 1;
952 }
953
954 for (uint i = i_start; i < i_end; i++) {
955 bezt = &nu->bezt[corners_index[i]];
956 bezt->h1 = bezt->h2 = HD_FREE;
957 }
958 }
959
960 if (calc_flag & CURVE_FIT_CALC_CYCLIC) {
961 nu->flagu |= CU_NURB_CYCLIC;
962 }
963 }
964
965 if (corners_index) {
966 free(corners_index);
967 }
968
969 if (cubic_spline) {
970 free(cubic_spline);
971 }
972
973#else
974 nu->pntsu = stroke_len;
975 nu->bezt = MEM_new_array_zeroed<BezTriple>(nu->pntsu, __func__);
976
977 BezTriple *bezt = nu->bezt;
978
979 {
980 BLI_mempool_iter iter;
981 const struct StrokeElem *selem;
982
984 for (selem = BLI_mempool_iterstep(&iter); selem; selem = BLI_mempool_iterstep(&iter)) {
985 copy_v3_v3(bezt->vec[1], selem->location_local);
986 if (!is_3d) {
987 bezt->vec[1][2] = 0.0f;
988 }
989
990 if (use_pressure_radius) {
991 bezt->radius = selem->pressure;
992 }
993 else {
994 bezt->radius = radius_max;
995 }
996
997 bezt->h1 = bezt->h2 = HD_AUTO;
998
999 bezt->f1 |= SELECT;
1000 bezt->f2 |= SELECT;
1001 bezt->f3 |= SELECT;
1002
1003 bezt++;
1004 }
1005 }
1006#endif
1007
1009 }
1010 else { /* CU_POLY */
1011 BLI_mempool_iter iter;
1012 const StrokeElem *selem;
1013
1014 nu->pntsu = stroke_len;
1015 nu->pntsv = 1;
1016 nu->type = CU_POLY;
1017 nu->bp = MEM_new_array_zeroed<BPoint>(nu->pntsu, __func__);
1018
1019 /* Misc settings. */
1020 nu->resolu = cu->resolu;
1021 nu->resolv = 1;
1022 nu->orderu = 4;
1023 nu->orderv = 1;
1024
1025 BPoint *bp = nu->bp;
1026
1028 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
1029 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)))
1030 {
1031 copy_v3_v3(bp->vec, selem->location_local);
1032 if (!is_3d) {
1033 bp->vec[2] = 0.0f;
1034 }
1035
1036 if (use_pressure_radius) {
1037 bp->radius = (selem->pressure * radius_range) + radius_min;
1038 }
1039 else {
1040 bp->radius = cps->radius_max;
1041 }
1042 bp->f1 = SELECT;
1043 bp->vec[3] = 1.0f;
1044
1045 bp++;
1046 }
1047
1049 }
1050
1051 BLI_addtail(nurblist, nu);
1052
1054 cu->actvert = nu->pntsu - 1;
1055
1057 DEG_id_tag_update(obedit->data, 0);
1058
1059 curve_draw_exit(op);
1060
1061 return OPERATOR_FINISHED;
1062}
1063
1065{
1066 if (RNA_struct_property_is_set(op->ptr, "stroke")) {
1067 return curve_draw_exec(C, op);
1068 }
1069
1070 if (!curve_draw_init(C, op, true)) {
1071 return OPERATOR_CANCELLED;
1072 }
1073
1074 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
1075
1077
1078 const bool is_modal = RNA_boolean_get(op->ptr, "wait_for_input");
1079
1080 /* Fallback (in case we can't find the depth on first test). */
1081 {
1082 const float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])};
1083 float center[3];
1084 negate_v3_v3(center, cdd->vc.rv3d->ofs);
1085 ED_view3d_win_to_3d(cdd->vc.v3d, cdd->vc.region, center, mval_fl, cdd->prev.location_world);
1086 copy_v3_v3(cdd->prev.location_world_valid, cdd->prev.location_world);
1087 }
1088
1092
1093 {
1094 View3D *v3d = cdd->vc.v3d;
1095 RegionView3D *rv3d = cdd->vc.rv3d;
1096 Object *obedit = cdd->vc.obedit;
1097 Curve *cu = id_cast<Curve *>(obedit->data);
1098
1099 const float *plane_no = nullptr;
1100 const float *plane_co = nullptr;
1101
1102 if (CU_IS_2D(cu)) {
1103 /* 2D overrides other options */
1104 plane_co = obedit->object_to_world().location();
1105 plane_no = obedit->object_to_world().ptr()[2];
1106 cdd->project.use_plane = true;
1107 }
1108 else {
1109 if ((cps->depth_mode == CURVE_PAINT_PROJECT_SURFACE) && (v3d->shading.type > OB_WIRE)) {
1110 /* needed or else the draw matrix can be incorrect */
1112
1115 depth_mode = V3D_DEPTH_SELECTED_ONLY;
1116 }
1117
1119 cdd->vc.region,
1120 cdd->vc.v3d,
1121 nullptr,
1122 depth_mode,
1123 false,
1124 &cdd->depths);
1125
1126 if (cdd->depths != nullptr) {
1127 cdd->project.use_depth = true;
1128 }
1129 else {
1130 BKE_report(op->reports, RPT_WARNING, "Unable to access depth buffer, using view plane");
1131 cdd->project.use_depth = false;
1132 }
1133 }
1134
1135 /* use view plane (when set or as a fallback when surface can't be found) */
1136 if (cdd->project.use_depth == false) {
1137 plane_co = cdd->vc.scene->cursor.location;
1138 plane_no = rv3d->viewinv[2];
1139 cdd->project.use_plane = true;
1140 }
1141
1142 if (cdd->project.use_depth && (cdd->curve_type != CU_POLY)) {
1143 cdd->sample.use_substeps = true;
1144 }
1145 }
1146
1147 if (cdd->project.use_plane) {
1148 normalize_v3_v3(cdd->project.plane, plane_no);
1149 cdd->project.plane[3] = -dot_v3v3(cdd->project.plane, plane_co);
1150 }
1151 }
1152
1153 if (is_modal == false) {
1154 curve_draw_event_add_first(op, event);
1155 }
1156
1157 /* add temp handler */
1159
1161}
1162
1163static void curve_draw_cancel(bContext * /*C*/, wmOperator *op)
1164{
1165 curve_draw_exit(op);
1166}
1167
1168/* Modal event handling of frame changing */
1170{
1172 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
1173
1174 UNUSED_VARS(C, op);
1175
1176 if (event->type == cdd->init_event_type) {
1177 if (event->val == KM_RELEASE) {
1179
1181
1183
1184 curve_draw_exec(C, op);
1185
1186 return OPERATOR_FINISHED;
1187 }
1188 }
1189 else if (ELEM(event->type, EVT_ESCKEY, RIGHTMOUSE)) {
1191 curve_draw_cancel(C, op);
1192 return OPERATOR_CANCELLED;
1193 }
1194 else if (ELEM(event->type, LEFTMOUSE)) {
1195 if (event->val == KM_PRESS) {
1196 curve_draw_event_add_first(op, event);
1197 }
1198 }
1199 else if (ISMOUSE_MOTION(event->type)) {
1200 if (cdd->state == CURVE_DRAW_PAINTING) {
1201 const float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])};
1202 if (len_squared_v2v2(mval_fl, cdd->prev.mval) > square_f(STROKE_SAMPLE_DIST_MIN_PX)) {
1203 curve_draw_event_add(op, event);
1204 }
1205 }
1206 }
1207
1208 return ret;
1209}
1210
1212{
1213 /* identifiers */
1214 ot->name = "Draw Curve";
1215 ot->idname = "CURVE_OT_draw";
1216 ot->description = "Draw a freehand spline";
1217
1218 /* API callbacks. */
1219 ot->exec = curve_draw_exec;
1222 ot->modal = curve_draw_modal;
1224
1225 /* flags */
1227
1228 /* properties */
1229 PropertyRNA *prop;
1230
1231 prop = RNA_def_float_distance(ot->srna,
1232 "error_threshold",
1233 0.0f,
1234 0.0f,
1235 10.0f,
1236 "Error",
1237 "Error distance threshold (in object units)",
1238 0.0001f,
1239 10.0f);
1241 RNA_def_property_ui_range(prop, 0.0, 10, 1, 4);
1242
1243 RNA_def_enum(ot->srna,
1244 "fit_method",
1247 "Fit Method",
1248 "");
1249
1251 ot->srna, "corner_angle", DEG2RADF(70.0f), 0.0f, M_PI, "Corner Angle", "", 0.0f, M_PI);
1253
1254 prop = RNA_def_boolean(ot->srna, "use_cyclic", true, "Cyclic", "");
1256
1257 prop = RNA_def_collection_runtime(ot->srna, "stroke", RNA_OperatorStrokeElement, "Stroke", "");
1259
1260 prop = RNA_def_boolean(ot->srna, "wait_for_input", true, "Wait for Input", "");
1262}
1263
1265
1266} // namespace blender
#define CU_IS_2D(cu)
Definition BKE_curve.hh:93
#define SELECT
Definition BKE_mask.hh:19
#define DEG2RADF(_deg)
#define M_PI
#define BLT_I18NCONTEXT_AMOUNT
Object is a sort of wrapper for general info.
#define UI_SCALE_FAC
#define REGION_DRAW_POST_VIEW
#define GPU_batch_uniform_3fv(batch, name, val)
Definition GPU_batch.hh:274
Read Blender memory allocation and freeing.
#define RNA_BEGIN(sptr, itemptr, propname)
#define RNA_END
#define C
Definition RandGen.cpp:29
#define NC_GEOM
Definition WM_types.hh:406
#define ND_DATA
Definition WM_types.hh:552
#define UNUSED_VARS(...)
#define ARRAY_SET_ITEMS(...)
#define UNLIKELY(x)
#define ELEM(...)
#define STROKE_CYCLIC_DIST_PX
#define STROKE_SAMPLE_DIST_MIN_PX
#define STROKE_SAMPLE_DIST_MAX_PX
#define ceil
void free(Subdiv *subdiv)
Definition subdiv.cc:192
void get_color_3fv(int colorid, float col[3])
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE void negate_v3_v3(float r[3], const float a[3])
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
int RNA_enum_get(PointerRNA *ptr, const char *name)
@ RPT_WARNING
Definition BKE_report.hh:40
void immEnd()
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void GPU_matrix_scale_1f(float factor)
ViewContext ED_view3d_viewcontext_init(bContext *C, Depsgraph *depsgraph)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void ED_view3d_depths_free(ViewDepths *depths)
static void stroke_elem_interp(StrokeElem *selem_out, const StrokeElem *selem_a, const StrokeElem *selem_b, float t)
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
static bool curve_draw_init(bContext *C, wmOperator *op, bool is_invoke)
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
MINLINE void copy_v2_v2(float r[2], const float a[2])
GPUVertFormat * immVertexFormat()
static void curve_draw_stroke_from_operator(wmOperator *op)
void WM_cursor_modal_set(wmWindow *win, int val)
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
bool ED_operator_editcurve(bContext *C)
void immBegin(GPUPrimType, uint vertex_len)
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 bool stroke_elem_project_fallback_elem(const CurveDrawData *cdd, const float location_fallback_depth[3], StrokeElem *selem)
void GPU_line_smooth(bool enable)
Definition gpu_state.cc:80
@ GPU_PRIM_LINE_STRIP
static wmOperatorStatus curve_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
void view3d_operator_needs_gpu(const bContext *C)
PropertyRNA * RNA_def_collection_runtime(StructOrFunctionRNA *cont, const char *identifier, StructRNA *type, const char *ui_name, const char *ui_description)
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 void curve_draw_stroke_to_operator_elem(wmOperator *op, const StrokeElem *selem)
bool ED_curve_deselect_all_multi(bContext *C)
const EnumPropertyItem rna_enum_curve_fit_method_items[]
Definition rna_scene.cc:257
static float stroke_elem_radius_from_pressure(const CurveDrawData *cdd, const float pressure)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
static void curve_draw_stroke_to_operator(wmOperator *op)
void immUnbindProgram()
static void stroke_elem_pressure_set(const CurveDrawData *cdd, StrokeElem *selem, float pressure)
ViewLayer * CTX_data_view_layer(const bContext *C)
void GPU_matrix_mul(const float m[4][4])
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
void GPU_line_width(float width)
Definition gpu_state.cc:151
void BKE_curve_nurb_active_set(Curve *cu, const Nurb *nu)
Definition curve.cc:5010
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
static void curve_draw_event_add_first(wmOperator *op, const wmEvent *event)
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
void CURVE_OT_draw(wmOperatorType *ot)
void BLI_mempool_destroy(BLI_mempool *pool) ATTR_NONNULL(1)
static void curve_draw_exit(wmOperator *op)
@ CURVE_PAINT_PROJECT_SURFACE
void * ED_region_draw_cb_activate(ARegionType *art, void(*draw)(const bContext *, ARegion *, void *), void *customdata, int type)
@ GPU_DEPTH_NONE
Definition GPU_state.hh:132
@ GPU_DEPTH_LESS_EQUAL
Definition GPU_state.hh:135
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
@ CURVE_PAINT_SURFACE_PLANE_NORMAL_SURFACE
@ CURVE_PAINT_SURFACE_PLANE_NORMAL_VIEW
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
void BKE_nurb_handles_calc(Nurb *nu)
Definition curve.cc:3992
bool ED_region_draw_cb_exit(ARegionType *art, void *handle)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
static void curve_draw_event_add(wmOperator *op, const wmEvent *event)
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])
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
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
static void curve_draw_exec_precalc(wmOperator *op)
Object * CTX_data_edit_object(const bContext *C)
void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
static void curve_draw_stroke_3d(const bContext *, ARegion *, void *arg)
void WM_cursor_modal_restore(wmWindow *win)
sqrt(x)+1/max(0
@ CURVE_PAINT_FIT_METHOD_REFIT
@ CURVE_PAINT_FIT_METHOD_SPLIT
void GPU_batch_draw(gpu::Batch *batch)
void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter) ATTR_NONNULL()
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
void * BLI_mempool_iterstep(BLI_mempool_iter *iter) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
static wmOperatorStatus curve_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
ListBaseT< Nurb > * object_editcurve_get(Object *ob)
Definition editcurve.cc:95
MINLINE void zero_v3(float r[3])
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
void GPU_batch_program_set_builtin(gpu::Batch *batch, GPUBuiltinShader shader_id)
MINLINE float normalize_v3_v3(float r[3], const float a[3])
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
MINLINE float normalize_v3(float n[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void immVertex3fv(uint attr_id, const float data[3])
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
static void curve_draw_cancel(bContext *, wmOperator *op)
@ WM_CURSOR_PAINT_BRUSH
Definition wm_cursors.hh:36
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
Main * CTX_data_main(const bContext *C)
static wmOperatorStatus curve_draw_exec(bContext *C, wmOperator *op)
void interp_v2_v2v2(float r[2], const float a[2], const float b[2], float t)
@ BLI_MEMPOOL_ALLOW_ITER
void ED_view3d_depth_override(Depsgraph *depsgraph, ARegion *region, View3D *v3d, Object *obact, eV3DDepthOverrideMode mode, bool use_overlay, ViewDepths **r_depths)
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
bool ED_view3d_depth_read_cached(const ViewDepths *vd, const int mval[2], int margin, float *r_depth)
void * BLI_mempool_calloc(BLI_mempool *pool) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1)
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
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)
MINLINE float square_f(float a)
eV3DDepthOverrideMode
Definition ED_view3d.hh:205
@ V3D_DEPTH_ALL
Definition ED_view3d.hh:207
@ V3D_DEPTH_SELECTED_ONLY
Definition ED_view3d.hh:215
bool ED_view3d_depth_read_cached_normal(const ARegion *region, const ViewDepths *depths, const int mval[2], float r_normal[3])
@ KM_RELEASE
Definition WM_types.hh:325
MINLINE float interpf(float target, float origin, float t)
static float stroke_elem_radius(const CurveDrawData *cdd, const StrokeElem *selem)
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
Scene * CTX_data_scene(const bContext *C)
gpu::Batch * GPU_batch_preset_sphere(int lod) ATTR_WARN_UNUSED_RESULT
bool RNA_collection_is_empty(PointerRNA *ptr, const char *name)
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
bool ED_view3d_depth_unproject_v3(const ARegion *region, const int mval[2], double depth, float r_location_world[3])
void GPU_matrix_translate_3f(float x, float y, float z)
@ CURVE_PAINT_FLAG_DEPTH_ONLY_SELECTED
@ CURVE_PAINT_FLAG_CORNERS_DETECT
@ CURVE_PAINT_FLAG_PRESSURE_RADIUS
@ CURVE_PAINT_FLAG_DEPTH_STROKE_ENDPOINTS
@ CURVE_PAINT_FLAG_DEPTH_STROKE_OFFSET_ABS
int BLI_mempool_len(const BLI_mempool *pool) ATTR_NONNULL(1)
void BKE_nurb_knot_calc_u(Nurb *nu)
Definition curve.cc:1214
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
static void curve_draw_stroke_from_operator_elem(wmOperator *op, PointerRNA *itemptr)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
void GPU_matrix_pop()
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])
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])
void RNA_collection_add(PointerRNA *ptr, const char *name, PointerRNA *r_value)
void GPU_depth_test(GPUDepthTest test)
Definition gpu_state.cc:70
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
float RNA_float_get(PointerRNA *ptr, const char *name)
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
void imm_cpack(uint x)
void GPU_matrix_push()
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void mul_transposed_mat3_m4_v3(const float M[4][4], float r[3])
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bke::ARegionRuntime * runtime
eBezTriple_Flag f2
eBezTriple_Handle h2
eBezTriple_Flag f3
eBezTriple_Flag f1
eBezTriple_Handle h1
struct blender::CurveDrawData::@156325255003027135357105342153325365161173160072 project
struct blender::CurveDrawData::@062375322331123247056003106277120211133242374153 sample
struct blender::CurveDrawData::@137145357117003102113331326375343242026266350061 radius
struct blender::CurveDrawData::@111115321263170113037071137311213323330021203231 prev
const c_style_mat & ptr() const
BezTriple * bezt
eNurbKnotFlag flagu
bke::ObjectRuntime * runtime
View3DCursor cursor
struct ToolSettings * toolsettings
struct CurvePaintSettings curve_paint_settings
View3DShading shading
ViewLayer * view_layer
Definition ED_view3d.hh:80
RegionView3D * rv3d
Definition ED_view3d.hh:86
Depsgraph * depsgraph
Definition ED_view3d.hh:78
unsigned short w
Definition ED_view3d.hh:92
unsigned short h
Definition ED_view3d.hh:92
double depth_range[2]
Definition ED_view3d.hh:96
struct ARegionType * type
wmEventType type
Definition WM_types.hh:817
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
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
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
struct ReportList * reports
#define ISMOUSE_MOTION(event_type)