コード例 #1
0
        public static short[] GetInds(this ModelMeshPart Part)
        {
            MeshDataContainer data = Part.GetPartData();

            if (data == null)
            {
                return(null);
            }
            if (data.Indices == null)
            {
                IndexBuffer ib      = Part.IndexBuffer;
                short[]     inds    = new short[Part.PrimitiveCount * 3];
                short[]     ib_inds = ib.Tag as short[];
                if (ib_inds == null)
                {
                    ib_inds = new short[ib.IndexCount];
                    ib.GetData <short>(ib_inds);
                    ib.Tag = ib_inds;
                }
                int offset = Part.StartIndex;
                for (int i = 0; i < inds.Length; ++i)
                {
                    inds[i] = ib_inds[i + offset];
                }
                data.Indices = inds;
            }
            return(data.Indices);
        }
コード例 #2
0
        public static VertexPositionColorTexture[] GetVerts(this ModelMeshPart Part)
        {
            MeshDataContainer data = Part.GetPartData();

            if (data == null)
            {
                return(null);
            }
            if (data.Vertices == null)
            {
                VertexBuffer vb = Part.VertexBuffer;
                VertexPositionColorTexture[] verts = new VertexPositionColorTexture[Part.NumVertices];
                byte[] vb_verts = vb.Tag as byte[];
                if (vb_verts == null)
                {
                    vb_verts = new byte[vb.VertexCount * vb.VertexDeclaration.VertexStride];
                    vb.GetData <byte>(vb_verts);
                    vb.Tag = vb_verts;
                }
                int offset     = Part.VertexOffset;
                int vertStride = vb.VertexDeclaration.VertexStride;
                var elements   = vb.VertexDeclaration.GetVertexElements();
                for (int v = 0; v < verts.Length; ++v)
                {
                    verts[v].Color = Color.White;
                }
                foreach (var element in elements)
                {
                    switch (element.VertexElementUsage)
                    {
                    case VertexElementUsage.Position: {
                        for (int v = 0; v < verts.Length; ++v)
                        {
                            verts[v].Position = vb_verts.ToVector3((v + offset) * vertStride + element.Offset);
                        }
                    } break;

                    /*case VertexElementUsage.Normal: {
                     *  for (int v = 0; v < verts.Length; ++v) {
                     *      verts[v].Normal = vb_verts.ToVector3((v + offset) * vertStride + element.Offset);
                     *  }
                     * } break;*/
                    case VertexElementUsage.TextureCoordinate: {
                        for (int v = 0; v < verts.Length; ++v)
                        {
                            verts[v].TextureCoordinate = vb_verts.ToVector2((v + offset) * vertStride + element.Offset);
                        }
                    } break;

                    case VertexElementUsage.Color: {
                        for (int v = 0; v < verts.Length; ++v)
                        {
                            verts[v].Color = vb_verts.ToColor((v + offset) * vertStride + element.Offset);
                        }
                    } break;
                    }
                }

                /*for (int v = 0; v < verts.Length; ++v) {
                 *  verts[v].Position = vb_verts[v + offset].Position;
                 *  verts[v].TextureCoordinate = vb_verts[v + offset].TextureCoordinate;
                 *  verts[v].Normal = vb_verts[v + offset].Normal;
                 *  verts[v].Color = Color.White;
                 * }*/
                data.Vertices = verts;
            }
            return(data.Vertices);
        }