Skip to content

Instantly share code, notes, and snippets.

@Taremin
Created August 27, 2024 17:30
Show Gist options
  • Save Taremin/434207d712afd97b08135707c5b5e8c6 to your computer and use it in GitHub Desktop.
Save Taremin/434207d712afd97b08135707c5b5e8c6 to your computer and use it in GitHub Desktop.
アクティブオブジェクトのシェイプキーの影響下にある頂点を選択する
import bpy
import numpy
obj = bpy.context.active_object
bpy.ops.object.mode_set(mode="OBJECT")
vlen = len(obj.data.vertices)
selected = numpy.zeros(vlen, dtype=bool)
obj.data.vertices.foreach_get("select", selected)
obj.data.polygons.foreach_set("select", numpy.zeros(len(obj.data.polygons), dtype=bool))
obj.data.edges.foreach_set("select", numpy.zeros(len(obj.data.edges), dtype=bool))
vco = numpy.empty((vlen, 3), dtype=numpy.float32)
obj.data.vertices.foreach_get("co", vco.ravel())
for key_block in obj.data.shape_keys.key_blocks:
if key_block == key_block.relative_key:
continue
points = numpy.empty((vlen, 3), dtype=numpy.float32)
key_block.points.foreach_get("co", points.ravel())
selected[numpy.where(vco != points)[0]] = True
obj.data.vertices.foreach_set("select", selected)
bpy.ops.object.mode_set(mode="EDIT")
@Taremin
Copy link
Author

Taremin commented Aug 27, 2024

追加選択にしない場合は9行目はコメントアウトする

# obj.data.vertices.foreach_get("select", selected)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment