Discussion:
[Bf-python] Extracting cloth vertices position
fmart
2014-03-14 12:49:13 UTC
Permalink
Hello,

I'm trying to obtain all vertices global position of a piece of cloth
after colliding with a table. My simulation starts with a plane as a
piece of cloth and another plane below as a table with the Collision
modifier.

To obtain all the data I need I'm using the following code (I've the
cloth selected):

import bpy
current_obj = bpy.context.active_object
print("="*40) # printing marker
for face in current_obj.data.polygons:
verts_in_face = face.vertices[:]
print("face index", face.index)
print("normal", face.normal)
for vert in verts_in_face:
local_point = current_obj.data.vertices[vert].co
world_point = current_obj.matrix_world * local_point
print("vert", vert, " vert co", world_point)


The simulation works well, I think the code also works well. However,
all that I obtain are vertices global position of the cloth in the
initial position, it doesn't matter whenever I pause the simulation.

Is there any possibility to obtain cloth vertices position after a
collision?

Thanks!

Felip
Bastien Montagne
2014-03-14 13:57:30 UTC
Permalink
Hi,

Yep, this way you?ll only get org data, before any modifier is applied?
Since cloth's pointcache data do not seem to be available from Python,
the only thing you can do to get cloth cos of vertices is to applies all
modifiers, like this e.g.:

# Generate temp mesh from object, with modifiers applied.
tmp_me = obj.to_mesh(/scene/, True, '/RENDER///')

# Use data from tmp_me...

# And then free it!
bpy.data.meshes.remove(tmp_me)
Post by fmart
Hello,
I'm trying to obtain all vertices global position of a piece of cloth
after colliding with a table. My simulation starts with a plane as a
piece of cloth and another plane below as a table with the Collision
modifier.
To obtain all the data I need I'm using the following code (I've the
import bpy
current_obj = bpy.context.active_object
print("="*40) # printing marker
verts_in_face = face.vertices[:]
print("face index", face.index)
print("normal", face.normal)
local_point = current_obj.data.vertices[vert].co
world_point = current_obj.matrix_world * local_point
print("vert", vert, " vert co", world_point)
The simulation works well, I think the code also works well. However,
all that I obtain are vertices global position of the cloth in the
initial position, it doesn't matter whenever I pause the simulation.
Is there any possibility to obtain cloth vertices position after a
collision?
Thanks!
Felip
_______________________________________________
Bf-python mailing list
Bf-python at blender.org
http://lists.blender.org/mailman/listinfo/bf-python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.blender.org/pipermail/bf-python/attachments/20140314/df4d9329/attachment.htm
fmart
2014-03-19 08:46:01 UTC
Permalink
Hi,

Thank you so much for your help, it was very helpful.

A
Post by Bastien Montagne
Hi,
Yep, this way
you'll only get org data, before any modifier is applied? Since cloth's
pointcache data do not seem to be available from Python, the only thing
you can do to get cloth cos of vertices is to applies all modifiers,
Post by Bastien Montagne
# Generate temp mesh from object, with modifiers
applied.
Post by Bastien Montagne
tmp_me = obj.to_mesh(_scene_, True, '_RENDER___')
# Use
data from tmp_me...
Post by Bastien Montagne
# And then free it!
bpy.data.meshes.remove(tmp_me)
Post by Bastien Montagne
Post by fmart
Hello,
I'm trying to obtain all vertices global position of a
piece of cloth
Post by Bastien Montagne
Post by fmart
after colliding with a table. My simulation starts
with a plane as a
Post by Bastien Montagne
Post by fmart
piece of cloth and another plane below as a table
with the Collision
Post by Bastien Montagne
Post by fmart
modifier.
To obtain all the data I need
I'm using the following code (I've the
import bpy
Post by Bastien Montagne
Post by fmart
current_obj = bpy.context.active_object
print("="*40) #
printing marker
verts_in_face = face.vertices[:]
Post by Bastien Montagne
Post by fmart
print("face index", face.index)
print("normal", face.normal)
local_point = current_obj.data.vertices[vert].co
Post by Bastien Montagne
Post by fmart
world_point =
current_obj.matrix_world * local_point
Post by Bastien Montagne
Post by fmart
print("vert", vert, " vert
co", world_point)
Post by Bastien Montagne
Post by fmart
The simulation works well, I think the code
also works well. However,
Post by Bastien Montagne
Post by fmart
all that I obtain are vertices global
position of the cloth in the
Post by Bastien Montagne
Post by fmart
initial position, it doesn't matter
whenever I pause the simulation.
Post by Bastien Montagne
Post by fmart
Is there any possibility to
obtain cloth vertices position after a
Post by Bastien Montagne
Post by fmart
collision?
Thanks!
Felip
_______________________________________________
Bf-python mailing list
Post by Bastien Montagne
Post by fmart
Bf-python at blender.org
http://lists.blender.org/mailman/listinfo/bf-python


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.blender.org/pipermail/bf-python/attachments/20140319/b49b4d7c/attachment.htm
Loading...