AoMEngineLibrary.AMP.GrnMax.ExportMaterial C# (CSharp) Method

ExportMaterial() private method

private ExportMaterial ( GrnMaterial mat ) : void
mat GrnMaterial
return void
        private void ExportMaterial(GrnMaterial mat)
        {
            mat.DataExtensionIndex = this.File.AddDataExtension(Maxscript.QueryString("mat.name"));

            mat.DiffuseColor = new Color3D(Maxscript.QueryFloat("mat.diffuse.r") / 255f,
                Maxscript.QueryFloat("mat.diffuse.g") / 255f,
                Maxscript.QueryFloat("mat.diffuse.b") / 255f);
            mat.AmbientColor = new Color3D(Maxscript.QueryFloat("mat.ambient.r") / 255f,
                Maxscript.QueryFloat("mat.ambient.g") / 255f,
                Maxscript.QueryFloat("mat.ambient.b") / 255f);
            mat.SpecularColor = new Color3D(Maxscript.QueryFloat("mat.specular.r") / 255f,
                Maxscript.QueryFloat("mat.specular.g") / 255f,
                Maxscript.QueryFloat("mat.specular.b") / 255f);
            mat.EmissiveColor = new Color3D(Maxscript.QueryFloat("mat.selfIllumColor.r") / 255f,
                Maxscript.QueryFloat("mat.selfIllumColor.g") / 255f,
                Maxscript.QueryFloat("mat.selfIllumColor.b") / 255f);
            mat.Opacity = Maxscript.QueryFloat("mat.opacity") / 100f;
            mat.SpecularExponent = Maxscript.QueryFloat("mat.specularLevel");

            GrnTexture tex = null;
            if (Maxscript.QueryBoolean("(classof mat.diffusemap) == BitmapTexture"))
            {
                tex = new GrnTexture(this.File);
                tex.DataExtensionIndex = this.File.AddDataExtension(Maxscript.QueryString("mat.diffusemap.name"));
                this.File.SetDataExtensionFileName(tex.DataExtensionIndex, Path.GetFileNameWithoutExtension(Maxscript.QueryString("mat.diffusemap.filename")) + ".tga");
            }
            else if (Maxscript.QueryBoolean("(classof mat.diffusemap) == CompositeTextureMap") && Maxscript.QueryBoolean("(classof mat.diffusemap.mapList[1]) == BitmapTexture"))
            {
                tex = new GrnTexture(this.File);
                tex.DataExtensionIndex = this.File.AddDataExtension(Maxscript.QueryString("mat.diffusemap.mapList[1].name"));
                this.File.SetDataExtensionFileName(tex.DataExtensionIndex, Path.GetFileNameWithoutExtension(Maxscript.QueryString("mat.diffusemap.mapList[1].filename")) + ".tga");
            }

            if (tex != null)
            {
                int texIndex = this.File.Textures.IndexOf(tex);
                if (texIndex >= 0)
                {
                    mat.DiffuseTextureIndex = texIndex;
                    this.File.DataExtensions.RemoveAt(tex.DataExtensionIndex);
                }
                else
                {
                    mat.DiffuseTextureIndex = this.File.Textures.Count;
                    this.File.Textures.Add(tex);
                    string fileNameNoExt = Path.GetFileNameWithoutExtension(tex.FileName);
                    if (!fileNameNoExt.Equals(tex.Name))
                    {
                        throw new Exception("Texture name " + tex.Name + " must be set to " + fileNameNoExt + ".");
                    }
                }
            }
        }