1

In my scene, I drag some of the objects and move them around while the physics is running (Alt+A). This means that the physical interactions could be quite different every time I do start the physics (Alt+A). Note that I am doing all of this when using Blender with GUI.

Instead of using the cursor, I want to feed new coordinates for the locations of the target objects that I want to move. I also want to do all of this when running Blender in the background and use the Python API. So I wonder, is there a way to avoid baking the simulation and do it frame-by-frame using the Python API?

I was initially thinking to run bpy.ops.screen.animation_play() but this command does not work when running Blender in the background. Even if there is a way to get it to work I don't know how how to feed in new location coordinates for the next frames. Also, I wouldn't know the frame rate and this might mess things up even further.

I also cannot bake the simulation due to the dynamic nature of my work: new location coordinates might be different on every run. Therefore, I think the only way to do what I want would be to do the simulation step-by-step. I would appreciate if someone can help me with this

P.S. I know I shouldn't change the position of the objects in the scene when the physics is working rather than applying force to them. I will figure this out later but any tip in the comments for resolving this would also be appreciated.

Amir
  • 3,074
  • 2
  • 29
  • 55

1 Answers1

2

If I understand your question correctly then the way that I do this is using bpy.context.scene.frame_set(). I set it to 1 at the beginning of the simulation and then inside a loop to step through the frames I use bpy.context.scene.frame_set(bpy.context.scene.frame_current + 1).

  • Thank you! This is what I needed! As anticipated, the problem with this is that I am not applying a force to the soft body objects in my scene and things get a bit messy because of that. Would be great if you know how I can apply some force to my objects to move them instead of just moving their location – Amir Oct 16 '18 at 14:44
  • 1
    Sorry, I'm pretty new to the blender physics game myself so I've never used forces. This frame-by-frame physics update thing just happened to be exactly what I was working on yesterday! – bigbadpiano Oct 16 '18 at 14:55