private void ExportBrgMaterial(string mainObject, BrgMaterial mat)
{
//mat.id = Maxscript.QueryInteger("{0}.material.materialIDList[{1}]", mainObject, materialIndex + 1);
//Maxscript.Command("mat = {0}.material[{1}]", mainObject, mat.id);
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.SpecularExponent = Maxscript.QueryFloat("mat.specularLevel");
if (mat.SpecularExponent > 0)
{
mat.Flags |= BrgMatFlag.SpecularExponent;
}
mat.Opacity = Maxscript.QueryFloat("mat.opacity") / 100f;
if (mat.Opacity < 1f)
{
mat.Flags |= BrgMatFlag.Alpha;
}
int opacityType = Maxscript.QueryInteger("mat.opacityType");
if (opacityType == 1)
{
mat.Flags |= BrgMatFlag.SubtractiveBlend;
}
else if (opacityType == 2)
{
mat.Flags |= BrgMatFlag.AdditiveBlend;
}
if (Maxscript.QueryBoolean("mat.twoSided"))
{
mat.Flags |= BrgMatFlag.TwoSided;
}
if (Maxscript.QueryBoolean("mat.faceMap"))
{
mat.Flags |= BrgMatFlag.FaceMap;
}
if (Maxscript.QueryBoolean("(classof mat.reflectionMap) == BitmapTexture"))
{
mat.Flags |= BrgMatFlag.WrapUTx1 | BrgMatFlag.WrapVTx1 | BrgMatFlag.REFLECTIONTEXTURE;
BrgMatSFX sfxMap = new BrgMatSFX();
sfxMap.Id = 30;
sfxMap.Name = Maxscript.QueryString("getFilenameFile(mat.reflectionMap.filename)") + ".cub";
mat.sfx.Add(sfxMap);
}
if (Maxscript.QueryBoolean("(classof mat.bumpMap) == BitmapTexture"))
{
mat.BumpMap = Maxscript.QueryString("getFilenameFile(mat.bumpMap.filename)");
if (mat.BumpMap.Length > 0)
{
mat.Flags |= BrgMatFlag.WrapUTx3 | BrgMatFlag.WrapVTx3 | BrgMatFlag.BumpMap;
}
}
if (Maxscript.QueryBoolean("(classof mat.diffusemap) == BitmapTexture"))
{
mat.DiffuseMap = Maxscript.QueryString("getFilenameFile(mat.diffusemap.filename)");
int parenthIndex = mat.DiffuseMap.IndexOf('(');
if (parenthIndex > 0)
{
mat.DiffuseMap = mat.DiffuseMap.Remove(parenthIndex);
}
if (mat.DiffuseMap.Length > 0)
{
mat.Flags |= BrgMatFlag.WrapUTx1 | BrgMatFlag.WrapVTx1;
if (Maxscript.QueryBoolean("mat.diffusemap.filename == mat.filtermap.filename"))
{
mat.Flags |= BrgMatFlag.PixelXForm1;
}
}
}
else if (Maxscript.QueryBoolean("(classof mat.diffusemap) == CompositeTextureMap") && Maxscript.QueryBoolean("(classof mat.diffusemap.mapList[1]) == BitmapTexture"))
{
mat.Flags |= BrgMatFlag.WrapUTx1 | BrgMatFlag.WrapVTx1 | BrgMatFlag.PixelXForm1;
mat.DiffuseMap = Maxscript.QueryString("getFilenameFile(mat.diffusemap.mapList[1].filename)");
int parenthIndex = mat.DiffuseMap.IndexOf('(');
if (parenthIndex > 0)
{
mat.DiffuseMap = mat.DiffuseMap.Remove(parenthIndex);
}
}
this.ExportMaterialFlagsFromName(mat);
}