Пример #1
0
        private bool LoadModel(string modelFormatFilename)
        {
            modelFormatFilename = DSystemConfiguration.ModelFilePath + @"Trees\" + modelFormatFilename;
            List <string> lines = null;

            try
            {
                // Open the model file.
                lines = File.ReadLines(modelFormatFilename).ToList();

                // Read in the vertex count.
                var vertexCountString = lines[0].Split(new char[] { ':' })[1].Trim();
                LoadingCount = int.Parse(vertexCountString);

                // Create the model using the vertex count that was read in.
                ModelObject = new DModelFormat[LoadingCount];

                // Read in the vertex data.
                for (var i = 4; i < lines.Count && i < 4 + LoadingCount; i++)
                {
                    var modelArray = lines[i].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                    ModelObject[i - 4] = new DModelFormat()
                    {
                        x  = float.Parse(modelArray[0]),
                        y  = float.Parse(modelArray[1]),
                        z  = float.Parse(modelArray[2]),
                        tu = float.Parse(modelArray[3]),
                        tv = float.Parse(modelArray[4]),
                        nx = float.Parse(modelArray[5]),
                        ny = float.Parse(modelArray[6]),
                        nz = float.Parse(modelArray[7])
                    };
                }

                // Close the model file.
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        private bool LoadModel(string modelFormatFilename)
        {
            modelFormatFilename = DSystemConfiguration.ModelFilePath + modelFormatFilename;
            List <string> lines = null;

            try
            {
                lines = File.ReadLines(modelFormatFilename).ToList();

                var vertexCountString = lines[0].Split(new char[] { ':' })[1].Trim();
                VertexCount = int.Parse(vertexCountString);
                IndexCount  = VertexCount;
                ModelObject = new DModelFormat[VertexCount];

                for (var i = 4; i < lines.Count && i < 4 + VertexCount; i++)
                {
                    var modelArray = lines[i].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                    ModelObject[i - 4] = new DModelFormat()
                    {
                        x  = float.Parse(modelArray[0]),
                        y  = float.Parse(modelArray[1]),
                        z  = float.Parse(modelArray[2]),
                        tu = float.Parse(modelArray[3]),
                        tv = float.Parse(modelArray[4]),
                        nx = float.Parse(modelArray[5]),
                        ny = float.Parse(modelArray[6]),
                        nz = float.Parse(modelArray[7])
                    };
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }