Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
        public TextureEditorForm(BMD model, ModelImporter _owner)
        {
            InitializeComponent();

            m_Model = model;
            this._owner = _owner;

            LoadTextures();
            InitTimer();
        }
Ejemplo n.º 7
0
 public SRTContainer[] GetAllLocalSRTValuesForFrame(BMD.ModelChunk[] chunks, int frame)
 {
     return GetAllLocalSRTValuesForFrame(chunks.Length, frame);
 }
Ejemplo n.º 8
0
            /*
             * 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;
            }
Ejemplo n.º 9
0
 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;
 }
Ejemplo n.º 10
0
 public ModelChunk(BMD model)
 {
     m_Model = model;
 }
Ejemplo n.º 11
0
        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));
            }
        }
Ejemplo n.º 12
0
        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();
        }
Ejemplo n.º 13
0
        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;
        }
Ejemplo n.º 14
0
        public static void RemoveModel(BMD model)
        {
            if (!m_Models.ContainsKey(model.m_FileName))
                return;

            RemoveModel(model.m_FileName);
        }