def apply(self): cam = None try: self.progressBar.setValue(0) self.progressBar.show() file_path = self.subForm.getFilePath() camera_text = self.subForm.getCameraText() camera_data = self.subForm.getCameraData() width, height = self.subForm.getImageResolution() self.progressBar.setValue(20) mkr_data_list = mayareadfile.read(file_path, image_width=width, image_height=height) self.progressBar.setValue(70) if camera_text == const.NEW_CAMERA_VALUE: cam = lib.create_new_camera() else: cam = camera_data self.progressBar.setValue(90) mayareadfile.create_nodes(mkr_data_list, cam=cam) finally: self.progressBar.setValue(100) self.progressBar.hide() # Update the camera comboBox with the created camera, or # the last used camera. selected_cameras = [cam] self.subForm.updateCameraList(self.subForm.camera_comboBox, self.subForm.camera_model, selected_cameras) return
def get_file_info_strings(file_path): """ Get the file path information, as user-readable strings. :param file_path: The marker file path to get info for. :type file_path: str :return Dictionary of various information about the given file path. :rtype: dict """ info = { 'num_points': '?', 'point_names': '?', 'frame_range': '?-?', 'start_frame': '?', 'end_frame': '?', 'lens_dist': '?', 'lens_undist': '?', 'positions': '?', 'has_camera_fov': '?', } file_info, mkr_data_list = mayareadfile.read(file_path) if isinstance(mkr_data_list, list) is False: return info fmt = get_file_path_format(file_path) info['fmt'] = fmt info['fmt_name'] = str(fmt.name) info['num_points'] = str(len(mkr_data_list)) start_frame = int(999999) end_frame = int(-999999) point_names = [] for mkr_data in mkr_data_list: name = mkr_data.get_name() point_names.append(name) # Get start / end frame. # We assume that there are X and Y keyframes on each frame, # therefore we do not test Y. x_keys = mkr_data.get_x() x_start = x_keys.get_start_frame() x_end = x_keys.get_end_frame() if x_start < start_frame: start_frame = x_start if x_end > end_frame: end_frame = x_end info['point_names'] = ' '.join(point_names) info['start_frame'] = start_frame info['end_frame'] = end_frame info['frame_range'] = '{0}-{1}'.format(start_frame, end_frame) info['lens_dist'] = file_info.marker_distorted info['lens_undist'] = file_info.marker_undistorted info['positions'] = file_info.bundle_positions info['has_camera_fov'] = bool(file_info.camera_field_of_view) return info
def get_file_info(file_path): """ Get the file path information. :param file_path: The marker file path to get info for. :type file_path: str :return: The file info. :rtype: FileInfo """ file_info, _ = mayareadfile.read(file_path) return file_info
def test_loadmarker_pftrack2dt_format(self): """ Test loading markers using the '.2dt'/'.txt' format. """ cam = lib_utils.create_new_camera() mkr_grp = lib_utils.create_new_marker_group(cam) mkr_data_list = [] paths = [ (self.get_data_path('pftrack', 'pftrack_corners_v001.txt'), (716.0, 572.0)), (self.get_data_path('pftrack', 'pftrack_corners_v002.txt'), (1920.0, 1080.0)), (self.get_data_path( 'pftrack', 'pftrack_hollywoodcameraworks_headtracking.txt'), (1920.0, 1080.0)), (self.get_data_path('pftrack', 'pftrack_user_track_docs.txt'), (1920.0, 1080.0)), ] for path, res in paths: print('Reading... %r (%s x %s)' % (path, res[0], res[1])) _, tmp_list = marker_read.read(path, image_width=res[0], image_height=res[1]) self.assertNotEqual(tmp_list, None) mkr_data_list += tmp_list # Create the markers num_nodes1 = len(maya.cmds.ls()) marker_read.create_nodes(mkr_data_list, cam=cam, mkr_grp=mkr_grp) num_nodes2 = len(maya.cmds.ls()) self.assertGreater(num_nodes2, num_nodes1) self.assertTrue(maya.cmds.objExists('lowerLeftSingleFrame_MKR')) self.assertTrue(maya.cmds.objExists('upperRightSingleFrame_MKR')) self.assertTrue(maya.cmds.objExists('upperLeft_MKR')) self.assertTrue(maya.cmds.objExists('upperRight_MKR')) self.assertTrue(maya.cmds.objExists('lowerLeft_MKR')) self.assertTrue(maya.cmds.objExists('lowerRight_MKR')) self.assertTrue(maya.cmds.objExists('Tracker0001_MKR')) self.assertTrue(maya.cmds.objExists('Tracker0002_MKR')) self.assertTrue(maya.cmds.objExists('head_MKR')) self.assertTrue(maya.cmds.objExists('head1_MKR')) self.assertTrue(maya.cmds.objExists('head2_MKR')) self.assertTrue(maya.cmds.objExists('head3_MKR')) self.assertTrue(maya.cmds.objExists('head4_MKR')) return
def get_file_info(file_path): """ Get the file path information. :param file_path: The marker file path to get info for. :type file_path: str :return Dictionary of various information about the given file path. :rtype: dict """ info = { 'num_points': '?', 'point_names': '?', 'frame_range': '?-?', 'start_frame': '?', 'end_frame': '?', } mkr_data_list = mayareadfile.read(file_path) if isinstance(mkr_data_list, list) is False: return info fmt = get_file_path_format(file_path) info['fmt'] = fmt info['fmt_name'] = str(fmt.name) info['num_points'] = str(len(mkr_data_list)) start_frame = int(999999) end_frame = int(-999999) point_names = [] for mkr_data in mkr_data_list: name = mkr_data.get_name() point_names.append(name) # Get start / end frame. # We assume that there are X and Y keyframes on each frame, # therefore we do not test Y. x_keys = mkr_data.get_x() x_start = x_keys.get_start_frame() x_end = x_keys.get_end_frame() if x_start < start_frame: start_frame = x_start if x_end > end_frame: end_frame = x_end info['point_names'] = pprint.pformat(point_names) info['start_frame'] = start_frame info['end_frame'] = end_frame info['frame_range'] = '{0}-{1}'.format(start_frame, end_frame) return info
def test_loadmarker_uvtrack_format(self): """ Test loading markers using the '.uv' format. """ cam = lib_utils.create_new_camera() mkr_grp = lib_utils.create_new_marker_group(cam) mkr_data_list = [] paths = [ self.get_data_path('uvtrack', 'test_v1.uv'), self.get_data_path('uvtrack', 'test_v3.uv'), self.get_data_path('uvtrack', 'test_v4.uv'), self.get_data_path('uvtrack', 'loadmarker_corners.uv'), self.get_data_path('uvtrack', 'cameraTrackRnD.uv'), self.get_data_path('uvtrack', 'stA.uv'), self.get_data_path('uvtrack', 'stA_with_emptyMarker.uv'), self.get_data_path('uvtrack', 'eye_fmt1_v001.uv'), self.get_data_path('uvtrack', 'eye_fmt2_v001.uv'), ] for path in paths: print('Reading... %r' % path) _, tmp_list = marker_read.read(path) self.assertNotEqual(tmp_list, None) mkr_data_list += tmp_list # Create the markers num_nodes1 = len(maya.cmds.ls()) marker_read.create_nodes(mkr_data_list, cam=cam, mkr_grp=mkr_grp) num_nodes2 = len(maya.cmds.ls()) self.assertGreater(num_nodes2, num_nodes1) self.assertTrue(maya.cmds.objExists('TopLeft_MKR')) self.assertEqual(maya.cmds.getAttr('TopLeft_MKR.translateX'), -0.5) self.assertEqual(maya.cmds.getAttr('TopLeft_MKR.translateY'), 0.5) self.assertTrue(maya.cmds.objExists('TopRight_MKR')) self.assertEqual(maya.cmds.getAttr('TopRight_MKR.translateX'), 0.5) self.assertEqual(maya.cmds.getAttr('TopRight_MKR.translateY'), 0.5) self.assertTrue(maya.cmds.objExists('BottomLeft_MKR')) self.assertEqual(maya.cmds.getAttr('BottomLeft_MKR.translateX'), -0.5) self.assertEqual(maya.cmds.getAttr('BottomLeft_MKR.translateY'), -0.5) self.assertTrue(maya.cmds.objExists('BottomRight_MKR')) self.assertEqual(maya.cmds.getAttr('BottomRight_MKR.translateX'), 0.5) self.assertEqual(maya.cmds.getAttr('BottomRight_MKR.translateY'), -0.5)
def get_file_path_format(text): """ Look up the Format from the file path. :param text: File path text. :returns: Format for the file path, or None if not found. :rtype: None or Format """ format_ = None formats = _get_file_path_formats(text) for fmt in formats: file_info, _ = mayareadfile.read(text) if file_info is not None: format_ = fmt break return format_
def test_loadmarker_tdetxt_format(self): """ Test loading markers using the '.uv' format. """ cam = lib_utils.create_new_camera() mkr_grp = lib_utils.create_new_marker_group(cam) mkr_data_list = [] paths = [ (self.get_data_path('3de_v4', 'loadmarker_corners.txt'), (1920.0, 1080.0)), # (self.get_data_path('3de_v4', '3de_export_cube.txt'), (1920.0, 1080.0)), # (self.get_data_path('3de_v4', 'FB1880_man_v05.txt'), (1920.0, 1080.0)), ] for path, res in paths: print('Reading... %r' % path) _, tmp_list = marker_read.read(path, image_width=res[0], image_height=res[1]) self.assertNotEqual(tmp_list, None) mkr_data_list += tmp_list # Create the markers num_nodes1 = len(maya.cmds.ls()) marker_read.create_nodes(mkr_data_list, cam=cam, mkr_grp=mkr_grp) num_nodes2 = len(maya.cmds.ls()) self.assertGreater(num_nodes2, num_nodes1) self.assertTrue(maya.cmds.objExists('TopLeft_MKR')) self.assertEqual(maya.cmds.getAttr('TopLeft_MKR.translateX'), -0.5) self.assertEqual(maya.cmds.getAttr('TopLeft_MKR.translateY'), 0.5) self.assertTrue(maya.cmds.objExists('TopRight_MKR')) self.assertEqual(maya.cmds.getAttr('TopRight_MKR.translateX'), 0.5) self.assertEqual(maya.cmds.getAttr('TopRight_MKR.translateY'), 0.5) self.assertTrue(maya.cmds.objExists('BottomLeft_MKR')) self.assertEqual(maya.cmds.getAttr('BottomLeft_MKR.translateX'), -0.5) self.assertEqual(maya.cmds.getAttr('BottomLeft_MKR.translateY'), -0.5) self.assertTrue(maya.cmds.objExists('BottomRight_MKR')) self.assertEqual(maya.cmds.getAttr('BottomRight_MKR.translateX'), 0.5) self.assertEqual(maya.cmds.getAttr('BottomRight_MKR.translateY'), -0.5)
def test_update_nodes(self): file_names = [ 'test_v1.uv', 'test_v3.uv', # only contains 1 point 'test_v3_with_3d_point.uv', ] for file_name in file_names: path = self.get_data_path('uvtrack', file_name) create_marker.main() # mkr = # mkr_list = [mkr] _, mkr_data_list = marker_read.read(path) mkr_list = lib_utils.get_selected_markers() marker_read.update_nodes(mkr_list, mkr_data_list, load_bundle_position=False) marker_read.update_nodes(mkr_list, mkr_data_list, load_bundle_position=True) return
def test_loadmarker_rz2_format(self): cam = lib_utils.create_new_camera() mkr_grp = lib_utils.create_new_marker_group(cam) mkr_data_list = [] paths = [ self.get_data_path('match_mover', 'loadmarker.rz2'), self.get_data_path('match_mover', 'loadmarker_corners.rz2'), # self.get_data_path('match_mover', '2dtracks.rz2'), # self.get_data_path('match_mover', 'cha_171_1020_atb_v001.rz2'), # self.get_data_path('match_mover', 'EP_1000_head_trackers_v002.rz2'), # self.get_data_path('match_mover', 'kipPointsMatchmover.rz2'), # self.get_data_path('match_mover', 'NonSequentialMatchmoverPoints.rz2'), ] for path in paths: _, tmp_list = marker_read.read(path) mkr_data_list += tmp_list # Create the markers num_nodes1 = len(maya.cmds.ls()) marker_read.create_nodes(mkr_data_list, cam=cam, mkr_grp=mkr_grp) num_nodes2 = len(maya.cmds.ls()) self.assertGreater(num_nodes2, num_nodes1) self.assertTrue(maya.cmds.objExists('TopLeft_MKR')) self.assertEqual(maya.cmds.getAttr('TopLeft_MKR.translateX'), -0.5) self.assertEqual(maya.cmds.getAttr('TopLeft_MKR.translateY'), 0.5) self.assertTrue(maya.cmds.objExists('TopRight_MKR')) self.assertEqual(maya.cmds.getAttr('TopRight_MKR.translateX'), 0.5) self.assertEqual(maya.cmds.getAttr('TopRight_MKR.translateY'), 0.5) self.assertTrue(maya.cmds.objExists('BottomLeft_MKR')) self.assertEqual(maya.cmds.getAttr('BottomLeft_MKR.translateX'), -0.5) self.assertEqual(maya.cmds.getAttr('BottomLeft_MKR.translateY'), -0.5) self.assertTrue(maya.cmds.objExists('BottomRight_MKR')) self.assertEqual(maya.cmds.getAttr('BottomRight_MKR.translateX'), 0.5) self.assertEqual(maya.cmds.getAttr('BottomRight_MKR.translateY'), -0.5)
def test_get_root_frames_from_markers_3(self): # Time Range start = 0 end = 41 maya.cmds.playbackOptions(animationStartTime=start, minTime=start, animationEndTime=end, maxTime=end) # Create Camera cam_tfm = maya.cmds.createNode('transform', name='cam_tfm') cam_shp = maya.cmds.createNode('camera', name='cam_shp', parent=cam_tfm) cam = mmapi.Camera(shape=cam_shp) # Create image plane path = self.get_data_path('operahouse', 'frame00.jpg') imgpl = maya.cmds.imagePlane(camera=cam_shp, fileName=path) maya.cmds.setAttr(imgpl[1] + '.useFrameExtension', 1) # Load Marker Data path = self.get_data_path('match_mover', 'loadmarker.rz2') _, mkr_data_list = marker_read.read(path) # Create Markers mkr_grp = mmapi.MarkerGroup().create_node(cam=cam) mkr_list = marker_read.create_nodes(mkr_data_list, cam=cam, mkr_grp=mkr_grp) # Calculate Root Frames min_frames_per_marker = 3 start_frame, end_frame = time_utils.get_maya_timeline_range_inner() frame_nums = mod.get_root_frames_from_markers(mkr_list, min_frames_per_marker, start_frame, end_frame) print 'frames:', frame_nums return
def apply(self): cam = None mkr_grp = None col = None file_path = self.subForm.getFilePath() load_mode = self.subForm.getLoadModeText() camera_text = self.subForm.getCameraText() camera_data = self.subForm.getCameraData() mkr_grp_text = self.subForm.getMarkerGroupText() mkr_grp_data = self.subForm.getMarkerGroupData() add_to_collection = self.subForm.getAddToCollectionValue() collection_text = self.subForm.getCollectionText() collection_data = self.subForm.getCollectionData() load_bnd_pos = self.subForm.getLoadBundlePositions() undist_mode = self.subForm.getDistortionModeText() use_overscan = self.subForm.getUseOverscanValue() undistorted = undist_mode == const.UNDISTORTION_MODE_VALUE width, height = self.subForm.getImageResolution() camera_field_of_view = None if use_overscan is True: camera_field_of_view = self.subForm.getCameraFieldOfViewValue() # Temporarily disable adding new Markers to the Active # Collection. config = userprefs_lib.get_config() key = userprefs_const.REG_EVNT_ADD_NEW_MKR_TO_KEY old_value = userprefs_lib.get_value(config, key) temp_value = userprefs_const.REG_EVNT_ADD_NEW_MKR_TO_NONE_VALUE userprefs_lib.set_value(config, key, temp_value) try: self.progressBar.setValue(0) self.progressBar.show() with undoutils.undo_chunk_context(): _, mkr_data_list = mayareadfile.read( file_path, image_width=width, image_height=height, undistorted=undistorted, ) self.progressBar.setValue(50) if load_mode == const.LOAD_MODE_NEW_VALUE: # Get Camera and MarkerGroup. if camera_text == const.NEW_CAMERA_VALUE: cam = lib.create_new_camera() mkr_grp = lib.create_new_marker_group(cam) else: cam = camera_data if mkr_grp_text == const.NEW_MARKER_GROUP_VALUE: mkr_grp = lib.create_new_marker_group(cam) else: mkr_grp = mkr_grp_data self.progressBar.setValue(60) # Get Collection col = None if add_to_collection is True: if collection_text == const.NEW_COLLECTION_VALUE: col = col_lib.create_collection() else: col = collection_data self.progressBar.setValue(70) mayareadfile.create_nodes( mkr_data_list, cam=cam, mkr_grp=mkr_grp, col=col, with_bundles=True, load_bundle_position=load_bnd_pos, camera_field_of_view=camera_field_of_view, ) elif load_mode == const.LOAD_MODE_REPLACE_VALUE: self.progressBar.setValue(60) mkr_list = lib.get_selected_markers() # NOTE: camera_field_of_view can only be from one # camera, because (we assume) only one MarkerData # file can be loaded at once. mayareadfile.update_nodes( mkr_list, mkr_data_list, load_bundle_position=load_bnd_pos, camera_field_of_view=camera_field_of_view) else: raise ValueError('Load mode is not valid: %r' % load_mode) self.progressBar.setValue(99) lib.trigger_maya_to_refresh() finally: self.progressBar.setValue(100) self.progressBar.hide() # Restore original config value. lib.deferred_revert_of_config_value(config, key, old_value) # Update the camera comboBox with the created camera, or # the last used camera. all_camera_nodes = lib.get_cameras() selected_cameras = [cam] active_camera = cam self.subForm.updateCameraList(self.subForm.camera_comboBox, self.subForm.camera_model, all_camera_nodes, selected_cameras, active_camera) active_camera = cam active_mkr_grp = mkr_grp mkr_grp_nodes = lib.get_marker_groups(active_camera) self.subForm.updateMarkerGroupList( self.subForm.markerGroup_comboBox, self.subForm.markerGroup_model, active_mkr_grp, mkr_grp_nodes) # Update the list of Collections, and pick the last used # Collection. active_col = col col_list = col_lib.get_collections() self.subForm.updateCollectionList(self.subForm.collection_comboBox, self.subForm.collection_model, active_col, col_list) # Update config file with latest values. config = get_config() if config is not None: config.set_value("data/use_overscan", use_overscan) config.set_value("data/load_bundle_position", load_bnd_pos) config.set_value("data/distortion_mode", undist_mode) config.set_value("data/load_mode", load_mode) config.write() return
def apply(self): cam = None mkr_grp = None file_path = self.subForm.getFilePath() load_mode = self.subForm.getLoadModeText() camera_text = self.subForm.getCameraText() camera_data = self.subForm.getCameraData() mkr_grp_text = self.subForm.getMarkerGroupText() mkr_grp_data = self.subForm.getMarkerGroupData() load_bnd_pos = self.subForm.getLoadBundlePositions() undist_mode = self.subForm.getDistortionModeText() use_overscan = self.subForm.getUseOverscanValue() undistorted = undist_mode == const.UNDISTORTION_MODE_VALUE width, height = self.subForm.getImageResolution() camera_field_of_view = None if use_overscan is True: camera_field_of_view = self.subForm.getCameraFieldOfViewValue() try: self.progressBar.setValue(0) self.progressBar.show() with undoutils.undo_chunk_context(): _, mkr_data_list = mayareadfile.read( file_path, image_width=width, image_height=height, undistorted=undistorted, ) self.progressBar.setValue(50) if load_mode == const.LOAD_MODE_NEW_VALUE: if camera_text == const.NEW_CAMERA_VALUE: cam = lib.create_new_camera() mkr_grp = lib.create_new_marker_group(cam) else: cam = camera_data if mkr_grp_text == const.NEW_MARKER_GROUP_VALUE: mkr_grp = lib.create_new_marker_group(cam) else: mkr_grp = mkr_grp_data self.progressBar.setValue(60) mayareadfile.create_nodes( mkr_data_list, cam=cam, mkr_grp=mkr_grp, with_bundles=True, load_bundle_position=load_bnd_pos, camera_field_of_view=camera_field_of_view, ) elif load_mode == const.LOAD_MODE_REPLACE_VALUE: self.progressBar.setValue(60) mkr_list = lib.get_selected_markers() # NOTE: camera_field_of_view can only be from one # camera, because (we assume) only one MarkerData # file can be loaded at once. mayareadfile.update_nodes( mkr_list, mkr_data_list, load_bundle_position=load_bnd_pos, camera_field_of_view=camera_field_of_view) else: raise ValueError('Load mode is not valid: %r' % load_mode) self.progressBar.setValue(99) lib.trigger_maya_to_refresh() finally: self.progressBar.setValue(100) self.progressBar.hide() # Update the camera comboBox with the created camera, or # the last used camera. all_camera_nodes = lib.get_cameras() selected_cameras = [cam] active_camera = cam self.subForm.updateCameraList(self.subForm.camera_comboBox, self.subForm.camera_model, all_camera_nodes, selected_cameras, active_camera) active_camera = cam active_mkr_grp = mkr_grp mkr_grp_nodes = lib.get_marker_groups(active_camera) self.subForm.updateMarkerGroupList( self.subForm.markerGroup_comboBox, self.subForm.markerGroup_model, active_mkr_grp, mkr_grp_nodes) # Update config file with latest values. config = get_config() if config is not None: config.set_value("data/use_overscan", use_overscan) config.set_value("data/load_bundle_position", load_bnd_pos) config.set_value("data/distortion_mode", undist_mode) config.set_value("data/load_mode", load_mode) config.write() return
def apply(self): cam = None mkr_grp = None file_path = self.subForm.getFilePath() load_mode = self.subForm.getLoadModeText() camera_text = self.subForm.getCameraText() camera_data = self.subForm.getCameraData() mkr_grp_text = self.subForm.getMarkerGroupText() mkr_grp_data = self.subForm.getMarkerGroupData() load_bnd_pos = self.subForm.getLoadBundlePositions() undist_mode = self.subForm.getDistortionModeText() undistorted = undist_mode == const.UNDISTORTION_MODE_VALUE width, height = self.subForm.getImageResolution() try: self.progressBar.setValue(0) self.progressBar.show() with undoutils.undo_chunk_context(): _, mkr_data_list = mayareadfile.read( file_path, image_width=width, image_height=height, undistorted=undistorted, ) self.progressBar.setValue(50) if load_mode == const.LOAD_MODE_NEW_VALUE: if camera_text == const.NEW_CAMERA_VALUE: cam = lib.create_new_camera() else: cam = camera_data if mkr_grp_text == const.NEW_MARKER_GROUP_VALUE: mkr_grp = lib.create_new_marker_group(cam) else: mkr_grp = mkr_grp_data self.progressBar.setValue(60) mayareadfile.create_nodes( mkr_data_list, cam=cam, mkr_grp=mkr_grp, with_bundles=True, load_bundle_position=load_bnd_pos, ) elif load_mode == const.LOAD_MODE_REPLACE_VALUE: self.progressBar.setValue(60) mkr_list = lib.get_selected_markers() mayareadfile.update_nodes(mkr_list, mkr_data_list) else: raise ValueError('Load mode is not valid: %r' % load_mode) self.progressBar.setValue(99) lib.trigger_maya_to_refresh() finally: self.progressBar.setValue(100) self.progressBar.hide() # Update the camera comboBox with the created camera, or # the last used camera. all_camera_nodes = lib.get_cameras() selected_cameras = [cam] active_camera = cam self.subForm.updateCameraList( self.subForm.camera_comboBox, self.subForm.camera_model, all_camera_nodes, selected_cameras, active_camera ) active_camera = cam active_mkr_grp = mkr_grp mkr_grp_nodes = lib.get_marker_groups(active_camera) self.subForm.updateMarkerGroupList( self.subForm.markerGroup_comboBox, self.subForm.markerGroup_model, active_mkr_grp, mkr_grp_nodes ) return
def test_opera_house(self): """ Load pre-tracked Markers for the 'opera house' image sequence, then solve it. http://danielwedge.com/fmatrix/operahouse.html """ start = 0 end = 41 # Set Time Range maya.cmds.playbackOptions( animationStartTime=start, minTime=start, animationEndTime=end, maxTime=end ) # Camera cam_tfm = maya.cmds.createNode('transform', name='cam_tfm') cam_shp = maya.cmds.createNode('camera', name='cam_shp', parent=cam_tfm) maya.cmds.setAttr(cam_tfm + '.rotateOrder', 2) # zxy maya.cmds.setAttr(cam_shp + '.focalLength', 14) maya.cmds.setAttr(cam_shp + '.horizontalFilmAperture', 5.4187 / 25.4) maya.cmds.setAttr(cam_shp + '.verticalFilmAperture', 4.0640 / 25.4) cam = mmapi.Camera(shape=cam_shp) # Set Camera Keyframes cam_data = { '0': (-0.19889791581420663, 0.5591321634949238, 7.258789219735233, -1.9999507874015703, -0.3999999999999992, 0.0), '22': (-4.840404384215566, 0.7543627646977502, 6.3465857678271425, -3.0709513272069815, -36.91024116734281, 0.0), '41': (-8.584368967987194, 0.6990718939718145, 5.508167213044364, -1.4738793091011815, -54.30997787050599, 0.0) } for key in sorted(cam_data.keys()): frame = int(key) for i, attr in enumerate(['tx', 'ty', 'tz', 'rx', 'ry', 'rz']): value = cam_data[key][i] maya.cmds.setKeyframe(cam_tfm, attribute=attr, time=frame, value=value) maya.cmds.setKeyframe(cam_shp, attribute='focalLength', time=start, value=14.0) maya.cmds.setKeyframe(cam_shp, attribute='focalLength', time=end, value=14.0) # Create image plane path = self.get_data_path('operahouse', 'frame00.jpg') imgpl = maya.cmds.imagePlane( camera=cam_shp, fileName=path ) maya.cmds.setAttr(imgpl[1] + '.useFrameExtension', 1) maya.cmds.setAttr(imgpl[1] + '.depth', 2000) maya.cmds.setAttr(imgpl[1] + '.frameCache', 0) maya.cmds.setAttr(imgpl[1] + '.coverageX', 3072) maya.cmds.setAttr(imgpl[1] + '.coverageY', 2304) # Create Horizon Line cir = maya.cmds.circle(name='horizon', nrx=0, nry=1, nrz=0) maya.cmds.setAttr(cir[1] + ".radius", 3000) # Create Cube for Opera House cube = maya.cmds.polyCube() maya.cmds.setAttr(cube[0] + ".ty", 0.5) maya.cmds.setAttr(cube[0] + ".sx", 2.68) maya.cmds.setAttr(cube[0] + ".sy", 0.91625416) maya.cmds.setAttr(cube[0] + ".sz", 1.68658365) # Marker Group mkr_grp = mmapi.MarkerGroup().create_node(cam=cam) mkr_grp_node = mkr_grp.get_node() # Bundle Group bnd_grp = maya.cmds.createNode('transform', name='bundleGroup') bnd_fg_grp = maya.cmds.createNode( 'transform', name='bundles_fg', parent=bnd_grp) bnd_bg_grp = maya.cmds.createNode( 'transform', name='bundles_bg', parent=bnd_grp) # Load Markers fg_points = [ 'Track_01', 'Track_02', 'Track_05', 'Track_06', 'Track_08', 'Track_09', 'Track_10', 'Track_11', 'Track_19', 'Track_20', 'Track_21', 'Track_22', 'Track_23', 'Track_23', 'Track_24', 'Track_25', 'Track_26', 'Track_27', ] bg_points = [ 'Track_03', 'Track_04', 'Track_07', 'Track_12', 'Track_13', 'Track_14', 'Track_15', 'Track_16', 'Track_17', 'Track_18', 'Track_28', 'Track_29', 'Track_30', 'Track_31', ] bnd_positions = { 'Track_23': (-0.7669678476654883, 0.704741253611808, 0.11480582185051777), 'Track_14': (-6.096859889443822, 2.0552736121532478, -64.25806442305448), 'Track_12': (45.11056705173852, 2.602519222901666, -43.16772737415769), 'Track_13': (-11.331222134074189, -0.9161249928992397, -63.60343691220178), 'Track_28': (12.97847320083373, 0.4908757961951475, -6.558878377403925), 'Track_24': (-0.9577362080844809, 0.11947272894636578, -0.29860515939718035), 'Track_25': (-0.3816240705349317, 0.09511793539283707, 0.5968218516602972), 'Track_05': (-0.5497538933513093, 0.9121450956455763, 0.0689419211208016), 'Track_06': (0.6442115545215732, 0.09146863102772763, 0.2698159600733472), 'Track_02': (-1.1928085448379213, 0.06849164070024401, 0.741609523996595), 'Track_17': (4.101733117764308, 0.4416977194116366, -20.775735845844235), 'Track_16': (10.499779696104385, 2.4959245952203037, -61.65315035391216), 'Track_21': (0.4422885021421483, 0.15594114410956195, -0.4586671394741284), 'Track_18': (13.426726902476766, 2.208127581689255, -62.440721369338476), 'Track_27': (-1.203371663768503, 0.07727436882970459, -0.34432924439358475), 'Track_07': (24.82344439444535, 3.8981611004590917, -62.57148439047777), 'Track_26': (-1.036542158437551, 0.1301250303434169, 0.6183349238312523), 'Track_11': (-1.2868698932117608, 0.07508027422294668, -0.6923287330737453), 'Track_09': (-1.1210978513200678, -0.0009538700668097195, -0.7481409812887209), 'Track_20': (0.5370453995103619, 0.32144750391315535, 0.10037404391850258), 'Track_08': (-0.35711469535141427, 0.8134673956410489, -0.8873816770491396), 'Track_19': (-1.0708190128497155, 0.5849715587489718, 0.22909459498373133), 'Track_10': (-0.8256010837265352, 0.04548785302325305, -0.6865934949556973), 'Track_30': (12.219883964568602, 1.6676763053004873, -63.511794156133575), 'Track_22': (-0.42435005852350927, 0.6386843510112235, -1.0271747982989685), 'Track_31': (14.4768210901898, 1.5761955139450978, -40.10088917167338), 'Track_15': (-0.17540615158899264, 2.5048877383268424, -64.10912011449136), 'Track_29': (15.264518808431728, 1.8337698745022983, -62.076762425418536), 'Track_03': (311.42375656555913, 16.402469194090923, -179.38329132993437), 'Track_01': (-1.0890118590423876, 0.5109764471108498, -0.707187214616633), 'Track_04': (209.73939576288353, 12.878819985707446, -150.30617721944793) } mkr_fg_grp = maya.cmds.createNode('transform', name='fg', parent=mkr_grp_node) mkr_bg_grp = maya.cmds.createNode('transform', name='bg', parent=mkr_grp_node) path = self.get_data_path('match_mover', 'loadmarker.rz2') _, mkr_data_list = marker_read.read(path) print 'mkr_data_list', mkr_data_list mkr_list = marker_read.create_nodes( mkr_data_list, cam=cam, mkr_grp=mkr_grp ) mkr_fg_list = [] mkr_bg_list = [] for mkr in mkr_list: mkr_node = mkr.get_node() mgrp = mkr_grp_node bgrp = bnd_grp pos = None for name in fg_points: if name in mkr_node: if name in bnd_positions: pos = bnd_positions[name] mgrp = mkr_fg_grp bgrp = bnd_fg_grp mkr_fg_list.append(mkr) break for name in bg_points: if name in mkr_node: if name in bnd_positions: pos = bnd_positions[name] mgrp = mkr_bg_grp bgrp = bnd_bg_grp mkr_bg_list.append(mkr) break maya.cmds.parent(mkr_node, mgrp, relative=True) bnd = mkr.get_bundle() bnd_node = bnd.get_node() plug_tx = bnd_node + '.tx' plug_ty = bnd_node + '.ty' plug_tz = bnd_node + '.tz' maya.cmds.setAttr(plug_tx, pos[0]) maya.cmds.setAttr(plug_ty, pos[1]) maya.cmds.setAttr(plug_tz, pos[2]) maya.cmds.parent(bnd_node, bgrp, relative=True) # bnd_node = bnd.get_node() # plug_tx = bnd_node + '.tx' # plug_ty = bnd_node + '.ty' # plug_tz = bnd_node + '.tz' # maya.cmds.setAttr(plug_tx, lock=True) # maya.cmds.setAttr(plug_ty, lock=True) # maya.cmds.setAttr(plug_tz, lock=True) # Frames # prim = [0, 22, 41] # sec = [3, 8, 12, 27, 33, 38] # prim = [0, 3, 8, 12, 22, 27, 33, 38, 41] frm_list = [] frm = mmapi.Frame(0, tags=['primary', '1', 'single001']) frm_list.append(frm) frm = mmapi.Frame(3, tags=['primary', '1', '2', 'single002']) frm_list.append(frm) frm = mmapi.Frame(8, tags=['primary', '2', '3', 'single003']) frm_list.append(frm) frm = mmapi.Frame(12, tags=['primary', '3', '4', 'single004']) frm_list.append(frm) frm = mmapi.Frame(22, tags=['primary', '4', '5', 'single005']) frm_list.append(frm) frm = mmapi.Frame(27, tags=['primary', '5', '6', 'single006']) frm_list.append(frm) frm = mmapi.Frame(33, tags=['primary', '6', '7', 'single007']) frm_list.append(frm) frm = mmapi.Frame(38, tags=['primary', '7', '8', 'single008']) frm_list.append(frm) frm = mmapi.Frame(41, tags=['primary', '8', 'single009']) frm_list.append(frm) root_frm_list = [] not_root_frm_list = [] for f in [0, 3, 8, 12, 16, 22, 27, 33, 38, 41]: frm = mmapi.Frame(f) root_frm_list.append(frm) for f in range(0, 41): frm = mmapi.Frame(f) not_root_frm_list.append(frm) sol_list = [] sol = mmapi.SolverStandard() sol.set_single_frame(False) sol.set_root_frame_list(root_frm_list) sol.set_frame_list(not_root_frm_list) sol.set_root_frame_strategy(mmapi.ROOT_FRAME_STRATEGY_GLOBAL_VALUE) sol.set_only_root_frames(False) sol.set_global_solve(False) sol._robust_loss_type = 1 sol._robust_loss_scale = 10.0 sol._auto_attr_blocks = True sol._triangulate_bundles = False sol_list.append(sol) # Collection col = mmapi.Collection() col.create_node('mySolverCollection') col.add_solver_list(sol_list) # Add markers col.add_marker_list(mkr_fg_list) col.add_marker_list(mkr_bg_list) # Attributes attr_cam_tx = mmapi.Attribute(cam_tfm + '.tx') attr_cam_ty = mmapi.Attribute(cam_tfm + '.ty') attr_cam_tz = mmapi.Attribute(cam_tfm + '.tz') attr_cam_rx = mmapi.Attribute(cam_tfm + '.rx') attr_cam_ry = mmapi.Attribute(cam_tfm + '.ry') attr_cam_rz = mmapi.Attribute(cam_tfm + '.rz') attr_cam_focal = mmapi.Attribute(cam_shp + '.focalLength') col.add_attribute(attr_cam_tx) col.add_attribute(attr_cam_ty) col.add_attribute(attr_cam_tz) col.add_attribute(attr_cam_rx) col.add_attribute(attr_cam_ry) col.add_attribute(attr_cam_rz) mkr_list = col.get_marker_list() for mkr in mkr_list: bnd = mkr.get_bundle() bnd_node = bnd.get_node() attr_tx = mmapi.Attribute(bnd_node + '.tx') attr_ty = mmapi.Attribute(bnd_node + '.ty') attr_tz = mmapi.Attribute(bnd_node + '.tz') col.add_attribute(attr_tx) col.add_attribute(attr_ty) col.add_attribute(attr_tz) # save the output path = self.get_data_path('test_solve_opera_house_before.ma') maya.cmds.file(rename=path) maya.cmds.file(save=True, type='mayaAscii', force=True) # Run solver! results = col.execute() # Ensure the values are correct for res in results: success = res.get_success() err = res.get_final_error() print 'err', err, 'success', success # Set Deviation mmapi.update_deviation_on_markers(mkr_list, results) mmapi.update_deviation_on_collection(col, results) # save the output path = self.get_data_path('test_solve_opera_house_after.ma') maya.cmds.file(rename=path) maya.cmds.file(save=True, type='mayaAscii', force=True) self.checkSolveResults(results) return