private void Init(string name, string serialized)
        {
            _Name     = name;
            _Commands = new List <LDrawCommand>();
            using (StringReader reader = new StringReader(serialized))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    Regex regex = new Regex("[ ]{2,}", RegexOptions.None);
                    line = regex.Replace(line, " ").Trim();

                    if (!String.IsNullOrEmpty(line))
                    {
                        var command = LDrawCommand.DeserializeCommand(line, this);
                        if (command != null)
                        {
                            _Commands.Add(command);
                        }
                    }
                }
            }

            if (!_models.ContainsKey(name))
            {
                _models.Add(name, this);
            }
        }
        public static LDrawCommand DeserializeCommand(string line, LDrawModel parent)
        {
            LDrawCommand command = null;
            int          type;
            var          args = line.Split(' ');

            //first arg is the command type
            if (Int32.TryParse(args[0], out type))
            {
                var commandType = (CommandType)type;

                switch (commandType)
                {
                case CommandType.SubFile:
                    command = new LDrawSubFile();
                    break;

                case CommandType.Triangle:
                    command = new LDrawTriangle();
                    break;

                case CommandType.Quad:
                    command = new LDrawQuad();
                    break;
                }
            }

            //if it is a valid command
            if (command != null)
            {
                //parse the second arg for color code
                if (!int.TryParse(args[1], out command._ColorCode))
                {
                    command._Color = args[1];
                }
                //set the parent ldraw
                command._Parent = parent;
                command.Deserialize(line);
            }

            return(command);
        }
        public static LDrawCommand DeserializeCommand(string line, LDrawModel parent)
        {
            LDrawCommand command = null;
            int          type;
            var          args = line.Split(' ');

            if (Int32.TryParse(args[0], out type))
            {
                var commandType = (CommandType)type;

                switch (commandType)
                {
                case CommandType.Comment:
                    command = new LDrawComment();
                    break;

                case CommandType.SubFile:
                    command = new LDrawSubFile();
                    break;

                case CommandType.Triangle:
                    command = new LDrawTriangle();
                    break;

                case CommandType.Quad:
                    command = new LDrawQuad();
                    break;
                }
            }

            if (command != null)
            {
                if (!(command is LDrawComment) && !int.TryParse(args[1], out command._ColorCode))
                {
                    command._Color = args[1];
                }
                command._Parent = parent;
                command.Deserialize(line);
            }

            return(command);
        }