Logo   Home Table of Contents    News  Dev Blogs  Gallery  Timeline  Legend  Tags  Sponsors 
Join us on... 
Banner

Current: Month Day, Year

9.1.5 Code of opengl/material.py

opengl/material provides all methods to deal with openGL material. The file only contains 1 class:

Class Material

This class is used to work with materials.

Variables

These variables are all preset by __init__ and the method to reset the material default().
namedescription
glob reference to global object.
env reference to environment object.
mhmatdir the directory where the material is placed (preset to object directory).
type the object type which is mostly used to find the material for a certain object.
tags a list of tags used for the material.
name Name of the material.
filename Filename of the material.
tex_diffuse reference to to diffuse texture (preset to None).
tex_litsphere reference to litsphere texture (preset to None).
tex_aomap reference to ambient occlusion map (preset to None).
tex_nomap reference to normal map (preset to None).
tex_mrmap reference to metal-roughness map (preset to None).
tex_emmap reference to emission map (preset to None).
tex_mask reference to mask map (preset to None) for coloration.
diffuseTexture name of the diffuse texture, optional attribute.
normalmapTexture name of the normalmap texture, optional attribute.
aomapTexture name of the ambient occlusion texture, optional attribute.
metallicRoughnessTexture name of the metallic roughness texture, optional attribute.
emissiveTexture name of the emission texture, optional attribute.
sp_litsphereTexture name of the litsphere texture, optional attribute.
maskTexture name of the mask texture, optional attribute.
colorationOldColor set to white (list of 3 floats)
colorationOldMethod old method before coloration is used, set to 0.
colorationMethod coloration method: 0: off, 1: hue-to-fixed, 2: desaturate + color multiply.
colorationColor color for coloration (3 floats), preset to white.
ambientColor ambient color (3 floats), preset to white.
diffuseColor diffuse color (3 floats), preset to white.
specularColor specular color (3 floats), preset to grey.
emissiveColor emissive color (3 floats), preset to black.
metallicFactor factor for metallic, preset to 0.0.
roughnessFactor factor for roughness, preset to 0.0.
mr_found indicates metallic roughness map is found, preset to False.
emissiveFactor factor for emission, preset to 0.0.
transparent indicates a material should be transparent, preset to False.
alphaToCoverage indicates alphaToCoverage should be used, preset to False.
backfaceCull indicates backface culling should be used, preset to False.
shader name of the shader, preset to "phong".
sp_AdditiveShading additive value used for litspheres, preset to 0.0.
description material description, preset to None.
aomapIntensity intensity of ambient occlusion map, preset to 1.0.
normalmapIntensity intensity of normal map, preset to 1.0.
transmission transmission factor for glass, preset to 1.0.
ior ior factor for glass, preset to 1.0.
glassRoughness factor ior factor for glassRoughness, preset to 0.05.
glassColor glass color preset to white.

Methods:

nameparametersreturnsdescription
default NoneNone Sets material defaults, used by __init__.
copy sourceNone will create a material copy to be used into self from source (currently not used.
isExistent filenamepath checks if a certain relative texture name is existent and returns path. First test is in object directory. Next in subfolder "materials". Then tries to get rid off the parent directory of relative material name (if an "/" is in the name) and tries directly. Then an absolute path is tested, so if it starts with clothes, this pathname is stripped. Then system and user path where checked for this file (they contain type annd basename). If nothing works none is returnend.
loadMatFile pathsuccess (boolean) Loads an mhmat file and return true on success, in case of false env.last_error contains the error. First sets filename and mhmatdir. Then all parameters mentioned variables are set. In case of a litsphere texture not found, shader is set to phong. Some old parameters are no longer supported (like shaderConfig)
textureRelName pathoutputpath Creates a relative name for the used texture. URI syntax is used (/ divider)
roundColor colorNone round all color components to 4 digits.
saveMatFile pathsuccess (bool) Saves material file. First all colors where rounded. Then the used textures are added as relative names and the used intensities. In case of litsphere the old shaderParam litsphereTexture is still used but only with the name. Shader itself is always saved. In case coloration method is not 0, the params for coloration are saved. Glass is saved for pbr and transmission greater than zero. Returns true in case of success.
getCurrentMatFilename Nonefilename Getter for material filename.
_getMaterialList objdir
mlist
mlist appends all materials in objdir and objdir/materials to mlist.
listAllMaterials objdirmaterialfiles scans material list of objdir (if empty mhmatdir is used). For eyes there is a special case. They are tested in system path. Then duplicates are avoided. This is due to the fact that makehuman comes with at least one eye material.
colorate NoneNone Nothing happens, when material has no diffuse texture. If it is allready colorated with same method, also nothing happens. Otherwise the diffuse texture is resetted. ImageEdit from opengl.texture is called with the specific method. colorationOldColor and colorationOldMethod are set to current parameters.
colorToName rgbstring generates a color name for display in viewer with hex values
mixColors colors
values
obj
texture Mixes the list of values with colors (ethnicity), free old diffuse texture and creates a unicolored new one.
uniColor rgb
obj
texture frees diffuse texture and ccreeate a new unicolored texture.
mapChanged mapname
maptexture
changed (bool) First gets old name of texture (if none it is ""). The check if mapname itself is attribute of the material. If that is the case compare old name and new name and returns True if it must not be changed.
colorChanged colname
maptexture
changed (bool) Since a color is created by a 1x1 texture first the name is fetched, if no maptexture is given it is "". Create a color name from new color and compare old name and new name and returns True if it must not be changed.
loadLitSphere modify
obj
litsphere texture Test if map is changed, if not get return current texture. Otherwise free litsphere texture and get a new one.
loadAOMap white
modify
obj
aomap texture in case of a system asset simply "white" is returned. If it has not changed, the old aomap is returned. If an aomapTexture is still in the attributes free old texture and get new one. If ambientColor was not changed, the old 1x1 pixel aomap is returned. Otherwise "aomapTexture" is freed and a new unicolor map is created with the current ambientColor value. If nothing is given, white is returned.
loadNOMap nocolor
modify
obj
normalmap texture If the map has not changed, the old normal map is returned. Otherwise the texture is freed and a new one is returned. If nothing is given, nocolor (the color having no effect for normals) is returned.
loadEMMap nocolor
modify
obj)
emission texture. If the texture has not changed, the old emissive texture is returned. If an emissiveTexture is still in the attributes free old texture and get new one. If emissiveColor was not changed, the old 1x1 pixel map is returned. Otherwise "emissiveTexture" is freed and a new unicolor map is created with the current emissiveColor value. If nothing is given, nocolor (black) is returned.
loadMRMap white
modify
obj
metal roughness texture If the map has not changed, the old metal roughness map is returned. Otherwise the texture is freed and a new one is returned. If nothing is given, white is returned.
loadMaskMap modify
obj
mask texture or None If the map has not changed, the old mask is returned. Otherwise the texture is freed and a new one is returned. If nothing is given, None is returned.
setDiffuse name
alternative
obj
diffuse texture This function can only be use for additional objects. Used for e.g. floor. If no name is given, the alternative is returned, Programs gets the diffuse texture and returns it. In case of None the alternative is returned.
loadDiffuse modify
obj
diffuse texture If the texture has not changed, the old diffuse texture is returned. If an diffuseTexture is still in the attributes free old texture and get new one. If diffuseColor was not changed, the old 1x1 pixel map is returned. Otherwise "diffuseTexture" is freed and a new unicolor map is created with the current diffuseColor value. If nothing is given, grey is returned.
saveDiffuse Nonefilename or None Method to save the colorated diffuse color as a temporary file. Returns filename if 'diffuseTexture' exists.
freeTexture atrribNone free only one texture (used in material editor).
freeTextures NoneNone frees all textures with destroy (if not of type system).
setDiffuse name
alternative
objdiffuse texture This function can only be use for additional objects. Used for e.g. floor. If no name is given, the alternative is returned, Programs gets the diffuse texture and returns it. In case of None the alternative is returned. loadDiffuse modify
objdiffuse texture If the texture has not changed, the old diffuse texture is returned. If an diffuseTexture is still in the attributes free old texture and get new one. If diffuseColor was not changed, the old 1x1 pixel map is returned. Otherwise "diffuseTexture" is freed and a new unicolor map is created with the current diffuseColor value. If nothing is given, grey is returned. saveDiffuse Nonefilename or None Method to save the colorated diffuse color as a temporary file. Returns filename if 'diffuseTexture' exists. freeTexture atrribNone free only one texture (used in material editor). freeTextures NoneNone frees all textures with destroy (if not of type system).