private void ReadEdge(ref SourceEdge sourceEdge) { sourceEdge.vertex0 = this.Stream.ReadUInt16(); sourceEdge.vertex1 = this.Stream.ReadUInt16(); }
private void BuildFace(ref SourceFace face, BspSubmeshStreams subMesh) { Vertex[] faceVertices = new Vertex[face.numedges]; var plane = this.planes[face.planenum]; var texture_id = this.texInfo[face.texinfo].texdata; Float2 minUV0 = new Float2(float.MaxValue, float.MaxValue); Float2 minUV1 = new Float2(float.MaxValue, float.MaxValue); Float2 maxUV1 = new Float2(float.MinValue, float.MinValue); int nextShouldBe = -1; for (int index = 0; index < faceVertices.Length; index++) { var listOfEdgesIndex = face.firstedge + index; if (listOfEdgesIndex >= this.listOfEdges.Length) { throw new BspFormatException( string.Format("Edge list index {0} is out of range [0..{1}]", listOfEdgesIndex, this.listOfEdges.Length - 1)); } var edgeIndex = this.listOfEdges[listOfEdgesIndex]; if (edgeIndex >= this.edges.Length) { throw new BspFormatException( string.Format("Edge index {0} is out of range [0..{1}]", edgeIndex, this.edges.Length - 1)); } SourceEdge edge; if (edgeIndex >= 0) { edge = this.edges[edgeIndex]; } else { var flippedEdge = this.edges[-edgeIndex]; edge = new SourceEdge { vertex0 = flippedEdge.vertex1, vertex1 = flippedEdge.vertex0 }; } var edgesvertex0 = edge.vertex0; if (edgesvertex0 >= this.vertices.Length) { throw new BspFormatException( string.Format("Vertex index {0} is out of range [0..{1}]", edgesvertex0, this.vertices.Length - 1)); } var edgesvertex1 = edge.vertex1; if (edgesvertex1 >= this.vertices.Length) { throw new BspFormatException( string.Format("Vertex index {0} is out of range [0..{1}]", edgesvertex1, this.vertices.Length - 1)); } if (nextShouldBe >= 0 && nextShouldBe != edgesvertex0) { throw new BspFormatException(string.Format("Wrong edge order")); } nextShouldBe = edgesvertex1; Vertex vertex; this.BuildVertex( this.vertices[(short)edgesvertex0], plane.normal, //(face.side == 0) ? plane.normal : -plane.normal, face, ref this.texInfo[face.texinfo], out vertex); faceVertices[index] = vertex; if (minUV0.X > vertex.UV0.X) { minUV0.X = vertex.UV0.X; } if (minUV0.Y > vertex.UV0.Y) { minUV0.Y = vertex.UV0.Y; } if (minUV1.X > vertex.UV1.X) { minUV1.X = vertex.UV1.X; } if (minUV1.Y > vertex.UV1.Y) { minUV1.Y = vertex.UV1.Y; } if (maxUV1.X < vertex.UV1.X) { maxUV1.X = vertex.UV1.X; } if (maxUV1.Y < vertex.UV1.Y) { maxUV1.Y = vertex.UV1.Y; } } if (this.textures[texture_id].name == "TOOLS/TOOLSSKYBOX") { minUV0.X = 0; minUV0.Y = 0; for (int j = 0; j < (int)face.numedges; ++j) { faceVertices[j].UV0 = new Float3(0, 0, 0); } } int[] indices = new int[faceVertices.Length]; for (int j = 0; j < faceVertices.Length; ++j) { meshStreams.Positions.Add(faceVertices[j].Position); meshStreams.Normals.Add(faceVertices[j].Normal); meshStreams.Colors.Add(faceVertices[j].Color); meshStreams.TexCoord0.Add(new Float2(faceVertices[j].UV0.X, faceVertices[j].UV0.Y)); meshStreams.TexCoord1.Add(new Float2(faceVertices[j].UV1.X, faceVertices[j].UV1.Y)); } for (int j = 1; j < faceVertices.Length - 1; ++j) { subMesh.AddToAllStreams(indices[0]); subMesh.AddToAllStreams(indices[j]); subMesh.AddToAllStreams(indices[j + 1]); } }