Object Mode: Add to EvaluationContext & DRWContextState
[blender.git] / source / blender / editors / space_view3d / view3d_view.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2008 Blender Foundation.
19  * All rights reserved.
20  *
21  * 
22  * Contributor(s): Blender Foundation
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/space_view3d/view3d_view.c
28  *  \ingroup spview3d
29  */
30
31 #include "DNA_camera_types.h"
32 #include "DNA_scene_types.h"
33 #include "DNA_object_types.h"
34
35 #include "MEM_guardedalloc.h"
36
37 #include "BLI_math.h"
38 #include "BLI_rect.h"
39 #include "BLI_utildefines.h"
40
41 #include "BKE_action.h"
42 #include "BKE_camera.h"
43 #include "BKE_context.h"
44 #include "BKE_object.h"
45 #include "BKE_global.h"
46 #include "BKE_main.h"
47 #include "BKE_report.h"
48 #include "BKE_scene.h"
49
50 #include "DEG_depsgraph.h"
51
52 #include "UI_resources.h"
53
54 #include "GPU_glew.h"
55 #include "GPU_select.h"
56 #include "GPU_matrix.h"
57
58 #include "WM_api.h"
59 #include "WM_types.h"
60
61 #include "ED_screen.h"
62
63 #include "DRW_engine.h"
64
65 #include "DEG_depsgraph_query.h"
66
67 #ifdef WITH_GAMEENGINE
68 #  include "BLI_listbase.h"
69 #  include "BLI_callbacks.h"
70
71 #  include "GPU_draw.h"
72
73 #  include "BL_System.h"
74 #endif
75
76 #include "view3d_intern.h"  /* own include */
77
78 /* -------------------------------------------------------------------- */
79 /** \name Smooth View Operator & Utilities
80  *
81  * Use for view transitions to have smooth (animated) transitions.
82  * \{ */
83
84 /* This operator is one of the 'timer refresh' ones like animation playback */
85
86 struct SmoothView3DState {
87         float dist;
88         float lens;
89         float quat[4];
90         float ofs[3];
91 };
92
93 struct SmoothView3DStore {
94         /* source*/
95         struct SmoothView3DState src;  /* source */
96         struct SmoothView3DState dst;  /* destination */
97         struct SmoothView3DState org;  /* original */
98
99         bool to_camera;
100
101         bool use_dyn_ofs;
102         float dyn_ofs[3];
103
104         /* When smooth-view is enabled, store the 'rv3d->view' here,
105          * assign back when the view motion is completed. */
106         char org_view;
107
108         double time_allowed;
109 };
110
111 static void view3d_smooth_view_state_backup(struct SmoothView3DState *sms_state,
112                                             const View3D *v3d, const RegionView3D *rv3d)
113 {
114         copy_v3_v3(sms_state->ofs,   rv3d->ofs);
115         copy_qt_qt(sms_state->quat,  rv3d->viewquat);
116         sms_state->dist            = rv3d->dist;
117         sms_state->lens            = v3d->lens;
118 }
119
120 static void view3d_smooth_view_state_restore(const struct SmoothView3DState *sms_state,
121                                              View3D *v3d, RegionView3D *rv3d)
122 {
123         copy_v3_v3(rv3d->ofs,      sms_state->ofs);
124         copy_qt_qt(rv3d->viewquat, sms_state->quat);
125         rv3d->dist               = sms_state->dist;
126         v3d->lens                = sms_state->lens;
127 }
128
129 /* will start timer if appropriate */
130 /* the arguments are the desired situation */
131 void ED_view3d_smooth_view_ex(
132         /* avoid passing in the context */
133         wmWindowManager *wm, wmWindow *win, ScrArea *sa,
134         View3D *v3d, ARegion *ar, const int smooth_viewtx,
135         const V3D_SmoothParams *sview)
136 {
137         RegionView3D *rv3d = ar->regiondata;
138         struct SmoothView3DStore sms = {{0}};
139         bool ok = false;
140         
141         /* initialize sms */
142         view3d_smooth_view_state_backup(&sms.dst, v3d, rv3d);
143         view3d_smooth_view_state_backup(&sms.src, v3d, rv3d);
144         /* if smoothview runs multiple times... */
145         if (rv3d->sms == NULL) {
146                 view3d_smooth_view_state_backup(&sms.org, v3d, rv3d);
147         }
148         else {
149                 sms.org = rv3d->sms->org;
150         }
151         sms.org_view = rv3d->view;
152
153         /* sms.to_camera = false; */  /* initizlized to zero anyway */
154
155         /* note on camera locking, this is a little confusing but works ok.
156          * we may be changing the view 'as if' there is no active camera, but in fact
157          * there is an active camera which is locked to the view.
158          *
159          * In the case where smooth view is moving _to_ a camera we don't want that
160          * camera to be moved or changed, so only when the camera is not being set should
161          * we allow camera option locking to initialize the view settings from the camera.
162          */
163         if (sview->camera == NULL && sview->camera_old == NULL) {
164                 ED_view3d_camera_lock_init(v3d, rv3d);
165         }
166
167         /* store the options we want to end with */
168         if (sview->ofs)
169                 copy_v3_v3(sms.dst.ofs, sview->ofs);
170         if (sview->quat)
171                 copy_qt_qt(sms.dst.quat, sview->quat);
172         if (sview->dist)
173                 sms.dst.dist = *sview->dist;
174         if (sview->lens)
175                 sms.dst.lens = *sview->lens;
176
177         if (sview->dyn_ofs) {
178                 BLI_assert(sview->ofs  == NULL);
179                 BLI_assert(sview->quat != NULL);
180
181                 copy_v3_v3(sms.dyn_ofs, sview->dyn_ofs);
182                 sms.use_dyn_ofs = true;
183
184                 /* calculate the final destination offset */
185                 view3d_orbit_apply_dyn_ofs(sms.dst.ofs, sms.src.ofs, sms.src.quat, sms.dst.quat, sms.dyn_ofs);
186         }
187
188         if (sview->camera) {
189                 sms.dst.dist = ED_view3d_offset_distance(sview->camera->obmat, sview->ofs, VIEW3D_DIST_FALLBACK);
190                 ED_view3d_from_object(sview->camera, sms.dst.ofs, sms.dst.quat, &sms.dst.dist, &sms.dst.lens);
191                 sms.to_camera = true; /* restore view3d values in end */
192         }
193         
194         /* skip smooth viewing for render engine draw */
195         if (smooth_viewtx && v3d->drawtype != OB_RENDER) {
196                 bool changed = false; /* zero means no difference */
197                 
198                 if (sview->camera_old != sview->camera)
199                         changed = true;
200                 else if (sms.dst.dist != rv3d->dist)
201                         changed = true;
202                 else if (sms.dst.lens != v3d->lens)
203                         changed = true;
204                 else if (!equals_v3v3(sms.dst.ofs, rv3d->ofs))
205                         changed = true;
206                 else if (!equals_v4v4(sms.dst.quat, rv3d->viewquat))
207                         changed = true;
208                 
209                 /* The new view is different from the old one
210                  * so animate the view */
211                 if (changed) {
212                         /* original values */
213                         if (sview->camera_old) {
214                                 sms.src.dist = ED_view3d_offset_distance(sview->camera_old->obmat, rv3d->ofs, 0.0f);
215                                 /* this */
216                                 ED_view3d_from_object(sview->camera_old, sms.src.ofs, sms.src.quat, &sms.src.dist, &sms.src.lens);
217                         }
218                         /* grid draw as floor */
219                         if ((rv3d->viewlock & RV3D_LOCKED) == 0) {
220                                 /* use existing if exists, means multiple calls to smooth view wont loose the original 'view' setting */
221                                 rv3d->view = RV3D_VIEW_USER;
222                         }
223
224                         sms.time_allowed = (double)smooth_viewtx / 1000.0;
225                         
226                         /* if this is view rotation only
227                          * we can decrease the time allowed by
228                          * the angle between quats 
229                          * this means small rotations wont lag */
230                         if (sview->quat && !sview->ofs && !sview->dist) {
231                                 /* scale the time allowed by the rotation */
232                                 sms.time_allowed *= (double)fabsf(angle_signed_normalized_qtqt(sms.dst.quat, sms.src.quat)) / M_PI; /* 180deg == 1.0 */
233                         }
234
235                         /* ensure it shows correct */
236                         if (sms.to_camera) {
237                                 /* use ortho if we move from an ortho view to an ortho camera */
238                                 rv3d->persp = (((rv3d->is_persp == false) &&
239                                                 (sview->camera->type == OB_CAMERA) &&
240                                                 (((Camera *)sview->camera->data)->type == CAM_ORTHO)) ?
241                                                 RV3D_ORTHO : RV3D_PERSP);
242                         }
243
244                         rv3d->rflag |= RV3D_NAVIGATING;
245                         
246                         /* not essential but in some cases the caller will tag the area for redraw,
247                          * and in that case we can get a flicker of the 'org' user view but we want to see 'src' */
248                         view3d_smooth_view_state_restore(&sms.src, v3d, rv3d);
249
250                         /* keep track of running timer! */
251                         if (rv3d->sms == NULL) {
252                                 rv3d->sms = MEM_mallocN(sizeof(struct SmoothView3DStore), "smoothview v3d");
253                         }
254                         *rv3d->sms = sms;
255                         if (rv3d->smooth_timer) {
256                                 WM_event_remove_timer(wm, win, rv3d->smooth_timer);
257                         }
258                         /* TIMER1 is hardcoded in keymap */
259                         rv3d->smooth_timer = WM_event_add_timer(wm, win, TIMER1, 1.0 / 100.0); /* max 30 frs/sec */
260
261                         ok = true;
262                 }
263         }
264         
265         /* if we get here nothing happens */
266         if (ok == false) {
267                 if (sms.to_camera == false) {
268                         copy_v3_v3(rv3d->ofs, sms.dst.ofs);
269                         copy_qt_qt(rv3d->viewquat, sms.dst.quat);
270                         rv3d->dist = sms.dst.dist;
271                         v3d->lens = sms.dst.lens;
272
273                         ED_view3d_camera_lock_sync(v3d, rv3d);
274                 }
275
276                 if (rv3d->viewlock & RV3D_BOXVIEW) {
277                         view3d_boxview_copy(sa, ar);
278                 }
279
280                 ED_region_tag_redraw(ar);
281         }
282 }
283
284 void ED_view3d_smooth_view(
285         bContext *C,
286         View3D *v3d, ARegion *ar, const int smooth_viewtx,
287         const struct V3D_SmoothParams *sview)
288 {
289         wmWindowManager *wm = CTX_wm_manager(C);
290         wmWindow *win = CTX_wm_window(C);
291         ScrArea *sa = CTX_wm_area(C);
292
293         ED_view3d_smooth_view_ex(
294                 wm, win, sa,
295                 v3d, ar, smooth_viewtx,
296                 sview);
297 }
298
299 /* only meant for timer usage */
300 static void view3d_smoothview_apply(bContext *C, View3D *v3d, ARegion *ar, bool sync_boxview)
301 {
302         RegionView3D *rv3d = ar->regiondata;
303         struct SmoothView3DStore *sms = rv3d->sms;
304         float step, step_inv;
305         
306         if (sms->time_allowed != 0.0)
307                 step = (float)((rv3d->smooth_timer->duration) / sms->time_allowed);
308         else
309                 step = 1.0f;
310         
311         /* end timer */
312         if (step >= 1.0f) {
313                 
314                 /* if we went to camera, store the original */
315                 if (sms->to_camera) {
316                         rv3d->persp = RV3D_CAMOB;
317                         view3d_smooth_view_state_restore(&sms->org, v3d, rv3d);
318                 }
319                 else {
320                         view3d_smooth_view_state_restore(&sms->dst, v3d, rv3d);
321
322                         ED_view3d_camera_lock_sync(v3d, rv3d);
323                         ED_view3d_camera_lock_autokey(v3d, rv3d, C, true, true);
324                 }
325                 
326                 if ((rv3d->viewlock & RV3D_LOCKED) == 0) {
327                         rv3d->view = sms->org_view;
328                 }
329
330                 MEM_freeN(rv3d->sms);
331                 rv3d->sms = NULL;
332                 
333                 WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), rv3d->smooth_timer);
334                 rv3d->smooth_timer = NULL;
335                 rv3d->rflag &= ~RV3D_NAVIGATING;
336         }
337         else {
338                 /* ease in/out */
339                 step = (3.0f * step * step - 2.0f * step * step * step);
340
341                 step_inv = 1.0f - step;
342
343                 interp_qt_qtqt(rv3d->viewquat, sms->src.quat, sms->dst.quat, step);
344
345                 if (sms->use_dyn_ofs) {
346                         view3d_orbit_apply_dyn_ofs(rv3d->ofs, sms->src.ofs, sms->src.quat, rv3d->viewquat, sms->dyn_ofs);
347                 }
348                 else {
349                         interp_v3_v3v3(rv3d->ofs, sms->src.ofs,  sms->dst.ofs,  step);
350                 }
351                 
352                 rv3d->dist = sms->dst.dist * step + sms->src.dist * step_inv;
353                 v3d->lens  = sms->dst.lens * step + sms->src.lens * step_inv;
354
355                 ED_view3d_camera_lock_sync(v3d, rv3d);
356                 if (ED_screen_animation_playing(CTX_wm_manager(C))) {
357                         ED_view3d_camera_lock_autokey(v3d, rv3d, C, true, true);
358                 }
359
360                 /* Event handling won't know if a UI item has been moved under the pointer. */
361                 WM_event_add_mousemove(C);
362         }
363         
364         if (sync_boxview && (rv3d->viewlock & RV3D_BOXVIEW)) {
365                 view3d_boxview_copy(CTX_wm_area(C), ar);
366         }
367
368         /* note: this doesn't work right because the v3d->lens is now used in ortho mode r51636,
369          * when switching camera in quad-view the other ortho views would zoom & reset.
370          *
371          * For now only redraw all regions when smoothview finishes.
372          */
373         if (step >= 1.0f) {
374                 WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
375         }
376         else {
377                 ED_region_tag_redraw(ar);
378         }
379 }
380
381 static int view3d_smoothview_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
382 {
383         View3D *v3d = CTX_wm_view3d(C);
384         ARegion *ar = CTX_wm_region(C);
385         RegionView3D *rv3d = ar->regiondata;
386
387         /* escape if not our timer */
388         if (rv3d->smooth_timer == NULL || rv3d->smooth_timer != event->customdata) {
389                 return OPERATOR_PASS_THROUGH;
390         }
391
392         view3d_smoothview_apply(C, v3d, ar, true);
393
394         return OPERATOR_FINISHED;
395 }
396
397 /**
398  * Apply the smoothview immediately, use when we need to start a new view operation.
399  * (so we don't end up half-applying a view operation when pressing keys quickly).
400  */
401 void ED_view3d_smooth_view_force_finish(
402         bContext *C,
403         View3D *v3d, ARegion *ar)
404 {
405         RegionView3D *rv3d = ar->regiondata;
406         EvaluationContext eval_ctx;
407
408         CTX_data_eval_ctx(C, &eval_ctx);
409
410         if (rv3d && rv3d->sms) {
411                 rv3d->sms->time_allowed = 0.0;  /* force finishing */
412                 view3d_smoothview_apply(C, v3d, ar, false);
413
414                 /* force update of view matrix so tools that run immediately after
415                  * can use them without redrawing first */
416                 Scene *scene = CTX_data_scene(C);
417                 ED_view3d_update_viewmat(&eval_ctx, scene, v3d, ar, NULL, NULL, NULL);
418         }
419 }
420
421 void VIEW3D_OT_smoothview(wmOperatorType *ot)
422 {
423         /* identifiers */
424         ot->name = "Smooth View";
425         ot->description = "";
426         ot->idname = "VIEW3D_OT_smoothview";
427
428         /* api callbacks */
429         ot->invoke = view3d_smoothview_invoke;
430
431         /* flags */
432         ot->flag = OPTYPE_INTERNAL;
433
434         ot->poll = ED_operator_view3d_active;
435 }
436
437 /** \} */
438
439 /* -------------------------------------------------------------------- */
440 /** \name Camera to View Operator
441  * \{ */
442
443 static int view3d_camera_to_view_exec(bContext *C, wmOperator *UNUSED(op))
444 {
445         View3D *v3d;
446         ARegion *ar;
447         RegionView3D *rv3d;
448
449         ObjectTfmProtectedChannels obtfm;
450
451         ED_view3d_context_user_region(C, &v3d, &ar);
452         rv3d = ar->regiondata;
453
454         ED_view3d_lastview_store(rv3d);
455
456         BKE_object_tfm_protected_backup(v3d->camera, &obtfm);
457
458         ED_view3d_to_object(v3d->camera, rv3d->ofs, rv3d->viewquat, rv3d->dist);
459
460         BKE_object_tfm_protected_restore(v3d->camera, &obtfm, v3d->camera->protectflag);
461
462         DEG_id_tag_update(&v3d->camera->id, OB_RECALC_OB);
463         rv3d->persp = RV3D_CAMOB;
464         
465         WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, v3d->camera);
466         
467         return OPERATOR_FINISHED;
468
469 }
470
471 static int view3d_camera_to_view_poll(bContext *C)
472 {
473         View3D *v3d;
474         ARegion *ar;
475
476         if (ED_view3d_context_user_region(C, &v3d, &ar)) {
477                 RegionView3D *rv3d = ar->regiondata;
478                 if (v3d && v3d->camera && !ID_IS_LINKED(v3d->camera)) {
479                         if (rv3d && (rv3d->viewlock & RV3D_LOCKED) == 0) {
480                                 if (rv3d->persp != RV3D_CAMOB) {
481                                         return 1;
482                                 }
483                         }
484                 }
485         }
486
487         return 0;
488 }
489
490 void VIEW3D_OT_camera_to_view(wmOperatorType *ot)
491 {
492         /* identifiers */
493         ot->name = "Align Camera To View";
494         ot->description = "Set camera view to active view";
495         ot->idname = "VIEW3D_OT_camera_to_view";
496         
497         /* api callbacks */
498         ot->exec = view3d_camera_to_view_exec;
499         ot->poll = view3d_camera_to_view_poll;
500         
501         /* flags */
502         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
503 }
504
505 /** \} */
506
507 /* -------------------------------------------------------------------- */
508 /** \name Camera Fit Frame to Selected Operator
509  * \{ */
510
511 /* unlike VIEW3D_OT_view_selected this is for framing a render and not
512  * meant to take into account vertex/bone selection for eg. */
513 static int view3d_camera_to_view_selected_exec(bContext *C, wmOperator *op)
514 {
515         Scene *scene = CTX_data_scene(C);
516         ViewLayer *view_layer = CTX_data_view_layer(C);
517         View3D *v3d = CTX_wm_view3d(C);  /* can be NULL */
518         Object *camera_ob = v3d ? v3d->camera : scene->camera;
519
520         float r_co[3]; /* the new location to apply */
521         float r_scale; /* only for ortho cameras */
522
523         if (camera_ob == NULL) {
524                 BKE_report(op->reports, RPT_ERROR, "No active camera");
525                 return OPERATOR_CANCELLED;
526         }
527
528         /* this function does all the important stuff */
529         if (BKE_camera_view_frame_fit_to_scene(scene, view_layer, camera_ob, r_co, &r_scale)) {
530                 ObjectTfmProtectedChannels obtfm;
531                 float obmat_new[4][4];
532
533                 if ((camera_ob->type == OB_CAMERA) && (((Camera *)camera_ob->data)->type == CAM_ORTHO)) {
534                         ((Camera *)camera_ob->data)->ortho_scale = r_scale;
535                 }
536
537                 copy_m4_m4(obmat_new, camera_ob->obmat);
538                 copy_v3_v3(obmat_new[3], r_co);
539
540                 /* only touch location */
541                 BKE_object_tfm_protected_backup(camera_ob, &obtfm);
542                 BKE_object_apply_mat4(camera_ob, obmat_new, true, true);
543                 BKE_object_tfm_protected_restore(camera_ob, &obtfm, OB_LOCK_SCALE | OB_LOCK_ROT4D);
544
545                 /* notifiers */
546                 DEG_id_tag_update(&camera_ob->id, OB_RECALC_OB);
547                 WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, camera_ob);
548                 return OPERATOR_FINISHED;
549         }
550         else {
551                 return OPERATOR_CANCELLED;
552         }
553 }
554
555 void VIEW3D_OT_camera_to_view_selected(wmOperatorType *ot)
556 {
557         /* identifiers */
558         ot->name = "Camera Fit Frame to Selected";
559         ot->description = "Move the camera so selected objects are framed";
560         ot->idname = "VIEW3D_OT_camera_to_view_selected";
561
562         /* api callbacks */
563         ot->exec = view3d_camera_to_view_selected_exec;
564         ot->poll = ED_operator_scene_editable;
565
566         /* flags */
567         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
568 }
569
570 /** \} */
571
572 /* -------------------------------------------------------------------- */
573 /** \name Object as Camera Operator
574  * \{ */
575
576 static void sync_viewport_camera_smoothview(bContext *C, View3D *v3d, Object *ob, const int smooth_viewtx)
577 {
578         Main *bmain = CTX_data_main(C);
579         for (bScreen *screen = bmain->screen.first; screen != NULL; screen = screen->id.next) {
580                 for (ScrArea *area = screen->areabase.first; area != NULL; area = area->next) {
581                         for (SpaceLink *space_link = area->spacedata.first; space_link != NULL; space_link = space_link->next) {
582                                 if (space_link->spacetype == SPACE_VIEW3D) {
583                                         View3D *other_v3d = (View3D *)space_link;
584                                         if (other_v3d == v3d) {
585                                                 continue;
586                                         }
587                                         if (other_v3d->camera == ob) {
588                                                 continue;
589                                         }
590                                         if (v3d->scenelock) {
591                                                 ListBase *lb = (space_link == area->spacedata.first)
592                                                                    ? &area->regionbase
593                                                                    : &space_link->regionbase;
594                                                 for (ARegion *other_ar = lb->first; other_ar != NULL; other_ar = other_ar->next) {
595                                                         if (other_ar->regiontype == RGN_TYPE_WINDOW) {
596                                                                 if (other_ar->regiondata) {
597                                                                         RegionView3D *other_rv3d = other_ar->regiondata;
598                                                                         if (other_rv3d->persp == RV3D_CAMOB) {
599                                                                                 Object *other_camera_old = other_v3d->camera;
600                                                                                 other_v3d->camera = ob;
601                                                                                 ED_view3d_lastview_store(other_rv3d);
602                                                                                 ED_view3d_smooth_view(
603                                                                                         C, other_v3d, other_ar, smooth_viewtx,
604                                                                                         &(const V3D_SmoothParams) {
605                                                                                             .camera_old = other_camera_old,
606                                                                                             .camera = other_v3d->camera,
607                                                                                             .ofs = other_rv3d->ofs,
608                                                                                             .quat = other_rv3d->viewquat,
609                                                                                             .dist = &other_rv3d->dist,
610                                                                                             .lens = &other_v3d->lens});
611                                                                         }
612                                                                         else {
613                                                                                 other_v3d->camera = ob;
614                                                                         }
615                                                                 }
616                                                         }
617                                                 }
618                                         }
619                                 }
620                         }
621                 }
622         }
623 }
624
625 static int view3d_setobjectascamera_exec(bContext *C, wmOperator *op)
626 {
627         View3D *v3d;
628         ARegion *ar;
629         RegionView3D *rv3d;
630
631         Scene *scene = CTX_data_scene(C);
632         Object *ob = CTX_data_active_object(C);
633
634         const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
635
636         /* no NULL check is needed, poll checks */
637         ED_view3d_context_user_region(C, &v3d, &ar);
638         rv3d = ar->regiondata;
639
640         if (ob) {
641                 Object *camera_old = (rv3d->persp == RV3D_CAMOB) ? V3D_CAMERA_SCENE(scene, v3d) : NULL;
642                 rv3d->persp = RV3D_CAMOB;
643                 v3d->camera = ob;
644                 if (v3d->scenelock)
645                         scene->camera = ob;
646
647                 /* unlikely but looks like a glitch when set to the same */
648                 if (camera_old != ob) {
649                         ED_view3d_lastview_store(rv3d);
650
651                         ED_view3d_smooth_view(
652                                 C, v3d, ar, smooth_viewtx,
653                                 &(const V3D_SmoothParams) {
654                                     .camera_old = camera_old, .camera = v3d->camera,
655                                     .ofs = rv3d->ofs, .quat = rv3d->viewquat,
656                                     .dist = &rv3d->dist, .lens = &v3d->lens});
657                 }
658
659                 if (v3d->scenelock) {
660                         sync_viewport_camera_smoothview(C, v3d, ob, smooth_viewtx);
661                         WM_event_add_notifier(C, NC_SCENE, scene);
662                 }
663                 WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, scene);
664         }
665         
666         return OPERATOR_FINISHED;
667 }
668
669 int ED_operator_rv3d_user_region_poll(bContext *C)
670 {
671         View3D *v3d_dummy;
672         ARegion *ar_dummy;
673
674         return ED_view3d_context_user_region(C, &v3d_dummy, &ar_dummy);
675 }
676
677 void VIEW3D_OT_object_as_camera(wmOperatorType *ot)
678 {
679         /* identifiers */
680         ot->name = "Set Active Object as Camera";
681         ot->description = "Set the active object as the active camera for this view or scene";
682         ot->idname = "VIEW3D_OT_object_as_camera";
683         
684         /* api callbacks */
685         ot->exec = view3d_setobjectascamera_exec;
686         ot->poll = ED_operator_rv3d_user_region_poll;
687         
688         /* flags */
689         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
690 }
691
692 /** \} */
693
694 /* -------------------------------------------------------------------- */
695 /** \name Window and View Matrix Calculation
696  * \{ */
697
698 /**
699  * \param rect optional for picking (can be NULL).
700  */
701 void view3d_winmatrix_set(const Depsgraph *depsgraph, ARegion *ar, const View3D *v3d, const rcti *rect)
702 {
703         RegionView3D *rv3d = ar->regiondata;
704         rctf viewplane;
705         float clipsta, clipend;
706         bool is_ortho;
707         
708         is_ortho = ED_view3d_viewplane_get(depsgraph, v3d, rv3d, ar->winx, ar->winy, &viewplane, &clipsta, &clipend, NULL);
709         rv3d->is_persp = !is_ortho;
710
711 #if 0
712         printf("%s: %d %d %f %f %f %f %f %f\n", __func__, winx, winy,
713                viewplane.xmin, viewplane.ymin, viewplane.xmax, viewplane.ymax,
714                clipsta, clipend);
715 #endif
716
717         if (rect) {  /* picking */
718                 rctf r;
719                 r.xmin = viewplane.xmin + (BLI_rctf_size_x(&viewplane) * (rect->xmin / (float)ar->winx));
720                 r.ymin = viewplane.ymin + (BLI_rctf_size_y(&viewplane) * (rect->ymin / (float)ar->winy));
721                 r.xmax = viewplane.xmin + (BLI_rctf_size_x(&viewplane) * (rect->xmax / (float)ar->winx));
722                 r.ymax = viewplane.ymin + (BLI_rctf_size_y(&viewplane) * (rect->ymax / (float)ar->winy));
723                 viewplane = r;
724         }
725
726         if (is_ortho) {
727                 gpuOrtho(viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
728         }
729         else {
730                 gpuFrustum(viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
731         }
732
733         /* update matrix in 3d view region */
734         gpuGetProjectionMatrix(rv3d->winmat);
735 }
736
737 static void obmat_to_viewmat(RegionView3D *rv3d, Object *ob)
738 {
739         float bmat[4][4];
740
741         rv3d->view = RV3D_VIEW_USER; /* don't show the grid */
742
743         normalize_m4_m4(bmat, ob->obmat);
744         invert_m4_m4(rv3d->viewmat, bmat);
745
746         /* view quat calculation, needed for add object */
747         mat4_normalized_to_quat(rv3d->viewquat, rv3d->viewmat);
748 }
749
750 /**
751  * Sets #RegionView3D.viewmat
752  *
753  * \param eval_ctx: Context.
754  * \param scene: Scene for camera and cursor location.
755  * \param v3d: View 3D space data.
756  * \param rv3d: 3D region which stores the final matrices.
757  * \param rect_scale: Optional 2D scale argument,
758  * Use when displaying a sub-region, eg: when #view3d_winmatrix_set takes a 'rect' argument.
759  *
760  * \note don't set windows active in here, is used by renderwin too.
761  */
762 void view3d_viewmatrix_set(
763         const EvaluationContext *eval_ctx, Scene *scene,
764         const View3D *v3d, RegionView3D *rv3d, const float rect_scale[2])
765 {
766         if (rv3d->persp == RV3D_CAMOB) {      /* obs/camera */
767                 if (v3d->camera) {
768                         const Depsgraph *depsgraph = eval_ctx->depsgraph;
769                         Object *camera_object = DEG_get_evaluated_object(depsgraph, v3d->camera);
770                         BKE_object_where_is_calc(eval_ctx, scene, camera_object);
771                         obmat_to_viewmat(rv3d, camera_object);
772                 }
773                 else {
774                         quat_to_mat4(rv3d->viewmat, rv3d->viewquat);
775                         rv3d->viewmat[3][2] -= rv3d->dist;
776                 }
777         }
778         else {
779                 bool use_lock_ofs = false;
780
781
782                 /* should be moved to better initialize later on XXX */
783                 if (rv3d->viewlock & RV3D_LOCKED)
784                         ED_view3d_lock(rv3d);
785                 
786                 quat_to_mat4(rv3d->viewmat, rv3d->viewquat);
787                 if (rv3d->persp == RV3D_PERSP) rv3d->viewmat[3][2] -= rv3d->dist;
788                 if (v3d->ob_centre) {
789                         Object *ob = v3d->ob_centre;
790                         float vec[3];
791                         
792                         copy_v3_v3(vec, ob->obmat[3]);
793                         if (ob->type == OB_ARMATURE && v3d->ob_centre_bone[0]) {
794                                 bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, v3d->ob_centre_bone);
795                                 if (pchan) {
796                                         copy_v3_v3(vec, pchan->pose_mat[3]);
797                                         mul_m4_v3(ob->obmat, vec);
798                                 }
799                         }
800                         translate_m4(rv3d->viewmat, -vec[0], -vec[1], -vec[2]);
801                         use_lock_ofs = true;
802                 }
803                 else if (v3d->ob_centre_cursor) {
804                         float vec[3];
805                         copy_v3_v3(vec, ED_view3d_cursor3d_get(scene, (View3D *)v3d));
806                         translate_m4(rv3d->viewmat, -vec[0], -vec[1], -vec[2]);
807                         use_lock_ofs = true;
808                 }
809                 else {
810                         translate_m4(rv3d->viewmat, rv3d->ofs[0], rv3d->ofs[1], rv3d->ofs[2]);
811                 }
812
813                 /* lock offset */
814                 if (use_lock_ofs) {
815                         float persmat[4][4], persinv[4][4];
816                         float vec[3];
817
818                         /* we could calculate the real persmat/persinv here
819                          * but it would be unreliable so better to later */
820                         mul_m4_m4m4(persmat, rv3d->winmat, rv3d->viewmat);
821                         invert_m4_m4(persinv, persmat);
822
823                         mul_v2_v2fl(vec, rv3d->ofs_lock, rv3d->is_persp ? rv3d->dist : 1.0f);
824                         vec[2] = 0.0f;
825
826                         if (rect_scale) {
827                                 /* Since 'RegionView3D.winmat' has been calculated and this function doesn't take the 'ARegion'
828                                  * we don't know about the region size.
829                                  * Use 'rect_scale' when drawing a sub-region to apply 2D offset,
830                                  * scaled by the difference between the sub-region and the region size.
831                                  */
832                                 vec[0] /= rect_scale[0];
833                                 vec[1] /= rect_scale[1];
834                         }
835
836                         mul_mat3_m4_v3(persinv, vec);
837                         translate_m4(rv3d->viewmat, vec[0], vec[1], vec[2]);
838                 }
839                 /* end lock offset */
840         }
841 }
842
843 /** \} */
844
845 /* -------------------------------------------------------------------- */
846 /** \name OpenGL Select Utilities
847  * \{ */
848
849 /**
850  * Optionally cache data for multiple calls to #view3d_opengl_select
851  *
852  * just avoid GPU_select headers outside this file
853  */
854 void view3d_opengl_select_cache_begin(void)
855 {
856         GPU_select_cache_begin();
857 }
858
859 void view3d_opengl_select_cache_end(void)
860 {
861         GPU_select_cache_end();
862 }
863
864 /**
865  * \warning be sure to account for a negative return value
866  * This is an error, "Too many objects in select buffer"
867  * and no action should be taken (can crash blender) if this happens
868  *
869  * \note (vc->obedit == NULL) can be set to explicitly skip edit-object selection.
870  */
871 int view3d_opengl_select(
872         const EvaluationContext *eval_ctx, ViewContext *vc, unsigned int *buffer, unsigned int bufsize, const rcti *input,
873         eV3DSelectMode select_mode)
874 {
875         struct bThemeState theme_state;
876         Depsgraph *graph = vc->depsgraph;
877         Scene *scene = vc->scene;
878         View3D *v3d = vc->v3d;
879         ARegion *ar = vc->ar;
880         rcti rect;
881         int hits;
882         const bool use_obedit_skip = (scene->obedit != NULL) && (vc->obedit == NULL);
883         const bool is_pick_select = (U.gpu_select_pick_deph != 0);
884         const bool do_passes = (
885                 (is_pick_select == false) &&
886                 (select_mode == VIEW3D_SELECT_PICK_NEAREST) &&
887                 GPU_select_query_check_active());
888         const bool use_nearest = (is_pick_select && select_mode == VIEW3D_SELECT_PICK_NEAREST);
889
890         char gpu_select_mode;
891
892         /* case not a border select */
893         if (input->xmin == input->xmax) {
894                 /* seems to be default value for bones only now */
895                 BLI_rcti_init_pt_radius(&rect, (const int[2]){input->xmin, input->ymin}, 12);
896         }
897         else {
898                 rect = *input;
899         }
900
901         if (is_pick_select) {
902                 if (is_pick_select && select_mode == VIEW3D_SELECT_PICK_NEAREST) {
903                         gpu_select_mode = GPU_SELECT_PICK_NEAREST;
904                 }
905                 else if (is_pick_select && select_mode == VIEW3D_SELECT_PICK_ALL) {
906                         gpu_select_mode = GPU_SELECT_PICK_ALL;
907                 }
908                 else {
909                         gpu_select_mode = GPU_SELECT_ALL;
910                 }
911         }
912         else {
913                 if (do_passes) {
914                         gpu_select_mode = GPU_SELECT_NEAREST_FIRST_PASS;
915                 }
916                 else {
917                         gpu_select_mode = GPU_SELECT_ALL;
918                 }
919         }
920
921         /* Tools may request depth outside of regular drawing code. */
922         UI_Theme_Store(&theme_state);
923         UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW);
924
925         /* Re-use cache (rect must be smaller then the cached)
926          * other context is assumed to be unchanged */
927         if (GPU_select_is_cached()) {
928                 GPU_select_begin(buffer, bufsize, &rect, gpu_select_mode, 0);
929                 GPU_select_cache_load_id();
930                 hits = GPU_select_end();
931                 goto finally;
932         }
933
934         G.f |= G_PICKSEL;
935
936         /* Important we use the 'viewmat' and don't re-calculate since
937          * the object & bone view locking takes 'rect' into account, see: T51629. */
938         ED_view3d_draw_setup_view(vc->win, eval_ctx, scene, ar, v3d, vc->rv3d->viewmat, NULL, &rect);
939
940         if (v3d->drawtype > OB_WIRE) {
941                 v3d->zbuf = true;
942                 glEnable(GL_DEPTH_TEST);
943         }
944         
945         if (vc->rv3d->rflag & RV3D_CLIPPING)
946                 ED_view3d_clipping_set(vc->rv3d);
947         
948         GPU_select_begin(buffer, bufsize, &rect, gpu_select_mode, 0);
949
950 #ifdef WITH_OPENGL_LEGACY
951         if (IS_VIEWPORT_LEGACY(vc->v3d)) {
952                 ED_view3d_draw_select_loop(vc, scene, sl, v3d, ar, use_obedit_skip, use_nearest);
953         }
954         else
955 #else
956         {
957                 DRW_draw_select_loop(
958                         graph, ar, v3d, eval_ctx->object_mode,
959                         use_obedit_skip, use_nearest, &rect);
960         }
961 #endif /* WITH_OPENGL_LEGACY */
962
963         hits = GPU_select_end();
964         
965         /* second pass, to get the closest object to camera */
966         if (do_passes && (hits > 0)) {
967                 GPU_select_begin(buffer, bufsize, &rect, GPU_SELECT_NEAREST_SECOND_PASS, hits);
968
969 #ifdef WITH_OPENGL_LEGACY
970                 if (IS_VIEWPORT_LEGACY(vc->v3d)) {
971                         ED_view3d_draw_select_loop(vc, scene, sl, v3d, ar, use_obedit_skip, use_nearest);
972                 }
973                 else
974 #else
975                 {
976                         DRW_draw_select_loop(
977                                 graph, ar, v3d, eval_ctx->object_mode,
978                                 use_obedit_skip, use_nearest, &rect);
979                 }
980 #endif /* WITH_OPENGL_LEGACY */
981
982                 GPU_select_end();
983         }
984
985         G.f &= ~G_PICKSEL;
986         ED_view3d_draw_setup_view(vc->win, eval_ctx, scene, ar, v3d, vc->rv3d->viewmat, NULL, NULL);
987         
988         if (v3d->drawtype > OB_WIRE) {
989                 v3d->zbuf = 0;
990                 glDisable(GL_DEPTH_TEST);
991         }
992         
993         if (vc->rv3d->rflag & RV3D_CLIPPING)
994                 ED_view3d_clipping_disable();
995
996 finally:
997         if (hits < 0) printf("Too many objects in select buffer\n");  /* XXX make error message */
998
999         UI_Theme_Restore(&theme_state);
1000
1001         return hits;
1002 }
1003
1004 /** \} */
1005
1006 /* -------------------------------------------------------------------- */
1007 /** \name View Layer Utilities
1008  * \{ */
1009
1010 int ED_view3d_view_layer_set(int lay, const int *values, int *active)
1011 {
1012         int i, tot = 0;
1013         
1014         /* ensure we always have some layer selected */
1015         for (i = 0; i < 20; i++)
1016                 if (values[i])
1017                         tot++;
1018         
1019         if (tot == 0)
1020                 return lay;
1021         
1022         for (i = 0; i < 20; i++) {
1023                 
1024                 if (active) {
1025                         /* if this value has just been switched on, make that layer active */
1026                         if (values[i] && (lay & (1 << i)) == 0) {
1027                                 *active = (1 << i);
1028                         }
1029                 }
1030                         
1031                 if (values[i]) lay |= (1 << i);
1032                 else lay &= ~(1 << i);
1033         }
1034         
1035         /* ensure always an active layer */
1036         if (active && (lay & *active) == 0) {
1037                 for (i = 0; i < 20; i++) {
1038                         if (lay & (1 << i)) {
1039                                 *active = 1 << i;
1040                                 break;
1041                         }
1042                 }
1043         }
1044         
1045         return lay;
1046 }
1047
1048 /** \} */
1049
1050 /* -------------------------------------------------------------------- */
1051 /** \name Game Engine Operator
1052  *
1053  * Start the game engine (handles context switching).
1054  * \{ */
1055
1056 #ifdef WITH_GAMEENGINE
1057
1058 static ListBase queue_back;
1059 static void game_engine_save_state(bContext *C, wmWindow *win)
1060 {
1061         Object *obact = CTX_data_active_object(C);
1062
1063         glPushAttrib(GL_ALL_ATTRIB_BITS);
1064
1065         if (obact && obact->mode & OB_MODE_TEXTURE_PAINT)
1066                 GPU_paint_set_mipmap(1);
1067
1068         queue_back = win->queue;
1069
1070         BLI_listbase_clear(&win->queue);
1071 }
1072
1073 static void game_engine_restore_state(bContext *C, wmWindow *win)
1074 {
1075         Object *obact = CTX_data_active_object(C);
1076
1077         if (obact && obact->mode & OB_MODE_TEXTURE_PAINT)
1078                 GPU_paint_set_mipmap(0);
1079
1080         /* check because closing win can set to NULL */
1081         if (win) {
1082                 win->queue = queue_back;
1083         }
1084
1085         GPU_state_init();
1086
1087         glPopAttrib();
1088 }
1089
1090 /* was space_set_commmandline_options in 2.4x */
1091 static void game_set_commmandline_options(GameData *gm)
1092 {
1093         SYS_SystemHandle syshandle;
1094         int test;
1095
1096         if ((syshandle = SYS_GetSystem())) {
1097                 /* User defined settings */
1098                 test = (U.gameflags & USER_DISABLE_MIPMAP);
1099                 GPU_set_mipmap(!test);
1100                 SYS_WriteCommandLineInt(syshandle, "nomipmap", test);
1101
1102                 /* File specific settings: */
1103                 /* Only test the first one. These two are switched
1104                  * simultaneously. */
1105                 test = (gm->flag & GAME_SHOW_FRAMERATE);
1106                 SYS_WriteCommandLineInt(syshandle, "show_framerate", test);
1107                 SYS_WriteCommandLineInt(syshandle, "show_profile", test);
1108
1109                 test = (gm->flag & GAME_SHOW_DEBUG_PROPS);
1110                 SYS_WriteCommandLineInt(syshandle, "show_properties", test);
1111
1112                 test = (gm->flag & GAME_SHOW_PHYSICS);
1113                 SYS_WriteCommandLineInt(syshandle, "show_physics", test);
1114
1115                 test = (gm->flag & GAME_ENABLE_ALL_FRAMES);
1116                 SYS_WriteCommandLineInt(syshandle, "fixedtime", test);
1117
1118                 test = (gm->flag & GAME_ENABLE_ANIMATION_RECORD);
1119                 SYS_WriteCommandLineInt(syshandle, "animation_record", test);
1120
1121                 test = (gm->flag & GAME_IGNORE_DEPRECATION_WARNINGS);
1122                 SYS_WriteCommandLineInt(syshandle, "ignore_deprecation_warnings", test);
1123
1124                 test = (gm->matmode == GAME_MAT_MULTITEX);
1125                 SYS_WriteCommandLineInt(syshandle, "blender_material", test);
1126                 test = (gm->matmode == GAME_MAT_GLSL);
1127                 SYS_WriteCommandLineInt(syshandle, "blender_glsl_material", test);
1128         }
1129 }
1130
1131 #endif /* WITH_GAMEENGINE */
1132
1133 static int game_engine_poll(bContext *C)
1134 {
1135         const wmWindow *win = CTX_wm_window(C);
1136         const Scene *scene = WM_window_get_active_scene(win);
1137
1138         /* we need a context and area to launch BGE
1139          * it's a temporary solution to avoid crash at load time
1140          * if we try to auto run the BGE. Ideally we want the
1141          * context to be set as soon as we load the file. */
1142
1143         if (win == NULL) return 0;
1144         if (CTX_wm_screen(C) == NULL) return 0;
1145
1146         if (CTX_data_mode_enum(C) != CTX_MODE_OBJECT)
1147                 return 0;
1148
1149         if (!BKE_scene_uses_blender_game(scene))
1150                 return 0;
1151
1152         return 1;
1153 }
1154
1155 static int game_engine_exec(bContext *C, wmOperator *op)
1156 {
1157 #ifdef WITH_GAMEENGINE
1158         Scene *startscene = CTX_data_scene(C);
1159         Main *bmain = CTX_data_main(C);
1160         ScrArea /* *sa, */ /* UNUSED */ *prevsa = CTX_wm_area(C);
1161         ARegion *ar, *prevar = CTX_wm_region(C);
1162         wmWindow *prevwin = CTX_wm_window(C);
1163         RegionView3D *rv3d;
1164         rcti cam_frame;
1165
1166         UNUSED_VARS(op);
1167
1168         /* bad context switch .. */
1169         if (!ED_view3d_context_activate(C))
1170                 return OPERATOR_CANCELLED;
1171
1172         /* redraw to hide any menus/popups, we don't go back to
1173          * the window manager until after this operator exits */
1174         WM_redraw_windows(C);
1175
1176         BLI_callback_exec(bmain, &startscene->id, BLI_CB_EVT_GAME_PRE);
1177
1178         rv3d = CTX_wm_region_view3d(C);
1179         /* sa = CTX_wm_area(C); */ /* UNUSED */
1180         ar = CTX_wm_region(C);
1181
1182         view3d_operator_needs_opengl(C);
1183
1184         game_set_commmandline_options(&startscene->gm);
1185
1186         if ((rv3d->persp == RV3D_CAMOB) &&
1187             (startscene->gm.framing.type == SCE_GAMEFRAMING_BARS) &&
1188             (startscene->gm.stereoflag != STEREO_DOME))
1189         {
1190                 const Depsgraph *depsgraph = CTX_data_depsgraph(C);
1191                 /* Letterbox */
1192                 rctf cam_framef;
1193                 ED_view3d_calc_camera_border(startscene, depsgraph, ar, CTX_wm_view3d(C), rv3d, &cam_framef, false);
1194                 cam_frame.xmin = cam_framef.xmin + ar->winrct.xmin;
1195                 cam_frame.xmax = cam_framef.xmax + ar->winrct.xmin;
1196                 cam_frame.ymin = cam_framef.ymin + ar->winrct.ymin;
1197                 cam_frame.ymax = cam_framef.ymax + ar->winrct.ymin;
1198                 BLI_rcti_isect(&ar->winrct, &cam_frame, &cam_frame);
1199         }
1200         else {
1201                 cam_frame.xmin = ar->winrct.xmin;
1202                 cam_frame.xmax = ar->winrct.xmax;
1203                 cam_frame.ymin = ar->winrct.ymin;
1204                 cam_frame.ymax = ar->winrct.ymax;
1205         }
1206
1207
1208         game_engine_save_state(C, prevwin);
1209
1210         StartKetsjiShell(C, ar, &cam_frame, 1);
1211
1212         /* window wasnt closed while the BGE was running */
1213         if (BLI_findindex(&CTX_wm_manager(C)->windows, prevwin) == -1) {
1214                 prevwin = NULL;
1215                 CTX_wm_window_set(C, NULL);
1216         }
1217
1218         ED_area_tag_redraw(CTX_wm_area(C));
1219
1220         if (prevwin) {
1221                 /* restore context, in case it changed in the meantime, for
1222                  * example by working in another window or closing it */
1223                 CTX_wm_region_set(C, prevar);
1224                 CTX_wm_window_set(C, prevwin);
1225                 CTX_wm_area_set(C, prevsa);
1226         }
1227
1228         game_engine_restore_state(C, prevwin);
1229
1230         //XXX restore_all_scene_cfra(scene_cfra_store);
1231         BKE_scene_set_background(CTX_data_main(C), startscene);
1232         //XXX BKE_scene_graph_update_for_newframe(bmain->eval_ctx, bmain, scene, depsgraph);
1233
1234         BLI_callback_exec(bmain, &startscene->id, BLI_CB_EVT_GAME_POST);
1235
1236         return OPERATOR_FINISHED;
1237 #else
1238         UNUSED_VARS(C);
1239         BKE_report(op->reports, RPT_ERROR, "Game engine is disabled in this build");
1240         return OPERATOR_CANCELLED;
1241 #endif
1242 }
1243
1244 void VIEW3D_OT_game_start(wmOperatorType *ot)
1245 {
1246         /* identifiers */
1247         ot->name = "Start Game Engine";
1248         ot->description = "Start game engine";
1249         ot->idname = "VIEW3D_OT_game_start";
1250
1251         /* api callbacks */
1252         ot->exec = game_engine_exec;
1253
1254         ot->poll = game_engine_poll;
1255 }
1256
1257 /** \} */