def _set_camera_frame_range(self, camera_id, path): # set frame range in_field, out_field = self.parent.utils.find_sequence_range( self.sgtk, path) tde4.setCameraSequenceAttr(camera_id, in_field, out_field, 1) tde4.setCameraFrameOffset(camera_id, in_field) no_of_frames = out_field - in_field + 1 # set calculation range tde4.setCameraCalculationRange(camera_id, 1, no_of_frames) # set playback range tde4.setCameraPlaybackRange(camera_id, 1, no_of_frames)
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 execute(self, operation, in_frame=None, out_frame=None, **kwargs): """ Main hook entry point :operation: String Frame operation to perform :in_frame: int in_frame for the current context (e.g. the current shot, current asset etc) :out_frame: int out_frame for the current context (e.g. the current shot, current asset etc) :returns: Depends on operation: 'set_frame_range' - Returns if the operation was successful 'get_frame_range' - Returns the frame range in the form (in_frame, out_frame) """ if operation == "get_frame_range": # since 3de doesn't have a concept of scene frame range, # return the first camera's frame range camera_id = tde4.getFirstCamera() (current_in, current_out, step) = tde4.getCameraSequenceAttr(camera_id) return (current_in, current_out) elif operation == "set_frame_range": for camera_id in tde4.getCameraList(): # set file frame range tde4.setCameraSequenceAttr(camera_id, in_frame, out_frame, 1) tde4.setCameraFrameOffset(camera_id, in_frame) no_of_frames = out_frame - in_frame + 1 # set calculation range tde4.setCameraCalculationRange(camera_id, 1, no_of_frames) # set playback range tde4.setCameraPlaybackRange(camera_id, 1, no_of_frames) return True
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
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
def image_frame_range(self, val): tde4.setCameraSequenceAttr(self._cam_id, val)