Blender V5.0
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
8
9#include "BLI_listbase.h"
10
11#include "BKE_context.hh"
12#include "BKE_layer.hh"
13#include "BKE_lib_id.hh"
14
16#include "DNA_object_types.h"
17
18#include "ED_gizmo_library.hh"
19
20#include "UI_resources.hh"
21
22#include "MEM_guardedalloc.h"
23
24#include "RNA_access.hh"
25#include "RNA_prototypes.hh"
26
27#include "WM_types.hh"
28
29#include "view3d_intern.hh" /* own include */
30
31/* -------------------------------------------------------------------- */
34
36{
37 View3D *v3d = CTX_wm_view3d(C);
38
40 return false;
41 }
43 return false;
44 }
45
46 const Scene *scene = CTX_data_scene(C);
47 ViewLayer *view_layer = CTX_data_view_layer(C);
48 BKE_view_layer_synced_ensure(scene, view_layer);
49 Base *base = BKE_view_layer_active_base_get(view_layer);
50 if (base && BASE_SELECTABLE(v3d, base)) {
51 const Object *ob = base->object;
52 if (ob->pd && ob->pd->forcefield) {
54 return true;
55 }
56 }
57 }
58 return false;
59}
60
61static void WIDGETGROUP_forcefield_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup)
62{
63 /* only wind effector for now */
64 wmGizmoWrapper *wwrapper = MEM_mallocN<wmGizmoWrapper>(__func__);
65 gzgroup->customdata = wwrapper;
66
67 wwrapper->gizmo = WM_gizmo_new("GIZMO_GT_arrow_3d", gzgroup, nullptr);
68 wmGizmo *gz = wwrapper->gizmo;
70 ED_gizmo_arrow3d_set_ui_range(gz, -200.0f, 200.0f);
72
75
76 /* All gizmos must perform undo. */
77 LISTBASE_FOREACH (wmGizmo *, gz_iter, &gzgroup->gizmos) {
79 }
80}
81
83{
84 wmGizmoWrapper *wwrapper = static_cast<wmGizmoWrapper *>(gzgroup->customdata);
85 wmGizmo *gz = wwrapper->gizmo;
86 const Scene *scene = CTX_data_scene(C);
87 ViewLayer *view_layer = CTX_data_view_layer(C);
88 BKE_view_layer_synced_ensure(scene, view_layer);
90 PartDeflect *pd = ob->pd;
91
92 if (pd->forcefield == PFIELD_WIND) {
93 const float size = (ob->type == OB_EMPTY) ? ob->empty_drawsize : 1.0f;
94 const float ofs[3] = {0.0f, -size, 0.0f};
95
96 PointerRNA field_ptr = RNA_pointer_create_discrete(&ob->id, &RNA_FieldSettings, pd);
97 WM_gizmo_set_matrix_location(gz, ob->object_to_world().location());
98 WM_gizmo_set_matrix_rotation_from_z_axis(gz, ob->object_to_world().ptr()[2]);
101 WM_gizmo_target_property_def_rna(gz, "offset", &field_ptr, "strength", -1);
102 }
103 else {
105 }
106}
107
121
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(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)
bool BKE_id_is_editable(const Main *bmain, const ID *id)
Definition lib_id.cc:2523
#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.
#define C
Definition RandGen.cpp:29
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:128
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
PointerRNA RNA_pointer_create_discrete(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:302
void WM_gizmo_set_matrix_location(wmGizmo *gz, const float origin[3])
Definition wm_gizmo.cc:287
void WM_gizmo_set_flag(wmGizmo *gz, const int flag, const bool enable)
Definition wm_gizmo.cc:307
void WM_gizmo_set_matrix_rotation_from_z_axis(wmGizmo *gz, const float z_axis[3])
Definition wm_gizmo.cc:277
wmGizmo * WM_gizmo_new(const StringRef idname, wmGizmoGroup *gzgroup, PointerRNA *properties)
Definition wm_gizmo.cc:98
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)