[Bf-extensions-cvs] [7850524e] master: Addon: BSurfaces: Refactoring. Fixed some bugs
Spivak Vladimir cwolf3d
noreply at git.blender.org
Mon Oct 7 00:49:04 CEST 2019
Commit: 7850524e6d7864196538781148026f282e69ce2c
Author: Spivak Vladimir (cwolf3d)
Date: Mon Oct 7 01:48:39 2019 +0300
Branches: master
https://developer.blender.org/rBA7850524e6d7864196538781148026f282e69ce2c
Addon: BSurfaces: Refactoring. Fixed some bugs
===================================================================
M mesh_bsurfaces.py
===================================================================
diff --git a/mesh_bsurfaces.py b/mesh_bsurfaces.py
index b84d0177..71ac52ff 100644
--- a/mesh_bsurfaces.py
+++ b/mesh_bsurfaces.py
@@ -20,7 +20,7 @@
bl_info = {
"name": "Bsurfaces GPL Edition",
"author": "Eclectiel, Spivak Vladimir(cwolf3d)",
- "version": (1, 6, 5),
+ "version": (1, 7, 0),
"blender": (2, 80, 0),
"location": "View3D EditMode > Sidebar > Edit Tab",
"description": "Modeling and retopology tool",
@@ -60,11 +60,17 @@ from bpy.types import (
AddonPreferences,
)
+# ----------------------------
# GLOBAL
global_color = [1.0, 0.0, 0.0, 1.0]
global_offset = 0.01
global_in_front = False
+global_mesh_object = ""
+global_gpencil_object = ""
+global_curve_object = ""
+# ----------------------------
+# Panels
class VIEW3D_PT_tools_SURFSK_mesh(Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
@@ -89,9 +95,12 @@ class VIEW3D_PT_tools_SURFSK_mesh(Panel):
col.label(text="Guide strokes:")
col.row().prop(scn, "SURFSK_guide", expand=True)
- if not scn.SURFSK_guide == 'Annotation':
- col.prop(scn, "SURFSK_strokes", text="")
- col.separator()
+ if scn.SURFSK_guide == 'GPencil':
+ col.prop(scn, "SURFSK_gpencil", text="")
+ col.separator()
+ if scn.SURFSK_guide == 'Curve':
+ col.prop(scn, "SURFSK_curve", text="")
+ col.separator()
props = col.operator("gpencil.surfsk_add_surface", text="Add Surface")
col.operator("gpencil.surfsk_edit_surface", text="Edit Surface")
@@ -132,12 +141,13 @@ class VIEW3D_PT_tools_SURFSK_curve(Panel):
col.operator("curve.surfsk_reorder_splines", text="Reorder Splines")
+# ----------------------------
# Returns the type of strokes used
def get_strokes_type(context):
- strokes_type = ""
+ strokes_type = "NO_STROKES"
strokes_num = 0
- # Check if they are grease pencil
+ # Check if they are annotation
if context.scene.bsurfaces.SURFSK_guide == 'Annotation':
try:
strokes = bpy.data.grease_pencils[0].layers.active.active_frame.strokes
@@ -147,27 +157,32 @@ def get_strokes_type(context):
if strokes_num > 0:
strokes_type = "GP_ANNOTATION"
except:
- pass
+ strokes_type = "NO_STROKES"
- try:
- gpencil = bpy.context.scene.bsurfaces.SURFSK_strokes
- strokes = gpencil.data.layers.active.active_frame.strokes
+ # Check if they are grease pencil
+ if context.scene.bsurfaces.SURFSK_guide == 'GPencil':
+ try:
+ global global_gpencil_object
+ gpencil = bpy.data.objects[global_gpencil_object]
+ strokes = gpencil.data.layers.active.active_frame.strokes
- strokes_num = len(strokes)
+ strokes_num = len(strokes)
- if strokes_num > 0:
- strokes_type = "GP_STROKES"
- except:
- pass
+ if strokes_num > 0:
+ strokes_type = "GP_STROKES"
+ except:
+ strokes_type = "NO_STROKES"
# Check if they are mesh
- main_object = bpy.context.scene.bsurfaces.SURFSK_mesh
+ global global_mesh_object
+ main_object = bpy.data.objects[global_mesh_object]
total_vert_sel = len([v for v in main_object.data.vertices if v.select])
# Check if they are curves, if there aren't grease pencil strokes
- if strokes_type == "":
+ if context.scene.bsurfaces.SURFSK_guide == 'Curve':
try:
- ob = bpy.context.scene.bsurfaces.SURFSK_strokes
+ global global_curve_object
+ ob = bpy.data.objects[global_curve_object]
if ob.type == "CURVE":
strokes_type = "EXTERNAL_CURVE"
strokes_num = len(ob.data.splines)
@@ -181,7 +196,7 @@ def get_strokes_type(context):
else:
strokes_type = "EXTERNAL_NO_CURVE"
except:
- pass
+ strokes_type = "NO_STROKES"
# Check if there is a single stroke without any selection in the object
if strokes_num == 1 and total_vert_sel == 0:
@@ -192,13 +207,11 @@ def get_strokes_type(context):
if strokes_num == 0 and total_vert_sel > 0:
strokes_type = "SELECTION_ALONE"
-
- if strokes_type == "":
- strokes_type = "NO_STROKES"
+
return strokes_type
-
+# ----------------------------
# Surface generator operator
class GPENCIL_OT_SURFSK_add_surface(Operator):
bl_idname = "gpencil.surfsk_add_surface"
@@ -285,7 +298,7 @@ class GPENCIL_OT_SURFSK_add_surface(Operator):
)
strokes_type: StringProperty()
initial_global_undo_state: BoolProperty()
-
+
def draw(self, context):
layout = self.layout
@@ -3116,9 +3129,16 @@ class GPENCIL_OT_SURFSK_add_surface(Operator):
bpy.ops.object.mode_set('INVOKE_REGION_WIN', mode='OBJECT')
+ global global_mesh_object
+
bsurfaces_props = bpy.context.scene.bsurfaces
- self.main_object = bsurfaces_props.SURFSK_mesh
- self.main_object.select_set(True)
+ self.main_object = bpy.data.objects[global_mesh_object]
+
+ try:
+ self.main_object.select_set(True)
+ except:
+ self.report({'WARNING'}, "Specify the name of the object with retopology")
+ return{"CANCELLED"}
bpy.context.view_layer.objects.active = self.main_object
self.update()
@@ -3200,7 +3220,7 @@ class GPENCIL_OT_SURFSK_add_surface(Operator):
# Delete grease pencil strokes
if self.strokes_type == "GP_STROKES" and not self.stopping_errors:
try:
- bpy.context.scene.bsurfaces.SURFSK_strokes.data.layers.active.clear()
+ bpy.context.scene.bsurfaces.SURFSK_gpencil.data.layers.active.clear()
except:
pass
@@ -3239,14 +3259,15 @@ class GPENCIL_OT_SURFSK_add_surface(Operator):
self.automatic_join = bsurfaces_props.SURFSK_automatic_join
self.loops_on_strokes = bsurfaces_props.SURFSK_loops_on_strokes
self.keep_strokes = bsurfaces_props.SURFSK_keep_strokes
- self.main_object = bsurfaces_props.SURFSK_mesh
-
+
try:
+ global global_mesh_object
+ self.main_object = bpy.data.objects[global_mesh_object]
self.main_object.select_set(True)
+ bpy.context.view_layer.objects.active = self.main_object
except:
self.report({'WARNING'}, "Specify the name of the object with retopology")
return{"CANCELLED"}
- bpy.context.view_layer.objects.active = self.main_object
self.update()
@@ -3270,12 +3291,9 @@ class GPENCIL_OT_SURFSK_add_surface(Operator):
if self.strokes_type == "GP_STROKES" or self.strokes_type == "EXTERNAL_CURVE" or self.strokes_type == "GP_ANNOTATION":
if self.strokes_type == "GP_STROKES":
# Convert grease pencil strokes to curve
- gp = bsurfaces_props.SURFSK_strokes
- #bpy.ops.gpencil.convert(type='CURVE', use_link_strokes=False)
+ global global_gpencil_object
+ gp = bpy.data.objects[global_gpencil_object]
self.original_curve = conver_gpencil_to_curve(self, context, gp, 'GPensil')
- # XXX gpencil.convert now keep org object as active/selected, *not* newly created curve!
- # XXX This is far from perfect, but should work in most cases...
- # self.original_curve = bpy.context.object
gplayer_prefix_translated = bpy.app.translations.pgettext_data('GP_Layer')
for ob in bpy.context.selected_objects:
if ob != bpy.context.view_layer.objects.active and \
@@ -3286,11 +3304,7 @@ class GPENCIL_OT_SURFSK_add_surface(Operator):
elif self.strokes_type == "GP_ANNOTATION":
# Convert grease pencil strokes to curve
gp = bpy.data.grease_pencils["Annotations"]
- #bpy.ops.gpencil.convert(type='CURVE', use_link_strokes=False)
self.original_curve = conver_gpencil_to_curve(self, context, gp, 'Annotation')
- # XXX gpencil.convert now keep org object as active/selected, *not* newly created curve!
- # XXX This is far from perfect, but should work in most cases...
- # self.original_curve = bpy.context.object
gplayer_prefix_translated = bpy.app.translations.pgettext_data('GP_Layer')
for ob in bpy.context.selected_objects:
if ob != bpy.context.view_layer.objects.active and \
@@ -3299,7 +3313,8 @@ class GPENCIL_OT_SURFSK_add_surface(Operator):
self.using_external_curves = False
elif self.strokes_type == "EXTERNAL_CURVE":
- self.original_curve = bsurfaces_props.SURFSK_strokes
+ global global_curve_object
+ self.original_curve = bpy.data.objects[global_curve_object]
self.using_external_curves = True
bpy.ops.object.editmode_toggle('INVOKE_REGION_WIN')
@@ -3461,11 +3476,11 @@ class GPENCIL_OT_SURFSK_add_surface(Operator):
# Delete grease pencil strokes
if self.strokes_type == "GP_STROKES" and not self.stopping_errors:
try:
- bpy.context.scene.bsurfaces.SURFSK_strokes.data.layers.active.clear()
+ bpy.context.scene.bsurfaces.SURFSK_gpencil.data.layers.active.clear()
except:
pass
- # Delete grease pencil strokes
+ # Delete annotation strokes
if self.strokes_type == "GP_ANNOTATION" and not self.stopping_errors:
try:
bpy.data.grease_pencils[0].layers.active.clear()
@@ -3521,7 +3536,8 @@ class GPENCIL_OT_SURFSK_add_surface(Operator):
else:
return{"CANCELLED"}
-# Edit strokes ope
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list