# Can I get vertex's coordinates result of cloth simulation?

blender version==2.9.
I want to get vertex coordinates result of cloth simulation(with python script, if I could). Now, although I could get the vertex coordinates, they are before cloth simulation.

v_world = v.co @ obj.matrix_world
type='ARROWS',
location=v_world)


can anyone help me? Thanks in advance!!

You can use the dependendy graph to do that (supposing the simulation is already baked):

import bpy
import bmesh

# Set the frame considered as the result of the sim
bpy.context.scene.frame_current = 30

# Get the dependency graph state for this frame
dg = bpy.context.evaluated_depsgraph_get()

# The object
obj = bpy.context.object

# The mesh from the object and dependency graph
bm = bmesh.new()
bm.from_object(obj, dg)

# Take the coordinates
for v in bm.verts:
print(v.co)

del bm

• Thank you so much !! – ktro2828 Oct 3 '20 at 9:30

I could get an shape result of cloth simulation by following script,

(already cloth modifier is set)
bpy.ops.ptcache.bake_all(bake=True)
bpy.ops.object.modifier_apply_as_shapekey(keep_modifier=False, modifier='Cloth')
bpy.context.object.use_shape_key_edit_mode = True
bpy.data.shape_keys['Key'].key_blocks['Cloth'].value = 1


But, still I got same coordinates before result of cloth simulation. I can edit vertices of resulting cloth simulation, so, I think I could get vertex result of this as same...

Thank you @lemon , this is the best way I think.

I found another way to get vertex resulting cloth simulation, so share this.

Before running code, I've added 'Plane' and set vertex groups named 'Group' and 'Target' ('Group': to pin cloth, 'Target': target vertex)

def add_modifier(obj):
"""Add cloth modifier and apply as shapekey
Args:
obj(bpy.data.objects): object for cloth simulation
(In this case, 'Plane')

Returns:
shapekey
"""
for ob in bpy.context.scene.objects:
ob.select_set(False)
obj.select_set(True)

# add modifier and set some properties
modifier = obj.modifiers['Cloth']
modifier.collision_settings.use_collision = True
modifier.settings.bending_model = 'LINEAR'
modifier.settings.vertex_group_mass = 'Group'

# bake cloth simulation to get last frame
bpy.ops.ptcache.bake_all(bake=True)
bpy.context.scene.frame_set(250)

# apply cloth modifier as shape-key
#  and set value as '1'(last frame)
bpy.ops.object.modifier_apply_as_shapekey(keep_modifier=False, modifier='Cloth')
bpy.context.object.use_shape_key_edit_mode = True
shapekey = bpy.data.shape_keys['Key'].key_blocks['Cloth']
shapekey.value = 1.0
return shapekey

# main
obj = bpy.data.objects['Plane']

# get vertices belong to vertex geoup named 'Target'
vg = obj.vertex_groups.get('Target')
vlist = []
for v in obj.data.vertices:
for g in v.groups:
if g.group == vg.index:
vlist.append(v)