4 * ***** BEGIN GPL 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.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
30 //#define NAN_LINEAR_PHYSICS
37 #include <sys/times.h>
44 #define snprintf _snprintf
48 #include "MEM_guardedalloc.h"
54 #include "IMB_imbuf_types.h"
55 #include "IMB_imbuf.h"
57 #include "DNA_action_types.h"
58 #include "DNA_armature_types.h"
59 #include "DNA_brush_types.h"
60 #include "DNA_camera_types.h"
61 #include "DNA_constraint_types.h"
62 #include "DNA_curve_types.h"
63 #include "DNA_group_types.h"
64 #include "DNA_gpencil_types.h"
65 #include "DNA_image_types.h"
66 #include "DNA_key_types.h"
67 #include "DNA_lamp_types.h"
68 #include "DNA_lattice_types.h"
69 #include "DNA_mesh_types.h"
70 #include "DNA_meshdata_types.h"
71 #include "DNA_meta_types.h"
72 #include "DNA_modifier_types.h"
73 #include "DNA_object_force.h"
74 #include "DNA_object_types.h"
75 #include "DNA_particle_types.h"
76 #include "DNA_screen_types.h"
77 #include "DNA_scene_types.h"
78 #include "DNA_space_types.h"
79 #include "DNA_texture_types.h"
80 #include "DNA_userdef_types.h"
81 #include "DNA_view3d_types.h"
82 #include "DNA_world_types.h"
84 #include "BLI_blenlib.h"
85 #include "BLI_arithb.h"
86 #include "BLI_editVert.h"
88 #include "BKE_action.h"
89 #include "BKE_armature.h"
91 #include "BKE_constraint.h"
92 #include "BKE_curve.h"
93 #include "BKE_customdata.h"
94 #include "BKE_displist.h"
95 #include "BKE_depsgraph.h"
96 #include "BKE_DerivedMesh.h"
97 #include "BKE_global.h"
98 #include "BKE_lattice.h"
99 #include "BKE_library.h"
100 #include "BKE_image.h"
103 #include "BKE_main.h"
104 #include "BKE_mesh.h"
105 #include "BKE_modifier.h"
106 #include "BKE_object.h"
107 #include "BKE_particle.h"
108 #include "BKE_pointcache.h"
109 #include "BKE_scene.h"
110 #include "BKE_sculpt.h"
111 #include "BKE_texture.h"
112 #include "BKE_utildefines.h"
114 #include "BIF_butspace.h"
115 #include "BIF_drawimage.h"
116 #include "BIF_drawgpencil.h"
117 #include "BIF_editgroup.h"
118 #include "BIF_editarmature.h"
119 #include "BIF_editmesh.h"
120 #include "BIF_editparticle.h"
122 #include "BIF_glutil.h"
123 #include "BIF_interface.h"
124 #include "BIF_interface_icons.h"
125 #include "BIF_keyframing.h"
126 #include "BIF_mywindow.h"
127 #include "BIF_poseobject.h"
128 #include "BIF_previewrender.h"
129 #include "BIF_radialcontrol.h"
130 #include "BIF_resources.h"
131 #include "BIF_retopo.h"
132 #include "BIF_screen.h"
133 #include "BIF_space.h"
136 #include "BIF_verse.h"
139 #include "BDR_drawaction.h"
140 #include "BDR_drawmesh.h"
141 #include "BDR_drawobject.h"
142 #include "BDR_editobject.h"
143 #include "BDR_vpaint.h"
144 #include "BDR_sculptmode.h"
145 #include "BDR_gpencil.h"
147 #include "BSE_drawview.h"
148 #include "BSE_filesel.h"
149 #include "BSE_headerbuttons.h"
150 #include "BSE_seqaudio.h"
151 #include "BSE_sequence.h"
152 #include "BSE_trans_types.h"
153 #include "BSE_time.h"
154 #include "BSE_view.h"
156 #ifndef DISABLE_PYTHON
157 #include "BPY_extern.h"
160 #include "RE_render_ext.h"
163 #include "mydevice.h"
164 #include "butspace.h" // event codes
166 #include "BIF_transform.h"
168 #include "RE_pipeline.h" // make_stars
170 #include "GPU_draw.h"
171 #include "GPU_material.h"
173 #include "multires.h"
175 /* For MULTISAMPLE_ARB #define.
176 Note that older systems like irix
177 may not have this, and will need a #ifdef
179 /* #include "GL/glext.h" Disabled for release, to avoid possibly breaking platforms.
180 Instead, the define we need will just be #defined if it's not in the platform opengl.h.
187 //static void drawname(Object *ob);
189 static void star_stuff_init_func(void)
195 static void star_stuff_vertex_func(float* i)
199 static void star_stuff_term_func(void)
204 void circf(float x, float y, float rad)
206 GLUquadricObj *qobj = gluNewQuadric();
208 gluQuadricDrawStyle(qobj, GLU_FILL);
212 glTranslatef(x, y, 0.);
214 gluDisk( qobj, 0.0, rad, 32, 1);
218 gluDeleteQuadric(qobj);
221 void circ(float x, float y, float rad)
223 GLUquadricObj *qobj = gluNewQuadric();
225 gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
229 glTranslatef(x, y, 0.);
231 gluDisk( qobj, 0.0, rad, 32, 1);
235 gluDeleteQuadric(qobj);
238 /* ********** ********** */
240 static void draw_bgpic(void)
245 float vec[4], fac, asp, zoomx, zoomy;
246 float x1, y1, x2, y2, cx, cy;
249 if(bgpic==NULL) return;
254 ibuf= BKE_image_get_ibuf(ima, &bgpic->iuser);
255 if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL) )
257 if(ibuf->channels!=4)
260 IMB_rect_from_float(ibuf);
265 calc_viewborder(G.vd, &vb);
275 /* calc window coord */
276 initgrabz(0.0, 0.0, 0.0);
277 window_to_3d(vec, 1, 0);
278 fac= MAX3( fabs(vec[0]), fabs(vec[1]), fabs(vec[1]) );
281 asp= ( (float)ibuf->y)/(float)ibuf->x;
283 vec[0] = vec[1] = vec[2] = 0.0;
284 view3d_project_float(curarea, vec, sco, G.vd->persmat);
288 x1= cx+ fac*(bgpic->xof-bgpic->size);
289 y1= cy+ asp*fac*(bgpic->yof-bgpic->size);
290 x2= cx+ fac*(bgpic->xof+bgpic->size);
291 y2= cy+ asp*fac*(bgpic->yof+bgpic->size);
298 if(x1 > curarea->winx ) return;
299 if(y1 > curarea->winy ) return;
301 zoomx= (x2-x1)/ibuf->x;
302 zoomy= (y2-y1)/ibuf->y;
304 /* for some reason; zoomlevels down refuses to use GL_ALPHA_SCALE */
305 if(zoomx < 1.0f || zoomy < 1.0f) {
306 float tzoom= MIN2(zoomx, zoomy);
309 if(ibuf->mipmap[0]==NULL)
310 IMB_makemipmap(ibuf, 0);
312 while(tzoom < 1.0f && mip<8 && ibuf->mipmap[mip]) {
319 ibuf= ibuf->mipmap[mip-1];
322 if(G.vd->zbuf) glDisable(GL_DEPTH_TEST);
324 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
326 glMatrixMode(GL_PROJECTION);
328 glMatrixMode(GL_MODELVIEW);
331 glaDefine2DArea(&curarea->winrct);
335 glPixelZoom(zoomx, zoomy);
336 glColor4f(1.0, 1.0, 1.0, 1.0-bgpic->blend);
337 glaDrawPixelsTex(x1, y1, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
339 glPixelZoom(1.0, 1.0);
340 glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
342 glMatrixMode(GL_PROJECTION);
344 glMatrixMode(GL_MODELVIEW);
348 if(G.vd->zbuf) glEnable(GL_DEPTH_TEST);
350 areawinset(curarea->win); // restore viewport / scissor
353 static void drawgrid_draw(float wx, float wy, float x, float y, float dx)
362 while(fx< curarea->winx) {
363 fdrawline(fx, 0.0, fx, (float)curarea->winy);
371 while(fy< curarea->winy) {
372 fdrawline(0.0, fy, (float)curarea->winx, fy);
378 // not intern, called in editobject for constraint axis too
379 void make_axis_color(char *col, char *col2, char axis)
382 col2[0]= col[0]>219?255:col[0]+36;
383 col2[1]= col[1]<26?0:col[1]-26;
384 col2[2]= col[2]<26?0:col[2]-26;
387 col2[0]= col[0]<46?0:col[0]-36;
388 col2[1]= col[1]>189?255:col[1]+66;
389 col2[2]= col[2]<46?0:col[2]-36;
392 col2[0]= col[0]<26?0:col[0]-26;
393 col2[1]= col[1]<26?0:col[1]-26;
394 col2[2]= col[2]>209?255:col[2]+46;
399 static void drawgrid(void)
401 /* extern short bgpicmode; */
402 float wx, wy, x, y, fw, fx, fy, dx;
404 char col[3], col2[3];
405 short sublines = G.vd->gridsubdiv;
407 vec4[0]=vec4[1]=vec4[2]=0.0;
409 Mat4MulVec4fl(G.vd->persmat, vec4);
414 wx= (curarea->winx/2.0); /* because of rounding errors, grid at wrong location */
415 wy= (curarea->winy/2.0);
420 vec4[0]=vec4[1]=G.vd->grid;
423 Mat4MulVec4fl(G.vd->persmat, vec4);
428 dx= fabs(x-(wx)*fx/fw);
429 if(dx==0) dx= fabs(y-(wy)*fy/fw);
431 glDepthMask(0); // disable write in zbuffer
434 BIF_ThemeColor(TH_GRID);
438 G.vd->gridview*= sublines;
442 G.vd->gridview*= sublines;
446 G.vd->gridview*= sublines;
450 BIF_ThemeColor(TH_GRID);
451 drawgrid_draw(wx, wy, x, y, dx);
454 else { // start blending out
455 BIF_ThemeColorBlend(TH_BACK, TH_GRID, dx/60.0);
456 drawgrid_draw(wx, wy, x, y, dx);
458 BIF_ThemeColor(TH_GRID);
459 drawgrid_draw(wx, wy, x, y, sublines*dx);
462 else { // start blending out (6 < dx < 60)
463 BIF_ThemeColorBlend(TH_BACK, TH_GRID, dx/60.0);
464 drawgrid_draw(wx, wy, x, y, dx);
466 BIF_ThemeColor(TH_GRID);
467 drawgrid_draw(wx, wy, x, y, sublines*dx);
471 if(dx>60.0) { // start blending in
472 G.vd->gridview/= sublines;
474 if(dx>60.0) { // start blending in
475 G.vd->gridview/= sublines;
478 BIF_ThemeColor(TH_GRID);
479 drawgrid_draw(wx, wy, x, y, dx);
482 BIF_ThemeColorBlend(TH_BACK, TH_GRID, dx/60.0);
483 drawgrid_draw(wx, wy, x, y, dx);
484 BIF_ThemeColor(TH_GRID);
485 drawgrid_draw(wx, wy, x, y, dx*sublines);
489 BIF_ThemeColorBlend(TH_BACK, TH_GRID, dx/60.0);
490 drawgrid_draw(wx, wy, x, y, dx);
491 BIF_ThemeColor(TH_GRID);
492 drawgrid_draw(wx, wy, x, y, dx*sublines);
496 BIF_ThemeColorBlend(TH_BACK, TH_GRID, dx/60.0);
497 drawgrid_draw(wx, wy, x, y, dx);
498 BIF_ThemeColor(TH_GRID);
499 drawgrid_draw(wx, wy, x, y, dx*sublines);
505 BIF_GetThemeColor3ubv(TH_GRID, col);
510 if(G.vd->view==3) make_axis_color(col, col2, 'y');
511 else make_axis_color(col, col2, 'x');
512 glColor3ubv((GLubyte *)col2);
514 fdrawline(0.0, y, (float)curarea->winx, y);
516 if(G.vd->view==7) make_axis_color(col, col2, 'y');
517 else make_axis_color(col, col2, 'z');
518 glColor3ubv((GLubyte *)col2);
520 fdrawline(x, 0.0, x, (float)curarea->winy);
522 glDepthMask(1); // enable write in zbuffer
528 static void drawfloor(void)
532 int a, gridlines, emphasise;
533 char col[3], col2[3];
536 vd= curarea->spacedata.first;
540 if(vd->gridlines<3) return;
542 if(G.vd->zbuf && G.obedit) glDepthMask(0); // for zbuffer-select
544 gridlines= vd->gridlines/2;
545 grid= gridlines*vd->grid;
547 BIF_GetThemeColor3ubv(TH_GRID, col);
548 BIF_GetThemeColor3ubv(TH_BACK, col2);
550 /* emphasise division lines lighter instead of darker, if background is darker than grid */
551 if ( ((col[0]+col[1]+col[2])/3+10) > (col2[0]+col2[1]+col2[2])/3 )
556 /* draw the Y axis and/or grid lines */
557 for(a= -gridlines;a<=gridlines;a++) {
559 /* check for the 'show Y axis' preference */
560 if (vd->gridflag & V3D_SHOW_Y) {
561 make_axis_color(col, col2, 'y');
562 glColor3ubv((GLubyte *)col2);
565 } else if (vd->gridflag & V3D_SHOW_FLOOR) {
566 BIF_ThemeColorShade(TH_GRID, emphasise);
571 /* check for the 'show grid floor' preference */
572 if (vd->gridflag & V3D_SHOW_FLOOR) {
574 BIF_ThemeColorShade(TH_GRID, emphasise);
576 else BIF_ThemeColorShade(TH_GRID, 10);
585 glBegin(GL_LINE_STRIP);
595 /* draw the X axis and/or grid lines */
596 for(a= -gridlines;a<=gridlines;a++) {
598 /* check for the 'show X axis' preference */
599 if (vd->gridflag & V3D_SHOW_X) {
600 make_axis_color(col, col2, 'x');
601 glColor3ubv((GLubyte *)col2);
604 } else if (vd->gridflag & V3D_SHOW_FLOOR) {
605 BIF_ThemeColorShade(TH_GRID, emphasise);
610 /* check for the 'show grid floor' preference */
611 if (vd->gridflag & V3D_SHOW_FLOOR) {
613 BIF_ThemeColorShade(TH_GRID, emphasise);
615 else BIF_ThemeColorShade(TH_GRID, 10);
624 glBegin(GL_LINE_STRIP);
634 /* draw the Z axis line */
635 /* check for the 'show Z axis' preference */
636 if (vd->gridflag & V3D_SHOW_Z) {
637 make_axis_color(col, col2, 'z');
638 glColor3ubv((GLubyte *)col2);
640 glBegin(GL_LINE_STRIP);
650 if(G.vd->zbuf && G.obedit) glDepthMask(1);
654 static void drawcursor(View3D *v3d)
659 /* we dont want the clipping for cursor */
662 project_short( give_cursor(), co);
671 circ((float)mx, (float)my, 10.0);
674 circ((float)mx, (float)my, 10.0);
678 sdrawline(mx-20, my, mx-5, my);
679 sdrawline(mx+5, my, mx+20, my);
680 sdrawline(mx, my-20, mx, my-5);
681 sdrawline(mx, my+5, mx, my+20);
685 /* ********* custom clipping *********** */
687 static void view3d_draw_clipping(View3D *v3d)
689 BoundBox *bb= v3d->clipbb;
691 BIF_ThemeColorShade(TH_BACK, -8);
695 glVertex3fv(bb->vec[0]); glVertex3fv(bb->vec[1]); glVertex3fv(bb->vec[2]); glVertex3fv(bb->vec[3]);
696 glVertex3fv(bb->vec[0]); glVertex3fv(bb->vec[4]); glVertex3fv(bb->vec[5]); glVertex3fv(bb->vec[1]);
697 glVertex3fv(bb->vec[4]); glVertex3fv(bb->vec[7]); glVertex3fv(bb->vec[6]); glVertex3fv(bb->vec[5]);
698 glVertex3fv(bb->vec[7]); glVertex3fv(bb->vec[3]); glVertex3fv(bb->vec[2]); glVertex3fv(bb->vec[6]);
699 glVertex3fv(bb->vec[1]); glVertex3fv(bb->vec[5]); glVertex3fv(bb->vec[6]); glVertex3fv(bb->vec[2]);
700 glVertex3fv(bb->vec[7]); glVertex3fv(bb->vec[4]); glVertex3fv(bb->vec[0]); glVertex3fv(bb->vec[3]);
705 void view3d_set_clipping(View3D *v3d)
711 QUATCOPY(plane, v3d->clip[a]);
712 glClipPlane(GL_CLIP_PLANE0+a, plane);
713 glEnable(GL_CLIP_PLANE0+a);
717 void view3d_clr_clipping(void)
722 glDisable(GL_CLIP_PLANE0+a);
726 int view3d_test_clipping(View3D *v3d, float *vec)
728 /* vec in world coordinates, returns 1 if clipped */
733 if(0.0f < v3d->clip[0][3] + INPR(view, v3d->clip[0]))
734 if(0.0f < v3d->clip[1][3] + INPR(view, v3d->clip[1]))
735 if(0.0f < v3d->clip[2][3] + INPR(view, v3d->clip[2]))
736 if(0.0f < v3d->clip[3][3] + INPR(view, v3d->clip[3]))
742 /* ********* end custom clipping *********** */
744 static void view3d_get_viewborder_size(View3D *v3d, float size_r[2])
746 float winmax= MAX2(v3d->area->winx, v3d->area->winy);
747 float aspect= (float) (G.scene->r.xsch*G.scene->r.xasp)/(G.scene->r.ysch*G.scene->r.yasp);
751 size_r[1]= winmax/aspect;
753 size_r[0]= winmax*aspect;
758 void calc_viewborder(struct View3D *v3d, rctf *viewborder_r)
760 float zoomfac, size[2];
761 float dx= 0.0f, dy= 0.0f;
763 view3d_get_viewborder_size(v3d, size);
765 /* magic zoom calculation, no idea what
766 * it signifies, if you find out, tell me! -zr
768 /* simple, its magic dude!
769 * well, to be honest, this gives a natural feeling zooming
770 * with multiple keypad presses (ton)
773 zoomfac= (M_SQRT2 + v3d->camzoom/50.0);
774 zoomfac= (zoomfac*zoomfac)*0.25;
776 size[0]= size[0]*zoomfac;
777 size[1]= size[1]*zoomfac;
779 /* center in window */
780 viewborder_r->xmin= 0.5*v3d->area->winx - 0.5*size[0];
781 viewborder_r->ymin= 0.5*v3d->area->winy - 0.5*size[1];
782 viewborder_r->xmax= viewborder_r->xmin + size[0];
783 viewborder_r->ymax= viewborder_r->ymin + size[1];
785 dx= v3d->area->winx*G.vd->camdx*zoomfac*2.0f;
786 dy= v3d->area->winy*G.vd->camdy*zoomfac*2.0f;
789 viewborder_r->xmin-= dx;
790 viewborder_r->ymin-= dy;
791 viewborder_r->xmax-= dx;
792 viewborder_r->ymax-= dy;
794 if(v3d->camera && v3d->camera->type==OB_CAMERA) {
795 Camera *cam= v3d->camera->data;
796 float w = viewborder_r->xmax - viewborder_r->xmin;
797 float h = viewborder_r->ymax - viewborder_r->ymin;
798 float side = MAX2(w, h);
800 viewborder_r->xmin+= cam->shiftx*side;
801 viewborder_r->xmax+= cam->shiftx*side;
802 viewborder_r->ymin+= cam->shifty*side;
803 viewborder_r->ymax+= cam->shifty*side;
807 void view3d_set_1_to_1_viewborder(View3D *v3d)
810 int im_width= (G.scene->r.size*G.scene->r.xsch)/100;
812 view3d_get_viewborder_size(v3d, size);
814 v3d->camzoom= (sqrt(4.0*im_width/size[0]) - M_SQRT2)*50.0;
815 v3d->camzoom= CLAMPIS(v3d->camzoom, -30, 300);
819 static void drawviewborder_flymode(void)
821 /* draws 4 edge brackets that frame the safe area where the
822 mouse can move during fly mode without spinning the view */
823 float x1, x2, y1, y2;
825 x1= 0.45*(float)curarea->winx;
826 y1= 0.45*(float)curarea->winy;
827 x2= 0.55*(float)curarea->winx;
828 y2= 0.55*(float)curarea->winy;
864 static void drawviewborder(void)
866 extern void gl_round_box(int mode, float minx, float miny, float maxx, float maxy, float rad); // interface_panel.c
868 float x1, x2, y1, y2;
869 float x3, y3, x4, y4;
873 if(G.vd->camera==NULL)
875 if(G.vd->camera->type==OB_CAMERA)
876 ca = G.vd->camera->data;
878 calc_viewborder(G.vd, &viewborder);
884 /* passepartout, specified in camera edit buttons */
885 if (ca && (ca->flag & CAM_SHOWPASSEPARTOUT) && ca->passepartalpha > 0.000001) {
886 if (ca->passepartalpha == 1.0) {
889 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
891 glColor4f(0, 0, 0, ca->passepartalpha);
894 glRectf(0.0, (float)curarea->winy, x1, 0.0);
895 if (x2 < (float)curarea->winx)
896 glRectf(x2, (float)curarea->winy, (float)curarea->winx, 0.0);
897 if (y2 < (float)curarea->winy)
898 glRectf(x1, (float)curarea->winy, x2, y2);
900 glRectf(x1, y1, x2, 0.0);
906 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
909 BIF_ThemeColor(TH_BACK);
910 glRectf(x1, y1, x2, y2);
913 BIF_ThemeColor(TH_WIRE);
914 glRectf(x1, y1, x2, y2);
916 /* camera name - draw in highlighted text color */
917 if (ca && (ca->flag & CAM_SHOWNAME)) {
918 BIF_ThemeColor(TH_TEXT_HI);
919 glRasterPos2f(x1, y1-15);
921 BMF_DrawString(G.font, G.vd->camera->id.name+2);
922 BIF_ThemeColor(TH_WIRE);
927 if(G.scene->r.mode & R_BORDER) {
930 x3= x1+ G.scene->r.border.xmin*(x2-x1);
931 y3= y1+ G.scene->r.border.ymin*(y2-y1);
932 x4= x1+ G.scene->r.border.xmax*(x2-x1);
933 y4= y1+ G.scene->r.border.ymax*(y2-y1);
936 glRectf(x3, y3, x4, y4);
940 if (ca && (ca->flag & CAM_SHOWTITLESAFE)) {
951 BIF_ThemeColorBlendShade(TH_WIRE, TH_BACK, 0.25, 0);
954 gl_round_box(GL_LINE_LOOP, x1, y1, x2, y2, 12.0);
958 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
962 void backdrawview3d(int test)
966 /*for 2.43 release, don't use glext and just define the constant.
967 this to avoid possibly breaking platforms before release.*/
968 #ifndef GL_MULTISAMPLE_ARB
969 #define GL_MULTISAMPLE_ARB 0x809D
972 #ifdef GL_MULTISAMPLE_ARB
976 if(G.f & G_VERTEXPAINT || G.f & G_WEIGHTPAINT || G.f & G_TEXTUREPAINT);
977 else if(G.obedit && G.vd->drawtype>OB_WIRE && (G.vd->flag & V3D_ZBUF_SELECT));
979 G.vd->flag &= ~V3D_NEEDBACKBUFDRAW;
983 if( !(G.vd->flag & V3D_NEEDBACKBUFDRAW) ) return;
987 addafterqueue(curarea->win, BACKBUFDRAW, 1);
993 /*Disable FSAA for backbuffer selection.
995 Only works if GL_MULTISAMPLE_ARB is defined by the header
996 file, which is should be for every OS that supports FSAA.*/
998 #ifdef GL_MULTISAMPLE_ARB
999 m = glIsEnabled(GL_MULTISAMPLE_ARB);
1000 if (m) glDisable(GL_MULTISAMPLE_ARB);
1004 glDrawBuffer(GL_AUX0);
1006 if(G.vd->drawtype > OB_WIRE) G.vd->zbuf= TRUE;
1007 curarea->win_swap &= ~WIN_BACK_OK;
1009 glDisable(GL_DITHER);
1011 glClearColor(0.0, 0.0, 0.0, 0.0);
1013 glEnable(GL_DEPTH_TEST);
1014 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1017 glClear(GL_COLOR_BUFFER_BIT);
1018 glDisable(GL_DEPTH_TEST);
1021 if(G.vd->flag & V3D_CLIPPING)
1022 view3d_set_clipping(G.vd);
1024 G.f |= G_BACKBUFSEL;
1026 base= (G.scene->basact);
1027 if(base && (base->lay & G.vd->lay)) {
1028 draw_object_backbufsel(base->object);
1031 G.vd->flag &= ~V3D_NEEDBACKBUFDRAW;
1033 G.f &= ~G_BACKBUFSEL;
1035 glDisable(GL_DEPTH_TEST);
1036 glEnable(GL_DITHER);
1039 glDrawBuffer(GL_BACK); /* we were in aux buffers */
1042 if(G.vd->flag & V3D_CLIPPING)
1043 view3d_clr_clipping();
1045 #ifdef GL_MULTISAMPLE_ARB
1046 if (m) glEnable(GL_MULTISAMPLE_ARB);
1049 /* it is important to end a view in a transform compatible with buttons */
1050 persp(PERSP_WIN); // set ortho
1051 bwin_scalematrix(curarea->win, G.vd->blockscale, G.vd->blockscale, G.vd->blockscale);
1055 void check_backbuf(void)
1057 if(G.vd->flag & V3D_NEEDBACKBUFDRAW)
1061 /* samples a single pixel (copied from vpaint) */
1062 unsigned int sample_backbuf(int x, int y)
1066 if(x>=curarea->winx || y>=curarea->winy) return 0;
1067 x+= curarea->winrct.xmin;
1068 y+= curarea->winrct.ymin;
1070 check_backbuf(); // actually not needed for apple
1073 glReadBuffer(GL_AUX0);
1075 glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col);
1076 glReadBuffer(GL_BACK);
1078 if(G.order==B_ENDIAN) SWITCH_INT(col);
1080 return framebuffer_to_index(col);
1083 /* reads full rect, converts indices */
1084 ImBuf *read_backbuf(short xmin, short ymin, short xmax, short ymax)
1086 unsigned int *dr, *rd;
1087 struct ImBuf *ibuf, *ibuf1;
1089 short xminc, yminc, xmaxc, ymaxc, xs, ys;
1092 if(xmin<0) xminc= 0; else xminc= xmin;
1093 if(xmax>=curarea->winx) xmaxc= curarea->winx-1; else xmaxc= xmax;
1094 if(xminc > xmaxc) return NULL;
1096 if(ymin<0) yminc= 0; else yminc= ymin;
1097 if(ymax>=curarea->winy) ymaxc= curarea->winy-1; else ymaxc= ymax;
1098 if(yminc > ymaxc) return NULL;
1100 ibuf= IMB_allocImBuf((xmaxc-xminc+1), (ymaxc-yminc+1), 32, IB_rect,0);
1102 check_backbuf(); // actually not needed for apple
1105 glReadBuffer(GL_AUX0);
1107 glReadPixels(curarea->winrct.xmin+xminc, curarea->winrct.ymin+yminc, (xmaxc-xminc+1), (ymaxc-yminc+1), GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
1108 glReadBuffer(GL_BACK);
1110 if(G.order==B_ENDIAN) IMB_convert_rgba_to_abgr(ibuf);
1112 a= (xmaxc-xminc+1)*(ymaxc-yminc+1);
1115 if(*dr) *dr= framebuffer_to_index(*dr);
1119 /* put clipped result back, if needed */
1120 if(xminc==xmin && xmaxc==xmax && yminc==ymin && ymaxc==ymax)
1123 ibuf1= IMB_allocImBuf( (xmax-xmin+1),(ymax-ymin+1),32,IB_rect,0);
1127 for(ys= ymin; ys<=ymax; ys++) {
1128 for(xs= xmin; xs<=xmax; xs++, dr++) {
1129 if( xs>=xminc && xs<=xmaxc && ys>=yminc && ys<=ymaxc) {
1135 IMB_freeImBuf(ibuf);
1139 /* smart function to sample a rect spiralling outside, nice for backbuf selection */
1140 unsigned int sample_backbuf_rect(short mval[2], int size, unsigned int min, unsigned int max, int *dist, short strict, unsigned int (*indextest)(unsigned int index))
1143 unsigned int *bufmin, *bufmax, *tbuf;
1145 int a, b, rc, nr, amount, dirvec[4][2];
1147 unsigned int index = 0;
1152 minx = mval[0]-(amount+1);
1153 miny = mval[1]-(amount+1);
1154 buf = read_backbuf(minx, miny, minx+size-1, miny+size-1);
1159 dirvec[0][0]= 1; dirvec[0][1]= 0;
1160 dirvec[1][0]= 0; dirvec[1][1]= -size;
1161 dirvec[2][0]= -1; dirvec[2][1]= 0;
1162 dirvec[3][0]= 0; dirvec[3][1]= size;
1166 bufmax = buf->rect + size*size;
1167 tbuf+= amount*size+ amount;
1169 for(nr=1; nr<=size; nr++) {
1171 for(a=0; a<2; a++) {
1172 for(b=0; b<nr; b++, distance++) {
1173 if (*tbuf && *tbuf>=min && *tbuf<max) { //we got a hit
1175 indexok = indextest(*tbuf - min+1);
1177 *dist= (short) sqrt( (float)distance );
1178 index = *tbuf - min+1;
1183 *dist= (short) sqrt( (float)distance ); // XXX, this distance is wrong -
1184 index = *tbuf - min+1; // messy yah, but indices start at 1
1189 tbuf+= (dirvec[rc][0]+dirvec[rc][1]);
1191 if(tbuf<bufmin || tbuf>=bufmax) {
1206 static void drawname(Object *ob)
1209 glRasterPos3f(0.0, 0.0, 0.0);
1211 BMF_DrawString(G.font, " ");
1212 BMF_DrawString(G.font, ob->id.name+2);
1216 static char *get_cfra_marker_name()
1218 ListBase *markers= &G.scene->markers;
1219 TimeMarker *m1, *m2;
1221 /* search through markers for match */
1222 for (m1=markers->first, m2=markers->last; m1 && m2; m1=m1->next, m2=m2->prev) {
1223 if (m1->frame==CFRA)
1229 if (m2->frame==CFRA)
1236 /* draw info beside axes in bottom left-corner:
1237 * framenum, object name, bone name (if available), marker name (if available)
1239 static void draw_selected_name(Object *ob)
1241 char info[256], *markern;
1244 /* get name of marker on current frame (if available) */
1245 markern= get_cfra_marker_name();
1247 /* check if there is an object */
1249 /* name(s) to display depends on type of object */
1250 if(ob->type==OB_ARMATURE) {
1251 bArmature *arm= ob->data;
1254 /* show name of active bone too (if possible) */
1257 for (ebo=G.edbo.first; ebo; ebo=ebo->next){
1258 if ((ebo->flag & BONE_ACTIVE) && (ebo->layer & arm->layer)) {
1264 else if(ob->pose && (ob->flag & OB_POSEMODE)) {
1265 bPoseChannel *pchan;
1266 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1267 if((pchan->bone->flag & BONE_ACTIVE) && (pchan->bone->layer & arm->layer)) {
1274 sprintf(info, "(%d) %s %s <%s>", CFRA, ob->id.name+2, name, markern);
1276 sprintf(info, "(%d) %s %s", CFRA, ob->id.name+2, name);
1278 sprintf(info, "(%d) %s", CFRA, ob->id.name+2);
1280 else if(ELEM3(ob->type, OB_MESH, OB_LATTICE, OB_CURVE)) {
1282 KeyBlock *kb = NULL;
1285 /* try to display active shapekey too */
1287 key = ob_get_key(ob);
1289 kb = BLI_findlink(&key->block, ob->shapenr-1);
1291 sprintf(shapes, ": %s ", kb->name);
1292 if(ob->shapeflag == OB_SHAPE_LOCK){
1293 sprintf(shapes, "%s (Pinned)",shapes);
1299 sprintf(info, "(%d) %s %s <%s>", CFRA, ob->id.name+2, shapes, markern);
1301 sprintf(info, "(%d) %s %s", CFRA, ob->id.name+2, shapes);
1304 /* standard object */
1306 sprintf(info, "(%d) %s <%s>", CFRA, ob->id.name+2, markern);
1308 sprintf(info, "(%d) %s", CFRA, ob->id.name+2);
1311 /* colour depends on whether there is a keyframe */
1312 if (id_frame_has_keyframe((ID *)ob, frame_to_float(CFRA), G.vd->keyflags))
1313 BIF_ThemeColor(TH_VERTEX_SELECT);
1315 BIF_ThemeColor(TH_TEXT_HI);
1320 sprintf(info, "(%d) <%s>", CFRA, markern);
1322 sprintf(info, "(%d)", CFRA);
1324 /* colour is always white */
1325 BIF_ThemeColor(TH_TEXT_HI);
1328 if (U.uiflag & USER_SHOW_ROTVIEWICON)
1329 offset = 14 + (U.rvisize * 2);
1331 glRasterPos2i(offset, 10);
1332 BMF_DrawString(G.fonts, info);
1336 /* Draw a live substitute of the view icon, which is always shown */
1337 static void draw_view_axis(void)
1339 const float k = U.rvisize; /* axis size */
1340 const float toll = 0.5; /* used to see when view is quasi-orthogonal */
1341 const float start = k + 1.0; /* axis center in screen coordinates, x=y */
1342 float ydisp = 0.0; /* vertical displacement to allow obj info text */
1344 /* rvibright ranges approx. from original axis icon color to gizmo color */
1345 float bright = U.rvibright / 15.0f;
1347 unsigned char col[3];
1348 unsigned char gridcol[3];
1355 /* thickness of lines is proportional to k */
1356 /* (log(k)-1) gives a more suitable thickness, but fps decreased by about 3 fps */
1357 glLineWidth(k / 10);
1358 //glLineWidth(log(k)-1); // a bit slow
1360 BIF_GetThemeColor3ubv(TH_GRID, (char *)gridcol);
1363 vec[0] = vec[3] = 1;
1364 vec[1] = vec[2] = 0;
1365 QuatMulVecf(G.vd->viewquat, vec);
1367 make_axis_color((char *)gridcol, (char *)col, 'x');
1368 rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v);
1369 s = s<0.5 ? s+0.5 : 1.0;
1371 v = (v<1.0-(bright) ? v+bright : 1.0);
1372 hsv_to_rgb(h, s, v, colf, colf+1, colf+2);
1377 fdrawline(start, start + ydisp, start + dx, start + dy + ydisp);
1378 if (fabs(dx) > toll || fabs(dy) > toll) {
1379 glRasterPos2i(start + dx + 2, start + dy + ydisp + 2);
1380 BMF_DrawString(G.fonts, "x");
1384 vec[1] = vec[3] = 1;
1385 vec[0] = vec[2] = 0;
1386 QuatMulVecf(G.vd->viewquat, vec);
1388 make_axis_color((char *)gridcol, (char *)col, 'y');
1389 rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v);
1390 s = s<0.5 ? s+0.5 : 1.0;
1392 v = (v<1.0-(bright) ? v+bright : 1.0);
1393 hsv_to_rgb(h, s, v, colf, colf+1, colf+2);
1398 fdrawline(start, start + ydisp, start + dx, start + dy + ydisp);
1399 if (fabs(dx) > toll || fabs(dy) > toll) {
1400 glRasterPos2i(start + dx + 2, start + dy + ydisp + 2);
1401 BMF_DrawString(G.fonts, "y");
1405 vec[2] = vec[3] = 1;
1406 vec[1] = vec[0] = 0;
1407 QuatMulVecf(G.vd->viewquat, vec);
1409 make_axis_color((char *)gridcol, (char *)col, 'z');
1410 rgb_to_hsv(col[0]/255.0f, col[1]/255.0f, col[2]/255.0f, &h, &s, &v);
1411 s = s<0.5 ? s+0.5 : 1.0;
1413 v = (v<1.0-(bright) ? v+bright : 1.0);
1414 hsv_to_rgb(h, s, v, colf, colf+1, colf+2);
1419 fdrawline(start, start + ydisp, start + dx, start + dy + ydisp);
1420 if (fabs(dx) > toll || fabs(dy) > toll) {
1421 glRasterPos2i(start + dx + 2, start + dy + ydisp + 2);
1422 BMF_DrawString(G.fonts, "z");
1425 /* restore line-width */
1430 static void draw_view_icon(void)
1434 if(G.vd->view==7) icon= ICON_AXIS_TOP;
1435 else if(G.vd->view==1) icon= ICON_AXIS_FRONT;
1436 else if(G.vd->view==3) icon= ICON_AXIS_SIDE;
1440 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1442 BIF_icon_draw(5.0, 5.0, icon);
1444 glDisable(GL_BLEND);
1447 char *view3d_get_name(View3D *v3d)
1451 switch (v3d->view) {
1453 if (v3d->persp == V3D_ORTHO)
1454 name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Back Ortho" : "Front Ortho";
1456 name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Back Persp" : "Front Persp";
1459 if (v3d->persp == V3D_ORTHO)
1460 name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Left Ortho" : "Right Ortho";
1462 name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Left Persp" : "Right Persp";
1465 if (v3d->persp == V3D_ORTHO)
1466 name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Bottom Ortho" : "Top Ortho";
1468 name = (v3d->flag2 & V3D_OPP_DIRECTION_NAME) ? "Bottom Persp" : "Top Persp";
1471 if (v3d->persp==V3D_CAMOB) {
1472 if ((v3d->camera) && (v3d->camera->type == OB_CAMERA)) {
1474 cam = v3d->camera->data;
1475 name = (cam->type != CAM_ORTHO) ? "Camera Persp" : "Camera Ortho";
1477 name = "Object as Camera";
1480 name = (v3d->persp == V3D_ORTHO) ? "User Ortho" : "User Persp";
1488 static void draw_viewport_name(ScrArea *sa)
1490 char *name = view3d_get_name(sa->spacedata.first);
1491 char *printable = NULL;
1493 if (G.vd->localview) {
1494 printable = malloc(strlen(name) + strlen(" (Local)_")); /* '_' gives space for '\0' */
1495 strcpy(printable, name);
1496 strcat(printable, " (Local)");
1502 BIF_ThemeColor(TH_TEXT_HI);
1503 glRasterPos2i(10, sa->winy-20);
1504 BMF_DrawString(G.fonts, printable);
1507 if (G.vd->localview) {
1512 /* ******************* view3d space & buttons ************** */
1515 /* temporal struct for storing transform properties */
1517 float ob_eul[4]; // used for quat too....
1518 float ob_scale[3]; // need temp space due to linked values
1524 } TransformProperties;
1526 /* is used for both read and write... */
1527 static void v3d_editvertex_buts(uiBlock *block, Object *ob, float lim)
1529 EditMesh *em = G.editMesh;
1530 EditVert *eve, *evedef=NULL;
1532 MDeformVert *dvert=NULL;
1533 TransformProperties *tfp= G.vd->properties_storage;
1534 float median[5], ve_median[5];
1535 int tot, totw, totweight, totedge;
1538 median[0]= median[1]= median[2]= median[3]= median[4]= 0.0;
1539 tot= totw= totweight= totedge= 0;
1542 if(ob->type==OB_MESH) {
1543 eve= em->verts.first;
1545 if(eve->f & SELECT) {
1548 VecAddf(median, median, eve->co);
1552 eed= em->edges.first;
1554 if((eed->f & SELECT)) {
1556 median[3]+= eed->crease;
1561 /* check for defgroups */
1563 dvert= CustomData_em_get(&em->vdata, evedef->data, CD_MDEFORMVERT);
1564 if(tot==1 && dvert && dvert->totweight) {
1566 int i, max=1, init=1;
1569 for (i=0; i<dvert->totweight; i++){
1570 dg = BLI_findlink (&ob->defbase, dvert->dw[i].def_nr);
1572 max+= snprintf(str, sizeof(str), "%s %%x%d|", dg->name, dvert->dw[i].def_nr);
1573 if(max<320) strcat(defstr, str);
1575 else printf("oh no!\n");
1576 if(tfp->curdef==dvert->dw[i].def_nr) {
1578 tfp->defweightp= &dvert->dw[i].weight;
1582 if(init) { // needs new initialized
1583 tfp->curdef= dvert->dw[0].def_nr;
1584 tfp->defweightp= &dvert->dw[0].weight;
1588 else if(ob->type==OB_CURVE || ob->type==OB_SURF) {
1589 extern ListBase editNurb; /* editcurve.c */
1597 if((nu->type & 7)==CU_BEZIER) {
1601 if(bezt->f2 & SELECT) {
1602 VecAddf(median, median, bezt->vec[1]);
1604 median[4]+= bezt->weight;
1608 if(bezt->f1 & SELECT) {
1609 VecAddf(median, median, bezt->vec[0]);
1612 if(bezt->f3 & SELECT) {
1613 VecAddf(median, median, bezt->vec[2]);
1622 a= nu->pntsu*nu->pntsv;
1624 if(bp->f1 & SELECT) {
1625 VecAddf(median, median, bp->vec);
1626 median[3]+= bp->vec[3];
1629 median[4]+= bp->weight;
1638 else if(ob->type==OB_LATTICE) {
1642 a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
1645 if(bp->f1 & SELECT) {
1646 VecAddf(median, median, bp->vec);
1648 median[4]+= bp->weight;
1657 median[0] /= (float)tot;
1658 median[1] /= (float)tot;
1659 median[2] /= (float)tot;
1660 if(totedge) median[3] /= (float)totedge;
1661 else if(totw) median[3] /= (float)totw;
1662 if(totweight) median[4] /= (float)totweight;
1664 if(G.vd->flag & V3D_GLOBAL_STATS)
1665 Mat4MulVecfl(ob->obmat, median);
1667 if(block) { // buttons
1669 if((ob->parent) && (ob->partype == PARBONE)) but_y = 135;
1672 uiBlockBeginAlign(block);
1673 uiDefButBitS(block, TOG, V3D_GLOBAL_STATS, REDRAWVIEW3D, "Global", 160, but_y, 70, 19, &G.vd->flag, 0, 0, 0, 0, "Displays global values");
1674 uiDefButBitS(block, TOGN, V3D_GLOBAL_STATS, REDRAWVIEW3D, "Local", 230, but_y, 70, 19, &G.vd->flag, 0, 0, 0, 0, "Displays local values");
1675 uiBlockEndAlign(block);
1677 memcpy(tfp->ve_median, median, sizeof(tfp->ve_median));
1679 uiBlockBeginAlign(block);
1681 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Vertex X:", 10, 110, 290, 19, &(tfp->ve_median[0]), -lim, lim, 10, 3, "");
1682 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Vertex Y:", 10, 90, 290, 19, &(tfp->ve_median[1]), -lim, lim, 10, 3, "");
1683 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Vertex Z:", 10, 70, 290, 19, &(tfp->ve_median[2]), -lim, lim, 10, 3, "");
1685 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Vertex W:", 10, 50, 290, 19, &(tfp->ve_median[3]), 0.01, 100.0, 10, 3, "");
1686 uiBlockEndAlign(block);
1689 uiDefBut(block, LABEL, 1, "Vertex Deform Groups", 10, 40, 290, 20, NULL, 0.0, 0.0, 0, 0, "");
1691 uiBlockBeginAlign(block);
1692 uiDefButF(block, NUM, B_NOP, "Weight:", 10, 20, 150, 19, tfp->defweightp, 0.0f, 1.0f, 10, 3, "Weight value");
1693 uiDefButI(block, MENU, REDRAWVIEW3D, defstr, 160, 20, 140, 19, &tfp->curdef, 0.0, 0.0, 0, 0, "Current Vertex Group");
1694 uiBlockEndAlign(block);
1697 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:", 10, 20, 290, 19, &(tfp->ve_median[4]), 0.0, 1.0, 10, 3, "");
1701 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median X:", 10, 110, 290, 19, &(tfp->ve_median[0]), -lim, lim, 10, 3, "");
1702 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median Y:", 10, 90, 290, 19, &(tfp->ve_median[1]), -lim, lim, 10, 3, "");
1703 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median Z:", 10, 70, 290, 19, &(tfp->ve_median[2]), -lim, lim, 10, 3, "");
1705 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median W:", 10, 50, 290, 19, &(tfp->ve_median[3]), 0.01, 100.0, 10, 3, "");
1706 uiBlockEndAlign(block);
1708 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:", 10, 20, 290, 19, &(tfp->ve_median[4]), 0.0, 1.0, 10, 3, "Weight is used for SoftBody Goal");
1711 if(ob->type==OB_CURVE && (totw==0)) { /* bez curves have no w */
1712 uiBlockBeginAlign(block);
1713 uiDefBut(block, BUT,B_SETPT_AUTO,"Auto", 10, 44, 72, 19, 0, 0, 0, 0, 0, "Auto handles (Shift H)");
1714 uiDefBut(block, BUT,B_SETPT_VECTOR,"Vector",82, 44, 73, 19, 0, 0, 0, 0, 0, "Vector handles (V)");
1715 uiDefBut(block, BUT,B_SETPT_ALIGN,"Align",155, 44, 73, 19, 0, 0, 0, 0, 0, "Align handles (H Toggles)");
1716 uiDefBut(block, BUT,B_SETPT_FREE,"Free", 227, 44, 72, 19, 0, 0, 0, 0, 0, "Align handles (H Toggles)");
1717 uiBlockEndAlign(block);
1721 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Crease W:", 10, 30, 290, 19, &(tfp->ve_median[3]), 0.0, 1.0, 10, 3, "");
1723 uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Median Crease W:", 10, 30, 290, 19, &(tfp->ve_median[3]), 0.0, 1.0, 10, 3, "");
1727 memcpy(ve_median, tfp->ve_median, sizeof(tfp->ve_median));
1729 if(G.vd->flag & V3D_GLOBAL_STATS) {
1730 Mat4Invert(ob->imat, ob->obmat);
1731 Mat4MulVecfl(ob->imat, median);
1732 Mat4MulVecfl(ob->imat, ve_median);
1734 VecSubf(median, ve_median, median);
1735 median[3]= ve_median[3]-median[3];
1736 median[4]= ve_median[4]-median[4];
1738 if(ob->type==OB_MESH) {
1740 eve= em->verts.first;
1742 if(eve->f & SELECT) {
1743 VecAddf(eve->co, eve->co, median);
1748 for(eed= em->edges.first; eed; eed= eed->next) {
1749 if(eed->f & SELECT) {
1750 /* ensure the median can be set to zero or one */
1751 if(ve_median[3]==0.0f) eed->crease= 0.0f;
1752 else if(ve_median[3]==1.0f) eed->crease= 1.0f;
1754 eed->crease+= median[3];
1755 CLAMP(eed->crease, 0.0, 1.0);
1760 recalc_editnormals();
1762 else if(ob->type==OB_CURVE || ob->type==OB_SURF) {
1763 extern ListBase editNurb; /* editcurve.c */
1771 if((nu->type & 7)==1) {
1775 if(bezt->f2 & SELECT) {
1776 VecAddf(bezt->vec[0], bezt->vec[0], median);
1777 VecAddf(bezt->vec[1], bezt->vec[1], median);
1778 VecAddf(bezt->vec[2], bezt->vec[2], median);
1779 bezt->weight+= median[4];
1782 if(bezt->f1 & SELECT) {
1783 VecAddf(bezt->vec[0], bezt->vec[0], median);
1785 if(bezt->f3 & SELECT) {
1786 VecAddf(bezt->vec[2], bezt->vec[2], median);
1794 a= nu->pntsu*nu->pntsv;
1796 if(bp->f1 & SELECT) {
1797 VecAddf(bp->vec, bp->vec, median);
1798 bp->vec[3]+= median[3];
1799 bp->weight+= median[4];
1805 testhandlesNurb(nu); /* test for bezier too */
1810 else if(ob->type==OB_LATTICE) {
1814 a= editLatt->pntsu*editLatt->pntsv*editLatt->pntsw;
1817 if(bp->f1 & SELECT) {
1818 VecAddf(bp->vec, bp->vec, median);
1819 bp->weight+= median[4];
1825 BIF_undo_push("Transform properties");
1829 /* assumes armature active */
1830 static void validate_bonebutton_cb(void *bonev, void *namev)
1834 if(ob && ob->type==OB_ARMATURE) {
1836 char oldname[32], newname[32];
1838 /* need to be on the stack */
1839 BLI_strncpy(newname, bone->name, 32);
1840 BLI_strncpy(oldname, (char *)namev, 32);
1842 BLI_strncpy(bone->name, oldname, 32);
1844 armature_bone_rename(ob->data, oldname, newname); // editarmature.c
1845 allqueue(REDRAWALL, 0);
1849 static void v3d_posearmature_buts(uiBlock *block, Object *ob, float lim)
1853 bPoseChannel *pchan;
1855 TransformProperties *tfp= G.vd->properties_storage;
1857 arm = get_armature(OBACT);
1858 if (!arm || !ob->pose) return;
1860 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
1862 if(bone && (bone->flag & BONE_ACTIVE) && (bone->layer & arm->layer))
1865 if (!pchan || !bone) return;
1867 if((ob->parent) && (ob->partype == PARBONE))
1868 but= uiDefBut (block, TEX, B_DIFF, "Bone:", 160, 130, 140, 19, bone->name, 1, 31, 0, 0, "");
1870 but= uiDefBut(block, TEX, B_DIFF, "Bone:", 160, 140, 140, 19, bone->name, 1, 31, 0, 0, "");
1871 uiButSetFunc(but, validate_bonebutton_cb, bone, NULL);
1873 QuatToEul(pchan->quat, tfp->ob_eul);
1874 tfp->ob_eul[0]*= 180.0/M_PI;
1875 tfp->ob_eul[1]*= 180.0/M_PI;
1876 tfp->ob_eul[2]*= 180.0/M_PI;
1878 uiBlockBeginAlign(block);
1879 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");
1880 uiDefButF(block, NUM, B_ARMATUREPANEL2, "LocX:", 30, 140, 120, 19, pchan->loc, -lim, lim, 100, 3, "");
1881 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");
1882 uiDefButF(block, NUM, B_ARMATUREPANEL2, "LocY:", 30, 120, 120, 19, pchan->loc+1, -lim, lim, 100, 3, "");
1883 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");
1884 uiDefButF(block, NUM, B_ARMATUREPANEL2, "LocZ:", 30, 100, 120, 19, pchan->loc+2, -lim, lim, 100, 3, "");
1886 uiBlockBeginAlign(block);
1887 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");
1888 uiDefButF(block, NUM, B_ARMATUREPANEL3, "RotX:", 30, 70, 120, 19, tfp->ob_eul, -1000.0, 1000.0, 100, 3, "");
1889 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");
1890 uiDefButF(block, NUM, B_ARMATUREPANEL3, "RotY:", 30, 50, 120, 19, tfp->ob_eul+1, -1000.0, 1000.0, 100, 3, "");
1891 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");
1892 uiDefButF(block, NUM, B_ARMATUREPANEL3, "RotZ:", 30, 30, 120, 19, tfp->ob_eul+2, -1000.0, 1000.0, 100, 3, "");
1894 uiBlockBeginAlign(block);
1895 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");
1896 uiDefButF(block, NUM, B_ARMATUREPANEL2, "ScaleX:", 180, 70, 120, 19, pchan->size, -lim, lim, 10, 3, "");
1897 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");
1898 uiDefButF(block, NUM, B_ARMATUREPANEL2, "ScaleY:", 180, 50, 120, 19, pchan->size+1, -lim, lim, 10, 3, "");
1899 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");
1900 uiDefButF(block, NUM, B_ARMATUREPANEL2, "ScaleZ:", 180, 30, 120, 19, pchan->size+2, -lim, lim, 10, 3, "");
1901 uiBlockEndAlign(block);
1904 static void v3d_editarmature_buts(uiBlock *block, Object *ob, float lim)
1906 bArmature *arm= G.obedit->data;
1909 TransformProperties *tfp= G.vd->properties_storage;
1911 ebone= G.edbo.first;
1913 for (ebone = G.edbo.first; ebone; ebone=ebone->next){
1914 if ((ebone->flag & BONE_ACTIVE) && (ebone->layer & arm->layer))
1921 if((ob->parent) && (ob->partype == PARBONE))
1922 but= uiDefBut(block, TEX, B_DIFF, "Bone:", 160, 130, 140, 19, ebone->name, 1, 31, 0, 0, "");
1924 but= uiDefBut(block, TEX, B_DIFF, "Bone:", 160, 150, 140, 19, ebone->name, 1, 31, 0, 0, "");
1925 uiButSetFunc(but, validate_editbonebutton_cb, ebone, NULL);
1927 uiBlockBeginAlign(block);
1928 uiDefButF(block, NUM, B_ARMATUREPANEL1, "HeadX:", 10, 70, 140, 19, ebone->head, -lim, lim, 10, 3, "");
1929 uiDefButF(block, NUM, B_ARMATUREPANEL1, "HeadY:", 10, 50, 140, 19, ebone->head+1, -lim, lim, 10, 3, "");
1930 uiDefButF(block, NUM, B_ARMATUREPANEL1, "HeadZ:", 10, 30, 140, 19, ebone->head+2, -lim, lim, 10, 3, "");
1931 uiBlockBeginAlign(block);
1932 uiDefButF(block, NUM, B_ARMATUREPANEL1, "TailX:", 160, 70, 140, 19, ebone->tail, -lim, lim, 10, 3, "");
1933 uiDefButF(block, NUM, B_ARMATUREPANEL1, "TailY:", 160, 50, 140, 19, ebone->tail+1, -lim, lim, 10, 3, "");
1934 uiDefButF(block, NUM, B_ARMATUREPANEL1, "TailZ:", 160, 30, 140, 19, ebone->tail+2, -lim, lim, 10, 3, "");
1935 uiBlockEndAlign(block);
1937 tfp->ob_eul[0]= 180.0*ebone->roll/M_PI;
1938 uiDefButF(block, NUM, B_ARMATUREPANEL1, "Roll:", 10, 100, 140, 19, tfp->ob_eul, -lim, lim, 1000, 3, "");
1940 uiDefButBitI(block, TOG, BONE_EDITMODE_LOCKED, REDRAWVIEW3D, "Lock", 160, 100, 140, 19, &(ebone->flag), 0, 0, 0, 0, "Prevents bone from being transformed in edit mode");
1942 uiBlockBeginAlign(block);
1943 uiDefButF(block, NUM, B_ARMATUREPANEL1, "TailRadius:", 10, 150, 140, 19, &ebone->rad_tail, 0, lim, 10, 3, "");
1944 if (ebone->parent && ebone->flag & BONE_CONNECTED )
1945 uiDefButF(block, NUM, B_ARMATUREPANEL1, "HeadRadius:", 10, 130, 140, 19, &ebone->parent->rad_tail, 0, lim, 10, 3, "");
1947 uiDefButF(block, NUM, B_ARMATUREPANEL1, "HeadRadius:", 10, 130, 140, 19, &ebone->rad_head, 0, lim, 10, 3, "");
1948 uiBlockEndAlign(block);
1951 static void v3d_editmetaball_buts(uiBlock *block, Object *ob, float lim)
1953 extern MetaElem *lastelem;
1956 uiBlockBeginAlign(block);
1957 uiDefButF(block, NUM, B_RECALCMBALL, "LocX:", 10, 70, 140, 19, &lastelem->x, -lim, lim, 100, 3, "");
1958 uiDefButF(block, NUM, B_RECALCMBALL, "LocY:", 10, 50, 140, 19, &lastelem->y, -lim, lim, 100, 3, "");
1959 uiDefButF(block, NUM, B_RECALCMBALL, "LocZ:", 10, 30, 140, 19, &lastelem->z, -lim, lim, 100, 3, "");
1961 uiBlockBeginAlign(block);
1962 if(lastelem->type!=MB_BALL)
1963 uiDefButF(block, NUM, B_RECALCMBALL, "dx:", 160, 70, 140, 19, &lastelem->expx, 0, lim, 100, 3, "");
1964 if((lastelem->type!=MB_BALL) && (lastelem->type!=MB_TUBE))
1965 uiDefButF(block, NUM, B_RECALCMBALL, "dy:", 160, 50, 140, 19, &lastelem->expy, 0, lim, 100, 3, "");
1966 if((lastelem->type==MB_ELIPSOID) || (lastelem->type==MB_CUBE))
1967 uiDefButF(block, NUM, B_RECALCMBALL, "dz:", 160, 30, 140, 19, &lastelem->expz, 0, lim, 100, 3, "");
1969 uiBlockEndAlign(block);
1971 uiBlockBeginAlign(block);
1972 uiDefButF(block, NUM, B_RECALCMBALL, "Radius:", 10, 120, 140, 19, &lastelem->rad, 0, lim, 100, 3, "Size of the active metaball");
1973 uiDefButF(block, NUM, B_RECALCMBALL, "Stiffness:", 10, 100, 140, 19, &lastelem->s, 0, 10, 100, 3, "Stiffness of the active metaball");
1974 uiBlockEndAlign(block);
1976 uiDefButS(block, MENU, B_RECALCMBALL, "Type%t|Ball%x0|Tube%x4|Plane%x5|Elipsoid%x6|Cube%x7", 160, 120, 140, 19, &lastelem->type, 0.0, 0.0, 0, 0, "Set active element type");
1981 void do_viewbuts(unsigned short event)
1986 TransformProperties *tfp= G.vd->properties_storage;
1989 if(vd==NULL) return;
1994 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
1995 allqueue(REDRAWVIEW3D, 1);
1998 case B_OBJECTPANELROT:
2000 ob->rot[0]= M_PI*tfp->ob_eul[0]/180.0;
2001 ob->rot[1]= M_PI*tfp->ob_eul[1]/180.0;
2002 ob->rot[2]= M_PI*tfp->ob_eul[2]/180.0;
2003 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2004 allqueue(REDRAWVIEW3D, 1);
2008 case B_OBJECTPANELSCALE:
2011 /* link scale; figure out which axis changed */
2012 if (tfp->link_scale) {
2013 float ratio, tmp, max = 0.0;
2017 max = fabs(tfp->ob_scale[0] - ob->size[0]);
2018 tmp = fabs(tfp->ob_scale[1] - ob->size[1]);
2023 tmp = fabs(tfp->ob_scale[2] - ob->size[2]);
2029 if (ob->size[axis] != tfp->ob_scale[axis]) {
2030 if (fabs(ob->size[axis]) > FLT_EPSILON) {
2031 ratio = tfp->ob_scale[axis] / ob->size[axis];
2032 ob->size[0] *= ratio;
2033 ob->size[1] *= ratio;
2034 ob->size[2] *= ratio;
2039 VECCOPY(ob->size, tfp->ob_scale);
2042 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2043 allqueue(REDRAWVIEW3D, 1);
2047 case B_OBJECTPANELDIMS:
2048 bb= object_get_boundbox(ob);
2050 float old_dims[3], scale[3], ratio, len[3];
2053 Mat4ToSize(ob->obmat, scale);
2055 len[0] = bb->vec[4][0] - bb->vec[0][0];
2056 len[1] = bb->vec[2][1] - bb->vec[0][1];
2057 len[2] = bb->vec[1][2] - bb->vec[0][2];
2059 old_dims[0] = fabs(scale[0]) * len[0];
2060 old_dims[1] = fabs(scale[1]) * len[1];
2061 old_dims[2] = fabs(scale[2]) * len[2];
2063 /* for each axis changed */
2064 for (axis = 0; axis<3; axis++) {
2065 if (fabs(old_dims[axis] - tfp->ob_dims[axis]) > 0.0001) {
2066 if (old_dims[axis] > 0.0) {
2067 ratio = tfp->ob_dims[axis] / old_dims[axis];
2068 if (tfp->link_scale) {
2069 ob->size[0] *= ratio;
2070 ob->size[1] *= ratio;
2071 ob->size[2] *= ratio;
2075 ob->size[axis] *= ratio;
2079 if (len[axis] > 0) {
2080 ob->size[axis] = tfp->ob_dims[axis] / len[axis];
2086 /* prevent multiple B_OBJECTPANELDIMS events to keep scaling, cycling with TAB on buttons can cause that */
2087 VECCOPY(tfp->ob_dims, old_dims);
2089 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2090 allqueue(REDRAWVIEW3D, 1);
2094 case B_OBJECTPANELMEDIAN:
2096 v3d_editvertex_buts(NULL, ob, 1.0);
2097 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2098 allqueue(REDRAWVIEW3D, 1);
2102 /* note; this case also used for parbone */
2103 case B_OBJECTPANELPARENT:
2105 if(ob->id.lib || test_parent_loop(ob->parent, ob) )
2108 DAG_scene_sort(G.scene);
2109 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2111 allqueue(REDRAWVIEW3D, 1);
2112 allqueue(REDRAWBUTSOBJECT, 0);
2113 allqueue(REDRAWOOPS, 0);
2117 case B_ARMATUREPANEL1:
2119 bArmature *arm= G.obedit->data;
2120 EditBone *ebone, *child;
2122 for (ebone = G.edbo.first; ebone; ebone=ebone->next){
2123 if ((ebone->flag & BONE_ACTIVE) && (ebone->layer & arm->layer))
2127 ebone->roll= M_PI*tfp->ob_eul[0]/180.0;
2128 // Update our parent
2129 if (ebone->parent && ebone->flag & BONE_CONNECTED){
2130 VECCOPY (ebone->parent->tail, ebone->head);
2133 // Update our children if necessary
2134 for (child = G.edbo.first; child; child=child->next){
2135 if (child->parent == ebone && (child->flag & BONE_CONNECTED)){
2136 VECCOPY (child->head, ebone->tail);
2139 if(arm->flag & ARM_MIRROR_EDIT) {
2140 EditBone *eboflip= armature_bone_get_mirrored(ebone);
2142 eboflip->roll= -ebone->roll;
2143 eboflip->head[0]= -ebone->head[0];
2144 eboflip->tail[0]= -ebone->tail[0];
2146 // Update our parent
2147 if (eboflip->parent && eboflip->flag & BONE_CONNECTED){
2148 VECCOPY (eboflip->parent->tail, eboflip->head);
2151 // Update our children if necessary
2152 for (child = G.edbo.first; child; child=child->next){
2153 if (child->parent == eboflip && (child->flag & BONE_CONNECTED)){
2154 VECCOPY (child->head, eboflip->tail);
2160 allqueue(REDRAWVIEW3D, 1);
2164 case B_ARMATUREPANEL3: // rotate button on channel
2167 bPoseChannel *pchan;
2171 arm = get_armature(OBACT);
2172 if (!arm || !ob->pose) return;
2174 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
2176 if(bone && (bone->flag & BONE_ACTIVE) && (bone->layer & arm->layer))
2181 /* make a copy to eul[3], to allow TAB on buttons to work */
2182 eul[0]= M_PI*tfp->ob_eul[0]/180.0;
2183 eul[1]= M_PI*tfp->ob_eul[1]/180.0;
2184 eul[2]= M_PI*tfp->ob_eul[2]/180.0;
2185 EulToQuat(eul, pchan->quat);
2187 /* no break, pass on */
2188 case B_ARMATUREPANEL2:
2190 ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
2191 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2192 allqueue(REDRAWVIEW3D, 1);
2195 case B_TRANSFORMSPACEADD:
2196 BIF_manageTransformOrientation(1, 0);
2197 allqueue(REDRAWVIEW3D, 1);
2199 case B_TRANSFORMSPACECLEAR:
2200 BIF_clearTransformOrientation();
2201 allqueue(REDRAWVIEW3D, 1);
2205 void removeTransformOrientation_func(void *target, void *unused)
2207 BIF_removeTransformOrientation((TransformOrientation *) target);
2210 void selectTransformOrientation_func(void *target, void *unused)
2212 BIF_selectTransformOrientation((TransformOrientation *) target);
2215 static void view3d_panel_transform_spaces(short cntrl)
2217 ListBase *transform_spaces = &G.scene->transform_spaces;
2218 TransformOrientation *ts = transform_spaces->first;
2221 int xco = 20, yco = 70, height = 140;
2224 block= uiNewBlock(&curarea->uiblocks, "view3d_panel_transform", UI_EMBOSS, UI_HELV, curarea->win);
2225 uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | cntrl);
2226 uiSetPanelHandler(VIEW3D_HANDLER_TRANSFORM); // for close and esc
2228 if(uiNewPanel(curarea, block, "Transform Orientations", "View3d", 10, 230, 318, height)==0) return;
2230 uiNewPanelHeight(block, height);
2232 uiBlockBeginAlign(block);
2235 uiDefBut(block, BUT, B_TRANSFORMSPACEADD, "Add", xco,120,80,20, 0, 0, 0, 0, 0, "Add the selected element as a Transform Orientation");
2237 uiDefBut(block, BUT, B_TRANSFORMSPACEADD, "Add", xco,120,80,20, 0, 0, 0, 0, 0, "Add the active object as a Transform Orientation");
2239 uiDefBut(block, BUT, B_TRANSFORMSPACECLEAR, "Clear", xco + 80,120,80,20, 0, 0, 0, 0, 0, "Removal all Transform Orientations");
2241 uiBlockEndAlign(block);
2243 uiBlockBeginAlign(block);
2245 uiDefButS(block, ROW, REDRAWHEADERS, "Global", xco, 90, 40,20, &G.vd->twmode, 5.0, (float)V3D_MANIP_GLOBAL,0, 0, "Global Transform Orientation");
2246 uiDefButS(block, ROW, REDRAWHEADERS, "Local", xco + 40, 90, 40,20, &G.vd->twmode, 5.0, (float)V3D_MANIP_LOCAL, 0, 0, "Local Transform Orientation");
2247 uiDefButS(block, ROW, REDRAWHEADERS, "Normal", xco + 80, 90, 40,20, &G.vd->twmode, 5.0, (float)V3D_MANIP_NORMAL,0, 0, "Normal Transform Orientation");
2248 uiDefButS(block, ROW, REDRAWHEADERS, "View", xco + 120, 90, 40,20, &G.vd->twmode, 5.0, (float)V3D_MANIP_VIEW, 0, 0, "View Transform Orientation");
2250 for (index = V3D_MANIP_CUSTOM, ts = transform_spaces->first ; ts ; ts = ts->next, index++) {
2252 BIF_ThemeColor(TH_BUT_ACTION);
2253 if (G.vd->twmode == index) {
2254 but = uiDefIconButS(block,ROW, REDRAWHEADERS, ICON_CHECKBOX_HLT, xco,yco,XIC,YIC, &G.vd->twmode, 5.0, (float)index, 0, 0, "Use this Custom Transform Orientation");
2257 but = uiDefIconButS(block,ROW, REDRAWHEADERS, ICON_CHECKBOX_DEHLT, xco,yco,XIC,YIC, &G.vd->twmode, 5.0, (float)index, 0, 0, "Use this Custom Transform Orientation");
2259 uiButSetFunc(but, selectTransformOrientation_func, ts, NULL);
2260 uiDefBut(block, TEX, 0, "", xco+=XIC, yco,100+XIC,20, &ts->name, 0, 30, 0, 0, "Edits the name of this Transform Orientation");
2261 but = uiDefIconBut(block, BUT, REDRAWVIEW3D, ICON_X, xco+=100+XIC,yco,XIC,YIC, 0, 0, 0, 0, 0, "Deletes this Transform Orientation");
2262 uiButSetFunc(but, removeTransformOrientation_func, ts, NULL);
2267 uiBlockEndAlign(block);
2269 if(yco < 0) uiNewPanelHeight(block, height-yco);
2273 static void view3d_panel_object(short cntrl) // VIEW3D_HANDLER_OBJECT
2278 TransformProperties *tfp;
2280 static char hexcol[128];
2282 if(ob==NULL) return;
2284 /* make sure we got storage */
2285 if(G.vd->properties_storage==NULL)
2286 G.vd->properties_storage= MEM_callocN(sizeof(TransformProperties), "TransformProperties");
2287 tfp= G.vd->properties_storage;
2289 block= uiNewBlock(&curarea->uiblocks, "view3d_panel_object", UI_EMBOSS, UI_HELV, curarea->win);
2290 uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | cntrl);
2291 uiSetPanelHandler(VIEW3D_HANDLER_OBJECT); // for close and esc
2293 if((G.f & G_SCULPTMODE) && !G.obedit) {
2294 if(!uiNewPanel(curarea, block, "Transform Properties", "View3d", 10, 230, 318, 234))
2296 } else if(G.f & G_PARTICLEEDIT && !G.obedit){
2297 if(!uiNewPanel(curarea, block, "Transform Properties", "View3d", 10, 230, 318, 234))
2300 if(!uiNewPanel(curarea, block, "Transform Properties", "View3d", 10, 230, 318, 204))
2304 uiSetButLock(object_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
2306 if(G.f & (G_VERTEXPAINT|G_TEXTUREPAINT|G_WEIGHTPAINT)) {
2307 uiBlockSetFlag(block, UI_BLOCK_FRONTBUFFER); // force old style frontbuffer draw
2310 bt= uiDefBut(block, TEX, B_IDNAME, "OB: ", 10,180,140,20, ob->id.name+2, 0.0, 21.0, 0, 0, "");
2312 if(ob->vnode) uiButSetFunc(bt, test_and_send_idbutton_cb, ob, ob->id.name);
2313 else uiButSetFunc(bt, test_idbutton_cb, ob->id.name, NULL);
2315 uiButSetFunc(bt, test_idbutton_cb, ob->id.name, NULL);
2318 if((G.f & G_PARTICLEEDIT)==0) {
2319 uiBlockBeginAlign(block);
2320 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_OBJECTPANELPARENT, "Par:", 160, 180, 140, 20, &ob->parent, "Parent Object");
2321 if((ob->parent) && (ob->partype == PARBONE)) {
2322 bt= uiDefBut(block, TEX, B_OBJECTPANELPARENT, "ParBone:", 160, 160, 140, 20, ob->parsubstr, 0, 30, 0, 0, "");
2323 uiButSetCompleteFunc(bt, autocomplete_bone, (void *)ob->parent);
2326 strcpy(ob->parsubstr, "");
2328 uiBlockEndAlign(block);
2332 lim= 10000.0f*MAX2(1.0, G.vd->grid);
2335 if(ob->type==OB_ARMATURE) v3d_editarmature_buts(block, ob, lim);
2336 if(ob->type==OB_MBALL) v3d_editmetaball_buts(block, ob, lim);
2337 else v3d_editvertex_buts(block, ob, lim);
2339 else if(ob->flag & OB_POSEMODE) {
2340 v3d_posearmature_buts(block, ob, lim);
2342 else if(G.f & G_WEIGHTPAINT) {
2343 uiNewPanelTitle(block, "Weight Paint Properties");
2344 weight_paint_buttons(block);
2346 else if(G.f & (G_VERTEXPAINT|G_TEXTUREPAINT)) {
2347 extern VPaint Gvp; /* from vpaint */
2348 static float hsv[3], old[3]; // used as temp mem for picker
2350 ToolSettings *settings= G.scene->toolsettings;
2352 if(G.f & G_VERTEXPAINT) rgb= &Gvp.r;
2353 else if(settings->imapaint.brush) rgb= settings->imapaint.brush->rgb;
2355 uiNewPanelTitle(block, "Paint Properties");
2357 /* 'f' is for floating panel */
2358 uiBlockPickerButtons(block, rgb, hsv, old, hexcol, 'f', REDRAWBUTSEDIT);
2360 else if(G.f & G_SCULPTMODE) {
2361 uiNewPanelTitle(block, "Sculpt Properties");
2362 sculptmode_draw_interface_tools(block,10,150);
2363 } else if(G.f & G_PARTICLEEDIT){
2364 uiNewPanelTitle(block, "Particle Edit Properties");
2365 particle_edit_buttons(block);
2367 BoundBox *bb = NULL;
2369 uiBlockBeginAlign(block);
2370 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");
2371 uiDefButF(block, NUM, B_OBJECTPANEL, "LocX:", 30, 150, 120, 19, &(ob->loc[0]), -lim, lim, 100, 3, "");
2372 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");
2373 uiDefButF(block, NUM, B_OBJECTPANEL, "LocY:", 30, 130, 120, 19, &(ob->loc[1]), -lim, lim, 100, 3, "");
2374 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");
2375 uiDefButF(block, NUM, B_OBJECTPANEL, "LocZ:", 30, 110, 120, 19, &(ob->loc[2]), -lim, lim, 100, 3, "");
2377 tfp->ob_eul[0]= 180.0*ob->rot[0]/M_PI;
2378 tfp->ob_eul[1]= 180.0*ob->rot[1]/M_PI;
2379 tfp->ob_eul[2]= 180.0*ob->rot[2]/M_PI;
2381 uiBlockBeginAlign(block);
2382 if ((ob->parent) && (ob->partype == PARBONE)) {
2383 uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTX, REDRAWVIEW3D, ICON_UNLOCKED, 160,130,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
2384 uiDefButF(block, NUM, B_OBJECTPANELROT, "RotX:", 180, 130, 120, 19, &(tfp->ob_eul[0]), -lim, lim, 1000, 3, "");
2385 uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTY, REDRAWVIEW3D, ICON_UNLOCKED, 160,110,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
2386 uiDefButF(block, NUM, B_OBJECTPANELROT, "RotY:", 180, 110, 120, 19, &(tfp->ob_eul[1]), -lim, lim, 1000, 3, "");
2387 uiDefIconButBitS(block, ICONTOG, OB_LOCK_ROTZ, REDRAWVIEW3D, ICON_UNLOCKED, 160,90,20,19, &(ob->protectflag), 0, 0, 0, 0, "Protects this value from being Transformed");
2388 uiDefButF(block, NUM, B_OBJECTPANELROT, "RotZ:", 180, 90, 120, 19, &(tfp->ob_eul[2]), -lim, lim, 1000, 3, "");
2392 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");
2393 uiDefButF(block, NUM, B_OBJECTPANELROT, "RotX:", 180, 150, 120, 19, &(tfp->ob_eul[0]), -lim, lim, 1000, 3, "");
2394 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");
2395 uiDefButF(block, NUM, B_OBJECTPANELROT, "RotY:", 180, 130, 120, 19, &(tfp->ob_eul[1]), -lim, lim, 1000, 3, "");
2396 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");
2397 uiDefButF(block, NUM, B_OBJECTPANELROT, "RotZ:", 180, 110, 120, 19, &(tfp->ob_eul[2]), -lim, lim, 1000, 3, "");
2400 tfp->ob_scale[0]= ob->size[0];
2401 tfp->ob_scale[1]= ob->size[1];
2402 tfp->ob_scale[2]= ob->size[2];
2404 uiBlockBeginAlign(block);
2405 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");
2406 uiDefButF(block, NUM, B_OBJECTPANELSCALE, "ScaleX:", 30, 80, 120, 19, &(tfp->ob_scale[0]), -lim, lim, 10, 3, "");
2407 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");
2408 uiDefButF(block, NUM, B_OBJECTPANELSCALE, "ScaleY:", 30, 60, 120, 19, &(tfp->ob_scale[1]), -lim, lim, 10, 3, "");
2409 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");
2410 uiDefButF(block, NUM, B_OBJECTPANELSCALE, "ScaleZ:", 30, 40, 120, 19, &(tfp->ob_scale[2]), -lim, lim, 10, 3, "");
2411 uiBlockEndAlign(block);
2413 uiDefButS(block, TOG, REDRAWVIEW3D, "Link Scale", 10, 10, 140, 19, &(tfp->link_scale), 0, 1, 0, 0, "Scale values vary proportionally in all directions");
2415 bb= object_get_boundbox(ob);
2419 Mat4ToSize(ob->obmat, scale);
2421 tfp->ob_dims[0] = fabs(scale[0]) * (bb->vec[4][0] - bb->vec[0][0]);
2422 tfp->ob_dims[1] = fabs(scale[1]) * (bb->vec[2][1] - bb->vec[0][1]);
2423 tfp->ob_dims[2] = fabs(scale[2]) * (bb->vec[1][2] - bb->vec[0][2]);
2425 uiBlockBeginAlign(block);
2426 if ((ob->parent) && (ob->partype == PARBONE)) {
2427 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "DimX:", 160, 60, 140, 19, &(tfp->ob_dims[0]), 0.0, lim, 10, 3, "Manipulate bounding box size");
2428 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "DimY:", 160, 40, 140, 19, &(tfp->ob_dims[1]), 0.0, lim, 10, 3, "Manipulate bounding box size");
2429 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "DimZ:", 160, 20, 140, 19, &(tfp->ob_dims[2]), 0.0, lim, 10, 3, "Manipulate bounding box size");
2433 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "DimX:", 160, 80, 140, 19, &(tfp->ob_dims[0]), 0.0, lim, 10, 3, "Manipulate bounding box size");
2434 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "DimY:", 160, 60, 140, 19, &(tfp->ob_dims[1]), 0.0, lim, 10, 3, "Manipulate bounding box size");
2435 uiDefButF(block, NUM, B_OBJECTPANELDIMS, "DimZ:", 160, 40, 140, 19, &(tfp->ob_dims[2]), 0.0, lim, 10, 3, "Manipulate bounding box size");
2438 uiBlockEndAlign(block);
2444 static void view3d_panel_background(short cntrl) // VIEW3D_HANDLER_BACKGROUND
2451 block= uiNewBlock(&curarea->uiblocks, "view3d_panel_background", UI_EMBOSS, UI_HELV, curarea->win);
2452 uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | cntrl);
2453 uiSetPanelHandler(VIEW3D_HANDLER_BACKGROUND); // for close and esc
2454 if(uiNewPanel(curarea, block, "Background Image", "View3d", 340, 10, 318, 204)==0) return;
2456 if(G.f & G_VERTEXPAINT || G.f & G_WEIGHTPAINT || G.f & G_TEXTUREPAINT || G.f & G_GREASEPENCIL) {
2457 uiBlockSetFlag(block, UI_BLOCK_FRONTBUFFER); // force old style frontbuffer draw
2460 if(vd->flag & V3D_DISPBGPIC) {
2461 if(vd->bgpic==NULL) {
2462 vd->bgpic= MEM_callocN(sizeof(BGpic), "bgpic");
2463 vd->bgpic->size= 5.0;
2464 vd->bgpic->blend= 0.5;
2465 vd->bgpic->iuser.fie_ima= 2;
2466 vd->bgpic->iuser.ok= 1;
2470 if(!(vd->flag & V3D_DISPBGPIC)) {
2471 uiDefButBitS(block, TOG, V3D_DISPBGPIC, B_REDR, "Use Background Image", 10, 180, 150, 20, &vd->flag, 0, 0, 0, 0, "Display an image in the background of this 3D View");
2472 uiDefBut(block, LABEL, 1, " ", 160, 180, 150, 20, NULL, 0.0, 0.0, 0, 0, "");
2475 uiBlockBeginAlign(block);
2476 uiDefButBitS(block, TOG, V3D_DISPBGPIC, B_REDR, "Use", 10, 225, 50, 20, &vd->flag, 0, 0, 0, 0, "Display an image in the background of this 3D View");
2477 uiDefButF(block, NUMSLI, B_REDR, "Blend:", 60, 225, 150, 20, &vd->bgpic->blend, 0.0,1.0, 0, 0, "Set the transparency of the background image");
2478 uiDefButF(block, NUM, B_REDR, "Size:", 210, 225, 100, 20, &vd->bgpic->size, 0.1, 250.0*vd->grid, 100, 0, "Set the size (width) of the background image");
2480 uiDefButF(block, NUM, B_REDR, "X Offset:", 10, 205, 150, 20, &vd->bgpic->xof, -250.0*vd->grid,250.0*vd->grid, 10, 2, "Set the horizontal offset of the background image");
2481 uiDefButF(block, NUM, B_REDR, "Y Offset:", 160, 205, 150, 20, &vd->bgpic->yof, -250.0*vd->grid,250.0*vd->grid, 10, 2, "Set the vertical offset of the background image");
2483 uiblock_image_panel(block, &vd->bgpic->ima, &vd->bgpic->iuser, B_REDR, B_REDR);
2488 static void view3d_panel_properties(short cntrl) // VIEW3D_HANDLER_SETTINGS
2496 block= uiNewBlock(&curarea->uiblocks, "view3d_panel_properties", UI_EMBOSS, UI_HELV, curarea->win);
2497 uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | cntrl);
2498 uiSetPanelHandler(VIEW3D_HANDLER_PROPERTIES); // for close and esc
2499 if(uiNewPanel(curarea, block, "View Properties", "View3d", 340, 30, 318, 254)==0) return;
2501 /* to force height */
2502 uiNewPanelHeight(block, 264);
2504 if(G.f & (G_VERTEXPAINT|G_FACESELECT|G_TEXTUREPAINT|G_WEIGHTPAINT|G_GREASEPENCIL)) {
2505 uiBlockSetFlag(block, UI_BLOCK_FRONTBUFFER); // force old style frontbuffer draw
2508 uiDefBut(block, LABEL, 1, "Grid:", 10, 220, 150, 19, NULL, 0.0, 0.0, 0, 0, "");
2509 uiBlockBeginAlign(block);
2510 uiDefButF(block, NUM, REDRAWVIEW3D, "Spacing:", 10, 200, 140, 19, &vd->grid, 0.001, 100.0, 10, 0, "Set the distance between grid lines");
2511 uiDefButS(block, NUM, REDRAWVIEW3D, "Lines:", 10, 180, 140, 19, &vd->gridlines, 0.0, 100.0, 100, 0, "Set the number of grid lines in perspective view");
2512 uiDefButS(block, NUM, REDRAWVIEW3D, "Divisions:", 10, 160, 140, 19, &vd->gridsubdiv, 1.0, 100.0, 100, 0, "Set the number of grid lines");
2513 uiBlockEndAlign(block);
2515 uiDefBut(block, LABEL, 1, "3D Display:", 160, 220, 150, 19, NULL, 0.0, 0.0, 0, 0, "");
2516 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");
2517 uiDefButBitS(block, TOG, V3D_SHOW_X, REDRAWVIEW3D, "X Axis", 160, 176, 48, 19, &vd->gridflag, 0, 0, 0, 0, "Show the X Axis line");
2518 uiDefButBitS(block, TOG, V3D_SHOW_Y, REDRAWVIEW3D, "Y Axis", 212, 176, 48, 19, &vd->gridflag, 0, 0, 0, 0, "Show the Y Axis line");
2519 uiDefButBitS(block, TOG, V3D_SHOW_Z, REDRAWVIEW3D, "Z Axis", 262, 176, 48, 19, &vd->gridflag, 0, 0, 0, 0, "Show the Z Axis line");
2521 uiDefBut(block, LABEL, 1, "View Camera:", 10, 140, 140, 19, NULL, 0.0, 0.0, 0, 0, "");
2523 uiDefButF(block, NUM, REDRAWVIEW3D, "Lens:", 10, 120, 140, 19, &vd->lens, 10.0, 120.0, 100, 0, "The lens angle in perspective view");
2524 uiBlockBeginAlign(block);
2525 uiDefButF(block, NUM, REDRAWVIEW3D, "Clip Start:", 10, 96, 140, 19, &vd->near, vd->grid/100.0, 100.0, 10, 0, "Set the beginning of the range in which 3D objects are displayed (perspective view)");
2526 uiDefButF(block, NUM, REDRAWVIEW3D, "Clip End:", 10, 76, 140, 19, &vd->far, 1.0, 10000.0*vd->grid, 100, 0, "Set the end of the range in which 3D objects are displayed (perspective view)");
2527 uiBlockEndAlign(block);
2529 uiDefBut(block, LABEL, 1, "3D Cursor:", 160, 150, 140, 19, NULL, 0.0, 0.0, 0, 0, "");
2531 uiBlockBeginAlign(block);
2532 curs= give_cursor();
2533 uiDefButF(block, NUM, REDRAWVIEW3D, "X:", 160, 130, 150, 22, curs, -10000.0*vd->grid, 10000.0*vd->grid, 10, 0, "X co-ordinate of the 3D cursor");
2534 uiDefButF(block, NUM, REDRAWVIEW3D, "Y:", 160, 108, 150, 22, curs+1, -10000.0*vd->grid, 10000.0*vd->grid, 10, 0, "Y co-ordinate of the 3D cursor");
2535 uiDefButF(block, NUM, REDRAWVIEW3D, "Z:", 160, 86, 150, 22, curs+2, -10000.0*vd->grid, 10000.0*vd->grid, 10, 0, "Z co-ordinate of the 3D cursor");
2536 uiBlockEndAlign(block);
2538 uiDefBut(block, LABEL, 1, "Display:", 10, 50, 150, 19, NULL, 0.0, 0.0, 0, 0, "");
2539 uiBlockBeginAlign(block);
2540 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");
2541 uiDefButBitS(block, TOG, V3D_DRAW_CENTERS, REDRAWVIEW3D, "All Object Centers", 10, 10, 140, 19, &vd->flag, 0, 0, 0, 0, "Draw the center points on all objects");
2542 uiDefButBitS(block, TOGN, V3D_HIDE_HELPLINES, REDRAWVIEW3D, "Relationship Lines", 10, -10, 140, 19, &vd->flag, 0, 0, 0, 0, "Draw dashed lines indicating Parent, Constraint, or Hook relationships");
2543 uiDefButBitS(block, TOG, V3D_SOLID_TEX, REDRAWVIEW3D, "Solid Tex", 10, -30, 140, 19, &vd->flag2, 0, 0, 0, 0, "Display textures in Solid draw type (Shift T)");
2544 uiBlockEndAlign(block);
2546 uiDefBut(block, LABEL, 1, "View Locking:", 160, 60, 150, 19, NULL, 0.0, 0.0, 0, 0, "");
2547 uiBlockBeginAlign(block);
2548 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, REDRAWVIEW3D, "Object:", 160, 40, 140, 19, &vd->ob_centre, "Lock view to center to this Object");
2549 uiDefBut(block, TEX, REDRAWVIEW3D, "Bone:", 160, 20, 140, 19, vd->ob_centre_bone, 1, 31, 0, 0, "If view locked to Object, use this Bone to lock to view to");
2551 uiDefBut(block, LABEL, 1, "Keyframe Display:", 160, -2, 150, 19, NULL, 0.0, 0.0, 0, 0, "");
2552 uiBlockBeginAlign(block);
2553 uiDefButBitS(block, TOG, ANIMFILTER_ACTIVE, REDRAWVIEW3D, "Active",160, -22, 50, 19, &vd->keyflags, 0, 0, 0, 0, "Show keyframes for active element only (i.e. active bone or active material)");
2554 uiDefButBitS(block, TOG, ANIMFILTER_MUTED, REDRAWVIEW3D, "Muted",210, -22, 50, 19, &vd->keyflags, 0, 0, 0, 0, "Show keyframes in muted channels");
2555 uiDefButBitS(block, TOG, ANIMFILTER_LOCAL, REDRAWVIEW3D, "Local",260, -22, 50, 19, &vd->keyflags, 0, 0, 0, 0, "Show keyframes directly connected to datablock");
2556 if ((vd->keyflags & ANIMFILTER_LOCAL)==0) {
2557 uiDefButBitS(block, TOGN, ANIMFILTER_NOMAT, REDRAWVIEW3D, "Material",160, -42, 75, 19, &vd->keyflags, 0, 0, 0, 0, "Show keyframes for any available Materials");
2558 uiDefButBitS(block, TOGN, ANIMFILTER_NOSKEY, REDRAWVIEW3D, "ShapeKey",235, -42, 75, 19, &vd->keyflags, 0, 0, 0, 0, "Show keyframes for any available Shape Keys");
2560 uiBlockEndAlign(block);
2563 static void view3d_panel_preview(ScrArea *sa, short cntrl) // VIEW3D_HANDLER_PREVIEW
2566 View3D *v3d= sa->spacedata.first;
2569 block= uiNewBlock(&sa->uiblocks, "view3d_panel_preview", UI_EMBOSS, UI_HELV, sa->win);
2570 uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | UI_PNL_SCALE | cntrl);
2571 uiSetPanelHandler(VIEW3D_HANDLER_PREVIEW); // for close and esc
2573 ofsx= -150+(sa->winx/2)/v3d->blockscale;
2574 ofsy= -100+(sa->winy/2)/v3d->blockscale;
2575 if(uiNewPanel(sa, block, "Preview", "View3d", ofsx, ofsy, 300, 200)==0) return;
2577 uiBlockSetDrawExtraFunc(block, BIF_view3d_previewdraw);
2579 if(G.scene->recalc & SCE_PRV_CHANGED) {
2580 G.scene->recalc &= ~SCE_PRV_CHANGED;
2581 //printf("found recalc\n");
2582 BIF_view3d_previewrender_free(sa->spacedata.first);
2583 BIF_preview_changed(0);
2587 static void view3d_panel_gpencil(short cntrl) // VIEW3D_HANDLER_GREASEPENCIL
2594 block= uiNewBlock(&curarea->uiblocks, "view3d_panel_gpencil", UI_EMBOSS, UI_HELV, curarea->win);
2595 uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | cntrl);
2596 uiSetPanelHandler(VIEW3D_HANDLER_GREASEPENCIL); // for close and esc
2597 if (uiNewPanel(curarea, block, "Grease Pencil", "View3d", 100, 30, 318, 204)==0) return;
2599 if (G.f & (G_VERTEXPAINT|G_WEIGHTPAINT|G_TEXTUREPAINT|G_GREASEPENCIL)) {
2600 uiBlockSetFlag(block, UI_BLOCK_FRONTBUFFER); // force old style frontbuffer draw
2603 /* allocate memory for gpd if drawing enabled (this must be done first or else we crash) */
2604 if (vd->flag2 & V3D_DISPGP) {
2605 if (vd->gpd == NULL)
2606 gpencil_data_setactive(curarea, gpencil_data_addnew());
2609 if (vd->flag2 & V3D_DISPGP) {
2610 bGPdata *gpd= vd->gpd;
2613 /* this is a variable height panel, newpanel doesnt force new size on existing panels */
2614 /* so first we make it default height */
2615 uiNewPanelHeight(block, 204);
2617 /* draw button for showing gpencil settings and drawings */
2618 uiDefButBitS(block, TOG, V3D_DISPGP, B_REDR, "Use Grease Pencil", 10, 225, 150, 20, &vd->flag2, 0, 0, 0, 0, "Display freehand annotations overlay over this 3D View (draw using Shift-LMB)");
2620 /* extend the panel if the contents won't fit */
2621 newheight= draw_gpencil_panel(block, gpd, curarea);
2622 uiNewPanelHeight(block, newheight);
2625 uiDefButBitS(block, TOG, V3D_DISPGP, B_REDR, "Use Grease Pencil", 10, 225, 150, 20, &vd->flag2, 0, 0, 0, 0, "Display freehand annotations overlay over this 3D View");
2626 uiDefBut(block, LABEL, 1, " ", 160, 180, 150, 20, NULL, 0.0, 0.0, 0, 0, "");
2631 static void view3d_blockhandlers(ScrArea *sa)
2633 View3D *v3d= sa->spacedata.first;
2636 /* warning; blocks need to be freed each time, handlers dont remove */
2637 uiFreeBlocksWin(&sa->uiblocks, sa->win);
2639 /*uv face-sel and wp mode when mixed with wire leave depth enabled causing
2640 models to draw over the UI */
2641 glDisable(GL_DEPTH_TEST);
2643 for(a=0; a<SPACE_MAXHANDLER; a+=2) {
2644 switch(v3d->blockhandler[a]) {
2645 case VIEW3D_HANDLER_PROPERTIES:
2646 view3d_panel_properties(v3d->blockhandler[a+1]);
2648 case VIEW3D_HANDLER_BACKGROUND:
2649 view3d_panel_background(v3d->blockhandler[a+1]);
2651 case VIEW3D_HANDLER_OBJECT:
2652 view3d_panel_object(v3d->blockhandler[a+1]);
2654 case VIEW3D_HANDLER_PREVIEW:
2655 view3d_panel_preview(sa, v3d->blockhandler[a+1]);
2657 case VIEW3D_HANDLER_TRANSFORM:
2658 view3d_panel_transform_spaces(v3d->blockhandler[a+1]);
2660 case VIEW3D_HANDLER_GREASEPENCIL:
2661 view3d_panel_gpencil(v3d->blockhandler[a+1]);
2664 /* clear action value for event */
2665 v3d->blockhandler[a+1]= 0;
2667 uiDrawBlocksPanels(sa, 0);
2671 /* ****************** View3d afterdraw *************** */
2673 typedef struct View3DAfter {
2674 struct View3DAfter *next, *prev;
2679 /* temp storage of Objects that need to be drawn as last */
2680 void add_view3d_after(View3D *v3d, Base *base, int type, int flag)
2682 View3DAfter *v3da= MEM_callocN(sizeof(View3DAfter), "View 3d after");
2684 BLI_addtail(&v3d->afterdraw, v3da);
2690 /* clears zbuffer and draws it over */
2691 static void view3d_draw_xray(View3D *v3d, int clear)
2693 View3DAfter *v3da, *next;
2696 for(v3da= v3d->afterdraw.first; v3da; v3da= v3da->next)
2697 if(v3da->type==V3D_XRAY) doit= 1;
2700 if(clear && v3d->zbuf) glClear(GL_DEPTH_BUFFER_BIT);
2703 for(v3da= v3d->afterdraw.first; v3da; v3da= next) {
2705 if(v3da->type==V3D_XRAY) {
2706 draw_object(v3da->base, v3da->flag);
2707 BLI_remlink(&v3d->afterdraw, v3da);
2715 /* disables write in zbuffer and draws it over */
2716 static void view3d_draw_transp(View3D *v3d)
2718 View3DAfter *v3da, *next;
2723 for(v3da= v3d->afterdraw.first; v3da; v3da= next) {
2725 if(v3da->type==V3D_TRANSP) {
2726 draw_object(v3da->base, v3da->flag);
2727 BLI_remlink(&v3d->afterdraw, v3da);
2737 /* *********************** */
2740 In most cases call draw_dupli_objects,
2741 draw_dupli_objects_color was added because when drawing set dupli's
2742 we need to force the color
2744 static void draw_dupli_objects_color(View3D *v3d, Base *base, int color)
2751 short transflag, use_displist= -1; /* -1 is initialize */
2754 if (base->object->restrictflag & OB_RESTRICT_VIEW) return;
2756 tbase.flag= OB_FROMDUPLI|base->flag;
2757 lb= object_duplilist(G.scene, base->object);
2759 for(dob= lb->first; dob; dob= dob->next) {
2762 tbase.object= dob->ob;
2764 /* extra service: draw the duplicator in drawtype of parent */
2765 /* MIN2 for the drawtype to allow bounding box objects in groups for lods */
2766 dt= tbase.object->dt; tbase.object->dt= MIN2(tbase.object->dt, base->object->dt);
2767 dtx= tbase.object->dtx; tbase.object->dtx= base->object->dtx;
2769 /* negative scale flag has to propagate */
2770 transflag= tbase.object->transflag;
2771 if(base->object->transflag & OB_NEG_SCALE)
2772 tbase.object->transflag ^= OB_NEG_SCALE;
2774 BIF_ThemeColorBlend(color, TH_BACK, 0.5);
2776 /* generate displist, test for new object */
2777 if(use_displist==1 && dob->prev && dob->prev->ob!=dob->ob) {
2779 glDeleteLists(displist, 1);
2781 /* generate displist */
2782 if(use_displist == -1) {
2784 /* lamp drawing messes with matrices, could be handled smarter... but this works */
2785 if(dob->ob->type==OB_LAMP || dob->type==OB_DUPLIGROUP)
2788 /* disable boundbox check for list creation */
2789 object_boundbox_flag(dob->ob, OB_BB_DISABLED, 1);
2790 /* need this for next part of code */
2791 bb= object_get_boundbox(dob->ob);
2793 Mat4One(dob->ob->obmat); /* obmat gets restored */
2795 displist= glGenLists(1);
2796 glNewList(displist, GL_COMPILE);
2797 draw_object(&tbase, DRAW_CONSTCOLOR);
2801 object_boundbox_flag(dob->ob, OB_BB_DISABLED, 0);
2805 mymultmatrix(dob->mat);
2806 if(boundbox_clip(dob->mat, bb))
2807 glCallList(displist);
2808 myloadmatrix(G.vd->viewmat);
2811 Mat4CpyMat4(dob->ob->obmat, dob->mat);
2812 draw_object(&tbase, DRAW_CONSTCOLOR);
2815 tbase.object->dt= dt;
2816 tbase.object->dtx= dtx;
2817 tbase.object->transflag= transflag;
2821 /* Transp afterdraw disabled, afterdraw only stores base pointers, and duplis can be same obj */
2823 free_object_duplilist(lb); /* does restore */
2826 glDeleteLists(displist, 1);
2829 static void draw_dupli_objects(View3D *v3d, Base *base)
2831 /* define the color here so draw_dupli_objects_color can be called
2832 * from the set loop */
2834 int color= (base->flag & SELECT)?TH_SELECT:TH_WIRE;
2836 if(base->object->dup_group && base->object->dup_group->id.us<1)
2839 draw_dupli_objects_color(v3d, base, color);
2842 void view3d_update_depths(View3D *v3d)
2844 /* Create storage for, and, if necessary, copy depth buffer */
2845 if(!v3d->depths) v3d->depths= MEM_callocN(sizeof(ViewDepths),"ViewDepths");
2847 ViewDepths *d= v3d->depths;
2848 if(d->w != v3d->area->winx ||
2849 d->h != v3d->area->winy ||
2851 d->w= v3d->area->winx;
2852 d->h= v3d->area->winy;
2854 MEM_freeN(d->depths);
2855 d->depths= MEM_mallocN(sizeof(float)*d->w*d->h,"View depths");
2860 glReadPixels(v3d->area->winrct.xmin,v3d->area->winrct.ymin,d->w,d->h,
2861 GL_DEPTH_COMPONENT,GL_FLOAT, d->depths);
2863 glGetDoublev(GL_DEPTH_RANGE,d->depth_range);
2870 /* Enable sculpting in wireframe mode by drawing sculpt object only to the depth buffer */
2871 static void draw_sculpt_depths(View3D *v3d)
2875 int dt= MIN2(v3d->drawtype, ob->dt);
2876 if(v3d->zbuf==0 && dt>OB_WIRE)
2880 int orig_vdt = v3d->drawtype;
2881 int orig_zbuf = v3d->zbuf;
2882 int orig_odt = ob->dt;
2884 glGetBooleanv(GL_DEPTH_TEST, &depth_on);
2885 v3d->drawtype = ob->dt = OB_SOLID;
2888 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
2889 glEnable(GL_DEPTH_TEST);
2890 draw_object(BASACT, 0);
2891 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
2893 glDisable(GL_DEPTH_TEST);
2895 v3d->drawtype = orig_vdt;
2896 v3d->zbuf = orig_zbuf;
2901 void draw_depth(ScrArea *sa, void *spacedata, int (* func)(void *))
2903 View3D *v3d= spacedata;
2908 /* temp set drawtype to solid */
2910 /* Setting these temporarily is not nice */
2913 glalphaclip = U.glalphaclip;
2915 U.glalphaclip = 0.5; /* not that nice but means we wont zoom into billboards */
2916 v3d->flag &= ~V3D_SELECT_OUTLINE;
2918 setwinmatrixview3d(sa->winx, sa->winy, NULL); /* 0= no pick rect */
2919 setviewmatrixview3d(); /* note: calls where_is_object for camera... */
2921 Mat4MulMat4(v3d->persmat, v3d->viewmat, sa->winmat);
2922 Mat4Invert(v3d->persinv, v3d->persmat);
2923 Mat4Invert(v3d->viewinv, v3d->viewmat);
2925 glClear(GL_DEPTH_BUFFER_BIT);
2927 myloadmatrix(v3d->viewmat);
2928 persp(PERSP_STORE); // store correct view for persp(PERSP_VIEW) calls
2930 if(v3d->flag & V3D_CLIPPING) {
2931 view3d_set_clipping(v3d);
2935 glEnable(GL_DEPTH_TEST);
2937 /* draw set first */
2939 for(SETLOOPER(G.scene->set, base)) {
2940 if(v3d->lay & base->lay) {
2941 if (func == NULL || func(base)) {
2942 draw_object(base, 0);
2943 if(base->object->transflag & OB_DUPLI) {
2944 draw_dupli_objects_color(v3d, base, TH_WIRE);
2951 for(base= G.scene->base.first; base; base= base->next) {
2952 if(v3d->lay & base->lay) {
2953 if (func == NULL || func(base)) {
2955 if(base->object->transflag & OB_DUPLI) {
2956 draw_dupli_objects(v3d, base);
2958 draw_object(base, 0);
2963 /* this isnt that nice, draw xray objects as if they are normal */
2964 if (v3d->afterdraw.first) {
2965 View3DAfter *v3da, *next;
2969 glDepthFunc(GL_ALWAYS); /* always write into the depth bufer, overwriting front z values */
2970 for(v3da= v3d->afterdraw.first; v3da; v3da= next) {
2972 if(v3da->type==V3D_XRAY) {
2973 draw_object(v3da->base, 0);
2976 /* dont remove this time */
2980 glDepthFunc(GL_LEQUAL); /* Now write the depth buffer normally */
2981 for(v3da= v3d->afterdraw.first; v3da; v3da= next) {
2983 if(v3da->type==V3D_XRAY) {
2984 v3d->xray= TRUE; v3d->transp= FALSE;
2985 } else if (v3da->type==V3D_TRANSP) {
2986 v3d->xray= FALSE; v3d->transp= TRUE;
2989 draw_object(v3da->base, 0); /* Draw Xray or Transp objects normally */
2990 BLI_remlink(&v3d->afterdraw, v3da);
2998 U.glalphaclip = glalphaclip;
3002 static void draw_viewport_fps(ScrArea *sa);
3004 typedef struct View3DShadow{
3005 struct View3DShadow*next, *prev;
3009 static void gpu_render_lamp_update(View3D *v3d, Object *ob, Object *par, float obmat[][4], ListBase *shadows)
3012 View3DShadow *shadow;
3014 lamp = GPU_lamp_from_blender(G.scene, ob, par);
3017 GPU_lamp_update(lamp, ob->lay, obmat);
3019 if((ob->lay & v3d->lay) && GPU_lamp_has_shadow_buffer(lamp)) {
3020 shadow= MEM_callocN(sizeof(View3DShadow), "View3DShadow");
3021 shadow->lamp = lamp;
3022 BLI_addtail(shadows, shadow);
3027 static void gpu_update_lamps_shadows(Scene *scene, View3D *v3d)
3030 View3DShadow *shadow;
3035 shadows.first= shadows.last= NULL;
3037 /* update lamp transform and gather shadow lamps */
3038 for(SETLOOPER(G.scene, base)) {
3041 if(ob->type == OB_LAMP)
3042 gpu_render_lamp_update(v3d, ob, NULL, ob->obmat, &shadows);
3044 if (ob->transflag & OB_DUPLI) {
3046 ListBase *lb = object_duplilist(G.scene, ob);
3048 for(dob=lb->first; dob; dob=dob->next)
3049 if(dob->ob->type==OB_LAMP)
3050 gpu_render_lamp_update(v3d, dob->ob, ob, dob->mat, &shadows);
3052 free_object_duplilist(lb);
3056 /* render shadows after updating all lamps, nested object_duplilist
3057 * don't work correct since it's replacing object matrices */
3058 for(shadow=shadows.first; shadow; shadow=shadow->next) {
3059 /* this needs to be done better .. */
3060 float viewmat[4][4], winmat[4][4];
3061 int drawtype, lay, winsize, flag2;
3063 drawtype= v3d->drawtype;
3065 flag2= v3d->flag2 & V3D_SOLID_TEX;
3067 v3d->drawtype = OB_SOLID;
3068 v3d->lay &= GPU_lamp_shadow_layer(shadow->lamp);
3069 v3d->flag2 &= ~V3D_SOLID_TEX;
3071 GPU_lamp_shadow_buffer_bind(shadow->lamp, viewmat, &winsize, winmat);