Blender  V3.3
view3d_gizmo_forcefield.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BLI_utildefines.h"
8 
9 #include "BKE_context.h"
10 #include "BKE_layer.h"
11 
12 #include "DNA_object_force_types.h"
13 #include "DNA_object_types.h"
14 
15 #include "ED_gizmo_library.h"
16 #include "ED_screen.h"
17 
18 #include "UI_resources.h"
19 
20 #include "MEM_guardedalloc.h"
21 
22 #include "RNA_access.h"
23 #include "RNA_prototypes.h"
24 
25 #include "WM_api.h"
26 #include "WM_types.h"
27 
28 #include "view3d_intern.h" /* own include */
29 
30 /* -------------------------------------------------------------------- */
35 {
36  View3D *v3d = CTX_wm_view3d(C);
37 
39  return false;
40  }
42  return false;
43  }
44 
45  ViewLayer *view_layer = CTX_data_view_layer(C);
46  Base *base = BASACT(view_layer);
47  if (base && BASE_SELECTABLE(v3d, base)) {
48  Object *ob = base->object;
49  if (ob->pd && ob->pd->forcefield) {
50  return true;
51  }
52  }
53  return false;
54 }
55 
57 {
58  /* only wind effector for now */
59  wmGizmoWrapper *wwrapper = MEM_mallocN(sizeof(wmGizmoWrapper), __func__);
60  gzgroup->customdata = wwrapper;
61 
62  wwrapper->gizmo = WM_gizmo_new("GIZMO_GT_arrow_3d", gzgroup, NULL);
63  wmGizmo *gz = wwrapper->gizmo;
65  ED_gizmo_arrow3d_set_ui_range(gz, -200.0f, 200.0f);
67 
70 }
71 
73 {
74  wmGizmoWrapper *wwrapper = gzgroup->customdata;
75  wmGizmo *gz = wwrapper->gizmo;
76  ViewLayer *view_layer = CTX_data_view_layer(C);
77  Object *ob = OBACT(view_layer);
78  PartDeflect *pd = ob->pd;
79 
80  if (pd->forcefield == PFIELD_WIND) {
81  const float size = (ob->type == OB_EMPTY) ? ob->empty_drawsize : 1.0f;
82  const float ofs[3] = {0.0f, -size, 0.0f};
83  PointerRNA field_ptr;
84 
85  RNA_pointer_create(&ob->id, &RNA_FieldSettings, pd, &field_ptr);
90  WM_gizmo_target_property_def_rna(gz, "offset", &field_ptr, "strength", -1);
91  }
92  else {
94  }
95 }
96 
98 {
99  gzgt->name = "Force Field Widgets";
100  gzgt->idname = "VIEW3D_GGT_force_field";
101 
104 
109 }
110 
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1100
struct View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:784
#define UNUSED(x)
@ BASE_SELECTABLE
Object is a sort of wrapper for general info.
@ OB_EMPTY
#define BASACT(_view_layer)
#define OBACT(_view_layer)
@ V3D_GIZMO_SHOW_EMPTY_FORCE_FIELD
@ V3D_GIZMO_HIDE
@ V3D_GIZMO_HIDE_CONTEXT
@ ED_GIZMO_ARROW_XFORM_FLAG_CONSTRAINED
Read Guarded memory(de)allocation.
#define C
Definition: RandGen.cpp:25
void UI_GetThemeColor3fv(int colorid, float col[3])
Definition: resources.c:1165
@ TH_GIZMO_HI
Definition: UI_resources.h:304
@ TH_GIZMO_PRIMARY
Definition: UI_resources.h:305
@ WM_GIZMO_HIDDEN
@ 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.c:33
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:136
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:5015
struct Object * object
struct PartDeflect * pd
float empty_drawsize
float obmat[4][4]
char gizmo_show_empty
char gizmo_flag
wmGizmoGroupFnSetupKeymap setup_keymap
wmGizmoGroupFnRefresh refresh
wmGizmoGroupFnInit setup
const char * idname
eWM_GizmoFlagGroupTypeFlag flag
wmGizmoGroupFnPoll poll
const char * name
struct wmGizmo * gizmo
float color_hi[4]
float color[4]
struct PointerRNA * ptr
static void WIDGETGROUP_forcefield_refresh(const bContext *C, wmGizmoGroup *gzgroup)
static bool WIDGETGROUP_forcefield_poll(const bContext *C, wmGizmoGroupType *UNUSED(gzgt))
void VIEW3D_GGT_force_field(wmGizmoGroupType *gzgt)
static void WIDGETGROUP_forcefield_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup)
void WM_gizmo_set_matrix_offset_location(wmGizmo *gz, const float offset[3])
Definition: wm_gizmo.c:299
void WM_gizmo_set_matrix_location(wmGizmo *gz, const float origin[3])
Definition: wm_gizmo.c:284
void WM_gizmo_set_flag(wmGizmo *gz, const int flag, const bool enable)
Definition: wm_gizmo.c:304
void WM_gizmo_set_matrix_rotation_from_z_axis(wmGizmo *gz, const float z_axis[3])
Definition: wm_gizmo.c:274
wmGizmo * WM_gizmo_new(const char *idname, wmGizmoGroup *gzgroup, PointerRNA *properties)
Definition: wm_gizmo.c:94
wmKeyMap * WM_gizmogroup_setup_keymap_generic_maybe_drag(const wmGizmoGroupType *UNUSED(gzgt), wmKeyConfig *kc)
void WM_gizmo_target_property_def_rna(wmGizmo *gz, const char *idname, PointerRNA *ptr, const char *propname, int index)