Table of contents
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
- MAYA_DEFAULT_MATERIALS
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 materialall_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 ontomat_data(dict): Dictionary of material data (Formatted as withget_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
# load preset library
mat_preset_lib = flair_material_presets.MaterialPresetLibrary()
# print available presets
preset_names = mat_preset_lib.keys()
print(preset_names)
method MaterialPresetLibrary.delete
1
delete(name)
Deletes the preset from the library.
Args:
name(unicode): Name of the preset to delete
method MaterialPresetLibrary.find
1
find()
Finds all available material presets and populates the library class. Material presets are searched on disk in the following locations:
- Specified presets folder in environment variable
FLAIR_PRESETS_PATH(FLAIR_PRESETS_PATH/materials) - User presets folder (
AppDocuments/Flair/presets/materials) - Installation presets folder
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 presetoptions(dict): options to load the material withobjects(unicode, list): name of objects to load preset onto (default: selected objects/components)
method MaterialPresetLibrary.rename_preset
1
rename_preset(name, new_name)
Rename an existing preset.
Args:
name(unicode): name of the preset to renamenew_name(unicode): new name of the preset
method MaterialPresetLibrary.save
1
save(name, mat)
Save the material attributes into a preset under the specified name. The preset is saved on disk in the first location that is writable among the following:
- Specified presets folder in environment variable
FLAIR_PRESETS_PATH(FLAIR_PRESETS_PATH/materials) - User presets folder (
AppDocuments/Flair/presets/materials) - Installation presets folder
Args:
name(unicode): name of the material presetmat(list, unicode): name of the material to create preset from