Esempio n. 1
0
    def _import_image_seq(self, path, sg_publish_data):
        """
        Import and image sequence and assign it to the selected cameras.

        :param str path: The file path to load.
        :param dict sg_publish_data: Shotgun data dictionary with all the standard publish fields.
        """
        app = self.parent
        path, start, end, step = get_hash_path_and_range_info_from_seq(path)
        name = app.engine.context.entity["name"]

        if tde4.getNoCameras():
            selected_cameras = filter(is_sequence_camera,
                                      tde4.getCameraList(True))
            if selected_cameras:
                app.logger.info(
                    "%d sequence cameras selected, assigning to all",
                    len(selected_cameras))
                for cam_id in selected_cameras:
                    current_name = tde4.getCameraName(cam_id)
                    app.logger.debug("Current camera: '%s'", current_name)
                    if current_name.startswith(name):
                        app.logger.info(
                            "'%s' already has name referring to Shot",
                            current_name)
                    else:
                        cam_name = name
                        count = 0
                        while tde4.findCameraByName(cam_name):
                            count += 1
                            cam_name = "{}__{:02}".format(name, count)
                        app.logger.info("Renaming '%s' to '%s'", current_name,
                                        cam_name)
                        tde4.setCameraName(cam_id, cam_name)
                    app.logger.debug("setCameraSequenceAttr: %s, %d, %d, %d",
                                     cam_id, start, end, step)
                    tde4.setCameraSequenceAttr(cam_id, start, end, step)
                    app.logger.debug("setCameraFrameOffset: %s, %d", cam_id,
                                     start)
                    tde4.setCameraFrameOffset(cam_id, start)
                    app.logger.debug(
                        "setCameraFrameRangeCalculationFlag: %s, 1", cam_id)
                    tde4.setCameraFrameRangeCalculationFlag(cam_id, 1)
                    app.logger.debug("setCameraPath: %s, %s", cam_id, path)
                    tde4.setCameraPath(cam_id, path)
            else:
                QtGui.QMessageBox.warning(
                    None, "No sequence cameras selected",
                    "Please select a sequence camera and try again")
        else:
            QtGui.QMessageBox.warning(
                None, "No cameras exist",
                "Please create a sequence camera and try again")
Esempio n. 2
0
def apply_to_camera(pgroup_id, cam_id, lens_id, options, file_data):
    """
    Replace the camera and lens with the given options.
    """
    camera_data = file_data.get('data', dict())

    # Set image file path
    file_start_frame = camera_data.get('start_frame')
    file_end_frame = camera_data.get('end_frame')
    plate_load = options.get('plate_load')
    plate_path = options.get('plate_path')
    if (plate_load and file_start_frame is not None
            and file_end_frame is not None and plate_path):
        plate_path = os.path.normpath(plate_path)
        tde4.setCameraPath(cam_id, plate_path)

        # Set plate frame range
        file_start = int(file_start_frame)
        file_end = int(file_end_frame)
        tde4.setCameraSequenceAttr(cam_id, file_start, file_end, 1)
        if SUPPORT_CAMERA_FRAME_OFFSET is True:
            tde4.setCameraFrameOffset(cam_id, file_start)

    # Set pixel aspect ratio
    par = options.get('par')
    if par:
        par = float(par)
        tde4.setLensPixelAspect(lens_id, par)

    # Set Camera name
    set_name = options.get('set_cam_name')
    if set_name:
        cam_name = camera_data.get('name', '')
        if cam_name:
            tde4.setCameraName(cam_id, cam_name)
        lens_name = cam_name + '_lens'
        if lens_name:
            tde4.setLensName(lens_id, lens_name)

    attr_data = camera_data.get('attr', dict())

    # Set film back
    #
    # Note: These values cannot be animated in 3DE, even if in Maya
    # they were animated. We only take the first value in the list and
    # assume the film back value is constant.
    fbk_size = options.get('fbk_size')
    filmBackWidthSamples = attr_data.get('filmBackWidth')
    filmBackHeightSamples = attr_data.get('filmBackHeight')
    if fbk_size and filmBackWidthSamples and filmBackHeightSamples:
        value_x = filmBackWidthSamples[0][-1] * MILLIMETERS_TO_CENTIMETRES
        value_y = filmBackHeightSamples[0][-1] * MILLIMETERS_TO_CENTIMETRES
        tde4.setLensFBackWidth(lens_id, value_x)
        tde4.setLensFBackHeight(lens_id, value_y)

    fbk_offset = options.get('fbk_offset')
    filmBackOffsetXSamples = attr_data.get('filmBackOffsetX')
    filmBackOffsetYSamples = attr_data.get('filmBackOffsetY')
    if fbk_offset and filmBackOffsetXSamples and filmBackOffsetYSamples:
        value_x = filmBackOffsetXSamples[0][-1] * MILLIMETERS_TO_CENTIMETRES
        value_y = filmBackOffsetYSamples[0][-1] * MILLIMETERS_TO_CENTIMETRES
        tde4.setLensLensCenterX(lens_id, value_x)
        tde4.setLensLensCenterY(lens_id, value_y)

    # Set focal length
    file_start_frame = camera_data.get('start_frame')
    file_end_frame = camera_data.get('end_frame')
    chosen_start_frame = options.get('start_frame')
    chosen_end_frame = options.get('end_frame')
    fl = options.get('fl')
    focalLengthSamples = attr_data.get('focalLength')
    if (fl and focalLengthSamples and isinstance(file_start_frame, (int, long))
            and isinstance(file_end_frame, (int, long))
            and isinstance(chosen_start_frame, basestring)
            and isinstance(chosen_end_frame, basestring)):
        file_start = int(file_start_frame)
        file_end = int(file_end_frame)
        chosen_start = int(chosen_start_frame)
        chosen_end = int(chosen_end_frame)
        focal_length_set = _set_camera_focal_length(
            cam_id,
            lens_id,
            focalLengthSamples,
            file_start,
            file_end,
            chosen_start,
            chosen_end,
        )

    # Set translation and rotation
    file_start_frame = camera_data.get('start_frame')
    file_end_frame = camera_data.get('end_frame')
    chosen_start_frame = options.get('start_frame')
    chosen_end_frame = options.get('end_frame')
    if (isinstance(file_start_frame,
                   (int, long)) and isinstance(file_end_frame, (int, long))
            and isinstance(chosen_start_frame, basestring)
            and isinstance(chosen_end_frame, basestring)):
        file_start = int(file_start_frame)
        file_end = int(file_end_frame)
        chosen_start = int(chosen_start_frame)
        chosen_end = int(chosen_end_frame)

        # Set Translation
        translate_set = False
        translate = options.get('translate')
        tx_samples = attr_data.get('translateX')
        ty_samples = attr_data.get('translateY')
        tz_samples = attr_data.get('translateZ')
        if translate and tx_samples and ty_samples and tz_samples:
            translate_set = _set_camera_translation(pgroup_id, cam_id,
                                                    tx_samples, ty_samples,
                                                    tz_samples, file_start,
                                                    file_end, chosen_start,
                                                    chosen_end)

        # Set Rotation
        rotate_set = False
        rotate = options.get('rotate')
        rx_samples = attr_data.get('rotateX')
        ry_samples = attr_data.get('rotateY')
        rz_samples = attr_data.get('rotateZ')
        if rotate and rx_samples and ry_samples and rz_samples:
            rotate_set = _set_camera_rotation(pgroup_id, cam_id, rx_samples,
                                              ry_samples, rz_samples,
                                              file_start, file_end,
                                              chosen_start, chosen_end)

        if translate_set or rotate_set:
            tde4.setPGroupPostfilterMode(pgroup_id, 'POSTFILTER_OFF')
            tde4.filterPGroup(pgroup_id, cam_id)
    return
Esempio n. 3
0
 def name(self, val):
     tde4.setCameraName(self._cam_id, val)