Blender  V2.93
view3d_gizmo_forcefield.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BLI_utildefines.h"
22 
23 #include "BKE_context.h"
24 #include "BKE_layer.h"
25 
26 #include "DNA_object_force_types.h"
27 #include "DNA_object_types.h"
28 
29 #include "ED_gizmo_library.h"
30 #include "ED_screen.h"
31 
32 #include "UI_resources.h"
33 
34 #include "MEM_guardedalloc.h"
35 
36 #include "RNA_access.h"
37 
38 #include "WM_api.h"
39 #include "WM_types.h"
40 
41 #include "view3d_intern.h" /* own include */
42 
43 /* -------------------------------------------------------------------- */
48 {
49  View3D *v3d = CTX_wm_view3d(C);
50 
52  return false;
53  }
55  return false;
56  }
57 
58  ViewLayer *view_layer = CTX_data_view_layer(C);
59  Base *base = BASACT(view_layer);
60  if (base && BASE_SELECTABLE(v3d, base)) {
61  Object *ob = base->object;
62  if (ob->pd && ob->pd->forcefield) {
63  return true;
64  }
65  }
66  return false;
67 }
68 
70 {
71  /* only wind effector for now */
72  wmGizmoWrapper *wwrapper = MEM_mallocN(sizeof(wmGizmoWrapper), __func__);
73  gzgroup->customdata = wwrapper;
74 
75  wwrapper->gizmo = WM_gizmo_new("GIZMO_GT_arrow_3d", gzgroup, NULL);
76  wmGizmo *gz = wwrapper->gizmo;
78  ED_gizmo_arrow3d_set_ui_range(gz, -200.0f, 200.0f);
80 
83 }
84 
86 {
87  wmGizmoWrapper *wwrapper = gzgroup->customdata;
88  wmGizmo *gz = wwrapper->gizmo;
89  ViewLayer *view_layer = CTX_data_view_layer(C);
90  Object *ob = OBACT(view_layer);
91  PartDeflect *pd = ob->pd;
92 
93  if (pd->forcefield == PFIELD_WIND) {
94  const float size = (ob->type == OB_EMPTY) ? ob->empty_drawsize : 1.0f;
95  const float ofs[3] = {0.0f, -size, 0.0f};
96  PointerRNA field_ptr;
97 
98  RNA_pointer_create(&ob->id, &RNA_FieldSettings, pd, &field_ptr);
103  WM_gizmo_target_property_def_rna(gz, "offset", &field_ptr, "strength", -1);
104  }
105  else {
107  }
108 }
109 
111 {
112  gzgt->name = "Force Field Widgets";
113  gzgt->idname = "VIEW3D_GGT_force_field";
114 
117 
122 }
123 
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1044
struct View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:760
#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.
StructRNA RNA_FieldSettings
#define C
Definition: RandGen.cpp:39
void UI_GetThemeColor3fv(int colorid, float col[3])
Definition: resources.c:1191
@ TH_GIZMO_HI
Definition: UI_resources.h:320
@ TH_GIZMO_PRIMARY
Definition: UI_resources.h:321
@ 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:47
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:146
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:6413
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:334
void WM_gizmo_set_matrix_location(wmGizmo *gz, const float origin[3])
Definition: wm_gizmo.c:316
void WM_gizmo_set_flag(wmGizmo *gz, const int flag, const bool enable)
Definition: wm_gizmo.c:339
void WM_gizmo_set_matrix_rotation_from_z_axis(wmGizmo *gz, const float z_axis[3])
Definition: wm_gizmo.c:306
wmGizmo * WM_gizmo_new(const char *idname, wmGizmoGroup *gzgroup, PointerRNA *properties)
Definition: wm_gizmo.c:114
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)