- opengl render anim exec function so python can render opengl animations without...
authorCampbell Barton <ideasman42@gmail.com>
Mon, 18 Jan 2010 14:40:06 +0000 (14:40 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 18 Jan 2010 14:40:06 +0000 (14:40 +0000)
- timeline rna camera access.
- new textblocks have tabs as spaces enabled by default since this is blenders default.

source/blender/blenkernel/intern/text.c
source/blender/editors/screen/screen_ops.c
source/blender/makesrna/intern/rna_timeline.c

index 50f7f6682f11ffe558bc3b9474caa800624f1631..e948ffdbaf2e421ea572e30e459ebae035f143da 100644 (file)
@@ -190,7 +190,7 @@ Text *add_empty_text(char *name)
     init_undo_text(ta);
 
        ta->nlines=1;
-       ta->flags= TXT_ISDIRTY | TXT_ISMEM;
+       ta->flags= TXT_ISDIRTY | TXT_ISMEM | TXT_TABSTOSPACES;
 
        ta->lines.first= ta->lines.last= NULL;
        ta->markers.first= ta->markers.last= NULL;
@@ -355,6 +355,8 @@ Text *add_text(char *file, const char *relpath)
        ta->markers.first= ta->markers.last= NULL;
        ta->curl= ta->sell= NULL;
        
+       ta->flags= TXT_TABSTOSPACES;
+       
        fseek(fp, 0L, SEEK_END);
        len= ftell(fp);
        fseek(fp, 0L, SEEK_SET);        
index 4461549aa28977e636cc89a6147222c31eaaf472..f837409ca4a9e2b96ac68e2ac350a085c5070091 100644 (file)
@@ -3260,7 +3260,7 @@ typedef struct OGLRender {
        bMovieHandle *mh;
        int cfrao, nfra;
        
-       wmTimer *timer;
+       wmTimer *timer; /* use to check if running modal or not (invoke'd or exec'd)*/
 } OGLRender;
 
 static void screen_opengl_render_apply(OGLRender *oglrender)
@@ -3378,8 +3378,8 @@ static void screen_opengl_render_end(bContext *C, OGLRender *oglrender)
                if(BKE_imtype_is_movie(scene->r.imtype))
                        oglrender->mh->end_movie();
        }
-       
-       if(oglrender->timer) {
+
+       if(oglrender->timer) { /* exec will not have a timer */
                scene->r.cfra= oglrender->cfrao;
                scene_update_for_newframe(scene, scene->lay);
                
@@ -3401,7 +3401,32 @@ static int screen_opengl_render_cancel(bContext *C, wmOperator *op)
        return OPERATOR_CANCELLED;
 }
 
-static int screen_opengl_render_modal(bContext *C, wmOperator *op, wmEvent *event)
+/* share between invoke and exec */
+static int screen_opengl_render_anim_initialize(bContext *C, wmOperator *op)
+{
+       /* initialize animation */
+       OGLRender *oglrender;
+       Scene *scene;
+
+       oglrender= op->customdata;
+       scene= oglrender->scene;
+
+       oglrender->reports= op->reports;
+       oglrender->mh= BKE_get_movie_handle(scene->r.imtype);
+       if(BKE_imtype_is_movie(scene->r.imtype)) {
+               if(!oglrender->mh->start_movie(scene, &scene->r, oglrender->sizex, oglrender->sizey, oglrender->reports)) {
+                       screen_opengl_render_end(C, oglrender);
+                       return 0;
+               }
+       }
+
+       oglrender->cfrao= scene->r.cfra;
+       oglrender->nfra= SFRA;
+       scene->r.cfra= SFRA;
+
+       return 1;
+}
+static int screen_opengl_render_anim_step(bContext *C, wmOperator *op)
 {
        OGLRender *oglrender= op->customdata;
        Scene *scene= oglrender->scene;
@@ -3410,32 +3435,18 @@ static int screen_opengl_render_modal(bContext *C, wmOperator *op, wmEvent *even
        char name[FILE_MAXDIR+FILE_MAXFILE];
        unsigned int lay;
        int ok= 0;
-       
-       switch(event->type) {
-               case ESCKEY:
-                       /* cancel */
-                       screen_opengl_render_end(C, op->customdata);
-                       return OPERATOR_FINISHED;
-               case TIMER:
-                       /* render frame? */
-                       if(oglrender->timer == event->customdata)
-                               break;
-               default:
-                       /* nothing to do */
-                       return OPERATOR_RUNNING_MODAL;
-       }
-       
+
        /* go to next frame */
        while(CFRA<oglrender->nfra) {
                if(scene->lay & 0xFF000000)
                        lay= scene->lay & 0xFF000000;
                else
                        lay= scene->lay;
-               
+
                scene_update_for_newframe(scene, lay);
                CFRA++;
        }
-       
+
        scene_update_for_newframe(scene, scene->lay);
 
        if(oglrender->rv3d->persp==RV3D_CAMOB && oglrender->v3d->camera && oglrender->v3d->scenelock) {
@@ -3446,7 +3457,7 @@ static int screen_opengl_render_modal(bContext *C, wmOperator *op, wmEvent *even
                if(camera)
                        oglrender->v3d->camera= scene->camera= camera;
        }
-
+       
        /* render into offscreen buffer */
        screen_opengl_render_apply(oglrender);
        
@@ -3477,11 +3488,42 @@ static int screen_opengl_render_modal(bContext *C, wmOperator *op, wmEvent *even
        oglrender->nfra += scene->r.frame_step;
        scene->r.cfra++;
        
-       WM_event_add_notifier(C, NC_SCENE|ND_RENDER_RESULT, oglrender->scene);
-       
        /* stop at the end or on error */
        if(scene->r.cfra > EFRA || !ok) {
                screen_opengl_render_end(C, op->customdata);
+               return 0;
+       }
+
+       return 1;
+}
+
+
+static int screen_opengl_render_modal(bContext *C, wmOperator *op, wmEvent *event)
+{
+       OGLRender *oglrender= op->customdata;
+
+       int ret;
+
+       switch(event->type) {
+               case ESCKEY:
+                       /* cancel */
+                       screen_opengl_render_end(C, op->customdata);
+                       return OPERATOR_FINISHED;
+               case TIMER:
+                       /* render frame? */
+                       if(oglrender->timer == event->customdata)
+                               break;
+               default:
+                       /* nothing to do */
+                       return OPERATOR_RUNNING_MODAL;
+       }
+
+       ret= screen_opengl_render_anim_step(C, op);
+
+       WM_event_add_notifier(C, NC_SCENE|ND_RENDER_RESULT, oglrender->scene);
+       
+       /* stop at the end or on error */
+       if(ret == 0) {
                return OPERATOR_FINISHED;
        }
        
@@ -3504,35 +3546,53 @@ static int screen_opengl_render_invoke(bContext *C, wmOperator *op, wmEvent *eve
                return OPERATOR_FINISHED;
        }
        else {
-               /* initialize animation */
-               OGLRender *oglrender;
-               Scene *scene;
-               
-               oglrender= op->customdata;
-               scene= oglrender->scene;
-               
-               oglrender->reports= op->reports;
-               oglrender->mh= BKE_get_movie_handle(scene->r.imtype);
-               if(BKE_imtype_is_movie(scene->r.imtype)) {
-                       if(!oglrender->mh->start_movie(scene, &scene->r, oglrender->sizex, oglrender->sizey, oglrender->reports)) {
-                               screen_opengl_render_end(C, oglrender);
-                               return OPERATOR_CANCELLED;
-                       }
-               }
-               
-               oglrender->cfrao= scene->r.cfra;
-               oglrender->nfra= SFRA;
-               scene->r.cfra= SFRA;
-               
+               OGLRender *oglrender= op->customdata;
+
+               if(!screen_opengl_render_anim_initialize(C, op))
+                       return OPERATOR_CANCELLED;
+
+               screen_set_image_output(C, event->x, event->y);
+
                WM_event_add_modal_handler(C, op);
                oglrender->timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f);
-               
-               screen_set_image_output(C, event->x, event->y);
-               
+
                return OPERATOR_RUNNING_MODAL;
        }
 }
 
+/* executes blocking render */
+static int screen_opengl_render_exec(bContext *C, wmOperator *op)
+{
+       int anim= RNA_boolean_get(op->ptr, "animation");
+
+       if(!screen_opengl_render_init(C, op))
+               return OPERATOR_CANCELLED;
+
+       if(!anim) { /* same as invoke */
+               /* render image */
+               screen_opengl_render_apply(op->customdata);
+               screen_opengl_render_end(C, op->customdata);
+
+               return OPERATOR_FINISHED;
+       }
+       else {
+               int ret= 1;
+
+               if(!screen_opengl_render_anim_initialize(C, op))
+                       return OPERATOR_CANCELLED;
+
+               while(ret) {
+                       ret= screen_opengl_render_anim_step(C, op);
+               }
+       }
+
+       // no redraw needed, we leave state as we entered it
+//     ED_update_for_newframe(C, 1);
+       WM_event_add_notifier(C, NC_SCENE|ND_RENDER_RESULT, CTX_data_scene(C));
+
+       return OPERATOR_FINISHED;
+}
+
 static void SCREEN_OT_opengl_render(wmOperatorType *ot)
 {
        /* identifiers */
@@ -3542,6 +3602,7 @@ static void SCREEN_OT_opengl_render(wmOperatorType *ot)
        
        /* api callbacks */
        ot->invoke= screen_opengl_render_invoke;
+       ot->exec= screen_opengl_render_exec; /* blocking */
        ot->modal= screen_opengl_render_modal;
        ot->cancel= screen_opengl_render_cancel;
        
index 5e20fca15f044a0e4a86877892b49cdd80002243..26021687f0ded1ad96c20d44c49365fc89bc04ea 100644 (file)
@@ -51,6 +51,13 @@ static void rna_def_timeline_marker(BlenderRNA *brna)
 
        prop= RNA_def_property(srna, "frame", PROP_INT, PROP_TIME);
        RNA_def_property_ui_text(prop, "Frame", "The frame on which the timeline marker appears.");
+
+#ifdef DURIAN_CAMERA_SWITCH
+       prop= RNA_def_property(srna, "camera", PROP_POINTER, PROP_NONE);
+       RNA_def_property_struct_type(prop, "Object");
+       RNA_def_property_flag(prop, PROP_EDITABLE|PROP_ID_SELF_CHECK);
+       RNA_def_property_ui_text(prop, "Camera", "Camera this timeline sets to active.");
+#endif
 }
 
 void RNA_def_timeline_marker(BlenderRNA *brna)