Guest User

Untitled

a guest
Jul 2nd, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1.  
  2. # Script to delete all shapes where vertices only move a distance smaller than a given threshold.
  3. #
  4. # pruneLength and basisName should be defined by the user.
  5. #
  6. # This script assumes that all the shapes are relative to a single basis shape key.
  7. # You must define the name of the basis shape key in basisName below.
  8. # Alter pruneLength to give a threshold below which shape movement is ignored.
  9. import bpy
  10.  
  11. def deleteShapeByName(obj, shapeName):
  12.  
  13. iShape = obj.data.shape_keys.key_blocks.keys().index(shapeName)
  14. obj.active_shape_key_index = iShape
  15. bpy.ops.object.shape_key_remove()
  16.  
  17. ###
  18. # User-defined constants
  19. basisName = 'Basis'
  20. pruneLength = 0.0001
  21. #
  22.  
  23. print('###')
  24.  
  25. bpy.ops.object.mode_set(mode='OBJECT')
  26. obj = bpy.context.object
  27. basisShape = obj.data.shape_keys.key_blocks[basisName]
  28.  
  29. shapesToDelete = []
  30.  
  31. numberOfShapes = len(obj.data.shape_keys.key_blocks)
  32. # Find the names of shape keys where none of the keys move more than pruneLength
  33. for shape in obj.data.shape_keys.key_blocks:
  34. noMovement = True
  35. if shape != basisShape:
  36. for v in obj.data.vertices:
  37. movement = (shape.data[v.index].co - basisShape.data[v.index].co).length
  38. if movement > pruneLength:
  39. noMovement = False
  40. break
  41. if noMovement:
  42. shapesToDelete.append(shape.name)
  43.  
  44. for shapeName in shapesToDelete:
  45. deleteShapeByName(obj, shapeName)
  46.  
  47. print(len(shapesToDelete), 'shape keys deleted from', numberOfShapes)
Add Comment
Please, Sign In to add comment