[Bf-blender-cvs] [118fde42f8e] greasepencil-object: GPencil: Make Bake Mesh to use a pop panel to define parameters

Antonio Vazquez noreply at git.blender.org
Thu Apr 2 12:05:05 CEST 2020


Commit: 118fde42f8ecd13ca175f63dd2ec328ebc678695
Author: Antonio Vazquez
Date:   Thu Apr 2 12:04:56 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB118fde42f8ecd13ca175f63dd2ec328ebc678695

GPencil: Make Bake Mesh to use a pop panel to define parameters

Run directly the operator could freeze the UI.

===================================================================

M	release/scripts/startup/bl_operators/__init__.py
A	release/scripts/startup/bl_operators/gpencil_mesh_bake.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/editors/gpencil/gpencil_mesh.c

===================================================================

diff --git a/release/scripts/startup/bl_operators/__init__.py b/release/scripts/startup/bl_operators/__init__.py
index 5af2bd22222..bca9bce8fea 100644
--- a/release/scripts/startup/bl_operators/__init__.py
+++ b/release/scripts/startup/bl_operators/__init__.py
@@ -48,6 +48,7 @@ _modules = [
     "uvcalc_smart_project",
     "vertexpaint_dirt",
     "view3d",
+    "gpencil_mesh_bake",
     "wm",
 ]
 
diff --git a/release/scripts/startup/bl_operators/gpencil_mesh_bake.py b/release/scripts/startup/bl_operators/gpencil_mesh_bake.py
new file mode 100644
index 00000000000..f6f29110e29
--- /dev/null
+++ b/release/scripts/startup/bl_operators/gpencil_mesh_bake.py
@@ -0,0 +1,114 @@
+# ##### 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
+)
+
+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,
+    )
+    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,
+    )
+    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="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',
+    )
+
+    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,
+            offset=self.offset
+        )
+
+        return {'FINISHED'}
+
+    def invoke(self, context, _event):
+        scene = context.scene
+        self.frame_start = scene.frame_start
+        self.frame_end = scene.frame_end
+
+        wm = context.window_manager
+        return wm.invoke_props_dialog(self)
+
+
+classes = (
+    GPENCIL_OT_mesh_bake,
+)
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 6d0fac6e5b3..3546af01531 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -2370,7 +2370,7 @@ class VIEW3D_MT_object_animation(Menu):
         layout.separator()
 
         layout.operator("nla.bake", text="Bake Action...")
-        layout.operator("gpencil.bake_mesh_animation", text="Bake Mesh to Grease Pencil")
+        layout.operator("gpencil.mesh_bake", text="Bake Mesh to Grease Pencil...")
 
 
 class VIEW3D_MT_object_rigid_body(Menu):
diff --git a/source/blender/editors/gpencil/gpencil_mesh.c b/source/blender/editors/gpencil/gpencil_mesh.c
index 8437eff210d..39ffd528266 100644
--- a/source/blender/editors/gpencil/gpencil_mesh.c
+++ b/source/blender/editors/gpencil/gpencil_mesh.c
@@ -52,16 +52,16 @@
 
 #include "ED_gpencil.h"
 
-/* Check end_frame is always > start frame! */
-static void gp_bake_set_end_frame(struct Main *UNUSED(main),
+/* Check frame_end is always > start frame! */
+static void gp_bake_set_frame_end(struct Main *UNUSED(main),
                                   struct Scene *UNUSED(scene),
                                   struct PointerRNA *ptr)
 {
-  int start_frame = RNA_int_get(ptr, "start_frame");
-  int end_frame = RNA_int_get(ptr, "end_frame");
+  int frame_start = RNA_int_get(ptr, "frame_start");
+  int frame_end = RNA_int_get(ptr, "frame_end");
 
-  if (end_frame <= start_frame) {
-    RNA_int_set(ptr, "end_frame", start_frame + 1);
+  if (frame_end <= frame_start) {
+    RNA_int_set(ptr, "frame_end", frame_start + 1);
   }
 }
 
@@ -99,13 +99,13 @@ static int gp_bake_mesh_animation_exec(bContext *C, wmOperator *op)
   /* Grab all relevant settings. */
   const int step = RNA_int_get(op->ptr, "step");
 
-  const int start_frame = (scene->r.sfra > RNA_int_get(op->ptr, "start_frame")) ?
+  const int frame_start = (scene->r.sfra > RNA_int_get(op->ptr, "frame_start")) ?
                               scene->r.sfra :
-                              RNA_int_get(op->ptr, "start_frame");
+                              RNA_int_get(op->ptr, "frame_start");
 
-  const int end_frame = (scene->r.efra < RNA_int_get(op->ptr, "end_frame")) ?
+  const int frame_end = (scene->r.efra < RNA_int_get(op->ptr, "frame_end")) ?
                             scene->r.efra :
-                            RNA_int_get(op->ptr, "end_frame");
+                            RNA_int_get(op->ptr, "frame_end");
 
   const float angle = RNA_float_get(op->ptr, "angle");
   const int thickness = RNA_int_get(op->ptr, "thickness");
@@ -121,10 +121,10 @@ static int gp_bake_mesh_animation_exec(bContext *C, wmOperator *op)
   /* Loop all frame range. */
   int oldframe = (int)DEG_get_ctime(depsgraph);
   int key = -1;
-  for (int i = start_frame; i < end_frame + 1; i++) {
+  for (int i = frame_start; i < frame_end + 1; i++) {
     key++;
     /* Jump if not step limit but include last frame always. */
-    if ((key % step != 0) && (i != end_frame)) {
+    if ((key % step != 0) && (i != frame_end)) {
       continue;
     }
 
@@ -194,11 +194,11 @@ void GPENCIL_OT_bake_mesh_animation(wmOperatorType *ot)
 
   /* properties */
   ot->prop = RNA_def_int(
-      ot->srna, "start_frame", 1, 1, 100000, "Start Frame", "The start frame", 1, 100000);
+      ot->srna, "frame_start", 1, 1, 100000, "Start Frame", "The start frame", 1, 100000);
 
   prop = RNA_def_int(
-      ot->srna, "end_frame", 250, 1, 100000, "End Frame", "The end frame of animation", 1, 100000);
-  RNA_def_property_update_runtime(prop, gp_bake_set_end_frame);
+      ot->srna, "frame_end", 250, 1, 100000, "End Frame", "The end frame of animation", 1, 100000);
+  RNA_def_property_update_runtime(prop, gp_bake_set_frame_end);
 
   prop = RNA_def_int(ot->srna, "step", 1, 1, 100, "Step", "Step between generated frames", 1, 100);



More information about the Bf-blender-cvs mailing list