public void fromXmlFile(string pointer) { string name = pointer.Replace(gameWindow.materialFolder, ""); Material newMat = new Material(); newMat.type = Material.FROM_XML; newMat.loaded = false; newMat.name = name; newMat.pointer = pointer; register(newMat); }
private void register(Material newMat) { if (!materialNames.Contains(newMat.name)) { newMat.identifier = materials.Count; materials.Add(newMat); materialNames.Add(newMat.name, newMat.identifier); } }
private void loadMaterialCache(Material material) { //shaders material.resolveShaders(gameWindow.shaderLoader); //textures material.resolveTextures(gameWindow.textureLoader); material.loaded = true; materials[material.identifier] = material; }
private void loadMaterial(Material material) { switch (material.type) { case Material.Type.fromXml: loadMaterialXml(material); break; case Material.Type.fromCache: loadMaterialCache(material); break; default: break; } }
public void loadMaterialXml(Material target) { XmlTextReader reader = new XmlTextReader(target.pointer); //target.envMapAlphaBaseTexture = false; gameWindow.log("parsing material: " + target.name); while (reader.Read()) { // parsing data in material tag if (reader.Name == "material" && reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "shader") target.shader = gameWindow.shaderLoader.getShader(reader.Value); else if (reader.Name == "ssnshader") target.ssnshader = gameWindow.shaderLoader.getShader(reader.Value); else if (reader.Name == "selection") target.selectionshader = gameWindow.shaderLoader.getShader(reader.Value); else if (reader.Name == "shadow") target.shadowshader = gameWindow.shaderLoader.getShader(reader.Value); else if (reader.Name == "definfo") target.definfoshader = gameWindow.shaderLoader.getShader(reader.Value); } gameWindow.log("shader: " + target.shader.name); reader.MoveToElement(); } // parsing textures if (reader.Name == "textures" && reader.HasAttributes) { while (reader.MoveToNextAttribute()) { Texture tmpTex = gameWindow.textureLoader.getTexture(reader.Value); if (reader.Name == "base") target.setTexture(Material.TexType.baseTexture, tmpTex); else if (reader.Name == "base2") target.setTexture(Material.TexType.base2Texture, tmpTex); else if (reader.Name == "base3") target.setTexture(Material.TexType.base3Texture, tmpTex); else if (reader.Name == "normal") target.setTexture(Material.TexType.normalTexture, tmpTex); else if (reader.Name == "reflection") target.setTexture(Material.TexType.reflectionTexture, tmpTex); else if (reader.Name == "definfo") target.setTexture(Material.TexType.definfoTexture, tmpTex); else if (reader.Name == "emit") target.setTexture(Material.TexType.emitTexture, tmpTex); } gameWindow.log("base: " + target.getTextureName(Material.TexType.baseTexture)); gameWindow.log("normal: " + target.getTextureName(Material.TexType.normalTexture)); reader.MoveToElement(); } // parsing envmap data if (reader.Name == "envmap") { target.propertys.useEnv = true; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "source") { if (reader.Value == "normalalpha") target.propertys.envMapAlphaNormalTexture = true; else if (reader.Value == "basealpha") target.propertys.envMapAlphaBaseTexture = true; else target.setTexture(Material.TexType.envMapTexture, gameWindow.textureLoader.getTexture(reader.Value)); } else if (reader.Name == "tint") { target.propertys.envMapTint = GenericMethods.VectorFromString(reader.Value); } } reader.MoveToElement(); } } /* -- moved to textures // parsing specular data if (reader.Name == "specmap") { target.propertys.useSpec = true; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "source") { if (reader.Value == "normalalpha") target.propertys.specMapAlphaNormalTexture = true; else if (reader.Value == "basealpha") target.propertys.specMapAlphaBaseTexture = true; else target.setTexture(Material.TexType.specMapTexture, gameWindow.textureLoader.getTexture(reader.Value)); } else if (reader.Name == "tint") { target.propertys.specMapTint = GenericMethods.VectorFromString(reader.Value); } else if (reader.Name == "exp") { target.propertys.specExp = GenericMethods.FloatFromString(reader.Value); } } reader.MoveToElement(); } } */ // parsing emit data if (reader.Name == "emit") { target.propertys.useEmit = true; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "source") { if (reader.Value == "normalalpha") target.propertys.emitMapAlphaNormalTexture = true; else if (reader.Value == "basealpha") target.propertys.emitMapAlphaBaseTexture = true; else target.setTexture(Material.TexType.emitMapTexture, gameWindow.textureLoader.getTexture(reader.Value)); } else if (reader.Name == "tint") { target.propertys.emitMapTint = GenericMethods.VectorFromString(reader.Value); } } reader.MoveToElement(); } } // parsing transparency data if (reader.Name == "transparency") { target.propertys.useAlpha = true; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "refraction") target.propertys.refStrength = GenericMethods.FloatFromString(reader.Value); if (reader.Name == "blur") target.propertys.blurStrength = GenericMethods.FloatFromString(reader.Value); if (reader.Name == "fresnel") target.propertys.fresnelStrength = GenericMethods.FloatFromString(reader.Value); } reader.MoveToElement(); } } // parsing lighting data if (reader.Name == "lighted") { target.propertys.useLight = true; } // parsing nucull if (reader.Name == "nocull") { target.propertys.noCull = true; } // parsing nucull if (reader.Name == "nodepthmask") { target.propertys.noDepthMask = true; } // parsing additive if (reader.Name == "additive") { target.propertys.additive = true; } // parsing fresnel data if (reader.Name == "fresnel" && reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "exp") target.propertys.fresnelExp = GenericMethods.FloatFromString(reader.Value); else if (reader.Name == "strength") target.propertys.fresnelStr = GenericMethods.FloatFromString(reader.Value); } reader.MoveToElement(); } target.loaded = true; materials[target.identifier] = target; } }
public void fromXmlFile(string pointer) { string name = pointer.Replace(gameWindow.materialFolder, ""); Material newMat = new Material(); newMat.type = Material.Type.fromXml; newMat.name = name; newMat.pointer = pointer; newMat.setArys(); register(newMat); }
internal void cacheMaterial(ref List<Material> mList) { Material tmpMat = new Material(); tmpMat.name = name; //propertys tmpMat.propertys = propertys; //shaders tmpMat.shader = shader.nameOnly(); tmpMat.ssnshader = ssnshader.nameOnly(); tmpMat.selectionshader = selectionshader.nameOnly(); tmpMat.shadowshader = shadowshader.nameOnly(); tmpMat.definfoshader = definfoshader.nameOnly(); //textures int texCount = textures.Length; tmpMat.textures = new Texture[texCount]; for (int i = 0; i < texCount; i++) { tmpMat.textures[i] = textures[i].nameOnly(); } mList.Add(tmpMat); }