Blender V4.3
view3d_gizmo_forcefield.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
9#include "BLI_utildefines.h"
10
11#include "BKE_context.hh"
12#include "BKE_layer.hh"
13
15#include "DNA_object_types.h"
16
17#include "ED_gizmo_library.hh"
18
19#include "UI_resources.hh"
20
21#include "MEM_guardedalloc.h"
22
23#include "RNA_access.hh"
24#include "RNA_prototypes.hh"
25
26#include "WM_types.hh"
27
28#include "view3d_intern.hh" /* own include */
29
30/* -------------------------------------------------------------------- */
34static bool WIDGETGROUP_forcefield_poll(const bContext *C, wmGizmoGroupType * /*gzgt*/)
35{
36 View3D *v3d = CTX_wm_view3d(C);
37
39 return false;
40 }
42 return false;
43 }
44
45 const Scene *scene = CTX_data_scene(C);
46 ViewLayer *view_layer = CTX_data_view_layer(C);
47 BKE_view_layer_synced_ensure(scene, view_layer);
48 Base *base = BKE_view_layer_active_base_get(view_layer);
49 if (base && BASE_SELECTABLE(v3d, base)) {
50 Object *ob = base->object;
51 if (ob->pd && ob->pd->forcefield) {
52 return true;
53 }
54 }
55 return false;
56}
57
58static void WIDGETGROUP_forcefield_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup)
59{
60 /* only wind effector for now */
61 wmGizmoWrapper *wwrapper = static_cast<wmGizmoWrapper *>(
62 MEM_mallocN(sizeof(wmGizmoWrapper), __func__));
63 gzgroup->customdata = wwrapper;
64
65 wwrapper->gizmo = WM_gizmo_new("GIZMO_GT_arrow_3d", gzgroup, nullptr);
66 wmGizmo *gz = wwrapper->gizmo;
68 ED_gizmo_arrow3d_set_ui_range(gz, -200.0f, 200.0f);
70
73
74 /* All gizmos must perform undo. */
75 LISTBASE_FOREACH (wmGizmo *, gz_iter, &gzgroup->gizmos) {
77 }
78}
79
81{
82 wmGizmoWrapper *wwrapper = static_cast<wmGizmoWrapper *>(gzgroup->customdata);
83 wmGizmo *gz = wwrapper->gizmo;
84 const Scene *scene = CTX_data_scene(C);
85 ViewLayer *view_layer = CTX_data_view_layer(C);
86 BKE_view_layer_synced_ensure(scene, view_layer);
88 PartDeflect *pd = ob->pd;
89
90 if (pd->forcefield == PFIELD_WIND) {
91 const float size = (ob->type == OB_EMPTY) ? ob->empty_drawsize : 1.0f;
92 const float ofs[3] = {0.0f, -size, 0.0f};
93
94 PointerRNA field_ptr = RNA_pointer_create(&ob->id, &RNA_FieldSettings, pd);
95 WM_gizmo_set_matrix_location(gz, ob->object_to_world().location());
96 WM_gizmo_set_matrix_rotation_from_z_axis(gz, ob->object_to_world().ptr()[2]);
99 WM_gizmo_target_property_def_rna(gz, "offset", &field_ptr, "strength", -1);
100 }
101 else {
103 }
104}
105
119
Scene * CTX_data_scene(const bContext *C)
View3D * CTX_wm_view3d(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
Base * BKE_view_layer_active_base_get(ViewLayer *view_layer)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
#define LISTBASE_FOREACH(type, var, list)
Object is a sort of wrapper for general info.
@ OB_EMPTY
#define BASE_SELECTABLE(v3d, base)
@ V3D_GIZMO_HIDE
@ V3D_GIZMO_HIDE_CONTEXT
@ V3D_GIZMO_SHOW_EMPTY_FORCE_FIELD
@ ED_GIZMO_ARROW_XFORM_FLAG_CONSTRAINED
Read Guarded memory(de)allocation.
void UI_GetThemeColor3fv(int colorid, float col[3])
@ TH_GIZMO_HI
@ TH_GIZMO_PRIMARY
@ WM_GIZMO_HIDDEN
@ WM_GIZMO_NEEDS_UNDO
@ WM_GIZMOGROUPTYPE_SCALE
@ WM_GIZMOGROUPTYPE_DEPTH_3D
@ WM_GIZMOGROUPTYPE_3D
@ WM_GIZMOGROUPTYPE_PERSISTENT
void ED_gizmo_arrow3d_set_range_fac(wmGizmo *gz, const float range_fac)
void ED_gizmo_arrow3d_set_ui_range(wmGizmo *gz, const float min, const float max)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
void *(* MEM_mallocN)(size_t len, const char *str)
Definition mallocn.cc:44
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
PointerRNA RNA_pointer_create(ID *id, StructRNA *type, void *data)
struct Object * object
struct PartDeflect * pd
float empty_drawsize
char gizmo_show_empty
wmGizmoGroupFnSetupKeymap setup_keymap
wmGizmoGroupFnRefresh refresh
wmGizmoGroupFnInit setup
const char * idname
eWM_GizmoFlagGroupTypeFlag flag
wmGizmoGroupFnPoll poll
float color_hi[4]
float color[4]
PointerRNA * ptr
static bool WIDGETGROUP_forcefield_poll(const bContext *C, wmGizmoGroupType *)
static void WIDGETGROUP_forcefield_refresh(const bContext *C, wmGizmoGroup *gzgroup)
static void WIDGETGROUP_forcefield_setup(const bContext *, wmGizmoGroup *gzgroup)
void VIEW3D_GGT_force_field(wmGizmoGroupType *gzgt)
void WM_gizmo_set_matrix_offset_location(wmGizmo *gz, const float offset[3])
Definition wm_gizmo.cc:298
wmGizmo * WM_gizmo_new(const char *idname, wmGizmoGroup *gzgroup, PointerRNA *properties)
Definition wm_gizmo.cc:94
void WM_gizmo_set_matrix_location(wmGizmo *gz, const float origin[3])
Definition wm_gizmo.cc:283
void WM_gizmo_set_flag(wmGizmo *gz, const int flag, const bool enable)
Definition wm_gizmo.cc:303
void WM_gizmo_set_matrix_rotation_from_z_axis(wmGizmo *gz, const float z_axis[3])
Definition wm_gizmo.cc:273
wmKeyMap * WM_gizmogroup_setup_keymap_generic_maybe_drag(const wmGizmoGroupType *, wmKeyConfig *kc)
void WM_gizmo_target_property_def_rna(wmGizmo *gz, const char *idname, PointerRNA *ptr, const char *propname, int index)