Skip to content

Instantly share code, notes, and snippets.

@jirihnidek
Created September 15, 2016 19:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jirihnidek/d8f2fa8d59a1a8f8a21bf9b299a1736e to your computer and use it in GitHub Desktop.
Save jirihnidek/d8f2fa8d59a1a8f8a21bf9b299a1736e to your computer and use it in GitHub Desktop.
Simple Blender Python script demonstrating using BMesh and Shape Keys
import bpy
import bmesh
import mathutils
def main():
"""
Example of bmesh and shape keys
"""
# Add basis shape
bpy.ops.object.shape_key_add(from_mix=False)
# Get the active mesh
me = bpy.context.object.data
# Get a BMesh representation
bm = bmesh.new()
bm.from_mesh(me)
# Get basis shape key
lay_shape_basis = bm.verts.layers.shape['Basis']
# Create new shape key
lay_my_shape = bm.verts.layers.shape.new('MyShape')
# Modify new shape key
for vert in bm.verts:
vert[lay_my_shape] = vert.co + mathutils.Vector((1.0, 0.0, 0.0))
# Frite bmesh back to mesh
bm.to_mesh(me)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment