void Start() { _noiseMapGeneration = new NoiseMapGenerator(); GenerateHeightMap(); GenerateTiles(); }
private void Start() { DataHolder.Instance.Init(); //DataHolder.Instance.printInfo(); noiseGenerator = gameObject.GetComponent <NoiseMapGenerator>(); pathFinder = gameObject.GetComponent <PathFinder>(); generate(); }
public void Initialise(Map map, int seed) { this.map = map; width = map.levelWidth; height = map.levelHeight; noiseMap = NoiseMapGenerator.Create(map, seed); wallMap = new int[width, height]; CreateWallMap(); ProcessMap(); MSMeshGenerator MSGen = GetComponent <MSMeshGenerator> (); Material[] mats = new Material[map.possibleTerrain.Length]; for (int i = 0; i < map.possibleTerrain.Length; i++) { mats [i] = map.possibleTerrain [i].terrainMaterial; } List <MeshFilter> walkables = MSGen.Generate(wallMap, map.tileSize, map.wallHeight, mats, map.wallMaterial); ObjectGenerator objGen = GetComponent <ObjectGenerator> (); List <GameObject> objects = objGen.GenerateObjects(map, noiseMap); NavMeshGenerator meshGen = GetComponent <NavMeshGenerator> (); meshGen.Initialise(); meshGen.BuildNavMesh(walkables, objects, wallMap.GetLength(0) * map.tileSize, wallMap.GetLength(1) * map.tileSize); StaticBatchingUtility.Combine(objects.ToArray(), objects [0].transform.parent.gameObject); Light worldLight = (Light)Instantiate(new GameObject(), Vector3.zero, Quaternion.Euler(map.lightOptions.angle), this.transform).AddComponent(typeof(Light)); worldLight.name = "World Light"; worldLight.type = LightType.Directional; worldLight.intensity = map.lightOptions.intensity; worldLight.color = map.lightOptions.lightColour; worldLight.shadows = LightShadows.Soft; worldLight.shadowStrength = 0.8f; if (map.postProcProfile != null) { Camera.main.GetComponent <PostProcessingBehaviour> ().profile = map.postProcProfile; } else { Debug.LogWarning("Map is missing a Post Processing Profile"); } }
void Start() { mapGenerator = FindObjectOfType <NoiseMapGenerator>(); maxViewDst = detailLevels [detailLevels.Length - 1].visibleDstThreshold; chunkSize = NoiseMapGenerator.mapChunkSize - 1; chunksVisibleInViewDst = Mathf.RoundToInt(maxViewDst / chunkSize); UpdateVisibleChunks(); }
void Start() { _noiseMapGeneration = new NoiseMapGenerator(); // get the tile dimensions from the tile Prefab Vector3 tileSize = TilePrefab.GetComponent <MeshRenderer>().bounds.size; _tileWidth = tileSize.x; _tileHeight = tileSize.z; GenerateHeightMap(); GenerateTiles(); }
// Generate terrain height map using Perlin noise private void generateHeightsMap() { float waveFreq1 = (30 + GameSettings.seed % 60) / 100; NoiseMapGenerator noiseMapGeneration = new NoiseMapGenerator(); Wave[] waves = new Wave[] { new Wave(GameSettings.seed, waveFreq1, 1f), }; var heights = noiseMapGeneration.GenerateNoiseMap( GameSettings.terrainAlphamapRes, GameSettings.terrainAlphamapRes, 20f, waves); terrainData.SetHeights(0, 0, heights); }
public override void OnInspectorGUI() { NoiseMapGenerator mapGen = (NoiseMapGenerator)target; if (DrawDefaultInspector()) { if (mapGen.autoUpdate) { mapGen.DrawMapInEditor(); } } if (GUILayout.Button("Generate Map")) { mapGen.DrawMapInEditor(); } }
public void GenerateTerrain() { meshHeightMultiplier = terrainGeneratorUI.heightMultiplierSlider.value; noiseMapGenerator = new NoiseMapGenerator(); displayMap = FindObjectOfType <DisplayMap>(); textureGenerator = new TextureGenerator(); meshGenerator = new MeshGenerator(); noiseMap = noiseMapGenerator.GenerateNoiseMap(mapWidth, mapHeight, noiseScale, octaves, persistance, lacunarity, seed, offset, animate, dropdownValue); Color[] colorMap = new Color[mapWidth * mapHeight]; for (int y = 0; y < mapHeight; y++) { for (int x = 0; x < mapWidth; x++) { float currHeight = noiseMap[x, y]; for (int i = 0; i < regions.Length; i++) { if (currHeight <= regions[i].height) { colorMap[y * mapWidth + x] = regions[i].color; break; } } } } if (drawMode == DrawMode.NoiseMap) { displayMap.DrawTexture(textureGenerator.TextureFromNoiseMap(noiseMap)); } else if (drawMode == DrawMode.ColorMap) { displayMap.DrawTexture(textureGenerator.TextureFromColorMap(colorMap, mapWidth, mapHeight)); } else if (drawMode == DrawMode.Mesh) { displayMap.DrawMesh(meshGenerator.GenerateTerrainMesh(noiseMap, meshHeightMultiplier, heightCurve), textureGenerator.TextureFromColorMap(colorMap, mapWidth, mapHeight)); } }
private void Start() { _noiseMapGenerator = new NoiseMapGenerator(); GenerateMap(); }
object RequestNoiseMap() { return(NoiseMapGenerator.GetNoiseMap3D(meshSettings.chunkSize + 1, meshSettings.chunkSize + 1, meshSettings.chunkSize + 1, bounds.min, noiseSettings)); }
public void GeneratePreview() { if (previewMode == PreviewMode.WholeSphere) { allSphereChunks.SetActive(false); meshFilter.gameObject.SetActive(true); noiseMap = NoiseMapGenerator.GetNoiseMap3D(diameter + 1, diameter + 1, diameter + 1, offset, noiseSettings); NoiseMapData mapData = new NoiseMapData(noiseMap, offset); Mesh mesh = MeshGenerator.GenerateSphereMesh(mapData, sphereMeshSettings, lod).GetMesh(); meshFilter.sharedMesh = mesh; UpdateReferenceSphere(); UpdateReferencePlanes(); } else if (previewMode == PreviewMode.SingleChunk) { allSphereChunks.SetActive(false); meshFilter.gameObject.SetActive(true); noiseMap = NoiseMapGenerator.GetNoiseMap3D(sphereMeshSettings.chunkSize + 1, sphereMeshSettings.chunkSize + 1, sphereMeshSettings.chunkSize + 1, offset, noiseSettings); NoiseMapData mapData = new NoiseMapData(noiseMap, offset); Mesh mesh = MeshGenerator.GenerateSphereChunkMesh(mapData, sphereMeshSettings, lod).GetMesh(); meshFilter.sharedMesh = mesh; } else if (previewMode == PreviewMode.AllChunks) { meshFilter.gameObject.SetActive(false); allSphereChunks.SetActive(true); DeleteChunks(); int chunkRadius = Mathf.CeilToInt(sphereMeshSettings.radius / sphereMeshSettings.chunkSize); if (noiseSettings.isNormalized) { chunkRadius += Mathf.Max(Mathf.RoundToInt(sphereMeshSettings.noiseHeightScale * (1 - noiseSettings.normShift)) / sphereMeshSettings.chunkSize, 2); } else { chunkRadius += Mathf.Max(Mathf.RoundToInt(sphereMeshSettings.noiseHeightScale * 1.5f) / sphereMeshSettings.chunkSize, 2); } if (chunkRadius % 2 == 1) { chunkRadius--; } // Save the old offset so we can change it back later for (int z = -chunkRadius; z < chunkRadius; z++) { for (int y = -chunkRadius; y < chunkRadius; y++) { for (int x = -chunkRadius; x < chunkRadius; x++) { Vector3 chunkOffset = new Vector3(x * sphereMeshSettings.chunkSize, y * sphereMeshSettings.chunkSize, z * sphereMeshSettings.chunkSize); GameObject newChunk = new GameObject("Chunk: " + chunkOffset.x + ", " + chunkOffset.y + ", " + chunkOffset.z); newChunk.transform.SetParent(allSphereChunks.transform); noiseMap = NoiseMapGenerator.GetNoiseMap3D(sphereMeshSettings.chunkSize + 1, sphereMeshSettings.chunkSize + 1, sphereMeshSettings.chunkSize + 1, chunkOffset, noiseSettings); NoiseMapData mapData = new NoiseMapData(noiseMap, chunkOffset); // Mesh mesh = MeshGenerator.GenerateSphereChunkMesh(mapData, sphereMeshSettings, lod).GetMesh(); // newChunk.AddComponent <MeshFilter>().sharedMesh = mesh; newChunk.AddComponent <MeshRenderer>().sharedMaterial = material; } } } } else if (previewMode == PreviewMode.Threaded) { MyStopwatch.stopwatch.Start(); meshFilter.gameObject.SetActive(false); allSphereChunks.SetActive(true); DeleteChunks(); //int chunkRadius = Mathf.CeilToInt(sphereMeshSettings.radius / sphereMeshSettings.chunkSize) + 2; //if (noiseSettings.isNormalized) //{ // chunkRadius += Mathf.Max(Mathf.RoundToInt(sphereMeshSettings.noiseHeightScale * (1 - noiseSettings.normShift)) / sphereMeshSettings.chunkSize, 2); //} //else //{ // chunkRadius += Mathf.Max(Mathf.RoundToInt(sphereMeshSettings.noiseHeightScale * 1.5f) / sphereMeshSettings.chunkSize, 2); //} int chunkRadius = viewDistance / sphereMeshSettings.chunkSize; int chunksCreated = 0; for (int z = -chunkRadius; z < chunkRadius; z++) { for (int y = Mathf.FloorToInt(sphereMeshSettings.radius / sphereMeshSettings.chunkSize) - chunkRadius; y < Mathf.CeilToInt(sphereMeshSettings.radius / sphereMeshSettings.chunkSize) + 2; y++) { for (int x = -chunkRadius; x < chunkRadius; x++) { Vector3 chunkOffset = new Vector3(x * sphereMeshSettings.chunkSize, y * sphereMeshSettings.chunkSize, z * sphereMeshSettings.chunkSize); new TerrainChunk(chunkOffset, allSphereChunks.transform, noiseSettings, sphereMeshSettings, material, allSphereChunks.transform); chunksCreated++; } } } //if (chunkRadius % 2 == 1) //{ // chunkRadius--; //} //int chunksCreated = 0; //for (int z = -chunkRadius; z < chunkRadius; z++) //{ // for (int y = -chunkRadius; y < chunkRadius; y++) // { // for (int x = -chunkRadius; x < chunkRadius; x++) // { // Vector3 chunkOffset = new Vector3(x * sphereMeshSettings.chunkSize, y * sphereMeshSettings.chunkSize, z * sphereMeshSettings.chunkSize); // new TerrainChunk(chunkOffset, sphereMeshSettings.chunkSize, allSphereChunks.transform, noiseSettings, sphereMeshSettings, material, vertexIncrement); // chunksCreated++; // } // } //} MyStopwatch.s = string.Format("{0}", chunksCreated); } UpdateReferenceSphere(); UpdateReferencePlanes(); }