Beispiel #1
0
 def updateOverscanValues(self):
     x = 100.0
     y = 100.0
     file_info = self.getFileInfo()
     camera = self.getCameraData()
     if file_info is not None and camera is not None:
         mkr_grp = None
         file_fovs = file_info.camera_field_of_view
         x, y = fieldofview.calculate_overscan_ratio(
             camera,
             mkr_grp,
             file_fovs
         )
         # NOTE: Inverse the overscan value, because the user will
         # be more comfortable with numbers above 100%.
         x = 1.0 / x
         y = 1.0 / y
         x *= 100.0
         y *= 100.0
     label_x = 'Width: %.2f' % x
     label_y = 'Height: %.2f' % y
     label_x += '%'
     label_y += '%'
     self.overscanX_label.setText(label_x)
     self.overscanY_label.setText(label_y)
     return
Beispiel #2
0
    def updateOverscanValues(self):
        label_x = ''
        label_y = ''
        data_source = ''

        use_overscan = self.getUseOverscanValue()
        load_mode_text = self.getLoadModeText()
        if use_overscan is False:
            if load_mode_text == const.LOAD_MODE_NEW_VALUE:
                data_source = 'from default values'
                label_x = 'Width: %.2f' % 100.0
                label_y = 'Height: %.2f' % 100.0
                label_x += '%'
                label_y += '%'
                label_y += ' (%s)' % data_source
            self.overscanX_label.setText(label_x)
            self.overscanY_label.setText(label_y)
            return

        file_info = self.getFileInfo()
        camera = self.getCameraData()
        has_file_data = (file_info is not None
                         and camera is not None
                         and isinstance(file_info.camera_field_of_view, list))
        if load_mode_text == const.LOAD_MODE_NEW_VALUE:
            if has_file_data is True:
                data_source = 'from file'

                # Purposefully do not allow Marker Group to influence the
                # value shown to the user.
                mkr_grp = None
                file_fovs = file_info.camera_field_of_view
                x, y = fieldofview.calculate_overscan_ratio(
                    camera,
                    mkr_grp,
                    file_fovs
                )
                # NOTE: Inverse the overscan value, because the user will
                # be more comfortable with numbers above 100%.
                x = 1.0 / x
                y = 1.0 / y
                x *= 100.0
                y *= 100.0
            else:
                data_source = 'from default values'
                x = 100.0
                y = 100.0
            label_x = 'Width: %.2f' % x
            label_y = 'Height: %.2f' % y
            label_x += '%'
            label_y += '%'
        elif load_mode_text == const.LOAD_MODE_REPLACE_VALUE:
            label_x = 'Width: ?'
            label_y = 'Height: ?'
            data_source = 'from selected Marker'

        label_y += ' (%s)' % data_source
        self.overscanX_label.setText(label_x)
        self.overscanY_label.setText(label_y)
        return
Beispiel #3
0
def update_nodes(mkr_list, mkr_data_list,
                 load_bundle_position=None,
                 camera_field_of_view=None):
    """
    Update the given mkr_list with data from mkr_data_list.
    The length of both lists must match.

    :param mkr_list: Markers to update.
    :type mkr_list: [Marker, ..]

    :param mkr_data_list: The MarkerData list to search for a match.
    :type mkr_data_list: [MarkerData, ..]

    :param load_bundle_position: Apply the 3D positions to bundle.
    :type load_bundle_position: bool

    :param camera_field_of_view: The camera field of view of the
                                 original camera with this 2D data.
    :type camera_field_of_view: [(int, float, float)]

    :returns: List of Marker objects that were changed.
    :rtype: [Marker, ..]
    """
    if load_bundle_position is None:
        load_bundle_position = True
    assert isinstance(mkr_list, (list, tuple, set))
    assert isinstance(mkr_data_list, (list, tuple, set))
    assert isinstance(load_bundle_position, bool)
    assert camera_field_of_view is None \
        or isinstance(camera_field_of_view, (list, tuple))
    selected_nodes = maya.cmds.ls(selection=True, long=True) or []

    # Calculate overscan for marker's camera node.
    overscan_per_camera = {}
    if camera_field_of_view is not None:
        for mkr in mkr_list:
            mkr_grp = mkr.get_marker_group()
            cam = mkr.get_camera()
            cam_shp = cam.get_shape_node()
            if cam_shp in overscan_per_camera:
                continue
            overscan_x, overscan_y = fieldofview.calculate_overscan_ratio(
                cam,
                mkr_grp,
                camera_field_of_view
            )
            overscan_per_camera[cam_shp] = (overscan_x, overscan_y)

    mkr_list_changed = []
    if len(mkr_list) == 1 and len(mkr_data_list) == 1:
        mkr = mkr_list[0]
        cam = mkr.get_camera()
        bnd = mkr.get_bundle()
        mkr_data = mkr_data_list[0]
        cam_shp = cam.get_shape_node()
        fallback_overscan = (1.0, 1.0)
        overscan_x, overscan_y = overscan_per_camera.get(
            cam_shp, fallback_overscan
        )
        _update_node(
            mkr, bnd, mkr_data,
            load_bundle_position,
            overscan_x, overscan_y
        )
    else:
        # Make a copy of mkr_list and mkr_data_list, to avoid any
        # posiblity of the given arguments mkr_list and mkr_data_list
        # being modified indirectly (which can happen in Python).
        mkr_list = list(mkr_list)
        mkr_data_list = list(mkr_data_list)
        while len(mkr_list) > 0:
            mkr = mkr_list.pop(0)
            mkr_data = _find_marker_data(mkr, mkr_data_list)
            if mkr_data is None:
                continue
            cam = mkr.get_camera()
            bnd = mkr.get_bundle()
            cam_shp = cam.get_shape_node()
            fallback_overscan = (1.0, 1.0)
            overscan_x, overscan_y = overscan_per_camera.get(
                cam_shp, fallback_overscan,
            )
            _update_node(
                mkr, bnd, mkr_data,
                load_bundle_position,
                overscan_x, overscan_y
            )
            mkr_data_list.remove(mkr_data)
            mkr_list_changed.append(mkr)

    mkr_nodes_changed = [mkr.get_node() for mkr in mkr_list_changed]
    if len(mkr_nodes_changed) > 0:
        maya.cmds.select(mkr_nodes_changed, replace=True)
    else:
        maya.cmds.select(selected_nodes, replace=True)
    return mkr_list_changed
Beispiel #4
0
def create_nodes(mkr_data_list,
                 cam=None,
                 mkr_grp=None,
                 col=None,
                 with_bundles=None,
                 load_bundle_position=None,
                 camera_field_of_view=None):
    """
    Create Markers for all given MarkerData objects

    :param mkr_data_list: List of MarkerData with data for creating
                          markers.
    :type mkr_data_list: [MarkerData, ..]

    :param cam: Camera to create Markers under.
    :type cam: Camera

    :param mkr_grp: Marker Group, under cam, that the markers will
                    be created under.
    :type mkr_grp: MarkerGroup

    :param col: Collection to add Markers to.
    :type col: Collection or None

    :param with_bundles: Create a bundle for each Marker.
    :type with_bundles: bool

    :param load_bundle_position: Apply the 3D positions to bundle.
    :type load_bundle_position: bool

    :param camera_field_of_view: The camera field of view of the
                                 original camera with this 2D data.
    :type camera_field_of_view: [(int, float, float)]

    :returns: List of Markers.
    :rtype: [Marker, ..]
    """
    if with_bundles is None:
        with_bundles = True
    if load_bundle_position is None:
        load_bundle_position = True
    assert isinstance(cam, mmapi.Camera)
    assert isinstance(mkr_grp, mmapi.MarkerGroup)
    assert col is None or isinstance(col, mmapi.Collection)
    assert isinstance(with_bundles, bool)
    assert isinstance(load_bundle_position, bool)
    assert camera_field_of_view is None \
        or isinstance(camera_field_of_view, (list, tuple))

    selected_nodes = maya.cmds.ls(selection=True, long=True) or []

    overscan_x = 1.0
    overscan_y = 1.0
    if camera_field_of_view is not None:
        overscan_x, overscan_y = fieldofview.calculate_overscan_ratio(
            cam,
            mkr_grp,
            camera_field_of_view
        )

    mkr_nodes = []
    mkr_list = []
    for mkr_data in mkr_data_list:
        # Create the nodes
        mkr, bnd = __create_node(
            mkr_data, cam, mkr_grp,
            with_bundles,
        )
        mkr_nodes.append(mkr.get_node())
        if mkr is not None:
            # Set attributes and add into list
            __set_node_data(
                mkr, bnd, mkr_data,
                load_bundle_position,
                overscan_x, overscan_y
            )
            mkr_list.append(mkr)

    if len(mkr_list) > 0 and col is not None:
        assert isinstance(col, mmapi.Collection)
        col.add_marker_list(mkr_list)

    if len(mkr_nodes) > 0:
        maya.cmds.select(mkr_nodes, replace=True)
    else:
        maya.cmds.select(selected_nodes, replace=True)
    return mkr_list