GPencil: Remove unneeded python for calling Bake Animation
The operator was using a secondary python operator to ask parameters before running, but this can be done in invoke. Differential Revision: https://developer.blender.org/D9330
This commit is contained in:
parent
390b28e338
commit
69a22afdb6
|
@ -48,7 +48,6 @@ _modules = [
|
|||
"uvcalc_lightmap",
|
||||
"vertexpaint_dirt",
|
||||
"view3d",
|
||||
"gpencil_mesh_bake",
|
||||
"wm",
|
||||
]
|
||||
|
||||
|
|
|
@ -1,163 +0,0 @@
|
|||
# ##### 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 #####
|
||||
|
||||
# <pep8-80 compliant>
|
||||
|
||||
import bpy
|
||||
from bpy.types import Operator
|
||||
from bpy.props import (
|
||||
IntProperty,
|
||||
FloatProperty,
|
||||
BoolProperty,
|
||||
EnumProperty,
|
||||
)
|
||||
|
||||
gp_object_items = []
|
||||
|
||||
|
||||
def my_objlist_callback(scene, context):
|
||||
gp_object_items.clear()
|
||||
gp_object_items.append(('*NEW', "New Object", ""))
|
||||
for o in context.scene.objects:
|
||||
if o.type == 'GPENCIL':
|
||||
gp_object_items.append((o.name, o.name, ""))
|
||||
|
||||
return gp_object_items
|
||||
|
||||
|
||||
class GPENCIL_OT_mesh_bake(Operator):
|
||||
"""Bake all mesh animation into grease pencil strokes"""
|
||||
bl_idname = "gpencil.mesh_bake"
|
||||
bl_label = "Bake Mesh to Grease Pencil"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
frame_start: IntProperty(
|
||||
name="Start Frame",
|
||||
description="Start frame for baking",
|
||||
min=0, max=300000,
|
||||
default=1,
|
||||
)
|
||||
frame_end: IntProperty(
|
||||
name="End Frame",
|
||||
description="End frame for baking",
|
||||
min=1, max=300000,
|
||||
default=250,
|
||||
)
|
||||
step: IntProperty(
|
||||
name="Frame Step",
|
||||
description="Frame Step",
|
||||
min=1, max=120,
|
||||
default=1,
|
||||
)
|
||||
thickness: IntProperty(
|
||||
name="Thickness",
|
||||
description="Thickness of the stroke lines",
|
||||
min=1, max=100,
|
||||
default=1,
|
||||
)
|
||||
angle: FloatProperty(
|
||||
name="Threshold Angle",
|
||||
description="Threshold to determine ends of the strokes",
|
||||
min=0,
|
||||
max=+3.141592,
|
||||
default=+1.22173, # 70 Degress
|
||||
subtype='ANGLE',
|
||||
)
|
||||
offset: FloatProperty(
|
||||
name="Stroke Offset",
|
||||
description="Offset strokes from fill",
|
||||
soft_min=0.0, soft_max=100.0,
|
||||
min=0.0, max=100.0,
|
||||
default=0.001,
|
||||
precision=3,
|
||||
step=1,
|
||||
subtype='DISTANCE',
|
||||
unit='LENGTH',
|
||||
)
|
||||
seams: BoolProperty(
|
||||
name="Only Seam Edges",
|
||||
description="Convert only seam edges",
|
||||
default=False,
|
||||
)
|
||||
faces: BoolProperty(
|
||||
name="Export Faces",
|
||||
description="Export faces as filled strokes",
|
||||
default=True,
|
||||
)
|
||||
only_selected: BoolProperty(
|
||||
name="Only Selected Keyframes",
|
||||
description="Convert only selected keyframes",
|
||||
default=False,
|
||||
)
|
||||
target: EnumProperty(
|
||||
name="Target Object",
|
||||
description="Grease Pencil Object",
|
||||
items=my_objlist_callback
|
||||
)
|
||||
frame_target: IntProperty(
|
||||
name="Target Frame",
|
||||
description="Destination frame for the baked animation",
|
||||
min=1, max=300000,
|
||||
default=1,
|
||||
)
|
||||
project_type: EnumProperty(
|
||||
name="Reproject Type",
|
||||
description="Type of projection",
|
||||
items=(
|
||||
("KEEP", "No Reproject", ""),
|
||||
("FRONT", "Front", "Reproject the strokes using the X-Z plane"),
|
||||
("SIDE", "Side", "Reproject the strokes using the Y-Z plane"),
|
||||
("TOP", "Top", "Reproject the strokes using the X-Y plane"),
|
||||
("VIEW", "View", "Reproject the strokes to current viewpoint"),
|
||||
("CURSOR", "Cursor", "Reproject the strokes using the orientation of 3D cursor")
|
||||
)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def poll(self, context):
|
||||
ob = context.active_object
|
||||
return ((ob is not None) and
|
||||
(ob.type in {'EMPTY', 'MESH'}) and
|
||||
(context.mode == 'OBJECT'))
|
||||
|
||||
def execute(self, context):
|
||||
bpy.ops.gpencil.bake_mesh_animation(
|
||||
frame_start=self.frame_start,
|
||||
frame_end=self.frame_end,
|
||||
step=self.step,
|
||||
angle=self.angle,
|
||||
thickness=self.thickness,
|
||||
seams=self.seams,
|
||||
faces=self.faces,
|
||||
only_selected=self.only_selected,
|
||||
offset=self.offset,
|
||||
target=self.target,
|
||||
frame_target=self.frame_target,
|
||||
project_type=self.project_type
|
||||
)
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
def invoke(self, context, _event):
|
||||
wm = context.window_manager
|
||||
return wm.invoke_props_dialog(self)
|
||||
|
||||
|
||||
classes = (
|
||||
GPENCIL_OT_mesh_bake,
|
||||
)
|
|
@ -2292,7 +2292,7 @@ class VIEW3D_MT_object_animation(Menu):
|
|||
layout.separator()
|
||||
|
||||
layout.operator("nla.bake", text="Bake Action...")
|
||||
layout.operator("gpencil.mesh_bake", text="Bake Mesh to Grease Pencil...")
|
||||
layout.operator("gpencil.bake_mesh_animation", text="Bake Mesh to Grease Pencil...")
|
||||
|
||||
|
||||
class VIEW3D_MT_object_rigid_body(Menu):
|
||||
|
|
|
@ -221,27 +221,17 @@ static int gpencil_bake_mesh_animation_exec(bContext *C, wmOperator *op)
|
|||
const bool only_selected = RNA_boolean_get(op->ptr, "only_selected");
|
||||
const float offset = RNA_float_get(op->ptr, "offset");
|
||||
const int frame_offset = RNA_int_get(op->ptr, "frame_target") - frame_start;
|
||||
char target[64];
|
||||
RNA_string_get(op->ptr, "target", target);
|
||||
const int project_type = RNA_enum_get(op->ptr, "project_type");
|
||||
ob_gpencil = (Object *)RNA_pointer_get(op->ptr, "target").data;
|
||||
|
||||
/* Create a new grease pencil object in origin. */
|
||||
bool newob = false;
|
||||
if (STREQ(target, "*NEW")) {
|
||||
if (ob_gpencil == NULL) {
|
||||
ushort local_view_bits = (v3d && v3d->localvd) ? v3d->local_view_uuid : 0;
|
||||
const float loc[3] = {0.0f, 0.0f, 0.0f};
|
||||
ob_gpencil = ED_gpencil_add_object(C, loc, local_view_bits);
|
||||
newob = true;
|
||||
}
|
||||
else {
|
||||
ob_gpencil = BLI_findstring(&bmain->objects, target, offsetof(ID, name) + 2);
|
||||
}
|
||||
|
||||
if ((ob_gpencil == NULL) || (ob_gpencil->type != OB_GPENCIL)) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Target grease pencil object not valid");
|
||||
gpencil_bake_free_ob_list(&ob_selected_list);
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
bGPdata *gpd = (bGPdata *)ob_gpencil->data;
|
||||
gpd->draw_mode = (project_type == GP_REPROJECT_KEEP) ? GP_DRAWMODE_3D : GP_DRAWMODE_2D;
|
||||
|
@ -384,6 +374,19 @@ static int gpencil_bake_mesh_animation_exec(bContext *C, wmOperator *op)
|
|||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
static int gpencil_bake_mesh_animation_invoke(bContext *C,
|
||||
wmOperator *op,
|
||||
const wmEvent *UNUSED(event))
|
||||
{
|
||||
/* Show popup dialog to allow editing. */
|
||||
/* FIXME: hard-coded dimensions here are just arbitrary. */
|
||||
return WM_operator_props_dialog_popup(C, op, 250);
|
||||
}
|
||||
|
||||
static bool rna_GPencil_object_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
|
||||
{
|
||||
return ((Object *)value.owner_id)->type == OB_GPENCIL;
|
||||
}
|
||||
void GPENCIL_OT_bake_mesh_animation(wmOperatorType *ot)
|
||||
{
|
||||
static const EnumPropertyItem reproject_type[] = {
|
||||
|
@ -413,6 +416,7 @@ void GPENCIL_OT_bake_mesh_animation(wmOperatorType *ot)
|
|||
ot->description = "Bake Mesh Animation to Grease Pencil strokes";
|
||||
|
||||
/* callbacks */
|
||||
ot->invoke = gpencil_bake_mesh_animation_invoke;
|
||||
ot->exec = gpencil_bake_mesh_animation_exec;
|
||||
ot->poll = gpencil_bake_mesh_animation_poll;
|
||||
|
||||
|
@ -420,7 +424,15 @@ void GPENCIL_OT_bake_mesh_animation(wmOperatorType *ot)
|
|||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
|
||||
/* properties */
|
||||
ot->prop = RNA_def_int(
|
||||
ot->prop = RNA_def_pointer_runtime(ot->srna,
|
||||
"target",
|
||||
&RNA_Object,
|
||||
"Target Object",
|
||||
"Target grease pencil object. Leave empty for new object");
|
||||
RNA_def_property_poll_runtime(ot->prop, rna_GPencil_object_poll);
|
||||
RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE);
|
||||
|
||||
prop = RNA_def_int(
|
||||
ot->srna, "frame_start", 1, 1, 100000, "Start Frame", "The start frame", 1, 100000);
|
||||
|
||||
prop = RNA_def_int(
|
||||
|
@ -449,12 +461,6 @@ void GPENCIL_OT_bake_mesh_animation(wmOperatorType *ot)
|
|||
RNA_def_float_distance(
|
||||
ot->srna, "offset", 0.001f, 0.0, 100.0, "Offset", "Offset strokes from fill", 0.0, 100.00);
|
||||
RNA_def_int(ot->srna, "frame_target", 1, 1, 100000, "Frame Target", "", 1, 100000);
|
||||
RNA_def_string(ot->srna,
|
||||
"target",
|
||||
"*NEW",
|
||||
64,
|
||||
"Target Object",
|
||||
"Target grease pencil object name. Leave empty for new object");
|
||||
|
||||
RNA_def_enum(ot->srna, "project_type", reproject_type, GP_REPROJECT_VIEW, "Projection Type", "");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue