public GcmfMaterial(ObjMtlMaterial mtl, Dictionary <Bitmap, int> modelTextureMapping) : this() { Flags = 0x7D4; // TODOXXX if (mtl.DiffuseTextureMap != null) { if (!BitmapComparision.ContainsBitmap(modelTextureMapping, mtl.DiffuseTextureMap)) { throw new InvalidOperationException("Diffuse texture map not found in modelTextureMapping."); } TextureIdx = Convert.ToUInt16(BitmapComparision.GetKeyFromBitmap(modelTextureMapping, mtl.DiffuseTextureMap)); } }
public void Load(ObjMtlModel model, GxInterpolationFormat intFormat, int numMipmaps, List <int> textureIds, out Dictionary <Bitmap, int> textureIndexMapping) { if (model == null) { throw new ArgumentNullException("model"); } // Gather all material definitions in the model IEnumerable <ObjMtlMaterial> allMaterials = model.Objects .SelectMany(o => o.Value.Meshes).Select(m => m.Material); Dictionary <Bitmap, int> textureIndexMappingInt = new Dictionary <Bitmap, int>(); int textureCount = 0; foreach (ObjMtlMaterial mat in allMaterials) { // Create and add texture for diffuse map if (mat.DiffuseTextureMap != null && !BitmapComparision.ContainsBitmap(textureIndexMappingInt, mat.DiffuseTextureMap)) { if (textureCount >= textureIds.Count) { throw new InvalidObjMtlFileException("Too many textures to import"); } TplTexture texture = new TplTexture(GxTextureFormat.CMPR, intFormat, numMipmaps, mat.DiffuseTextureMap); this[textureIds[textureCount]] = texture; textureIndexMappingInt.Add(mat.DiffuseTextureMap, textureIds[textureCount]); ++textureCount; } } // Replace the 'out' variable at the end so it does not get // modified if an exception textureIndexMapping = textureIndexMappingInt; }
public GcmfMaterial(ObjMtlMaterial mtl, Dictionary <Bitmap, int> modelTextureMapping, string presetFolder) : this() { Flags = 0x7D4; // TODOXXX if (mtl.DiffuseTextureMap != null) { if (!BitmapComparision.ContainsBitmap(modelTextureMapping, mtl.DiffuseTextureMap)) { throw new InvalidOperationException("Diffuse texture map not found in modelTextureMapping."); } TextureIdx = Convert.ToUInt16(BitmapComparision.GetKeyFromBitmap(modelTextureMapping, mtl.DiffuseTextureMap)); } Match materialPreset = Regex.Match(mtl.Name, @"(?<=MAT_)[^\]]*"); if (presetFolder != null && materialPreset.Success) { string[] lines = System.IO.File.ReadAllLines(String.Format("{0}\\{1}.txt", presetFolder, materialPreset.Value)); for (int i = 0; i < lines.Length; i++) { string[] line = lines[i].Split(); if (line.Length == 2) { switch (line[0]) { case "FLAGS": Flags = Convert.ToUInt32(line[1], 16); break; case "TEXTURE_INDEX": TextureIdx = Convert.ToUInt16(line[1], 16); break; case "UNKNOWN_6": Unk6 = Convert.ToByte(line[1], 16); break; case "ANISOTROPY": AnisotropyLevel = Convert.ToByte(line[1], 16); break; case "UNKNOWN_C": UnkC = Convert.ToUInt16(line[1], 16); break; case "UNKNOWN_10": Unk10 = Convert.ToUInt32(line[1], 16); break; default: throw new InvalidOperationException(String.Format("Material preset {0} contains an invalid entry.", materialPreset.Value)); } } else { throw new InvalidOperationException(String.Format("Material preset {0} is not valid.", materialPreset.Value)); } } } }