MaxScript

function getAllTextureFiles inputMaterials =
(
	local allTextureFiles = #();
	for eachMat in inputMaterials do
	(
		format "-- Material: %\n" eachMat.name;
		for i = 1 to (getNumSubTexmaps eachMat) do
		(
			try 
			( 
				if (getNumSubTexmaps (getSubTexmap eachMat i)) != 0 
				then
			  	(
			  		join allTextureFiles (getAllTextureFiles #((getSubTexmap eachMat i)));
			  	)
			) catch ();

			if (isProperty (getSubTexmap eachMat i) #filename) then
			(
				append allTextureFiles (getSubTexmap eachMat i);
				format "---- TextureFile: \"%\"\n" (getSubTexmap eachMat i).filename;
			);
		);
	);
	return allTextureFiles;
);

allTextureFiles = (getAllTextureFiles sceneMaterials);

  

--Search the Texture for all sub textures
fn findTextures ThisTexture = 
(
    if ThisTexture != undefined do
    (
        texcount = (getNumSubTexmaps ThisTexture)
        if texcount == 0 do --parent textures don't have a filename (will error)
        (
            print ThisTexture.filename
        )
        for i in 1 to texcount do
        (
            Texture = getSubTexMap ThisTexture i
            findTextures (Texture)
        )
    )
)

--Search the Material or object for all sub materials and sub textures
fn findMaterials ThisObject = 
(
    if ThisObject != undefined do
    (
        --check the subtextures
        subtexcount = getNumSubTexmaps ThisObject.material
        for i in 1 to subtexcount do
        (
            findTextures (getSubTexMap ThisObject.material i)
        )

        --check the submaterials
        submatcount = getNumSubMtls ThisObject.material
        for i in 1 to submatcount do
        (
            findMaterials (getSubMtl ThisObject.material i)
        )
    )
)

findMaterials selection[1]

 

posted @ 2013-01-20 16:54  maadiah  阅读(407)  评论(0编辑  收藏  举报