Skip to content

Instantly share code, notes, and snippets.

@beyondlimits
Last active January 24, 2021 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beyondlimits/2249988e839353ad5fa0b05865826569 to your computer and use it in GitHub Desktop.
Save beyondlimits/2249988e839353ad5fa0b05865826569 to your computer and use it in GitHub Desktop.
An approach for Blender 2.91 to track geometry changes of an object and update geometry of another object in edit mode. This could be used as a crude way to implement custom modifiers.
import bmesh
from bpy import app, data, types
from traceback import format_exc
handlers = app.handlers.depsgraph_update_post
handlers.clear()
# data.texts{'Output'] - stdout
# data.meshes['Source'] - source mesh (cage)
# data.meshes['Target'] - target mesh (modified source mesh)
def handle(scene, depsgraph):
out = data.texts['Output']
out.clear()
try:
target = data.meshes['Target']
for upd in depsgraph.updates:
if upd.is_updated_geometry and isinstance(upd.id, types.Mesh):
# check whether we're interested in this mesh
if upd.id.name == 'Source':
out.write(upd.id.name + '\n')
bm = bmesh.from_edit_mesh(upd.id).copy()
# APPLY MODIFICATIONS HERE (e.g. scale)
bm.transform(Matrix.Scale(2, 4))
bm.to_mesh(target)
except:
out.from_string(format_exc())
handlers.append(handle)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment