public SubsectorMeshComponents(SubsectorPlane plane, SectorPlane sectorPlane, List <Seg2F> edges, GameObject gameObject) { subsectorPlane = plane; texture = TextureManager.Texture(plane.SectorPlane.TextureName, ResourceNamespace.Flats); Mesh = CreateMesh(sectorPlane, edges, texture); Filter = CreateFilter(gameObject); Renderer = CreateRenderer(gameObject); Collider = CreateCollider(gameObject, edges); }
public Wall(int index, Side side, WallSection section) { Index = index; Side = side; Section = section; TextureName = GetTextureNameFrom(side, section); Texture = TextureManager.Texture(TextureName); meshComponents = new WallMeshComponents(this, Texture); (SectorPlane floor, SectorPlane ceiling) = FindBoundingPlane(); FloorHeight = floor.Height; CeilingHeight = ceiling.Height; AttachToSectorPlanes(); side.Walls.Add(this); }
private static Mesh CreateMesh(SectorPlane sectorPlane, List <Seg2F> edges, Texture texture) { (Vector3[] vertices, Vector2[] uvCoords) = CalculateVertices(sectorPlane, edges, texture); int[] indices = CalculateIndices(vertices.Length); Vector3[] normals = CalculateNormals(sectorPlane, vertices.Length); Color[] colors = CalculateColors(sectorPlane, vertices.Length); return(new Mesh { vertices = vertices, triangles = indices, normals = normals, uv = uvCoords, colors = colors }); }
private static (Vector3[] vertices, Vector2[] uvCoords) CalculateVertices(SectorPlane plane, List <Seg2F> edges, Texture texture) { int vertexCount = edges.Count; Vector3[] vertices = new Vector3[vertexCount]; Vector2[] uvCoords = new Vector2[vertexCount]; for (int i = 0; i < vertexCount; i++) { Vector2 vertex = edges[i].Start.UnityFloat(); vertices[i] = new Vector3(vertex.x, plane.Height, vertex.y).MapUnit(); uvCoords[i] = vertex * texture.InverseDimension; } // If it's a ceiling, we have to reverse the triangle fan to make // the facing side visible. if (plane.IsCeiling) { Array.Reverse(vertices, 0, vertices.Length); Array.Reverse(uvCoords, 0, uvCoords.Length); } return(vertices, uvCoords); }