public int GetTextureID(BMD.MaterialGroup matgroup) { if (matgroup.m_Texture == null) return 0; string texkey = string.Format("{0}|{1}|{2:X8}", matgroup.m_Texture.m_TexName, matgroup.m_Texture.m_PalName, matgroup.m_TexParams); if (m_TextureIDs.Contains(texkey)) return (int)m_TextureIDs[texkey]; int retid = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, retid); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Four, (int)matgroup.m_Texture.m_Width, (int)matgroup.m_Texture.m_Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, matgroup.m_Texture.m_Data); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)(((matgroup.m_TexParams & 0x10000) == 0x10000) ? (((matgroup.m_TexParams & 0x40000) == 0x40000) ? TextureWrapMode.MirroredRepeat : TextureWrapMode.Repeat) : TextureWrapMode.Clamp)); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)(((matgroup.m_TexParams & 0x20000) == 0x20000) ? (((matgroup.m_TexParams & 0x80000) == 0x80000) ? TextureWrapMode.MirroredRepeat : TextureWrapMode.Repeat) : TextureWrapMode.Clamp)); m_TextureIDs.Add(texkey, retid); return retid; }
private static void SaveTextureAsPNG(BMD.Texture currentTexture, String fileName) { Bitmap tex = new Bitmap((int)currentTexture.m_Width, (int)currentTexture.m_Height); for (int y = 0; y < (int)currentTexture.m_Height; y++) { for (int x = 0; x < (int)currentTexture.m_Width; x++) { tex.SetPixel(x, y, Color.FromArgb(currentTexture.m_Data[((y * currentTexture.m_Width) + x) * 4 + 3], currentTexture.m_Data[((y * currentTexture.m_Width) + x) * 4 + 2], currentTexture.m_Data[((y * currentTexture.m_Width) + x) * 4 + 1], currentTexture.m_Data[((y * currentTexture.m_Width) + x) * 4])); } } try { tex.Save(fileName, System.Drawing.Imaging.ImageFormat.Png); } catch (Exception ex) { MessageBox.Show("An error occurred while trying to save texture " + currentTexture.m_TexName + ".\n\n " + ex.Message + "\n" + ex.Data + "\n" + ex.StackTrace + "\n" + ex.Source); } }
public ModelPiece(BMD.MaterialGroup matgroup, TextureCache texcache) { BeginMode[] beginmodes = { BeginMode.Triangles, BeginMode.Quads, BeginMode.TriangleStrip, BeginMode.QuadStrip }; m_TextureID = texcache.GetTextureID(matgroup); m_DispListID = GL.GenLists(1); GL.NewList(m_DispListID, ListMode.Compile); GL.BindTexture(TextureTarget.Texture2D, m_TextureID); foreach (BMD.VertexList vtxlist in matgroup.m_Geometry) { GL.Begin(beginmodes[vtxlist.m_PolyType]); foreach (BMD.Vertex vtx in vtxlist.m_VertexList) { GL.Color4(vtx.m_Color); if (m_TextureID != 0) GL.TexCoord2(vtx.m_TexCoord); GL.Vertex3(vtx.m_Position); } GL.End(); } GL.EndList(); }
public static int[] GetDisplayLists(BMD model) { if (!m_Models.ContainsKey(model.m_FileName)) return null; CachedModel cmdl = m_Models[model.m_FileName]; if (cmdl.m_DisplayLists != null) return cmdl.m_DisplayLists; int[] dl = new int[3]; bool keep = false; dl[0] = GL.GenLists(1); GL.NewList(dl[0], ListMode.Compile); keep = cmdl.m_Model.Render(RenderMode.Opaque, 1f); GL.EndList(); if (!keep) { GL.DeleteLists(dl[0], 1); dl[0] = 0; } dl[1] = GL.GenLists(1); GL.NewList(dl[1], ListMode.Compile); keep = cmdl.m_Model.Render(RenderMode.Translucent, 1f); GL.EndList(); if (!keep) { GL.DeleteLists(dl[1], 1); dl[1] = 0; } dl[2] = GL.GenLists(1); GL.NewList(dl[2], ListMode.Compile); keep = cmdl.m_Model.Render(RenderMode.Picking, 1f); GL.EndList(); if (!keep) { GL.DeleteLists(dl[2], 1); dl[2] = 0; } cmdl.m_DisplayLists = dl; return dl; }
public Matrix4[] GetAllLocalMatricesForFrame(BMD.ModelChunk[] chunks, int frame) { Matrix4[] matrices = new Matrix4[chunks.Length]; for (int i = 0; i < chunks.Length; i++) { if (i >= m_AnimationData.Length) break; matrices[i] = m_AnimationData[i].GetLocalMatrix(frame); } return matrices; }
public TextureEditorForm(BMD model, ModelImporter _owner) { InitializeComponent(); m_Model = model; this._owner = _owner; LoadTextures(); InitTimer(); }
public SRTContainer[] GetAllLocalSRTValuesForFrame(BMD.ModelChunk[] chunks, int frame) { return GetAllLocalSRTValuesForFrame(chunks.Length, frame); }
/* * Returns the SRT matrix for the specified bone for the current frame having been multiplied by all parent transformations */ public Matrix4 GetMatrix(BMD.ModelChunk[] chunks, int boneID, Matrix4[] otherMatrices, int frame) { SRTContainer srt = GetScaleRotationTranslation(frame); Matrix4 ret = srt.m_Matrix; if (chunks[boneID].m_ParentOffset < 0) { Matrix4.Mult(ref ret, ref otherMatrices[boneID + chunks[boneID].m_ParentOffset], out ret); } return ret; }
public void Construct(string filename, float scale) { m_Model = ModelCache.GetModel(filename); m_DisplayLists = ModelCache.GetDisplayLists(m_Model); m_Scale = new Vector3(scale, scale, scale); m_Filename = filename; }
public ModelChunk(BMD model) { m_Model = model; }
private void LoadTextures() { // Reload the model m_Model = new BMD(m_Model.m_File); lbxTextures.Items.Clear(); for (int i = 0; i < m_Model.m_TextureIDs.Count; i++) { lbxTextures.Items.Add(m_Model.m_TextureIDs.Keys.ElementAt(i)); } lbxPalettes.Items.Clear(); for (int i = 0; i < m_Model.m_PaletteIDs.Keys.Count; i++) { lbxPalettes.Items.Add(m_Model.m_PaletteIDs.Keys.ElementAt(i)); } }
private void LoadBitmap(BMD.Texture currentTexture) { Bitmap tex = new Bitmap((int)currentTexture.m_Width, (int)currentTexture.m_Height); for (int y = 0; y < (int)currentTexture.m_Height; y++) { for (int x = 0; x < (int)currentTexture.m_Width; x++) { tex.SetPixel(x, y, Color.FromArgb(currentTexture.m_Data[((y * currentTexture.m_Width) + x) * 4 + 3], currentTexture.m_Data[((y * currentTexture.m_Width) + x) * 4 + 2], currentTexture.m_Data[((y * currentTexture.m_Width) + x) * 4 + 1], currentTexture.m_Data[((y * currentTexture.m_Width) + x) * 4])); } } pbxTexture.Image = new Bitmap(tex); pbxTexture.Refresh(); }
public static BMD GetModel(string name) { if (m_Models.ContainsKey(name)) { CachedModel found = m_Models[name]; found.m_References++; return found.m_Model; } NitroFile mdfile = Program.m_ROM.GetFileFromName(name); if (mdfile == null) return null; BMD model = new BMD(mdfile); model.PrepareToRender(); CachedModel cmdl = new CachedModel(); cmdl.m_Model = model; cmdl.m_DisplayLists = null; cmdl.m_References = 1; m_Models.Add(name, cmdl); return model; }
public static void RemoveModel(BMD model) { if (!m_Models.ContainsKey(model.m_FileName)) return; RemoveModel(model.m_FileName); }