Blender V4.5
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.h"
15#include "BLI_math_matrix.h"
16#include "BLI_math_rotation.h"
17#include "BLI_math_vector.h"
18#include "BLI_mempool.h"
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
56#define USE_SPLINE_FIT
57
58#ifdef USE_SPLINE_FIT
59extern "C" {
60# include "curve_fit_nd.h"
61}
62#endif
63
64/* Distance between input samples */
65#define STROKE_SAMPLE_DIST_MIN_PX 1
66#define STROKE_SAMPLE_DIST_MAX_PX 3
67
68/* Distance between start/end points to consider cyclic */
69#define STROKE_CYCLIC_DIST_PX 8
70
71/* -------------------------------------------------------------------- */
74
75struct StrokeElem {
76 float mval[2];
79
80 /* Surface normal, may be zeroed. */
81 float normal_world[3];
82 float normal_local[3];
83
84 float pressure;
85};
86
91
95
96 /* projecting 2D into 3D space */
97 struct {
98 /* use a plane or project to the surface */
100 float plane[4];
101
102 /* use 'rv3d->depths', note that this will become 'damaged' while drawing, but that's OK. */
104
105 /* offset projection by this value */
107 float offset[3]; /* world-space */
111
112 /* cursor sampling */
113 struct {
114 /* use substeps, needed for nicely interpolating depth */
117
118 struct {
119 float min, max, range;
121
122 struct {
123 float mval[2];
124 /* Used in case we can't calculate the depth. */
126
128
131
135
136 /* StrokeElem */
138
140};
141
142static float stroke_elem_radius_from_pressure(const CurveDrawData *cdd, const float pressure)
143{
144 const Curve *cu = static_cast<const Curve *>(cdd->vc.obedit->data);
145 return ((pressure * cdd->radius.range) + cdd->radius.min) * cu->bevel_radius;
146}
147
148static float stroke_elem_radius(const CurveDrawData *cdd, const StrokeElem *selem)
149{
150 return stroke_elem_radius_from_pressure(cdd, selem->pressure);
151}
152
153static void stroke_elem_pressure_set(const CurveDrawData *cdd, StrokeElem *selem, float pressure)
154{
155 if ((cdd->project.surface_offset != 0.0f) && !cdd->project.use_surface_offset_absolute &&
156 !is_zero_v3(selem->normal_local))
157 {
158 const float adjust = stroke_elem_radius_from_pressure(cdd, pressure) -
160 madd_v3_v3fl(selem->location_local, selem->normal_local, adjust);
162 selem->location_world, cdd->vc.obedit->object_to_world().ptr(), selem->location_local);
163 }
164 selem->pressure = pressure;
165}
166
167static void stroke_elem_interp(StrokeElem *selem_out,
168 const StrokeElem *selem_a,
169 const StrokeElem *selem_b,
170 float t)
171{
172 interp_v2_v2v2(selem_out->mval, selem_a->mval, selem_b->mval, t);
173 interp_v3_v3v3(selem_out->location_world, selem_a->location_world, selem_b->location_world, t);
174 interp_v3_v3v3(selem_out->location_local, selem_a->location_local, selem_b->location_local, t);
175 selem_out->pressure = interpf(selem_a->pressure, selem_b->pressure, t);
176}
177
181static bool stroke_elem_project(const CurveDrawData *cdd,
182 const int mval_i[2],
183 const float mval_fl[2],
184 float surface_offset,
185 const float radius,
186 float r_location_world[3],
187 float r_normal_world[3])
188{
189 ARegion *region = cdd->vc.region;
190
191 bool is_location_world_set = false;
192
193 /* project to 'location_world' */
194 if (cdd->project.use_plane) {
195 /* get the view vector to 'location' */
196 if (ED_view3d_win_to_3d_on_plane(region, cdd->project.plane, mval_fl, true, r_location_world))
197 {
198 if (r_normal_world) {
199 zero_v3(r_normal_world);
200 }
201 is_location_world_set = true;
202 }
203 }
204 else {
205 const ViewDepths *depths = cdd->depths;
206 if (depths && (uint(mval_i[0]) < depths->w) && (uint(mval_i[1]) < depths->h)) {
207 float depth_fl = 1.0f;
208 ED_view3d_depth_read_cached(depths, mval_i, 0, &depth_fl);
209 const double depth = double(depth_fl);
210 if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
211 if (ED_view3d_depth_unproject_v3(region, mval_i, depth, r_location_world)) {
212 is_location_world_set = true;
213 if (r_normal_world) {
214 zero_v3(r_normal_world);
215 }
216
217 if (surface_offset != 0.0f) {
218 const float offset = cdd->project.use_surface_offset_absolute ? 1.0f : radius;
219 float normal[3];
220 if (ED_view3d_depth_read_cached_normal(region, depths, mval_i, normal)) {
221 madd_v3_v3fl(r_location_world, normal, offset * surface_offset);
222 if (r_normal_world) {
223 copy_v3_v3(r_normal_world, normal);
224 }
225 }
226 }
227 }
228 }
229 }
230 }
231
232 if (is_location_world_set) {
233 if (cdd->project.use_offset) {
234 add_v3_v3(r_location_world, cdd->project.offset);
235 }
236 }
237
238 return is_location_world_set;
239}
240
242 const int mval_i[2],
243 const float mval_fl[2],
244 const float surface_offset,
245 const float radius,
246 const float location_fallback_depth[3],
247 float r_location_world[3],
248 float r_location_local[3],
249 float r_normal_world[3],
250 float r_normal_local[3])
251{
252 bool is_depth_found = stroke_elem_project(
253 cdd, mval_i, mval_fl, surface_offset, radius, r_location_world, r_normal_world);
254 if (is_depth_found == false) {
256 cdd->vc.v3d, cdd->vc.region, location_fallback_depth, mval_fl, r_location_world);
257 zero_v3(r_normal_local);
258 }
259 mul_v3_m4v3(r_location_local, cdd->vc.obedit->world_to_object().ptr(), r_location_world);
260
261 if (!is_zero_v3(r_normal_world)) {
262 copy_v3_v3(r_normal_local, r_normal_world);
263 mul_transposed_mat3_m4_v3(cdd->vc.obedit->object_to_world().ptr(), r_normal_local);
264 normalize_v3(r_normal_local);
265 }
266 else {
267 zero_v3(r_normal_local);
268 }
269
270 return is_depth_found;
271}
272
277 const float location_fallback_depth[3],
278 StrokeElem *selem)
279{
280 const int mval_i[2] = {int(selem->mval[0]), int(selem->mval[1])};
281 const float radius = stroke_elem_radius(cdd, selem);
283 mval_i,
284 selem->mval,
286 radius,
287 location_fallback_depth,
288 selem->location_world,
289 selem->location_local,
290 selem->normal_world,
291 selem->normal_local);
292}
293
295
296/* -------------------------------------------------------------------- */
299
301{
302 PointerRNA itemptr;
303 RNA_collection_add(op->ptr, "stroke", &itemptr);
304
305 RNA_float_set_array(&itemptr, "mouse", selem->mval);
306 RNA_float_set_array(&itemptr, "location", selem->location_world);
307 RNA_float_set(&itemptr, "pressure", selem->pressure);
308}
309
311{
312 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
313
314 StrokeElem *selem = static_cast<StrokeElem *>(BLI_mempool_calloc(cdd->stroke_elem_pool));
315
316 RNA_float_get_array(itemptr, "mouse", selem->mval);
317 RNA_float_get_array(itemptr, "location", selem->location_world);
319 selem->location_local, cdd->vc.obedit->world_to_object().ptr(), selem->location_world);
320 selem->pressure = RNA_float_get(itemptr, "pressure");
321}
322
324{
325 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
326
327 BLI_mempool_iter iter;
328 const StrokeElem *selem;
329
331 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
332 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)))
333 {
335 }
336}
337
339{
340 RNA_BEGIN (op->ptr, itemptr, "stroke") {
342 }
343 RNA_END;
344}
345
347
348/* -------------------------------------------------------------------- */
351
352static void curve_draw_stroke_3d(const bContext * /*C*/, ARegion * /*region*/, void *arg)
353{
354 wmOperator *op = static_cast<wmOperator *>(arg);
355 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
356
357 const int stroke_len = BLI_mempool_len(cdd->stroke_elem_pool);
358
359 if (stroke_len == 0) {
360 return;
361 }
362
363 Object *obedit = cdd->vc.obedit;
364 Curve *cu = static_cast<Curve *>(obedit->data);
365
366 if (cu->bevel_radius > 0.0f) {
367 BLI_mempool_iter iter;
368 const StrokeElem *selem;
369
370 const float location_zero[3] = {0};
371 const float *location_prev = location_zero;
372
373 float color[3];
375
376 blender::gpu::Batch *sphere = GPU_batch_preset_sphere(0);
378 GPU_batch_uniform_3fv(sphere, "color", color);
379
380 /* scale to edit-mode space */
382 GPU_matrix_mul(obedit->object_to_world().ptr());
383
385 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
386 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)))
387 {
388 GPU_matrix_translate_3f(selem->location_local[0] - location_prev[0],
389 selem->location_local[1] - location_prev[1],
390 selem->location_local[2] - location_prev[2]);
391
392 const float radius = stroke_elem_radius(cdd, selem);
393
395 GPU_matrix_scale_1f(radius);
396 GPU_batch_draw(sphere);
398
399 location_prev = selem->location_local;
400 }
401
403 }
404
405 if (stroke_len > 1) {
406 float(*coord_array)[3] = static_cast<float(*)[3]>(
407 MEM_mallocN(sizeof(*coord_array) * stroke_len, __func__));
408
409 {
410 BLI_mempool_iter iter;
411 const StrokeElem *selem;
412 int i;
414 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)), i = 0; selem;
415 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)), i++)
416 {
417 copy_v3_v3(coord_array[i], selem->location_world);
418 }
419 }
420
421 {
425
428 GPU_line_smooth(true);
429 GPU_line_width(3.0f);
430
431 imm_cpack(0x0);
432 immBegin(GPU_PRIM_LINE_STRIP, stroke_len);
433 for (int i = 0; i < stroke_len; i++) {
434 immVertex3fv(pos, coord_array[i]);
435 }
436 immEnd();
437
438 GPU_line_width(1.0f);
439
440 imm_cpack(0xffffffff);
441 immBegin(GPU_PRIM_LINE_STRIP, stroke_len);
442 for (int i = 0; i < stroke_len; i++) {
443 immVertex3fv(pos, coord_array[i]);
444 }
445 immEnd();
446
447 /* Reset defaults */
450 GPU_line_smooth(false);
451
453 }
454
455 MEM_freeN(coord_array);
456 }
457}
458
459static void curve_draw_event_add(wmOperator *op, const wmEvent *event)
460{
461 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
462 Object *obedit = cdd->vc.obedit;
463
464 invert_m4_m4(obedit->runtime->world_to_object.ptr(), obedit->object_to_world().ptr());
465
466 StrokeElem *selem = static_cast<StrokeElem *>(BLI_mempool_calloc(cdd->stroke_elem_pool));
467
468 ARRAY_SET_ITEMS(selem->mval, event->mval[0], event->mval[1]);
469
470 /* handle pressure sensitivity (which is supplied by tablets or otherwise 1.0) */
471 selem->pressure = event->tablet.pressure;
472
473 bool is_depth_found = stroke_elem_project_fallback_elem(
474 cdd, cdd->prev.location_world_valid, selem);
475
476 if (is_depth_found) {
477 /* use the depth if a fallback wasn't used */
479 }
481
482 float len_sq = len_squared_v2v2(cdd->prev.mval, selem->mval);
483 copy_v2_v2(cdd->prev.mval, selem->mval);
484
485 if (cdd->sample.use_substeps && cdd->prev.selem) {
486 const StrokeElem selem_target = *selem;
487 StrokeElem *selem_new_last = selem;
488 if (len_sq >= square_f(STROKE_SAMPLE_DIST_MAX_PX)) {
489 int n = int(ceil(sqrt(double(len_sq)))) / STROKE_SAMPLE_DIST_MAX_PX;
490
491 for (int i = 1; i < n; i++) {
492 StrokeElem *selem_new = selem_new_last;
493 stroke_elem_interp(selem_new, cdd->prev.selem, &selem_target, float(i) / n);
494
495 const bool is_depth_found_substep = stroke_elem_project_fallback_elem(
496 cdd, cdd->prev.location_world_valid, selem_new);
497 if (is_depth_found == false) {
498 if (is_depth_found_substep) {
500 }
501 }
502
503 selem_new_last = static_cast<StrokeElem *>(BLI_mempool_calloc(cdd->stroke_elem_pool));
504 }
505 }
506 selem = selem_new_last;
507 *selem_new_last = selem_target;
508 }
509
510 cdd->prev.selem = selem;
511
513}
514
515static void curve_draw_event_add_first(wmOperator *op, const wmEvent *event)
516{
517 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
519
520 /* add first point */
521 curve_draw_event_add(op, event);
522
525 {
526 RegionView3D *rv3d = cdd->vc.rv3d;
527
528 cdd->project.use_depth = false;
529 cdd->project.use_plane = true;
530
531 float normal[3] = {0.0f};
532 if (ELEM(cps->surface_plane,
535 {
536 if (ED_view3d_depth_read_cached_normal(cdd->vc.region, cdd->depths, event->mval, normal)) {
538 float cross_a[3], cross_b[3];
539 cross_v3_v3v3(cross_a, rv3d->viewinv[2], normal);
540 cross_v3_v3v3(cross_b, normal, cross_a);
541 copy_v3_v3(normal, cross_b);
542 }
543 }
544 }
545
546 /* CURVE_PAINT_SURFACE_PLANE_VIEW or fallback */
547 if (is_zero_v3(normal)) {
548 copy_v3_v3(normal, rv3d->viewinv[2]);
549 }
550
551 normalize_v3_v3(cdd->project.plane, normal);
553
554 /* Special case for when we only have offset applied on the first-hit,
555 * the remaining stroke must be offset too. */
556 if (cdd->project.surface_offset != 0.0f) {
557 const float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])};
558
559 float location_no_offset[3];
560
561 if (stroke_elem_project(cdd, event->mval, mval_fl, 0.0f, 0.0f, location_no_offset, nullptr))
562 {
563 sub_v3_v3v3(cdd->project.offset, cdd->prev.location_world_valid, location_no_offset);
564 if (!is_zero_v3(cdd->project.offset)) {
565 cdd->project.use_offset = true;
566 }
567 }
568 }
569 /* end special case */
570 }
571
572 cdd->init_event_type = event->type;
574}
575
576static bool curve_draw_init(bContext *C, wmOperator *op, bool is_invoke)
577{
578 BLI_assert(op->customdata == nullptr);
579
582
583 if (is_invoke) {
585 if (ELEM(nullptr, cdd->vc.region, cdd->vc.rv3d, cdd->vc.v3d, cdd->vc.win, cdd->vc.scene)) {
586 MEM_freeN(cdd);
587 BKE_report(op->reports, RPT_ERROR, "Unable to access 3D viewport");
588 return false;
589 }
590 }
591 else {
592 cdd->vc.bmain = CTX_data_main(C);
593 cdd->vc.depsgraph = depsgraph;
594 cdd->vc.scene = CTX_data_scene(C);
597
598 /* Using an empty stroke complicates logic later,
599 * it's simplest to disallow early on (see: #94085). */
600 if (RNA_collection_is_empty(op->ptr, "stroke")) {
601 MEM_freeN(cdd);
602 BKE_report(op->reports, RPT_ERROR, "The \"stroke\" cannot be empty");
603 return false;
604 }
605 }
606
607 op->customdata = cdd;
608
610
611 cdd->curve_type = cps->curve_type;
612
613 cdd->radius.min = cps->radius_min;
614 cdd->radius.max = cps->radius_max;
615 cdd->radius.range = cps->radius_max - cps->radius_min;
619
621
622 return true;
623}
624
626{
627 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
628 if (cdd) {
629 if (cdd->draw_handle_view) {
632 }
633
634 if (cdd->stroke_elem_pool) {
636 }
637
638 if (cdd->depths) {
640 }
641 MEM_freeN(cdd);
642 op->customdata = nullptr;
643 }
644}
645
650{
651 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
653 PropertyRNA *prop;
654
655 prop = RNA_struct_find_property(op->ptr, "fit_method");
656 if (!RNA_property_is_set(op->ptr, prop)) {
657 RNA_property_enum_set(op->ptr, prop, cps->fit_method);
658 }
659
660 prop = RNA_struct_find_property(op->ptr, "corner_angle");
661 if (!RNA_property_is_set(op->ptr, prop)) {
662 const float corner_angle = (cps->flag & CURVE_PAINT_FLAG_CORNERS_DETECT) ? cps->corner_angle :
663 float(M_PI);
664 RNA_property_float_set(op->ptr, prop, corner_angle);
665 }
666
667 prop = RNA_struct_find_property(op->ptr, "error_threshold");
668 if (!RNA_property_is_set(op->ptr, prop)) {
669
670 /* Error isn't set so we'll have to calculate it from the pixel values. */
671 BLI_mempool_iter iter;
672 const StrokeElem *selem, *selem_prev;
673
674 float len_3d = 0.0f, len_2d = 0.0f;
675 float scale_px; /* pixel to local space scale */
676
677 int i = 0;
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)), i++)
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_malloc_arrayN<float>(stroke_len, __func__);
726 StrokeElem **selem_array = static_cast<StrokeElem **>(
727 MEM_mallocN(sizeof(*selem_array) * stroke_len, __func__));
728 lengths[0] = 0.0f;
729
730 float len_3d = 0.0f;
731
732 int i = 1;
734 selem_prev = static_cast<StrokeElem *>(BLI_mempool_iterstep(&iter));
735 selem_array[0] = selem_prev;
736 for (selem = static_cast<StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
737 selem = static_cast<StrokeElem *>(BLI_mempool_iterstep(&iter)), i++)
738 {
739 const float len_3d_segment = len_v3v3(selem->location_local, selem_prev->location_local);
740 len_3d += len_3d_segment;
741 lengths[i] = len_3d;
742 selem_array[i] = selem;
743 selem_prev = selem;
744 }
745
746 if (cps->radius_taper_start != 0.0f) {
747 const float len_taper_max = cps->radius_taper_start * len_3d;
748 for (i = 0; i < stroke_len && lengths[i] < len_taper_max; i++) {
749 const float pressure_new = selem_array[i]->pressure * (lengths[i] / len_taper_max);
750 stroke_elem_pressure_set(cdd, selem_array[i], pressure_new);
751 }
752 }
753
754 if (cps->radius_taper_end != 0.0f) {
755 const float len_taper_max = cps->radius_taper_end * len_3d;
756 const float len_taper_min = len_3d - len_taper_max;
757 for (i = stroke_len - 1; i > 0 && lengths[i] > len_taper_min; i--) {
758 const float pressure_new = selem_array[i]->pressure *
759 ((len_3d - lengths[i]) / len_taper_max);
760 stroke_elem_pressure_set(cdd, selem_array[i], pressure_new);
761 }
762 }
763
764 MEM_freeN(lengths);
765 MEM_freeN(selem_array);
766 }
767}
768
770{
771 if (op->customdata == nullptr) {
772 if (!curve_draw_init(C, op, false)) {
773 return OPERATOR_CANCELLED;
774 }
775 }
776
777 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
778
780 Object *obedit = cdd->vc.obedit;
781 Curve *cu = static_cast<Curve *>(obedit->data);
782 ListBase *nurblist = object_editcurve_get(obedit);
783
784 int stroke_len = BLI_mempool_len(cdd->stroke_elem_pool);
785
786 const bool is_3d = (cu->flag & CU_3D) != 0;
787 invert_m4_m4(obedit->runtime->world_to_object.ptr(), obedit->object_to_world().ptr());
788
789 if (BLI_mempool_len(cdd->stroke_elem_pool) == 0) {
791 stroke_len = BLI_mempool_len(cdd->stroke_elem_pool);
792 }
793
794 /* Deselect all existing curves. */
796
797 const float radius_min = cps->radius_min;
798 const float radius_max = cps->radius_max;
799 const float radius_range = cps->radius_max - cps->radius_min;
800
801 Nurb *nu = MEM_callocN<Nurb>(__func__);
802 nu->pntsv = 0;
803 nu->resolu = cu->resolu;
804 nu->resolv = cu->resolv;
805 nu->flag |= CU_SMOOTH;
806
807 const bool use_pressure_radius = (cps->flag & CURVE_PAINT_FLAG_PRESSURE_RADIUS) ||
808 ((cps->radius_taper_start != 0.0f) ||
809 (cps->radius_taper_end != 0.0f));
810
811 if (cdd->curve_type == CU_BEZIER) {
812 nu->type = CU_BEZIER;
813
814#ifdef USE_SPLINE_FIT
815
816 /* Allow to interpolate multiple channels */
817 int dims = 3;
818 struct {
819 int radius;
820 } coords_indices;
821 coords_indices.radius = use_pressure_radius ? dims++ : -1;
822
823 float *coords = MEM_malloc_arrayN<float>(stroke_len * dims, __func__);
824
825 float *cubic_spline = nullptr;
826 uint cubic_spline_len = 0;
827
828 /* error in object local space */
829 const int fit_method = RNA_enum_get(op->ptr, "fit_method");
830 const float error_threshold = RNA_float_get(op->ptr, "error_threshold");
831 const float corner_angle = RNA_float_get(op->ptr, "corner_angle");
832 const bool use_cyclic = RNA_boolean_get(op->ptr, "use_cyclic");
833
834 {
835 BLI_mempool_iter iter;
836 const StrokeElem *selem;
837 float *co = coords;
838
840 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
841 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)), co += dims)
842 {
843 copy_v3_v3(co, selem->location_local);
844 if (coords_indices.radius != -1) {
845 co[coords_indices.radius] = selem->pressure;
846 }
847
848 /* remove doubles */
849 if ((co != coords) && UNLIKELY(memcmp(co, co - dims, sizeof(float) * dims) == 0)) {
850 co -= dims;
851 stroke_len--;
852 }
853 }
854 }
855
856 uint *corners = nullptr;
857 uint corners_len = 0;
858
859 if ((fit_method == CURVE_PAINT_FIT_METHOD_SPLIT) && (corner_angle < float(M_PI))) {
860 /* this could be configurable... */
861 const float corner_radius_min = error_threshold / 8;
862 const float corner_radius_max = error_threshold * 2;
863 const uint samples_max = 16;
864
865 curve_fit_corners_detect_fl(coords,
866 stroke_len,
867 dims,
868 corner_radius_min,
869 corner_radius_max,
870 samples_max,
871 corner_angle,
872 &corners,
873 &corners_len);
874 }
875
876 uint *corners_index = nullptr;
877 uint corners_index_len = 0;
878 uint calc_flag = CURVE_FIT_CALC_HIGH_QUALIY;
879
880 if ((stroke_len > 2) && use_cyclic) {
881 calc_flag |= CURVE_FIT_CALC_CYCLIC;
882 }
883
884 int result;
885 if (fit_method == CURVE_PAINT_FIT_METHOD_REFIT) {
886 result = curve_fit_cubic_to_points_refit_fl(coords,
887 stroke_len,
888 dims,
889 error_threshold,
890 calc_flag,
891 nullptr,
892 0,
893 corner_angle,
894 &cubic_spline,
895 &cubic_spline_len,
896 nullptr,
897 &corners_index,
898 &corners_index_len);
899 }
900 else {
901 result = curve_fit_cubic_to_points_fl(coords,
902 stroke_len,
903 dims,
904 error_threshold,
905 calc_flag,
906 corners,
907 corners_len,
908 &cubic_spline,
909 &cubic_spline_len,
910 nullptr,
911 &corners_index,
912 &corners_index_len);
913 }
914
915 MEM_freeN(coords);
916 if (corners) {
917 free(corners);
918 }
919
920 if (result == 0) {
921 nu->pntsu = cubic_spline_len;
922 nu->bezt = MEM_calloc_arrayN<BezTriple>(nu->pntsu, __func__);
923
924 float *co = cubic_spline;
925 BezTriple *bezt = nu->bezt;
926 for (int j = 0; j < cubic_spline_len; j++, bezt++, co += (dims * 3)) {
927 const float *handle_l = co + (dims * 0);
928 const float *pt = co + (dims * 1);
929 const float *handle_r = co + (dims * 2);
930
931 copy_v3_v3(bezt->vec[0], handle_l);
932 copy_v3_v3(bezt->vec[1], pt);
933 copy_v3_v3(bezt->vec[2], handle_r);
934
935 if (coords_indices.radius != -1) {
936 bezt->radius = (pt[coords_indices.radius] * cdd->radius.range) + cdd->radius.min;
937 }
938 else {
939 bezt->radius = radius_max;
940 }
941
942 bezt->h1 = bezt->h2 = HD_ALIGN; /* will set to free in second pass */
943 bezt->f1 = bezt->f2 = bezt->f3 = SELECT;
944 }
945
946 if (corners_index) {
947 /* ignore the first and last */
948 uint i_start = 0, i_end = corners_index_len;
949
950 if ((corners_index_len >= 2) && (calc_flag & CURVE_FIT_CALC_CYCLIC) == 0) {
951 i_start += 1;
952 i_end -= 1;
953 }
954
955 for (uint i = i_start; i < i_end; i++) {
956 bezt = &nu->bezt[corners_index[i]];
957 bezt->h1 = bezt->h2 = HD_FREE;
958 }
959 }
960
961 if (calc_flag & CURVE_FIT_CALC_CYCLIC) {
962 nu->flagu |= CU_NURB_CYCLIC;
963 }
964 }
965
966 if (corners_index) {
967 free(corners_index);
968 }
969
970 if (cubic_spline) {
971 free(cubic_spline);
972 }
973
974#else
975 nu->pntsu = stroke_len;
976 nu->bezt = MEM_callocN(nu->pntsu * sizeof(BezTriple), __func__);
977
978 BezTriple *bezt = nu->bezt;
979
980 {
981 BLI_mempool_iter iter;
982 const struct StrokeElem *selem;
983
985 for (selem = BLI_mempool_iterstep(&iter); selem; selem = BLI_mempool_iterstep(&iter)) {
986 copy_v3_v3(bezt->vec[1], selem->location_local);
987 if (!is_3d) {
988 bezt->vec[1][2] = 0.0f;
989 }
990
991 if (use_pressure_radius) {
992 bezt->radius = selem->pressure;
993 }
994 else {
995 bezt->radius = radius_max;
996 }
997
998 bezt->h1 = bezt->h2 = HD_AUTO;
999
1000 bezt->f1 |= SELECT;
1001 bezt->f2 |= SELECT;
1002 bezt->f3 |= SELECT;
1003
1004 bezt++;
1005 }
1006 }
1007#endif
1008
1010 }
1011 else { /* CU_POLY */
1012 BLI_mempool_iter iter;
1013 const StrokeElem *selem;
1014
1015 nu->pntsu = stroke_len;
1016 nu->pntsv = 1;
1017 nu->type = CU_POLY;
1018 nu->bp = MEM_calloc_arrayN<BPoint>(nu->pntsu, __func__);
1019
1020 /* Misc settings. */
1021 nu->resolu = cu->resolu;
1022 nu->resolv = 1;
1023 nu->orderu = 4;
1024 nu->orderv = 1;
1025
1026 BPoint *bp = nu->bp;
1027
1029 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
1030 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)))
1031 {
1032 copy_v3_v3(bp->vec, selem->location_local);
1033 if (!is_3d) {
1034 bp->vec[2] = 0.0f;
1035 }
1036
1037 if (use_pressure_radius) {
1038 bp->radius = (selem->pressure * radius_range) + radius_min;
1039 }
1040 else {
1041 bp->radius = cps->radius_max;
1042 }
1043 bp->f1 = SELECT;
1044 bp->vec[3] = 1.0f;
1045
1046 bp++;
1047 }
1048
1050 }
1051
1052 BLI_addtail(nurblist, nu);
1053
1055 cu->actvert = nu->pntsu - 1;
1056
1058 DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
1059
1060 curve_draw_exit(op);
1061
1062 return OPERATOR_FINISHED;
1063}
1064
1066{
1067 if (RNA_struct_property_is_set(op->ptr, "stroke")) {
1068 return curve_draw_exec(C, op);
1069 }
1070
1071 if (!curve_draw_init(C, op, true)) {
1072 return OPERATOR_CANCELLED;
1073 }
1074
1075 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
1076
1078
1079 const bool is_modal = RNA_boolean_get(op->ptr, "wait_for_input");
1080
1081 /* Fallback (in case we can't find the depth on first test). */
1082 {
1083 const float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])};
1084 float center[3];
1085 negate_v3_v3(center, cdd->vc.rv3d->ofs);
1086 ED_view3d_win_to_3d(cdd->vc.v3d, cdd->vc.region, center, mval_fl, cdd->prev.location_world);
1088 }
1089
1093
1094 {
1095 View3D *v3d = cdd->vc.v3d;
1096 RegionView3D *rv3d = cdd->vc.rv3d;
1097 Object *obedit = cdd->vc.obedit;
1098 Curve *cu = static_cast<Curve *>(obedit->data);
1099
1100 const float *plane_no = nullptr;
1101 const float *plane_co = nullptr;
1102
1103 if (CU_IS_2D(cu)) {
1104 /* 2D overrides other options */
1105 plane_co = obedit->object_to_world().location();
1106 plane_no = obedit->object_to_world().ptr()[2];
1107 cdd->project.use_plane = true;
1108 }
1109 else {
1110 if ((cps->depth_mode == CURVE_PAINT_PROJECT_SURFACE) && (v3d->shading.type > OB_WIRE)) {
1111 /* needed or else the draw matrix can be incorrect */
1113
1116 depth_mode = V3D_DEPTH_SELECTED_ONLY;
1117 }
1118
1120 cdd->vc.region,
1121 cdd->vc.v3d,
1122 nullptr,
1123 depth_mode,
1124 false,
1125 &cdd->depths);
1126
1127 if (cdd->depths != nullptr) {
1128 cdd->project.use_depth = true;
1129 }
1130 else {
1131 BKE_report(op->reports, RPT_WARNING, "Unable to access depth buffer, using view plane");
1132 cdd->project.use_depth = false;
1133 }
1134 }
1135
1136 /* use view plane (when set or as a fallback when surface can't be found) */
1137 if (cdd->project.use_depth == false) {
1138 plane_co = cdd->vc.scene->cursor.location;
1139 plane_no = rv3d->viewinv[2];
1140 cdd->project.use_plane = true;
1141 }
1142
1143 if (cdd->project.use_depth && (cdd->curve_type != CU_POLY)) {
1144 cdd->sample.use_substeps = true;
1145 }
1146 }
1147
1148 if (cdd->project.use_plane) {
1149 normalize_v3_v3(cdd->project.plane, plane_no);
1150 cdd->project.plane[3] = -dot_v3v3(cdd->project.plane, plane_co);
1151 }
1152 }
1153
1154 if (is_modal == false) {
1155 curve_draw_event_add_first(op, event);
1156 }
1157
1158 /* add temp handler */
1160
1162}
1163
1164static void curve_draw_cancel(bContext * /*C*/, wmOperator *op)
1165{
1166 curve_draw_exit(op);
1167}
1168
1169/* Modal event handling of frame changing */
1171{
1173 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
1174
1175 UNUSED_VARS(C, op);
1176
1177 if (event->type == cdd->init_event_type) {
1178 if (event->val == KM_RELEASE) {
1180
1182
1184
1185 curve_draw_exec(C, op);
1186
1187 return OPERATOR_FINISHED;
1188 }
1189 }
1190 else if (ELEM(event->type, EVT_ESCKEY, RIGHTMOUSE)) {
1192 curve_draw_cancel(C, op);
1193 return OPERATOR_CANCELLED;
1194 }
1195 else if (ELEM(event->type, LEFTMOUSE)) {
1196 if (event->val == KM_PRESS) {
1197 curve_draw_event_add_first(op, event);
1198 }
1199 }
1200 else if (ISMOUSE_MOTION(event->type)) {
1201 if (cdd->state == CURVE_DRAW_PAINTING) {
1202 const float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])};
1204 curve_draw_event_add(op, event);
1205 }
1206 }
1207 }
1208
1209 return ret;
1210}
1211
1213{
1214 /* identifiers */
1215 ot->name = "Draw Curve";
1216 ot->idname = "CURVE_OT_draw";
1217 ot->description = "Draw a freehand spline";
1218
1219 /* API callbacks. */
1220 ot->exec = curve_draw_exec;
1221 ot->invoke = curve_draw_invoke;
1222 ot->cancel = curve_draw_cancel;
1223 ot->modal = curve_draw_modal;
1224 ot->poll = ED_operator_editcurve;
1225
1226 /* flags */
1227 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1228
1229 /* properties */
1230 PropertyRNA *prop;
1231
1232 prop = RNA_def_float_distance(ot->srna,
1233 "error_threshold",
1234 0.0f,
1235 0.0f,
1236 10.0f,
1237 "Error",
1238 "Error distance threshold (in object units)",
1239 0.0001f,
1240 10.0f);
1242 RNA_def_property_ui_range(prop, 0.0, 10, 1, 4);
1243
1244 RNA_def_enum(ot->srna,
1245 "fit_method",
1248 "Fit Method",
1249 "");
1250
1252 ot->srna, "corner_angle", DEG2RADF(70.0f), 0.0f, M_PI, "Corner Angle", "", 0.0f, M_PI);
1254
1255 prop = RNA_def_boolean(ot->srna, "use_cyclic", true, "Cyclic", "");
1257
1258 prop = RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
1260
1261 prop = RNA_def_boolean(ot->srna, "wait_for_input", true, "Wait for Input", "");
1263}
1264
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)
void BKE_nurb_handles_calc(Nurb *nu)
Definition curve.cc:3961
#define CU_IS_2D(cu)
Definition BKE_curve.hh:89
void BKE_curve_nurb_active_set(Curve *cu, const Nurb *nu)
Definition curve.cc:4980
void BKE_nurb_knot_calc_u(Nurb *nu)
Definition curve.cc:1193
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)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:111
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)
@ BLI_MEMPOOL_ALLOW_ITER
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)
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_SMOOTH
@ CU_NURB_CYCLIC
@ CU_BEZIER
@ CU_POLY
@ HD_FREE
@ HD_AUTO
@ HD_ALIGN
@ CU_3D
@ OB_WIRE
Object is a sort of wrapper for general info.
@ 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
@ CURVE_PAINT_PROJECT_SURFACE
@ CURVE_PAINT_SURFACE_PLANE_NORMAL_SURFACE
@ CURVE_PAINT_SURFACE_PLANE_NORMAL_VIEW
#define UI_SCALE_FAC
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ OPERATOR_RUNNING_MODAL
bool ED_operator_editcurve(bContext *C)
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
Read Guarded memory(de)allocation.
#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
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
@ KM_PRESS
Definition WM_types.hh:308
@ KM_RELEASE
Definition WM_types.hh:309
BPy_StructRNA * depsgraph
#define SELECT
ListBase * object_editcurve_get(Object *ob)
Definition editcurve.cc:90
#define STROKE_CYCLIC_DIST_PX
static void curve_draw_exec_precalc(wmOperator *op)
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])
CurveDrawState
@ CURVE_DRAW_IDLE
@ CURVE_DRAW_PAINTING
static wmOperatorStatus curve_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event)
#define STROKE_SAMPLE_DIST_MIN_PX
static wmOperatorStatus curve_draw_exec(bContext *C, wmOperator *op)
static void curve_draw_event_add(wmOperator *op, const wmEvent *event)
void CURVE_OT_draw(wmOperatorType *ot)
static void curve_draw_stroke_to_operator_elem(wmOperator *op, const StrokeElem *selem)
static wmOperatorStatus curve_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
static void curve_draw_stroke_3d(const bContext *, ARegion *, void *arg)
static void curve_draw_stroke_from_operator_elem(wmOperator *op, PointerRNA *itemptr)
static float stroke_elem_radius(const CurveDrawData *cdd, const StrokeElem *selem)
static void curve_draw_stroke_to_operator(wmOperator *op)
static bool stroke_elem_project_fallback_elem(const CurveDrawData *cdd, const float location_fallback_depth[3], StrokeElem *selem)
static bool curve_draw_init(bContext *C, wmOperator *op, bool is_invoke)
static float stroke_elem_radius_from_pressure(const CurveDrawData *cdd, const float pressure)
static void stroke_elem_pressure_set(const CurveDrawData *cdd, StrokeElem *selem, float pressure)
static void curve_draw_stroke_from_operator(wmOperator *op)
#define STROKE_SAMPLE_DIST_MAX_PX
static void stroke_elem_interp(StrokeElem *selem_out, const StrokeElem *selem_a, const StrokeElem *selem_b, float t)
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_cancel(bContext *, wmOperator *op)
static void curve_draw_event_add_first(wmOperator *op, const wmEvent *event)
static void curve_draw_exit(wmOperator *op)
bool ED_curve_deselect_all_multi(bContext *C)
uint pos
#define ceil
#define sqrt
format
void * MEM_mallocN(size_t len, const char *str)
Definition mallocn.cc:128
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:123
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
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
uint8_t f1
float vec[4]
float vec[3][3]
bool use_surface_offset_absolute
ViewDepths * depths
struct CurveDrawData::@104077103135250163144132301337337050327307344264 prev
struct CurveDrawData::@033215176245230233042326161252226337061274332022 sample
float location_world[3]
CurveDrawState state
const StrokeElem * selem
struct CurveDrawData::@122265357101141262273373067270112361265333146160 radius
struct CurveDrawData::@364244323034303323047304115166303066117226245314 project
float location_world_valid[3]
BLI_mempool * stroke_elem_pool
short resolv
short resolu
float bevel_radius
Definition DNA_ID.h:404
short flagu
short orderu
short orderv
short flag
short type
BezTriple * bezt
BPoint * bp
short resolu
short resolv
ObjectRuntimeHandle * runtime
float viewinv[4][4]
struct ToolSettings * toolsettings
View3DCursor cursor
float normal_world[3]
float normal_local[3]
float location_local[3]
float location_world[3]
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
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:4225