Skip to content
Snippets Groups Projects
mesh_bsurfaces.py 180 KiB
Newer Older
# ##### 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; version 2
#  of the License.
#
#  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 #####

Eclectiel L's avatar
Eclectiel L committed
    "name": "Bsurfaces GPL Edition",
    "author": "Eclectiel",
    "version": (1,5),
    "blender": (2, 63, 0),
    "api": 45996,
Eclectiel L's avatar
Eclectiel L committed
    "location": "View3D > EditMode > ToolShelf",
    "description": "Modeling and retopology tool.",
    "wiki_url": "http://www.bsurfaces.info",
    "tracker_url": "http://projects.blender.org/tracker/index.php?"\
        "func=detail&aid=26642",
    "category": "Mesh"}
import bmesh
import mathutils
import operator



class VIEW3D_PT_tools_SURFSK_mesh(bpy.types.Panel):
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'
    bl_context = "mesh_edit"
Eclectiel L's avatar
Eclectiel L committed
    bl_label = "Bsurfaces"
    @classmethod
    def poll(cls, context):
        return context.active_object
    def draw(self, context):
        layout = self.layout
        
        scn = context.scene
        ob = context.object
        
        col = layout.column(align=True)
        row = layout.row()
        row.separator()
Eclectiel L's avatar
Eclectiel L committed
        col.operator("gpencil.surfsk_add_surface", text="Add Surface")
        col.operator("gpencil.surfsk_edit_strokes", text="Edit Strokes")
        col.prop(scn, "SURFSK_cyclic_cross")
        col.prop(scn, "SURFSK_cyclic_follow")
        col.prop(scn, "SURFSK_loops_on_strokes")
        col.prop(scn, "SURFSK_automatic_join")
        col.prop(scn, "SURFSK_keep_strokes")
        
        
        
class VIEW3D_PT_tools_SURFSK_curve(bpy.types.Panel):
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'TOOLS'
    bl_context = "curve_edit"
    bl_label = "Bsurfaces"
    
    @classmethod
    def poll(cls, context):
        return context.active_object
    
    
    def draw(self, context):
        layout = self.layout
        
        scn = context.scene
        ob = context.object
        
        col = layout.column(align=True)
        row = layout.row()
        row.separator()
        col.operator("curve.surfsk_first_points", text="Set First Points")
        col.operator("curve.switch_direction", text="Switch Direction")
        col.operator("curve.surfsk_reorder_splines", text="Reorder Splines")
        



#### Returns the type of strokes used.
def get_strokes_type(main_object):
    strokes_type = ""
    strokes_num = 0
    
    # Check if they are grease pencil
    try:
        #### Get the active grease pencil layer.
        strokes_num = len(main_object.grease_pencil.layers.active.active_frame.strokes)
        
        if strokes_num > 0:
            strokes_type = "GP_STROKES"
    except:
        pass
    
    
    # Check if they are curves, if there aren't grease pencil strokes.
    if strokes_type == "":
        if len(bpy.context.selected_objects) == 2:
            for ob in bpy.context.selected_objects:
                if ob != bpy.context.scene.objects.active and ob.type == "CURVE":
                    strokes_type = "EXTERNAL_CURVE"
                    strokes_num = len(ob.data.splines)
                    
                    # Check if there is any non-bezier spline.
                    for i in range(len(ob.data.splines)):
                        if ob.data.splines[i].type != "BEZIER":
                            strokes_type = "CURVE_WITH_NON_BEZIER_SPLINES"
                            break
                            
                elif ob != bpy.context.scene.objects.active and ob.type != "CURVE":
                    strokes_type = "EXTERNAL_NO_CURVE"
        elif len(bpy.context.selected_objects) > 2:
            strokes_type = "MORE_THAN_ONE_EXTERNAL"
    
    
    # Check if there is a single stroke without any selection in the object.
    if strokes_num == 1 and main_object.data.total_vert_sel == 0:
        if strokes_type == "EXTERNAL_CURVE":
            strokes_type = "SINGLE_CURVE_STROKE_NO_SELECTION"
        elif strokes_type == "GP_STROKES":
            strokes_type = "SINGLE_GP_STROKE_NO_SELECTION"
    if strokes_num == 0 and main_object.data.total_vert_sel > 0:
        strokes_type = "SELECTION_ALONE"
        
    if strokes_type == "":
        strokes_type = "NO_STROKES"
    
    
    
    return strokes_type



# Surface generator operator.
Eclectiel L's avatar
Eclectiel L committed
class GPENCIL_OT_SURFSK_add_surface(bpy.types.Operator):
    bl_idname = "gpencil.surfsk_add_surface"
Eclectiel L's avatar
Eclectiel L committed
    bl_label = "Bsurfaces add surface"
    bl_description = "Generates surfaces from grease pencil strokes, bezier curves or loose edges."
Eclectiel L's avatar
Eclectiel L committed
    bl_options = {'REGISTER', 'UNDO'}
    edges_U = bpy.props.IntProperty(name = "Cross",
                        description = "Number of face-loops crossing the strokes.",
                        default = 1,
                        min = 1,
                        max = 200)
                        
    edges_V = bpy.props.IntProperty(name = "Follow",
                        description = "Number of face-loops following the strokes.",
                        default = 1,
                        min = 1,
                        max = 200)
    
    cyclic_cross = bpy.props.BoolProperty(name = "Cyclic Cross",
                        description = "Make cyclic the face-loops crossing the strokes.",
                        default = False)
                        
    cyclic_follow = bpy.props.BoolProperty(name = "Cyclic Follow",
                        description = "Make cyclic the face-loops following the strokes.",
                        default = False)
                        
    loops_on_strokes = bpy.props.BoolProperty(name = "Loops on strokes",
                        description = "Make the loops match the paths of the strokes.",
                        default = False)
    
    automatic_join = bpy.props.BoolProperty(name = "Automatic join",
                        description = "Join automatically vertices of either surfaces generated by crosshatching, or from the borders of closed shapes.",
                        default = False)
                        
    join_stretch_factor = bpy.props.FloatProperty(name = "Stretch",
                        description = "Amount of stretching or shrinking allowed for edges when joining vertices automatically.",
                        default = 1,
                        min = 0,
                        max = 3,
                        subtype = 'FACTOR')
Loading
Loading full blame...