Material

Functions for dealing with hierarchies.

DeleteUnusedSubMaterials
Takes an object using a multi/SO material, and removes any unused sub-materials.
GetSubMaterials
Get all the submaterials of the passed material.
GetStandardSubMaterials
Get all the standard submaterials of the passed material.
GetObjectMaterials
Get all the materials and submaterials applied to the passed object.
GetObjectStandardMaterials
Get all the standard materials and submaterials applied to the passed object.
GetSubTextures
Get all the subtextures of the passed material or texture.
GetBitmapTextures
Get all the bitmap subtextures of the passed material or texture.
GetUsedMatIDs
Get which material IDs are used in an object.
ReduceSubMaterials
Takes a multi/SO material, and remove any duplicate sub-materials.
RemapMeshMaterials
Switches an object's matID's around based on the passed remapArray (from ReduceSubMaterials()).

DeleteUnusedSubMaterials:

Takes an object using a multi/SO material, and removes any unused sub-materials.
NOTE: the original object and material are not touched. Use RemapMeshMaterials to update the originals.

Returns:

An array, where:
Array[1] == A new, reduced, multi/SO material.
Array[2] == An array of integers. The array size is equal to the size of the original multi-material's materialList array.
Each array item specifies which sub-material in the NEW multi-material corresponds to the indexed sub-material. So, if:
array[2][5] == 3
then the fifth sub-material in the original material maps to the third sub-material in the new material.

Arguments:
<obj>
The object using a multi/SO material.

Back to top...


GetSubMaterials:

Get all the submaterials of the passed material.

Returns:

An array of all the sub-materials of the passed material.

Arguments:
<mat>
The material who's submaterials should be retrieved.
[MaterialFilter:DefaultMaterialFilter]
A function that will filter which submaterials will be gathered.
The function should take a single material as an argument, and return true if the material should be gathered, otherwise false.
By default, all submaterials will be gathered.
Supplying something else can allow you to be more critical of what is returned. ie:
fn FooMat mat = (
    (ClassOf mat == standardMaterial) AND
    (findString mat.name "Foo" != undefined)
)
MyMats = GetSubMaterials aMat MaterialFilter:FooMat
...MyMats would contain an array of Standard materials that have the word "Foo" in their name.

Back to top...


GetStandardSubMaterials:

Get all the standard submaterials of the passed material. This is just a shortcut to calling GetSubMaterials with a custom MaterialFilter function that gets only Standard materials.

Returns:

An array of all the standard sub-materials of the passed material.

Arguments:
<mat>
The material who's submaterials should be retrieved.

Back to top...


GetObjectMaterials:

Get all the materials and submaterials applied to the passed object.

Returns:

An array of all the sub-materials applied to the passed object.

Arguments:
<object>
The object who's materials and submaterials should be retrieved.
[MaterialFilter:DefaultMaterialFilter]
A function that will filter which submaterials will be gathered.
The function should take a single material as an argument, and return true if the material should be gathered, otherwise false.
By default, all submaterials will be gathered.
Supplying something else can allow you to be more critical of what is returned. ie:
fn FooStdMat mat = (
    (ClassOf mat == standardMaterial) AND
    (findString mat.name "Foo" != undefined)
)
MyMats = GetObjectMaterials anObj MaterialFilter:FooStdMat
...MyMats would contain an array of Standard materials that have the word "Foo" in their name.

Back to top...


GetObjectStandardMaterials:

Get all the standard materials and submaterials applied to the passed object.

Returns:

An array of all the standard sub-materials applied to the passed object.

Arguments:
<object>
The object who's materials and submaterials should be retrieved.

Back to top...


GetSubTextures:

Get all the subtextures of the passed material or texture.

Returns:

An array of all the sub-textures of the passed material or texture.

Arguments:
<mat>
The material or texture who's subtextures should be retrieved.
[TextureFilter:DefaultTextureFilter]
A function that will filter which subtextures will be gathered.
The function should take a single material or texture as an argument, and return true if the material/texture should be gathered, otherwise false.
By default, all subtextures will be gathered.
Supplying something else can allow you to be more critical of what is returned. ie:
fn FooBitmapTex tex = (
    (ClassOf tex == Bitmaptexture) AND
    (findString tex.name "Foo" != undefined)
)
MyTexs = GetSubTextures aTex TextureFilter:FooBitmapTex
...MyTexs would contain an array of bitmap textures that have the word "Foo" in their name.

Back to top...


GetBitmapTextures:

Get all the bitmap subtextures of the passed material or texture. This is just a shortcut to calling GetSubTextures with a custom MaterialFilter function that gets only Bitmap textures.

Returns:

An array of all the bitmap sub-textures of the passed material or texture.

Arguments:
<mat>
The material or texture who's subtextures should be retrieved.

Back to top...


GetUsedMatIDs:

Get which material IDs are used in an object.

Returns:

A sorted array of integers corresponding to which material IDs are used in the mesh.

Arguments:
<obj>
An object with a multi/SO material assigned to it.

Back to top...


ReduceSubMaterials:

Takes a multi/SO material, and remove any duplicate sub-materials.
NOTE: the original object and material are not touched. Use RemapMeshMaterials to update the originals.

Returns:

An array, where:
Array[1] == A new, reduced, multi/SO material.
Array[2] == An array of integers. The array size is equal to the size of the original multi-material's materialList array.
Each array item specifies which sub-material in the NEW multi-material corresponds to the indexed sub-material. So, if:
array[2][5] == 3
then the fifth sub-material in the original material maps to the third sub-material in the new material.

Arguments:
<mat>
The material that needs to have duplicates removed.
[compareFunc:undefined]
A function you can use when two sub-materials are compared. The function should take two materials, and return true if they're considered "the same", otherwise false.
If this is undefined (the default), materials are simply checked for being instances. An example of comparing for materials that share diffuse maps only would be:
fn HasSameDiffuseTexture matA matB = (
  if (ClassOf matA == StandardMaterial) AND
     (ClassOf matB == StandardMaterial) AND
     (matA.diffuseMap != undefined) AND
     (matA.diffuseMap != undefined) then (
        return (matA.diffuseMap == matB.diffuseMap)
  )
  false
)
And would be used like:

ReduceSubMaterials myMaterial compareFunc:HasSameDiffuseTexture

Back to top...


RemapMeshMaterials:

Switches an object's matID's around based on the passed remapArray (from ReduceSubMaterials or ReduceSubMaterials).
ie: the following will take an object's multi-material, remove duplicates, and re-order the object's face material ID's to use the new multi-material:
retArray = ReduceSubMaterials meshObj.material
meshObj.material = retArray[1]
RemapMeshMaterials meshObj retArray[2]

Returns:

OK.

Arguments:
<obj>
An editable mesh that needs its face material ID's re-ordered.
<remapArray>
A "Material Remap Array", as returned by the ReduceSubMaterials() function.

Back to top...