Exemple #1
0
    def save(self, name, screenshot=True, **info):
        """
        Saves an attribute set to disk
        Args:
            name (str): Name of the attribute set to save
            objects (lst): List of objects to create attribute sets of (default -> selected)
            folder (str): Folder within directory to save this to
            screenshot (bool): Determines if a screenshot should be saved
            **info: Any additional arguments to be saved in the accompanying json file
        """
        logger.debug("Type of attribute set is: {0}".format(self.type))

        savePath = lib.Path(PATH.path)
        savePath.child("presets").child(self.type).createDir()

        # path to json file to save
        path = os.path.join(savePath.path, "{0}.json".format(name))

        # add to json dictionary
        info['name'] = name

        # select custom object
        prevSelection = cmds.ls(sl=True)
        selection = prevSelection
        if self.objects:
            cmds.select(self.objects, r=True)
            selection = cmds.ls(sl=True)

        # capture screenshot
        if screenshot:
            shotPath = self.saveScreenshot(name, directory=savePath.path)
            info['screenshot'] = os.path.basename(shotPath)

        # get attributes
        selAttrs = cmds.channelBox("mainChannelBox", sma=True, q=True)  # gets selected attributes in channelbox
        if not selAttrs:
            selAttrs = cmds.listAttr(se=True)  # settable attributes

        attrs = []
        for obj in selection:
            for attr in selAttrs:
                if cmds.attributeQuery(attr, node=obj, exists=True):
                    attrs.append("{0}.{1}".format(obj, attr))

        logger.debug(attrs)

        # store attributes in dict
        savedAttrs = {}
        for attr in attrs:
            savedAttrs[attr] = cmds.getAttr(attr)
        info['attributes'] = savedAttrs

        # write and save json info
        with open(path, 'w') as f:
            json.dump(info, f, indent=4)

        self[name] = info

        # make everything normal again
        cmds.select(prevSelection, r=True)  # restore selection
Exemple #2
0
    def find(self):
        """
        Finds the attribute sets on disk
        """
        self.clear()  # clear dictionary
        findPath = lib.Path(PATH.path)
        findPath.child("presets").child(self.type)

        files = os.listdir(findPath.path)  # list all files in directory
        attrSets = [f for f in files if f.endswith(".json")]  # only json files

        for aSet in attrSets:
            name, ext = os.path.splitext(aSet)
            setFile = os.path.join(findPath.path, aSet)

            with open(setFile, 'r') as f:
                info = json.load(f)

            # read screenshot
            screenshot = "{0}.jpg".format(name)
            if screenshot in files:
                info['screenshot'] = os.path.join(findPath.path, screenshot)

            # add default info (in case the json file does not have this)
            info['name'] = name
            info['path'] = setFile

            # add controller info to library
            self[name] = info  # add to dictionary
Exemple #3
0
    def save(self, name, screenshot=True, **info):
        """
        Saves an attribute set to disk
        Args:
            name (str): Name of the attribute set to save
            screenshot (bool): Determines if a screenshot should be saved
            **info: Any additional arguments to be saved in the accompanying json file
        """
        # select custom object
        prevSelection = cmds.ls(sl=True, l=True)
        selection = prevSelection

        # get material from selection
        mat, xforms = getMaterial(selection)
        print(mat, xforms)

        cmds.select(xforms, r=True)

        logger.info("Saving attributes of {0}".format(mat))

        # create directory
        logger.debug("Type of attribute set is: {0}".format(self.type))
        savePath = lib.Path(PATH.path)
        savePath.child("presets").child(self.type).createDir()

        # path to json file to save
        path = os.path.join(savePath.path, "{0}.json".format(name))

        # add to json dictionary
        info['name'] = name
        info['type'] = cmds.objectType(mat)

        # capture screenshot
        if screenshot:
            shotPath = self.saveScreenshot(name, directory=savePath.path)
            info['screenshot'] = os.path.basename(shotPath)

        if info['type'] == 'ShaderfxShader':
            getMaterialAttrs(mat, info)
        else:
            # DEPRECATED (PrototypeC)
            # get attributes
            setTextures = []
            setAttrs = cmds.listAttr(mat, ud=True, st="x*", k=True)  # settable attributes
            attributes = {}
            for attr in setAttrs:
                attributes[attr] = cmds.getAttr("{0}.{1}".format(mat, attr))
            info['attributes'] = attributes
            textures = {}
            for texture in setTextures:
                textures[texture] = cmds.getAttr("{0}.{1}".format(mat, texture))
            info['textures'] = textures

        # write and save json info
        with open(path, 'w') as f:
            json.dump(info, f, indent=4)

        self[name] = info
        # make everything normal again
        cmds.select(prevSelection, r=True)  # restore selection
Exemple #4
0
    def load(self, name):
        """
        Loads the specified attribute set
        Args:
            name (str): Name of the attribute set to import
        """
        attrs = self[name]['attributes']
        # check if substrate is available
        substrateAttr = "{0}.substrateTexture".format(mnpr_info.configNode)
        p = lib.Path(lib.getLibDir()).parent().child("textures")
        textures = os.listdir(p.path)
        if attrs[substrateAttr] not in textures:
            # check if substrates have been installed
            if len(textures) <= 2:
                result = cmds.confirmDialog(t="Substrates (papers/canvas) not found", m="The required substrate is not available.\nWould you like to download the MNPR substrates?", b=['Yes', 'Load anyway', 'Close'], icn="warning")
                if result == "Close":
                    return
                elif result == "Yes":
                    mnpr_runner.downloadSubstrates()
                    return
                else:
                    cmds.warning("Substrate texture not found, reverting to default substrate (style might not display correctly)")
                    attrs[substrateAttr] = "rough_default_2k.jpg"
            else:
                cmds.warning("Substrate texture not found, reverting to default substrate (style might not display correctly)")
                attrs[substrateAttr] = "rough_default_2k.jpg"

        # check change of style first
        styleAttr = "{0}.style".format(mnpr_info.configNode)
        if styleAttr in attrs:
            style = attrs[styleAttr]
            if style != cmds.mnpr(style=True):
                lib.setAttr(mnpr_info.configNode, "style", style)
                func = functools.partial(self.loadStyle, attrs)
                return cmds.scriptJob(runOnce=True, event=["SelectionChanged", func])
            else:
                # set attributes
                for attr in attrs:
                    splitter = attr.split('.')
                    lib.setAttr(splitter[0], splitter[1], attrs[attr])
        else:
            # for legacy presets (we do not worry about styles here)
            for attr in attrs:
                splitter = attr.split('.')
                if "NPRConfig" in splitter[0]:
                    splitter[0] = "mnprConfig"
                lib.setAttr(splitter[0], splitter[1], attrs[attr])
        lib.printInfo("Attributes set successfully")
Exemple #5
0
def getSubstrates():
    """
    Downloads and extracts the substrate textures
    """
    url = "https://researchdata.ntu.edu.sg/api/access/datafile/2793?gbrecs=true"
    if lib.localOS() == "mac":
        result = cmds.confirmDialog(t="Download substrates", m="Please download the substrates and extract them into the textures folder of MNPR.", b="Download", icn="information")
        if result == "Download":
            lib.openUrl("https://doi.org/10.21979/N9/HI7GT7")
            lib.openUrl(url)
            return
        else:
            print "No substrates will be downloaded.",
            return
    # windows and linux
    import zipfile
    result = cmds.confirmDialog(t="Downloading substrates", m="Do you wish to download the substrates \nautomatically in the background?", b=['Yes', 'Manual download', 'Close'], icn="question")
    if result == "Manual download":
        lib.openUrl("https://doi.org/10.21979/N9/HI7GT7")
        lib.openUrl(url)
        return
    elif result == "Close":
        print "No substrates will be downloaded.",
        return
    else:
        p = lib.Path(lib.getLibDir())
        p.parent().child("textures")
        dest = os.path.join(p.path, "seamless_textures_light.zip")
        if lib.downloader(url, dest):
            print "Substrates downloaded, extracting..."
            zip = zipfile.ZipFile(dest, 'r')
            zip.extractall(p.path)
            zip.close()
            os.remove(dest)
            print "MNPR substrates installed successfully",
            cmds.confirmDialog(t="Download successful", m="The substrates downloaded successfully", b="Yay!", icn="information")
        else:
            cmds.warning("Problem downloading substrates, please download and install manually")
            result = cmds.confirmDialog(t="Download substrates", m="Please download the substrates and extract them into the textures folder of MNPR.", b="Download", icn="information")
            if result == "Download":
                lib.openUrl("https://doi.org/10.21979/N9/HI7GT7")
                lib.openUrl(url)
Exemple #6
0
import os, json, logging, pprint, operator, traceback
from PySide2 import QtWidgets, QtCore, QtGui
import maya.cmds as cmds
import coopLib as lib
import coopQt as qt
import mnpr_system
import mnpr_info
import mnpr_pFX

# LOGGING
logging.basicConfig()  # errors and everything else (2 separate log groups)
logger = logging.getLogger("matPresets")  # create a logger for this file
logger.setLevel(logging.DEBUG)  # defines the logging level (INFO for releases)
# logger.setLevel(logging.INFO)  # defines the logging level (DEBUG for debugging)

PATH = lib.Path(os.path.dirname(os.path.realpath(__file__))).parent()

# setting nodes
settingNodes = {
    "reflectanceModel", "vtxControls", "Shadow", "Flip-Back-Faces",
    "Transparent", "Specularity", "specularModel", "Specular-In-Transparent",
    "maxLights"
}

# procedural setting nodes
procSettingNodes = {
    "Variation_Procedural_MNPR", "Variation_3D_MNPR",
    "Application_Procedural_MNPR", "Application_3D_MNPR",
    "Density_Procedural_MNPR", "Density_3D_MNPR", "Detail_Procedural_MNPR",
    "Detail_3D_MNPR", "Distortion_Procedural_MNPR", "Distortion_3D_MNPR",
    "uIncline_Procedural_MNPR", "uIncline_3D_MNPR", "vIncline_Procedural_MNPR",
Exemple #7
0
import os, json, logging, pprint, operator, traceback, functools
from PySide2 import QtWidgets, QtCore, QtGui
import maya.cmds as cmds
import coopLib as lib
import coopQt as qt
import mnpr_system
import mnpr_runner
import mnpr_info

# LOGGING
logging.basicConfig()  # errors and everything else (2 separate log groups)
logger = logging.getLogger("mnpr_presets")  # create a logger for this file
logger.setLevel(logging.DEBUG)  # defines the logging level (INFO for releases)
# logger.setLevel(logging.INFO)  # defines the logging level (DEBUG for debugging)

PATH = lib.Path(lib.getLibDir()).parent()


#        _         _          _ _ _
#    ___| |_ _   _| | ___    | (_) |__
#   / __| __| | | | |/ _ \   | | | '_ \
#   \__ \ |_| |_| | |  __/   | | | |_) |
#   |___/\__|\__, |_|\___|   |_|_|_.__/
#            |___/
class AttributeSetsLibrary(dict):
    """ Attribute sets library """
    type = "attrSets"
    objects = []

    def save(self, name, screenshot=True, **info):
        """