Esempio n. 1
0
		public static idMapBrush ParseQ3(idLexer lexer, Vector3 origin)
		{
			int rotate;
			int[] shift = new int[2];
			float[] scale = new float[2];

			Vector3[] planePoints = new Vector3[3];
			List<idMapBrushSide> sides = new List<idMapBrushSide>();
			idMapBrushSide side;
			idToken token;

			do
			{
				if(lexer.CheckTokenString("}") == true)
				{
					break;
				}

				side = new idMapBrushSide();
				sides.Add(side);

				// read the three point plane definition
				float[] tmp = lexer.Parse1DMatrix(3);
				float[] tmp2 = lexer.Parse1DMatrix(3);
				float[] tmp3 = lexer.Parse1DMatrix(3);

				if((tmp == null) || (tmp2 == null) || (tmp3 == null))
				{
					lexer.Error("idMapBrush::ParseQ3: unable to read brush side plane definition");
					return null;
				}

				planePoints[0] = new Vector3(tmp[0], tmp[1], tmp[2]) - origin;
				planePoints[1] = new Vector3(tmp2[0], tmp2[1], tmp2[2]) - origin;
				planePoints[2] = new Vector3(tmp3[0], tmp3[1], tmp3[2]) - origin;

				side.Plane.FromPoints(planePoints[0], planePoints[1], planePoints[2]);

				// read the material
				token = lexer.ReadTokenOnLine();

				if(token == null)
				{
					lexer.Error("idMapBrush::ParseQ3: unable to read brush side material");
					return null;
				}

				// we have an implicit 'textures/' in the old format
				side.Material = "textures/" + token.ToString();

				// read the texture shift, rotate and scale
				shift[0] = lexer.ParseInt();
				shift[1] = lexer.ParseInt();

				rotate = lexer.ParseInt();

				scale[0] = lexer.ParseFloat();
				scale[1] = lexer.ParseFloat();

				side.TextureMatrix[0] = new Vector3(0.03125f, 0.0f, 0.0f);
				side.TextureMatrix[1] = new Vector3(0.0f, 0.03125f, 0.0f);

				side.Origin = origin;

				// Q2 allowed override of default flags and values, but we don't any more
				if(lexer.ReadTokenOnLine() != null)
				{
					if(lexer.ReadTokenOnLine() != null)
					{
						if(lexer.ReadTokenOnLine() != null)
						{

						}
					}
				}
			}
			while(true);

			idMapBrush brush = new idMapBrush();

			for(int i = 0; i < sides.Count; i++)
			{
				brush.AddSide(sides[i]);
			}

			brush.Dict = new idDict();

			return brush;
		}
Esempio n. 2
0
		public static idMapBrush Parse(idLexer lexer, Vector3 origin, bool newFormat = true, float version = idMapFile.CurrentMapVersion)
		{
			idToken token;
			idMapBrushSide side;
			List<idMapBrushSide> sides = new List<idMapBrushSide>();
			idDict dict = new idDict();
			Vector3[] planePoints = new Vector3[3];

			if(lexer.ExpectTokenString("{") == false)
			{
				return null;
			}

			do
			{
				if((token = lexer.ReadToken()) == null)
				{
					lexer.Error("idMapBrush::Parse: unexpected EOF");
					return null;
				}

				if(token.ToString() == "}")
				{
					break;
				}

				// here we may have to jump over brush epairs ( only used in editor )
				do
				{
					// if token is a brace
					if(token.ToString() == "(")
					{
						break;
					}

					// the token should be a key string for a key/value pair
					if(token.Type != TokenType.String)
					{
						lexer.Error("idMapBrush::Parse: unexpected {0}, expected ( or epair key string", token.ToString());
						return null;
					}


					string key = token.ToString();

					if(((token = lexer.ReadTokenOnLine()) == null) || (token.Type != TokenType.String))
					{
						lexer.Error("idMapBrush::Parse: expected epair value string not found");
						return null;
					}

					dict.Set(key, token.ToString());

					// try to read the next key
					if((token = lexer.ReadToken()) == null)
					{
						lexer.Error("idMapBrush::Parse: unexpected EOF");
						return null;
					}
				}
				while(true);

				lexer.UnreadToken = token;

				side = new idMapBrushSide();
				sides.Add(side);

				if(newFormat == true)
				{
					float[] tmp = lexer.Parse1DMatrix(4);

					if(tmp == null)
					{
						lexer.Error("idMapBrush::Parse: unable to read brush side plane definition");
						return null;
					}
					else
					{
						side.Plane = new Plane(tmp[0], tmp[1], tmp[2], tmp[3]);
					}
				}
				else
				{
					// read the three point plane definition
					float[] tmp, tmp2, tmp3;

					if(((tmp = lexer.Parse1DMatrix(3)) == null)
						|| ((tmp2 = lexer.Parse1DMatrix(3)) == null)
						|| ((tmp3 = lexer.Parse1DMatrix(3)) == null))
					{
						lexer.Error("idMapBrush::Parse: unable to read brush side plane definition");
						return null;
					}

					planePoints[0] = new Vector3(tmp[0], tmp[1], tmp[2]) - origin;
					planePoints[1] = new Vector3(tmp2[0], tmp2[1], tmp2[2]) - origin;
					planePoints[2] = new Vector3(tmp3[0], tmp3[1], tmp3[2]) - origin;

					side.Plane.FromPoints(planePoints[0], planePoints[1], planePoints[2]);
				}

				// read the texture matrix
				// this is odd, because the texmat is 2D relative to default planar texture axis
				float[,] tmp5 = lexer.Parse2DMatrix(2, 3);

				if(tmp5 == null)
				{
					lexer.Error("idMapBrush::Parse: unable to read brush side texture matrix");
					return null;
				}

				side.TextureMatrix[0] = new Vector3(tmp5[0, 0], tmp5[0, 1], tmp5[0, 2]);
				side.TextureMatrix[1] = new Vector3(tmp5[1, 0], tmp5[1, 1], tmp5[1, 2]);
				side.Origin = origin;

				// read the material
				if((token = lexer.ReadTokenOnLine()) == null)
				{
					lexer.Error("idMapBrush::Parse: unable to read brush side material");
					return null;
				}

				// we had an implicit 'textures/' in the old format...
				if(version < 2.0f)
				{
					side.Material = "textures/" + token.ToString();
				}
				else
				{
					side.Material = token.ToString();
				}

				// Q2 allowed override of default flags and values, but we don't any more
				if(lexer.ReadTokenOnLine() != null)
				{
					if(lexer.ReadTokenOnLine() != null)
					{
						if(lexer.ReadTokenOnLine() != null)
						{

						}
					}
				}
			}
			while(true);

			if(lexer.ExpectTokenString("}") == false)
			{
				return null;
			}

			idMapBrush brush = new idMapBrush();

			foreach(idMapBrushSide s in sides)
			{
				brush.AddSide(s);
			}

			brush.Dict = dict;

			return brush;
		}
Esempio n. 3
0
		public void AddSide(idMapBrushSide side)
		{
			_sides.Add(side);
		}
Esempio n. 4
0
        public static idMapBrush ParseQ3(idLexer lexer, Vector3 origin)
        {
            int rotate;

            int[]   shift = new int[2];
            float[] scale = new float[2];

            Vector3[]             planePoints = new Vector3[3];
            List <idMapBrushSide> sides       = new List <idMapBrushSide>();
            idMapBrushSide        side;
            idToken token;

            do
            {
                if (lexer.CheckTokenString("}") == true)
                {
                    break;
                }

                side = new idMapBrushSide();
                sides.Add(side);

                // read the three point plane definition
                float[] tmp  = lexer.Parse1DMatrix(3);
                float[] tmp2 = lexer.Parse1DMatrix(3);
                float[] tmp3 = lexer.Parse1DMatrix(3);

                if ((tmp == null) || (tmp2 == null) || (tmp3 == null))
                {
                    lexer.Error("idMapBrush::ParseQ3: unable to read brush side plane definition");
                    return(null);
                }

                planePoints[0] = new Vector3(tmp[0], tmp[1], tmp[2]) - origin;
                planePoints[1] = new Vector3(tmp2[0], tmp2[1], tmp2[2]) - origin;
                planePoints[2] = new Vector3(tmp3[0], tmp3[1], tmp3[2]) - origin;

                side.Plane.FromPoints(planePoints[0], planePoints[1], planePoints[2]);

                // read the material
                token = lexer.ReadTokenOnLine();

                if (token == null)
                {
                    lexer.Error("idMapBrush::ParseQ3: unable to read brush side material");
                    return(null);
                }

                // we have an implicit 'textures/' in the old format
                side.Material = "textures/" + token.ToString();

                // read the texture shift, rotate and scale
                shift[0] = lexer.ParseInt();
                shift[1] = lexer.ParseInt();

                rotate = lexer.ParseInt();

                scale[0] = lexer.ParseFloat();
                scale[1] = lexer.ParseFloat();

                side.TextureMatrix[0] = new Vector3(0.03125f, 0.0f, 0.0f);
                side.TextureMatrix[1] = new Vector3(0.0f, 0.03125f, 0.0f);

                side.Origin = origin;

                // Q2 allowed override of default flags and values, but we don't any more
                if (lexer.ReadTokenOnLine() != null)
                {
                    if (lexer.ReadTokenOnLine() != null)
                    {
                        if (lexer.ReadTokenOnLine() != null)
                        {
                        }
                    }
                }
            }while(true);

            idMapBrush brush = new idMapBrush();

            for (int i = 0; i < sides.Count; i++)
            {
                brush.AddSide(sides[i]);
            }

            brush.Dict = new idDict();

            return(brush);
        }
Esempio n. 5
0
        public static idMapBrush Parse(idLexer lexer, Vector3 origin, bool newFormat = true, float version = idMapFile.CurrentMapVersion)
        {
            idToken               token;
            idMapBrushSide        side;
            List <idMapBrushSide> sides = new List <idMapBrushSide>();
            idDict dict = new idDict();

            Vector3[] planePoints = new Vector3[3];

            if (lexer.ExpectTokenString("{") == false)
            {
                return(null);
            }

            do
            {
                if ((token = lexer.ReadToken()) == null)
                {
                    lexer.Error("idMapBrush::Parse: unexpected EOF");
                    return(null);
                }

                if (token.ToString() == "}")
                {
                    break;
                }

                // here we may have to jump over brush epairs ( only used in editor )
                do
                {
                    // if token is a brace
                    if (token.ToString() == "(")
                    {
                        break;
                    }

                    // the token should be a key string for a key/value pair
                    if (token.Type != TokenType.String)
                    {
                        lexer.Error("idMapBrush::Parse: unexpected {0}, expected ( or epair key string", token.ToString());
                        return(null);
                    }


                    string key = token.ToString();

                    if (((token = lexer.ReadTokenOnLine()) == null) || (token.Type != TokenType.String))
                    {
                        lexer.Error("idMapBrush::Parse: expected epair value string not found");
                        return(null);
                    }

                    dict.Set(key, token.ToString());

                    // try to read the next key
                    if ((token = lexer.ReadToken()) == null)
                    {
                        lexer.Error("idMapBrush::Parse: unexpected EOF");
                        return(null);
                    }
                }while(true);

                lexer.UnreadToken = token;

                side = new idMapBrushSide();
                sides.Add(side);

                if (newFormat == true)
                {
                    float[] tmp = lexer.Parse1DMatrix(4);

                    if (tmp == null)
                    {
                        lexer.Error("idMapBrush::Parse: unable to read brush side plane definition");
                        return(null);
                    }
                    else
                    {
                        side.Plane = new Plane(tmp[0], tmp[1], tmp[2], tmp[3]);
                    }
                }
                else
                {
                    // read the three point plane definition
                    float[] tmp, tmp2, tmp3;

                    if (((tmp = lexer.Parse1DMatrix(3)) == null) ||
                        ((tmp2 = lexer.Parse1DMatrix(3)) == null) ||
                        ((tmp3 = lexer.Parse1DMatrix(3)) == null))
                    {
                        lexer.Error("idMapBrush::Parse: unable to read brush side plane definition");
                        return(null);
                    }

                    planePoints[0] = new Vector3(tmp[0], tmp[1], tmp[2]) - origin;
                    planePoints[1] = new Vector3(tmp2[0], tmp2[1], tmp2[2]) - origin;
                    planePoints[2] = new Vector3(tmp3[0], tmp3[1], tmp3[2]) - origin;

                    side.Plane.FromPoints(planePoints[0], planePoints[1], planePoints[2]);
                }

                // read the texture matrix
                // this is odd, because the texmat is 2D relative to default planar texture axis
                float[,] tmp5 = lexer.Parse2DMatrix(2, 3);

                if (tmp5 == null)
                {
                    lexer.Error("idMapBrush::Parse: unable to read brush side texture matrix");
                    return(null);
                }

                side.TextureMatrix[0] = new Vector3(tmp5[0, 0], tmp5[0, 1], tmp5[0, 2]);
                side.TextureMatrix[1] = new Vector3(tmp5[1, 0], tmp5[1, 1], tmp5[1, 2]);
                side.Origin           = origin;

                // read the material
                if ((token = lexer.ReadTokenOnLine()) == null)
                {
                    lexer.Error("idMapBrush::Parse: unable to read brush side material");
                    return(null);
                }

                // we had an implicit 'textures/' in the old format...
                if (version < 2.0f)
                {
                    side.Material = "textures/" + token.ToString();
                }
                else
                {
                    side.Material = token.ToString();
                }

                // Q2 allowed override of default flags and values, but we don't any more
                if (lexer.ReadTokenOnLine() != null)
                {
                    if (lexer.ReadTokenOnLine() != null)
                    {
                        if (lexer.ReadTokenOnLine() != null)
                        {
                        }
                    }
                }
            }while(true);

            if (lexer.ExpectTokenString("}") == false)
            {
                return(null);
            }

            idMapBrush brush = new idMapBrush();

            foreach (idMapBrushSide s in sides)
            {
                brush.AddSide(s);
            }

            brush.Dict = dict;

            return(brush);
        }
Esempio n. 6
0
 public void AddSide(idMapBrushSide side)
 {
     _sides.Add(side);
 }