diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Constants.cs b/sdkproject/Assets/Mapbox/Core/Unity/Constants.cs index f0f8db1ee..4829a89eb 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Constants.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Constants.cs @@ -1,5 +1,7 @@ namespace Mapbox.Unity { + using UnityEngine; + public static class Constants { public static class Path @@ -9,5 +11,15 @@ public static class Path /// public const string TOKEN_FILE = "MapboxAccess.text"; } + + /// + /// Store common vector constants to avoid the method access cost of Unity's convenience getters. + /// + public static class Math + { + public static readonly Vector3 Vector3Zero = new Vector3(0, 0, 0); + public static readonly Vector3 Vector3Up = new Vector3(0, 1, 0); + public static readonly Vector3 Vector3Down = new Vector3(0, -1, 0); + } } } \ No newline at end of file diff --git a/sdkproject/Assets/Mapbox/Core/Unity/Editor/TerrainFactoryEditor.cs b/sdkproject/Assets/Mapbox/Core/Unity/Editor/TerrainFactoryEditor.cs index 988ed45a6..0311a5408 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/Editor/TerrainFactoryEditor.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/Editor/TerrainFactoryEditor.cs @@ -57,7 +57,7 @@ public override void OnInspectorGUI() EditorGUILayout.PropertyField(mapIdType_Prop); switch ((MapIdType)mapIdType_Prop.enumValueIndex) { - case MapIdType.StandardHeight: + case MapIdType.Standard: GUI.enabled = false; EditorGUILayout.PropertyField(mapId_Prop, new GUIContent("Map Id")); mapId_Prop.stringValue = _defaultMapId; @@ -74,7 +74,7 @@ public override void OnInspectorGUI() EditorGUILayout.PropertyField(mapIdType_Prop); switch ((MapIdType)mapIdType_Prop.enumValueIndex) { - case MapIdType.StandardHeight: + case MapIdType.Standard: GUI.enabled = false; EditorGUILayout.PropertyField(mapId_Prop, new GUIContent("Map Id")); mapId_Prop.stringValue = _defaultMapId; diff --git a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/TerrainFactory.cs b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/TerrainFactory.cs index 72ad51f43..a6dae00f0 100644 --- a/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/TerrainFactory.cs +++ b/sdkproject/Assets/Mapbox/Core/Unity/MeshGeneration/Factories/TerrainFactory.cs @@ -18,7 +18,7 @@ public enum TerrainGenerationType public enum MapIdType { - StandardHeight, + Standard, Custom } @@ -142,7 +142,6 @@ private void GenerateTerrainMesh(UnityTile tile, float heightMultiplier) var go = tile.gameObject; var mesh = new MeshData(); mesh.Vertices = new List(_sampleCount * _sampleCount); - mesh.Normals = new List(_sampleCount * _sampleCount); var step = 1f / (_sampleCount - 1); for (float y = 0; y < _sampleCount; y++) { @@ -161,12 +160,11 @@ private void GenerateTerrainMesh(UnityTile tile, float heightMultiplier) (int)((1 - yrat) * 255)), tile.RelativeScale), (float)(yy - tile.Rect.Center.y))); + mesh.Normals.Add(Unity.Constants.Math.Vector3Up); mesh.UV[0].Add(new Vector2(x * step, 1 - (y * step))); } } - //we can read these from a hardcoded dictionary as well - //no need to calculate this every single time unless we need a really high range for sampleCount var trilist = new List(); var dir = Vector3.zero; int vertA, vertB, vertC;