/// <summary> /// Initializes a new instance of the <see cref="UFLT.Utils.IntermediateMaterial"/> class. /// </summary> /// <param name='bank'>Material bank, used for finding materials.</param> /// <param name='mp'>Material palette or null.</param> /// <param name='main'>Main texture or null.</param> /// <param name='detail'>Detail texture or null.</param> /// <param name='transparancy'>Transparancy</param> /// <param name='lm'>Light mode.</param> public IntermediateMaterial(MaterialBank bank, MaterialPalette mp, TexturePalette main, TexturePalette detail, ushort transparancy, LightMode lm) { MaterialBank = bank; Palette = mp; MainTexture = main; DetailTexture = detail; Transparency = transparancy; LightMode = lm; }
/// <summary> /// Restore settings from a stereogram /// </summary> /// <param name="stereogram"></param> public void RestoreStereogramSettings(Stereogram stereogram) { if (stereogram != null && stereogram.options != null) { DepthmapPalette.SelectItem(stereogram.options.depthmap); TexturePalette.SelectItem(stereogram.options.texture); Options = new Options(stereogram.options); PreviewItem = stereogram; } }
/// <summary> /// Finds the or create material. Thread safe. /// </summary> /// <returns> /// The found or created material, never returns null. /// </returns> /// <param name='f'>The face to find a material for.</param> public IntermediateMaterial FindOrCreateMaterial(Face f) { // TODO: A faster lookup data structure, currently using a linear search. // Fetch palettes // Fetch palettes MaterialPalette mp = null; if (f.MaterialIndex != -1) { if (!f.Header.MaterialPalettes.TryGetValue(f.MaterialIndex, out mp)) { f.Log.WriteError("FindOrCreateMaterial:Could not find material palette: " + f.MaterialIndex); } } TexturePalette mainTex = null; if (f.TexturePattern != -1) { if (!f.Header.TexturePalettes.TryGetValue(f.TexturePattern, out mainTex)) { f.Log.WriteError("FindOrCreateMaterial:Could not find texture palette: " + f.TexturePattern); } } TexturePalette detailTex = null; if (f.DetailTexturePattern != -1) { if (!f.Header.TexturePalettes.TryGetValue(f.DetailTexturePattern, out detailTex)) { f.Log.WriteError("FindOrCreateMaterial:Could not find detail texture palette: " + f.DetailTexturePattern); } } lock (this) { foreach (IntermediateMaterial current in Materials) { if (current.Equals(mp, mainTex, detailTex, f.Transparency, f.LightMode)) { // We found a matching material return(current); } } // Create a new material IntermediateMaterial im = new IntermediateMaterial(this, mp, mainTex, detailTex, f.Transparency, f.LightMode); Materials.Add(im); return(im); } }
void Awake() { if (Instance != null) { Debug.LogError("Illegal singleton in TexturePalette"); } Instance = this; this.image = this.GetComponent <Image>(); var cursorObj = this.image.rectTransform.FindChild("Cursor"); this.cursorImage = cursorObj.GetComponent <Image>(); this.texSize = new Vector2(image.material.mainTexture.width, image.material.mainTexture.height); }
static void SplitPalettes(string filename, bool isTEX) { TextureHeader header; var palettes = new List <TexturePalette>(); using (FileStream infile = new FileStream(filename, FileMode.Open, FileAccess.Read)) { if (isTEX) { header = TextureHeader.ReadFromTEXFile(infile); } else { header = TextureHeader.ReadFromCDPFile(infile); } for (int i = 0; i < header.PaletteCount; i++) { if (isTEX) { palettes.Add(TexturePalette.ReadFromFile <TEXPalette>(infile, i, header.PaletteIDs[i])); } else { palettes.Add(TexturePalette.ReadFromFile <CDPPalette>(infile, i, header.PaletteIDs[i])); } } } filename = filename.Replace('.', '_'); string paletteIDsText = ""; foreach (TexturePalette palette in palettes) { string paletteID = string.Format("{0:X2}", palette.PaletteID); paletteIDsText += paletteID + "\r\n"; using (FileStream paletteFile = new FileStream(filename + "_" + paletteID + ".gtp", FileMode.Create, FileAccess.Write)) { paletteFile.Write(palette.PaletteData, 0, palette.PaletteData.Length); } } using (FileStream indexFile = new FileStream(filename + ".txt", FileMode.Create, FileAccess.Write)) { byte[] stringBytes = Encoding.ASCII.GetBytes(paletteIDsText.ToCharArray()); indexFile.Write(stringBytes, 0, stringBytes.Length); } }
/// <summary> /// Compares various material attrbiutes to see if this material matches. /// </summary> /// <param name="mp"></param> /// <param name="main"></param> /// <param name="detail"></param> /// <param name="trans"></param> /// <param name="lm"></param> /// <returns></returns> public bool Equals(MaterialPalette mp, TexturePalette main, TexturePalette detail, ushort trans, LightMode lm) { if (!MaterialPalette.Equals(Palette, mp)) { return(false); } if (!TexturePalette.Equals(MainTexture, main)) { return(false); } if (!TexturePalette.Equals(DetailTexture, detail)) { return(false); } if (Transparency != trans) { return(false); } if (LightMode != lm) { return(false); } return(true); }
public override int GetHashCode() { return(TexturePalette.GetHashCode() ^ TextureId.GetHashCode()); }
static void BuildCDP(string filename) { string cdpName = Path.GetFileNameWithoutExtension(filename).Replace("_cdp", ".cdp").Replace("_cnp", ".cnp"); if (!File.Exists(cdpName)) { return; } List <byte> paletteIDs = new List <byte>(); using (StreamReader indexFile = File.OpenText(filename)) { while (!indexFile.EndOfStream) { byte paletteID; if (!byte.TryParse(indexFile.ReadLine(), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out paletteID)) { continue; } paletteIDs.Add(paletteID); } } string basePaletteName = Path.GetFileNameWithoutExtension(filename) + "_"; List <TexturePalette> palettes = new List <TexturePalette>(); foreach (byte paletteID in paletteIDs.ToList()) { string paletteName = basePaletteName + string.Format("{0:X2}", paletteID) + ".gtp"; if (!File.Exists(paletteName)) { paletteIDs.Remove(paletteID); continue; } palettes.Add(TexturePalette.ReadFromGTP(paletteName, paletteID)); } using (FileStream cdpFile = new FileStream(cdpName, FileMode.Open, FileAccess.ReadWrite)) { byte oldPaletteCount = (byte)cdpFile.ReadByte(); cdpFile.Write(new byte[0x20 - 1], 0, 0x20 - 1); cdpFile.Position = 0; cdpFile.WriteByte((byte)palettes.Count); byte[] unknownData = new byte[0x40]; if (palettes.Count > oldPaletteCount) { cdpFile.Position = 0x220; cdpFile.Read(unknownData, 0, unknownData.Length); } for (int i = 0; i < palettes.Count; i++) { cdpFile.Position = 2 + i; cdpFile.WriteByte(palettes[i].PaletteID); cdpFile.Position = 0x20 + (i * 0x240); cdpFile.Write(palettes[i].PaletteData, 0, palettes[i].PaletteData.Length); if (i >= oldPaletteCount) { cdpFile.Write(unknownData, 0, unknownData.Length); } } int leftovers = oldPaletteCount - palettes.Count; if (leftovers > 0) { cdpFile.Position = 0x20 + (palettes.Count * 0x240); byte[] blankData = new byte[leftovers * 0x240]; cdpFile.Write(blankData, 0, blankData.Length); } cdpFile.Position = 0; using (FileStream zipFile = new FileStream(cdpName + ".gz", FileMode.Create, FileAccess.Write)) { using (GZipStream zip = new GZipStream(zipFile, CompressionMode.Compress)) { cdpFile.CopyTo(zip); } } } }
public List <BitmapType> GetTextures() { return(TexturePalette.GetItems()); }
/// <summary> /// Finds the texture if it has already been loaded else loads /// the new texture and records it for future re-use. /// </summary> Texture will be loaded in the same thread. /// <returns> /// Found texture or null if it can not be found/loaded. /// </returns> /// <param name='tp'>Tp.</param> public Texture2D FindOrCreateTexture(TexturePalette tp) { // Find the texture // TODO: Make the path absolute? string path = FileFinder.Instance.Find(tp.FileName); if (path != string.Empty) { // Have we already loaded this texture? Texture2D tex = null; // TODO: Maybe hash the paths for faster lookup? if (_Textures.TryGetValue(path, out tex)) { // We found it! return(tex); } string ext = Path.GetExtension(path); if (ext == ".rgb" || ext == ".rgba" || ext == ".bw" || ext == ".int" || ext == ".inta" || ext == ".sgi") { TextureSGI sgi = new TextureSGI(path); tex = sgi.Texture; if (tex != null) { // DuckbearLab: FIX! //_Textures[path].hideFlags = HideFlags.DontSave; // DuckbearLab: FIX! //tex.name = Path.GetFileNameWithoutExtension(path); tex.name = Path.GetFullPath(path); _Textures[path] = tex; return(tex); } } else { WWW www = new WWW("file://" + path); while (!www.isDone) { } if (string.IsNullOrEmpty(www.error) && www.texture != null) { // DuckbearLab: FIX! //www.texture.hideFlags = HideFlags.DontSave; // DuckbearLab: FIX! //www.texture.name = Path.GetFileNameWithoutExtension(path); //www.texture.name = Path.GetFullPath(path); var resultTexture = www.texture; resultTexture.name = Path.GetFullPath(path); _Textures[path] = resultTexture; // TODO: You are here!!!! /*FieldInfo fi = www.texture.GetType().GetField("m_Name", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase); * if (fi != null) Debug.Log("FOund it ");*/ //myFieldInfo.SetValue( www.texture, "TEST" ); //Debug.Log( myFieldInfo.GetValue( www.texture ) ); return(resultTexture); } else { Debug.LogError(www.error); } } } return(null); }
public bool Equals(MaterialPalette otherMaterialPalette, TexturePalette otherMainTexturePalette, TexturePalette otherDetailTexturePalette, ushort otherTransparency, Face.LightMode otherLightMode) { return(Equals(materialPalette, otherMaterialPalette) && Equals(mainTexturePalette, otherMainTexturePalette) && Equals(detailTexturePalette, otherDetailTexturePalette)); }