Last active
September 3, 2018 05:15
-
-
Save rockarts/c3122d244d19ed6a3db686d2c3e66de7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Valley of the 10 Peaks | |
| //NE & SW Corners | |
| var minLat = 51.20 | |
| var minLon = -116.28 | |
| var maxLat = 51.32 | |
| var maxLon = -116.12 | |
| var terrainNode: TerrainNode? | |
| var terrainNodeScale = SCNVector3(0.0003, 0.0003, 0.0003) // Scale down map (otherwise it's far too big) | |
| func createTerrain() { | |
| terrainNode = TerrainNode(minLat: minLat, maxLat: maxLat, | |
| minLon: minLon, maxLon: maxLon) | |
| if let terrainNode = terrainNode { | |
| terrainNode.scale = terrainNodeScale // Scale down map | |
| terrainNode.geometry?.materials = defaultMaterials() | |
| scene.rootNode.addChildNode(terrainNode) | |
| //create terrain geometry based on mapbox elevation data | |
| terrainNode.fetchTerrainHeights(minWallHeight: 100.0, enableDynamicShadows: true, progress: { progress, total in }, completion: { | |
| NSLog("Terrain load complete") | |
| }) | |
| terrainNode.fetchTerrainTexture("mapbox/satellite-v9", progress: { progress, total in }, completion: { image in | |
| NSLog("Texture load complete") | |
| //apply the satellite image to the terrain mesh | |
| terrainNode.geometry?.materials[4].diffuse.contents = image | |
| }) | |
| } | |
| } | |
| // Create default materials for each side of the terrain node | |
| func defaultMaterials() -> [SCNMaterial] { | |
| let groundImage = SCNMaterial() | |
| groundImage.diffuse.contents = UIColor.darkGray | |
| groundImage.name = "Ground texture" | |
| let sideMaterial = SCNMaterial() | |
| sideMaterial.diffuse.contents = UIColor.darkGray | |
| sideMaterial.isDoubleSided = true | |
| sideMaterial.name = "Side" | |
| let bottomMaterial = SCNMaterial() | |
| bottomMaterial.diffuse.contents = UIColor.black | |
| bottomMaterial.name = "Bottom" | |
| return [sideMaterial, sideMaterial, sideMaterial, sideMaterial, groundImage, bottomMaterial] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment