Skip to content
Snippets Groups Projects
Commit b2c68d8e authored by Shrinivas Kulkarni's avatar Shrinivas Kulkarni
Browse files

curve_assign_shapekey: 1) Passed target & shape key objects as params to main...

curve_assign_shapekey: 1) Passed target & shape key objects as params to main function 2) Fix to retain first key name, if target already has shape keys
parent e7a8ab24
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# This Blender add-on assigns one or more Bezier Curves as shape keys to another # This Blender add-on assigns one or more Bezier Curves as shape keys to another
# Bezier Curve # Bezier Curve
# #
# Supported Blender Version: 2.80 Beta # Supported Blender Versions: 2.8x
# #
# Copyright (C) 2019 Shrinivas Kulkarni # Copyright (C) 2019 Shrinivas Kulkarni
# #
...@@ -400,18 +400,12 @@ class Path: ...@@ -400,18 +400,12 @@ class Path:
self.curve.data = self.getNewCurveData() self.curve.data = self.getNewCurveData()
bpy.data.curves.remove(curveData) bpy.data.curves.remove(curveData)
def main(removeOriginal, space, matchParts, matchCriteria, alignBy, alignValues): def main(targetObj, shapekeyObjs, removeOriginal, space, matchParts, \
targetObj = bpy.context.active_object matchCriteria, alignBy, alignValues):
if(targetObj == None or not isBezier(targetObj)):
return
target = Path(targetObj) target = Path(targetObj)
shapekeys = [Path(c) for c in bpy.context.selected_objects if isBezier(c) \ shapekeys = [Path(c) for c in shapekeyObjs]
and c != bpy.context.active_object]
if(len(shapekeys) == 0):
return
shapekeys = getExistingShapeKeyPaths(target) + shapekeys shapekeys = getExistingShapeKeyPaths(target) + shapekeys
userSel = [target] + shapekeys userSel = [target] + shapekeys
...@@ -437,18 +431,20 @@ def main(removeOriginal, space, matchParts, matchCriteria, alignBy, alignValues) ...@@ -437,18 +431,20 @@ def main(removeOriginal, space, matchParts, matchCriteria, alignBy, alignValues)
for j, part in enumerate(path.parts): for j, part in enumerate(path.parts):
part.toClose = allToClose[j] part.toClose = allToClose[j]
target.updateCurve() if(targetObj.data.shape_keys != None):
skName = targetObj.data.shape_keys.key_blocks[0].name
else:
skName = 'Basis'
target.curve.shape_key_add(name = 'Basis') target.updateCurve()
target.curve.shape_key_add(name = skName)
addShapeKeys(target.curve, shapekeys, space) addShapeKeys(target.curve, shapekeys, space)
if(removeOriginal): if(removeOriginal):
for path in userSel: for path in userSel:
if(path.curve != target.curve): if(path.curve != target.curve):
safeRemoveCurveObj(path.curve) safeRemoveObj(path.curve)
return {}
def getSplineSegs(spline): def getSplineSegs(spline):
p = spline.bezier_points p = spline.bezier_points
...@@ -743,7 +739,7 @@ def addShapeKeys(curve, paths, space): ...@@ -743,7 +739,7 @@ def addShapeKeys(curve, paths, space):
key.data[i].handle_right = pt[2] key.data[i].handle_right = pt[2]
#TODO: Remove try #TODO: Remove try
def safeRemoveCurveObj(obj): def safeRemoveObj(obj):
try: try:
collections = obj.users_collection collections = obj.users_collection
...@@ -791,9 +787,14 @@ class AssignShapeKeysOp(Operator): ...@@ -791,9 +787,14 @@ class AssignShapeKeysOp(Operator):
alignVal2 = params.alignVal2 alignVal2 = params.alignVal2
alignVal3 = params.alignVal3 alignVal3 = params.alignVal3
createdObjsMap = main(removeOriginal, space, \ targetObj = bpy.context.active_object
matchParts, [matchCri1, matchCri2, matchCri3], \ shapekeyObjs = [obj for obj in bpy.context.selected_objects if isBezier(obj) \
alignBy, [alignVal1, alignVal2, alignVal3]) and obj != targetObj]
if(targetObj != None and isBezier(targetObj) and len(shapekeyObjs) > 0):
main(targetObj, shapekeyObjs, removeOriginal, space, \
matchParts, [matchCri1, matchCri2, matchCri3], \
alignBy, [alignVal1, alignVal2, alignVal3])
return {'FINISHED'} return {'FINISHED'}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment