[Bf-extensions-cvs] [d9c25b4] master: initial commit: Skinify by karab44: T51036

meta-androcto noreply at git.blender.org
Sun Apr 2 01:50:22 CEST 2017


Commit: d9c25b43907a2620a77b6fd889af9302f859c9d2
Author: meta-androcto
Date:   Sun Apr 2 09:50:03 2017 +1000
Branches: master
https://developer.blender.org/rBAd9c25b43907a2620a77b6fd889af9302f859c9d2

initial commit: Skinify by karab44: T51036

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

A	object_skinify.py

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

diff --git a/object_skinify.py b/object_skinify.py
new file mode 100644
index 0000000..1c1bc29
--- /dev/null
+++ b/object_skinify.py
@@ -0,0 +1,558 @@
+# ##### 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 #####
+
+bl_info = {
+    "name": "Skinify Rig",
+    "author": "Albert Makac (karab44)",
+    "version": (0, 8),
+    "blender": (2, 7, 8),
+    "location": "Properties > Bone > Skinify Rig (visible on pose mode only)",
+    "description": "Creates a mesh object from selected bones",
+    "warning": "",
+    "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Object/Skinify",
+    "category": "Object"}
+
+# NOTE: there are some unused scene variables around commented out
+# is the persintent scene props needed or can a property group be used instead?
+
+import bpy
+from bpy.props import (
+        FloatProperty,
+        IntProperty,
+        BoolProperty
+        )
+# from bpy_extras import object_utils
+from mathutils import Vector, Euler
+from bpy.app.handlers import persistent
+
+bpy.types.Scene.sub_level = IntProperty(
+                                name="sub_level",
+                                min=0, max=4,
+                                default=1,
+                                description="mesh density"
+                                )
+bpy.types.Scene.thickness = FloatProperty(
+                                name="thickness",
+                                min=0.01,
+                                default=0.8,
+                                description="adjust shape thickness"
+                                )
+bpy.types.Scene.finger_thickness = FloatProperty(
+                                name="finger_thickness",
+                                min=0.01, max=1.0,
+                                default=0.25,
+                                description="adjust finger thickness relative to body"
+                                )
+bpy.types.Scene.connect_mesh = BoolProperty(
+                                name="solid_shape",
+                                default=False,
+                                description="makes solid shape from bone chains"
+                                )
+bpy.types.Scene.connect_parents = BoolProperty(
+                                name="fill_gaps",
+                                default=False,
+                                description="fills the gaps between parented bones"
+                                )
+bpy.types.Scene.generate_all = BoolProperty(
+                                name="all_shapes",
+                                default=False,
+                                description="generates shapes from all bones"
+                                )
+bpy.types.Scene.head_ornaments = BoolProperty(
+                                name="head_ornaments",
+                                default=False,
+                                description="includes head ornaments"
+                                )
+bpy.types.Scene.apply_mod = BoolProperty(
+                                name="apply_modifiers",
+                                default=True,
+                                description="applies Modifiers to mesh"
+                                )
+bpy.types.Scene.parent_armature = BoolProperty(
+                                name="parent_armature",
+                                default=True,
+                                description="applies mesh to Armature"
+                                )
+
+
+# initialize properties
+def init_props():
+    scn = bpy.context.scene
+
+    scn.connect_mesh = False
+    scn.connect_parents = False
+    scn.generate_all = False
+    scn.thickness = 0.8
+    scn.finger_thickness = 0.25
+    scn.apply_mod = True
+    scn.parent_armature = True
+    scn.sub_level = 1
+
+
+# selects vertices
+def select_vertices(mesh_obj, idx):
+    bpy.context.scene.objects.active = mesh_obj
+    mode = mesh_obj.mode
+    bpy.ops.object.mode_set(mode='EDIT')
+    bpy.ops.mesh.select_all(action='DESELECT')
+    bpy.ops.object.mode_set(mode='OBJECT')
+
+    for i in idx:
+        mesh_obj.data.vertices[i].select = True
+
+    selectedVerts = [v.index for v in mesh_obj.data.vertices if v.select]
+
+    bpy.ops.object.mode_set(mode=mode)
+    return selectedVerts
+
+
+# generates edges from vertices used by skin modifier
+def generate_edges(mesh, shape_object, bones, scale, connect_mesh=False, connect_parents=False,
+                   head_ornaments=False, generate_all=False):
+    """
+    This function adds vertices for all heads and tails
+    """
+    # scene preferences
+    # scn = bpy.context.scene
+
+    # detect the head, face, hands, breast, heels or other exceptionary bones to exclusion or customization
+    common_ignore_list = ['eye', 'heel', 'breast', 'root']
+
+    # bvh_ignore_list = []
+    rigify_ignore_list = []
+    pitchipoy_ignore_list = ['face', 'breast', 'pelvis', 'nose', 'lip', 'jaw', 'chin', 'ear.', 'brow',
+                            'lid', 'forehead', 'temple', 'cheek', 'teeth', 'tongue']
+
+    alternate_scale_list = []
+    # rig_type rigify = 1, pitchipoy = 2
+    rig_type = 0
+    me = mesh
+    verts = []
+    edges = []
+    idx = 0
+    alternate_scale_idx_list = list()
+
+    ignore_list = common_ignore_list
+    # detect rig type
+    for b in bones:
+        if b.name == 'hips' and b.rigify_type == 'spine':
+            ignore_list = ignore_list + rigify_ignore_list
+            rig_type = 1
+            break
+        if b.name == 'spine' and b.rigify_type == 'pitchipoy.super_torso_turbo':
+            ignore_list = ignore_list + pitchipoy_ignore_list
+            rig_type = 2
+            break
+
+    # edge generator loop
+    for b in bones:
+        # look for rig's hands and their childs
+        if 'hand' in b.name.lower():
+            # prepare the list
+            for c in b.children_recursive:
+                alternate_scale_list.append(c.name)
+
+        found = False
+
+        for i in ignore_list:
+            if i in b.name.lower():
+
+                found = True
+                break
+
+        if found and generate_all is False:
+            continue
+            
+        #fix for drawing rootbone and relationship lines
+        if 'root' in b.name.lower() and generate_all is False:
+            continue
+                    
+
+        # ignore any head ornaments
+        if head_ornaments is False:
+            if b.parent is not None:
+                if 'head' in b.parent.name.lower():
+                    continue
+
+        if connect_parents:
+            if b.parent is not None and b.parent.bone.select is True and b.bone.use_connect is False:
+                if 'root' in b.parent.name.lower() and generate_all is False:
+                    continue
+                #ignore shoulder
+                if 'shoulder' in b.name.lower() and connect_mesh is True:
+                    continue
+                #connect the upper arm directly with chest ommiting shoulders    
+                if 'shoulder' in b.parent.name.lower() and connect_mesh is True:
+                    vert1 = b.head
+                    vert2 = b.parent.parent.tail                
+                
+                else:
+                    vert1 = b.head
+                    vert2 = b.parent.tail
+                
+                verts.append(vert1)
+                verts.append(vert2)
+                edges.append([idx, idx + 1])
+
+                # also make list of edges made of gaps between the bones
+                for a in alternate_scale_list:
+                    if b.name == a:
+                        alternate_scale_idx_list.append(idx)
+                        alternate_scale_idx_list.append(idx + 1)
+
+                idx = idx + 2
+            # for bvh free floating hips and hips correction for rigify and pitchipoy
+            if ((generate_all is False and 'hip' in b.name.lower()) or
+              (generate_all is False and (b.name == 'hips' and rig_type == 1) or
+              (b.name == 'spine' and rig_type == 2))):
+                continue
+                
+        
+        vert1 = b.head
+        vert2 = b.tail
+        verts.append(vert1)
+        verts.append(vert2)
+
+        edges.append([idx, idx + 1])
+
+        for a in alternate_scale_list:
+            if b.name == a:
+                alternate_scale_idx_list.append(idx)
+                alternate_scale_idx_list.append(idx + 1)
+
+        idx = idx + 2
+
+    # Create mesh from given verts, faces
+    me.from_pydata(verts, edges, [])
+    # Update mesh with new data
+    me.update()
+
+    # set object scale exact as armature's scale
+    shape_object.scale = scale
+
+    return alternate_scale_idx_list, rig_type
+
+
+def generate_mesh(shape_object, size, thickness=0.8, finger_thickness=0.25, sub_level=1,
+                  connect_mesh=False, connect_parents=False, generate_all=False, apply_mod=True,
+                  alternate_scale_idx_list=[], rig_type=0):
+    """
+    This function adds modifiers for generated edges
+    """
+    # scn = bpy.context.scene
+
+    bpy.ops.object.mode_set(mode='EDIT')
+    bpy.ops.mesh.select_all(action='DESELECT')
+
+    # add skin modifier
+    shape_object.modifiers.new("Skin", 'SKIN')
+    bpy.ops.mesh.select_all(action='SELECT')
+
+    override = bpy.context.copy()
+    for area in bpy.context.screen.areas:
+        if area.type == 'VIEW_3D':
+            for region in area.regions:
+                if

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list