[Bf-extensions-cvs] [b154bd63] master: curve_assign_shapekey: Initial commit to release: T62799
Shrinivas Kulkarni
noreply at git.blender.org
Wed Jun 19 16:59:17 CEST 2019
Commit: b154bd63c0fd87bbb4679c2635f3fc5701f86ae0
Author: Shrinivas Kulkarni
Date: Wed Jun 19 20:27:26 2019 +0530
Branches: master
https://developer.blender.org/rBAb154bd63c0fd87bbb4679c2635f3fc5701f86ae0
curve_assign_shapekey: Initial commit to release: T62799
===================================================================
A curve_assign_shapekey.py
===================================================================
diff --git a/curve_assign_shapekey.py b/curve_assign_shapekey.py
new file mode 100644
index 00000000..287873a0
--- /dev/null
+++ b/curve_assign_shapekey.py
@@ -0,0 +1,1104 @@
+#
+#
+# This Blender add-on assigns one or more Bezier Curves as shape keys to another
+# Bezier Curve
+#
+# Supported Blender Version: 2.80 Beta
+#
+# Copyright (C) 2019 Shrinivas Kulkarni
+#
+# License: MIT (https://github.com/Shriinivas/assignshapekey/blob/master/LICENSE)
+#
+
+import bpy, bmesh, bgl, gpu
+from gpu_extras.batch import batch_for_shader
+from bpy.props import BoolProperty, EnumProperty
+from collections import OrderedDict
+from mathutils import Vector
+from math import sqrt, floor
+from functools import cmp_to_key
+
+#################### UI and Registration Stuff ####################
+
+bl_info = {
+ "name": "Assign Shape Keys",
+ "author": "Shrinivas Kulkarni",
+ "version": (1, 0, 0),
+ "location": "Properties > Active Tool and Workspace Settings > Assign Shape Keys",
+ "description": "Assigns one or more Bezier curves as shape keys to another Bezier curve",
+ "category": "Object",
+ "blender": (2, 80, 0),
+}
+
+matchList = [('vCnt', 'Vertex Count', 'Match by vertex count'),
+ ('bbArea', 'Area', 'Match by surface area of the bounding box'), \
+ ('bbHeight', 'Height', 'Match by bounding box height'), \
+ ('bbWidth', 'Width', 'Match by bounding box width'),
+ ('bbDepth', 'Depth', 'Match by bounding box depth'),
+ ('minX', 'Min X', 'Match by bounding bon Min X'),
+ ('maxX', 'Max X', 'Match by bounding bon Max X'),
+ ('minY', 'Min Y', 'Match by bounding bon Min Y'),
+ ('maxY', 'Max Y', 'Match by bounding bon Max Y'),
+ ('minZ', 'Min Z', 'Match by bounding bon Min Z'),
+ ('maxZ', 'Max Z', 'Match by bounding bon Max Z')]
+
+def markVertHandler(self, context):
+ if(self.markVertex):
+ bpy.ops.wm.mark_vertex()
+
+class AssignShapeKeyParams(bpy.types.PropertyGroup):
+
+ removeOriginal : BoolProperty(name = "Remove Shape Key Objects", \
+ description = "Remove shape key objects after assigning to target", \
+ default = True)
+
+ space : EnumProperty(name = "Space", \
+ items = [('worldspace', 'World Space', 'worldspace'),
+ ('localspace', 'Local Space', 'localspace')], \
+ description = 'Space that shape keys are evluated in')
+
+ alignList : EnumProperty(name="Vertex Alignment", items = \
+ [("-None-", 'Manual Alignment', "Align curve segments based on starting vertex"), \
+ ('vertCo', 'Vertex Coordinates', 'Align curve segments based on vertex coordinates')], \
+ description = 'Start aligning the vertices of target and shape keys from',
+ default = '-None-')
+
+ alignVal1 : EnumProperty(name="Value 1",
+ items = matchList, default = 'minX', description='First align criterion')
+
+ alignVal2 : EnumProperty(name="Value 2",
+ items = matchList, default = 'maxY', description='Second align criterion')
+
+ alignVal3 : EnumProperty(name="Value 3",
+ items = matchList, default = 'minZ', description='Third align criterion')
+
+ matchParts : EnumProperty(name="Match Parts", items = \
+ [("-None-", 'None', "Don't match parts"), \
+ ('default', 'Default', 'Use part (spline) order as in curve'), \
+ ('custom', 'Custom', 'Use one of the custom criteria for part matching')], \
+ description='Match disconnected parts', default = 'default')
+
+ matchCri1 : EnumProperty(name="Value 1",
+ items = matchList, default = 'minX', description='First match criterion')
+
+ matchCri2 : EnumProperty(name="Value 2",
+ items = matchList, default = 'maxY', description='Second match criterion')
+
+ matchCri3 : EnumProperty(name="Value 3",
+ items = matchList, default = 'minZ', description='Third match criterion')
+
+ markVertex : BoolProperty(name="Mark Starting Vertices", \
+ description='Mark first vertices in all splines of selected curves', \
+ default = False, update = markVertHandler)
+
+class AssignShapeKeysPanel(bpy.types.Panel):
+
+ bl_label = "Assign Shape Keys"
+ bl_idname = "CURVE_PT_assign_shape_keys"
+ bl_space_type = 'VIEW_3D'
+ bl_region_type = 'UI'
+ bl_category = "Tool"
+
+ @classmethod
+ def poll(cls, context):
+ return context.mode in {'OBJECT', 'EDIT_CURVE'}
+
+ def draw(self, context):
+
+ layout = self.layout
+ col = layout.column()
+ params = context.window_manager.AssignShapeKeyParams
+
+ if(context.mode == 'OBJECT'):
+ row = col.row()
+ row.prop(params, "removeOriginal")
+
+ row = col.row()
+ row.prop(params, "space")
+
+ row = col.row()
+ row.prop(params, "alignList")
+
+ if(params.alignList == 'vertCo'):
+ row = col.row()
+ row.prop(params, "alignVal1")
+ row.prop(params, "alignVal2")
+ row.prop(params, "alignVal3")
+
+ row = col.row()
+ row.prop(params, "matchParts")
+
+ if(params.matchParts == 'custom'):
+ row = col.row()
+ row.prop(params, "matchCri1")
+ row.prop(params, "matchCri2")
+ row.prop(params, "matchCri3")
+
+ row = col.row()
+ row.operator("object.assign_shape_keys")
+ else:
+ col.prop(params, "markVertex", \
+ toggle = True)
+
+class AssignShapeKeysOp(bpy.types.Operator):
+
+ bl_idname = "object.assign_shape_keys"
+ bl_label = "Assign Shape Keys"
+ bl_options = {'REGISTER', 'UNDO'}
+
+ def execute(self, context):
+ params = context.window_manager.AssignShapeKeyParams
+ removeOriginal = params.removeOriginal
+ space = params.space
+
+ matchParts = params.matchParts
+ matchCri1 = params.matchCri1
+ matchCri2 = params.matchCri2
+ matchCri3 = params.matchCri3
+
+ alignBy = params.alignList
+ alignVal1 = params.alignVal1
+ alignVal2 = params.alignVal2
+ alignVal3 = params.alignVal3
+
+ createdObjsMap = main(removeOriginal, space, \
+ matchParts, [matchCri1, matchCri2, matchCri3], \
+ alignBy, [alignVal1, alignVal2, alignVal3])
+
+ return {'FINISHED'}
+
+class MarkerController:
+ drawHandlerRef = None
+ defPointSize = 6
+ ptColor = (0, .8, .8, 1)
+
+ def createSMMap(self, context):
+ objs = context.selected_objects
+ smMap = {}
+ for curve in objs:
+ if(not isBezier(curve)):
+ continue
+
+ smMap[curve.name] = {}
+ mw = curve.matrix_world
+ for splineIdx, spline in enumerate(curve.data.splines):
+ if(not spline.use_cyclic_u):
+ continue
+
+ #initialize to the curr start vert co and idx
+ smMap[curve.name][splineIdx] = \
+ [mw @ curve.data.splines[splineIdx].bezier_points[0].co, 0]
+
+ for pt in spline.bezier_points:
+ pt.select_control_point = False
+
+ if(len(smMap[curve.name]) == 0):
+ del smMap[curve.name]
+
+ return smMap
+
+ def createBatch(self, context):
+ positions = [s[0] for cn in self.smMap.values() for s in cn.values()]
+ colors = [MarkerController.ptColor for i in range(0, len(positions))]
+
+ self.batch = batch_for_shader(self.shader, \
+ "POINTS", {"pos": positions, "color": colors})
+
+ if context.area:
+ context.area.tag_redraw()
+
+ def drawHandler(self):
+ bgl.glPointSize(MarkerController.defPointSize)
+ self.batch.draw(self.shader)
+
+ def removeMarkers(self, context):
+ if(MarkerController.drawHandlerRef != None):
+ bpy.types.SpaceView3D.draw_handler_remove(MarkerController.drawHandlerRef, \
+ "WINDOW")
+
+ if(context.area and hasattr(context.space_data, 'region_3d')):
+ context.area.tag_redraw()
+
+ MarkerController.drawHandlerRef = None
+
+ self.deselectAll()
+
+ def __init__(self, context):
+ self.smMap = self.createSMMap(context)
+ self.shader = gpu.shader.from_builtin('3D_FLAT_COLOR')
+ self.shader.bind()
+
+ MarkerController.drawHandlerRef = \
+ bpy.types.SpaceView3D.draw_handler_add(self.drawHandler, \
+ (), "WINDOW", "POST_VIEW")
+
+ self.createBatch(context)
+
+ def saveStartVerts(self):
+ for curveName in self.smMap.keys():
+ curve = bpy.data.objects[curveName]
+ splines = curve.data.splines
+ spMap = self.smMap[curveName]
+
+ for splineIdx in spMap.keys():
+ markerInfo = spMap[splineIdx]
+ if(markerInfo[1] != 0):
+ pts = splines[splineIdx].bezier_points
+ loc, idx = markerInfo[0], markerInfo[1]
+ cnt = len(pts)
+
+ ptCopy = [[p.co.copy(), p.handle_right.copy(), \
+ p.handle_left.copy(), p.handle_right_type, \
+ p.handle_left_type] for p in pts]
+
+ for i, pt in enumerate(pts):
+ srcIdx = (idx + i) % cnt
+ p = ptCopy[srcIdx]
+
+ #Must set the types first
+ pt.handle_right_type = p[3]
+ pt.handle_left_type = p[4]
+ pt.co = p[0]
+ pt
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list