コード例 #1
0
ファイル: TexturePreview.cs プロジェクト: spazmodica/acrender
        private void lbTextureList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lbTextureList.SelectedIndex >= 0)
            {
                uint fileId = ((EmbeddedFileEntry)lbTextureList.SelectedItem).FileID;

                if ((fileId & 0xFF000000) == 0x04000000)
                {
                    ACPalette palette = PaletteLoader.Instance.LoadPalette(fileId);
                    SetPreviewBitmap(palette.GetPreviewBitmap());
                }
                else if ((fileId & 0xFF000000) == 0x05000000)
                {
                    ACTexture texture = TextureLoader.Instance.LoadTexture(fileId);
                    if (cbAlphaMap.Checked)
                    {
                        SetPreviewBitmap(ConvertToAlphaMap(texture.GetBitmap()));
                    }
                    else
                    {
                        SetPreviewBitmap(texture.GetBitmap());
                    }
                }
                else if ((fileId & 0xFF000000) == 0x08000000)
                {
                    MeshDecoration decoration = new MeshDecoration(fileId);
                    Bitmap         bmp        = new Bitmap(pbPreview.Width, pbPreview.Height, PixelFormat.Format24bppRgb);
                    using (Graphics g = Graphics.FromImage(bmp))
                    {
                        g.Clear(Color.White);
                        int  height = 10;
                        Font font   = new Font("Tahoma", height);
                        g.DrawString(String.Format("Decoration 0x{0:X8}", fileId), font, Brushes.Black, 5, 5 + (0 * height));
                        if (decoration.DecorationType == DecorationType.Texture)
                        {
                            g.DrawString(String.Format("Texture, texture id: 0x{0:X8}", decoration.Texture.ID), font, Brushes.Black, 5, 5 + (1 * height));
                        }
                        else if (decoration.DecorationType == DecorationType.SolidColor)
                        {
                            g.DrawString(String.Format("Solid, color: 0x{0:X8}", decoration.SolidColor.ToArgb()), font, Brushes.Black, 5, 5 + (1 * height));
                        }
                        else if (decoration.DecorationType == DecorationType.Unknown)
                        {
                            g.DrawString(String.Format("Unknown decoration type."), font, Brushes.Black, 5, 5 + (1 * height));
                        }
                        g.DrawString(String.Format("Type flag: {0:X}", decoration.TypeFlag), font, Brushes.Black, 5, 5 + (2 * height));
                    }
                    SetPreviewBitmap(bmp);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Initialized the vertex & index buffers for this mesh scene
        /// </summary>
        public void ReInitialize()
        {
            if (m_noTexturing)
            {
                ReInitializeWithoutTexturing();
                return;
            }

            // prepare vars
            m_coloredTrifans.Clear();
            m_texturedTrifans.Clear();

            // loop through the texturing info and determine for each of them what
            // type of decoration it is.
            m_decorations = new MeshDecoration[m_simpleMesh.TextureInfo.Length];
            m_textures    = new Texture[m_decorations.Length];
            for (int i = 0; i < m_decorations.Length; i++)
            {
                m_decorations[i] = new MeshDecoration(m_simpleMesh.TextureInfo[i]);
                if (m_decorations[i].DecorationType == DecorationType.Texture)
                {
                    Bitmap bmp = m_decorations[i].Texture.GetBitmap();
                    m_textures[i] = new Texture(m_device, bmp, 0, Pool.Managed);
                }
            }

            // we'll have to create two sets of index buffers:
            // one for textured trifans and one for colored trifans
            // we'll have to determine for each trifan to which of these it belongs

            List <VertexLookup> texturedVertexTable = new List <VertexLookup>();
            List <VertexLookup> coloredVertexTable  = new List <VertexLookup>();
            List <ushort>       texturedIndexList   = new List <ushort>();
            List <ushort>       coloredIndexList    = new List <ushort>();

            for (int i = 0; i < (int)m_simpleMesh.SecondTrifanSet.TrifanCount; i++)
            {
                TrifanInfo trifan         = m_simpleMesh.SecondTrifanSet.TrifanData[i];
                bool       drawSolidColor = false;
                drawSolidColor = (trifan.Flags & 0x04) == 0x04;
                // draw solid when this trifan is drawn using a solid color
                drawSolidColor = drawSolidColor || (m_decorations[(int)trifan.TextureIndex].DecorationType == DecorationType.SolidColor);

                if (drawSolidColor)
                {
                    Color          color      = m_decorations[(int)trifan.TextureIndex].SolidColor;
                    TrifanDrawInfo trifanInfo = new TrifanDrawInfo();
                    trifanInfo.IndexBufferStart = (ushort)coloredIndexList.Count;
                    trifanInfo.PrimitiveCount   = trifan.VertexCount - 2;
                    for (int j = 0; j < trifan.VertexIndices.Length; j++)
                    {
                        VertexLookup lookup = new VertexLookup(trifan.VertexIndices[j], 0, color);
                        ushort       vertexIndex;
                        if (!coloredVertexTable.Contains(lookup))
                        {
                            coloredVertexTable.Add(lookup);
                        }
                        vertexIndex = (ushort)coloredVertexTable.IndexOf(lookup);
                        coloredIndexList.Add(vertexIndex);
                    }
                    m_coloredTrifans.Add(i, trifanInfo);
                }
                else
                {
                    TrifanDrawInfo trifanInfo = new TrifanDrawInfo();
                    trifanInfo.IndexBufferStart = (ushort)texturedIndexList.Count;
                    trifanInfo.PrimitiveCount   = trifan.VertexCount - 2;
                    for (int j = 0; j < trifan.VertexIndices.Length; j++)
                    {
                        VertexLookup lookup = new VertexLookup(trifan.VertexIndices[j], trifan.UVIndex[j]);
                        ushort       vertexIndex;
                        if (!texturedVertexTable.Contains(lookup))
                        {
                            texturedVertexTable.Add(lookup);
                        }
                        vertexIndex = (ushort)texturedVertexTable.IndexOf(lookup);
                        texturedIndexList.Add(vertexIndex);
                    }
                    m_texturedTrifans.Add(i, trifanInfo);
                }
            }

            // now create the actual index & vertex buffers

            // texture vb & ib
            if (texturedVertexTable.Count > 0)
            {
                m_vbTextured = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured),
                                                texturedVertexTable.Count, m_device, Usage.WriteOnly,
                                                CustomVertex.PositionNormalTextured.Format, Pool.Managed);
                GraphicsStream stream = m_vbTextured.Lock(0, 0, LockFlags.None);
                foreach (VertexLookup lookup in texturedVertexTable)
                {
                    VertexInfo vertex = m_simpleMesh.VertexInfo[(int)lookup.VertexId];
                    stream.Write(new CustomVertex.PositionNormalTextured(vertex.X,
                                                                         vertex.Y, vertex.Z, vertex.NX, vertex.NY, vertex.NZ,
                                                                         vertex.CUVData[lookup.UVIndex].U, vertex.CUVData[lookup.UVIndex].V));
                }
                m_vbTextured.Unlock();

                m_ibTextured = new IndexBuffer(typeof(ushort), texturedIndexList.Count,
                                               m_device, Usage.WriteOnly, Pool.Managed);
                stream = m_ibTextured.Lock(0, 0, LockFlags.None);
                stream.Write(texturedIndexList.ToArray());
                m_ibTextured.Unlock();
            }
            m_vbTexturedLength = texturedVertexTable.Count;

            // color vb & ib
            if (coloredVertexTable.Count > 0)
            {
                m_vbColored = new VertexBuffer(typeof(CustomVertex.PositionNormalColored),
                                               coloredVertexTable.Count, m_device, Usage.WriteOnly,
                                               CustomVertex.PositionNormalColored.Format, Pool.Managed);
                GraphicsStream stream = m_vbColored.Lock(0, 0, LockFlags.None);
                foreach (VertexLookup lookup in coloredVertexTable)
                {
                    VertexInfo vertex = m_simpleMesh.VertexInfo[(int)lookup.VertexId];
                    stream.Write(new CustomVertex.PositionNormalColored(vertex.X,
                                                                        vertex.Y, vertex.Z, vertex.NX, vertex.NY, vertex.NZ,
                                                                        lookup.Color.ToArgb()));
                }
                m_vbColored.Unlock();

                m_ibColored = new IndexBuffer(typeof(ushort), coloredIndexList.Count,
                                              m_device, Usage.WriteOnly, Pool.Managed);
                stream = m_ibColored.Lock(0, 0, LockFlags.None);
                stream.Write(coloredIndexList.ToArray());
                m_ibColored.Unlock();
            }
            m_vbColoredLength = coloredVertexTable.Count;
        }
コード例 #3
0
        public void ReInitializeWithoutTexturing()
        {
            // prepare vars
            m_coloredTrifans.Clear();
            m_texturedTrifans.Clear();

            // loop through the texturing info and determine for each of them what
            // type of decoration it is.
            m_decorations = new MeshDecoration[0];
            m_textures    = new Texture[0];


            // create a single trifan set of red trifans
            List <VertexLookup> coloredVertexTable = new List <VertexLookup>();
            List <ushort>       coloredIndexList   = new List <ushort>();

            for (int i = 0; i < (int)m_simpleMesh.SecondTrifanSet.TrifanCount; i++)
            {
                TrifanInfo trifan = m_simpleMesh.SecondTrifanSet.TrifanData[i];

                Color          color      = Color.Red;
                TrifanDrawInfo trifanInfo = new TrifanDrawInfo();
                trifanInfo.IndexBufferStart = (ushort)coloredIndexList.Count;
                trifanInfo.PrimitiveCount   = trifan.VertexCount - 2;
                for (int j = 0; j < trifan.VertexIndices.Length; j++)
                {
                    VertexLookup lookup = new VertexLookup(trifan.VertexIndices[j], 0, color);
                    ushort       vertexIndex;
                    if (!coloredVertexTable.Contains(lookup))
                    {
                        coloredVertexTable.Add(lookup);
                    }
                    vertexIndex = (ushort)coloredVertexTable.IndexOf(lookup);
                    coloredIndexList.Add(vertexIndex);
                }
                m_coloredTrifans.Add(i, trifanInfo);
            }

            // now create the actual index & vertex buffers

            // texture vb & ib
            m_vbTexturedLength = 0;

            // color vb & ib
            if (coloredVertexTable.Count > 0)
            {
                m_vbColored = new VertexBuffer(typeof(CustomVertex.PositionNormalColored),
                                               coloredVertexTable.Count, m_device, Usage.WriteOnly,
                                               CustomVertex.PositionNormalColored.Format, Pool.Managed);
                GraphicsStream stream = m_vbColored.Lock(0, 0, LockFlags.None);
                foreach (VertexLookup lookup in coloredVertexTable)
                {
                    VertexInfo vertex = m_simpleMesh.VertexInfo[(int)lookup.VertexId];
                    stream.Write(new CustomVertex.PositionNormalColored(vertex.X,
                                                                        vertex.Y, vertex.Z, vertex.NX, vertex.NY, vertex.NZ,
                                                                        lookup.Color.ToArgb()));
                }
                m_vbColored.Unlock();

                m_ibColored = new IndexBuffer(typeof(ushort), coloredIndexList.Count,
                                              m_device, Usage.WriteOnly, Pool.Managed);
                stream = m_ibColored.Lock(0, 0, LockFlags.None);
                stream.Write(coloredIndexList.ToArray());
                m_ibColored.Unlock();
            }
            m_vbColoredLength = coloredVertexTable.Count;
        }