public static GenerateTerrainMesh ( float heightMap ) : MeshData, | ||
heightMap | float | |
return | MeshData, |
public void DrawMapInEditor() { craterTypeNr = RandomizerType(); MapData mapData = GenerateMapData(Vector2.zero); MapDisplay display = FindObjectOfType <MapDisplay>(); //reference to mapdisplay, gives different options if (drawMode == DrawMode.NoiseMap) { display.DrawTexture(TextureGenerator.TextureFromHeightMap(NoiseGenerator.GenerateNoiseMap(mapChunkSize + 2, mapChunkSize + 2, seed, noiseScale, octaves, persistance, lacunarity, Vector2.zero + offset, normalizeMode))); } if (drawMode == DrawMode.MixedHeightMap) { display.DrawTexture(TextureGenerator.TextureFromHeightMap(mapData.heightMap)); } else if (drawMode == DrawMode.ColourMap) { display.DrawTexture(TextureGenerator.ColourMapTexture(mapData.colourMap, mapChunkSize, mapChunkSize)); } else if (drawMode == DrawMode.Mesh) { display.DrawMesh(MeshGenerator.GenerateTerrainMesh(mapData.heightMap, meshHeightMultiplier, meshHeightCurve, LOD), TextureGenerator.ColourMapTexture(mapData.colourMap, mapChunkSize, mapChunkSize)); } else if (drawMode == DrawMode.Crater) { display.DrawTexture( TextureGenerator.TextureFromHeightMap(CraterGenerator.GenerateCrater(mapChunkSize, craterSize, craterIntensity, position.x, position.y, ellipse.x, ellipse.y))); } else if (drawMode == DrawMode.CraterRing) { display.DrawTexture(TextureGenerator.TextureFromHeightMap(CraterRingGenerator.GenerateCraterRing(mapChunkSize, craterSize + craters[craterTypeNr].ringWidth, craterIntensity + craterSize + craters[craterTypeNr].ringWeight, position.x, position.y, ellipse.x, ellipse.y))); } else if (drawMode == DrawMode.CraterFalloff) { display.DrawTexture(TextureGenerator.TextureFromHeightMap(CraterFalloffGenerator.GenerateCraterFalloff(mapChunkSize, craterSize + craters[craterTypeNr].ringWidth + craters[craterTypeNr].falloffstart, craterIntensity + craterSize + craters[craterTypeNr].falloffWeight, position.x, position.y, ellipse.x, ellipse.y))); } else if (drawMode == DrawMode.CraterStripes) { display.DrawTexture(TextureGenerator.TextureFromHeightMap(CraterStripesGenerator.GenerateCraterStripes(mapChunkSize, craters[craterTypeNr].stripeSin, craters[craterTypeNr].stripeQuantity))); } else if (drawMode == DrawMode.CraterSinW) { display.DrawTexture( TextureGenerator.TextureFromHeightMap(CraterSinW.GenerateCraterSinW(mapChunkSize, craters[craterTypeNr].sinWCentress, position.x, position.y, ellipse.x, ellipse.y, craters[craterTypeNr].sinWQuantity))); } else if (drawMode == DrawMode.CraterQuadFalloff) { display.DrawTexture(TextureGenerator.TextureFromHeightMap(CraterQuadFalloffGenerator.GenerateCraterQuadFalloff(mapChunkSize, position.x, position.y, craters[craterTypeNr].lineStart, 0))); } //else if (drawMode == DrawMode.CraterSidedParable) //{ // display.DrawTexture(TextureGenerator.TextureFromHeightMap(CraterSidedParable.GenerateCraterSidedParable(mapChunkSize, craters[craterTypeNr].diagScale, craters[craterTypeNr].diagParable, craters[craterTypeNr].diagDirection))); //} else if (drawMode == DrawMode.CraterCentralPeak) { display.DrawTexture( TextureGenerator.TextureFromHeightMap(CraterCentralPeak.GenerateCreaterCentralPeak(mapChunkSize, craters[craterTypeNr].centralSize, craters[craterTypeNr].centralPeakness, position.x + craters[craterTypeNr].centralPosition.x, position.y + craters[craterTypeNr].centralPosition.y, ellipse.x, ellipse.y))); } else if (drawMode == DrawMode.CraterTerrace) { display.DrawTexture( TextureGenerator.TextureFromHeightMap(CraterTerrace.GenerateCraterTerrace(mapChunkSize, craters[craterTypeNr].terraceSize, craters[craterTypeNr].terracePeakness, position.x + craters[craterTypeNr].terracePosition.x, position.y + craters[craterTypeNr].terracePosition.y, ellipse.x, ellipse.y))); } else if (drawMode == DrawMode.CraterPseudoRnd) { display.DrawTexture(TextureGenerator.TextureFromHeightMap(CraterPseudoRndGenerator.GenerateCraterPseudoRnd(mapChunkSize, pseudoDensity, pseudoPeaks, pseudoVal))); } }
// takes as parameters map data, an LOD, and an action void MeshDataThread(MapData mapData, int lod, Action <MeshData> callback) { MeshData meshData = MeshGenerator.GenerateTerrainMesh(mapData.heightMap, meshHeightMultiplier, lod); lock (meshDataQueue) { meshDataQueue.Enqueue(new ThreadInfo <MeshData> (callback, meshData)); } }
public void RequestMesh(HeightMap heightMap, MeshSettings meshSettings) { hasRequestedMesh = true; ThreadedDataRequester.RequestData(() => MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, lod), OnMeshDataReceived); }
public void DrawMapInEditor() { textureData.ApplyToMaterial(terrainMaterial); textureData.UpdateMeshHeights(terrainMaterial, heightMapSettings.minHeight, heightMapSettings.maxHeight); if (drawMode == DrawMode.NoiseMap) { var heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings.numberOfVerticesPerLine, heightMapSettings, erosion, Vector3.zero); DrawTexture(TextureGenerator.TextureFromHeightMap(heightMap)); } else if (drawMode == DrawMode.Mesh) { var heightMap = HeightMapGenerator.GenerateHeightMap(meshSettings.numberOfVerticesPerLine, heightMapSettings, erosion, Vector3.zero); DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap.values, meshSettings, editorPreviewLevelOfDetail)); } else if (drawMode == DrawMode.FalloffMap) { DrawTexture(TextureGenerator.TextureFromHeightMap(new HeightMap(FalloffGenerator.GenerateFalloffMap(meshSettings.numberOfVerticesPerLine), 0, 1))); } else if (drawMode == DrawMode.NewMapGen) { var map = TestGenerator.GenerateVoronoiMap(meshSettings.numberOfVerticesPerLine, meshSettings.numberOfVerticesPerLine, numberOfBiomes, heightMapSettings.noiseSettings.seed, edgeCuttoffPercent, useGrid); var color = new Color[meshSettings.numberOfVerticesPerLine * meshSettings.numberOfVerticesPerLine]; for (var i = 0; i < meshSettings.numberOfVerticesPerLine * meshSettings.numberOfVerticesPerLine; i++) { color[i] = map[i % meshSettings.numberOfVerticesPerLine, i / meshSettings.numberOfVerticesPerLine].biome.color; } DrawTexture(TextureGenerator.TextureFromColorMap(color, meshSettings.numberOfVerticesPerLine, meshSettings.numberOfVerticesPerLine)); } else if (drawMode == DrawMode.DomainWarping) { DrawTexture( TextureGenerator.TextureFromColorMap( TestGenerator.DomainWarpMap( meshSettings.numberOfVerticesPerLine, meshSettings.numberOfVerticesPerLine, heightMapSettings.noiseSettings.seed ), meshSettings.numberOfVerticesPerLine, meshSettings.numberOfVerticesPerLine) ); } else if (drawMode == DrawMode.DomainWarpedNewMap) { var map = TestGenerator.GenerateVoronoiMap(meshSettings.numberOfVerticesPerLine, meshSettings.numberOfVerticesPerLine, numberOfBiomes, heightMapSettings.noiseSettings.seed, edgeCuttoffPercent, useGrid); var warpedMap = TestGenerator.DomainWarpMap(map, meshSettings.numberOfVerticesPerLine, meshSettings.numberOfVerticesPerLine, heightMapSettings.noiseSettings.seed, map[0, 0], warpingAmplitude * meshSettings.numberOfVerticesPerLine / 240f, adjustmentFactor, meshSettings.numberOfVerticesPerLine * 0.1f); var warpedSize = Mathf.RoundToInt(meshSettings.numberOfVerticesPerLine * adjustmentFactor); var color = new Color[warpedSize * warpedSize]; for (var i = 0; i < color.Length; i++) { var x = i % warpedSize; var y = i / warpedSize; color[i] = warpedMap[x, y].biome.color; } DrawTexture(TextureGenerator.TextureFromColorMap(color, warpedSize, warpedSize)); } else if (drawMode == DrawMode.DomainWarpedAndMeshedNewMap) { var map = TestGenerator.GenerateVoronoiMap(meshSettings.numberOfVerticesPerLine, meshSettings.numberOfVerticesPerLine, numberOfBiomes, heightMapSettings.noiseSettings.seed, edgeCuttoffPercent, useGrid); var warpedMap = TestGenerator.DomainWarpMap(map, meshSettings.numberOfVerticesPerLine, meshSettings.numberOfVerticesPerLine, heightMapSettings.noiseSettings.seed, map[0, 0], warpingAmplitude * meshSettings.numberOfVerticesPerLine / 240f, adjustmentFactor, meshSettings.numberOfVerticesPerLine * 0.1f); var warpedSize = Mathf.RoundToInt(meshSettings.numberOfVerticesPerLine * adjustmentFactor); var heightMap = TestGenerator.TestFillHeightMap(warpedMap, warpedSize, warpedSize, heightMapSettings.noiseSettings.seed, noiseScale, heightScale); var color = new Color[warpedSize * warpedSize]; for (var i = 0; i < color.Length; i++) { var x = i % warpedSize; var y = i / warpedSize; color[i] = warpedMap[x, y].biome.color; } DebugWriteFile("warpedHeightMap", heightMap, warpedSize); meshSettings.numberOfVerticesPerLine = warpedSize; DrawMesh(MeshGenerator.GenerateTerrainMesh(heightMap, meshSettings, editorPreviewLevelOfDetail), TextureGenerator.TextureFromColorMap(color, warpedSize, warpedSize)); } }