X3DObject.Materials

Introduced

v4.0

Description

Returns a MaterialCollection containing all Material objects on the X3DObject, including those on clusters and subsurfaces.

Examples

JScript Example

/* 
        This example demonstrates how to access material on an object by first creating the object, then
        adding a constant and lambert shader, and then enumerating the materials collection for that 
        object to 'find' the newly applied materials.
*/
// Set up the scene with the new object
NewScene( null, false );
var oRoot = Application.ActiveProject.ActiveScene.Root;
var oObject = oRoot.AddGeometry( "Cylinder", "MeshSurface" );
// Add the materials
ApplyShader( "Material\\Constant", oObject );
BlendInTextureLayers( "Image", oObject );
SelectGeometryComponents( oObject + ".poly[14,15]" );
ApplyShader( "Material\\Lambert" );
// Loop through the collection of materials
var e = new Enumerator(oObject.Materials);
for ( ; !e.atEnd(); e.moveNext() ) {
        var oMat = e.item();
        Application.LogMessage( "Found " + oMat );
}
// ---------- OUTPUT ---------- 
//INFO : "Found cylinder.Material"
//INFO : "Found cylinder.polymsh.cls.Polygon.Material1"