- Home /
Question by
PioMine · Sep 06, 2021 at 08:41 PM ·
map-generation
Map generation by sebastian lague errors
recently i followed the tutorial by sebastian lague and im getting 5 errors that i cant solve:
(51,64): error CS1503: Argument 1: cannot convert from 'float[,]' to 'HeightMap' (55,36): error CS1501: No overload for method 'GenerateTerrainMesh' takes 4 arguments (57,62): error CS1503: Argument 1: cannot convert from 'float[,]' to 'HeightMap' (85,37): error CS1501: No overload for method 'GenerateTerrainMesh' takes 4 arguments (108,29): error CS1501: No overload for method 'GenerateNoiseMap' takes 9 arguments
code:
using UnityEngine;
using System.Collections;
using System;
using System.Threading;
using System.Collections.Generic;
public class MapGenerator : MonoBehaviour {
public enum DrawMode {NoiseMap, ColourMap, Mesh, FalloffMap};
public DrawMode drawMode;
public Noise.NormalizeMode normalizeMode;
public const int mapChunkSize = 241;
[Range(0,6)]
public int editorPreviewLOD;
public float noiseScale;
public int octaves;
[Range(0,1)]
public float persistance;
public float lacunarity;
public int seed;
public Vector2 offset;
public bool useFalloff;
public float meshHeightMultiplier;
public AnimationCurve meshHeightCurve;
public bool autoUpdate;
public TerrainType[] regions;
float[,] falloffMap;
Queue<MapThreadInfo<MapData>> mapDataThreadInfoQueue = new Queue<MapThreadInfo<MapData>>();
Queue<MapThreadInfo<MeshData>> meshDataThreadInfoQueue = new Queue<MapThreadInfo<MeshData>>();
void Awake() {
falloffMap = FalloffGenerator.GenerateFalloffMap (mapChunkSize);
}
public void DrawMapInEditor() {
MapData mapData = GenerateMapData (Vector2.zero);
MapDisplay display = FindObjectOfType<MapDisplay> ();
if (drawMode == DrawMode.NoiseMap)
{
display.DrawTexture (TextureGenerator.TextureFromHeightMap (mapData.heightMap));
} else if (drawMode == DrawMode.ColourMap) {
display.DrawTexture (TextureGenerator.TextureFromColourMap (mapData.colourMap, mapChunkSize, mapChunkSize));
} else if (drawMode == DrawMode.Mesh) {
display.DrawMesh (MeshGenerator.GenerateTerrainMesh (mapData.heightMap, meshHeightMultiplier, meshHeightCurve, editorPreviewLOD), TextureGenerator.TextureFromColourMap (mapData.colourMap, mapChunkSize, mapChunkSize));
} else if (drawMode == DrawMode.FalloffMap) {
display.DrawTexture(TextureGenerator.TextureFromHeightMap(FalloffGenerator.GenerateFalloffMap(mapChunkSize)));
}
}
public void RequestMapData(Vector2 centre, Action<MapData> callback) {
ThreadStart threadStart = delegate {
MapDataThread (centre, callback);
};
new Thread (threadStart).Start ();
}
void MapDataThread(Vector2 centre, Action<MapData> callback) {
MapData mapData = GenerateMapData (centre);
lock (mapDataThreadInfoQueue) {
mapDataThreadInfoQueue.Enqueue (new MapThreadInfo<MapData> (callback, mapData));
}
}
public void RequestMeshData(MapData mapData, int lod, Action<MeshData> callback) {
ThreadStart threadStart = delegate {
MeshDataThread (mapData, lod, callback);
};
new Thread (threadStart).Start ();
}
void MeshDataThread(MapData mapData, int lod, Action<MeshData> callback) {
MeshData meshData = MeshGenerator.GenerateTerrainMesh (mapData.heightMap, meshHeightMultiplier, meshHeightCurve, lod);
lock (meshDataThreadInfoQueue) {
meshDataThreadInfoQueue.Enqueue (new MapThreadInfo<MeshData> (callback, meshData));
}
}
void Update() {
if (mapDataThreadInfoQueue.Count > 0) {
for (int i = 0; i < mapDataThreadInfoQueue.Count; i++) {
MapThreadInfo<MapData> threadInfo = mapDataThreadInfoQueue.Dequeue ();
threadInfo.callback (threadInfo.parameter);
}
}
if (meshDataThreadInfoQueue.Count > 0) {
for (int i = 0; i < meshDataThreadInfoQueue.Count; i++) {
MapThreadInfo<MeshData> threadInfo = meshDataThreadInfoQueue.Dequeue ();
threadInfo.callback (threadInfo.parameter);
}
}
}
MapData GenerateMapData(Vector2 centre) {
float[,] noiseMap = Noise.GenerateNoiseMap (mapChunkSize, mapChunkSize, seed, noiseScale, octaves, persistance, lacunarity, centre + offset, normalizeMode);
Color[] colourMap = new Color[mapChunkSize * mapChunkSize];
for (int y = 0; y < mapChunkSize; y++) {
for (int x = 0; x < mapChunkSize; x++) {
if (useFalloff) {
noiseMap [x, y] = Mathf.Clamp01(noiseMap [x, y] - falloffMap [x, y]);
}
float currentHeight = noiseMap [x, y];
for (int i = 0; i < regions.Length; i++) {
if (currentHeight >= regions [i].height) {
colourMap [y * mapChunkSize + x] = regions [i].colour;
} else {
break;
}
}
}
}
return new MapData (noiseMap, colourMap);
}
void OnValidate() {
if (lacunarity < 1) {
lacunarity = 1;
}
if (octaves < 0) {
octaves = 0;
}
falloffMap = FalloffGenerator.GenerateFalloffMap (mapChunkSize);
}
struct MapThreadInfo<T> {
public readonly Action<T> callback;
public readonly T parameter;
public MapThreadInfo (Action<T> callback, T parameter)
{
this.callback = callback;
this.parameter = parameter;
}
}
}
more codes that errors and main code recalls to:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class HeightMapGenerator {
public static HeightMap GenerateHeightMap(int width, int height, HeightMapSettings settings, Vector2 sampleCentre) {
float[,] values = Noise.GenerateNoiseMap (width, height, settings.noiseSettings, sampleCentre);
AnimationCurve heightCurve_threadsafe = new AnimationCurve (settings.heightCurve.keys);
float minValue = float.MaxValue;
float maxValue = float.MinValue;
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
values [i, j] *= heightCurve_threadsafe.Evaluate (values [i, j]) * settings.heightMultiplier;
if (values [i, j] > maxValue) {
maxValue = values [i, j];
}
if (values [i, j] < minValue) {
minValue = values [i, j];
}
}
}
return new HeightMap (values, minValue, maxValue);
}
}
public struct HeightMap {
public readonly float[,] values;
public readonly float minValue;
public readonly float maxValue;
public HeightMap (float[,] values, float minValue, float maxValue)
{
this.values = values;
this.minValue = minValue;
this.maxValue = maxValue;
}
}
and
using UnityEngine;
using System.Collections;
public static class TextureGenerator {
public static Texture2D TextureFromColourMap(Color[] colourMap, int width, int height) {
Texture2D texture = new Texture2D (width, height);
texture.filterMode = FilterMode.Point;
texture.wrapMode = TextureWrapMode.Clamp;
texture.SetPixels (colourMap);
texture.Apply ();
return texture;
}
public static Texture2D TextureFromHeightMap(HeightMap heightMap) {
int width = heightMap.values.GetLength (0);
int height = heightMap.values.GetLength (1);
Color[] colourMap = new Color[width * height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
colourMap [y * width + x] = Color.Lerp (Color.black, Color.white, Mathf.InverseLerp(heightMap.minValue,heightMap.maxValue,heightMap.values [x, y]));
}
}
return TextureFromColourMap (colourMap, width, height);
}
//draw the current ObjectMap
public static Texture2D TextureFromObjectMap(ObjectMap heightMap) {
int width = heightMap.values.GetLength (0);
int height = heightMap.values.GetLength (1);
Color[] colourMap = new Color[width * height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
colourMap [y * width + x] = Color.Lerp (Color.black, Color.white, Mathf.InverseLerp(heightMap.minValue,heightMap.maxValue,heightMap.values [x, y]));
}
}
return TextureFromColourMap (colourMap, width, height);
}
}
sorry for bothering and thank you in advance
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613042656im_/https://answers.unity.com/themes/thub/images/avi.jpg)