From b356eb6a8bfad738028e67844c7755f5684f7ce3 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 8 Mar 2010 20:08:04 +0000 Subject: [PATCH] image re-project now uses offscreen render function and has input for render size. unrelated changes that ended up being more trouble to commit separate... - removed BLI_split_dirfile(), was nasty, occasionaly modifying the source string, it could create directories and used the $CWD in some cases. was only used in 2 places in filesel.c, if this gives problems can address without bringing back this function. renamed BLI_split_dirfile_basic --> BLI_split_dirfile - view3d_operator_needs_opengl was being called for offscreen render when it wasnt needed. --- release/scripts/op/image.py | 1 + release/scripts/ui/space_view3d_toolbar.py | 2 + source/blender/blenkernel/BKE_displist.h | 1 + source/blender/blenkernel/BKE_image.h | 2 + source/blender/blenkernel/intern/image.c | 21 ++- source/blender/blenkernel/intern/pointcache.c | 2 +- source/blender/blenkernel/intern/sequencer.c | 115 +++++++++------- source/blender/blenkernel/intern/sound.c | 2 + source/blender/blenkernel/intern/text.c | 4 +- source/blender/blenlib/BLI_path_util.h | 3 +- source/blender/blenlib/intern/bpath.c | 6 +- source/blender/blenlib/intern/path_util.c | 128 +----------------- source/blender/blenloader/intern/writefile.c | 4 +- source/blender/collada/DocumentExporter.cpp | 2 +- source/blender/collada/DocumentImporter.cpp | 2 +- source/blender/editors/include/ED_view3d.h | 2 + source/blender/editors/render/render_opengl.c | 15 +- .../editors/sculpt_paint/paint_image.c | 34 ++--- .../editors/space_sequencer/sequencer_add.c | 4 +- .../editors/space_view3d/view3d_draw.c | 43 ++++++ source/blender/makesdna/DNA_scene_types.h | 3 + .../makesrna/intern/rna_sculpt_paint.c | 3 + .../blender/makesrna/intern/rna_sequencer.c | 6 +- source/gameengine/Ketsji/KX_PythonInit.cpp | 4 +- 24 files changed, 175 insertions(+), 234 deletions(-) diff --git a/release/scripts/op/image.py b/release/scripts/op/image.py index d68fc6a1a67..b2433481b84 100644 --- a/release/scripts/op/image.py +++ b/release/scripts/op/image.py @@ -92,6 +92,7 @@ class ProjectEdit(bpy.types.Operator): filename = os.path.basename(bpy.data.filename) filename = os.path.splitext(filename)[0] + # filename = bpy.utils.clean_name(filename) # fixes rubbish, needs checking if filename.startswith("."): # TODO, have a way to check if the file is saved, assuem .B25.blend filename = os.path.join(os.path.dirname(bpy.data.filename), filename) diff --git a/release/scripts/ui/space_view3d_toolbar.py b/release/scripts/ui/space_view3d_toolbar.py index 7996407445f..b8cde368e0b 100644 --- a/release/scripts/ui/space_view3d_toolbar.py +++ b/release/scripts/ui/space_view3d_toolbar.py @@ -910,6 +910,8 @@ class VIEW3D_PT_tools_projectpaint(View3DPanel): row = col.row(align=True) row.operator("image.project_edit", text="View Edit") row.operator("image.project_apply", text="Apply") + + col.prop(ipaint, "screen_grab_size", text="") sub = col.column() sub.operator("paint.project_image") diff --git a/source/blender/blenkernel/BKE_displist.h b/source/blender/blenkernel/BKE_displist.h index e685dd90223..01a1126e464 100644 --- a/source/blender/blenkernel/BKE_displist.h +++ b/source/blender/blenkernel/BKE_displist.h @@ -62,6 +62,7 @@ struct Material; struct Bone; struct Mesh; struct EditMesh; +struct DerivedMesh; /* used for curves, nurbs, mball, importing */ typedef struct DispList { diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index 6b22b10cf24..d1808366944 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -117,6 +117,8 @@ struct Image *BKE_add_image_file(const char *name, int frame); /* adds image, adds ibuf, generates color or pattern */ struct Image *BKE_add_image_size(int width, int height, char *name, int floatbuf, short uvtestgrid, float color[4]); +/* adds image from imbuf, owns imbuf */ +struct Image *BKE_add_image_imbuf(struct ImBuf *ibuf); /* for reload, refresh, pack */ void BKE_image_signal(struct Image *ima, struct ImageUser *iuser, int signal); diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index accadb3d434..ac107212e30 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -563,10 +563,8 @@ static ImBuf *add_ibuf_size(int width, int height, char *name, int floatbuf, sho /* adds new image block, creates ImBuf and initializes color */ Image *BKE_add_image_size(int width, int height, char *name, int floatbuf, short uvtestgrid, float color[4]) { - Image *ima; - /* on save, type is changed to FILE in editsima.c */ - ima= image_alloc(name, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST); + Image *ima= image_alloc(name, IMA_SRC_GENERATED, IMA_TYPE_UV_TEST); if (ima) { ImBuf *ibuf; @@ -585,6 +583,23 @@ Image *BKE_add_image_size(int width, int height, char *name, int floatbuf, short return ima; } +/* creates an image image owns the imbuf passed */ +Image *BKE_add_image_imbuf(ImBuf *ibuf) +{ + /* on save, type is changed to FILE in editsima.c */ + char filename[sizeof(ibuf->name)]; + BLI_split_dirfile(ibuf->name, NULL, filename); + Image *ima= image_alloc(filename, IMA_SRC_FILE, IMA_TYPE_IMAGE); + + if (ima) { + BLI_strncpy(ima->name, ibuf->name, FILE_MAX); + image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0); + ima->ok= IMA_OK_LOADED; + } + + return ima; +} + /* packs rect from memory as PNG */ void BKE_image_memorypack(Image *ima) { diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index b1319a81f5d..7ae2898ab8d 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -1060,7 +1060,7 @@ static int ptcache_path(PTCacheID *pid, char *filename) blendfilename= (lib)? lib->filename: G.sce; - BLI_split_dirfile_basic(blendfilename, NULL, file); + BLI_split_dirfile(blendfilename, NULL, file); i = strlen(file); /* remove .blend */ diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 98dbf83f032..d3b05cf802c 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -79,6 +79,8 @@ static int seqrecty= 0; #define SELECT 1 ListBase seqbase_clipboard; int seqbase_clipboard_frame; +void *sequencer_view3d_cb= NULL; /* NULL in background mode */ + void printf_strip(Sequence *seq) { @@ -2104,7 +2106,6 @@ static void do_build_seq_ibuf(Scene *scene, Sequence * seq, TStripElem *se, int } else if(seq->type == SEQ_SCENE) { // scene can be NULL after deletions Scene *sce= seq->scene;// *oldsce= scene; Render *re; - RenderResult rres; int have_seq= FALSE; int sce_valid= FALSE; @@ -2130,58 +2131,70 @@ static void do_build_seq_ibuf(Scene *scene, Sequence * seq, TStripElem *se, int if (!sce_valid) { se->ok = STRIPELEM_FAILED; } else if (se->ibuf==NULL && sce_valid) { - int oldcfra; - /* Hack! This function can be called from do_render_seq(), in that case - the seq->scene can already have a Render initialized with same name, - so we have to use a default name. (compositor uses scene name to - find render). - However, when called from within the UI (image preview in sequencer) - we do want to use scene Render, that way the render result is defined - for display in render/imagewindow + int do_opengl= 0; + if(do_opengl && have_seq==0 && (sequencer_view3d_cb!=NULL)) { + /* opengl offscreen render */ - Hmm, don't see, why we can't do that all the time, - and since G.rendering is uhm, gone... (Peter) - */ + /* sequencer_view3d_cb */ + // void (*seq_view3d_cb)(Scene *, int, int, int, int)= sequencer_view3d_cb; - int rendering = 1; - int doseq; - - oldcfra = seq->scene->r.cfra; - - if(rendering) - re= RE_NewRender(" do_build_seq_ibuf", RE_SLOT_DEFAULT); - else - re= RE_NewRender(sce->id.name, RE_SLOT_VIEW); - - /* prevent eternal loop */ - doseq= scene->r.scemode & R_DOSEQ; - scene->r.scemode &= ~R_DOSEQ; - - RE_BlenderFrame(re, sce, NULL, - seq->sfra+se->nr+seq->anim_startofs); - - RE_AcquireResultImage(re, &rres); - - if(rres.rectf) { - se->ibuf= IMB_allocImBuf(rres.rectx, rres.recty, 32, IB_rectfloat, 0); - memcpy(se->ibuf->rect_float, rres.rectf, 4*sizeof(float)*rres.rectx*rres.recty); - if(rres.rectz) { - addzbuffloatImBuf(se->ibuf); - memcpy(se->ibuf->zbuf_float, rres.rectz, sizeof(float)*rres.rectx*rres.recty); - } - } else if (rres.rect32) { - se->ibuf= IMB_allocImBuf(rres.rectx, rres.recty, 32, IB_rect, 0); - memcpy(se->ibuf->rect, rres.rect32, 4*rres.rectx*rres.recty); + // seq_view3d_cb(scene, cfra, render_size, seqrectx, seqrecty); } + else { + RenderResult rres; + int oldcfra; + /* Hack! This function can be called from do_render_seq(), in that case + the seq->scene can already have a Render initialized with same name, + so we have to use a default name. (compositor uses scene name to + find render). + However, when called from within the UI (image preview in sequencer) + we do want to use scene Render, that way the render result is defined + for display in render/imagewindow - RE_ReleaseResultImage(re); + Hmm, don't see, why we can't do that all the time, + and since G.rendering is uhm, gone... (Peter) + */ + + int rendering = 1; + int doseq; + + oldcfra = seq->scene->r.cfra; + + if(rendering) + re= RE_NewRender(" do_build_seq_ibuf", RE_SLOT_DEFAULT); + else + re= RE_NewRender(sce->id.name, RE_SLOT_VIEW); + + /* prevent eternal loop */ + doseq= scene->r.scemode & R_DOSEQ; + scene->r.scemode &= ~R_DOSEQ; + + RE_BlenderFrame(re, sce, NULL, + seq->sfra+se->nr+seq->anim_startofs); + + RE_AcquireResultImage(re, &rres); + + if(rres.rectf) { + se->ibuf= IMB_allocImBuf(rres.rectx, rres.recty, 32, IB_rectfloat, 0); + memcpy(se->ibuf->rect_float, rres.rectf, 4*sizeof(float)*rres.rectx*rres.recty); + if(rres.rectz) { + addzbuffloatImBuf(se->ibuf); + memcpy(se->ibuf->zbuf_float, rres.rectz, sizeof(float)*rres.rectx*rres.recty); + } + } else if (rres.rect32) { + se->ibuf= IMB_allocImBuf(rres.rectx, rres.recty, 32, IB_rect, 0); + memcpy(se->ibuf->rect, rres.rect32, 4*rres.rectx*rres.recty); + } + + RE_ReleaseResultImage(re); + + // BIF_end_render_callbacks(); + + /* restore */ + scene->r.scemode |= doseq; - // BIF_end_render_callbacks(); - - /* restore */ - scene->r.scemode |= doseq; - - seq->scene->r.cfra = oldcfra; + seq->scene->r.cfra = oldcfra; + } copy_to_ibuf_still(seq, se); @@ -3803,7 +3816,7 @@ Sequence *sequencer_add_image_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo strip->len = seq->len = seq_load->len ? seq_load->len : 1; strip->us= 1; strip->stripdata= se= MEM_callocN(seq->len*sizeof(StripElem), "stripelem"); - BLI_split_dirfile_basic(seq_load->path, strip->dir, se->name); + BLI_split_dirfile(seq_load->path, strip->dir, se->name); seq_load_apply(scene, seq, seq_load); @@ -3853,7 +3866,7 @@ Sequence *sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo strip->stripdata= se= MEM_callocN(seq->len*sizeof(StripElem), "stripelem"); - BLI_split_dirfile_basic(seq_load->path, strip->dir, se->name); + BLI_split_dirfile(seq_load->path, strip->dir, se->name); seq->scene_sound = sound_add_scene_sound(scene, seq, seq_load->start_frame, seq_load->start_frame + strip->len, 0); @@ -3897,7 +3910,7 @@ Sequence *sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoadInfo strip->stripdata= se= MEM_callocN(seq->len*sizeof(StripElem), "stripelem"); - BLI_split_dirfile_basic(seq_load->path, strip->dir, se->name); + BLI_split_dirfile(seq_load->path, strip->dir, se->name); calc_sequence_disp(scene, seq); diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index e014b209e07..23df930aa84 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -39,6 +39,7 @@ static int force_device = -1; +#ifdef WITH_JACK static void sound_sync_callback(void* data, int mode, float time) { struct Main* bmain = (struct Main*)data; @@ -58,6 +59,7 @@ static void sound_sync_callback(void* data, int mode, float time) scene = scene->id.next; } } +#endif int sound_define_from_str(char *str) { diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index b58caf14293..a7f80953f22 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -247,7 +247,7 @@ int reopen_text(Text *text) BLI_strncpy(str, text->name, FILE_MAXDIR+FILE_MAXFILE); BLI_convertstringcode(str, G.sce); - BLI_split_dirfile_basic(str, NULL, sfile); + BLI_split_dirfile(str, NULL, sfile); fp= fopen(str, "r"); if(fp==NULL) return 0; @@ -345,7 +345,7 @@ Text *add_text(char *file, const char *relpath) BLI_strncpy(str, file, FILE_MAXDIR+FILE_MAXFILE); if (relpath) /* can be NULL (bg mode) */ BLI_convertstringcode(str, relpath); - BLI_split_dirfile_basic(str, NULL, sfile); + BLI_split_dirfile(str, NULL, sfile); fp= fopen(str, "r"); if(fp==NULL) return NULL; diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h index 9b4084aa172..36a540e4d97 100644 --- a/source/blender/blenlib/BLI_path_util.h +++ b/source/blender/blenlib/BLI_path_util.h @@ -56,8 +56,7 @@ void BLI_setenv_if_new(const char *env, const char* val); void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file); void BLI_make_exist(char *dir); void BLI_make_existing_file(char *name); -void BLI_split_dirfile(char *string, char *dir, char *file); -void BLI_split_dirfile_basic(const char *string, char *dir, char *file); +void BLI_split_dirfile(const char *string, char *dir, char *file); void BLI_join_dirfile(char *string, const char *dir, const char *file); int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char *base_dir, const char *src_dir, const char *dest_dir); void BLI_getlastdir(const char* dir, char *last, int maxlen); diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index 8d3d807ba1b..71d16adeab5 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -290,7 +290,7 @@ static void seq_setpath(struct BPathIterator *bpi, char *path) { if (SEQ_HAS_PATH(seq)) { if (seq->type == SEQ_IMAGE || seq->type == SEQ_MOVIE) { - BLI_split_dirfile_basic(path, seq->strip->dir, seq->strip->stripdata->name); + BLI_split_dirfile(path, seq->strip->dir, seq->strip->stripdata->name); } else { /* simple case */ BLI_strncpy(seq->strip->dir, path, sizeof(seq->strip->dir)); @@ -673,7 +673,7 @@ void findMissingFiles(char *basepath, char *str) { //XXX waitcursor( 1 ); - BLI_split_dirfile_basic(str, dirname, NULL); + BLI_split_dirfile(str, dirname, NULL); BLI_bpathIterator_init(&bpi, basepath); @@ -694,7 +694,7 @@ void findMissingFiles(char *basepath, char *str) { /* can the dir be opened? */ filesize = -1; recur_depth = 0; - BLI_split_dirfile_basic(filepath, NULL, filename); /* the file to find */ + BLI_split_dirfile(filepath, NULL, filename); /* the file to find */ findFileRecursive(filename_new, dirname, filename, &filesize, &recur_depth); if (filesize == -1) { /* could not open dir */ diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index fe43960b770..2346b172e87 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -1163,7 +1163,7 @@ int BLI_testextensie(const char *str, const char *ext) * - dosnt use CWD, or deal with relative paths. * - Only fill's in *dir and *file when they are non NULL * */ -void BLI_split_dirfile_basic(const char *string, char *dir, char *file) +void BLI_split_dirfile(const char *string, char *dir, char *file) { int lslash=0, i = 0; for (i=0; string[i]!='\0'; i++) { @@ -1183,128 +1183,6 @@ void BLI_split_dirfile_basic(const char *string, char *dir, char *file) } } - -/* Warning, - * - May modify 'string' variable - * - May create the directory if it dosnt exist - * if this is not needed use BLI_split_dirfile_basic(...) - */ -void BLI_split_dirfile(char *string, char *dir, char *file) -{ - int a; -#ifdef WIN32 - int sl; - short is_relative = 0; - char path[FILE_MAX]; -#endif - - dir[0]= 0; - file[0]= 0; - -#ifdef WIN32 - BLI_strncpy(path, string, FILE_MAX); - BLI_char_switch(path, '/', '\\'); /* make sure we have a valid path format */ - sl = strlen(path); - if (sl) { - int len; - if (path[0] == '/' || path[0] == '\\') { - BLI_strncpy(dir, path, FILE_MAXDIR); - if (sl > 1 && path[0] == '\\' && path[1] == '\\') is_relative = 1; - } else if (sl > 2 && path[1] == ':' && path[2] == '\\') { - BLI_strncpy(dir, path, FILE_MAXDIR); - } else { - BLI_getwdN(dir); - strcat(dir,"\\"); - strcat(dir,path); - BLI_strncpy(path,dir,FILE_MAXDIR+FILE_MAXFILE); - } - - // BLI_exist doesn't recognize a slashed dirname as a dir - // check if a trailing slash exists, and remove it. Do not do this - // when we are already at root. -jesterKing - a = strlen(dir); - if(a>=4 && dir[a-1]=='\\') dir[a-1] = 0; - - if (is_relative) { - printf("WARNING: BLI_split_dirfile needs absolute dir\n"); - } - else { - BLI_make_exist(dir); - } - - if (S_ISDIR(BLI_exist(dir))) { - - /* copy from end of string into file, to ensure filename itself isn't truncated - if string is too long. (aphex) */ - - len = FILE_MAXFILE - strlen(path); - - if (len < 0) - BLI_strncpy(file,path + abs(len),FILE_MAXFILE); - else - BLI_strncpy(file,path,FILE_MAXFILE); - - if (strrchr(path,'\\')) { - BLI_strncpy(file,strrchr(path,'\\')+1,FILE_MAXFILE); - } - - if ( (a = strlen(dir)) ) { - if (dir[a-1] != '\\') strcat(dir,"\\"); - } - } - else { - a = strlen(dir) - 1; - while(a>0 && dir[a] != '\\') a--; - dir[a + 1] = 0; - BLI_strncpy(file, path + strlen(dir),FILE_MAXFILE); - } - - } - else { - /* defaulting to first valid drive hoping it's not empty CD and DVD drives */ - get_default_root(dir); - file[0]=0; - } -#else - if (strlen(string)) { - if (string[0] == '/') { - strcpy(dir, string); - } else if (string[1] == ':' && string[2] == '\\') { - string+=2; - strcpy(dir, string); - } else { - BLI_getwdN(dir); - strcat(dir,"/"); - strcat(dir,string); - strcpy((char *)string,dir); - } - - BLI_make_exist(dir); - - if (S_ISDIR(BLI_exist(dir))) { - strcpy(file,string + strlen(dir)); - - if (strrchr(file,'/')) strcpy(file,strrchr(file,'/')+1); - - if ( (a = strlen(dir)) ) { - if (dir[a-1] != '/') strcat(dir,"/"); - } - } - else { - a = strlen(dir) - 1; - while(dir[a] != '/') a--; - dir[a + 1] = 0; - strcpy(file, string + strlen(dir)); - } - } - else { - BLI_getwdN(dir); - strcat(dir, "/"); - file[0] = 0; - } -#endif -} - /* simple appending of filename to dir, does not check for valid path! */ void BLI_join_dirfile(char *string, const char *dir, const char *file) { @@ -1363,7 +1241,7 @@ int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char if (rel) rel[0]= 0; - BLI_split_dirfile_basic(base_dir, blend_dir, NULL); + BLI_split_dirfile(base_dir, blend_dir, NULL); if (src_dir[0]=='\0') return 0; @@ -1374,7 +1252,7 @@ int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char BLI_convertstringcode(path, base_dir); /* get the directory part */ - BLI_split_dirfile_basic(path, dir, base); + BLI_split_dirfile(path, dir, base); len= strlen(blend_dir); diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index 22fcd28ca00..3a5b8e14de3 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -2466,8 +2466,8 @@ int BLO_write_file(Main *mainvar, char *dir, int write_flags, ReportList *report if(write_flags & G_FILE_RELATIVE_REMAP) { char dir1[FILE_MAXDIR+FILE_MAXFILE]; char dir2[FILE_MAXDIR+FILE_MAXFILE]; - BLI_split_dirfile_basic(dir, dir1, NULL); - BLI_split_dirfile_basic(mainvar->name, dir2, NULL); + BLI_split_dirfile(dir, dir1, NULL); + BLI_split_dirfile(mainvar->name, dir2, NULL); /* just incase there is some subtle difference */ BLI_cleanup_dir(mainvar->name, dir1); diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp index 3e1898a64d9..a4c45358417 100644 --- a/source/blender/collada/DocumentExporter.cpp +++ b/source/blender/collada/DocumentExporter.cpp @@ -1433,7 +1433,7 @@ public: char src[FILE_MAX]; char dir[FILE_MAX]; - BLI_split_dirfile_basic(mfilename, dir, NULL); + BLI_split_dirfile(mfilename, dir, NULL); BKE_rebase_path(abs, sizeof(abs), rel, sizeof(rel), G.sce, image->name, dir); diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 33c9a061cda..e3bdf25bdc0 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -3407,7 +3407,7 @@ public: char dir[FILE_MAX]; char full_path[FILE_MAX]; - BLI_split_dirfile_basic(filename, dir, NULL); + BLI_split_dirfile(filename, dir, NULL); BLI_join_dirfile(full_path, dir, filepath.c_str()); Image *ima = BKE_add_image_file(full_path, 0); if (!ima) { diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index cb73c5f5b39..303748c79fd 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -158,6 +158,8 @@ int ED_view3d_context_activate(struct bContext *C); void ED_view3d_draw_offscreen(struct Scene *scene, struct View3D *v3d, struct ARegion *ar, int winx, int winy, float viewmat[][4], float winmat[][4]); +struct ImBuf *ED_view3d_draw_offscreen_imbuf(struct Scene *scene, struct View3D *v3d, struct ARegion *ar, int sizex, int sizey); + void view3d_clipping_local(struct RegionView3D *rv3d, float mat[][4]); Base *ED_view3d_give_base_under_cursor(struct bContext *C, short *mval); diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c index 7916f29043f..212dc335a63 100644 --- a/source/blender/editors/render/render_opengl.c +++ b/source/blender/editors/render/render_opengl.c @@ -37,23 +37,15 @@ #include "BLI_editVert.h" #include "BLI_dlrbTree.h" -#include "DNA_armature_types.h" -#include "DNA_image_types.h" -#include "DNA_lattice_types.h" #include "DNA_object_types.h" -#include "DNA_mesh_types.h" -#include "DNA_curve_types.h" #include "DNA_scene_types.h" -#include "DNA_meta_types.h" #include "DNA_view3d_types.h" #include "BKE_blender.h" -#include "BKE_colortools.h" +#include "BKE_object.h" #include "BKE_context.h" -#include "BKE_customdata.h" #include "BKE_global.h" #include "BKE_image.h" -#include "BKE_idprop.h" #include "BKE_library.h" #include "BKE_main.h" #include "BKE_mesh.h" @@ -62,7 +54,6 @@ #include "BKE_scene.h" #include "BKE_screen.h" #include "BKE_utildefines.h" -#include "BKE_sound.h" #include "BKE_writeavi.h" #include "WM_api.h" @@ -180,7 +171,6 @@ static int screen_opengl_render_init(bContext *C, wmOperator *op) sizex= (scene->r.size*scene->r.xsch)/100; sizey= (scene->r.size*scene->r.ysch)/100; - view3d_operator_needs_opengl(C); ofs= GPU_offscreen_create(sizex, sizey); if(!ofs) { @@ -468,3 +458,6 @@ void RENDER_OT_opengl(wmOperatorType *ot) RNA_def_boolean(ot->srna, "animation", 0, "Animation", ""); } + +/* function for getting an opengl buffer from a View3D, used by sequencer */ +// extern void *sequencer_view3d_cb; diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index bd4462c7913..4a98f524bc4 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -5479,37 +5479,21 @@ void PAINT_OT_project_image(wmOperatorType *ot) ot->prop= prop; } -static Image *ED_region_image(ARegion *ar, char *filename) -{ - int x= ar->winrct.xmin; - int y= ar->winrct.ymin; - int w= ar->winrct.xmax-x; - int h= ar->winrct.ymax-y; - - if (h && w) { - float color[] = {0, 0, 0, 1}; - Image *image = BKE_add_image_size(w, h, filename, 0, 0, color); - ImBuf *ibuf= BKE_image_get_ibuf(image, NULL); - - glReadBuffer(GL_FRONT); - glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); - glFinish(); - glReadBuffer(GL_BACK); - - return image; - } - - return NULL; -} - static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op) { - ARegion *ar= CTX_wm_region(C); Image *image; + ImBuf *ibuf; char filename[FILE_MAX]; + + Scene *scene= CTX_data_scene(C); + ToolSettings *settings= scene->toolsettings; + int w= settings->imapaint.screen_grab_size[0]; + int h= settings->imapaint.screen_grab_size[1]; + RNA_string_get(op->ptr, "filename", filename); - image= ED_region_image(ar, filename); + ibuf= ED_view3d_draw_offscreen_imbuf(CTX_data_scene(C), CTX_wm_view3d(C), CTX_wm_region(C), w, h); + image= BKE_add_image_imbuf(ibuf); if(image) { /* now for the trickyness. store the view projection here! diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c index bd1053d8d77..7a809f7b668 100644 --- a/source/blender/editors/space_sequencer/sequencer_add.c +++ b/source/blender/editors/space_sequencer/sequencer_add.c @@ -282,7 +282,7 @@ static int sequencer_add_generic_strip_exec(bContext *C, wmOperator *op, SeqLoad char dir_only[FILE_MAX]; char file_only[FILE_MAX]; - BLI_split_dirfile_basic(seq_load.path, dir_only, NULL); + BLI_split_dirfile(seq_load.path, dir_only, NULL); RNA_BEGIN(op->ptr, itemptr, "files") { RNA_string_get(&itemptr, "name", file_only); @@ -422,7 +422,7 @@ static int sequencer_add_image_strip_exec(bContext *C, wmOperator *op) RNA_END; } else { - BLI_split_dirfile_basic(seq_load.path, NULL, se->name); + BLI_split_dirfile(seq_load.path, NULL, se->name); if(seq_load.start_frame < seq_load.end_frame) { seq->endstill= seq_load.end_frame - seq_load.start_frame; } diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index ea81a8cafd9..35818a4e3e0 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -95,6 +95,7 @@ #include "GPU_draw.h" #include "GPU_material.h" +#include "GPU_extensions.h" #include "view3d_intern.h" // own include @@ -2032,6 +2033,48 @@ void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx, glPopMatrix(); } +/* utility func for ED_view3d_draw_offscreen */ +ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar, int sizex, int sizey) +{ + RegionView3D *rv3d= ar->regiondata; + ImBuf *ibuf; + GPUOffScreen *ofs; + + /* bind */ + ofs= GPU_offscreen_create(sizex, sizey); + if(ofs == NULL) + return NULL; + + GPU_offscreen_bind(ofs); + + /* render 3d view */ + if(rv3d->persp==RV3D_CAMOB && v3d->camera) { + float winmat[4][4]; + float _clipsta, _clipend, _lens, _yco, _dx, _dy; + rctf _viewplane; + + object_camera_matrix(&scene->r, v3d->camera, sizex, sizey, 0, winmat, &_viewplane, &_clipsta, &_clipend, &_lens, &_yco, &_dx, &_dy); + + ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat); + } + else { + ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, NULL); + } + + /* read in pixels & stamp */ + ibuf= IMB_allocImBuf(sizex, sizey, 24, IB_rect, 0); + glReadPixels(0, 0, sizex, sizey, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); + + //if((scene->r.stamp & R_STAMP_ALL) && (scene->r.stamp & R_STAMP_DRAW)) + // BKE_stamp_buf(scene, NULL, rr->rectf, rr->rectx, rr->recty, 4); + + /* unbind */ + GPU_offscreen_unbind(ofs); + GPU_offscreen_free(ofs); + + return ibuf; +} + /* NOTE: the info that this uses is updated in ED_refresh_viewport_fps(), * which currently gets called during SCREEN_OT_animation_step. */ diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 928637a0047..c9339b4bddd 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -521,6 +521,9 @@ typedef struct ImagePaintSettings { /* for projection painting only */ short seam_bleed, normal_angle; + short screen_grab_size[2]; /* capture size for re-projection */ + + int pad1; void *paintcursor; /* wm handle */ } ImagePaintSettings; diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c index 456071499e3..4aa1401ac84 100644 --- a/source/blender/makesrna/intern/rna_sculpt_paint.c +++ b/source/blender/makesrna/intern/rna_sculpt_paint.c @@ -351,6 +351,9 @@ static void rna_def_image_paint(BlenderRNA *brna) prop= RNA_def_property(srna, "normal_angle", PROP_INT, PROP_UNSIGNED); RNA_def_property_range(prop, 0, 90); RNA_def_property_ui_text(prop, "Angle", "Paint most on faces pointing towards the view acording to this angle"); + + prop= RNA_def_int_array(srna, "screen_grab_size", 2, NULL, 0, 0, "screen_grab_size", "Size to capture the image for re-projecting", 0, 0); + RNA_def_property_range(prop, 512, 16384); } static void rna_def_particle_edit(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_sequencer.c b/source/blender/makesrna/intern/rna_sequencer.c index 7464df6eb79..8f80ae8a301 100644 --- a/source/blender/makesrna/intern/rna_sequencer.c +++ b/source/blender/makesrna/intern/rna_sequencer.c @@ -319,7 +319,7 @@ static void rna_Sequence_filepath_set(PointerRNA *ptr, const char *value) Sequence *seq= (Sequence*)(ptr->data); char dir[FILE_MAX], name[FILE_MAX]; - BLI_split_dirfile_basic(value, dir, name); + BLI_split_dirfile(value, dir, name); BLI_strncpy(seq->strip->dir, dir, sizeof(seq->strip->dir)); BLI_strncpy(seq->strip->stripdata->name, name, sizeof(seq->strip->stripdata->name)); } @@ -347,7 +347,7 @@ static void rna_SoundSequence_filename_set(PointerRNA *ptr, const char *value) Sequence *seq= (Sequence*)(ptr->data); char dir[FILE_MAX], name[FILE_MAX]; - BLI_split_dirfile_basic(value, dir, name); + BLI_split_dirfile(value, dir, name); BLI_strncpy(seq->strip->dir, dir, sizeof(seq->strip->dir)); BLI_strncpy(seq->strip->stripdata->name, name, sizeof(seq->strip->stripdata->name)); } @@ -357,7 +357,7 @@ static void rna_SequenceElement_filename_set(PointerRNA *ptr, const char *value) StripElem *elem= (StripElem*)(ptr->data); char name[FILE_MAX]; - BLI_split_dirfile_basic(value, NULL, name); + BLI_split_dirfile(value, NULL, name); BLI_strncpy(elem->name, name, sizeof(elem->name)); } diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 6f0ae284392..c30939fba54 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -474,7 +474,7 @@ static PyObject* gPyGetBlendFileList(PyObject*, PyObject* args) BLI_convertstringcode(cpath, gp_GamePythonPath); } else { /* Get the dir only */ - BLI_split_dirfile_basic(gp_GamePythonPath, cpath, NULL); + BLI_split_dirfile(gp_GamePythonPath, cpath, NULL); } if((dp = opendir(cpath)) == NULL) { @@ -1786,7 +1786,7 @@ static void initPySysObjects__append(PyObject *sys_path, char *filename) PyObject *item; char expanded[FILE_MAXDIR + FILE_MAXFILE]; - BLI_split_dirfile_basic(filename, expanded, NULL); /* get the dir part of filename only */ + BLI_split_dirfile(filename, expanded, NULL); /* get the dir part of filename only */ BLI_convertstringcode(expanded, gp_GamePythonPath); /* filename from lib->filename is (always?) absolute, so this may not be needed but it wont hurt */ BLI_cleanup_file(gp_GamePythonPath, expanded); /* Dont use BLI_cleanup_dir because it adds a slash - BREAKS WIN32 ONLY */ item= PyUnicode_FromString(expanded);