Setting Poses and Reading Mesh Data in Python

Hi All,
I am doing a project in which I would like to use blender’s capabilities. Aim of the project is to demonstrate results of a simulation (I am simulating effect of wind on tree trunk). For this I have setup a mesh and armature with all IK and other constraints. Now, I would like to run my simulation code in this setup. My thinking is the following and I would like to know if the following is possible in 2.49 or is it advisable to move to 2.56?

  1. Read Mesh, Armature Data from blender. I would like all the verts, bones data in world coordinates after all the modifiers/constraints are applied (e.g., if a bone moves, the mesh should change accordingly and then I would like to read mesh data after the change. similarly, for mesh, ik and other constraints should be solved before I read data).
  2. Run my simulation step (on armature, mesh is not effected by simulation). I am also doing a collision detection here across trees.
  3. Apply the changes to armature back in to blender and KeyFrame it.
  4. Do this in a loop.

Anyone, can you please advice me on best way to do this? Can I do in python 2.49 (because I already have all the setup in 2.49 and am wary to move to 2.56 because it is beta). Or, should I move to 2.56. Or, is it necessary to move to hacking and coding blender c++?

Thanks much for all of the help. This has been a great community :slight_smile:

jMonkeyPlatform (Java) at least can read meshes and bones from a .blend (compressed or not) and use it inside of jMonkey … a Python script can read ‘text files’ (with data) and apply it Blender
(cannot compare the scripting possibilities in 2.49 agains 2.56, I myself would prefer 2.56 …)

Thanks for the reply.
Reading mesh and bone is supported by blender python as well, If I understand correctly. I am having problem understanding about the following: Once the bone poses are keyframed, if I want to read the mesh vertices (in absolute/global coordinate space) after being deformed by bones. Also, another thing is that, once I know the pose I wanted, how do I keyframe it in blender (this qn I think have a simpler answer, I would need to do one of those global to pose space transformation and key it in those pose channels… need to figure it out still). The first question of reading vertex data after deforming is more of a problem for me.

infact the first question turned out to be easier :slight_smile:

you just need to go to required frame (still need to figure out how to do this in python) and do the following:


me = Blender.Mesh.Get('Cylinder') # get the mesh first
me.getFromObject('Cylinder')        # do this so that you get the modified mesh after all deformations applied
                                                  # you need to pass the object's name to which the deformation is applied
                                                  # basic point is that a mesh could be associated with many objects which deform differently
                                                  # and hence you need to pass the object name to this function to replace current data in me 
                                                  # with deformed mesh data
print me.verts[705]                       # here use it whatever way you want



so, now need to figure out 1) how to go to required frame from python 2) how to update all in a scene after going to the required frame from python.

I will keep working and post my progress here so that any one else could benefit. Also, please some one tell me if they know (so that some time is saved :slight_smile:

infact the first question turned out to be easier :slight_smile:

you just need to go to required frame (still need to figure out how to do this in python) and do the following:


me = Blender.Mesh.Get('Cylinder') # get the mesh first
me.getFromObject('Cylinder')        # do this so that you get the modified mesh after all deformations applied
                                                  # you need to pass the object's name to which the deformation is applied
                                                  # basic point is that a  mesh could be associated with many objects which deform differently
                                                  # and hence you need  to pass the object name to this function to replace current data in me 
                                                  # with deformed mesh data
print me.verts[705]                       # here use it whatever way you want
 


so, now need to figure out 1) how to go to required frame from python 2) how to update all in a scene after going to the required frame from python.

I will keep working and post my progress here so that any one else could benefit. Also, please some one tell me if they know (so that some time is saved :slight_smile:

moving to a frame :slight_smile:


me = Blender.Mesh.Get('Cylinder')
ob = Blender.Object.Get('Armature')
print me.verts[705]                            # before deformation
ob.evaluatePose(11)                          # evaluate at frame 11 (before this make sure object is bound to 
                                                        # the necessary action
me.getFromObject('Cylinder')              # get deformed mesh
print me.verts[705]                             # after deformation


now, associating an action to armature object, i guess is easy as I have seen an API. So, I will not post it here unless it is non-trivial.
Now, how to do this in NLA? adding actions and setting up NLA is my next tast. I will keep this thread updated.