Advertisement
Dieton

Blender Every Shape Key On Every Frame.py

Feb 21st, 2024 (edited)
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.88 KB | Software | 0 0
  1. """
  2. Copyright (c) [2/21/24] [Dieton]
  3.  
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10.  
  11. The above copyright notice and this permission notice shall be included in all
  12. copies or substantial portions of the Software.
  13.  
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. SOFTWARE.
  21.  
  22. EveryShapeKeyEveryFrame Blender Script
  23.  
  24. Description:
  25. This script automates the process of creating an animation in Blender where each frame corresponds to a different blend shape (shape key). It sets the value of the current shape key to 1.0 and all other shape keys to 0.0 on each frame, creating a abrupt transition between different blend shapes.
  26.  
  27. Usage:
  28. 1. Select the object with shape keys.
  29. 2. Run the script in Blender's Text Editor.
  30. 3. The animation will be created starting from frame 1.
  31.  
  32. """
  33.  
  34. import bpy
  35.  
  36. def create_blend_shape_animation(obj):
  37.     # Check if the object has shape keys
  38.     if obj and obj.type == 'MESH' and obj.data.shape_keys:
  39.         # Set the start frame
  40.         start_frame = 1
  41.         bpy.context.scene.frame_set(start_frame)
  42.  
  43.         # Iterate through all shape keys
  44.         for i, shape_key in enumerate(obj.data.shape_keys.key_blocks):
  45.             # Set the value of the current shape key to 1.0
  46.             shape_key.value = 1.0
  47.  
  48.             # Insert a keyframe for the shape key's value
  49.             shape_key.keyframe_insert(data_path="value", frame=bpy.context.scene.frame_current)
  50.  
  51.             # Reset the shape key value to 0.0 for all other shape keys
  52.             for other_key in obj.data.shape_keys.key_blocks:
  53.                 if other_key != shape_key:
  54.                     other_key.value = 0.0
  55.                     other_key.keyframe_insert(data_path="value", frame=bpy.context.scene.frame_current)
  56.  
  57.             # Go to the next frame
  58.             bpy.context.scene.frame_set(bpy.context.scene.frame_current + 1)
  59.  
  60.         # Set the end frame
  61.         bpy.context.scene.frame_end = bpy.context.scene.frame_current
  62.  
  63. # Get the active object
  64. active_object = bpy.context.active_object
  65.  
  66. # Call the function to create the blend shape animation
  67. create_blend_shape_animation(active_object)
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement