def _ingest_check_work(self, comment, force=False): """Check this file has a corresponding psyop work file. Args: comment (str): save comment force (bool): lose unsaved changes without confirmation """ _work = self.to_psy_work() _src = _work.cache_read('vendor_source_file') if _work.exists() and _src: print 'THIS', self.path print 'SRC', _src if _src != self: raise RuntimeError('Source does not match') return print ' - INGEST WORK', _work.path print ' - COMMENT', comment if not force: qt.ok_cancel('Copy {} to pipeline?\n\n{}\n\n{}'.format( _work.step, self.path, _work.path)) host.open_scene(self, force=force, lazy=True) # Update refs for _ref in qt.progress_bar( ref.find_refs(), 'Updating {:d} ref{}', stack_key='UpdateRefs'): self._ingest_check_ref(_ref) # Save to disk print ' - SAVING WORK', _work.path _work.save(comment=comment, safe=False, force=force) _work.cache_write(tag='vendor_source_file', data=self.path)
def scene_has_bake_set(self): """Check if this file has a bake set. Returns: (bool): whether bake set """ host.open_scene(self.path, lazy=True, force=True) return cmds.objExists('bakeSet')
def _revert_scene_fn(*args, **kwargs): _cur_file = host.cur_scene() _tmp_file = abs_path('{}/_psyhive_tmp.mb'.format( tempfile.gettempdir())) host.save_as(_tmp_file, force=True) _result = func(*args, **kwargs) host.open_scene(_tmp_file, force=True) if _cur_file: cmds.file(rename=_cur_file) return _result
def generate(self): """Generate mov in current nuke session.""" if not host.cur_scene() == _REVIEW_MOV_EXPORT_NK: host.open_scene(_REVIEW_MOV_EXPORT_NK, force=True) for _idx, _mov in enumerate(self.input_movs): _node = nuke.toNode('Read{:d}'.format(_idx+1)) _node['file'].fromUserText(_mov.path) _last = _node['last'].value() print 'LAST', _last nuke.toNode('Write1')['file'].setValue(self.path) nuke.render('Write1', 1, _last)
def scene_get_refs(self, force=False): """Find reference paths in this scene. Args: force (bool): lose unsaved changes without confirmation Returns: (dict): dict of reference namespaces/paths """ host.open_scene(self.path, lazy=True, force=True) _refs = {} for _ref in ref.find_refs(): _refs[_ref.namespace] = _ref.path return _refs
def _scene_read_ingest_issues(self, force=False, verbose=0): """Get a list of sanity check issues for this file. An empty list means that no issues were found. Args: force (bool): lose unsaved changes without confirmation verbose (int): print process data Returns: (str list): list of issues """ lprint('CHECKING ISSUES', self.path, verbose=verbose) host.open_scene(self.path, lazy=True, force=True) self.scene_get_frame_range() _issues = [] _issues += check_current_scene(show_dialog=False, verbose=0) # Check for work _work = self.to_psy_work() _latest = _work.find_latest() if _latest and _latest.ver_n > _work.ver_n: _issues.append('later version exists') # Apply sanity checks if self.step == 'rig': if not self.scene_has_bake_set(): _issues.append('missing bake set') if not self.scene_has_valid_meshes(): _issues.append('no valid meshes') if not self.scene_meshes_match_model(): _issues.append('meshes do not match model') elif self.step in ['animation', 'previz']: if not self.scene_get_cam(): _issues.append('no cam found') # _refs = self.scene_get_refs(force=force) # for _namespace, _file in _refs.items(): # _issues += self._get_ref_issues( # namespace=_namespace, file_=_file, refs=_refs, # verbose=verbose) else: raise ValueError(self.step) return _issues
def _generate_fbx(work, load_scene=True, lazy=True, force=False): """Generate fbx for a work file. Args: work (FrasierWork): work file to generate for load_scene (bool): load scene before export (for debugging) lazy (bool): don't load file if it's already open force (bool): overwrite existing files without confirmation """ print 'EXPORT FBX' if load_scene: if not lazy or host.cur_scene() != work.path: print ' - LOADING SCENE FOR FBX EXPORT' host.open_scene(work.path, force=True) work.export_fbx(force=force)
def build_aistandin_output(output): """Build aiStandIn ma file output. Args: output (str): path to aiStandIn output Returns: (str): path to output file """ print 'BUILD aiStandIn MA', output # Get paths for standin + rest cache + shade _out = tk2.TTOutput(output) assert _out.format == 'aistandin' _standin = _out.map_to(tk2.TTOutputFile, extension='ma') print ' - STANDIN', _standin assert _standin.extn == 'ma' _ver = tk2.TTOutputVersion(output) print ' - VER', _ver _rest_cache = get_single(_ver.find(extn='abc', filter_='restCache')) print ' - REST CACHE', _rest_cache _shade = _ver.find_file(extn='mb', format_='maya') print ' - SHADE', _shade assert not _shade == _out.path # Build aiStandIn node dprint('OPENING SHADE SCENE') host.open_scene(_shade.path, force=True) build_aistandin_from_shade(archive=_rest_cache, shade=_ShadeScene(), animated=False, name='AIS', deferred=False) # Strip out scene cmds.delete('GEO') host.save_as(file_=_standin.path, force=True) return _standin.path
def batch_scale_anim(filter_='', replace=False): """Batch scale face anim fbxs. Fbxs are read from scale folders in: P:/projects/frasier_38732V/production/scaled_fbx Args: filter_ (str): filter fbx list replace (bool): replace existing output files """ # Get latest version of each filename _to_process = {} for _fbx in find(_SCALED_FBX_ROOT, extn='fbx', class_=_FASInputFbx, filter_=filter_, type_='f'): _to_process[_fbx.filename] = _fbx _inputs = sorted(_to_process.values()) print 'FOUND {:d} INPUT FBXS'.format(len(_inputs)) if not replace: _inputs = [ _input for _input in _inputs if not _input.output.exists() or _input.output.cache_read('source') != _input ] print ' - {:d} NEED REPLACING'.format(len(_inputs)) # Generate output fbxs for _input in qt.progress_bar(_inputs, 'Processing {:d} fbx{}'): print _input print _input.anim_scale print _input.output print _input.output.cache_fmt host.open_scene(_input, force=True, lazy=False) scale_face_anim(namespace='', scale=_input.anim_scale) _save_fbx(_input.output, force=True) _input.output.cache_write('source', _input) print
def scene_get_cam(self): """Get render cam from this scene. Returns: (str): camera name """ print 'READING CAM', self.path host.open_scene(self.path, lazy=True, force=True) _cam_rig = None for _ref in ref.find_refs(): if 'cam' not in _ref.path.lower(): continue if _ref.is_loaded(): _cam_rig = _ref continue print ' - REF', _ref.path _psy_file = ingest.map_file_to_psy_asset(_ref.path) print ' - PSY FILE', _psy_file if _psy_file: _ref.swap_to(_psy_file) assert not _cam_rig _cam_rig = _ref _cams = [ _cam for _cam in hom.find_nodes(class_=hom.HFnCamera) if _cam not in DEFAULT_NODES] print ' - CAMS', _cams print ' - CAM RIG', _cam_rig if not len(_cams) == 1 and _cam_rig: _cam_rig_cam = _cam_rig.get_tfm('animCam') return str(_cam_rig_cam) _cam = get_single(_cams) return str(_cam)
def scene_get_frame_range(self): """Check if this scene's meshes match the model meshes.""" host.open_scene(self.path, lazy=True, force=True) return host.t_range(int)
def build_shader_outputs(output, force=True, verbose=1): """Build shader outputs for the given shade asset. This consists of: - mb file containing just shaders for this asset - yml file containing list of shaders - standin file containing shaders attached to aiStandIn node Args: output (str): path to aiStandIn output force (bool): overrwrite existing files without confirmation verbose (int): print process data Returns: (str): path to output file """ lprint('BUILD aiStandIn MA', output, verbose=verbose) # Get paths for standin + rest cache + shade _out = tk2.TTOutput(output) _shaders = _out.map_to(tk2.TTOutputFile, format='shaders', extension='mb') _yml = _out.map_to(tk2.TTOutputFile, format='shaders', extension='yml') _standin = _out.map_to(tk2.TTOutputFile, format='aistandin', extension='ma') _ver = tk2.TTOutputVersion(output) _rest_cache = get_single(_ver.find(extn='abc', filter_='restCache'), catch=True) _shade = _ver.find_file(extn='mb', format_='maya') lprint(' - VER ', _ver.path, verbose=verbose) lprint(' - SHADE ', _shade.path, verbose=verbose) lprint(' - REST CACHE', _rest_cache, verbose=verbose) lprint(' - STANDIN ', _standin.path, verbose=verbose) lprint(' - SHADERS ', _shaders.path, verbose=verbose) assert not _shade == _out.path # Build aiStandIn node lprint(' - OPENING SHADE SCENE', verbose=verbose) host.open_scene(_shade.path, force=True) build_aistandin_from_shade(archive=_rest_cache, shade=_ShadeScene(), animated=False, name='AIS', deferred=False) # Remove + save aistandin cmds.delete('GEO') host.save_as(file_=_standin.path, force=force) # Remove standin + save shaders if cmds.objExists('AIS'): cmds.delete('AIS') _ses = [ str(_se) for _se in cmds.ls(type='shadingEngine') if _se not in DEFAULT_NODES ] lprint(" - SHADING ENGINES", _ses, verbose=verbose) host.save_as(_shaders.path, force=force) write_yaml(file_=_yml.path, data=_ses, force=True) return _standin.path