private SEAMaterial AppendMaterial(Scene scene, Material material)
{
int sIndex = GetIndexByTag(material);
if (sIndex != -1) return (SEAMaterial)Writer.Objects[sIndex];
SEAMaterial mat = new SEAMaterial(GetValidString(materials, material.Name));
mat.doubleSided = material.IsTwoSided;
mat.receiveLights = true;
mat.receiveShadows = true;
mat.receiveFog = true;
mat.repeat = true;
mat.alpha = material.Opacity;
//
// DEFAULT
//
PhongTech defaultTech = new PhongTech();
defaultTech.diffuseColor = ToInteger( material.ColorDiffuse );
defaultTech.specularColor = ToInteger( material.ColorSpecular );
defaultTech.specular = material.ShininessStrength;
defaultTech.gloss = material.Shininess;
mat.techniques.Add(defaultTech);
//
// DIFFUSE_MAP
//
if (material.HasTextureDiffuse)
{
SEAObject tex = AppendTextureFromSlot(scene, material.TextureDiffuse);
if (tex != null)
{
DiffuseMapTech tech = new DiffuseMapTech();
tech.texture = GetIndex(tex);
mat.techniques.Add(tech);
}
}
//
// SPECULAR_MAP
//
if (material.HasTextureSpecular)
{
SEAObject tex = AppendTextureFromSlot(scene, material.TextureSpecular);
if (tex != null)
{
SpecularMapTech tech = new SpecularMapTech();
tech.texture = GetIndex(tex);
mat.techniques.Add(tech);
}
}
//
// EMISSIVE_MAP
//
if (material.HasTextureAmbient || material.HasTextureEmissive)
{
SEAObject tex = AppendTextureFromSlot(scene, material.HasTextureAmbient ? material.TextureAmbient : material.TextureEmissive);
if (tex != null)
{
EmissiveMapTech tech = new EmissiveMapTech();
tech.texture = GetIndex(tex);
mat.techniques.Add(tech);
}
}
//
// NORMAL_MAP
//
if (material.HasTextureNormal)
{
SEAObject tex = AppendTextureFromSlot(scene, material.TextureNormal);
if (tex != null)
{
NormalMapTech tech = new NormalMapTech();
tech.texture = GetIndex(tex);
mat.techniques.Add(tech);
}
}
//
// OPACITY_MAP
//
if (material.HasTextureOpacity)
{
SEAObject tex = AppendTextureFromSlot(scene, material.TextureOpacity);
if (tex != null)
{
OpacityMapTech tech = new OpacityMapTech();
tech.texture = GetIndex(tex);
mat.techniques.Add(tech);
}
}
//
// REFLECTION_MAP
//
if (material.HasTextureReflection)
{
SEAObject tex = AppendTextureFromSlot(scene, material.TextureReflection);
if (tex != null)
{
ReflectionTech tech = new ReflectionTech();
tech.texture = GetIndex(tex);
tech.alpha = material.Reflectivity;
mat.techniques.Add(tech);
}
}
// --
mat.tag = material;
materials.Add(mat);
Writer.AddObject(mat);
return mat;
}