Blender V5.3
view3d_placement.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
13
14#include "MEM_guardedalloc.h"
15
16#include "BLI_math_geom_c.hh"
17#include "BLI_math_matrix_c.hh"
19
20#include "BKE_context.hh"
21#include "BKE_lib_id.hh"
22#include "BKE_modifier.hh"
23#include "BKE_paint.hh"
24#include "BKE_screen.hh"
25
26#include "BLT_translation.hh"
27
28#include "RNA_access.hh"
29#include "RNA_define.hh"
30
31#include "WM_api.hh"
32#include "WM_toolsystem.hh"
33
34#include "ED_gizmo_utils.hh"
35#include "ED_screen.hh"
36#include "ED_space_api.hh"
37#include "ED_view3d.hh"
38
39#include "UI_resources.hh"
40
41#include "GPU_immediate.hh"
42#include "GPU_state.hh"
43
44#include "view3d_intern.hh"
45
46namespace blender {
47
48static const char *view3d_gzgt_placement_id = "VIEW3D_GGT_placement";
49
55static const float eps_view_align = 1e-2f;
56
57/* -------------------------------------------------------------------- */
60
69
74
79
83};
84
86 /* Window manager variables (set these even when waiting for input). */
91
94
95 float co_src[3];
96
98 struct {
110 float plane[4];
111 float co_dst[3];
112
131 float degenerate_diagonal[3];
137
141 int degenerate_axis;
142
143 } step[2];
144
146 float view_plane[4];
147
148 float matrix_orient[3][3];
150
153 float snap_co[3];
154
157
159
162
165
168
169 /* WORKAROUND: We need to remove #SCE_SNAP_TO_GRID temporarily. */
172};
173
175
176/* -------------------------------------------------------------------- */
179
184 const float plane[4],
185 const float mval[2],
186 const float *plane_fallback,
187 float r_out[3])
188{
189 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
190 bool do_clip = rv3d->is_persp;
191 if (plane_fallback != nullptr) {
193 region, plane, mval, do_clip, plane_fallback, r_out);
194 }
195 return ED_view3d_win_to_3d_on_plane(region, plane, mval, do_clip, r_out);
196}
197
201static int dot_v3_array_find_max_index(const float dirs[][3],
202 const int dirs_len,
203 const float dir_test[3],
204 bool is_signed)
205{
206 int index_found = -1;
207 float dot_best = -1.0f;
208 for (int i = 0; i < dirs_len; i++) {
209 float dot_test = dot_v3v3(dirs[i], dir_test);
210 if (is_signed == false) {
211 dot_test = fabsf(dot_test);
212 }
213 if ((index_found == -1) || (dot_test > dot_best)) {
214 dot_best = dot_test;
215 index_found = i;
216 }
217 }
218 return index_found;
219}
220
222 idp_gizmogroup_from_region)(ARegion *region)
223{
224 wmGizmoMap *gzmap = region->runtime->gizmo_map;
225 return gzmap ? WM_gizmomap_group_find(gzmap, view3d_gzgt_placement_id) : nullptr;
226}
227
234 Scene *scene, View3D *v3d, ARegion *region, const float co_relative[3], float co[3])
235{
236 const float grid_size = ED_view3d_grid_view_scale(scene, v3d, region, nullptr);
237 if (grid_size == 0.0f) [[unlikely]] {
238 return false;
239 }
240
242 co_relative = nullptr;
243 }
244
245 if (co_relative != nullptr) {
246 sub_v3_v3(co, co_relative);
247 }
248 mul_v3_fl(co, 1.0f / grid_size);
249 co[0] = roundf(co[0]);
250 co[1] = roundf(co[1]);
251 co[2] = roundf(co[2]);
252 mul_v3_fl(co, grid_size);
253 if (co_relative != nullptr) {
254 add_v3_v3(co, co_relative);
255 }
256
257 return true;
258}
259
261
262/* -------------------------------------------------------------------- */
265
266static void draw_line_loop(const float coords[][3], int coords_len, const float color[4])
267{
268 GPUVertFormat *format = immVertexFormat();
269 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
270
271 gpu::VertBuf *vert = GPU_vertbuf_create_with_format(*format);
272 GPU_vertbuf_data_alloc(*vert, coords_len);
273
274 for (int i = 0; i < coords_len; i++) {
275 GPU_vertbuf_attr_set(vert, pos, i, coords[i]);
276 }
277
279 gpu::Batch *batch = GPU_batch_create_ex(GPU_PRIM_LINE_LOOP, vert, nullptr, GPU_BATCH_OWNS_VBO);
281
282 GPU_batch_uniform_4fv(batch, "color", color);
283
284 float viewport[4];
285 GPU_viewport_size_get_f(viewport);
286 GPU_batch_uniform_2fv(batch, "viewportSize", &viewport[2]);
287 GPU_batch_uniform_1f(batch, "lineWidth", U.pixelsize);
288
289 GPU_batch_draw(batch);
290
291 GPU_batch_discard(batch);
293}
294
295static void draw_line_pairs(const float coords_a[][3],
296 float coords_b[][3],
297 int coords_len,
298 const float color[4])
299{
300 GPUVertFormat *format = immVertexFormat();
301 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
302
303 gpu::VertBuf *vert = GPU_vertbuf_create_with_format(*format);
304 GPU_vertbuf_data_alloc(*vert, coords_len * 2);
305
306 for (int i = 0; i < coords_len; i++) {
307 GPU_vertbuf_attr_set(vert, pos, i * 2, coords_a[i]);
308 GPU_vertbuf_attr_set(vert, pos, (i * 2) + 1, coords_b[i]);
309 }
310
312 gpu::Batch *batch = GPU_batch_create_ex(GPU_PRIM_LINES, vert, nullptr, GPU_BATCH_OWNS_VBO);
314
315 GPU_batch_uniform_4fv(batch, "color", color);
316
317 float viewport[4];
318 GPU_viewport_size_get_f(viewport);
319 GPU_batch_uniform_2fv(batch, "viewportSize", &viewport[2]);
320 GPU_batch_uniform_1f(batch, "lineWidth", U.pixelsize);
321
322 GPU_batch_draw(batch);
323
324 GPU_batch_discard(batch);
326}
327
328static void draw_line_bounds(const BoundBox *bounds, const float color[4])
329{
330 GPUVertFormat *format = immVertexFormat();
331 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
332
333 const int edges[12][2] = {
334 /* First side. */
335 {0, 1},
336 {1, 2},
337 {2, 3},
338 {3, 0}, /* Second side. */
339 {4, 5},
340 {5, 6},
341 {6, 7},
342 {7, 4}, /* Edges between. */
343 {0, 4},
344 {1, 5},
345 {2, 6},
346 {3, 7},
347 };
348
349 gpu::VertBuf *vert = GPU_vertbuf_create_with_format(*format);
350 GPU_vertbuf_data_alloc(*vert, ARRAY_SIZE(edges) * 2);
351
352 for (int i = 0, j = 0; i < ARRAY_SIZE(edges); i++) {
353 GPU_vertbuf_attr_set(vert, pos, j++, bounds->vec[edges[i][0]]);
354 GPU_vertbuf_attr_set(vert, pos, j++, bounds->vec[edges[i][1]]);
355 }
356
358 gpu::Batch *batch = GPU_batch_create_ex(GPU_PRIM_LINES, vert, nullptr, GPU_BATCH_OWNS_VBO);
360
361 GPU_batch_uniform_4fv(batch, "color", color);
362
363 float viewport[4];
364 GPU_viewport_size_get_f(viewport);
365 GPU_batch_uniform_2fv(batch, "viewportSize", &viewport[2]);
366 GPU_batch_uniform_1f(batch, "lineWidth", U.pixelsize);
367
368 GPU_batch_draw(batch);
369
370 GPU_batch_discard(batch);
372}
373
375{
376 *bounds = BoundBox{};
377
378 if (compare_v3v3(ipd->co_src, ipd->step[0].co_dst, FLT_EPSILON)) {
379 return false;
380 }
381
382 float matrix_orient_inv[3][3];
383 invert_m3_m3(matrix_orient_inv, ipd->matrix_orient);
384
385 const int x_axis = (ipd->orient_axis + 1) % 3;
386 const int y_axis = (ipd->orient_axis + 2) % 3;
387
388 float quad_base[4][3];
389 float quad_secondary[4][3];
390
391 copy_v3_v3(quad_base[0], ipd->co_src);
392 copy_v3_v3(quad_base[2], ipd->step[0].co_dst);
393
394 /* Only set when we have a fixed aspect. */
395 float fixed_aspect_dimension;
396
397 /* *** Primary *** */
398
399 {
400 float delta_local[3];
401 float delta_a[3];
402 float delta_b[3];
403
404 sub_v3_v3v3(delta_local, ipd->step[0].co_dst, ipd->co_src);
405 mul_m3_v3(matrix_orient_inv, delta_local);
406
407 copy_v3_v3(delta_a, delta_local);
408 copy_v3_v3(delta_b, delta_local);
409 delta_a[ipd->orient_axis] = 0.0f;
410 delta_b[ipd->orient_axis] = 0.0f;
411
412 delta_a[x_axis] = 0.0f;
413 delta_b[y_axis] = 0.0f;
414
415 /* Assign here in case secondary. */
416 fixed_aspect_dimension = max_ff(fabsf(delta_a[y_axis]), fabsf(delta_b[x_axis]));
417
418 if (ipd->step[0].is_fixed_aspect) {
419 delta_a[y_axis] = copysignf(fixed_aspect_dimension, delta_a[y_axis]);
420 delta_b[x_axis] = copysignf(fixed_aspect_dimension, delta_b[x_axis]);
421 }
422
423 mul_m3_v3(ipd->matrix_orient, delta_a);
424 mul_m3_v3(ipd->matrix_orient, delta_b);
425
426 if (ipd->step[0].is_fixed_aspect) {
427 /* Recalculate the destination point. */
428 copy_v3_v3(quad_base[2], ipd->co_src);
429 add_v3_v3(quad_base[2], delta_a);
430 add_v3_v3(quad_base[2], delta_b);
431 }
432
433 add_v3_v3v3(quad_base[1], ipd->co_src, delta_a);
434 add_v3_v3v3(quad_base[3], ipd->co_src, delta_b);
435 }
436
437 if (ipd->step[0].is_centered) {
438 /* Use a copy in case aspect was applied to the quad. */
439 float base_co_dst[3];
440 copy_v3_v3(base_co_dst, quad_base[2]);
441 for (int i = 0; i < ARRAY_SIZE(quad_base); i++) {
442 sub_v3_v3(quad_base[i], base_co_dst);
443 mul_v3_fl(quad_base[i], 2.0f);
444 add_v3_v3(quad_base[i], base_co_dst);
445 }
446 fixed_aspect_dimension *= 2.0f;
447 }
448
449 /* *** Secondary *** */
450
451 float delta_local[3];
452 if (ipd->step_index == STEP_DEPTH) {
453 sub_v3_v3v3(delta_local, ipd->step[1].co_dst, ipd->step[0].co_dst);
454 }
455 else {
456 zero_v3(delta_local);
457 }
458
459 if (ipd->step[1].is_fixed_aspect) {
460 if (!is_zero_v3(delta_local)) {
461 normalize_v3_length(delta_local, fixed_aspect_dimension);
462 }
463 }
464
465 if (ipd->step[1].is_centered) {
466 float temp_delta[3];
467 if (ipd->step[1].is_fixed_aspect) {
468 mul_v3_v3fl(temp_delta, delta_local, 0.5f);
469 }
470 else {
471 copy_v3_v3(temp_delta, delta_local);
472 mul_v3_fl(delta_local, 2.0f);
473 }
474
475 for (int i = 0; i < ARRAY_SIZE(quad_base); i++) {
476 sub_v3_v3(quad_base[i], temp_delta);
477 }
478 }
479
480 if ((ipd->step_index == STEP_DEPTH) &&
481 (compare_v3v3(ipd->step[0].co_dst, ipd->step[1].co_dst, FLT_EPSILON) == false))
482 {
483
484 for (int i = 0; i < ARRAY_SIZE(quad_base); i++) {
485 add_v3_v3v3(quad_secondary[i], quad_base[i], delta_local);
486 }
487 }
488 else {
489 copy_v3_v3(quad_secondary[0], quad_base[0]);
490 copy_v3_v3(quad_secondary[1], quad_base[1]);
491 copy_v3_v3(quad_secondary[2], quad_base[2]);
492 copy_v3_v3(quad_secondary[3], quad_base[3]);
493 }
494
495 for (int i = 0; i < 4; i++) {
496 copy_v3_v3(bounds->vec[i], quad_base[i]);
497 copy_v3_v3(bounds->vec[i + 4], quad_secondary[i]);
498 }
499
500 return true;
501}
502
503static void draw_circle_in_quad(const float v1[3],
504 const float v2[3],
505 const float v3[3],
506 const float v4[3],
507 const int resolution,
508 const float color[4])
509{
510 /* This isn't so efficient. */
511 const float quad[4][2] = {
512 {-1, -1},
513 {+1, -1},
514 {+1, +1},
515 {-1, +1},
516 };
517
518 float (*coords)[3] = MEM_new_array_uninitialized<float[3]>(resolution + 1, __func__);
519 for (int i = 0; i <= resolution; i++) {
520 float theta = ((2.0f * M_PI) * (float(i) / float(resolution))) + 0.01f;
521 float x = cosf(theta);
522 float y = sinf(theta);
523 const float pt[2] = {x, y};
524 float w[4];
526
527 float *co = coords[i];
528 zero_v3(co);
529 madd_v3_v3fl(co, v1, w[0]);
530 madd_v3_v3fl(co, v2, w[1]);
531 madd_v3_v3fl(co, v3, w[2]);
532 madd_v3_v3fl(co, v4, w[3]);
533 }
534 draw_line_loop(coords, resolution + 1, color);
535 MEM_delete(coords);
536}
537
539
540/* -------------------------------------------------------------------- */
543
546 const float color[4],
547 int flatten_axis)
548{
549 UNUSED_VARS(C);
550
552 calc_bbox(ipd, &bounds);
553
554 /* Use cavalier projection, since it maps the scale usefully to the cursor. */
555 if (flatten_axis == STEP_BASE) {
556 /* Calculate the plane that would be defined by the side of the cube vertices
557 * if the plane had any volume. */
558
559 float no[3];
560
562 no, ipd->matrix_orient[ipd->orient_axis], ipd->matrix_orient[(ipd->orient_axis + 1) % 3]);
563
564 RegionView3D *rv3d = static_cast<RegionView3D *>(ipd->region->regiondata);
565 copy_v3_v3(no, rv3d->viewinv[2]);
566 normalize_v3(no);
567
568 float base_plane[4];
569
570 plane_from_point_normal_v3(base_plane, bounds.vec[0], no);
571
572 /* Offset all vertices even though we only need to offset the half of them.
573 * This is harmless as `dist` will be zero for the `base_plane` aligned side of the cube. */
574 for (int i = 0; i < ARRAY_SIZE(bounds.vec); i++) {
575 const float dist = dist_signed_to_plane_v3(bounds.vec[i], base_plane);
576 madd_v3_v3fl(bounds.vec[i], base_plane, -dist);
577 madd_v3_v3fl(bounds.vec[i], ipd->step[STEP_BASE].degenerate_diagonal_display, dist);
578 }
579 }
580
581 if (flatten_axis == STEP_DEPTH) {
582 const float *base_plane = ipd->step[0].plane;
583 for (int i = 0; i < 4; i++) {
584 const float dist = dist_signed_to_plane_v3(bounds.vec[i + 4], base_plane);
585 madd_v3_v3fl(bounds.vec[i + 4], base_plane, -dist);
586 madd_v3_v3fl(bounds.vec[i + 4], ipd->step[STEP_DEPTH].degenerate_diagonal_display, dist);
587 }
588 }
589
591
593 /* pass */
594 }
598 }
599 else if (ipd->primitive_type == PLACE_PRIMITIVE_TYPE_CONE) {
601
602 float center[3];
603 mid_v3_v3v3v3v3(center, UNPACK4(&bounds.vec[4]));
604
605 float coords_a[4][3];
606 float coords_b[4][3];
607
608 for (int i = 0; i < 4; i++) {
609 copy_v3_v3(coords_a[i], center);
610 mid_v3_v3v3(coords_b[i], bounds.vec[i], bounds.vec[(i + 1) % 4]);
611 }
612
613 draw_line_pairs(coords_a, coords_b, 4, color);
614 }
615 else if (ELEM(ipd->primitive_type,
619 {
620 /* See bound-box diagram for reference. */
621
622 /* Primary Side. */
623 float v01[3], v12[3], v23[3], v30[3];
624 mid_v3_v3v3(v01, bounds.vec[0], bounds.vec[1]);
625 mid_v3_v3v3(v12, bounds.vec[1], bounds.vec[2]);
626 mid_v3_v3v3(v23, bounds.vec[2], bounds.vec[3]);
627 mid_v3_v3v3(v30, bounds.vec[3], bounds.vec[0]);
628 /* Secondary Side. */
629 float v45[3], v56[3], v67[3], v74[3];
630 mid_v3_v3v3(v45, bounds.vec[4], bounds.vec[5]);
631 mid_v3_v3v3(v56, bounds.vec[5], bounds.vec[6]);
632 mid_v3_v3v3(v67, bounds.vec[6], bounds.vec[7]);
633 mid_v3_v3v3(v74, bounds.vec[7], bounds.vec[4]);
634 /* Edges between. */
635 float v04[3], v15[3], v26[3], v37[3];
636 mid_v3_v3v3(v04, bounds.vec[0], bounds.vec[4]);
637 mid_v3_v3v3(v15, bounds.vec[1], bounds.vec[5]);
638 mid_v3_v3v3(v26, bounds.vec[2], bounds.vec[6]);
639 mid_v3_v3v3(v37, bounds.vec[3], bounds.vec[7]);
640
641 draw_circle_in_quad(v01, v45, v67, v23, 32, color);
642 draw_circle_in_quad(v30, v12, v56, v74, 32, color);
643 draw_circle_in_quad(v04, v15, v26, v37, 32, color);
644 }
645}
646
647static void draw_primitive_view(const bContext *C, ARegion * /*region*/, void *arg)
648{
649 InteractivePlaceData *ipd = static_cast<InteractivePlaceData *>(arg);
650 float color[4];
652
653 const bool use_depth = !XRAY_ENABLED(ipd->v3d);
654 const GPUDepthTest depth_test_enabled = GPU_depth_test_get();
655
656 if (use_depth) {
658 color[3] = 0.15f;
660 }
661
662 /* Show a flattened projection if the current step is aligned to the view. */
663 if (ipd->step[ipd->step_index].is_degenerate_view_align) {
664 const RegionView3D *rv3d = static_cast<const RegionView3D *>(ipd->region->regiondata);
665 if (!rv3d->is_persp) {
667 }
668 }
669
670 if (use_depth) {
672 }
673 color[3] = 1.0f;
675
676 if (use_depth) {
677 if (depth_test_enabled == false) {
679 }
680 }
681}
682
684
685/* -------------------------------------------------------------------- */
690
692 const wmEvent * /*event*/,
693 float r_co_src[3],
694 float r_matrix_orient[3][3],
695 bool *r_is_enabled,
696 bool *r_is_snap_invert)
697{
699 copy_v3_v3(r_co_src, snap_data->loc);
700 if (r_matrix_orient) {
701 copy_m3_m3(r_matrix_orient, snap_data->plane_omat);
702 }
703 if (r_is_enabled) {
704 *r_is_enabled = snap_data->is_enabled;
705 }
706 if (r_is_snap_invert) {
707 *r_is_snap_invert = snap_data->is_snap_invert;
708 }
709 return snap_data->type_target != SCE_SNAP_TO_NONE;
710}
711
713
714/* -------------------------------------------------------------------- */
717
719{
721 ToolSettings *tool_settings = CTX_data_tool_settings(C);
722
723 const int plane_axis = tool_settings->plane_axis;
724
725 const enum ePlace_Origin plane_origin[2] = {
726 ePlace_Origin(RNA_enum_get(op->ptr, "plane_origin_base")),
727 ePlace_Origin(RNA_enum_get(op->ptr, "plane_origin_depth")),
728 };
729 const enum ePlace_Aspect plane_aspect[2] = {
730 ePlace_Aspect(RNA_enum_get(op->ptr, "plane_aspect_base")),
731 ePlace_Aspect(RNA_enum_get(op->ptr, "plane_aspect_depth")),
732 };
733
734 InteractivePlaceData *ipd = static_cast<InteractivePlaceData *>(op->customdata);
735
737
739 if (snap_state_new) {
740 ipd->snap_state = snap_state = snap_state_new;
741
742 /* For drag events, update the location since it will be set from the drag-start.
743 * This is needed as cursor-drawing doesn't deal with drag events and will use
744 * the current cursor location instead of the drag-start. */
745 if (event->val == KM_PRESS_DRAG) {
746 /* Set this flag so snapping always updated. */
747 int mval[2];
748 WM_event_drag_start_mval(event, ipd->region, mval);
749
750 /* Be sure to also compute the #V3DSnapCursorData.plane_omat. */
751 snap_state->draw_plane = true;
752
753 ED_view3d_cursor_snap_data_update(snap_state_new, C, ipd->region, mval);
754 }
755 }
756
757 snap_state->draw_point = true;
758 snap_state->draw_plane = true;
759 ipd->is_snap_found =
761 C, event, ipd->co_src, ipd->matrix_orient, &ipd->use_snap, &ipd->is_snap_invert) != 0;
762
763 snap_state->draw_plane = false;
765
766 ipd->orient_axis = plane_axis;
767 for (int i = 0; i < 2; i++) {
768 ipd->step[i].is_centered_init = (plane_origin[i] == PLACE_ORIGIN_CENTER);
769 ipd->step[i].is_centered = ipd->step[i].is_centered_init;
770
771 ipd->step[i].is_fixed_aspect_init = (plane_aspect[i] == PLACE_ASPECT_FIXED);
772 ipd->step[i].is_fixed_aspect = ipd->step[i].is_fixed_aspect_init;
773 }
774
775 ipd->step_index = STEP_BASE;
776
777 ipd->snap_to_ptr = &tool_settings->snap_mode_tools;
778 if (*ipd->snap_to_ptr == SCE_SNAP_TO_NONE) {
779 ipd->snap_to_ptr = &tool_settings->snap_mode;
780 }
781 ipd->snap_to_restore = *ipd->snap_to_ptr;
782
783 plane_from_point_normal_v3(ipd->step[0].plane, ipd->co_src, ipd->matrix_orient[plane_axis]);
784
785 copy_v3_v3(ipd->step[0].co_dst, ipd->co_src);
786
787 {
788 RegionView3D *rv3d = static_cast<RegionView3D *>(ipd->region->regiondata);
789 const float view_axis_dot = fabsf(dot_v3v3(rv3d->viewinv[2], ipd->matrix_orient[plane_axis]));
790 ipd->step[STEP_BASE].is_degenerate_view_align = view_axis_dot < eps_view_align;
791 ipd->step[STEP_DEPTH].is_degenerate_view_align = fabsf(view_axis_dot - 1.0f) < eps_view_align;
792
793 float view_axis[3];
794 normalize_v3_v3(view_axis, rv3d->viewinv[2]);
795 plane_from_point_normal_v3(ipd->view_plane, ipd->co_src, view_axis);
796 }
797
798 if (ipd->step[STEP_BASE].is_degenerate_view_align ||
799 ipd->step[STEP_DEPTH].is_degenerate_view_align)
800 {
801 RegionView3D *rv3d = static_cast<RegionView3D *>(ipd->region->regiondata);
802 float axis_view[3];
803 add_v3_v3v3(axis_view, rv3d->viewinv[0], rv3d->viewinv[1]);
804 normalize_v3(axis_view);
805
806 /* Setup fallback axes. */
807 for (int i = 0; i < 2; i++) {
808 if (ipd->step[i].is_degenerate_view_align) {
809 const int degenerate_axis =
810 (i == STEP_BASE) ?
811 /* For #STEP_BASE find the orient axis that align to the view. */
812 dot_v3_array_find_max_index(ipd->matrix_orient, 3, rv3d->viewinv[2], false) :
813 /* For #STEP_DEPTH the orient axis is always view aligned when degenerate. */
814 ipd->orient_axis;
815
816 float axis_fallback[4][3];
817 const int x_axis = (degenerate_axis + 1) % 3;
818 const int y_axis = (degenerate_axis + 2) % 3;
819
820 /* Assign 4x diagonal axes, find which one is closest to the viewport diagonal
821 * bottom left to top right, for a predictable direction from a user perspective. */
822 add_v3_v3v3(axis_fallback[0], ipd->matrix_orient[x_axis], ipd->matrix_orient[y_axis]);
823 sub_v3_v3v3(axis_fallback[1], ipd->matrix_orient[x_axis], ipd->matrix_orient[y_axis]);
824 negate_v3_v3(axis_fallback[2], axis_fallback[0]);
825 negate_v3_v3(axis_fallback[3], axis_fallback[1]);
826
827 const int axis_best = dot_v3_array_find_max_index(axis_fallback, 4, axis_view, true);
828 normalize_v3_v3(ipd->step[i].degenerate_diagonal, axis_fallback[axis_best]);
829 ipd->step[i].degenerate_axis = degenerate_axis;
830
831 /* `degenerate_view_plane_fallback` is used to map cursor motion from a view aligned
832 * plane back onto the view aligned plane.
833 *
834 * The dot product check below ensures cursor motion
835 * isn't inverted from a user perspective. */
836 const bool degenerate_axis_is_flip = dot_v3v3(ipd->matrix_orient[degenerate_axis],
837 ((i == STEP_BASE) ?
838 ipd->step[i].degenerate_diagonal :
839 rv3d->viewinv[2])) < 0.0f;
840
841 copy_v3_v3(ipd->step[i].degenerate_diagonal_display, ipd->step[i].degenerate_diagonal);
842 if (degenerate_axis_is_flip) {
843 negate_v3(ipd->step[i].degenerate_diagonal_display);
844 }
845 }
846 }
847 }
848
851
853
854 /* Setup the primitive type. */
855 {
856 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "primitive_type");
857 if (RNA_property_is_set(op->ptr, prop)) {
859 ipd->use_tool = false;
860 }
861 else {
862 ipd->use_tool = true;
863
864 /* Get from the tool, a bit of a non-standard way of operating. */
865 const bToolRef *tref = ipd->area->runtime.tool;
866 if (tref && STREQ(tref->idname, "builtin.primitive_cube_add")) {
868 }
869 else if (tref && STREQ(tref->idname, "builtin.primitive_cylinder_add")) {
871 }
872 else if (tref && STREQ(tref->idname, "builtin.primitive_cone_add")) {
874 }
875 else if (tref && STREQ(tref->idname, "builtin.primitive_uv_sphere_add")) {
877 }
878 else if (tref && STREQ(tref->idname, "builtin.primitive_ico_sphere_add")) {
880 }
881 else if (tref && STREQ(tref->idname, "builtin.primitive_quad_sphere_add")) {
883 }
884 else {
885 /* If the user runs this as an operator they should set the 'primitive_type',
886 * however running from operator search will end up at this point. */
888 ipd->use_tool = false;
889 }
890 }
891 }
892}
893
894enum {
901};
902
904{
905 InteractivePlaceData *ipd = static_cast<InteractivePlaceData *>(op->customdata);
906 WorkspaceStatus status(C);
907 status.item(ipd->step_index == STEP_BASE ? IFACE_("Define Base") : IFACE_("Define Depth"),
908 ICON_MOUSE_MOVE);
909 status.item(IFACE_("Cancel"), ICON_EVENT_ESC);
910 status.opmodal(IFACE_("Fixed Aspect"),
911 op->type,
913 ipd->step[ipd->step_index].is_fixed_aspect);
914 status.opmodal(IFACE_("Center Pivot"),
915 op->type,
917 ipd->step[ipd->step_index].is_centered);
918 status.opmodal(IFACE_("Snap"), op->type, PLACE_MODAL_SNAP_ON, ipd->use_snap);
919}
920
922 wmOperator *op,
923 const wmEvent *event)
924{
925 const bool wait_for_input = RNA_boolean_get(op->ptr, "wait_for_input");
926
928 op->customdata = ipd;
929
930 ipd->scene = CTX_data_scene(C);
931 ipd->area = CTX_wm_area(C);
932 ipd->region = CTX_wm_region(C);
933 ipd->v3d = CTX_wm_view3d(C);
934
935 if (wait_for_input) {
936 ipd->wait_for_input = true;
937/* TODO: support snapping when not using with tool. */
938#if 0
940#endif
941 }
942 else {
944 }
945
947
949
951}
952
954{
955 UNUSED_VARS(C);
956
957 InteractivePlaceData *ipd = static_cast<InteractivePlaceData *>(op->customdata);
959
960 if (ipd->region != nullptr) {
961 if (ipd->draw_handle_view != nullptr) {
963 }
965 }
966
968
969 MEM_delete(ipd);
970}
971
976
978{
979 static const EnumPropertyItem modal_items[] = {
980 {PLACE_MODAL_SNAP_ON, "SNAP_ON", 0, "Snap On", ""},
981 {PLACE_MODAL_SNAP_OFF, "SNAP_OFF", 0, "Snap Off", ""},
982 {PLACE_MODAL_FIXED_ASPECT_ON, "FIXED_ASPECT_ON", 0, "Fixed Aspect On", ""},
983 {PLACE_MODAL_FIXED_ASPECT_OFF, "FIXED_ASPECT_OFF", 0, "Fixed Aspect Off", ""},
984 {PLACE_MODAL_PIVOT_CENTER_ON, "PIVOT_CENTER_ON", 0, "Center Pivot On", ""},
985 {PLACE_MODAL_PIVOT_CENTER_OFF, "PIVOT_CENTER_OFF", 0, "Center Pivot Off", ""},
986 {0, nullptr, 0, nullptr, nullptr},
987 };
988
989 const char *keymap_name = "View3D Placement Modal";
990 wmKeyMap *keymap = WM_modalkeymap_find(keyconf, keymap_name);
991
992 /* This function is called for each space-type, only needs to add map once. */
993 if (keymap && keymap->modal_items) {
994 return;
995 }
996
997 keymap = WM_modalkeymap_ensure(keyconf, keymap_name, modal_items);
998
999 WM_modalkeymap_assign(keymap, "VIEW3D_OT_interactive_add");
1000}
1001
1003 wmOperator *op,
1004 const wmEvent *event)
1005{
1006 UNUSED_VARS(C, op);
1007
1008 InteractivePlaceData *ipd = static_cast<InteractivePlaceData *>(op->customdata);
1009
1010 ARegion *region = ipd->region;
1011 bool do_redraw = false;
1012 bool do_cursor_update = false;
1013
1014 /* Handle modal key-map. */
1015 if (event->type == EVT_MODAL_MAP) {
1016 bool is_fallthrough = false;
1017 switch (event->val) {
1019 is_fallthrough = true;
1021 }
1023 ipd->step[ipd->step_index].is_fixed_aspect =
1024 is_fallthrough ^ ipd->step[ipd->step_index].is_fixed_aspect_init;
1025 do_redraw = true;
1026 break;
1027 }
1029 is_fallthrough = true;
1031 }
1033 ipd->step[ipd->step_index].is_centered = is_fallthrough ^
1034 ipd->step[ipd->step_index].is_centered_init;
1035 do_redraw = true;
1036 break;
1037 }
1038 case PLACE_MODAL_SNAP_ON: {
1039 is_fallthrough = true;
1041 }
1042 case PLACE_MODAL_SNAP_OFF: {
1043 const ToolSettings *ts = ipd->scene->toolsettings;
1044 ipd->is_snap_invert = is_fallthrough;
1045 ipd->use_snap = (ipd->is_snap_invert == !(ts->snap_flag & SCE_SNAP));
1046 do_cursor_update = true;
1047 break;
1048 }
1049 }
1050 }
1051 else {
1052 switch (event->type) {
1053 case EVT_ESCKEY:
1054 case RIGHTMOUSE: {
1055 /* Restore snap mode. */
1056 *ipd->snap_to_ptr = ipd->snap_to_restore;
1058 return OPERATOR_CANCELLED;
1059 }
1060 case MOUSEMOVE: {
1061 do_cursor_update = true;
1062 break;
1063 }
1064 default: {
1065 break;
1066 }
1067 }
1068 }
1069
1070 if (ipd->wait_for_input) {
1071 if (ELEM(event->type, LEFTMOUSE)) {
1072 if (event->val == KM_PRESS) {
1073 view3d_interactive_add_begin(C, op, event);
1074 ipd->wait_for_input = false;
1076 }
1077 }
1079 }
1080
1081 if (ipd->step_index == STEP_BASE) {
1082 if (ELEM(event->type, ipd->launch_event, LEFTMOUSE)) {
1083 if (event->val == KM_RELEASE) {
1085 if (ipd->snap_to_restore & SCE_SNAP_TO_GRID) {
1086 /* Don't snap to grid in #STEP_DEPTH. */
1088 }
1089
1090 /* Set secondary plane. */
1091
1092 /* Create normal. */
1093 {
1094 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
1095 float no[3], no_temp[3];
1096
1097 if (ipd->step[STEP_DEPTH].is_degenerate_view_align) {
1098 cross_v3_v3v3(no_temp, ipd->step[0].plane, ipd->step[STEP_DEPTH].degenerate_diagonal);
1099 cross_v3_v3v3(no, no_temp, ipd->step[0].plane);
1100 }
1101 else {
1102 cross_v3_v3v3(no_temp, ipd->step[0].plane, rv3d->viewinv[2]);
1103 cross_v3_v3v3(no, no_temp, ipd->step[0].plane);
1104 }
1105 normalize_v3(no);
1106
1107 plane_from_point_normal_v3(ipd->step[1].plane, ipd->step[0].co_dst, no);
1108 }
1109
1110 copy_v3_v3(ipd->step[1].co_dst, ipd->step[0].co_dst);
1111 ipd->step_index = STEP_DEPTH;
1112
1113 /* Use the toggle from the previous step. */
1114 if (ipd->step[0].is_centered != ipd->step[0].is_centered_init) {
1115 ipd->step[1].is_centered = !ipd->step[1].is_centered;
1116 }
1117 if (ipd->step[0].is_fixed_aspect != ipd->step[0].is_fixed_aspect_init) {
1118 ipd->step[1].is_fixed_aspect = !ipd->step[1].is_fixed_aspect;
1119 }
1120 }
1121 }
1122 }
1123 else if (ipd->step_index == STEP_DEPTH) {
1124 if (ELEM(event->type, ipd->launch_event, LEFTMOUSE)) {
1125 if (event->val == KM_PRESS) {
1126 /* Restore snap mode. */
1127 *ipd->snap_to_ptr = ipd->snap_to_restore;
1128
1129 /* Confirm. */
1131 calc_bbox(ipd, &bounds);
1132
1133 float location[3];
1134 float rotation[3];
1135 float scale[3];
1136
1137 float matrix_orient_axis[3][3];
1138 copy_m3_m3(matrix_orient_axis, ipd->matrix_orient);
1139 if (ipd->orient_axis != 2) {
1140 swap_v3_v3(matrix_orient_axis[2], matrix_orient_axis[ipd->orient_axis]);
1141 swap_v3_v3(matrix_orient_axis[0], matrix_orient_axis[1]);
1142 }
1143 /* Needed for shapes where the sign matters (cone for eg). */
1144 {
1145 float delta[3];
1146 sub_v3_v3v3(delta, bounds.vec[0], bounds.vec[4]);
1147 if (dot_v3v3(ipd->matrix_orient[ipd->orient_axis], delta) > 0.0f) {
1148 negate_v3(matrix_orient_axis[2]);
1149
1150 /* Only flip Y so we don't flip a single axis which causes problems. */
1151 negate_v3(matrix_orient_axis[1]);
1152 }
1153 }
1154
1155 mat3_to_eul(rotation, matrix_orient_axis);
1156
1157 mid_v3_v3v3(location, bounds.vec[0], bounds.vec[6]);
1158 const int cube_verts[3] = {3, 1, 4};
1159 for (int i = 0; i < 3; i++) {
1160 scale[i] = len_v3v3(bounds.vec[0], bounds.vec[cube_verts[i]]);
1161 /* Primitives have size 2 by default, compensate for this here. */
1162 scale[i] /= 2.0f;
1163 }
1164
1165 wmOperatorType *ot = nullptr;
1167 ot = WM_operatortype_find("MESH_OT_primitive_cube_add", false);
1168 }
1170 ot = WM_operatortype_find("MESH_OT_primitive_cylinder_add", false);
1171 }
1172 else if (ipd->primitive_type == PLACE_PRIMITIVE_TYPE_CONE) {
1173 ot = WM_operatortype_find("MESH_OT_primitive_cone_add", false);
1174 }
1176 ot = WM_operatortype_find("MESH_OT_primitive_uv_sphere_add", false);
1177 }
1179 ot = WM_operatortype_find("MESH_OT_primitive_ico_sphere_add", false);
1180 }
1182 ot = WM_operatortype_find("MESH_OT_primitive_quad_sphere_add", false);
1183 }
1184 if (ot != nullptr) {
1186
1187 if (ipd->use_tool) {
1188 bToolRef *tref = ipd->area->runtime.tool;
1189 PointerRNA temp_props;
1190 WM_toolsystem_ref_properties_init_for_keymap(tref, &temp_props, &op_props, ot);
1191 std::swap(temp_props, op_props);
1192 WM_operator_properties_free(&temp_props);
1193 }
1194
1195 RNA_float_set_array(&op_props, "rotation", rotation);
1196 RNA_float_set_array(&op_props, "location", location);
1197 RNA_float_set_array(&op_props, "scale", scale);
1198
1199 /* Always use the defaults here since desired bounds have been set interactively, it does
1200 * not make sense to use a different values from a previous command. */
1202 RNA_float_set(&op_props, "size", 2.0f);
1203 }
1204 if (ELEM(ipd->primitive_type,
1209 {
1210 RNA_float_set(&op_props, "radius", 1.0f);
1211 }
1213 {
1214 RNA_float_set(&op_props, "depth", 2.0f);
1215 }
1217 RNA_float_set(&op_props, "radius1", 1.0f);
1218 RNA_float_set(&op_props, "radius2", 0.0f);
1219 }
1220
1222 WM_operator_properties_free(&op_props);
1223 }
1224 else {
1225 BLI_assert(0);
1226 }
1227
1229 return OPERATOR_FINISHED;
1230 }
1231 }
1232 }
1233 else {
1234 BLI_assert(0);
1235 }
1236
1237 if (do_cursor_update) {
1238 float mval_fl[2];
1239 WM_event_drag_start_mval_fl(event, region, mval_fl);
1240
1241 /* Calculate the snap location on mouse-move or when toggling snap. */
1242 ipd->is_snap_found = false;
1243 if (ipd->use_snap) {
1245 C, event, ipd->snap_co, nullptr, nullptr, nullptr);
1246 }
1247
1248 if (ipd->step_index == STEP_BASE) {
1249 if (ipd->is_snap_found) {
1251 ipd->step[STEP_BASE].co_dst, ipd->step[STEP_BASE].plane, ipd->snap_co);
1252 }
1253 else {
1255 region,
1256 ipd->step[STEP_BASE].plane,
1257 mval_fl,
1258 ipd->step[STEP_BASE].is_degenerate_view_align ? ipd->view_plane : nullptr,
1259 ipd->step[STEP_BASE].co_dst))
1260 {
1261 /* pass */
1262 }
1263
1266 ipd->scene, ipd->v3d, ipd->region, ipd->co_src, ipd->step[STEP_BASE].co_dst))
1267 {
1268 }
1269 }
1270 }
1271 }
1272 else if (ipd->step_index == STEP_DEPTH) {
1273 if (ipd->is_snap_found) {
1275 ipd->step[STEP_DEPTH].co_dst, ipd->step[STEP_DEPTH].plane, ipd->snap_co);
1276 }
1277 else {
1279 region,
1280 ipd->step[STEP_DEPTH].plane,
1281 mval_fl,
1282 ipd->step[STEP_DEPTH].is_degenerate_view_align ? ipd->view_plane : nullptr,
1283 ipd->step[STEP_DEPTH].co_dst))
1284 {
1285 /* pass */
1286 }
1287
1290 ipd->scene, ipd->v3d, ipd->region, ipd->co_src, ipd->step[STEP_DEPTH].co_dst))
1291 {
1292 }
1293 }
1294 }
1295
1296 /* Correct the point so it's aligned with the 'ipd->step[0].co_dst'. */
1297 float close[3], delta[3];
1299 close, ipd->step[STEP_BASE].plane, ipd->step[STEP_DEPTH].co_dst);
1300 sub_v3_v3v3(delta, close, ipd->step[STEP_BASE].co_dst);
1301 sub_v3_v3(ipd->step[STEP_DEPTH].co_dst, delta);
1302 }
1303 do_redraw = true;
1304 }
1305
1306 if (do_redraw) {
1307 ED_region_tag_redraw(region);
1309 }
1310
1312}
1313
1315{
1316 const enum eContextObjectMode mode = CTX_data_mode_enum(C);
1317
1318 if (mode == CTX_MODE_SCULPT) {
1322 }
1323
1325}
1326
1328{
1329 /* identifiers */
1330 ot->name = "Add Primitive Object";
1331 ot->description = "Interactively add an object";
1332 ot->idname = "VIEW3D_OT_interactive_add";
1333
1334 /* API callbacks. */
1339
1340 /* NOTE: let the operator we call handle undo and registering itself. */
1341 /* flags */
1342 ot->flag = 0;
1343
1344 /* properties */
1345 PropertyRNA *prop;
1346
1347 /* Normally not accessed directly, leave unset and check the active tool. */
1348 static const EnumPropertyItem primitive_type[] = {
1349 {PLACE_PRIMITIVE_TYPE_CUBE, "CUBE", 0, "Cube", ""},
1350 {PLACE_PRIMITIVE_TYPE_CYLINDER, "CYLINDER", 0, "Cylinder", ""},
1351 {PLACE_PRIMITIVE_TYPE_CONE, "CONE", 0, "Cone", ""},
1352 {PLACE_PRIMITIVE_TYPE_SPHERE_UV, "SPHERE_UV", 0, "UV Sphere", ""},
1353 {PLACE_PRIMITIVE_TYPE_SPHERE_ICO, "SPHERE_ICO", 0, "ICO Sphere", ""},
1354 {PLACE_PRIMITIVE_TYPE_SPHERE_QUAD, "SPHERE_QUAD", 0, "Quad Sphere", ""},
1355 {0, nullptr, 0, nullptr, nullptr},
1356 };
1357
1358 prop = RNA_def_property(ot->srna, "primitive_type", PROP_ENUM, PROP_NONE);
1359 RNA_def_property_ui_text(prop, "Primitive", "");
1360 RNA_def_property_enum_items(prop, primitive_type);
1362
1363 { /* Plane Origin. */
1364 static const EnumPropertyItem items[] = {
1365 {PLACE_ORIGIN_BASE, "EDGE", 0, "Edge", "Start placing the edge position"},
1366 {PLACE_ORIGIN_CENTER, "CENTER", 0, "Center", "Start placing the center position"},
1367 {0, nullptr, 0, nullptr, nullptr},
1368 };
1369 const char *identifiers[2] = {"plane_origin_base", "plane_origin_depth"};
1370 for (int i = 0; i < 2; i++) {
1371 prop = RNA_def_property(ot->srna, identifiers[i], PROP_ENUM, PROP_NONE);
1372 RNA_def_property_ui_text(prop, "Origin", "The initial position for placement");
1374 RNA_def_property_enum_items(prop, items);
1376 }
1377 }
1378
1379 { /* Plane Aspect. */
1380 static const EnumPropertyItem items[] = {
1381 {PLACE_ASPECT_FREE, "FREE", 0, "Free", "Use an unconstrained aspect"},
1382 {PLACE_ASPECT_FIXED, "FIXED", 0, "Fixed", "Use a fixed 1:1 aspect"},
1383 {0, nullptr, 0, nullptr, nullptr},
1384 };
1385 const char *identifiers[2] = {"plane_aspect_base", "plane_aspect_depth"};
1386 for (int i = 0; i < 2; i++) {
1387 prop = RNA_def_property(ot->srna, identifiers[i], PROP_ENUM, PROP_NONE);
1388 RNA_def_property_ui_text(prop, "Aspect", "The initial aspect setting");
1390 RNA_def_property_enum_items(prop, items);
1392 }
1393 }
1394
1395 /* When not accessed via a tool. */
1396 prop = RNA_def_boolean(ot->srna, "wait_for_input", true, "Wait for Input", "");
1398}
1399
1401
1402/* -------------------------------------------------------------------- */
1408
1409static void preview_plane_free_fn(void *customdata)
1410{
1411 V3DSnapCursorState *snap_state = static_cast<V3DSnapCursorState *>(customdata);
1413}
1414
1415static bool snap_cursor_poll(ARegion *region, void *data)
1416{
1418 static_cast<wmGizmoGroupType *>(data)) == nullptr)
1419 {
1420 /* Wrong viewport. */
1421 return false;
1422 }
1423 return true;
1424}
1425
1426static void WIDGETGROUP_placement_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup)
1427{
1429 if (snap_state) {
1430 snap_state->poll = snap_cursor_poll;
1431 snap_state->poll_data = gzgroup->type;
1432 snap_state->draw_plane = true;
1433
1434 gzgroup->customdata = snap_state;
1436 }
1437}
1438
1440{
1442 const Scene *scene = CTX_data_scene(C);
1443 if (BKE_id_is_editable(CTX_data_main(C), &scene->id)) {
1444 return true;
1445 }
1446 }
1447 return false;
1448}
1449
1463
1465
1466} // namespace blender
#define ATTR_FALLTHROUGH
#define M_PI
#define IFACE_(msgid)
#define REGION_DRAW_POST_VIEW
#define XRAY_ENABLED(v3d)
#define GPU_batch_uniform_1f(batch, name, x)
Definition GPU_batch.hh:267
#define GPU_batch_uniform_2fv(batch, name, val)
Definition GPU_batch.hh:273
#define GPU_batch_uniform_4fv(batch, name, val)
Definition GPU_batch.hh:275
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UNPACK4(a)
#define UNUSED_VARS(...)
#define ELEM(...)
#define STREQ(a, b)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
void item(std::string text, int icon1, int icon2=0)
Definition area.cc:1076
void opmodal(std::string text, const wmOperatorType *ot, int propvalue, bool inverted=false)
Definition area.cc:1107
#define copysignf(x, y)
#define roundf(x)
#define FLT_EPSILON
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
float3x3 scale(float3x3 mat, float2 scale)
void get_color_3fv(int colorid, float col[3])
BMesh Iterators.
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static bool view3d_interactive_add_calc_snap(bContext *, const wmEvent *, float r_co_src[3], float r_matrix_orient[3][3], bool *r_is_enabled, bool *r_is_snap_invert)
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)
void mul_m3_v3(const float M[3][3], float r[3])
ScrArea * CTX_wm_area(const bContext *C)
static const char * view3d_gzgt_placement_id
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
int RNA_enum_get(PointerRNA *ptr, const char *name)
void WM_event_drag_start_mval_fl(const wmEvent *event, const ARegion *region, float r_mval[2])
gpu::Batch * GPU_batch_create_ex(GPUPrimType primitive_type, gpu::VertBuf *vertex_buf, gpu::IndexBuf *index_buf, GPUBatchFlag owns_flag)
Definition gpu_batch.cc:53
void RNA_def_property_enum_default(PropertyRNA *prop, int value)
@ PLACE_PRIMITIVE_TYPE_CONE
@ PLACE_PRIMITIVE_TYPE_CUBE
@ PLACE_PRIMITIVE_TYPE_SPHERE_UV
@ PLACE_PRIMITIVE_TYPE_CYLINDER
@ PLACE_PRIMITIVE_TYPE_SPHERE_ICO
@ PLACE_PRIMITIVE_TYPE_SPHERE_QUAD
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
V3DSnapCursorState * ED_view3d_cursor_snap_state_create()
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition wm_keymap.cc:999
bool BKE_object_sculpt_use_dyntopo(const Object *object)
void mid_v3_v3v3v3v3(float v[3], const float v1[3], const float v2[3], const float v3[3], const float v4[3])
MultiresModifierData * BKE_sculpt_multires_active(const Scene *scene, Object *ob)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
static void preview_plane_free_fn(void *customdata)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
V3DSnapCursorState * ED_view3d_cursor_snap_state_active_get()
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
GPUDepthTest GPU_depth_test_get()
Definition gpu_state.cc:229
static wmOperatorStatus view3d_interactive_add_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void copy_m3_m3(float m1[3][3], const float m2[3][3])
void WM_operator_properties_free(PointerRNA *ptr)
bool invert_m3_m3(float inverse[3][3], const float mat[3][3])
float dist_signed_to_plane_v3(const float p[3], const float plane[4])
Definition math_geom.cc:511
GPUVertFormat * immVertexFormat()
static bool view3d_interactive_add_poll(bContext *C)
static bool snap_cursor_poll(ARegion *region, void *data)
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
static bool calc_bbox(InteractivePlaceData *ipd, BoundBox *bounds)
static void draw_line_bounds(const BoundBox *bounds, const float color[4])
PointerRNA WM_operator_properties_create_ptr(wmOperatorType *ot)
@ GPU_PRIM_LINE_LOOP
void GPU_batch_discard(gpu::Batch *batch)
enum eContextObjectMode CTX_data_mode_enum(const bContext *C)
static void view3d_interactive_add_status(wmOperator *op, bContext *C)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
void closest_to_plane_normalized_v3(float r_close[3], const float plane[4], const float pt[3])
Definition math_geom.cc:458
void plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3])
Definition math_geom.cc:225
@ CTX_MODE_SCULPT
@ CTX_MODE_EDIT_MESH
@ CTX_MODE_OBJECT
MINLINE void mul_v3_fl(float r[3], float f)
static const float eps_view_align
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
static void draw_line_pairs(const float coords_a[][3], float coords_b[][3], int coords_len, const float color[4])
MINLINE void sub_v3_v3(float r[3], const float a[3])
V3DSnapCursorData * ED_view3d_cursor_snap_data_get()
static bool idp_snap_calc_incremental(Scene *scene, View3D *v3d, ARegion *region, const float co_relative[3], float co[3])
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
void * ED_region_draw_cb_activate(ARegionType *art, void(*draw)(const bContext *, ARegion *, void *), void *customdata, int type)
static UNUSED_FUNCTION_WITH_RETURN_TYPE(wmGizmoGroup *, idp_gizmogroup_from_region)(ARegion *region)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
static void draw_circle_in_quad(const float v1[3], const float v2[3], const float v3[3], const float v4[3], const int resolution, const float color[4])
void ED_view3d_cursor_snap_state_free(V3DSnapCursorState *state)
static void view3d_interactive_add_begin(bContext *C, wmOperator *op, const wmEvent *event)
static void draw_primitive_view(const bContext *C, ARegion *, void *arg)
@ 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)
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 GPU_viewport_size_get_f(float coords[4])
Definition gpu_state.cc:258
MINLINE void swap_v3_v3(float a[3], float b[3])
static void view3d_interactive_add_exit(bContext *C, wmOperator *op)
BMesh const char void * data
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 GPU_vertbuf_attr_set(gpu::VertBuf *, uint a_idx, uint v_idx, const void *data)
@ GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR
void VIEW3D_GGT_placement(wmGizmoGroupType *gzgt)
float ED_view3d_grid_view_scale(const Scene *scene, const View3D *v3d, const ARegion *region, const char **r_grid_unit)
void barycentric_weights_v2_quad(const float v1[2], const float v2[2], const float v3[2], const float v4[2], const float co[2], float w[4])
void viewplace_modal_keymap(wmKeyConfig *keyconf)
void mat3_to_eul(float eul[3], const float mat[3][3])
wmGizmoGroup * WM_gizmomap_group_find_ptr(wmGizmoMap *gzmap, const wmGizmoGroupType *gzgt)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
MINLINE void negate_v3(float r[3])
static wmOperatorStatus view3d_interactive_add_modal(bContext *C, wmOperator *op, const wmEvent *event)
void GPU_batch_draw(gpu::Batch *batch)
@ GPU_BATCH_OWNS_VBO
Definition GPU_batch.hh:44
void ED_view3d_cursor_snap_data_update(V3DSnapCursorState *state, const bContext *C, const ARegion *region, const int2 &mval)
ToolSettings * CTX_data_tool_settings(const bContext *C)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
MINLINE void zero_v3(float r[3])
static bool WIDGETGROUP_placement_poll(const bContext *C, wmGizmoGroupType *gzgt)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
static int dot_v3_array_find_max_index(const float dirs[][3], const int dirs_len, const float dir_test[3], bool is_signed)
void WM_event_drag_start_mval(const wmEvent *event, const ARegion *region, int r_mval[2])
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
void GPU_batch_program_set_builtin(gpu::Batch *batch, GPUBuiltinShader shader_id)
static void WIDGETGROUP_placement_setup(const bContext *, wmGizmoGroup *gzgroup)
MINLINE float normalize_v3_v3(float r[3], const float a[3])
void ED_view3d_cursor_snap_state_prevpoint_set(V3DSnapCursorState *state, const float prev_point[3])
@ WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL
@ WM_GIZMOGROUPTYPE_SCALE
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
static void draw_primitive_view_impl(const bContext *C, InteractivePlaceData *ipd, const float color[4], int flatten_axis)
MINLINE float normalize_v3(float n[3])
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void WM_toolsystem_ref_properties_init_for_keymap(bToolRef *tref, PointerRNA *dst_ptr, PointerRNA *src_ptr, wmOperatorType *ot)
MINLINE void add_v3_v3(float r[3], const float a[3])
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
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])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
bool WM_gizmo_group_type_ensure(const StringRef idname)
MINLINE bool compare_v3v3(const float v1[3], const float v2[3], float limit) ATTR_WARN_UNUSED_RESULT
Main * CTX_data_main(const bContext *C)
@ PLACE_MODAL_PIVOT_CENTER_OFF
@ PLACE_MODAL_FIXED_ASPECT_ON
@ PLACE_MODAL_FIXED_ASPECT_OFF
@ PLACE_MODAL_PIVOT_CENTER_ON
ATTR_WARN_UNUSED_RESULT const BMVert * v2
void VIEW3D_OT_interactive_add(wmOperatorType *ot)
MINLINE float max_ff(float a, float b)
MINLINE float normalize_v3_length(float n[3], float unit_length)
static void draw_line_loop(const float coords[][3], int coords_len, const float color[4])
static bool view3d_win_to_3d_on_plane_maybe_fallback(const ARegion *region, const float plane[4], const float mval[2], const float *plane_fallback, float r_out[3])
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
wmGizmoGroup * WM_gizmomap_group_find(wmGizmoMap *gzmap, const char *idname)
@ KM_PRESS_DRAG
Definition WM_types.hh:332
@ KM_RELEASE
Definition WM_types.hh:325
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
bool ED_view3d_win_to_3d_on_plane_with_fallback(const ARegion *region, const float plane[4], const float mval[2], bool do_clip, const float plane_fallback[4], float r_out[3])
Scene * CTX_data_scene(const bContext *C)
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition wm_keymap.cc:972
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
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
bool ED_gizmo_poll_or_unlink_delayed_from_tool(const bContext *C, wmGizmoGroupType *gzgt)
int WM_userdef_event_type_from_keymap_type(int kmitype)
bool BKE_id_is_editable(const Main *bmain, const ID *id)
Definition lib_id.cc:2782
void GPU_depth_test(GPUDepthTest test)
Definition gpu_state.cc:70
Object * CTX_data_active_object(const bContext *C)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
ARegion * CTX_wm_region(const bContext *C)
void ED_workspace_status_text(bContext *C, const char *str)
Definition area.cc:1153
static void view3d_interactive_add_cancel(bContext *C, wmOperator *op)
MINLINE bool is_zero_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
View3D * CTX_wm_view3d(const bContext *C)
#define fabsf
#define sinf
#define cosf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bke::ARegionRuntime * runtime
enum ePlace_PrimType primitive_type
struct blender::InteractivePlaceData::@262236072047070366215036140021023227272173351323 step[2]
struct ToolSettings * toolsettings
ScrArea_Runtime runtime
bool(*) poll(ARegion *region, void *custom_poll_data)
Definition ED_view3d.hh:380
struct ARegionType * type
wmEventType type
Definition WM_types.hh:817
wmGizmoMapType_Params gzmap_params
eWM_GizmoFlagGroupTypeFlag flag
wmGizmoGroupType * type
void(*) customdata_free(void *)
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
struct wmOperatorType * type