This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/editors/gizmo_library/gizmo_library_presets.c

146 lines
4.0 KiB
C
Raw Normal View History

2017-06-10 10:56:42 +10:00
/*
* 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.
*/
/** \file
* \ingroup edgizmolib
2017-06-10 10:56:42 +10:00
*
* \name Gizmo Lib Presets
2017-06-10 10:56:42 +10:00
*
* \brief Preset shapes that can be drawn from any gizmo type.
2017-06-10 10:56:42 +10:00
*/
#include "MEM_guardedalloc.h"
2017-06-10 10:56:42 +10:00
#include "BLI_math.h"
#include "DNA_view3d_types.h"
#include "DNA_object_types.h"
#include "BKE_context.h"
2017-06-10 10:56:42 +10:00
#include "GPU_matrix.h"
#include "GPU_select.h"
#include "DEG_depsgraph.h"
2017-06-10 10:56:42 +10:00
#include "RNA_access.h"
#include "WM_types.h"
#include "WM_api.h"
#include "ED_view3d.h"
#include "ED_screen.h"
2017-06-10 10:56:42 +10:00
/* own includes */
#include "ED_gizmo_library.h" /* own include */
#include "gizmo_library_intern.h" /* own include */
2017-06-10 10:56:42 +10:00
/* TODO, this is to be used by RNA. might move to ED_gizmo_library */
2017-06-10 10:56:42 +10:00
/**
* Given a single axis, orient the matrix to a different direction.
*/
static void single_axis_convert(int src_axis,
2019-09-14 08:10:50 +10:00
const float src_mat[4][4],
int dst_axis,
float dst_mat[4][4])
2017-06-10 10:56:42 +10:00
{
copy_m4_m4(dst_mat, src_mat);
if (src_axis == dst_axis) {
return;
}
float rotmat[3][3];
mat3_from_axis_conversion_single(src_axis, dst_axis, rotmat);
transpose_m3(rotmat);
mul_m4_m4m3(dst_mat, src_mat, rotmat);
2017-06-10 10:56:42 +10:00
}
/**
* Use for all geometry.
*/
static void ed_gizmo_draw_preset_geometry(const struct wmGizmo *gz,
2019-09-14 08:10:50 +10:00
const float mat[4][4],
int select_id,
const GizmoGeomInfo *info)
2017-06-10 10:56:42 +10:00
{
const bool is_select = (select_id != -1);
const bool is_highlight = is_select && (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0;
2017-06-10 10:56:42 +10:00
float color[4];
gizmo_color_get(gz, is_highlight, color);
2017-06-10 10:56:42 +10:00
if (is_select) {
GPU_select_load_id(select_id);
}
2017-06-10 10:56:42 +10:00
GPU_matrix_push();
GPU_matrix_mul(mat);
wm_gizmo_geometryinfo_draw(info, is_select, color);
GPU_matrix_pop();
2017-06-10 10:56:42 +10:00
if (is_select) {
GPU_select_load_id(-1);
}
2017-06-10 10:56:42 +10:00
}
void ED_gizmo_draw_preset_box(const struct wmGizmo *gz, float mat[4][4], int select_id)
2017-06-10 10:56:42 +10:00
{
ed_gizmo_draw_preset_geometry(gz, mat, select_id, &wm_gizmo_geom_data_cube);
2017-06-10 10:56:42 +10:00
}
void ED_gizmo_draw_preset_arrow(const struct wmGizmo *gz, float mat[4][4], int axis, int select_id)
2017-06-10 10:56:42 +10:00
{
float mat_rotate[4][4];
single_axis_convert(OB_POSZ, mat, axis, mat_rotate);
ed_gizmo_draw_preset_geometry(gz, mat_rotate, select_id, &wm_gizmo_geom_data_arrow);
2017-06-10 10:56:42 +10:00
}
void ED_gizmo_draw_preset_circle(const struct wmGizmo *gz,
float mat[4][4],
int axis,
int select_id)
2017-06-10 10:56:42 +10:00
{
float mat_rotate[4][4];
single_axis_convert(OB_POSZ, mat, axis, mat_rotate);
ed_gizmo_draw_preset_geometry(gz, mat_rotate, select_id, &wm_gizmo_geom_data_dial);
2017-06-10 10:56:42 +10:00
}
void ED_gizmo_draw_preset_facemap(
const bContext *C, const struct wmGizmo *gz, Object *ob, const int facemap, int select_id)
2017-06-10 10:56:42 +10:00
{
Refactor access to dependency graph This change ensures that operators which needs access to evaluated data first makes sure there is a dependency graph. Other accesses to the dependency graph made it more explicit about whether they just need a valid dependency graph pointer or whether they expect the graph to be already evaluated. This replaces OPTYPE_USE_EVAL_DATA which is now removed. Some general rules about usage of accessors: - Drawing is expected to happen from a fully evaluated dependency graph. There is now a function to access it, which will in the future control that dependency graph is actually evaluated. This check is not yet done because there are some things to be taken care about first: for example, post-update hooks might leave scene in a state where something is still tagged for update. - All operators which needs to access evaluated state must use CTX_data_ensure_evaluated_depsgraph(). This function replaces OPTYPE_USE_EVAL_DATA. The call is generally to be done in the very beginning of the operator, prior other logic (unless this is some comprehensive operator which might or might not need access to an evaluated state). This call is never to be used from a loop. If some utility function requires evaluated state of dependency graph the graph is to be passed as an explicit argument. This way it is clear that no evaluation happens in a loop or something like this. - All cases which needs to know dependency graph pointer, but which doesn't want to actually evaluate it can use old-style function CTX_data_depsgraph_pointer(), assuming that underlying code will ensure dependency graph is evaluated prior to accessing it. - The new functions are replacing OPTYPE_USE_EVAL_DATA, so now it is explicit and local about where dependency graph is being ensured. This commit also contains some fixes of wrong usage of evaluation functions on original objects. Ideally should be split out, but in reality with all the APIs being renamed is quite tricky. Fixes T67454: Blender crash on rapid undo and select Speculation here is that sometimes undo and selection operators are sometimes handled in the same event loop iteration, which leaves non-evaluated dependency graph. Fixes T67973: Crash on Fix Deforms operator Fixes T67902: Crash when undo a loop cut Reviewers: brecht Reviewed By: brecht Subscribers: lichtwerk Maniphest Tasks: T67454 Differential Revision: https://developer.blender.org/D5343
2019-07-25 16:36:22 +02:00
/* Dependency graph is supposed to be evaluated prior to draw. */
Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C);
const bool is_select = (select_id != -1);
const bool is_highlight = is_select && (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0;
2017-06-10 10:56:42 +10:00
float color[4];
gizmo_color_get(gz, is_highlight, color);
2017-06-10 10:56:42 +10:00
if (is_select) {
GPU_select_load_id(select_id);
}
2017-06-10 10:56:42 +10:00
GPU_matrix_push();
GPU_matrix_mul(ob->obmat);
Refactor access to dependency graph This change ensures that operators which needs access to evaluated data first makes sure there is a dependency graph. Other accesses to the dependency graph made it more explicit about whether they just need a valid dependency graph pointer or whether they expect the graph to be already evaluated. This replaces OPTYPE_USE_EVAL_DATA which is now removed. Some general rules about usage of accessors: - Drawing is expected to happen from a fully evaluated dependency graph. There is now a function to access it, which will in the future control that dependency graph is actually evaluated. This check is not yet done because there are some things to be taken care about first: for example, post-update hooks might leave scene in a state where something is still tagged for update. - All operators which needs to access evaluated state must use CTX_data_ensure_evaluated_depsgraph(). This function replaces OPTYPE_USE_EVAL_DATA. The call is generally to be done in the very beginning of the operator, prior other logic (unless this is some comprehensive operator which might or might not need access to an evaluated state). This call is never to be used from a loop. If some utility function requires evaluated state of dependency graph the graph is to be passed as an explicit argument. This way it is clear that no evaluation happens in a loop or something like this. - All cases which needs to know dependency graph pointer, but which doesn't want to actually evaluate it can use old-style function CTX_data_depsgraph_pointer(), assuming that underlying code will ensure dependency graph is evaluated prior to accessing it. - The new functions are replacing OPTYPE_USE_EVAL_DATA, so now it is explicit and local about where dependency graph is being ensured. This commit also contains some fixes of wrong usage of evaluation functions on original objects. Ideally should be split out, but in reality with all the APIs being renamed is quite tricky. Fixes T67454: Blender crash on rapid undo and select Speculation here is that sometimes undo and selection operators are sometimes handled in the same event loop iteration, which leaves non-evaluated dependency graph. Fixes T67973: Crash on Fix Deforms operator Fixes T67902: Crash when undo a loop cut Reviewers: brecht Reviewed By: brecht Subscribers: lichtwerk Maniphest Tasks: T67454 Differential Revision: https://developer.blender.org/D5343
2019-07-25 16:36:22 +02:00
ED_draw_object_facemap(depsgraph, ob, color, facemap);
GPU_matrix_pop();
2017-06-10 10:56:42 +10:00
if (is_select) {
GPU_select_load_id(-1);
}
2017-06-10 10:56:42 +10:00
}