I have a script that generates random hair I want it to play animation from 1st frame to 250th, and then output a rendered image of 250th frame, or simply give me the 250th frame without playing animation (that would a be better option)
Here's my code to play animation:
# Animation Frame Timer
def stop_playback(scene):
if scene.frame_current == 250:
bpy.ops.screen.animation_cancel(restore_frame=False)
bpy.app.handlers.frame_change_pre.append(stop_playback)
bpy.ops.screen.animation_play()
bpy.data.scenes["Scene"].frame_set(250)
I have 2 scripts. One for generating hair, and one for rendering my output image. I use this command in terminal to execute it:
#!/bin/bash
frames_cnt=#needed number of images
output_frame_path='BlenderRepository/RenderedImages/LongHair'
for (( i=1; i<=frames_cnt; i++ )); do
echo "Rendering frame ${i}/${frames_cnt}..."
(
cd /home/ds/Documents/blender2.80/
./blender --background una.blend --python BlenderRepository/Scripts/Config/LongHair/LongHair.py --python BlenderRepository/Scripts/Config/LongHair/RenderLongHairImage.py -- "${output_frame_path}/frame_${i}.png"
)
echo "Frame ${i}/${frames_cnt} has been rendered"
done
When I executing my script via terminal, I suppose it gives me the 1st frame as output. Well, formally its 250th frame, but it looks like 1st frame, as you can see here:
And here's example when I manually execute my scripts via blender one by one:
You can see that the animation has been played, and its 250th frame, as hair lay down. I executed my 1st script for generating hair, wait for animation to run from 1 to 250th frame, and then executed the 2nd script.
So my question is how can I make it work automatically? Is it possible to make it work that way in the --background? I mean I want my second script wait for 1st script to end animation run, so I can get the right image of 250th frame.
2 Particle Systems code:
psys = ob.particle_systems[-1]
psys1 = ob.particle_systems[-1]
pc = psys.point_cache
pc1 = psys1.point_cache
print(pc.frame_start, pc.frame_end)
bpy.ops.ptcache.bake({"point_cache": pc}, bake=True)
bpy.ops.ptcache.bake({"point_cache": pc1}, bake=True)