Exemplo n.º 1
0
		public static idMapPatch Parse(idLexer lexer, Vector3 origin, bool patchDef3 = true, float version = idMapFile.CurrentMapVersion)
		{
			if(lexer.ExpectTokenString("{") == false)
			{
				return null;
			}

			// read the material (we had an implicit 'textures/' in the old format...)
			idToken token = lexer.ReadToken();

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

			// Parse it
			float[] info;

			if(patchDef3 == true)
			{
				info = lexer.Parse1DMatrix(7);

				if(info == null)
				{
					lexer.Error("idMapPatch::Parse: unable to Parse patchDef3 info");
					return null;
				}
			} 
			else 
			{
				info = lexer.Parse1DMatrix(5);

				if(info == null)
				{
					lexer.Error("idMapPatch::Parse: unable to parse patchDef2 info");
					return null;
				}
			}

			idMapPatch patch = new idMapPatch((int) info[0], (int) info[1]);

			if(version < 2.0f)
			{
				patch.Material = "textures/" + token.ToString();
			}
			else
			{
				patch.Material = token.ToString();
			}

			if(patchDef3 == true)
			{
				patch.HorizontalSubdivisions = (int) info[2];
				patch.VerticalSubdivisions = (int) info[3];
				patch.ExplicitlySubdivided = true;
			}

			if((patch.Width < 0) || (patch.Height < 0))
			{
				lexer.Error("idMapPatch::Parse: bad size");
				return null;
			}

			// these were written out in the wrong order, IMHO
			if(lexer.ExpectTokenString("(") == false)
			{
				lexer.Error("idMapPatch::Parse: bad patch vertex data");
				return null;
			}

			for(int j = 0; j < patch.Width; j++)
			{
				if(lexer.ExpectTokenString("(") == false)
				{
					lexer.Error("idMapPatch::Parse: bad vertex row data");
					return null;
				}

				for(int i = 0; i < patch.Height; i++)
				{
					float[] v = lexer.Parse1DMatrix(5);

					if(v == null)
					{
						lexer.Error("idMapPatch::Parse: bad vertex column data");
						return null;
					}

					Vertex vert = new Vertex();
					vert.Position.X = v[0] - origin.X;
					vert.Position.Y = v[1] - origin.Y;
					vert.Position.Z = v[2] - origin.Z;
					vert.TextureCoordinates = new Vector2(v[3], v[4]);

					patch.SetVertex(i * patch.Width + j, vert);
				}

				if(lexer.ExpectTokenString(")") == false)
				{
					lexer.Error("idMapPatch::Parse: unable to parse patch control points");
					return null;
				}
			}

			if(lexer.ExpectTokenString(")") == false)
			{
				lexer.Error("idMapPatch::Parse: unable to parse patch control points, no closure" );
				return null;
			}

			// read any key/value pairs
			while((token = lexer.ReadToken()) != null)
			{
				if(token.ToString() == "}")
				{
					lexer.ExpectTokenString("}");
					break;
				}

				if(token.Type == TokenType.String)
				{
					string key = token.ToString();
					token = lexer.ExpectTokenType(TokenType.String, 0);

					patch.Dict.Set(key, token.ToString());
				}
			}
			
			return patch;
		}
Exemplo n.º 2
0
		public void DrawStretchPicture(Vertex[] vertices, int[] indexes, idMaterial material, bool clip, float minX, float minY, float maxX, float maxY)
		{
			if((vertices == null) || (indexes == null) || (material == null))
			{
				return;
			}

			// break the current surface if we are changing to a new material
			if(material != _surface.Material)
			{
				if(_surface.VertexCount > 0)
				{
					AdvanceSurface();
				}

				_surface.Material = material;
				_surface.Material.EnsureNotPurged(); // in case it was a gui item started before a level change
			}

			clip = false;

			// add the verts and indexes to the current surface
			if(clip == true)
			{
				idConsole.WriteLine("idGuiModle.DrawStretchPicture clip");

				/*int i, j;

		// FIXME:	this is grim stuff, and should be rewritten if we have any significant
		//			number of guis asking for clipping
				 
		idFixedWinding w;
		for ( i = 0; i < indexCount; i += 3 ) {
			w.Clear();
			w.AddPoint(idVec5(dverts[dindexes[i]].xyz.x, dverts[dindexes[i]].xyz.y, dverts[dindexes[i]].xyz.z, dverts[dindexes[i]].st.x, dverts[dindexes[i]].st.y));
			w.AddPoint(idVec5(dverts[dindexes[i+1]].xyz.x, dverts[dindexes[i+1]].xyz.y, dverts[dindexes[i+1]].xyz.z, dverts[dindexes[i+1]].st.x, dverts[dindexes[i+1]].st.y));
			w.AddPoint(idVec5(dverts[dindexes[i+2]].xyz.x, dverts[dindexes[i+2]].xyz.y, dverts[dindexes[i+2]].xyz.z, dverts[dindexes[i+2]].st.x, dverts[dindexes[i+2]].st.y));

			for ( j = 0; j < 3; j++ ) {
				if ( w[j].x < min_x || w[j].x > max_x ||
					w[j].y < min_y || w[j].y > max_y ) {
					break;
				}
			}
			if ( j < 3 ) {
				idPlane p;
				p.Normal().y = p.Normal().z = 0.0f; p.Normal().x = 1.0f; p.SetDist( min_x );
				w.ClipInPlace( p );
				p.Normal().y = p.Normal().z = 0.0f; p.Normal().x = -1.0f; p.SetDist( -max_x );
				w.ClipInPlace( p );
				p.Normal().x = p.Normal().z = 0.0f; p.Normal().y = 1.0f; p.SetDist( min_y );
				w.ClipInPlace( p );
				p.Normal().x = p.Normal().z = 0.0f; p.Normal().y = -1.0f; p.SetDist( -max_y );
				w.ClipInPlace( p );
			}

			int	numVerts = verts.Num();
			verts.SetNum( numVerts + w.GetNumPoints(), false );
			for ( j = 0 ; j < w.GetNumPoints() ; j++ ) {
				idDrawVert *dv = &verts[numVerts+j];

				dv->xyz.x = w[j].x;
				dv->xyz.y = w[j].y;
				dv->xyz.z = w[j].z;
				dv->st.x = w[j].s;
				dv->st.y = w[j].t;
				dv->normal.Set(0, 0, 1);
				dv->tangents[0].Set(1, 0, 0);
				dv->tangents[1].Set(0, 1, 0);
			}
			surf->numVerts += w.GetNumPoints();

			for ( j = 2; j < w.GetNumPoints(); j++ ) {
				indexes.Append( numVerts - surf->firstVert );
				indexes.Append( numVerts + j - 1 - surf->firstVert );
				indexes.Append( numVerts + j - surf->firstVert );
				surf->numIndexes += 3;
			}
		}*/

			}
			else
			{
				int currentVertexCount = _vertices.Count;
				int currentIndexCount = _indexes.Count;
				int vertexCount = vertices.Length;
				int indexCount = indexes.Length;

				_surface.VertexCount += vertexCount;
				_surface.IndexCount += indexCount;

				for(int i = 0; i < indexCount; i++)
				{
					_indexes.Add(currentVertexCount + indexes[i] - _surface.FirstVertex);
				}

				_vertices.AddRange(vertices);
			}
		}
Exemplo n.º 3
0
		public void SetVertex(int index, Vertex vertex)
		{
			_surface.SetVertex(index, vertex);
		}
Exemplo n.º 4
0
		public idPatchSurface(int maxWidth, int maxHeight) : base()
		{
			_width = maxWidth;
			_height = maxHeight;
			_maxWidth = maxWidth;
			_maxHeight = maxHeight;
			_vertices = new Vertex[maxWidth * maxHeight];
		}
Exemplo n.º 5
0
		public void DrawStretchPicture(float x, float y, float width, float height, float s, float t, float s2, float t2, idMaterial material)
		{
			Vertex[] vertices = new Vertex[4];
			int[] indexes = new int[6];

			if(material == null)
			{
				return;
			}

			// clip to edges, because the pic may be going into a guiShader
			// instead of full screen
			if(x < 0)
			{
				s += (s2 - s) * -x / width;
				width += x;
				x = 0;
			}

			if(y < 0)
			{
				t += (t2 - t) * -y / height;
				height += y;
				y = 0;
			}
			if((x + width) > 640)
			{
				s2 -= (s2 - s) * (x + width - 640) / width;
				width = 640 - x;
			}

			if((y + height) > 480)
			{
				t2 -= (t2 - t) * (y + height - 480) / height;
				height = 480 - y;
			}

			if((width <= 0) || (height <= 0))
			{
				// completely clipped away
				return;		
			}

			indexes[0] = 3;
			indexes[1] = 0;
			indexes[2] = 2;
			indexes[3] = 2;
			indexes[4] = 0;
			indexes[5] = 1;

			vertices[0].Position = new Vector3(x, y, 0);
			vertices[0].TextureCoordinates = new Vector2(s, t);
			vertices[0].Normal = new Vector3(0, 0, 1);

			// TODO: tangents
			/*vertices[0].tangents[0][0] = 1;
			vertices[0].tangents[0][1] = 0;
			vertices[0].tangents[0][2] = 0;
			vertices[0].tangents[1][0] = 0;
			vertices[0].tangents[1][1] = 1;
			vertices[0].tangents[1][2] = 0;*/


			vertices[1].Position = new Vector3(x + width, y, 0);
			vertices[1].TextureCoordinates = new Vector2(s2, t);
			vertices[1].Normal = new Vector3(0, 0, 1);
			/*vertices[1].tangents[0][0] = 1;
			vertices[1].tangents[0][1] = 0;
			vertices[1].tangents[0][2] = 0;
			vertices[1].tangents[1][0] = 0;
			vertices[1].tangents[1][1] = 1;
			vertices[1].tangents[1][2] = 0;*/

			vertices[2].Position = new Vector3(x + width, y + height, 0);
			vertices[2].TextureCoordinates = new Vector2(s2, t2);
			vertices[2].Normal = new Vector3(0, 0, 1);
			/*vertices[2].tangents[0][0] = 1;
			vertices[2].tangents[0][1] = 0;
			vertices[2].tangents[0][2] = 0;
			vertices[2].tangents[1][0] = 0;
			vertices[2].tangents[1][1] = 1;
			vertices[2].tangents[1][2] = 0;*/

			vertices[3].Position = new Vector3(x, y + height, 0);
			vertices[3].TextureCoordinates = new Vector2(s, t2);
			vertices[3].Normal = new Vector3(0, 0, 1);
			/*vertices[3].tangents[0][0] = 1;
			vertices[3].tangents[0][1] = 0;
			vertices[3].tangents[0][2] = 0;
			vertices[3].tangents[1][0] = 0;
			vertices[3].tangents[1][1] = 1;
			vertices[3].tangents[1][2] = 0;*/

			DrawStretchPicture(vertices, indexes, material, false, 0, 0, 640.0f, 480.0f);
		}
Exemplo n.º 6
0
		private void TransformVertices(Vertex[] verts, idJointMatrix[] entityJoints)
		{
			int j, i;
			int vertCount = verts.Length;

			for(j = i = 0; i < vertCount; i++)
			{
				Vector3 w = new Vector3(_scaledWeights[j].X, _scaledWeights[j].Y, _scaledWeights[j].Z);
				Vector3 v = entityJoints[_weightIndex[j * 2 + 0]].ToVector3() * w;

				while(_weightIndex[j * 2 + 1] == 0)
				{
					j++;
					v += entityJoints[_weightIndex[j * 2 + 0]].ToVector3() * w;
				}

				j++;
				verts[i].Position = v;
			}
		}
Exemplo n.º 7
0
		public void DrawStretchPicture(float x, float y, float width, float height, float s, float t, float s2, float t2, idMaterial material)
		{
			Vertex[] verts = new Vertex[4];
			int[] indexes = new int[6];

			/*indexes[0] = 0;
			indexes[1] = 1;
			indexes[2] = 2;
			indexes[3] = 0;
			indexes[4] = 2;
			indexes[5] = 3;*/
			
			indexes[0] = 3;
			indexes[1] = 0;
			indexes[2] = 2;
			indexes[3] = 2;
			indexes[4] = 0;
			indexes[5] = 1;

			verts[0].Position = new Vector3(x, y, 0);
			verts[0].TextureCoordinates = new Vector2(s, t);
			verts[0].Normal = new Vector3(0, 0, 1);
			/*verts[0].Tangents = new Vector3[] {
				new Vector3(1, 0, 0),
				new Vector3(0, 1, 0)
			};*/

			verts[1].Position = new Vector3(x + width, y, 0);
			verts[1].TextureCoordinates = new Vector2(s2, t);
			verts[1].Normal = new Vector3(0, 0, 1);
			/*verts[1].Tangents = new Vector3[] {
				new Vector3(1, 0, 0),
				new Vector3(0, 1, 0)
			};*/

			verts[2].Position = new Vector3(x + width, y + height, 0);
			verts[2].TextureCoordinates = new Vector2(s2, t2);
			verts[2].Normal = new Vector3(0, 0, 1);
			/*verts[2].Tangents = new Vector3[] {
				new Vector3(1, 0, 0),
				new Vector3(0, 1, 0)
			};*/

			verts[3].Position = new Vector3(x, y + height, 0);
			verts[3].TextureCoordinates = new Vector2(s, t2);
			verts[3].Normal = new Vector3(0, 0, 1);
			/*verts[3].Tangents = new Vector3[] {
				new Vector3(1, 0, 0),
				new Vector3(0, 1, 0)
			};*/

			bool ident = _matrix != Matrix.Identity;

			if(ident == true)
			{
				idConsole.Warning("TODO: IDENT == true");
				/*verts[0].Position -= _origin;
				verts[0].Position *= _matrix.Translation;
				verts[0].Position += _origin;
				verts[1].Position -= _origin;
				verts[1].Position *= _matrix.Translation;
				verts[1].Position += _origin;
				verts[2].Position -= _origin;
				verts[2].Position *= _matrix.Translation;
				verts[2].Position += _origin;
				verts[3].Position -= _origin;
				verts[3].Position *= _matrix.Translation;
				verts[3].Position += _origin;*/
			}

			idE.RenderSystem.DrawStretchPicture(verts.ToArray(), indexes.ToArray(), material, ident);
		}
Exemplo n.º 8
0
		public void Parse(idLexer lexer, idJointMatrix[] joints)
		{
			lexer.ExpectTokenString("{");

			//
			// parse name
			//
			if(lexer.CheckTokenString("name") == true)
			{
				lexer.ReadToken();
			}

			//
			// parse shader
			//
			lexer.ExpectTokenString("shader");

			idToken token = lexer.ReadToken();
			string materialName = token.ToString();

			_material = idE.DeclManager.FindMaterial(materialName);

			//
			// parse texture coordinates
			//
			lexer.ExpectTokenString("numverts");
			int count = lexer.ParseInt();

			if(count < 0)
			{
				lexer.Error("Invalid size: {0}", token.ToString());
			}

			_texCoords = new Vector2[count];

			int[] firstWeightForVertex = new int[count];
			int[] weightCountForVertex = new int[count];
			int maxWeight = 0;
			int coordCount = _texCoords.Length;

			_weightCount = 0;

			for(int i = 0; i < coordCount; i++)
			{
				lexer.ExpectTokenString("vert");
				lexer.ParseInt();

				float[] tmp = lexer.Parse1DMatrix(2);

				_texCoords[i] = new Vector2(tmp[0], tmp[1]);
				
				firstWeightForVertex[i] = lexer.ParseInt();
				weightCountForVertex[i] = lexer.ParseInt();

				if(weightCountForVertex[i] == 0)
				{
					lexer.Error("Vertex without any joint weights.");
				}

				_weightCount += weightCountForVertex[i];

				if((weightCountForVertex[i] + firstWeightForVertex[i]) > maxWeight)
				{
					maxWeight = weightCountForVertex[i] + firstWeightForVertex[i];
				}
			}

			//
			// parse tris
			//
			lexer.ExpectTokenString("numtris");
			_triangleCount = lexer.ParseInt();

			if(_triangleCount < 0)
			{
				lexer.Error("Invalid size: {0}", _triangleCount);
			}

			int[] tris = new int[_triangleCount * 3];

			for(int i = 0; i < _triangleCount; i++)
			{
				lexer.ExpectTokenString("tri");
				lexer.ParseInt();

				tris[i * 3 + 0] = lexer.ParseInt();
				tris[i * 3 + 1] = lexer.ParseInt();
				tris[i * 3 + 2] = lexer.ParseInt();
			}

			//
			// parse weights
			//
			lexer.ExpectTokenString("numweights");
			count = lexer.ParseInt();

			if(count < 0)
			{
				lexer.Error("Invalid size: {0}", count);
			}

			if(maxWeight > count)
			{
				lexer.Warning("Vertices reference out of range weights in model ({0} of {1} weights).", maxWeight, count);
			}

			VertexWeight[] tempWeights = new VertexWeight[count];

			for(int i = 0; i < count; i++)
			{
				lexer.ExpectTokenString("weight");
				lexer.ParseInt();

				int jointIndex = lexer.ParseInt();

				if((jointIndex < 0) || (jointIndex >= joints.Length))
				{
					lexer.Error("Joint index out of range({0}): {1}", joints.Length, jointIndex);
				}

				tempWeights[i].JointIndex = jointIndex;
				tempWeights[i].JointWeight = lexer.ParseFloat();

				float[] tmp = lexer.Parse1DMatrix(3);

				tempWeights[i].Offset = new Vector3(tmp[0], tmp[1], tmp[2]);
			}

			// create pre-scaled weights and an index for the vertex/joint lookup
			_scaledWeights = new Vector4[_weightCount];
			_weightIndex = new int[_weightCount * 2];

			count = 0;
			coordCount = _texCoords.Length;

			for(int i = 0; i < coordCount; i++)
			{
				int num = firstWeightForVertex[i];
				int weightCount = weightCountForVertex[i];

				for(int j = 0; j < weightCount; j++, num++, count++)
				{
					Vector3 tmp = tempWeights[num].Offset * tempWeights[num].JointWeight;

					_scaledWeights[count].X = tmp.X;
					_scaledWeights[count].Y = tmp.Y;
					_scaledWeights[count].Z = tmp.Z;
					_scaledWeights[count].W = tempWeights[num].JointWeight;

					_weightIndex[count * 2 + 0] = tempWeights[num].JointIndex;
				}

				_weightIndex[count * 2 - 1] = 1;
			}

			lexer.ExpectTokenString("}");

			// update counters
			idConsole.Warning("TODO: idRenderModel_MD5 update counters");

			/*c_numVerts += texCoords.Num();
			c_numWeights += numWeights;
			c_numWeightJoints++;
			for ( i = 0; i < numWeights; i++ ) {
				c_numWeightJoints += weightIndex[i*2+1];
			}*/

			//
			// build the information that will be common to all animations of this mesh:
			// silhouette edge connectivity and normal / tangent generation information
			//
			Vertex[] verts = new Vertex[_texCoords.Length];
			int vertCount = verts.Length;

			for(int i = 0; i < vertCount; i++)
			{
				verts[i].TextureCoordinates = _texCoords[i];
			}

			TransformVertices(verts, joints);

			idConsole.Warning("TODO: idMD5Mesh Deform");
			//_deformInfo = idE.RenderSystem.BuildDeformInformation(verts, tris, _material.UseUnsmoothedTangents);
		}
Exemplo n.º 9
0
		public idBounds CalculateBounds(idJointMatrix[] joints)
		{
			Vertex[] verts = new Vertex[_texCoords.Length];
			idBounds bounds = idBounds.Zero;

			TransformVertices(verts, joints);

			idHelper.MinMax(ref bounds.Min, ref bounds.Max, verts, _texCoords.Length);

			return bounds;
		}
Exemplo n.º 10
0
		public void SetVertex(int index, Vertex vert)
		{
			_vertices[index] = vert;
		}
Exemplo n.º 11
0
		public void DrawStretchPicture(Vertex[] vertices, int[] indexes, idMaterial material, bool clip = true, float minX = 0.0f, float minY = 0.0f, float maxX = 640.0f, float maxY = 0.0f)
		{
			_guiModel.DrawStretchPicture(vertices, indexes, material, clip, minX, minY, maxX, maxY);
		}
Exemplo n.º 12
0
		internal VertexCache AllocateVertexCacheFrameTemporary(Vertex[] vertices)
		{
			VertexCache cache = new VertexCache();

			if(vertices.Length == 0)
			{
				idConsole.Error("AllocateVertexCacheFromTemorary: size = 0");
			}

			// TODO: vertex cache alloc > frameBytes
			/*if(dynamicAllocThisFrame + size > frameBytes)
			{
				// if we don't have enough room in the temp block, allocate a static block,
				// but immediately free it so it will get freed at the next frame
				tempOverflow = true;
				Alloc(data, size, &block);
				Free(block);
				return block;
			}*/

			// this data is just going on the shared dynamic list

			// TODO: i think we could have one massive vertex buffer for temporary frame data.  
			// save having all these creations and destructions of buffers

			// move it from the freeDynamicHeaders list to the dynamicHeaders list
			_dynamicVertexCache.Add(cache);

			// TODO: dynamicAllocThisFrame += block->size;
			// TODO: dynamicCountThisFrame++;

			cache.Tag = VertexCacheType.Temporary;
			cache.Data = vertices;

			return cache;
		}