Table of contents
  1. module flair_material_presets
    1. Global Variables
    2. function get_material_attrs
    3. function set_material_attrs
    4. class MaterialPresetLibrary
      1. method MaterialPresetLibrary.find
      2. method MaterialPresetLibrary.load
      3. method MaterialPresetLibrary.save

module flair_material_presets

API module exposing functions related to material presets within Flair. The material presets are directly applied onto flairShader nodes assigned to objects, changing material settings and attributes. This module is directly used by the Material Presets UI.

Presets are individually stored as .json files and contain attributes of objects and their values.

Examples:

Instance the material presets library

1
2
3
4
5
6
import flair_material_presets

mat_preset_lib = flair_material_presets.MaterialPresetLibrary()
mat_preset_lib.find()  # not needed to manually find starting Flair 1.1.3+

print(mat_preset_lib)

Load material presets onto objects with the material presets library

1
2
3
4
5
6
7
8
9
10
11
12
# refer to earlier example to instance material presets library

# create object (if needed)
object = cmds.polySphere(r=1)

# create a new material and set "_painterly" preset with all options enabled
options = { "new": True, "textures": True, "noiseFX": True, "attributes": True }
mat_preset_lib.load("_painterly", options, object)

# load "green" preset, but only its noiseFX values
options = { "new": False, "textures": False, "noiseFX": True, "attributes": False }
mat_preset_lib.load("green", options, object)

Global Variables

  • SFX_MATERIAL
  • FLAIR_MATERIAL

function get_material_attrs

1
get_material_attrs(mat, all_attrs=True)

From the specified material, get the attributes/textures/type and their values.

Data is returned as a Python dictionary e.g.,:

1
2
3
4
5
6
7
8
9
10
11
12
{'attributes': {'albedo': [(0.0, 0.0, 0.0)],
                'alphaMask': 0.0,
                 ... },
 'textures': {'albedo': {'attrs': {'alphaGain': 1.0,
                                   'alphaIsLuminance': False,
                                    ... },
                         'name': 'file1',
                          ... }
              'alphaMask':  0.0,
               ... },
 'type': 'flairShader'
}

Args:

  • mat (unicode): Name of the material
  • all_attrs (bool): If all attributes are needed. Otherwise, only textures and Maya’s ShaderFX settings

Returns:

  • (dict): Material data containing all specified attributes and their values

function set_material_attrs

1
set_material_attrs(mat, mat_data, options=None, silent=False)

Set material data onto material according to options.

Options are:

  • textures - attributes with connected textures as their inputs
  • noiseFX - attributes that control NoiseFX within the material
  • attributes - all remaining attributes.

Args:

  • mat (unicode): Name of the material to set attributes onto
  • mat_data (dict): Dictionary of material data (Formatted as with get_material_attrs())
  • options (dict): Dictionary of options to set (default: {"textures": True, "noiseFX": True, "attributes": True })
  • silent (bool): If no warnings should be printed out when attribute is not found on material

class MaterialPresetLibrary

Preset library class to save and load material presets within Flair.

This class inherits from the Python dict object, extending its functionality.

Example:

Load library and print available presets

1
2
3
4
5
6
7
# load preset library
mat_preset_lib = flair_material_presets.MaterialPresetLibrary()
mat_preset_lib.find()  # not needed to manually find starting Flair 1.1.3+

# print available presets
preset_names = mat_preset_lib.keys()
print(preset_names)

method MaterialPresetLibrary.find

1
find()

Finds all available material presets and populates the library class.


method MaterialPresetLibrary.load

1
load(name, options, objects=None)

Load the material preset with the specified options onto objects/components. If no Flair material has been assigned to the specified objects, one will be created.

Options are:

  • new - create a new material even if the same material type was assigned before
  • textures - set attributes with connected textures as their inputs
  • noiseFX - set attributes that control NoiseFX within the material
  • attributes - set all remaining attributes.

Options are a requirement for this method and can be defined as follows:

options = {"new": False, "textures": True, "noiseFX": True, "attributes": True }

Special presets will work the same way they do within the Material Presets UI.

Args:

  • name (unicode): name of material preset
  • options (dict): options to load the material with
  • objects (unicode, list): name of objects to load preset onto (default: selected objects/components)

method MaterialPresetLibrary.save

1
save(name, mat)

Save the material attributes into a preset under the specified name

Args:

  • name (unicode): name of the material preset
  • mat (list, unicode): name of the material to create preset from