// Convert .map file to .obj file.
        private static void ConvertFile(string path)
        {
            Console.WriteLine("Parsing file: " + path + "...");

            DateTime startTime = DateTime.Now;

            RadiantMap   map = RadiantMap.Parse(path);
            WavefrontObj obj = WavefrontObj.CreateFromRadiantMap(map);

            if (_textureFilter.Length > 0)
            {
                obj.FilterTextures(_textureFilter);
            }

            obj.SaveFile(Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path)) + ".obj", _scale);

            DateTime endTime = DateTime.Now;

            Console.WriteLine("Finished in: " + (endTime - startTime).Milliseconds + "ms.");
        }
        // Converts a RadiantMap object to a WavefrontObj object.
        public static WavefrontObj CreateFromRadiantMap(RadiantMap map)
        {
            List <ObjObject> objects = new List <ObjObject>();

            for (int i = 0; i < map.Brushes.Length; ++i)
            {
                Brush     brush = map.Brushes[i];
                ObjObject obj   = ObjObject.CreateFromBrush("Brush_" + i, brush);
                objects.Add(obj);
            }

            for (int i = 0; i < map.Patches.Length; ++i)
            {
                Patch     patch = map.Patches[i];
                ObjObject obj   = ObjObject.CreateFromPatch("Patch_" + i, patch);
                objects.Add(obj);
            }

            return(new WavefrontObj(objects.ToArray()));
        }
Exemple #3
0
        // Parses a .map file to our radiant map object.
        public static RadiantMap Parse(string path)
        {
            string[]      content    = File.ReadAllLines(path);
            bool          started    = false;
            bool          inBrush    = false;
            bool          inPatch    = false;
            List <string> brushLines = null;

            RadiantMap map = new RadiantMap();

            for (int i = 0; i < content.Length; ++i)
            {
                // Skip empty lines.
                if (content[i].Length < 1)
                {
                    continue;
                }

                if (started)
                {
                    if (content[i].Contains("{"))
                    {
                        if (!inBrush)
                        {
                            inBrush    = true;
                            brushLines = new List <string>();
                            brushLines.Add(content[i]);
                        }
                        else if (!inPatch)
                        {
                            inPatch = true;
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else if (content[i].Contains("}"))
                    {
                        if (inPatch)
                        {
                            map.Add(Patch.CreateFromCode(brushLines.ToArray()));
                            inPatch = false;
                        }
                        else if (inBrush)
                        {
                            map.Add(Brush.CreateFromCode(brushLines.ToArray()));
                            inBrush    = false;
                            brushLines = new List <string>();
                        }
                        else
                        {
                            break;
                        }
                    }
                    else if (inBrush)
                    {
                        brushLines.Add(content[i]);
                    }
                }
                else
                {
                    if (content[i][0] == '{')
                    {
                        started = true;
                    }
                }
            }

            return(map);
        }