diff options
Diffstat (limited to 'source/blender/editors')
33 files changed, 1870 insertions, 1378 deletions
diff --git a/source/blender/editors/Makefile b/source/blender/editors/Makefile index 6a9d695ab0e..e259168a4ef 100644 --- a/source/blender/editors/Makefile +++ b/source/blender/editors/Makefile @@ -43,7 +43,7 @@ DIRS = armature \ metaball \ gpencil \ physics \ - preview \ + render \ uvedit \ space_outliner \ space_time \ diff --git a/source/blender/editors/SConscript b/source/blender/editors/SConscript index ccffbdb15d5..226e9247f91 100644 --- a/source/blender/editors/SConscript +++ b/source/blender/editors/SConscript @@ -14,7 +14,7 @@ SConscript(['datafiles/SConscript', 'curve/SConscript', 'gpencil/SConscript', 'physics/SConscript', - 'preview/SConscript', + 'render/SConscript', 'sound/SConscript', 'space_buttons/SConscript', 'space_file/SConscript', diff --git a/source/blender/editors/include/ED_particle.h b/source/blender/editors/include/ED_particle.h index 28807caa255..a052142102d 100644 --- a/source/blender/editors/include/ED_particle.h +++ b/source/blender/editors/include/ED_particle.h @@ -38,6 +38,7 @@ struct RadialControl; struct rcti; struct wmWindowManager; struct PTCacheEdit; +struct Scene; /* particle edit mode */ void PE_free_ptcache_edit(struct PTCacheEdit *edit); @@ -46,7 +47,7 @@ int PE_start_edit(struct PTCacheEdit *edit); /* access */ struct PTCacheEdit *PE_get_current(struct Scene *scene, struct Object *ob); int PE_minmax(struct Scene *scene, float *min, float *max); -struct ParticleEditSettings *PE_settings(Scene *scene); +struct ParticleEditSettings *PE_settings(struct Scene *scene); /* update calls */ void PE_hide_keys_time(struct Scene *scene, struct PTCacheEdit *edit, float cfra); @@ -59,15 +60,11 @@ int PE_circle_select(struct bContext *C, int selecting, short *mval, float rad); int PE_lasso_select(struct bContext *C, short mcords[][2], short moves, short select); /* undo */ -void PE_undo_push(Scene *scene, char *str); -void PE_undo_step(Scene *scene, int step); -void PE_undo(Scene *scene); -void PE_redo(Scene *scene); -void PE_undo_menu(Scene *scene, Object *ob); - -/* operators */ -void ED_operatortypes_particle(void); -void ED_keymap_particle(struct wmWindowManager *wm); +void PE_undo_push(struct Scene *scene, char *str); +void PE_undo_step(struct Scene *scene, int step); +void PE_undo(struct Scene *scene); +void PE_redo(struct Scene *scene); +void PE_undo_menu(struct Scene *scene, struct Object *ob); #endif /* ED_PARTICLE_H */ diff --git a/source/blender/editors/include/ED_physics.h b/source/blender/editors/include/ED_physics.h index 6ab804230d0..ee340c54e7d 100644 --- a/source/blender/editors/include/ED_physics.h +++ b/source/blender/editors/include/ED_physics.h @@ -31,11 +31,8 @@ #define ED_PHYSICS_H /* operators */ - -void ED_operatortypes_boids(void); -void ED_operatortypes_pointcache(void); -void ED_operatortypes_fluid(void); -//void ED_keymap_pointcache(struct wmWindowManager *wm); +void ED_operatortypes_physics(void); +void ED_keymap_physics(struct wmWindowManager *wm); #endif /* ED_PHYSICS_H */ diff --git a/source/blender/editors/include/ED_previewrender.h b/source/blender/editors/include/ED_render.h index b858a269236..be93bf92e5e 100644 --- a/source/blender/editors/include/ED_previewrender.h +++ b/source/blender/editors/include/ED_render.h @@ -21,22 +21,29 @@ * ***** END GPL LICENSE BLOCK ***** */ -#ifndef ED_PREVIEWRENDER_H -#define ED_PREVIEWRENDER_H +#ifndef ED_RENDER_H +#define ED_RENDER_H #include "DNA_vec_types.h" -struct View3D; -struct SpaceButs; -struct RenderInfo; -struct Scene; -struct Image; -struct Render; struct bContext; struct ID; +struct Main; struct MTex; +struct Render; +struct RenderInfo; + +/* render_ops.c */ + +void ED_operatortypes_render(void); + +/* render_shading.c */ + +void ED_render_id_flush_update(struct Main *bmain, struct ID *id); + +/* render_preview.c */ -#define PREVIEW_RENDERSIZE 140 +#define _RENDERSIZE 140 /* stores rendered preview - is also used for icons */ typedef struct RenderInfo { diff --git a/source/blender/editors/include/UI_interface_icons.h b/source/blender/editors/include/UI_interface_icons.h index bf160b4ad68..afe6a2b9dcb 100644 --- a/source/blender/editors/include/UI_interface_icons.h +++ b/source/blender/editors/include/UI_interface_icons.h @@ -57,9 +57,9 @@ int UI_icon_get_height(int icon_id); void UI_icon_draw(float x, float y, int icon_id); void UI_icon_draw_preview(float x, float y, int icon_id, int nocreate); -void UI_icon_draw_aspect(float x, float y, int icon_id, float aspect); -void UI_icon_draw_aspect_blended(float x, float y, int icon_id, float aspect, int shade); -void UI_icon_draw_size_blended(float x, float y, int size, int icon_id, int shade); +void UI_icon_draw_aspect(float x, float y, int icon_id, float aspect, float alpha); +void UI_icon_draw_aspect_color(float x, float y, int icon_id, float aspect, float *rgb); +void UI_icon_draw_size(float x, float y, int size, int icon_id, float alpha); void UI_icons_free(); void UI_icons_free_drawinfo(void *drawinfo); diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index 0c11e64c0bb..1153c475339 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -59,7 +59,7 @@ #include "BIF_glutil.h" #include "ED_datafiles.h" -#include "ED_previewrender.h" +#include "ED_render.h" #include "UI_interface.h" #include "UI_interface_icons.h" @@ -86,23 +86,45 @@ typedef struct IconImage { typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha); +#define ICON_TYPE_PREVIEW 0 +#define ICON_TYPE_TEXTURE 1 +#define ICON_TYPE_BUFFER 2 +#define ICON_TYPE_VECTOR 3 + typedef struct DrawInfo { + int type; + + union { + /* type specific data */ + struct { + VectorDrawFunc func; + } vector; + struct { + IconImage* image; + } buffer; + struct { + int x, y, w, h; + } texture; + } data; +} DrawInfo; + +typedef struct IconTexture { + GLuint id; int w; int h; - float aspect; - VectorDrawFunc drawFunc; /* If drawFunc is defined then it is a vector icon, otherwise use rect */ - IconImage* icon; -} DrawInfo; + float invw; + float invh; +} IconTexture; /* ******************* STATIC LOCAL VARS ******************* */ /* static here to cache results of icon directory scan, so it's not * scanning the filesystem each time the menu is drawn */ static struct ListBase iconfilelist = {0, 0}; - +static IconTexture icongltex = {0, 0, 0, 0.0f, 0.0f}; /* **************************************************** */ -static void def_internal_icon(ImBuf *bbuf, int icon_id, int xofs, int yofs, int size) +static void def_internal_icon(ImBuf *bbuf, int icon_id, int xofs, int yofs, int size, int type) { Icon *new_icon = NULL; IconImage *iimg = NULL; @@ -116,23 +138,28 @@ static void def_internal_icon(ImBuf *bbuf, int icon_id, int xofs, int yofs, int new_icon->type = 0; di = MEM_callocN(sizeof(DrawInfo), "drawinfo"); - di->drawFunc = 0; - di->w = size; - di->h = size; - di->aspect = 1.0f; - - iimg = MEM_mallocN(sizeof(IconImage), "icon_img"); - iimg->rect = MEM_mallocN(size*size*sizeof(unsigned int), "icon_rect"); - iimg->w = size; - iimg->h = size; + di->type= type; - /* Here we store the rect in the icon - same as before */ - imgsize = bbuf->x; - for (y=0; y<size; y++) { - memcpy(&iimg->rect[y*size], &bbuf->rect[(y+yofs)*imgsize+xofs], size*sizeof(int)); + if(type == ICON_TYPE_TEXTURE) { + di->data.texture.x= xofs; + di->data.texture.y= yofs; + di->data.texture.w= size; + di->data.texture.h= size; } + else if(type == ICON_TYPE_BUFFER) { + iimg = MEM_mallocN(sizeof(IconImage), "icon_img"); + iimg->rect = MEM_mallocN(size*size*sizeof(unsigned int), "icon_rect"); + iimg->w = size; + iimg->h = size; + + /* Here we store the rect in the icon - same as before */ + imgsize = bbuf->x; + for (y=0; y<size; y++) { + memcpy(&iimg->rect[y*size], &bbuf->rect[(y+yofs)*imgsize+xofs], size*sizeof(int)); + } - di->icon = iimg; + di->data.buffer.image = iimg; + } new_icon->drawinfo_free = UI_icons_free_drawinfo; new_icon->drawinfo = di; @@ -151,11 +178,8 @@ static void def_internal_vicon( int icon_id, VectorDrawFunc drawFunc) new_icon->type = 0; di = MEM_callocN(sizeof(DrawInfo), "drawinfo"); - di->drawFunc =drawFunc; - di->w = ICON_DEFAULT_HEIGHT; - di->h = ICON_DEFAULT_HEIGHT; - di->aspect = 1.0f; - di->icon = NULL; + di->type= ICON_TYPE_VECTOR; + di->data.vector.func =drawFunc; new_icon->drawinfo_free = 0; new_icon->drawinfo = di; @@ -431,7 +455,7 @@ static void init_internal_icons() { bTheme *btheme= U.themes.first; ImBuf *bbuf= NULL; - int x, y; + int x, y, icontype; char iconfilestr[FILE_MAXDIR+FILE_MAXFILE]; char filenamestr[FILE_MAXFILE+16]; // 16 == strlen(".blender/icons/")+1 @@ -451,17 +475,54 @@ static void init_internal_icons() printf("\n***WARNING***\nIcons file %s too small.\nUsing built-in Icons instead\n", iconfilestr); IMB_freeImBuf(bbuf); bbuf= NULL; + } } } - } if(bbuf==NULL) bbuf = IMB_ibImageFromMemory((int *)datatoc_blenderbuttons, datatoc_blenderbuttons_size, IB_rect); + if(bbuf) { + /* free existing texture if any */ + if(icongltex.id) { + glDeleteTextures(1, &icongltex.id); + icongltex.id= 0; + } + + /* we only use a texture for cards with non-power of two */ + if(GLEW_ARB_texture_non_power_of_two) { + glGenTextures(1, &icongltex.id); + + if(icongltex.id) { + icongltex.w = bbuf->x; + icongltex.h = bbuf->y; + icongltex.invw = 1.0f/bbuf->x; + icongltex.invh = 1.0f/bbuf->y; + + glBindTexture(GL_TEXTURE_2D, icongltex.id); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bbuf->x, bbuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, bbuf->rect); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glBindTexture(GL_TEXTURE_2D, 0); + + if(glGetError() == GL_OUT_OF_MEMORY) { + glDeleteTextures(1, &icongltex.id); + icongltex.id= 0; + } + } + } + } + + if(icongltex.id) + icontype= ICON_TYPE_TEXTURE; + else + icontype= ICON_TYPE_BUFFER; + for (y=0; y<ICON_GRID_ROWS; y++) { for (x=0; x<ICON_GRID_COLS; x++) { def_internal_icon(bbuf, BIFICONID_FIRST + y*ICON_GRID_COLS + x, x*(ICON_GRID_W+ICON_GRID_MARGIN)+ICON_GRID_MARGIN, - y*(ICON_GRID_H+ICON_GRID_MARGIN)+ICON_GRID_MARGIN, ICON_GRID_W); + y*(ICON_GRID_H+ICON_GRID_MARGIN)+ICON_GRID_MARGIN, ICON_GRID_W, + icontype); } } @@ -588,6 +649,11 @@ ListBase *UI_iconfile_list(void) void UI_icons_free() { + if(icongltex.id) { + glDeleteTextures(1, &icongltex.id); + icongltex.id= 0; + } + free_iconfile_list(&iconfilelist); BKE_icons_free(); } @@ -596,12 +662,14 @@ void UI_icons_free_drawinfo(void *drawinfo) { DrawInfo *di = drawinfo; - if (di) - { - if (di->icon) { - MEM_freeN(di->icon->rect); - MEM_freeN(di->icon); + if(di) { + if(di->type == ICON_TYPE_BUFFER) { + if(di->data.buffer.image) { + MEM_freeN(di->data.buffer.image->rect); + MEM_freeN(di->data.buffer.image); + } } + MEM_freeN(di); } } @@ -611,12 +679,7 @@ static DrawInfo *icon_create_drawinfo() DrawInfo *di = NULL; di = MEM_callocN(sizeof(DrawInfo), "di_icon"); - - di->drawFunc = 0; - di->w = ICON_DEFAULT_HEIGHT; - di->h = ICON_DEFAULT_HEIGHT; - di->icon = NULL; - di->aspect = 1.0f; + di->type= ICON_TYPE_PREVIEW; return di; } @@ -640,7 +703,7 @@ int UI_icon_get_width(int icon_id) } if (di) - return di->w; + return ICON_DEFAULT_HEIGHT; return 0; } @@ -665,7 +728,7 @@ int UI_icon_get_height(int icon_id) } if (di) - return di->h; + return ICON_DEFAULT_HEIGHT; return 0; } @@ -718,12 +781,23 @@ static void icon_set_image(bContext *C, ID *id, PreviewImage* prv_img, int miple prv_img->w[miplevel], prv_img->h[miplevel]); } -static void icon_draw_rect(float x, float y, int w, int h, float aspect, int rw, int rh, unsigned int *rect) +static void icon_draw_rect(float x, float y, int w, int h, float aspect, int rw, int rh, unsigned int *rect, float alpha, float *rgb) { - + /* modulate color */ + if(alpha != 1.0f) + glPixelTransferf(GL_ALPHA_SCALE, alpha); + + if(rgb) { + glPixelTransferf(GL_RED_SCALE, rgb[0]); + glPixelTransferf(GL_GREEN_SCALE, rgb[1]); + glPixelTransferf(GL_BLUE_SCALE, rgb[2]); + } + + /* position */ glRasterPos2f(x, y); // XXX ui_rasterpos_safe(x, y, aspect); + /* draw */ if((w<1 || h<1)) { // XXX - TODO 2.5 verify whether this case can happen // and only print in debug @@ -731,23 +805,68 @@ static void icon_draw_rect(float x, float y, int w, int h, float aspect, int rw, } /* rect contains image in 'rendersize', we only scale if needed */ else if(rw!=w && rh!=h) { - ImBuf *ima; if(w>2000 || h>2000) { /* something has gone wrong! */ printf("insane icon size w=%d h=%d\n",w,h); - return; } - /* first allocate imbuf for scaling and copy preview into it */ - ima = IMB_allocImBuf(rw, rh, 32, IB_rect, 0); - memcpy(ima->rect, rect, rw*rh*sizeof(unsigned int)); - - /* scale it */ - IMB_scaleImBuf(ima, w, h); - glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, ima->rect); - - IMB_freeImBuf(ima); + else { + ImBuf *ima; + + /* first allocate imbuf for scaling and copy preview into it */ + ima = IMB_allocImBuf(rw, rh, 32, IB_rect, 0); + memcpy(ima->rect, rect, rw*rh*sizeof(unsigned int)); + + /* scale it */ + IMB_scaleImBuf(ima, w, h); + glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, ima->rect); + + IMB_freeImBuf(ima); + } } else glDrawPixels(w, h, GL_RGBA, GL_UNSIGNED_BYTE, rect); + + /* restore color */ + if(alpha != 0.0f) + glPixelTransferf(GL_ALPHA_SCALE, 1.0f); + + if(rgb) { + glPixelTransferf(GL_RED_SCALE, 1.0f); + glPixelTransferf(GL_GREEN_SCALE, 1.0f); + glPixelTransferf(GL_BLUE_SCALE, 1.0f); + } +} + +static void icon_draw_texture(float x, float y, float w, float h, int ix, int iy, int iw, int ih, float alpha, float *rgb) +{ + float x1, x2, y1, y2; + + if(rgb) glColor4f(rgb[0], rgb[1], rgb[2], alpha); + else glColor4f(1.0f, 1.0f, 1.0f, alpha); + + x1= ix*icongltex.invw; + x2= (ix + ih)*icongltex.invw; + y1= iy*icongltex.invh; + y2= (iy + ih)*icongltex.invh; + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, icongltex.id); + + glBegin(GL_QUADS); + glTexCoord2f(x1, y1); + glVertex2f(x, y); + + glTexCoord2f(x2, y1); + glVertex2f(x+w, y); + + glTexCoord2f(x2, y2); + glVertex2f(x+w, y+h); + + glTexCoord2f(x1, y2); + glVertex2f(x, y+h); + glEnd(); + + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); } /* Drawing size for preview images at level miplevel */ @@ -760,10 +879,12 @@ static int preview_size(int miplevel) return 0; } -static void icon_draw_size(float x, float y, int icon_id, float aspect, int miplevel, int draw_size, int nocreate) +static void icon_draw_size(float x, float y, int icon_id, float aspect, float alpha, float *rgb, int miplevel, int draw_size, int nocreate) { Icon *icon = NULL; DrawInfo *di = NULL; + IconImage *iimg; + int w, h; icon = BKE_icon_get(icon_id); @@ -771,7 +892,7 @@ static void icon_draw_size(float x, float y, int icon_id, float aspect, int mipl printf("icon_draw_mipmap: Internal error, no icon for icon ID: %d\n", icon_id); return; } - + di = (DrawInfo*)icon->drawinfo; if (!di) { @@ -781,31 +902,38 @@ static void icon_draw_size(float x, float y, int icon_id, float aspect, int mipl icon->drawinfo_free = UI_icons_free_drawinfo; } - di->aspect = aspect; /* scale width and height according to aspect */ - di->w = (int)(draw_size/di->aspect + 0.5f); - di->h = (int)(draw_size/di->aspect + 0.5f); + w = (int)(draw_size/aspect + 0.5f); + h = (int)(draw_size/aspect + 0.5f); - if (di->drawFunc) { + if(di->type == ICON_TYPE_VECTOR) { /* vector icons use the uiBlock transformation, they are not drawn with untransformed coordinates like the other icons */ - di->drawFunc(x, y, ICON_DEFAULT_HEIGHT, ICON_DEFAULT_HEIGHT, 1.0f); + di->data.vector.func(x, y, ICON_DEFAULT_HEIGHT, ICON_DEFAULT_HEIGHT, 1.0f); } - else if (di->icon) { + else if(di->type == ICON_TYPE_TEXTURE) { + icon_draw_texture(x, y, w, h, di->data.texture.x, di->data.texture.y, + di->data.texture.w, di->data.texture.h, alpha, rgb); + } + else if(di->type == ICON_TYPE_BUFFER) { /* it is a builtin icon */ - if (!di->icon->rect) return; /* something has gone wrong! */ + iimg= di->data.buffer.image; - icon_draw_rect(x,y,di->w, di->h, di->aspect, di->icon->w, di->icon->h, di->icon->rect); + if(!iimg->rect) return; /* something has gone wrong! */ + + icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, rgb); } - else { + else if(di->type == ICON_TYPE_PREVIEW) { PreviewImage* pi = BKE_previewimg_get((ID*)icon->obj); - if (pi) { + if(pi) { /* no create icon on this level in code */ + if(!pi->rect[miplevel]) return; /* something has gone wrong! */ - if (!pi->rect[miplevel]) return; /* something has gone wrong! */ - - icon_draw_rect(x,y,di->w, di->h, di->aspect, pi->w[miplevel], pi->h[miplevel], pi->rect[miplevel]); + /* preview images use premul alpha ... */ + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + icon_draw_rect(x, y, w, h, aspect, pi->w[miplevel], pi->h[miplevel], pi->rect[miplevel], 1.0f, NULL); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } } } @@ -847,50 +975,35 @@ int ui_id_icon_get(bContext *C, ID *id) return iconid; } -static void icon_draw_mipmap(float x, float y, int icon_id, float aspect, int miplevel, int nocreate) +static void icon_draw_mipmap(float x, float y, int icon_id, float aspect, float alpha, int miplevel, int nocreate) { int draw_size = preview_size(miplevel); - icon_draw_size(x,y,icon_id, aspect, miplevel, draw_size, nocreate); + icon_draw_size(x, y, icon_id, aspect, alpha, NULL, miplevel, draw_size, nocreate); } +void UI_icon_draw_aspect(float x, float y, int icon_id, float aspect, float alpha) +{ + icon_draw_mipmap(x, y, icon_id, aspect, alpha, PREVIEW_MIPMAP_ZERO, 0); +} -void UI_icon_draw_aspect(float x, float y, int icon_id, float aspect) +void UI_icon_draw_aspect_color(float x, float y, int icon_id, float aspect, float *rgb) { - icon_draw_mipmap(x,y,icon_id, aspect, PREVIEW_MIPMAP_ZERO, 0); + int draw_size = preview_size(PREVIEW_MIPMAP_ZERO); + icon_draw_size(x, y, icon_id, aspect, 1.0f, rgb, PREVIEW_MIPMAP_ZERO, draw_size, 0); } void UI_icon_draw(float x, float y, int icon_id) { - UI_icon_draw_aspect(x, y, icon_id, 1.0f); + UI_icon_draw_aspect(x, y, icon_id, 1.0f, 1.0f); } -void UI_icon_draw_size_blended(float x, float y, int size, int icon_id, int shade) +void UI_icon_draw_size(float x, float y, int size, int icon_id, float alpha) { - if(shade < 0) { - float r= (128+shade)/128.0f; - glPixelTransferf(GL_ALPHA_SCALE, r); - } - - icon_draw_size(x,y,icon_id, 1.0f, 0, size, 1); - - if(shade < 0) - glPixelTransferf(GL_ALPHA_SCALE, 1.0f); + icon_draw_size(x, y, icon_id, 1.0f, alpha, NULL, 0, size, 1); } void UI_icon_draw_preview(float x, float y, int icon_id, int nocreate) { - icon_draw_mipmap(x,y,icon_id, 1.0f, PREVIEW_MIPMAP_LARGE, nocreate); + icon_draw_mipmap(x, y, icon_id, 1.0f, 1.0f, PREVIEW_MIPMAP_LARGE, nocreate); } -void UI_icon_draw_aspect_blended(float x, float y, int icon_id, float aspect, int shade) -{ - if(shade < 0) { - float r= (128+shade)/128.0f; - glPixelTransferf(GL_ALPHA_SCALE, r); - } - - UI_icon_draw_aspect(x, y, icon_id, aspect); - - if(shade < 0) - glPixelTransferf(GL_ALPHA_SCALE, 1.0f); -} diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index d7b136cd661..57dc484f975 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -40,7 +40,7 @@ #include "BKE_utildefines.h" #include "ED_screen.h" -#include "ED_previewrender.h" +#include "ED_render.h" #include "RNA_access.h" diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index d9a6c50315a..007a57fb67a 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -697,7 +697,7 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol) /* icons have been standardized... and this call draws in untransformed coordinates */ #define ICON_HEIGHT 16.0f -static void widget_draw_icon(uiBut *but, BIFIconID icon, int blend, rcti *rect) +static void widget_draw_icon(uiBut *but, BIFIconID icon, float alpha, rcti *rect) { int xs=0, ys=0; float aspect, height; @@ -724,7 +724,7 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, int blend, rcti *rect) if ELEM4(but->type, TOG, ROW, TOGN, LISTROW) { if(but->flag & UI_SELECT); else if(but->flag & UI_ACTIVE); - else blend= -60; + else alpha= 0.5f; } glEnable(GL_BLEND); @@ -757,14 +757,14 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, int blend, rcti *rect) ys= (rect->ymin+rect->ymax- height)/2; } - UI_icon_draw_aspect_blended(xs, ys, icon, aspect, blend); + UI_icon_draw_aspect(xs, ys, icon, aspect, alpha); } if(but->flag & UI_ICON_SUBMENU) { xs= rect->xmax-17; ys= (rect->ymin+rect->ymax- height)/2; - UI_icon_draw_aspect_blended(xs, ys, ICON_RIGHTARROW_THIN, aspect, blend); + UI_icon_draw_aspect(xs, ys, ICON_RIGHTARROW_THIN, aspect, alpha); } glDisable(GL_BLEND); @@ -902,7 +902,7 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB /* check for button text label */ if (but->type == ICONTEXTROW) { - widget_draw_icon(but, (BIFIconID) (but->icon+but->iconadd), 0, rect); + widget_draw_icon(but, (BIFIconID) (but->icon+but->iconadd), 1.0f, rect); } else { @@ -913,14 +913,14 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB else if(but->pointype==INT) dualset= BTST( *(((int *)but->poin)+1), but->bitnr); - widget_draw_icon(but, ICON_DOT, dualset?0:-100, rect); + widget_draw_icon(but, ICON_DOT, dualset?1.0f:0.25f, rect); } /* If there's an icon too (made with uiDefIconTextBut) then draw the icon and offset the text label to accomodate it */ if (but->flag & UI_HAS_ICON) { - widget_draw_icon(but, but->icon+but->iconadd, 0, rect); + widget_draw_icon(but, but->icon+but->iconadd, 1.0f, rect); rect->xmin += UI_icon_get_width(but->icon+but->iconadd); @@ -2581,7 +2581,7 @@ void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, char *name, int iconid, int xs= rect->xmin+4; int ys= 1 + (rect->ymin+rect->ymax- ICON_HEIGHT)/2; glEnable(GL_BLEND); - UI_icon_draw_aspect_blended(xs, ys, iconid, 1.2f, 0); /* XXX scale weak get from fstyle? */ + UI_icon_draw_aspect(xs, ys, iconid, 1.2f, 0.5f); /* XXX scale weak get from fstyle? */ glDisable(GL_BLEND); } } diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index 87c4560916d..c5499ef8f5d 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -175,5 +175,9 @@ void OBJECT_OT_game_property_remove(struct wmOperatorType *ot); void OBJECT_OT_shape_key_add(struct wmOperatorType *ot); void OBJECT_OT_shape_key_remove(struct wmOperatorType *ot); +/* object_group.c */ +void OBJECT_OT_group_add(struct wmOperatorType *ot); +void OBJECT_OT_group_remove(struct wmOperatorType *ot); + #endif /* ED_OBJECT_INTERN_H */ diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index 7397cead505..3f975d1e807 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -176,6 +176,9 @@ void ED_operatortypes_object(void) WM_operatortype_append(LATTICE_OT_select_all_toggle); WM_operatortype_append(LATTICE_OT_make_regular); + + WM_operatortype_append(OBJECT_OT_group_add); + WM_operatortype_append(OBJECT_OT_group_remove); /* macros */ ot= WM_operatortype_append_macro("OBJECT_OT_duplicate_move", "Duplicate", OPTYPE_UNDO|OPTYPE_REGISTER); diff --git a/source/blender/editors/physics/physics_boids.c b/source/blender/editors/physics/particle_boids.c index 148359068ad..47d073e2dbb 100644 --- a/source/blender/editors/physics/physics_boids.c +++ b/source/blender/editors/physics/particle_boids.c @@ -25,35 +25,21 @@ * ***** END GPL LICENSE BLOCK ***** */ -//#include <stdlib.h> -//#include <string.h> -// +#include <stdlib.h> + #include "MEM_guardedalloc.h" #include "DNA_boid_types.h" #include "DNA_particle_types.h" -//#include "DNA_curve_types.h" #include "DNA_object_types.h" -//#include "DNA_material_types.h" -//#include "DNA_texture_types.h" #include "DNA_scene_types.h" -//#include "DNA_world_types.h" #include "BKE_boids.h" #include "BKE_context.h" #include "BKE_depsgraph.h" -//#include "BKE_font.h" -//#include "BKE_library.h" -//#include "BKE_main.h" -//#include "BKE_material.h" #include "BKE_particle.h" -//#include "BKE_texture.h" -//#include "BKE_utildefines.h" -//#include "BKE_world.h" -//#include "BLI_editVert.h" #include "BLI_listbase.h" -// #include "RNA_access.h" #include "RNA_enum_types.h" #include "RNA_define.h" @@ -61,13 +47,10 @@ #include "WM_api.h" #include "WM_types.h" -//#include "ED_curve.h" -//#include "ED_mesh.h" -// -//#include "buttons_intern.h" // own include +#include "physics_intern.h" /************************ add/del boid rule operators *********************/ -static int boidrule_add_exec(bContext *C, wmOperator *op) +static int rule_add_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); @@ -101,23 +84,23 @@ static int boidrule_add_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void BOID_OT_boidrule_add(wmOperatorType *ot) +void BOID_OT_rule_add(wmOperatorType *ot) { /* identifiers */ ot->name= "Add Boid Rule"; ot->description = "Add a boid rule to the current boid state."; - ot->idname= "BOID_OT_boidrule_add"; + ot->idname= "BOID_OT_rule_add"; /* api callbacks */ ot->invoke= WM_menu_invoke; - ot->exec= boidrule_add_exec; + ot->exec= rule_add_exec; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; RNA_def_enum(ot->srna, "type", boidrule_type_items, 0, "Type", ""); } -static int boidrule_del_exec(bContext *C, wmOperator *op) +static int rule_del_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); @@ -153,21 +136,21 @@ static int boidrule_del_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void BOID_OT_boidrule_del(wmOperatorType *ot) +void BOID_OT_rule_del(wmOperatorType *ot) { /* identifiers */ ot->name= "Remove Boid Rule"; - ot->idname= "BOID_OT_boidrule_del"; + ot->idname= "BOID_OT_rule_del"; /* api callbacks */ - ot->exec= boidrule_del_exec; + ot->exec= rule_del_exec; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } /************************ move up/down boid rule operators *********************/ -static int boidrule_move_up_exec(bContext *C, wmOperator *op) +static int rule_move_up_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); @@ -194,19 +177,19 @@ static int boidrule_move_up_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void BOID_OT_boidrule_move_up(wmOperatorType *ot) +void BOID_OT_rule_move_up(wmOperatorType *ot) { ot->name= "Move Up Boid Rule"; ot->description= "Move boid rule up in the list."; - ot->idname= "BOID_OT_boidrule_move_up"; + ot->idname= "BOID_OT_rule_move_up"; - ot->exec= boidrule_move_up_exec; + ot->exec= rule_move_up_exec; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -static int boidrule_move_down_exec(bContext *C, wmOperator *op) +static int rule_move_down_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); @@ -233,13 +216,13 @@ static int boidrule_move_down_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void BOID_OT_boidrule_move_down(wmOperatorType *ot) +void BOID_OT_rule_move_down(wmOperatorType *ot) { ot->name= "Move Down Boid Rule"; ot->description= "Move boid rule down in the list."; - ot->idname= "BOID_OT_boidrule_move_down"; + ot->idname= "BOID_OT_rule_move_down"; - ot->exec= boidrule_move_down_exec; + ot->exec= rule_move_down_exec; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; @@ -247,7 +230,7 @@ void BOID_OT_boidrule_move_down(wmOperatorType *ot) /************************ add/del boid state operators *********************/ -static int boidstate_add_exec(bContext *C, wmOperator *op) +static int state_add_exec(bContext *C, wmOperator *op) { PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); ParticleSystem *psys= ptr.data; @@ -273,20 +256,20 @@ static int boidstate_add_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void BOID_OT_boidstate_add(wmOperatorType *ot) +void BOID_OT_state_add(wmOperatorType *ot) { /* identifiers */ ot->name= "Add Boid State"; ot->description = "Add a boid state to the particle system."; - ot->idname= "BOID_OT_boidstate_add"; + ot->idname= "BOID_OT_state_add"; /* api callbacks */ - ot->exec= boidstate_add_exec; + ot->exec= state_add_exec; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -static int boidstate_del_exec(bContext *C, wmOperator *op) +static int state_del_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); @@ -327,21 +310,21 @@ static int boidstate_del_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void BOID_OT_boidstate_del(wmOperatorType *ot) +void BOID_OT_state_del(wmOperatorType *ot) { /* identifiers */ ot->name= "Remove Boid State"; - ot->idname= "BOID_OT_boidstate_del"; + ot->idname= "BOID_OT_state_del"; /* api callbacks */ - ot->exec= boidstate_del_exec; + ot->exec= state_del_exec; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } /************************ move up/down boid state operators *********************/ -static int boidstate_move_up_exec(bContext *C, wmOperator *op) +static int state_move_up_exec(bContext *C, wmOperator *op) { PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); ParticleSystem *psys= ptr.data; @@ -366,19 +349,19 @@ static int boidstate_move_up_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void BOID_OT_boidstate_move_up(wmOperatorType *ot) +void BOID_OT_state_move_up(wmOperatorType *ot) { ot->name= "Move Up Boid State"; ot->description= "Move boid state up in the list."; - ot->idname= "BOID_OT_boidstate_move_up"; + ot->idname= "BOID_OT_state_move_up"; - ot->exec= boidstate_move_up_exec; + ot->exec= state_move_up_exec; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -static int boidstate_move_down_exec(bContext *C, wmOperator *op) +static int state_move_down_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); @@ -403,28 +386,15 @@ static int boidstate_move_down_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void BOID_OT_boidstate_move_down(wmOperatorType *ot) +void BOID_OT_state_move_down(wmOperatorType *ot) { ot->name= "Move Down Boid State"; ot->description= "Move boid state down in the list."; - ot->idname= "BOID_OT_boidstate_move_down"; + ot->idname= "BOID_OT_state_move_down"; - ot->exec= boidstate_move_down_exec; + ot->exec= state_move_down_exec; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -/*******************************************************************************/ -void ED_operatortypes_boids(void) -{ - WM_operatortype_append(BOID_OT_boidrule_add); - WM_operatortype_append(BOID_OT_boidrule_del); - WM_operatortype_append(BOID_OT_boidrule_move_up); - WM_operatortype_append(BOID_OT_boidrule_move_down); - - WM_operatortype_append(BOID_OT_boidstate_add); - WM_operatortype_append(BOID_OT_boidstate_del); - WM_operatortype_append(BOID_OT_boidstate_move_up); - WM_operatortype_append(BOID_OT_boidstate_move_down); -} diff --git a/source/blender/editors/physics/editparticle.c b/source/blender/editors/physics/particle_edit.c index a5e169eba06..3478d63f67e 100644 --- a/source/blender/editors/physics/editparticle.c +++ b/source/blender/editors/physics/particle_edit.c @@ -106,7 +106,7 @@ static void PTCacheUndo_clear(PTCacheEdit *edit); /**************************** utilities *******************************/ -static int PE_poll(bContext *C) +int PE_poll(bContext *C) { Scene *scene= CTX_data_scene(C); Object *ob= CTX_data_active_object(C); @@ -120,7 +120,7 @@ static int PE_poll(bContext *C) return (edit && (ob->mode & OB_MODE_PARTICLE_EDIT)); } -static int PE_hair_poll(bContext *C) +int PE_hair_poll(bContext *C) { Scene *scene= CTX_data_scene(C); Object *ob= CTX_data_active_object(C); @@ -134,7 +134,7 @@ static int PE_hair_poll(bContext *C) return (edit && edit->psys && (ob->mode & OB_MODE_PARTICLE_EDIT)); } -static int PE_poll_3dview(bContext *C) +int PE_poll_3dview(bContext *C) { return PE_poll(C) && CTX_wm_area(C)->spacetype == SPACE_VIEW3D && CTX_wm_region(C)->regiontype == RGN_TYPE_WINDOW; @@ -3948,61 +3948,3 @@ void PARTICLE_OT_specials_menu(wmOperatorType *ot) ot->poll= PE_hair_poll; } -/**************************** registration **********************************/ - -void ED_operatortypes_particle(void) -{ - WM_operatortype_append(PARTICLE_OT_select_all_toggle); - WM_operatortype_append(PARTICLE_OT_select_first); - WM_operatortype_append(PARTICLE_OT_select_last); - WM_operatortype_append(PARTICLE_OT_select_linked); - WM_operatortype_append(PARTICLE_OT_select_less); - WM_operatortype_append(PARTICLE_OT_select_more); - - WM_operatortype_append(PARTICLE_OT_hide); - WM_operatortype_append(PARTICLE_OT_reveal); - - WM_operatortype_append(PARTICLE_OT_rekey); - WM_operatortype_append(PARTICLE_OT_subdivide); - WM_operatortype_append(PARTICLE_OT_remove_doubles); - WM_operatortype_append(PARTICLE_OT_delete); - WM_operatortype_append(PARTICLE_OT_mirror); - - WM_operatortype_append(PARTICLE_OT_brush_set); - WM_operatortype_append(PARTICLE_OT_brush_edit); - WM_operatortype_append(PARTICLE_OT_brush_radial_control); - - WM_operatortype_append(PARTICLE_OT_specials_menu); - - WM_operatortype_append(PARTICLE_OT_particle_edit_toggle); - WM_operatortype_append(PARTICLE_OT_edited_clear); -} - -void ED_keymap_particle(wmWindowManager *wm) -{ - wmKeyMap *keymap; - - keymap= WM_keymap_find(wm, "Particle", 0, 0); - keymap->poll= PE_poll; - - WM_keymap_add_item(keymap, "PARTICLE_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0); - WM_keymap_add_item(keymap, "PARTICLE_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0); - WM_keymap_add_item(keymap, "PARTICLE_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0); - WM_keymap_add_item(keymap, "PARTICLE_OT_select_linked", LKEY, KM_PRESS, 0, 0); - RNA_boolean_set(WM_keymap_add_item(keymap, "PARTICLE_OT_select_linked", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "deselect", 1); - - WM_keymap_add_item(keymap, "PARTICLE_OT_delete", XKEY, KM_PRESS, 0, 0); - WM_keymap_add_item(keymap, "PARTICLE_OT_delete", DELKEY, KM_PRESS, 0, 0); - - WM_keymap_add_item(keymap, "PARTICLE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0); - WM_keymap_add_item(keymap, "PARTICLE_OT_hide", HKEY, KM_PRESS, 0, 0); - RNA_enum_set(WM_keymap_add_item(keymap, "PARTICLE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1); - - WM_keymap_add_item(keymap, "PARTICLE_OT_brush_edit", ACTIONMOUSE, KM_PRESS, 0, 0); - WM_keymap_add_item(keymap, "PARTICLE_OT_brush_edit", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0); - RNA_enum_set(WM_keymap_add_item(keymap, "PARTICLE_OT_brush_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE); - RNA_enum_set(WM_keymap_add_item(keymap, "PARTICLE_OT_brush_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", WM_RADIALCONTROL_STRENGTH); - - WM_keymap_add_item(keymap, "PARTICLE_OT_specials_menu", WKEY, KM_PRESS, 0, 0); -} - diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c new file mode 100644 index 00000000000..cef630b6711 --- /dev/null +++ b/source/blender/editors/physics/particle_object.c @@ -0,0 +1,575 @@ +/** + * $Id: + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009 Blender Foundation. + * All rights reserved. + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <stdlib.h> +#include <string.h> + +#include "MEM_guardedalloc.h" + +#include "DNA_meshdata_types.h" +#include "DNA_modifier_types.h" +#include "DNA_object_types.h" +#include "DNA_particle_types.h" +#include "DNA_scene_types.h" +#include "DNA_windowmanager_types.h" + +#include "BLI_arithb.h" +#include "BLI_listbase.h" + +#include "BKE_context.h" +#include "BKE_depsgraph.h" +#include "BKE_DerivedMesh.h" +#include "BKE_cdderivedmesh.h" +#include "BKE_main.h" +#include "BKE_particle.h" +#include "BKE_pointcache.h" +#include "BKE_utildefines.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "ED_particle.h" + +#include "physics_intern.h" + +/********************** particle system slot operators *********************/ + +static int particle_system_add_exec(bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + Scene *scene = CTX_data_scene(C); + + if(!scene || !ob) + return OPERATOR_CANCELLED; + + object_add_particle_system(scene, ob); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_particle_system_add(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Add Particle System Slot"; + ot->idname= "OBJECT_OT_particle_system_add"; + ot->description="Add a particle system."; + + /* api callbacks */ + ot->exec= particle_system_add_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +static int particle_system_remove_exec(bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + Scene *scene = CTX_data_scene(C); + + if(!scene || !ob) + return OPERATOR_CANCELLED; + + object_remove_particle_system(scene, ob); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_particle_system_remove(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Remove Particle System Slot"; + ot->idname= "OBJECT_OT_particle_system_remove"; + ot->description="Remove the selected particle system."; + + /* api callbacks */ + ot->exec= particle_system_remove_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/********************** new particle settings operator *********************/ + +static int psys_poll(bContext *C) +{ + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); + return (ptr.data != NULL); +} + +static int new_particle_settings_exec(bContext *C, wmOperator *op) +{ + Scene *scene = CTX_data_scene(C); + Main *bmain= CTX_data_main(C); + ParticleSystem *psys; + ParticleSettings *part = NULL; + Object *ob; + PointerRNA ptr; + + ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); + + psys = ptr.data; + + /* add or copy particle setting */ + if(psys->part) + part= psys_copy_settings(psys->part); + else + part= psys_new_settings("ParticleSettings", bmain); + + ob= ptr.id.data; + + if(psys->part) + psys->part->id.us--; + + psys->part = part; + + psys_check_boid_data(psys); + + DAG_scene_sort(scene); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); + + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_new(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "New Particle Settings"; + ot->idname= "PARTICLE_OT_new"; + ot->description="Add new particle settings."; + + /* api callbacks */ + ot->exec= new_particle_settings_exec; + ot->poll= psys_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/********************** keyed particle target operators *********************/ + +static int new_particle_target_exec(bContext *C, wmOperator *op) +{ + Scene *scene = CTX_data_scene(C); + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); + ParticleSystem *psys= ptr.data; + Object *ob = ptr.id.data; + + ParticleTarget *pt; + + if(!psys) + return OPERATOR_CANCELLED; + + pt = psys->targets.first; + for(; pt; pt=pt->next) + pt->flag &= ~PTARGET_CURRENT; + + pt = MEM_callocN(sizeof(ParticleTarget), "keyed particle target"); + + pt->flag |= PTARGET_CURRENT; + pt->psys = 1; + + BLI_addtail(&psys->targets, pt); + + DAG_scene_sort(scene); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); + + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_new_target(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "New Particle Target"; + ot->idname= "PARTICLE_OT_new_target"; + ot->description="Add a new particle target."; + + /* api callbacks */ + ot->exec= new_particle_target_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +static int remove_particle_target_exec(bContext *C, wmOperator *op) +{ + Scene *scene = CTX_data_scene(C); + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); + ParticleSystem *psys= ptr.data; + Object *ob = ptr.id.data; + + ParticleTarget *pt; + + if(!psys) + return OPERATOR_CANCELLED; + + pt = psys->targets.first; + for(; pt; pt=pt->next) { + if(pt->flag & PTARGET_CURRENT) { + BLI_remlink(&psys->targets, pt); + MEM_freeN(pt); + break; + } + + } + pt = psys->targets.last; + + if(pt) + pt->flag |= PTARGET_CURRENT; + + DAG_scene_sort(scene); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); + + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_remove_target(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Remove Particle Target"; + ot->idname= "PARTICLE_OT_remove_target"; + ot->description="Remove the selected particle target."; + + /* api callbacks */ + ot->exec= remove_particle_target_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/************************ move up particle target operator *********************/ + +static int target_move_up_exec(bContext *C, wmOperator *op) +{ + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); + ParticleSystem *psys= ptr.data; + Object *ob = ptr.id.data; + ParticleTarget *pt; + + if(!psys) + return OPERATOR_CANCELLED; + + pt = psys->targets.first; + for(; pt; pt=pt->next) { + if(pt->flag & PTARGET_CURRENT && pt->prev) { + BLI_remlink(&psys->targets, pt); + BLI_insertlink(&psys->targets, pt->prev->prev, pt); + + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + break; + } + } + + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_target_move_up(wmOperatorType *ot) +{ + ot->name= "Move Up Target"; + ot->idname= "PARTICLE_OT_target_move_up"; + ot->description= "Move particle target up in the list."; + + ot->exec= target_move_up_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/************************ move down particle target operator *********************/ + +static int target_move_down_exec(bContext *C, wmOperator *op) +{ + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); + ParticleSystem *psys= ptr.data; + Object *ob = ptr.id.data; + ParticleTarget *pt; + + if(!psys) + return OPERATOR_CANCELLED; + pt = psys->targets.first; + for(; pt; pt=pt->next) { + if(pt->flag & PTARGET_CURRENT && pt->next) { + BLI_remlink(&psys->targets, pt); + BLI_insertlink(&psys->targets, pt->next, pt); + + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + break; + } + } + + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_target_move_down(wmOperatorType *ot) +{ + ot->name= "Move Down Target"; + ot->idname= "PARTICLE_OT_target_move_down"; + ot->description= "Move particle target down in the list."; + + ot->exec= target_move_down_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/************************ connect/disconnect hair operators *********************/ + +static void disconnect_hair(Scene *scene, Object *ob, ParticleSystem *psys) +{ + ParticleSystemModifierData *psmd = psys_get_modifier(ob,psys); + ParticleData *pa; + PTCacheEdit *edit; + PTCacheEditPoint *point; + PTCacheEditKey *ekey = NULL; + HairKey *key; + int i, k; + float hairmat[4][4]; + + if(!ob || !psys || psys->flag & PSYS_GLOBAL_HAIR) + return; + + if(!psys->part || psys->part->type != PART_HAIR) + return; + + edit = psys->edit; + point= edit ? edit->points : NULL; + + for(i=0, pa=psys->particles; i<psys->totpart; i++,pa++) { + if(point) { + ekey = point->keys; + point++; + } + + psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, hairmat); + + for(k=0,key=pa->hair; k<pa->totkey; k++,key++) { + Mat4MulVecfl(hairmat,key->co); + + if(ekey) { + ekey->flag &= ~PEK_USE_WCO; + ekey++; + } + } + } + + psys_free_path_cache(psys, psys->edit); + + psys->flag |= PSYS_GLOBAL_HAIR; + + PE_update_object(scene, ob, 0); +} + +static int disconnect_hair_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); + ParticleSystem *psys= NULL; + int all = RNA_boolean_get(op->ptr, "all"); + + if(!ob) + return OPERATOR_CANCELLED; + + if(all) { + for(psys=ob->particlesystem.first; psys; psys=psys->next) { + disconnect_hair(scene, ob, psys); + } + } + else { + psys = ptr.data; + disconnect_hair(scene, ob, psys); + } + + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_disconnect_hair(wmOperatorType *ot) +{ + ot->name= "Disconnect Hair"; + ot->description= "Disconnect hair from the emitter mesh."; + ot->idname= "PARTICLE_OT_disconnect_hair"; + + ot->exec= disconnect_hair_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + RNA_def_boolean(ot->srna, "all", 0, "All hair", "Disconnect all hair systems from the emitter mesh"); +} + +static void connect_hair(Scene *scene, Object *ob, ParticleSystem *psys) +{ + ParticleSystemModifierData *psmd = psys_get_modifier(ob,psys); + ParticleData *pa; + PTCacheEdit *edit; + PTCacheEditPoint *point; + PTCacheEditKey *ekey; + HairKey *key; + BVHTreeFromMesh bvhtree; + BVHTreeNearest nearest; + MFace *mface; + DerivedMesh *dm = NULL; + int numverts; + int i, k; + float hairmat[4][4], imat[4][4]; + float v[4][3], vec[3]; + + if(!psys || !psys->part || psys->part->type != PART_HAIR) + return; + + edit= psys->edit; + point= edit ? edit->points : NULL; + + if(psmd->dm->deformedOnly) + dm= psmd->dm; + else + dm= mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); + + numverts = dm->getNumVerts (dm); + + memset( &bvhtree, 0, sizeof(bvhtree) ); + + /* convert to global coordinates */ + for (i=0; i<numverts; i++) + Mat4MulVecfl (ob->obmat, CDDM_get_vert(dm, i)->co); + + bvhtree_from_mesh_faces(&bvhtree, dm, 0.0, 2, 6); + + for(i=0, pa= psys->particles; i<psys->totpart; i++,pa++) { + key = pa->hair; + + nearest.index = -1; + nearest.dist = FLT_MAX; + + BLI_bvhtree_find_nearest(bvhtree.tree, key->co, &nearest, bvhtree.nearest_callback, &bvhtree); + + if(nearest.index == -1) { + printf("No nearest point found for hair root!"); + continue; + } + + mface = CDDM_get_face(dm,nearest.index); + + VecCopyf(v[0], CDDM_get_vert(dm,mface->v1)->co); + VecCopyf(v[1], CDDM_get_vert(dm,mface->v2)->co); + VecCopyf(v[2], CDDM_get_vert(dm,mface->v3)->co); + if(mface->v4) { + VecCopyf(v[3], CDDM_get_vert(dm,mface->v4)->co); + MeanValueWeights(v, 4, nearest.co, pa->fuv); + } + else + MeanValueWeights(v, 3, nearest.co, pa->fuv); + + pa->num = nearest.index; + pa->num_dmcache = psys_particle_dm_face_lookup(ob,psmd->dm,pa->num,pa->fuv,NULL); + + psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, hairmat); + Mat4Invert(imat,hairmat); + + VECSUB(vec, nearest.co, key->co); + + if(point) { + ekey = point->keys; + point++; + } + + for(k=0,key=pa->hair; k<pa->totkey; k++,key++) { + VECADD(key->co, key->co, vec); + Mat4MulVecfl(imat,key->co); + + if(ekey) { + ekey->flag |= PEK_USE_WCO; + ekey++; + } + } + } + + free_bvhtree_from_mesh(&bvhtree); + if(!psmd->dm->deformedOnly) + dm->release(dm); + + psys_free_path_cache(psys, psys->edit); + + psys->flag &= ~PSYS_GLOBAL_HAIR; + + PE_update_object(scene, ob, 0); +} + +static int connect_hair_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); + ParticleSystem *psys= NULL; + int all = RNA_boolean_get(op->ptr, "all"); + + if(!ob) + return OPERATOR_CANCELLED; + + if(all) { + for(psys=ob->particlesystem.first; psys; psys=psys->next) { + connect_hair(scene, ob, psys); + } + } + else { + psys = ptr.data; + connect_hair(scene, ob, psys); + } + + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + + return OPERATOR_FINISHED; +} + +void PARTICLE_OT_connect_hair(wmOperatorType *ot) +{ + ot->name= "Connect Hair"; + ot->description= "Connect hair to the emitter mesh."; + ot->idname= "PARTICLE_OT_connect_hair"; + + ot->exec= connect_hair_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + RNA_def_boolean(ot->srna, "all", 0, "All hair", "Connect all hair systems to the emitter mesh"); +} + diff --git a/source/blender/editors/physics/ed_fluidsim.c b/source/blender/editors/physics/physics_fluid.c index 093fa3f0a49..126c21a554b 100644 --- a/source/blender/editors/physics/ed_fluidsim.c +++ b/source/blender/editors/physics/physics_fluid.c @@ -93,6 +93,8 @@ #include "WM_api.h" #include "WM_types.h" +#include "physics_intern.h" // own include + /* enable/disable overall compilation */ #ifndef DISABLE_ELBEEM @@ -1200,8 +1202,3 @@ void FLUID_OT_bake(wmOperatorType *ot) ot->poll= ED_operator_object_active; } -void ED_operatortypes_fluid(void) -{ - WM_operatortype_append(FLUID_OT_bake); -} - diff --git a/source/blender/editors/physics/physics_intern.h b/source/blender/editors/physics/physics_intern.h index e03649575cb..956f26c478d 100644 --- a/source/blender/editors/physics/physics_intern.h +++ b/source/blender/editors/physics/physics_intern.h @@ -33,6 +33,72 @@ #ifndef ED_PHYSICS_INTERN_H #define ED_PHYSICS_INTERN_H +struct wmOperatorType; + +/* particle_edit.c */ +int PE_poll(struct bContext *C); +int PE_hair_poll(struct bContext *C); +int PE_poll_3dview(struct bContext *C); + +void PARTICLE_OT_select_all_toggle(struct wmOperatorType *ot); +void PARTICLE_OT_select_first(struct wmOperatorType *ot); +void PARTICLE_OT_select_last(struct wmOperatorType *ot); +void PARTICLE_OT_select_linked(struct wmOperatorType *ot); +void PARTICLE_OT_select_less(struct wmOperatorType *ot); +void PARTICLE_OT_select_more(struct wmOperatorType *ot); + +void PARTICLE_OT_hide(struct wmOperatorType *ot); +void PARTICLE_OT_reveal(struct wmOperatorType *ot); + +void PARTICLE_OT_rekey(struct wmOperatorType *ot); +void PARTICLE_OT_subdivide(struct wmOperatorType *ot); +void PARTICLE_OT_remove_doubles(struct wmOperatorType *ot); +void PARTICLE_OT_delete(struct wmOperatorType *ot); +void PARTICLE_OT_mirror(struct wmOperatorType *ot); + +void PARTICLE_OT_brush_set(struct wmOperatorType *ot); +void PARTICLE_OT_brush_edit(struct wmOperatorType *ot); +void PARTICLE_OT_brush_radial_control(struct wmOperatorType *ot); + +void PARTICLE_OT_specials_menu(struct wmOperatorType *ot); + +void PARTICLE_OT_particle_edit_toggle(struct wmOperatorType *ot); +void PARTICLE_OT_edited_clear(struct wmOperatorType *ot); + +/* particle_object.c */ +void OBJECT_OT_particle_system_add(struct wmOperatorType *ot); +void OBJECT_OT_particle_system_remove(struct wmOperatorType *ot); + +void PARTICLE_OT_new(struct wmOperatorType *ot); +void PARTICLE_OT_new_target(struct wmOperatorType *ot); +void PARTICLE_OT_remove_target(struct wmOperatorType *ot); +void PARTICLE_OT_target_move_up(struct wmOperatorType *ot); +void PARTICLE_OT_target_move_down(struct wmOperatorType *ot); +void PARTICLE_OT_connect_hair(struct wmOperatorType *ot); +void PARTICLE_OT_disconnect_hair(struct wmOperatorType *ot); + +/* particle_boids.c */ +void BOID_OT_rule_add(struct wmOperatorType *ot); +void BOID_OT_rule_del(struct wmOperatorType *ot); +void BOID_OT_rule_move_up(struct wmOperatorType *ot); +void BOID_OT_rule_move_down(struct wmOperatorType *ot); + +void BOID_OT_state_add(struct wmOperatorType *ot); +void BOID_OT_state_del(struct wmOperatorType *ot); +void BOID_OT_state_move_up(struct wmOperatorType *ot); +void BOID_OT_state_move_down(struct wmOperatorType *ot); + +/* physics_fluid.c */ +void FLUID_OT_bake(struct wmOperatorType *ot); + +/* physics_pointcache.c */ +void PTCACHE_OT_bake_all(struct wmOperatorType *ot); +void PTCACHE_OT_free_bake_all(struct wmOperatorType *ot); +void PTCACHE_OT_bake(struct wmOperatorType *ot); +void PTCACHE_OT_free_bake(struct wmOperatorType *ot); +void PTCACHE_OT_bake_from_cache(struct wmOperatorType *ot); +void PTCACHE_OT_add_new(struct wmOperatorType *ot); +void PTCACHE_OT_remove(struct wmOperatorType *ot); #endif /* ED_PHYSICS_INTERN_H */ diff --git a/source/blender/editors/physics/physics_ops.c b/source/blender/editors/physics/physics_ops.c new file mode 100644 index 00000000000..a62d3d8fd78 --- /dev/null +++ b/source/blender/editors/physics/physics_ops.c @@ -0,0 +1,173 @@ +/** + * $Id: + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009 Blender Foundation. + * All rights reserved. + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <stdlib.h> + +#include "DNA_windowmanager_types.h" + +#include "RNA_access.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "ED_physics.h" + +#include "physics_intern.h" // own include + +/***************************** particles ***********************************/ + +static void operatortypes_particle(void) +{ + WM_operatortype_append(PARTICLE_OT_select_all_toggle); + WM_operatortype_append(PARTICLE_OT_select_first); + WM_operatortype_append(PARTICLE_OT_select_last); + WM_operatortype_append(PARTICLE_OT_select_linked); + WM_operatortype_append(PARTICLE_OT_select_less); + WM_operatortype_append(PARTICLE_OT_select_more); + + WM_operatortype_append(PARTICLE_OT_hide); + WM_operatortype_append(PARTICLE_OT_reveal); + + WM_operatortype_append(PARTICLE_OT_rekey); + WM_operatortype_append(PARTICLE_OT_subdivide); + WM_operatortype_append(PARTICLE_OT_remove_doubles); + WM_operatortype_append(PARTICLE_OT_delete); + WM_operatortype_append(PARTICLE_OT_mirror); + + WM_operatortype_append(PARTICLE_OT_brush_set); + WM_operatortype_append(PARTICLE_OT_brush_edit); + WM_operatortype_append(PARTICLE_OT_brush_radial_control); + + WM_operatortype_append(PARTICLE_OT_specials_menu); + + WM_operatortype_append(PARTICLE_OT_particle_edit_toggle); + WM_operatortype_append(PARTICLE_OT_edited_clear); + + + WM_operatortype_append(OBJECT_OT_particle_system_add); + WM_operatortype_append(OBJECT_OT_particle_system_remove); + + WM_operatortype_append(PARTICLE_OT_new); + WM_operatortype_append(PARTICLE_OT_new_target); + WM_operatortype_append(PARTICLE_OT_remove_target); + WM_operatortype_append(PARTICLE_OT_target_move_up); + WM_operatortype_append(PARTICLE_OT_target_move_down); + WM_operatortype_append(PARTICLE_OT_connect_hair); + WM_operatortype_append(PARTICLE_OT_disconnect_hair); +} + +static void keymap_particle(wmWindowManager *wm) +{ + wmKeyMap *keymap; + + keymap= WM_keymap_find(wm, "Particle", 0, 0); + keymap->poll= PE_poll; + + WM_keymap_add_item(keymap, "PARTICLE_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "PARTICLE_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "PARTICLE_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "PARTICLE_OT_select_linked", LKEY, KM_PRESS, 0, 0); + RNA_boolean_set(WM_keymap_add_item(keymap, "PARTICLE_OT_select_linked", LKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "deselect", 1); + + WM_keymap_add_item(keymap, "PARTICLE_OT_delete", XKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "PARTICLE_OT_delete", DELKEY, KM_PRESS, 0, 0); + + WM_keymap_add_item(keymap, "PARTICLE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0); + WM_keymap_add_item(keymap, "PARTICLE_OT_hide", HKEY, KM_PRESS, 0, 0); + RNA_enum_set(WM_keymap_add_item(keymap, "PARTICLE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1); + + WM_keymap_add_item(keymap, "PARTICLE_OT_brush_edit", ACTIONMOUSE, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "PARTICLE_OT_brush_edit", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0); + RNA_enum_set(WM_keymap_add_item(keymap, "PARTICLE_OT_brush_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE); + RNA_enum_set(WM_keymap_add_item(keymap, "PARTICLE_OT_brush_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", WM_RADIALCONTROL_STRENGTH); + + WM_keymap_add_item(keymap, "PARTICLE_OT_specials_menu", WKEY, KM_PRESS, 0, 0); +} + +/******************************* boids *************************************/ + +static void operatortypes_boids(void) +{ + WM_operatortype_append(BOID_OT_rule_add); + WM_operatortype_append(BOID_OT_rule_del); + WM_operatortype_append(BOID_OT_rule_move_up); + WM_operatortype_append(BOID_OT_rule_move_down); + + WM_operatortype_append(BOID_OT_state_add); + WM_operatortype_append(BOID_OT_state_del); + WM_operatortype_append(BOID_OT_state_move_up); + WM_operatortype_append(BOID_OT_state_move_down); +} + +/********************************* fluid ***********************************/ + +static void operatortypes_fluid(void) +{ + WM_operatortype_append(FLUID_OT_bake); +} + +/**************************** point cache **********************************/ + +static void operatortypes_pointcache(void) +{ + WM_operatortype_append(PTCACHE_OT_bake_all); + WM_operatortype_append(PTCACHE_OT_free_bake_all); + WM_operatortype_append(PTCACHE_OT_bake); + WM_operatortype_append(PTCACHE_OT_free_bake); + WM_operatortype_append(PTCACHE_OT_bake_from_cache); + WM_operatortype_append(PTCACHE_OT_add_new); + WM_operatortype_append(PTCACHE_OT_remove); +} + +//static void keymap_pointcache(wmWindowManager *wm) +//{ +// wmKeyMap *keymap= WM_keymap_find(wm, "Pointcache", 0, 0); +// +// WM_keymap_add_item(keymap, "PHYSICS_OT_bake_all", AKEY, KM_PRESS, 0, 0); +// WM_keymap_add_item(keymap, "PHYSICS_OT_free_all", PADPLUSKEY, KM_PRESS, KM_CTRL, 0); +// WM_keymap_add_item(keymap, "PHYSICS_OT_bake_particle_system", PADMINUS, KM_PRESS, KM_CTRL, 0); +// WM_keymap_add_item(keymap, "PHYSICS_OT_free_particle_system", LKEY, KM_PRESS, 0, 0); +//} + +/****************************** general ************************************/ + +void ED_operatortypes_physics(void) +{ + operatortypes_particle(); + operatortypes_boids(); + operatortypes_fluid(); + operatortypes_pointcache(); +} + +void ED_keymap_physics(wmWindowManager *wm) +{ + keymap_particle(wm); + //keymap_pointcache(wm); +} + + + diff --git a/source/blender/editors/physics/ed_pointcache.c b/source/blender/editors/physics/physics_pointcache.c index ed3aaf0cfd1..26099a18966 100644 --- a/source/blender/editors/physics/ed_pointcache.c +++ b/source/blender/editors/physics/physics_pointcache.c @@ -27,6 +27,8 @@ * ***** END GPL LICENSE BLOCK ***** */ +#include <stdlib.h> + #include "MEM_guardedalloc.h" #include "DNA_scene_types.h" @@ -332,26 +334,4 @@ void PTCACHE_OT_remove(wmOperatorType *ot) /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } -/**************************** registration **********************************/ - -void ED_operatortypes_pointcache(void) -{ - WM_operatortype_append(PTCACHE_OT_bake_all); - WM_operatortype_append(PTCACHE_OT_free_bake_all); - WM_operatortype_append(PTCACHE_OT_bake); - WM_operatortype_append(PTCACHE_OT_free_bake); - WM_operatortype_append(PTCACHE_OT_bake_from_cache); - WM_operatortype_append(PTCACHE_OT_add_new); - WM_operatortype_append(PTCACHE_OT_remove); -} - -//void ED_keymap_pointcache(wmWindowManager *wm) -//{ -// wmKeyMap *keymap= WM_keymap_find(wm, "Pointcache", 0, 0); -// -// WM_keymap_add_item(keymap, "PHYSICS_OT_bake_all", AKEY, KM_PRESS, 0, 0); -// WM_keymap_add_item(keymap, "PHYSICS_OT_free_all", PADPLUSKEY, KM_PRESS, KM_CTRL, 0); -// WM_keymap_add_item(keymap, "PHYSICS_OT_bake_particle_system", PADMINUS, KM_PRESS, KM_CTRL, 0); -// WM_keymap_add_item(keymap, "PHYSICS_OT_free_particle_system", LKEY, KM_PRESS, 0, 0); -//} diff --git a/source/blender/editors/preview/Makefile b/source/blender/editors/render/Makefile index 48e1dc64673..ed25f0be02a 100644 --- a/source/blender/editors/preview/Makefile +++ b/source/blender/editors/render/Makefile @@ -28,7 +28,7 @@ # # Makes module object directory and bounces make to subdirectories. -LIBNAME = ed_preview +LIBNAME = ed_render DIR = $(OCGDIR)/blender/$(LIBNAME) include nan_compile.mk diff --git a/source/blender/editors/preview/SConscript b/source/blender/editors/render/SConscript index 922232822ff..cca2ab9b2ab 100644 --- a/source/blender/editors/preview/SConscript +++ b/source/blender/editors/render/SConscript @@ -9,4 +9,4 @@ incs += ' #/intern/guardedalloc ../../gpu' incs += ' ../../makesrna ../../render/extern/include #/intern/elbeem/extern' incs += ' ../../blenloader' -env.BlenderLib ( 'bf_editors_preview', sources, Split(incs), [], libtype=['core'], priority=[45] ) +env.BlenderLib ( 'bf_editors_render', sources, Split(incs), [], libtype=['core'], priority=[45] ) diff --git a/source/blender/editors/preview/previewrender_intern.h b/source/blender/editors/render/render_intern.h index 74a3aeee754..dccc2d36002 100644 --- a/source/blender/editors/preview/previewrender_intern.h +++ b/source/blender/editors/render/render_intern.h @@ -26,12 +26,24 @@ * ***** END GPL LICENSE BLOCK ***** */ -#ifndef PREVIEWRENDER_INTERN_H -#define PREVIEWRENDER_INTERN_H +#ifndef RENDER_INTERN_H +#define RENDER_INTERN_H -/* internal exports only */ +struct wmOperatorType; +/* render_shading.c */ +void OBJECT_OT_material_slot_add(struct wmOperatorType *ot); +void OBJECT_OT_material_slot_remove(struct wmOperatorType *ot); +void OBJECT_OT_material_slot_assign(struct wmOperatorType *ot); +void OBJECT_OT_material_slot_select(struct wmOperatorType *ot); +void OBJECT_OT_material_slot_deselect(struct wmOperatorType *ot); +void MATERIAL_OT_new(struct wmOperatorType *ot); +void TEXTURE_OT_new(struct wmOperatorType *ot); +void WORLD_OT_new(struct wmOperatorType *ot); -#endif /* PREVIEWRENDER_INTERN_H */ +void SCENE_OT_render_layer_add(struct wmOperatorType *ot); +void SCENE_OT_render_layer_remove(struct wmOperatorType *ot); + +#endif /* RENDER_INTERN_H */ diff --git a/source/blender/editors/render/render_ops.c b/source/blender/editors/render/render_ops.c new file mode 100644 index 00000000000..8b60582d466 --- /dev/null +++ b/source/blender/editors/render/render_ops.c @@ -0,0 +1,54 @@ +/** + * $Id: + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009 Blender Foundation. + * All rights reserved. + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <stdlib.h> + +#include "DNA_windowmanager_types.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "render_intern.h" // own include + +/***************************** render ***********************************/ + +void ED_operatortypes_render(void) +{ + WM_operatortype_append(OBJECT_OT_material_slot_add); + WM_operatortype_append(OBJECT_OT_material_slot_remove); + WM_operatortype_append(OBJECT_OT_material_slot_assign); + WM_operatortype_append(OBJECT_OT_material_slot_select); + WM_operatortype_append(OBJECT_OT_material_slot_deselect); + + WM_operatortype_append(MATERIAL_OT_new); + WM_operatortype_append(TEXTURE_OT_new); + WM_operatortype_append(WORLD_OT_new); + + WM_operatortype_append(SCENE_OT_render_layer_add); + WM_operatortype_append(SCENE_OT_render_layer_remove); +} + diff --git a/source/blender/editors/preview/previewrender.c b/source/blender/editors/render/render_preview.c index 91928b971f3..81f6badc24b 100644 --- a/source/blender/editors/preview/previewrender.c +++ b/source/blender/editors/render/render_preview.c @@ -88,12 +88,12 @@ #include "WM_api.h" #include "WM_types.h" -#include "ED_previewrender.h" +#include "ED_render.h" #include "ED_view3d.h" #include "UI_interface.h" -#include "previewrender_intern.h" +#include "render_intern.h" #define PR_XMIN 10 #define PR_YMIN 5 @@ -294,6 +294,14 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre } sce->r.color_mgt_flag = scene->r.color_mgt_flag; + /* exception: don't color manage texture previews or icons */ + if((sp && sp->pr_method==PR_ICON_RENDER) || id_type == ID_TE) + sce->r.color_mgt_flag &= ~R_COLOR_MANAGEMENT; + if((sp && sp->pr_method==PR_ICON_RENDER) && id_type != ID_WO) + sce->r.alphamode= R_ALPHAPREMUL; + else + sce->r.alphamode= R_ADDSKY; + sce->r.cfra= scene->r.cfra; if(id_type==ID_MA) { @@ -364,9 +372,6 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre sce->lay= 1<<MA_TEXTURE; - /* exception: don't color manage texture previews */ - sce->r.color_mgt_flag &= ~R_COLOR_MANAGEMENT; - for(base= sce->base.first; base; base= base->next) { if(base->object->id.name[2]=='t') { Material *mat= give_current_material(base->object, base->object->actcol); @@ -1081,12 +1086,9 @@ void ED_preview_icon_job(const bContext *C, void *owner, ID *id, unsigned int *r ShaderPreview *sp; /* XXX ugly global still, but we can't do preview while rendering */ - if(G.rendering) + if(G.rendering) { + printf("abort icon because rendering\n"); return; - - /* XXX this is not correct, can't work with threads */ - if(GS(id->name) == ID_TE) { - ntreeTexSetPreviewFlag(1); } steve= WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), owner); @@ -1094,7 +1096,7 @@ void ED_preview_icon_job(const bContext *C, void *owner, ID *id, unsigned int *r /* customdata for preview thread */ sp->scene= CTX_data_scene(C); - sp->owner= owner; + sp->owner= id; sp->sizex= sizex; sp->sizey= sizey; sp->pr_method= PR_ICON_RENDER; @@ -1107,9 +1109,6 @@ void ED_preview_icon_job(const bContext *C, void *owner, ID *id, unsigned int *r WM_jobs_callbacks(steve, common_preview_startjob, NULL, NULL); WM_jobs_start(CTX_wm_manager(C), steve); - - /* signal to rerender icon in menus */ - BKE_icon_changed(BKE_icon_getid(id)); } void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, MTex *slot, int sizex, int sizey) @@ -1118,12 +1117,9 @@ void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, M ShaderPreview *sp; /* XXX ugly global still, but we can't do preview while rendering */ - if(G.rendering) + if(G.rendering) { + printf("abort shader because rendering\n"); return; - - /* XXX this is not correct, can't work with threads */ - if(GS(id->name) == ID_TE) { - ntreeTexSetPreviewFlag(1); } steve= WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), owner); @@ -1145,9 +1141,6 @@ void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, M WM_jobs_callbacks(steve, common_preview_startjob, NULL, shader_preview_updatejob); WM_jobs_start(CTX_wm_manager(C), steve); - - /* signal to rerender icon in menus */ - BKE_icon_changed(BKE_icon_getid(id)); } diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c new file mode 100644 index 00000000000..a31a60ecbd6 --- /dev/null +++ b/source/blender/editors/render/render_shading.c @@ -0,0 +1,645 @@ +/** + * $Id: + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2009 Blender Foundation. + * All rights reserved. + * + * Contributor(s): Blender Foundation + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <stdlib.h> +#include <string.h> + +#include "MEM_guardedalloc.h" + +#include "DNA_curve_types.h" +#include "DNA_lamp_types.h" +#include "DNA_material_types.h" +#include "DNA_meshdata_types.h" +#include "DNA_node_types.h" +#include "DNA_object_types.h" +#include "DNA_texture_types.h" +#include "DNA_scene_types.h" +#include "DNA_world_types.h" + +#include "BKE_context.h" +#include "BKE_depsgraph.h" +#include "BKE_font.h" +#include "BKE_icons.h" +#include "BKE_library.h" +#include "BKE_main.h" +#include "BKE_material.h" +#include "BKE_node.h" +#include "BKE_scene.h" +#include "BKE_texture.h" +#include "BKE_utildefines.h" +#include "BKE_world.h" + +#include "BLI_arithb.h" +#include "BLI_editVert.h" +#include "BLI_listbase.h" + +#include "GPU_material.h" + +#include "RNA_access.h" +#include "RNA_enum_types.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "ED_curve.h" +#include "ED_mesh.h" +#include "ED_render.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "UI_interface.h" +#include "UI_resources.h" + +#include "render_intern.h" // own include + +/***************************** Updates *********************************** + * ED_render_id_flush_update gets called from DAG_id_flush_update, to do * + * editor level updates when the ID changes. when these ID blocks are in * + * the dependency graph, we can get rid of the manual dependency checks */ + +static int mtex_use_tex(MTex **mtex, int tot, Tex *tex) +{ + int a; + + if(!mtex) + return 0; + + for(a=0; a<tot; a++) + if(mtex[a] && mtex[a]->tex == tex) + return 1; + + return 0; +} + +static int nodes_use_tex(bNodeTree *ntree, Tex *tex) +{ + bNode *node; + + for(node=ntree->nodes.first; node; node= node->next) { + if(node->id) { + if(node->id == (ID*)tex) { + return 1; + } + else if(node->type==NODE_GROUP) { + if(nodes_use_tex((bNodeTree *)node->id, tex)) + return 1; + } + } + } + + return 0; +} + +static void material_changed(Main *bmain, Material *ma) +{ + /* icons */ + BKE_icon_changed(BKE_icon_getid(&ma->id)); + + /* glsl */ + if(ma->gpumaterial.first) + GPU_material_free(ma); +} + +static void texture_changed(Main *bmain, Tex *tex) +{ + Material *ma; + Lamp *la; + World *wo; + + /* icons */ + BKE_icon_changed(BKE_icon_getid(&tex->id)); + + /* find materials */ + for(ma=bmain->mat.first; ma; ma=ma->id.next) { + if(mtex_use_tex(ma->mtex, MAX_MTEX, tex)); + else if(ma->use_nodes && ma->nodetree && nodes_use_tex(ma->nodetree, tex)); + else continue; + + BKE_icon_changed(BKE_icon_getid(&ma->id)); + + if(ma->gpumaterial.first) + GPU_material_free(ma); + } + + /* find lamps */ + for(la=bmain->lamp.first; la; la=la->id.next) { + if(mtex_use_tex(la->mtex, MAX_MTEX, tex)); + else continue; + + BKE_icon_changed(BKE_icon_getid(&la->id)); + } + + /* find worlds */ + for(wo=bmain->world.first; wo; wo=wo->id.next) { + if(mtex_use_tex(wo->mtex, MAX_MTEX, tex)); + else continue; + + BKE_icon_changed(BKE_icon_getid(&wo->id)); + } +} + +static void lamp_changed(Main *bmain, Lamp *la) +{ + Object *ob; + Material *ma; + + /* icons */ + BKE_icon_changed(BKE_icon_getid(&la->id)); + + /* glsl */ + for(ob=bmain->object.first; ob; ob=ob->id.next) + if(ob->data == la && ob->gpulamp.first) + GPU_lamp_free(ob); + + for(ma=bmain->mat.first; ma; ma=ma->id.next) + if(ma->gpumaterial.first) + GPU_material_free(ma); +} + +static void world_changed(Main *bmain, World *wo) +{ + Material *ma; + + /* icons */ + BKE_icon_changed(BKE_icon_getid(&wo->id)); + + /* glsl */ + for(ma=bmain->mat.first; ma; ma=ma->id.next) + if(ma->gpumaterial.first) + GPU_material_free(ma); +} + +void ED_render_id_flush_update(Main *bmain, ID *id) +{ + switch(GS(id->name)) { + case ID_MA: + material_changed(bmain, (Material*)id); + break; + case ID_TE: + texture_changed(bmain, (Tex*)id); + break; + case ID_WO: + world_changed(bmain, (World*)id); + break; + case ID_LA: + lamp_changed(bmain, (Lamp*)id); + break; + default: + break; + } +} + +/********************** material slot operators *********************/ + +static int material_slot_add_exec(bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + + if(!ob) + return OPERATOR_CANCELLED; + + object_add_material_slot(ob); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_material_slot_add(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Add Material Slot"; + ot->idname= "OBJECT_OT_material_slot_add"; + ot->description="Add a new material slot or duplicate the selected one."; + + /* api callbacks */ + ot->exec= material_slot_add_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +static int material_slot_remove_exec(bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + + if(!ob) + return OPERATOR_CANCELLED; + + object_remove_material_slot(ob); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_material_slot_remove(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Remove Material Slot"; + ot->idname= "OBJECT_OT_material_slot_remove"; + ot->description="Remove the selected material slot."; + + /* api callbacks */ + ot->exec= material_slot_remove_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +static int material_slot_assign_exec(bContext *C, wmOperator *op) +{ + Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + + if(!ob) + return OPERATOR_CANCELLED; + + if(ob && ob->actcol>0) { + if(ob->type == OB_MESH) { + EditMesh *em= ((Mesh*)ob->data)->edit_mesh; + EditFace *efa; + + if(em) { + for(efa= em->faces.first; efa; efa=efa->next) + if(efa->f & SELECT) + efa->mat_nr= ob->actcol-1; + } + } + else if(ELEM(ob->type, OB_CURVE, OB_SURF)) { + ListBase *editnurb= ((Curve*)ob->data)->editnurb; + Nurb *nu; + + if(editnurb) { + for(nu= editnurb->first; nu; nu= nu->next) + if(isNurbsel(nu)) + nu->mat_nr= nu->charidx= ob->actcol-1; + } + } + else if(ob->type == OB_FONT) { + EditFont *ef= ((Curve*)ob->data)->editfont; + int i, selstart, selend; + + if(ef && BKE_font_getselection(ob, &selstart, &selend)) { + for(i=selstart; i<=selend; i++) + ef->textbufinfo[i].mat_nr = ob->actcol-1; + } + } + } + + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); + WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_material_slot_assign(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Assign Material Slot"; + ot->idname= "OBJECT_OT_material_slot_assign"; + ot->description="Assign the material in the selected material slot to the selected vertices."; + + /* api callbacks */ + ot->exec= material_slot_assign_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +static int material_slot_de_select(bContext *C, int select) +{ + Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; + + if(!ob) + return OPERATOR_CANCELLED; + + if(ob->type == OB_MESH) { + EditMesh *em= ((Mesh*)ob->data)->edit_mesh; + + if(em) { + if(select) + EM_select_by_material(em, ob->actcol-1); + else + EM_deselect_by_material(em, ob->actcol-1); + } + } + else if ELEM(ob->type, OB_CURVE, OB_SURF) { + ListBase *editnurb= ((Curve*)ob->data)->editnurb; + Nurb *nu; + BPoint *bp; + BezTriple *bezt; + int a; + + for(nu= editnurb->first; nu; nu=nu->next) { + if(nu->mat_nr==ob->actcol-1) { + if(nu->bezt) { + a= nu->pntsu; + bezt= nu->bezt; + while(a--) { + if(bezt->hide==0) { + if(select) { + bezt->f1 |= SELECT; + bezt->f2 |= SELECT; + bezt->f3 |= SELECT; + } + else { + bezt->f1 &= ~SELECT; + bezt->f2 &= ~SELECT; + bezt->f3 &= ~SELECT; + } + } + bezt++; + } + } + else if(nu->bp) { + a= nu->pntsu*nu->pntsv; + bp= nu->bp; + while(a--) { + if(bp->hide==0) { + if(select) bp->f1 |= SELECT; + else bp->f1 &= ~SELECT; + } + bp++; + } + } + } + } + } + + WM_event_add_notifier(C, NC_GEOM|ND_SELECT, ob->data); + + return OPERATOR_FINISHED; +} + +static int material_slot_select_exec(bContext *C, wmOperator *op) +{ + return material_slot_de_select(C, 1); +} + +void OBJECT_OT_material_slot_select(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Select Material Slot"; + ot->idname= "OBJECT_OT_material_slot_select"; + ot->description="Select vertices assigned to the selected material slot."; + + /* api callbacks */ + ot->exec= material_slot_select_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +static int material_slot_deselect_exec(bContext *C, wmOperator *op) +{ + return material_slot_de_select(C, 0); +} + +void OBJECT_OT_material_slot_deselect(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Deselect Material Slot"; + ot->idname= "OBJECT_OT_material_slot_deselect"; + ot->description="Deselect vertices assigned to the selected material slot."; + + /* api callbacks */ + ot->exec= material_slot_deselect_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/********************** new material operator *********************/ + +static int new_material_exec(bContext *C, wmOperator *op) +{ + Material *ma= CTX_data_pointer_get_type(C, "material", &RNA_Material).data; + Object *ob; + PointerRNA ptr; + int index; + + /* add or copy material */ + if(ma) + ma= copy_material(ma); + else + ma= add_material("Material"); + + ma->id.us--; /* compensating for us++ in assign_material */ + + /* attempt to assign to material slot */ + ptr= CTX_data_pointer_get_type(C, "material_slot", &RNA_MaterialSlot); + + if(ptr.data) { + ob= ptr.id.data; + index= (Material**)ptr.data - ob->mat; + + assign_material(ob, ma, index+1); + + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + } + + WM_event_add_notifier(C, NC_MATERIAL|NA_ADDED, ma); + + return OPERATOR_FINISHED; +} + +void MATERIAL_OT_new(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "New Material"; + ot->idname= "MATERIAL_OT_new"; + ot->description="Add a new material."; + + /* api callbacks */ + ot->exec= new_material_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/********************** new texture operator *********************/ + +static int new_texture_exec(bContext *C, wmOperator *op) +{ + Tex *tex= CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data; + ID *id; + MTex *mtex; + PointerRNA ptr; + + /* add or copy texture */ + if(tex) + tex= copy_texture(tex); + else + tex= add_texture("Texture"); + + id_us_min(&tex->id); + + /* attempt to assign to texture slot */ + ptr= CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot); + + if(ptr.data) { + id= ptr.id.data; + mtex= ptr.data; + + if(mtex) { + if(mtex->tex) + id_us_min(&mtex->tex->id); + mtex->tex= tex; + id_us_plus(&tex->id); + } + + /* XXX nodes, notifier .. */ + } + + WM_event_add_notifier(C, NC_TEXTURE|NA_ADDED, tex); + + return OPERATOR_FINISHED; +} + +void TEXTURE_OT_new(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "New Texture"; + ot->idname= "TEXTURE_OT_new"; + ot->description="Add a new texture."; + + /* api callbacks */ + ot->exec= new_texture_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/********************** new world operator *********************/ + +static int new_world_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + World *wo= CTX_data_pointer_get_type(C, "world", &RNA_World).data; + + /* add or copy world */ + if(wo) + wo= copy_world(wo); + else + wo= add_world("World"); + + /* assign to scene */ + if(scene->world) + id_us_min(&scene->world->id); + scene->world= wo; + + WM_event_add_notifier(C, NC_WORLD|NA_ADDED, wo); + + return OPERATOR_FINISHED; +} + +void WORLD_OT_new(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "New World"; + ot->idname= "WORLD_OT_new"; + ot->description= "Add a new world."; + + /* api callbacks */ + ot->exec= new_world_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +/********************** render layer operators *********************/ + +static int render_layer_add_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + + scene_add_render_layer(scene); + scene->r.actlay= BLI_countlist(&scene->r.layers) - 1; + + WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene); + + return OPERATOR_FINISHED; +} + +void SCENE_OT_render_layer_add(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Add Render Layer"; + ot->idname= "SCENE_OT_render_layer_add"; + ot->description="Add a render layer."; + + /* api callbacks */ + ot->exec= render_layer_add_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + +static int render_layer_remove_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + SceneRenderLayer *rl; + int act= scene->r.actlay; + + if(BLI_countlist(&scene->r.layers) <= 1) + return OPERATOR_CANCELLED; + + rl= BLI_findlink(&scene->r.layers, scene->r.actlay); + BLI_remlink(&scene->r.layers, rl); + MEM_freeN(rl); + + scene->r.actlay= 0; + + if(scene->nodetree) { + bNode *node; + for(node= scene->nodetree->nodes.first; node; node= node->next) { + if(node->type==CMP_NODE_R_LAYERS && node->id==NULL) { + if(node->custom1==act) + node->custom1= 0; + else if(node->custom1>act) + node->custom1--; + } + } + } + + WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene); + + return OPERATOR_FINISHED; +} + +void SCENE_OT_render_layer_remove(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Remove Render Layer"; + ot->idname= "SCENE_OT_render_layer_remove"; + ot->description="Remove the selected render layer."; + + /* api callbacks */ + ot->exec= render_layer_remove_exec; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c index 18bc7ec9555..8c563c98d9b 100644 --- a/source/blender/editors/space_api/spacetypes.c +++ b/source/blender/editors/space_api/spacetypes.c @@ -46,8 +46,8 @@ #include "ED_markers.h" #include "ED_mesh.h" #include "ED_object.h" -#include "ED_particle.h" #include "ED_physics.h" +#include "ED_render.h" #include "ED_screen.h" #include "ED_sculpt.h" #include "ED_space_api.h" @@ -92,15 +92,13 @@ void ED_spacetypes_init(void) ED_operatortypes_sculpt(); ED_operatortypes_uvedit(); ED_operatortypes_paint(); - ED_operatortypes_particle(); + ED_operatortypes_physics(); ED_operatortypes_curve(); ED_operatortypes_armature(); ED_operatortypes_marker(); - ED_operatortypes_pointcache(); - ED_operatortypes_fluid(); ED_operatortypes_metaball(); - ED_operatortypes_boids(); ED_operatortypes_sound(); + ED_operatortypes_render(); ui_view2d_operatortypes(); @@ -127,7 +125,7 @@ void ED_spacetypes_keymap(wmWindowManager *wm) ED_keymap_uvedit(wm); ED_keymap_curve(wm); ED_keymap_armature(wm); - ED_keymap_particle(wm); + ED_keymap_physics(wm); ED_keymap_metaball(wm); ED_keymap_paint(wm); ED_marker_keymap(wm); diff --git a/source/blender/editors/space_buttons/buttons_intern.h b/source/blender/editors/space_buttons/buttons_intern.h index 0a5a5714a06..2e95fde8f99 100644 --- a/source/blender/editors/space_buttons/buttons_intern.h +++ b/source/blender/editors/space_buttons/buttons_intern.h @@ -64,33 +64,6 @@ void buttons_context_draw(const struct bContext *C, struct uiLayout *layout); void buttons_context_register(struct ARegionType *art); /* buttons_ops.c */ -void OBJECT_OT_group_add(struct wmOperatorType *ot); -void OBJECT_OT_group_remove(struct wmOperatorType *ot); - -void OBJECT_OT_material_slot_add(struct wmOperatorType *ot); -void OBJECT_OT_material_slot_remove(struct wmOperatorType *ot); -void OBJECT_OT_material_slot_assign(struct wmOperatorType *ot); -void OBJECT_OT_material_slot_select(struct wmOperatorType *ot); -void OBJECT_OT_material_slot_deselect(struct wmOperatorType *ot); - -void MATERIAL_OT_new(struct wmOperatorType *ot); -void TEXTURE_OT_new(struct wmOperatorType *ot); -void WORLD_OT_new(struct wmOperatorType *ot); - -void OBJECT_OT_particle_system_add(struct wmOperatorType *ot); -void OBJECT_OT_particle_system_remove(struct wmOperatorType *ot); - -void PARTICLE_OT_new(struct wmOperatorType *ot); -void PARTICLE_OT_new_target(struct wmOperatorType *ot); -void PARTICLE_OT_remove_target(struct wmOperatorType *ot); -void PARTICLE_OT_target_move_up(struct wmOperatorType *ot); -void PARTICLE_OT_target_move_down(struct wmOperatorType *ot); -void PARTICLE_OT_connect_hair(struct wmOperatorType *ot); -void PARTICLE_OT_disconnect_hair(struct wmOperatorType *ot); - -void SCENE_OT_render_layer_add(struct wmOperatorType *ot); -void SCENE_OT_render_layer_remove(struct wmOperatorType *ot); - void BUTTONS_OT_file_browse(struct wmOperatorType *ot); void BUTTONS_OT_toolbox(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_buttons/buttons_ops.c b/source/blender/editors/space_buttons/buttons_ops.c index 4387da19341..2d961f78243 100644 --- a/source/blender/editors/space_buttons/buttons_ops.c +++ b/source/blender/editors/space_buttons/buttons_ops.c @@ -30,53 +30,14 @@ #include "MEM_guardedalloc.h" -#include "DNA_boid_types.h" -#include "DNA_curve_types.h" -#include "DNA_group_types.h" -#include "DNA_object_types.h" -#include "DNA_material_types.h" -#include "DNA_meshdata_types.h" -#include "DNA_modifier_types.h" -#include "DNA_node_types.h" -#include "DNA_texture_types.h" -#include "DNA_scene_types.h" #include "DNA_screen_types.h" #include "DNA_space_types.h" -#include "DNA_world_types.h" -#include "BKE_bvhutils.h" -#include "BKE_cdderivedmesh.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" -#include "BKE_DerivedMesh.h" -#include "BKE_group.h" -#include "BKE_font.h" -#include "BKE_library.h" -#include "BKE_main.h" -#include "BKE_material.h" -#include "BKE_modifier.h" -#include "BKE_node.h" -#include "BKE_particle.h" -#include "BKE_pointcache.h" -#include "BKE_scene.h" -#include "BKE_texture.h" -#include "BKE_utildefines.h" -#include "BKE_world.h" - -#include "BLI_arithb.h" -#include "BLI_editVert.h" -#include "BLI_listbase.h" - -#include "RNA_access.h" -#include "RNA_enum_types.h" #include "WM_api.h" #include "WM_types.h" -#include "ED_curve.h" -#include "ED_mesh.h" -#include "ED_particle.h" - #include "RNA_access.h" #include "RNA_define.h" @@ -85,953 +46,6 @@ #include "buttons_intern.h" // own include - -/********************** material slot operators *********************/ - -static int material_slot_add_exec(bContext *C, wmOperator *op) -{ - Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; - - if(!ob) - return OPERATOR_CANCELLED; - - object_add_material_slot(ob); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - - return OPERATOR_FINISHED; -} - -void OBJECT_OT_material_slot_add(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Add Material Slot"; - ot->idname= "OBJECT_OT_material_slot_add"; - ot->description="Add a new material slot or duplicate the selected one."; - - /* api callbacks */ - ot->exec= material_slot_add_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -static int material_slot_remove_exec(bContext *C, wmOperator *op) -{ - Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; - - if(!ob) - return OPERATOR_CANCELLED; - - object_remove_material_slot(ob); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - - return OPERATOR_FINISHED; -} - -void OBJECT_OT_material_slot_remove(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Remove Material Slot"; - ot->idname= "OBJECT_OT_material_slot_remove"; - ot->description="Remove the selected material slot."; - - /* api callbacks */ - ot->exec= material_slot_remove_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -static int material_slot_assign_exec(bContext *C, wmOperator *op) -{ - Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; - - if(!ob) - return OPERATOR_CANCELLED; - - if(ob && ob->actcol>0) { - if(ob->type == OB_MESH) { - EditMesh *em= ((Mesh*)ob->data)->edit_mesh; - EditFace *efa; - - if(em) { - for(efa= em->faces.first; efa; efa=efa->next) - if(efa->f & SELECT) - efa->mat_nr= ob->actcol-1; - } - } - else if(ELEM(ob->type, OB_CURVE, OB_SURF)) { - ListBase *editnurb= ((Curve*)ob->data)->editnurb; - Nurb *nu; - - if(editnurb) { - for(nu= editnurb->first; nu; nu= nu->next) - if(isNurbsel(nu)) - nu->mat_nr= nu->charidx= ob->actcol-1; - } - } - else if(ob->type == OB_FONT) { - EditFont *ef= ((Curve*)ob->data)->editfont; - int i, selstart, selend; - - if(ef && BKE_font_getselection(ob, &selstart, &selend)) { - for(i=selstart; i<=selend; i++) - ef->textbufinfo[i].mat_nr = ob->actcol-1; - } - } - } - - DAG_id_flush_update(&ob->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data); - - return OPERATOR_FINISHED; -} - -void OBJECT_OT_material_slot_assign(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Assign Material Slot"; - ot->idname= "OBJECT_OT_material_slot_assign"; - ot->description="Assign the material in the selected material slot to the selected vertices."; - - /* api callbacks */ - ot->exec= material_slot_assign_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -static int material_slot_de_select(bContext *C, int select) -{ - Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; - - if(!ob) - return OPERATOR_CANCELLED; - - if(ob->type == OB_MESH) { - EditMesh *em= ((Mesh*)ob->data)->edit_mesh; - - if(em) { - if(select) - EM_select_by_material(em, ob->actcol-1); - else - EM_deselect_by_material(em, ob->actcol-1); - } - } - else if ELEM(ob->type, OB_CURVE, OB_SURF) { - ListBase *editnurb= ((Curve*)ob->data)->editnurb; - Nurb *nu; - BPoint *bp; - BezTriple *bezt; - int a; - - for(nu= editnurb->first; nu; nu=nu->next) { - if(nu->mat_nr==ob->actcol-1) { - if(nu->bezt) { - a= nu->pntsu; - bezt= nu->bezt; - while(a--) { - if(bezt->hide==0) { - if(select) { - bezt->f1 |= SELECT; - bezt->f2 |= SELECT; - bezt->f3 |= SELECT; - } - else { - bezt->f1 &= ~SELECT; - bezt->f2 &= ~SELECT; - bezt->f3 &= ~SELECT; - } - } - bezt++; - } - } - else if(nu->bp) { - a= nu->pntsu*nu->pntsv; - bp= nu->bp; - while(a--) { - if(bp->hide==0) { - if(select) bp->f1 |= SELECT; - else bp->f1 &= ~SELECT; - } - bp++; - } - } - } - } - } - - WM_event_add_notifier(C, NC_GEOM|ND_SELECT, ob->data); - - return OPERATOR_FINISHED; -} - -static int material_slot_select_exec(bContext *C, wmOperator *op) -{ - return material_slot_de_select(C, 1); -} - -void OBJECT_OT_material_slot_select(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Select Material Slot"; - ot->idname= "OBJECT_OT_material_slot_select"; - ot->description="Select vertices assigned to the selected material slot."; - - /* api callbacks */ - ot->exec= material_slot_select_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -static int material_slot_deselect_exec(bContext *C, wmOperator *op) -{ - return material_slot_de_select(C, 0); -} - -void OBJECT_OT_material_slot_deselect(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Deselect Material Slot"; - ot->idname= "OBJECT_OT_material_slot_deselect"; - ot->description="Deselect vertices assigned to the selected material slot."; - - /* api callbacks */ - ot->exec= material_slot_deselect_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -/********************** new material operator *********************/ - -static int new_material_exec(bContext *C, wmOperator *op) -{ - Material *ma= CTX_data_pointer_get_type(C, "material", &RNA_Material).data; - Object *ob; - PointerRNA ptr; - int index; - - /* add or copy material */ - if(ma) - ma= copy_material(ma); - else - ma= add_material("Material"); - - ma->id.us--; /* compensating for us++ in assign_material */ - - /* attempt to assign to material slot */ - ptr= CTX_data_pointer_get_type(C, "material_slot", &RNA_MaterialSlot); - - if(ptr.data) { - ob= ptr.id.data; - index= (Material**)ptr.data - ob->mat; - - assign_material(ob, ma, index+1); - - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - } - - WM_event_add_notifier(C, NC_MATERIAL|NA_ADDED, ma); - - return OPERATOR_FINISHED; -} - -void MATERIAL_OT_new(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "New Material"; - ot->idname= "MATERIAL_OT_new"; - ot->description="Add a new material."; - - /* api callbacks */ - ot->exec= new_material_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -/********************** new texture operator *********************/ - -static int new_texture_exec(bContext *C, wmOperator *op) -{ - Tex *tex= CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data; - ID *id; - MTex *mtex; - PointerRNA ptr; - - /* add or copy texture */ - if(tex) - tex= copy_texture(tex); - else - tex= add_texture("Texture"); - - id_us_min(&tex->id); - - /* attempt to assign to texture slot */ - ptr= CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot); - - if(ptr.data) { - id= ptr.id.data; - mtex= ptr.data; - - if(mtex) { - if(mtex->tex) - id_us_min(&mtex->tex->id); - mtex->tex= tex; - id_us_plus(&tex->id); - } - - /* XXX nodes, notifier .. */ - } - - WM_event_add_notifier(C, NC_TEXTURE|NA_ADDED, tex); - - return OPERATOR_FINISHED; -} - -void TEXTURE_OT_new(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "New Texture"; - ot->idname= "TEXTURE_OT_new"; - ot->description="Add a new texture."; - - /* api callbacks */ - ot->exec= new_texture_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -/********************** new world operator *********************/ - -static int new_world_exec(bContext *C, wmOperator *op) -{ - Scene *scene= CTX_data_scene(C); - World *wo= CTX_data_pointer_get_type(C, "world", &RNA_World).data; - - /* add or copy world */ - if(wo) - wo= copy_world(wo); - else - wo= add_world("World"); - - /* assign to scene */ - if(scene->world) - id_us_min(&scene->world->id); - scene->world= wo; - - WM_event_add_notifier(C, NC_WORLD|NA_ADDED, wo); - - return OPERATOR_FINISHED; -} - -void WORLD_OT_new(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "New World"; - ot->idname= "WORLD_OT_new"; - ot->description= "Add a new world."; - - /* api callbacks */ - ot->exec= new_world_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - - - -/********************** particle system slot operators *********************/ - -static int particle_system_add_exec(bContext *C, wmOperator *op) -{ - Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; - Scene *scene = CTX_data_scene(C); - - if(!scene || !ob) - return OPERATOR_CANCELLED; - - object_add_particle_system(scene, ob); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - - return OPERATOR_FINISHED; -} - -void OBJECT_OT_particle_system_add(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Add Particle System Slot"; - ot->idname= "OBJECT_OT_particle_system_add"; - ot->description="Add a particle system."; - - /* api callbacks */ - ot->exec= particle_system_add_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -static int particle_system_remove_exec(bContext *C, wmOperator *op) -{ - Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; - Scene *scene = CTX_data_scene(C); - - if(!scene || !ob) - return OPERATOR_CANCELLED; - - object_remove_particle_system(scene, ob); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - - return OPERATOR_FINISHED; -} - -void OBJECT_OT_particle_system_remove(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Remove Particle System Slot"; - ot->idname= "OBJECT_OT_particle_system_remove"; - ot->description="Remove the selected particle system."; - - /* api callbacks */ - ot->exec= particle_system_remove_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -/********************** new particle settings operator *********************/ - -static int psys_poll(bContext *C) -{ - PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); - return (ptr.data != NULL); -} - -static int new_particle_settings_exec(bContext *C, wmOperator *op) -{ - Scene *scene = CTX_data_scene(C); - Main *bmain= CTX_data_main(C); - ParticleSystem *psys; - ParticleSettings *part = NULL; - Object *ob; - PointerRNA ptr; - - ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); - - psys = ptr.data; - - /* add or copy particle setting */ - if(psys->part) - part= psys_copy_settings(psys->part); - else - part= psys_new_settings("ParticleSettings", bmain); - - ob= ptr.id.data; - - if(psys->part) - psys->part->id.us--; - - psys->part = part; - - psys_check_boid_data(psys); - - DAG_scene_sort(scene); - DAG_id_flush_update(&ob->id, OB_RECALC_DATA); - - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - - return OPERATOR_FINISHED; -} - -void PARTICLE_OT_new(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "New Particle Settings"; - ot->idname= "PARTICLE_OT_new"; - ot->description="Add new particle settings."; - - /* api callbacks */ - ot->exec= new_particle_settings_exec; - ot->poll= psys_poll; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -/********************** keyed particle target operators *********************/ - -static int new_particle_target_exec(bContext *C, wmOperator *op) -{ - Scene *scene = CTX_data_scene(C); - PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); - ParticleSystem *psys= ptr.data; - Object *ob = ptr.id.data; - - ParticleTarget *pt; - - if(!psys) - return OPERATOR_CANCELLED; - - pt = psys->targets.first; - for(; pt; pt=pt->next) - pt->flag &= ~PTARGET_CURRENT; - - pt = MEM_callocN(sizeof(ParticleTarget), "keyed particle target"); - - pt->flag |= PTARGET_CURRENT; - pt->psys = 1; - - BLI_addtail(&psys->targets, pt); - - DAG_scene_sort(scene); - DAG_id_flush_update(&ob->id, OB_RECALC_DATA); - - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - - return OPERATOR_FINISHED; -} - -void PARTICLE_OT_new_target(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "New Particle Target"; - ot->idname= "PARTICLE_OT_new_target"; - ot->description="Add a new particle target."; - - /* api callbacks */ - ot->exec= new_particle_target_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -static int remove_particle_target_exec(bContext *C, wmOperator *op) -{ - Scene *scene = CTX_data_scene(C); - PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); - ParticleSystem *psys= ptr.data; - Object *ob = ptr.id.data; - - ParticleTarget *pt; - - if(!psys) - return OPERATOR_CANCELLED; - - pt = psys->targets.first; - for(; pt; pt=pt->next) { - if(pt->flag & PTARGET_CURRENT) { - BLI_remlink(&psys->targets, pt); - MEM_freeN(pt); - break; - } - - } - pt = psys->targets.last; - - if(pt) - pt->flag |= PTARGET_CURRENT; - - DAG_scene_sort(scene); - DAG_id_flush_update(&ob->id, OB_RECALC_DATA); - - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - - return OPERATOR_FINISHED; -} - -void PARTICLE_OT_remove_target(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Remove Particle Target"; - ot->idname= "PARTICLE_OT_remove_target"; - ot->description="Remove the selected particle target."; - - /* api callbacks */ - ot->exec= remove_particle_target_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -/************************ move up particle target operator *********************/ - -static int target_move_up_exec(bContext *C, wmOperator *op) -{ - PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); - ParticleSystem *psys= ptr.data; - Object *ob = ptr.id.data; - ParticleTarget *pt; - - if(!psys) - return OPERATOR_CANCELLED; - - pt = psys->targets.first; - for(; pt; pt=pt->next) { - if(pt->flag & PTARGET_CURRENT && pt->prev) { - BLI_remlink(&psys->targets, pt); - BLI_insertlink(&psys->targets, pt->prev->prev, pt); - - DAG_id_flush_update(&ob->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - break; - } - } - - return OPERATOR_FINISHED; -} - -void PARTICLE_OT_target_move_up(wmOperatorType *ot) -{ - ot->name= "Move Up Target"; - ot->idname= "PARTICLE_OT_target_move_up"; - ot->description= "Move particle target up in the list."; - - ot->exec= target_move_up_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -/************************ move down particle target operator *********************/ - -static int target_move_down_exec(bContext *C, wmOperator *op) -{ - PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); - ParticleSystem *psys= ptr.data; - Object *ob = ptr.id.data; - ParticleTarget *pt; - - if(!psys) - return OPERATOR_CANCELLED; - pt = psys->targets.first; - for(; pt; pt=pt->next) { - if(pt->flag & PTARGET_CURRENT && pt->next) { - BLI_remlink(&psys->targets, pt); - BLI_insertlink(&psys->targets, pt->next, pt); - - DAG_id_flush_update(&ob->id, OB_RECALC_DATA); - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - break; - } - } - - return OPERATOR_FINISHED; -} - -void PARTICLE_OT_target_move_down(wmOperatorType *ot) -{ - ot->name= "Move Down Target"; - ot->idname= "PARTICLE_OT_target_move_down"; - ot->description= "Move particle target down in the list."; - - ot->exec= target_move_down_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -/************************ connect/disconnect hair operators *********************/ - -static void disconnect_hair(Scene *scene, Object *ob, ParticleSystem *psys) -{ - ParticleSystemModifierData *psmd = psys_get_modifier(ob,psys); - ParticleData *pa; - PTCacheEdit *edit; - PTCacheEditPoint *point; - PTCacheEditKey *ekey = NULL; - HairKey *key; - int i, k; - float hairmat[4][4]; - - if(!ob || !psys || psys->flag & PSYS_GLOBAL_HAIR) - return; - - if(!psys->part || psys->part->type != PART_HAIR) - return; - - edit = psys->edit; - point= edit ? edit->points : NULL; - - for(i=0, pa=psys->particles; i<psys->totpart; i++,pa++) { - if(point) { - ekey = point->keys; - point++; - } - - psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, hairmat); - - for(k=0,key=pa->hair; k<pa->totkey; k++,key++) { - Mat4MulVecfl(hairmat,key->co); - - if(ekey) { - ekey->flag &= ~PEK_USE_WCO; - ekey++; - } - } - } - - psys_free_path_cache(psys, psys->edit); - - psys->flag |= PSYS_GLOBAL_HAIR; - - PE_update_object(scene, ob, 0); -} - -static int disconnect_hair_exec(bContext *C, wmOperator *op) -{ - Scene *scene= CTX_data_scene(C); - Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; - PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); - ParticleSystem *psys= NULL; - int all = RNA_boolean_get(op->ptr, "all"); - - if(!ob) - return OPERATOR_CANCELLED; - - if(all) { - for(psys=ob->particlesystem.first; psys; psys=psys->next) { - disconnect_hair(scene, ob, psys); - } - } - else { - psys = ptr.data; - disconnect_hair(scene, ob, psys); - } - - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - - return OPERATOR_FINISHED; -} - -void PARTICLE_OT_disconnect_hair(wmOperatorType *ot) -{ - ot->name= "Disconnect Hair"; - ot->description= "Disconnect hair from the emitter mesh."; - ot->idname= "PARTICLE_OT_disconnect_hair"; - - ot->exec= disconnect_hair_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; - - RNA_def_boolean(ot->srna, "all", 0, "All hair", "Disconnect all hair systems from the emitter mesh"); -} - -static void connect_hair(Scene *scene, Object *ob, ParticleSystem *psys) -{ - ParticleSystemModifierData *psmd = psys_get_modifier(ob,psys); - ParticleData *pa; - PTCacheEdit *edit; - PTCacheEditPoint *point; - PTCacheEditKey *ekey; - HairKey *key; - BVHTreeFromMesh bvhtree; - BVHTreeNearest nearest; - MFace *mface; - DerivedMesh *dm = NULL; - int numverts; - int i, k; - float hairmat[4][4], imat[4][4]; - float v[4][3], vec[3]; - - if(!psys || !psys->part || psys->part->type != PART_HAIR) - return; - - edit= psys->edit; - point= edit ? edit->points : NULL; - - if(psmd->dm->deformedOnly) - dm= psmd->dm; - else - dm= mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH); - - numverts = dm->getNumVerts (dm); - - memset( &bvhtree, 0, sizeof(bvhtree) ); - - /* convert to global coordinates */ - for (i=0; i<numverts; i++) - Mat4MulVecfl (ob->obmat, CDDM_get_vert(dm, i)->co); - - bvhtree_from_mesh_faces(&bvhtree, dm, 0.0, 2, 6); - - for(i=0, pa= psys->particles; i<psys->totpart; i++,pa++) { - key = pa->hair; - - nearest.index = -1; - nearest.dist = FLT_MAX; - - BLI_bvhtree_find_nearest(bvhtree.tree, key->co, &nearest, bvhtree.nearest_callback, &bvhtree); - - if(nearest.index == -1) { - printf("No nearest point found for hair root!"); - continue; - } - - mface = CDDM_get_face(dm,nearest.index); - - VecCopyf(v[0], CDDM_get_vert(dm,mface->v1)->co); - VecCopyf(v[1], CDDM_get_vert(dm,mface->v2)->co); - VecCopyf(v[2], CDDM_get_vert(dm,mface->v3)->co); - if(mface->v4) { - VecCopyf(v[3], CDDM_get_vert(dm,mface->v4)->co); - MeanValueWeights(v, 4, nearest.co, pa->fuv); - } - else - MeanValueWeights(v, 3, nearest.co, pa->fuv); - - pa->num = nearest.index; - pa->num_dmcache = psys_particle_dm_face_lookup(ob,psmd->dm,pa->num,pa->fuv,NULL); - - psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, pa, hairmat); - Mat4Invert(imat,hairmat); - - VECSUB(vec, nearest.co, key->co); - - if(point) { - ekey = point->keys; - point++; - } - - for(k=0,key=pa->hair; k<pa->totkey; k++,key++) { - VECADD(key->co, key->co, vec); - Mat4MulVecfl(imat,key->co); - - if(ekey) { - ekey->flag |= PEK_USE_WCO; - ekey++; - } - } - } - - free_bvhtree_from_mesh(&bvhtree); - if(!psmd->dm->deformedOnly) - dm->release(dm); - - psys_free_path_cache(psys, psys->edit); - - psys->flag &= ~PSYS_GLOBAL_HAIR; - - PE_update_object(scene, ob, 0); -} - -static int connect_hair_exec(bContext *C, wmOperator *op) -{ - Scene *scene= CTX_data_scene(C); - Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; - PointerRNA ptr = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem); - ParticleSystem *psys= NULL; - int all = RNA_boolean_get(op->ptr, "all"); - - if(!ob) - return OPERATOR_CANCELLED; - - if(all) { - for(psys=ob->particlesystem.first; psys; psys=psys->next) { - connect_hair(scene, ob, psys); - } - } - else { - psys = ptr.data; - connect_hair(scene, ob, psys); - } - - WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); - - return OPERATOR_FINISHED; -} - -void PARTICLE_OT_connect_hair(wmOperatorType *ot) -{ - ot->name= "Connect Hair"; - ot->description= "Connect hair to the emitter mesh."; - ot->idname= "PARTICLE_OT_connect_hair"; - - ot->exec= connect_hair_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; - - RNA_def_boolean(ot->srna, "all", 0, "All hair", "Connect all hair systems to the emitter mesh"); -} - -/********************** render layer operators *********************/ - -static int render_layer_add_exec(bContext *C, wmOperator *op) -{ - Scene *scene= CTX_data_scene(C); - - scene_add_render_layer(scene); - scene->r.actlay= BLI_countlist(&scene->r.layers) - 1; - - WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene); - - return OPERATOR_FINISHED; -} - -void SCENE_OT_render_layer_add(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Add Render Layer"; - ot->idname= "SCENE_OT_render_layer_add"; - ot->description="Add a render layer."; - - /* api callbacks */ - ot->exec= render_layer_add_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - -static int render_layer_remove_exec(bContext *C, wmOperator *op) -{ - Scene *scene= CTX_data_scene(C); - SceneRenderLayer *rl; - int act= scene->r.actlay; - - if(BLI_countlist(&scene->r.layers) <= 1) - return OPERATOR_CANCELLED; - - rl= BLI_findlink(&scene->r.layers, scene->r.actlay); - BLI_remlink(&scene->r.layers, rl); - MEM_freeN(rl); - - scene->r.actlay= 0; - - if(scene->nodetree) { - bNode *node; - for(node= scene->nodetree->nodes.first; node; node= node->next) { - if(node->type==CMP_NODE_R_LAYERS && node->id==NULL) { - if(node->custom1==act) - node->custom1= 0; - else if(node->custom1>act) - node->custom1--; - } - } - } - - WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, scene); - - return OPERATOR_FINISHED; -} - -void SCENE_OT_render_layer_remove(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Remove Render Layer"; - ot->idname= "SCENE_OT_render_layer_remove"; - ot->description="Remove the selected render layer."; - - /* api callbacks */ - ot->exec= render_layer_remove_exec; - - /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; -} - /********************** toolbox operator *********************/ static int toolbox_invoke(bContext *C, wmOperator *op, wmEvent *event) diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c index 48acaffd580..6ffbb79f273 100644 --- a/source/blender/editors/space_buttons/space_buttons.c +++ b/source/blender/editors/space_buttons/space_buttons.c @@ -57,7 +57,7 @@ #include "UI_resources.h" #include "UI_view2d.h" -#include "ED_previewrender.h" +#include "ED_render.h" #include "buttons_intern.h" // own include @@ -185,33 +185,6 @@ static void buttons_main_area_draw(const bContext *C, ARegion *ar) void buttons_operatortypes(void) { - WM_operatortype_append(OBJECT_OT_group_add); - WM_operatortype_append(OBJECT_OT_group_remove); - - WM_operatortype_append(OBJECT_OT_material_slot_add); - WM_operatortype_append(OBJECT_OT_material_slot_remove); - WM_operatortype_append(OBJECT_OT_material_slot_assign); - WM_operatortype_append(OBJECT_OT_material_slot_select); - WM_operatortype_append(OBJECT_OT_material_slot_deselect); - - WM_operatortype_append(MATERIAL_OT_new); - WM_operatortype_append(TEXTURE_OT_new); - WM_operatortype_append(WORLD_OT_new); - - WM_operatortype_append(OBJECT_OT_particle_system_add); - WM_operatortype_append(OBJECT_OT_particle_system_remove); - - WM_operatortype_append(PARTICLE_OT_new); - WM_operatortype_append(PARTICLE_OT_new_target); - WM_operatortype_append(PARTICLE_OT_remove_target); - WM_operatortype_append(PARTICLE_OT_target_move_up); - WM_operatortype_append(PARTICLE_OT_target_move_down); - WM_operatortype_append(PARTICLE_OT_connect_hair); - WM_operatortype_append(PARTICLE_OT_disconnect_hair); - - WM_operatortype_append(SCENE_OT_render_layer_add); - WM_operatortype_append(SCENE_OT_render_layer_remove); - WM_operatortype_append(BUTTONS_OT_toolbox); WM_operatortype_append(BUTTONS_OT_file_browse); } diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 5d02e096228..77a1b671054 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -313,16 +313,16 @@ static int get_file_icon(struct direntry *file) static void file_draw_icon(int sx, int sy, int icon, int width, int height) { float x,y; - int blend=0; + float alpha=1.0f; x = (float)(sx); y = (float)(sy-height); - if (icon == ICON_FILE_BLANK) blend = -80; + if (icon == ICON_FILE_BLANK) alpha = 0.375f; glEnable(GL_BLEND); - UI_icon_draw_aspect_blended(x, y, icon, 1.f, blend); + UI_icon_draw_aspect(x, y, icon, 1.f, alpha); } diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c index 1d57f4e0d4c..c7e458b9e87 100644 --- a/source/blender/editors/space_node/node_draw.c +++ b/source/blender/editors/space_node/node_draw.c @@ -685,7 +685,7 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN icon_id= ICON_MATERIAL_DATA; iconofs-= 18.0f; glEnable(GL_BLEND); - UI_icon_draw_aspect_blended(iconofs, rct->ymax-NODE_DY+2, icon_id, snode->aspect, -60); + UI_icon_draw_aspect(iconofs, rct->ymax-NODE_DY+2, icon_id, snode->aspect, 0.5f); glDisable(GL_BLEND); } if(node->type == NODE_GROUP) { @@ -693,21 +693,18 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN iconofs-= 18.0f; glEnable(GL_BLEND); if(node->id->lib) { - glPixelTransferf(GL_GREEN_SCALE, 0.7f); - glPixelTransferf(GL_BLUE_SCALE, 0.3f); - UI_icon_draw_aspect(iconofs, rct->ymax-NODE_DY+2, ICON_NODE, snode->aspect); - glPixelTransferf(GL_GREEN_SCALE, 1.0f); - glPixelTransferf(GL_BLUE_SCALE, 1.0f); + float rgb[3] = {1.0f, 0.7f, 0.3f}; + UI_icon_draw_aspect_color(iconofs, rct->ymax-NODE_DY+2, ICON_NODE, snode->aspect, rgb); } else { - UI_icon_draw_aspect_blended(iconofs, rct->ymax-NODE_DY+2, ICON_NODE, snode->aspect, -60); + UI_icon_draw_aspect(iconofs, rct->ymax-NODE_DY+2, ICON_NODE, snode->aspect, 0.5f); } glDisable(GL_BLEND); } if(node->typeinfo->flag & NODE_OPTIONS) { iconofs-= 18.0f; glEnable(GL_BLEND); - UI_icon_draw_aspect_blended(iconofs, rct->ymax-NODE_DY+2, ICON_BUTS, snode->aspect, -60); + UI_icon_draw_aspect(iconofs, rct->ymax-NODE_DY+2, ICON_BUTS, snode->aspect, 0.5f); glDisable(GL_BLEND); } { /* always hide/reveal unused sockets */ @@ -720,7 +717,7 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN else*/ shade= -90; glEnable(GL_BLEND); - UI_icon_draw_aspect_blended(iconofs, rct->ymax-NODE_DY+2, ICON_PLUS, snode->aspect, shade); + UI_icon_draw_aspect(iconofs, rct->ymax-NODE_DY+2, ICON_PLUS, snode->aspect, 0.5f); glDisable(GL_BLEND); } diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c index 5fc09408229..5a89851d65b 100644 --- a/source/blender/editors/space_node/node_edit.c +++ b/source/blender/editors/space_node/node_edit.c @@ -62,7 +62,7 @@ #include "BKE_scene.h" #include "BKE_utildefines.h" -#include "ED_previewrender.h" +#include "ED_render.h" #include "BIF_gl.h" diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c index 12a5f33e119..2cfd9d99123 100644 --- a/source/blender/editors/space_node/space_node.c +++ b/source/blender/editors/space_node/space_node.c @@ -48,7 +48,7 @@ #include "BKE_screen.h" #include "BKE_node.h" -#include "ED_previewrender.h" +#include "ED_render.h" #include "ED_space_api.h" #include "ED_screen.h" diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 6e415ec731d..c175f835d67 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -448,12 +448,21 @@ static void view3d_main_area_listener(ARegion *ar, wmNotifier *wmn) ED_region_tag_redraw(ar); break; } + break; + case NC_WORLD: + switch(wmn->data) { + case ND_WORLD_DRAW: + ED_region_tag_redraw(ar); + break; + } + break; case NC_LAMP: switch(wmn->data) { case ND_LIGHTING_DRAW: ED_region_tag_redraw(ar); break; } + break; case NC_IMAGE: /* this could be more fine grained checks if we had * more context than just the region */ |