2011-09-05 16:04:15 +00:00
|
|
|
/*
|
|
|
|
* ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2013-09-12 03:02:50 +00:00
|
|
|
/** \file blender/editors/physics/dynamicpaint_ops.c
|
|
|
|
* \ingroup edphys
|
|
|
|
*/
|
|
|
|
|
2011-10-13 20:00:22 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2011-10-22 16:16:14 +00:00
|
|
|
#include "BLI_string.h"
|
2011-11-10 12:28:26 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2011-10-13 20:00:22 +00:00
|
|
|
|
2012-10-26 17:32:50 +00:00
|
|
|
#include "BLF_translation.h"
|
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
#include "DNA_dynamicpaint_types.h"
|
|
|
|
#include "DNA_modifier_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
2011-10-13 20:00:22 +00:00
|
|
|
#include "BKE_blender.h"
|
2011-09-05 16:04:15 +00:00
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_deform.h"
|
2014-11-18 23:52:17 +01:00
|
|
|
#include "BKE_object_deform.h"
|
2011-09-05 16:04:15 +00:00
|
|
|
#include "BKE_depsgraph.h"
|
|
|
|
#include "BKE_dynamicpaint.h"
|
2011-10-13 20:00:22 +00:00
|
|
|
#include "BKE_global.h"
|
2011-09-05 16:04:15 +00:00
|
|
|
#include "BKE_modifier.h"
|
2011-10-13 20:00:22 +00:00
|
|
|
#include "BKE_report.h"
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
#include "ED_mesh.h"
|
|
|
|
#include "ED_screen.h"
|
2012-01-02 17:15:24 +00:00
|
|
|
#include "ED_object.h"
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
|
|
|
#include "RNA_enum_types.h"
|
|
|
|
|
2011-10-13 20:00:22 +00:00
|
|
|
#include "PIL_time.h"
|
|
|
|
|
2011-09-05 16:04:15 +00:00
|
|
|
#include "WM_types.h"
|
|
|
|
#include "WM_api.h"
|
|
|
|
|
2011-11-14 16:05:44 +00:00
|
|
|
#include "physics_intern.h" /* own include */
|
|
|
|
|
2011-11-10 12:28:26 +00:00
|
|
|
static int surface_slot_add_exec(bContext *C, wmOperator *UNUSED(op))
|
2011-09-05 16:04:15 +00:00
|
|
|
{
|
2011-11-14 16:05:44 +00:00
|
|
|
DynamicPaintModifierData *pmd = NULL;
|
2012-01-02 17:15:24 +00:00
|
|
|
Object *cObject = ED_object_context(C);
|
2011-10-28 14:46:09 +00:00
|
|
|
DynamicPaintCanvasSettings *canvas;
|
2011-09-05 16:04:15 +00:00
|
|
|
DynamicPaintSurface *surface;
|
|
|
|
|
|
|
|
/* Make sure we're dealing with a canvas */
|
|
|
|
pmd = (DynamicPaintModifierData *)modifiers_findByType(cObject, eModifierType_DynamicPaint);
|
2013-03-25 08:29:06 +00:00
|
|
|
if (!pmd || !pmd->canvas)
|
|
|
|
return OPERATOR_CANCELLED;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
2011-10-28 14:46:09 +00:00
|
|
|
canvas = pmd->canvas;
|
|
|
|
surface = dynamicPaint_createNewSurface(canvas, CTX_data_scene(C));
|
2011-09-05 16:04:15 +00:00
|
|
|
|
2013-03-25 08:29:06 +00:00
|
|
|
if (!surface)
|
|
|
|
return OPERATOR_CANCELLED;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
/* set preview for this surface only and set active */
|
2011-10-28 14:46:09 +00:00
|
|
|
canvas->active_sur = 0;
|
2012-10-10 23:44:07 +00:00
|
|
|
for (surface = surface->prev; surface; surface = surface->prev) {
|
|
|
|
surface->flags &= ~MOD_DPAINT_PREVIEW;
|
|
|
|
canvas->active_sur++;
|
2011-09-05 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add surface slot */
|
|
|
|
void DPAINT_OT_surface_slot_add(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Add Surface Slot";
|
|
|
|
ot->idname = "DPAINT_OT_surface_slot_add";
|
|
|
|
ot->description = "Add a new Dynamic Paint surface slot";
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = surface_slot_add_exec;
|
|
|
|
ot->poll = ED_operator_object_active_editable;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-10-10 23:44:07 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-09-05 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
2011-11-10 12:28:26 +00:00
|
|
|
static int surface_slot_remove_exec(bContext *C, wmOperator *UNUSED(op))
|
2011-09-05 16:04:15 +00:00
|
|
|
{
|
2011-11-14 16:05:44 +00:00
|
|
|
DynamicPaintModifierData *pmd = NULL;
|
2012-10-10 23:44:07 +00:00
|
|
|
Object *obj_ctx = ED_object_context(C);
|
2011-10-28 14:46:09 +00:00
|
|
|
DynamicPaintCanvasSettings *canvas;
|
2011-09-05 16:04:15 +00:00
|
|
|
DynamicPaintSurface *surface;
|
2012-10-10 23:44:07 +00:00
|
|
|
int id = 0;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
/* Make sure we're dealing with a canvas */
|
2012-10-10 23:44:07 +00:00
|
|
|
pmd = (DynamicPaintModifierData *)modifiers_findByType(obj_ctx, eModifierType_DynamicPaint);
|
2011-10-28 14:46:09 +00:00
|
|
|
if (!pmd || !pmd->canvas) return OPERATOR_CANCELLED;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
2011-10-28 14:46:09 +00:00
|
|
|
canvas = pmd->canvas;
|
|
|
|
surface = canvas->surfaces.first;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
/* find active surface and remove it */
|
2012-10-10 23:44:07 +00:00
|
|
|
for (; surface; surface = surface->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (id == canvas->active_sur) {
|
2011-10-28 14:46:09 +00:00
|
|
|
canvas->active_sur -= 1;
|
2011-09-05 16:04:15 +00:00
|
|
|
dynamicPaint_freeSurface(surface);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
id++;
|
|
|
|
}
|
|
|
|
|
2011-10-28 14:46:09 +00:00
|
|
|
dynamicPaint_resetPreview(canvas);
|
2012-10-10 23:44:07 +00:00
|
|
|
DAG_id_tag_update(&obj_ctx->id, OB_RECALC_DATA);
|
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, obj_ctx);
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove surface slot */
|
|
|
|
void DPAINT_OT_surface_slot_remove(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Remove Surface Slot";
|
|
|
|
ot->idname = "DPAINT_OT_surface_slot_remove";
|
|
|
|
ot->description = "Remove the selected surface slot";
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = surface_slot_remove_exec;
|
|
|
|
ot->poll = ED_operator_object_active_editable;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-10-10 23:44:07 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-09-05 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int type_toggle_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
|
2012-01-02 17:15:24 +00:00
|
|
|
Object *cObject = ED_object_context(C);
|
2011-09-05 16:04:15 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)modifiers_findByType(cObject, eModifierType_DynamicPaint);
|
2012-10-10 23:44:07 +00:00
|
|
|
int type = RNA_enum_get(op->ptr, "type");
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
if (!pmd) return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
/* if type is already enabled, toggle it off */
|
|
|
|
if (type == MOD_DYNAMICPAINT_TYPE_CANVAS && pmd->canvas) {
|
|
|
|
dynamicPaint_freeCanvas(pmd);
|
|
|
|
}
|
|
|
|
else if (type == MOD_DYNAMICPAINT_TYPE_BRUSH && pmd->brush) {
|
|
|
|
dynamicPaint_freeBrush(pmd);
|
|
|
|
}
|
|
|
|
/* else create a new type */
|
|
|
|
else {
|
|
|
|
if (!dynamicPaint_createType(pmd, type, scene))
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2012-03-01 12:20:18 +00:00
|
|
|
/* update dependency */
|
2011-09-05 16:04:15 +00:00
|
|
|
DAG_id_tag_update(&cObject->id, OB_RECALC_DATA);
|
2013-02-21 19:33:04 +00:00
|
|
|
DAG_relations_tag_update(CTX_data_main(C));
|
2012-10-10 23:44:07 +00:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, cObject);
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DPAINT_OT_type_toggle(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Toggle Type Active";
|
|
|
|
ot->idname = "DPAINT_OT_type_toggle";
|
2011-11-14 19:13:52 +00:00
|
|
|
ot->description = "Toggle whether given type is active or not";
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = type_toggle_exec;
|
|
|
|
ot->poll = ED_operator_object_active_editable;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-10-10 23:44:07 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
/* properties */
|
2012-10-10 23:44:07 +00:00
|
|
|
prop = RNA_def_enum(ot->srna, "type", prop_dynamicpaint_type_items, MOD_DYNAMICPAINT_TYPE_CANVAS, "Type", "");
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->prop = prop;
|
2011-09-05 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int output_toggle_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2012-01-02 17:15:24 +00:00
|
|
|
Object *ob = ED_object_context(C);
|
2011-10-28 14:46:09 +00:00
|
|
|
DynamicPaintSurface *surface;
|
2011-09-05 16:04:15 +00:00
|
|
|
DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)modifiers_findByType(ob, eModifierType_DynamicPaint);
|
2012-10-10 23:44:07 +00:00
|
|
|
int output = RNA_enum_get(op->ptr, "output"); /* currently only 1/0 */
|
2011-09-05 16:04:15 +00:00
|
|
|
|
2011-10-28 14:46:09 +00:00
|
|
|
if (!pmd || !pmd->canvas) return OPERATOR_CANCELLED;
|
|
|
|
surface = get_activeSurface(pmd->canvas);
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
/* if type is already enabled, toggle it off */
|
2011-10-28 14:46:09 +00:00
|
|
|
if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) {
|
2011-11-14 06:46:07 +00:00
|
|
|
int exists = dynamicPaint_outputLayerExists(surface, ob, output);
|
|
|
|
const char *name;
|
2011-10-28 14:46:09 +00:00
|
|
|
|
2011-11-14 06:46:07 +00:00
|
|
|
if (output == 0)
|
2011-10-28 14:46:09 +00:00
|
|
|
name = surface->output_name;
|
2011-11-14 06:46:07 +00:00
|
|
|
else
|
2011-10-28 14:46:09 +00:00
|
|
|
name = surface->output_name2;
|
|
|
|
|
|
|
|
/* Vertex Color Layer */
|
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
|
|
|
|
if (!exists)
|
2013-03-21 20:54:48 +00:00
|
|
|
ED_mesh_color_add(ob->data, name, true);
|
2011-10-28 14:46:09 +00:00
|
|
|
else
|
2013-03-21 20:15:39 +00:00
|
|
|
ED_mesh_color_remove_named(ob->data, name);
|
2011-10-28 14:46:09 +00:00
|
|
|
}
|
|
|
|
/* Vertex Weight Layer */
|
|
|
|
else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) {
|
2011-11-14 06:46:07 +00:00
|
|
|
if (!exists) {
|
2014-11-18 23:52:17 +01:00
|
|
|
BKE_object_defgroup_add_name(ob, name);
|
2011-11-14 06:46:07 +00:00
|
|
|
}
|
2011-10-28 14:46:09 +00:00
|
|
|
else {
|
|
|
|
bDeformGroup *defgroup = defgroup_find_name(ob, name);
|
2014-11-18 23:52:17 +01:00
|
|
|
if (defgroup) BKE_object_defgroup_remove(ob, defgroup);
|
2011-09-05 16:04:15 +00:00
|
|
|
}
|
2011-10-28 14:46:09 +00:00
|
|
|
}
|
2011-09-05 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DPAINT_OT_output_toggle(wmOperatorType *ot)
|
|
|
|
{
|
2011-11-14 06:46:07 +00:00
|
|
|
static EnumPropertyItem prop_output_toggle_types[] = {
|
|
|
|
{0, "A", 0, "Output A", ""},
|
|
|
|
{1, "B", 0, "Output B", ""},
|
|
|
|
{0, NULL, 0, NULL, NULL}
|
|
|
|
};
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Toggle Output Layer";
|
|
|
|
ot->idname = "DPAINT_OT_output_toggle";
|
2011-11-14 19:13:52 +00:00
|
|
|
ot->description = "Add or remove Dynamic Paint output data layer";
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = output_toggle_exec;
|
|
|
|
ot->poll = ED_operator_object_active_editable;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-10-10 23:44:07 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-09-05 16:04:15 +00:00
|
|
|
|
|
|
|
/* properties */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->prop = RNA_def_enum(ot->srna, "output", prop_output_toggle_types, 0, "Output Toggle", "");
|
2011-09-05 16:04:15 +00:00
|
|
|
}
|
2011-10-13 20:00:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***************************** Image Sequence Baking ******************************/
|
|
|
|
|
|
|
|
/*
|
2012-03-03 16:31:46 +00:00
|
|
|
* Do actual bake operation. Loop through to-be-baked frames.
|
2012-03-04 04:35:12 +00:00
|
|
|
* Returns 0 on failure.
|
2012-03-03 16:31:46 +00:00
|
|
|
*/
|
2011-10-13 20:00:22 +00:00
|
|
|
static int dynamicPaint_bakeImageSequence(bContext *C, DynamicPaintSurface *surface, Object *cObject)
|
|
|
|
{
|
|
|
|
DynamicPaintCanvasSettings *canvas = surface->canvas;
|
2012-10-10 23:44:07 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2011-10-13 20:00:22 +00:00
|
|
|
wmWindow *win = CTX_wm_window(C);
|
|
|
|
int frame = 1;
|
|
|
|
int frames;
|
|
|
|
|
|
|
|
frames = surface->end_frame - surface->start_frame + 1;
|
2012-10-26 17:32:50 +00:00
|
|
|
if (frames <= 0) {
|
|
|
|
BLI_strncpy(canvas->error, N_("No frames to bake"), sizeof(canvas->error));
|
|
|
|
return 0;
|
|
|
|
}
|
2011-10-13 20:00:22 +00:00
|
|
|
|
2011-10-28 14:46:09 +00:00
|
|
|
/* Set frame to start point (also inits modifier data) */
|
2011-10-13 20:00:22 +00:00
|
|
|
frame = surface->start_frame;
|
|
|
|
scene->r.cfra = (int)frame;
|
2012-05-25 12:37:11 +00:00
|
|
|
ED_update_for_newframe(CTX_data_main(C), scene, 1);
|
2011-10-13 20:00:22 +00:00
|
|
|
|
|
|
|
/* Init surface */
|
Fix #36058: Displace Modifier errors using a baked Image and displace baking inconsistency between 2.67/2.68RC and previous versions
This was in fact really nasty bug, caused by multitex_nodes
function using global variable R (which is a copy of current
renderer). this variable is not initialized to anything
meaningful for until first rendering (preview or final)
happened.
Since multitex_nodes might be used outside of render pipeline,
made it so whether CM is on or off as an argument to functions
multitex_ext_safe and multitex_ext. Now multitex_nodes() is
only shall be used for stuff happening from render pipeline!
Also needed to make some changes to other places, so all the
usages of texture sampling knows for the fact whether CM is
on or off.
And one more change is related on behavior of dispalcement,
wave, warp, weightvg modifiers and smoke. They'll be always
using CM off since texture is used for influence, not for
color.
It's rather bigger patch, but it's mostly straightforward
changes, which we really need to be done.
Reviewed by Brecht, thanks!
2013-07-15 14:47:58 +00:00
|
|
|
if (!dynamicPaint_createUVSurface(scene, surface)) return 0;
|
2011-10-13 20:00:22 +00:00
|
|
|
|
2011-10-28 14:46:09 +00:00
|
|
|
/* Loop through selected frames */
|
2012-10-10 23:44:07 +00:00
|
|
|
for (frame = surface->start_frame; frame <= surface->end_frame; frame++) {
|
2011-10-13 20:00:22 +00:00
|
|
|
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 */
|
2013-02-11 15:48:43 +00:00
|
|
|
if (!G.background) {
|
|
|
|
WM_cursor_time(win, (int)progress);
|
|
|
|
}
|
2011-10-13 20:00:22 +00:00
|
|
|
|
|
|
|
/* calculate a frame */
|
|
|
|
scene->r.cfra = (int)frame;
|
2012-05-25 12:37:11 +00:00
|
|
|
ED_update_for_newframe(CTX_data_main(C), scene, 1);
|
2011-10-13 20:00:22 +00:00
|
|
|
if (!dynamicPaint_calculateFrame(surface, scene, cObject, frame)) return 0;
|
|
|
|
|
|
|
|
/*
|
2012-03-03 16:31:46 +00:00
|
|
|
* Save output images
|
|
|
|
*/
|
2011-10-13 20:00:22 +00:00
|
|
|
{
|
2011-10-28 14:46:09 +00:00
|
|
|
char filename[FILE_MAX];
|
|
|
|
|
|
|
|
/* primary output layer */
|
|
|
|
if (surface->flags & MOD_DPAINT_OUT1) {
|
|
|
|
/* set filepath */
|
2011-11-20 14:38:11 +00:00
|
|
|
BLI_join_dirfile(filename, sizeof(filename), surface->image_output_path, surface->output_name);
|
2011-10-28 14:46:09 +00:00
|
|
|
BLI_path_frame(filename, frame, 4);
|
2011-11-20 14:38:11 +00:00
|
|
|
|
2011-10-28 14:46:09 +00:00
|
|
|
/* save image */
|
|
|
|
dynamicPaint_outputSurfaceImage(surface, filename, 0);
|
2011-10-13 20:00:22 +00:00
|
|
|
}
|
2011-10-28 14:46:09 +00:00
|
|
|
/* secondary output */
|
|
|
|
if (surface->flags & MOD_DPAINT_OUT2 && surface->type == MOD_DPAINT_SURFACE_T_PAINT) {
|
|
|
|
/* set filepath */
|
2011-11-20 14:38:11 +00:00
|
|
|
BLI_join_dirfile(filename, sizeof(filename), surface->image_output_path, surface->output_name2);
|
2011-10-28 14:46:09 +00:00
|
|
|
BLI_path_frame(filename, frame, 4);
|
2011-11-20 14:38:11 +00:00
|
|
|
|
2011-10-28 14:46:09 +00:00
|
|
|
/* save image */
|
|
|
|
dynamicPaint_outputSurfaceImage(surface, filename, 1);
|
2011-10-13 20:00:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2011-11-14 16:05:44 +00:00
|
|
|
* Bake Dynamic Paint image sequence surface
|
|
|
|
*/
|
|
|
|
static int dynamicPaint_initBake(struct bContext *C, struct wmOperator *op)
|
2011-10-13 20:00:22 +00:00
|
|
|
{
|
2013-02-11 15:48:43 +00:00
|
|
|
wmWindow *win = CTX_wm_window(C);
|
2011-10-13 20:00:22 +00:00
|
|
|
DynamicPaintModifierData *pmd = NULL;
|
2011-10-22 16:16:14 +00:00
|
|
|
DynamicPaintCanvasSettings *canvas;
|
2012-01-02 17:15:24 +00:00
|
|
|
Object *ob = ED_object_context(C);
|
2011-10-13 20:00:22 +00:00
|
|
|
int status = 0;
|
|
|
|
double timer = PIL_check_seconds_timer();
|
|
|
|
DynamicPaintSurface *surface;
|
|
|
|
|
|
|
|
/*
|
2012-03-03 16:31:46 +00:00
|
|
|
* Get modifier data
|
|
|
|
*/
|
2011-10-13 20:00:22 +00:00
|
|
|
pmd = (DynamicPaintModifierData *)modifiers_findByType(ob, eModifierType_DynamicPaint);
|
|
|
|
if (!pmd) {
|
2012-10-16 07:53:10 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Bake failed: no Dynamic Paint modifier found");
|
2011-10-13 20:00:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure we're dealing with a canvas */
|
2011-10-22 16:16:14 +00:00
|
|
|
canvas = pmd->canvas;
|
|
|
|
if (!canvas) {
|
2012-10-16 07:53:10 +00:00
|
|
|
BKE_report(op->reports, RPT_ERROR, "Bake failed: invalid canvas");
|
2011-10-13 20:00:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-10-22 16:16:14 +00:00
|
|
|
surface = get_activeSurface(canvas);
|
2011-10-13 20:00:22 +00:00
|
|
|
|
|
|
|
/* Set state to baking and init surface */
|
2011-10-22 16:16:14 +00:00
|
|
|
canvas->error[0] = '\0';
|
|
|
|
canvas->flags |= MOD_DPAINT_BAKING;
|
2014-04-01 11:34:00 +11:00
|
|
|
G.is_break = false; /* reset blender_test_break*/
|
2011-10-13 20:00:22 +00:00
|
|
|
|
|
|
|
/* Bake Dynamic Paint */
|
|
|
|
status = dynamicPaint_bakeImageSequence(C, surface, ob);
|
|
|
|
/* Clear bake */
|
2011-10-28 14:46:09 +00:00
|
|
|
canvas->flags &= ~MOD_DPAINT_BAKING;
|
2013-02-11 15:48:43 +00:00
|
|
|
if (!G.background) {
|
2013-09-06 22:34:29 +00:00
|
|
|
WM_cursor_modal_restore(win);
|
2013-02-11 15:48:43 +00:00
|
|
|
}
|
2011-10-13 20:00:22 +00:00
|
|
|
dynamicPaint_freeSurfaceData(surface);
|
|
|
|
|
|
|
|
/* Bake was successful:
|
2012-03-03 16:31:46 +00:00
|
|
|
* Report for ended bake and how long it took */
|
2011-10-13 20:00:22 +00:00
|
|
|
if (status) {
|
|
|
|
/* Show bake info */
|
2015-06-30 14:47:31 +10:00
|
|
|
BKE_reportf(op->reports, RPT_INFO, "Bake complete! (%.2f)", PIL_check_seconds_timer() - timer);
|
2011-10-13 20:00:22 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-10-18 16:25:58 +00:00
|
|
|
if (strlen(canvas->error)) { /* If an error occurred */
|
2012-10-16 07:53:10 +00:00
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "Bake failed: %s", canvas->error);
|
2011-10-13 20:00:22 +00:00
|
|
|
}
|
2012-10-16 07:53:10 +00:00
|
|
|
else { /* User canceled the bake */
|
2012-10-18 16:25:58 +00:00
|
|
|
BKE_report(op->reports, RPT_WARNING, "Baking canceled!");
|
2011-10-13 20:00:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dynamicpaint_bake_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
/* Bake dynamic paint */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!dynamicPaint_initBake(C, op)) {
|
2011-10-13 20:00:22 +00:00
|
|
|
return OPERATOR_CANCELLED;}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DPAINT_OT_bake(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Dynamic Paint Bake";
|
|
|
|
ot->description = "Bake dynamic paint image sequence surface";
|
|
|
|
ot->idname = "DPAINT_OT_bake";
|
2011-10-13 20:00:22 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = dynamicpaint_bake_exec;
|
|
|
|
ot->poll = ED_operator_object_active_editable;
|
2011-11-10 12:28:26 +00:00
|
|
|
}
|