public void Replace(Bitmap bmp) { FileMap tMap, pMap; if (HasPalette) { PLT0Node pn = GetPaletteNode(); tMap = TextureConverter.Get(Format).EncodeTextureIndexed(bmp, LevelOfDetail, pn.Colors, pn.Format, QuantizationAlgorithm.MedianCut, out pMap); pn.ReplaceRaw(pMap); } else { tMap = TextureConverter.Get(Format).EncodeTEX0Texture(bmp, LevelOfDetail); } ReplaceRaw(tMap); }
public Bitmap GetImage(int index) { PLT0Node plt = GetPaletteNode(); try { if (plt != null) { return(TextureConverter.DecodeIndexed(Header, plt.Palette, index + 1)); } else { return(TextureConverter.Decode(Header, index + 1)); } } catch { return(null); } }
public Bitmap GetImage(int index, PLT0Node plt) { try { if (WorkingUncompressed != DataSource.Empty) { if (plt != null) { return(TextureConverter.DecodeIndexed(Header1, plt.Palette, index + 1)); } else { return(TextureConverter.Decode(Header1, index + 1)); } } else { return(null); } } catch { return(null); } }
public Bitmap GetImage(int index, PLT0Node plt) { try { if (WorkingUncompressed != DataSource.Empty) { if (plt != null) { return(TextureConverter.DecodeIndexed( (VoidPtr)CommonHeader + 0x40, _width, _height, plt.Palette, index + 1, _format)); } else { return(TextureConverter.Decode( (VoidPtr)CommonHeader + 0x40, _width, _height, index + 1, _format)); } } else { return(null); } } catch { return(null); } }
public unsafe void Attach(TEX0Node tex, PLT0Node plt) { ClearImages(); _textures = new Bitmap[tex.LevelOfDetail]; for (int i = 0; i < tex.LevelOfDetail; i++) _textures[i] = tex.GetImage(i, plt); if (_textures.Length != 0) { _width = _textures[0].Width; _height = _textures[0].Height; } _remake = true; Initialize(); }
public Bitmap GetImage(int index) { PLT0Node plt = GetPaletteNode(); return(SharesData ? SourceNode.GetImage(index, plt) : GetImage(index, plt)); }
internal unsafe void Prepare(GLContext ctx, MDL0MaterialRefNode mRef) { if (_context == null) { _context = ctx; } if (palette == null && mRef.PaletteNode != null) { palette = mRef.RootNode.FindChild("Palettes(NW4R)/" + mRef.Palette, true) as PLT0Node; } try { if (Texture != null) { Texture.Bind(mRef.Index, (int)((MDL0MaterialNode)mRef.Parent).ShaderNode.programHandle); } else { Load(mRef.Index, (int)((MDL0MaterialNode)mRef.Parent).ShaderNode.programHandle, palette); } } catch { } int filter = 0; switch (mRef.MagFilter) { case MDL0MaterialRefNode.TextureMagFilter.Nearest: filter = (int)GLTextureFilter.NEAREST; break; case MDL0MaterialRefNode.TextureMagFilter.Linear: filter = (int)GLTextureFilter.LINEAR; break; } _context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MagFilter, filter); switch (mRef.MinFilter) { case MDL0MaterialRefNode.TextureMinFilter.Nearest: filter = (int)GLTextureFilter.NEAREST; break; case MDL0MaterialRefNode.TextureMinFilter.Linear: filter = (int)GLTextureFilter.LINEAR; break; case MDL0MaterialRefNode.TextureMinFilter.Nearest_Mipmap_Nearest: filter = (int)GLTextureFilter.NEAREST_MIPMAP_NEAREST; break; case MDL0MaterialRefNode.TextureMinFilter.Nearest_Mipmap_Linear: filter = (int)GLTextureFilter.NEAREST_MIPMAP_LINEAR; break; case MDL0MaterialRefNode.TextureMinFilter.Linear_Mipmap_Nearest: filter = (int)GLTextureFilter.LINEAR_MIPMAP_NEAREST; break; case MDL0MaterialRefNode.TextureMinFilter.Linear_Mipmap_Linear: filter = (int)GLTextureFilter.LINEAR_MIPMAP_LINEAR; break; } _context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MinFilter, filter); _context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.LODBias, mRef.LODBias); //_context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.BaseLevel, 0); float *p = stackalloc float[4]; p[0] = p[1] = p[2] = p[3] = 1.0f; if (Selected && !ObjOnly) { p[0] = -1.0f; } _context.glLight(GLLightTarget.Light0, GLLightParameter.SPECULAR, p); _context.glLight(GLLightTarget.Light0, GLLightParameter.DIFFUSE, p); }
private unsafe void Load(int index, int program, PLT0Node palette) { if (_context == null) { return; } Source = null; if (Texture != null) { Texture.Delete(); } Texture = new GLTexture(_context, 0, 0); Texture.Bind(index, program); //ctx._states[String.Format("{0}_TexRef", Name)] = Texture; Bitmap bmp = null; TEX0Node tNode = null; if (_context._states.ContainsKey("_Node_Refs")) { List <ResourceNode> nodes = _context._states["_Node_Refs"] as List <ResourceNode>; List <ResourceNode> searched = new List <ResourceNode>(nodes.Count); foreach (ResourceNode n in nodes) { ResourceNode node = n.RootNode; if (searched.Contains(node)) { continue; } searched.Add(node); //Search node itself first if ((tNode = node.FindChild("Textures(NW4R)/" + Name, true) as TEX0Node) != null) { Source = tNode; if (palette != null) { bmp = tNode.GetImage(0, palette); } else { bmp = tNode.GetImage(0); } } else { //Then search node directory string path = node._origPath; if (path != null) { DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(path)); foreach (FileInfo file in dir.GetFiles(Name + ".*")) { if (file.Name.EndsWith(".tga")) { Source = file.FullName; bmp = TGA.FromFile(file.FullName); break; } else if (file.Name.EndsWith(".png") || file.Name.EndsWith(".tiff") || file.Name.EndsWith(".tif")) { Source = file.FullName; bmp = (Bitmap)Bitmap.FromFile(file.FullName); break; } } } } if (bmp != null) { break; } } searched.Clear(); if (bmp != null) { int w = bmp.Width, h = bmp.Height, size = w * h; Texture._width = w; Texture._height = h; //_context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MagFilter, (int)GLTextureFilter.LINEAR); //_context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MinFilter, (int)GLTextureFilter.NEAREST_MIPMAP_LINEAR); //_context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.BaseLevel, 0); //if (tNode != null) // _context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MaxLevel, tNode.LevelOfDetail); //else // _context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MaxLevel, 0); BitmapData data = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); try { using (UnsafeBuffer buffer = new UnsafeBuffer(size << 2)) { ARGBPixel *sPtr = (ARGBPixel *)data.Scan0; ABGRPixel *dPtr = (ABGRPixel *)buffer.Address; for (int i = 0; i < size; i++) { *dPtr++ = (ABGRPixel)(*sPtr++); } int res = _context.gluBuild2DMipmaps(GLTextureTarget.Texture2D, GLInternalPixelFormat._4, w, h, GLPixelDataFormat.RGBA, GLPixelDataType.UNSIGNED_BYTE, buffer.Address); if (res != 0) { } } } finally { bmp.UnlockBits(data); bmp.Dispose(); } } } }
private unsafe void Load(int index, int program, PLT0Node palette) { if (_context == null) { return; } Source = null; if (Texture != null) { Texture.Delete(); } Texture = new GLTexture(); Texture.Bind(index, program, _context); //ctx._states[String.Format("{0}_TexRef", Name)] = Texture; Bitmap bmp = null; TEX0Node tNode = null; if (_context._states.ContainsKey("_Node_Refs")) { List <ResourceNode> nodes = _context._states["_Node_Refs"] as List <ResourceNode>; List <ResourceNode> searched = new List <ResourceNode>(nodes.Count); foreach (ResourceNode n in nodes) { ResourceNode node = n.RootNode; if (searched.Contains(node)) { continue; } searched.Add(node); //Search node itself first if ((tNode = node.FindChild("Textures(NW4R)/" + Name, true) as TEX0Node) != null) { Source = tNode; if (palette != null) { Texture.Attach(tNode, palette); } else { Texture.Attach(tNode); } return; } else { //Then search node directory string path = node._origPath; if (path != null) { DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(path)); if (dir.Exists && Name != "<null>") { foreach (FileInfo file in dir.GetFiles(Name + ".*")) { if (file.Name.EndsWith(".tga")) { Source = file.FullName; bmp = TGA.FromFile(file.FullName); break; } else if (file.Name.EndsWith(".png") || file.Name.EndsWith(".tiff") || file.Name.EndsWith(".tif")) { Source = file.FullName; bmp = (Bitmap)Bitmap.FromFile(file.FullName); break; } } } } } if (bmp != null) { break; } } searched.Clear(); if (bmp != null) { Texture.Attach(bmp); } } }
internal unsafe void Prepare(MDL0MaterialRefNode mRef, int shaderProgramHandle) { if (mRef.PaletteNode != null && palette == null) { palette = mRef.RootNode.FindChild("Palettes(NW4R)/" + mRef.Palette, true) as PLT0Node; } try { if (Texture != null) { Texture.Bind(mRef.Index, shaderProgramHandle, _context); } else { Load(mRef.Index, shaderProgramHandle, palette); } } catch { } int filter = 0; switch (mRef.MagFilter) { case MDL0MaterialRefNode.TextureMagFilter.Nearest: filter = (int)TextureMagFilter.Nearest; break; case MDL0MaterialRefNode.TextureMagFilter.Linear: filter = (int)TextureMagFilter.Linear; break; } GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, filter); switch (mRef.MinFilter) { case MDL0MaterialRefNode.TextureMinFilter.Nearest: filter = (int)TextureMinFilter.Nearest; break; case MDL0MaterialRefNode.TextureMinFilter.Linear: filter = (int)TextureMinFilter.Linear; break; case MDL0MaterialRefNode.TextureMinFilter.Nearest_Mipmap_Nearest: filter = (int)TextureMinFilter.NearestMipmapNearest; break; case MDL0MaterialRefNode.TextureMinFilter.Nearest_Mipmap_Linear: filter = (int)TextureMinFilter.NearestMipmapLinear; break; case MDL0MaterialRefNode.TextureMinFilter.Linear_Mipmap_Nearest: filter = (int)TextureMinFilter.LinearMipmapNearest; break; case MDL0MaterialRefNode.TextureMinFilter.Linear_Mipmap_Linear: filter = (int)TextureMinFilter.LinearMipmapLinear; break; } GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, filter); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureLodBias, mRef.LODBias); switch ((int)mRef.UWrapMode) { case 0: GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); break; case 1: GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); break; case 2: GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.MirroredRepeat); break; } switch ((int)mRef.VWrapMode) { case 0: GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); break; case 1: GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); break; case 2: GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.MirroredRepeat); break; } float *p = stackalloc float[4]; p[0] = p[1] = p[2] = p[3] = 1.0f; if (Selected && !ObjOnly) { p[0] = -1.0f; } GL.Light(LightName.Light0, LightParameter.Specular, p); GL.Light(LightName.Light0, LightParameter.Diffuse, p); }
private unsafe void Load(int index, int program, PLT0Node palette) { if (_context == null) return; Source = null; if (Texture != null) Texture.Delete(); Texture = new GLTexture(); Texture.Bind(index, program, _context); //ctx._states[String.Format("{0}_TexRef", Name)] = Texture; Bitmap bmp = null; TEX0Node tNode = null; if (_context._states.ContainsKey("_Node_Refs")) { List<ResourceNode> nodes = _context._states["_Node_Refs"] as List<ResourceNode>; List<ResourceNode> searched = new List<ResourceNode>(nodes.Count); foreach (ResourceNode n in nodes) { ResourceNode node = n.RootNode; if (searched.Contains(node)) continue; searched.Add(node); //Search node itself first if ((tNode = node.FindChild("Textures(NW4R)/" + Name, true) as TEX0Node) != null) { Source = tNode; if (palette != null) Texture.Attach(tNode, palette); else Texture.Attach(tNode); return; } else { //Then search node directory string path = node._origPath; if (path != null) { DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(path)); if (dir.Exists && Name != "<null>") foreach (FileInfo file in dir.GetFiles(Name + ".*")) { if (file.Name.EndsWith(".tga")) { Source = file.FullName; bmp = TGA.FromFile(file.FullName); break; } else if (file.Name.EndsWith(".png") || file.Name.EndsWith(".tiff") || file.Name.EndsWith(".tif")) { Source = file.FullName; bmp = (Bitmap)Bitmap.FromFile(file.FullName); break; } } } } if (bmp != null) break; } searched.Clear(); if (bmp != null) Texture.Attach(bmp); } }
internal unsafe void Prepare(MDL0MaterialRefNode mRef, int shaderProgramHandle) { if (mRef.PaletteNode != null && palette == null) palette = mRef.RootNode.FindChild("Palettes(NW4R)/" + mRef.Palette, true) as PLT0Node; try { if (Texture != null) Texture.Bind(mRef.Index, shaderProgramHandle, _context); else Load(mRef.Index, shaderProgramHandle, palette); } catch { } int filter = 0; switch (mRef.MagFilter) { case MDL0MaterialRefNode.TextureMagFilter.Nearest: filter = (int)TextureMagFilter.Nearest; break; case MDL0MaterialRefNode.TextureMagFilter.Linear: filter = (int)TextureMagFilter.Linear; break; } GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, filter); switch (mRef.MinFilter) { case MDL0MaterialRefNode.TextureMinFilter.Nearest: filter = (int)TextureMinFilter.Nearest; break; case MDL0MaterialRefNode.TextureMinFilter.Linear: filter = (int)TextureMinFilter.Linear; break; case MDL0MaterialRefNode.TextureMinFilter.Nearest_Mipmap_Nearest: filter = (int)TextureMinFilter.NearestMipmapNearest; break; case MDL0MaterialRefNode.TextureMinFilter.Nearest_Mipmap_Linear: filter = (int)TextureMinFilter.NearestMipmapLinear; break; case MDL0MaterialRefNode.TextureMinFilter.Linear_Mipmap_Nearest: filter = (int)TextureMinFilter.LinearMipmapNearest; break; case MDL0MaterialRefNode.TextureMinFilter.Linear_Mipmap_Linear: filter = (int)TextureMinFilter.LinearMipmapLinear; break; } GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, filter); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureLodBias, mRef.LODBias); switch ((int)mRef.UWrapMode) { case 0: GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge); break; case 1: GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); break; case 2: GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.MirroredRepeat); break; } switch ((int)mRef.VWrapMode) { case 0: GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge); break; case 1: GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); break; case 2: GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.MirroredRepeat); break; } float* p = stackalloc float[4]; p[0] = p[1] = p[2] = p[3] = 1.0f; if (Selected && !ObjOnly) p[0] = -1.0f; GL.Light(LightName.Light0, LightParameter.Specular, p); GL.Light(LightName.Light0, LightParameter.Diffuse, p); }
public Bitmap GetImage(int index) { PLT0Node plt = GetPaletteNode(); return(GetImage(index, plt)); }
public new DialogResult ShowDialog(IWin32Window owner) { _bresParent = null; _origTEX0 = null; _origPLT0 = null; _origREFT = null; _origTPL = null; _origTPLPlt = null; _paletteData = _textureData = null; DialogResult = DialogResult.Cancel; try { return base.ShowDialog(owner); } //catch (Exception x) { MessageBox.Show(x.ToString()); return DialogResult.Cancel; } finally { DisposeImages(); } }
public void EncodeSource() { TextureConverter format = TextureConverter.Get((WiiPixelFormat)cboFormat.SelectedItem); if (format.IsIndexed) { if (_origTEX0 != null || _bresParent != null) _textureData = format.EncodeTextureIndexed(_indexed, (int)numLOD.Value, (WiiPaletteFormat)cboPaletteFormat.SelectedItem, out _paletteData); else if (_origREFT != null || _reftParent != null) _textureData = format.EncodeREFTTextureIndexed(_indexed, (int)numLOD.Value, (WiiPaletteFormat)cboPaletteFormat.SelectedItem); else if (_origTPL != null || _tplParent != null) _textureData = format.EncodeTPLTextureIndexed(_indexed, (int)numLOD.Value, (WiiPaletteFormat)cboPaletteFormat.SelectedItem, out _paletteData); } else { if ((format.RawFormat == WiiPixelFormat.CMPR) && (_cmprBuffer != null)) { if (_origTEX0 != null || _bresParent != null) _textureData = ((CMPR)format).EncodeTextureCached(_source, (int)numLOD.Value, _cmprBuffer); else if (_origREFT != null || _reftParent != null) _textureData = ((CMPR)format).EncodeREFTTextureCached(_source, (int)numLOD.Value, _cmprBuffer); else if (_origTPL != null || _tplParent != null) _textureData = ((CMPR)format).EncodeTPLTextureCached(_source, (int)numLOD.Value, _cmprBuffer); } else if (_origTEX0 != null || _bresParent != null) _textureData = format.EncodeTEX0Texture(_source, (int)numLOD.Value); else if (_origREFT != null || _reftParent != null) _textureData = format.EncodeREFTTexture(_source, (int)numLOD.Value, WiiPaletteFormat.IA8); else if (_origTPL != null || _tplParent != null) _textureData = format.EncodeTPLTexture(_source, (int)numLOD.Value); } if (_bresParent != null) { _origTEX0 = _bresParent.CreateResource<TEX0Node>(Path.GetFileNameWithoutExtension(_imageSource)); if (_paletteData != null) { _origPLT0 = _bresParent.CreateResource<PLT0Node>(_origTEX0.Name); _origPLT0.Name = _origTEX0.Name; _origPLT0.ReplaceRaw(_paletteData); } _origTEX0.ReplaceRaw(_textureData); } else if (_tplParent != null) { _origTPL = new TPLTextureNode() { Name = "Texture" }; _tplParent.AddChild(_origTPL); _origTPL.ReplaceRaw(_textureData); if (_paletteData != null) { _origTPLPlt = new TPLPaletteNode() { Name = "Palette" }; _origTPL.AddChild(_origTPLPlt); _origTPLPlt.ReplaceRaw(_paletteData); } } else if (_reftParent != null) { _reftParent.AddChild(_origREFT = new REFTEntryNode() { Name = Path.GetFileNameWithoutExtension(_imageSource) }); _origREFT.ReplaceRaw(_textureData); } else if (_origTEX0 != null) { if (_origPLT0 != null) { if (_paletteData != null) _origPLT0.ReplaceRaw(_paletteData); else { _origPLT0.Remove(); _origPLT0.Dispose(); } } else if (_paletteData != null) { if ((_origTEX0.Parent == null) || (_origTEX0.Parent.Parent == null)) { _paletteData.Dispose(); _paletteData = null; } else { _bresParent = _origTEX0.Parent.Parent as BRESNode; _origPLT0 = _bresParent.CreateResource<PLT0Node>(_origTEX0.Name); _origPLT0.Name = _origTEX0.Name; _origPLT0.ReplaceRaw(_paletteData); } } _origTEX0.ReplaceRaw(_textureData); } else if (_origREFT != null) _origREFT.ReplaceRaw(_textureData); else if (_origTPL != null) { _origTPL.ReplaceRaw(_textureData); if (_origTPLPlt != null) { if (_paletteData != null) { _origTPL.AddChild(_origTPLPlt); _origTPLPlt.ReplaceRaw(_paletteData); } else { _origTPLPlt.Remove(); _origTPLPlt.Dispose(); } } else if (_paletteData != null) { if (_origTPL.Parent == null) { _paletteData.Dispose(); _paletteData = null; } else { _origTPLPlt = new TPLPaletteNode() { _name = "Palette" }; _origTPL.AddChild(_origTPLPlt); _origTPLPlt.ReplaceRaw(_paletteData); } } } }