2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-19 12:14:58 +00:00
|
|
|
* ***** 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
|
2008-12-26 10:31:44 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2008-12-19 12:14:58 +00:00
|
|
|
*
|
|
|
|
|
* 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-19 12:14:58 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2008 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
2008-12-26 10:31:44 +00:00
|
|
|
*
|
2008-12-19 12:14:58 +00:00
|
|
|
* Contributor(s): Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/space_view3d/view3d_edit.c
|
|
|
|
|
* \ingroup spview3d
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2008-12-19 12:14:58 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <float.h>
|
|
|
|
|
|
2008-12-20 11:33:16 +00:00
|
|
|
#include "DNA_armature_types.h"
|
2008-12-19 12:14:58 +00:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
2010-11-08 02:30:46 +00:00
|
|
|
#include "DNA_camera_types.h"
|
2011-05-14 04:25:47 +00:00
|
|
|
#include "DNA_lamp_types.h"
|
2008-12-19 12:14:58 +00:00
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2009-11-10 20:43:45 +00:00
|
|
|
#include "BLI_math.h"
|
2008-12-19 12:14:58 +00:00
|
|
|
#include "BLI_rand.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2008-12-19 12:14:58 +00:00
|
|
|
|
2011-11-18 23:32:17 +00:00
|
|
|
#include "BKE_camera.h"
|
2008-12-19 17:14:02 +00:00
|
|
|
#include "BKE_context.h"
|
2010-09-01 13:41:53 +00:00
|
|
|
#include "BKE_image.h"
|
|
|
|
|
#include "BKE_library.h"
|
2008-12-19 12:14:58 +00:00
|
|
|
#include "BKE_object.h"
|
2009-08-15 19:48:50 +00:00
|
|
|
#include "BKE_paint.h"
|
2009-01-21 02:24:12 +00:00
|
|
|
#include "BKE_report.h"
|
2008-12-19 12:14:58 +00:00
|
|
|
#include "BKE_scene.h"
|
2011-05-20 04:14:29 +00:00
|
|
|
#include "BKE_screen.h"
|
2011-05-14 17:50:33 +00:00
|
|
|
#include "BKE_depsgraph.h" /* for ED_view3d_camera_lock_sync */
|
2008-12-19 12:14:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "BIF_gl.h"
|
2011-01-05 15:37:36 +00:00
|
|
|
#include "BIF_glutil.h"
|
2008-12-19 12:14:58 +00:00
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
2008-12-19 17:14:02 +00:00
|
|
|
#include "WM_types.h"
|
2008-12-19 12:14:58 +00:00
|
|
|
|
2008-12-19 19:27:41 +00:00
|
|
|
#include "RNA_access.h"
|
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
|
2009-02-20 20:39:27 +00:00
|
|
|
#include "ED_particle.h"
|
2008-12-19 12:14:58 +00:00
|
|
|
#include "ED_screen.h"
|
2009-07-08 16:17:47 +00:00
|
|
|
#include "ED_transform.h"
|
2010-02-25 15:10:27 +00:00
|
|
|
#include "ED_mesh.h"
|
2010-10-21 07:38:09 +00:00
|
|
|
#include "ED_view3d.h"
|
2008-12-19 12:14:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "PIL_time.h" /* smoothview */
|
|
|
|
|
|
|
|
|
|
#include "view3d_intern.h" // own include
|
|
|
|
|
|
|
|
|
|
/* ********************** view3d_edit: view manipulations ********************* */
|
|
|
|
|
|
2011-05-23 15:46:09 +00:00
|
|
|
int ED_view3d_camera_lock_check(View3D *v3d, RegionView3D *rv3d)
|
|
|
|
|
{
|
|
|
|
|
return ((v3d->camera) &&
|
|
|
|
|
(v3d->camera->id.lib == NULL) &&
|
|
|
|
|
(v3d->flag2 & V3D_LOCK_CAMERA) &&
|
|
|
|
|
(rv3d->persp==RV3D_CAMOB));
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-14 17:50:33 +00:00
|
|
|
void ED_view3d_camera_lock_init(View3D *v3d, RegionView3D *rv3d)
|
|
|
|
|
{
|
2011-05-23 15:46:09 +00:00
|
|
|
if(ED_view3d_camera_lock_check(v3d, rv3d)) {
|
2011-05-14 17:50:33 +00:00
|
|
|
ED_view3d_from_object(v3d->camera, rv3d->ofs, rv3d->viewquat, &rv3d->dist, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-27 11:52:59 +00:00
|
|
|
/* return TRUE if the camera is moved */
|
|
|
|
|
int ED_view3d_camera_lock_sync(View3D *v3d, RegionView3D *rv3d)
|
2011-05-14 17:50:33 +00:00
|
|
|
{
|
2011-05-23 15:46:09 +00:00
|
|
|
if(ED_view3d_camera_lock_check(v3d, rv3d)) {
|
2011-11-11 05:34:07 +00:00
|
|
|
ObjectTfmProtectedChannels obtfm;
|
2011-05-23 02:53:30 +00:00
|
|
|
Object *root_parent;
|
|
|
|
|
|
|
|
|
|
if((U.uiflag & USER_CAM_LOCK_NO_PARENT)==0 && (root_parent= v3d->camera->parent)) {
|
|
|
|
|
Object *ob_update;
|
|
|
|
|
float view_mat[4][4];
|
|
|
|
|
float diff_mat[4][4];
|
|
|
|
|
float parent_mat[4][4];
|
|
|
|
|
|
|
|
|
|
while(root_parent->parent) {
|
|
|
|
|
root_parent= root_parent->parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist);
|
|
|
|
|
|
|
|
|
|
invert_m4_m4(v3d->camera->imat, v3d->camera->obmat);
|
Math lib: matrix multiplication order fix for two functions that were
inconsistent with similar functions & math notation:
mul_m4_m4m4(R, B, A) => mult_m4_m4m4(R, A, B)
mul_m3_m3m4(R, B, A) => mult_m3_m3m4(R, A, B)
For branch maintainers, it should be relatively simple to fix things manually,
it's also possible run this script after merging to do automatic replacement:
http://www.pasteall.org/27459/python
2011-12-16 19:53:12 +00:00
|
|
|
mult_m4_m4m4(diff_mat, view_mat, v3d->camera->imat);
|
2011-05-23 02:53:30 +00:00
|
|
|
|
Math lib: matrix multiplication order fix for two functions that were
inconsistent with similar functions & math notation:
mul_m4_m4m4(R, B, A) => mult_m4_m4m4(R, A, B)
mul_m3_m3m4(R, B, A) => mult_m3_m3m4(R, A, B)
For branch maintainers, it should be relatively simple to fix things manually,
it's also possible run this script after merging to do automatic replacement:
http://www.pasteall.org/27459/python
2011-12-16 19:53:12 +00:00
|
|
|
mult_m4_m4m4(parent_mat, diff_mat, root_parent->obmat);
|
2011-11-11 05:34:07 +00:00
|
|
|
|
|
|
|
|
object_tfm_protected_backup(root_parent, &obtfm);
|
2011-05-23 02:53:30 +00:00
|
|
|
object_apply_mat4(root_parent, parent_mat, TRUE, FALSE);
|
2011-11-11 05:34:07 +00:00
|
|
|
object_tfm_protected_restore(root_parent, &obtfm, root_parent->protectflag);
|
2011-05-23 02:53:30 +00:00
|
|
|
|
|
|
|
|
ob_update= v3d->camera;
|
|
|
|
|
while(ob_update) {
|
|
|
|
|
DAG_id_tag_update(&ob_update->id, OB_RECALC_OB);
|
|
|
|
|
WM_main_add_notifier(NC_OBJECT|ND_TRANSFORM, ob_update);
|
|
|
|
|
ob_update= ob_update->parent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2011-11-11 05:34:07 +00:00
|
|
|
object_tfm_protected_backup(v3d->camera, &obtfm);
|
2011-05-23 02:53:30 +00:00
|
|
|
ED_view3d_to_object(v3d->camera, rv3d->ofs, rv3d->viewquat, rv3d->dist);
|
2011-11-11 05:34:07 +00:00
|
|
|
object_tfm_protected_restore(v3d->camera, &obtfm, v3d->camera->protectflag);
|
|
|
|
|
|
2011-05-23 02:53:30 +00:00
|
|
|
DAG_id_tag_update(&v3d->camera->id, OB_RECALC_OB);
|
|
|
|
|
WM_main_add_notifier(NC_OBJECT|ND_TRANSFORM, v3d->camera);
|
|
|
|
|
}
|
2011-08-27 11:52:59 +00:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return FALSE;
|
2011-05-14 17:50:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-01-20 18:31:11 +00:00
|
|
|
/* ********************* box view support ***************** */
|
|
|
|
|
|
|
|
|
|
static void view3d_boxview_clip(ScrArea *sa)
|
|
|
|
|
{
|
|
|
|
|
ARegion *ar;
|
|
|
|
|
BoundBox *bb = MEM_callocN(sizeof(BoundBox), "clipbb");
|
|
|
|
|
float clip[6][4];
|
2009-10-21 17:56:26 +00:00
|
|
|
float x1= 0.0f, y1= 0.0f, z1= 0.0f, ofs[3] = {0.0f, 0.0f, 0.0f};
|
2009-01-20 18:31:11 +00:00
|
|
|
int val;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-20 18:31:11 +00:00
|
|
|
/* create bounding box */
|
|
|
|
|
for(ar= sa->regionbase.first; ar; ar= ar->next) {
|
|
|
|
|
if(ar->regiontype==RGN_TYPE_WINDOW) {
|
|
|
|
|
RegionView3D *rv3d= ar->regiondata;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2.5
Smaller jobs, all in one commit!
- Moved object_do_update out of view3d drawing, into
the event system (currently after notifiers).
Depsgraph calls for setting update flags will have to
keep track of each Screen's needs, so a UI showing only
a Sequencer doesn't do objects.
- Added button in "Properties region" in 3D window to set
or disable 4-split, including the 3 options it has.
(lock, box, clip)
- Restored legacy code for UI, to make things work like
bone rename, autocomplete.
- Node editor now shows Curves widgets again
- Bugfix: composite job increased Viewer user id count
- Bugfix: Node editor, not "Enable nodes" still called
a Job, which didn't do anything
- Various code cleaning, unused vars and prototypes.
2009-02-11 16:54:55 +00:00
|
|
|
if(rv3d->viewlock & RV3D_BOXCLIP) {
|
2009-10-27 02:54:25 +00:00
|
|
|
if(ELEM(rv3d->view, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM)) {
|
2009-01-20 18:31:11 +00:00
|
|
|
if(ar->winx>ar->winy) x1= rv3d->dist;
|
|
|
|
|
else x1= ar->winx*rv3d->dist/ar->winy;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-20 18:31:11 +00:00
|
|
|
if(ar->winx>ar->winy) y1= ar->winy*rv3d->dist/ar->winx;
|
|
|
|
|
else y1= rv3d->dist;
|
2010-02-25 20:26:38 +00:00
|
|
|
copy_v2_v2(ofs, rv3d->ofs);
|
2009-01-20 18:31:11 +00:00
|
|
|
}
|
2009-10-27 02:54:25 +00:00
|
|
|
else if(ELEM(rv3d->view, RV3D_VIEW_FRONT, RV3D_VIEW_BACK)) {
|
2009-01-20 18:31:11 +00:00
|
|
|
ofs[2]= rv3d->ofs[2];
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-20 18:31:11 +00:00
|
|
|
if(ar->winx>ar->winy) z1= ar->winy*rv3d->dist/ar->winx;
|
|
|
|
|
else z1= rv3d->dist;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-20 18:31:11 +00:00
|
|
|
for(val=0; val<8; val++) {
|
|
|
|
|
if(ELEM4(val, 0, 3, 4, 7))
|
|
|
|
|
bb->vec[val][0]= -x1 - ofs[0];
|
|
|
|
|
else
|
|
|
|
|
bb->vec[val][0]= x1 - ofs[0];
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-20 18:31:11 +00:00
|
|
|
if(ELEM4(val, 0, 1, 4, 5))
|
|
|
|
|
bb->vec[val][1]= -y1 - ofs[1];
|
|
|
|
|
else
|
|
|
|
|
bb->vec[val][1]= y1 - ofs[1];
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-20 18:31:11 +00:00
|
|
|
if(val > 3)
|
|
|
|
|
bb->vec[val][2]= -z1 - ofs[2];
|
|
|
|
|
else
|
|
|
|
|
bb->vec[val][2]= z1 - ofs[2];
|
2009-07-09 02:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
2009-01-20 18:31:11 +00:00
|
|
|
/* normals for plane equations */
|
2009-11-10 20:43:45 +00:00
|
|
|
normal_tri_v3( clip[0],bb->vec[0], bb->vec[1], bb->vec[4]);
|
|
|
|
|
normal_tri_v3( clip[1],bb->vec[1], bb->vec[2], bb->vec[5]);
|
|
|
|
|
normal_tri_v3( clip[2],bb->vec[2], bb->vec[3], bb->vec[6]);
|
|
|
|
|
normal_tri_v3( clip[3],bb->vec[3], bb->vec[0], bb->vec[7]);
|
|
|
|
|
normal_tri_v3( clip[4],bb->vec[4], bb->vec[5], bb->vec[6]);
|
|
|
|
|
normal_tri_v3( clip[5],bb->vec[0], bb->vec[2], bb->vec[1]);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-20 18:31:11 +00:00
|
|
|
/* then plane equations */
|
2012-01-19 16:12:40 +00:00
|
|
|
for(val=0; val<6; val++) {
|
|
|
|
|
clip[val][3] = -dot_v3v3(clip[val], bb->vec[val % 5]);
|
2009-01-20 18:31:11 +00:00
|
|
|
}
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-20 18:31:11 +00:00
|
|
|
/* create bounding box */
|
|
|
|
|
for(ar= sa->regionbase.first; ar; ar= ar->next) {
|
|
|
|
|
if(ar->regiontype==RGN_TYPE_WINDOW) {
|
|
|
|
|
RegionView3D *rv3d= ar->regiondata;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2.5
Smaller jobs, all in one commit!
- Moved object_do_update out of view3d drawing, into
the event system (currently after notifiers).
Depsgraph calls for setting update flags will have to
keep track of each Screen's needs, so a UI showing only
a Sequencer doesn't do objects.
- Added button in "Properties region" in 3D window to set
or disable 4-split, including the 3 options it has.
(lock, box, clip)
- Restored legacy code for UI, to make things work like
bone rename, autocomplete.
- Node editor now shows Curves widgets again
- Bugfix: composite job increased Viewer user id count
- Bugfix: Node editor, not "Enable nodes" still called
a Job, which didn't do anything
- Various code cleaning, unused vars and prototypes.
2009-02-11 16:54:55 +00:00
|
|
|
if(rv3d->viewlock & RV3D_BOXCLIP) {
|
2009-01-20 18:31:11 +00:00
|
|
|
rv3d->rflag |= RV3D_CLIPPING;
|
|
|
|
|
memcpy(rv3d->clip, clip, sizeof(clip));
|
2010-01-30 03:22:22 +00:00
|
|
|
if(rv3d->clipbb) MEM_freeN(rv3d->clipbb);
|
|
|
|
|
rv3d->clipbb= MEM_dupallocN(bb);
|
2009-01-20 18:31:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
MEM_freeN(bb);
|
|
|
|
|
}
|
|
|
|
|
|
2.5
Smaller jobs, all in one commit!
- Moved object_do_update out of view3d drawing, into
the event system (currently after notifiers).
Depsgraph calls for setting update flags will have to
keep track of each Screen's needs, so a UI showing only
a Sequencer doesn't do objects.
- Added button in "Properties region" in 3D window to set
or disable 4-split, including the 3 options it has.
(lock, box, clip)
- Restored legacy code for UI, to make things work like
bone rename, autocomplete.
- Node editor now shows Curves widgets again
- Bugfix: composite job increased Viewer user id count
- Bugfix: Node editor, not "Enable nodes" still called
a Job, which didn't do anything
- Various code cleaning, unused vars and prototypes.
2009-02-11 16:54:55 +00:00
|
|
|
/* sync center/zoom view of region to others, for view transforms */
|
2009-01-20 14:23:32 +00:00
|
|
|
static void view3d_boxview_sync(ScrArea *sa, ARegion *ar)
|
|
|
|
|
{
|
|
|
|
|
ARegion *artest;
|
|
|
|
|
RegionView3D *rv3d= ar->regiondata;
|
2010-11-08 03:44:52 +00:00
|
|
|
short clip= 0;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-20 14:23:32 +00:00
|
|
|
for(artest= sa->regionbase.first; artest; artest= artest->next) {
|
|
|
|
|
if(artest!=ar && artest->regiontype==RGN_TYPE_WINDOW) {
|
|
|
|
|
RegionView3D *rv3dtest= artest->regiondata;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-20 14:23:32 +00:00
|
|
|
if(rv3dtest->viewlock) {
|
|
|
|
|
rv3dtest->dist= rv3d->dist;
|
|
|
|
|
|
2009-10-27 02:54:25 +00:00
|
|
|
if( ELEM(rv3d->view, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM) ) {
|
|
|
|
|
if( ELEM(rv3dtest->view, RV3D_VIEW_FRONT, RV3D_VIEW_BACK))
|
2009-01-20 14:23:32 +00:00
|
|
|
rv3dtest->ofs[0]= rv3d->ofs[0];
|
2009-10-27 02:54:25 +00:00
|
|
|
else if( ELEM(rv3dtest->view, RV3D_VIEW_RIGHT, RV3D_VIEW_LEFT))
|
2009-01-20 14:23:32 +00:00
|
|
|
rv3dtest->ofs[1]= rv3d->ofs[1];
|
|
|
|
|
}
|
2009-10-27 02:54:25 +00:00
|
|
|
else if( ELEM(rv3d->view, RV3D_VIEW_FRONT, RV3D_VIEW_BACK) ) {
|
|
|
|
|
if( ELEM(rv3dtest->view, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM))
|
2009-01-20 14:23:32 +00:00
|
|
|
rv3dtest->ofs[0]= rv3d->ofs[0];
|
2009-10-27 02:54:25 +00:00
|
|
|
else if( ELEM(rv3dtest->view, RV3D_VIEW_RIGHT, RV3D_VIEW_LEFT))
|
2009-01-20 14:23:32 +00:00
|
|
|
rv3dtest->ofs[2]= rv3d->ofs[2];
|
|
|
|
|
}
|
2009-10-27 02:54:25 +00:00
|
|
|
else if( ELEM(rv3d->view, RV3D_VIEW_RIGHT, RV3D_VIEW_LEFT) ) {
|
|
|
|
|
if( ELEM(rv3dtest->view, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM))
|
2009-01-20 14:23:32 +00:00
|
|
|
rv3dtest->ofs[1]= rv3d->ofs[1];
|
2009-10-27 02:54:25 +00:00
|
|
|
if( ELEM(rv3dtest->view, RV3D_VIEW_FRONT, RV3D_VIEW_BACK))
|
2009-01-20 14:23:32 +00:00
|
|
|
rv3dtest->ofs[2]= rv3d->ofs[2];
|
|
|
|
|
}
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2010-11-08 03:44:52 +00:00
|
|
|
clip |= rv3dtest->viewlock & RV3D_BOXCLIP;
|
|
|
|
|
|
2009-01-20 14:23:32 +00:00
|
|
|
ED_region_tag_redraw(artest);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-11-08 03:44:52 +00:00
|
|
|
|
|
|
|
|
if(clip) {
|
|
|
|
|
view3d_boxview_clip(sa);
|
|
|
|
|
}
|
2009-01-20 14:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* for home, center etc */
|
2.5
Smaller jobs, all in one commit!
- Moved object_do_update out of view3d drawing, into
the event system (currently after notifiers).
Depsgraph calls for setting update flags will have to
keep track of each Screen's needs, so a UI showing only
a Sequencer doesn't do objects.
- Added button in "Properties region" in 3D window to set
or disable 4-split, including the 3 options it has.
(lock, box, clip)
- Restored legacy code for UI, to make things work like
bone rename, autocomplete.
- Node editor now shows Curves widgets again
- Bugfix: composite job increased Viewer user id count
- Bugfix: Node editor, not "Enable nodes" still called
a Job, which didn't do anything
- Various code cleaning, unused vars and prototypes.
2009-02-11 16:54:55 +00:00
|
|
|
void view3d_boxview_copy(ScrArea *sa, ARegion *ar)
|
2009-01-20 14:23:32 +00:00
|
|
|
{
|
|
|
|
|
ARegion *artest;
|
|
|
|
|
RegionView3D *rv3d= ar->regiondata;
|
2010-11-08 03:44:52 +00:00
|
|
|
short clip= 0;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-20 14:23:32 +00:00
|
|
|
for(artest= sa->regionbase.first; artest; artest= artest->next) {
|
|
|
|
|
if(artest!=ar && artest->regiontype==RGN_TYPE_WINDOW) {
|
|
|
|
|
RegionView3D *rv3dtest= artest->regiondata;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-20 14:23:32 +00:00
|
|
|
if(rv3dtest->viewlock) {
|
|
|
|
|
rv3dtest->dist= rv3d->dist;
|
2010-07-26 06:34:56 +00:00
|
|
|
copy_v3_v3(rv3dtest->ofs, rv3d->ofs);
|
2009-01-20 14:23:32 +00:00
|
|
|
ED_region_tag_redraw(artest);
|
2010-11-08 03:44:52 +00:00
|
|
|
|
|
|
|
|
clip |= rv3dtest->viewlock & RV3D_BOXCLIP;
|
2009-01-20 14:23:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-11-08 03:44:52 +00:00
|
|
|
|
|
|
|
|
if(clip) {
|
|
|
|
|
view3d_boxview_clip(sa);
|
|
|
|
|
}
|
2009-01-20 14:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
2010-11-08 03:44:52 +00:00
|
|
|
/* 'clip' is used to know if our clip setting has changed */
|
|
|
|
|
void ED_view3d_quadview_update(ScrArea *sa, ARegion *ar, short do_clip)
|
2010-01-30 03:22:22 +00:00
|
|
|
{
|
2010-11-08 03:44:52 +00:00
|
|
|
ARegion *arsync= NULL;
|
2010-01-30 03:22:22 +00:00
|
|
|
RegionView3D *rv3d= ar->regiondata;
|
|
|
|
|
short viewlock;
|
|
|
|
|
/* this function copies flags from the first of the 3 other quadview
|
|
|
|
|
regions to the 2 other, so it assumes this is the region whose
|
|
|
|
|
properties are always being edited, weak */
|
|
|
|
|
viewlock= rv3d->viewlock;
|
|
|
|
|
|
|
|
|
|
if((viewlock & RV3D_LOCKED)==0)
|
|
|
|
|
viewlock= 0;
|
2010-11-08 03:44:52 +00:00
|
|
|
else if((viewlock & RV3D_BOXVIEW)==0) {
|
2010-01-30 03:22:22 +00:00
|
|
|
viewlock &= ~RV3D_BOXCLIP;
|
2010-11-08 03:44:52 +00:00
|
|
|
do_clip= TRUE;
|
|
|
|
|
}
|
2010-01-30 03:22:22 +00:00
|
|
|
|
|
|
|
|
for(; ar; ar= ar->prev) {
|
|
|
|
|
if(ar->alignment==RGN_ALIGN_QSPLIT) {
|
|
|
|
|
rv3d= ar->regiondata;
|
|
|
|
|
rv3d->viewlock= viewlock;
|
2010-11-08 03:44:52 +00:00
|
|
|
|
|
|
|
|
if(do_clip && (viewlock & RV3D_BOXCLIP)==0) {
|
|
|
|
|
rv3d->rflag &= ~RV3D_BOXCLIP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* use arsync so we sync with one of the aligned views below
|
|
|
|
|
* else the view jumps on changing view settings like 'clip'
|
|
|
|
|
* since it copies from the perspective view */
|
|
|
|
|
arsync= ar;
|
2010-01-30 03:22:22 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-08 03:44:52 +00:00
|
|
|
if(rv3d->viewlock & RV3D_BOXVIEW) {
|
|
|
|
|
view3d_boxview_copy(sa, arsync ? arsync : sa->regionbase.last);
|
|
|
|
|
}
|
2010-01-30 03:22:22 +00:00
|
|
|
|
|
|
|
|
ED_area_tag_redraw(sa);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* ************************** init for view ops **********************************/
|
2008-12-19 12:14:58 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
typedef struct ViewOpsData {
|
2009-01-20 14:23:32 +00:00
|
|
|
ScrArea *sa;
|
2008-12-19 17:14:02 +00:00
|
|
|
ARegion *ar;
|
2011-05-14 05:42:58 +00:00
|
|
|
View3D *v3d;
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
RegionView3D *rv3d;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2009-12-16 23:05:59 +00:00
|
|
|
/* needed for continuous zoom */
|
|
|
|
|
wmTimer *timer;
|
|
|
|
|
double timer_lastdraw;
|
|
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
float oldquat[4];
|
2011-11-11 05:34:07 +00:00
|
|
|
float viewquat[4]; /* working copy of rv3d->viewquat */
|
2008-12-19 17:14:02 +00:00
|
|
|
float trackvec[3];
|
2011-04-22 15:34:07 +00:00
|
|
|
float mousevec[3]; /* dolly only */
|
2008-12-19 17:14:02 +00:00
|
|
|
float reverse, dist0;
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
float grid, far;
|
2009-09-25 10:24:42 +00:00
|
|
|
short axis_snap; /* view rotate only */
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-12-09 00:45:50 +00:00
|
|
|
/* use for orbit selection and auto-dist */
|
|
|
|
|
float ofs[3], dyn_ofs[3];
|
|
|
|
|
short use_dyn_ofs;
|
|
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
int origx, origy, oldx, oldy;
|
2009-09-25 10:24:42 +00:00
|
|
|
int origkey; /* the key that triggered the operator */
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
} ViewOpsData;
|
2008-12-19 12:14:58 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
#define TRACKBALLSIZE (1.1)
|
2008-12-19 12:14:58 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
static void calctrackballvec(rcti *rect, int mx, int my, float *vec)
|
2008-12-19 12:14:58 +00:00
|
|
|
{
|
|
|
|
|
float x, y, radius, d, z, t;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 12:14:58 +00:00
|
|
|
radius= TRACKBALLSIZE;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 12:14:58 +00:00
|
|
|
/* normalize x and y */
|
2008-12-19 17:14:02 +00:00
|
|
|
x= (rect->xmax + rect->xmin)/2 - mx;
|
|
|
|
|
x/= (float)((rect->xmax - rect->xmin)/4);
|
|
|
|
|
y= (rect->ymax + rect->ymin)/2 - my;
|
|
|
|
|
y/= (float)((rect->ymax - rect->ymin)/2);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 12:14:58 +00:00
|
|
|
d = sqrt(x*x + y*y);
|
2011-08-25 15:49:52 +00:00
|
|
|
if (d < radius * (float)M_SQRT1_2) { /* Inside sphere */
|
|
|
|
|
z= sqrt(radius*radius - d*d);
|
|
|
|
|
}
|
|
|
|
|
else { /* On hyperbola */
|
|
|
|
|
t= radius / (float)M_SQRT2;
|
|
|
|
|
z= t*t / d;
|
2008-12-19 12:14:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vec[0]= x;
|
|
|
|
|
vec[1]= y;
|
|
|
|
|
vec[2]= -z; /* yah yah! */
|
2008-12-19 17:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
2008-12-19 12:14:58 +00:00
|
|
|
|
2009-11-25 14:13:43 +00:00
|
|
|
static void viewops_data_create(bContext *C, wmOperator *op, wmEvent *event)
|
2008-12-19 17:14:02 +00:00
|
|
|
{
|
2009-10-15 15:58:12 +00:00
|
|
|
static float lastofs[3] = {0,0,0};
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
RegionView3D *rv3d;
|
2008-12-19 17:14:02 +00:00
|
|
|
ViewOpsData *vod= MEM_callocN(sizeof(ViewOpsData), "viewops data");
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* store data */
|
|
|
|
|
op->customdata= vod;
|
2009-01-20 14:23:32 +00:00
|
|
|
vod->sa= CTX_wm_area(C);
|
2008-12-19 17:14:02 +00:00
|
|
|
vod->ar= CTX_wm_region(C);
|
2011-05-14 05:42:58 +00:00
|
|
|
vod->v3d= vod->sa->spacedata.first;
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
vod->rv3d= rv3d= vod->ar->regiondata;
|
2011-05-15 03:07:07 +00:00
|
|
|
|
|
|
|
|
/* set the view from the camera, if view locking is enabled.
|
|
|
|
|
* we may want to make this optional but for now its needed always */
|
|
|
|
|
ED_view3d_camera_lock_init(vod->v3d, vod->rv3d);
|
|
|
|
|
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
vod->dist0= rv3d->dist;
|
2011-11-11 05:34:07 +00:00
|
|
|
copy_qt_qt(vod->viewquat, rv3d->viewquat);
|
2010-07-26 06:34:56 +00:00
|
|
|
copy_qt_qt(vod->oldquat, rv3d->viewquat);
|
2008-12-19 17:14:02 +00:00
|
|
|
vod->origx= vod->oldx= event->x;
|
|
|
|
|
vod->origy= vod->oldy= event->y;
|
2009-09-25 10:24:42 +00:00
|
|
|
vod->origkey= event->type; /* the key that triggered the operator. */
|
2009-12-09 00:45:50 +00:00
|
|
|
vod->use_dyn_ofs= (U.uiflag & USER_ORBIT_SELECTION) ? 1:0;
|
2011-04-22 15:34:07 +00:00
|
|
|
copy_v3_v3(vod->ofs, rv3d->ofs);
|
2009-12-09 00:45:50 +00:00
|
|
|
|
|
|
|
|
if (vod->use_dyn_ofs) {
|
2009-10-15 15:58:12 +00:00
|
|
|
/* If there's no selection, lastofs is unmodified and last value since static */
|
2009-12-21 15:37:19 +00:00
|
|
|
calculateTransformCenter(C, V3D_CENTROID, lastofs);
|
2010-02-26 09:02:52 +00:00
|
|
|
negate_v3_v3(vod->dyn_ofs, lastofs);
|
2009-12-09 00:45:50 +00:00
|
|
|
}
|
|
|
|
|
else if (U.uiflag & USER_ORBIT_ZBUF) {
|
|
|
|
|
|
|
|
|
|
view3d_operator_needs_opengl(C); /* needed for zbuf drawing */
|
|
|
|
|
|
2011-05-20 13:09:34 +00:00
|
|
|
if((vod->use_dyn_ofs=ED_view3d_autodist(CTX_data_scene(C), vod->ar, vod->v3d, event->mval, vod->dyn_ofs))) {
|
2011-05-18 17:52:26 +00:00
|
|
|
if (rv3d->is_persp) {
|
2009-12-09 00:45:50 +00:00
|
|
|
float my_origin[3]; /* original G.vd->ofs */
|
|
|
|
|
float my_pivot[3]; /* view */
|
|
|
|
|
float dvec[3];
|
|
|
|
|
|
|
|
|
|
// locals for dist correction
|
|
|
|
|
float mat[3][3];
|
|
|
|
|
float upvec[3];
|
|
|
|
|
|
2010-07-26 06:34:56 +00:00
|
|
|
negate_v3_v3(my_origin, rv3d->ofs); /* ofs is flipped */
|
2009-12-09 00:45:50 +00:00
|
|
|
|
|
|
|
|
/* Set the dist value to be the distance from this 3d point */
|
|
|
|
|
/* this means youll always be able to zoom into it and panning wont go bad when dist was zero */
|
|
|
|
|
|
|
|
|
|
/* remove dist value */
|
|
|
|
|
upvec[0] = upvec[1] = 0;
|
|
|
|
|
upvec[2] = rv3d->dist;
|
|
|
|
|
copy_m3_m4(mat, rv3d->viewinv);
|
|
|
|
|
|
|
|
|
|
mul_m3_v3(mat, upvec);
|
|
|
|
|
sub_v3_v3v3(my_pivot, rv3d->ofs, upvec);
|
|
|
|
|
negate_v3(my_pivot); /* ofs is flipped */
|
|
|
|
|
|
2011-10-17 06:39:13 +00:00
|
|
|
/* find a new ofs value that is along the view axis (rather than the mouse location) */
|
2009-12-09 00:45:50 +00:00
|
|
|
closest_to_line_v3(dvec, vod->dyn_ofs, my_pivot, my_origin);
|
|
|
|
|
vod->dist0 = rv3d->dist = len_v3v3(my_pivot, dvec);
|
|
|
|
|
|
2010-02-25 20:26:38 +00:00
|
|
|
negate_v3_v3(rv3d->ofs, dvec);
|
2009-12-09 00:45:50 +00:00
|
|
|
}
|
|
|
|
|
negate_v3(vod->dyn_ofs);
|
2010-07-26 06:34:56 +00:00
|
|
|
copy_v3_v3(vod->ofs, rv3d->ofs);
|
2009-12-09 00:45:50 +00:00
|
|
|
}
|
2009-10-15 15:58:12 +00:00
|
|
|
}
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2011-05-20 13:50:41 +00:00
|
|
|
{
|
|
|
|
|
/* for dolly */
|
|
|
|
|
float mval_f[2];
|
|
|
|
|
VECCOPY2D(mval_f, event->mval);
|
|
|
|
|
ED_view3d_win_to_vector(vod->ar, mval_f, vod->mousevec);
|
|
|
|
|
}
|
2011-04-22 15:34:07 +00:00
|
|
|
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
/* lookup, we dont pass on v3d to prevent confusement */
|
2011-05-14 05:42:58 +00:00
|
|
|
vod->grid= vod->v3d->grid;
|
|
|
|
|
vod->far= vod->v3d->far;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
calctrackballvec(&vod->ar->winrct, event->x, event->y, vod->trackvec);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
initgrabz(rv3d, -rv3d->ofs[0], -rv3d->ofs[1], -rv3d->ofs[2]);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
vod->reverse= 1.0f;
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
if (rv3d->persmat[2][1] < 0.0f)
|
2008-12-19 17:14:02 +00:00
|
|
|
vod->reverse= -1.0f;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2009-11-25 14:13:43 +00:00
|
|
|
rv3d->rflag |= RV3D_NAVIGATING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void viewops_data_free(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2011-01-03 01:26:54 +00:00
|
|
|
ARegion *ar;
|
2009-11-25 14:13:43 +00:00
|
|
|
Paint *p = paint_get_active(CTX_data_scene(C));
|
|
|
|
|
|
2011-01-03 01:26:54 +00:00
|
|
|
if(op->customdata) {
|
|
|
|
|
ViewOpsData *vod= op->customdata;
|
|
|
|
|
ar= vod->ar;
|
|
|
|
|
vod->rv3d->rflag &= ~RV3D_NAVIGATING;
|
2009-11-25 14:13:43 +00:00
|
|
|
|
2011-01-03 01:26:54 +00:00
|
|
|
if(vod->timer)
|
|
|
|
|
WM_event_remove_timer(CTX_wm_manager(C), vod->timer->win, vod->timer);
|
2009-11-25 14:13:43 +00:00
|
|
|
|
2011-01-03 01:26:54 +00:00
|
|
|
MEM_freeN(vod);
|
|
|
|
|
op->customdata= NULL;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ar= CTX_wm_region(C);
|
|
|
|
|
}
|
2009-12-16 23:05:59 +00:00
|
|
|
|
2011-01-03 01:26:54 +00:00
|
|
|
if(p && (p->flags & PAINT_FAST_NAVIGATE))
|
|
|
|
|
ED_region_tag_redraw(ar);
|
2008-12-26 10:31:44 +00:00
|
|
|
}
|
2008-12-19 17:14:02 +00:00
|
|
|
|
|
|
|
|
/* ************************** viewrotate **********************************/
|
|
|
|
|
|
|
|
|
|
static const float thres = 0.93f; //cos(20 deg);
|
|
|
|
|
|
|
|
|
|
#define COS45 0.70710678118654746
|
|
|
|
|
#define SIN45 COS45
|
|
|
|
|
|
2010-07-26 19:57:44 +00:00
|
|
|
static float snapquats[39][5] = {
|
|
|
|
|
/*{q0, q1, q3, q4, view}*/
|
|
|
|
|
{COS45, -SIN45, 0.0, 0.0, RV3D_VIEW_FRONT}, //front
|
|
|
|
|
{0.0, 0.0, -SIN45, -SIN45, RV3D_VIEW_BACK}, //back
|
|
|
|
|
{1.0, 0.0, 0.0, 0.0, RV3D_VIEW_TOP}, //top
|
|
|
|
|
{0.0, -1.0, 0.0, 0.0, RV3D_VIEW_BOTTOM}, //bottom
|
|
|
|
|
{0.5, -0.5, -0.5, -0.5, RV3D_VIEW_RIGHT}, //left
|
|
|
|
|
{0.5, -0.5, 0.5, 0.5, RV3D_VIEW_LEFT}, //right
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* some more 45 deg snaps */
|
2010-07-26 19:57:44 +00:00
|
|
|
{0.65328145027160645, -0.65328145027160645, 0.27059805393218994, 0.27059805393218994, 0},
|
|
|
|
|
{0.92387950420379639, 0.0, 0.0, 0.38268342614173889, 0},
|
|
|
|
|
{0.0, -0.92387950420379639, 0.38268342614173889, 0.0, 0},
|
|
|
|
|
{0.35355335474014282, -0.85355335474014282, 0.35355338454246521, 0.14644660055637360, 0},
|
|
|
|
|
{0.85355335474014282, -0.35355335474014282, 0.14644660055637360, 0.35355338454246521, 0},
|
|
|
|
|
{0.49999994039535522, -0.49999994039535522, 0.49999997019767761, 0.49999997019767761, 0},
|
|
|
|
|
{0.27059802412986755, -0.65328145027160645, 0.65328145027160645, 0.27059802412986755, 0},
|
|
|
|
|
{0.65328145027160645, -0.27059802412986755, 0.27059802412986755, 0.65328145027160645, 0},
|
|
|
|
|
{0.27059799432754517, -0.27059799432754517, 0.65328139066696167, 0.65328139066696167, 0},
|
|
|
|
|
{0.38268336653709412, 0.0, 0.0, 0.92387944459915161, 0},
|
|
|
|
|
{0.0, -0.38268336653709412, 0.92387944459915161, 0.0, 0},
|
|
|
|
|
{0.14644658565521240, -0.35355335474014282, 0.85355335474014282, 0.35355335474014282, 0},
|
|
|
|
|
{0.35355335474014282, -0.14644658565521240, 0.35355335474014282, 0.85355335474014282, 0},
|
|
|
|
|
{0.0, 0.0, 0.92387944459915161, 0.38268336653709412, 0},
|
|
|
|
|
{-0.0, 0.0, 0.38268336653709412, 0.92387944459915161, 0},
|
|
|
|
|
{-0.27059802412986755, 0.27059802412986755, 0.65328133106231689, 0.65328133106231689, 0},
|
|
|
|
|
{-0.38268339633941650, 0.0, 0.0, 0.92387938499450684, 0},
|
|
|
|
|
{0.0, 0.38268339633941650, 0.92387938499450684, 0.0, 0},
|
|
|
|
|
{-0.14644658565521240, 0.35355338454246521, 0.85355329513549805, 0.35355332493782043, 0},
|
|
|
|
|
{-0.35355338454246521, 0.14644658565521240, 0.35355332493782043, 0.85355329513549805, 0},
|
|
|
|
|
{-0.49999991059303284, 0.49999991059303284, 0.49999985098838806, 0.49999985098838806, 0},
|
|
|
|
|
{-0.27059799432754517, 0.65328145027160645, 0.65328139066696167, 0.27059799432754517, 0},
|
|
|
|
|
{-0.65328145027160645, 0.27059799432754517, 0.27059799432754517, 0.65328139066696167, 0},
|
|
|
|
|
{-0.65328133106231689, 0.65328133106231689, 0.27059793472290039, 0.27059793472290039, 0},
|
|
|
|
|
{-0.92387932538986206, 0.0, 0.0, 0.38268333673477173, 0},
|
|
|
|
|
{0.0, 0.92387932538986206, 0.38268333673477173, 0.0, 0},
|
|
|
|
|
{-0.35355329513549805, 0.85355329513549805, 0.35355329513549805, 0.14644657075405121, 0},
|
|
|
|
|
{-0.85355329513549805, 0.35355329513549805, 0.14644657075405121, 0.35355329513549805, 0},
|
|
|
|
|
{-0.38268330693244934, 0.92387938499450684, 0.0, 0.0, 0},
|
|
|
|
|
{-0.92387938499450684, 0.38268330693244934, 0.0, 0.0, 0},
|
|
|
|
|
{-COS45, 0.0, 0.0, SIN45, 0},
|
|
|
|
|
{COS45, 0.0, 0.0, SIN45, 0},
|
|
|
|
|
{0.0, 0.0, 0.0, 1.0, 0}
|
2008-12-19 17:14:02 +00:00
|
|
|
};
|
|
|
|
|
|
2009-09-25 10:24:42 +00:00
|
|
|
enum {
|
|
|
|
|
VIEW_PASS= 0,
|
|
|
|
|
VIEW_APPLY,
|
|
|
|
|
VIEW_CONFIRM
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
|
|
|
|
|
#define VIEW_MODAL_CONFIRM 1 /* used for all view operations */
|
|
|
|
|
#define VIEWROT_MODAL_AXIS_SNAP_ENABLE 2
|
|
|
|
|
#define VIEWROT_MODAL_AXIS_SNAP_DISABLE 3
|
2010-01-06 12:22:59 +00:00
|
|
|
#define VIEWROT_MODAL_SWITCH_ZOOM 4
|
|
|
|
|
#define VIEWROT_MODAL_SWITCH_MOVE 5
|
|
|
|
|
#define VIEWROT_MODAL_SWITCH_ROTATE 6
|
2009-09-25 10:24:42 +00:00
|
|
|
|
|
|
|
|
/* called in transform_ops.c, on each regeneration of keymaps */
|
Key Configuration
Keymaps are now saveable and configurable from the user preferences, note
that editing one item in a keymap means the whole keymap is now defined by
the user and will not be updated by Blender, an option for syncing might be
added later. The outliner interface is still there, but I will probably
remove it.
There's actually 3 levels now:
* Default builtin key configuration.
* Key configuration loaded from .py file, for configs like Blender 2.4x
or other 3D applications.
* Keymaps edited by the user and saved in .B.blend. These can be saved
to .py files as well to make creating distributable configurations
easier.
Also, user preferences sections were reorganized a bit, now there is:
Interface, Editing, Input, Files and System.
Implementation notes:
* wmKeyConfig was added which represents a key configuration containing
keymaps.
* wmKeymapItem was renamed to wmKeyMapItem for consistency with wmKeyMap.
* Modal maps are not wrapped yet.
* User preferences DNA file reading did not support newdataadr() yet,
added this now for reading keymaps.
* Key configuration related settings are now RNA wrapped.
* is_property_set and is_property_hidden python methods were added.
2009-10-08 18:40:03 +00:00
|
|
|
void viewrotate_modal_keymap(wmKeyConfig *keyconf)
|
2009-09-25 10:24:42 +00:00
|
|
|
{
|
|
|
|
|
static EnumPropertyItem modal_items[] = {
|
2010-01-25 23:57:08 +00:00
|
|
|
{VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
|
2009-09-25 10:24:42 +00:00
|
|
|
|
|
|
|
|
{VIEWROT_MODAL_AXIS_SNAP_ENABLE, "AXIS_SNAP_ENABLE", 0, "Enable Axis Snap", ""},
|
2010-01-06 20:29:49 +00:00
|
|
|
{VIEWROT_MODAL_AXIS_SNAP_DISABLE, "AXIS_SNAP_DISABLE", 0, "Disable Axis Snap", ""},
|
2010-01-06 12:22:59 +00:00
|
|
|
|
|
|
|
|
{VIEWROT_MODAL_SWITCH_ZOOM, "SWITCH_TO_ZOOM", 0, "Switch to Zoom"},
|
|
|
|
|
{VIEWROT_MODAL_SWITCH_MOVE, "SWITCH_TO_MOVE", 0, "Switch to Move"},
|
2009-09-25 10:24:42 +00:00
|
|
|
|
|
|
|
|
{0, NULL, 0, NULL, NULL}};
|
|
|
|
|
|
Key Configuration
Keymaps are now saveable and configurable from the user preferences, note
that editing one item in a keymap means the whole keymap is now defined by
the user and will not be updated by Blender, an option for syncing might be
added later. The outliner interface is still there, but I will probably
remove it.
There's actually 3 levels now:
* Default builtin key configuration.
* Key configuration loaded from .py file, for configs like Blender 2.4x
or other 3D applications.
* Keymaps edited by the user and saved in .B.blend. These can be saved
to .py files as well to make creating distributable configurations
easier.
Also, user preferences sections were reorganized a bit, now there is:
Interface, Editing, Input, Files and System.
Implementation notes:
* wmKeyConfig was added which represents a key configuration containing
keymaps.
* wmKeymapItem was renamed to wmKeyMapItem for consistency with wmKeyMap.
* Modal maps are not wrapped yet.
* User preferences DNA file reading did not support newdataadr() yet,
added this now for reading keymaps.
* Key configuration related settings are now RNA wrapped.
* is_property_set and is_property_hidden python methods were added.
2009-10-08 18:40:03 +00:00
|
|
|
wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "View3D Rotate Modal");
|
2009-09-25 10:24:42 +00:00
|
|
|
|
|
|
|
|
/* this function is called for each spacetype, only needs to add map once */
|
|
|
|
|
if(keymap) return;
|
|
|
|
|
|
Key Configuration
Keymaps are now saveable and configurable from the user preferences, note
that editing one item in a keymap means the whole keymap is now defined by
the user and will not be updated by Blender, an option for syncing might be
added later. The outliner interface is still there, but I will probably
remove it.
There's actually 3 levels now:
* Default builtin key configuration.
* Key configuration loaded from .py file, for configs like Blender 2.4x
or other 3D applications.
* Keymaps edited by the user and saved in .B.blend. These can be saved
to .py files as well to make creating distributable configurations
easier.
Also, user preferences sections were reorganized a bit, now there is:
Interface, Editing, Input, Files and System.
Implementation notes:
* wmKeyConfig was added which represents a key configuration containing
keymaps.
* wmKeymapItem was renamed to wmKeyMapItem for consistency with wmKeyMap.
* Modal maps are not wrapped yet.
* User preferences DNA file reading did not support newdataadr() yet,
added this now for reading keymaps.
* Key configuration related settings are now RNA wrapped.
* is_property_set and is_property_hidden python methods were added.
2009-10-08 18:40:03 +00:00
|
|
|
keymap= WM_modalkeymap_add(keyconf, "View3D Rotate Modal", modal_items);
|
2009-09-25 10:24:42 +00:00
|
|
|
|
|
|
|
|
/* items for modal map */
|
|
|
|
|
WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, VIEW_MODAL_CONFIRM);
|
|
|
|
|
WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, VIEW_MODAL_CONFIRM);
|
|
|
|
|
|
2010-01-06 12:22:59 +00:00
|
|
|
WM_modalkeymap_add_item(keymap, LEFTALTKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_AXIS_SNAP_ENABLE);
|
|
|
|
|
WM_modalkeymap_add_item(keymap, LEFTALTKEY, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_AXIS_SNAP_DISABLE);
|
2009-09-25 10:24:42 +00:00
|
|
|
|
2010-07-15 03:49:32 +00:00
|
|
|
/* disabled mode switching for now, can re-implement better, later on
|
2010-01-06 12:22:59 +00:00
|
|
|
WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ZOOM);
|
|
|
|
|
WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ZOOM);
|
|
|
|
|
WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_MOVE);
|
2010-07-15 03:49:32 +00:00
|
|
|
*/
|
2010-01-06 12:22:59 +00:00
|
|
|
|
2009-09-25 10:24:42 +00:00
|
|
|
/* assign map to operators */
|
|
|
|
|
WM_modalkeymap_assign(keymap, "VIEW3D_OT_rotate");
|
|
|
|
|
|
|
|
|
|
}
|
2008-12-19 17:14:02 +00:00
|
|
|
|
2009-09-25 10:24:42 +00:00
|
|
|
static void viewrotate_apply(ViewOpsData *vod, int x, int y)
|
2008-12-19 17:14:02 +00:00
|
|
|
{
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
RegionView3D *rv3d= vod->rv3d;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2011-05-15 03:42:28 +00:00
|
|
|
rv3d->view= RV3D_VIEW_USER; /* need to reset everytime because of view snapping */
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
if (U.flag & USER_TRACKBALL) {
|
|
|
|
|
float phi, si, q1[4], dvec[3], newvec[3];
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
calctrackballvec(&vod->ar->winrct, x, y, newvec);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
sub_v3_v3v3(dvec, newvec, vod->trackvec);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
si= sqrt(dvec[0]*dvec[0]+ dvec[1]*dvec[1]+ dvec[2]*dvec[2]);
|
2011-03-27 15:57:27 +00:00
|
|
|
si /= (float)(2.0 * TRACKBALLSIZE);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
cross_v3_v3v3(q1+1, vod->trackvec, newvec);
|
|
|
|
|
normalize_v3(q1+1);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* Allow for rotation beyond the interval
|
|
|
|
|
* [-pi, pi] */
|
2011-03-27 15:57:27 +00:00
|
|
|
while (si > 1.0f)
|
|
|
|
|
si -= 2.0f;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* This relation is used instead of
|
|
|
|
|
* phi = asin(si) so that the angle
|
|
|
|
|
* of rotation is linearly proportional
|
|
|
|
|
* to the distance that the mouse is
|
|
|
|
|
* dragged. */
|
2011-03-27 15:57:27 +00:00
|
|
|
phi = si * (float)(M_PI / 2.0);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
q1[0]= cos(phi);
|
2010-02-25 20:26:38 +00:00
|
|
|
mul_v3_fl(q1+1, sin(phi));
|
2011-11-11 05:34:07 +00:00
|
|
|
mul_qt_qtqt(vod->viewquat, q1, vod->oldquat);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2009-12-09 00:45:50 +00:00
|
|
|
if (vod->use_dyn_ofs) {
|
2008-12-19 17:14:02 +00:00
|
|
|
/* compute the post multiplication quat, to rotate the offset correctly */
|
2010-07-26 06:34:56 +00:00
|
|
|
copy_qt_qt(q1, vod->oldquat);
|
2009-11-10 20:43:45 +00:00
|
|
|
conjugate_qt(q1);
|
2011-11-11 05:34:07 +00:00
|
|
|
mul_qt_qtqt(q1, q1, vod->viewquat);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
conjugate_qt(q1); /* conj == inv for unit quat */
|
2010-07-26 06:34:56 +00:00
|
|
|
copy_v3_v3(rv3d->ofs, vod->ofs);
|
2010-04-23 23:57:00 +00:00
|
|
|
sub_v3_v3(rv3d->ofs, vod->dyn_ofs);
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_qt_v3(q1, rv3d->ofs);
|
2010-04-21 12:27:48 +00:00
|
|
|
add_v3_v3(rv3d->ofs, vod->dyn_ofs);
|
2008-12-19 17:14:02 +00:00
|
|
|
}
|
2008-12-26 10:31:44 +00:00
|
|
|
}
|
2008-12-19 17:14:02 +00:00
|
|
|
else {
|
|
|
|
|
/* New turntable view code by John Aughey */
|
2010-02-25 20:26:38 +00:00
|
|
|
float phi, q1[4];
|
2008-12-19 17:14:02 +00:00
|
|
|
float m[3][3];
|
|
|
|
|
float m_inv[3][3];
|
2011-03-27 15:57:27 +00:00
|
|
|
float xvec[3] = {1.0f, 0.0f, 0.0f};
|
2008-12-19 17:14:02 +00:00
|
|
|
/* Sensitivity will control how fast the viewport rotates. 0.0035 was
|
|
|
|
|
obtained experimentally by looking at viewport rotation sensitivities
|
|
|
|
|
on other modeling programs. */
|
|
|
|
|
/* Perhaps this should be a configurable user parameter. */
|
2011-03-27 15:57:27 +00:00
|
|
|
const float sensitivity = 0.0035f;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* Get the 3x3 matrix and its inverse from the quaternion */
|
2011-11-11 05:34:07 +00:00
|
|
|
quat_to_mat3( m,vod->viewquat);
|
2009-11-10 20:43:45 +00:00
|
|
|
invert_m3_m3(m_inv,m);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* Determine the direction of the x vector (for rotating up and down) */
|
2010-01-11 11:14:36 +00:00
|
|
|
/* This can likely be computed directly from the quaternion. */
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_m3_v3(m_inv,xvec);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* Perform the up/down rotation */
|
|
|
|
|
phi = sensitivity * -(y - vod->oldy);
|
|
|
|
|
q1[0] = cos(phi);
|
2010-02-25 20:26:38 +00:00
|
|
|
mul_v3_v3fl(q1+1, xvec, sin(phi));
|
2011-11-11 05:34:07 +00:00
|
|
|
mul_qt_qtqt(vod->viewquat, vod->viewquat, q1);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2009-12-09 00:45:50 +00:00
|
|
|
if (vod->use_dyn_ofs) {
|
2009-11-10 20:43:45 +00:00
|
|
|
conjugate_qt(q1); /* conj == inv for unit quat */
|
2010-04-23 23:57:00 +00:00
|
|
|
sub_v3_v3(rv3d->ofs, vod->dyn_ofs);
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_qt_v3(q1, rv3d->ofs);
|
2010-04-21 12:27:48 +00:00
|
|
|
add_v3_v3(rv3d->ofs, vod->dyn_ofs);
|
2008-12-19 17:14:02 +00:00
|
|
|
}
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* Perform the orbital rotation */
|
|
|
|
|
phi = sensitivity * vod->reverse * (x - vod->oldx);
|
|
|
|
|
q1[0] = cos(phi);
|
|
|
|
|
q1[1] = q1[2] = 0.0;
|
|
|
|
|
q1[3] = sin(phi);
|
2011-11-11 05:34:07 +00:00
|
|
|
mul_qt_qtqt(vod->viewquat, vod->viewquat, q1);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2009-12-09 00:45:50 +00:00
|
|
|
if (vod->use_dyn_ofs) {
|
2009-11-10 20:43:45 +00:00
|
|
|
conjugate_qt(q1);
|
2010-04-23 23:57:00 +00:00
|
|
|
sub_v3_v3(rv3d->ofs, vod->dyn_ofs);
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_qt_v3(q1, rv3d->ofs);
|
2010-04-21 12:27:48 +00:00
|
|
|
add_v3_v3(rv3d->ofs, vod->dyn_ofs);
|
2008-12-19 17:14:02 +00:00
|
|
|
}
|
2008-12-19 12:14:58 +00:00
|
|
|
}
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* check for view snap */
|
2009-09-25 10:24:42 +00:00
|
|
|
if (vod->axis_snap){
|
2008-12-19 17:14:02 +00:00
|
|
|
int i;
|
2010-07-26 00:11:14 +00:00
|
|
|
float viewquat_inv[4];
|
|
|
|
|
float zaxis[3]={0,0,1};
|
2011-11-11 05:34:07 +00:00
|
|
|
invert_qt_qt(viewquat_inv, vod->viewquat);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2010-07-26 00:11:14 +00:00
|
|
|
mul_qt_v3(viewquat_inv, zaxis);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
for (i = 0 ; i < 39; i++){
|
2010-07-26 00:11:14 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
float view = (int)snapquats[i][4];
|
2010-07-26 00:11:14 +00:00
|
|
|
float viewquat_inv_test[4];
|
|
|
|
|
float zaxis_test[3]={0,0,1};
|
|
|
|
|
|
|
|
|
|
invert_qt_qt(viewquat_inv_test, snapquats[i]);
|
|
|
|
|
mul_qt_v3(viewquat_inv_test, zaxis_test);
|
|
|
|
|
|
2011-03-27 15:57:27 +00:00
|
|
|
if(angle_v3v3(zaxis_test, zaxis) < DEG2RADF(45/3)) {
|
2010-07-26 00:11:14 +00:00
|
|
|
/* find the best roll */
|
|
|
|
|
float quat_roll[4], quat_final[4], quat_best[4];
|
|
|
|
|
float viewquat_align[4]; /* viewquat aligned to zaxis_test */
|
|
|
|
|
float viewquat_align_inv[4]; /* viewquat aligned to zaxis_test */
|
|
|
|
|
float best_angle = FLT_MAX;
|
|
|
|
|
int j;
|
|
|
|
|
|
|
|
|
|
/* viewquat_align is the original viewquat aligned to the snapped axis
|
|
|
|
|
* for testing roll */
|
|
|
|
|
rotation_between_vecs_to_quat(viewquat_align, zaxis_test, zaxis);
|
|
|
|
|
normalize_qt(viewquat_align);
|
2011-11-11 05:34:07 +00:00
|
|
|
mul_qt_qtqt(viewquat_align, vod->viewquat, viewquat_align);
|
2010-07-26 00:11:14 +00:00
|
|
|
normalize_qt(viewquat_align);
|
|
|
|
|
invert_qt_qt(viewquat_align_inv, viewquat_align);
|
|
|
|
|
|
|
|
|
|
/* find best roll */
|
|
|
|
|
for(j= 0; j<8; j++) {
|
|
|
|
|
float angle;
|
|
|
|
|
float xaxis1[3]={1,0,0};
|
|
|
|
|
float xaxis2[3]={1,0,0};
|
|
|
|
|
float quat_final_inv[4];
|
|
|
|
|
|
2011-03-27 15:57:27 +00:00
|
|
|
axis_angle_to_quat(quat_roll, zaxis_test, (float)j * DEG2RADF(45.0f));
|
2010-07-26 00:11:14 +00:00
|
|
|
normalize_qt(quat_roll);
|
|
|
|
|
|
|
|
|
|
mul_qt_qtqt(quat_final, snapquats[i], quat_roll);
|
|
|
|
|
normalize_qt(quat_final);
|
|
|
|
|
|
|
|
|
|
/* compare 2 vector angles to find the least roll */
|
|
|
|
|
invert_qt_qt(quat_final_inv, quat_final);
|
|
|
|
|
mul_qt_v3(viewquat_align_inv, xaxis1);
|
|
|
|
|
mul_qt_v3(quat_final_inv, xaxis2);
|
|
|
|
|
angle= angle_v3v3(xaxis1, xaxis2);
|
|
|
|
|
|
|
|
|
|
if(angle <= best_angle) {
|
|
|
|
|
best_angle= angle;
|
|
|
|
|
copy_qt_qt(quat_best, quat_final);
|
|
|
|
|
if(j) view= 0; /* view grid assumes certain up axis */
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2011-11-11 05:34:07 +00:00
|
|
|
copy_qt_qt(vod->viewquat, quat_best);
|
2010-07-26 00:11:14 +00:00
|
|
|
rv3d->view= view; /* if we snap to a rolled camera the grid is invalid */
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-19 12:14:58 +00:00
|
|
|
}
|
2008-12-19 17:14:02 +00:00
|
|
|
vod->oldx= x;
|
|
|
|
|
vod->oldy= y;
|
|
|
|
|
|
2011-01-21 02:32:58 +00:00
|
|
|
/* avoid precision loss over time */
|
2011-11-11 05:34:07 +00:00
|
|
|
normalize_qt(vod->viewquat);
|
|
|
|
|
|
|
|
|
|
/* use a working copy so view rotation locking doesnt overwrite the locked
|
|
|
|
|
* rotation back into the view we calculate with */
|
|
|
|
|
copy_qt_qt(rv3d->viewquat, vod->viewquat);
|
2010-12-22 02:28:06 +00:00
|
|
|
|
2011-05-14 17:50:33 +00:00
|
|
|
ED_view3d_camera_lock_sync(vod->v3d, rv3d);
|
|
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
ED_region_tag_redraw(vod->ar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int viewrotate_modal(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
|
{
|
2008-12-19 19:27:41 +00:00
|
|
|
ViewOpsData *vod= op->customdata;
|
2009-09-25 10:24:42 +00:00
|
|
|
short event_code= VIEW_PASS;
|
2008-12-19 17:14:02 +00:00
|
|
|
|
|
|
|
|
/* execute the events */
|
2009-09-25 10:24:42 +00:00
|
|
|
if(event->type==MOUSEMOVE) {
|
|
|
|
|
event_code= VIEW_APPLY;
|
|
|
|
|
}
|
|
|
|
|
else if(event->type==EVT_MODAL_MAP) {
|
|
|
|
|
switch (event->val) {
|
|
|
|
|
case VIEW_MODAL_CONFIRM:
|
|
|
|
|
event_code= VIEW_CONFIRM;
|
|
|
|
|
break;
|
|
|
|
|
case VIEWROT_MODAL_AXIS_SNAP_ENABLE:
|
|
|
|
|
vod->axis_snap= TRUE;
|
|
|
|
|
event_code= VIEW_APPLY;
|
|
|
|
|
break;
|
|
|
|
|
case VIEWROT_MODAL_AXIS_SNAP_DISABLE:
|
|
|
|
|
vod->axis_snap= FALSE;
|
|
|
|
|
event_code= VIEW_APPLY;
|
|
|
|
|
break;
|
2010-01-06 12:22:59 +00:00
|
|
|
case VIEWROT_MODAL_SWITCH_ZOOM:
|
|
|
|
|
WM_operator_name_call(C, "VIEW3D_OT_zoom", WM_OP_INVOKE_DEFAULT, NULL);
|
|
|
|
|
event_code= VIEW_CONFIRM;
|
|
|
|
|
break;
|
|
|
|
|
case VIEWROT_MODAL_SWITCH_MOVE:
|
|
|
|
|
WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, NULL);
|
|
|
|
|
event_code= VIEW_CONFIRM;
|
|
|
|
|
break;
|
2009-09-25 10:24:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(event->type==vod->origkey && event->val==KM_RELEASE) {
|
|
|
|
|
event_code= VIEW_CONFIRM;
|
|
|
|
|
}
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2009-09-25 10:24:42 +00:00
|
|
|
if(event_code==VIEW_APPLY) {
|
|
|
|
|
viewrotate_apply(vod, event->x, event->y);
|
|
|
|
|
}
|
|
|
|
|
else if (event_code==VIEW_CONFIRM) {
|
2011-05-21 08:56:37 +00:00
|
|
|
ED_view3d_depth_tag_update(vod->rv3d);
|
2009-11-25 14:13:43 +00:00
|
|
|
viewops_data_free(C, op);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2009-09-25 10:24:42 +00:00
|
|
|
return OPERATOR_FINISHED;
|
2008-12-19 12:14:58 +00:00
|
|
|
}
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
2008-12-19 12:14:58 +00:00
|
|
|
}
|
|
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
static int viewrotate_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
2008-12-19 12:14:58 +00:00
|
|
|
{
|
2008-12-19 17:14:02 +00:00
|
|
|
ViewOpsData *vod;
|
2010-11-16 09:35:58 +00:00
|
|
|
RegionView3D *rv3d;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* makes op->customdata */
|
2009-11-25 14:13:43 +00:00
|
|
|
viewops_data_create(C, op, event);
|
2008-12-19 17:14:02 +00:00
|
|
|
vod= op->customdata;
|
2010-11-16 09:35:58 +00:00
|
|
|
rv3d= vod->rv3d;
|
|
|
|
|
|
|
|
|
|
if(rv3d->viewlock) { /* poll should check but in some cases fails, see poll func for details */
|
|
|
|
|
viewops_data_free(C, op);
|
2011-02-05 19:07:54 +00:00
|
|
|
return OPERATOR_PASS_THROUGH;
|
2010-11-16 09:35:58 +00:00
|
|
|
}
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* switch from camera view when: */
|
2010-11-16 09:35:58 +00:00
|
|
|
if(rv3d->persp != RV3D_PERSP) {
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2010-11-08 03:55:03 +00:00
|
|
|
if (U.uiflag & USER_AUTOPERSP) {
|
2011-05-23 15:46:09 +00:00
|
|
|
if(!ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) {
|
2011-05-15 02:39:36 +00:00
|
|
|
rv3d->persp= RV3D_PERSP;
|
|
|
|
|
}
|
2010-11-08 03:55:03 +00:00
|
|
|
}
|
2010-11-16 09:35:58 +00:00
|
|
|
else if(rv3d->persp==RV3D_CAMOB) {
|
2010-06-01 19:48:55 +00:00
|
|
|
|
|
|
|
|
/* changed since 2.4x, use the camera view */
|
2011-05-14 05:42:58 +00:00
|
|
|
if(vod->v3d->camera) {
|
|
|
|
|
ED_view3d_from_object(vod->v3d->camera, rv3d->ofs, rv3d->viewquat, &rv3d->dist, NULL);
|
2010-11-08 02:30:46 +00:00
|
|
|
}
|
2010-11-08 03:55:03 +00:00
|
|
|
|
2011-05-23 15:46:09 +00:00
|
|
|
if(!ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) {
|
2010-11-16 09:35:58 +00:00
|
|
|
rv3d->persp= rv3d->lpersp;
|
2010-11-08 02:30:46 +00:00
|
|
|
}
|
2010-06-01 19:48:55 +00:00
|
|
|
}
|
2008-12-19 17:14:02 +00:00
|
|
|
ED_region_tag_redraw(vod->ar);
|
|
|
|
|
}
|
2010-01-11 11:14:36 +00:00
|
|
|
|
|
|
|
|
if (event->type == MOUSEPAN) {
|
|
|
|
|
viewrotate_apply(vod, event->prevx, event->prevy);
|
2011-05-21 08:56:37 +00:00
|
|
|
ED_view3d_depth_tag_update(rv3d);
|
2010-01-11 11:14:36 +00:00
|
|
|
|
|
|
|
|
viewops_data_free(C, op);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
else if (event->type == MOUSEROTATE) {
|
|
|
|
|
/* MOUSEROTATE performs orbital rotation, so y axis delta is set to 0 */
|
|
|
|
|
viewrotate_apply(vod, event->prevx, event->y);
|
2011-05-21 08:56:37 +00:00
|
|
|
ED_view3d_depth_tag_update(rv3d);
|
2010-01-11 11:14:36 +00:00
|
|
|
|
|
|
|
|
viewops_data_free(C, op);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* add temp handler */
|
|
|
|
|
WM_event_add_modal_handler(C, op);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2010-01-11 11:14:36 +00:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
2008-12-19 17:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-03 20:47:03 +00:00
|
|
|
static int view3d_camera_active_poll(bContext *C)
|
|
|
|
|
{
|
|
|
|
|
if(ED_operator_view3d_active(C)) {
|
|
|
|
|
RegionView3D *rv3d= CTX_wm_region_view3d(C);
|
2010-07-06 11:50:59 +00:00
|
|
|
if(rv3d && rv3d->persp==RV3D_CAMOB) {
|
2010-07-03 20:47:03 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-16 06:57:37 +00:00
|
|
|
/* test for unlocked camera view in quad view */
|
|
|
|
|
static int view3d_camera_user_poll(bContext *C)
|
|
|
|
|
{
|
|
|
|
|
View3D *v3d;
|
|
|
|
|
ARegion *ar;
|
|
|
|
|
|
|
|
|
|
if (ED_view3d_context_user_region(C, &v3d, &ar)) {
|
|
|
|
|
RegionView3D *rv3d = ar->regiondata;
|
|
|
|
|
if(rv3d->persp==RV3D_CAMOB) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-06 11:04:54 +00:00
|
|
|
static int viewrotate_cancel(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
viewops_data_free(C, op);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-25 10:24:42 +00:00
|
|
|
void VIEW3D_OT_rotate(wmOperatorType *ot)
|
2008-12-19 17:14:02 +00:00
|
|
|
{
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* identifiers */
|
|
|
|
|
ot->name= "Rotate view";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Rotate the view";
|
2009-09-25 10:24:42 +00:00
|
|
|
ot->idname= "VIEW3D_OT_rotate";
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->invoke= viewrotate_invoke;
|
|
|
|
|
ot->modal= viewrotate_modal;
|
2011-02-05 19:07:54 +00:00
|
|
|
ot->poll= ED_operator_region_view3d_active;
|
2011-06-06 11:04:54 +00:00
|
|
|
ot->cancel= viewrotate_cancel;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-31 19:40:40 +00:00
|
|
|
/* flags */
|
2009-10-10 17:19:49 +00:00
|
|
|
ot->flag= OPTYPE_BLOCKING|OPTYPE_GRAB_POINTER;
|
2008-12-19 17:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-14 21:20:45 +00:00
|
|
|
// NDOF utility functions
|
|
|
|
|
// (should these functions live in this file?)
|
2011-08-02 08:12:50 +00:00
|
|
|
float ndof_to_axis_angle(struct wmNDOFMotionData* ndof, float axis[3])
|
2011-08-02 07:08:22 +00:00
|
|
|
{
|
|
|
|
|
return ndof->dt * normalize_v3_v3(axis, ndof->rvec);
|
|
|
|
|
}
|
2011-07-14 21:20:45 +00:00
|
|
|
|
|
|
|
|
void ndof_to_quat(struct wmNDOFMotionData* ndof, float q[4])
|
2011-08-02 07:08:22 +00:00
|
|
|
{
|
|
|
|
|
float axis[3];
|
|
|
|
|
float angle;
|
2011-06-20 21:34:23 +00:00
|
|
|
|
2011-08-02 08:12:50 +00:00
|
|
|
angle= ndof_to_axis_angle(ndof, axis);
|
2011-08-02 07:08:22 +00:00
|
|
|
axis_angle_to_quat(q, axis, angle);
|
|
|
|
|
}
|
2011-06-20 21:34:23 +00:00
|
|
|
|
2011-08-27 11:52:59 +00:00
|
|
|
/* -- "orbit" navigation (trackball/turntable)
|
|
|
|
|
* -- zooming
|
|
|
|
|
* -- panning in rotationally-locked views
|
|
|
|
|
*/
|
2011-08-02 05:52:27 +00:00
|
|
|
static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
|
2010-08-07 10:57:15 +00:00
|
|
|
{
|
2011-08-27 11:52:59 +00:00
|
|
|
if (event->type != NDOF_MOTION) {
|
2011-08-06 22:31:16 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2011-08-27 11:52:59 +00:00
|
|
|
}
|
2011-08-06 22:31:16 +00:00
|
|
|
else {
|
2011-08-27 11:52:59 +00:00
|
|
|
View3D *v3d= CTX_wm_view3d(C);
|
2011-08-06 22:31:16 +00:00
|
|
|
RegionView3D* rv3d = CTX_wm_region_view3d(C);
|
|
|
|
|
wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata;
|
2010-08-07 10:57:15 +00:00
|
|
|
|
2011-08-27 11:52:59 +00:00
|
|
|
ED_view3d_camera_lock_init(v3d, rv3d);
|
|
|
|
|
|
2011-08-06 22:31:16 +00:00
|
|
|
rv3d->rot_angle = 0.f; // off by default, until changed later this function
|
2011-06-28 15:59:46 +00:00
|
|
|
|
2011-08-06 22:31:16 +00:00
|
|
|
if (ndof->progress != P_FINISHING) {
|
|
|
|
|
const float dt = ndof->dt;
|
|
|
|
|
|
|
|
|
|
// tune these until everything feels right
|
|
|
|
|
const float rot_sensitivity = 1.f;
|
|
|
|
|
const float zoom_sensitivity = 1.f;
|
|
|
|
|
const float pan_sensitivity = 1.f;
|
|
|
|
|
|
|
|
|
|
// rather have bool, but...
|
|
|
|
|
int has_rotation = rv3d->viewlock != RV3D_LOCKED && !is_zero_v3(ndof->rvec);
|
|
|
|
|
|
|
|
|
|
float view_inv[4];
|
2011-06-27 20:12:10 +00:00
|
|
|
invert_qt_qt(view_inv, rv3d->viewquat);
|
2011-08-06 22:31:16 +00:00
|
|
|
|
|
|
|
|
//#define DEBUG_NDOF_MOTION
|
|
|
|
|
#ifdef DEBUG_NDOF_MOTION
|
|
|
|
|
printf("ndof: T=(%.2f,%.2f,%.2f) R=(%.2f,%.2f,%.2f) dt=%.3f delivered to 3D view\n",
|
|
|
|
|
ndof->tx, ndof->ty, ndof->tz, ndof->rx, ndof->ry, ndof->rz, ndof->dt);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (ndof->tvec[2]) {
|
|
|
|
|
// Zoom!
|
|
|
|
|
// velocity should be proportional to the linear velocity attained by rotational motion of same strength
|
|
|
|
|
// [got that?]
|
|
|
|
|
// proportional to arclength = radius * angle
|
|
|
|
|
|
|
|
|
|
float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tvec[2];
|
|
|
|
|
|
|
|
|
|
if (U.ndof_flag & NDOF_ZOOM_INVERT)
|
|
|
|
|
zoom_distance = -zoom_distance;
|
|
|
|
|
|
|
|
|
|
rv3d->dist += zoom_distance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rv3d->viewlock == RV3D_LOCKED) {
|
|
|
|
|
/* rotation not allowed -- explore panning options instead */
|
|
|
|
|
float pan_vec[3] = {ndof->tvec[0], ndof->tvec[1], 0.0f};
|
|
|
|
|
mul_v3_fl(pan_vec, pan_sensitivity * rv3d->dist * dt);
|
|
|
|
|
|
|
|
|
|
/* transform motion from view to world coordinates */
|
|
|
|
|
invert_qt_qt(view_inv, rv3d->viewquat);
|
|
|
|
|
mul_qt_v3(view_inv, pan_vec);
|
|
|
|
|
|
|
|
|
|
/* move center of view opposite of hand motion (this is camera mode, not object mode) */
|
|
|
|
|
sub_v3_v3(rv3d->ofs, pan_vec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (has_rotation) {
|
|
|
|
|
|
|
|
|
|
rv3d->view = RV3D_VIEW_USER;
|
|
|
|
|
|
|
|
|
|
if (U.flag & USER_TRACKBALL) {
|
|
|
|
|
float rot[4];
|
|
|
|
|
float axis[3];
|
|
|
|
|
float angle = rot_sensitivity * ndof_to_axis_angle(ndof, axis);
|
2011-09-07 10:33:46 +00:00
|
|
|
|
2011-11-14 14:02:19 +00:00
|
|
|
if (U.ndof_flag & NDOF_ROLL_INVERT_AXIS)
|
2011-09-07 10:33:46 +00:00
|
|
|
axis[2] = -axis[2];
|
|
|
|
|
|
2011-11-14 14:02:19 +00:00
|
|
|
if (U.ndof_flag & NDOF_TILT_INVERT_AXIS)
|
2011-09-07 10:33:46 +00:00
|
|
|
axis[0] = -axis[0];
|
|
|
|
|
|
2011-11-14 14:02:19 +00:00
|
|
|
if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS)
|
2011-09-07 10:33:46 +00:00
|
|
|
axis[1] = -axis[1];
|
|
|
|
|
|
2011-08-06 22:31:16 +00:00
|
|
|
// transform rotation axis from view to world coordinates
|
|
|
|
|
mul_qt_v3(view_inv, axis);
|
|
|
|
|
|
|
|
|
|
// update the onscreen doo-dad
|
|
|
|
|
rv3d->rot_angle = angle;
|
|
|
|
|
copy_v3_v3(rv3d->rot_axis, axis);
|
|
|
|
|
|
|
|
|
|
axis_angle_to_quat(rot, axis, angle);
|
|
|
|
|
|
|
|
|
|
// apply rotation
|
|
|
|
|
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
|
|
|
|
|
} else {
|
|
|
|
|
/* turntable view code by John Aughey, adapted for 3D mouse by [mce] */
|
|
|
|
|
float angle, rot[4];
|
|
|
|
|
float xvec[3] = {1,0,0};
|
|
|
|
|
|
|
|
|
|
/* Determine the direction of the x vector (for rotating up and down) */
|
|
|
|
|
mul_qt_v3(view_inv, xvec);
|
|
|
|
|
|
|
|
|
|
/* Perform the up/down rotation */
|
|
|
|
|
angle = rot_sensitivity * dt * ndof->rvec[0];
|
2011-11-14 14:02:19 +00:00
|
|
|
if (U.ndof_flag & NDOF_TILT_INVERT_AXIS)
|
2011-08-06 22:31:16 +00:00
|
|
|
angle = -angle;
|
|
|
|
|
rot[0] = cos(angle);
|
|
|
|
|
mul_v3_v3fl(rot+1, xvec, sin(angle));
|
|
|
|
|
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
|
|
|
|
|
|
|
|
|
|
/* Perform the orbital rotation */
|
|
|
|
|
angle = rot_sensitivity * dt * ndof->rvec[1];
|
2011-11-14 14:02:19 +00:00
|
|
|
if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS)
|
2011-08-06 22:31:16 +00:00
|
|
|
angle = -angle;
|
|
|
|
|
|
|
|
|
|
// update the onscreen doo-dad
|
|
|
|
|
rv3d->rot_angle = angle;
|
|
|
|
|
rv3d->rot_axis[0] = 0;
|
|
|
|
|
rv3d->rot_axis[1] = 0;
|
|
|
|
|
rv3d->rot_axis[2] = 1;
|
|
|
|
|
|
|
|
|
|
rot[0] = cos(angle);
|
|
|
|
|
rot[1] = rot[2] = 0.0;
|
|
|
|
|
rot[3] = sin(angle);
|
|
|
|
|
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
|
|
|
|
|
}
|
2011-07-26 02:35:46 +00:00
|
|
|
}
|
2011-06-20 01:54:49 +00:00
|
|
|
}
|
2010-08-07 10:57:15 +00:00
|
|
|
|
2011-08-27 11:52:59 +00:00
|
|
|
ED_view3d_camera_lock_sync(v3d, rv3d);
|
|
|
|
|
|
2011-08-06 22:31:16 +00:00
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
2011-06-28 15:59:46 +00:00
|
|
|
|
2011-08-06 22:31:16 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
2011-06-20 01:54:49 +00:00
|
|
|
}
|
2011-01-21 09:59:58 +00:00
|
|
|
|
2011-07-26 22:43:07 +00:00
|
|
|
void VIEW3D_OT_ndof_orbit(struct wmOperatorType *ot)
|
2010-08-07 10:57:15 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2011-07-26 22:43:07 +00:00
|
|
|
ot->name = "NDOF Orbit View";
|
2011-09-19 12:26:20 +00:00
|
|
|
ot->description = "Explore every angle of an object using the 3D mouse";
|
2011-07-26 22:43:07 +00:00
|
|
|
ot->idname = "VIEW3D_OT_ndof_orbit";
|
2010-08-07 10:57:15 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2011-07-14 03:28:31 +00:00
|
|
|
ot->invoke = ndof_orbit_invoke;
|
2010-08-07 10:57:15 +00:00
|
|
|
ot->poll = ED_operator_view3d_active;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-27 11:52:59 +00:00
|
|
|
/* -- "pan" navigation
|
|
|
|
|
* -- zoom or dolly?
|
|
|
|
|
*/
|
2011-08-02 05:52:27 +00:00
|
|
|
static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
|
2011-07-26 22:43:07 +00:00
|
|
|
{
|
2011-08-27 11:52:59 +00:00
|
|
|
if (event->type != NDOF_MOTION) {
|
2011-08-06 22:31:16 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2011-08-27 11:52:59 +00:00
|
|
|
}
|
2011-08-06 22:31:16 +00:00
|
|
|
else {
|
2011-08-27 11:52:59 +00:00
|
|
|
View3D *v3d= CTX_wm_view3d(C);
|
2011-08-06 22:31:16 +00:00
|
|
|
RegionView3D* rv3d = CTX_wm_region_view3d(C);
|
|
|
|
|
wmNDOFMotionData* ndof = (wmNDOFMotionData*) event->customdata;
|
2011-07-26 22:43:07 +00:00
|
|
|
|
2011-08-27 11:52:59 +00:00
|
|
|
ED_view3d_camera_lock_init(v3d, rv3d);
|
2011-07-26 22:43:07 +00:00
|
|
|
|
2011-08-06 22:31:16 +00:00
|
|
|
rv3d->rot_angle = 0.f; // we're panning here! so erase any leftover rotation from other operators
|
|
|
|
|
|
|
|
|
|
if (ndof->progress != P_FINISHING) {
|
|
|
|
|
const float dt = ndof->dt;
|
|
|
|
|
float view_inv[4];
|
2011-07-26 22:43:07 +00:00
|
|
|
#if 0 // ------------------------------------------- zoom with Z
|
2011-08-06 22:31:16 +00:00
|
|
|
// tune these until everything feels right
|
|
|
|
|
const float zoom_sensitivity = 1.f;
|
|
|
|
|
const float pan_sensitivity = 1.f;
|
|
|
|
|
|
|
|
|
|
float pan_vec[3] = {
|
|
|
|
|
ndof->tx, ndof->ty, 0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// "zoom in" or "translate"? depends on zoom mode in user settings?
|
|
|
|
|
if (ndof->tz) {
|
|
|
|
|
float zoom_distance = zoom_sensitivity * rv3d->dist * dt * ndof->tz;
|
|
|
|
|
rv3d->dist += zoom_distance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mul_v3_fl(pan_vec, pan_sensitivity * rv3d->dist * dt);
|
2011-07-26 22:43:07 +00:00
|
|
|
#else // ------------------------------------------------------- dolly with Z
|
2011-08-06 22:31:16 +00:00
|
|
|
float speed = 10.f; // blender units per second
|
|
|
|
|
// ^^ this is ok for default cube scene, but should scale with.. something
|
2011-07-26 22:43:07 +00:00
|
|
|
|
2011-08-06 22:31:16 +00:00
|
|
|
// tune these until everything feels right
|
|
|
|
|
const float forward_sensitivity = 1.f;
|
|
|
|
|
const float vertical_sensitivity = 0.4f;
|
|
|
|
|
const float lateral_sensitivity = 0.6f;
|
2011-07-26 22:43:07 +00:00
|
|
|
|
2011-09-07 10:33:46 +00:00
|
|
|
float pan_vec[3];
|
|
|
|
|
|
2011-11-14 14:02:19 +00:00
|
|
|
if (U.ndof_flag & NDOF_PANX_INVERT_AXIS)
|
2011-09-07 10:33:46 +00:00
|
|
|
pan_vec[0] = -lateral_sensitivity * ndof->tvec[0];
|
|
|
|
|
else
|
|
|
|
|
pan_vec[0] = lateral_sensitivity * ndof->tvec[0];
|
|
|
|
|
|
2011-11-14 14:02:19 +00:00
|
|
|
if (U.ndof_flag & NDOF_PANZ_INVERT_AXIS)
|
2011-09-07 10:33:46 +00:00
|
|
|
pan_vec[1] = -vertical_sensitivity * ndof->tvec[1];
|
|
|
|
|
else
|
|
|
|
|
pan_vec[1] = vertical_sensitivity * ndof->tvec[1];
|
|
|
|
|
|
2011-11-14 14:02:19 +00:00
|
|
|
if (U.ndof_flag & NDOF_PANY_INVERT_AXIS)
|
2011-09-07 10:33:46 +00:00
|
|
|
pan_vec[2] = -forward_sensitivity * ndof->tvec[2];
|
|
|
|
|
else
|
|
|
|
|
pan_vec[2] = forward_sensitivity * ndof->tvec[2];
|
2011-07-26 22:43:07 +00:00
|
|
|
|
2011-08-06 22:31:16 +00:00
|
|
|
mul_v3_fl(pan_vec, speed * dt);
|
2011-07-26 22:43:07 +00:00
|
|
|
#endif
|
2011-08-06 22:31:16 +00:00
|
|
|
/* transform motion from view to world coordinates */
|
|
|
|
|
invert_qt_qt(view_inv, rv3d->viewquat);
|
|
|
|
|
mul_qt_v3(view_inv, pan_vec);
|
2011-07-26 22:43:07 +00:00
|
|
|
|
2011-08-06 22:31:16 +00:00
|
|
|
/* move center of view opposite of hand motion (this is camera mode, not object mode) */
|
|
|
|
|
sub_v3_v3(rv3d->ofs, pan_vec);
|
|
|
|
|
}
|
2011-07-26 22:43:07 +00:00
|
|
|
|
2011-08-27 11:52:59 +00:00
|
|
|
ED_view3d_camera_lock_sync(v3d, rv3d);
|
|
|
|
|
|
2011-08-06 22:31:16 +00:00
|
|
|
ED_region_tag_redraw(CTX_wm_region(C));
|
2011-07-26 22:43:07 +00:00
|
|
|
|
2011-08-06 22:31:16 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
2011-07-26 22:43:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VIEW3D_OT_ndof_pan(struct wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "NDOF Pan View";
|
2011-09-19 12:26:20 +00:00
|
|
|
ot->description = "Position your viewpoint with the 3D mouse";
|
2011-07-26 22:43:07 +00:00
|
|
|
ot->idname = "VIEW3D_OT_ndof_pan";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->invoke = ndof_pan_invoke;
|
|
|
|
|
ot->poll = ED_operator_view3d_active;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* ************************ viewmove ******************************** */
|
|
|
|
|
|
2009-09-25 10:24:42 +00:00
|
|
|
|
|
|
|
|
/* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
|
|
|
|
|
|
|
|
|
|
/* called in transform_ops.c, on each regeneration of keymaps */
|
Key Configuration
Keymaps are now saveable and configurable from the user preferences, note
that editing one item in a keymap means the whole keymap is now defined by
the user and will not be updated by Blender, an option for syncing might be
added later. The outliner interface is still there, but I will probably
remove it.
There's actually 3 levels now:
* Default builtin key configuration.
* Key configuration loaded from .py file, for configs like Blender 2.4x
or other 3D applications.
* Keymaps edited by the user and saved in .B.blend. These can be saved
to .py files as well to make creating distributable configurations
easier.
Also, user preferences sections were reorganized a bit, now there is:
Interface, Editing, Input, Files and System.
Implementation notes:
* wmKeyConfig was added which represents a key configuration containing
keymaps.
* wmKeymapItem was renamed to wmKeyMapItem for consistency with wmKeyMap.
* Modal maps are not wrapped yet.
* User preferences DNA file reading did not support newdataadr() yet,
added this now for reading keymaps.
* Key configuration related settings are now RNA wrapped.
* is_property_set and is_property_hidden python methods were added.
2009-10-08 18:40:03 +00:00
|
|
|
void viewmove_modal_keymap(wmKeyConfig *keyconf)
|
2009-09-25 10:24:42 +00:00
|
|
|
{
|
|
|
|
|
static EnumPropertyItem modal_items[] = {
|
|
|
|
|
{VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
|
2010-07-29 07:21:57 +00:00
|
|
|
|
|
|
|
|
{VIEWROT_MODAL_SWITCH_ZOOM, "SWITCH_TO_ZOOM", 0, "Switch to Zoom"},
|
|
|
|
|
{VIEWROT_MODAL_SWITCH_ROTATE, "SWITCH_TO_ROTATE", 0, "Switch to Rotate"},
|
2009-09-25 10:24:42 +00:00
|
|
|
|
|
|
|
|
{0, NULL, 0, NULL, NULL}};
|
|
|
|
|
|
Key Configuration
Keymaps are now saveable and configurable from the user preferences, note
that editing one item in a keymap means the whole keymap is now defined by
the user and will not be updated by Blender, an option for syncing might be
added later. The outliner interface is still there, but I will probably
remove it.
There's actually 3 levels now:
* Default builtin key configuration.
* Key configuration loaded from .py file, for configs like Blender 2.4x
or other 3D applications.
* Keymaps edited by the user and saved in .B.blend. These can be saved
to .py files as well to make creating distributable configurations
easier.
Also, user preferences sections were reorganized a bit, now there is:
Interface, Editing, Input, Files and System.
Implementation notes:
* wmKeyConfig was added which represents a key configuration containing
keymaps.
* wmKeymapItem was renamed to wmKeyMapItem for consistency with wmKeyMap.
* Modal maps are not wrapped yet.
* User preferences DNA file reading did not support newdataadr() yet,
added this now for reading keymaps.
* Key configuration related settings are now RNA wrapped.
* is_property_set and is_property_hidden python methods were added.
2009-10-08 18:40:03 +00:00
|
|
|
wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "View3D Move Modal");
|
2009-09-25 10:24:42 +00:00
|
|
|
|
|
|
|
|
/* this function is called for each spacetype, only needs to add map once */
|
|
|
|
|
if(keymap) return;
|
|
|
|
|
|
Key Configuration
Keymaps are now saveable and configurable from the user preferences, note
that editing one item in a keymap means the whole keymap is now defined by
the user and will not be updated by Blender, an option for syncing might be
added later. The outliner interface is still there, but I will probably
remove it.
There's actually 3 levels now:
* Default builtin key configuration.
* Key configuration loaded from .py file, for configs like Blender 2.4x
or other 3D applications.
* Keymaps edited by the user and saved in .B.blend. These can be saved
to .py files as well to make creating distributable configurations
easier.
Also, user preferences sections were reorganized a bit, now there is:
Interface, Editing, Input, Files and System.
Implementation notes:
* wmKeyConfig was added which represents a key configuration containing
keymaps.
* wmKeymapItem was renamed to wmKeyMapItem for consistency with wmKeyMap.
* Modal maps are not wrapped yet.
* User preferences DNA file reading did not support newdataadr() yet,
added this now for reading keymaps.
* Key configuration related settings are now RNA wrapped.
* is_property_set and is_property_hidden python methods were added.
2009-10-08 18:40:03 +00:00
|
|
|
keymap= WM_modalkeymap_add(keyconf, "View3D Move Modal", modal_items);
|
2009-09-25 10:24:42 +00:00
|
|
|
|
|
|
|
|
/* items for modal map */
|
|
|
|
|
WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, VIEW_MODAL_CONFIRM);
|
|
|
|
|
WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, VIEW_MODAL_CONFIRM);
|
|
|
|
|
|
2010-07-15 03:49:32 +00:00
|
|
|
/* disabled mode switching for now, can re-implement better, later on
|
2010-01-06 12:22:59 +00:00
|
|
|
WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ZOOM);
|
|
|
|
|
WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ZOOM);
|
|
|
|
|
WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE);
|
2010-07-15 03:49:32 +00:00
|
|
|
*/
|
2010-01-06 12:22:59 +00:00
|
|
|
|
2009-09-25 10:24:42 +00:00
|
|
|
/* assign map to operators */
|
|
|
|
|
WM_modalkeymap_assign(keymap, "VIEW3D_OT_move");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
static void viewmove_apply(ViewOpsData *vod, int x, int y)
|
|
|
|
|
{
|
2011-05-23 15:46:09 +00:00
|
|
|
if((vod->rv3d->persp==RV3D_CAMOB) && !ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) {
|
2011-05-20 04:14:29 +00:00
|
|
|
const float zoomfac= BKE_screen_view3d_zoom_to_fac((float)vod->rv3d->camzoom) * 2.0f;
|
2010-09-11 04:39:00 +00:00
|
|
|
vod->rv3d->camdx += (vod->oldx - x)/(vod->ar->winx * zoomfac);
|
|
|
|
|
vod->rv3d->camdy += (vod->oldy - y)/(vod->ar->winy * zoomfac);
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
CLAMP(vod->rv3d->camdx, -1.0f, 1.0f);
|
|
|
|
|
CLAMP(vod->rv3d->camdy, -1.0f, 1.0f);
|
2008-12-19 12:14:58 +00:00
|
|
|
}
|
2008-12-19 17:14:02 +00:00
|
|
|
else {
|
|
|
|
|
float dvec[3];
|
2011-05-20 13:50:41 +00:00
|
|
|
float mval_f[2];
|
|
|
|
|
|
|
|
|
|
mval_f[0]= x - vod->oldx;
|
|
|
|
|
mval_f[1]= y - vod->oldy;
|
|
|
|
|
ED_view3d_win_to_delta(vod->ar, mval_f, dvec);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2010-04-21 12:27:48 +00:00
|
|
|
add_v3_v3(vod->rv3d->ofs, dvec);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2.5
Smaller jobs, all in one commit!
- Moved object_do_update out of view3d drawing, into
the event system (currently after notifiers).
Depsgraph calls for setting update flags will have to
keep track of each Screen's needs, so a UI showing only
a Sequencer doesn't do objects.
- Added button in "Properties region" in 3D window to set
or disable 4-split, including the 3 options it has.
(lock, box, clip)
- Restored legacy code for UI, to make things work like
bone rename, autocomplete.
- Node editor now shows Curves widgets again
- Bugfix: composite job increased Viewer user id count
- Bugfix: Node editor, not "Enable nodes" still called
a Job, which didn't do anything
- Various code cleaning, unused vars and prototypes.
2009-02-11 16:54:55 +00:00
|
|
|
if(vod->rv3d->viewlock & RV3D_BOXVIEW)
|
2009-01-20 14:23:32 +00:00
|
|
|
view3d_boxview_sync(vod->sa, vod->ar);
|
2008-12-19 17:14:02 +00:00
|
|
|
}
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
vod->oldx= x;
|
|
|
|
|
vod->oldy= y;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2011-05-14 17:50:33 +00:00
|
|
|
ED_view3d_camera_lock_sync(vod->v3d, vod->rv3d);
|
|
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
ED_region_tag_redraw(vod->ar);
|
|
|
|
|
}
|
2008-12-19 12:14:58 +00:00
|
|
|
|
|
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
static int viewmove_modal(bContext *C, wmOperator *op, wmEvent *event)
|
2008-12-26 10:31:44 +00:00
|
|
|
{
|
2009-09-25 10:24:42 +00:00
|
|
|
|
2008-12-19 19:27:41 +00:00
|
|
|
ViewOpsData *vod= op->customdata;
|
2009-09-25 10:24:42 +00:00
|
|
|
short event_code= VIEW_PASS;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* execute the events */
|
2009-09-25 10:24:42 +00:00
|
|
|
if(event->type==MOUSEMOVE) {
|
|
|
|
|
event_code= VIEW_APPLY;
|
|
|
|
|
}
|
|
|
|
|
else if(event->type==EVT_MODAL_MAP) {
|
|
|
|
|
switch (event->val) {
|
|
|
|
|
case VIEW_MODAL_CONFIRM:
|
|
|
|
|
event_code= VIEW_CONFIRM;
|
|
|
|
|
break;
|
2010-01-06 12:22:59 +00:00
|
|
|
case VIEWROT_MODAL_SWITCH_ZOOM:
|
|
|
|
|
WM_operator_name_call(C, "VIEW3D_OT_zoom", WM_OP_INVOKE_DEFAULT, NULL);
|
|
|
|
|
event_code= VIEW_CONFIRM;
|
|
|
|
|
break;
|
|
|
|
|
case VIEWROT_MODAL_SWITCH_ROTATE:
|
|
|
|
|
WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL);
|
|
|
|
|
event_code= VIEW_CONFIRM;
|
|
|
|
|
break;
|
2009-09-25 10:24:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(event->type==vod->origkey && event->val==KM_RELEASE) {
|
|
|
|
|
event_code= VIEW_CONFIRM;
|
|
|
|
|
}
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2009-09-25 10:24:42 +00:00
|
|
|
if(event_code==VIEW_APPLY) {
|
|
|
|
|
viewmove_apply(vod, event->x, event->y);
|
|
|
|
|
}
|
|
|
|
|
else if (event_code==VIEW_CONFIRM) {
|
2011-05-21 08:56:37 +00:00
|
|
|
ED_view3d_depth_tag_update(vod->rv3d);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2009-11-25 14:13:43 +00:00
|
|
|
viewops_data_free(C, op);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2009-09-25 10:24:42 +00:00
|
|
|
return OPERATOR_FINISHED;
|
2008-12-19 17:14:02 +00:00
|
|
|
}
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int viewmove_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
|
{
|
2011-05-14 17:50:33 +00:00
|
|
|
ViewOpsData *vod;
|
|
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* makes op->customdata */
|
2009-11-25 14:13:43 +00:00
|
|
|
viewops_data_create(C, op, event);
|
2011-05-14 17:50:33 +00:00
|
|
|
vod= op->customdata;
|
|
|
|
|
|
2010-01-11 11:14:36 +00:00
|
|
|
if (event->type == MOUSEPAN) {
|
|
|
|
|
viewmove_apply(vod, event->prevx, event->prevy);
|
2011-05-21 08:56:37 +00:00
|
|
|
ED_view3d_depth_tag_update(vod->rv3d);
|
2010-01-11 11:14:36 +00:00
|
|
|
|
|
|
|
|
viewops_data_free(C, op);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* add temp handler */
|
|
|
|
|
WM_event_add_modal_handler(C, op);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2010-01-11 11:14:36 +00:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
2008-12-19 17:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
2011-06-06 11:04:54 +00:00
|
|
|
static int viewmove_cancel(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
viewops_data_free(C, op);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-25 10:24:42 +00:00
|
|
|
void VIEW3D_OT_move(wmOperatorType *ot)
|
2008-12-19 17:14:02 +00:00
|
|
|
{
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* identifiers */
|
2009-03-23 03:14:56 +00:00
|
|
|
ot->name= "Move view";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Move the view";
|
2009-09-25 10:24:42 +00:00
|
|
|
ot->idname= "VIEW3D_OT_move";
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->invoke= viewmove_invoke;
|
|
|
|
|
ot->modal= viewmove_modal;
|
2008-12-26 19:07:31 +00:00
|
|
|
ot->poll= ED_operator_view3d_active;
|
2011-06-06 11:04:54 +00:00
|
|
|
ot->cancel= viewmove_cancel;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-31 19:40:40 +00:00
|
|
|
/* flags */
|
2009-10-10 17:19:49 +00:00
|
|
|
ot->flag= OPTYPE_BLOCKING|OPTYPE_GRAB_POINTER;
|
2008-12-19 17:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ************************ viewzoom ******************************** */
|
|
|
|
|
|
2011-05-22 11:36:56 +00:00
|
|
|
/* viewdolly_modal_keymap has an exact copy of this, apply fixes to both */
|
2009-09-25 10:24:42 +00:00
|
|
|
/* called in transform_ops.c, on each regeneration of keymaps */
|
Key Configuration
Keymaps are now saveable and configurable from the user preferences, note
that editing one item in a keymap means the whole keymap is now defined by
the user and will not be updated by Blender, an option for syncing might be
added later. The outliner interface is still there, but I will probably
remove it.
There's actually 3 levels now:
* Default builtin key configuration.
* Key configuration loaded from .py file, for configs like Blender 2.4x
or other 3D applications.
* Keymaps edited by the user and saved in .B.blend. These can be saved
to .py files as well to make creating distributable configurations
easier.
Also, user preferences sections were reorganized a bit, now there is:
Interface, Editing, Input, Files and System.
Implementation notes:
* wmKeyConfig was added which represents a key configuration containing
keymaps.
* wmKeymapItem was renamed to wmKeyMapItem for consistency with wmKeyMap.
* Modal maps are not wrapped yet.
* User preferences DNA file reading did not support newdataadr() yet,
added this now for reading keymaps.
* Key configuration related settings are now RNA wrapped.
* is_property_set and is_property_hidden python methods were added.
2009-10-08 18:40:03 +00:00
|
|
|
void viewzoom_modal_keymap(wmKeyConfig *keyconf)
|
2009-09-25 10:24:42 +00:00
|
|
|
{
|
|
|
|
|
static EnumPropertyItem modal_items[] = {
|
|
|
|
|
{VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
|
2010-07-29 07:21:57 +00:00
|
|
|
|
|
|
|
|
{VIEWROT_MODAL_SWITCH_ROTATE, "SWITCH_TO_ROTATE", 0, "Switch to Rotate"},
|
|
|
|
|
{VIEWROT_MODAL_SWITCH_MOVE, "SWITCH_TO_MOVE", 0, "Switch to Move"},
|
2009-09-25 10:24:42 +00:00
|
|
|
|
|
|
|
|
{0, NULL, 0, NULL, NULL}};
|
|
|
|
|
|
Key Configuration
Keymaps are now saveable and configurable from the user preferences, note
that editing one item in a keymap means the whole keymap is now defined by
the user and will not be updated by Blender, an option for syncing might be
added later. The outliner interface is still there, but I will probably
remove it.
There's actually 3 levels now:
* Default builtin key configuration.
* Key configuration loaded from .py file, for configs like Blender 2.4x
or other 3D applications.
* Keymaps edited by the user and saved in .B.blend. These can be saved
to .py files as well to make creating distributable configurations
easier.
Also, user preferences sections were reorganized a bit, now there is:
Interface, Editing, Input, Files and System.
Implementation notes:
* wmKeyConfig was added which represents a key configuration containing
keymaps.
* wmKeymapItem was renamed to wmKeyMapItem for consistency with wmKeyMap.
* Modal maps are not wrapped yet.
* User preferences DNA file reading did not support newdataadr() yet,
added this now for reading keymaps.
* Key configuration related settings are now RNA wrapped.
* is_property_set and is_property_hidden python methods were added.
2009-10-08 18:40:03 +00:00
|
|
|
wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "View3D Zoom Modal");
|
2009-09-25 10:24:42 +00:00
|
|
|
|
|
|
|
|
/* this function is called for each spacetype, only needs to add map once */
|
|
|
|
|
if(keymap) return;
|
|
|
|
|
|
Key Configuration
Keymaps are now saveable and configurable from the user preferences, note
that editing one item in a keymap means the whole keymap is now defined by
the user and will not be updated by Blender, an option for syncing might be
added later. The outliner interface is still there, but I will probably
remove it.
There's actually 3 levels now:
* Default builtin key configuration.
* Key configuration loaded from .py file, for configs like Blender 2.4x
or other 3D applications.
* Keymaps edited by the user and saved in .B.blend. These can be saved
to .py files as well to make creating distributable configurations
easier.
Also, user preferences sections were reorganized a bit, now there is:
Interface, Editing, Input, Files and System.
Implementation notes:
* wmKeyConfig was added which represents a key configuration containing
keymaps.
* wmKeymapItem was renamed to wmKeyMapItem for consistency with wmKeyMap.
* Modal maps are not wrapped yet.
* User preferences DNA file reading did not support newdataadr() yet,
added this now for reading keymaps.
* Key configuration related settings are now RNA wrapped.
* is_property_set and is_property_hidden python methods were added.
2009-10-08 18:40:03 +00:00
|
|
|
keymap= WM_modalkeymap_add(keyconf, "View3D Zoom Modal", modal_items);
|
2009-09-25 10:24:42 +00:00
|
|
|
|
|
|
|
|
/* items for modal map */
|
|
|
|
|
WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, VIEW_MODAL_CONFIRM);
|
|
|
|
|
WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, VIEW_MODAL_CONFIRM);
|
|
|
|
|
|
2010-07-15 03:49:32 +00:00
|
|
|
/* disabled mode switching for now, can re-implement better, later on
|
2010-01-06 12:22:59 +00:00
|
|
|
WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE);
|
|
|
|
|
WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE);
|
|
|
|
|
WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_MOVE);
|
2010-07-15 03:49:32 +00:00
|
|
|
*/
|
2010-01-06 12:22:59 +00:00
|
|
|
|
2009-09-25 10:24:42 +00:00
|
|
|
/* assign map to operators */
|
|
|
|
|
WM_modalkeymap_assign(keymap, "VIEW3D_OT_zoom");
|
|
|
|
|
}
|
|
|
|
|
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
static void view_zoom_mouseloc(ARegion *ar, float dfac, int mx, int my)
|
2008-12-19 17:14:02 +00:00
|
|
|
{
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
RegionView3D *rv3d= ar->regiondata;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
if(U.uiflag & USER_ZOOM_TO_MOUSEPOS) {
|
|
|
|
|
float dvec[3];
|
|
|
|
|
float tvec[3];
|
|
|
|
|
float tpos[3];
|
2011-05-20 13:50:41 +00:00
|
|
|
float mval_f[2];
|
2008-12-19 17:14:02 +00:00
|
|
|
float new_dist;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2010-02-25 20:26:38 +00:00
|
|
|
negate_v3_v3(tpos, rv3d->ofs);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* Project cursor position into 3D space */
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
initgrabz(rv3d, tpos[0], tpos[1], tpos[2]);
|
2011-05-20 13:50:41 +00:00
|
|
|
|
2011-05-23 02:59:29 +00:00
|
|
|
mval_f[0]= (float)(((mx - ar->winrct.xmin) * 2) - ar->winx) / 2.0f;
|
|
|
|
|
mval_f[1]= (float)(((my - ar->winrct.ymin) * 2) - ar->winy) / 2.0f;
|
2011-05-20 13:50:41 +00:00
|
|
|
ED_view3d_win_to_delta(ar, mval_f, dvec);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* Calculate view target position for dolly */
|
2010-02-25 20:26:38 +00:00
|
|
|
add_v3_v3v3(tvec, tpos, dvec);
|
|
|
|
|
negate_v3(tvec);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* Offset to target position and dolly */
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
new_dist = rv3d->dist * dfac;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2010-07-26 06:34:56 +00:00
|
|
|
copy_v3_v3(rv3d->ofs, tvec);
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
rv3d->dist = new_dist;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* Calculate final offset */
|
2010-02-25 20:26:38 +00:00
|
|
|
madd_v3_v3v3fl(rv3d->ofs, tvec, dvec, dfac);
|
2008-12-19 17:14:02 +00:00
|
|
|
} else {
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
rv3d->dist *= dfac;
|
2008-12-19 17:14:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-04-22 14:47:35 +00:00
|
|
|
static void viewzoom_apply(ViewOpsData *vod, int x, int y, const short viewzoom, const short zoom_invert)
|
2008-12-19 17:14:02 +00:00
|
|
|
{
|
|
|
|
|
float zfac=1.0;
|
|
|
|
|
|
2010-01-11 11:14:36 +00:00
|
|
|
if(viewzoom==USER_ZOOM_CONT) {
|
2009-12-16 23:05:59 +00:00
|
|
|
double time= PIL_check_seconds_timer();
|
|
|
|
|
float time_step= (float)(time - vod->timer_lastdraw);
|
2011-04-22 14:47:35 +00:00
|
|
|
float fac;
|
|
|
|
|
|
|
|
|
|
if (U.uiflag & USER_ZOOM_HORIZ) {
|
|
|
|
|
fac= (float)(x - vod->origx);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
fac= (float)(y - vod->origy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(zoom_invert) {
|
|
|
|
|
fac= -fac;
|
|
|
|
|
}
|
2009-12-16 23:05:59 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
// oldstyle zoom
|
2011-04-22 14:47:35 +00:00
|
|
|
zfac = 1.0f + ((fac / 20.0f) * time_step);
|
2009-12-16 23:05:59 +00:00
|
|
|
vod->timer_lastdraw= time;
|
2008-12-19 17:14:02 +00:00
|
|
|
}
|
2010-01-11 11:14:36 +00:00
|
|
|
else if(viewzoom==USER_ZOOM_SCALE) {
|
2008-12-19 17:14:02 +00:00
|
|
|
int ctr[2], len1, len2;
|
|
|
|
|
// method which zooms based on how far you move the mouse
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
ctr[0] = (vod->ar->winrct.xmax + vod->ar->winrct.xmin)/2;
|
|
|
|
|
ctr[1] = (vod->ar->winrct.ymax + vod->ar->winrct.ymin)/2;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
len1 = (int)sqrt((ctr[0] - x)*(ctr[0] - x) + (ctr[1] - y)*(ctr[1] - y)) + 5;
|
|
|
|
|
len2 = (int)sqrt((ctr[0] - vod->origx)*(ctr[0] - vod->origx) + (ctr[1] - vod->origy)*(ctr[1] - vod->origy)) + 5;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
zfac = vod->dist0 * ((float)len2/len1) / vod->rv3d->dist;
|
2008-12-19 17:14:02 +00:00
|
|
|
}
|
|
|
|
|
else { /* USER_ZOOM_DOLLY */
|
2009-11-28 04:43:15 +00:00
|
|
|
float len1, len2;
|
|
|
|
|
|
2011-04-22 14:47:35 +00:00
|
|
|
if (U.uiflag & USER_ZOOM_HORIZ) {
|
2009-11-28 04:43:15 +00:00
|
|
|
len1 = (vod->ar->winrct.xmax - x) + 5;
|
|
|
|
|
len2 = (vod->ar->winrct.xmax - vod->origx) + 5;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
len1 = (vod->ar->winrct.ymax - y) + 5;
|
|
|
|
|
len2 = (vod->ar->winrct.ymax - vod->origy) + 5;
|
|
|
|
|
}
|
2011-04-22 14:47:35 +00:00
|
|
|
if (zoom_invert) {
|
2009-11-28 04:43:15 +00:00
|
|
|
SWAP(float, len1, len2);
|
2011-04-22 14:47:35 +00:00
|
|
|
}
|
2009-11-28 04:43:15 +00:00
|
|
|
|
2011-03-27 15:57:27 +00:00
|
|
|
zfac = vod->dist0 * (2.0f * ((len2/len1)-1.0f) + 1.0f) / vod->rv3d->dist;
|
2008-12-19 17:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-27 15:57:27 +00:00
|
|
|
if(zfac != 1.0f && zfac*vod->rv3d->dist > 0.001f * vod->grid &&
|
2011-04-22 14:47:35 +00:00
|
|
|
zfac * vod->rv3d->dist < 10.0f * vod->far)
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
view_zoom_mouseloc(vod->ar, zfac, vod->oldx, vod->oldy);
|
2008-12-19 17:14:02 +00:00
|
|
|
|
2011-05-19 17:19:05 +00:00
|
|
|
/* these limits were in old code too */
|
|
|
|
|
if(vod->rv3d->dist<0.001f * vod->grid) vod->rv3d->dist= 0.001f * vod->grid;
|
|
|
|
|
if(vod->rv3d->dist>10.0f * vod->far) vod->rv3d->dist=10.0f * vod->far;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2.5
Smaller jobs, all in one commit!
- Moved object_do_update out of view3d drawing, into
the event system (currently after notifiers).
Depsgraph calls for setting update flags will have to
keep track of each Screen's needs, so a UI showing only
a Sequencer doesn't do objects.
- Added button in "Properties region" in 3D window to set
or disable 4-split, including the 3 options it has.
(lock, box, clip)
- Restored legacy code for UI, to make things work like
bone rename, autocomplete.
- Node editor now shows Curves widgets again
- Bugfix: composite job increased Viewer user id count
- Bugfix: Node editor, not "Enable nodes" still called
a Job, which didn't do anything
- Various code cleaning, unused vars and prototypes.
2009-02-11 16:54:55 +00:00
|
|
|
if(vod->rv3d->viewlock & RV3D_BOXVIEW)
|
2009-01-20 14:23:32 +00:00
|
|
|
view3d_boxview_sync(vod->sa, vod->ar);
|
|
|
|
|
|
2011-05-14 17:50:33 +00:00
|
|
|
ED_view3d_camera_lock_sync(vod->v3d, vod->rv3d);
|
|
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
ED_region_tag_redraw(vod->ar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int viewzoom_modal(bContext *C, wmOperator *op, wmEvent *event)
|
2008-12-26 10:31:44 +00:00
|
|
|
{
|
2008-12-19 19:27:41 +00:00
|
|
|
ViewOpsData *vod= op->customdata;
|
2009-09-25 10:24:42 +00:00
|
|
|
short event_code= VIEW_PASS;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* execute the events */
|
2010-02-06 12:44:37 +00:00
|
|
|
if (event->type == TIMER && event->customdata == vod->timer) {
|
|
|
|
|
/* continuous zoom */
|
|
|
|
|
event_code= VIEW_APPLY;
|
|
|
|
|
}
|
|
|
|
|
else if(event->type==MOUSEMOVE) {
|
2009-09-25 10:24:42 +00:00
|
|
|
event_code= VIEW_APPLY;
|
|
|
|
|
}
|
|
|
|
|
else if(event->type==EVT_MODAL_MAP) {
|
|
|
|
|
switch (event->val) {
|
|
|
|
|
case VIEW_MODAL_CONFIRM:
|
|
|
|
|
event_code= VIEW_CONFIRM;
|
|
|
|
|
break;
|
2010-01-06 12:22:59 +00:00
|
|
|
case VIEWROT_MODAL_SWITCH_MOVE:
|
|
|
|
|
WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, NULL);
|
|
|
|
|
event_code= VIEW_CONFIRM;
|
|
|
|
|
break;
|
|
|
|
|
case VIEWROT_MODAL_SWITCH_ROTATE:
|
|
|
|
|
WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL);
|
|
|
|
|
event_code= VIEW_CONFIRM;
|
|
|
|
|
break;
|
2009-09-25 10:24:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(event->type==vod->origkey && event->val==KM_RELEASE) {
|
|
|
|
|
event_code= VIEW_CONFIRM;
|
|
|
|
|
}
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2009-09-25 10:24:42 +00:00
|
|
|
if(event_code==VIEW_APPLY) {
|
2011-04-22 14:47:35 +00:00
|
|
|
viewzoom_apply(vod, event->x, event->y, U.viewzoom, (U.uiflag & USER_ZOOM_INVERT) != 0);
|
2009-09-25 10:24:42 +00:00
|
|
|
}
|
|
|
|
|
else if (event_code==VIEW_CONFIRM) {
|
2011-05-21 08:56:37 +00:00
|
|
|
ED_view3d_depth_tag_update(vod->rv3d);
|
2009-11-25 14:13:43 +00:00
|
|
|
viewops_data_free(C, op);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2009-09-25 10:24:42 +00:00
|
|
|
return OPERATOR_FINISHED;
|
2008-12-19 17:14:02 +00:00
|
|
|
}
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-19 19:27:41 +00:00
|
|
|
static int viewzoom_exec(bContext *C, wmOperator *op)
|
2008-12-19 17:14:02 +00:00
|
|
|
{
|
2011-01-03 01:26:54 +00:00
|
|
|
View3D *v3d;
|
|
|
|
|
RegionView3D *rv3d;
|
|
|
|
|
ScrArea *sa;
|
|
|
|
|
ARegion *ar;
|
2011-05-19 17:19:05 +00:00
|
|
|
short use_cam_zoom;
|
2011-01-03 01:26:54 +00:00
|
|
|
|
2008-12-19 19:27:41 +00:00
|
|
|
int delta= RNA_int_get(op->ptr, "delta");
|
2011-01-03 01:26:54 +00:00
|
|
|
int mx, my;
|
|
|
|
|
|
|
|
|
|
if(op->customdata) {
|
|
|
|
|
ViewOpsData *vod= op->customdata;
|
|
|
|
|
|
|
|
|
|
sa= vod->sa;
|
|
|
|
|
ar= vod->ar;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
sa= CTX_wm_area(C);
|
|
|
|
|
ar= CTX_wm_region(C);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v3d= sa->spacedata.first;
|
|
|
|
|
rv3d= ar->regiondata;
|
|
|
|
|
|
2012-01-11 16:32:12 +00:00
|
|
|
mx= RNA_struct_property_is_set(op->ptr, "mx") ? RNA_int_get(op->ptr, "mx") : ar->winx / 2;
|
|
|
|
|
my= RNA_struct_property_is_set(op->ptr, "my") ? RNA_int_get(op->ptr, "my") : ar->winy / 2;
|
2008-12-19 19:27:41 +00:00
|
|
|
|
2011-05-23 15:46:09 +00:00
|
|
|
use_cam_zoom= (rv3d->persp==RV3D_CAMOB) && !(rv3d->is_persp && ED_view3d_camera_lock_check(v3d, rv3d));
|
2011-05-19 17:19:05 +00:00
|
|
|
|
2008-12-19 19:27:41 +00:00
|
|
|
if(delta < 0) {
|
|
|
|
|
/* this min and max is also in viewmove() */
|
2011-05-19 17:19:05 +00:00
|
|
|
if(use_cam_zoom) {
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
rv3d->camzoom-= 10;
|
2010-09-11 04:39:00 +00:00
|
|
|
if(rv3d->camzoom < RV3D_CAMZOOM_MIN) rv3d->camzoom= RV3D_CAMZOOM_MIN;
|
2008-12-19 19:27:41 +00:00
|
|
|
}
|
2011-03-27 15:57:27 +00:00
|
|
|
else if(rv3d->dist < 10.0f * v3d->far) {
|
2011-01-03 01:26:54 +00:00
|
|
|
view_zoom_mouseloc(ar, 1.2f, mx, my);
|
2009-10-16 00:23:40 +00:00
|
|
|
}
|
2008-12-19 19:27:41 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2011-05-19 17:19:05 +00:00
|
|
|
if(use_cam_zoom) {
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
rv3d->camzoom+= 10;
|
2010-09-11 04:39:00 +00:00
|
|
|
if(rv3d->camzoom > RV3D_CAMZOOM_MAX) rv3d->camzoom= RV3D_CAMZOOM_MAX;
|
2008-12-19 19:27:41 +00:00
|
|
|
}
|
2011-03-27 15:57:27 +00:00
|
|
|
else if(rv3d->dist> 0.001f * v3d->grid) {
|
2011-01-03 01:26:54 +00:00
|
|
|
view_zoom_mouseloc(ar, .83333f, mx, my);
|
2009-10-16 00:23:40 +00:00
|
|
|
}
|
2008-12-19 19:27:41 +00:00
|
|
|
}
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2.5
Smaller jobs, all in one commit!
- Moved object_do_update out of view3d drawing, into
the event system (currently after notifiers).
Depsgraph calls for setting update flags will have to
keep track of each Screen's needs, so a UI showing only
a Sequencer doesn't do objects.
- Added button in "Properties region" in 3D window to set
or disable 4-split, including the 3 options it has.
(lock, box, clip)
- Restored legacy code for UI, to make things work like
bone rename, autocomplete.
- Node editor now shows Curves widgets again
- Bugfix: composite job increased Viewer user id count
- Bugfix: Node editor, not "Enable nodes" still called
a Job, which didn't do anything
- Various code cleaning, unused vars and prototypes.
2009-02-11 16:54:55 +00:00
|
|
|
if(rv3d->viewlock & RV3D_BOXVIEW)
|
2011-01-03 01:26:54 +00:00
|
|
|
view3d_boxview_sync(sa, ar);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2011-05-21 08:56:37 +00:00
|
|
|
ED_view3d_depth_tag_update(rv3d);
|
2011-05-14 17:50:33 +00:00
|
|
|
|
|
|
|
|
ED_view3d_camera_lock_sync(v3d, rv3d);
|
|
|
|
|
|
2011-01-03 01:26:54 +00:00
|
|
|
ED_region_tag_redraw(ar);
|
|
|
|
|
|
2010-01-19 04:14:57 +00:00
|
|
|
viewops_data_free(C, op);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 19:27:41 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-22 11:36:56 +00:00
|
|
|
/* this is an exact copy of viewzoom_modal_keymap */
|
|
|
|
|
/* called in transform_ops.c, on each regeneration of keymaps */
|
|
|
|
|
void viewdolly_modal_keymap(wmKeyConfig *keyconf)
|
|
|
|
|
{
|
|
|
|
|
static EnumPropertyItem modal_items[] = {
|
|
|
|
|
{VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
|
|
|
|
|
|
|
|
|
|
{VIEWROT_MODAL_SWITCH_ROTATE, "SWITCH_TO_ROTATE", 0, "Switch to Rotate"},
|
|
|
|
|
{VIEWROT_MODAL_SWITCH_MOVE, "SWITCH_TO_MOVE", 0, "Switch to Move"},
|
|
|
|
|
|
|
|
|
|
{0, NULL, 0, NULL, NULL}};
|
|
|
|
|
|
|
|
|
|
wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "View3D Dolly Modal");
|
|
|
|
|
|
|
|
|
|
/* this function is called for each spacetype, only needs to add map once */
|
|
|
|
|
if(keymap) return;
|
|
|
|
|
|
|
|
|
|
keymap= WM_modalkeymap_add(keyconf, "View3D Dolly Modal", modal_items);
|
|
|
|
|
|
|
|
|
|
/* items for modal map */
|
|
|
|
|
WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, VIEW_MODAL_CONFIRM);
|
|
|
|
|
WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, VIEW_MODAL_CONFIRM);
|
|
|
|
|
|
|
|
|
|
/* disabled mode switching for now, can re-implement better, later on
|
|
|
|
|
WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE);
|
|
|
|
|
WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE);
|
|
|
|
|
WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_MOVE);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* assign map to operators */
|
|
|
|
|
WM_modalkeymap_assign(keymap, "VIEW3D_OT_dolly");
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-22 15:34:07 +00:00
|
|
|
/* viewdolly_invoke() copied this function, changes here may apply there */
|
2008-12-19 19:27:41 +00:00
|
|
|
static int viewzoom_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
|
{
|
2011-05-14 05:42:58 +00:00
|
|
|
ViewOpsData *vod;
|
|
|
|
|
|
|
|
|
|
/* makes op->customdata */
|
|
|
|
|
viewops_data_create(C, op, event);
|
|
|
|
|
vod= op->customdata;
|
|
|
|
|
|
2009-10-16 00:23:40 +00:00
|
|
|
/* if one or the other zoom position aren't set, set from event */
|
2012-01-11 16:32:12 +00:00
|
|
|
if (!RNA_struct_property_is_set(op->ptr, "mx") || !RNA_struct_property_is_set(op->ptr, "my")) {
|
2009-10-16 00:23:40 +00:00
|
|
|
RNA_int_set(op->ptr, "mx", event->x);
|
|
|
|
|
RNA_int_set(op->ptr, "my", event->y);
|
|
|
|
|
}
|
2008-12-19 19:27:41 +00:00
|
|
|
|
2012-01-11 16:32:12 +00:00
|
|
|
if(RNA_struct_property_is_set(op->ptr, "delta")) {
|
2008-12-19 19:27:41 +00:00
|
|
|
viewzoom_exec(C, op);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2010-01-11 11:14:36 +00:00
|
|
|
if (event->type == MOUSEZOOM) {
|
2011-04-22 14:47:35 +00:00
|
|
|
/* Bypass Zoom invert flag for track pads (pass FALSE always) */
|
2009-12-16 23:05:59 +00:00
|
|
|
|
2011-04-22 14:47:35 +00:00
|
|
|
if (U.uiflag & USER_ZOOM_HORIZ) {
|
2010-01-11 11:14:36 +00:00
|
|
|
vod->origx = vod->oldx = event->x;
|
2011-04-22 14:47:35 +00:00
|
|
|
viewzoom_apply(vod, event->prevx, event->prevy, USER_ZOOM_DOLLY, FALSE);
|
2010-01-11 11:14:36 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Set y move = x move as MOUSEZOOM uses only x axis to pass magnification value */
|
2010-05-29 21:31:57 +00:00
|
|
|
vod->origy = vod->oldy = vod->origy + event->x - event->prevx;
|
2011-04-22 14:47:35 +00:00
|
|
|
viewzoom_apply(vod, event->prevx, event->prevy, USER_ZOOM_DOLLY, FALSE);
|
2010-01-11 11:14:36 +00:00
|
|
|
}
|
2011-05-21 08:56:37 +00:00
|
|
|
ED_view3d_depth_tag_update(vod->rv3d);
|
2010-01-11 11:14:36 +00:00
|
|
|
|
|
|
|
|
viewops_data_free(C, op);
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2010-02-06 12:44:37 +00:00
|
|
|
if(U.viewzoom == USER_ZOOM_CONT) {
|
|
|
|
|
/* needs a timer to continue redrawing */
|
|
|
|
|
vod->timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f);
|
|
|
|
|
vod->timer_lastdraw= PIL_check_seconds_timer();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-11 11:14:36 +00:00
|
|
|
/* add temp handler */
|
|
|
|
|
WM_event_add_modal_handler(C, op);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
2008-12-19 19:27:41 +00:00
|
|
|
}
|
|
|
|
|
return OPERATOR_FINISHED;
|
2008-12-19 17:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
2011-06-06 11:04:54 +00:00
|
|
|
static int viewzoom_cancel(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
viewops_data_free(C, op);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
2008-12-19 17:14:02 +00:00
|
|
|
|
2009-03-29 02:15:13 +00:00
|
|
|
void VIEW3D_OT_zoom(wmOperatorType *ot)
|
2008-12-19 17:14:02 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2011-04-19 11:17:29 +00:00
|
|
|
ot->name= "Zoom View";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Zoom in/out in the view";
|
2009-03-29 02:15:13 +00:00
|
|
|
ot->idname= "VIEW3D_OT_zoom";
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->invoke= viewzoom_invoke;
|
2008-12-19 19:27:41 +00:00
|
|
|
ot->exec= viewzoom_exec;
|
2008-12-19 17:14:02 +00:00
|
|
|
ot->modal= viewzoom_modal;
|
2010-09-27 10:44:46 +00:00
|
|
|
ot->poll= ED_operator_region_view3d_active;
|
2011-06-06 11:04:54 +00:00
|
|
|
ot->cancel= viewzoom_cancel;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-31 19:40:40 +00:00
|
|
|
/* flags */
|
2009-10-10 17:19:49 +00:00
|
|
|
ot->flag= OPTYPE_BLOCKING|OPTYPE_GRAB_POINTER;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-11-23 17:07:30 +00:00
|
|
|
RNA_def_int(ot->srna, "delta", 0, INT_MIN, INT_MAX, "Delta", "", INT_MIN, INT_MAX);
|
2009-10-16 00:23:40 +00:00
|
|
|
RNA_def_int(ot->srna, "mx", 0, 0, INT_MAX, "Zoom Position X", "", 0, INT_MAX);
|
|
|
|
|
RNA_def_int(ot->srna, "my", 0, 0, INT_MAX, "Zoom Position Y", "", 0, INT_MAX);
|
2008-12-19 17:14:02 +00:00
|
|
|
}
|
|
|
|
|
|
2011-04-22 15:34:07 +00:00
|
|
|
|
|
|
|
|
/* ************************ viewdolly ******************************** */
|
|
|
|
|
static void view_dolly_mouseloc(ARegion *ar, float orig_ofs[3], float dvec[3], float dfac)
|
|
|
|
|
{
|
|
|
|
|
RegionView3D *rv3d= ar->regiondata;
|
2011-08-19 16:21:29 +00:00
|
|
|
madd_v3_v3v3fl(rv3d->ofs, orig_ofs, dvec, -(1.0f - dfac));
|
2011-04-22 15:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void viewdolly_apply(ViewOpsData *vod, int x, int y, const short zoom_invert)
|
|
|
|
|
{
|
|
|
|
|
float zfac=1.0;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
float len1, len2;
|
|
|
|
|
|
|
|
|
|
if (U.uiflag & USER_ZOOM_HORIZ) {
|
|
|
|
|
len1 = (vod->ar->winrct.xmax - x) + 5;
|
|
|
|
|
len2 = (vod->ar->winrct.xmax - vod->origx) + 5;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
len1 = (vod->ar->winrct.ymax - y) + 5;
|
|
|
|
|
len2 = (vod->ar->winrct.ymax - vod->origy) + 5;
|
|
|
|
|
}
|
|
|
|
|
if (zoom_invert)
|
|
|
|
|
SWAP(float, len1, len2);
|
|
|
|
|
|
2011-08-19 16:21:29 +00:00
|
|
|
zfac = 1.0f + ((len2 - len1) * 0.01f * vod->rv3d->dist);
|
2011-04-22 15:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(zfac != 1.0f)
|
|
|
|
|
view_dolly_mouseloc(vod->ar, vod->ofs, vod->mousevec, zfac);
|
|
|
|
|
|
|
|
|
|
if(vod->rv3d->viewlock & RV3D_BOXVIEW)
|
|
|
|
|
view3d_boxview_sync(vod->sa, vod->ar);
|
|
|
|
|
|
2011-05-14 17:50:33 +00:00
|
|
|
ED_view3d_camera_lock_sync(vod->v3d, vod->rv3d);
|
|
|
|
|
|
2011-04-22 15:34:07 +00:00
|
|
|
ED_region_tag_redraw(vod->ar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int viewdolly_modal(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
|
{
|
|
|
|
|
ViewOpsData *vod= op->customdata;
|
|
|
|
|
short event_code= VIEW_PASS;
|
|
|
|
|
|
|
|
|
|
/* execute the events */
|
|
|
|
|
if(event->type==MOUSEMOVE) {
|
|
|
|
|
event_code= VIEW_APPLY;
|
|
|
|
|
}
|
|
|
|
|
else if(event->type==EVT_MODAL_MAP) {
|
|
|
|
|
switch (event->val) {
|
|
|
|
|
case VIEW_MODAL_CONFIRM:
|
|
|
|
|
event_code= VIEW_CONFIRM;
|
|
|
|
|
break;
|
|
|
|
|
case VIEWROT_MODAL_SWITCH_MOVE:
|
|
|
|
|
WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, NULL);
|
|
|
|
|
event_code= VIEW_CONFIRM;
|
|
|
|
|
break;
|
|
|
|
|
case VIEWROT_MODAL_SWITCH_ROTATE:
|
|
|
|
|
WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL);
|
|
|
|
|
event_code= VIEW_CONFIRM;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if(event->type==vod->origkey && event->val==KM_RELEASE) {
|
|
|
|
|
event_code= VIEW_CONFIRM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(event_code==VIEW_APPLY) {
|
|
|
|
|
viewdolly_apply(vod, event->x, event->y, (U.uiflag & USER_ZOOM_INVERT) != 0);
|
|
|
|
|
}
|
|
|
|
|
else if (event_code==VIEW_CONFIRM) {
|
2011-05-21 08:56:37 +00:00
|
|
|
ED_view3d_depth_tag_update(vod->rv3d);
|
2011-04-22 15:34:07 +00:00
|
|
|
viewops_data_free(C, op);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int viewdolly_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2011-05-08 10:29:40 +00:00
|
|
|
/* View3D *v3d; */
|
2011-04-22 15:34:07 +00:00
|
|
|
RegionView3D *rv3d;
|
|
|
|
|
ScrArea *sa;
|
|
|
|
|
ARegion *ar;
|
|
|
|
|
float mousevec[3];
|
|
|
|
|
|
|
|
|
|
int delta= RNA_int_get(op->ptr, "delta");
|
|
|
|
|
|
|
|
|
|
if(op->customdata) {
|
|
|
|
|
ViewOpsData *vod= op->customdata;
|
|
|
|
|
|
|
|
|
|
sa= vod->sa;
|
|
|
|
|
ar= vod->ar;
|
|
|
|
|
copy_v3_v3(mousevec, vod->mousevec);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
sa= CTX_wm_area(C);
|
|
|
|
|
ar= CTX_wm_region(C);
|
2011-05-12 06:52:24 +00:00
|
|
|
negate_v3_v3(mousevec, ((RegionView3D *)ar->regiondata)->viewinv[2]);
|
|
|
|
|
normalize_v3(mousevec);
|
2011-04-22 15:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-08 10:29:40 +00:00
|
|
|
/* v3d= sa->spacedata.first; */ /* UNUSED */
|
2011-04-22 15:34:07 +00:00
|
|
|
rv3d= ar->regiondata;
|
|
|
|
|
|
|
|
|
|
/* overwrite the mouse vector with the view direction (zoom into the center) */
|
|
|
|
|
if((U.uiflag & USER_ZOOM_TO_MOUSEPOS) == 0) {
|
|
|
|
|
normalize_v3_v3(mousevec, rv3d->viewinv[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(delta < 0) {
|
|
|
|
|
view_dolly_mouseloc(ar, rv3d->ofs, mousevec, 1.2f);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
view_dolly_mouseloc(ar, rv3d->ofs, mousevec, .83333f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(rv3d->viewlock & RV3D_BOXVIEW)
|
|
|
|
|
view3d_boxview_sync(sa, ar);
|
|
|
|
|
|
2011-05-21 08:56:37 +00:00
|
|
|
ED_view3d_depth_tag_update(rv3d);
|
2011-04-22 15:34:07 +00:00
|
|
|
ED_region_tag_redraw(ar);
|
|
|
|
|
|
|
|
|
|
viewops_data_free(C, op);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* copied from viewzoom_invoke(), changes here may apply there */
|
|
|
|
|
static int viewdolly_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
2011-05-14 05:42:58 +00:00
|
|
|
{
|
|
|
|
|
ViewOpsData *vod;
|
|
|
|
|
|
|
|
|
|
/* makes op->customdata */
|
|
|
|
|
viewops_data_create(C, op, event);
|
|
|
|
|
vod= op->customdata;
|
|
|
|
|
|
2011-04-22 15:34:07 +00:00
|
|
|
/* if one or the other zoom position aren't set, set from event */
|
2012-01-11 16:32:12 +00:00
|
|
|
if (!RNA_struct_property_is_set(op->ptr, "mx") || !RNA_struct_property_is_set(op->ptr, "my")) {
|
2011-04-22 15:34:07 +00:00
|
|
|
RNA_int_set(op->ptr, "mx", event->x);
|
|
|
|
|
RNA_int_set(op->ptr, "my", event->y);
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-11 16:32:12 +00:00
|
|
|
if(RNA_struct_property_is_set(op->ptr, "delta")) {
|
2011-04-22 15:34:07 +00:00
|
|
|
viewdolly_exec(C, op);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* overwrite the mouse vector with the view direction (zoom into the center) */
|
|
|
|
|
if((U.uiflag & USER_ZOOM_TO_MOUSEPOS) == 0) {
|
2011-05-12 06:52:24 +00:00
|
|
|
negate_v3_v3(vod->mousevec, vod->rv3d->viewinv[2]);
|
|
|
|
|
normalize_v3(vod->mousevec);
|
2011-04-22 15:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event->type == MOUSEZOOM) {
|
|
|
|
|
/* Bypass Zoom invert flag for track pads (pass FALSE always) */
|
|
|
|
|
|
|
|
|
|
if (U.uiflag & USER_ZOOM_HORIZ) {
|
|
|
|
|
vod->origx = vod->oldx = event->x;
|
|
|
|
|
viewdolly_apply(vod, event->prevx, event->prevy, FALSE);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
/* Set y move = x move as MOUSEZOOM uses only x axis to pass magnification value */
|
|
|
|
|
vod->origy = vod->oldy = vod->origy + event->x - event->prevx;
|
|
|
|
|
viewdolly_apply(vod, event->prevx, event->prevy, FALSE);
|
|
|
|
|
}
|
2011-05-21 08:56:37 +00:00
|
|
|
ED_view3d_depth_tag_update(vod->rv3d);
|
2011-04-22 15:34:07 +00:00
|
|
|
|
|
|
|
|
viewops_data_free(C, op);
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* add temp handler */
|
|
|
|
|
WM_event_add_modal_handler(C, op);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* like ED_operator_region_view3d_active but check its not in ortho view */
|
|
|
|
|
static int viewdolly_poll(bContext *C)
|
|
|
|
|
{
|
|
|
|
|
RegionView3D *rv3d= CTX_wm_region_view3d(C);
|
|
|
|
|
|
2011-05-14 17:50:33 +00:00
|
|
|
if(rv3d) {
|
|
|
|
|
if (rv3d->persp == RV3D_PERSP) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
View3D *v3d= CTX_wm_view3d(C);
|
2011-05-23 15:46:09 +00:00
|
|
|
if (ED_view3d_camera_lock_check(v3d, rv3d)) {
|
2011-05-14 17:50:33 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-22 15:34:07 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-06 11:04:54 +00:00
|
|
|
static int viewdolly_cancel(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
viewops_data_free(C, op);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-22 15:34:07 +00:00
|
|
|
void VIEW3D_OT_dolly(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name= "Dolly view";
|
|
|
|
|
ot->description = "Dolly in/out in the view";
|
|
|
|
|
ot->idname= "VIEW3D_OT_dolly";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->invoke= viewdolly_invoke;
|
|
|
|
|
ot->exec= viewdolly_exec;
|
|
|
|
|
ot->modal= viewdolly_modal;
|
|
|
|
|
ot->poll= viewdolly_poll;
|
2011-06-06 11:04:54 +00:00
|
|
|
ot->cancel= viewdolly_cancel;
|
2011-04-22 15:34:07 +00:00
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag= OPTYPE_BLOCKING|OPTYPE_GRAB_POINTER;
|
|
|
|
|
|
|
|
|
|
RNA_def_int(ot->srna, "delta", 0, INT_MIN, INT_MAX, "Delta", "", INT_MIN, INT_MAX);
|
|
|
|
|
RNA_def_int(ot->srna, "mx", 0, 0, INT_MAX, "Zoom Position X", "", 0, INT_MAX);
|
|
|
|
|
RNA_def_int(ot->srna, "my", 0, 0, INT_MAX, "Zoom Position Y", "", 0, INT_MAX);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-10-05 13:15:58 +00:00
|
|
|
static int view3d_all_exec(bContext *C, wmOperator *op) /* was view3d_home() in 2.4x */
|
2008-12-20 11:33:16 +00:00
|
|
|
{
|
|
|
|
|
ARegion *ar= CTX_wm_region(C);
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
|
|
|
|
RegionView3D *rv3d= CTX_wm_region_view3d(C);
|
2008-12-20 11:33:16 +00:00
|
|
|
Scene *scene= CTX_data_scene(C);
|
|
|
|
|
Base *base;
|
2009-08-20 21:09:48 +00:00
|
|
|
float *curs;
|
2011-05-23 15:46:09 +00:00
|
|
|
const short skip_camera= ED_view3d_camera_lock_check(v3d, rv3d);
|
2008-12-20 11:33:16 +00:00
|
|
|
|
|
|
|
|
int center= RNA_boolean_get(op->ptr, "center");
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-20 11:33:16 +00:00
|
|
|
float size, min[3], max[3], afm[3];
|
|
|
|
|
int ok= 1, onedone=0;
|
|
|
|
|
|
|
|
|
|
if(center) {
|
2009-08-20 21:09:48 +00:00
|
|
|
/* in 2.4x this also move the cursor to (0, 0, 0) (with shift+c). */
|
|
|
|
|
curs= give_cursor(scene, v3d);
|
2010-10-05 13:15:58 +00:00
|
|
|
zero_v3(min);
|
|
|
|
|
zero_v3(max);
|
|
|
|
|
zero_v3(curs);
|
2008-12-20 11:33:16 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
|
}
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-20 11:33:16 +00:00
|
|
|
for(base= scene->base.first; base; base= base->next) {
|
2011-01-17 23:47:11 +00:00
|
|
|
if(BASE_VISIBLE(v3d, base)) {
|
2008-12-20 11:33:16 +00:00
|
|
|
onedone= 1;
|
2011-05-14 17:50:33 +00:00
|
|
|
|
|
|
|
|
if(skip_camera && base->object == v3d->camera) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-20 11:33:16 +00:00
|
|
|
minmax_object(base->object, min, max);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-06-22 15:46:15 +00:00
|
|
|
if(!onedone) {
|
|
|
|
|
ED_region_tag_redraw(ar);
|
|
|
|
|
/* TODO - should this be cancel?
|
|
|
|
|
* I think no, because we always move the cursor, with or without
|
|
|
|
|
* object, but in this case there is no change in the scene,
|
|
|
|
|
* only the cursor so I choice a ED_region_tag like
|
|
|
|
|
* smooth_view do for the center_cursor.
|
|
|
|
|
* See bug #22640
|
|
|
|
|
*/
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2010-10-05 13:15:58 +00:00
|
|
|
sub_v3_v3v3(afm, max, min);
|
2008-12-20 11:33:16 +00:00
|
|
|
size= 0.7f*MAX3(afm[0], afm[1], afm[2]);
|
2011-03-27 15:57:27 +00:00
|
|
|
if(size == 0.0f) ok= 0;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-20 11:33:16 +00:00
|
|
|
if(ok) {
|
|
|
|
|
float new_dist;
|
|
|
|
|
float new_ofs[3];
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-20 11:33:16 +00:00
|
|
|
new_dist = size;
|
|
|
|
|
new_ofs[0]= -(min[0]+max[0])/2.0f;
|
|
|
|
|
new_ofs[1]= -(min[1]+max[1])/2.0f;
|
|
|
|
|
new_ofs[2]= -(min[2]+max[2])/2.0f;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-20 11:33:16 +00:00
|
|
|
// correction for window aspect ratio
|
|
|
|
|
if(ar->winy>2 && ar->winx>2) {
|
|
|
|
|
size= (float)ar->winx/(float)ar->winy;
|
2011-03-27 15:57:27 +00:00
|
|
|
if(size < 1.0f) size= 1.0f/size;
|
2008-12-20 11:33:16 +00:00
|
|
|
new_dist*= size;
|
|
|
|
|
}
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2011-05-23 15:46:09 +00:00
|
|
|
if ((rv3d->persp==RV3D_CAMOB) && !ED_view3d_camera_lock_check(v3d, rv3d)) {
|
2009-10-27 02:54:25 +00:00
|
|
|
rv3d->persp= RV3D_PERSP;
|
2011-04-28 07:55:29 +00:00
|
|
|
smooth_view(C, v3d, ar, v3d->camera, NULL, new_ofs, NULL, &new_dist, NULL);
|
2008-12-20 11:33:16 +00:00
|
|
|
}
|
2010-03-22 09:30:00 +00:00
|
|
|
else {
|
2011-04-28 07:55:29 +00:00
|
|
|
smooth_view(C, v3d, ar, NULL, NULL, new_ofs, NULL, &new_dist, NULL);
|
2010-03-22 09:30:00 +00:00
|
|
|
}
|
2008-12-20 11:33:16 +00:00
|
|
|
}
|
|
|
|
|
// XXX BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2010-02-10 17:38:58 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, v3d);
|
2008-12-20 11:33:16 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-03 20:47:03 +00:00
|
|
|
|
2009-07-09 08:39:58 +00:00
|
|
|
void VIEW3D_OT_view_all(wmOperatorType *ot)
|
2008-12-20 11:33:16 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2009-09-26 16:43:20 +00:00
|
|
|
ot->name= "View All";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "View all objects in scene";
|
2009-07-09 08:39:58 +00:00
|
|
|
ot->idname= "VIEW3D_OT_view_all";
|
2008-12-20 11:33:16 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2010-10-05 13:15:58 +00:00
|
|
|
ot->exec= view3d_all_exec;
|
2010-11-04 15:59:09 +00:00
|
|
|
ot->poll= ED_operator_region_view3d_active;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-31 19:40:40 +00:00
|
|
|
/* flags */
|
2.5
Operator goodies!
--- Macro operators
Operators now can consist of multiple operators. Such a macro operator
is identical and behaves identical to other opererators. Macros can
also be constructed of macros even! Currently only hardcoded macros are
implemented, this to solve combined operators such as 'add duplicate' or
'extrude' (both want a transform appended).
Usage is simple:
- WM_operatortype_append_macro() : add new operatortype, name, flags
- WM_operatortype_macro_define() : add existing operator to macro
(Note: macro_define will also allow properties to be set, doesnt work
right now)
On converting the macro wmOperatorType to a real operator, it makes a
list of all operators, and the standard macro callbacks (exec, invoke,
modal, poll) just will use all.
Important note; switching to a modal operator only works as last in the
chain now!
Macros implemented for duplicate, extrude and rip. Tool menu works fine
for it, also the redo hotkey F4 works properly.
--- Operator redo fix
The operators use the undo system to switch back, but this could give
errors if other actions added undo pushes (buttons, outliner). Now the
redo for operator searches back for the correct undo level.
This fixes issues with many redos.
Note for brecht: removed the ED_undo_push for buttons... it was called
on *every* button now, which is probably too much? For example, using
the 'toolbar' redo also caused this...
2009-07-29 17:56:38 +00:00
|
|
|
ot->flag= 0;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-16 23:53:11 +00:00
|
|
|
RNA_def_boolean(ot->srna, "center", 0, "Center", "");
|
2008-12-20 11:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-19 16:04:44 +00:00
|
|
|
/* like a localview without local!, was centerview() in 2.4x */
|
|
|
|
|
static int viewselected_exec(bContext *C, wmOperator *UNUSED(op))
|
2008-12-26 10:31:44 +00:00
|
|
|
{
|
2008-12-20 11:33:16 +00:00
|
|
|
ARegion *ar= CTX_wm_region(C);
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
|
|
|
|
RegionView3D *rv3d= CTX_wm_region_view3d(C);
|
2008-12-20 11:33:16 +00:00
|
|
|
Scene *scene= CTX_data_scene(C);
|
|
|
|
|
Object *ob= OBACT;
|
2009-01-02 19:10:35 +00:00
|
|
|
Object *obedit= CTX_data_edit_object(C);
|
2008-12-20 11:33:16 +00:00
|
|
|
float size, min[3], max[3], afm[3];
|
2010-02-05 15:55:45 +00:00
|
|
|
int ok=0, ok_dist=1;
|
2011-05-23 15:46:09 +00:00
|
|
|
const short skip_camera= ED_view3d_camera_lock_check(v3d, rv3d);
|
2008-12-20 11:33:16 +00:00
|
|
|
|
|
|
|
|
/* SMOOTHVIEW */
|
|
|
|
|
float new_ofs[3];
|
|
|
|
|
float new_dist;
|
|
|
|
|
|
|
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
|
|
2009-08-15 21:46:25 +00:00
|
|
|
if (ob && ob->mode & OB_MODE_WEIGHT_PAINT) {
|
2008-12-20 11:33:16 +00:00
|
|
|
/* hardcoded exception, we look for the one selected armature */
|
|
|
|
|
/* this is weak code this way, we should make a generic active/selection callback interface once... */
|
|
|
|
|
Base *base;
|
|
|
|
|
for(base=scene->base.first; base; base= base->next) {
|
|
|
|
|
if(TESTBASELIB(v3d, base)) {
|
|
|
|
|
if(base->object->type==OB_ARMATURE)
|
2009-08-16 03:24:23 +00:00
|
|
|
if(base->object->mode & OB_MODE_POSE)
|
2008-12-20 11:33:16 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(base)
|
|
|
|
|
ob= base->object;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-01-02 19:10:35 +00:00
|
|
|
if(obedit) {
|
2009-02-14 13:07:09 +00:00
|
|
|
ok = minmax_verts(obedit, min, max); /* only selected */
|
2008-12-20 11:33:16 +00:00
|
|
|
}
|
2009-08-16 03:24:23 +00:00
|
|
|
else if(ob && (ob->mode & OB_MODE_POSE)) {
|
2008-12-20 11:33:16 +00:00
|
|
|
if(ob->pose) {
|
|
|
|
|
bArmature *arm= ob->data;
|
|
|
|
|
bPoseChannel *pchan;
|
|
|
|
|
float vec[3];
|
|
|
|
|
|
|
|
|
|
for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
|
|
|
|
|
if(pchan->bone->flag & BONE_SELECTED) {
|
|
|
|
|
if(pchan->bone->layer & arm->layer) {
|
merge own commits into render branch into trunk since 27560
27562, 27570, 27571, 27574, 27576, 27577, 27579, 27590, 27591, 27594, 27595, 27596, 27599, 27605, 27611, 27612, 27613, 27614, 27623
2010-03-20 16:41:01 +00:00
|
|
|
bPoseChannel *pchan_tx= pchan->custom_tx ? pchan->custom_tx : pchan;
|
2008-12-20 11:33:16 +00:00
|
|
|
ok= 1;
|
2010-07-26 06:34:56 +00:00
|
|
|
mul_v3_m4v3(vec, ob->obmat, pchan_tx->pose_head);
|
2008-12-20 11:33:16 +00:00
|
|
|
DO_MINMAX(vec, min, max);
|
2010-07-26 06:34:56 +00:00
|
|
|
mul_v3_m4v3(vec, ob->obmat, pchan_tx->pose_tail);
|
2008-12-20 11:33:16 +00:00
|
|
|
DO_MINMAX(vec, min, max);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-15 19:48:50 +00:00
|
|
|
else if (paint_facesel_test(ob)) {
|
2010-11-03 01:56:02 +00:00
|
|
|
ok= paintface_minmax(ob, min, max);
|
2008-12-20 11:33:16 +00:00
|
|
|
}
|
2009-08-16 02:35:44 +00:00
|
|
|
else if (ob && (ob->mode & OB_MODE_PARTICLE_EDIT)) {
|
2009-01-24 13:45:24 +00:00
|
|
|
ok= PE_minmax(scene, min, max);
|
2008-12-20 11:33:16 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2011-05-14 17:50:33 +00:00
|
|
|
Base *base;
|
|
|
|
|
for(base= FIRSTBASE; base; base = base->next) {
|
2008-12-20 18:43:21 +00:00
|
|
|
if(TESTBASE(v3d, base)) {
|
2010-02-24 20:11:35 +00:00
|
|
|
|
2011-05-14 17:50:33 +00:00
|
|
|
if(skip_camera && base->object == v3d->camera) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-20 11:33:16 +00:00
|
|
|
/* account for duplis */
|
2010-02-24 20:11:35 +00:00
|
|
|
if (minmax_object_duplis(scene, base->object, min, max)==0)
|
|
|
|
|
minmax_object(base->object, min, max); /* use if duplis not found */
|
2008-12-20 11:33:16 +00:00
|
|
|
|
|
|
|
|
ok= 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(ok==0) return OPERATOR_FINISHED;
|
|
|
|
|
|
2010-02-25 20:26:38 +00:00
|
|
|
sub_v3_v3v3(afm, max, min);
|
2009-02-14 10:03:24 +00:00
|
|
|
size= MAX3(afm[0], afm[1], afm[2]);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2011-05-20 11:15:44 +00:00
|
|
|
if(!rv3d->is_persp) {
|
2010-02-05 15:55:45 +00:00
|
|
|
if(size < 0.0001f) { /* if its a sinble point. dont even re-scale */
|
|
|
|
|
ok_dist= 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* perspective should be a bit farther away to look nice */
|
|
|
|
|
size*= 0.7f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if(size <= v3d->near*1.5f) {
|
|
|
|
|
size= v3d->near*1.5f;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-20 11:33:16 +00:00
|
|
|
|
2010-02-25 21:10:43 +00:00
|
|
|
add_v3_v3v3(new_ofs, min, max);
|
|
|
|
|
mul_v3_fl(new_ofs, -0.5f);
|
|
|
|
|
|
2008-12-20 11:33:16 +00:00
|
|
|
new_dist = size;
|
|
|
|
|
|
|
|
|
|
/* correction for window aspect ratio */
|
|
|
|
|
if(ar->winy>2 && ar->winx>2) {
|
|
|
|
|
size= (float)ar->winx/(float)ar->winy;
|
|
|
|
|
if(size<1.0f) size= 1.0f/size;
|
|
|
|
|
new_dist*= size;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-23 15:46:09 +00:00
|
|
|
if (rv3d->persp==RV3D_CAMOB && !ED_view3d_camera_lock_check(v3d, rv3d)) {
|
2009-10-27 02:54:25 +00:00
|
|
|
rv3d->persp= RV3D_PERSP;
|
2011-04-28 07:55:29 +00:00
|
|
|
smooth_view(C, v3d, ar, v3d->camera, NULL, new_ofs, NULL, &new_dist, NULL);
|
2009-07-09 02:45:48 +00:00
|
|
|
}
|
2008-12-26 18:15:46 +00:00
|
|
|
else {
|
2011-04-28 07:55:29 +00:00
|
|
|
smooth_view(C, v3d, ar, NULL, NULL, new_ofs, NULL, ok_dist ? &new_dist : NULL, NULL);
|
2008-12-20 11:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
2010-11-07 14:57:24 +00:00
|
|
|
/* smooth view does viewlock RV3D_BOXVIEW copy */
|
|
|
|
|
|
2008-12-20 11:33:16 +00:00
|
|
|
// XXX BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
2009-02-14 13:07:09 +00:00
|
|
|
|
2010-01-13 22:17:56 +00:00
|
|
|
void VIEW3D_OT_view_selected(wmOperatorType *ot)
|
2008-12-20 11:33:16 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/* identifiers */
|
2009-09-26 16:43:20 +00:00
|
|
|
ot->name= "View Selected";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Move the view to the selection center";
|
2010-01-13 22:17:56 +00:00
|
|
|
ot->idname= "VIEW3D_OT_view_selected";
|
2008-12-20 11:33:16 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2010-01-13 22:17:56 +00:00
|
|
|
ot->exec= viewselected_exec;
|
2010-09-27 10:44:46 +00:00
|
|
|
ot->poll= ED_operator_region_view3d_active;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-31 19:40:40 +00:00
|
|
|
/* flags */
|
2.5
Operator goodies!
--- Macro operators
Operators now can consist of multiple operators. Such a macro operator
is identical and behaves identical to other opererators. Macros can
also be constructed of macros even! Currently only hardcoded macros are
implemented, this to solve combined operators such as 'add duplicate' or
'extrude' (both want a transform appended).
Usage is simple:
- WM_operatortype_append_macro() : add new operatortype, name, flags
- WM_operatortype_macro_define() : add existing operator to macro
(Note: macro_define will also allow properties to be set, doesnt work
right now)
On converting the macro wmOperatorType to a real operator, it makes a
list of all operators, and the standard macro callbacks (exec, invoke,
modal, poll) just will use all.
Important note; switching to a modal operator only works as last in the
chain now!
Macros implemented for duplicate, extrude and rip. Tool menu works fine
for it, also the redo hotkey F4 works properly.
--- Operator redo fix
The operators use the undo system to switch back, but this could give
errors if other actions added undo pushes (buttons, outliner). Now the
redo for operator searches back for the correct undo level.
This fixes issues with many redos.
Note for brecht: removed the ED_undo_push for buttons... it was called
on *every* button now, which is probably too much? For example, using
the 'toolbar' redo also caused this...
2009-07-29 17:56:38 +00:00
|
|
|
ot->flag= 0;
|
2008-12-20 11:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int viewcenter_cursor_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-11-22 23:11:32 +00:00
|
|
|
{
|
|
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
|
|
|
|
RegionView3D *rv3d= CTX_wm_region_view3d(C);
|
|
|
|
|
Scene *scene= CTX_data_scene(C);
|
|
|
|
|
|
|
|
|
|
if (rv3d) {
|
2011-04-28 07:55:29 +00:00
|
|
|
ARegion *ar= CTX_wm_region(C);
|
|
|
|
|
|
2010-07-03 20:47:03 +00:00
|
|
|
/* non camera center */
|
|
|
|
|
float new_ofs[3];
|
|
|
|
|
negate_v3_v3(new_ofs, give_cursor(scene, v3d));
|
2011-04-28 07:55:29 +00:00
|
|
|
smooth_view(C, v3d, ar, NULL, NULL, new_ofs, NULL, NULL, NULL);
|
2009-11-22 23:11:32 +00:00
|
|
|
|
2010-11-07 14:57:24 +00:00
|
|
|
/* smooth view does viewlock RV3D_BOXVIEW copy */
|
2009-11-22 23:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VIEW3D_OT_view_center_cursor(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name= "Center View to Cursor";
|
2011-09-19 12:26:20 +00:00
|
|
|
ot->description= "Center the view so that the cursor is in the middle of the view";
|
2009-11-22 23:11:32 +00:00
|
|
|
ot->idname= "VIEW3D_OT_view_center_cursor";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec= viewcenter_cursor_exec;
|
|
|
|
|
ot->poll= ED_operator_view3d_active;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
2009-11-23 00:03:51 +00:00
|
|
|
ot->flag= 0;
|
2009-11-22 23:11:32 +00:00
|
|
|
}
|
2008-12-20 11:33:16 +00:00
|
|
|
|
2010-10-15 12:29:02 +00:00
|
|
|
static int view3d_center_camera_exec(bContext *C, wmOperator *UNUSED(op)) /* was view3d_home() in 2.4x */
|
2010-07-03 20:47:03 +00:00
|
|
|
{
|
2011-05-15 14:07:24 +00:00
|
|
|
Scene *scene= CTX_data_scene(C);
|
|
|
|
|
float xfac, yfac;
|
|
|
|
|
float size[2];
|
2010-07-03 20:47:03 +00:00
|
|
|
|
2012-01-16 06:57:37 +00:00
|
|
|
View3D *v3d;
|
|
|
|
|
ARegion *ar;
|
|
|
|
|
RegionView3D *rv3d;
|
|
|
|
|
|
|
|
|
|
/* no NULL check is needed, poll checks */
|
|
|
|
|
ED_view3d_context_user_region(C, &v3d, &ar);
|
|
|
|
|
rv3d = ar->regiondata;
|
|
|
|
|
|
2010-07-03 20:47:03 +00:00
|
|
|
rv3d->camdx= rv3d->camdy= 0.0f;
|
|
|
|
|
|
2011-11-19 18:35:42 +00:00
|
|
|
ED_view3d_calc_camera_border_size(scene, ar, v3d, rv3d, size);
|
2011-05-15 14:07:24 +00:00
|
|
|
|
|
|
|
|
/* 4px is just a little room from the edge of the area */
|
|
|
|
|
xfac= (float)ar->winx / (float)(size[0] + 4);
|
|
|
|
|
yfac= (float)ar->winy / (float)(size[1] + 4);
|
|
|
|
|
|
2011-05-20 04:14:29 +00:00
|
|
|
rv3d->camzoom= BKE_screen_view3d_zoom_from_fac(MIN2(xfac, yfac));
|
|
|
|
|
CLAMP(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX);
|
2011-05-15 14:07:24 +00:00
|
|
|
|
2010-07-03 20:47:03 +00:00
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, CTX_wm_view3d(C));
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VIEW3D_OT_view_center_camera(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name= "View Camera Center";
|
|
|
|
|
ot->description = "Center the camera view";
|
|
|
|
|
ot->idname= "VIEW3D_OT_view_center_camera";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec= view3d_center_camera_exec;
|
2012-01-16 06:57:37 +00:00
|
|
|
ot->poll= view3d_camera_user_poll;
|
2010-07-03 20:47:03 +00:00
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag= 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-27 01:29:56 +00:00
|
|
|
/* ********************* Set render border operator ****************** */
|
|
|
|
|
|
|
|
|
|
static int render_border_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
2008-12-27 01:29:56 +00:00
|
|
|
ARegion *ar= CTX_wm_region(C);
|
2010-04-16 02:14:56 +00:00
|
|
|
RegionView3D *rv3d= ED_view3d_context_rv3d(C);
|
2008-12-27 01:29:56 +00:00
|
|
|
Scene *scene= CTX_data_scene(C);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2008-12-27 01:29:56 +00:00
|
|
|
rcti rect;
|
|
|
|
|
rctf vb;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2008-12-27 01:29:56 +00:00
|
|
|
/* get border select values using rna */
|
|
|
|
|
rect.xmin= RNA_int_get(op->ptr, "xmin");
|
|
|
|
|
rect.ymin= RNA_int_get(op->ptr, "ymin");
|
|
|
|
|
rect.xmax= RNA_int_get(op->ptr, "xmax");
|
|
|
|
|
rect.ymax= RNA_int_get(op->ptr, "ymax");
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2008-12-27 01:29:56 +00:00
|
|
|
/* calculate range */
|
2011-05-21 08:56:37 +00:00
|
|
|
ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &vb, FALSE);
|
2008-12-27 01:29:56 +00:00
|
|
|
|
|
|
|
|
scene->r.border.xmin= ((float)rect.xmin-vb.xmin)/(vb.xmax-vb.xmin);
|
|
|
|
|
scene->r.border.ymin= ((float)rect.ymin-vb.ymin)/(vb.ymax-vb.ymin);
|
|
|
|
|
scene->r.border.xmax= ((float)rect.xmax-vb.xmin)/(vb.xmax-vb.xmin);
|
|
|
|
|
scene->r.border.ymax= ((float)rect.ymax-vb.ymin)/(vb.ymax-vb.ymin);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
|
|
|
|
/* actually set border */
|
2011-03-27 15:57:27 +00:00
|
|
|
CLAMP(scene->r.border.xmin, 0.0f, 1.0f);
|
|
|
|
|
CLAMP(scene->r.border.ymin, 0.0f, 1.0f);
|
|
|
|
|
CLAMP(scene->r.border.xmax, 0.0f, 1.0f);
|
|
|
|
|
CLAMP(scene->r.border.ymax, 0.0f, 1.0f);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2008-12-27 01:29:56 +00:00
|
|
|
/* drawing a border surrounding the entire camera view switches off border rendering
|
|
|
|
|
* or the border covers no pixels */
|
2011-03-27 15:57:27 +00:00
|
|
|
if ((scene->r.border.xmin <= 0.0f && scene->r.border.xmax >= 1.0f &&
|
|
|
|
|
scene->r.border.ymin <= 0.0f && scene->r.border.ymax >= 1.0f) ||
|
2008-12-27 01:29:56 +00:00
|
|
|
(scene->r.border.xmin == scene->r.border.xmax ||
|
|
|
|
|
scene->r.border.ymin == scene->r.border.ymax ))
|
|
|
|
|
{
|
|
|
|
|
scene->r.mode &= ~R_BORDER;
|
|
|
|
|
} else {
|
|
|
|
|
scene->r.mode |= R_BORDER;
|
|
|
|
|
}
|
2009-12-11 19:23:11 +00:00
|
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, NULL);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2008-12-27 01:29:56 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VIEW3D_OT_render_border(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name= "Set Render Border";
|
2011-09-19 12:26:20 +00:00
|
|
|
ot->description = "Set the boundaries of the border render and enables border render";
|
2008-12-27 01:29:56 +00:00
|
|
|
ot->idname= "VIEW3D_OT_render_border";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
2010-07-03 20:47:03 +00:00
|
|
|
ot->invoke= WM_border_select_invoke;
|
2008-12-27 01:29:56 +00:00
|
|
|
ot->exec= render_border_exec;
|
|
|
|
|
ot->modal= WM_border_select_modal;
|
2011-06-06 11:04:54 +00:00
|
|
|
ot->cancel= WM_border_select_cancel;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2010-07-03 20:47:03 +00:00
|
|
|
ot->poll= view3d_camera_active_poll;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-31 19:40:40 +00:00
|
|
|
/* flags */
|
|
|
|
|
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2008-12-27 01:29:56 +00:00
|
|
|
/* rna */
|
2009-01-16 23:53:11 +00:00
|
|
|
RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX);
|
|
|
|
|
RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX);
|
|
|
|
|
RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX);
|
|
|
|
|
RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX);
|
2008-12-27 01:29:56 +00:00
|
|
|
|
2009-01-16 00:58:33 +00:00
|
|
|
}
|
|
|
|
|
/* ********************* Border Zoom operator ****************** */
|
|
|
|
|
|
2009-07-24 23:07:18 +00:00
|
|
|
static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
|
2009-01-16 00:58:33 +00:00
|
|
|
{
|
|
|
|
|
ARegion *ar= CTX_wm_region(C);
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
|
|
|
|
RegionView3D *rv3d= CTX_wm_region_view3d(C);
|
2009-01-16 00:58:33 +00:00
|
|
|
Scene *scene= CTX_data_scene(C);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-16 00:58:33 +00:00
|
|
|
/* Zooms in on a border drawn by the user */
|
|
|
|
|
rcti rect;
|
|
|
|
|
float dvec[3], vb[2], xscale, yscale, scale;
|
|
|
|
|
|
|
|
|
|
/* SMOOTHVIEW */
|
|
|
|
|
float new_dist;
|
|
|
|
|
float new_ofs[3];
|
|
|
|
|
|
|
|
|
|
/* ZBuffer depth vars */
|
|
|
|
|
bglMats mats;
|
2010-10-21 07:38:09 +00:00
|
|
|
float depth_close= FLT_MAX;
|
2009-01-16 00:58:33 +00:00
|
|
|
double cent[2], p[3];
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-16 00:58:33 +00:00
|
|
|
/* note; otherwise opengl won't work */
|
|
|
|
|
view3d_operator_needs_opengl(C);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-16 00:58:33 +00:00
|
|
|
/* get border select values using rna */
|
|
|
|
|
rect.xmin= RNA_int_get(op->ptr, "xmin");
|
|
|
|
|
rect.ymin= RNA_int_get(op->ptr, "ymin");
|
|
|
|
|
rect.xmax= RNA_int_get(op->ptr, "xmax");
|
|
|
|
|
rect.ymax= RNA_int_get(op->ptr, "ymax");
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-16 00:58:33 +00:00
|
|
|
/* Get Z Depths, needed for perspective, nice for ortho */
|
|
|
|
|
bgl_get_mats(&mats);
|
|
|
|
|
draw_depth(scene, ar, v3d, NULL);
|
2010-10-21 07:38:09 +00:00
|
|
|
|
|
|
|
|
{
|
|
|
|
|
/* avoid allocating the whole depth buffer */
|
|
|
|
|
ViewDepths depth_temp= {0};
|
2009-01-16 00:58:33 +00:00
|
|
|
|
2010-10-21 07:38:09 +00:00
|
|
|
/* avoid view3d_update_depths() for speed. */
|
|
|
|
|
view3d_update_depths_rect(ar, &depth_temp, &rect);
|
|
|
|
|
|
|
|
|
|
/* find the closest Z pixel */
|
|
|
|
|
depth_close= view3d_depth_near(&depth_temp);
|
|
|
|
|
|
|
|
|
|
MEM_freeN(depth_temp.depths);
|
2009-01-16 00:58:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cent[0] = (((double)rect.xmin)+((double)rect.xmax)) / 2;
|
|
|
|
|
cent[1] = (((double)rect.ymin)+((double)rect.ymax)) / 2;
|
|
|
|
|
|
2011-05-20 11:15:44 +00:00
|
|
|
if (rv3d->is_persp) {
|
2009-01-16 00:58:33 +00:00
|
|
|
double p_corner[3];
|
|
|
|
|
|
|
|
|
|
/* no depths to use, we cant do anything! */
|
2010-01-01 17:48:48 +00:00
|
|
|
if (depth_close==FLT_MAX){
|
2009-01-21 02:24:12 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Depth Too Large");
|
2009-01-16 00:58:33 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2009-01-21 02:24:12 +00:00
|
|
|
}
|
2009-01-16 00:58:33 +00:00
|
|
|
/* convert border to 3d coordinates */
|
2012-01-19 16:04:44 +00:00
|
|
|
if ( (!gluUnProject(cent[0], cent[1], depth_close,
|
|
|
|
|
mats.modelview, mats.projection, (GLint *)mats.viewport,
|
|
|
|
|
&p[0], &p[1], &p[2])) ||
|
|
|
|
|
(!gluUnProject((double)rect.xmin, (double)rect.ymin, depth_close,
|
|
|
|
|
mats.modelview, mats.projection, (GLint *)mats.viewport,
|
|
|
|
|
&p_corner[0], &p_corner[1], &p_corner[2])))
|
|
|
|
|
{
|
2009-01-16 00:58:33 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2012-01-19 16:04:44 +00:00
|
|
|
}
|
2009-01-16 00:58:33 +00:00
|
|
|
|
|
|
|
|
dvec[0] = p[0]-p_corner[0];
|
|
|
|
|
dvec[1] = p[1]-p_corner[1];
|
|
|
|
|
dvec[2] = p[2]-p_corner[2];
|
|
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
new_dist = len_v3(dvec);
|
2011-03-27 15:57:27 +00:00
|
|
|
if(new_dist <= v3d->near * 1.5f) new_dist= v3d->near * 1.5f;
|
2009-01-16 00:58:33 +00:00
|
|
|
|
|
|
|
|
new_ofs[0] = -p[0];
|
|
|
|
|
new_ofs[1] = -p[1];
|
|
|
|
|
new_ofs[2] = -p[2];
|
|
|
|
|
|
|
|
|
|
} else { /* othographic */
|
|
|
|
|
/* find the current window width and height */
|
|
|
|
|
vb[0] = ar->winx;
|
|
|
|
|
vb[1] = ar->winy;
|
|
|
|
|
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
new_dist = rv3d->dist;
|
2009-01-16 00:58:33 +00:00
|
|
|
|
|
|
|
|
/* convert the drawn rectangle into 3d space */
|
2012-01-19 16:04:44 +00:00
|
|
|
if (depth_close != FLT_MAX && gluUnProject(cent[0], cent[1], depth_close,
|
|
|
|
|
mats.modelview, mats.projection, (GLint *)mats.viewport,
|
|
|
|
|
&p[0], &p[1], &p[2]))
|
|
|
|
|
{
|
2009-01-16 00:58:33 +00:00
|
|
|
new_ofs[0] = -p[0];
|
|
|
|
|
new_ofs[1] = -p[1];
|
|
|
|
|
new_ofs[2] = -p[2];
|
2011-05-20 13:50:41 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
float mval_f[2];
|
2009-01-16 00:58:33 +00:00
|
|
|
/* We cant use the depth, fallback to the old way that dosnt set the center depth */
|
2010-02-25 20:26:38 +00:00
|
|
|
copy_v3_v3(new_ofs, rv3d->ofs);
|
2009-01-16 00:58:33 +00:00
|
|
|
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
initgrabz(rv3d, -new_ofs[0], -new_ofs[1], -new_ofs[2]);
|
2009-01-16 00:58:33 +00:00
|
|
|
|
2011-05-20 13:50:41 +00:00
|
|
|
mval_f[0]= (rect.xmin + rect.xmax - vb[0]) / 2.0f;
|
|
|
|
|
mval_f[1]= (rect.ymin + rect.ymax - vb[1]) / 2.0f;
|
|
|
|
|
ED_view3d_win_to_delta(ar, mval_f, dvec);
|
2009-01-16 00:58:33 +00:00
|
|
|
/* center the view to the center of the rectangle */
|
2010-04-23 23:57:00 +00:00
|
|
|
sub_v3_v3(new_ofs, dvec);
|
2009-01-16 00:58:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* work out the ratios, so that everything selected fits when we zoom */
|
|
|
|
|
xscale = ((rect.xmax-rect.xmin)/vb[0]);
|
|
|
|
|
yscale = ((rect.ymax-rect.ymin)/vb[1]);
|
|
|
|
|
scale = (xscale >= yscale)?xscale:yscale;
|
|
|
|
|
|
|
|
|
|
/* zoom in as required, or as far as we can go */
|
2011-03-27 15:57:27 +00:00
|
|
|
new_dist = ((new_dist*scale) >= 0.001f * v3d->grid)? new_dist*scale:0.001f * v3d->grid;
|
2009-01-16 00:58:33 +00:00
|
|
|
}
|
|
|
|
|
|
2011-04-28 07:55:29 +00:00
|
|
|
smooth_view(C, v3d, ar, NULL, NULL, new_ofs, NULL, &new_dist, NULL);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2.5
Smaller jobs, all in one commit!
- Moved object_do_update out of view3d drawing, into
the event system (currently after notifiers).
Depsgraph calls for setting update flags will have to
keep track of each Screen's needs, so a UI showing only
a Sequencer doesn't do objects.
- Added button in "Properties region" in 3D window to set
or disable 4-split, including the 3 options it has.
(lock, box, clip)
- Restored legacy code for UI, to make things work like
bone rename, autocomplete.
- Node editor now shows Curves widgets again
- Bugfix: composite job increased Viewer user id count
- Bugfix: Node editor, not "Enable nodes" still called
a Job, which didn't do anything
- Various code cleaning, unused vars and prototypes.
2009-02-11 16:54:55 +00:00
|
|
|
if(rv3d->viewlock & RV3D_BOXVIEW)
|
2009-01-20 14:23:32 +00:00
|
|
|
view3d_boxview_sync(CTX_wm_area(C), ar);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-16 00:58:33 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
|
2009-07-24 23:07:18 +00:00
|
|
|
static int view3d_zoom_border_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
2009-01-16 00:58:33 +00:00
|
|
|
{
|
2011-05-15 02:39:36 +00:00
|
|
|
View3D *v3d= CTX_wm_view3d(C);
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
RegionView3D *rv3d= CTX_wm_region_view3d(C);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-16 00:58:33 +00:00
|
|
|
/* if in camera view do not exec the operator so we do not conflict with set render border*/
|
2011-05-23 15:46:09 +00:00
|
|
|
if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d))
|
2009-07-09 02:45:48 +00:00
|
|
|
return WM_border_select_invoke(C, op, event);
|
|
|
|
|
else
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
return OPERATOR_PASS_THROUGH;
|
2009-01-16 00:58:33 +00:00
|
|
|
}
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
|
2009-03-29 02:15:13 +00:00
|
|
|
void VIEW3D_OT_zoom_border(wmOperatorType *ot)
|
2009-01-16 00:58:33 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name= "Border Zoom";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Zoom in the view to the nearest object contained in the border";
|
2009-03-29 02:15:13 +00:00
|
|
|
ot->idname= "VIEW3D_OT_zoom_border";
|
2009-01-16 00:58:33 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2009-07-24 23:07:18 +00:00
|
|
|
ot->invoke= view3d_zoom_border_invoke;
|
|
|
|
|
ot->exec= view3d_zoom_border_exec;
|
2009-01-16 00:58:33 +00:00
|
|
|
ot->modal= WM_border_select_modal;
|
2011-06-06 11:04:54 +00:00
|
|
|
ot->cancel= WM_border_select_cancel;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2010-09-27 10:44:46 +00:00
|
|
|
ot->poll= ED_operator_region_view3d_active;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-31 19:40:40 +00:00
|
|
|
/* flags */
|
2.5
Operator goodies!
--- Macro operators
Operators now can consist of multiple operators. Such a macro operator
is identical and behaves identical to other opererators. Macros can
also be constructed of macros even! Currently only hardcoded macros are
implemented, this to solve combined operators such as 'add duplicate' or
'extrude' (both want a transform appended).
Usage is simple:
- WM_operatortype_append_macro() : add new operatortype, name, flags
- WM_operatortype_macro_define() : add existing operator to macro
(Note: macro_define will also allow properties to be set, doesnt work
right now)
On converting the macro wmOperatorType to a real operator, it makes a
list of all operators, and the standard macro callbacks (exec, invoke,
modal, poll) just will use all.
Important note; switching to a modal operator only works as last in the
chain now!
Macros implemented for duplicate, extrude and rip. Tool menu works fine
for it, also the redo hotkey F4 works properly.
--- Operator redo fix
The operators use the undo system to switch back, but this could give
errors if other actions added undo pushes (buttons, outliner). Now the
redo for operator searches back for the correct undo level.
This fixes issues with many redos.
Note for brecht: removed the ED_undo_push for buttons... it was called
on *every* button now, which is probably too much? For example, using
the 'toolbar' redo also caused this...
2009-07-29 17:56:38 +00:00
|
|
|
ot->flag= 0;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-16 00:58:33 +00:00
|
|
|
/* rna */
|
2009-01-16 23:53:11 +00:00
|
|
|
RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX);
|
|
|
|
|
RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX);
|
|
|
|
|
RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX);
|
|
|
|
|
RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX);
|
2009-01-16 00:58:33 +00:00
|
|
|
|
2008-12-27 01:29:56 +00:00
|
|
|
}
|
2011-02-23 06:48:47 +00:00
|
|
|
|
|
|
|
|
/* sets the view to 1:1 camera/render-pixel */
|
2011-11-04 14:36:06 +00:00
|
|
|
static void view3d_set_1_to_1_viewborder(Scene *scene, ARegion *ar, View3D *v3d)
|
2011-02-23 06:48:47 +00:00
|
|
|
{
|
|
|
|
|
RegionView3D *rv3d= ar->regiondata;
|
|
|
|
|
float size[2];
|
|
|
|
|
int im_width= (scene->r.size*scene->r.xsch)/100;
|
|
|
|
|
|
2011-11-19 18:35:42 +00:00
|
|
|
ED_view3d_calc_camera_border_size(scene, ar, v3d, rv3d, size);
|
2011-05-20 04:14:29 +00:00
|
|
|
|
|
|
|
|
rv3d->camzoom= BKE_screen_view3d_zoom_from_fac((float)im_width/size[0]);
|
|
|
|
|
CLAMP(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX);
|
2011-02-23 06:48:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int view3d_zoom_1_to_1_camera_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
|
{
|
|
|
|
|
Scene *scene= CTX_data_scene(C);
|
|
|
|
|
|
2012-01-16 06:57:37 +00:00
|
|
|
View3D *v3d;
|
|
|
|
|
ARegion *ar;
|
2011-02-23 06:48:47 +00:00
|
|
|
|
2012-01-16 06:57:37 +00:00
|
|
|
/* no NULL check is needed, poll checks */
|
|
|
|
|
ED_view3d_context_user_region(C, &v3d, &ar);
|
|
|
|
|
|
|
|
|
|
view3d_set_1_to_1_viewborder(scene, ar, v3d);
|
|
|
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, v3d);
|
2011-02-23 06:48:47 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VIEW3D_OT_zoom_camera_1_to_1(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name= "Zoom Camera 1:1";
|
|
|
|
|
ot->description = "Match the camera to 1:1 to the render output";
|
|
|
|
|
ot->idname= "VIEW3D_OT_zoom_camera_1_to_1";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec= view3d_zoom_1_to_1_camera_exec;
|
2012-01-16 06:57:37 +00:00
|
|
|
ot->poll= view3d_camera_user_poll;
|
2011-02-23 06:48:47 +00:00
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag= 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-26 10:31:44 +00:00
|
|
|
/* ********************* Changing view operator ****************** */
|
|
|
|
|
|
2008-12-23 09:59:02 +00:00
|
|
|
static EnumPropertyItem prop_view_items[] = {
|
2009-10-27 02:54:25 +00:00
|
|
|
{RV3D_VIEW_FRONT, "FRONT", 0, "Front", "View From the Front"},
|
|
|
|
|
{RV3D_VIEW_BACK, "BACK", 0, "Back", "View From the Back"},
|
|
|
|
|
{RV3D_VIEW_LEFT, "LEFT", 0, "Left", "View From the Left"},
|
|
|
|
|
{RV3D_VIEW_RIGHT, "RIGHT", 0, "Right", "View From the Right"},
|
|
|
|
|
{RV3D_VIEW_TOP, "TOP", 0, "Top", "View From the Top"},
|
|
|
|
|
{RV3D_VIEW_BOTTOM, "BOTTOM", 0, "Bottom", "View From the Bottom"},
|
2011-09-19 12:26:20 +00:00
|
|
|
{RV3D_VIEW_CAMERA, "CAMERA", 0, "Camera", "View From the active camera"},
|
2009-06-16 00:52:21 +00:00
|
|
|
{0, NULL, 0, NULL, NULL}};
|
2008-12-23 09:59:02 +00:00
|
|
|
|
2009-11-06 10:38:00 +00:00
|
|
|
|
|
|
|
|
/* would like to make this a generic function - outside of transform */
|
|
|
|
|
|
2012-01-19 16:04:44 +00:00
|
|
|
static void axis_set_view(bContext *C, View3D *v3d, ARegion *ar,
|
|
|
|
|
float q1, float q2, float q3, float q4,
|
|
|
|
|
short view, int perspo, int align_active)
|
2008-12-23 09:59:02 +00:00
|
|
|
{
|
2011-04-28 08:26:49 +00:00
|
|
|
RegionView3D *rv3d= ar->regiondata; /* no NULL check is needed, poll checks */
|
2008-12-23 09:59:02 +00:00
|
|
|
float new_quat[4];
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2008-12-23 09:59:02 +00:00
|
|
|
new_quat[0]= q1; new_quat[1]= q2;
|
|
|
|
|
new_quat[2]= q3; new_quat[3]= q4;
|
2011-04-30 06:40:39 +00:00
|
|
|
normalize_qt(new_quat);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-11-06 10:38:00 +00:00
|
|
|
if(align_active) {
|
|
|
|
|
/* align to active object */
|
|
|
|
|
Object *obact= CTX_data_active_object(C);
|
|
|
|
|
if (obact==NULL) {
|
|
|
|
|
/* no active object, ignore this option */
|
|
|
|
|
align_active= FALSE;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
float obact_quat[4];
|
2009-11-06 22:10:08 +00:00
|
|
|
float twmat[3][3];
|
2009-11-06 10:38:00 +00:00
|
|
|
|
|
|
|
|
/* same as transform manipulator when normal is set */
|
2011-02-18 16:47:10 +00:00
|
|
|
ED_getTransformOrientationMatrix(C, twmat, FALSE);
|
2009-11-06 10:38:00 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
mat3_to_quat( obact_quat,twmat);
|
|
|
|
|
invert_qt(obact_quat);
|
|
|
|
|
mul_qt_qtqt(new_quat, new_quat, obact_quat);
|
2009-11-06 10:38:00 +00:00
|
|
|
|
2011-05-15 03:42:28 +00:00
|
|
|
rv3d->view= view= RV3D_VIEW_USER;
|
2009-11-06 10:38:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(align_active==FALSE) {
|
|
|
|
|
/* normal operation */
|
|
|
|
|
if(rv3d->viewlock) {
|
|
|
|
|
/* only pass on if */
|
|
|
|
|
if(rv3d->view==RV3D_VIEW_FRONT && view==RV3D_VIEW_BACK);
|
|
|
|
|
else if(rv3d->view==RV3D_VIEW_BACK && view==RV3D_VIEW_FRONT);
|
|
|
|
|
else if(rv3d->view==RV3D_VIEW_RIGHT && view==RV3D_VIEW_LEFT);
|
|
|
|
|
else if(rv3d->view==RV3D_VIEW_LEFT && view==RV3D_VIEW_RIGHT);
|
|
|
|
|
else if(rv3d->view==RV3D_VIEW_BOTTOM && view==RV3D_VIEW_TOP);
|
|
|
|
|
else if(rv3d->view==RV3D_VIEW_TOP && view==RV3D_VIEW_BOTTOM);
|
|
|
|
|
else return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rv3d->view= view;
|
|
|
|
|
}
|
2009-01-20 14:23:32 +00:00
|
|
|
|
|
|
|
|
if(rv3d->viewlock) {
|
2011-04-28 07:55:29 +00:00
|
|
|
ED_region_tag_redraw(ar);
|
2009-01-20 14:23:32 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-27 02:54:25 +00:00
|
|
|
if (rv3d->persp==RV3D_CAMOB && v3d->camera) {
|
2008-12-23 09:59:02 +00:00
|
|
|
|
2010-09-07 09:15:59 +00:00
|
|
|
if (U.uiflag & USER_AUTOPERSP) rv3d->persp= view ? RV3D_ORTHO : RV3D_PERSP;
|
2009-10-27 02:54:25 +00:00
|
|
|
else if(rv3d->persp==RV3D_CAMOB) rv3d->persp= perspo;
|
2008-12-23 09:59:02 +00:00
|
|
|
|
2011-04-28 07:55:29 +00:00
|
|
|
smooth_view(C, v3d, ar, v3d->camera, NULL, rv3d->ofs, new_quat, NULL, NULL);
|
2009-07-09 02:45:48 +00:00
|
|
|
}
|
2008-12-26 18:15:46 +00:00
|
|
|
else {
|
2008-12-23 09:59:02 +00:00
|
|
|
|
2010-09-07 09:15:59 +00:00
|
|
|
if (U.uiflag & USER_AUTOPERSP) rv3d->persp= view ? RV3D_ORTHO : RV3D_PERSP;
|
2009-10-27 02:54:25 +00:00
|
|
|
else if(rv3d->persp==RV3D_CAMOB) rv3d->persp= perspo;
|
2008-12-23 09:59:02 +00:00
|
|
|
|
2011-04-28 07:55:29 +00:00
|
|
|
smooth_view(C, v3d, ar, NULL, NULL, NULL, new_quat, NULL, NULL);
|
2008-12-23 09:59:02 +00:00
|
|
|
}
|
2008-12-26 18:15:46 +00:00
|
|
|
|
2008-12-23 09:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int viewnumpad_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2012-01-14 12:24:25 +00:00
|
|
|
View3D *v3d;
|
|
|
|
|
ARegion *ar;
|
|
|
|
|
RegionView3D *rv3d;
|
2008-12-23 09:59:02 +00:00
|
|
|
Scene *scene= CTX_data_scene(C);
|
2012-01-14 12:24:25 +00:00
|
|
|
static int perspo = RV3D_PERSP;
|
2009-12-07 10:40:55 +00:00
|
|
|
int viewnum, align_active, nextperspo;
|
2008-12-23 09:59:02 +00:00
|
|
|
|
2012-01-16 06:57:37 +00:00
|
|
|
/* no NULL check is needed, poll checks */
|
2012-01-14 12:24:25 +00:00
|
|
|
ED_view3d_context_user_region(C, &v3d, &ar);
|
|
|
|
|
rv3d = ar->regiondata;
|
|
|
|
|
|
2009-02-04 05:15:39 +00:00
|
|
|
viewnum = RNA_enum_get(op->ptr, "type");
|
2009-11-06 10:38:00 +00:00
|
|
|
align_active = RNA_boolean_get(op->ptr, "align_active");
|
2008-12-23 09:59:02 +00:00
|
|
|
|
2011-02-05 19:07:54 +00:00
|
|
|
/* set this to zero, gets handled in axis_set_view */
|
|
|
|
|
if(rv3d->viewlock)
|
|
|
|
|
align_active= 0;
|
2009-12-07 10:40:55 +00:00
|
|
|
|
2008-12-23 09:59:02 +00:00
|
|
|
/* Use this to test if we started out with a camera */
|
|
|
|
|
|
2009-12-07 10:40:55 +00:00
|
|
|
if (rv3d->persp == RV3D_CAMOB) {
|
|
|
|
|
nextperspo= rv3d->lpersp;
|
|
|
|
|
} else {
|
|
|
|
|
nextperspo= perspo;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-23 09:59:02 +00:00
|
|
|
switch (viewnum) {
|
2009-10-27 02:54:25 +00:00
|
|
|
case RV3D_VIEW_BOTTOM :
|
2012-01-19 16:04:44 +00:00
|
|
|
axis_set_view(C, v3d, ar, 0.0, -1.0, 0.0, 0.0,
|
|
|
|
|
viewnum, nextperspo, align_active);
|
2008-12-23 09:59:02 +00:00
|
|
|
break;
|
|
|
|
|
|
2009-10-27 02:54:25 +00:00
|
|
|
case RV3D_VIEW_BACK:
|
2012-01-19 16:04:44 +00:00
|
|
|
axis_set_view(C, v3d, ar, 0.0, 0.0, (float)-cos(M_PI/4.0), (float)-cos(M_PI/4.0),
|
|
|
|
|
viewnum, nextperspo, align_active);
|
2008-12-23 09:59:02 +00:00
|
|
|
break;
|
|
|
|
|
|
2009-10-27 02:54:25 +00:00
|
|
|
case RV3D_VIEW_LEFT:
|
2012-01-19 16:04:44 +00:00
|
|
|
axis_set_view(C, v3d, ar, 0.5, -0.5, 0.5, 0.5,
|
|
|
|
|
viewnum, nextperspo, align_active);
|
2008-12-23 09:59:02 +00:00
|
|
|
break;
|
|
|
|
|
|
2009-10-27 02:54:25 +00:00
|
|
|
case RV3D_VIEW_TOP:
|
2012-01-19 16:04:44 +00:00
|
|
|
axis_set_view(C, v3d, ar, 1.0, 0.0, 0.0, 0.0,
|
|
|
|
|
viewnum, nextperspo, align_active);
|
2008-12-23 09:59:02 +00:00
|
|
|
break;
|
|
|
|
|
|
2009-10-27 02:54:25 +00:00
|
|
|
case RV3D_VIEW_FRONT:
|
2012-01-19 16:04:44 +00:00
|
|
|
axis_set_view(C, v3d, ar, (float)cos(M_PI/4.0), (float)-sin(M_PI/4.0), 0.0, 0.0,
|
|
|
|
|
viewnum, nextperspo, align_active);
|
2008-12-23 09:59:02 +00:00
|
|
|
break;
|
|
|
|
|
|
2009-10-27 02:54:25 +00:00
|
|
|
case RV3D_VIEW_RIGHT:
|
2012-01-19 16:04:44 +00:00
|
|
|
axis_set_view(C, v3d, ar, 0.5, -0.5, -0.5, -0.5,
|
|
|
|
|
viewnum, nextperspo, align_active);
|
2008-12-23 09:59:02 +00:00
|
|
|
break;
|
|
|
|
|
|
2009-10-27 02:54:25 +00:00
|
|
|
case RV3D_VIEW_CAMERA:
|
2009-01-20 14:23:32 +00:00
|
|
|
if(rv3d->viewlock==0) {
|
|
|
|
|
/* lastview - */
|
|
|
|
|
|
2009-10-27 02:54:25 +00:00
|
|
|
if(rv3d->persp != RV3D_CAMOB) {
|
2010-07-24 01:32:03 +00:00
|
|
|
Object *ob= OBACT;
|
2010-01-29 06:43:13 +00:00
|
|
|
|
|
|
|
|
if (!rv3d->smooth_timer) {
|
|
|
|
|
/* store settings of current view before allowing overwriting with camera view
|
|
|
|
|
* only if we're not currently in a view transition */
|
2010-07-24 01:32:03 +00:00
|
|
|
copy_qt_qt(rv3d->lviewquat, rv3d->viewquat);
|
2010-01-29 06:43:13 +00:00
|
|
|
rv3d->lview= rv3d->view;
|
|
|
|
|
rv3d->lpersp= rv3d->persp;
|
|
|
|
|
}
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-20 14:23:32 +00:00
|
|
|
#if 0
|
|
|
|
|
if(G.qual==LR_ALTKEY) {
|
|
|
|
|
if(oldcamera && is_an_active_object(oldcamera)) {
|
|
|
|
|
v3d->camera= oldcamera;
|
|
|
|
|
}
|
|
|
|
|
handle_view3d_lock();
|
2008-12-26 18:15:46 +00:00
|
|
|
}
|
2009-01-20 14:23:32 +00:00
|
|
|
#endif
|
2010-07-24 01:32:03 +00:00
|
|
|
|
|
|
|
|
/* first get the default camera for the view lock type */
|
|
|
|
|
if(v3d->scenelock) {
|
|
|
|
|
/* sets the camera view if available */
|
|
|
|
|
v3d->camera= scene->camera;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* use scene camera if one is not set (even though we're unlocked) */
|
|
|
|
|
if(v3d->camera==NULL) {
|
|
|
|
|
v3d->camera= scene->camera;
|
2009-01-20 14:23:32 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2010-07-24 01:32:03 +00:00
|
|
|
/* if the camera isnt found, check a number of options */
|
|
|
|
|
if(v3d->camera==NULL && ob && ob->type==OB_CAMERA)
|
|
|
|
|
v3d->camera= ob;
|
|
|
|
|
|
|
|
|
|
if(v3d->camera==NULL)
|
|
|
|
|
v3d->camera= scene_find_camera(scene);
|
|
|
|
|
|
|
|
|
|
/* couldnt find any useful camera, bail out */
|
|
|
|
|
if(v3d->camera==NULL)
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
|
|
/* important these dont get out of sync for locked scenes */
|
|
|
|
|
if(v3d->scenelock)
|
|
|
|
|
scene->camera= v3d->camera;
|
|
|
|
|
|
|
|
|
|
/* finally do snazzy view zooming */
|
2009-10-27 02:54:25 +00:00
|
|
|
rv3d->persp= RV3D_CAMOB;
|
2011-04-28 07:55:29 +00:00
|
|
|
smooth_view(C, v3d, ar, NULL, v3d->camera, rv3d->ofs, rv3d->viewquat, &rv3d->dist, &v3d->lens);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2008-12-26 18:15:46 +00:00
|
|
|
}
|
2009-01-20 14:23:32 +00:00
|
|
|
else{
|
|
|
|
|
/* return to settings of last view */
|
|
|
|
|
/* does smooth_view too */
|
2012-01-19 16:04:44 +00:00
|
|
|
axis_set_view(C, v3d, ar,
|
|
|
|
|
rv3d->lviewquat[0], rv3d->lviewquat[1], rv3d->lviewquat[2], rv3d->lviewquat[3],
|
|
|
|
|
rv3d->lview, rv3d->lpersp, 0);
|
2008-12-23 09:59:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default :
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-27 02:54:25 +00:00
|
|
|
if(rv3d->persp != RV3D_CAMOB) perspo= rv3d->persp;
|
2008-12-23 09:59:02 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
2010-11-19 17:16:25 +00:00
|
|
|
|
|
|
|
|
|
2008-12-26 11:11:21 +00:00
|
|
|
void VIEW3D_OT_viewnumpad(wmOperatorType *ot)
|
2008-12-23 09:59:02 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name= "View numpad";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Set the view";
|
2008-12-26 11:11:21 +00:00
|
|
|
ot->idname= "VIEW3D_OT_viewnumpad";
|
2008-12-23 09:59:02 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec= viewnumpad_exec;
|
2012-01-14 12:24:25 +00:00
|
|
|
ot->poll= ED_operator_rv3d_user_region_poll;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-31 19:40:40 +00:00
|
|
|
/* flags */
|
2.5
Operator goodies!
--- Macro operators
Operators now can consist of multiple operators. Such a macro operator
is identical and behaves identical to other opererators. Macros can
also be constructed of macros even! Currently only hardcoded macros are
implemented, this to solve combined operators such as 'add duplicate' or
'extrude' (both want a transform appended).
Usage is simple:
- WM_operatortype_append_macro() : add new operatortype, name, flags
- WM_operatortype_macro_define() : add existing operator to macro
(Note: macro_define will also allow properties to be set, doesnt work
right now)
On converting the macro wmOperatorType to a real operator, it makes a
list of all operators, and the standard macro callbacks (exec, invoke,
modal, poll) just will use all.
Important note; switching to a modal operator only works as last in the
chain now!
Macros implemented for duplicate, extrude and rip. Tool menu works fine
for it, also the redo hotkey F4 works properly.
--- Operator redo fix
The operators use the undo system to switch back, but this could give
errors if other actions added undo pushes (buttons, outliner). Now the
redo for operator searches back for the correct undo level.
This fixes issues with many redos.
Note for brecht: removed the ED_undo_push for buttons... it was called
on *every* button now, which is probably too much? For example, using
the 'toolbar' redo also caused this...
2009-07-29 17:56:38 +00:00
|
|
|
ot->flag= 0;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-02-04 05:15:39 +00:00
|
|
|
RNA_def_enum(ot->srna, "type", prop_view_items, 0, "View", "The Type of view");
|
2011-09-20 07:56:58 +00:00
|
|
|
RNA_def_boolean(ot->srna, "align_active", 0, "Align Active", "Align to the active object's axis");
|
2008-12-23 09:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-03 03:54:03 +00:00
|
|
|
static EnumPropertyItem prop_view_orbit_items[] = {
|
2009-06-16 00:52:21 +00:00
|
|
|
{V3D_VIEW_STEPLEFT, "ORBITLEFT", 0, "Orbit Left", "Orbit the view around to the Left"},
|
|
|
|
|
{V3D_VIEW_STEPRIGHT, "ORBITRIGHT", 0, "Orbit Right", "Orbit the view around to the Right"},
|
|
|
|
|
{V3D_VIEW_STEPUP, "ORBITUP", 0, "Orbit Up", "Orbit the view Up"},
|
|
|
|
|
{V3D_VIEW_STEPDOWN, "ORBITDOWN", 0, "Orbit Down", "Orbit the view Down"},
|
|
|
|
|
{0, NULL, 0, NULL, NULL}};
|
2009-02-03 03:54:03 +00:00
|
|
|
|
|
|
|
|
static int vieworbit_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2012-01-14 12:24:25 +00:00
|
|
|
View3D *v3d;
|
|
|
|
|
ARegion *ar;
|
|
|
|
|
RegionView3D *rv3d;
|
2010-02-25 20:26:38 +00:00
|
|
|
float phi, q1[4], new_quat[4];
|
2009-02-03 03:54:03 +00:00
|
|
|
int orbitdir;
|
|
|
|
|
|
2012-01-14 12:24:25 +00:00
|
|
|
/* no NULL check is needed, poll checks */
|
|
|
|
|
ED_view3d_context_user_region(C, &v3d, &ar);
|
|
|
|
|
rv3d = ar->regiondata;
|
|
|
|
|
|
2009-02-03 03:54:03 +00:00
|
|
|
orbitdir = RNA_enum_get(op->ptr, "type");
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-02-03 03:54:03 +00:00
|
|
|
if(rv3d->viewlock==0) {
|
2011-05-23 15:46:09 +00:00
|
|
|
if((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d)) {
|
2009-02-03 03:54:03 +00:00
|
|
|
if(orbitdir == V3D_VIEW_STEPLEFT || orbitdir == V3D_VIEW_STEPRIGHT) {
|
2010-02-25 20:26:38 +00:00
|
|
|
float si;
|
2009-02-03 03:54:03 +00:00
|
|
|
/* z-axis */
|
|
|
|
|
phi= (float)(M_PI/360.0)*U.pad_rot_angle;
|
|
|
|
|
if(orbitdir == V3D_VIEW_STEPRIGHT) phi= -phi;
|
|
|
|
|
si= (float)sin(phi);
|
|
|
|
|
q1[0]= (float)cos(phi);
|
|
|
|
|
q1[1]= q1[2]= 0.0;
|
|
|
|
|
q1[3]= si;
|
2010-01-03 03:01:46 +00:00
|
|
|
mul_qt_qtqt(new_quat, rv3d->viewquat, q1);
|
2011-05-15 03:42:28 +00:00
|
|
|
rv3d->view= RV3D_VIEW_USER;
|
2009-02-03 03:54:03 +00:00
|
|
|
}
|
2010-01-03 03:01:46 +00:00
|
|
|
else if(orbitdir == V3D_VIEW_STEPDOWN || orbitdir == V3D_VIEW_STEPUP) {
|
2009-02-03 03:54:03 +00:00
|
|
|
/* horizontal axis */
|
2010-07-26 06:34:56 +00:00
|
|
|
copy_v3_v3(q1+1, rv3d->viewinv[0]);
|
2009-02-03 03:54:03 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
normalize_v3(q1+1);
|
2009-02-03 03:54:03 +00:00
|
|
|
phi= (float)(M_PI/360.0)*U.pad_rot_angle;
|
|
|
|
|
if(orbitdir == V3D_VIEW_STEPDOWN) phi= -phi;
|
|
|
|
|
q1[0]= (float)cos(phi);
|
2010-02-25 20:26:38 +00:00
|
|
|
mul_v3_fl(q1+1, sin(phi));
|
2010-01-03 03:01:46 +00:00
|
|
|
mul_qt_qtqt(new_quat, rv3d->viewquat, q1);
|
2011-05-15 03:42:28 +00:00
|
|
|
rv3d->view= RV3D_VIEW_USER;
|
2009-02-03 03:54:03 +00:00
|
|
|
}
|
2010-01-03 03:01:46 +00:00
|
|
|
|
2011-04-28 08:26:49 +00:00
|
|
|
smooth_view(C, CTX_wm_view3d(C), ar, NULL, NULL, NULL, new_quat, NULL, NULL);
|
2009-02-03 03:54:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-09 02:45:48 +00:00
|
|
|
return OPERATOR_FINISHED;
|
2009-02-03 03:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VIEW3D_OT_view_orbit(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name= "View Orbit";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Orbit the view";
|
2009-02-03 03:54:03 +00:00
|
|
|
ot->idname= "VIEW3D_OT_view_orbit";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec= vieworbit_exec;
|
2012-01-14 12:24:25 +00:00
|
|
|
ot->poll= ED_operator_rv3d_user_region_poll;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-02-03 03:54:03 +00:00
|
|
|
/* flags */
|
2.5
Operator goodies!
--- Macro operators
Operators now can consist of multiple operators. Such a macro operator
is identical and behaves identical to other opererators. Macros can
also be constructed of macros even! Currently only hardcoded macros are
implemented, this to solve combined operators such as 'add duplicate' or
'extrude' (both want a transform appended).
Usage is simple:
- WM_operatortype_append_macro() : add new operatortype, name, flags
- WM_operatortype_macro_define() : add existing operator to macro
(Note: macro_define will also allow properties to be set, doesnt work
right now)
On converting the macro wmOperatorType to a real operator, it makes a
list of all operators, and the standard macro callbacks (exec, invoke,
modal, poll) just will use all.
Important note; switching to a modal operator only works as last in the
chain now!
Macros implemented for duplicate, extrude and rip. Tool menu works fine
for it, also the redo hotkey F4 works properly.
--- Operator redo fix
The operators use the undo system to switch back, but this could give
errors if other actions added undo pushes (buttons, outliner). Now the
redo for operator searches back for the correct undo level.
This fixes issues with many redos.
Note for brecht: removed the ED_undo_push for buttons... it was called
on *every* button now, which is probably too much? For example, using
the 'toolbar' redo also caused this...
2009-07-29 17:56:38 +00:00
|
|
|
ot->flag= 0;
|
2009-02-03 03:54:03 +00:00
|
|
|
RNA_def_enum(ot->srna, "type", prop_view_orbit_items, 0, "Orbit", "Direction of View Orbit");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static EnumPropertyItem prop_view_pan_items[] = {
|
2009-06-16 00:52:21 +00:00
|
|
|
{V3D_VIEW_PANLEFT, "PANLEFT", 0, "Pan Left", "Pan the view to the Left"},
|
|
|
|
|
{V3D_VIEW_PANRIGHT, "PANRIGHT", 0, "Pan Right", "Pan the view to the Right"},
|
|
|
|
|
{V3D_VIEW_PANUP, "PANUP", 0, "Pan Up", "Pan the view Up"},
|
|
|
|
|
{V3D_VIEW_PANDOWN, "PANDOWN", 0, "Pan Down", "Pan the view Down"},
|
|
|
|
|
{0, NULL, 0, NULL, NULL}};
|
2009-02-03 03:54:03 +00:00
|
|
|
|
|
|
|
|
static int viewpan_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
|
|
|
|
ARegion *ar= CTX_wm_region(C);
|
2009-07-09 02:45:48 +00:00
|
|
|
RegionView3D *rv3d= CTX_wm_region_view3d(C);
|
|
|
|
|
float vec[3];
|
2011-05-20 13:50:41 +00:00
|
|
|
float mval_f[2]= {0.0f, 0.0f};
|
2009-02-03 03:54:03 +00:00
|
|
|
int pandir;
|
|
|
|
|
|
|
|
|
|
pandir = RNA_enum_get(op->ptr, "type");
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-02-03 03:54:03 +00:00
|
|
|
initgrabz(rv3d, 0.0, 0.0, 0.0);
|
2011-05-20 13:50:41 +00:00
|
|
|
if(pandir == V3D_VIEW_PANRIGHT) { mval_f[0]= -32.0f; ED_view3d_win_to_delta(ar, mval_f, vec); }
|
|
|
|
|
else if(pandir == V3D_VIEW_PANLEFT) { mval_f[0]= 32.0f; ED_view3d_win_to_delta(ar, mval_f, vec); }
|
|
|
|
|
else if(pandir == V3D_VIEW_PANUP) { mval_f[1]= -25.0f; ED_view3d_win_to_delta(ar, mval_f, vec); }
|
|
|
|
|
else if(pandir == V3D_VIEW_PANDOWN) { mval_f[1]= 25.0f; ED_view3d_win_to_delta(ar, mval_f, vec); }
|
2010-10-07 10:04:07 +00:00
|
|
|
add_v3_v3(rv3d->ofs, vec);
|
2009-02-03 03:54:03 +00:00
|
|
|
|
2.5
Smaller jobs, all in one commit!
- Moved object_do_update out of view3d drawing, into
the event system (currently after notifiers).
Depsgraph calls for setting update flags will have to
keep track of each Screen's needs, so a UI showing only
a Sequencer doesn't do objects.
- Added button in "Properties region" in 3D window to set
or disable 4-split, including the 3 options it has.
(lock, box, clip)
- Restored legacy code for UI, to make things work like
bone rename, autocomplete.
- Node editor now shows Curves widgets again
- Bugfix: composite job increased Viewer user id count
- Bugfix: Node editor, not "Enable nodes" still called
a Job, which didn't do anything
- Various code cleaning, unused vars and prototypes.
2009-02-11 16:54:55 +00:00
|
|
|
if(rv3d->viewlock & RV3D_BOXVIEW)
|
2009-02-03 03:54:03 +00:00
|
|
|
view3d_boxview_sync(CTX_wm_area(C), ar);
|
|
|
|
|
|
|
|
|
|
ED_region_tag_redraw(ar);
|
|
|
|
|
|
2009-07-09 02:45:48 +00:00
|
|
|
return OPERATOR_FINISHED;
|
2009-02-03 03:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VIEW3D_OT_view_pan(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name= "View Pan";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Pan the view";
|
2009-02-03 03:54:03 +00:00
|
|
|
ot->idname= "VIEW3D_OT_view_pan";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec= viewpan_exec;
|
2010-09-27 10:44:46 +00:00
|
|
|
ot->poll= ED_operator_region_view3d_active;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-02-03 03:54:03 +00:00
|
|
|
/* flags */
|
2.5
Operator goodies!
--- Macro operators
Operators now can consist of multiple operators. Such a macro operator
is identical and behaves identical to other opererators. Macros can
also be constructed of macros even! Currently only hardcoded macros are
implemented, this to solve combined operators such as 'add duplicate' or
'extrude' (both want a transform appended).
Usage is simple:
- WM_operatortype_append_macro() : add new operatortype, name, flags
- WM_operatortype_macro_define() : add existing operator to macro
(Note: macro_define will also allow properties to be set, doesnt work
right now)
On converting the macro wmOperatorType to a real operator, it makes a
list of all operators, and the standard macro callbacks (exec, invoke,
modal, poll) just will use all.
Important note; switching to a modal operator only works as last in the
chain now!
Macros implemented for duplicate, extrude and rip. Tool menu works fine
for it, also the redo hotkey F4 works properly.
--- Operator redo fix
The operators use the undo system to switch back, but this could give
errors if other actions added undo pushes (buttons, outliner). Now the
redo for operator searches back for the correct undo level.
This fixes issues with many redos.
Note for brecht: removed the ED_undo_push for buttons... it was called
on *every* button now, which is probably too much? For example, using
the 'toolbar' redo also caused this...
2009-07-29 17:56:38 +00:00
|
|
|
ot->flag= 0;
|
2009-02-03 03:54:03 +00:00
|
|
|
RNA_def_enum(ot->srna, "type", prop_view_pan_items, 0, "Pan", "Direction of View Pan");
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int viewpersportho_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-02-03 03:54:03 +00:00
|
|
|
{
|
2012-01-14 12:24:25 +00:00
|
|
|
View3D *v3d_dummy;
|
|
|
|
|
ARegion *ar;
|
|
|
|
|
RegionView3D *rv3d;
|
|
|
|
|
|
|
|
|
|
/* no NULL check is needed, poll checks */
|
|
|
|
|
ED_view3d_context_user_region(C, &v3d_dummy, &ar);
|
|
|
|
|
rv3d = ar->regiondata;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-02-03 03:54:03 +00:00
|
|
|
if(rv3d->viewlock==0) {
|
2009-10-27 02:54:25 +00:00
|
|
|
if(rv3d->persp!=RV3D_ORTHO)
|
|
|
|
|
rv3d->persp=RV3D_ORTHO;
|
|
|
|
|
else rv3d->persp=RV3D_PERSP;
|
2009-02-03 03:54:03 +00:00
|
|
|
ED_region_tag_redraw(ar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-02-03 03:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VIEW3D_OT_view_persportho(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
2009-09-20 05:05:16 +00:00
|
|
|
ot->name= "View Persp/Ortho";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Switch the current view from perspective/orthographic";
|
2009-02-03 03:54:03 +00:00
|
|
|
ot->idname= "VIEW3D_OT_view_persportho";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec= viewpersportho_exec;
|
2012-01-14 12:24:25 +00:00
|
|
|
ot->poll= ED_operator_rv3d_user_region_poll;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-02-03 03:54:03 +00:00
|
|
|
/* flags */
|
2.5
Operator goodies!
--- Macro operators
Operators now can consist of multiple operators. Such a macro operator
is identical and behaves identical to other opererators. Macros can
also be constructed of macros even! Currently only hardcoded macros are
implemented, this to solve combined operators such as 'add duplicate' or
'extrude' (both want a transform appended).
Usage is simple:
- WM_operatortype_append_macro() : add new operatortype, name, flags
- WM_operatortype_macro_define() : add existing operator to macro
(Note: macro_define will also allow properties to be set, doesnt work
right now)
On converting the macro wmOperatorType to a real operator, it makes a
list of all operators, and the standard macro callbacks (exec, invoke,
modal, poll) just will use all.
Important note; switching to a modal operator only works as last in the
chain now!
Macros implemented for duplicate, extrude and rip. Tool menu works fine
for it, also the redo hotkey F4 works properly.
--- Operator redo fix
The operators use the undo system to switch back, but this could give
errors if other actions added undo pushes (buttons, outliner). Now the
redo for operator searches back for the correct undo level.
This fixes issues with many redos.
Note for brecht: removed the ED_undo_push for buttons... it was called
on *every* button now, which is probably too much? For example, using
the 'toolbar' redo also caused this...
2009-07-29 17:56:38 +00:00
|
|
|
ot->flag= 0;
|
2009-02-03 03:54:03 +00:00
|
|
|
}
|
|
|
|
|
|
2011-04-28 08:26:49 +00:00
|
|
|
|
2010-01-19 22:44:43 +00:00
|
|
|
/* ******************** add background image operator **************** */
|
2009-02-03 03:54:03 +00:00
|
|
|
|
2010-12-08 11:42:11 +00:00
|
|
|
static BGpic *background_image_add(bContext *C)
|
2010-01-19 22:44:43 +00:00
|
|
|
{
|
|
|
|
|
View3D *v3d= CTX_wm_view3d(C);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2011-11-18 14:28:45 +00:00
|
|
|
return ED_view3D_background_image_new(v3d);
|
2010-09-01 13:41:53 +00:00
|
|
|
}
|
2010-01-19 22:44:43 +00:00
|
|
|
|
2010-12-08 11:42:11 +00:00
|
|
|
static int background_image_add_exec(bContext *C, wmOperator *UNUSED(op))
|
2010-09-01 13:41:53 +00:00
|
|
|
{
|
2010-12-08 11:42:11 +00:00
|
|
|
background_image_add(C);
|
2010-01-19 22:44:43 +00:00
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-08 11:42:11 +00:00
|
|
|
static int background_image_add_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
|
2010-01-19 22:44:43 +00:00
|
|
|
{
|
2010-09-01 13:41:53 +00:00
|
|
|
View3D *v3d= CTX_wm_view3d(C);
|
|
|
|
|
Image *ima= NULL;
|
|
|
|
|
BGpic *bgpic;
|
2012-01-11 08:51:06 +00:00
|
|
|
char name[MAX_ID_NAME-2];
|
2010-09-01 13:41:53 +00:00
|
|
|
|
|
|
|
|
/* check input variables */
|
2012-01-11 16:32:12 +00:00
|
|
|
if(RNA_struct_property_is_set(op->ptr, "filepath")) {
|
2010-09-01 13:41:53 +00:00
|
|
|
char path[FILE_MAX];
|
|
|
|
|
|
|
|
|
|
RNA_string_get(op->ptr, "filepath", path);
|
2010-10-15 12:29:02 +00:00
|
|
|
ima= BKE_add_image_file(path);
|
2010-09-01 13:41:53 +00:00
|
|
|
}
|
2012-01-11 16:32:12 +00:00
|
|
|
else if(RNA_struct_property_is_set(op->ptr, "name")) {
|
2010-09-01 13:41:53 +00:00
|
|
|
RNA_string_get(op->ptr, "name", name);
|
|
|
|
|
ima= (Image *)find_id("IM", name);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-08 11:42:11 +00:00
|
|
|
bgpic = background_image_add(C);
|
2010-09-01 13:41:53 +00:00
|
|
|
|
|
|
|
|
if (ima) {
|
|
|
|
|
bgpic->ima = ima;
|
|
|
|
|
|
|
|
|
|
if(ima->id.us==0) id_us_plus(&ima->id);
|
|
|
|
|
else id_lib_extern(&ima->id);
|
|
|
|
|
|
|
|
|
|
if (!(v3d->flag & V3D_DISPBGPICS))
|
|
|
|
|
v3d->flag |= V3D_DISPBGPICS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, v3d);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2010-01-19 22:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
2010-12-08 11:42:11 +00:00
|
|
|
void VIEW3D_OT_background_image_add(wmOperatorType *ot)
|
2010-01-19 22:44:43 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Add Background Image";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description= "Add a new background image";
|
2010-12-08 11:42:11 +00:00
|
|
|
ot->idname = "VIEW3D_OT_background_image_add";
|
2010-01-19 22:44:43 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2010-12-08 11:42:11 +00:00
|
|
|
ot->invoke = background_image_add_invoke;
|
|
|
|
|
ot->exec = background_image_add_exec;
|
2010-01-19 22:44:43 +00:00
|
|
|
ot->poll = ED_operator_view3d_active;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = 0;
|
2010-09-01 13:41:53 +00:00
|
|
|
|
|
|
|
|
/* properties */
|
2012-01-11 08:51:06 +00:00
|
|
|
RNA_def_string(ot->srna, "name", "Image", MAX_ID_NAME-2, "Name", "Image name to assign");
|
2010-09-01 13:41:53 +00:00
|
|
|
RNA_def_string(ot->srna, "filepath", "Path", FILE_MAX, "Filepath", "Path to image file");
|
2010-01-19 22:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
2010-09-01 13:41:53 +00:00
|
|
|
|
2010-01-19 22:44:43 +00:00
|
|
|
/* ***** remove image operator ******* */
|
2010-12-08 11:42:11 +00:00
|
|
|
static int background_image_remove_exec(bContext *C, wmOperator *op)
|
2010-01-19 22:44:43 +00:00
|
|
|
{
|
2011-11-18 14:28:45 +00:00
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
2010-01-19 22:44:43 +00:00
|
|
|
int index = RNA_int_get(op->ptr, "index");
|
2011-11-18 14:28:45 +00:00
|
|
|
BGpic *bgpic_rem= BLI_findlink(&v3d->bgpicbase, index);
|
2010-01-19 22:44:43 +00:00
|
|
|
|
|
|
|
|
if(bgpic_rem) {
|
2011-11-18 14:28:45 +00:00
|
|
|
ED_view3D_background_image_remove(v3d, bgpic_rem);
|
|
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, v3d);
|
2011-01-12 03:41:12 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return OPERATOR_CANCELLED;
|
2010-01-19 22:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-08 11:42:11 +00:00
|
|
|
void VIEW3D_OT_background_image_remove(wmOperatorType *ot)
|
2010-01-19 22:44:43 +00:00
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Remove Background Image";
|
|
|
|
|
ot->description= "Remove a background image from the 3D view";
|
2010-12-08 11:42:11 +00:00
|
|
|
ot->idname = "VIEW3D_OT_background_image_remove";
|
2010-01-19 22:44:43 +00:00
|
|
|
|
|
|
|
|
/* api callbacks */
|
2010-12-08 11:42:11 +00:00
|
|
|
ot->exec = background_image_remove_exec;
|
2010-01-19 22:44:43 +00:00
|
|
|
ot->poll = ED_operator_view3d_active;
|
|
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
|
ot->flag = 0;
|
|
|
|
|
|
|
|
|
|
RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Background image index to remove ", 0, INT_MAX);
|
|
|
|
|
}
|
2010-09-01 13:41:53 +00:00
|
|
|
|
2008-12-21 12:43:34 +00:00
|
|
|
/* ********************* set clipping operator ****************** */
|
|
|
|
|
|
2009-11-21 16:44:05 +00:00
|
|
|
static void calc_clipping_plane(float clip[6][4], BoundBox *clipbb)
|
|
|
|
|
{
|
|
|
|
|
int val;
|
|
|
|
|
|
|
|
|
|
for(val=0; val<4; val++) {
|
|
|
|
|
|
|
|
|
|
normal_tri_v3( clip[val],clipbb->vec[val], clipbb->vec[val==3?0:val+1], clipbb->vec[val+4]);
|
|
|
|
|
|
|
|
|
|
clip[val][3]=
|
|
|
|
|
- clip[val][0]*clipbb->vec[val][0]
|
|
|
|
|
- clip[val][1]*clipbb->vec[val][1]
|
|
|
|
|
- clip[val][2]*clipbb->vec[val][2];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void calc_local_clipping(float clip_local[][4], BoundBox *clipbb, float mat[][4])
|
|
|
|
|
{
|
|
|
|
|
BoundBox clipbb_local;
|
|
|
|
|
float imat[4][4];
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
invert_m4_m4(imat, mat);
|
|
|
|
|
|
|
|
|
|
for(i=0; i<8; i++) {
|
|
|
|
|
mul_v3_m4v3(clipbb_local.vec[i], imat, clipbb->vec[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
calc_clipping_plane(clip_local, &clipbb_local);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ED_view3d_local_clipping(RegionView3D *rv3d, float mat[][4])
|
|
|
|
|
{
|
|
|
|
|
if(rv3d->rflag & RV3D_CLIPPING)
|
|
|
|
|
calc_local_clipping(rv3d->clip_local, rv3d->clipbb, mat);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-21 12:43:34 +00:00
|
|
|
static int view3d_clipping_exec(bContext *C, wmOperator *op)
|
|
|
|
|
{
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
RegionView3D *rv3d= CTX_wm_region_view3d(C);
|
2009-10-27 19:53:34 +00:00
|
|
|
ViewContext vc;
|
|
|
|
|
bglMats mats;
|
2008-12-21 12:43:34 +00:00
|
|
|
rcti rect;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-21 12:43:34 +00:00
|
|
|
rect.xmin= RNA_int_get(op->ptr, "xmin");
|
|
|
|
|
rect.ymin= RNA_int_get(op->ptr, "ymin");
|
|
|
|
|
rect.xmax= RNA_int_get(op->ptr, "xmax");
|
|
|
|
|
rect.ymax= RNA_int_get(op->ptr, "ymax");
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
rv3d->rflag |= RV3D_CLIPPING;
|
|
|
|
|
rv3d->clipbb= MEM_callocN(sizeof(BoundBox), "clipbb");
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-21 12:43:34 +00:00
|
|
|
/* note; otherwise opengl won't work */
|
|
|
|
|
view3d_operator_needs_opengl(C);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2009-10-27 19:53:34 +00:00
|
|
|
view3d_set_viewcontext(C, &vc);
|
2010-01-10 20:31:23 +00:00
|
|
|
view3d_get_transformation(vc.ar, vc.rv3d, NULL, &mats); /* NULL because we don't want it in object space */
|
2011-05-21 08:56:37 +00:00
|
|
|
ED_view3d_calc_clipping(rv3d->clipbb, rv3d->clip, &mats, &rect);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-21 12:43:34 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int view3d_clipping_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
|
{
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
RegionView3D *rv3d= CTX_wm_region_view3d(C);
|
|
|
|
|
ARegion *ar= CTX_wm_region(C);
|
|
|
|
|
|
|
|
|
|
if(rv3d->rflag & RV3D_CLIPPING) {
|
|
|
|
|
rv3d->rflag &= ~RV3D_CLIPPING;
|
|
|
|
|
ED_region_tag_redraw(ar);
|
|
|
|
|
if(rv3d->clipbb) MEM_freeN(rv3d->clipbb);
|
|
|
|
|
rv3d->clipbb= NULL;
|
2008-12-21 12:43:34 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return WM_border_select_invoke(C, op, event);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* toggles */
|
2009-07-09 08:39:58 +00:00
|
|
|
void VIEW3D_OT_clip_border(wmOperatorType *ot)
|
2008-12-21 12:43:34 +00:00
|
|
|
{
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-21 12:43:34 +00:00
|
|
|
/* identifiers */
|
2009-02-03 03:54:03 +00:00
|
|
|
ot->name= "Clipping Border";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Set the view clipping border";
|
2009-07-09 08:39:58 +00:00
|
|
|
ot->idname= "VIEW3D_OT_clip_border";
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-21 12:43:34 +00:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->invoke= view3d_clipping_invoke;
|
|
|
|
|
ot->exec= view3d_clipping_exec;
|
|
|
|
|
ot->modal= WM_border_select_modal;
|
2011-06-06 11:04:54 +00:00
|
|
|
ot->cancel= WM_border_select_cancel;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2010-09-27 10:44:46 +00:00
|
|
|
ot->poll= ED_operator_region_view3d_active;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-31 19:40:40 +00:00
|
|
|
/* flags */
|
2.5
Operator goodies!
--- Macro operators
Operators now can consist of multiple operators. Such a macro operator
is identical and behaves identical to other opererators. Macros can
also be constructed of macros even! Currently only hardcoded macros are
implemented, this to solve combined operators such as 'add duplicate' or
'extrude' (both want a transform appended).
Usage is simple:
- WM_operatortype_append_macro() : add new operatortype, name, flags
- WM_operatortype_macro_define() : add existing operator to macro
(Note: macro_define will also allow properties to be set, doesnt work
right now)
On converting the macro wmOperatorType to a real operator, it makes a
list of all operators, and the standard macro callbacks (exec, invoke,
modal, poll) just will use all.
Important note; switching to a modal operator only works as last in the
chain now!
Macros implemented for duplicate, extrude and rip. Tool menu works fine
for it, also the redo hotkey F4 works properly.
--- Operator redo fix
The operators use the undo system to switch back, but this could give
errors if other actions added undo pushes (buttons, outliner). Now the
redo for operator searches back for the correct undo level.
This fixes issues with many redos.
Note for brecht: removed the ED_undo_push for buttons... it was called
on *every* button now, which is probably too much? For example, using
the 'toolbar' redo also caused this...
2009-07-29 17:56:38 +00:00
|
|
|
ot->flag= 0;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2008-12-21 12:43:34 +00:00
|
|
|
/* rna */
|
2009-01-16 23:53:11 +00:00
|
|
|
RNA_def_int(ot->srna, "xmin", 0, INT_MIN, INT_MAX, "X Min", "", INT_MIN, INT_MAX);
|
|
|
|
|
RNA_def_int(ot->srna, "xmax", 0, INT_MIN, INT_MAX, "X Max", "", INT_MIN, INT_MAX);
|
|
|
|
|
RNA_def_int(ot->srna, "ymin", 0, INT_MIN, INT_MAX, "Y Min", "", INT_MIN, INT_MAX);
|
|
|
|
|
RNA_def_int(ot->srna, "ymax", 0, INT_MIN, INT_MAX, "Y Max", "", INT_MIN, INT_MAX);
|
2008-12-21 12:43:34 +00:00
|
|
|
}
|
|
|
|
|
|
2008-12-26 19:07:31 +00:00
|
|
|
/* ***************** 3d cursor cursor op ******************* */
|
|
|
|
|
|
|
|
|
|
/* mx my in region coords */
|
2010-10-15 01:36:14 +00:00
|
|
|
static int set_3dcursor_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
|
2008-12-26 19:07:31 +00:00
|
|
|
{
|
|
|
|
|
Scene *scene= CTX_data_scene(C);
|
|
|
|
|
ARegion *ar= CTX_wm_region(C);
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
|
|
|
|
RegionView3D *rv3d= CTX_wm_region_view3d(C);
|
2008-12-26 19:07:31 +00:00
|
|
|
float dx, dy, fz, *fp = NULL, dvec[3], oldcurs[3];
|
2011-05-20 07:40:05 +00:00
|
|
|
int mval[2];
|
2009-01-02 19:10:35 +00:00
|
|
|
// short ctrl= 0; // XXX
|
2010-08-06 03:52:13 +00:00
|
|
|
int flip;
|
2008-12-26 19:07:31 +00:00
|
|
|
fp= give_cursor(scene, v3d);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-01-02 19:10:35 +00:00
|
|
|
// if(obedit && ctrl) lr_click= 1;
|
2010-07-26 06:34:56 +00:00
|
|
|
copy_v3_v3(oldcurs, fp);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2011-05-12 16:47:36 +00:00
|
|
|
project_int_noclip(ar, fp, mval);
|
2010-08-06 03:52:13 +00:00
|
|
|
flip= initgrabz(rv3d, fp[0], fp[1], fp[2]);
|
|
|
|
|
|
|
|
|
|
/* reset the depth based on the view offset */
|
|
|
|
|
if(flip) {
|
|
|
|
|
negate_v3_v3(fp, rv3d->ofs);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2010-08-06 03:52:13 +00:00
|
|
|
/* re initialize */
|
2011-05-12 16:47:36 +00:00
|
|
|
project_int_noclip(ar, fp, mval);
|
2010-08-06 03:52:13 +00:00
|
|
|
flip= initgrabz(rv3d, fp[0], fp[1], fp[2]);
|
2012-01-20 15:18:57 +00:00
|
|
|
(void)flip;
|
2010-08-06 03:52:13 +00:00
|
|
|
}
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2008-12-26 19:07:31 +00:00
|
|
|
if(mval[0]!=IS_CLIPPED) {
|
2010-02-04 16:30:28 +00:00
|
|
|
short depth_used = 0;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2010-02-04 16:30:28 +00:00
|
|
|
if (U.uiflag & USER_ORBIT_ZBUF) { /* maybe this should be accessed some other way */
|
|
|
|
|
view3d_operator_needs_opengl(C);
|
2011-05-20 13:09:34 +00:00
|
|
|
if (ED_view3d_autodist(scene, ar, v3d, event->mval, fp))
|
2010-02-04 16:30:28 +00:00
|
|
|
depth_used= 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(depth_used==0) {
|
2011-05-20 13:50:41 +00:00
|
|
|
float mval_f[2];
|
2011-05-20 16:43:23 +00:00
|
|
|
VECSUB2D(mval_f, mval, event->mval);
|
2011-05-20 13:50:41 +00:00
|
|
|
ED_view3d_win_to_delta(ar, mval_f, dvec);
|
2010-04-23 23:57:00 +00:00
|
|
|
sub_v3_v3(fp, dvec);
|
2010-02-04 16:30:28 +00:00
|
|
|
}
|
2008-12-26 19:07:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2011-05-20 07:40:05 +00:00
|
|
|
dx= ((float)(event->mval[0]-(ar->winx/2)))*rv3d->zfac/(ar->winx/2);
|
|
|
|
|
dy= ((float)(event->mval[1]-(ar->winy/2)))*rv3d->zfac/(ar->winy/2);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
fz= rv3d->persmat[0][3]*fp[0]+ rv3d->persmat[1][3]*fp[1]+ rv3d->persmat[2][3]*fp[2]+ rv3d->persmat[3][3];
|
|
|
|
|
fz= fz/rv3d->zfac;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
fp[0]= (rv3d->persinv[0][0]*dx + rv3d->persinv[1][0]*dy+ rv3d->persinv[2][0]*fz)-rv3d->ofs[0];
|
|
|
|
|
fp[1]= (rv3d->persinv[0][1]*dx + rv3d->persinv[1][1]*dy+ rv3d->persinv[2][1]*fz)-rv3d->ofs[1];
|
|
|
|
|
fp[2]= (rv3d->persinv[0][2]*dx + rv3d->persinv[1][2]*dy+ rv3d->persinv[2][2]*fz)-rv3d->ofs[2];
|
2008-12-26 19:07:31 +00:00
|
|
|
}
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-12-10 09:58:10 +00:00
|
|
|
if(v3d && v3d->localvd)
|
|
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, v3d);
|
|
|
|
|
else
|
|
|
|
|
WM_event_add_notifier(C, NC_SCENE|NA_EDITED, scene);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2011-10-01 13:46:20 +00:00
|
|
|
return OPERATOR_FINISHED;
|
2008-12-26 19:07:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VIEW3D_OT_cursor3d(wmOperatorType *ot)
|
|
|
|
|
{
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2008-12-26 19:07:31 +00:00
|
|
|
/* identifiers */
|
|
|
|
|
ot->name= "Set 3D Cursor";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Set the location of the 3D cursor";
|
2008-12-26 19:07:31 +00:00
|
|
|
ot->idname= "VIEW3D_OT_cursor3d";
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2008-12-26 19:07:31 +00:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->invoke= set_3dcursor_invoke;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2008-12-26 19:07:31 +00:00
|
|
|
ot->poll= ED_operator_view3d_active;
|
2011-04-21 13:11:51 +00:00
|
|
|
|
2009-11-02 16:07:49 +00:00
|
|
|
/* flags */
|
2009-12-28 18:09:16 +00:00
|
|
|
// ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
|
2011-04-21 13:11:51 +00:00
|
|
|
|
2008-12-26 19:07:31 +00:00
|
|
|
/* rna later */
|
|
|
|
|
|
|
|
|
|
}
|
2008-12-21 12:43:34 +00:00
|
|
|
|
2009-07-08 15:01:28 +00:00
|
|
|
/* ***************** manipulator op ******************* */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int manipulator_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
|
{
|
|
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
|
|
|
|
|
|
|
|
|
if(!(v3d->twflag & V3D_USE_MANIPULATOR)) return OPERATOR_PASS_THROUGH;
|
|
|
|
|
if(!(v3d->twflag & V3D_DRAW_MANIPULATOR)) return OPERATOR_PASS_THROUGH;
|
|
|
|
|
|
2009-11-12 19:42:53 +00:00
|
|
|
/* only no modifier or shift */
|
|
|
|
|
if(event->keymodifier != 0 && event->keymodifier != KM_SHIFT) return OPERATOR_PASS_THROUGH;
|
|
|
|
|
|
2009-07-08 15:01:28 +00:00
|
|
|
/* note; otherwise opengl won't work */
|
|
|
|
|
view3d_operator_needs_opengl(C);
|
2009-07-09 02:45:48 +00:00
|
|
|
|
|
|
|
|
if(0==BIF_do_manipulator(C, event, op))
|
2009-07-08 15:01:28 +00:00
|
|
|
return OPERATOR_PASS_THROUGH;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-07-08 15:01:28 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VIEW3D_OT_manipulator(wmOperatorType *ot)
|
|
|
|
|
{
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-07-08 15:01:28 +00:00
|
|
|
/* identifiers */
|
|
|
|
|
ot->name= "3D Manipulator";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Manipulate selected item by axis";
|
2009-07-08 15:01:28 +00:00
|
|
|
ot->idname= "VIEW3D_OT_manipulator";
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-07-08 15:01:28 +00:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->invoke= manipulator_invoke;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2009-07-08 15:01:28 +00:00
|
|
|
ot->poll= ED_operator_view3d_active;
|
2009-07-09 02:45:48 +00:00
|
|
|
|
2010-04-03 17:38:43 +00:00
|
|
|
/* properties to pass to transform */
|
|
|
|
|
Transform_Properties(ot, P_CONSTRAINT);
|
2009-07-08 15:01:28 +00:00
|
|
|
}
|
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int enable_manipulator_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
|
2010-01-14 05:29:25 +00:00
|
|
|
{
|
|
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
|
|
|
|
|
|
|
|
|
v3d->twtype=0;
|
|
|
|
|
|
|
|
|
|
if (RNA_boolean_get(op->ptr, "translate"))
|
|
|
|
|
v3d->twtype |= V3D_MANIP_TRANSLATE;
|
|
|
|
|
if (RNA_boolean_get(op->ptr, "rotate"))
|
|
|
|
|
v3d->twtype |= V3D_MANIP_ROTATE;
|
|
|
|
|
if (RNA_boolean_get(op->ptr, "scale"))
|
|
|
|
|
v3d->twtype |= V3D_MANIP_SCALE;
|
|
|
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, v3d);
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
2009-07-08 15:01:28 +00:00
|
|
|
|
2010-01-14 05:29:25 +00:00
|
|
|
void VIEW3D_OT_enable_manipulator(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name= "Enable 3D Manipulator";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Enable the transform manipulator for use";
|
2010-01-14 05:29:25 +00:00
|
|
|
ot->idname= "VIEW3D_OT_enable_manipulator";
|
|
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
|
ot->invoke= enable_manipulator_invoke;
|
|
|
|
|
ot->poll= ED_operator_view3d_active;
|
|
|
|
|
|
|
|
|
|
/* rna later */
|
|
|
|
|
RNA_def_boolean(ot->srna, "translate", 0, "Translate", "Enable the translate manipulator");
|
|
|
|
|
RNA_def_boolean(ot->srna, "rotate", 0, "Rotate", "Enable the rotate manipulator");
|
|
|
|
|
RNA_def_boolean(ot->srna, "scale", 0, "Scale", "Enable the scale manipulator");
|
|
|
|
|
}
|
2008-12-20 11:33:16 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* ************************* below the line! *********************** */
|
|
|
|
|
|
|
|
|
|
|
2011-05-12 16:47:36 +00:00
|
|
|
static float view_autodist_depth_margin(ARegion *ar, const int mval[2], int margin)
|
2010-01-01 17:48:48 +00:00
|
|
|
{
|
2010-10-21 07:38:09 +00:00
|
|
|
ViewDepths depth_temp= {0};
|
|
|
|
|
rcti rect;
|
|
|
|
|
float depth_close;
|
2010-01-01 17:48:48 +00:00
|
|
|
|
|
|
|
|
if(margin==0) {
|
|
|
|
|
/* Get Z Depths, needed for perspective, nice for ortho */
|
2010-10-21 07:38:09 +00:00
|
|
|
rect.xmin= mval[0];
|
|
|
|
|
rect.ymin= mval[1];
|
|
|
|
|
rect.xmax= mval[0] + 1;
|
|
|
|
|
rect.ymax= mval[1] + 1;
|
2010-01-01 17:48:48 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
rect.xmax = mval[0] + margin;
|
|
|
|
|
rect.ymax = mval[1] + margin;
|
|
|
|
|
|
|
|
|
|
rect.xmin = mval[0] - margin;
|
|
|
|
|
rect.ymin = mval[1] - margin;
|
2010-10-21 07:38:09 +00:00
|
|
|
}
|
2010-01-01 17:48:48 +00:00
|
|
|
|
2010-10-21 07:38:09 +00:00
|
|
|
view3d_update_depths_rect(ar, &depth_temp, &rect);
|
|
|
|
|
depth_close= view3d_depth_near(&depth_temp);
|
2010-10-27 08:55:13 +00:00
|
|
|
if(depth_temp.depths) MEM_freeN(depth_temp.depths);
|
|
|
|
|
return depth_close;
|
2010-01-01 17:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* XXX todo Zooms in on a border drawn by the user */
|
2012-01-19 16:04:44 +00:00
|
|
|
int ED_view3d_autodist(Scene *scene, ARegion *ar, View3D *v3d, const int mval[2], float mouse_worldloc[3])
|
2008-12-19 17:14:02 +00:00
|
|
|
{
|
2.5
View3D has been split now in a local part (RegionView3D) and a
per-area part (old View3D). Currently local is:
- view transform
- camera zoom/offset
- gpencil (todo)
- custom clipping planes
Rest is in Area still, like active camera, draw type, layers,
localview, custom centers, around-settings, transform widget,
gridlines, and so on (mostly stuff as available in header).
To see it work; also added new feature for region split,
press SHIFT+ALT+CTRL+S for four-split.
The idea is to make a preset 4-split, configured to stick
to top/right/front views for three views.
Another cool idea to explore is to then box-clip all drawing
based on these 3 views.
Note about the code:
- currently view3d still stores some depricated settings, to
convert from older files. Not all settings are copied over
though, like custom clip planes or the 'lock view to object'.
- since some view3d ops are now on area level, the operators
for it should keep track of that.
Bugfix in transform: quat initialize in operator-invoke missed
one zero.
Als brought back GE to compile for missing Ipos and channels.
2009-01-19 16:54:41 +00:00
|
|
|
bglMats mats; /* ZBuffer depth vars */
|
2010-01-01 17:48:48 +00:00
|
|
|
float depth_close= FLT_MAX;
|
2008-12-19 17:14:02 +00:00
|
|
|
double cent[2], p[3];
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
/* Get Z Depths, needed for perspective, nice for ortho */
|
|
|
|
|
bgl_get_mats(&mats);
|
|
|
|
|
draw_depth(scene, ar, v3d, NULL);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2010-01-01 17:48:48 +00:00
|
|
|
depth_close= view_autodist_depth_margin(ar, mval, 4);
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2010-01-01 17:48:48 +00:00
|
|
|
if (depth_close==FLT_MAX)
|
2008-12-19 17:14:02 +00:00
|
|
|
return 0;
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
cent[0] = (double)mval[0];
|
|
|
|
|
cent[1] = (double)mval[1];
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2012-01-19 16:04:44 +00:00
|
|
|
if (!gluUnProject(cent[0], cent[1], depth_close,
|
|
|
|
|
mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2]))
|
|
|
|
|
{
|
2008-12-19 17:14:02 +00:00
|
|
|
return 0;
|
2012-01-19 16:04:44 +00:00
|
|
|
}
|
2008-12-26 10:31:44 +00:00
|
|
|
|
2008-12-19 17:14:02 +00:00
|
|
|
mouse_worldloc[0] = (float)p[0];
|
|
|
|
|
mouse_worldloc[1] = (float)p[1];
|
|
|
|
|
mouse_worldloc[2] = (float)p[2];
|
|
|
|
|
return 1;
|
2008-12-19 12:14:58 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-20 13:09:34 +00:00
|
|
|
int ED_view3d_autodist_init(Scene *scene, ARegion *ar, View3D *v3d, int mode) //, float *autodist )
|
2009-11-30 01:13:46 +00:00
|
|
|
{
|
|
|
|
|
/* Get Z Depths, needed for perspective, nice for ortho */
|
2010-01-01 16:46:27 +00:00
|
|
|
switch(mode) {
|
|
|
|
|
case 0:
|
|
|
|
|
draw_depth(scene, ar, v3d, NULL);
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
draw_depth_gpencil(scene, ar, v3d);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-11-30 01:13:46 +00:00
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// no 4x4 sampling, run view_autodist_init first
|
2012-01-19 16:04:44 +00:00
|
|
|
int ED_view3d_autodist_simple(ARegion *ar, const int mval[2], float mouse_worldloc[3],
|
|
|
|
|
int margin, float *force_depth) //, float *autodist )
|
2009-11-30 01:13:46 +00:00
|
|
|
{
|
|
|
|
|
bglMats mats; /* ZBuffer depth vars, could cache? */
|
|
|
|
|
float depth;
|
|
|
|
|
double cent[2], p[3];
|
|
|
|
|
|
|
|
|
|
/* Get Z Depths, needed for perspective, nice for ortho */
|
2010-01-01 15:05:31 +00:00
|
|
|
if(force_depth)
|
|
|
|
|
depth= *force_depth;
|
|
|
|
|
else
|
2010-01-01 17:48:48 +00:00
|
|
|
depth= view_autodist_depth_margin(ar, mval, margin);
|
2008-12-19 12:14:58 +00:00
|
|
|
|
2010-01-01 15:05:31 +00:00
|
|
|
if (depth==FLT_MAX)
|
2009-11-30 01:13:46 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
cent[0] = (double)mval[0];
|
|
|
|
|
cent[1] = (double)mval[1];
|
|
|
|
|
|
2010-01-01 15:05:31 +00:00
|
|
|
bgl_get_mats(&mats);
|
2012-01-19 16:04:44 +00:00
|
|
|
|
|
|
|
|
if (!gluUnProject(cent[0], cent[1], depth,
|
|
|
|
|
mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2]))
|
|
|
|
|
{
|
2009-11-30 01:13:46 +00:00
|
|
|
return 0;
|
2012-01-19 16:04:44 +00:00
|
|
|
}
|
2008-12-19 12:14:58 +00:00
|
|
|
|
2009-11-30 01:13:46 +00:00
|
|
|
mouse_worldloc[0] = (float)p[0];
|
|
|
|
|
mouse_worldloc[1] = (float)p[1];
|
|
|
|
|
mouse_worldloc[2] = (float)p[2];
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2008-12-19 17:14:02 +00:00
|
|
|
|
2011-05-20 13:09:34 +00:00
|
|
|
int ED_view3d_autodist_depth(struct ARegion *ar, const int mval[2], int margin, float *depth)
|
2010-01-01 15:05:31 +00:00
|
|
|
{
|
2010-01-01 17:48:48 +00:00
|
|
|
*depth= view_autodist_depth_margin(ar, mval, margin);
|
2010-01-01 15:05:31 +00:00
|
|
|
|
|
|
|
|
return (*depth==FLT_MAX) ? 0:1;
|
2011-02-02 03:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int depth_segment_cb(int x, int y, void *userData)
|
|
|
|
|
{
|
|
|
|
|
struct { struct ARegion *ar; int margin; float depth; } *data = userData;
|
2011-05-12 16:47:36 +00:00
|
|
|
int mval[2];
|
2011-02-02 03:32:58 +00:00
|
|
|
float depth;
|
|
|
|
|
|
2011-05-12 16:47:36 +00:00
|
|
|
mval[0]= x;
|
|
|
|
|
mval[1]= y;
|
2011-02-02 03:32:58 +00:00
|
|
|
|
|
|
|
|
depth= view_autodist_depth_margin(data->ar, mval, data->margin);
|
|
|
|
|
|
|
|
|
|
if(depth != FLT_MAX) {
|
|
|
|
|
data->depth= depth;
|
2010-01-01 15:05:31 +00:00
|
|
|
return 0;
|
2011-02-02 03:32:58 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-19 16:04:44 +00:00
|
|
|
int ED_view3d_autodist_depth_seg(struct ARegion *ar, const int mval_sta[2], const int mval_end[2],
|
|
|
|
|
int margin, float *depth)
|
2011-02-02 03:32:58 +00:00
|
|
|
{
|
2011-03-03 17:59:04 +00:00
|
|
|
struct { struct ARegion *ar; int margin; float depth; } data = {NULL};
|
2011-02-02 03:32:58 +00:00
|
|
|
int p1[2];
|
|
|
|
|
int p2[2];
|
|
|
|
|
|
|
|
|
|
data.ar= ar;
|
|
|
|
|
data.margin= margin;
|
|
|
|
|
data.depth= FLT_MAX;
|
|
|
|
|
|
2011-11-07 01:38:32 +00:00
|
|
|
copy_v2_v2_int(p1, mval_sta);
|
|
|
|
|
copy_v2_v2_int(p2, mval_end);
|
2011-02-02 03:32:58 +00:00
|
|
|
|
|
|
|
|
plot_line_v2v2i(p1, p2, depth_segment_cb, &data);
|
|
|
|
|
|
|
|
|
|
*depth= data.depth;
|
|
|
|
|
|
|
|
|
|
return (*depth==FLT_MAX) ? 0:1;
|
2010-01-01 15:05:31 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-14 04:25:47 +00:00
|
|
|
/* Gets the view trasnformation from a camera
|
|
|
|
|
* currently dosnt take camzoom into account
|
|
|
|
|
*
|
|
|
|
|
* The dist is not modified for this function, if NULL its assimed zero
|
|
|
|
|
* */
|
|
|
|
|
void ED_view3d_from_m4(float mat[][4], float ofs[3], float quat[4], float *dist)
|
|
|
|
|
{
|
|
|
|
|
/* Offset */
|
|
|
|
|
if (ofs)
|
|
|
|
|
negate_v3_v3(ofs, mat[3]);
|
|
|
|
|
|
|
|
|
|
/* Quat */
|
|
|
|
|
if (quat) {
|
|
|
|
|
float imat[4][4];
|
|
|
|
|
invert_m4_m4(imat, mat);
|
|
|
|
|
mat4_to_quat(quat, imat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dist) {
|
|
|
|
|
float nmat[3][3];
|
|
|
|
|
float vec[3];
|
|
|
|
|
|
|
|
|
|
vec[0]= 0.0f;
|
|
|
|
|
vec[1]= 0.0f;
|
|
|
|
|
vec[2]= -(*dist);
|
|
|
|
|
|
|
|
|
|
copy_m3_m4(nmat, mat);
|
|
|
|
|
normalize_m3(nmat);
|
|
|
|
|
|
2011-08-31 01:07:55 +00:00
|
|
|
mul_m3_v3(nmat, vec);
|
2011-05-14 04:25:47 +00:00
|
|
|
sub_v3_v3(ofs, vec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-23 02:23:03 +00:00
|
|
|
void ED_view3d_to_m4(float mat[][4], const float ofs[3], const float quat[4], const float dist)
|
|
|
|
|
{
|
|
|
|
|
float iviewquat[4]= {-quat[0], quat[1], quat[2], quat[3]};
|
|
|
|
|
float dvec[3]= {0.0f, 0.0f, dist};
|
|
|
|
|
|
|
|
|
|
quat_to_mat4(mat, iviewquat);
|
|
|
|
|
mul_mat3_m4_v3(mat, dvec);
|
|
|
|
|
sub_v3_v3v3(mat[3], dvec, ofs);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-14 04:25:47 +00:00
|
|
|
|
|
|
|
|
/* object -> view */
|
|
|
|
|
void ED_view3d_from_object(Object *ob, float ofs[3], float quat[4], float *dist, float *lens)
|
|
|
|
|
{
|
|
|
|
|
ED_view3d_from_m4(ob->obmat, ofs, quat, dist);
|
|
|
|
|
|
2011-11-18 23:32:17 +00:00
|
|
|
if(lens) {
|
|
|
|
|
CameraParams params;
|
|
|
|
|
|
|
|
|
|
camera_params_init(¶ms);
|
|
|
|
|
camera_params_from_object(¶ms, ob);
|
|
|
|
|
*lens= params.lens;
|
2011-05-14 04:25:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* view -> object */
|
|
|
|
|
void ED_view3d_to_object(Object *ob, const float ofs[3], const float quat[4], const float dist)
|
|
|
|
|
{
|
2011-05-23 02:23:03 +00:00
|
|
|
float mat[4][4];
|
|
|
|
|
ED_view3d_to_m4(mat, ofs, quat, dist);
|
|
|
|
|
object_apply_mat4(ob, mat, TRUE, TRUE);
|
2011-05-14 04:25:47 +00:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2011-11-18 14:28:45 +00:00
|
|
|
BGpic *ED_view3D_background_image_new(View3D *v3d)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
|
|
|
|
BGpic *bgpic= MEM_callocN(sizeof(BGpic), "Background Image");
|
|
|
|
|
|
|
|
|
|
bgpic->size= 5.0;
|
|
|
|
|
bgpic->blend= 0.5;
|
|
|
|
|
bgpic->iuser.fie_ima= 2;
|
|
|
|
|
bgpic->iuser.ok= 1;
|
|
|
|
|
bgpic->view= 0; /* 0 for all */
|
2011-11-18 15:29:40 +00:00
|
|
|
bgpic->flag |= V3D_BGPIC_EXPANDED;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
BLI_addtail(&v3d->bgpicbase, bgpic);
|
|
|
|
|
|
|
|
|
|
return bgpic;
|
|
|
|
|
}
|
2011-11-18 14:28:45 +00:00
|
|
|
|
2011-11-23 16:12:11 +00:00
|
|
|
void ED_view3D_background_image_remove(View3D *v3d, BGpic *bgpic)
|
2011-11-18 14:28:45 +00:00
|
|
|
{
|
|
|
|
|
BLI_remlink(&v3d->bgpicbase, bgpic);
|
|
|
|
|
|
|
|
|
|
if(bgpic->ima)
|
|
|
|
|
id_us_min(&bgpic->ima->id);
|
|
|
|
|
|
|
|
|
|
if(bgpic->clip)
|
|
|
|
|
id_us_min(&bgpic->clip->id);
|
|
|
|
|
|
|
|
|
|
MEM_freeN(bgpic);
|
|
|
|
|
}
|
2011-11-23 16:12:11 +00:00
|
|
|
|
|
|
|
|
void ED_view3D_background_image_clear(View3D *v3d)
|
|
|
|
|
{
|
|
|
|
|
BGpic *bgpic= v3d->bgpicbase.first;
|
|
|
|
|
|
|
|
|
|
while(bgpic) {
|
|
|
|
|
BGpic *next_bgpic= bgpic->next;
|
|
|
|
|
|
|
|
|
|
ED_view3D_background_image_remove(v3d, bgpic);
|
|
|
|
|
|
|
|
|
|
bgpic= next_bgpic;
|
|
|
|
|
}
|
|
|
|
|
}
|