Skip to content

Commit 68f8b36

Browse files
committed
Merge commit '712cd80dd287588b40b164b20ab4ced121d79ffc' into ui-fixes
* commit '712cd80dd287588b40b164b20ab4ced121d79ffc': Fix range height extrusion (#613) # Conflicts: # sdkproject/Assets/Mapbox/Unity/DataContainers/MapboxEnums.cs
2 parents dc22e22 + 712cd80 commit 68f8b36

File tree

5 files changed

+87
-50
lines changed

5 files changed

+87
-50
lines changed

documentation/docs/05-changelog.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
## CHANGELOG
2+
### v.1.4.0
3+
*??/??/2018*
4+
5+
#####
6+
- Fix `Range Property` extrusion option for vector features.
7+
- Add scale factor for extrusion value derived from feature property.
28

39
### v.1.4.0
410
*03/20/2018*
511

612
#####
7-
- Drag and drop prefabs for most common use cases.
13+
- Drag and drop prefabs for most common use cases.
814
- New Abstract Map UI
9-
- Style development - colorization and atlas template generator
15+
- Style development - colorization and atlas template generator
1016
- Use texture atlas for building geometries.
11-
- Merge buildings with unique ids using the experimental 3D buildings tileset.
17+
- Merge buildings with unique ids using the experimental 3D buildings tileset.
1218
- Added a API call on AbstractMap to query height at a certain latitude longitude.
1319
- Included EditorConfig file to enforce coding style
1420
- Integration of previously seperate AR support https://github.com/mapbox/mapbox-unity-sdk/pull/544
1521

1622
### v.1.3.0
1723
*12/18/2017*
1824

19-
##### Upgrade Instructions
25+
##### Upgrade Instructions
2026
- As always, if you already have a project with a previous version of the SDK, please remove older versions before installing this new one!
2127
- `FeatureBehaviour` is no longer added to feature gameobjects by default. Use a `FeatureBehaviourModifier` to add this component (optimization).
2228
- `TextureModifier` is obsolete. Please use `MaterialModifier`.
@@ -31,7 +37,7 @@
3137

3238
##### New Features
3339
- Added convenience methods to `AbstractMap` to convert between Lat/Lon ↔ Vector3. This also works for maps that have been translated, rotated, or scaled! #387
34-
- Added tile error exception events that you can hook into to know when specific tiles fail to load. We provide an example `TileErrorHandler` object that logs these to console.
40+
- Added tile error exception events that you can hook into to know when specific tiles fail to load. We provide an example `TileErrorHandler` object that logs these to console.
3541
- Added C# wrapper for Mapbox Token API (to validate tokens).
3642
- Added transparency shader for raster tiles—this enables you to convert black to alpha from Mapbox studio styles (to render just road labels, for example).
3743
- Added new `LoftModifier`—use this to make complex geometry from line features.
@@ -43,7 +49,7 @@
4349
##### Bug Fixes
4450
- It should now be safe to nest the Mapbox folder (SDK) in your own projects.
4551
- You can now properly change/load scenes at runtime. #381
46-
- Fixed token validation issues (validate token when initializing `MapboxAccess`). #430
52+
- Fixed token validation issues (validate token when initializing `MapboxAccess`). #430
4753
- Custom inspectors now properly serialize assets assigned via built-in object browser.
4854
- Fix for certain tile providers not updating properly when re-initializing a map.
4955
- Fixed issue where clipped features would result in several new features. #398
@@ -67,7 +73,7 @@
6773
- Array support to mock a specific route (`LocationArrayEditorLocationProvider`).
6874
- Transform support on `EditorLocationProvider` to create simple offsets.
6975
- Use Unity Remote app to send location updates directly to the Unity editor from your device!
70-
- `DynamicZoom` example has been improved, see new `Zoomable` map example.
76+
- `DynamicZoom` example has been improved, see new `Zoomable` map example.
7177
- Added string to lat/lon conversion method.
7278
- Various nodes in the map factory framework now have public fields to support run-time styling or modification before map generation (based on settings, for example).
7379
- Maps now support float values for zoom level—you can use this to inform camera controllers, for example.
@@ -214,7 +220,7 @@
214220
- Elevation textures are no longer held in memory and height data parsing and access is much faster
215221
- Added new `FlatTerrainFactory` that is optimized specifically for flat maps
216222
- Tiles can now be cached in memory—configure the cache size in `MapboxAccess.cs` (default size is 500)
217-
- Slippy maps now dispose tiles that determined to be "out of range"
223+
- Slippy maps now dispose tiles that determined to be "out of range"
218224
- Tiles that are out of range before completion are properly cancelled
219225
- Terrain generation in Unity 5.5+ should be much faster and allocate less memory
220226

@@ -256,12 +262,12 @@
256262
- Fixed issue where visualizers for `MeshFactories` were not being serialized properly
257263
- Fixed null reference exception when creating a new `MeshFactory`
258264

259-
### v0.5.0
265+
### v0.5.0
260266

261267
*04/26/2017*
262268

263-
- Added support for UWP
264-
- Share your Hololens creations with us!
269+
- Added support for UWP
270+
- Share your Hololens creations with us!
265271
- Fixed precision issue with tile conversions
266272
- Replaced `Geocoordinate` with `Vector2d`
267273
- Mapbox API Token is now stored in MapboxAccess.txt

sdkproject/Assets/Mapbox/Unity/DataContainers/GeometryExtrusionOptions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using Mapbox.Unity.MeshGeneration.Modifiers;
55
using Mapbox.Unity.MeshGeneration.Data;
6+
using UnityEngine;
67

78
[Serializable]
89
public class GeometryExtrusionOptions : ModifierProperties
@@ -16,9 +17,12 @@ public override Type ModifierType
1617
}
1718
public ExtrusionType extrusionType = ExtrusionType.None;
1819
public ExtrusionGeometryType extrusionGeometryType = ExtrusionGeometryType.RoofAndSide;
20+
[Tooltip("Property name in feature layer to use for extrusion.")]
1921
public string propertyName = "height";
2022
public float minimumHeight = 0f;
2123
public float maximumHeight = 0f;
24+
[Tooltip("Scale factor to multiply the extrusion value of the feature.")]
25+
public float extrusionScaleFactor = 1f;
2226
}
2327

2428
[Serializable]
@@ -38,6 +42,7 @@ public override Type ModifierType
3842
public string propertyName = "height";
3943
public float minimumHeight = 0f;
4044
public float maximumHeight = 0f;
45+
public float extrusionScaleFactor = 1f;
4146

4247
public GeometryExtrusionWithAtlasOptions()
4348
{
@@ -50,6 +55,7 @@ public GeometryExtrusionWithAtlasOptions(GeometryExtrusionOptions extrusionOptio
5055
propertyName = extrusionOptions.propertyName;
5156
minimumHeight = extrusionOptions.minimumHeight;
5257
maximumHeight = extrusionOptions.maximumHeight;
58+
extrusionScaleFactor = extrusionOptions.extrusionScaleFactor;
5359

5460
texturingType = uvOptions.texturingType;
5561
atlasInfo = uvOptions.atlasInfo;

sdkproject/Assets/Mapbox/Unity/Editor/PropertyDrawers/GeometryExtrusionOptionsDrawer.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using UnityEditor;
44
using UnityEngine;
55
using Mapbox.Unity.Map;
6+
using Mapbox.VectorTile.ExtensionMethods;
67

78
[CustomPropertyDrawer(typeof(GeometryExtrusionOptions))]
89
public class GeometryExtrusionOptionsDrawer : PropertyDrawer
@@ -12,9 +13,9 @@ public class GeometryExtrusionOptionsDrawer : PropertyDrawer
1213
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
1314
{
1415
EditorGUI.BeginProperty(position, label, property);
15-
16-
var typePosition = EditorGUI.PrefixLabel(new Rect(position.x, position.y, position.width, lineHeight), GUIUtility.GetControlID(FocusType.Passive), new GUIContent("Extrusion Type"));
1716
var extrusionTypeProperty = property.FindPropertyRelative("extrusionType");
17+
var typePosition = EditorGUI.PrefixLabel(new Rect(position.x, position.y, position.width, lineHeight), GUIUtility.GetControlID(FocusType.Passive), new GUIContent { text = "Extrusion Type", tooltip = EnumExtensions.Description((Unity.Map.ExtrusionType)extrusionTypeProperty.enumValueIndex) });
18+
1819

1920
EditorGUI.indentLevel--;
2021
extrusionTypeProperty.enumValueIndex = EditorGUI.Popup(typePosition, extrusionTypeProperty.enumValueIndex, extrusionTypeProperty.enumDisplayNames);
@@ -24,48 +25,57 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
2425
var minHeightProperty = property.FindPropertyRelative("minimumHeight");
2526
var maxHeightProperty = property.FindPropertyRelative("maximumHeight");
2627

28+
var extrusionGeometryType = property.FindPropertyRelative("extrusionGeometryType");
29+
var extrusionGeometryGUI = new GUIContent { text = "Extrusion Geometry Type", tooltip = EnumExtensions.Description((Unity.Map.ExtrusionGeometryType)extrusionGeometryType.enumValueIndex) };
2730
EditorGUI.indentLevel++;
2831
switch (sourceTypeValue)
2932
{
3033
case Unity.Map.ExtrusionType.None:
3134
break;
3235
case Unity.Map.ExtrusionType.PropertyHeight:
3336
position.y += lineHeight;
34-
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), property.FindPropertyRelative("extrusionGeometryType"));
37+
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), extrusionGeometryType, extrusionGeometryGUI);
3538
position.y += lineHeight;
3639
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), property.FindPropertyRelative("propertyName"));
3740
break;
3841
case Unity.Map.ExtrusionType.MinHeight:
3942
position.y += lineHeight;
40-
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), property.FindPropertyRelative("extrusionGeometryType"));
43+
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), extrusionGeometryType, extrusionGeometryGUI);
4144
position.y += lineHeight;
4245
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), property.FindPropertyRelative("propertyName"));
4346
break;
4447
case Unity.Map.ExtrusionType.MaxHeight:
4548
position.y += lineHeight;
46-
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), property.FindPropertyRelative("extrusionGeometryType"));
49+
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), extrusionGeometryType, extrusionGeometryGUI);
4750
position.y += lineHeight;
4851
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), property.FindPropertyRelative("propertyName"));
4952
break;
5053
case Unity.Map.ExtrusionType.RangeHeight:
5154
position.y += lineHeight;
52-
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), property.FindPropertyRelative("extrusionGeometryType"));
55+
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), extrusionGeometryType, extrusionGeometryGUI);
5356
position.y += lineHeight;
5457
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), property.FindPropertyRelative("propertyName"));
5558
position.y += lineHeight;
5659
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), minHeightProperty);
5760
position.y += lineHeight;
5861
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), maxHeightProperty);
62+
if (minHeightProperty.floatValue > maxHeightProperty.floatValue)
63+
{
64+
//position.y += lineHeight;
65+
EditorGUILayout.HelpBox("Maximum Height less than Minimum Height!", MessageType.Error);
66+
}
5967
break;
6068
case Unity.Map.ExtrusionType.AbsoluteHeight:
6169
position.y += lineHeight;
62-
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), property.FindPropertyRelative("extrusionGeometryType"));
70+
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), extrusionGeometryType, extrusionGeometryGUI);
6371
position.y += lineHeight;
6472
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), maxHeightProperty, new GUIContent { text = "Height" });
6573
break;
6674
default:
6775
break;
6876
}
77+
position.y += lineHeight;
78+
EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, lineHeight), property.FindPropertyRelative("extrusionScaleFactor"), new GUIContent { text = "Scale Factor" });
6979
EditorGUI.indentLevel--;
7080

7181
EditorGUI.EndProperty();
@@ -75,7 +85,7 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent
7585
var extrusionTypeProperty = property.FindPropertyRelative("extrusionType");
7686
var sourceTypeValue = (Unity.Map.ExtrusionType)extrusionTypeProperty.enumValueIndex;
7787

78-
int rows = 0;
88+
int rows = 1;
7989
//if (showPosition)
8090
{
8191
switch (sourceTypeValue)

sdkproject/Assets/Mapbox/Unity/MeshGeneration/Modifiers/MeshModifiers/HeightModifier.cs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,6 @@ public static MinMaxPair GetMinMaxHeight(List<Vector3> vertices)
3939
[CreateAssetMenu(menuName = "Mapbox/Modifiers/Height Modifier")]
4040
public class HeightModifier : MeshModifier
4141
{
42-
//[SerializeField]
43-
//[Tooltip("Flatten top polygons to prevent unwanted slanted roofs because of the bumpy terrain")]
44-
//private bool _flatTops;
45-
46-
//[SerializeField]
47-
//[Tooltip("Fix all features to certain height, suggested to be used for pushing roads above terrain level to prevent z-fighting.")]
48-
//private bool _forceHeight;
49-
50-
//[SerializeField]
51-
//[Tooltip("Fixed height value for ForceHeight option")]
52-
//private float _height;
5342
private float _scale = 1;
5443

5544
//[SerializeField]
@@ -89,17 +78,21 @@ public override void Run(VectorFeatureUnity feature, MeshData md, UnityTile tile
8978

9079
float maxHeight = 1.0f;
9180
float minHeight = 0.0f;
81+
9282
QueryHeight(feature, md, tile, out maxHeight, out minHeight);
93-
height = (maxHeight - minHeight) * _scale;
94-
maxHeight = maxHeight * _scale;
95-
minHeight = minHeight * _scale;
83+
84+
maxHeight = maxHeight * _options.extrusionScaleFactor * _scale;
85+
minHeight = minHeight * _options.extrusionScaleFactor * _scale;
86+
height = (maxHeight - minHeight);
87+
9688
//Set roof height
9789
GenerateRoofMesh(md, minHeight, maxHeight);
9890

9991
GenerateWallMesh(md);
10092

10193
}
102-
private void GenerateWallMesh(MeshData md)
94+
95+
protected virtual void GenerateWallMesh(MeshData md)
10396
{
10497
md.Vertices.Capacity = _counter + md.Edges.Count * 2;
10598
float d = 0f;
@@ -170,7 +163,7 @@ private void GenerateWallMesh(MeshData md)
170163
}
171164
}
172165

173-
private void GenerateRoofMesh(MeshData md, float minHeight, float maxHeight)
166+
protected virtual void GenerateRoofMesh(MeshData md, float minHeight, float maxHeight)
174167
{
175168
if (_options.extrusionGeometryType != ExtrusionGeometryType.SideOnly)
176169
{
@@ -206,6 +199,10 @@ private void GenerateRoofMesh(MeshData md, float minHeight, float maxHeight)
206199
}
207200
break;
208201
case ExtrusionType.RangeHeight:
202+
for (int i = 0; i < _counter; i++)
203+
{
204+
md.Vertices[i] = new Vector3(md.Vertices[i].x, md.Vertices[i].y + maxHeight, md.Vertices[i].z);
205+
}
209206
break;
210207
case ExtrusionType.AbsoluteHeight:
211208
for (int i = 0; i < _counter; i++)
@@ -219,7 +216,7 @@ private void GenerateRoofMesh(MeshData md, float minHeight, float maxHeight)
219216
}
220217
}
221218

222-
private void QueryHeight(VectorFeatureUnity feature, MeshData md, UnityTile tile, out float maxHeight, out float minHeight)
219+
protected virtual void QueryHeight(VectorFeatureUnity feature, MeshData md, UnityTile tile, out float maxHeight, out float minHeight)
223220
{
224221
minHeight = 0.0f;
225222
maxHeight = 0.0f;
@@ -244,8 +241,20 @@ private void QueryHeight(VectorFeatureUnity feature, MeshData md, UnityTile tile
244241
case ExtrusionType.RangeHeight:
245242
if (feature.Properties.ContainsKey(_options.propertyName))
246243
{
244+
if (_options.minimumHeight > _options.maximumHeight)
245+
{
246+
Debug.LogError("Maximum Height less than Minimum Height.Swapping values for extrusion.");
247+
var temp = _options.minimumHeight;
248+
_options.minimumHeight = _options.maximumHeight;
249+
_options.maximumHeight = temp;
250+
}
247251
var featureHeight = Convert.ToSingle(feature.Properties[_options.propertyName]);
248252
maxHeight = Math.Min(Math.Max(_options.minimumHeight, featureHeight), _options.maximumHeight);
253+
if (feature.Properties.ContainsKey("min_height"))
254+
{
255+
var featureMinHeight = Convert.ToSingle(feature.Properties["min_height"]);
256+
minHeight = Math.Min(featureMinHeight, _options.maximumHeight);
257+
}
249258
}
250259
break;
251260
case ExtrusionType.AbsoluteHeight:

sdkproject/Assets/Mapbox/Unity/MeshGeneration/Modifiers/TextureSideWallModifier.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ namespace Mapbox.Unity.MeshGeneration.Modifiers
99
[CreateAssetMenu(menuName = "Mapbox/Modifiers/Textured Side Wall Modifier")]
1010
public class TextureSideWallModifier : MeshModifier
1111
{
12-
//[SerializeField]
13-
//private float _height;
14-
//[SerializeField]
15-
//private bool _forceHeight;
16-
1712
private float _scaledFloorHeight = 0;
1813
private float _scaledFirstFloorHeight = 0;
1914
private float _scaledTopFloorHeight = 0;
@@ -92,17 +87,11 @@ public override void Run(VectorFeatureUnity feature, MeshData md, UnityTile tile
9287

9388
//read or force height
9489
float maxHeight = 1, minHeight = 0;
95-
//SetHeight(feature, md, tile, out maxHeight, out minHeight);
96-
//height = maxHeight - minHeight;
97-
//for (int i = 0; i < md.Vertices.Count; i++)
98-
//{
99-
// md.Vertices[i] = new Vector3(md.Vertices[i].x, md.Vertices[i].y + maxHeight, md.Vertices[i].z);
100-
//}
10190

10291
QueryHeight(feature, md, tile, out maxHeight, out minHeight);
103-
height = (maxHeight - minHeight) * _scale;
104-
maxHeight = maxHeight * _scale;
105-
minHeight = minHeight * _scale;
92+
maxHeight = maxHeight * _options.extrusionScaleFactor * _scale;
93+
minHeight = minHeight * _options.extrusionScaleFactor * _scale;
94+
height = (maxHeight - minHeight);
10695

10796
GenerateRoofMesh(md, minHeight, maxHeight);
10897

@@ -367,6 +356,10 @@ private void GenerateRoofMesh(MeshData md, float minHeight, float maxHeight)
367356
}
368357
break;
369358
case ExtrusionType.RangeHeight:
359+
for (int i = 0; i < _counter; i++)
360+
{
361+
md.Vertices[i] = new Vector3(md.Vertices[i].x, md.Vertices[i].y + maxHeight, md.Vertices[i].z);
362+
}
370363
break;
371364
case ExtrusionType.AbsoluteHeight:
372365
for (int i = 0; i < _counter; i++)
@@ -405,8 +398,21 @@ private void QueryHeight(VectorFeatureUnity feature, MeshData md, UnityTile tile
405398
case ExtrusionType.RangeHeight:
406399
if (feature.Properties.ContainsKey(_options.propertyName))
407400
{
401+
if (_options.minimumHeight > _options.maximumHeight)
402+
{
403+
Debug.LogError("Maximum Height less than Minimum Height.Swapping values for extrusion.");
404+
var temp = _options.minimumHeight;
405+
_options.minimumHeight = _options.maximumHeight;
406+
_options.maximumHeight = temp;
407+
}
408408
var featureHeight = Convert.ToSingle(feature.Properties[_options.propertyName]);
409409
maxHeight = Math.Min(Math.Max(_options.minimumHeight, featureHeight), _options.maximumHeight);
410+
if (feature.Properties.ContainsKey("min_height"))
411+
{
412+
var featureMinHeight = Convert.ToSingle(feature.Properties["min_height"]);
413+
minHeight = Math.Min(featureMinHeight, _options.maximumHeight);
414+
//maxHeight -= minHeight;
415+
}
410416
}
411417
break;
412418
case ExtrusionType.AbsoluteHeight:

0 commit comments

Comments
 (0)