/* * Do actual bake operation. Loop through to-be-baked frames. * Returns 0 on failure. */ static void dynamicPaint_bakeImageSequence(DynamicPaintBakeJob *job) { DynamicPaintSurface *surface = job->surface; Object *cObject = job->ob; DynamicPaintCanvasSettings *canvas = surface->canvas; Scene *scene = job->scene; int frame = 1, orig_frame; int frames; frames = surface->end_frame - surface->start_frame + 1; if (frames <= 0) { BLI_strncpy(canvas->error, N_("No frames to bake"), sizeof(canvas->error)); return; } /* Show progress bar. */ *(job->do_update) = true; /* Set frame to start point (also inits modifier data) */ frame = surface->start_frame; orig_frame = scene->r.cfra; scene->r.cfra = (int)frame; ED_update_for_newframe(job->bmain, scene, 1); /* Init surface */ if (!dynamicPaint_createUVSurface(scene, surface, job->progress, job->do_update)) { job->success = 0; return; } /* Loop through selected frames */ for (frame = surface->start_frame; frame <= surface->end_frame; frame++) { /* The first 10% are for createUVSurface... */ const float progress = 0.1f + 0.9f * (frame - surface->start_frame) / (float)frames; surface->current_frame = frame; /* If user requested stop, quit baking */ if (G.is_break) { job->success = 0; return; } /* Update progress bar */ *(job->do_update) = true; *(job->progress) = progress; /* calculate a frame */ scene->r.cfra = (int)frame; ED_update_for_newframe(job->bmain, scene, 1); if (!dynamicPaint_calculateFrame(surface, scene, cObject, frame)) { job->success = 0; return; } /* * Save output images */ { char filename[FILE_MAX]; /* primary output layer */ if (surface->flags & MOD_DPAINT_OUT1) { /* set filepath */ BLI_join_dirfile(filename, sizeof(filename), surface->image_output_path, surface->output_name); BLI_path_frame(filename, frame, 4); /* save image */ dynamicPaint_outputSurfaceImage(surface, filename, 0); } /* secondary output */ if (surface->flags & MOD_DPAINT_OUT2 && surface->type == MOD_DPAINT_SURFACE_T_PAINT) { /* set filepath */ BLI_join_dirfile(filename, sizeof(filename), surface->image_output_path, surface->output_name2); BLI_path_frame(filename, frame, 4); /* save image */ dynamicPaint_outputSurfaceImage(surface, filename, 1); } } } scene->r.cfra = orig_frame; }
/* * Do actual bake operation. Loop through to-be-baked frames. * Returns 0 on failure. */ static int dynamicPaint_bakeImageSequence(bContext *C, DynamicPaintSurface *surface, Object *cObject) { DynamicPaintCanvasSettings *canvas = surface->canvas; Scene *scene = CTX_data_scene(C); wmWindow *win = CTX_wm_window(C); int frame = 1; int frames; frames = surface->end_frame - surface->start_frame + 1; if (frames <= 0) { BLI_strncpy(canvas->error, N_("No frames to bake"), sizeof(canvas->error)); return 0; } /* Set frame to start point (also inits modifier data) */ frame = surface->start_frame; scene->r.cfra = (int)frame; ED_update_for_newframe(CTX_data_main(C), scene, 1); /* Init surface */ if (!dynamicPaint_createUVSurface(scene, surface)) return 0; /* Loop through selected frames */ for (frame = surface->start_frame; frame <= surface->end_frame; frame++) { float progress = (frame - surface->start_frame) / (float)frames * 100; surface->current_frame = frame; /* If user requested stop (esc), quit baking */ if (blender_test_break()) return 0; /* Update progress bar cursor */ if (!G.background) { WM_cursor_time(win, (int)progress); } /* calculate a frame */ scene->r.cfra = (int)frame; ED_update_for_newframe(CTX_data_main(C), scene, 1); if (!dynamicPaint_calculateFrame(surface, scene, cObject, frame)) return 0; /* * Save output images */ { char filename[FILE_MAX]; /* primary output layer */ if (surface->flags & MOD_DPAINT_OUT1) { /* set filepath */ BLI_join_dirfile(filename, sizeof(filename), surface->image_output_path, surface->output_name); BLI_path_frame(filename, frame, 4); /* save image */ dynamicPaint_outputSurfaceImage(surface, filename, 0); } /* secondary output */ if (surface->flags & MOD_DPAINT_OUT2 && surface->type == MOD_DPAINT_SURFACE_T_PAINT) { /* set filepath */ BLI_join_dirfile(filename, sizeof(filename), surface->image_output_path, surface->output_name2); BLI_path_frame(filename, frame, 4); /* save image */ dynamicPaint_outputSurfaceImage(surface, filename, 1); } } } return 1; }