def load_shader(self, shader_name): """ Loads given shader name in current DCC :param shader_name: str """ artellapipe.ShadersMgr().load_shader(shader_name=shader_name)
def get_shaders_path(self, status=defines.ArtellaFileStatus.WORKING, next_version=False): """ Returns path where asset shaders are stored :return: str """ shaders_path_file_type = artellapipe.ShadersMgr( ).get_shaders_path_file_type() if not shaders_path_file_type: LOGGER.warning('No Asset Shaders Path file type available!') return None shader_file_path_template = artellapipe.FilesMgr().get_template( 'shaders') if not shader_file_path_template: LOGGER.warning('No shaders path template found!') return None template_dict = { 'project_id': self._project.id, 'project_id_number': self._project.id_number, 'asset_type': self.get_category(), 'asset_name': self.get_name() } asset_shaders_path = self.solve_path( file_type=shaders_path_file_type, template=shader_file_path_template, template_dict=template_dict, status=status, check_file_type=False) return asset_shaders_path
def _export_file(self, file_path, *args, **kwargs): if not tp.is_maya(): LOGGER.warning('Shaders export is only supported in Maya!') return shaders_to_export = artellapipe.ShadersMgr().get_asset_shaders_to_export( asset=self._asset, return_only_shaders=False) locked_file = False if os.path.isfile(file_path): res = qtutils.show_question( None, 'Exporting Shaders Mapping File', 'Shaders Mapping File "{}" already exists. Do you want to overwrite it?'.format(file_path)) if res == QMessageBox.No: return artellapipe.FilesMgr().lock_file(file_path) locked_file = True try: with open(file_path, 'w') as fp: json.dump(shaders_to_export, fp) except Exception as exc: LOGGER.error('Error while exporting Shaders Mapping File "{}" | {}'.format(file_path, exc)) finally: if locked_file: artellapipe.FilesMgr().unlock_file(file_path) if os.path.isfile(file_path): return file_path
def _open_shaders_path(self): """ Internal callback function that is called when the user clicks on Open Shaders Path button """ shaders_paths = artellapipe.ShadersMgr().get_shaders_paths() or list() for shader_path in shaders_paths: osplatform.open_folder(shader_path)
def export(self, new_version=False, comment=None): exported_shader = None if self.do_export.isChecked(): if self._asset: exported_shader = artellapipe.ShadersMgr( ).export_asset_shaders(asset=self._asset, shader_swatch=self._shader_swatch, new_version=new_version, comment=comment, shaders_to_export=[self._name]) else: exported_shader = artellapipe.ShadersMgr().export_shader( shader_name=self._name, shader_swatch=self._shader_swatch, new_version=new_version, comment=comment) return exported_shader
def get_shader_path(self): """ Returns path of the shader :return: str """ shaders_extensions = artellapipe.ShadersMgr().get_shaders_extensions() if not shaders_extensions: return None for shader_extension in shaders_extensions: if not shader_extension.startswith('.'): shader_extension = '.{}'.format(shader_extension) shaders_paths = artellapipe.ShadersMgr().get_shaders_paths() for shaders_path in shaders_paths: shader_path = path_utils.clean_path( os.path.join(shaders_path, self._name + shader_extension)) if not os.path.isfile(shader_path): continue return shader_path
def export_shaders(self, new_version=False, comment=None): exported_shaders = list() if self._shaders_list.count() <= 0: LOGGER.error('No Shaders To Export. Aborting ....') return exported_shaders try: for i in range(self._shaders_list.count()): shader_item = self._shaders_list.item(i) shader = self._shaders_list.itemWidget(shader_item) self._progress_text.setText( 'Exporting shader: {0} ... Please wait!'.format( shader.name)) self.repaint() exported_shader = shader.export(new_version=new_version, comment=comment) if exported_shader is not None: if type(exported_shader) == list: exported_shaders.extend(exported_shader) else: exported_shaders.append(exported_shader) # else: # LOGGER.error('Error while exporting shader: {}'.format(shader.name)) except Exception as e: exceptions.capture_sentry_exception(e) LOGGER.error(str(e)) LOGGER.error(traceback.format_exc()) return exported_shaders if self._asset and self.export_shader_mapper_cbx.isChecked(): self._progress_text.setText( 'Exporting Shaders Mapping File ... Please wait!') self.repaint() artellapipe.ShadersMgr().export_asset_shaders_mapping( self._asset, comment=comment, new_version=new_version) return exported_shaders
def _do_export(self): """ Executes the export of the choose collection """ # Get data from ui self.collection_name = self.ui.collection_cbx.currentText() self.shaders_dict = self._get_shaders() self.scalps_list = self._get_scalps() ptx_folder = self._get_root_folder() export_path = self.ui.path_txf.text() self.character = self.ui.export_character_cbx.currentText() comment = self.ui.comment_pte.toPlainText() # analise if there is an export folder if not export_path: if not self.character: raise ValueError("export path must be specified") ################################################################################################################ # Export objects into a .groom folder ################################################################################################################ # generate export path if export_path: self.export_path_folder = export_path if '.groom' not in export_path: self.export_path_folder = export_path + '.groom' else: working_folder = self._project.get_working_folder() self.export_path_folder = os.path.join( self.proje.get_asses_path(), "Characters", self.character, working_folder, "groom", "groom_package.groom") # if the folder already exists delete it, and create a new one self.delete_artella_folder(self.export_path_folder) os.makedirs(self.export_path_folder) # get the ptx path if '${PROJECT}' in ptx_folder: project_path = str(mc.workspace(fullName=True, q=True)) ptx_folder = os.path.join(project_path, ptx_folder.replace('${PROJECT}', '')) LOGGER.debug("XGEN || All data parsed") self.ui.progress_lbl.setText("Exporting Files (PTX)") # copy the ptx files shutil.copytree(ptx_folder, os.path.join(self.export_path_folder, self.collection_name)) LOGGER.debug("XGEN || PTEX files exported") # export xgen file xg.exportPalette(palette=str(self.collection_name), fileName=str("{}/{}.xgen".format(self.export_path_folder, self.collection_name))) self.ui.progress_lbl.setText("Exporting Files (.XGEN)") LOGGER.debug("XGEN || Collection file exported") # export sculpts mc.select(self.scalps_list, replace=True) mc.file(rename=os.path.join(self.export_path_folder, 'scalps.ma')) mc.file(es=True, type='mayaAscii') mc.select(cl=True) self.ui.progress_lbl.setText("Exporting Scalps (.MA)") LOGGER.debug("XGEN || Sculpts Exported") # export material artellapipe.ShadersMgr().export_shaders(shader_names=self.shaders_dict.values(), publish=True, comment=comment) self.ui.progress_lbl.setText("Exporting Material (.sshader)") LOGGER.debug("XGEN || Material Exported") # export mapping with open(os.path.join(self.export_path_folder, 'shader.json'), 'w') as fp: json.dump(self.shaders_dict, fp) self.ui.progress_lbl.setText("Exporting Mapping (.JSON)") LOGGER.debug("XGEN || Mapping Exported") # add file to artella if comment: self._add_file_to_artella(file_path_global=self.export_path_folder, comment=comment) LOGGER.debug("XGEN || Files added to artella") else: LOGGER.warning("XGEN || Files are not been loaded to Artella. Do it manually")
def _on_unload_scene_shaders(self): """ Internal callback function that is called when Unload Scene Shaders menubar button is pressed """ artellapipe.ShadersMgr().unload_shaders()
def refresh(self): """ Refresh shaders data """ self.clear() shaders_extensions = artellapipe.ShadersMgr().get_shaders_extensions() if not shaders_extensions: return False for shader_extension in shaders_extensions: if not shader_extension.startswith('.'): shader_extension = '.{}'.format(shader_extension) if not self._shaders_path: shaders_library_paths = artellapipe.ShadersMgr( ).get_shaders_paths() if not shaders_library_paths: LOGGER.warning( 'Current Project has no shaders paths defined!') return False else: shaders_library_paths = python.force_list(self._shaders_path) valid_state = True invalid_paths = list() for shaders_path in shaders_library_paths: if not os.path.exists(shaders_path): invalid_paths.append(shaders_path) if invalid_paths: result = qtutils.show_question( None, 'Shaders Path not found!', 'Shaders Path is not sync! To start using this tool you should sync this folder first. ' 'Do you want to do it?') if result == QMessageBox.Yes: artellapipe.ShadersMgr().update_shaders( shaders_paths=invalid_paths) for shaders_path in invalid_paths: if not os.path.exists(shaders_path): LOGGER.debug( 'Shader Library Path not found after sync. Something is wrong, please contact TD!' ) valid_state = False if not valid_state: return False for shaders_path in shaders_library_paths: for shader_file in os.listdir(shaders_path): if not shader_file.endswith(shader_extension): LOGGER.warning( 'Shader File: "{}" has invalid shader extension! Skipping ...' .format(shader_file)) continue shader_name = os.path.splitext(shader_file)[0] shader_widget = self.SHADER_VIEWER_WIDGET_CLASS( project=self._project, shader_name=shader_name) shader_widget.clicked.connect( partial(self._on_shader_widget_clicked, shader_name)) self.add_shader(shader_widget)
def set_asset(self, asset): self._asset = asset asset_shaders = artellapipe.ShadersMgr().get_asset_shaders_to_export( self._asset) or list() self._shaders = asset_shaders self.refresh()
def _on_update_shaders(self): """ Internal callback function that is called when the user clicks Sync Shaders button """ artellapipe.ShadersMgr().update_shaders()