1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/editors/space_view3d/view3d_gizmo_forcefield.c
* \ingroup spview3d
*/
#include "BLI_blenlib.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BKE_context.h"
#include "BKE_object.h"
#include "DNA_object_types.h"
#include "DNA_object_force_types.h"
#include "ED_screen.h"
#include "ED_gizmo_library.h"
#include "UI_resources.h"
#include "MEM_guardedalloc.h"
#include "RNA_access.h"
#include "WM_api.h"
#include "WM_types.h"
#include "view3d_intern.h" /* own include */
/* -------------------------------------------------------------------- */
/** \name Force Field Manipulators
* \{ */
static bool WIDGETGROUP_forcefield_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt))
{
View3D *v3d = CTX_wm_view3d(C);
if ((v3d->flag2 & V3D_RENDER_OVERRIDE) ||
(v3d->mpr_flag & (V3D_MANIPULATOR_HIDE | V3D_MANIPULATOR_HIDE_CONTEXT)))
{
return false;
}
Object *ob = CTX_data_active_object(C);
return (ob && ob->pd && ob->pd->forcefield);
}
static void WIDGETGROUP_forcefield_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
{
/* only wind effector for now */
wmManipulatorWrapper *wwrapper = MEM_mallocN(sizeof(wmManipulatorWrapper), __func__);
mgroup->customdata = wwrapper;
wwrapper->manipulator = WM_manipulator_new("MANIPULATOR_WT_arrow_3d", mgroup, NULL);
wmManipulator *mpr = wwrapper->manipulator;
RNA_enum_set(mpr->ptr, "transform", ED_MANIPULATOR_ARROW_XFORM_FLAG_CONSTRAINED);
ED_manipulator_arrow3d_set_ui_range(mpr, -200.0f, 200.0f);
ED_manipulator_arrow3d_set_range_fac(mpr, 6.0f);
UI_GetThemeColor3fv(TH_MANIPULATOR_PRIMARY, mpr->color);
UI_GetThemeColor3fv(TH_MANIPULATOR_HI, mpr->color_hi);
}
static void WIDGETGROUP_forcefield_refresh(const bContext *C, wmManipulatorGroup *mgroup)
{
wmManipulatorWrapper *wwrapper = mgroup->customdata;
wmManipulator *mpr = wwrapper->manipulator;
Object *ob = CTX_data_active_object(C);
PartDeflect *pd = ob->pd;
if (pd->forcefield == PFIELD_WIND) {
const float size = (ob->type == OB_EMPTY) ? ob->empty_drawsize : 1.0f;
const float ofs[3] = {0.0f, -size, 0.0f};
PointerRNA field_ptr;
RNA_pointer_create(&ob->id, &RNA_FieldSettings, pd, &field_ptr);
WM_manipulator_set_matrix_location(mpr, ob->obmat[3]);
WM_manipulator_set_matrix_rotation_from_z_axis(mpr, ob->obmat[2]);
WM_manipulator_set_matrix_offset_location(mpr, ofs);
WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, false);
WM_manipulator_target_property_def_rna(mpr, "offset", &field_ptr, "strength", -1);
}
else {
WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, true);
}
}
void VIEW3D_WGT_force_field(wmManipulatorGroupType *wgt)
{
wgt->name = "Force Field Widgets";
wgt->idname = "VIEW3D_WGT_force_field";
wgt->flag |= (WM_MANIPULATORGROUPTYPE_PERSISTENT |
WM_MANIPULATORGROUPTYPE_3D |
WM_MANIPULATORGROUPTYPE_SCALE |
WM_MANIPULATORGROUPTYPE_DEPTH_3D);
wgt->poll = WIDGETGROUP_forcefield_poll;
wgt->setup = WIDGETGROUP_forcefield_setup;
wgt->refresh = WIDGETGROUP_forcefield_refresh;
}
/** \} */
|