Blender V5.3
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
8
9#include "DNA_curve_types.h"
10
11#include "BLI_math_matrix_c.hh"
13#include "BLI_math_vector_c.hh"
14#include "BLI_mempool.hh"
15
16#include "BLT_translation.hh"
17
18#include "BKE_attribute.hh"
19#include "BKE_context.hh"
20#include "BKE_curves.hh"
21#include "BKE_object_types.hh"
22#include "BKE_report.hh"
23#include "BKE_screen.hh"
24
25#include "DEG_depsgraph.hh"
26
27#include "WM_api.hh"
28
29#include "ED_curves.hh"
30#include "ED_screen.hh"
31#include "ED_space_api.hh"
32#include "ED_view3d.hh"
33
34#include "GPU_batch.hh"
35#include "GPU_batch_presets.hh"
36#include "GPU_immediate.hh"
37#include "GPU_immediate_util.hh"
38#include "GPU_matrix.hh"
39#include "GPU_state.hh"
40
41#include "UI_resources.hh"
42
43#include "RNA_access.hh"
44#include "RNA_define.hh"
45#include "RNA_enum_types.hh"
46#include "RNA_prototypes.hh"
47
48namespace blender {
49
50extern "C" {
51#include "curve_fit_nd.h"
52}
53
54namespace ed::curves {
55
56/* Distance between input samples */
57#define STROKE_SAMPLE_DIST_MIN_PX 1
58#define STROKE_SAMPLE_DIST_MAX_PX 3
59
60/* Distance between start/end points to consider cyclic */
61#define STROKE_CYCLIC_DIST_PX 8
62
63/* -------------------------------------------------------------------- */
66
67struct StrokeElem {
68 float mval[2];
71
72 /* Surface normal, may be zeroed. */
73 float normal_world[3];
74 float normal_local[3];
75
76 float pressure;
77};
78
83
89
90 /* projecting 2D into 3D space */
91 struct {
92 /* use a plane or project to the surface */
93 bool use_plane;
94 float plane[4];
95
96 /* use 'rv3d->depths', note that this will become 'damaged' while drawing, but that's OK. */
97 bool use_depth;
98
99 /* offset projection by this value */
100 bool use_offset;
101 float offset[3]; /* world-space */
102 float surface_offset;
105
106 /* cursor sampling */
107 struct {
108 /* use substeps, needed for nicely interpolating depth */
109 bool use_substeps;
111
112 struct {
113 float min, max, range;
115
116 struct {
117 float mval[2];
118 /* Used in case we can't calculate the depth. */
119 float location_world[3];
120
121 float location_world_valid[3];
122
123 const StrokeElem *selem;
125
129
130 /* StrokeElem */
132
134};
135
136static float stroke_elem_radius_from_pressure(const CurveDrawData *cdd, const float pressure)
137{
138 return ((pressure * cdd->radius.range) + cdd->radius.min) * cdd->bevel_radius;
139}
140
141static float stroke_elem_radius(const CurveDrawData *cdd, const StrokeElem *selem)
142{
143 return stroke_elem_radius_from_pressure(cdd, selem->pressure);
144}
145
146static void stroke_elem_pressure_set(const CurveDrawData *cdd, StrokeElem *selem, float pressure)
147{
148 if ((cdd->project.surface_offset != 0.0f) && !cdd->project.use_surface_offset_absolute &&
149 !is_zero_v3(selem->normal_local))
150 {
151 const float adjust = stroke_elem_radius_from_pressure(cdd, pressure) -
153 madd_v3_v3fl(selem->location_local, selem->normal_local, adjust);
155 selem->location_world, cdd->vc.obedit->object_to_world().ptr(), selem->location_local);
156 }
157 selem->pressure = pressure;
158}
159
160static void stroke_elem_interp(StrokeElem *selem_out,
161 const StrokeElem *selem_a,
162 const StrokeElem *selem_b,
163 float t)
164{
165 interp_v2_v2v2(selem_out->mval, selem_a->mval, selem_b->mval, t);
166 interp_v3_v3v3(selem_out->location_world, selem_a->location_world, selem_b->location_world, t);
167 interp_v3_v3v3(selem_out->location_local, selem_a->location_local, selem_b->location_local, t);
168 selem_out->pressure = interpf(selem_a->pressure, selem_b->pressure, t);
169}
170
174static bool stroke_elem_project(const CurveDrawData *cdd,
175 const int mval_i[2],
176 const float mval_fl[2],
177 float surface_offset,
178 const float radius,
179 float r_location_world[3],
180 float r_normal_world[3])
181{
182 ARegion *region = cdd->vc.region;
183
184 bool is_location_world_set = false;
185
186 /* project to 'location_world' */
187 if (cdd->project.use_plane) {
188 /* get the view vector to 'location' */
189 if (ED_view3d_win_to_3d_on_plane(region, cdd->project.plane, mval_fl, true, r_location_world))
190 {
191 if (r_normal_world) {
192 zero_v3(r_normal_world);
193 }
194 is_location_world_set = true;
195 }
196 }
197 else {
198 const ViewDepths *depths = cdd->depths;
199 if (depths && (uint(mval_i[0]) < depths->w) && (uint(mval_i[1]) < depths->h)) {
200 float depth_fl = 1.0f;
201 ED_view3d_depth_read_cached(depths, mval_i, 0, &depth_fl);
202 const double depth = double(depth_fl);
203 if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
204 if (ED_view3d_depth_unproject_v3(region, mval_i, depth, r_location_world)) {
205 is_location_world_set = true;
206 if (r_normal_world) {
207 zero_v3(r_normal_world);
208 }
209
210 if (surface_offset != 0.0f) {
211 const float offset = cdd->project.use_surface_offset_absolute ? 1.0f : radius;
212 float normal[3];
213 if (ED_view3d_depth_read_cached_normal(region, depths, mval_i, normal)) {
214 madd_v3_v3fl(r_location_world, normal, offset * surface_offset);
215 if (r_normal_world) {
216 copy_v3_v3(r_normal_world, normal);
217 }
218 }
219 }
220 }
221 }
222 }
223 }
224
225 if (is_location_world_set) {
226 if (cdd->project.use_offset) {
227 add_v3_v3(r_location_world, cdd->project.offset);
228 }
229 }
230
231 return is_location_world_set;
232}
233
235 const int mval_i[2],
236 const float mval_fl[2],
237 const float surface_offset,
238 const float radius,
239 const float location_fallback_depth[3],
240 float r_location_world[3],
241 float r_location_local[3],
242 float r_normal_world[3],
243 float r_normal_local[3])
244{
245 bool is_depth_found = stroke_elem_project(
246 cdd, mval_i, mval_fl, surface_offset, radius, r_location_world, r_normal_world);
247 if (is_depth_found == false) {
249 cdd->vc.v3d, cdd->vc.region, location_fallback_depth, mval_fl, r_location_world);
250 zero_v3(r_normal_local);
251 }
252 mul_v3_m4v3(r_location_local, cdd->vc.obedit->world_to_object().ptr(), r_location_world);
253
254 if (!is_zero_v3(r_normal_world)) {
255 copy_v3_v3(r_normal_local, r_normal_world);
256 mul_transposed_mat3_m4_v3(cdd->vc.obedit->object_to_world().ptr(), r_normal_local);
257 normalize_v3(r_normal_local);
258 }
259 else {
260 zero_v3(r_normal_local);
261 }
262
263 return is_depth_found;
264}
265
270 const float location_fallback_depth[3],
271 StrokeElem *selem)
272{
273 const int mval_i[2] = {int(selem->mval[0]), int(selem->mval[1])};
274 const float radius = stroke_elem_radius(cdd, selem);
276 mval_i,
277 selem->mval,
278 cdd->project.surface_offset,
279 radius,
280 location_fallback_depth,
281 selem->location_world,
282 selem->location_local,
283 selem->normal_world,
284 selem->normal_local);
285}
286
288
289/* -------------------------------------------------------------------- */
292
294{
295 PointerRNA itemptr;
296 RNA_collection_add(op->ptr, "stroke", &itemptr);
297
298 RNA_float_set_array(&itemptr, "mouse", selem->mval);
299 RNA_float_set_array(&itemptr, "location", selem->location_world);
300 RNA_float_set(&itemptr, "pressure", selem->pressure);
301}
302
304{
305 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
306
307 StrokeElem *selem = static_cast<StrokeElem *>(BLI_mempool_calloc(cdd->stroke_elem_pool));
308
309 RNA_float_get_array(itemptr, "mouse", selem->mval);
310 RNA_float_get_array(itemptr, "location", selem->location_world);
312 selem->location_local, cdd->vc.obedit->world_to_object().ptr(), selem->location_world);
313 selem->pressure = RNA_float_get(itemptr, "pressure");
314}
315
317{
318 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
319
320 BLI_mempool_iter iter;
321 const StrokeElem *selem;
322
324 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
325 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)))
326 {
328 }
329}
330
332{
333 RNA_BEGIN (op->ptr, itemptr, "stroke") {
335 }
336 RNA_END;
337}
338
340
341static void curve_draw_stroke_3d(const bContext * /*C*/, ARegion * /*region*/, void *arg)
342{
343 wmOperator *op = static_cast<wmOperator *>(arg);
344 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
345
346 const int stroke_len = BLI_mempool_len(cdd->stroke_elem_pool);
347
348 if (stroke_len == 0) {
349 return;
350 }
351
352 Object *obedit = cdd->vc.obedit;
353
354 /* Disabled: not representative in enough cases, and curves draw shape is not per object yet.
355 * In the future this could be enabled when the object's draw shape is "strand" or "3D". */
356 if (false && cdd->bevel_radius > 0.0f) {
357 BLI_mempool_iter iter;
358 const StrokeElem *selem;
359
360 const float location_zero[3] = {0};
361 const float *location_prev = location_zero;
362
363 float color[3];
365
366 gpu::Batch *sphere = GPU_batch_preset_sphere(0);
368 GPU_batch_uniform_3fv(sphere, "color", color);
369
370 /* scale to edit-mode space */
372 GPU_matrix_mul(obedit->object_to_world().ptr());
373
375 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
376 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)))
377 {
378 GPU_matrix_translate_3f(selem->location_local[0] - location_prev[0],
379 selem->location_local[1] - location_prev[1],
380 selem->location_local[2] - location_prev[2]);
381
382 const float radius = stroke_elem_radius(cdd, selem);
383
385 GPU_matrix_scale_1f(radius);
386 GPU_batch_draw(sphere);
388
389 location_prev = selem->location_local;
390 }
391
393 }
394
395 if (stroke_len > 1) {
396 float (*coord_array)[3] = MEM_new_array_uninitialized<float[3]>(stroke_len, __func__);
397
398 {
399 BLI_mempool_iter iter;
400 const StrokeElem *selem;
401 int i;
403 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)), i = 0; selem;
404 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)), i++)
405 {
406 copy_v3_v3(coord_array[i], selem->location_world);
407 }
408 }
409
410 {
411 GPUVertFormat *format = immVertexFormat();
412 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
414
417 GPU_line_smooth(true);
418 GPU_line_width(3.0f);
419
420 imm_cpack(0x0);
421 immBegin(GPU_PRIM_LINE_STRIP, stroke_len);
422 for (int i = 0; i < stroke_len; i++) {
423 immVertex3fv(pos, coord_array[i]);
424 }
425 immEnd();
426
427 GPU_line_width(1.0f);
428
429 imm_cpack(0xffffffff);
430 immBegin(GPU_PRIM_LINE_STRIP, stroke_len);
431 for (int i = 0; i < stroke_len; i++) {
432 immVertex3fv(pos, coord_array[i]);
433 }
434 immEnd();
435
436 /* Reset defaults */
439 GPU_line_smooth(false);
440
442 }
443
444 MEM_delete(coord_array);
445 }
446}
447
448static void curve_draw_event_add(wmOperator *op, const wmEvent *event)
449{
450 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
451 Object *obedit = cdd->vc.obedit;
452
453 invert_m4_m4(obedit->runtime->world_to_object.ptr(), obedit->object_to_world().ptr());
454
455 StrokeElem *selem = static_cast<StrokeElem *>(BLI_mempool_calloc(cdd->stroke_elem_pool));
456
457 ARRAY_SET_ITEMS(selem->mval, event->mval[0], event->mval[1]);
458
459 /* handle pressure sensitivity (which is supplied by tablets or otherwise 1.0) */
460 selem->pressure = event->tablet.pressure;
461
462 bool is_depth_found = stroke_elem_project_fallback_elem(
463 cdd, cdd->prev.location_world_valid, selem);
464
465 if (is_depth_found) {
466 /* use the depth if a fallback wasn't used */
467 copy_v3_v3(cdd->prev.location_world_valid, selem->location_world);
468 }
469 copy_v3_v3(cdd->prev.location_world, selem->location_world);
470
471 float len_sq = len_squared_v2v2(cdd->prev.mval, selem->mval);
472 copy_v2_v2(cdd->prev.mval, selem->mval);
473
474 if (cdd->sample.use_substeps && cdd->prev.selem) {
475 const StrokeElem selem_target = *selem;
476 StrokeElem *selem_new_last = selem;
477 if (len_sq >= square_f(STROKE_SAMPLE_DIST_MAX_PX)) {
478 int n = int(ceil(sqrt(double(len_sq)))) / STROKE_SAMPLE_DIST_MAX_PX;
479
480 for (int i = 1; i < n; i++) {
481 StrokeElem *selem_new = selem_new_last;
482 stroke_elem_interp(selem_new, cdd->prev.selem, &selem_target, float(i) / n);
483
484 const bool is_depth_found_substep = stroke_elem_project_fallback_elem(
485 cdd, cdd->prev.location_world_valid, selem_new);
486 if (is_depth_found == false) {
487 if (is_depth_found_substep) {
488 copy_v3_v3(cdd->prev.location_world_valid, selem_new->location_world);
489 }
490 }
491
492 selem_new_last = static_cast<StrokeElem *>(BLI_mempool_calloc(cdd->stroke_elem_pool));
493 }
494 }
495 selem = selem_new_last;
496 *selem_new_last = selem_target;
497 }
498
499 cdd->prev.selem = selem;
500
502}
503
504static void curve_draw_event_add_first(wmOperator *op, const wmEvent *event)
505{
506 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
508
509 /* add first point */
510 curve_draw_event_add(op, event);
511
512 if ((cps->depth_mode == CURVE_PAINT_PROJECT_SURFACE) && cdd->project.use_depth &&
514 {
515 RegionView3D *rv3d = cdd->vc.rv3d;
516
517 cdd->project.use_depth = false;
518 cdd->project.use_plane = true;
519
520 float normal[3] = {0.0f};
521 if (ELEM(cps->surface_plane,
524 {
525 if (ED_view3d_depth_read_cached_normal(cdd->vc.region, cdd->depths, event->mval, normal)) {
527 float cross_a[3], cross_b[3];
528 cross_v3_v3v3(cross_a, rv3d->viewinv[2], normal);
529 cross_v3_v3v3(cross_b, normal, cross_a);
530 copy_v3_v3(normal, cross_b);
531 }
532 }
533 }
534
535 /* CURVE_PAINT_SURFACE_PLANE_VIEW or fallback */
536 if (is_zero_v3(normal)) {
537 copy_v3_v3(normal, rv3d->viewinv[2]);
538 }
539
540 normalize_v3_v3(cdd->project.plane, normal);
541 cdd->project.plane[3] = -dot_v3v3(cdd->project.plane, cdd->prev.location_world_valid);
542
543 /* Special case for when we only have offset applied on the first-hit,
544 * the remaining stroke must be offset too. */
545 if (cdd->project.surface_offset != 0.0f) {
546 const float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])};
547
548 float location_no_offset[3];
549
550 if (stroke_elem_project(cdd, event->mval, mval_fl, 0.0f, 0.0f, location_no_offset, nullptr))
551 {
552 sub_v3_v3v3(cdd->project.offset, cdd->prev.location_world_valid, location_no_offset);
553 if (!is_zero_v3(cdd->project.offset)) {
554 cdd->project.use_offset = true;
555 }
556 }
557 }
558 /* end special case */
559 }
560
561 cdd->init_event_type = event->type;
563}
564
566{
567 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
568 if (cdd) {
569 if (cdd->draw_handle_view) {
572 }
573
574 if (cdd->stroke_elem_pool) {
576 }
577
578 if (cdd->depths) {
580 }
581 MEM_delete(cdd);
582 op->customdata = nullptr;
583 }
584}
585
586static bool curve_draw_init(bContext *C, wmOperator *op, bool is_invoke)
587{
588 BLI_assert(op->customdata == nullptr);
589
591
592 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
593
594 if (is_invoke) {
595 cdd->vc = ED_view3d_viewcontext_init(C, depsgraph);
596 if (ELEM(nullptr, cdd->vc.region, cdd->vc.rv3d, cdd->vc.v3d, cdd->vc.win, cdd->vc.scene)) {
597 MEM_delete(cdd);
598 BKE_report(op->reports, RPT_ERROR, "Unable to access 3D viewport");
599 return false;
600 }
601 }
602 else {
603 cdd->vc.bmain = CTX_data_main(C);
604 cdd->vc.depsgraph = depsgraph;
605 cdd->vc.scene = CTX_data_scene(C);
608
609 /* Using an empty stroke complicates logic later,
610 * it's simplest to disallow early on (see: #94085). */
611 if (RNA_collection_is_empty(op->ptr, "stroke")) {
612 MEM_delete(cdd);
613 BKE_report(op->reports, RPT_ERROR, "The \"stroke\" cannot be empty");
614 return false;
615 }
616 }
617
618 op->customdata = cdd;
619 cdd->bevel_radius = 1.0f;
620 cdd->is_curve_2d = RNA_boolean_get(op->ptr, "is_curve_2d");
621
623
624 cdd->curve_type = cps->curve_type;
625
626 cdd->radius.min = cps->radius_min;
627 cdd->radius.max = cps->radius_max;
628 cdd->radius.range = cps->radius_max - cps->radius_min;
629 cdd->project.surface_offset = cps->surface_offset;
630 cdd->project.use_surface_offset_absolute = (cps->flag &
632
634
635 return true;
636}
637
640 const CurveDrawData *cdd,
641 const int curve_index,
642 const bool is_cyclic,
643 const uint cubic_spline_len,
644 const int dims,
645 const int radius_index,
646 const float radius_max,
647 const float *cubic_spline,
648 const uint *corners_index,
649 const uint corners_index_len)
650{
651 curves.resize(curves.points_num() + cubic_spline_len, curve_index + 1);
652
653 MutableSpan<float3> positions = curves.positions_for_write();
654 MutableSpan<float3> handle_positions_l = curves.handle_positions_left_for_write();
655 MutableSpan<float3> handle_positions_r = curves.handle_positions_right_for_write();
656 MutableSpan<int8_t> handle_types_l = curves.handle_types_left_for_write();
657 MutableSpan<int8_t> handle_types_r = curves.handle_types_right_for_write();
658
659 const IndexRange new_points = curves.points_by_curve()[curve_index];
660
662 "radius", bke::AttrDomain::Point);
663
664 const float *co = cubic_spline;
665
666 for (const int64_t i : new_points) {
667 const float *handle_l = co + (dims * 0);
668 const float *pt = co + (dims * 1);
669 const float *handle_r = co + (dims * 2);
670
671 copy_v3_v3(handle_positions_l[i], handle_l);
672 copy_v3_v3(positions[i], pt);
673 copy_v3_v3(handle_positions_r[i], handle_r);
674
675 const float radius = (radius_index != -1) ?
676 (pt[radius_index] * cdd->radius.range) + cdd->radius.min :
677 radius_max;
678 radii.span[i] = radius;
679
680 handle_types_l[i] = BEZIER_HANDLE_ALIGN;
681 handle_types_r[i] = BEZIER_HANDLE_ALIGN;
682 co += (dims * 3);
683 }
684
685 if (corners_index) {
686 /* ignore the first and last */
687 uint i_start = 0, i_end = corners_index_len;
688
689 if ((corners_index_len >= 2) && !is_cyclic) {
690 i_start += 1;
691 i_end -= 1;
692 }
693
694 for (const auto i : IndexRange(i_start, i_end - i_start)) {
695 const int64_t corner_i = new_points[corners_index[i]];
696 handle_types_l[corner_i] = BEZIER_HANDLE_FREE;
697 handle_types_r[corner_i] = BEZIER_HANDLE_FREE;
698 }
699 }
700
701 radii.finish();
702}
703
706 const CurveDrawData *cdd,
707 const int curve_index,
708 const bool is_cyclic,
709 const uint cubic_spline_len,
710 const int dims,
711 const int radius_index,
712 const float radius_max,
713 const float *cubic_spline)
714{
715 const int point_num = (cubic_spline_len - 2) * 3 + 4 + (is_cyclic ? 2 : 0);
716 curves.resize(curves.points_num() + point_num, curve_index + 1);
717
718 MutableSpan<float3> positions = curves.positions_for_write();
719 MutableSpan<float> weights = curves.nurbs_weights_for_write();
720
721 const IndexRange new_points = curves.points_by_curve()[curve_index];
722
724 "radius", bke::AttrDomain::Point);
725 /* If cyclic shows to first left handle else first control point. */
726 const float *pt = cubic_spline + (is_cyclic ? 0 : dims);
727
728 for (const int64_t i : new_points) {
729 const float radius = (radius_index != -1) ?
730 (pt[radius_index] * cdd->radius.range) + cdd->radius.min :
731 radius_max;
732 copy_v3_v3(positions[i], pt);
733 weights[i] = 1.0f;
734 radii.span[i] = radius;
735
736 pt += dims;
737 }
738
739 radii.finish();
740}
741
743{
744 if (op->customdata == nullptr) {
745 if (!curve_draw_init(C, op, false)) {
746 return OPERATOR_CANCELLED;
747 }
748 }
749
750 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
751
753 Object *obedit = cdd->vc.obedit;
754
755 int stroke_len = BLI_mempool_len(cdd->stroke_elem_pool);
756
757 invert_m4_m4(obedit->runtime->world_to_object.ptr(), obedit->object_to_world().ptr());
758
759 if (BLI_mempool_len(cdd->stroke_elem_pool) == 0) {
761 stroke_len = BLI_mempool_len(cdd->stroke_elem_pool);
762 }
763
764 /* error in object local space */
765 const int fit_method = RNA_enum_get(op->ptr, "fit_method");
766 const float error_threshold = RNA_float_get(op->ptr, "error_threshold");
767 const float corner_angle = RNA_float_get(op->ptr, "corner_angle");
768 const bool use_cyclic = RNA_boolean_get(op->ptr, "use_cyclic");
769 const bool bezier_as_nurbs = RNA_boolean_get(op->ptr, "bezier_as_nurbs");
770 bool is_cyclic = (stroke_len > 2) && use_cyclic;
771
772 const float radius_min = cps->radius_min;
773 const float radius_max = cps->radius_max;
774 const float radius_range = cps->radius_max - cps->radius_min;
775
776 Curves *curves_id = id_cast<Curves *>(obedit->data);
777 bke::CurvesGeometry &curves = curves_id->geometry.wrap();
778 const int curve_index = curves.curves_num();
779
780 const bool use_pressure_radius = (cps->flag & CURVE_PAINT_FLAG_PRESSURE_RADIUS) ||
781 ((cps->radius_taper_start != 0.0f) ||
782 (cps->radius_taper_end != 0.0f));
783
784 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
786 remove_selection_attributes(attributes, selection_attribute_names);
787
788 if (cdd->curve_type == CU_BEZIER) {
789 /* Allow to interpolate multiple channels */
790 int dims = 3;
791 const int radius_index = use_pressure_radius ? dims++ : -1;
792
793 float *coords = MEM_new_array_uninitialized<float>(stroke_len * dims, __func__);
794
795 float *cubic_spline = nullptr;
796 uint cubic_spline_len = 0;
797
798 {
799 BLI_mempool_iter iter;
800 const StrokeElem *selem;
801 float *co = coords;
802
804 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
805 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)), co += dims)
806 {
807 copy_v3_v3(co, selem->location_local);
808 if (radius_index != -1) {
809 co[radius_index] = selem->pressure;
810 }
811
812 /* remove doubles */
813 if ((co != coords) && UNLIKELY(memcmp(co, co - dims, sizeof(float) * dims) == 0)) {
814 co -= dims;
815 stroke_len--;
816 }
817 }
818 }
819
820 uint *corners = nullptr;
821 uint corners_len = 0;
822
823 if ((fit_method == CURVE_PAINT_FIT_METHOD_SPLIT) && (corner_angle < float(M_PI))) {
824 /* this could be configurable... */
825 const float corner_radius_min = error_threshold / 8;
826 const float corner_radius_max = error_threshold * 2;
827 const uint samples_max = 16;
828
829 curve_fit_corners_detect_fl(coords,
830 stroke_len,
831 dims,
832 corner_radius_min,
833 corner_radius_max,
834 samples_max,
835 corner_angle,
836 &corners,
837 &corners_len);
838 }
839
840 uint *corners_index = nullptr;
841 uint corners_index_len = 0;
842 uint calc_flag = CURVE_FIT_CALC_HIGH_QUALITY;
843
844 if ((stroke_len > 2) && use_cyclic) {
845 calc_flag |= CURVE_FIT_CALC_CYCLIC;
846 }
847 else {
848 /* Might need this update if stroke_len <= 2 after removing doubles. */
849 is_cyclic = false;
850 }
851
852 int result;
853 if (fit_method == CURVE_PAINT_FIT_METHOD_REFIT) {
854 result = curve_fit_cubic_to_points_refit_fl(coords,
855 stroke_len,
856 dims,
857 error_threshold,
858 calc_flag,
859 nullptr,
860 0,
861 corner_angle,
862 &cubic_spline,
863 &cubic_spline_len,
864 nullptr,
865 &corners_index,
866 &corners_index_len);
867 }
868 else {
869 result = curve_fit_cubic_to_points_fl(coords,
870 stroke_len,
871 dims,
872 error_threshold,
873 calc_flag,
874 corners,
875 corners_len,
876 &cubic_spline,
877 &cubic_spline_len,
878 nullptr,
879 &corners_index,
880 &corners_index_len);
881 }
882
883 MEM_delete(coords);
884 if (corners) {
885 free(corners);
886 }
887
888 if (result == 0) {
889 int8_t knots_mode;
890 int8_t order;
891 CurveType curve_type;
892 if (bezier_as_nurbs) {
893 bool is_cyclic_curve = calc_flag & CURVE_FIT_CALC_CYCLIC;
895 attributes,
896 cdd,
897 curve_index,
898 is_cyclic_curve,
899 cubic_spline_len,
900 dims,
901 radius_index,
902 radius_max,
903 cubic_spline);
904 order = 4;
905 knots_mode = is_cyclic_curve ? NURBS_KNOT_MODE_BEZIER : NURBS_KNOT_MODE_ENDPOINT_BEZIER;
906 curve_type = CURVE_TYPE_NURBS;
907 }
908 else {
910 attributes,
911 cdd,
912 curve_index,
913 is_cyclic,
914 cubic_spline_len,
915 dims,
916 radius_index,
917 radius_max,
918 cubic_spline,
919 corners_index,
920 corners_index_len);
921 order = 0;
922 knots_mode = 0;
923 curve_type = CURVE_TYPE_BEZIER;
924 }
925 curves.nurbs_knots_modes_for_write()[curve_index] = knots_mode;
926 curves.nurbs_orders_for_write()[curve_index] = order;
927 curves.fill_curve_types(IndexRange(curve_index, 1), curve_type);
928
929 /* If Bezier curve is being added, loop through all three names, otherwise through ones in
930 * `selection_attribute_names`. */
931 for (const StringRef selection_name :
932 (bezier_as_nurbs ? selection_attribute_names :
934 {
935 bke::AttributeWriter<bool> selection = attributes.lookup_or_add_for_write<bool>(
936 selection_name, bke::AttrDomain::Curve);
937 if (selection_name == ".selection" || !bezier_as_nurbs) {
938 selection.varray.set(curve_index, true);
939 }
940 selection.finish();
941 }
942
943 if (attributes.contains("resolution")) {
944 curves.resolution_for_write()[curve_index] = 12;
945 }
947 attributes,
950 "radius",
951 "handle_left",
952 "handle_right",
953 "handle_type_left",
954 "handle_type_right",
955 "nurbs_weight",
956 ".selection",
957 ".selection_handle_left",
958 ".selection_handle_right"}),
959 curves.points_by_curve()[curve_index]);
961 attributes,
964 "resolution",
965 "cyclic",
966 "nurbs_order",
967 "knots_mode",
968 ".selection",
969 ".selection_handle_left",
970 ".selection_handle_right"}),
971 IndexRange(curve_index, 1));
972 }
973
974 if (corners_index) {
975 free(corners_index);
976 }
977
978 if (cubic_spline) {
979 free(cubic_spline);
980 }
981 }
982 else { /* CU_POLY */
983 curves.resize(curves.points_num() + stroke_len, curve_index + 1);
984 curves.fill_curve_types(IndexRange(curve_index, 1), CURVE_TYPE_POLY);
985
986 MutableSpan<float3> positions = curves.positions_for_write();
988 "radius", bke::AttrDomain::Point);
989
990 const IndexRange new_points = curves.points_by_curve()[curve_index];
991
992 IndexRange::Iterator points_iter = new_points.begin();
993
994 BLI_mempool_iter iter;
996 for (const auto *selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
997 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)), points_iter++)
998 {
999 const int64_t i = *points_iter;
1000 copy_v3_v3(positions[i], selem->location_local);
1001 if (cdd->is_curve_2d) {
1002 positions[i][2] = 0.0f;
1003 }
1004
1005 radii.span[i] = use_pressure_radius ? (selem->pressure * radius_range) + radius_min :
1006 cps->radius_max;
1007 }
1008
1009 radii.finish();
1010
1011 bke::AttributeWriter<bool> selection = attributes.lookup_or_add_for_write<bool>(
1012 ".selection", bke::AttrDomain::Curve);
1013 selection.varray.set(curve_index, true);
1014 selection.finish();
1015
1016 /* Creates ".selection_handle_left" and ".selection_handle_right" attributes, otherwise all
1017 * existing Bezier handles would be treated as selected. */
1018 for (const StringRef selection_name : get_curves_bezier_selection_attribute_names(curves)) {
1019 bke::AttributeWriter<bool> selection = attributes.lookup_or_add_for_write<bool>(
1020 selection_name, bke::AttrDomain::Curve);
1021 selection.finish();
1022 }
1023
1025 attributes,
1028 "radius",
1029 ".selection",
1030 ".selection_handle_left",
1031 ".selection_handle_right"}),
1032 new_points);
1034 attributes,
1037 {"curve_type", ".selection", ".selection_handle_left", ".selection_handle_right"}),
1038 IndexRange(curve_index, 1));
1039 }
1040
1041 if (is_cyclic) {
1042 curves.cyclic_for_write()[curve_index] = true;
1043 }
1044
1047
1048 curve_draw_exit(op);
1049
1050 return OPERATOR_FINISHED;
1051}
1052
1054{
1055 if (RNA_struct_property_is_set(op->ptr, "stroke")) {
1056 return curves_draw_exec(C, op);
1057 }
1058
1059 if (!curve_draw_init(C, op, true)) {
1060 return OPERATOR_CANCELLED;
1061 }
1062
1063 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
1064
1066
1067 const bool is_modal = RNA_boolean_get(op->ptr, "wait_for_input");
1068
1069 /* Fallback (in case we can't find the depth on first test). */
1070 {
1071 const float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])};
1072 float center[3];
1073 negate_v3_v3(center, cdd->vc.rv3d->ofs);
1074 ED_view3d_win_to_3d(cdd->vc.v3d, cdd->vc.region, center, mval_fl, cdd->prev.location_world);
1075 copy_v3_v3(cdd->prev.location_world_valid, cdd->prev.location_world);
1076 }
1077
1081
1082 {
1083 View3D *v3d = cdd->vc.v3d;
1084 RegionView3D *rv3d = cdd->vc.rv3d;
1085 Object *obedit = cdd->vc.obedit;
1086
1087 const float *plane_no = nullptr;
1088 const float *plane_co = nullptr;
1089
1090 if (cdd->is_curve_2d) {
1091 /* 2D overrides other options */
1092 plane_co = obedit->object_to_world().location();
1093 plane_no = obedit->object_to_world().ptr()[2];
1094 cdd->project.use_plane = true;
1095 }
1096 else {
1097 if ((cps->depth_mode == CURVE_PAINT_PROJECT_SURFACE) && (v3d->shading.type > OB_WIRE)) {
1098 /* needed or else the draw matrix can be incorrect */
1100
1103 depth_mode = V3D_DEPTH_SELECTED_ONLY;
1104 }
1105
1107 cdd->vc.region,
1108 cdd->vc.v3d,
1109 nullptr,
1110 depth_mode,
1111 false,
1112 &cdd->depths);
1113
1114 if (cdd->depths != nullptr) {
1115 cdd->project.use_depth = true;
1116 }
1117 else {
1118 BKE_report(op->reports, RPT_WARNING, "Unable to access depth buffer, using view plane");
1119 cdd->project.use_depth = false;
1120 }
1121 }
1122
1123 /* use view plane (when set or as a fallback when surface can't be found) */
1124 if (cdd->project.use_depth == false) {
1125 plane_co = cdd->vc.scene->cursor.location;
1126 plane_no = rv3d->viewinv[2];
1127 cdd->project.use_plane = true;
1128 }
1129
1130 if (cdd->project.use_depth && (cdd->curve_type != CU_POLY)) {
1131 cdd->sample.use_substeps = true;
1132 }
1133 }
1134
1135 if (cdd->project.use_plane) {
1136 normalize_v3_v3(cdd->project.plane, plane_no);
1137 cdd->project.plane[3] = -dot_v3v3(cdd->project.plane, plane_co);
1138 }
1139 }
1140
1141 if (is_modal == false) {
1142 curve_draw_event_add_first(op, event);
1143 }
1144
1145 /* add temp handler */
1147
1149}
1150
1151static void curve_draw_cancel(bContext * /*C*/, wmOperator *op)
1152{
1153 curve_draw_exit(op);
1154}
1155
1160{
1161 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
1163 PropertyRNA *prop;
1164
1165 prop = RNA_struct_find_property(op->ptr, "fit_method");
1166 if (!RNA_property_is_set(op->ptr, prop)) {
1167 RNA_property_enum_set(op->ptr, prop, cps->fit_method);
1168 }
1169
1170 prop = RNA_struct_find_property(op->ptr, "corner_angle");
1171 if (!RNA_property_is_set(op->ptr, prop)) {
1172 const float corner_angle = (cps->flag & CURVE_PAINT_FLAG_CORNERS_DETECT) ? cps->corner_angle :
1173 float(M_PI);
1174 RNA_property_float_set(op->ptr, prop, corner_angle);
1175 }
1176
1177 prop = RNA_struct_find_property(op->ptr, "error_threshold");
1178 if (!RNA_property_is_set(op->ptr, prop)) {
1179
1180 /* Error isn't set so we'll have to calculate it from the pixel values. */
1181 BLI_mempool_iter iter;
1182 const StrokeElem *selem, *selem_prev;
1183
1184 float len_3d = 0.0f, len_2d = 0.0f;
1185 float scale_px; /* pixel to local space scale */
1186
1188 selem_prev = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter));
1189 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
1190 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)))
1191 {
1192 len_3d += len_v3v3(selem->location_local, selem_prev->location_local);
1193 len_2d += len_v2v2(selem->mval, selem_prev->mval);
1194 selem_prev = selem;
1195 }
1196 scale_px = ((len_3d > 0.0f) && (len_2d > 0.0f)) ? (len_3d / len_2d) : 0.0f;
1197 float error_threshold = (cps->error_threshold * UI_SCALE_FAC) * scale_px;
1198 RNA_property_float_set(op->ptr, prop, error_threshold);
1199 }
1200
1201 prop = RNA_struct_find_property(op->ptr, "use_cyclic");
1202 if (!RNA_property_is_set(op->ptr, prop)) {
1203 bool use_cyclic = false;
1204
1205 if (BLI_mempool_len(cdd->stroke_elem_pool) > 2) {
1206 BLI_mempool_iter iter;
1207 const StrokeElem *selem, *selem_first, *selem_last;
1208
1210 selem_first = selem_last = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter));
1211 for (selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
1212 selem = static_cast<const StrokeElem *>(BLI_mempool_iterstep(&iter)))
1213 {
1214 selem_last = selem;
1215 }
1216
1217 if (len_squared_v2v2(selem_first->mval, selem_last->mval) <=
1219 {
1220 use_cyclic = true;
1221 }
1222 }
1223
1224 RNA_property_boolean_set(op->ptr, prop, use_cyclic);
1225 }
1226
1227 if ((cps->radius_taper_start != 0.0f) || (cps->radius_taper_end != 0.0f)) {
1228 /* NOTE: we could try to de-duplicate the length calculations above. */
1229 const int stroke_len = BLI_mempool_len(cdd->stroke_elem_pool);
1230
1231 BLI_mempool_iter iter;
1232 StrokeElem *selem, *selem_prev;
1233
1234 float *lengths = MEM_new_array_uninitialized<float>(stroke_len, __func__);
1235 StrokeElem **selem_array = MEM_new_array_uninitialized<StrokeElem *>(stroke_len, __func__);
1236 lengths[0] = 0.0f;
1237
1238 float len_3d = 0.0f;
1239
1240 int i = 1;
1242 selem_prev = static_cast<StrokeElem *>(BLI_mempool_iterstep(&iter));
1243 selem_array[0] = selem_prev;
1244 for (selem = static_cast<StrokeElem *>(BLI_mempool_iterstep(&iter)); selem;
1245 selem = static_cast<StrokeElem *>(BLI_mempool_iterstep(&iter)), i++)
1246 {
1247 const float len_3d_segment = len_v3v3(selem->location_local, selem_prev->location_local);
1248 len_3d += len_3d_segment;
1249 lengths[i] = len_3d;
1250 selem_array[i] = selem;
1251 selem_prev = selem;
1252 }
1253
1254 if (cps->radius_taper_start != 0.0f) {
1255 const float len_taper_max = cps->radius_taper_start * len_3d;
1256 for (i = 0; i < stroke_len && lengths[i] < len_taper_max; i++) {
1257 const float pressure_new = selem_array[i]->pressure * (lengths[i] / len_taper_max);
1258 stroke_elem_pressure_set(cdd, selem_array[i], pressure_new);
1259 }
1260 }
1261
1262 if (cps->radius_taper_end != 0.0f) {
1263 const float len_taper_max = cps->radius_taper_end * len_3d;
1264 const float len_taper_min = len_3d - len_taper_max;
1265 for (i = stroke_len - 1; i > 0 && lengths[i] > len_taper_min; i--) {
1266 const float pressure_new = selem_array[i]->pressure *
1267 ((len_3d - lengths[i]) / len_taper_max);
1268 stroke_elem_pressure_set(cdd, selem_array[i], pressure_new);
1269 }
1270 }
1271
1272 MEM_delete(lengths);
1273 MEM_delete(selem_array);
1274 }
1275}
1276
1278{
1280 CurveDrawData *cdd = static_cast<CurveDrawData *>(op->customdata);
1281
1282 UNUSED_VARS(C, op);
1283
1284 if (event->type == cdd->init_event_type) {
1285 if (event->val == KM_RELEASE) {
1287
1289
1291
1292 curves_draw_exec(C, op);
1293
1294 return OPERATOR_FINISHED;
1295 }
1296 }
1297 else if (ELEM(event->type, EVT_ESCKEY, RIGHTMOUSE)) {
1299 curve_draw_cancel(C, op);
1300 return OPERATOR_CANCELLED;
1301 }
1302 else if (ELEM(event->type, LEFTMOUSE)) {
1303 if (event->val == KM_PRESS) {
1304 curve_draw_event_add_first(op, event);
1305 }
1306 }
1307 else if (ISMOUSE_MOTION(event->type)) {
1308 if (cdd->state == CURVE_DRAW_PAINTING) {
1309 const float mval_fl[2] = {float(event->mval[0]), float(event->mval[1])};
1310 if (len_squared_v2v2(mval_fl, cdd->prev.mval) > square_f(STROKE_SAMPLE_DIST_MIN_PX)) {
1311 curve_draw_event_add(op, event);
1312 }
1313 }
1314 }
1315
1316 return ret;
1317}
1318
1320{
1321 ot->name = "Draw Curves";
1322 ot->idname = __func__;
1323 ot->description = "Draw a freehand curve";
1324
1325 ot->exec = curves_draw_exec;
1329
1330 /* flags */
1332
1333 /* properties */
1334 PropertyRNA *prop;
1335
1336 prop = RNA_def_float_distance(ot->srna,
1337 "error_threshold",
1338 0.0f,
1339 0.0f,
1340 10.0f,
1341 "Error",
1342 "Error distance threshold (in object units)",
1343 0.0001f,
1344 10.0f);
1346 RNA_def_property_ui_range(prop, 0.0, 10, 1, 4);
1347
1348 RNA_def_enum(ot->srna,
1349 "fit_method",
1352 "Fit Method",
1353 "");
1354
1356 ot->srna, "corner_angle", DEG2RADF(70.0f), 0.0f, M_PI, "Corner Angle", "", 0.0f, M_PI);
1358
1359 prop = RNA_def_boolean(ot->srna, "use_cyclic", true, "Cyclic", "");
1361
1362 prop = RNA_def_collection_runtime(ot->srna, "stroke", RNA_OperatorStrokeElement, "Stroke", "");
1364
1365 prop = RNA_def_boolean(ot->srna, "wait_for_input", true, "Wait for Input", "");
1367
1368 prop = RNA_def_boolean(ot->srna, "is_curve_2d", false, "Curve 2D", "");
1370
1371 prop = RNA_def_boolean(ot->srna, "bezier_as_nurbs", false, "As NURBS", "");
1373}
1374
1375} // namespace ed::curves
1376} // namespace blender
Low-level operations for curves.
#define DEG2RADF(_deg)
#define M_PI
#define BLT_I18NCONTEXT_AMOUNT
#define UI_SCALE_FAC
#define REGION_DRAW_POST_VIEW
#define GPU_batch_uniform_3fv(batch, name, val)
Definition GPU_batch.hh:274
#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(...)
constexpr IndexRange()=default
bool contains(StringRef name) const
GAttributeWriter lookup_or_add_for_write(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
GSpanAttributeWriter lookup_or_add_for_write_only_span(StringRef name, AttrDomain domain, AttrType data_type)
#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
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)
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)
__int64 int64_t
Definition BKE_text.h:90
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)
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
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()
void WM_cursor_modal_set(wmWindow *win, int val)
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
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)
void GPU_line_smooth(bool enable)
Definition gpu_state.cc:80
@ GPU_PRIM_LINE_STRIP
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)
const EnumPropertyItem rna_enum_curve_fit_method_items[]
Definition rna_scene.cc:257
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
void immUnbindProgram()
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
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
@ NURBS_KNOT_MODE_ENDPOINT_BEZIER
@ NURBS_KNOT_MODE_BEZIER
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
void BLI_mempool_destroy(BLI_mempool *pool) ATTR_NONNULL(1)
@ 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])
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
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)
Object * CTX_data_edit_object(const bContext *C)
void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
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()
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
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])
@ WM_CURSOR_PAINT_BRUSH
Definition wm_cursors.hh:36
Main * CTX_data_main(const bContext *C)
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)
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ 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)
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)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
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])
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)
signed char int8_t
Definition BKE_text.h:76
void GPU_matrix_push()
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
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
const c_style_mat & ptr() const
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
struct blender::ed::curves::CurveDrawData::@247152145240054336224050301110166375000012104347 sample
struct blender::ed::curves::CurveDrawData::@332173142022203262172216375203276374363372325337 prev
struct blender::ed::curves::CurveDrawData::@100312067132037265017121376345011227346323072053 radius
struct blender::ed::curves::CurveDrawData::@326120374103257003006123022301306212154111126206 project
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
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)