Mesh generation with the Mapbox Maps SDK for Unity, Part 3: style buildings
Note: This tutorial applies to versions 1.3.0 or earlier of the Mapbox SDK for Unity. To get started with version 1.4.0 or later, please visit this new tutorial.
This is the third in a series of tutorials that will walk you through how to create a visualization of 3D buildings on top of a 3D terrain map for use in a Unity application. In Part 3, you'll select and style specific building types using your
CityMergedBuildingStack from Part 2 of this series.
To do this, you’ll place several additional stacks under the
CityBuildingLayerVisualizer to define how your subset of buildings should appear in the scene.
Before getting started, you’ll need to:
- Install the Mapbox Maps SDK for Unity. For full installation instructions, visit https://www.mapbox.com/unity-sdk.
- Start a Mapbox project in Unity. For step-by-step instructions on how to set up a new Unity project, see Part 1 .
- Add 3D buildings to your project. For step-by-step instructions, see Part 2
In part 2 of this series, you added some 3D buildings to your scene, but they all look the same. What if you wanted to add some emphasis to a particular type of building? In this guide, you'll create additional stacks to define how all the schools in your scene should look.
To get started, open the Unity project you created in part 2 of this tutorial series. Create an additional folder in your BuildingLayer directory and call it CityBlueBuildingStack.
- Right-click on the CityBlueBuildingStack.
- Navigate to the Mapbox context menu.
- Select Modifiers context menu, create a Merged Modifier Stack called
Next, using the steps above create the following modifiers:
- A SnapTerrainModifier called
- A PolygonMeshModifier called
- A UVModifier called
- A HeightModifier called
- Add each of the modifiers to your
CityBlueBuildingStackin the order that you created above.
If you've completed part 2 of this series, the above should look familiar. You're creating a second MergedModifierStack that mimics all the characteristics of the one you created in the last tutorial. In a future step, you'll add the MergedModifierStack you created to your layer visualizer to apply a distinct style to the schools in your scene.
Now that you've created a MergedModifierStack for your buildings, you'll need to apply some styles to visually differentiate the schools from all the other buildings in the scene.
In the CityBlueBuildingStack folder, create a
Material Modifier and rename it
Create a new custom material so you can distinguish the buildings in this stack:
- Right-click on your CityBlueBuildingStack folder and create a new material called
- From the topmost color picker in the
CityBlueBuildingMaterialinspector window, choose a shade of blue for your material.
- In the
CityBuildingMaterialModifierclick Add New Empty.
- Click Submesh 0 Material
- Change the Size to 1.
- Add your
- Click Add New Empty to add Submesh 1 Material
Finally, add your new texture modifier to your merged modifier stack:
- Select your
- Under Game Object Modifiers select Add New Empty.
- Find and select your
At this point, your buildings are almost ready to visualize! To apply the blue color you created above to the schools in your scene, add the
CityBlueMergedBuildingStack to your
- In the
CityBuildingLayerVisualizerinspector window, select Add New Empty under Stacks.
schoolin the empty field.
CityBlueBuildingStackto the Stack field.
Click play to see all the schools in your scene displayed as blue buildings.
Map Editor from the Unity Editor at the top to show then the configurations that you have made. Make sure yours match the screenshot.
You built a scene that visualizes map tiles draped over a 3D elevation model, then you added 3D buildings and created a special style for all the schools in your scene.
On your own, try:
- Using some different materials for the top and side of your buildings.
- Using a
HeightFilterto filter all the buildings below a given height.
Want to keep working? Read the Mapbox Maps SDK for Unity documentation to keep building.