예제 #1
0
    def update(self, items):
        """
        Perform replacements given a number of scene items passed from the app.

        Once a selection has been performed in the main UI and the user clicks
        the update button, this method is called.

        The items parameter is a list of dictionaries on the same form as was
        generated by the scan_scene hook above. The path key now holds
        the that each node should be updated *to* rather than the current path.
        """
        engine = self.parent.engine

        for i in items:
            node_id = i["node"]
            node_type = i["type"]
            new_path = i["path"]

            if node_type == "camera":
                engine.log_debug(
                    "Footage for camera %s: Updating to version %s" %
                    (node_id, new_path))
                camera_id = tde4.findCameraByName(node_id)
                tde4.setCameraPath(camera_id, new_path)

            elif node_type == "model":
                engine.log_debug(
                    "OBJ file for model %s: Updating to version %s" %
                    (node_id, new_path))
                name, pgroup_id, model_id = node_id
                tde4.importOBJ3DModel(pgroup_id, model_id, new_path)
예제 #2
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")
    def _import_img_seq_to_cam(self, path, sg_publish_data):
        selected_cameras = tde4.getCameraList(True)

        if len(selected_cameras) == 0:
            camera_id = tde4.createCamera("SEQUENCE")
        elif len(selected_cameras) == 1:
            camera_id = selected_cameras[0]
        else:
            raise Exception("Multiple cameras selected.")

        formatted_path = self._get_formatted_seq_path(path)
        tde4.setCameraPath(camera_id, formatted_path)

        # by default, use display window
        tde4.setCameraImportEXRDisplayWindowFlag(camera_id, True)

        self._set_camera_frame_range(camera_id, path)
        self._set_camera_fps(camera_id)
        self._set_camera_lens_filmback(camera_id)
    def _import_plate(self, path, sg_publish_data):

        import re
        file_name = os.path.basename(path)
        path = os.path.dirname(path)
        count = len(os.listdir(path))
        path = re.sub("v\d+", re.search("v\d+", path).group() + "_jpg", path)
        pad = "#" * int(
            filter(str.isdigit,
                   re.search("%\d+d", file_name).group()))
        file_name = re.sub("%\d+d", pad, file_name)
        file_name = file_name.replace(file_name.split(".")[-1], "jpg")
        path = os.path.join(path, file_name)

        c = tde4.getCurrentCamera()
        tde4.setCameraPath(c, path)
        tde4.setCameraImageWidth(c, 1920)
        tde4.setCameraImageHeight(c, 1080)
        tde4.setCameraSequenceAttr(c, 1001, 1000 + count, 1)

        return
예제 #5
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
예제 #6
0
 def image_path(self, val):
     tde4.setCameraPath(self._cam_id, val)