Blender V5.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
8
9#include "BLI_listbase.hh"
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
31namespace blender {
32
33/* -------------------------------------------------------------------- */
36
38{
39 View3D *v3d = CTX_wm_view3d(C);
40
42 return false;
43 }
45 return false;
46 }
47
48 const Main *bmain = CTX_data_main(C);
49 const Scene *scene = CTX_data_scene(C);
50 ViewLayer *view_layer = CTX_data_view_layer(C);
51 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
52 Base *base = BKE_view_layer_active_base_get(view_layer);
53 if (base && BASE_SELECTABLE(v3d, base)) {
54 const Object *ob = base->object;
55 if (ob->pd && ob->pd->forcefield) {
57 return true;
58 }
59 }
60 }
61 return false;
62}
63
64static void WIDGETGROUP_forcefield_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup)
65{
66 /* only wind effector for now */
68 gzgroup->customdata = wwrapper;
69
70 wwrapper->gizmo = WM_gizmo_new("GIZMO_GT_arrow_3d", gzgroup, nullptr);
71 wmGizmo *gz = wwrapper->gizmo;
73 ED_gizmo_arrow3d_set_ui_range(gz, -200.0f, 200.0f);
75
78
79 /* All gizmos must perform undo. */
80 for (wmGizmo &gz_iter : gzgroup->gizmos) {
82 }
83}
84
86{
87 wmGizmoWrapper *wwrapper = static_cast<wmGizmoWrapper *>(gzgroup->customdata);
88 wmGizmo *gz = wwrapper->gizmo;
89 const Main *bmain = CTX_data_main(C);
90 const Scene *scene = CTX_data_scene(C);
91 ViewLayer *view_layer = CTX_data_view_layer(C);
92 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
94 PartDeflect *pd = ob->pd;
95
96 if (pd->forcefield == PFIELD_WIND) {
97 const float size = (ob->type == OB_EMPTY) ? ob->empty_drawsize : 1.0f;
98 const float ofs[3] = {0.0f, -size, 0.0f};
99
100 PointerRNA field_ptr = RNA_pointer_create_discrete(&ob->id, RNA_FieldSettings, pd);
101 WM_gizmo_set_matrix_location(gz, ob->object_to_world().location());
102 WM_gizmo_set_matrix_rotation_from_z_axis(gz, ob->object_to_world().ptr()[2]);
105 WM_gizmo_target_property_def_rna(gz, "offset", &field_ptr, "strength", -1);
106 }
107 else {
109 }
110}
111
125
127
128} // namespace blender
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
void get_color_3fv(int colorid, float col[3])
BMesh Iterators.
void WM_gizmo_set_matrix_rotation_from_z_axis(wmGizmo *gz, const float z_axis[3])
Definition wm_gizmo.cc:273
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void ED_gizmo_arrow3d_set_range_fac(wmGizmo *gz, const float range_fac)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
void VIEW3D_GGT_force_field(wmGizmoGroupType *gzgt)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
Base * BKE_view_layer_active_base_get(ViewLayer *view_layer)
void WM_gizmo_set_matrix_offset_location(wmGizmo *gz, const float offset[3])
Definition wm_gizmo.cc:298
ViewLayer * CTX_data_view_layer(const bContext *C)
void WM_gizmo_target_property_def_rna(wmGizmo *gz, const char *idname, PointerRNA *ptr, const char *propname, int index)
void WM_gizmo_set_flag(wmGizmo *gz, const int flag, const bool enable)
Definition wm_gizmo.cc:303
@ ED_GIZMO_ARROW_XFORM_FLAG_CONSTRAINED
static void WIDGETGROUP_forcefield_setup(const bContext *, wmGizmoGroup *gzgroup)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
wmGizmo * WM_gizmo_new(const StringRef idname, wmGizmoGroup *gzgroup, PointerRNA *properties)
Definition wm_gizmo.cc:97
@ V3D_GIZMO_SHOW_EMPTY_FORCE_FIELD
@ WM_GIZMOGROUPTYPE_DEPTH_3D
@ WM_GIZMOGROUPTYPE_PERSISTENT
@ WM_GIZMOGROUPTYPE_SCALE
@ WM_GIZMO_NEEDS_UNDO
Main * CTX_data_main(const bContext *C)
void ED_gizmo_arrow3d_set_ui_range(wmGizmo *gz, const float min, const float max)
static bool WIDGETGROUP_forcefield_poll(const bContext *C, wmGizmoGroupType *)
Scene * CTX_data_scene(const bContext *C)
wmKeyMap * WM_gizmogroup_setup_keymap_generic_maybe_drag(const wmGizmoGroupType *, wmKeyConfig *kc)
void WM_gizmo_set_matrix_location(wmGizmo *gz, const float origin[3])
Definition wm_gizmo.cc:283
bool BKE_id_is_editable(const Main *bmain, const ID *id)
Definition lib_id.cc:2782
View3D * CTX_wm_view3d(const bContext *C)
static void WIDGETGROUP_forcefield_refresh(const bContext *C, wmGizmoGroup *gzgroup)
struct Object * object
struct PartDeflect * pd
eView3D_GizmoShowEmpty gizmo_show_empty
eView3D_GizmoFlag gizmo_flag
wmGizmoGroupFnRefresh refresh
wmGizmoGroupFnSetupKeymap setup_keymap
eWM_GizmoFlagGroupTypeFlag flag
ListBaseT< wmGizmo > gizmos