public Material(string texturename, MaterialMap.MapType mapType) { m_ambientColor = new Vec4(0.8f, 0.8f, 0.8f); m_diffuseColor = new Vec4(0.8f, 0.8f, 0.8f); m_shininess = 0.5f; m_specularColor = new Vec4(0.1f, 0.1f, 0.1f); AddMaterialMap(new FileMaterialMap(texturename, mapType)); Transparency = 0; m_twoSided = false; m_name = texturename; }
private static void ReadTexMap(BinaryReader r, uint length, MaterialMap.MapType mapType) { long start = r.BaseStream.Position; fileData.CurrentMaterial.texmaps.Add(new TexMapData()); fileData.CurrentMaterial.LastTexMap.fileMaterialMap = new FileMaterialMap("", mapType); fileData.CurrentMaterial.material.AddMaterialMap(fileData.CurrentMaterial.LastTexMap.fileMaterialMap); while (r.BaseStream.Position < start + length) { ReadTexMapSub(r); } }
public Material(XmlNode node) { if (node.Attributes["name"] != null) { m_name = node.Attributes["name"].Value; } else { m_name = "Unnamed material " + (matCount++); } if (node.Attributes["id"] != null) { m_id = int.Parse(node.Attributes["id"].Value); } if (node.Attributes["diffuse"] != null) { m_diffuseColor = new Vec4(node.Attributes["diffuse"].Value); } else { m_diffuseColor = new Vec4(0.8f, 0.8f, 0.85f); } if (node.Attributes["ambient"] != null) { m_ambientColor = new Vec4(node.Attributes["ambient"].Value); } else { m_ambientColor = 0.8f * Diffuse; } if (node.Attributes["specular"] != null) { m_specularColor = new Vec4(node.Attributes["specular"].Value); } else { m_specularColor = new Vec4(0.25f, 0.25f, 0.25f); } if (node.Attributes["shininess"] != null) { m_shininess = (float)double.Parse(node.Attributes["shininess"].Value, CommonSettings.Culture); } else { m_shininess = 0; } if (node.Attributes["transparency"] != null) { Transparency = (float)double.Parse(node.Attributes["transparency"].Value, CommonSettings.Culture); } else { Transparency = 0; } if (node.Attributes["twosided"] != null) { m_twoSided = bool.Parse(node.Attributes["twosided"].Value); } else { m_twoSided = false; } if (node.Attributes["texture"] != null) { MaterialMap.MapType mapType = MaterialMap.MapType.Diffuse; if (node.Attributes["type"] != null) { mapType = (MaterialMap.MapType)Enum.Parse(typeof(MaterialMap.MapType), node.Attributes["type"].Value); } AddMaterialMap(new FileMaterialMap(node.Attributes["texture"].Value, mapType)); } else if (node.Attributes["file"] != null) { MaterialMap.MapType mapType = MaterialMap.MapType.Diffuse; if (node.Attributes["type"] != null) { mapType = (MaterialMap.MapType)Enum.Parse(typeof(MaterialMap.MapType), node.Attributes["type"].Value); } AddMaterialMap(new FileMaterialMap(node.Attributes["file"].Value, mapType)); } if (node.Attributes["scale"] != null) { Scale = (float)double.Parse(node.Attributes["scale"].Value, CommonSettings.Culture); } else { Scale = 1; } if (node.Attributes["remap"] != null) { string remap = node.Attributes["remap"].Value; string[] split = remap.Split(';'); RemapUV(new Vec2((float)double.Parse(split[0]), (float)double.Parse(split[1])), new Vec2((float)double.Parse(split[2]), (float)double.Parse(split[3]))); } foreach (XmlNode subnode in node.ChildNodes) { if (subnode.Name == "Shader") { Shader s = Shader.Load(subnode); AddShader(s); } else if (subnode.Name == "Texture") { MaterialMap.MapType mapType = MaterialMap.MapType.Diffuse; if (subnode.Attributes["type"] != null) { mapType = (MaterialMap.MapType)Enum.Parse(typeof(MaterialMap.MapType), subnode.Attributes["type"].Value); } AddMaterialMap(new FileMaterialMap(subnode.Attributes["file"].Value, mapType)); } } }