4 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version. The Blender
10 * Foundation also sells licenses for use in proprietary software under
11 * the Blender License. See http://www.blender.org/BL/ for information
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24 * All rights reserved.
26 * The Original Code is: all of this file.
28 * Contributor(s): none yet.
30 * ***** END GPL/BL DUAL LICENSE BLOCK *****
33 //#define NAN_LINEAR_PHYSICS
40 #include <sys/times.h>
45 #include "MEM_guardedalloc.h"
51 #include "IMB_imbuf_types.h"
52 #include "IMB_imbuf.h"
54 #include "DNA_action_types.h"
55 #include "DNA_armature_types.h"
56 #include "DNA_camera_types.h"
57 #include "DNA_constraint_types.h"
58 #include "DNA_curve_types.h"
59 #include "DNA_group_types.h"
60 #include "DNA_image_types.h"
61 #include "DNA_lattice_types.h"
62 #include "DNA_mesh_types.h"
63 #include "DNA_meshdata_types.h"
64 #include "DNA_meta_types.h"
65 #include "DNA_object_types.h"
66 #include "DNA_screen_types.h"
67 #include "DNA_scene_types.h"
68 #include "DNA_space_types.h"
69 #include "DNA_texture_types.h"
70 #include "DNA_userdef_types.h"
71 #include "DNA_view3d_types.h"
72 #include "DNA_world_types.h"
74 #include "BLI_blenlib.h"
75 #include "BLI_arithb.h"
76 #include "BLI_editVert.h"
78 #include "BKE_action.h"
79 #include "BKE_armature.h"
81 #include "BKE_constraint.h"
82 #include "BKE_curve.h"
83 #include "BKE_displist.h"
84 #include "BKE_depsgraph.h"
85 #include "BKE_DerivedMesh.h"
86 #include "BKE_global.h"
87 #include "BKE_lattice.h"
88 #include "BKE_library.h"
89 #include "BKE_image.h"
94 #include "BKE_object.h"
95 #include "BKE_scene.h"
96 #include "BKE_texture.h"
97 #include "BKE_utildefines.h"
99 #include "BIF_butspace.h"
100 #include "BIF_drawimage.h"
101 #include "BIF_editgroup.h"
102 #include "BIF_editarmature.h"
103 #include "BIF_editmesh.h"
105 #include "BIF_glutil.h"
106 #include "BIF_interface.h"
107 #include "BIF_interface_icons.h"
108 #include "BIF_mywindow.h"
109 #include "BIF_poseobject.h"
110 #include "BIF_previewrender.h"
111 #include "BIF_resources.h"
112 #include "BIF_screen.h"
113 #include "BIF_space.h"
115 #include "BDR_drawmesh.h"
116 #include "BDR_drawobject.h"
117 #include "BDR_editobject.h"
118 #include "BDR_vpaint.h"
120 #include "BSE_drawview.h"
121 #include "BSE_filesel.h"
122 #include "BSE_headerbuttons.h"
123 #include "BSE_seqaudio.h"
124 #include "BSE_trans_types.h"
125 #include "BSE_time.h"
126 #include "BSE_view.h"
128 #include "BPY_extern.h"
130 #include "RE_render_ext.h"
133 #include "mydevice.h"
134 #include "butspace.h" // event codes
136 #include "BIF_transform.h"
138 #include "RE_pipeline.h" // make_stars
144 void drawname(Object *ob);
146 static void star_stuff_init_func(void)
152 static void star_stuff_vertex_func(float* i)
156 static void star_stuff_term_func(void)
161 static void setalpha_bgpic(BGpic *bgpic)
166 alph= (int)(255.0*(1.0-bgpic->blend));
168 rect= (char *)bgpic->rect;
169 for(y=0; y< bgpic->yim; y++) {
170 for(x= bgpic->xim; x>0; x--, rect+=4) {
177 void default_gl_light(void)
182 if(U.light[0].flag==0 && U.light[1].flag==0 && U.light[2].flag==0) {
184 U.light[0].vec[0]= -0.3; U.light[0].vec[1]= 0.3; U.light[0].vec[2]= 0.9;
185 U.light[0].col[0]= 0.8; U.light[0].col[1]= 0.8; U.light[0].col[2]= 0.8;
186 U.light[0].spec[0]= 0.5; U.light[0].spec[1]= 0.5; U.light[0].spec[2]= 0.5;
187 U.light[0].spec[3]= 1.0;
190 U.light[1].vec[0]= 0.5; U.light[1].vec[1]= 0.5; U.light[1].vec[2]= 0.1;
191 U.light[1].col[0]= 0.4; U.light[1].col[1]= 0.4; U.light[1].col[2]= 0.8;
192 U.light[1].spec[0]= 0.3; U.light[1].spec[1]= 0.3; U.light[1].spec[2]= 0.5;
193 U.light[1].spec[3]= 1.0;
196 U.light[2].vec[0]= 0.3; U.light[2].vec[1]= -0.3; U.light[2].vec[2]= -0.2;
197 U.light[2].col[0]= 0.8; U.light[2].col[1]= 0.5; U.light[2].col[2]= 0.4;
198 U.light[2].spec[0]= 0.5; U.light[2].spec[1]= 0.4; U.light[2].spec[2]= 0.3;
199 U.light[2].spec[3]= 1.0;
203 glLightfv(GL_LIGHT0, GL_POSITION, U.light[0].vec);
204 glLightfv(GL_LIGHT0, GL_DIFFUSE, U.light[0].col);
205 glLightfv(GL_LIGHT0, GL_SPECULAR, U.light[0].spec);
207 glLightfv(GL_LIGHT1, GL_POSITION, U.light[1].vec);
208 glLightfv(GL_LIGHT1, GL_DIFFUSE, U.light[1].col);
209 glLightfv(GL_LIGHT1, GL_SPECULAR, U.light[1].spec);
211 glLightfv(GL_LIGHT2, GL_POSITION, U.light[2].vec);
212 glLightfv(GL_LIGHT2, GL_DIFFUSE, U.light[2].col);
213 glLightfv(GL_LIGHT2, GL_SPECULAR, U.light[2].spec);
217 if(U.light[a].flag) glEnable(GL_LIGHT0+a);
218 else glDisable(GL_LIGHT0+a);
220 // clear stuff from other opengl lamp usage
221 glLightf(GL_LIGHT0+a, GL_SPOT_CUTOFF, 180.0);
222 glLightf(GL_LIGHT0+a, GL_CONSTANT_ATTENUATION, 1.0);
223 glLightf(GL_LIGHT0+a, GL_LINEAR_ATTENUATION, 0.0);
225 else glDisable(GL_LIGHT0+a);
228 glDisable(GL_LIGHTING);
230 glDisable(GL_COLOR_MATERIAL);
233 /* also called when render 'ogl' */
234 void init_gl_stuff(void)
236 float mat_ambient[] = { 0.0, 0.0, 0.0, 0.0 };
237 float mat_specular[] = { 0.5, 0.5, 0.5, 1.0 };
238 float mat_shininess[] = { 35.0 };
241 const GLubyte *patc= pat;
244 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
245 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_specular);
246 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
247 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
251 /* no local viewer, looks ugly in ortho mode */
252 /* glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, &one); */
254 glDepthFunc(GL_LEQUAL);
255 /* scaling matrices */
256 glEnable(GL_NORMALIZE);
258 glShadeModel(GL_FLAT);
260 glDisable(GL_ALPHA_TEST);
262 glDisable(GL_DEPTH_TEST);
264 glDisable(GL_LIGHTING);
265 glDisable(GL_LOGIC_OP);
266 glDisable(GL_STENCIL_TEST);
267 glDisable(GL_TEXTURE_1D);
268 glDisable(GL_TEXTURE_2D);
270 glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
271 glPixelTransferi(GL_RED_SCALE, 1);
272 glPixelTransferi(GL_RED_BIAS, 0);
273 glPixelTransferi(GL_GREEN_SCALE, 1);
274 glPixelTransferi(GL_GREEN_BIAS, 0);
275 glPixelTransferi(GL_BLUE_SCALE, 1);
276 glPixelTransferi(GL_BLUE_BIAS, 0);
277 glPixelTransferi(GL_ALPHA_SCALE, 1);
278 glPixelTransferi(GL_ALPHA_BIAS, 0);
280 glPixelTransferi(GL_DEPTH_BIAS, 0);
281 glPixelTransferi(GL_DEPTH_SCALE, 1);
282 glDepthRange(0.0, 1.0);
285 for(x=0; x<32; x++) {
287 if( (x) & 1) pat[a++]= 0x88;
292 glPolygonStipple(patc);
298 void circf(float x, float y, float rad)
300 GLUquadricObj *qobj = gluNewQuadric();
302 gluQuadricDrawStyle(qobj, GLU_FILL);
306 glTranslatef(x, y, 0.);
308 gluDisk( qobj, 0.0, rad, 32, 1);
312 gluDeleteQuadric(qobj);
315 void circ(float x, float y, float rad)
317 GLUquadricObj *qobj = gluNewQuadric();
319 gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
323 glTranslatef(x, y, 0.);
325 gluDisk( qobj, 0.0, rad, 32, 1);
329 gluDeleteQuadric(qobj);
332 /* ********** ********** */
334 static void draw_bgpic(void)
338 float vec[4], fac, asp, zoomx, zoomy;
339 float x1, y1, x2, y2, cx, cy;
342 if(bgpic==NULL) return;
345 extern void init_render_texture(struct Render *re, Tex *tex);
346 /* note; bad call, this has to be recoded to move to blenkernel */
347 init_render_texture(NULL, bgpic->tex);
348 free_unused_animimages();
349 ima= bgpic->tex->ima;
355 if(ima==NULL) return;
356 if(ima->ok==0) return;
361 if(ima->ibuf==NULL) {
363 if(bgpic->rect) MEM_freeN(bgpic->rect);
367 ima_ibuf_is_nul(bgpic->tex, bgpic->tex->ima);
371 load_image(ima, IB_rect, G.sce, G.scene->r.cfra);
374 if(ima->ibuf==NULL) {
380 /* this ensures that when ibuf changed (reloaded) the backbuf changes too */
381 if(bgpic->ibuf!=ima->ibuf) {
382 if(bgpic->rect) MEM_freeN(bgpic->rect);
385 bgpic->ibuf= ima->ibuf;
387 if(bgpic->rect==NULL) {
389 bgpic->rect= MEM_dupallocN(ima->ibuf->rect);
390 bgpic->xim= ima->ibuf->x;
391 bgpic->yim= ima->ibuf->y;
392 setalpha_bgpic(bgpic);
398 calc_viewborder(G.vd, &vb);
408 /* calc window coord */
409 initgrabz(0.0, 0.0, 0.0);
410 window_to_3d(vec, 1, 0);
411 fac= MAX3( fabs(vec[0]), fabs(vec[1]), fabs(vec[1]) );
414 asp= ( (float)ima->ibuf->y)/(float)ima->ibuf->x;
416 vec[0] = vec[1] = vec[2] = 0.0;
417 view3d_project_float(curarea, vec, sco, G.vd->persmat);
421 x1= cx+ fac*(bgpic->xof-bgpic->size);
422 y1= cy+ asp*fac*(bgpic->yof-bgpic->size);
423 x2= cx+ fac*(bgpic->xof+bgpic->size);
424 y2= cy+ asp*fac*(bgpic->yof+bgpic->size);
431 if(x1 > curarea->winx ) return;
432 if(y1 > curarea->winy ) return;
434 zoomx= (x2-x1)/ima->ibuf->x;
435 zoomy= (y2-y1)/ima->ibuf->y;
438 if(G.vd->zbuf) glDisable(GL_DEPTH_TEST);
440 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
442 glMatrixMode(GL_PROJECTION);
444 glMatrixMode(GL_MODELVIEW);
447 glaDefine2DArea(&curarea->winrct);
448 glPixelZoom(zoomx, zoomy);
449 glaDrawPixelsSafe(x1, y1, ima->ibuf->x, ima->ibuf->y, ima->ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, bgpic->rect);
450 glPixelZoom(1.0, 1.0);
452 glMatrixMode(GL_PROJECTION);
454 glMatrixMode(GL_MODELVIEW);
457 glBlendFunc(GL_ONE, GL_ZERO);
459 if(G.vd->zbuf) glEnable(GL_DEPTH_TEST);
461 areawinset(curarea->win); // restore viewport / scissor
464 static void drawgrid_draw(float wx, float wy, float x, float y, float dx)
473 while(fx< curarea->winx) {
474 fdrawline(fx, 0.0, fx, (float)curarea->winy);
482 while(fy< curarea->winy) {
483 fdrawline(0.0, fy, (float)curarea->winx, fy);
489 // not intern, called in editobject for constraint axis too
490 void make_axis_color(char *col, char *col2, char axis)
493 col2[0]= col[0]>219?255:col[0]+36;
494 col2[1]= col[1]<26?0:col[1]-26;
495 col2[2]= col[2]<26?0:col[2]-26;
498 col2[0]= col[0]<46?0:col[0]-36;
499 col2[1]= col[1]>189?255:col[1]+66;
500 col2[2]= col[2]<46?0:col[2]-36;
503 col2[0]= col[0]<26?0:col[0]-26;
504 col2[1]= col[1]<26?0:col[1]-26;
505 col2[2]= col[2]>209?255:col[2]+46;
510 static void drawgrid(void)
512 /* extern short bgpicmode; */
513 float wx, wy, x, y, fw, fx, fy, dx;
515 char col[3], col2[3];
517 vec4[0]=vec4[1]=vec4[2]=0.0;
519 Mat4MulVec4fl(G.vd->persmat, vec4);
524 wx= (curarea->winx/2.0); /* because of rounding errors, grid at wrong location */
525 wy= (curarea->winy/2.0);
530 vec4[0]=vec4[1]=G.vd->grid;
533 Mat4MulVec4fl(G.vd->persmat, vec4);
538 dx= fabs(x-(wx)*fx/fw);
539 if(dx==0) dx= fabs(y-(wy)*fy/fw);
541 glDepthMask(0); // disable write in zbuffer
544 BIF_ThemeColor(TH_GRID);
548 G.vd->gridview*= 10.0;
552 G.vd->gridview*= 10.0;
556 G.vd->gridview*= 10.0;
560 BIF_ThemeColor(TH_GRID);
561 drawgrid_draw(wx, wy, x, y, dx);
564 else { // start blending out
565 BIF_ThemeColorBlend(TH_BACK, TH_GRID, dx/60.0);
566 drawgrid_draw(wx, wy, x, y, dx);
568 BIF_ThemeColor(TH_GRID);
569 drawgrid_draw(wx, wy, x, y, 10*dx);
572 else { // start blending out (6 < dx < 60)
573 BIF_ThemeColorBlend(TH_BACK, TH_GRID, dx/60.0);
574 drawgrid_draw(wx, wy, x, y, dx);
576 BIF_ThemeColor(TH_GRID);
577 drawgrid_draw(wx, wy, x, y, 10*dx);
581 if(dx>60.0) { // start blending in
582 G.vd->gridview/= 10.0;
584 if(dx>60.0) { // start blending in
585 G.vd->gridview/= 10.0;
588 BIF_ThemeColor(TH_GRID);
589 drawgrid_draw(wx, wy, x, y, dx);
592 BIF_ThemeColorBlend(TH_BACK, TH_GRID, dx/60.0);
593 drawgrid_draw(wx, wy, x, y, dx);
594 BIF_ThemeColor(TH_GRID);
595 drawgrid_draw(wx, wy, x, y, dx*10);
599 BIF_ThemeColorBlend(TH_BACK, TH_GRID, dx/60.0);
600 drawgrid_draw(wx, wy, x, y, dx);
601 BIF_ThemeColor(TH_GRID);
602 drawgrid_draw(wx, wy, x, y, dx*10);
606 BIF_ThemeColorBlend(TH_BACK, TH_GRID, dx/60.0);
607 drawgrid_draw(wx, wy, x, y, dx);
608 BIF_ThemeColor(TH_GRID);
609 drawgrid_draw(wx, wy, x, y, dx*10);
615 BIF_GetThemeColor3ubv(TH_GRID, col);
620 if(G.vd->view==3) make_axis_color(col, col2, 'y');
621 else make_axis_color(col, col2, 'x');
624 fdrawline(0.0, y, (float)curarea->winx, y);
626 if(G.vd->view==7) make_axis_color(col, col2, 'y');
627 else make_axis_color(col, col2, 'z');
630 fdrawline(x, 0.0, x, (float)curarea->winy);
632 glDepthMask(1); // enable write in zbuffer
637 static void drawfloor(void)
641 int a, gridlines, emphasise;
642 char col[3], col2[3];
645 vd= curarea->spacedata.first;
649 if(vd->gridlines<3) return;
651 if(G.vd->zbuf && G.obedit) glDepthMask(0); // for zbuffer-select
653 gridlines= vd->gridlines/2;
654 grid= gridlines*vd->grid;
656 BIF_GetThemeColor3ubv(TH_GRID, col);
657 BIF_GetThemeColor3ubv(TH_BACK, col2);
659 /* emphasise division lines lighter instead of darker, if background is darker than grid */
660 if ( ((col[0]+col[1]+col[2])/3+10) > (col2[0]+col2[1]+col2[2])/3 )
665 /* draw the Y axis and/or grid lines */
666 for(a= -gridlines;a<=gridlines;a++) {
668 /* check for the 'show Y axis' preference */
669 if (vd->gridflag & V3D_SHOW_Y) {
670 make_axis_color(col, col2, 'y');
674 } else if (vd->gridflag & V3D_SHOW_FLOOR) {
675 BIF_ThemeColorShade(TH_GRID, emphasise);
680 /* check for the 'show grid floor' preference */
681 if (vd->gridflag & V3D_SHOW_FLOOR) {
683 BIF_ThemeColorShade(TH_GRID, emphasise);
685 else BIF_ThemeColorShade(TH_GRID, 10);
694 glBegin(GL_LINE_STRIP);
704 /* draw the X axis and/or grid lines */
705 for(a= -gridlines;a<=gridlines;a++) {
707 /* check for the 'show X axis' preference */
708 if (vd->gridflag & V3D_SHOW_X) {
709 make_axis_color(col, col2, 'x');
713 } else if (vd->gridflag & V3D_SHOW_FLOOR) {
714 BIF_ThemeColorShade(TH_GRID, emphasise);
719 /* check for the 'show grid floor' preference */
720 if (vd->gridflag & V3D_SHOW_FLOOR) {
722 BIF_ThemeColorShade(TH_GRID, emphasise);
724 else BIF_ThemeColorShade(TH_GRID, 10);
733 glBegin(GL_LINE_STRIP);
743 /* draw the Z axis line */
744 /* check for the 'show Z axis' preference */
745 if (vd->gridflag & V3D_SHOW_Z) {
746 make_axis_color(col, col2, 'z');
749 glBegin(GL_LINE_STRIP);
759 if(G.vd->zbuf && G.obedit) glDepthMask(1);
763 static void drawcursor(View3D *v3d)
768 /* we dont want the clipping for cursor */
771 project_short( give_cursor(), co);
780 circ((float)mx, (float)my, 10.0);
783 circ((float)mx, (float)my, 10.0);
787 sdrawline(mx-20, my, mx-5, my);
788 sdrawline(mx+5, my, mx+20, my);
789 sdrawline(mx, my-20, mx, my-5);
790 sdrawline(mx, my+5, mx, my+20);
794 /* ********* custom clipping *********** */
796 static void view3d_draw_clipping(View3D *v3d)
798 BoundBox *bb= v3d->clipbb;
800 BIF_ThemeColorShade(TH_BACK, -8);
804 glVertex3fv(bb->vec[0]); glVertex3fv(bb->vec[1]); glVertex3fv(bb->vec[2]); glVertex3fv(bb->vec[3]);
805 glVertex3fv(bb->vec[0]); glVertex3fv(bb->vec[4]); glVertex3fv(bb->vec[5]); glVertex3fv(bb->vec[1]);
806 glVertex3fv(bb->vec[4]); glVertex3fv(bb->vec[7]); glVertex3fv(bb->vec[6]); glVertex3fv(bb->vec[5]);
807 glVertex3fv(bb->vec[7]); glVertex3fv(bb->vec[3]); glVertex3fv(bb->vec[2]); glVertex3fv(bb->vec[6]);
808 glVertex3fv(bb->vec[1]); glVertex3fv(bb->vec[5]); glVertex3fv(bb->vec[6]); glVertex3fv(bb->vec[2]);
809 glVertex3fv(bb->vec[7]); glVertex3fv(bb->vec[4]); glVertex3fv(bb->vec[0]); glVertex3fv(bb->vec[3]);
814 void view3d_set_clipping(View3D *v3d)
820 QUATCOPY(plane, v3d->clip[a]);
821 glClipPlane(GL_CLIP_PLANE0+a, plane);
822 glEnable(GL_CLIP_PLANE0+a);
826 void view3d_clr_clipping(void)
831 glDisable(GL_CLIP_PLANE0+a);
835 int view3d_test_clipping(View3D *v3d, float *vec)
837 /* vec in world coordinates, returns 1 if clipped */
842 if(0.0f < v3d->clip[0][3] + INPR(view, v3d->clip[0]))
843 if(0.0f < v3d->clip[1][3] + INPR(view, v3d->clip[1]))
844 if(0.0f < v3d->clip[2][3] + INPR(view, v3d->clip[2]))
845 if(0.0f < v3d->clip[3][3] + INPR(view, v3d->clip[3]))
851 /* ********* end custom clipping *********** */
853 static void view3d_get_viewborder_size(View3D *v3d, float size_r[2])
855 float winmax= MAX2(v3d->area->winx, v3d->area->winy);
856 float aspect= (float) (G.scene->r.xsch*G.scene->r.xasp)/(G.scene->r.ysch*G.scene->r.yasp);
860 size_r[1]= winmax/aspect;
862 size_r[0]= winmax*aspect;
867 void calc_viewborder(struct View3D *v3d, rctf *viewborder_r)
869 float zoomfac, size[2];
870 float dx= 0.0f, dy= 0.0f;
872 view3d_get_viewborder_size(v3d, size);
874 /* magic zoom calculation, no idea what
875 * it signifies, if you find out, tell me! -zr
877 /* simple, its magic dude!
878 * well, to be honest, this gives a natural feeling zooming
879 * with multiple keypad presses (ton)
882 zoomfac= (M_SQRT2 + v3d->camzoom/50.0);
883 zoomfac= (zoomfac*zoomfac)*0.25;
885 size[0]= size[0]*zoomfac;
886 size[1]= size[1]*zoomfac;
888 /* center in window */
889 viewborder_r->xmin= 0.5*v3d->area->winx - 0.5*size[0];
890 viewborder_r->ymin= 0.5*v3d->area->winy - 0.5*size[1];
891 viewborder_r->xmax= viewborder_r->xmin + size[0];
892 viewborder_r->ymax= viewborder_r->ymin + size[1];
894 dx= v3d->area->winx*G.vd->camdx;
895 dy= v3d->area->winy*G.vd->camdy;
898 viewborder_r->xmin-= dx;
899 viewborder_r->ymin-= dy;
900 viewborder_r->xmax-= dx;
901 viewborder_r->ymax-= dy;
904 void view3d_set_1_to_1_viewborder(View3D *v3d)
907 int im_width= (G.scene->r.size*G.scene->r.xsch)/100;
909 view3d_get_viewborder_size(v3d, size);
911 v3d->camzoom= (sqrt(4.0*im_width/size[0]) - M_SQRT2)*50.0;
912 v3d->camzoom= CLAMPIS(v3d->camzoom, -30, 300);
916 static void drawviewborder_flymode(void)
918 /* draws 4 edge brackets that frame the safe area where the
919 mouse can move during fly mode without spinning the view */
920 float x1, x2, y1, y2;
922 x1= 0.45*(float)curarea->winx;
923 y1= 0.45*(float)curarea->winy;
924 x2= 0.55*(float)curarea->winx;
925 y2= 0.55*(float)curarea->winy;
961 static void drawviewborder(void)
963 extern void gl_round_box(int mode, float minx, float miny, float maxx, float maxy, float rad); // interface_panel.c
965 float x1, x2, y1, y2;
966 float x3, y3, x4, y4;
970 if(G.vd->camera==NULL)
972 if(G.vd->camera->type==OB_CAMERA)
973 ca = G.vd->camera->data;
975 calc_viewborder(G.vd, &viewborder);
981 /* passepartout, specified in camera edit buttons */
982 if (ca && (ca->flag & CAM_SHOWPASSEPARTOUT)) {
983 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
985 glColor4f(0, 0, 0, ca->passepartalpha);
988 glRectf(0.0, (float)curarea->winy, x1, 0.0);
989 if (x2 < (float)curarea->winx)
990 glRectf(x2, (float)curarea->winy, (float)curarea->winx, 0.0);
991 if (y2 < (float)curarea->winy)
992 glRectf(x1, (float)curarea->winy, x2, y2);
994 glRectf(x1, y1, x2, 0.0);
1000 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
1003 BIF_ThemeColor(TH_BACK);
1004 glRectf(x1, y1, x2, y2);
1007 BIF_ThemeColor(TH_WIRE);
1008 glRectf(x1, y1, x2, y2);
1011 if (ca && (ca->flag & CAM_SHOWNAME)) {
1012 glRasterPos2f(x1, y1-15);
1014 BMF_DrawString(G.font, G.vd->camera->id.name+2);
1019 if(G.scene->r.mode & R_BORDER) {
1022 x3= x1+ G.scene->r.border.xmin*(x2-x1);
1023 y3= y1+ G.scene->r.border.ymin*(y2-y1);
1024 x4= x1+ G.scene->r.border.xmax*(x2-x1);
1025 y4= y1+ G.scene->r.border.ymax*(y2-y1);
1028 glRectf(x3, y3, x4, y4);
1032 if (ca && (ca->flag & CAM_SHOWTITLESAFE)) {
1043 BIF_ThemeColorBlendShade(TH_WIRE, TH_BACK, 0.25, 0);
1046 gl_round_box(GL_LINE_LOOP, x1, y1, x2, y2, 12.0);
1050 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1055 void backdrawview3d(int test)
1059 if(G.f & (G_VERTEXPAINT|G_FACESELECT|G_TEXTUREPAINT|G_WEIGHTPAINT));
1060 else if(G.obedit && G.vd->drawtype>OB_WIRE && (G.vd->flag & V3D_ZBUF_SELECT));
1062 G.vd->flag &= ~V3D_NEEDBACKBUFDRAW;
1066 if( !(G.vd->flag & V3D_NEEDBACKBUFDRAW) ) return;
1070 addafterqueue(curarea->win, BACKBUFDRAW, 1);
1077 glDrawBuffer(GL_AUX0);
1079 if(G.vd->drawtype > OB_WIRE) G.vd->zbuf= TRUE;
1080 curarea->win_swap &= ~WIN_BACK_OK;
1082 glDisable(GL_DITHER);
1084 glClearColor(0.0, 0.0, 0.0, 0.0);
1086 glEnable(GL_DEPTH_TEST);
1087 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1090 glClear(GL_COLOR_BUFFER_BIT);
1091 glDisable(GL_DEPTH_TEST);
1094 if(G.vd->flag & V3D_CLIPPING)
1095 view3d_set_clipping(G.vd);
1097 G.f |= G_BACKBUFSEL;
1099 base= (G.scene->basact);
1100 if(base && (base->lay & G.vd->lay)) {
1101 draw_object_backbufsel(base->object);
1104 G.vd->flag &= ~V3D_NEEDBACKBUFDRAW;
1106 G.f &= ~G_BACKBUFSEL;
1108 glDisable(GL_DEPTH_TEST);
1109 glEnable(GL_DITHER);
1112 glDrawBuffer(GL_BACK); /* we were in aux buffers */
1115 if(G.vd->flag & V3D_CLIPPING)
1116 view3d_clr_clipping();
1118 /* it is important to end a view in a transform compatible with buttons */
1119 persp(PERSP_WIN); // set ortho
1120 bwin_scalematrix(curarea->win, G.vd->blockscale, G.vd->blockscale, G.vd->blockscale);
1124 void check_backbuf(void)
1126 if(G.vd->flag & V3D_NEEDBACKBUFDRAW)
1130 /* samples a single pixel (copied from vpaint) */
1131 unsigned int sample_backbuf(int x, int y)
1135 if(x>=curarea->winx || y>=curarea->winy) return 0;
1136 x+= curarea->winrct.xmin;
1137 y+= curarea->winrct.ymin;
1139 check_backbuf(); // actually not needed for apple
1142 glReadBuffer(GL_AUX0);
1144 glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col);
1145 glReadBuffer(GL_BACK);
1147 if(G.order==B_ENDIAN) SWITCH_INT(col);
1149 return framebuffer_to_index(col);
1152 /* reads full rect, converts indices */
1153 ImBuf *read_backbuf(short xmin, short ymin, short xmax, short ymax)
1155 unsigned int *dr, *rd;
1156 struct ImBuf *ibuf, *ibuf1;
1158 short xminc, yminc, xmaxc, ymaxc, xs, ys;
1161 if(xmin<0) xminc= 0; else xminc= xmin;
1162 if(xmax>=curarea->winx) xmaxc= curarea->winx-1; else xmaxc= xmax;
1163 if(xminc > xmaxc) return NULL;
1165 if(ymin<0) yminc= 0; else yminc= ymin;
1166 if(ymax>=curarea->winy) ymaxc= curarea->winy-1; else ymaxc= ymax;
1167 if(yminc > ymaxc) return NULL;
1169 ibuf= IMB_allocImBuf((xmaxc-xminc+1), (ymaxc-yminc+1), 32, IB_rect,0);
1171 check_backbuf(); // actually not needed for apple
1174 glReadBuffer(GL_AUX0);
1176 glReadPixels(curarea->winrct.xmin+xminc, curarea->winrct.ymin+yminc, (xmaxc-xminc+1), (ymaxc-yminc+1), GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
1177 glReadBuffer(GL_BACK);
1179 if(G.order==B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf);
1181 a= (xmaxc-xminc+1)*(ymaxc-yminc+1);
1184 if(*dr) *dr= framebuffer_to_index(*dr);
1189 IMB_saveiff(ibuf, "/tmp/rt.png", IB_rect);
1191 /* put clipped result back, if needed */
1192 if(xminc==xmin && xmaxc==xmax && yminc==ymin && ymaxc==ymax)
1195 ibuf1= IMB_allocImBuf( (xmax-xmin+1),(ymax-ymin+1),32,IB_rect,0);
1199 for(ys= ymin; ys<=ymax; ys++) {
1200 for(xs= xmin; xs<=xmax; xs++, dr++) {
1201 if( xs>=xminc && xs<=xmaxc && ys>=yminc && ys<=ymaxc) {
1207 IMB_freeImBuf(ibuf);
1211 /* smart function to sample a rect spiralling outside, nice for backbuf selection */
1212 unsigned int sample_backbuf_rect(short mval[2], int size, unsigned int min, unsigned int max, short *dist)
1215 unsigned int *bufmin, *bufmax, *tbuf;
1217 int a, b, rc, nr, amount, dirvec[4][2];
1219 unsigned int index = 0;
1223 minx = mval[0]-(amount+1);
1224 miny = mval[1]-(amount+1);
1225 buf = read_backbuf(minx, miny, minx+size-1, miny+size-1);
1230 dirvec[0][0]= 1; dirvec[0][1]= 0;
1231 dirvec[1][0]= 0; dirvec[1][1]= -size;
1232 dirvec[2][0]= -1; dirvec[2][1]= 0;
1233 dirvec[3][0]= 0; dirvec[3][1]= size;
1237 bufmax = buf->rect + size*size;
1238 tbuf+= amount*size+ amount;
1240 for(nr=1; nr<=size; nr++) {
1242 for(a=0; a<2; a++) {
1243 for(b=0; b<nr; b++, distance++) {
1244 if (*tbuf && *tbuf>=min && *tbuf<max) {
1245 *dist= (short) sqrt( (float)distance ); // XXX, this distance is wrong - zr
1246 index = *tbuf - min+1; // messy yah, but indices start at 1
1250 tbuf+= (dirvec[rc][0]+dirvec[rc][1]);
1252 if(tbuf<bufmin || tbuf>=bufmax) {
1266 void drawname(Object *ob)
1269 glRasterPos3f(0.0, 0.0, 0.0);
1271 BMF_DrawString(G.font, " ");
1272 BMF_DrawString(G.font, ob->id.name+2);
1276 static void draw_selected_name(Object *ob)
1281 if(ob->type==OB_ARMATURE) {
1282 bArmature *arm= ob->data;
1287 for (ebo=G.edbo.first; ebo; ebo=ebo->next){
1288 if ((ebo->flag & BONE_ACTIVE) && (ebo->layer & arm->layer)) {
1294 else if(ob->pose && (ob->flag & OB_POSEMODE)) {
1295 bPoseChannel *pchan;
1296 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1297 if((pchan->bone->flag & BONE_ACTIVE) && (pchan->bone->layer & arm->layer)) {
1304 sprintf(info, "(%d) %s %s", CFRA, ob->id.name+2, name);
1306 sprintf(info, "(%d) %s", CFRA, ob->id.name+2);
1308 else sprintf(info, "(%d) %s", CFRA, ob->id.name+2);
1310 BIF_ThemeColor(TH_TEXT_HI);
1311 if (U.uiflag & USER_SHOW_ROTVIEWICON)
1312 offset = 14 + (U.rvisize * 2);
1314 glRasterPos2i(offset, 10);
1315 BMF_DrawString(G.fonts, info);
1319 /* Draw a live substitute of the view icon, which is always shown */
1320 static void draw_view_axis(void)
1322 const float k = U.rvisize; /* axis size */
1323 const float toll = 0.5; /* used to see when view is quasi-orthogonal */
1324 const float start = k + 1.0; /* axis center in screen coordinates, x=y */
1325 float ydisp = 0.0; /* vertical displacement to allow obj info text */
1327 /* rvibright ranges approx. from original axis icon color to gizmo color */
1328 float bright = U.rvibright / 15.0f;
1330 unsigned char col[3];
1331 unsigned char gridcol[3];
1338 BIF_GetThemeColor3ubv(TH_GRID, gridcol);
1341 vec[0] = vec[3] = 1;
1342 vec[1] = vec[2] = 0;
1343 QuatMulVecf(G.vd->viewquat, vec);
1345 make_axis_color(gridcol, col, 'x');
1346 rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v);
1347 s = s<0.5 ? s+0.5 : 1.0;
1349 v = (v<1.0-(bright) ? v+bright : 1.0);
1350 hsv_to_rgb(h, s, v, colf, colf+1, colf+2);
1355 fdrawline(start, start + ydisp, start + dx, start + dy + ydisp);
1356 if (fabs(dx) > toll || fabs(dy) > toll) {
1357 glRasterPos2i(start + dx + 2, start + dy + ydisp + 2);
1358 BMF_DrawString(G.fonts, "x");
1362 vec[1] = vec[3] = 1;
1363 vec[0] = vec[2] = 0;
1364 QuatMulVecf(G.vd->viewquat, vec);
1366 make_axis_color(gridcol, col, 'y');
1367 rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v);
1368 s = s<0.5 ? s+0.5 : 1.0;
1370 v = (v<1.0-(bright) ? v+bright : 1.0);
1371 hsv_to_rgb(h, s, v, colf, colf+1, colf+2);
1376 fdrawline(start, start + ydisp, start + dx, start + dy + ydisp);
1377 if (fabs(dx) > toll || fabs(dy) > toll) {
1378 glRasterPos2i(start + dx + 2, start + dy + ydisp + 2);
1379 BMF_DrawString(G.fonts, "y");
1383 vec[2] = vec[3] = 1;
1384 vec[1] = vec[0] = 0;
1385 QuatMulVecf(G.vd->viewquat, vec);
1387 make_axis_color(gridcol, col, 'z');
1388 rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v);
1389 s = s<0.5 ? s+0.5 : 1.0;
1391 v = (v<1.0-(bright) ? v+bright : 1.0);
1392 hsv_to_rgb(h, s, v, colf, colf+1, colf+2);
1397 fdrawline(start, start + ydisp, start + dx, start + dy + ydisp);
1398 if (fabs(dx) > toll || fabs(dy) > toll) {
1399 glRasterPos2i(start + dx + 2, start + dy + ydisp + 2);
1400 BMF_DrawString(G.fonts, "z");
1405 static void draw_view_icon(void)
1409 if(G.vd->view==7) icon= ICON_AXIS_TOP;
1410 else if(G.vd->view==1) icon= ICON_AXIS_FRONT;
1411 else if(G.vd->view==3) icon= ICON_AXIS_SIDE;
1415 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1417 BIF_icon_draw(5.0, 5.0, icon);
1419 glBlendFunc(GL_ONE, GL_ZERO);
1420 glDisable(GL_BLEND);
1423 static void draw_viewport_name(ScrArea *sa)
1427 switch(G.vd->view) {
1429 name = (G.vd->flag2 & V3D_OPP_DIRECTION_NAME) ? "Back" : "Front";
1432 name = (G.vd->flag2 & V3D_OPP_DIRECTION_NAME) ? "Left" : "Right";
1435 name = (G.vd->flag2 & V3D_OPP_DIRECTION_NAME) ? "Bottom" : "Top";
1438 name = G.vd->persp==V3D_PERSP_USE_THE_CAMERA ? "Camera" : "User";
1442 BIF_ThemeColor(TH_TEXT_HI);
1443 glRasterPos2i(10, sa->winy-20);
1444 BMF_DrawString(G.fonts, name);
1448 /* ******************* view3d space & buttons ************** */
1450 static void view3d_change_bgpic_ima(View3D *v3d, Image *newima) {
1451 if (v3d->bgpic && v3d->bgpic->ima!=newima) {
1453 id_us_plus((ID*) newima);
1454 if (v3d->bgpic->ima)
1455 v3d->bgpic->ima->id.us--;
1456 v3d->bgpic->ima= newima;
1458 if(v3d->bgpic->rect) MEM_freeN(v3d->bgpic->rect);
1459 v3d->bgpic->rect= NULL;
1461 allqueue(REDRAWVIEW3D, 0);
1464 static void view3d_change_bgpic_tex(View3D *v3d, Tex *newtex) {
1465 if (v3d->bgpic && v3d->bgpic->tex!=newtex) {
1467 id_us_plus((ID*) newtex);
1468 if (v3d->bgpic->tex)
1469 v3d->bgpic->tex->id.us--;
1470 v3d->bgpic->tex= newtex;
1472 allqueue(REDRAWVIEW3D, 0);
1476 static void load_bgpic_image(char *name)
1481 areawinset(curarea->win);
1483 if(vd==0 || vd->bgpic==0) return;
1485 ima= add_image(name);
1487 if(vd->bgpic->ima) {
1488 vd->bgpic->ima->id.us--;
1490 vd->bgpic->ima= ima;
1492 free_image_buffers(ima); /* force read again */
1495 allqueue(REDRAWVIEW3D, 0);
1499 /* this one assumes there is only one global active object in blender... (for object panel) */
1500 static float ob_eul[4]; // used for quat too....
1501 static float ob_scale[3]; // need temp space due to linked values
1502 static float ob_dims[3];
1503 static short link_scale = 0;
1505 /* this one assumes there is only one editmode in blender... (for object panel) */
1506 static float ve_median[5];
1508 /* is used for both read and write... */
1509 static void v3d_editvertex_buts(uiBlock *block, Object *ob, float lim)
1511 static int curdef=0;
1512 static float *defweightp= NULL;
1513 EditMesh *em = G.editMesh;
1514 EditVert *eve, *evedef=NULL;
1517 int tot, totw, totweight, totedge;
1520 median[0]= median[1]= median[2]= median[3]= median[4]= 0.0;
1521 tot= totw= totweight= totedge= 0;
1524 if(ob->type==OB_MESH) {
1525 eve= em->verts.first;
1530 VecAddf(median, median, eve->co);
1534 eed= em->edges.first;
1536 if((eed->f & SELECT)) {
1538 median[3]+= eed->crease;
1542 /* check for defgroups */
1543 if(tot==1 && evedef->totweight) {
1545 int i, max=1, init=1;
1548 for (i=0; i<evedef->totweight; i++){
1549 dg = BLI_findlink (&ob->defbase, evedef->dw[i].def_nr);
1551 max+= sprintf(str, "%s %%x%d|", dg->name, evedef->dw[i].def_nr);
1552 if(max<320) strcat(defstr, str);
1554 else printf("oh no!\n");
1555 if(curdef==evedef->dw[i].def_nr) {
1557 defweightp= &evedef->dw[i].weight;
1561 if(init) { // needs new initialized
1562 curdef= evedef->dw[0].def_nr;
1563 defweightp= &evedef->dw[0].weight;
1567 else if(ob->type==OB_CURVE || ob->type==OB_SURF) {
1568 extern ListBase editNurb; /* editcurve.c */
1576 if((nu->type & 7)==1) {
1581 VecAddf(median, median, bezt->vec[1]);
1583 median[4]+= bezt->weight;
1588 VecAddf(median, median, bezt->vec[0]);
1592 VecAddf(median, median, bezt->vec[2]);
1601 a= nu->pntsu*nu->pntsv;
1604 VecAddf(median, median, bp->vec);
1605 median[3]+= bp->vec[3];
1608 median[4]+= bp->weight;
1617 else if(ob->type==OB_LATTICE) {
1621 a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
1624 if(bp->f1 & SELECT) {
1625 VecAddf(median, median, bp->vec);
1627 median[4]+= bp->weight;
1636 median[0] /= (float)tot;
1637 median[1] /= (float)tot;
1638 median[2] /= (float)tot;
1639 if(totedge) median[3] /= (float)totedge;
1640 else if(totw) median[3] /= (float)totw;
1641 if(totweight) median[4] /= (float)totweight;
1643 if(G.vd->flag & V3D_GLOBAL_STATS)
1644 Mat4MulVecfl(ob->obmat, median);
1646 if(block) { // buttons
1648 uiBlockBeginAlign(block);
1649 uiDefButBitS(block, TOG, V3D_GLOBAL_STATS, REDRAWVIEW3D, "Global", 160, 150, 70, 19, &G.vd->flag, 0, 0, 0, 0, "Displays global values");
1650 uiDefButBitS(block, TOGN, V3D_GLOBAL_STATS, REDRAWVIEW3D, "Local", 230, 150, 70, 19, &G.vd->flag, 0, 0, 0, 0, "Displays local values");
1652 memcpy(ve_median, median, sizeof(ve_median));
1654 uiBlockBeginAlign(block);
1656 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Vertex X:", 10, 110, 290, 19, &(ve_median[0]), -lim, lim, 10, 3, "");
1657 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Vertex Y:", 10, 90, 290, 19, &(ve_median[1]), -lim, lim, 10, 3, "");
1658 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Vertex Z:", 10, 70, 290, 19, &(ve_median[2]), -lim, lim, 10, 3, "");
1660 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Vertex W:", 10, 50, 290, 19, &(ve_median[3]), 0.01, 100.0, 10, 3, "");
1661 uiBlockEndAlign(block);
1664 uiDefBut(block, LABEL, 1, "Vertex Deform Groups", 10, 40, 290, 20, NULL, 0.0, 0.0, 0, 0, "");
1666 uiBlockBeginAlign(block);
1667 uiDefButF(block, NUM, B_NOP, "Weight:", 10, 20, 150, 19, defweightp, 0.0f, 1.0f, 10, 3, "Weight value");
1668 uiDefButI(block, MENU, REDRAWVIEW3D, defstr, 160, 20, 140, 19, &curdef, 0.0, 0.0, 0, 0, "Current Vertex Group");
1669 uiBlockEndAlign(block);
1672 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:", 10, 20, 290, 19, &(ve_median[4]), 0.0, 1.0, 10, 3, "");
1676 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median X:", 10, 110, 290, 19, &(ve_median[0]), -lim, lim, 10, 3, "");
1677 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median Y:", 10, 90, 290, 19, &(ve_median[1]), -lim, lim, 10, 3, "");
1678 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median Z:", 10, 70, 290, 19, &(ve_median[2]), -lim, lim, 10, 3, "");
1680 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median W:", 10, 50, 290, 19, &(ve_median[3]), 0.01, 100.0, 10, 3, "");
1681 uiBlockEndAlign(block);
1683 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:", 10, 20, 290, 19, &(ve_median[4]), 0.0, 1.0, 10, 3, "Weight is used for SoftBody Goal");
1687 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Crease W:", 10, 30, 290, 19, &(ve_median[3]), 0.0, 1.0, 10, 3, "");
1689 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median Crease W:", 10, 30, 290, 19, &(ve_median[3]), 0.0, 1.0, 10, 3, "");
1694 if(G.vd->flag & V3D_GLOBAL_STATS) {
1695 Mat4Invert(ob->imat, ob->obmat);
1696 Mat4MulVecfl(ob->imat, median);
1697 Mat4MulVecfl(ob->imat, ve_median);
1699 VecSubf(median, ve_median, median);
1700 median[3]= ve_median[3]-median[3];
1701 median[4]= ve_median[4]-median[4];
1703 if(ob->type==OB_MESH) {
1706 eve= em->verts.first;
1709 VecAddf(eve->co, eve->co, median);
1714 /* calculate the differences to squeeze a range smaller when values are close to 1 or 0 */
1715 /* this way you can edit a median value which is applied on clipped values :) */
1718 for(eed= em->edges.first; eed; eed= eed->next) {
1719 if(eed->f & SELECT) {
1720 if(max < ABS(eed->crease-ve_median[3])) max= ABS(eed->crease-ve_median[3]);
1724 if(ve_median[3]> 0.5) diffac= (1.0-ve_median[3])/max;
1725 else diffac= (ve_median[3])/max;
1726 if(diffac>1.0) diffac= 1.0;
1730 for(eed= em->edges.first; eed; eed= eed->next) {
1731 if(eed->f & SELECT) {
1732 eed->crease+= median[3];
1733 eed->crease= ve_median[3] + diffac*(eed->crease-ve_median[3]);
1735 CLAMP(eed->crease, 0.0, 1.0);
1739 recalc_editnormals();
1741 else if(ob->type==OB_CURVE || ob->type==OB_SURF) {
1742 extern ListBase editNurb; /* editcurve.c */
1750 if((nu->type & 7)==1) {
1755 VecAddf(bezt->vec[0], bezt->vec[0], median);
1756 VecAddf(bezt->vec[1], bezt->vec[1], median);
1757 VecAddf(bezt->vec[2], bezt->vec[2], median);
1758 bezt->weight+= median[4];
1762 VecAddf(bezt->vec[0], bezt->vec[0], median);
1765 VecAddf(bezt->vec[2], bezt->vec[2], median);
1773 a= nu->pntsu*nu->pntsv;
1776 VecAddf(bp->vec, bp->vec, median);
1777 bp->vec[3]+= median[3];
1778 bp->weight+= median[4];
1784 testhandlesNurb(nu); /* test for bezier too */
1789 else if(ob->type==OB_LATTICE) {
1793 a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
1796 if(bp->f1 & SELECT) {
1797 VecAddf(bp->vec, bp->vec, median);
1798 bp->weight+= median[4];
1804 BIF_undo_push("Transform properties");
1808 /* assumes armature active */
1809 static void validate_bonebutton_cb(void *bonev, void *namev)
1813 if(ob && ob->type==OB_ARMATURE) {
1815 char oldname[32], newname[32];
1817 /* need to be on the stack */
1818 BLI_strncpy(newname, bone->name, 32);
1819 BLI_strncpy(oldname, (char *)namev, 32);
1821 BLI_strncpy(bone->name, oldname, 32);
1823 armature_bone_rename(ob->data, oldname, newname); // editarmature.c
1824 allqueue(REDRAWALL, 0);
1829 static void v3d_posearmature_buts(uiBlock *block, Object *ob, float lim)
1833 bPoseChannel *pchan;
1836 arm = get_armature(OBACT);
1837 if (!arm || !ob->pose) return;
1839 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1841 if(bone && (bone->flag & BONE_ACTIVE) && (bone->layer & arm->layer))
1846 but= uiDefBut(block, TEX, B_DIFF, "Bone:", 160, 140, 140, 19, bone->name, 1, 31, 0, 0, "");
1847 uiButSetFunc(but, validate_bonebutton_cb, bone, NULL);
1849 QuatToEul(pchan->quat, ob_eul);
1850 ob_eul[0]*= 180.0/M_PI;
1851 ob_eul[1]*= 180.0/M_PI;
1852 ob_eul[2]*= 180.0/M_PI;
1854 uiBlockBeginAlign(block);
1855 uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCX, REDRAWVIEW3D, ICON_UNLOCKED, 10,140,20,19, &(pchan->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1856 uiDefButF(block, NUM, B_ARMATUREPANEL2, "LocX:", 30, 140, 120, 19, pchan->loc, -lim, lim, 100, 3, "");
1857 uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCY, REDRAWVIEW3D, ICON_UNLOCKED, 10,120,20,19, &(pchan->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1858 uiDefButF(block, NUM, B_ARMATUREPANEL2, "LocY:", 30, 120, 120, 19, pchan->loc+1, -lim, lim, 100, 3, "");
1859 uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCZ, REDRAWVIEW3D, ICON_UNLOCKED, 10,100,20,19, &(pchan->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1860 uiDefButF(block, NUM, B_ARMATUREPANEL2, "locZ:", 30, 100, 120, 19, pchan->loc+2, -lim, lim, 100, 3, "");
1862 uiBlockBeginAlign(block);
1863 uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTX, REDRAWVIEW3D, ICON_UNLOCKED, 10,70,20,19, &(pchan->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1864 uiDefButF(block, NUM, B_ARMATUREPANEL3, "RotX:", 30, 70, 120, 19, ob_eul, -1000.0, 1000.0, 100, 3, "");
1865 uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTY, REDRAWVIEW3D, ICON_UNLOCKED, 10,50,20,19, &(pchan->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1866 uiDefButF(block, NUM, B_ARMATUREPANEL3, "RotY:", 30, 50, 120, 19, ob_eul+1, -1000.0, 1000.0, 100, 3, "");
1867 uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTZ, REDRAWVIEW3D, ICON_UNLOCKED, 10,30,20,19, &(pchan->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1868 uiDefButF(block, NUM, B_ARMATUREPANEL3, "RotZ:", 30, 30, 120, 19, ob_eul+2, -1000.0, 1000.0, 100, 3, "");
1870 uiBlockBeginAlign(block);
1871 uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEX, REDRAWVIEW3D, ICON_UNLOCKED, 160,70,20,19, &(pchan->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1872 uiDefButF(block, NUM, B_ARMATUREPANEL2, "ScaleX:", 180, 70, 120, 19, pchan->size, -lim, lim, 10, 3, "");
1873 uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEY, REDRAWVIEW3D, ICON_UNLOCKED, 160,50,20,19, &(pchan->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1874 uiDefButF(block, NUM, B_ARMATUREPANEL2, "ScaleY:", 180, 50, 120, 19, pchan->size+1, -lim, lim, 10, 3, "");
1875 uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEZ, REDRAWVIEW3D, ICON_UNLOCKED, 160,30,20,19, &(pchan->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
1876 uiDefButF(block, NUM, B_ARMATUREPANEL2, "ScaleZ:", 180, 30, 120, 19, pchan->size+2, -lim, lim, 10, 3, "");
1877 uiBlockEndAlign(block);
1880 static void v3d_editarmature_buts(uiBlock *block, Object *ob, float lim)
1882 bArmature *arm= G.obedit->data;
1886 ebone= G.edbo.first;
1888 for (ebone = G.edbo.first; ebone; ebone=ebone->next){
1889 if ((ebone->flag & BONE_ACTIVE) && (ebone->layer & arm->layer))
1896 but= uiDefBut(block, TEX, B_DIFF, "Bone:", 160, 150, 140, 19, ebone->name, 1, 31, 0, 0, "");
1897 uiButSetFunc(but, validate_editbonebutton_cb, ebone, NULL);
1899 uiBlockBeginAlign(block);
1900 uiDefButF(block, NUM, B_ARMATUREPANEL1, "RootX:", 10, 70, 140, 19, ebone->head, -lim, lim, 10, 3, "");
1901 uiDefButF(block, NUM, B_ARMATUREPANEL1, "RootY:", 10, 50, 140, 19, ebone->head+1, -lim, lim, 10, 3, "");
1902 uiDefButF(block, NUM, B_ARMATUREPANEL1, "RootZ:", 10, 30, 140, 19, ebone->head+2, -lim, lim, 10, 3, "");
1903 uiBlockBeginAlign(block);
1904 uiDefButF(block, NUM, B_ARMATUREPANEL1, "TipX:", 160, 70, 140, 19, ebone->tail, -lim, lim, 10, 3, "");
1905 uiDefButF(block, NUM, B_ARMATUREPANEL1, "TipY:", 160, 50, 140, 19, ebone->tail+1, -lim, lim, 10, 3, "");
1906 uiDefButF(block, NUM, B_ARMATUREPANEL1, "TipZ:", 160, 30, 140, 19, ebone->tail+2, -lim, lim, 10, 3, "");
1907 uiBlockEndAlign(block);
1908 ob_eul[0]= 180.0*ebone->roll/M_PI;
1909 uiDefButF(block, NUM, B_ARMATUREPANEL1, "Roll:", 10, 100, 140, 19, ob_eul, -lim, lim, 1000, 3, "");
1912 uiBlockBeginAlign(block);
1913 uiDefButF(block, NUM, B_ARMATUREPANEL1, "TipRadius:", 10, 150, 140, 19, &ebone->rad_tail, 0, lim, 10, 3, "");
1914 if (ebone->parent && ebone->flag & BONE_CONNECTED )
1915 uiDefButF(block, NUM, B_ARMATUREPANEL1, "HeadRadius:", 10, 130, 140, 19, &ebone->parent->rad_tail, 0, lim, 10, 3, "");
1917 uiDefButF(block, NUM, B_ARMATUREPANEL1, "HeadRadius:", 10, 130, 140, 19, &ebone->rad_head, 0, lim, 10, 3, "");
1918 uiBlockEndAlign(block);
1921 static void v3d_editmetaball_buts(uiBlock *block, Object *ob, float lim)
1923 extern MetaElem *lastelem;
1926 uiBlockBeginAlign(block);
1927 uiDefButF(block, NUM, B_RECALCMBALL, "LocX:", 10, 70, 140, 19, &lastelem->x, -lim, lim, 100, 3, "");
1928 uiDefButF(block, NUM, B_RECALCMBALL, "LocY:", 10, 50, 140, 19, &lastelem->y, -lim, lim, 100, 3, "");
1929 uiDefButF(block, NUM, B_RECALCMBALL, "LocZ:", 10, 30, 140, 19, &lastelem->z, -lim, lim, 100, 3, "");
1931 uiBlockBeginAlign(block);
1932 if(lastelem->type!=MB_BALL)
1933 uiDefButF(block, NUM, B_RECALCMBALL, "dx:", 160, 70, 140, 19, &lastelem->expx, 0, lim, 100, 3, "");
1934 if((lastelem->type!=MB_BALL) && (lastelem->type!=MB_TUBE))
1935 uiDefButF(block, NUM, B_RECALCMBALL, "dy:", 160, 50, 140, 19, &lastelem->expy, 0, lim, 100, 3, "");
1936 if((lastelem->type==MB_ELIPSOID) || (lastelem->type==MB_CUBE))
1937 uiDefButF(block, NUM, B_RECALCMBALL, "dz:", 160, 30, 140, 19, &lastelem->expz, 0, lim, 100, 3, "");
1939 uiBlockEndAlign(block);
1941 uiDefButF(block, NUM, B_RECALCMBALL, "Stiffness:", 10, 100, 140, 19, &lastelem->s, 0, lim, 100, 3, "");
1945 void do_viewbuts(unsigned short event)
1957 if(vd->bgpic && vd->bgpic->ima) name= vd->bgpic->ima->name;
1960 if(G.qual==LR_CTRLKEY)
1961 activate_imageselect(FILE_SPECIAL, "Select Image", name, load_bgpic_image);
1963 activate_fileselect(FILE_SPECIAL, "Select Image", name, load_bgpic_image);
1967 if(vd->bgpic && vd->bgpic->rect) setalpha_bgpic(vd->bgpic);
1968 addqueue(curarea->win, REDRAW, 1);
1973 if (vd->menunr==-2) {
1974 activate_databrowse((ID*) vd->bgpic->ima, ID_IM, 0, B_BGPICBROWSE, &vd->menunr, do_viewbuts);
1975 } else if (vd->menunr>0) {
1976 Image *newima= (Image*) BLI_findlink(&G.main->image, vd->menunr-1);
1979 view3d_change_bgpic_ima(vd, newima);
1986 view3d_change_bgpic_ima(vd, NULL);
1991 if (vd->texnr==-2) {
1992 activate_databrowse((ID*) vd->bgpic->tex, ID_TE, 0, B_BGPICTEX, &vd->texnr, do_viewbuts);
1993 } else if (vd->texnr>0) {
1994 Tex *newtex= (Tex*) BLI_findlink(&G.main->tex, vd->texnr-1);
1997 view3d_change_bgpic_tex(vd, newtex);
2002 case B_BGPICTEXCLEAR:
2004 view3d_change_bgpic_tex(vd, NULL);
2008 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2009 allqueue(REDRAWVIEW3D, 1);
2012 case B_OBJECTPANELROT:
2014 ob->rot[0]= M_PI*ob_eul[0]/180.0;
2015 ob->rot[1]= M_PI*ob_eul[1]/180.0;
2016 ob->rot[2]= M_PI*ob_eul[2]/180.0;
2017 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2018 allqueue(REDRAWVIEW3D, 1);
2022 case B_OBJECTPANELSCALE:
2024 float ratio, tmp, max = 0.0;
2027 /* figure out which axis changed */
2029 max = fabs(ob_scale[0] - ob->size[0]);
2030 tmp = fabs(ob_scale[1] - ob->size[1]);
2035 tmp = fabs(ob_scale[2] - ob->size[2]);
2041 if (ob->size[axis] != ob_scale[axis]) {
2043 if (fabs(ob->size[axis]) > FLT_EPSILON) {
2044 ratio = ob_scale[axis] / ob->size[axis];
2045 ob->size[0] *= ratio;
2046 ob->size[1] *= ratio;
2047 ob->size[2] *= ratio;
2050 ob->size[axis] = ob_scale[axis];
2052 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2053 allqueue(REDRAWVIEW3D, 1);
2058 case B_OBJECTPANELDIMS:
2059 bb= object_get_boundbox(ob);
2061 float old_dims[3], scale[3], ratio, len[3];
2064 Mat4ToSize(ob->obmat, scale);
2066 len[0] = bb->vec[4][0] - bb->vec[0][0];
2067 len[1] = bb->vec[2][1] - bb->vec[0][1];
2068 len[2] = bb->vec[1][2] - bb->vec[0][2];
2070 old_dims[0] = fabs(scale[0]) * len[0];
2071 old_dims[1] = fabs(scale[1]) * len[1];
2072 old_dims[2] = fabs(scale[2]) * len[2];
2074 /* for each axis changed */
2075 for (axis = 0; axis<3; axis++) {
2076 if (fabs(old_dims[axis] - ob_dims[axis]) > 0.0001) {
2077 if (old_dims[axis] > 0.0) {
2078 ratio = ob_dims[axis] / old_dims[axis];
2080 ob->size[0] *= ratio;
2081 ob->size[1] *= ratio;
2082 ob->size[2] *= ratio;
2086 ob->size[axis] *= ratio;
2090 if (len[axis] > 0) {
2091 ob->size[axis] = ob_dims[axis] / len[axis];
2097 /* prevent multiple B_OBJECTPANELDIMS events to keep scaling, cycling with TAB on buttons can cause that */
2098 VECCOPY(ob_dims, old_dims);
2100 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2101 allqueue(REDRAWVIEW3D, 1);
2105 case B_OBJECTPANELMEDIAN:
2107 v3d_editvertex_buts(NULL, ob, 1.0);
2108 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2109 allqueue(REDRAWVIEW3D, 1);
2112 case B_OBJECTPANELPARENT:
2114 if(ob->id.lib || test_parent_loop(ob->parent, ob) )
2117 DAG_scene_sort(G.scene);
2118 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2120 allqueue(REDRAWVIEW3D, 1);
2121 allqueue(REDRAWBUTSOBJECT, 0);
2125 case B_ARMATUREPANEL1:
2127 bArmature *arm= G.obedit->data;
2128 EditBone *ebone, *child;
2130 for (ebone = G.edbo.first; ebone; ebone=ebone->next){
2131 if ((ebone->flag & BONE_ACTIVE) && (ebone->layer & arm->layer))
2135 ebone->roll= M_PI*ob_eul[0]/180.0;
2136 // Update our parent
2137 if (ebone->parent && ebone->flag & BONE_CONNECTED){
2138 VECCOPY (ebone->parent->tail, ebone->head);
2141 // Update our children if necessary
2142 for (child = G.edbo.first; child; child=child->next){
2143 if (child->parent == ebone && (child->flag & BONE_CONNECTED)){
2144 VECCOPY (child->head, ebone->tail);
2147 if(arm->flag & ARM_MIRROR_EDIT) {
2148 EditBone *eboflip= armature_bone_get_mirrored(ebone);
2150 eboflip->roll= -ebone->roll;
2151 eboflip->head[0]= -ebone->head[0];
2152 eboflip->tail[0]= -ebone->tail[0];
2154 // Update our parent
2155 if (eboflip->parent && eboflip->flag & BONE_CONNECTED){
2156 VECCOPY (eboflip->parent->tail, eboflip->head);
2159 // Update our children if necessary
2160 for (child = G.edbo.first; child; child=child->next){
2161 if (child->parent == eboflip && (child->flag & BONE_CONNECTED)){
2162 VECCOPY (child->head, eboflip->tail);
2168 allqueue(REDRAWVIEW3D, 1);
2172 case B_ARMATUREPANEL3: // rotate button on channel
2175 bPoseChannel *pchan;
2178 arm = get_armature(OBACT);
2179 if (!arm || !ob->pose) return;
2181 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
2183 if(bone && (bone->flag & BONE_ACTIVE) && (bone->layer & arm->layer))
2188 ob_eul[0]*= M_PI/180.0;
2189 ob_eul[1]*= M_PI/180.0;
2190 ob_eul[2]*= M_PI/180.0;
2191 EulToQuat(ob_eul, pchan->quat);
2193 /* no break, pass on */
2194 case B_ARMATUREPANEL2:
2196 ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
2197 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2198 allqueue(REDRAWVIEW3D, 1);
2205 static void view3d_panel_object(short cntrl) // VIEW3D_HANDLER_OBJECT
2211 static char hexcol[128];
2213 if(ob==NULL) return;
2215 block= uiNewBlock(&curarea->uiblocks, "view3d_panel_object", UI_EMBOSS, UI_HELV, curarea->win);
2216 uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | cntrl);
2217 uiSetPanelHandler(VIEW3D_HANDLER_OBJECT); // for close and esc
2219 /* (ton) can't use the rename trick for paint... panel names and settings are stored in the files and
2220 used to find previous locations when re-open. This causes flipping */
2222 if(uiNewPanel(curarea, block, "Transform Properties", "View3d", 10, 230, 318, 204)==0) return;
2224 if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
2226 if(G.f & (G_VERTEXPAINT|G_FACESELECT|G_TEXTUREPAINT|G_WEIGHTPAINT)) {
2227 uiBlockSetFlag(block, UI_BLOCK_FRONTBUFFER); // force old style frontbuffer draw
2230 bt= uiDefBut(block, TEX, B_IDNAME, "OB: ", 10,180,140,20, ob->id.name+2, 0.0, 19.0, 0, 0, "");
2231 uiButSetFunc(bt, test_idbutton_cb, ob->id.name, NULL);
2233 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_OBJECTPANELPARENT, "Par:", 160, 180, 140, 20, &ob->parent, "Parent Object");
2236 lim= 10000.0f*MAX2(1.0, G.vd->grid);
2239 if(ob->type==OB_ARMATURE) v3d_editarmature_buts(block, ob, lim);
2240 if(ob->type==OB_MBALL) v3d_editmetaball_buts(block, ob, lim);
2241 else v3d_editvertex_buts(block, ob, lim);
2243 else if(ob->flag & OB_POSEMODE) {
2244 v3d_posearmature_buts(block, ob, lim);
2246 else if(G.f & (G_VERTEXPAINT|G_TEXTUREPAINT)) {
2247 extern VPaint Gvp; /* from vpaint */
2248 static float hsv[3], old[3]; // used as temp mem for picker
2249 uiBlockPickerButtons(block, &Gvp.r, hsv, old, hexcol, 'f', REDRAWBUTSEDIT); /* 'f' is for floating panel */
2252 BoundBox *bb = NULL;
2254 uiBlockBeginAlign(block);
2255 uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCX, REDRAWVIEW3D, ICON_UNLOCKED, 10,150,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
2256 uiDefButF(block, NUM, B_OBJECTPANEL, "LocX:", 30, 150, 120, 19, &(ob->loc[0]), -lim, lim, 100, 3, "");
2257 uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCY, REDRAWVIEW3D, ICON_UNLOCKED, 10,130,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
2258 uiDefButF(block, NUM, B_OBJECTPANEL, "LocY:", 30, 130, 120, 19, &(ob->loc[1]), -lim, lim, 100, 3, "");
2259 uiDefIconButBitS(block, ICONTOG, OB_LOCK_LOCZ, REDRAWVIEW3D, ICON_UNLOCKED, 10,110,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
2260 uiDefButF(block, NUM, B_OBJECTPANEL, "LocZ:", 30, 110, 120, 19, &(ob->loc[2]), -lim, lim, 100, 3, "");
2262 ob_eul[0]= 180.0*ob->rot[0]/M_PI;
2263 ob_eul[1]= 180.0*ob->rot[1]/M_PI;
2264 ob_eul[2]= 180.0*ob->rot[2]/M_PI;
2266 uiBlockBeginAlign(block);
2267 uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTX, REDRAWVIEW3D, ICON_UNLOCKED, 160,150,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
2268 uiDefButF(block, NUM, B_OBJECTPANELROT, "RotX:", 180, 150, 120, 19, &(ob_eul[0]), -lim, lim, 1000, 3, "");
2269 uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTY, REDRAWVIEW3D, ICON_UNLOCKED, 160,130,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
2270 uiDefButF(block, NUM, B_OBJECTPANELROT, "RotY:", 180, 130, 120, 19, &(ob_eul[1]), -lim, lim, 1000, 3, "");
2271 uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTZ, REDRAWVIEW3D, ICON_UNLOCKED, 160,110,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
2272 uiDefButF(block, NUM, B_OBJECTPANELROT, "RotZ:", 180, 110, 120, 19, &(ob_eul[2]), -lim, lim, 1000, 3, "");
2274 ob_scale[0]= ob->size[0];
2275 ob_scale[1]= ob->size[1];
2276 ob_scale[2]= ob->size[2];
2278 uiBlockBeginAlign(block);
2279 uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEX, REDRAWVIEW3D, ICON_UNLOCKED, 10,80,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
2280 uiDefButF(block, NUM, B_OBJECTPANELSCALE, "ScaleX:", 30, 80, 120, 19, &(ob_scale[0]), -lim, lim, 10, 3, "");
2281 uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEY, REDRAWVIEW3D, ICON_UNLOCKED, 10,60,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
2282 uiDefButF(block, NUM, B_OBJECTPANELSCALE, "ScaleY:", 30, 60, 120, 19, &(ob_scale[1]), -lim, lim, 10, 3, "");
2283 uiDefIconButBitS(block, ICONTOG, OB_LOCK_SCALEZ, REDRAWVIEW3D, ICON_UNLOCKED, 10,40,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
2284 uiDefButF(block, NUM, B_OBJECTPANELSCALE, "ScaleZ:", 30, 40, 120, 19, &(ob_scale[2]), -lim, lim, 10, 3, "");
2285 uiBlockEndAlign(block);
2287 uiDefButS(block, TOG, REDRAWVIEW3D, "Link Scale", 10, 10, 140, 19, &(link_scale), 0, 1, 0, 0, "Scale values vary proportionally in all directions");
2289 bb= object_get_boundbox(ob);
2293 Mat4ToSize(ob->obmat, scale);
2295 ob_dims[0] = fabs(scale[0]) * (bb->vec[4][0] - bb->vec[0][0]);
2296 ob_dims[1] = fabs(scale[1]) * (bb->vec[2][1] - bb->vec[0][1]);
2297 ob_dims[2] = fabs(scale[2]) * (bb->vec[1][2] - bb->vec[0][2]);
2299 uiBlockBeginAlign(block);
2300 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "DimX:", 160, 80, 140, 19, &(ob_dims[0]), 0.0, lim, 10, 3, "Manipulate bounding box size");
2301 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "DimY:", 160, 60, 140, 19, &(ob_dims[1]), 0.0, lim, 10, 3, "Manipulate bounding box size");
2302 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "DimZ:", 160, 40, 140, 19, &(ob_dims[2]), 0.0, lim, 10, 3, "Manipulate bounding box size");
2304 uiBlockEndAlign(block);
2310 static void view3d_panel_background(short cntrl) // VIEW3D_HANDLER_BACKGROUND
2319 block= uiNewBlock(&curarea->uiblocks, "view3d_panel_background", UI_EMBOSS, UI_HELV, curarea->win);
2320 uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | cntrl);
2321 uiSetPanelHandler(VIEW3D_HANDLER_BACKGROUND); // for close and esc
2322 if(uiNewPanel(curarea, block, "Background Image", "View3d", 340, 10, 318, 204)==0) return;
2324 if(G.f & (G_VERTEXPAINT|G_FACESELECT|G_TEXTUREPAINT|G_WEIGHTPAINT)) {
2325 uiBlockSetFlag(block, UI_BLOCK_FRONTBUFFER); // force old style frontbuffer draw
2328 if(vd->flag & V3D_DISPBGPIC) {
2330 vd->bgpic= MEM_callocN(sizeof(BGpic), "bgpic");
2331 vd->bgpic->size= 5.0;
2332 vd->bgpic->blend= 0.5;
2336 uiDefButBitS(block, TOG, V3D_DISPBGPIC, REDRAWVIEW3D, "Use Background Image", 0, 162, 200, 20, &vd->flag, 0, 0, 0, 0, "Display an image in the background of the 3D View");
2338 uiDefBut(block, LABEL, 1, " ", 206, 162, 84, 20, NULL, 0.0, 0.0, 0, 0, "");
2341 if(vd->flag & V3D_DISPBGPIC) {
2343 /* Background Image */
2344 uiDefBut(block, LABEL, 1, "Image:", 0, 128, 76, 19, NULL, 0.0, 0.0, 0, 0, "");
2346 uiBlockBeginAlign(block);
2347 uiDefIconBut(block, BUT, B_LOADBGPIC, ICON_FILESEL, 90, 128, 20, 20, 0, 0, 0, 0, 0, "Open a new background image");
2349 id= (ID *)vd->bgpic->ima;
2350 IDnames_to_pupstring(&strp, NULL, NULL, &(G.main->image), id, &(vd->menunr));
2353 uiDefButS(block, MENU, B_BGPICBROWSE, strp, 110, 128, 20, 20, &(vd->menunr), 0, 0, 0, 0, "Select a background image");
2355 if(vd->bgpic->ima) {
2356 uiDefBut(block, TEX, 0,"BG: ", 130, 128, 140, 20, &vd->bgpic->ima->name,0.0,100.0, 0, 0, "The currently selected background image");
2357 uiDefIconBut(block, BUT, B_BGPICCLEAR, ICON_X, 270, 128, 20, 20, 0, 0, 0, 0, 0, "Remove background image link");
2359 uiBlockEndAlign(block);
2361 uiBlockEndAlign(block);
2366 /* Background texture */
2367 uiDefBut(block, LABEL, 1, "Texture:", 0, 100, 76, 19, NULL, 0.0, 0.0, 0, 0, "");
2369 id= (ID *)vd->bgpic->tex;
2370 IDnames_to_pupstring(&strp, NULL, NULL, &(G.main->tex), id, &(vd->texnr));
2372 uiBlockBeginAlign(block);
2373 uiDefButS(block, MENU, B_BGPICTEX, strp, 90, 100, 20,20, &(vd->texnr), 0, 0, 0, 0, "Select a texture to use as an animated background image");
2377 uiDefBut(block, TEX, B_IDNAME, "TE:", 110, 100, 160, 20, id->name+2, 0.0, 18.0, 0, 0, "");
2378 uiDefIconBut(block, BUT, B_BGPICTEXCLEAR, ICON_X, 270, 100, 20, 20, 0, 0, 0, 0, 0, "Remove background texture link");
2379 uiBlockEndAlign(block);
2381 uiBlockEndAlign(block);
2384 uiDefButF(block, NUMSLI, B_BLENDBGPIC, "Blend:", 0, 60 , 290, 19, &vd->bgpic->blend, 0.0,1.0, 0, 0, "Set the transparency of the background image");
2386 uiDefButF(block, NUM, REDRAWVIEW3D, "Size:", 0, 28, 140, 19, &vd->bgpic->size, 0.1, 250.0*vd->grid, 100, 0, "Set the size (width) of the background image");
2388 uiDefButF(block, NUM, REDRAWVIEW3D, "X Offset:", 0, 6, 140, 19, &vd->bgpic->xof, -250.0*vd->grid,250.0*vd->grid, 10, 2, "Set the horizontal offset of the background image");
2389 uiDefButF(block, NUM, REDRAWVIEW3D, "Y Offset:", 150, 6, 140, 19, &vd->bgpic->yof, -250.0*vd->grid,250.0*vd->grid, 10, 2, "Set the vertical offset of the background image");
2393 // uiDefButF(block, NUM, REDRAWVIEW3D, "Size:", 160,160,150,20, &vd->bgpic->size, 0.1, 250.0, 100, 0, "Set the size for the width of the BackGroundPic");
2397 // uiDefButF(block, NUMSLI, B_BLENDBGPIC, "Blend:", 120,100,190,20,&vd->bgpic->blend, 0.0,1.0, 0, 0, "Set the BackGroundPic transparency");
2399 // uiDefButF(block, NUM, B_DIFF, "Center X: ", 10,70,140,20,&vd->bgpic->xof, -20.0,20.0, 10, 2, "Set the BackGroundPic X Offset");
2400 // uiDefButF(block, NUM, B_DIFF, "Center Y: ", 160,70,140,20,&vd->bgpic->yof, -20.0,20.0, 10, 2, "Set the BackGroundPic Y Offset");
2406 static void view3d_panel_properties(short cntrl) // VIEW3D_HANDLER_SETTINGS
2414 block= uiNewBlock(&curarea->uiblocks, "view3d_panel_properties", UI_EMBOSS, UI_HELV, curarea->win);
2415 uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | cntrl);
2416 uiSetPanelHandler(VIEW3D_HANDLER_PROPERTIES); // for close and esc
2417 if(uiNewPanel(curarea, block, "View Properties", "View3d", 340, 30, 318, 254)==0) return;
2419 /* to force height */
2420 uiNewPanelHeight(block, 254);
2422 if(G.f & (G_VERTEXPAINT|G_FACESELECT|G_TEXTUREPAINT|G_WEIGHTPAINT)) {
2423 uiBlockSetFlag(block, UI_BLOCK_FRONTBUFFER); // force old style frontbuffer draw
2426 uiDefBut(block, LABEL, 1, "Grid:", 10, 220, 150, 19, NULL, 0.0, 0.0, 0, 0, "");
2427 uiDefButF(block, NUM, REDRAWVIEW3D, "Spacing:", 10, 200, 140, 19, &vd->grid, 0.001, 100.0, 10, 0, "Set the distance between grid lines");
2428 uiDefButS(block, NUM, REDRAWVIEW3D, "Lines:", 10, 176, 140, 19, &vd->gridlines, 0.0, 100.0, 100, 0, "Set the number of grid lines");
2430 uiDefBut(block, LABEL, 1, "3D Display:", 160, 220, 150, 19, NULL, 0.0, 0.0, 0, 0, "");
2431 uiDefButBitS(block, TOG, V3D_SHOW_FLOOR, REDRAWVIEW3D, "Grid Floor",160, 200, 150, 19, &vd->gridflag, 0, 0, 0, 0, "Show the grid floor in free camera mode");
2432 uiDefButBitS(block, TOG, V3D_SHOW_X, REDRAWVIEW3D, "X Axis", 160, 176, 48, 19, &vd->gridflag, 0, 0, 0, 0, "Show the X Axis line");
2433 uiDefButBitS(block, TOG, V3D_SHOW_Y, REDRAWVIEW3D, "Y Axis", 212, 176, 48, 19, &vd->gridflag, 0, 0, 0, 0, "Show the Y Axis line");
2434 uiDefButBitS(block, TOG, V3D_SHOW_Z, REDRAWVIEW3D, "Z Axis", 262, 176, 48, 19, &vd->gridflag, 0, 0, 0, 0, "Show the Z Axis line");
2436 uiDefBut(block, LABEL, 1, "View Camera:", 10, 150, 140, 19, NULL, 0.0, 0.0, 0, 0, "");
2438 uiDefButF(block, NUM, REDRAWVIEW3D, "Lens:", 10, 130, 140, 19, &vd->lens, 10.0, 120.0, 100, 0, "The lens angle in perspective view");
2439 uiBlockBeginAlign(block);
2440 uiDefButF(block, NUM, REDRAWVIEW3D, "Clip Start:", 10, 106, 140, 19, &vd->near, vd->grid/10.0, 100.0, 10, 0, "Set the beginning of the range in which 3D objects are displayed (perspective view)");
2441 uiDefButF(block, NUM, REDRAWVIEW3D, "Clip End:", 10, 86, 140, 19, &vd->far, 1.0, 1000.0*vd->grid, 100, 0, "Set the end of the range in which 3D objects are displayed (perspective view)");
2442 uiBlockEndAlign(block);
2444 uiDefBut(block, LABEL, 1, "3D Cursor:", 160, 150, 140, 19, NULL, 0.0, 0.0, 0, 0, "");
2446 uiBlockBeginAlign(block);
2447 curs= give_cursor();
2448 uiDefButF(block, NUM, REDRAWVIEW3D, "X:", 160, 130, 150, 22, curs, -1000.0*vd->grid, 1000.0*vd->grid, 10, 0, "X co-ordinate of the 3D cursor");
2449 uiDefButF(block, NUM, REDRAWVIEW3D, "Y:", 160, 108, 150, 22, curs+1, -1000.0*vd->grid, 1000.0*vd->grid, 10, 0, "Y co-ordinate of the 3D cursor");
2450 uiDefButF(block, NUM, REDRAWVIEW3D, "Z:", 160, 86, 150, 22, curs+2, -1000.0*vd->grid, 1000.0*vd->grid, 10, 0, "Z co-ordinate of the 3D cursor");
2451 uiBlockEndAlign(block);
2453 uiDefBut(block, LABEL, 1, "Display:", 10, 50, 150, 19, NULL, 0.0, 0.0, 0, 0, "");
2455 uiDefButBitS(block, TOG, V3D_SELECT_OUTLINE, REDRAWVIEW3D, "Outline Selected", 10, 30, 140, 19, &vd->flag, 0, 0, 0, 0, "Highlight selected objects with an outline, in Solid, Shaded or Textured viewport shading modes");
2456 uiDefButBitS(block, TOG, V3D_DRAW_CENTERS, REDRAWVIEW3D, "All Object Centers", 160, 30, 150, 19, &vd->flag, 0, 0, 0, 0, "Draw the center points on all objects");
2458 uiDefButBitS(block, TOGN, V3D_HIDE_HELPLINES, REDRAWVIEW3D, "Relationship Lines", 10, 6, 140, 19, &vd->flag, 0, 0, 0, 0, "Draw dashed lines indicating Parent, Constraint, or Hook relationships");
2462 static void view3d_panel_preview(ScrArea *sa, short cntrl) // VIEW3D_HANDLER_PREVIEW
2465 View3D *v3d= sa->spacedata.first;
2468 block= uiNewBlock(&sa->uiblocks, "view3d_panel_preview", UI_EMBOSS, UI_HELV, sa->win);
2469 uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | UI_PNL_SCALE | cntrl);
2470 uiSetPanelHandler(VIEW3D_HANDLER_PREVIEW); // for close and esc
2472 ofsx= -150+(sa->winx/2)/v3d->blockscale;
2473 ofsy= -100+(sa->winy/2)/v3d->blockscale;
2474 if(uiNewPanel(sa, block, "Preview", "View3d", ofsx, ofsy, 300, 200)==0) return;
2476 uiBlockSetDrawExtraFunc(block, BIF_view3d_previewdraw);
2478 if(G.scene->recalc & SCE_PRV_CHANGED) {
2479 G.scene->recalc &= ~SCE_PRV_CHANGED;
2480 //printf("found recalc\n");
2481 BIF_view3d_previewrender_free(sa->spacedata.first);
2482 BIF_preview_changed(0);
2487 static void view3d_blockhandlers(ScrArea *sa)
2489 View3D *v3d= sa->spacedata.first;
2492 /* warning; blocks need to be freed each time, handlers dont remove */
2493 uiFreeBlocksWin(&sa->uiblocks, sa->win);
2495 /*uv face-sel and wp mode when mixed with wire leave depth enabled causing
2496 models to draw over the UI */
2497 glDisable(GL_DEPTH_TEST);
2499 for(a=0; a<SPACE_MAXHANDLER; a+=2) {
2501 switch(v3d->blockhandler[a]) {
2503 case VIEW3D_HANDLER_PROPERTIES:
2504 view3d_panel_properties(v3d->blockhandler[a+1]);
2506 case VIEW3D_HANDLER_BACKGROUND:
2507 view3d_panel_background(v3d->blockhandler[a+1]);
2509 case VIEW3D_HANDLER_OBJECT:
2510 view3d_panel_object(v3d->blockhandler[a+1]);
2512 case VIEW3D_HANDLER_PREVIEW:
2513 view3d_panel_preview(sa, v3d->blockhandler[a+1]);
2517 /* clear action value for event */
2518 v3d->blockhandler[a+1]= 0;
2520 uiDrawBlocksPanels(sa, 0);
2524 /* ****************** View3d afterdraw *************** */
2526 typedef struct View3DAfter {
2527 struct View3DAfter *next, *prev;
2532 /* temp storage of Objects that need to be drawn as last */
2533 void add_view3d_after(View3D *v3d, Base *base, int type)
2535 View3DAfter *v3da= MEM_callocN(sizeof(View3DAfter), "View 3d after");
2537 BLI_addtail(&v3d->afterdraw, v3da);
2542 /* clears zbuffer and draws it over */
2543 static void view3d_draw_xray(View3D *v3d, int flag)
2545 View3DAfter *v3da, *next;
2548 for(v3da= v3d->afterdraw.first; v3da; v3da= v3da->next)
2549 if(v3da->type==V3D_XRAY) doit= 1;
2552 if(v3d->zbuf) glClear(GL_DEPTH_BUFFER_BIT);
2555 for(v3da= v3d->afterdraw.first; v3da; v3da= next) {
2557 if(v3da->type==V3D_XRAY) {
2558 draw_object(v3da->base, flag);
2559 BLI_remlink(&v3d->afterdraw, v3da);
2567 /* disables write in zbuffer and draws it over */
2568 static void view3d_draw_transp(View3D *v3d, int flag)
2570 View3DAfter *v3da, *next;
2575 for(v3da= v3d->afterdraw.first; v3da; v3da= next) {
2577 if(v3da->type==V3D_TRANSP) {
2578 draw_object(v3da->base, flag);
2579 BLI_remlink(&v3d->afterdraw, v3da);
2589 /* *********************** */
2591 static void draw_dupli_objects(View3D *v3d, Base *base)
2596 int color= (base->flag & SELECT)?TH_SELECT:TH_WIRE;
2601 if(base->object->dup_group && base->object->dup_group->id.us<1)
2604 tbase.flag= OB_FROMDUPLI|base->flag;
2605 lb= object_duplilist(G.scene, base->object);
2607 for(dob= lb->first; dob; dob= dob->next) {
2608 tbase.object= dob->ob;
2610 Mat4CpyMat4(dob->ob->obmat, dob->mat);
2612 /* extra service: draw the duplicator in drawtype of parent */
2613 dt= tbase.object->dt; tbase.object->dt= base->object->dt;
2614 dtx= tbase.object->dtx; tbase.object->dtx= base->object->dtx;
2616 /* negative scale flag has to propagate */
2617 transflag= tbase.object->transflag;
2618 if(base->object->transflag & OB_NEG_SCALE)
2619 tbase.object->transflag ^= OB_NEG_SCALE;
2621 BIF_ThemeColorBlend(color, TH_BACK, 0.5);
2622 draw_object(&tbase, DRAW_CONSTCOLOR);
2624 tbase.object->dt= dt;
2625 tbase.object->dtx= dtx;
2626 tbase.object->transflag= transflag;
2629 /* Transp afterdraw disabled, afterdraw only stores base pointers, and duplis can be same obj */
2631 free_object_duplilist(lb); /* does restore */
2635 void drawview3dspace(ScrArea *sa, void *spacedata)
2637 View3D *v3d= spacedata;
2642 /* update all objects, ipos, matrices, displists, etc. Flags set by depgraph or manual,
2643 no layer check here, gets correct flushed */
2644 for(base= G.scene->base.first; base; base= base->next) {
2645 object_handle_update(base->object); // bke_object.h
2648 setwinmatrixview3d(sa->winx, sa->winy, NULL); /* 0= no pick rect */
2649 setviewmatrixview3d(); /* note: calls where_is_object for camera... */
2651 Mat4MulMat4(v3d->persmat, v3d->viewmat, sa->winmat);
2652 Mat4Invert(v3d->persinv, v3d->persmat);
2653 Mat4Invert(v3d->viewinv, v3d->viewmat);
2655 /* calculate pixelsize factor once, is used for lamps and obcenters */
2657 float len1, len2, vec[3];
2659 VECCOPY(vec, v3d->persinv[0]);
2660 len1= Normalise(vec);
2661 VECCOPY(vec, v3d->persinv[1]);
2662 len2= Normalise(vec);
2664 v3d->pixsize= 2.0f*(len1>len2?len1:len2);
2666 /* correct for window size */
2667 if(sa->winx > sa->winy) v3d->pixsize/= (float)sa->winx;
2668 else v3d->pixsize/= (float)sa->winy;
2671 if(v3d->drawtype > OB_WIRE) {
2672 if(G.f & G_SIMULATION)
2673 glClearColor(0.0, 0.0, 0.0, 0.0);
2676 BIF_GetThemeColor3fv(TH_BACK, col);
2677 glClearColor(col[0], col[1], col[2], 0.0);
2679 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2685 BIF_GetThemeColor3fv(TH_BACK, col);
2686 glClearColor(col[0], col[1], col[2], 0.0);
2687 glClear(GL_COLOR_BUFFER_BIT);
2690 myloadmatrix(v3d->viewmat);
2691 persp(PERSP_STORE); // store correct view for persp(PERSP_VIEW) calls
2693 if(v3d->flag & V3D_CLIPPING)
2694 view3d_draw_clipping(v3d);
2696 /* set zbuffer after we draw clipping region */
2697 if(v3d->drawtype > OB_WIRE) {
2699 glEnable(GL_DEPTH_TEST);
2702 // needs to be done always, gridview is adjusted in drawgrid() now
2703 v3d->gridview= v3d->grid;
2705 if(v3d->view==0 || v3d->persp!=0) {
2708 if(G.scene->world) {
2709 if(G.scene->world->mode & WO_STARS) {
2710 RE_make_stars(NULL, star_stuff_init_func, star_stuff_vertex_func,
2711 star_stuff_term_func);
2714 if(v3d->flag & V3D_DISPBGPIC) draw_bgpic();
2720 if(v3d->flag & V3D_DISPBGPIC) {
2725 if(v3d->flag & V3D_CLIPPING)
2726 view3d_set_clipping(v3d);
2728 /* draw set first */
2730 for(SETLOOPER(G.scene->set, base)) {
2732 if(v3d->lay & base->lay) {
2734 object_handle_update(base->object);
2736 BIF_ThemeColorBlend(TH_WIRE, TH_BACK, 0.6f);
2737 draw_object(base, DRAW_CONSTCOLOR);
2739 if(base->object->transflag & OB_DUPLI) {
2740 draw_dupli_objects(v3d, base);
2745 /* Transp and X-ray afterdraw stuff */
2746 view3d_draw_xray(v3d, DRAW_CONSTCOLOR); // clears zbuffer if it is used!
2747 view3d_draw_transp(v3d, DRAW_CONSTCOLOR);
2750 /* then draw not selected and the duplis, but skip editmode object */
2751 for(base= G.scene->base.first; base; base= base->next) {
2752 if(v3d->lay & base->lay) {
2755 if(base->object->transflag & OB_DUPLI) {
2756 draw_dupli_objects(v3d, base);
2758 if((base->flag & SELECT)==0) {
2759 if(base->object!=G.obedit) draw_object(base, 0);
2763 /* draw selected and editmode */
2764 for(base= G.scene->base.first; base; base= base->next) {
2765 if(v3d->lay & base->lay) {
2766 if (base->object==G.obedit || ( base->flag & SELECT) )
2767 draw_object(base, 0);
2772 BIF_drawConstraint();
2773 if(G.obedit) BIF_drawPropCircle(); // only editmode has proportional edit
2776 if(G.scene->radio) RAD_drawall(v3d->drawtype>=OB_SOLID);
2778 /* Transp and X-ray afterdraw stuff */
2779 view3d_draw_xray(v3d, 0); // clears zbuffer if it is used!
2780 view3d_draw_transp(v3d, 0);
2782 if(v3d->flag & V3D_CLIPPING)
2783 view3d_clr_clipping();
2785 BIF_draw_manipulator(sa);
2789 glDisable(GL_DEPTH_TEST);
2792 persp(PERSP_WIN); // set ortho
2794 if(v3d->persp>1) drawviewborder();
2795 if(v3d->flag2 & V3D_FLYMODE) drawviewborder_flymode();
2796 if(!(G.f & G_PLAYANIM)) drawcursor(v3d);
2797 if(U.uiflag & USER_SHOW_ROTVIEWICON)
2801 if(U.uiflag & USER_SHOW_VIEWPORTNAME)
2802 draw_viewport_name(sa);
2805 if(ob && (U.uiflag & USER_DRAWVIEWINFO))
2806 draw_selected_name(ob);
2808 draw_area_emboss(sa);
2810 /* it is important to end a view in a transform compatible with buttons */
2812 bwin_scalematrix(sa->win, v3d->blockscale, v3d->blockscale, v3d->blockscale);
2813 view3d_blockhandlers(sa);
2815 sa->win_swap= WIN_BACK_OK;
2817 if(G.f & (G_VERTEXPAINT|G_FACESELECT|G_TEXTUREPAINT|G_WEIGHTPAINT)) {
2818 v3d->flag |= V3D_NEEDBACKBUFDRAW;
2819 addafterqueue(sa->win, BACKBUFDRAW, 1);
2821 // test for backbuf select
2822 if(G.obedit && v3d->drawtype>OB_WIRE && (v3d->flag & V3D_ZBUF_SELECT)) {
2823 extern int afterqtest(short win, unsigned short evt); //editscreen.c
2825 v3d->flag |= V3D_NEEDBACKBUFDRAW;
2826 if(afterqtest(sa->win, BACKBUFDRAW)==0) {
2827 addafterqueue(sa->win, BACKBUFDRAW, 1);
2831 /* run any view3d draw handler script links */
2832 if (sa->scriptlink.totscript)
2833 BPY_do_spacehandlers(sa, 0, SPACEHANDLER_VIEW3D_DRAW);
2835 /* run scene redraw script links */
2836 if((G.f & G_DOSCRIPTLINKS) && G.scene->scriptlink.totscript &&
2838 BPY_do_pyscript((ID *)G.scene, SCRIPT_REDRAW);
2844 void drawview3d_render(struct View3D *v3d, int winx, int winy)
2850 update_for_newframe_muted(); /* first, since camera can be animated */
2852 setwinmatrixview3d(winx, winy, NULL);
2854 setviewmatrixview3d();
2855 myloadmatrix(v3d->viewmat);
2856 glMatrixMode(GL_PROJECTION);
2857 mygetmatrix(winmat);
2858 glMatrixMode(GL_MODELVIEW);
2859 Mat4MulMat4(v3d->persmat, v3d->viewmat, winmat);
2860 Mat4Invert(v3d->persinv, v3d->persmat);
2861 Mat4Invert(v3d->viewinv, v3d->viewmat);
2863 free_all_realtime_images();
2864 reshadeall_displist();
2866 if(v3d->drawtype > OB_WIRE) {
2868 glEnable(GL_DEPTH_TEST);
2871 if(v3d->flag & V3D_CLIPPING)
2872 view3d_set_clipping(v3d);
2874 if (v3d->drawtype==OB_TEXTURE && G.scene->world) {
2875 glClearColor(G.scene->world->horr, G.scene->world->horg, G.scene->world->horb, 0.0);
2878 BIF_GetThemeColor3fv(TH_BACK, col);
2879 glClearColor(col[0], col[1], col[2], 0.0);
2881 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2883 /* abuse! to make sure it doesnt draw the helpstuff */
2884 G.f |= G_SIMULATION;
2886 /* first draw set */
2889 for(SETLOOPER(G.scene->set, base)) {
2890 if(v3d->lay & base->lay) {
2891 if ELEM3(base->object->type, OB_LAMP, OB_CAMERA, OB_LATTICE);
2893 where_is_object(base->object);
2895 BIF_ThemeColorBlend(TH_WIRE, TH_BACK, 0.6f);
2896 draw_object(base, DRAW_CONSTCOLOR);
2898 if(base->object->transflag & OB_DUPLI) {
2899 draw_dupli_objects(v3d, base);
2905 /* Transp and X-ray afterdraw stuff */
2906 view3d_draw_xray(v3d, DRAW_CONSTCOLOR); // clears zbuffer if it is used!
2907 view3d_draw_transp(v3d, DRAW_CONSTCOLOR);
2910 /* first not selected and duplis */
2911 base= G.scene->base.first;
2914 if(v3d->lay & base->lay) {
2915 if ELEM3(base->object->type, OB_LAMP, OB_CAMERA, OB_LATTICE);
2918 if(base->object->transflag & OB_DUPLI) {
2919 draw_dupli_objects(v3d, base);
2921 else if((base->flag & SELECT)==0) {
2922 draw_object(base, 0);
2931 base= G.scene->base.first;
2934 if ( ((base)->flag & SELECT) && ((base)->lay & v3d->lay) ) {
2935 if ELEM3(base->object->type, OB_LAMP, OB_CAMERA, OB_LATTICE);
2936 else draw_object(base, 0);
2942 if(G.scene->radio) RAD_drawall(v3d->drawtype>=OB_SOLID);
2944 /* Transp and X-ray afterdraw stuff */
2945 view3d_draw_xray(v3d, 0); // clears zbuffer if it is used!
2946 view3d_draw_transp(v3d, 0);
2948 if(v3d->flag & V3D_CLIPPING)
2949 view3d_clr_clipping();
2953 glDisable(GL_DEPTH_TEST);
2956 G.f &= ~G_SIMULATION;
2962 free_all_realtime_images();
2966 double tottime = 0.0;
2968 int update_time(void)
2970 static double ltime;
2973 if ((U.mixbufsize)&&(audiostream_pos() != CFRA)&&(G.scene->audio.flag & AUDIO_SYNC)) return 0;
2975 time = PIL_check_seconds_timer();
2977 tottime += (time - ltime);
2979 return (tottime < 0.0);
2982 void inner_play_anim_loop(int init, int mode)
2985 static ScrArea *oldsa;
2986 static double swaptime;
2992 swaptime= 1.0/(float)G.scene->r.frs_sec;
2999 set_timecursor(CFRA);
3001 update_for_newframe_nodraw(1); /* adds no events in UI */
3003 sa= G.curscreen->areabase.first;
3006 scrarea_do_windraw(sa);
3008 else if(curmode & 1) { /* catch modes 1 and 3 */
3009 if ELEM(sa->spacetype, SPACE_VIEW3D, SPACE_SEQ) {
3010 scrarea_do_windraw(sa);
3017 /* make sure that swaptime passed by */
3018 tottime -= swaptime;
3019 while (update_time()) PIL_sleep_ms(1);
3022 if (tottime > 0.0) tottime = 0.0;
3025 audiostream_start( CFRA );
3028 if (U.mixbufsize && (G.scene->audio.flag & AUDIO_SYNC)) CFRA = audiostream_pos();
3033 /* play_anim: 'mode' defines where to play and if repeat is on:
3035 * - 1: all view3d and seq areas
3036 * - 2: current area, no replay
3037 * - 3: all view3d and seq areas, no replay */
3038 int play_anim(int mode)
3040 ScrArea *sa, *oldsa;
3042 unsigned short event=0;
3045 /* patch for very very old scenes */
3046 if(SFRA==0) SFRA= 1;
3047 if(EFRA==0) EFRA= 250;
3049 if(SFRA>EFRA) return 0;
3053 /* waitcursor(1); */
3054 G.f |= G_PLAYANIM; /* in sequence.c and view.c this is handled */
3059 audiostream_start( CFRA );
3061 inner_play_anim_loop(1, mode); /* 1==init */
3063 /* forces all buffers to be OK for current frame (otherwise other windows get redrawn with CFRA+1) */
3064 curarea->win_swap= WIN_BACK_OK;
3065 screen_swapbuffers();
3071 /* we test events first because of MKEY event */
3073 event= extern_qread(&val);
3074 if(event==ESCKEY) break;
3075 else if(event==MIDDLEMOUSE) {
3076 if(U.flag & USER_VIEWMOVE) {
3077 if(G.qual & LR_SHIFTKEY) viewmove(0);
3078 else if(G.qual & LR_CTRLKEY) viewmove(2);
3082 if(G.qual & LR_SHIFTKEY) viewmove(1);
3083 else if(G.qual & LR_CTRLKEY) viewmove(2);
3087 else if(event==MKEY) {
3088 if(val) add_timeline_marker(CFRA-1);
3091 if(ELEM3(event, ESCKEY, SPACEKEY, RIGHTMOUSE)) break;
3093 inner_play_anim_loop(0, 0);
3094 screen_swapbuffers();
3096 if((mode > 1) && CFRA==EFRA) break; /* no replay */
3099 if(event==SPACEKEY);
3104 if(oldsa!=curarea) areawinset(oldsa->win);
3106 /* restore all areas */
3107 sa= G.curscreen->areabase.first;
3109 if( (mode && sa->spacetype==SPACE_VIEW3D) || sa==curarea) addqueue(sa->win, REDRAW, 1);
3113 /* groups could have changed ipo */
3114 allspace(REMAKEIPO, 0);
3115 allqueue(REDRAWIPO, 0);
3116 allqueue(REDRAWNLA, 0);
3117 allqueue (REDRAWACTION, 0);
3119 /* restore for cfra */
3120 update_for_newframe_muted();
3125 if (event==ESCKEY || event==SPACEKEY) return 1;