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.
This commit is contained in:
Campbell Barton 2010-03-08 20:08:04 +00:00
parent 187b3bc1eb
commit b356eb6a8b
24 changed files with 175 additions and 234 deletions

@ -92,6 +92,7 @@ class ProjectEdit(bpy.types.Operator):
filename = os.path.basename(bpy.data.filename) filename = os.path.basename(bpy.data.filename)
filename = os.path.splitext(filename)[0] filename = os.path.splitext(filename)[0]
# filename = bpy.utils.clean_name(filename) # fixes <memory> rubbish, needs checking
if filename.startswith("."): # TODO, have a way to check if the file is saved, assuem .B25.blend 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) filename = os.path.join(os.path.dirname(bpy.data.filename), filename)

@ -910,6 +910,8 @@ class VIEW3D_PT_tools_projectpaint(View3DPanel):
row = col.row(align=True) row = col.row(align=True)
row.operator("image.project_edit", text="View Edit") row.operator("image.project_edit", text="View Edit")
row.operator("image.project_apply", text="Apply") row.operator("image.project_apply", text="Apply")
col.prop(ipaint, "screen_grab_size", text="")
sub = col.column() sub = col.column()
sub.operator("paint.project_image") sub.operator("paint.project_image")

@ -62,6 +62,7 @@ struct Material;
struct Bone; struct Bone;
struct Mesh; struct Mesh;
struct EditMesh; struct EditMesh;
struct DerivedMesh;
/* used for curves, nurbs, mball, importing */ /* used for curves, nurbs, mball, importing */
typedef struct DispList { typedef struct DispList {

@ -117,6 +117,8 @@ struct Image *BKE_add_image_file(const char *name, int frame);
/* adds image, adds ibuf, generates color or pattern */ /* 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]); 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 */ /* for reload, refresh, pack */
void BKE_image_signal(struct Image *ima, struct ImageUser *iuser, int signal); void BKE_image_signal(struct Image *ima, struct ImageUser *iuser, int signal);

@ -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 */ /* 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 *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 */ /* 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) { if (ima) {
ImBuf *ibuf; ImBuf *ibuf;
@ -585,6 +583,23 @@ Image *BKE_add_image_size(int width, int height, char *name, int floatbuf, short
return ima; 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 */ /* packs rect from memory as PNG */
void BKE_image_memorypack(Image *ima) void BKE_image_memorypack(Image *ima)
{ {

@ -1060,7 +1060,7 @@ static int ptcache_path(PTCacheID *pid, char *filename)
blendfilename= (lib)? lib->filename: G.sce; blendfilename= (lib)? lib->filename: G.sce;
BLI_split_dirfile_basic(blendfilename, NULL, file); BLI_split_dirfile(blendfilename, NULL, file);
i = strlen(file); i = strlen(file);
/* remove .blend */ /* remove .blend */

@ -79,6 +79,8 @@ static int seqrecty= 0;
#define SELECT 1 #define SELECT 1
ListBase seqbase_clipboard; ListBase seqbase_clipboard;
int seqbase_clipboard_frame; int seqbase_clipboard_frame;
void *sequencer_view3d_cb= NULL; /* NULL in background mode */
void printf_strip(Sequence *seq) 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 } else if(seq->type == SEQ_SCENE) { // scene can be NULL after deletions
Scene *sce= seq->scene;// *oldsce= scene; Scene *sce= seq->scene;// *oldsce= scene;
Render *re; Render *re;
RenderResult rres;
int have_seq= FALSE; int have_seq= FALSE;
int sce_valid= 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) { if (!sce_valid) {
se->ok = STRIPELEM_FAILED; se->ok = STRIPELEM_FAILED;
} else if (se->ibuf==NULL && sce_valid) { } else if (se->ibuf==NULL && sce_valid) {
int oldcfra; int do_opengl= 0;
/* Hack! This function can be called from do_render_seq(), in that case if(do_opengl && have_seq==0 && (sequencer_view3d_cb!=NULL)) {
the seq->scene can already have a Render initialized with same name, /* opengl offscreen render */
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
Hmm, don't see, why we can't do that all the time, /* sequencer_view3d_cb */
and since G.rendering is uhm, gone... (Peter) // void (*seq_view3d_cb)(Scene *, int, int, int, int)= sequencer_view3d_cb;
*/
int rendering = 1; // seq_view3d_cb(scene, cfra, render_size, seqrectx, seqrecty);
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);
} }
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(); seq->scene->r.cfra = oldcfra;
}
/* restore */
scene->r.scemode |= doseq;
seq->scene->r.cfra = oldcfra;
copy_to_ibuf_still(seq, se); 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->len = seq->len = seq_load->len ? seq_load->len : 1;
strip->us= 1; strip->us= 1;
strip->stripdata= se= MEM_callocN(seq->len*sizeof(StripElem), "stripelem"); 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); 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"); 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); 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"); 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); calc_sequence_disp(scene, seq);

@ -39,6 +39,7 @@
static int force_device = -1; static int force_device = -1;
#ifdef WITH_JACK
static void sound_sync_callback(void* data, int mode, float time) static void sound_sync_callback(void* data, int mode, float time)
{ {
struct Main* bmain = (struct Main*)data; 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; scene = scene->id.next;
} }
} }
#endif
int sound_define_from_str(char *str) int sound_define_from_str(char *str)
{ {

@ -247,7 +247,7 @@ int reopen_text(Text *text)
BLI_strncpy(str, text->name, FILE_MAXDIR+FILE_MAXFILE); BLI_strncpy(str, text->name, FILE_MAXDIR+FILE_MAXFILE);
BLI_convertstringcode(str, G.sce); BLI_convertstringcode(str, G.sce);
BLI_split_dirfile_basic(str, NULL, sfile); BLI_split_dirfile(str, NULL, sfile);
fp= fopen(str, "r"); fp= fopen(str, "r");
if(fp==NULL) return 0; 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); BLI_strncpy(str, file, FILE_MAXDIR+FILE_MAXFILE);
if (relpath) /* can be NULL (bg mode) */ if (relpath) /* can be NULL (bg mode) */
BLI_convertstringcode(str, relpath); BLI_convertstringcode(str, relpath);
BLI_split_dirfile_basic(str, NULL, sfile); BLI_split_dirfile(str, NULL, sfile);
fp= fopen(str, "r"); fp= fopen(str, "r");
if(fp==NULL) return NULL; if(fp==NULL) return NULL;

@ -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_file_string(const char *relabase, char *string, const char *dir, const char *file);
void BLI_make_exist(char *dir); void BLI_make_exist(char *dir);
void BLI_make_existing_file(char *name); void BLI_make_existing_file(char *name);
void BLI_split_dirfile(char *string, char *dir, char *file); void BLI_split_dirfile(const char *string, char *dir, char *file);
void BLI_split_dirfile_basic(const char *string, char *dir, char *file);
void BLI_join_dirfile(char *string, const char *dir, const 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); 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); void BLI_getlastdir(const char* dir, char *last, int maxlen);

@ -290,7 +290,7 @@ static void seq_setpath(struct BPathIterator *bpi, char *path) {
if (SEQ_HAS_PATH(seq)) { if (SEQ_HAS_PATH(seq)) {
if (seq->type == SEQ_IMAGE || seq->type == SEQ_MOVIE) { 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 { } else {
/* simple case */ /* simple case */
BLI_strncpy(seq->strip->dir, path, sizeof(seq->strip->dir)); BLI_strncpy(seq->strip->dir, path, sizeof(seq->strip->dir));
@ -673,7 +673,7 @@ void findMissingFiles(char *basepath, char *str) {
//XXX waitcursor( 1 ); //XXX waitcursor( 1 );
BLI_split_dirfile_basic(str, dirname, NULL); BLI_split_dirfile(str, dirname, NULL);
BLI_bpathIterator_init(&bpi, basepath); BLI_bpathIterator_init(&bpi, basepath);
@ -694,7 +694,7 @@ void findMissingFiles(char *basepath, char *str) {
/* can the dir be opened? */ /* can the dir be opened? */
filesize = -1; filesize = -1;
recur_depth = 0; 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); findFileRecursive(filename_new, dirname, filename, &filesize, &recur_depth);
if (filesize == -1) { /* could not open dir */ if (filesize == -1) { /* could not open dir */

@ -1163,7 +1163,7 @@ int BLI_testextensie(const char *str, const char *ext)
* - dosnt use CWD, or deal with relative paths. * - dosnt use CWD, or deal with relative paths.
* - Only fill's in *dir and *file when they are non NULL * - 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; int lslash=0, i = 0;
for (i=0; string[i]!='\0'; i++) { 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! */ /* simple appending of filename to dir, does not check for valid path! */
void BLI_join_dirfile(char *string, const char *dir, const char *file) 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) if (rel)
rel[0]= 0; 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') if (src_dir[0]=='\0')
return 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); BLI_convertstringcode(path, base_dir);
/* get the directory part */ /* get the directory part */
BLI_split_dirfile_basic(path, dir, base); BLI_split_dirfile(path, dir, base);
len= strlen(blend_dir); len= strlen(blend_dir);

@ -2466,8 +2466,8 @@ int BLO_write_file(Main *mainvar, char *dir, int write_flags, ReportList *report
if(write_flags & G_FILE_RELATIVE_REMAP) { if(write_flags & G_FILE_RELATIVE_REMAP) {
char dir1[FILE_MAXDIR+FILE_MAXFILE]; char dir1[FILE_MAXDIR+FILE_MAXFILE];
char dir2[FILE_MAXDIR+FILE_MAXFILE]; char dir2[FILE_MAXDIR+FILE_MAXFILE];
BLI_split_dirfile_basic(dir, dir1, NULL); BLI_split_dirfile(dir, dir1, NULL);
BLI_split_dirfile_basic(mainvar->name, dir2, NULL); BLI_split_dirfile(mainvar->name, dir2, NULL);
/* just incase there is some subtle difference */ /* just incase there is some subtle difference */
BLI_cleanup_dir(mainvar->name, dir1); BLI_cleanup_dir(mainvar->name, dir1);

@ -1433,7 +1433,7 @@ public:
char src[FILE_MAX]; char src[FILE_MAX];
char dir[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); BKE_rebase_path(abs, sizeof(abs), rel, sizeof(rel), G.sce, image->name, dir);

@ -3407,7 +3407,7 @@ public:
char dir[FILE_MAX]; char dir[FILE_MAX];
char full_path[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()); BLI_join_dirfile(full_path, dir, filepath.c_str());
Image *ima = BKE_add_image_file(full_path, 0); Image *ima = BKE_add_image_file(full_path, 0);
if (!ima) { if (!ima) {

@ -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, void ED_view3d_draw_offscreen(struct Scene *scene, struct View3D *v3d, struct ARegion *ar,
int winx, int winy, float viewmat[][4], float winmat[][4]); 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]); void view3d_clipping_local(struct RegionView3D *rv3d, float mat[][4]);
Base *ED_view3d_give_base_under_cursor(struct bContext *C, short *mval); Base *ED_view3d_give_base_under_cursor(struct bContext *C, short *mval);

@ -37,23 +37,15 @@
#include "BLI_editVert.h" #include "BLI_editVert.h"
#include "BLI_dlrbTree.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_object_types.h"
#include "DNA_mesh_types.h"
#include "DNA_curve_types.h"
#include "DNA_scene_types.h" #include "DNA_scene_types.h"
#include "DNA_meta_types.h"
#include "DNA_view3d_types.h" #include "DNA_view3d_types.h"
#include "BKE_blender.h" #include "BKE_blender.h"
#include "BKE_colortools.h" #include "BKE_object.h"
#include "BKE_context.h" #include "BKE_context.h"
#include "BKE_customdata.h"
#include "BKE_global.h" #include "BKE_global.h"
#include "BKE_image.h" #include "BKE_image.h"
#include "BKE_idprop.h"
#include "BKE_library.h" #include "BKE_library.h"
#include "BKE_main.h" #include "BKE_main.h"
#include "BKE_mesh.h" #include "BKE_mesh.h"
@ -62,7 +54,6 @@
#include "BKE_scene.h" #include "BKE_scene.h"
#include "BKE_screen.h" #include "BKE_screen.h"
#include "BKE_utildefines.h" #include "BKE_utildefines.h"
#include "BKE_sound.h"
#include "BKE_writeavi.h" #include "BKE_writeavi.h"
#include "WM_api.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; sizex= (scene->r.size*scene->r.xsch)/100;
sizey= (scene->r.size*scene->r.ysch)/100; sizey= (scene->r.size*scene->r.ysch)/100;
view3d_operator_needs_opengl(C);
ofs= GPU_offscreen_create(sizex, sizey); ofs= GPU_offscreen_create(sizex, sizey);
if(!ofs) { if(!ofs) {
@ -468,3 +458,6 @@ void RENDER_OT_opengl(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "animation", 0, "Animation", ""); 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;

@ -5479,37 +5479,21 @@ void PAINT_OT_project_image(wmOperatorType *ot)
ot->prop= prop; 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) static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
{ {
ARegion *ar= CTX_wm_region(C);
Image *image; Image *image;
ImBuf *ibuf;
char filename[FILE_MAX]; 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); 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) { if(image) {
/* now for the trickyness. store the view projection here! /* now for the trickyness. store the view projection here!

@ -282,7 +282,7 @@ static int sequencer_add_generic_strip_exec(bContext *C, wmOperator *op, SeqLoad
char dir_only[FILE_MAX]; char dir_only[FILE_MAX];
char file_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_BEGIN(op->ptr, itemptr, "files") {
RNA_string_get(&itemptr, "name", file_only); RNA_string_get(&itemptr, "name", file_only);
@ -422,7 +422,7 @@ static int sequencer_add_image_strip_exec(bContext *C, wmOperator *op)
RNA_END; RNA_END;
} }
else { 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) { if(seq_load.start_frame < seq_load.end_frame) {
seq->endstill= seq_load.end_frame - seq_load.start_frame; seq->endstill= seq_load.end_frame - seq_load.start_frame;
} }

@ -95,6 +95,7 @@
#include "GPU_draw.h" #include "GPU_draw.h"
#include "GPU_material.h" #include "GPU_material.h"
#include "GPU_extensions.h"
#include "view3d_intern.h" // own include #include "view3d_intern.h" // own include
@ -2032,6 +2033,48 @@ void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx,
glPopMatrix(); 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(), /* NOTE: the info that this uses is updated in ED_refresh_viewport_fps(),
* which currently gets called during SCREEN_OT_animation_step. * which currently gets called during SCREEN_OT_animation_step.
*/ */

@ -521,6 +521,9 @@ typedef struct ImagePaintSettings {
/* for projection painting only */ /* for projection painting only */
short seam_bleed, normal_angle; short seam_bleed, normal_angle;
short screen_grab_size[2]; /* capture size for re-projection */
int pad1;
void *paintcursor; /* wm handle */ void *paintcursor; /* wm handle */
} ImagePaintSettings; } ImagePaintSettings;

@ -351,6 +351,9 @@ static void rna_def_image_paint(BlenderRNA *brna)
prop= RNA_def_property(srna, "normal_angle", PROP_INT, PROP_UNSIGNED); prop= RNA_def_property(srna, "normal_angle", PROP_INT, PROP_UNSIGNED);
RNA_def_property_range(prop, 0, 90); 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"); 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) static void rna_def_particle_edit(BlenderRNA *brna)

@ -319,7 +319,7 @@ static void rna_Sequence_filepath_set(PointerRNA *ptr, const char *value)
Sequence *seq= (Sequence*)(ptr->data); Sequence *seq= (Sequence*)(ptr->data);
char dir[FILE_MAX], name[FILE_MAX]; 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->dir, dir, sizeof(seq->strip->dir));
BLI_strncpy(seq->strip->stripdata->name, name, sizeof(seq->strip->stripdata->name)); 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); Sequence *seq= (Sequence*)(ptr->data);
char dir[FILE_MAX], name[FILE_MAX]; 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->dir, dir, sizeof(seq->strip->dir));
BLI_strncpy(seq->strip->stripdata->name, name, sizeof(seq->strip->stripdata->name)); 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); StripElem *elem= (StripElem*)(ptr->data);
char name[FILE_MAX]; 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)); BLI_strncpy(elem->name, name, sizeof(elem->name));
} }

@ -474,7 +474,7 @@ static PyObject* gPyGetBlendFileList(PyObject*, PyObject* args)
BLI_convertstringcode(cpath, gp_GamePythonPath); BLI_convertstringcode(cpath, gp_GamePythonPath);
} else { } else {
/* Get the dir only */ /* Get the dir only */
BLI_split_dirfile_basic(gp_GamePythonPath, cpath, NULL); BLI_split_dirfile(gp_GamePythonPath, cpath, NULL);
} }
if((dp = opendir(cpath)) == NULL) { if((dp = opendir(cpath)) == NULL) {
@ -1786,7 +1786,7 @@ static void initPySysObjects__append(PyObject *sys_path, char *filename)
PyObject *item; PyObject *item;
char expanded[FILE_MAXDIR + FILE_MAXFILE]; 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_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 */ BLI_cleanup_file(gp_GamePythonPath, expanded); /* Dont use BLI_cleanup_dir because it adds a slash - BREAKS WIN32 ONLY */
item= PyUnicode_FromString(expanded); item= PyUnicode_FromString(expanded);