public Mesh FixNormals(Mesh mesh) { Vector3[] normals = mesh.normals; int width = MeshGenerator.GetVerticesPerDimension(mapData.GetWidth(), GetActualLOD()); int height = MeshGenerator.GetVerticesPerDimension(mapData.GetHeight(), GetActualLOD()); foreach (DisplayNeighborRelation relation in mapData.GetDisplayNeighbors()) { MapDisplay other = relation.GetOtherDisplay(mapData); if (other == null || other.GetStatus() == MapDisplayStatus.HIDDEN) { continue; } Mesh otherMesh = relation.GetOtherMesh(mapData); DisplayReadySlice otherSlice = relation.GetOtherDRSlice(mapData); Vector3[] otherNormals = otherMesh.normals; int otherWidth = MeshGenerator.GetVerticesPerDimension(otherSlice.GetWidth(), other.GetActualLOD()); int otherHeight = MeshGenerator.GetVerticesPerDimension(otherSlice.GetHeight(), other.GetActualLOD()); if (relation.IsFirstMember(mapData)) { FixNormals(normals, width, height, otherNormals, otherWidth, otherHeight, relation.neighborType); } else { FixNormals(otherNormals, otherWidth, otherHeight, normals, width, height, relation.neighborType); } otherMesh.normals = otherNormals; } mesh.normals = normals; return(mesh); }
public static MeshData GenerateTerrainMesh(DisplayReadySlice mapData, float heightMultiplier = 0f, int levelOfDetail = 0, float minHeight = 0f) { int width = mapData.GetWidth(); int height = mapData.GetHeight(); //Debug.Log("w: " + width + " h:" + height); Vector2 topLeft = mapData.GetTopLeft(); float topLeftX = topLeft.x; float topLeftZ = topLeft.y; int actualLOD = mapData.GetActualLOD(); int verticesPerLine = GetVerticesPerDimension(width, actualLOD); int verticesPerColumn = GetVerticesPerDimension(height, actualLOD); MeshData meshData = new MeshData(verticesPerLine, verticesPerColumn); int vertexIndex = 0; for (int y = 0; y < height; y += mapData.SimplificationIncrementForY(y)) { for (int x = 0; x < width; x += mapData.SimplificationIncrementForX(x)) { meshData.vertices [vertexIndex] = new Vector3(topLeftX + x, mapData.GetNormalized(x, y), topLeftZ - y); meshData.uvs [vertexIndex] = new Vector2(x / (float)width, y / (float)height); if (x < width - 1 && y < height - 1) { meshData.AddTriangle(vertexIndex, vertexIndex + verticesPerLine + 1, vertexIndex + verticesPerLine); meshData.AddTriangle(vertexIndex + verticesPerLine + 1, vertexIndex, vertexIndex + 1); } vertexIndex++; } } return(meshData); }
public void SetMapData(DisplayReadySlice mapData) { this.mapData = mapData; int originalLod = mapData.lod; mapData.lod = lowLod; lowLodMesh = GenerateMesh(); mapData.lod = originalLod; }
public virtual DisplayReadySlice AsDisplayReadySlice(int lod) { DisplayReadySlice ret = new DisplayReadySlice(this, lod); foreach (MapNeighborRelation neighbor in neighbors) { ret.AddDisplayNeighbor(neighbor.AsDisplayNeighborRelation()); } return(ret); }
public void SetMapData(DisplayReadySlice mapData) { if (this.displayData == null) { this.displayData = new MapDisplayData(mapData); } else { this.displayData.SetMapData(mapData); } }
public DisplayReadySlice GetOtherDRSlice(DisplayReadySlice member) { if (member.baseSlice == firstMember) { return(secondDRSlice); } else if (member.baseSlice == secondMember) { return(firstDRSlice); } else { throw new System.ArgumentException("Tried to GetOtherDRSlice for non-existing member!"); } }
public void AddDisplay(DisplayReadySlice member, MapDisplay display) { if (member.baseSlice == firstMember) { firstDisplay = display; } else if (member.baseSlice == secondMember) { secondDisplay = display; } else { throw new System.ArgumentException("Tried to add display to a non-existing member!"); } }
public void AddDisplayReadySlice(DisplayReadySlice member) { if (member.baseSlice == firstMember) { firstDRSlice = member; } else if (member.baseSlice == secondMember) { secondDRSlice = member; } else { throw new System.ArgumentException("Tried to add display ready slice w/ non-existing baseSlice!"); } }
public void Setup() { data = MapData.ForTesting(new float[10, 10] { { 0.0F, 0.1F, 0.2F, 0.3F, 0.4F, 0F, 0F, 0F, 0F, 0F }, { 1.0F, 1.1F, 1.2F, 1.3F, 1.4F, 0F, 0F, 0F, 0F, 0F }, { 2.0F, 2.1F, 2.2F, 2.3F, 2.4F, 0F, 0F, 0F, 0F, 0F }, { 3.0F, 3.1F, 3.2F, 3.3F, 3.4F, 0F, 0F, 0F, 0F, 0F }, { 4.0F, 4.1F, 4.2F, 4.3F, 4.4F, 0F, 0F, 0F, 0F, 0F }, { 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F }, { 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F }, { 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F }, { 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F }, { 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F, 0F }, }).GetSlices(5)[0].AsSlice().AsDisplayReadySlice(5); }
public int GetOtherWidth(DisplayReadySlice member) { return(base.GetOtherWidth(member.baseSlice)); }
public Mesh GetOtherMesh(DisplayReadySlice member) { return(GetMesh(GetOtherDisplay(member))); }
public bool IsFirstMember(DisplayReadySlice member) { return(base.IsFirstMember(member.baseSlice)); }
public int GetOtherHeight(DisplayReadySlice member) { return(base.GetOtherHeight(member.baseSlice)); }
public MapDisplayData(DisplayReadySlice mapData) { this.SetMapData(mapData); }