void BlenderSync::sync_motion(BL::SpaceView3D b_v3d, BL::Object b_override, void **python_thread_state) { if(scene->need_motion() == Scene::MOTION_NONE) return; /* get camera object here to deal with camera switch */ BL::Object b_cam = b_scene.camera(); if(b_override) b_cam = b_override; Camera prevcam = *(scene->camera); /* go back and forth one frame */ int frame = b_scene.frame_current(); for(int motion = -1; motion <= 1; motion += 2) { /* we need to set the python thread state again because this * function assumes it is being executed from python and will * try to save the thread state */ python_thread_state_restore(python_thread_state); b_scene.frame_set(frame + motion, 0.0f); python_thread_state_save(python_thread_state); /* camera object */ if(b_cam) sync_camera_motion(b_cam, motion); /* mesh objects */ sync_objects(b_v3d, motion); } /* we need to set the python thread state again because this * function assumes it is being executed from python and will * try to save the thread state */ python_thread_state_restore(python_thread_state); b_scene.frame_set(frame, 0.0f); python_thread_state_save(python_thread_state); /* tag camera for motion update */ if(scene->camera->motion_modified(prevcam)) scene->camera->tag_update(); }
void BlenderSync::sync_motion(BL::RenderSettings &b_render, BL::Depsgraph &b_depsgraph, BL::Object &b_override, int width, int height, void **python_thread_state) { if (scene->need_motion() == Scene::MOTION_NONE) return; /* get camera object here to deal with camera switch */ BL::Object b_cam = b_scene.camera(); if (b_override) b_cam = b_override; Camera prevcam = *(scene->camera); int frame_center = b_scene.frame_current(); float subframe_center = b_scene.frame_subframe(); float frame_center_delta = 0.0f; if (scene->need_motion() != Scene::MOTION_PASS && scene->camera->motion_position != Camera::MOTION_POSITION_CENTER) { float shuttertime = scene->camera->shuttertime; if (scene->camera->motion_position == Camera::MOTION_POSITION_END) { frame_center_delta = -shuttertime * 0.5f; } else { assert(scene->camera->motion_position == Camera::MOTION_POSITION_START); frame_center_delta = shuttertime * 0.5f; } float time = frame_center + subframe_center + frame_center_delta; int frame = (int)floorf(time); float subframe = time - frame; python_thread_state_restore(python_thread_state); b_engine.frame_set(frame, subframe); python_thread_state_save(python_thread_state); sync_camera_motion(b_render, b_cam, width, height, 0.0f); sync_objects(b_depsgraph, 0.0f); } /* always sample these times for camera motion */ motion_times.insert(-1.0f); motion_times.insert(1.0f); /* note iteration over motion_times set happens in sorted order */ foreach (float relative_time, motion_times) { /* center time is already handled. */ if (relative_time == 0.0f) { continue; } VLOG(1) << "Synchronizing motion for the relative time " << relative_time << "."; /* fixed shutter time to get previous and next frame for motion pass */ float shuttertime = scene->motion_shutter_time(); /* compute frame and subframe time */ float time = frame_center + subframe_center + frame_center_delta + relative_time * shuttertime * 0.5f; int frame = (int)floorf(time); float subframe = time - frame; /* change frame */ python_thread_state_restore(python_thread_state); b_engine.frame_set(frame, subframe); python_thread_state_save(python_thread_state); /* sync camera, only supports two times at the moment */ if (relative_time == -1.0f || relative_time == 1.0f) { sync_camera_motion(b_render, b_cam, width, height, relative_time); } /* sync object */ sync_objects(b_depsgraph, relative_time); } /* we need to set the python thread state again because this * function assumes it is being executed from python and will * try to save the thread state */ python_thread_state_restore(python_thread_state); b_engine.frame_set(frame_center, subframe_center); python_thread_state_save(python_thread_state); /* tag camera for motion update */ if (scene->camera->motion_modified(prevcam)) scene->camera->tag_update(); }