packages/Windows API Code Pack 1.1/source/Samples/DirectX/CS/UtilitiesLibrary/MeshLoader/XMeshLoader.cs
/// <summary>
/// Loads the per vertex color for a mesh
/// </summary>
/// <param name="vertexColorData"></param>
/// <returns></returns>
Loads the per vertex color for a mesh
Loads the per vertex color for a mesh
Dictionary<int, Vector4F> LoadMeshColors(IXDataObject dataObject)
        {
            Regex findVertexColor = new Regex(@"([\d]+); ([\d]+\.[\d]+);([\d]+\.[\d]+);([\d]+\.[\d]+);([\d]+\.[\d]+);;");
            Match vertexCount = findArrayCount.Match(dataObject.Body);
            if(!vertexCount.Success)
                throw new System.IO.InvalidDataException("problem reading vertex colors count");
            Dictionary<int, Vector4F> colorDictionary = new Dictionary<int,Vector4F>();
            int verticies = int.Parse(vertexCount.Groups[1].Value, CultureInfo.InvariantCulture);
            int dataOffset = vertexCount.Index + vertexCount.Length;
            for(int vertexIndex = 0; vertexIndex < verticies; vertexIndex++)
            {
                Match vertexColor = findVertexColor.Match(dataObject.Body, dataOffset);
                if(!vertexColor.Success)
                    throw new System.IO.InvalidDataException("problem reading vertex colors");
                else
                    dataOffset = vertexColor.Index + vertexColor.Length;
                colorDictionary[int.Parse(vertexColor.Groups[1].Value, CultureInfo.InvariantCulture)] =
                    new Vector4F(
                        float.Parse(vertexColor.Groups[2].Value, CultureInfo.InvariantCulture),
                        float.Parse(vertexColor.Groups[3].Value, CultureInfo.InvariantCulture),
                        float.Parse(vertexColor.Groups[4].Value, CultureInfo.InvariantCulture),
                        float.Parse(vertexColor.Groups[5].Value, CultureInfo.InvariantCulture));
            }
            return colorDictionary;
        }
Dictionary < int , Vector4F > LoadMeshColors ( IXDataObject dataObject ) { Regex findVertexColor = new Regex ( @"([\d]+); ([\d]+\.[\d]+);([\d]+\.[\d]+);([\d]+\.[\d]+);([\d]+\.[\d]+);;" ) ; Match vertexCount = findArrayCount . Match ( dataObject . Body ) ; if ( ! vertexCount . Success ) throw new System . IO . InvalidDataException ( " " ) ; Dictionary < int , Vector4F > colorDictionary = new Dictionary < int , Vector4F > ( ) ; int verticies = int . Parse ( vertexCount . Groups [ 1 ] . Value , CultureInfo . InvariantCulture ) ; int dataOffset = vertexCount . Index + vertexCount . Length ; for ( int vertexIndex = 0 ; vertexIndex < verticies ; vertexIndex ++ ) { Match vertexColor = findVertexColor . Match ( dataObject . Body , dataOffset ) ; if ( ! vertexColor . Success ) throw new System . IO . InvalidDataException ( " " ) ; else dataOffset = vertexColor . Index + vertexColor . Length ; colorDictionary [ int . Parse ( vertexColor . Groups [ 1 ] . Value , CultureInfo . InvariantCulture ) ] = new Vector4F ( float . Parse ( vertexColor . Groups [ 2 ] . Value , CultureInfo . InvariantCulture ) , float . Parse ( vertexColor . Groups [ 3 ] . Value , CultureInfo . InvariantCulture ) , float . Parse ( vertexColor . Groups [ 4 ] . Value , CultureInfo . InvariantCulture ) , float . Parse ( vertexColor . Groups [ 5 ] . Value , CultureInfo . InvariantCulture ) ) ; } return colorDictionary ; }
Loads the per vertex color for a mesh
Loads the per vertex color for a mesh
None
dataObject
IXDataObject
vertexColorData
None