├── Example scenes ├── CubeScene.swift └── Houses │ ├── Box.swift │ ├── Car model │ ├── Car.png │ ├── Car1.mtl │ └── Car1.obj │ ├── House models │ ├── House.png │ ├── House1.mtl │ ├── House1.obj │ ├── House2.mtl │ ├── House2.obj │ ├── House3.mtl │ ├── House3.obj │ ├── House4.mtl │ ├── House4.obj │ ├── House5.mtl │ ├── House5.obj │ ├── House6.mtl │ └── House6.obj │ ├── House.swift │ ├── HouseScene.swift │ └── Road.swift ├── Hg2DGeometry.swift ├── HgGraph.swift ├── HgIO.swift ├── HgLightNode.swift ├── HgMath.swift ├── HgNode.swift ├── HgRenderer.swift ├── HgScene.swift ├── HgSkyboxNode.swift ├── IOSMercury ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── BasicCar.mtl ├── BasicCar.obj ├── BigHouse.mtl ├── BigHouse.obj ├── HgIOSViewController.swift └── Info.plist ├── Mercury.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── OSXMercury ├── AppDelegate.swift ├── Base.lproj │ └── MainMenu.xib ├── HgOSXViewController.swift └── Info.plist ├── README.md ├── Screen.Shot.2016-02-29.at.7.51.18.PM.png ├── Screen.Shot.2016-02-29.at.7.52.07.PM.png ├── Screen.Shot.2016-02-29.at.8.01.20.PM.png ├── Shaders ├── Composition.metal ├── GBuffer.metal ├── Light.metal ├── Post.metal ├── Skybox.metal └── ZOnly.metal └── skybox.png /Example scenes/CubeScene.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CubeScene.swift 3 | // IOSMercury 4 | // 5 | // Created by Joshua Knapp on 7/8/17. 6 | // 7 | 8 | import Foundation 9 | import simd 10 | 11 | class CubeScene: HgScene { 12 | 13 | override func run(){ 14 | 15 | position = float3(0,0,500) 16 | //rotation = float3(.pi, 0, 0) 17 | //magnification = 0.1 18 | let box = Box(x:100, y:100, z:100) 19 | addChild(box) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Example scenes/Houses/Box.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Box.swift 3 | // Mercury 4 | // 5 | // Created by Joshua Knapp on 2/25/16. 6 | // 7 | // 8 | 9 | import Foundation 10 | 11 | //HgNode subclass that describes a box with no bottom 12 | 13 | class Box:HgNode { 14 | 15 | 16 | init(x: Float, y: Float, z: Float) { 17 | 18 | 19 | super.init() 20 | defer { self.updateVertexBuffer() } 21 | vertexData = Array(repeating: vertex(), count: 30) 22 | 23 | //up face 24 | vertexData[0].position = ( x / 2, y / 2, z / 2) 25 | vertexData[1].position = ( -x / 2, y / 2, z / 2) 26 | vertexData[2].position = ( -x / 2, -y / 2, z / 2) 27 | vertexData[3].position = vertexData[2].position 28 | vertexData[4].position = ( x / 2, -y / 2, z / 2) 29 | vertexData[5].position = vertexData[0].position 30 | 31 | for i in 0..<6 { 32 | vertexData[i].normal = (0,0,1) 33 | } 34 | 35 | //south face 36 | vertexData[6].position = ( x / 2, -y / 2, z / 2) 37 | vertexData[7].position = ( -x / 2, -y / 2, z / 2) 38 | vertexData[8].position = ( -x / 2, -y / 2, -z / 2) 39 | vertexData[9].position = vertexData[8].position 40 | vertexData[10].position = ( x / 2, -y / 2, -z / 2) 41 | vertexData[11].position = vertexData[6].position 42 | 43 | for i in 6..<12 { 44 | vertexData[i].normal = (0,-1,0) 45 | } 46 | 47 | //north face 48 | vertexData[12].position = ( -x / 2, y / 2, z / 2) 49 | vertexData[13].position = ( x / 2, y / 2, z / 2) 50 | vertexData[14].position = ( x / 2, y / 2, -z / 2) 51 | vertexData[15].position = vertexData[14].position 52 | vertexData[16].position = ( -x / 2, y / 2, -z / 2) 53 | vertexData[17].position = vertexData[12].position 54 | 55 | for i in 12..<18 { 56 | vertexData[i].normal = (0,1,0) 57 | } 58 | 59 | //east face 60 | vertexData[18].position = ( x / 2, y / 2, z / 2) 61 | vertexData[19].position = ( x / 2, -y / 2, z / 2) 62 | vertexData[20].position = ( x / 2, -y / 2, -z / 2) 63 | vertexData[21].position = vertexData[20].position 64 | vertexData[22].position = ( x / 2, y / 2, -z / 2) 65 | vertexData[23].position = vertexData[18].position 66 | 67 | for i in 18..<24 { 68 | vertexData[i].normal = (1,0,0) 69 | } 70 | 71 | //west face 72 | vertexData[24].position = ( -x / 2, -y / 2, z / 2) 73 | vertexData[25].position = ( -x / 2, y / 2, z / 2) 74 | vertexData[26].position = ( -x / 2, y / 2, -z / 2) 75 | vertexData[27].position = vertexData[26].position 76 | vertexData[28].position = ( -x / 2, -y / 2, -z / 2) 77 | vertexData[29].position = vertexData[24].position 78 | 79 | for i in 24..<30 { 80 | vertexData[i].normal = (-1,0,0) 81 | } 82 | 83 | vertexCount = 30 84 | } 85 | 86 | 87 | } 88 | -------------------------------------------------------------------------------- /Example scenes/Houses/Car model/Car.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sntwo/Mercury/d4d2c41c0847957481c6006f7d190907ab300136/Example scenes/Houses/Car model/Car.png -------------------------------------------------------------------------------- /Example scenes/Houses/Car model/Car1.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'BasicCar.blend' 2 | # Material Count: 3 3 | 4 | newmtl Material.001 5 | Ns 96.078431 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.640000 0.640000 0.640000 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.000000 11 | d 1.000000 12 | illum 2 13 | 14 | newmtl Material.002 15 | Ns 96.078431 16 | Ka 1.000000 1.000000 1.000000 17 | Kd 0.640000 0.640000 0.640000 18 | Ks 0.500000 0.500000 0.500000 19 | Ke 0.000000 0.000000 0.000000 20 | Ni 1.000000 21 | d 1.000000 22 | illum 2 23 | 24 | newmtl Material.004 25 | Ns 96.078431 26 | Ka 1.000000 1.000000 1.000000 27 | Kd 0.640000 0.640000 0.640000 28 | Ks 0.500000 0.500000 0.500000 29 | Ke 0.000000 0.000000 0.000000 30 | Ni 1.000000 31 | d 1.000000 32 | illum 2 33 | -------------------------------------------------------------------------------- /Example scenes/Houses/House models/House.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sntwo/Mercury/d4d2c41c0847957481c6006f7d190907ab300136/Example scenes/Houses/House models/House.png -------------------------------------------------------------------------------- /Example scenes/Houses/House models/House1.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'BigHouse.blend' 2 | # Material Count: 1 3 | 4 | newmtl Material.001 5 | Ns 96.078431 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.640000 0.640000 0.640000 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.000000 11 | d 1.000000 12 | illum 2 13 | -------------------------------------------------------------------------------- /Example scenes/Houses/House models/House2.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'House.blend' 2 | # Material Count: 1 3 | 4 | newmtl Material.001 5 | Ns 96.078431 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.640000 0.640000 0.640000 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.000000 11 | d 1.000000 12 | illum 2 13 | -------------------------------------------------------------------------------- /Example scenes/Houses/House models/House3.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'HouseWithFlatRoof.blend' 2 | # Material Count: 1 3 | 4 | newmtl Material.001 5 | Ns 96.078431 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.640000 0.640000 0.640000 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.000000 11 | d 1.000000 12 | illum 2 13 | -------------------------------------------------------------------------------- /Example scenes/Houses/House models/House4.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'MediumHouse.blend' 2 | # Material Count: 1 3 | 4 | newmtl Material.001 5 | Ns 96.078431 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.640000 0.640000 0.640000 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.000000 11 | d 1.000000 12 | illum 2 13 | -------------------------------------------------------------------------------- /Example scenes/Houses/House models/House4.obj: -------------------------------------------------------------------------------- 1 | # Blender v2.78 (sub 0) OBJ File: 'MediumHouse.blend' 2 | # www.blender.org 3 | mtllib House4.mtl 4 | o Cube 5 | v -0.825028 1.695846 3.368628 6 | v -0.825028 2.081764 3.368628 7 | v -0.825028 1.695846 2.982710 8 | v -0.825028 2.081764 2.982710 9 | v -0.439110 1.695846 3.368628 10 | v -0.439110 2.081764 3.368628 11 | v -0.439110 1.695846 2.982710 12 | v -0.439110 2.081764 2.982710 13 | v -0.868448 2.050842 3.412048 14 | v -0.868448 2.050842 2.939290 15 | v -0.395690 2.050842 2.939290 16 | v -0.395690 2.050842 3.412048 17 | v -0.868448 2.387519 3.412048 18 | v -0.868448 2.387519 2.939290 19 | v -0.395690 2.387519 2.939290 20 | v -0.395690 2.387519 3.412048 21 | v -0.816945 2.387519 3.360544 22 | v -0.816945 2.387519 2.990793 23 | v -0.447194 2.387519 2.990794 24 | v -0.447194 2.387519 3.360544 25 | v -0.816945 2.092364 3.360544 26 | v -0.816945 2.092364 2.990793 27 | v -0.447194 2.092364 2.990794 28 | v -0.447194 2.092364 3.360544 29 | v -1.000000 -0.040325 1.000000 30 | v -1.000000 -0.040325 1.000000 31 | v -1.000000 -0.040325 1.000000 32 | v -1.000000 -0.040325 1.000000 33 | v -1.000000 1.483531 0.999999 34 | v -1.000000 -0.040325 -0.000000 35 | v -1.000002 -0.040325 3.791640 36 | v -0.000000 -0.040325 1.000000 37 | v -1.000000 1.483531 0.999999 38 | v -1.000000 1.483531 -0.000000 39 | v -1.000000 -0.040325 -0.000000 40 | v 0.000000 -0.040325 -0.000000 41 | v -1.000002 -0.040325 3.791640 42 | v -0.000000 -0.040325 1.000000 43 | v -0.000002 -0.040325 3.791640 44 | v -1.000001 0.282630 2.516018 45 | v -1.000001 0.282630 2.310675 46 | v -1.000000 0.282630 1.325918 47 | v -1.000001 0.965223 1.325918 48 | v -1.000002 0.282630 3.500775 49 | v -1.000000 1.483531 0.999999 50 | v -1.000000 1.483531 -0.000000 51 | v -1.000000 1.483531 -1.000000 52 | v -0.999999 -0.040325 -1.000000 53 | v -0.999999 -0.040325 -1.000000 54 | v 0.000000 -0.040325 -1.000000 55 | v 1.000000 -0.040325 0.000000 56 | v 1.000000 -0.040325 1.000000 57 | v -1.000002 1.483531 3.791640 58 | v 1.000000 -0.040325 1.000000 59 | v 0.999999 -0.040325 3.791640 60 | v -0.000002 0.296634 3.791640 61 | v -0.484150 0.296634 3.791639 62 | v -0.484150 0.979228 3.791640 63 | v -0.000002 0.979228 3.791640 64 | v -0.000002 1.939016 3.791640 65 | v -1.000002 1.483531 3.791640 66 | v -0.960515 0.282630 3.500775 67 | v -0.960514 0.282630 2.516018 68 | v -1.000001 0.965223 2.516018 69 | v -1.000002 0.965223 3.500775 70 | v -1.000001 0.965223 2.310675 71 | v -0.960514 0.282630 2.310675 72 | v -0.960514 0.282630 1.325918 73 | v -0.960514 0.965223 1.325918 74 | v -1.000000 1.483531 0.999999 75 | v -1.000000 1.483531 -1.000000 76 | v -0.999999 -0.040325 -1.000000 77 | v 0.000000 -0.040325 -1.000000 78 | v 1.000000 -0.040325 -1.000000 79 | v 1.000000 -0.040325 0.000000 80 | v 0.999999 -0.040325 3.791640 81 | v 0.999998 1.483531 3.791641 82 | v 0.500608 0.979228 3.791640 83 | v 0.500608 0.296634 3.791640 84 | v -0.960514 0.965223 2.516018 85 | v -0.960515 0.965223 3.500775 86 | v -0.960514 0.965223 2.310675 87 | v -0.999999 -0.040325 -1.000000 88 | v -1.000000 1.483531 -1.000000 89 | v -1.000000 1.483531 -1.000000 90 | v 1.000000 -0.040325 -1.000000 91 | v 1.000000 -0.040325 1.000000 92 | v 1.000000 -0.040325 1.000000 93 | v 1.000001 -0.040325 -1.972457 94 | v 1.000000 -0.040325 -1.000000 95 | v 2.502374 -0.040325 0.000001 96 | v 2.502374 -0.040325 0.301709 97 | v 2.539414 -0.040325 0.301709 98 | v 2.539414 -0.040325 1.000001 99 | v 2.539415 -0.040325 -0.999999 100 | v 2.539414 -0.040325 -0.303765 101 | v 2.502374 -0.040325 -0.303765 102 | v 0.999999 0.282630 2.516019 103 | v 0.999999 0.282630 3.500776 104 | v 0.999999 1.483531 1.000001 105 | v 0.999999 0.965223 1.325919 106 | v 1.000000 0.282630 1.325919 107 | v 0.999999 0.282630 2.310676 108 | v 0.999998 1.483531 3.791641 109 | v 2.539415 -0.040325 -0.999999 110 | v 2.502374 0.847709 0.301709 111 | v 2.502374 0.847709 -0.303765 112 | v 2.539414 0.847709 0.301709 113 | v 2.539414 0.847709 0.000001 114 | v 2.539414 1.964027 0.000001 115 | v 2.539413 1.483531 1.000001 116 | v 2.539415 1.483531 -0.999999 117 | v 2.539414 0.847709 -0.303765 118 | v 0.999999 0.965223 2.310676 119 | v 0.999998 0.965223 3.500776 120 | v 0.999999 0.965223 2.516019 121 | v 0.946484 0.282630 2.516019 122 | v 0.946484 0.282630 3.500776 123 | v 2.539414 -0.040325 1.000001 124 | v 2.539413 1.483531 1.000002 125 | v 0.946485 0.965223 1.325918 126 | v 0.946485 0.282630 1.325918 127 | v 0.946484 0.282630 2.310676 128 | v 0.999999 1.483531 1.000001 129 | v 1.000001 1.483531 -0.999999 130 | v 2.539415 1.483531 -0.999999 131 | v 0.946484 0.965223 2.516019 132 | v 0.946484 0.965223 2.310676 133 | v 0.946484 0.965223 3.500776 134 | v 0.999999 1.483531 1.000001 135 | v 1.000001 1.483531 -0.999999 136 | v 1.000001 1.483531 -0.999999 137 | v 0.999999 1.483531 1.000001 138 | v 1.000001 1.483531 -0.999999 139 | v 1.000000 1.590579 0.000001 140 | v 1.018124 1.521507 -0.044256 141 | v 0.000000 1.910402 -0.000000 142 | v -0.000000 1.910402 1.045419 143 | v -1.045420 1.445334 1.045419 144 | v -1.045419 1.448997 -0.000000 145 | v 1.045419 1.910402 0.000000 146 | v -0.000002 1.910402 3.963853 147 | v -1.045421 1.445334 3.963853 148 | v 0.000000 1.910402 -1.045419 149 | v -1.045420 1.677060 1.045419 150 | v -1.045419 1.680723 -0.000000 151 | v 1.045419 1.445334 1.045419 152 | v 1.045419 1.445334 -1.045419 153 | v -1.045421 1.677059 3.963853 154 | v 1.045418 1.445334 3.963854 155 | v -0.000002 2.142128 3.963854 156 | v -1.045419 1.445334 -1.045420 157 | v -0.000000 2.142128 0.000000 158 | v -1.045419 1.677060 -1.045419 159 | v 2.654753 1.910402 0.000001 160 | v 2.654752 1.445334 1.045420 161 | v 2.654753 1.445334 -1.045418 162 | v -0.000001 2.142128 1.045419 163 | v 1.045418 1.677060 1.045420 164 | v 1.045417 1.677059 3.963854 165 | v 2.654752 1.677060 1.045421 166 | v 2.654753 2.142128 0.000001 167 | v 1.045420 1.677060 -1.045418 168 | v 2.654753 1.677060 -1.045418 169 | v 0.000000 2.142128 -1.045419 170 | v 1.045419 2.142128 0.000001 171 | v -0.484150 0.979228 3.743136 172 | v -0.484150 0.296634 3.743136 173 | v 0.500608 0.296634 3.743136 174 | v 0.500608 0.979228 3.743136 175 | v -1.045419 1.445635 -0.959605 176 | v 0.000000 1.910402 -0.959605 177 | v 1.045419 1.483510 -0.959605 178 | v -1.045419 1.677360 -0.959605 179 | v 2.654753 1.715235 -0.959603 180 | v 2.654753 1.483510 -0.959604 181 | v 1.045420 1.715235 -0.959604 182 | v 0.000000 -0.040325 -1.000000 183 | vt 0.1462 0.8538 184 | vt 0.0163 0.9837 185 | vt 0.0163 0.8538 186 | vt 0.1462 0.8538 187 | vt 0.0163 0.9837 188 | vt 0.0163 0.8538 189 | vt 0.1462 0.8538 190 | vt 0.0163 0.9837 191 | vt 0.0163 0.8538 192 | vt 0.1462 0.8538 193 | vt 0.0163 0.9837 194 | vt 0.0163 0.8538 195 | vt 0.0163 0.8538 196 | vt 0.1462 0.9837 197 | vt 0.0163 0.9837 198 | vt 0.1462 0.8538 199 | vt 0.0163 0.9837 200 | vt 0.0163 0.8538 201 | vt 0.0163 0.9837 202 | vt 0.0163 0.9837 203 | vt 0.1462 0.9837 204 | vt 0.0163 0.9837 205 | vt 0.0163 0.8538 206 | vt 0.1462 0.9837 207 | vt 0.0163 0.9837 208 | vt 0.1462 0.8538 209 | vt 0.0163 0.9837 210 | vt 0.0163 0.8538 211 | vt 0.1462 0.8538 212 | vt 0.0163 0.9837 213 | vt 0.0163 0.8538 214 | vt 0.1462 0.8538 215 | vt 0.0163 0.9837 216 | vt 0.0163 0.8538 217 | vt 0.1462 0.8538 218 | vt 0.0163 0.9837 219 | vt 0.0163 0.8538 220 | vt 0.0163 0.8538 221 | vt 0.1462 0.9837 222 | vt 0.0163 0.9837 223 | vt 0.1462 0.8538 224 | vt 0.0163 0.9837 225 | vt 0.0163 0.8538 226 | vt 0.1462 0.8538 227 | vt 0.0163 0.9837 228 | vt 0.0163 0.8538 229 | vt 0.1462 0.8538 230 | vt 0.0163 0.9837 231 | vt 0.0163 0.8538 232 | vt 0.1462 0.8538 233 | vt 0.0163 0.9837 234 | vt 0.0163 0.8538 235 | vt 0.1462 0.8538 236 | vt 0.0163 0.8538 237 | vt 0.1462 0.8538 238 | vt 0.0163 0.9837 239 | vt 0.0163 0.8538 240 | vt 0.0813 0.8799 241 | vt 0.0816 0.8802 242 | vt 0.0812 0.8796 243 | vt 0.0838 0.8539 244 | vt 0.0846 0.8538 245 | vt 0.0819 0.8799 246 | vt 0.0973 0.8831 247 | vt 0.0970 0.8829 248 | vt 0.0484 0.8756 249 | vt 0.0798 0.8931 250 | vt 0.0798 0.8933 251 | vt 0.0930 0.8958 252 | vt 0.0459 0.8844 253 | vt 0.0491 0.8748 254 | vt 0.0767 0.8741 255 | vt 0.0629 0.8731 256 | vt 0.0842 0.8539 257 | vt 0.0846 0.8538 258 | vt 0.1039 0.8571 259 | vt 0.1039 0.8571 260 | vt 0.1107 0.8881 261 | vt 0.1105 0.8879 262 | vt 0.1053 0.8998 263 | vt 0.0899 0.9071 264 | vt 0.0375 0.8620 265 | vt 0.0395 0.8616 266 | vt 0.0771 0.9063 267 | vt 0.0374 0.8732 268 | vt 0.0503 0.8726 269 | vt 0.0586 0.8720 270 | vt 0.0596 0.8730 271 | vt 0.0777 0.8625 272 | vt 0.0611 0.8636 273 | vt 0.0766 0.8735 274 | vt 0.0771 0.8630 275 | vt 0.1256 0.8657 276 | vt 0.1106 0.8881 277 | vt 0.1057 0.8993 278 | vt 0.0998 0.9110 279 | vt 0.0801 0.9064 280 | vt 0.0781 0.9062 281 | vt 0.0427 0.8944 282 | vt 0.0772 0.9070 283 | vt 0.0422 0.8916 284 | vt 0.0291 0.8884 285 | vt 0.0395 0.8889 286 | vt 0.0556 0.8655 287 | vt 0.0546 0.8652 288 | vt 0.0485 0.8663 289 | vt 0.0501 0.8726 290 | vt 0.9299 0.1770 291 | vt 0.9278 0.1759 292 | vt 0.9292 0.1756 293 | vt 0.0487 0.8669 294 | vt 0.0618 0.8636 295 | vt 0.0628 0.8731 296 | vt 0.9337 0.1773 297 | vt 0.9305 0.1752 298 | vt 0.9338 0.1751 299 | vt 0.1262 0.8662 300 | vt 0.1266 0.8665 301 | vt 0.0901 0.9065 302 | vt 0.0869 0.9143 303 | vt 0.0919 0.9156 304 | vt 0.0892 0.9146 305 | vt 0.0889 0.9145 306 | vt 0.0570 0.9017 307 | vt 0.0163 0.8988 308 | vt 0.1002 0.9126 309 | vt 0.0989 0.9109 310 | vt 0.0854 0.9128 311 | vt 0.0515 0.1356 312 | vt 0.0523 0.1355 313 | vt 0.0512 0.1373 314 | vt 0.0869 0.9142 315 | vt 0.0863 0.9176 316 | vt 0.0863 0.9177 317 | vt 0.0831 0.9199 318 | vt 0.0843 0.9138 319 | vt 0.0865 0.9218 320 | vt 0.0873 0.9179 321 | vt 0.0884 0.9181 322 | vt 0.0884 0.9180 323 | vt 0.0740 0.9236 324 | vt 0.0507 0.9094 325 | vt 0.0537 0.9004 326 | vt 0.0404 0.8936 327 | vt 0.0408 0.8947 328 | vt 0.0838 0.9212 329 | vt 0.0699 0.9156 330 | vt 0.0711 0.9074 331 | vt 0.0714 0.9079 332 | vt 0.0572 0.9016 333 | vt 0.0175 0.8966 334 | vt 0.0979 0.9265 335 | vt 0.0914 0.9144 336 | vt 0.0904 0.9212 337 | vt 0.0898 0.9220 338 | vt 0.0485 0.9091 339 | vt 0.0528 0.9006 340 | vt 0.0522 0.9099 341 | vt 0.0685 0.9157 342 | vt 0.0302 0.8980 343 | vt 0.0323 0.8993 344 | vt 0.0475 0.9089 345 | vt 0.9260 0.1815 346 | vt 0.9275 0.1848 347 | vt 0.9243 0.1827 348 | vt 0.0760 0.9247 349 | vt 0.9296 0.1832 350 | vt 0.9319 0.1862 351 | vt 0.9285 0.1850 352 | vt 0.0753 0.9244 353 | vt 0.0746 0.9240 354 | vt 0.0949 0.9274 355 | vt 0.0961 0.9270 356 | vt 0.0856 0.9296 357 | vt 0.0853 0.9289 358 | vt 0.0955 0.9272 359 | vt 0.9378 0.0736 360 | vt 0.9255 0.0822 361 | vt 0.9315 0.0702 362 | vt 0.0440 0.8778 363 | vt 0.0369 0.8742 364 | vt 0.0338 0.8814 365 | vt 0.0303 0.8875 366 | vt 0.0393 0.8892 367 | vt 0.0420 0.8832 368 | vt 0.9327 0.9215 369 | vt 0.9272 0.9160 370 | vt 0.9327 0.9160 371 | vt 0.1462 0.8538 372 | vt 0.0163 0.9837 373 | vt 0.0163 0.8538 374 | vt 0.9272 0.9215 375 | vt 0.9327 0.9160 376 | vt 0.9327 0.9215 377 | vt 0.8883 0.9270 378 | vt 0.9016 0.9229 379 | vt 0.9016 0.9240 380 | vt 0.8952 0.9203 381 | vt 0.8961 0.9195 382 | vt 0.8961 0.9203 383 | vt 0.9148 0.9270 384 | vt 0.9151 0.9260 385 | vt 0.8952 0.9203 386 | vt 0.8961 0.9195 387 | vt 0.8961 0.9203 388 | vt 0.9272 0.9215 389 | vt 0.9327 0.9160 390 | vt 0.8961 0.9203 391 | vt 0.8952 0.9195 392 | vt 0.8961 0.9195 393 | vt 0.8961 0.9203 394 | vt 0.8952 0.9203 395 | vt 0.8952 0.9195 396 | vt 0.8961 0.9199 397 | vt 0.8952 0.9195 398 | vt 0.8961 0.9195 399 | vt 0.9015 0.9043 400 | vt 0.9146 0.9174 401 | vt 0.9015 0.9174 402 | vt 0.9146 0.9043 403 | vt 0.9081 0.9174 404 | vt 0.9081 0.9043 405 | vt 0.8961 0.9203 406 | vt 0.8961 0.9195 407 | vt 0.8952 0.9203 408 | vt 0.8961 0.9195 409 | vt 0.8961 0.9203 410 | vt 0.8952 0.9203 411 | vt 0.8961 0.9195 412 | vt 0.8961 0.9203 413 | vt 0.8952 0.9203 414 | vt 0.8957 0.9203 415 | vt 0.8952 0.9195 416 | vt 0.8961 0.9203 417 | vt 0.8952 0.9203 418 | vt 0.8961 0.9195 419 | vt 0.8961 0.9203 420 | vt 0.8961 0.9203 421 | vt 0.8952 0.9195 422 | vt 0.8961 0.9195 423 | vt 0.8952 0.9203 424 | vt 0.8961 0.9195 425 | vt 0.8961 0.9203 426 | vt 0.8952 0.9199 427 | vt 0.8961 0.9195 428 | vt 0.8961 0.9199 429 | vt 0.8952 0.9195 430 | vt 0.8961 0.9195 431 | vt 0.8952 0.9203 432 | vt 0.8952 0.9195 433 | vt 0.8961 0.9203 434 | vt 0.8952 0.9203 435 | vt 0.8961 0.9203 436 | vt 0.8961 0.9195 437 | vt 0.8957 0.9203 438 | vt 0.8952 0.9195 439 | vt 0.8957 0.9195 440 | vt 0.8961 0.9203 441 | vt 0.8952 0.9203 442 | vt 0.9147 0.9236 443 | vt 0.8885 0.9237 444 | vt 0.8881 0.9261 445 | vt 0.1109 0.8880 446 | vt 0.8961 0.9195 447 | vt 0.8952 0.9203 448 | vt 0.8961 0.9203 449 | vt 0.9015 0.9043 450 | vt 0.9015 0.9174 451 | vt 0.8961 0.9203 452 | vt 0.8952 0.9199 453 | vt 0.9327 0.9215 454 | vt 0.9272 0.9187 455 | vt 0.9327 0.9187 456 | vt 0.9272 0.9215 457 | vt 0.9327 0.9187 458 | vt 0.9327 0.9215 459 | vt 0.0636 0.9385 460 | vt 0.0511 0.9194 461 | vt 0.0636 0.9194 462 | vt 0.0762 0.9194 463 | vt 0.0762 0.9385 464 | vt 0.1462 0.9837 465 | vt 0.1462 0.9837 466 | vt 0.1462 0.9837 467 | vt 0.1462 0.8538 468 | vt 0.1462 0.9837 469 | vt 0.1462 0.9837 470 | vt 0.1462 0.9837 471 | vt 0.1462 0.9837 472 | vt 0.1462 0.8538 473 | vt 0.1462 0.9837 474 | vt 0.1462 0.9837 475 | vt 0.1462 0.9837 476 | vt 0.1462 0.9837 477 | vt 0.1462 0.8538 478 | vt 0.1462 0.9837 479 | vt 0.1462 0.9837 480 | vt 0.1462 0.9837 481 | vt 0.1462 0.9837 482 | vt 0.1462 0.9837 483 | vt 0.0181 0.8729 484 | vt 0.9281 0.1771 485 | vt 0.9307 0.1772 486 | vt 0.1264 0.8664 487 | vt 0.0884 0.9141 488 | vt 0.0523 0.1375 489 | vt 0.0525 0.1357 490 | vt 0.9286 0.1830 491 | vt 0.9325 0.1845 492 | vt 0.9336 0.0837 493 | vt 0.0440 0.8779 494 | vt 0.9272 0.9215 495 | vt 0.1462 0.9837 496 | vt 0.9272 0.9160 497 | vt 0.8952 0.9195 498 | vt 0.8952 0.9195 499 | vt 0.9272 0.9160 500 | vt 0.8952 0.9203 501 | vt 0.9146 0.9043 502 | vt 0.9146 0.9174 503 | vt 0.8952 0.9195 504 | vt 0.8952 0.9195 505 | vt 0.8952 0.9203 506 | vt 0.8952 0.9195 507 | vt 0.8952 0.9203 508 | vt 0.9016 0.9202 509 | vt 0.9272 0.9215 510 | vt 0.9272 0.9187 511 | vt 0.0511 0.9385 512 | vn -1.0000 0.0000 -0.0000 513 | vn 0.0000 0.0000 -1.0000 514 | vn 1.0000 0.0000 0.0000 515 | vn -0.0000 0.0000 1.0000 516 | vn 0.0000 -1.0000 -0.0000 517 | vn -0.5801 -0.8146 0.0000 518 | vn 0.5801 -0.8146 0.0000 519 | vn 0.0000 -0.8146 -0.5801 520 | vn 0.0000 -0.8146 0.5801 521 | vn 0.0000 1.0000 0.0000 522 | vn -0.9708 -0.2384 -0.0255 523 | vn -0.9621 -0.2710 0.0290 524 | vn 0.4038 -0.9149 -0.0000 525 | vn 0.4065 -0.9137 0.0000 526 | vn 0.4062 -0.9138 0.0000 527 | vn -0.3765 -0.8464 0.3765 528 | vn -0.4065 -0.9137 -0.0000 529 | vn -0.4038 0.9149 0.0032 530 | vn 0.0000 -0.9137 -0.4065 531 | vn -0.0000 -0.9137 0.4065 532 | vn -0.4065 0.9137 -0.0000 533 | vn -0.4038 0.9149 -0.0032 534 | vn 0.4065 0.9137 0.0000 535 | vn -0.0000 0.9137 0.4065 536 | vn 0.0000 0.9137 -0.4065 537 | vn -0.3496 -0.8560 0.3808 538 | vn 0.0315 0.0207 -0.9993 539 | vn 0.4065 -0.9137 -0.0032 540 | vn -0.3765 -0.8464 -0.3765 541 | vn 0.4065 -0.9137 0.0032 542 | vn -0.3780 -0.9258 -0.0000 543 | vn 0.4062 -0.9138 0.0032 544 | vn -0.0315 0.0207 -0.9993 545 | usemtl Material.001 546 | s off 547 | f 4/1/1 1/2/1 2/3/1 548 | f 8/4/2 3/5/2 4/6/2 549 | f 6/7/3 7/8/3 8/9/3 550 | f 2/10/4 5/11/4 6/12/4 551 | f 1/13/5 7/14/5 5/11/5 552 | f 8/4/6 12/15/6 6/12/6 553 | f 10/16/2 15/17/2 11/18/2 554 | f 2/10/7 10/19/7 4/6/7 555 | f 6/7/8 9/20/8 2/3/8 556 | f 8/9/9 10/21/9 11/22/9 557 | f 13/23/10 20/24/10 17/25/10 558 | f 11/26/3 16/27/3 12/28/3 559 | f 9/29/1 14/30/1 10/31/1 560 | f 12/32/4 13/33/4 9/34/4 561 | f 19/35/1 24/36/1 20/37/1 562 | f 15/38/10 18/39/10 19/40/10 563 | f 15/41/10 20/42/10 16/43/10 564 | f 13/44/10 18/45/10 14/46/10 565 | f 23/47/10 21/48/10 24/49/10 566 | f 17/50/3 22/51/3 18/52/3 567 | f 20/53/2 21/48/2 17/54/2 568 | f 18/55/4 23/56/4 19/57/4 569 | f 26/58/4 28/59/4 25/60/4 570 | f 26/58/4 33/61/4 29/62/4 571 | f 27/63/4 35/64/4 30/65/4 572 | f 28/59/4 37/66/4 25/60/4 573 | f 27/63/4 38/67/4 28/59/4 574 | f 29/62/1 35/64/1 26/58/1 575 | f 32/68/5 30/65/5 36/69/5 576 | f 28/59/5 39/70/5 31/71/5 577 | f 42/72/1 25/60/1 41/73/1 578 | f 29/62/4 70/74/4 45/75/4 579 | f 34/76/4 45/75/4 46/77/4 580 | f 30/65/4 48/78/4 49/79/4 581 | f 50/80/5 30/65/5 49/79/5 582 | f 51/81/5 32/68/5 36/69/5 583 | f 37/66/4 61/82/4 53/83/4 584 | f 54/84/5 39/70/5 38/67/5 585 | f 58/85/4 61/82/4 31/71/4 586 | f 32/68/4 54/84/4 38/67/4 587 | f 44/86/10 63/87/10 40/88/10 588 | f 33/61/1 43/89/1 66/90/1 589 | f 41/73/10 68/91/10 42/72/10 590 | f 42/72/4 69/92/4 43/89/4 591 | f 46/77/4 47/93/4 34/76/4 592 | f 34/76/1 48/78/1 35/64/1 593 | f 50/80/4 83/94/4 73/95/4 594 | f 74/96/5 36/69/5 50/80/5 595 | f 51/81/4 87/97/4 52/98/4 596 | f 55/99/4 88/100/4 76/101/4 597 | f 55/99/4 78/102/4 79/103/4 598 | f 40/88/4 80/104/4 64/105/4 599 | f 65/106/2 62/107/2 44/86/2 600 | f 63/108/1 81/109/1 80/110/1 601 | f 64/105/5 81/111/5 65/106/5 602 | f 33/61/4 61/82/4 70/74/4 603 | f 43/89/5 82/112/5 66/90/5 604 | f 66/90/2 67/113/2 41/73/2 605 | f 68/114/1 82/115/1 69/116/1 606 | f 71/117/4 85/118/4 47/93/4 607 | f 74/96/4 75/119/4 51/81/4 608 | f 75/119/5 92/120/5 87/97/5 609 | f 95/121/5 96/122/5 97/123/5 610 | f 88/100/4 52/98/4 87/97/4 611 | f 76/101/3 88/100/3 103/124/3 612 | f 104/125/4 55/99/4 76/101/4 613 | f 90/126/4 95/121/4 86/127/4 614 | f 87/97/4 119/128/4 88/100/4 615 | f 92/129/3 91/130/3 106/131/3 616 | f 93/132/2 106/133/2 108/134/2 617 | f 111/135/3 94/136/3 108/134/3 618 | f 110/137/3 109/138/3 113/139/3 619 | f 97/123/4 113/139/4 107/140/4 620 | f 100/141/3 104/125/3 114/142/3 621 | f 98/143/10 118/144/10 99/145/10 622 | f 88/100/4 120/146/4 100/141/4 623 | f 101/147/4 122/148/4 102/149/4 624 | f 102/149/10 123/150/10 103/124/10 625 | f 100/141/4 77/151/4 104/125/4 626 | f 125/152/2 105/153/2 90/126/2 627 | f 109/138/5 106/133/5 107/140/5 628 | f 111/135/4 119/128/4 94/136/4 629 | f 112/154/1 105/153/1 126/155/1 630 | f 116/156/4 117/157/4 98/143/4 631 | f 114/142/2 123/150/2 128/158/2 632 | f 101/147/5 128/158/5 121/159/5 633 | f 115/160/2 118/144/2 129/161/2 634 | f 115/160/5 127/162/5 116/156/5 635 | f 118/163/3 127/164/3 129/165/3 636 | f 120/146/4 130/166/4 100/141/4 637 | f 123/167/3 121/168/3 128/169/3 638 | f 100/141/4 133/170/4 124/171/4 639 | f 126/155/5 132/172/5 112/154/5 640 | f 131/173/4 132/172/4 125/152/4 641 | f 136/174/11 130/166/11 135/175/11 642 | f 135/175/12 134/176/12 136/174/12 643 | f 168/177/4 170/178/4 167/179/4 644 | f 57/180/3 167/181/3 58/85/3 645 | f 59/182/5 167/181/5 170/183/5 646 | f 78/102/1 169/184/1 79/103/1 647 | f 56/185/10 79/103/10 169/184/10 648 | f 138/186/13 140/187/13 137/188/13 649 | f 141/189/5 138/190/5 137/191/5 650 | f 138/192/14 143/193/14 139/194/14 651 | f 171/195/15 144/196/15 172/197/15 652 | f 145/198/1 140/199/1 139/200/1 653 | f 173/201/16 144/196/16 148/202/16 654 | f 139/203/1 149/204/1 145/205/1 655 | f 147/206/17 142/207/17 138/186/17 656 | f 142/208/4 149/209/4 143/210/4 657 | f 153/211/18 146/212/18 145/213/18 658 | f 171/214/1 154/215/1 152/216/1 659 | f 147/217/19 155/218/19 156/219/19 660 | f 148/220/20 176/221/20 173/222/20 661 | f 158/223/21 149/209/21 151/224/21 662 | f 159/225/3 150/226/3 147/227/3 663 | f 160/228/4 142/229/4 150/230/4 664 | f 158/223/21 153/231/21 145/213/21 665 | f 174/232/22 153/233/22 154/234/22 666 | f 147/235/4 161/236/4 159/237/4 667 | f 155/238/3 161/239/3 156/240/3 668 | f 163/241/2 157/242/2 148/243/2 669 | f 175/244/3 155/245/3 176/246/3 670 | f 159/237/23 151/247/23 160/248/23 671 | f 153/211/23 158/249/23 159/250/23 672 | f 165/251/21 154/252/21 153/233/21 673 | f 166/253/24 161/239/24 162/254/24 674 | f 177/255/25 162/256/25 175/257/25 675 | f 166/253/24 153/231/24 159/250/24 676 | f 163/258/23 165/259/23 153/233/23 677 | f 177/255/25 153/233/25 166/253/25 678 | f 144/196/2 163/260/2 148/202/2 679 | f 154/261/2 144/196/2 152/262/2 680 | f 49/79/4 72/263/4 83/94/4 681 | f 163/258/25 175/257/25 164/264/25 682 | f 164/265/3 176/246/3 157/266/3 683 | f 141/267/20 176/221/20 155/268/20 684 | f 140/269/1 174/270/1 171/214/1 685 | f 141/271/26 172/272/26 173/273/26 686 | f 140/274/13 172/275/13 137/276/13 687 | f 178/277/27 85/278/27 172/279/27 688 | f 178/277/2 125/280/2 90/281/2 689 | f 4/1/1 3/282/1 1/2/1 690 | f 8/4/2 7/14/2 3/5/2 691 | f 6/7/3 5/283/3 7/8/3 692 | f 2/10/4 1/284/4 5/11/4 693 | f 1/13/5 3/285/5 7/14/5 694 | f 8/4/6 11/286/6 12/15/6 695 | f 10/16/2 14/287/2 15/17/2 696 | f 2/10/7 9/288/7 10/19/7 697 | f 6/7/8 12/289/8 9/20/8 698 | f 8/9/9 4/1/9 10/21/9 699 | f 13/23/10 16/290/10 20/24/10 700 | f 11/26/3 15/291/3 16/27/3 701 | f 9/29/1 13/292/1 14/30/1 702 | f 12/32/4 16/293/4 13/33/4 703 | f 19/35/1 23/294/1 24/36/1 704 | f 15/38/10 14/295/10 18/39/10 705 | f 15/41/10 19/296/10 20/42/10 706 | f 13/44/10 17/297/10 18/45/10 707 | f 23/47/10 22/298/10 21/48/10 708 | f 17/50/3 21/299/3 22/51/3 709 | f 20/53/2 24/300/2 21/48/2 710 | f 18/55/4 22/298/4 23/56/4 711 | f 26/58/4 27/63/4 28/59/4 712 | f 26/58/4 25/60/4 33/61/4 713 | f 27/63/4 26/58/4 35/64/4 714 | f 28/59/4 31/71/4 37/66/4 715 | f 27/63/4 32/68/4 38/67/4 716 | f 29/62/1 34/76/1 35/64/1 717 | f 32/68/5 27/63/5 30/65/5 718 | f 28/59/5 38/67/5 39/70/5 719 | f 44/86/1 40/88/1 37/66/1 720 | f 42/72/1 43/89/1 25/60/1 721 | f 37/66/1 40/88/1 41/73/1 722 | f 43/89/1 33/61/1 25/60/1 723 | f 37/66/1 41/73/1 25/60/1 724 | f 29/62/4 33/61/4 70/74/4 725 | f 34/76/4 29/62/4 45/75/4 726 | f 30/65/4 35/64/4 48/78/4 727 | f 50/80/5 36/69/5 30/65/5 728 | f 51/81/5 52/98/5 32/68/5 729 | f 37/66/4 31/71/4 61/82/4 730 | f 54/84/5 55/99/5 39/70/5 731 | f 31/71/4 39/70/4 57/180/4 732 | f 39/70/4 56/185/4 57/180/4 733 | f 60/301/4 61/82/4 58/85/4 734 | f 58/85/4 59/182/4 60/301/4 735 | f 31/71/4 57/180/4 58/85/4 736 | f 32/68/4 52/98/4 54/84/4 737 | f 44/86/10 62/107/10 63/87/10 738 | f 41/73/1 40/88/1 64/105/1 739 | f 65/106/1 44/86/1 37/66/1 740 | f 66/90/1 41/73/1 64/105/1 741 | f 65/106/1 37/66/1 53/83/1 742 | f 64/105/1 65/106/1 53/83/1 743 | f 53/83/1 33/61/1 66/90/1 744 | f 66/90/1 64/105/1 53/83/1 745 | f 41/73/10 67/113/10 68/91/10 746 | f 42/72/4 68/91/4 69/92/4 747 | f 46/77/4 71/117/4 47/93/4 748 | f 34/76/1 47/93/1 48/78/1 749 | f 50/80/4 49/79/4 83/94/4 750 | f 74/96/5 51/81/5 36/69/5 751 | f 51/81/4 75/119/4 87/97/4 752 | f 55/99/4 54/84/4 88/100/4 753 | f 77/151/4 60/301/4 78/102/4 754 | f 60/301/4 59/182/4 78/102/4 755 | f 56/185/4 39/70/4 79/103/4 756 | f 77/151/4 78/102/4 55/99/4 757 | f 79/103/4 39/70/4 55/99/4 758 | f 40/88/4 63/87/4 80/104/4 759 | f 65/106/2 81/111/2 62/107/2 760 | f 63/108/1 62/302/1 81/109/1 761 | f 64/105/5 80/104/5 81/111/5 762 | f 33/61/4 53/83/4 61/82/4 763 | f 43/89/5 69/92/5 82/112/5 764 | f 66/90/2 82/112/2 67/113/2 765 | f 68/114/1 67/303/1 82/115/1 766 | f 71/117/4 84/304/4 85/118/4 767 | f 74/96/4 86/127/4 75/119/4 768 | f 94/136/5 87/97/5 92/120/5 769 | f 75/119/5 91/305/5 92/120/5 770 | f 92/120/5 93/132/5 94/136/5 771 | f 91/305/5 75/119/5 97/123/5 772 | f 86/127/5 95/121/5 97/123/5 773 | f 97/123/5 75/119/5 86/127/5 774 | f 88/100/4 54/84/4 52/98/4 775 | f 98/143/3 99/145/3 76/101/3 776 | f 88/100/3 100/141/3 101/147/3 777 | f 102/149/3 103/124/3 88/100/3 778 | f 88/100/3 101/147/3 102/149/3 779 | f 98/143/3 76/101/3 103/124/3 780 | f 104/125/4 77/151/4 55/99/4 781 | f 90/126/4 105/153/4 95/121/4 782 | f 87/97/4 94/136/4 119/128/4 783 | f 107/306/3 106/131/3 91/130/3 784 | f 91/130/3 97/307/3 107/306/3 785 | f 93/132/2 92/120/2 106/133/2 786 | f 108/134/3 109/138/3 110/137/3 787 | f 110/137/3 111/135/3 108/134/3 788 | f 94/136/3 93/132/3 108/134/3 789 | f 96/122/3 95/121/3 113/139/3 790 | f 112/154/3 110/137/3 113/139/3 791 | f 113/139/3 95/121/3 112/154/3 792 | f 97/123/4 96/122/4 113/139/4 793 | f 116/156/3 98/143/3 103/124/3 794 | f 114/142/3 101/147/3 100/141/3 795 | f 116/156/3 103/124/3 114/142/3 796 | f 76/101/3 99/145/3 115/160/3 797 | f 116/156/3 114/142/3 104/125/3 798 | f 104/125/3 76/101/3 115/160/3 799 | f 115/160/3 116/156/3 104/125/3 800 | f 98/143/10 117/157/10 118/144/10 801 | f 88/100/4 119/128/4 120/146/4 802 | f 101/147/4 121/159/4 122/148/4 803 | f 102/149/10 122/148/10 123/150/10 804 | f 100/141/4 124/171/4 77/151/4 805 | f 125/152/2 126/155/2 105/153/2 806 | f 107/140/5 113/139/5 109/138/5 807 | f 109/138/5 108/134/5 106/133/5 808 | f 111/135/4 120/146/4 119/128/4 809 | f 112/154/4 95/121/4 105/153/4 810 | f 116/156/4 127/162/4 117/157/4 811 | f 114/142/2 103/124/2 123/150/2 812 | f 101/147/5 114/142/5 128/158/5 813 | f 115/160/2 99/145/2 118/144/2 814 | f 115/160/5 129/161/5 127/162/5 815 | f 118/163/3 117/308/3 127/164/3 816 | f 120/146/10 111/135/10 130/166/10 817 | f 123/167/3 122/309/3 121/168/3 818 | f 100/141/4 130/166/4 133/170/4 819 | f 126/155/4 125/152/4 132/172/4 820 | f 131/173/4 134/176/4 132/172/4 821 | f 136/174/2 133/170/2 130/166/2 822 | f 135/175/4 132/172/4 134/176/4 823 | f 168/177/4 169/310/4 170/178/4 824 | f 57/180/3 168/311/3 167/181/3 825 | f 170/183/5 78/102/5 59/182/5 826 | f 59/182/5 58/85/5 167/181/5 827 | f 78/102/1 170/183/1 169/184/1 828 | f 169/184/10 168/311/10 56/185/10 829 | f 57/180/10 56/185/10 168/311/10 830 | f 138/186/28 139/312/28 140/187/28 831 | f 141/189/29 147/313/29 138/190/29 832 | f 138/192/14 142/314/14 143/193/14 833 | f 171/195/30 152/262/30 144/196/30 834 | f 145/198/1 146/315/1 140/199/1 835 | f 173/201/31 172/197/31 144/196/31 836 | f 139/203/1 143/316/1 149/204/1 837 | f 147/206/17 150/317/17 142/207/17 838 | f 142/208/4 151/318/4 149/209/4 839 | f 171/214/1 174/270/1 154/215/1 840 | f 147/217/19 141/319/19 155/218/19 841 | f 148/220/20 157/320/20 176/221/20 842 | f 158/223/21 145/198/21 149/209/21 843 | f 159/225/3 160/321/3 150/226/3 844 | f 160/228/4 151/247/4 142/229/4 845 | f 174/232/22 146/212/22 153/233/22 846 | f 147/235/4 156/322/4 161/236/4 847 | f 155/238/3 162/323/3 161/239/3 848 | f 163/241/2 164/324/2 157/242/2 849 | f 175/244/3 162/256/3 155/245/3 850 | f 159/237/23 158/249/23 151/247/23 851 | f 166/253/24 159/225/24 161/239/24 852 | f 177/255/25 166/325/25 162/256/25 853 | f 177/255/25 163/241/25 153/233/25 854 | f 144/196/2 165/326/2 163/260/2 855 | f 154/261/2 165/326/2 144/196/2 856 | f 49/79/4 48/78/4 72/263/4 857 | f 163/258/25 177/255/25 175/257/25 858 | f 164/265/3 175/244/3 176/246/3 859 | f 141/267/20 173/222/20 176/221/20 860 | f 140/269/1 146/212/1 174/270/1 861 | f 141/271/5 137/327/5 172/272/5 862 | f 140/274/32 171/328/32 172/275/32 863 | f 178/277/2 48/329/2 85/278/2 864 | f 178/277/33 172/279/33 125/280/33 865 | -------------------------------------------------------------------------------- /Example scenes/Houses/House models/House5.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'SmallHouse.blend' 2 | # Material Count: 1 3 | 4 | newmtl Material.002 5 | Ns 96.078431 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.640000 0.640000 0.640000 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.000000 11 | d 1.000000 12 | illum 2 13 | -------------------------------------------------------------------------------- /Example scenes/Houses/House models/House5.obj: -------------------------------------------------------------------------------- 1 | # Blender v2.78 (sub 0) OBJ File: 'SmallHouse.blend' 2 | # www.blender.org 3 | mtllib House5.mtl 4 | o Cube_Cube.002 5 | v -0.602511 2.031580 0.723893 6 | v -0.602511 2.044969 0.669412 7 | v -0.602511 1.604321 -0.318354 8 | v -0.602511 0.034607 -0.318354 9 | v -0.602511 0.034607 1.681646 10 | v -0.602511 1.604321 1.681646 11 | v -0.766397 2.050426 0.681646 12 | v -0.446036 2.031580 0.723893 13 | v -0.550903 2.044969 0.669412 14 | v -0.766397 1.531211 -0.482239 15 | v 2.602715 1.531211 -0.482239 16 | v 2.602715 2.050426 0.681646 17 | v 2.438830 1.604321 -0.318354 18 | v 1.688759 0.965499 -0.318354 19 | v 1.688759 0.502083 -0.318354 20 | v 2.345677 0.965499 -0.318354 21 | v 2.438830 0.034607 -0.318354 22 | v 2.438830 0.034607 1.681646 23 | v 1.525867 0.034607 1.681646 24 | v 1.525867 0.034607 1.630396 25 | v 1.061105 0.034607 1.630396 26 | v 1.061105 0.034607 1.681646 27 | v 0.798889 0.034607 1.681646 28 | v 0.798889 0.034607 1.588378 29 | v -0.240685 0.034607 1.588378 30 | v -0.240685 0.034607 1.681646 31 | v -0.240685 0.966986 1.681646 32 | v 0.798889 0.966986 1.681646 33 | v 1.061105 0.034826 1.681646 34 | v 1.059534 0.034826 1.681646 35 | v 1.059534 0.759069 1.681646 36 | v 1.525658 0.759069 1.681646 37 | v 1.688759 0.910039 1.681646 38 | v 1.688759 0.965499 1.681646 39 | v 1.748675 0.965499 1.681646 40 | v 2.438830 1.604321 1.681646 41 | v -0.766397 1.531211 1.845531 42 | v 2.438830 2.049104 0.684609 43 | v 2.438830 2.050063 0.680831 44 | v -0.766397 2.333738 0.681646 45 | v -0.766397 1.814522 -0.482239 46 | v 2.602715 1.814522 -0.482239 47 | v 2.602715 2.333738 0.681646 48 | v 2.345677 0.965499 -0.301554 49 | v 1.688759 0.965499 -0.301554 50 | v 1.688759 0.502083 -0.301554 51 | v 2.345677 0.502083 -0.318354 52 | v 1.525867 0.034752 1.681646 53 | v 0.798889 0.966986 1.588378 54 | v -0.240685 0.966986 1.588378 55 | v 1.061105 0.034826 1.681646 56 | v 1.059534 0.034826 1.630370 57 | v 1.059534 0.759069 1.630370 58 | v 1.525658 0.759069 1.630370 59 | v 2.345677 0.965499 1.681646 60 | v 2.345677 0.502083 1.681646 61 | v 1.688759 0.502083 1.681646 62 | v 1.525658 0.135883 1.681646 63 | v 1.525867 0.135883 1.681646 64 | v 1.688759 0.502083 1.651670 65 | v 1.688759 0.965499 1.651670 66 | v 2.345677 0.965499 1.651670 67 | v 2.602715 1.531211 1.845531 68 | v -0.766397 1.814522 1.845531 69 | v -0.404077 2.103067 0.164569 70 | v -0.404077 1.972027 -0.129174 71 | v -0.110334 1.972027 -0.129174 72 | v -0.110334 2.103067 0.164569 73 | v 2.602715 1.814522 1.845531 74 | v 2.345677 0.502083 -0.301554 75 | v 1.525658 0.034826 1.630370 76 | v 1.525658 0.034826 1.630396 77 | v 1.525658 0.135883 1.630396 78 | v 2.345677 0.502083 1.651670 79 | v -0.404077 2.234663 0.164569 80 | v -0.404077 2.234663 -0.129174 81 | v -0.110334 2.234663 -0.129174 82 | v -0.110334 2.234663 0.164569 83 | v -0.420518 2.222652 0.181010 84 | v -0.420518 2.222652 -0.145615 85 | v -0.093893 2.222652 -0.145615 86 | v -0.093893 2.222652 0.181010 87 | v -0.420518 2.461278 0.181010 88 | v -0.420518 2.461278 -0.145615 89 | v -0.093893 2.461278 -0.145615 90 | v -0.093893 2.461278 0.181010 91 | v -0.373824 2.461278 0.134316 92 | v -0.373824 2.461278 -0.098921 93 | v -0.140587 2.461278 -0.098921 94 | v -0.140587 2.461278 0.134316 95 | v -0.373824 2.191994 0.134316 96 | v -0.373824 2.191994 -0.098921 97 | v -0.140587 2.191994 -0.098921 98 | v -0.140587 2.191994 0.134316 99 | v 1.525867 0.135883 1.630396 100 | vt 0.0469 0.9336 101 | vt 0.0367 0.9395 102 | vt 0.0469 0.9570 103 | vt 0.8446 0.8755 104 | vt 0.8637 0.8663 105 | vt 0.8425 0.8663 106 | vt 0.8640 0.8579 107 | vt 0.8422 0.8796 108 | vt 0.8422 0.8579 109 | vt 0.8637 0.8663 110 | vt 0.8578 0.8589 111 | vt 0.8446 0.8755 112 | vt 0.0447 0.9394 113 | vt 0.0352 0.9570 114 | vt 0.0352 0.9336 115 | vt 0.0586 0.9336 116 | vt 0.0363 0.9444 117 | vt 0.0363 0.9364 118 | vt 0.0467 0.9452 119 | vt 0.0478 0.9464 120 | vt 0.0456 0.9510 121 | vt 0.8422 0.8796 122 | vt 0.8640 0.8579 123 | vt 0.8640 0.8796 124 | vt 0.8640 0.8579 125 | vt 0.8422 0.8796 126 | vt 0.8422 0.8579 127 | vt 0.8640 0.8579 128 | vt 0.8422 0.8796 129 | vt 0.8422 0.8579 130 | vt 0.8422 0.8579 131 | vt 0.8640 0.8796 132 | vt 0.8422 0.8796 133 | vt 0.8437 0.8742 134 | vt 0.8626 0.8742 135 | vt 0.8626 0.8633 136 | vt 0.0676 0.9429 137 | vt 0.0584 0.9431 138 | vt 0.0581 0.9429 139 | vt 0.0577 0.9497 140 | vt 0.0574 0.9500 141 | vt 0.0447 0.9343 142 | vt 0.0586 0.9336 143 | vt 0.0570 0.9512 144 | vt 0.0367 0.9395 145 | vt 0.0367 0.9512 146 | vt 0.0586 0.9500 147 | vt 0.0586 0.9570 148 | vt 0.0586 0.9500 149 | vt 0.0759 0.9073 150 | vt 0.0711 0.9277 151 | vt 0.0698 0.9260 152 | vt 0.0658 0.0997 153 | vt 0.0445 0.1172 154 | vt 0.0385 0.0997 155 | vt 0.0471 0.9081 156 | vt 0.0552 0.9243 157 | vt 0.0539 0.9260 158 | vt 0.0586 0.9464 159 | vt 0.0586 0.9464 160 | vt 0.0586 0.9464 161 | vt 0.0404 0.9402 162 | vt 0.0411 0.9500 163 | vt 0.0404 0.9500 164 | vt 0.0411 0.9563 165 | vt 0.0404 0.9563 166 | vt 0.0523 0.9510 167 | vt 0.0571 0.9500 168 | vt 0.0762 0.9396 169 | vt 0.0791 0.9288 170 | vt 0.0771 0.9409 171 | vt 0.0783 0.9420 172 | vt 0.0936 0.9411 173 | vt 0.8422 0.8579 174 | vt 0.8640 0.8796 175 | vt 0.8422 0.8796 176 | vt 0.8574 0.8754 177 | vt 0.8640 0.8796 178 | vt 0.8519 0.8754 179 | vt 0.8640 0.8579 180 | vt 0.8422 0.8796 181 | vt 0.8422 0.8579 182 | vt 0.0669 0.9500 183 | vt 0.0673 0.9432 184 | vt 0.9500 0.0894 185 | vt 0.9250 0.0692 186 | vt 0.9521 0.0693 187 | vt 0.0666 0.9498 188 | vt 0.0646 0.0798 189 | vt 0.0322 0.0296 190 | vt 0.0646 0.0296 191 | vt 0.0411 0.9660 192 | vt 0.0411 0.9660 193 | vt 0.0411 0.9646 194 | vt 0.0946 0.9420 195 | vt 0.0948 0.9293 196 | vt 0.0957 0.9284 197 | vt 0.0785 0.9280 198 | vt 0.9395 0.0695 199 | vt 0.9504 0.0788 200 | vt 0.9379 0.0787 201 | vt 0.8437 0.8633 202 | vt 0.8531 0.8796 203 | vt 0.8626 0.8742 204 | vt 0.8640 0.8579 205 | vt 0.8422 0.8796 206 | vt 0.8422 0.8579 207 | vt 0.8640 0.8579 208 | vt 0.8422 0.8796 209 | vt 0.0426 0.9637 210 | vt 0.0422 0.9643 211 | vt 0.0425 0.9641 212 | vt 0.0435 0.9640 213 | vt 0.0431 0.9637 214 | vt 0.0433 0.9639 215 | vt 0.0438 0.9643 216 | vt 0.0433 0.9637 217 | vt 0.0434 0.9641 218 | vt 0.0427 0.9637 219 | vt 0.0426 0.9640 220 | vt 0.0428 0.9637 221 | vt 0.0434 0.9645 222 | vt 0.0433 0.9644 223 | vt 0.0434 0.9645 224 | vt 0.0427 0.9644 225 | vt 0.0428 0.9644 226 | vt 0.0428 0.9644 227 | vt 0.0424 0.9645 228 | vt 0.0425 0.9645 229 | vt 0.0425 0.9645 230 | vt 0.0434 0.9645 231 | vt 0.0432 0.9645 232 | vt 0.0434 0.9645 233 | vt 0.0432 0.9658 234 | vt 0.0438 0.9653 235 | vt 0.0435 0.9654 236 | vt 0.0426 0.9656 237 | vt 0.0427 0.9658 238 | vt 0.0429 0.9658 239 | vt 0.0425 0.9654 240 | vt 0.0424 0.9659 241 | vt 0.0428 0.9658 242 | vt 0.0431 0.9658 243 | vt 0.0435 0.9655 244 | vt 0.0433 0.9656 245 | vt 0.0435 0.9658 246 | vt 0.0434 0.9658 247 | vt 0.0435 0.9658 248 | vt 0.0427 0.9658 249 | vt 0.0428 0.9659 250 | vt 0.0428 0.9659 251 | vt 0.0421 0.9657 252 | vt 0.0423 0.9656 253 | vt 0.0423 0.9656 254 | vt 0.0432 0.9656 255 | vt 0.0436 0.9656 256 | vt 0.0436 0.9656 257 | vt 0.0434 0.9639 258 | vt 0.0433 0.9641 259 | vt 0.0436 0.9643 260 | vt 0.0426 0.9641 261 | vt 0.0429 0.9638 262 | vt 0.0428 0.9638 263 | vt 0.0424 0.9643 264 | vt 0.0428 0.9639 265 | vt 0.0425 0.9639 266 | vt 0.0432 0.9638 267 | vt 0.0432 0.9640 268 | vt 0.0434 0.9641 269 | vt 0.0423 0.9647 270 | vt 0.0425 0.9644 271 | vt 0.0424 0.9646 272 | vt 0.0000 0.0000 273 | vt 0.0000 0.0000 274 | vt 0.0000 0.0000 275 | vt 0.0000 0.0000 276 | vt 0.0000 0.0000 277 | vt 0.0352 0.9500 278 | vt 0.0000 0.0000 279 | vt 0.0367 0.9512 280 | vt 0.0570 0.9512 281 | vt 0.0570 0.9395 282 | vt 0.8578 0.8589 283 | vt 0.8484 0.8589 284 | vt 0.8616 0.8755 285 | vt 0.8640 0.8796 286 | vt 0.8531 0.8796 287 | vt 0.8616 0.8755 288 | vt 0.8484 0.8589 289 | vt 0.8425 0.8663 290 | vt 0.0516 0.9394 291 | vt 0.0586 0.9570 292 | vt 0.0352 0.9364 293 | vt 0.0352 0.9336 294 | vt 0.0586 0.9570 295 | vt 0.0352 0.9570 296 | vt 0.0352 0.9500 297 | vt 0.0358 0.9500 298 | vt 0.0358 0.9463 299 | vt 0.0352 0.9464 300 | vt 0.0352 0.9444 301 | vt 0.0352 0.9336 302 | vt 0.0586 0.9336 303 | vt 0.0451 0.9368 304 | vt 0.0586 0.9364 305 | vt 0.0447 0.9517 306 | vt 0.0352 0.9570 307 | vt 0.0478 0.9500 308 | vt 0.0455 0.9512 309 | vt 0.0586 0.9444 310 | vt 0.0586 0.9464 311 | vt 0.8422 0.8579 312 | vt 0.8640 0.8796 313 | vt 0.8640 0.8796 314 | vt 0.8531 0.8579 315 | vt 0.8437 0.8633 316 | vt 0.0516 0.9343 317 | vt 0.0469 0.9570 318 | vt 0.0570 0.9395 319 | vt 0.0469 0.9336 320 | vt 0.0779 0.9080 321 | vt 0.0595 0.1190 322 | vt 0.0494 0.9073 323 | vt 0.0411 0.9402 324 | vt 0.0449 0.9562 325 | vt 0.0571 0.9500 326 | vt 0.0517 0.9562 327 | vt 0.0765 0.9414 328 | vt 0.8640 0.8579 329 | vt 0.8422 0.8796 330 | vt 0.8519 0.8773 331 | vt 0.8574 0.8773 332 | vt 0.8640 0.8796 333 | vt 0.9229 0.0892 334 | vt 0.0322 0.0798 335 | vt 0.0404 0.9646 336 | vt 0.9513 0.0699 337 | vt 0.8626 0.8633 338 | vt 0.8531 0.8579 339 | vt 0.8437 0.8742 340 | vt 0.8640 0.8796 341 | vt 0.8640 0.8796 342 | vt 0.0424 0.9637 343 | vt 0.0432 0.9637 344 | vt 0.0435 0.9637 345 | vt 0.0424 0.9640 346 | vt 0.0434 0.9644 347 | vt 0.0427 0.9644 348 | vt 0.0424 0.9645 349 | vt 0.0432 0.9645 350 | vt 0.0435 0.9659 351 | vt 0.0424 0.9655 352 | vt 0.0421 0.9653 353 | vt 0.0432 0.9658 354 | vt 0.0434 0.9658 355 | vt 0.0427 0.9658 356 | vt 0.0421 0.9657 357 | vt 0.0433 0.9656 358 | vt 0.0431 0.9639 359 | vt 0.0428 0.9640 360 | vt 0.0427 0.9641 361 | vt 0.0431 0.9638 362 | vt 0.0424 0.9645 363 | vt 0.0000 0.0000 364 | vn -1.0000 0.0000 0.0000 365 | vn 0.0000 -0.9132 -0.4074 366 | vn 0.0000 0.9711 0.2387 367 | vn 0.0000 -0.9132 0.4074 368 | vn 0.0000 0.0000 -1.0000 369 | vn 0.0000 -1.0000 0.0000 370 | vn 0.0000 0.0000 1.0000 371 | vn -0.0026 0.9699 0.2433 372 | vn 1.0000 0.0000 0.0000 373 | vn -0.0000 -0.9133 0.4074 374 | vn 0.0000 0.9132 -0.4074 375 | vn 0.0000 1.0000 0.0000 376 | vn 0.0000 0.9132 0.4074 377 | vn 0.5899 -0.8075 0.0000 378 | vn 0.0000 -0.8075 0.5899 379 | vn -0.5899 -0.8075 0.0000 380 | vn 0.0000 -0.8075 -0.5899 381 | vn 0.0005 0.0000 1.0000 382 | vn -1.0000 -0.0021 0.0000 383 | vn 0.0000 -0.9132 -0.4075 384 | vn -0.0025 0.9693 0.2458 385 | vn 0.0000 -0.9132 0.4076 386 | vn 1.0000 -0.0001 0.0000 387 | usemtl Material.002 388 | s off 389 | f 4/1/1 5/2/1 1/3/1 390 | f 1/4/2 7/5/2 8/6/2 391 | f 9/7/3 1/8/3 8/9/3 392 | f 10/10/4 11/11/4 3/12/4 393 | f 14/13/5 3/14/5 13/15/5 394 | f 4/16/6 24/17/6 25/18/6 395 | f 28/19/7 31/20/7 34/21/7 396 | f 8/22/8 39/23/8 9/24/8 397 | f 41/25/1 7/26/1 40/27/1 398 | f 42/28/5 10/29/5 41/30/5 399 | f 42/31/9 12/32/9 11/33/9 400 | f 7/34/10 9/35/10 39/36/10 401 | f 16/37/6 45/38/6 14/39/6 402 | f 14/39/9 46/40/9 15/41/9 403 | f 16/42/5 13/15/5 17/43/5 404 | f 38/44/9 17/45/9 13/46/9 405 | f 19/47/7 18/48/7 48/49/7 406 | f 24/50/1 28/51/1 49/52/1 407 | f 24/53/7 50/54/7 25/55/7 408 | f 26/56/9 50/57/9 27/58/9 409 | f 27/58/6 49/52/6 28/51/6 410 | f 51/59/7 30/60/7 29/61/7 411 | f 30/62/9 53/63/9 31/64/9 412 | f 31/64/6 54/65/6 32/66/6 413 | f 18/48/7 57/67/7 59/68/7 414 | f 33/69/9 60/70/9 61/71/9 415 | f 35/72/6 61/71/6 62/73/6 416 | f 64/74/1 7/75/1 37/76/1 417 | f 67/77/11 42/28/11 41/78/11 418 | f 42/28/11 67/77/11 68/79/11 419 | f 69/80/9 12/81/9 43/82/9 420 | f 47/83/1 44/84/1 16/37/1 421 | f 70/85/5 45/86/5 44/87/5 422 | f 15/41/12 70/88/12 47/83/12 423 | f 54/89/7 52/90/7 71/91/7 424 | f 71/92/1 72/93/1 73/94/1 425 | f 55/95/1 74/96/1 56/97/1 426 | f 56/97/12 60/70/12 57/98/12 427 | f 60/99/7 62/100/7 61/101/7 428 | f 63/102/2 6/103/2 36/104/2 429 | f 64/105/7 63/106/7 69/107/7 430 | f 43/108/13 64/109/13 69/107/13 431 | f 65/110/1 76/111/1 66/112/1 432 | f 76/113/5 67/114/5 66/115/5 433 | f 77/116/9 68/117/9 67/118/9 434 | f 78/119/7 65/120/7 68/121/7 435 | f 76/122/14 79/123/14 80/124/14 436 | f 76/125/15 81/126/15 77/127/15 437 | f 77/128/16 82/129/16 78/130/16 438 | f 75/131/17 82/132/17 79/133/17 439 | f 79/134/1 84/135/1 80/136/1 440 | f 80/137/5 85/138/5 81/139/5 441 | f 81/140/9 86/141/9 82/142/9 442 | f 82/143/7 83/144/7 79/145/7 443 | f 84/146/12 87/147/12 88/148/12 444 | f 84/149/12 89/150/12 85/151/12 445 | f 85/152/12 90/153/12 86/154/12 446 | f 86/155/12 87/156/12 83/157/12 447 | f 87/158/9 92/159/9 88/160/9 448 | f 88/161/7 93/162/7 89/163/7 449 | f 89/164/1 94/165/1 90/166/1 450 | f 90/167/5 91/168/5 87/169/5 451 | f 93/170/12 91/171/12 94/172/12 452 | f 95/173/18 72/174/18 20/175/18 453 | f 58/176/6 95/173/6 59/177/6 454 | f 20/178/19 58/176/19 73/179/19 455 | f 6/180/1 1/3/1 5/2/1 456 | f 2/181/1 3/182/1 1/3/1 457 | f 4/1/1 1/3/1 3/182/1 458 | f 1/4/2 6/103/2 7/5/2 459 | f 7/5/20 12/183/20 38/184/20 460 | f 38/184/2 8/6/2 7/5/2 461 | f 6/103/2 37/185/2 7/5/2 462 | f 9/7/3 2/186/3 1/8/3 463 | f 3/12/4 2/187/4 7/188/4 464 | f 11/11/4 12/189/4 13/190/4 465 | f 3/12/4 7/188/4 10/10/4 466 | f 11/11/4 13/190/4 3/12/4 467 | f 14/13/5 15/191/5 4/192/5 468 | f 4/192/5 3/14/5 14/13/5 469 | f 13/15/5 16/42/5 14/13/5 470 | f 26/193/6 5/194/6 25/18/6 471 | f 4/16/6 17/195/6 24/17/6 472 | f 18/196/6 19/197/6 20/198/6 473 | f 21/199/6 22/200/6 23/201/6 474 | f 17/195/6 18/196/6 20/198/6 475 | f 21/199/6 23/201/6 24/17/6 476 | f 17/195/6 20/198/6 21/199/6 477 | f 25/18/6 5/194/6 4/16/6 478 | f 17/195/6 21/199/6 24/17/6 479 | f 6/202/7 5/203/7 27/204/7 480 | f 5/203/7 26/205/7 27/204/7 481 | f 35/206/7 36/207/7 34/21/7 482 | f 32/208/7 33/209/7 34/21/7 483 | f 34/21/7 36/207/7 28/19/7 484 | f 6/202/7 27/204/7 28/19/7 485 | f 23/210/7 22/211/7 30/60/7 486 | f 22/211/7 29/61/7 30/60/7 487 | f 36/207/7 6/202/7 28/19/7 488 | f 28/19/7 23/210/7 31/20/7 489 | f 31/20/7 32/208/7 34/21/7 490 | f 23/210/7 30/60/7 31/20/7 491 | f 8/22/21 38/212/21 39/23/21 492 | f 41/25/1 10/213/1 7/26/1 493 | f 42/28/5 11/214/5 10/29/5 494 | f 42/31/9 43/108/9 12/32/9 495 | f 39/36/4 13/215/4 12/216/4 496 | f 12/216/22 7/34/22 39/36/22 497 | f 2/187/4 9/35/4 7/34/4 498 | f 16/37/6 44/84/6 45/38/6 499 | f 14/39/9 45/38/9 46/40/9 500 | f 4/192/5 15/191/5 17/43/5 501 | f 47/217/5 16/42/5 17/43/5 502 | f 17/43/5 15/191/5 47/217/5 503 | f 13/46/23 39/218/23 38/44/23 504 | f 38/44/9 36/219/9 18/220/9 505 | f 18/220/9 17/45/9 38/44/9 506 | f 24/50/1 23/221/1 28/51/1 507 | f 24/53/7 49/222/7 50/54/7 508 | f 26/56/9 25/223/9 50/57/9 509 | f 27/58/6 50/57/6 49/52/6 510 | f 30/62/9 52/224/9 53/63/9 511 | f 31/64/6 53/63/6 54/65/6 512 | f 36/207/7 35/206/7 55/225/7 513 | f 36/207/7 55/225/7 18/48/7 514 | f 59/68/7 48/49/7 18/48/7 515 | f 32/208/7 58/226/7 57/67/7 516 | f 57/67/7 33/209/7 32/208/7 517 | f 18/48/7 55/225/7 56/227/7 518 | f 57/67/7 58/226/7 59/68/7 519 | f 18/48/7 56/227/7 57/67/7 520 | f 61/71/9 34/228/9 33/69/9 521 | f 33/69/9 57/98/9 60/70/9 522 | f 62/73/6 55/95/6 35/72/6 523 | f 35/72/6 34/228/6 61/71/6 524 | f 64/74/1 40/229/1 7/75/1 525 | f 41/78/11 40/230/11 65/231/11 526 | f 66/232/11 67/77/11 41/78/11 527 | f 41/78/11 65/231/11 66/232/11 528 | f 65/231/11 40/230/11 68/79/11 529 | f 43/82/11 42/28/11 68/79/11 530 | f 68/79/11 40/230/11 43/82/11 531 | f 69/80/9 63/233/9 12/81/9 532 | f 47/83/1 70/88/1 44/84/1 533 | f 70/85/5 46/234/5 45/86/5 534 | f 15/41/12 46/40/12 70/88/12 535 | f 54/89/7 53/235/7 52/90/7 536 | f 73/94/1 58/236/1 32/66/1 537 | f 54/65/1 71/92/1 73/94/1 538 | f 73/94/1 32/66/1 54/65/1 539 | f 55/95/1 62/73/1 74/96/1 540 | f 56/97/12 74/96/12 60/70/12 541 | f 60/99/7 74/237/7 62/100/7 542 | f 38/238/2 12/239/2 36/104/2 543 | f 63/102/2 37/240/2 6/103/2 544 | f 36/104/2 12/239/2 63/102/2 545 | f 64/105/7 37/241/7 63/106/7 546 | f 43/108/13 40/242/13 64/109/13 547 | f 65/110/1 75/243/1 76/111/1 548 | f 76/113/5 77/244/5 67/114/5 549 | f 77/116/9 78/245/9 68/117/9 550 | f 78/119/7 75/246/7 65/120/7 551 | f 76/122/14 75/247/14 79/123/14 552 | f 76/125/15 80/248/15 81/126/15 553 | f 77/128/16 81/249/16 82/129/16 554 | f 75/131/17 78/250/17 82/132/17 555 | f 79/134/1 83/251/1 84/135/1 556 | f 80/137/5 84/252/5 85/138/5 557 | f 81/140/9 85/253/9 86/141/9 558 | f 82/143/7 86/254/7 83/144/7 559 | f 84/146/12 83/255/12 87/147/12 560 | f 84/149/12 88/256/12 89/150/12 561 | f 85/152/12 89/257/12 90/153/12 562 | f 86/155/12 90/258/12 87/156/12 563 | f 87/158/9 91/259/9 92/159/9 564 | f 88/161/7 92/260/7 93/162/7 565 | f 89/164/1 93/261/1 94/165/1 566 | f 90/167/5 94/262/5 91/168/5 567 | f 93/170/12 92/263/12 91/171/12 568 | f 95/173/7 73/179/7 72/174/7 569 | f 58/176/6 73/179/6 95/173/6 570 | f 20/178/19 19/264/19 58/176/19 571 | -------------------------------------------------------------------------------- /Example scenes/Houses/House models/House6.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'SmallHouse 2.blend' 2 | # Material Count: 1 3 | 4 | newmtl Material.002 5 | Ns 96.078431 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.640000 0.640000 0.640000 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.000000 11 | d 1.000000 12 | illum 2 13 | -------------------------------------------------------------------------------- /Example scenes/Houses/House models/House6.obj: -------------------------------------------------------------------------------- 1 | # Blender v2.78 (sub 0) OBJ File: 'SmallHouse 2.blend' 2 | # www.blender.org 3 | mtllib House6.mtl 4 | o Cube_Cube.002 5 | v -0.602511 2.031580 0.723893 6 | v -0.602511 2.044969 0.669412 7 | v -0.602511 1.604321 -0.318354 8 | v -0.602511 0.034607 -0.318354 9 | v -0.602511 0.034607 1.681646 10 | v -0.602511 1.604321 1.681646 11 | v -0.766397 2.050426 0.681646 12 | v -0.446036 2.031580 0.723893 13 | v -0.550903 2.044969 0.669412 14 | v -0.766397 1.531211 -0.482239 15 | v 3.034118 1.531211 -0.482239 16 | v 3.034118 2.050426 0.681646 17 | v 2.870233 1.604321 -0.318354 18 | v 1.688759 0.965499 -0.318354 19 | v 1.688759 0.502083 -0.318354 20 | v 2.345677 0.965499 -0.318354 21 | v 2.870233 0.034607 -0.318354 22 | v 2.870233 0.034607 1.681646 23 | v 1.525867 0.034607 1.681646 24 | v 1.525867 0.034607 1.630396 25 | v 1.061105 0.034607 1.630396 26 | v 1.061105 0.034607 1.681646 27 | v 0.798889 0.034607 1.681646 28 | v 0.798889 0.034607 1.588378 29 | v -0.240685 0.034607 1.588378 30 | v -0.240685 0.034607 1.681646 31 | v -0.240685 0.966986 1.681646 32 | v 0.798889 0.966986 1.681646 33 | v 1.061105 0.034826 1.681646 34 | v 1.059534 0.034826 1.681646 35 | v 1.059534 0.759069 1.681646 36 | v 1.525658 0.759069 1.681646 37 | v 1.688759 0.910039 1.681646 38 | v 1.688759 0.965499 1.681646 39 | v 1.748675 0.965499 1.681646 40 | v 2.870233 1.604321 1.681646 41 | v -0.766397 1.531211 1.845531 42 | v 2.870233 2.049104 0.684609 43 | v 2.870233 2.050063 0.680831 44 | v -0.766397 2.333738 0.681646 45 | v -0.766397 1.814522 -0.482239 46 | v 3.034118 1.814522 -0.482239 47 | v 3.034118 2.333738 0.681646 48 | v 2.345677 0.965499 -0.301554 49 | v 1.688759 0.965499 -0.301554 50 | v 1.688759 0.502083 -0.301554 51 | v 2.345677 0.502083 -0.318354 52 | v 1.525867 0.034752 1.681646 53 | v 1.525658 0.135883 1.630396 54 | v 1.525658 0.135883 1.681646 55 | v 0.798889 0.966986 1.588378 56 | v -0.240685 0.966986 1.588378 57 | v 1.061105 0.034826 1.681646 58 | v 1.059534 0.034826 1.630370 59 | v 1.059534 0.759069 1.630370 60 | v 1.525658 0.759069 1.630370 61 | v 2.777080 0.965499 1.681646 62 | v 2.777080 0.502083 1.681646 63 | v 1.688759 0.502083 1.681646 64 | v 1.525867 0.135883 1.681646 65 | v 1.688759 0.502083 1.651670 66 | v 1.688759 0.965499 1.651670 67 | v 2.777080 0.965499 1.651670 68 | v 3.034118 1.531211 1.845531 69 | v -0.766397 1.814522 1.845531 70 | v -0.404077 2.103067 0.164569 71 | v -0.404077 1.972027 -0.129174 72 | v -0.110334 1.972027 -0.129174 73 | v -0.110334 2.103067 0.164569 74 | v 3.034118 1.814522 1.845531 75 | v 2.345677 0.502083 -0.301554 76 | v 1.525867 0.135883 1.630396 77 | v 1.525658 0.034826 1.630370 78 | v 1.525658 0.034826 1.630396 79 | v 2.777080 0.502083 1.651670 80 | v 0.098202 1.900276 1.653304 81 | v 0.098202 2.185660 1.013581 82 | v 1.823842 2.185660 1.013581 83 | v -0.404077 2.234663 0.164569 84 | v -0.404077 2.234663 -0.129174 85 | v -0.110334 2.234663 -0.129174 86 | v -0.110334 2.234663 0.164569 87 | v 1.823842 1.900276 1.653304 88 | v 0.098202 2.381044 1.653304 89 | v 0.098202 2.517708 1.346955 90 | v 0.098202 2.521991 1.329529 91 | v 0.098202 2.381044 1.013581 92 | v 1.823842 2.381044 1.013581 93 | v -0.420518 2.222652 0.181010 94 | v -0.420518 2.222652 -0.145615 95 | v -0.093893 2.222652 -0.145615 96 | v -0.093893 2.222652 0.181010 97 | v 1.823842 2.523620 1.333182 98 | v 1.823842 2.523314 1.334390 99 | v 1.823842 2.381044 1.653304 100 | v 1.074404 2.013345 1.653304 101 | v 0.875604 2.013345 1.653304 102 | v 0.230828 2.013345 1.653304 103 | v 1.719180 2.345717 1.653304 104 | v 1.719180 2.013345 1.653304 105 | v 1.074404 2.345717 1.653304 106 | v 0.875604 2.345717 1.653304 107 | v 0.230828 2.345717 1.653304 108 | v 0.045781 2.523736 1.333442 109 | v 0.148252 2.517708 1.346955 110 | v 0.114709 2.521991 1.329529 111 | v 1.876262 2.357659 0.961160 112 | v -0.420518 2.461278 0.181010 113 | v -0.420518 2.461278 -0.145615 114 | v -0.093893 2.461278 -0.145615 115 | v -0.093893 2.461278 0.181010 116 | v 1.876262 2.523736 1.333442 117 | v 0.875604 2.013345 1.624011 118 | v 0.230828 2.013345 1.624011 119 | v 0.875604 2.345717 1.624011 120 | v 0.230828 2.345717 1.624011 121 | v 1.876262 2.357659 1.705724 122 | v 0.045781 2.357659 1.705724 123 | v 0.045781 2.357659 0.961160 124 | v -0.373824 2.461278 0.134316 125 | v -0.373824 2.461278 -0.098921 126 | v -0.140587 2.461278 -0.098921 127 | v -0.140587 2.461278 0.134316 128 | v 0.045781 2.448280 1.705724 129 | v 0.045781 2.614357 1.333442 130 | v 0.045781 2.448280 0.961160 131 | v 1.876262 2.448280 0.961160 132 | v 1.876262 2.614357 1.333442 133 | v -0.373824 2.191994 0.134316 134 | v -0.373824 2.191994 -0.098921 135 | v -0.140587 2.191994 -0.098921 136 | v -0.140587 2.191994 0.134316 137 | v 1.876262 2.448280 1.705724 138 | v 1.074404 2.013345 1.624011 139 | v 1.074404 2.345717 1.624011 140 | v 1.719180 2.345717 1.624011 141 | v 1.719180 2.013345 1.624011 142 | vt 0.0469 0.9336 143 | vt 0.0367 0.9395 144 | vt 0.0469 0.9570 145 | vt 0.8446 0.8755 146 | vt 0.8637 0.8663 147 | vt 0.8425 0.8663 148 | vt 0.8640 0.8579 149 | vt 0.8422 0.8796 150 | vt 0.8422 0.8579 151 | vt 0.8637 0.8663 152 | vt 0.8578 0.8589 153 | vt 0.8446 0.8755 154 | vt 0.0447 0.9394 155 | vt 0.0352 0.9570 156 | vt 0.0352 0.9336 157 | vt 0.0586 0.9336 158 | vt 0.0363 0.9444 159 | vt 0.0363 0.9364 160 | vt 0.0467 0.9452 161 | vt 0.0478 0.9464 162 | vt 0.0456 0.9510 163 | vt 0.8422 0.8796 164 | vt 0.8640 0.8579 165 | vt 0.8640 0.8796 166 | vt 0.8626 0.8633 167 | vt 0.8437 0.8633 168 | vt 0.8437 0.8742 169 | vt 0.8640 0.8579 170 | vt 0.8422 0.8796 171 | vt 0.8422 0.8579 172 | vt 0.8640 0.8579 173 | vt 0.8422 0.8796 174 | vt 0.8422 0.8579 175 | vt 0.8422 0.8579 176 | vt 0.8640 0.8796 177 | vt 0.8422 0.8796 178 | vt 0.0676 0.9429 179 | vt 0.0584 0.9431 180 | vt 0.0581 0.9429 181 | vt 0.0577 0.9497 182 | vt 0.0574 0.9500 183 | vt 0.0447 0.9343 184 | vt 0.0586 0.9336 185 | vt 0.0570 0.9512 186 | vt 0.0367 0.9395 187 | vt 0.0367 0.9512 188 | vt 0.0586 0.9500 189 | vt 0.0586 0.9570 190 | vt 0.0586 0.9500 191 | vt 0.0352 0.9500 192 | vt 0.0000 0.0000 193 | vt 0.0000 0.0000 194 | vt 0.0759 0.9073 195 | vt 0.0711 0.9277 196 | vt 0.0698 0.9260 197 | vt 0.0658 0.0997 198 | vt 0.0445 0.1172 199 | vt 0.0385 0.0997 200 | vt 0.0471 0.9081 201 | vt 0.0552 0.9243 202 | vt 0.0539 0.9260 203 | vt 0.0586 0.9464 204 | vt 0.0586 0.9464 205 | vt 0.0586 0.9464 206 | vt 0.0404 0.9402 207 | vt 0.0411 0.9500 208 | vt 0.0404 0.9500 209 | vt 0.0411 0.9563 210 | vt 0.0404 0.9563 211 | vt 0.0523 0.9510 212 | vt 0.0343 0.9345 213 | vt 0.0342 0.9416 214 | vt 0.0331 0.9292 215 | vt 0.0358 0.9299 216 | vt 0.0491 0.9292 217 | vt 0.8437 0.8633 218 | vt 0.8531 0.8796 219 | vt 0.8626 0.8742 220 | vt 0.8422 0.8579 221 | vt 0.8640 0.8796 222 | vt 0.8422 0.8796 223 | vt 0.8574 0.8754 224 | vt 0.8640 0.8796 225 | vt 0.8519 0.8754 226 | vt 0.8640 0.8579 227 | vt 0.8422 0.8796 228 | vt 0.8422 0.8579 229 | vt 0.0669 0.9500 230 | vt 0.0673 0.9432 231 | vt 0.9500 0.0894 232 | vt 0.9250 0.0692 233 | vt 0.9521 0.0693 234 | vt 0.0666 0.9498 235 | vt 0.0000 0.0000 236 | vt 0.0000 0.0000 237 | vt 0.0411 0.9660 238 | vt 0.0411 0.9660 239 | vt 0.0411 0.9646 240 | vt 0.0646 0.0798 241 | vt 0.0322 0.0296 242 | vt 0.0646 0.0296 243 | vt 0.0485 0.9299 244 | vt 0.0489 0.9395 245 | vt 0.0481 0.9389 246 | vt 0.0347 0.9407 247 | vt 0.9395 0.0695 248 | vt 0.9504 0.0788 249 | vt 0.9379 0.0787 250 | vt 0.8640 0.8579 251 | vt 0.8422 0.8796 252 | vt 0.8422 0.8579 253 | vt 0.8640 0.8796 254 | vt 0.8578 0.8629 255 | vt 0.8640 0.8579 256 | vt 0.0426 0.9637 257 | vt 0.0422 0.9643 258 | vt 0.0425 0.9641 259 | vt 0.0435 0.9640 260 | vt 0.0431 0.9637 261 | vt 0.0433 0.9639 262 | vt 0.0438 0.9643 263 | vt 0.0433 0.9637 264 | vt 0.0434 0.9641 265 | vt 0.0427 0.9637 266 | vt 0.0426 0.9640 267 | vt 0.0428 0.9637 268 | vt 0.8458 0.8629 269 | vt 0.8422 0.8796 270 | vt 0.0000 0.0000 271 | vt 0.0000 0.0000 272 | vt 0.0546 0.9595 273 | vt 0.0546 0.9595 274 | vt 0.0546 0.9595 275 | vt 0.0546 0.9595 276 | vt 0.0546 0.9595 277 | vt 0.0434 0.9645 278 | vt 0.0433 0.9644 279 | vt 0.0434 0.9645 280 | vt 0.0427 0.9644 281 | vt 0.0428 0.9644 282 | vt 0.0428 0.9644 283 | vt 0.0424 0.9645 284 | vt 0.0425 0.9645 285 | vt 0.0425 0.9645 286 | vt 0.0434 0.9645 287 | vt 0.0432 0.9645 288 | vt 0.0434 0.9645 289 | vt 0.0485 0.9560 290 | vt 0.0486 0.9560 291 | vt 0.0471 0.9556 292 | vt 0.0543 0.9602 293 | vt 0.0477 0.9581 294 | vt 0.0515 0.9589 295 | vt 0.0514 0.9577 296 | vt 0.0518 0.9578 297 | vt 0.0508 0.9587 298 | vt 0.0542 0.9582 299 | vt 0.0547 0.9582 300 | vt 0.0539 0.9596 301 | vt 0.0555 0.9567 302 | vt 0.0551 0.9566 303 | vt 0.0554 0.9568 304 | vt 0.0551 0.9565 305 | vt 0.0552 0.9549 306 | vt 0.0552 0.9549 307 | vt 0.0478 0.9549 308 | vt 0.0432 0.9658 309 | vt 0.0438 0.9653 310 | vt 0.0435 0.9654 311 | vt 0.0426 0.9656 312 | vt 0.0427 0.9658 313 | vt 0.0429 0.9658 314 | vt 0.0425 0.9654 315 | vt 0.0424 0.9659 316 | vt 0.0428 0.9658 317 | vt 0.0431 0.9658 318 | vt 0.0435 0.9655 319 | vt 0.0433 0.9656 320 | vt 0.0539 0.9595 321 | vt 0.0516 0.9589 322 | vt 0.0541 0.9583 323 | vt 0.0518 0.9578 324 | vt 0.9631 0.9441 325 | vt 0.9626 0.9417 326 | vt 0.9629 0.9443 327 | vt 0.9626 0.9418 328 | vt 0.9790 0.9434 329 | vt 0.0435 0.9658 330 | vt 0.0434 0.9658 331 | vt 0.0435 0.9658 332 | vt 0.0427 0.9658 333 | vt 0.0428 0.9659 334 | vt 0.0428 0.9659 335 | vt 0.0421 0.9657 336 | vt 0.0423 0.9656 337 | vt 0.0423 0.9656 338 | vt 0.0432 0.9656 339 | vt 0.0436 0.9656 340 | vt 0.0436 0.9656 341 | vt 0.9661 0.0211 342 | vt 0.9688 0.0234 343 | vt 0.9657 0.0227 344 | vt 0.9772 0.9462 345 | vt 0.9772 0.9468 346 | vt 0.9780 0.9398 347 | vt 0.9779 0.9432 348 | vt 0.9620 0.9390 349 | vt 0.9783 0.9393 350 | vt 0.9609 0.9389 351 | vt 0.0434 0.9639 352 | vt 0.0433 0.9641 353 | vt 0.0436 0.9643 354 | vt 0.0426 0.9641 355 | vt 0.0429 0.9638 356 | vt 0.0428 0.9638 357 | vt 0.0424 0.9643 358 | vt 0.0428 0.9639 359 | vt 0.0425 0.9639 360 | vt 0.0432 0.9638 361 | vt 0.0432 0.9640 362 | vt 0.0434 0.9641 363 | vt 0.9630 0.9442 364 | vt 0.9629 0.9417 365 | vt 0.0423 0.9647 366 | vt 0.0425 0.9644 367 | vt 0.0424 0.9646 368 | vt 0.0512 0.9577 369 | vt 0.0490 0.9570 370 | vt 0.0490 0.9571 371 | vt 0.9702 0.0221 372 | vt 0.9727 0.0244 373 | vt 0.9696 0.0236 374 | vt 0.0484 0.9580 375 | vt 0.0508 0.9587 376 | vt 0.0485 0.9580 377 | vt 0.0367 0.9512 378 | vt 0.0570 0.9512 379 | vt 0.0570 0.9395 380 | vt 0.8578 0.8589 381 | vt 0.8484 0.8589 382 | vt 0.8616 0.8755 383 | vt 0.8640 0.8796 384 | vt 0.8531 0.8796 385 | vt 0.8616 0.8755 386 | vt 0.8484 0.8589 387 | vt 0.8425 0.8663 388 | vt 0.0516 0.9394 389 | vt 0.0586 0.9570 390 | vt 0.0352 0.9364 391 | vt 0.0352 0.9336 392 | vt 0.0586 0.9570 393 | vt 0.0352 0.9570 394 | vt 0.0352 0.9500 395 | vt 0.0358 0.9500 396 | vt 0.0358 0.9463 397 | vt 0.0352 0.9464 398 | vt 0.0352 0.9444 399 | vt 0.0352 0.9336 400 | vt 0.0586 0.9336 401 | vt 0.0451 0.9368 402 | vt 0.0586 0.9364 403 | vt 0.0447 0.9517 404 | vt 0.0352 0.9570 405 | vt 0.0478 0.9500 406 | vt 0.0455 0.9512 407 | vt 0.0586 0.9444 408 | vt 0.0586 0.9464 409 | vt 0.8422 0.8579 410 | vt 0.8626 0.8742 411 | vt 0.8531 0.8579 412 | vt 0.8640 0.8796 413 | vt 0.8640 0.8796 414 | vt 0.0516 0.9343 415 | vt 0.0469 0.9570 416 | vt 0.0570 0.9395 417 | vt 0.0469 0.9336 418 | vt 0.0000 0.0000 419 | vt 0.0779 0.9080 420 | vt 0.0595 0.1190 421 | vt 0.0494 0.9073 422 | vt 0.0411 0.9402 423 | vt 0.0449 0.9562 424 | vt 0.0571 0.9500 425 | vt 0.0571 0.9500 426 | vt 0.0517 0.9562 427 | vt 0.0341 0.9302 428 | vt 0.8626 0.8633 429 | vt 0.8531 0.8579 430 | vt 0.8437 0.8742 431 | vt 0.8640 0.8579 432 | vt 0.8422 0.8796 433 | vt 0.8519 0.8773 434 | vt 0.8574 0.8773 435 | vt 0.8640 0.8796 436 | vt 0.9229 0.0892 437 | vt 0.0404 0.9646 438 | vt 0.0322 0.0798 439 | vt 0.9513 0.0699 440 | vt 0.8640 0.8796 441 | vt 0.8578 0.8741 442 | vt 0.8458 0.8741 443 | vt 0.0424 0.9637 444 | vt 0.0432 0.9637 445 | vt 0.0435 0.9637 446 | vt 0.0424 0.9640 447 | vt 0.0546 0.9595 448 | vt 0.0546 0.9595 449 | vt 0.0546 0.9595 450 | vt 0.0434 0.9644 451 | vt 0.0427 0.9644 452 | vt 0.0424 0.9645 453 | vt 0.0432 0.9645 454 | vt 0.0487 0.9570 455 | vt 0.0548 0.9581 456 | vt 0.0485 0.9560 457 | vt 0.0556 0.9566 458 | vt 0.0478 0.9547 459 | vt 0.0435 0.9659 460 | vt 0.0424 0.9655 461 | vt 0.0421 0.9653 462 | vt 0.0432 0.9658 463 | vt 0.9772 0.9469 464 | vt 0.9627 0.9417 465 | vt 0.9792 0.9432 466 | vt 0.9781 0.9431 467 | vt 0.9609 0.9393 468 | vt 0.0434 0.9658 469 | vt 0.0427 0.9658 470 | vt 0.0421 0.9657 471 | vt 0.0433 0.9656 472 | vt 0.9692 0.0219 473 | vt 0.0431 0.9639 474 | vt 0.0428 0.9640 475 | vt 0.0427 0.9641 476 | vt 0.0431 0.9638 477 | vt 0.0424 0.9645 478 | vt 0.9733 0.0231 479 | vn -1.0000 0.0000 0.0000 480 | vn 0.0000 -0.9132 -0.4074 481 | vn 0.0000 0.9711 0.2387 482 | vn 0.0000 -0.9132 0.4074 483 | vn 0.0000 0.0000 -1.0000 484 | vn 0.0000 -1.0000 0.0000 485 | vn 0.0000 0.0000 1.0000 486 | vn -0.0023 0.9701 0.2427 487 | vn 0.0000 -0.9132 0.4075 488 | vn 1.0000 0.0000 0.0000 489 | vn -1.0000 -0.0021 0.0000 490 | vn 0.0000 0.9132 -0.4074 491 | vn 0.0000 1.0000 0.0000 492 | vn 0.0000 0.9132 0.4074 493 | vn 0.0005 0.0000 1.0000 494 | vn 0.5899 -0.8075 0.0000 495 | vn 0.0000 -0.8075 0.5899 496 | vn -0.5899 -0.8075 0.0000 497 | vn 0.0000 -0.8075 -0.5899 498 | vn 0.0000 0.9711 0.2386 499 | vn -0.0014 0.9705 0.2413 500 | vn 0.0000 -0.9127 0.4086 501 | vn -0.0022 0.9693 0.2458 502 | vn -0.0000 -0.9133 0.4074 503 | vn 1.0000 0.0001 0.0000 504 | vn 0.0000 -0.9131 -0.4078 505 | vn -0.0014 0.9691 0.2465 506 | vn 0.0000 -0.9133 0.4073 507 | usemtl Material.002 508 | s off 509 | f 4/1/1 5/2/1 1/3/1 510 | f 1/4/2 7/5/2 8/6/2 511 | f 9/7/3 1/8/3 8/9/3 512 | f 10/10/4 11/11/4 3/12/4 513 | f 14/13/5 3/14/5 13/15/5 514 | f 4/16/6 24/17/6 25/18/6 515 | f 28/19/7 31/20/7 34/21/7 516 | f 8/22/8 39/23/8 9/24/8 517 | f 39/25/9 12/26/9 7/27/9 518 | f 41/28/1 7/29/1 40/30/1 519 | f 42/31/5 10/32/5 41/33/5 520 | f 42/34/10 12/35/10 11/36/10 521 | f 16/37/6 45/38/6 14/39/6 522 | f 14/39/10 46/40/10 15/41/10 523 | f 16/42/5 13/15/5 17/43/5 524 | f 38/44/10 17/45/10 13/46/10 525 | f 19/47/7 18/48/7 48/49/7 526 | f 20/50/11 50/51/11 49/52/11 527 | f 24/53/1 28/54/1 51/55/1 528 | f 24/56/7 52/57/7 25/58/7 529 | f 26/59/10 52/60/10 27/61/10 530 | f 27/61/6 51/55/6 28/54/6 531 | f 53/62/7 30/63/7 29/64/7 532 | f 30/65/10 55/66/10 31/67/10 533 | f 31/67/6 56/68/6 32/69/6 534 | f 18/48/7 59/70/7 48/49/7 535 | f 33/71/10 61/72/10 62/73/10 536 | f 35/74/6 62/73/6 63/75/6 537 | f 64/76/2 6/77/2 36/78/2 538 | f 65/79/1 7/80/1 37/81/1 539 | f 68/82/12 42/31/12 41/83/12 540 | f 42/31/12 68/82/12 69/84/12 541 | f 70/85/10 12/86/10 43/87/10 542 | f 47/88/1 44/89/1 16/37/1 543 | f 71/90/5 45/91/5 44/92/5 544 | f 15/41/13 71/93/13 47/88/13 545 | f 50/51/6 72/94/6 60/95/6 546 | f 73/96/1 74/97/1 49/98/1 547 | f 56/99/7 54/100/7 73/101/7 548 | f 57/102/1 75/103/1 58/104/1 549 | f 58/104/13 61/72/13 59/105/13 550 | f 61/106/7 63/107/7 62/108/7 551 | f 65/109/7 64/110/7 70/111/7 552 | f 40/112/14 78/113/14 43/114/14 553 | f 66/115/1 80/116/1 67/117/1 554 | f 80/118/5 68/119/5 67/120/5 555 | f 81/121/10 69/122/10 68/123/10 556 | f 82/124/7 66/125/7 69/126/7 557 | f 83/127/14 65/128/14 70/111/14 558 | f 72/94/15 74/129/15 20/130/15 559 | f 85/131/1 86/132/1 77/133/1 560 | f 87/134/5 78/135/5 77/133/5 561 | f 80/136/16 89/137/16 90/138/16 562 | f 80/139/17 91/140/17 81/141/17 563 | f 81/142/18 92/143/18 82/144/18 564 | f 79/145/19 92/146/19 89/147/19 565 | f 93/148/10 94/149/10 78/150/10 566 | f 76/151/7 83/152/7 97/153/7 567 | f 101/154/7 102/155/7 96/156/7 568 | f 103/157/7 84/158/7 98/159/7 569 | f 104/160/2 105/161/2 85/162/2 570 | f 106/163/20 85/162/20 105/161/20 571 | f 87/164/4 119/165/4 88/166/4 572 | f 89/167/1 109/168/1 90/169/1 573 | f 90/170/5 110/171/5 91/172/5 574 | f 91/173/10 111/174/10 92/175/10 575 | f 92/176/7 108/177/7 89/178/7 576 | f 105/161/21 93/148/21 106/163/21 577 | f 97/153/13 114/179/13 98/159/13 578 | f 102/155/1 113/180/1 97/153/1 579 | f 98/159/10 116/181/10 103/157/10 580 | f 103/157/6 115/182/6 102/155/6 581 | f 95/183/2 112/184/2 117/185/2 582 | f 93/186/22 112/184/22 104/187/22 583 | f 109/188/13 120/189/13 121/190/13 584 | f 109/191/13 122/192/13 110/193/13 585 | f 110/194/13 123/195/13 111/196/13 586 | f 111/197/13 120/198/13 108/199/13 587 | f 114/200/7 115/201/7 116/202/7 588 | f 124/203/1 104/187/1 118/204/1 589 | f 126/205/1 104/187/1 125/206/1 590 | f 127/207/5 119/208/5 126/205/5 591 | f 127/207/10 112/184/10 107/209/10 592 | f 120/210/10 130/211/10 121/212/10 593 | f 121/213/7 131/214/7 122/215/7 594 | f 122/216/1 132/217/1 123/218/1 595 | f 123/219/5 129/220/5 120/221/5 596 | f 133/222/10 112/184/10 128/223/10 597 | f 124/203/7 117/185/7 133/222/7 598 | f 128/223/14 124/203/14 133/222/14 599 | f 127/207/12 125/206/12 128/223/12 600 | f 131/224/13 129/225/13 132/226/13 601 | f 96/156/10 135/227/10 101/154/10 602 | f 101/154/6 136/228/6 99/229/6 603 | f 134/230/7 136/231/7 135/232/7 604 | f 100/233/13 134/234/13 96/156/13 605 | f 99/229/1 137/235/1 100/233/1 606 | f 6/236/1 1/3/1 5/2/1 607 | f 2/237/1 3/238/1 1/3/1 608 | f 4/1/1 1/3/1 3/238/1 609 | f 1/4/2 6/77/2 7/5/2 610 | f 7/5/2 12/239/2 38/240/2 611 | f 38/240/2 8/6/2 7/5/2 612 | f 6/77/2 37/241/2 7/5/2 613 | f 9/7/3 2/242/3 1/8/3 614 | f 3/12/4 2/243/4 7/244/4 615 | f 11/11/4 12/245/4 13/246/4 616 | f 3/12/4 7/244/4 10/10/4 617 | f 11/11/4 13/246/4 3/12/4 618 | f 14/13/5 15/247/5 4/248/5 619 | f 4/248/5 3/14/5 14/13/5 620 | f 13/15/5 16/42/5 14/13/5 621 | f 26/249/6 5/250/6 25/18/6 622 | f 4/16/6 17/251/6 24/17/6 623 | f 18/252/6 19/253/6 20/254/6 624 | f 21/255/6 22/256/6 23/257/6 625 | f 17/251/6 18/252/6 20/254/6 626 | f 21/255/6 23/257/6 24/17/6 627 | f 17/251/6 20/254/6 21/255/6 628 | f 25/18/6 5/250/6 4/16/6 629 | f 17/251/6 21/255/6 24/17/6 630 | f 6/258/7 5/259/7 27/260/7 631 | f 5/259/7 26/261/7 27/260/7 632 | f 35/262/7 36/263/7 34/21/7 633 | f 32/264/7 33/265/7 34/21/7 634 | f 34/21/7 36/263/7 28/19/7 635 | f 6/258/7 27/260/7 28/19/7 636 | f 23/266/7 22/267/7 30/63/7 637 | f 22/267/7 29/64/7 30/63/7 638 | f 36/263/7 6/258/7 28/19/7 639 | f 28/19/7 23/266/7 31/20/7 640 | f 31/20/7 32/264/7 34/21/7 641 | f 23/266/7 30/63/7 31/20/7 642 | f 8/22/23 38/268/23 39/23/23 643 | f 7/27/4 2/243/4 9/269/4 644 | f 39/25/4 13/270/4 12/26/4 645 | f 7/27/24 9/269/24 39/25/24 646 | f 41/28/1 10/271/1 7/29/1 647 | f 42/31/5 11/272/5 10/32/5 648 | f 42/34/10 43/114/10 12/35/10 649 | f 16/37/6 44/89/6 45/38/6 650 | f 14/39/10 45/38/10 46/40/10 651 | f 4/248/5 15/247/5 17/43/5 652 | f 47/273/5 16/42/5 17/43/5 653 | f 17/43/5 15/247/5 47/273/5 654 | f 13/46/25 39/274/25 38/44/25 655 | f 38/44/10 36/275/10 18/276/10 656 | f 18/276/10 17/45/10 38/44/10 657 | f 20/50/11 19/277/11 50/51/11 658 | f 24/53/1 23/278/1 28/54/1 659 | f 24/56/7 51/279/7 52/57/7 660 | f 26/59/10 25/280/10 52/60/10 661 | f 27/61/6 52/60/6 51/55/6 662 | f 30/65/10 54/281/10 55/66/10 663 | f 31/67/6 55/66/6 56/68/6 664 | f 36/263/7 35/262/7 57/282/7 665 | f 36/263/7 57/282/7 18/48/7 666 | f 60/283/7 48/49/7 59/70/7 667 | f 32/264/7 50/284/7 59/70/7 668 | f 59/70/7 33/265/7 32/264/7 669 | f 18/48/7 57/282/7 58/285/7 670 | f 59/70/7 50/284/7 60/283/7 671 | f 18/48/7 58/285/7 59/70/7 672 | f 62/73/10 34/286/10 33/71/10 673 | f 33/71/10 59/105/10 61/72/10 674 | f 63/75/6 57/102/6 35/74/6 675 | f 35/74/6 34/286/6 62/73/6 676 | f 38/287/2 12/288/2 36/78/2 677 | f 64/76/2 37/289/2 6/77/2 678 | f 36/78/2 12/288/2 64/76/2 679 | f 65/79/1 40/290/1 7/80/1 680 | f 41/83/12 40/291/12 66/292/12 681 | f 67/293/12 68/82/12 41/83/12 682 | f 41/83/12 66/292/12 67/293/12 683 | f 66/292/12 40/291/12 69/84/12 684 | f 43/87/12 42/31/12 69/84/12 685 | f 69/84/12 40/291/12 43/87/12 686 | f 70/85/10 64/294/10 12/86/10 687 | f 47/88/1 71/93/1 44/89/1 688 | f 71/90/5 46/295/5 45/91/5 689 | f 15/41/13 46/40/13 71/93/13 690 | f 50/51/6 49/52/6 72/94/6 691 | f 49/98/1 50/296/1 32/69/1 692 | f 56/68/1 73/96/1 49/98/1 693 | f 49/98/1 32/69/1 56/68/1 694 | f 56/99/7 55/297/7 54/100/7 695 | f 57/102/1 63/75/1 75/103/1 696 | f 58/104/13 75/103/13 61/72/13 697 | f 61/106/7 75/298/7 63/107/7 698 | f 65/109/7 37/299/7 64/110/7 699 | f 40/112/14 65/128/14 77/300/14 700 | f 77/300/14 78/113/14 40/112/14 701 | f 65/128/14 76/301/14 77/300/14 702 | f 66/115/1 79/302/1 80/116/1 703 | f 80/118/5 81/303/5 68/119/5 704 | f 81/121/10 82/304/10 69/122/10 705 | f 82/124/7 79/305/7 66/125/7 706 | f 70/111/14 43/114/14 78/113/14 707 | f 83/127/14 76/301/14 65/128/14 708 | f 70/111/14 78/113/14 83/127/14 709 | f 72/94/7 49/52/7 74/129/7 710 | f 77/133/1 76/306/1 84/307/1 711 | f 84/307/1 85/131/1 77/133/1 712 | f 86/132/1 87/134/1 77/133/1 713 | f 87/134/5 88/308/5 78/135/5 714 | f 80/136/16 79/309/16 89/137/16 715 | f 80/139/17 90/310/17 91/140/17 716 | f 81/142/18 91/311/18 92/143/18 717 | f 79/145/19 82/312/19 92/146/19 718 | f 83/152/10 78/150/10 95/313/10 719 | f 88/166/10 93/148/10 78/150/10 720 | f 94/149/10 95/313/10 78/150/10 721 | f 100/233/7 96/156/7 83/152/7 722 | f 97/153/7 98/159/7 76/151/7 723 | f 83/152/7 95/313/7 100/233/7 724 | f 96/156/7 97/153/7 83/152/7 725 | f 95/313/7 99/229/7 100/233/7 726 | f 101/154/7 99/229/7 95/313/7 727 | f 102/155/7 97/153/7 96/156/7 728 | f 101/154/7 95/313/7 102/155/7 729 | f 103/157/7 102/155/7 84/158/7 730 | f 84/158/7 76/151/7 98/159/7 731 | f 102/155/7 95/313/7 84/158/7 732 | f 84/158/2 118/314/2 104/160/2 733 | f 104/160/26 112/315/26 94/149/26 734 | f 94/149/2 105/161/2 104/160/2 735 | f 85/162/2 84/158/2 104/160/2 736 | f 106/163/3 86/316/3 85/162/3 737 | f 87/164/4 86/316/4 104/160/4 738 | f 107/317/4 112/315/4 88/166/4 739 | f 87/164/4 104/160/4 119/165/4 740 | f 107/317/4 88/166/4 119/165/4 741 | f 89/167/1 108/318/1 109/168/1 742 | f 90/170/5 109/319/5 110/171/5 743 | f 91/173/10 110/320/10 111/174/10 744 | f 92/176/7 111/321/7 108/177/7 745 | f 105/161/27 94/149/27 93/148/27 746 | f 97/153/13 113/180/13 114/179/13 747 | f 102/155/1 115/182/1 113/180/1 748 | f 98/159/10 114/179/10 116/181/10 749 | f 103/157/6 116/181/6 115/182/6 750 | f 118/204/2 84/322/2 95/183/2 751 | f 95/183/2 94/323/2 112/184/2 752 | f 117/185/2 118/204/2 95/183/2 753 | f 104/187/28 86/324/28 106/325/28 754 | f 93/186/4 88/326/4 112/184/4 755 | f 104/187/9 106/325/9 93/186/9 756 | f 109/188/13 108/327/13 120/189/13 757 | f 109/191/13 121/328/13 122/192/13 758 | f 110/194/13 122/329/13 123/195/13 759 | f 111/197/13 123/330/13 120/198/13 760 | f 114/200/7 113/331/7 115/201/7 761 | f 124/203/1 125/206/1 104/187/1 762 | f 126/205/1 119/208/1 104/187/1 763 | f 127/207/5 107/209/5 119/208/5 764 | f 127/207/10 128/223/10 112/184/10 765 | f 120/210/10 129/332/10 130/211/10 766 | f 121/213/7 130/333/7 131/214/7 767 | f 122/216/1 131/334/1 132/217/1 768 | f 123/219/5 132/335/5 129/220/5 769 | f 133/222/10 117/185/10 112/184/10 770 | f 124/203/7 118/204/7 117/185/7 771 | f 128/223/14 125/206/14 124/203/14 772 | f 127/207/12 126/205/12 125/206/12 773 | f 131/224/13 130/336/13 129/225/13 774 | f 96/156/10 134/234/10 135/227/10 775 | f 101/154/6 135/227/6 136/228/6 776 | f 134/230/7 137/337/7 136/231/7 777 | f 100/233/13 137/235/13 134/234/13 778 | f 99/229/1 136/228/1 137/235/1 779 | -------------------------------------------------------------------------------- /Example scenes/Houses/House.swift: -------------------------------------------------------------------------------- 1 | // 2 | // House.swift 3 | // mercury 4 | // 5 | // Created by Joshua Knapp on 11/14/15. 6 | // Copyright © 2015 Joshua Knapp. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import simd 11 | 12 | class houseNode:HgOBJNode{ 13 | 14 | init?(x: Float, y: Float, z: Float) { 15 | let idx = random(1, high: 6) 16 | super.init(name:"House" + String(idx)) 17 | type = .textured("House") 18 | scale = float3(x,y,z) //empirically set 19 | rotation = float3(.pi / 2, .pi , 0) //empirically set 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Example scenes/Houses/HouseScene.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MainScene.swift 3 | // Mercury 4 | // 5 | // Created by Joshua Knapp on 12/19/15. 6 | // 7 | // 8 | 9 | import Foundation 10 | import simd 11 | import ModelIO 12 | import MetalKit 13 | 14 | 15 | class HouseScene: HgScene { 16 | 17 | var roads = Roads() 18 | var time:Float = 0 19 | 20 | 21 | override func run() { 22 | print("running main scene") 23 | 24 | rotation = float3(1.4 * .pi, 0, 0.5) 25 | magnification = 1.5 26 | 27 | 28 | //add a ground plane 29 | let floor = HgPlaneNode(width: 5280 * 2, length: 5280 * 2) 30 | floor.diffuseColor = (0.1,0.9,0.1, 1) 31 | floor.ambientColor = (0.3,0.3,0.3,1) 32 | //floor.position = float3(0,0,5) 33 | addChild(floor) 34 | 35 | //add some houses 36 | for i in -5..<5 { 37 | //for i in 0...0{ 38 | if let house = houseNode(x: 5, y: 5, z: 5) { 39 | house.position = float3(Float(i * 50), 0, 5) 40 | addChild(house) 41 | } 42 | } 43 | 44 | //add a road 45 | roads.addSegment(float2(5280, 60), p2:float2(-5280, 60)) 46 | roads.addCars() 47 | addChild(roads) 48 | 49 | 50 | //print(roads) 51 | 52 | //makes a flat background 53 | //skybox.texture = nil 54 | //skybox.ambientColor = (0.29,0.58,0.22,1); 55 | 56 | 57 | //load a mdl skycube 58 | let mdltex = MDLSkyCubeTexture(name: nil, 59 | channelEncoding: .uInt8, 60 | textureDimensions: [Int32(128), Int32(128)], 61 | turbidity: 0, 62 | sunElevation: 1, 63 | upperAtmosphereScattering: 0.5, 64 | groundAlbedo: 0.8) 65 | 66 | mdltex.groundColor = CGColor(red: 1,green: 1,blue: 1,alpha: 1) 67 | 68 | let loader = MTKTextureLoader(device: HgRenderer.device) 69 | 70 | do { 71 | let mtltexture = try loader.newTexture(texture:mdltex) 72 | //print("loaded texture \(name)") 73 | 74 | skybox.texture = mtltexture 75 | } catch let error { 76 | print("Failed to load texture, error \(error)") 77 | } 78 | 79 | skybox.type = .textured("abc") 80 | 81 | //lightPosition = float3(0,0.5,1) 82 | 83 | } 84 | 85 | /* 86 | override func updateScene(_ dt: TimeInterval) { 87 | super.updateScene(dt) 88 | time += Float(dt) 89 | //sunPosition = float3(0, sin(time), cos(time)) 90 | //print(time) 91 | }*/ 92 | 93 | 94 | } 95 | -------------------------------------------------------------------------------- /Example scenes/Houses/Road.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Road.swift 3 | // mercury 4 | // 5 | // Created by Joshua Knapp on 11/14/15. 6 | // Copyright © 2015 Joshua Knapp. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import simd 11 | import Metal 12 | 13 | private let carColors:[float4] = [float4(0.6, 0.9, 0.2, 1.0), float4(0.1, 0.3, 0.9, 1.0), float4(0.2, 0.2, 0.9, 1.0), float4(0.9, 0.1, 0.05, 1.0)] 14 | 15 | class Car:HgNode { 16 | 17 | var path:[HgGraphVertex] = [] 18 | var pathIndex = 0 19 | var acceleration:Float = 4 / 60 / 4 20 | var speed:Float = 0 21 | var maxSpeed:Float = 1 22 | var heading = float2(0,0) 23 | 24 | static var classtexture:MTLTexture? = { 25 | return HgRenderer.loadTexture("Car") 26 | }() 27 | 28 | override var texture:MTLTexture? { get { 29 | return Car.classtexture 30 | } set {}} 31 | 32 | static var defaultVertices:[vertex] = { 33 | let carproto = HgOBJNode(name:"Car1")! 34 | return carproto.vertexData 35 | }() 36 | 37 | weak var currentSegment:RoadSegment! 38 | 39 | init?(startNode:HgGraphVertex, endNode:HgGraphVertex) { 40 | 41 | super.init() 42 | type = .textured("Car") 43 | rotation = float3(0, .pi / 2 , .pi / 2) //empirically set 44 | path = [startNode, endNode] 45 | let i = random(0, high: carColors.count - 1) 46 | let color = carColors[i] 47 | vertexData = Car.defaultVertices 48 | vertexCount = vertexData.count 49 | print("vertices: \(vertexCount)") 50 | for i in 0.. RoadSegment? { 294 | for segment in segments { 295 | if n1 == segment.edge.fromNeighbor && n2 == segment.edge.toNeighbor { 296 | return segment 297 | } 298 | } 299 | return nil 300 | } 301 | 302 | /* 303 | static func segmentForNode(n1:HgGraphVertex, inout i:Int) -> RoadSegment? { 304 | for segment in segments { 305 | if segment.node1 === n1 { 306 | i = 1 307 | return segment 308 | } 309 | else if segment.node2 === n1 { 310 | i = 2 311 | return segment 312 | } 313 | } 314 | print("could not find segment for node!") 315 | return nil 316 | } 317 | */ 318 | 319 | override func rebuffer() { 320 | super.rebuffer() 321 | var c = 0 322 | for s in Roads.segments { 323 | c += s.verticeCount 324 | } 325 | 326 | print("road vertice count is \(myVertexCount), cummulative vertice count is \(c), data has \(vertexData.count)") 327 | } 328 | 329 | } 330 | 331 | class RoadSegment{ 332 | var edge:HgGraphEdge 333 | weak var roads:Roads? 334 | 335 | //var zones = [Zone]() 336 | 337 | var verticeCount:Int = 0 338 | var verticeStartIndex:Int = 0 339 | 340 | var carGenerationRate = 0 341 | var node2CarGenerationRate = 0 342 | var destinations = [HgGraphVertex]() 343 | 344 | var cars = [Car]() 345 | 346 | init(edge:HgGraphEdge){ 347 | self.edge = edge 348 | } 349 | 350 | func addCar(_ car:Car){ 351 | cars.append(car) 352 | } 353 | 354 | func removeCar(_ car:Car){ 355 | for (index,element) in cars.enumerated() { 356 | if car === element { 357 | if cars.remove(at: index) === car { 358 | 359 | } 360 | else { 361 | print("removed wrong car!!") 362 | } 363 | break 364 | } 365 | } 366 | } 367 | 368 | func roadUpdate(_ dt:TimeInterval){ 369 | //print("cars: \(cars.count)") 370 | //print("road update, cg is \(carGenerationRate)") 371 | if carGenerationRate > 0 { 372 | let chance = random(0, high: 10000) 373 | let target = random(0, high: destinations.count - 1) 374 | if chance < carGenerationRate { 375 | //print("rolled") 376 | if let r = roads{ 377 | let car = Car(startNode: edge.fromNeighbor, endNode: destinations[target]) 378 | let car2 = Car(startNode: edge.toNeighbor, endNode: destinations[target]) 379 | //print("about to add a car") 380 | r.addChild(car!) 381 | r.addChild(car2!) 382 | } 383 | } 384 | } 385 | 386 | for car in cars { 387 | car.roadUpdate(dt) 388 | } 389 | } 390 | } 391 | -------------------------------------------------------------------------------- /Hg2DGeometry.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HgGeometry.swift 3 | // mercury 4 | // 5 | // Created by Joshua Knapp on 10/26/15. 6 | // Copyright © 2015 Joshua Knapp. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import simd 11 | 12 | struct HgPolygon { 13 | 14 | ///a set of points that describe the boundary of the polygon in counterclockwise order 15 | var points: [float2] 16 | 17 | let EPSILON:Float = 0.0000000001 18 | 19 | //calculates the area, negative values indicate counterclockwise order 20 | func getArea() -> Float { 21 | let n = points.count 22 | var A:Float = 0 23 | var p = n - 1 24 | for var q in 0.. Bool { 33 | 34 | var Ax:Float, Ay:Float, Bx:Float, By:Float, Cx:Float, Cy:Float, Px:Float, Py:Float 35 | 36 | Ax = contour[V[u]].x 37 | Ay = contour[V[u]].y 38 | 39 | Bx = contour[V[v]].x 40 | By = contour[V[v]].y 41 | 42 | Cx = contour[V[w]].x 43 | Cy = contour[V[w]].y 44 | 45 | if EPSILON > (((Bx-Ax)*(Cy-Ay)) - ((By-Ay)*(Cx-Ax))) { return false} 46 | 47 | 48 | var p = 0 49 | while p < n { 50 | if (p == u) || (p == v) || (p == w) { continue } 51 | Px = contour[V[p]].x 52 | Py = contour[V[p]].y 53 | if insideTriangle(Ax,Ay: Ay,Bx: Bx,By: By,Cx: Cx,Cy: Cy,Px: Px,Py: Py) { return false } 54 | p += 1 55 | } 56 | 57 | return true 58 | } 59 | 60 | ///decides if a point p is inside of the triangle defined by A,B,C 61 | fileprivate func insideTriangle(_ Ax:Float, Ay:Float, Bx:Float, By:Float, Cx:Float, Cy:Float, Px:Float, Py:Float) -> Bool { 62 | 63 | let ax = Cx - Bx; let ay = Cy - By 64 | let bx = Ax - Cx; let by = Ay - Cy 65 | let cx = Bx - Ax; let cy = By - Ay 66 | let apx = Px - Ax; let apy = Py - Ay 67 | let bpx = Px - Bx; let bpy = Py - By 68 | let cpx = Px - Cx; let cpy = Py - Cy 69 | 70 | let aCROSSbp = ax * bpy - ay * bpx 71 | let cCROSSap = cx * apy - cy * apx 72 | let bCROSScp = bx * cpy - by * cpx 73 | 74 | return aCROSSbp >= 0 && bCROSScp >= 0 && cCROSSap >= 0 75 | 76 | } 77 | 78 | func tesselate() -> [float2] { 79 | 80 | var result = [float2]() 81 | 82 | 83 | //make a list of vertices 84 | var V = [Int](repeating: 0, count: points.count) 85 | 86 | //make sure it is counter-clockwise 87 | if 0 < getArea() { 88 | for v in 0..= count {print("error in triangulate loop, count is \(count)"); exit(0)} 105 | 106 | var u = v 107 | if nv <= u { u = 0 } 108 | v = u + 1 109 | if nv <= v { v = 0 } 110 | var w = v + 1 111 | if nv <= w { w = 0 } 112 | 113 | if snip(points, u: u, v: v, w: w, n: nv, V: &V) { 114 | let a = V[u] 115 | let b = V[v] 116 | let c = V[w] 117 | 118 | result += [points[a]] 119 | result += [points[b]] 120 | result += [points[c]] 121 | 122 | var s = v 123 | /* remove v from remaining polygon */ 124 | 125 | for t in v+1.. Float{ 177 | let t2 = t*t 178 | let t3 = t2 * t 179 | return c0 + c1*t + c2*t2 + c3*t3 180 | } 181 | } 182 | 183 | class HgLine { 184 | 185 | ///start point of the line 186 | var p0:float2 187 | ///end point of the line 188 | var p1:float2 189 | 190 | let vector:float2 191 | let straightLength:Float 192 | let angle:Float 193 | let inverseAngle:Float 194 | 195 | init(p0:float2, p1:float2){ 196 | 197 | self.p0 = p0 198 | self.p1 = p1 199 | 200 | vector = (p1 - p0) 201 | straightLength = length(vector) 202 | angle = atan2f(self.vector.y, self.vector.x) 203 | inverseAngle = angle + .pi / 2 204 | } 205 | 206 | func broadenOffset(_ width:Float) -> float2 { 207 | return float2(cos(inverseAngle) * width / 2, sin(inverseAngle) * width / 2) 208 | } 209 | 210 | //takes off length from both ends 211 | func chop(_ length:Float){ 212 | 213 | guard straightLength > length * 2 else {print("tried to chop more off HgLine than there is!");return} 214 | 215 | let offset = float2(cos(angle) * length, sin(angle) * length) 216 | p0 += offset 217 | p1 -= offset 218 | } 219 | 220 | func tesselate(_ width:Float) -> [float2] { 221 | 222 | let offset = broadenOffset(width) 223 | 224 | let a = p0 + offset 225 | let b = p0 - offset 226 | let c = p1 + offset 227 | let d = p1 - offset 228 | 229 | var ret = [float2]() 230 | ret += [a, b, c, c , d, a] 231 | return ret 232 | } 233 | 234 | } 235 | 236 | class HgCircle { 237 | 238 | var center:float2 239 | var radius:Float 240 | 241 | init(center:float2, radius:Float) { 242 | self.center = center 243 | self.radius = radius 244 | } 245 | 246 | func tesselate(_ divisions:Int) -> [float2] { 247 | let angleIncrement = 2 * .pi / Float(divisions) 248 | var angle:Float = 0 249 | var ret = [float2]() 250 | for _ in 0 ..< divisions { 251 | ret += [center, 252 | float2(cos(angle) * radius, sin(angle) * radius), 253 | float2(cos(angle + angleIncrement) * radius, sin(angle + angleIncrement) * radius)] 254 | angle += angleIncrement 255 | } 256 | return ret 257 | } 258 | } 259 | 260 | class HgPlaneNode:HgNode { 261 | 262 | let width:Float 263 | let length:Float 264 | 265 | init(width:Float, length:Float) { 266 | self.width = width 267 | self.length = length 268 | 269 | let x = width 270 | let y = length 271 | 272 | super.init() 273 | 274 | //left wound... 275 | vertexData = Array(repeating: vertex(), count: 6) 276 | 277 | vertexData[0].position = ( x / 2, y / 2, 0) 278 | vertexData[1].position = ( -x / 2, y / 2, 0) 279 | vertexData[2].position = ( -x / 2, -y / 2, 0) 280 | vertexData[3].position = vertexData[2].position 281 | vertexData[4].position = ( x / 2, -y / 2, 0) 282 | vertexData[5].position = vertexData[0].position 283 | for i in 0...5 { 284 | vertexData[i].normal = (0,0,1) 285 | } 286 | vertexCount = 6 287 | 288 | self.updateVertexBuffer() 289 | } 290 | } 291 | -------------------------------------------------------------------------------- /HgGraph.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HgGraph.swift 3 | // Mercury 4 | // 5 | // Created by Joshua Knapp on 3/4/16. 6 | // 7 | // 8 | 9 | import Foundation 10 | import simd 11 | 12 | ///adopt this protocol to be allow entrance into HgGraph. Position will be rounded to nearest Int 13 | protocol HgGraphable { 14 | var position:float2 { get } 15 | } 16 | 17 | class HgGraphVertex:Hashable, CustomStringConvertible{ 18 | 19 | var position = float2(0,0) 20 | var neighbors = Set() 21 | var visited = false 22 | var path:HgGraphPath? 23 | 24 | var description:String { get { return "\(position.x) \(position.y)" } } 25 | 26 | init(position:float2){ 27 | self.position = position 28 | } 29 | 30 | @discardableResult 31 | func addConnection(to destination:HgGraphVertex, twoWay:Bool = true) -> [HgGraphEdge] { 32 | 33 | var ret = [HgGraphEdge]() 34 | let toEdge = HgGraphEdge(from: self, to: destination) 35 | neighbors.insert(toEdge) 36 | ret += [toEdge] 37 | 38 | if twoWay{ 39 | ret += destination.addConnection(to: self, twoWay: false) 40 | } 41 | return ret 42 | } 43 | 44 | func removeConnection(to destination:HgGraphVertex, twoWay:Bool = true) { 45 | neighbors.remove(HgGraphEdge(from:self, to: destination)) 46 | 47 | if twoWay{ 48 | destination.removeConnection(to: self, twoWay: false) 49 | } 50 | 51 | } 52 | 53 | ///conforming to Hashable 54 | var hashValue : Int { 55 | get { 56 | //going to round off to integers because we don't want points to really be any closer anyway 57 | let x = Int(round(position.x)) 58 | let y = Int(round(position.y)) 59 | return "\(x),\(y)".hashValue 60 | } 61 | } 62 | } 63 | 64 | //conforming HgGraphVertex to Equatable 65 | func ==(lhs: HgGraphVertex, rhs: HgGraphVertex) -> Bool { 66 | return lhs.hashValue == rhs.hashValue 67 | } 68 | 69 | 70 | class HgGraphEdge:Hashable { 71 | 72 | unowned var fromNeighbor: HgGraphVertex 73 | unowned var toNeighbor: HgGraphVertex 74 | var weight: Float 75 | var vector: float2 76 | var angle: Float 77 | 78 | init(from:HgGraphVertex, to:HgGraphVertex) { 79 | 80 | toNeighbor = to 81 | fromNeighbor = from 82 | weight = distance_squared(to.position, from.position) 83 | vector = to.position - from.position 84 | angle = atan2f(vector.y, vector.x) 85 | 86 | } 87 | 88 | ///conforming to Hashable 89 | var hashValue : Int { get { return toNeighbor.hashValue } } 90 | 91 | } 92 | 93 | //conforming HgGraphEdge to Equatable 94 | func ==(lhs: HgGraphEdge, rhs: HgGraphEdge) -> Bool { 95 | return lhs.hashValue == rhs.hashValue 96 | } 97 | 98 | enum djError:Error { 99 | case notFound 100 | case unknown 101 | } 102 | 103 | 104 | ///maintains a Set of HgGraphVertex(s) 105 | class HgGraph { 106 | 107 | var canvas = Set() 108 | 109 | ///create a new vertex 110 | func addVertex(_ object:HgGraphable) -> HgGraphVertex{ 111 | let newVertex = HgGraphVertex(position: object.position) 112 | canvas.insert(newVertex) 113 | return newVertex 114 | } 115 | 116 | /// Searches the existing within distance of p1 and p2 and adds a connection if found. If points are not found, new points are created. If a new potential point is within distance of an existing connection line, the new point is moved to be on that line. 117 | /// - parameter distance: Function will not create a new node less than this distance to an existing node 118 | /// - parameter p1, p2: 2D points to add the new connection between 119 | func addConnection(from p1:float2, to p2:float2, twoWay:Bool = true, distance:Float = 16) -> [HgGraphEdge] { 120 | 121 | var node1:HgGraphVertex? 122 | var node2:HgGraphVertex? 123 | 124 | //need mutable values 125 | var point1 = p1 126 | var point2 = p2 127 | 128 | //look for matching nodes 129 | if let n1 = nodeNearPoint(p1, distance: distance) { 130 | node1 = n1 131 | } else { 132 | if let seg = snapToConnection(&point1, distance: distance){ 133 | 134 | node1 = HgGraphVertex(position: point1) 135 | node1!.addConnection(to: seg.toNeighbor) 136 | node1!.addConnection(to: seg.fromNeighbor) 137 | 138 | seg.toNeighbor.removeConnection(to: seg.fromNeighbor) 139 | 140 | canvas.insert(node1!) 141 | } 142 | } 143 | 144 | if let n2 = nodeNearPoint(p2, distance: distance) { 145 | node2 = n2 146 | } else { 147 | if let seg = snapToConnection(&point2, distance: distance){ 148 | 149 | node2 = HgGraphVertex(position: point2) 150 | node2!.addConnection(to: seg.toNeighbor) 151 | node2!.addConnection(to: seg.fromNeighbor) 152 | 153 | seg.toNeighbor.removeConnection(to: seg.fromNeighbor) 154 | 155 | canvas.insert(node2!) 156 | } 157 | } 158 | 159 | //no points near existing points or on connections, so create new one(s) 160 | if let _ = node1 { 161 | } else { 162 | 163 | node1 = HgGraphVertex(position: p1) 164 | canvas.insert(node1!) 165 | } 166 | if let _ = node2 { 167 | } else { 168 | node2 = HgGraphVertex(position: p2) 169 | canvas.insert(node2!) 170 | } 171 | 172 | //need to check for crossing existing edges... 173 | 174 | return node2!.addConnection(to: node1!) 175 | 176 | } 177 | 178 | ///find Dijkstra's shortest path - reference https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm 179 | func dijkstra(from: HgGraphVertex, to: HgGraphVertex) throws -> [HgGraphVertex] { 180 | 181 | var frontier = Set() 182 | for n in canvas { 183 | n.visited = false 184 | n.path = nil 185 | } 186 | 187 | let sourcePath = HgGraphPath(node: from) 188 | sourcePath.distance = 0 189 | from.path = sourcePath 190 | 191 | for edge in from.neighbors { 192 | let path = HgGraphPath(node: edge.toNeighbor) 193 | path.distance = edge.weight 194 | path.previous = sourcePath 195 | edge.toNeighbor.path = path 196 | frontier.insert(edge.toNeighbor) 197 | } 198 | 199 | while !frontier.isEmpty { 200 | for node in frontier { 201 | for edge in node.neighbors { 202 | let dist = edge.weight + node.path!.distance 203 | if let p = edge.toNeighbor.path { 204 | if p.distance > dist { 205 | let newPath = HgGraphPath(node: edge.toNeighbor) 206 | newPath.distance = dist 207 | newPath.previous = node.path! 208 | edge.toNeighbor.path = newPath 209 | } 210 | } else { 211 | let newPath = HgGraphPath(node: edge.toNeighbor) 212 | newPath.distance = dist 213 | newPath.previous = node.path! 214 | edge.toNeighbor.path = newPath 215 | frontier.insert(edge.toNeighbor) 216 | } 217 | } 218 | frontier.remove(node) 219 | } 220 | } 221 | 222 | if let p = to.path { 223 | var retVal = [HgGraphVertex]() 224 | retVal.append(p.node) 225 | while p.previous != nil { 226 | retVal.insert(p.previous!.node, at:0) 227 | } 228 | return retVal 229 | } else { 230 | throw djError.notFound 231 | } 232 | } 233 | 234 | ///returns a vertex within distance of p, if it exists 235 | func nodeNearPoint(_ p:float2, distance:Float = 16) -> HgGraphVertex? { 236 | for vertex in canvas{ 237 | if distance_squared(p, vertex.position) < distance * distance { 238 | //print("found") 239 | return vertex 240 | } 241 | } 242 | return nil 243 | } 244 | 245 | ///moves p to on an edge if it is within a certain distance 246 | func snapToConnection(_ p:inout float2, distance:Float) -> HgGraphEdge? { 247 | 248 | //iterate through all the edges in the graph 249 | for vertex in canvas { 250 | for connection in vertex.neighbors { 251 | //print("segment angle is \(segment.angle)") 252 | let sn1 = connection.toNeighbor 253 | let sn2 = connection.fromNeighbor 254 | let tp = sn1.position 255 | let dp = sn2.position 256 | let rotmat = float4x4(ZRotation: -connection.angle) 257 | let p1 = rotmat * float4(p.x,p.y,1,0) 258 | let n1 = rotmat * float4(tp.x,tp.y, 1, 0) 259 | let n2 = rotmat * float4(dp.x, dp.y, 1, 0) 260 | 261 | //print("p1 is \(p1) n1 is \(n1) n2 is \(n2)") 262 | if n1.x...n2.x ~= p1.x && fabs(p1.y - n1.y) < distance { 263 | //found segment 264 | 265 | let revrotmat = float4x4(ZRotation: connection.angle) 266 | let p2 = revrotmat * float4(p1.x, n1.y, 0, 1) 267 | p.x = p2.x 268 | p.y = p2.y 269 | 270 | return connection 271 | } 272 | } 273 | } 274 | return nil 275 | } 276 | } 277 | 278 | //conforming HgGraphEdge to Equatable 279 | func ==(lhs: HgGraphPath, rhs: HgGraphPath) -> Bool { 280 | return lhs.hashValue == rhs.hashValue 281 | } 282 | 283 | class HgGraphPath:Hashable { 284 | 285 | ///the distance of the path through nodes 286 | var distance: Float = .greatestFiniteMagnitude 287 | var node:HgGraphVertex 288 | var previous: HgGraphPath? 289 | 290 | init(node:HgGraphVertex){ 291 | self.node = node 292 | } 293 | 294 | ///conforming to Hashable 295 | var hashValue : Int { 296 | get { 297 | return "\(String(describing: previous?.hashValue))".hashValue 298 | } 299 | } 300 | } 301 | 302 | -------------------------------------------------------------------------------- /HgIO.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HgIO.swift 3 | // IOSMercury 4 | // 5 | // Created by Joshua Knapp on 8/2/17. 6 | // 7 | 8 | import Foundation 9 | import SceneKit.ModelIO 10 | 11 | class HgOBJNode: HgNode { 12 | 13 | init?(name: String) { 14 | super.init() 15 | var OBJStringContent:String 16 | do { 17 | let urlpath = Bundle.main.path(forResource: name, ofType: "obj") 18 | let url = NSURL.fileURL(withPath: urlpath!) 19 | OBJStringContent = try String(contentsOf: url) 20 | } catch { 21 | print("Could not load OBJ file \(error)") 22 | return 23 | } 24 | 25 | let lines = OBJStringContent.components(separatedBy: CharacterSet.newlines) 26 | 27 | var positions : [(Float, Float, Float)] = [] //x,y,z 28 | var normals : [(Float, Float, Float)] = [] // x,y,z 29 | var uvs : [(Float, Float)] = []// u,v 30 | var faces : [(p:Int, uv:Int, n:Int)] = [] // xyz,uv,n index 31 | 32 | //iterate through lines in file and fill position, normal, and uv array of values. fill faces with indexes of above values. 33 | for line in lines { 34 | if (line.hasPrefix("v ")){//Vertex 35 | let components = line.components(separatedBy: CharacterSet.whitespaces) 36 | positions.append((Float(components[1])!,Float(components[2])!, Float(components[3])! ) ) 37 | } else if (line.hasPrefix("vt ")) {//UV coords 38 | let components = line.components(separatedBy: CharacterSet.whitespaces) 39 | uvs.append((Float(components[1])!,1.0 - Float(components[2])! )) //obj 0,0 is top left, mtl is bottom left 40 | } else if (line.hasPrefix("vn ")) {//Normal coords 41 | let components = line.components(separatedBy: CharacterSet.whitespaces) 42 | normals.append((Float(components[1])!,Float(components[2])!, Float(components[3])! ) ) 43 | } else if (line.hasPrefix("f ")) {//Face with vertices/uv/normals... stunningly OBJ uses 1 based lists 44 | let components = line.components(separatedBy: CharacterSet.whitespaces).dropFirst() 45 | 46 | //this is troubling because faces may be defined in fans or triangles... 47 | //Only do triangles for now 48 | //var indices = [(p:Int, uv:Int, n:Int)]() 49 | for component in components { 50 | let bits = component.components(separatedBy: "/") 51 | let p = Int(bits[0]), uv = Int(bits[1]), n = Int(bits[2]) 52 | faces.append((p! - 1, uv! - 1, n! - 1 )) 53 | // FIXME: get rid of ! 54 | //indices.append((p! - 1, uv! - 1, n! - 1 )) // -1 to turn that OBJ 1 based array into 0 based sensibility 55 | } 56 | /* 57 | // manually generate a triangle-fan 58 | var idx = 1 59 | for _ in 1.. Bool { 157 | return lhs.x == rhs.x && lhs.y == rhs.y 158 | } 159 | 160 | ///Takes degrees, returns radians 161 | public func radians(_ degrees: Float) -> Float { return degrees * .pi / 180.0 } 162 | 163 | ///Returns a random integer between and including the input values 164 | public func random(_ low: Int, high: Int) -> Int { 165 | return Int(arc4random_uniform(UInt32(high - low) + 1) + UInt32(low)) 166 | } 167 | 168 | -------------------------------------------------------------------------------- /HgNode.swift: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // S2Node.swift 4 | // S2SWEngine 5 | // 6 | // Created by Joshua Knapp on 6/7/14. 7 | // Copyright (c) 2014 Joshua Knapp. All rights reserved. 8 | // 9 | 10 | //import Foundation 11 | import Metal 12 | import simd 13 | import MetalKit 14 | 15 | 16 | class HgNode { 17 | 18 | struct vertex { 19 | var position: (x:Float, y:Float, z:Float) = (0, 0, 0) 20 | var normal: (x:Float, y:Float, z:Float) = (0, 0, 1) 21 | 22 | /// (0, 0) is top left, (1, 1) is bottom right 23 | var texture: (u:Float, v:Float) = (0, 0) 24 | //color of the object in shadow 25 | //var ambientColor: (r:Float, g:Float, b:Float, a:Float) = (0.3,0.3,0.3,1) 26 | var ambientColor: (r:Float, g:Float, b:Float, a:Float) = (1.0,1.0,1.0,1) 27 | //color of the object in direct light 28 | //var diffuseColor: (r:Float, g:Float, b:Float, a:Float) = (0.9,0.9,0.9,1) 29 | var diffuseColor: (r:Float, g:Float, b:Float, a:Float) = (0.64,0.64,0.64,1) 30 | } 31 | 32 | struct uniform { 33 | 34 | var modelMatrix: float4x4 = float4x4(scale: float3(1,1,1)) 35 | var projectionMatrix: float4x4 = float4x4(scale: float3(1,1,1)) 36 | var lightMatrix: float4x4 = float4x4(scale: float3(1,1,1)) 37 | var normalMatrix: float3x3 = float3x3(1) 38 | var lightPosition: float3 = float3(0,0,1) 39 | } 40 | 41 | enum nodeType { 42 | case textured(String) 43 | case untextured 44 | } 45 | 46 | 47 | fileprivate(set) var children = [HgNode]() 48 | fileprivate(set) var lights = [HgLightNode]() 49 | 50 | weak var parent:HgNode? { didSet { modelMatrixIsDirty = true } } 51 | 52 | var position = float3(0,0,1) { didSet { modelMatrixIsDirty = true } } 53 | var rotation = float3(0,0,0) { didSet { modelMatrixIsDirty = true } } 54 | var scale = float3(1,1,1) { didSet { modelMatrixIsDirty = true } } 55 | var type:nodeType = .untextured 56 | 57 | var ambientColor:(Float,Float,Float,Float) = (1,1,1,1) { didSet { 58 | for i in 0...size + MemoryLayout.size + MemoryLayout.size 101 | return HgRenderer.device.makeBuffer(length: uniformSize, options: [])! 102 | }() 103 | 104 | lazy var compositionUniformBuffer:MTLBuffer = { 105 | let uniformSize = MemoryLayout.size 106 | return HgRenderer.device.makeBuffer(length: uniformSize, options: [])! 107 | }() 108 | 109 | fileprivate var _texture:MTLTexture? 110 | 111 | var texture:MTLTexture? { get { 112 | 113 | switch type.self { 114 | 115 | case let .textured(tName): 116 | //print("got tname \(tName)") 117 | if let t = _texture { 118 | return t 119 | } else { 120 | _texture = HgRenderer.loadTexture(tName) 121 | return _texture 122 | } 123 | 124 | case .untextured: 125 | print("error: tried to get texture from untextured node") 126 | break 127 | // 128 | } 129 | //print("returning nil") 130 | return nil 131 | 132 | } set { 133 | _texture = newValue 134 | } 135 | } 136 | 137 | 138 | //do we really need this? 139 | var vertexCount:Int = 0 140 | 141 | var vertexData = [vertex]() 142 | var uniforms = uniform() 143 | 144 | //MARK:- graph functions 145 | 146 | func addChild(_ child: HgNode){ 147 | child.parent = self 148 | children.append(child) 149 | } 150 | 151 | func removeFromGraph(){ 152 | if let p = parent { 153 | p.removeChild(self) 154 | } 155 | } 156 | 157 | func removeChild(_ child:HgNode){ 158 | for (index, element) in children.enumerated() { 159 | if element === child { 160 | children.remove(at: index) 161 | break 162 | } 163 | } 164 | } 165 | 166 | // TODO: Do we really want to do this every frame? 167 | func flattenHeirarchy() -> ([HgNode],[HgNode],[HgLightNode]) { 168 | var textured:[HgNode] 169 | var untextured:[HgNode] 170 | switch type { 171 | case .textured: 172 | textured = [self as HgNode] 173 | untextured = [HgNode]() 174 | case .untextured: 175 | untextured = [self as HgNode] 176 | textured = [HgNode]() 177 | } 178 | var lgt = lights 179 | for node in children { 180 | let (a,b,c) = node.flattenHeirarchy() 181 | textured += a 182 | untextured += b 183 | lgt += c 184 | } 185 | return (textured, untextured, lgt) 186 | } 187 | 188 | func updateModelMatrix(){ 189 | 190 | let x = float4x4(XRotation: rotation.x) 191 | let y = float4x4(YRotation: rotation.y) 192 | let z = float4x4(ZRotation: rotation.z) 193 | let t = float4x4(translation: position) 194 | let s = float4x4(scale: scale) 195 | var m = t * s * x * y * z 196 | 197 | if let p = self.parent { 198 | m = p.modelMatrix * m 199 | } 200 | 201 | modelMatrix = m 202 | modelMatrixIsDirty = false 203 | 204 | } 205 | 206 | //MARK:- Render functions 207 | func updateNode(_ dt:TimeInterval){ 208 | if modelMatrixIsDirty { 209 | updateUniformBuffer() 210 | } 211 | for light in lights{ 212 | light.updateNode(1/60) 213 | } 214 | for child in children{ 215 | child.updateNode(1/60) 216 | } 217 | } 218 | 219 | func rebuffer(){ 220 | let dataSize = vertexData.count * MemoryLayout.size(ofValue: vertexData[0]) 221 | vertexBuffer = HgRenderer.device.makeBuffer(bytes: vertexData, length: dataSize, options: [])! 222 | } 223 | 224 | func updateUniformBuffer() { 225 | 226 | updateModelMatrix() 227 | 228 | uniforms.modelMatrix = modelMatrix 229 | uniforms.normalMatrix = float3x3(mat4:modelMatrix) 230 | uniforms.projectionMatrix = scene.projectionMatrix 231 | uniforms.lightPosition = scene.sunPosition 232 | 233 | memcpy(uniformBuffer.contents(), &uniforms, 4 * MemoryLayout.size + MemoryLayout.size + MemoryLayout.size) 234 | } 235 | 236 | func updateVertexBuffer() { 237 | memcpy(vertexBuffer.contents(), &vertexData, MemoryLayout.size(ofValue: vertexData[0]) * vertexData.count) 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /HgRenderer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HgRenderer.swift 3 | // mercury 4 | // 5 | // Created by Joshua Knapp on 11/10/15. 6 | // Copyright © 2015 Joshua Knapp. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import MetalKit 11 | 12 | final class HgRenderer { 13 | 14 | ////////////////////////singleton syntax 15 | static let sharedInstance = HgRenderer() 16 | fileprivate init(){} 17 | //////////////////////////////////////// 18 | 19 | static let device: MTLDevice = MTLCreateSystemDefaultDevice()! 20 | static let library = device.makeDefaultLibrary()! 21 | static let commandQueue = device.makeCommandQueue() 22 | 23 | var view:MTKView? = nil { 24 | didSet { 25 | view!.depthStencilPixelFormat = .depth32Float_stencil8 26 | view!.colorPixelFormat = .bgra8Unorm 27 | view!.sampleCount = 1 28 | view!.clearColor = MTLClearColorMake(0.8, 0.8, 0.8, 1.0) 29 | } 30 | } 31 | 32 | ///Vertex buffer for drawing full screen quads 33 | lazy var quadVertexBuffer:MTLBuffer = { 34 | var quadVerts = Array(repeating: quadVertex(), count: 6) 35 | quadVerts[0].position = (1,1) // top right 36 | quadVerts[0].texture = (1,1) 37 | quadVerts[1].position = (-1,1) // top left 38 | quadVerts[1].texture = (0,1) 39 | quadVerts[2].position = (-1,-1) // bottom left 40 | quadVerts[2].texture = (0,0) 41 | quadVerts[3] = quadVerts[2] 42 | quadVerts[4].position = (1,-1) // bottom right 43 | quadVerts[4].texture = (1,0) 44 | quadVerts[5] = quadVerts[0] 45 | 46 | return HgRenderer.device.makeBuffer(bytes: quadVerts,length:MemoryLayout.size * 24,options:[])! 47 | }() 48 | 49 | struct quadVertex { 50 | var position: (x:Float, y:Float) = (0, 0) 51 | var texture: (u:Float, v:Float) = (0, 0) 52 | } 53 | 54 | //MARK:- Rendering 55 | func renderShadowBuffer(nodes:[HgNode]) { 56 | //not yet implemented 57 | } 58 | 59 | func renderGBuffer(texturedNodes:[HgNode], untexturedNodes:[HgNode], box:HgSkyboxNode, commandBuffer:MTLCommandBuffer) { 60 | 61 | let encoder = commandBuffer.makeRenderCommandEncoder(descriptor: gBufferRenderPassDescriptor)! 62 | encoder.label = "g buffer" 63 | encoder.setDepthStencilState(gBufferDepthStencilState) 64 | encoder.setCullMode(.back) 65 | 66 | //encoder.pushDebugGroup("skybox") 67 | 68 | encoder.setVertexBuffer(box.vertexBuffer, offset: 0, index: 0) 69 | encoder.setVertexBuffer(box.uniformBuffer, offset: 0, index: 1) 70 | 71 | if let sbt = box.texture { 72 | encoder.setRenderPipelineState(skyboxRenderPipeline) 73 | encoder.setFragmentTexture(sbt, index: 0) 74 | } 75 | else { 76 | encoder.setRenderPipelineState(skyboxRenderPipelineUntextured) 77 | //encoder.setFragmentTexture(skyboxTexture, atIndex: 0) 78 | } 79 | 80 | encoder.drawPrimitives(type: .triangle, vertexStart: 0, vertexCount: box.vertexCount) 81 | 82 | encoder.setRenderPipelineState(texturedGBufferRenderPipeline) 83 | for node in texturedNodes { 84 | guard node.vertexCount > 0 else { continue } 85 | encoder.setVertexBuffer(node.vertexBuffer, offset: 0, index: 0) 86 | encoder.setVertexBuffer(node.uniformBuffer, offset: 0, index: 1) 87 | //print(node.texture) 88 | encoder.setFragmentTexture(node.texture, index: 0) 89 | encoder.drawPrimitives(type: .triangle, vertexStart: 0, vertexCount: node.vertexCount) 90 | } 91 | 92 | encoder.setRenderPipelineState(gBufferRenderPipeline) 93 | for node in untexturedNodes { 94 | guard node.vertexCount > 0 else { continue } 95 | encoder.setVertexBuffer(node.vertexBuffer, offset: 0, index: 0) 96 | encoder.setVertexBuffer(node.uniformBuffer, offset: 0, index: 1) 97 | encoder.drawPrimitives(type: .triangle, vertexStart: 0, vertexCount: node.vertexCount) 98 | } 99 | encoder.popDebugGroup() 100 | encoder.endEncoding() 101 | } 102 | 103 | func renderLightBuffer(lights:[HgLightNode], commandBuffer:MTLCommandBuffer) { 104 | let encoder = commandBuffer.makeRenderCommandEncoder(descriptor: lightBufferRenderPassDescriptor)! 105 | encoder.label = "light" 106 | //encoder.setDepthStencilState(lightBufferDepthStencilState) 107 | encoder.pushDebugGroup("lightBuffer") 108 | encoder.setRenderPipelineState(lightBufferRenderPipeline) 109 | 110 | encoder.setFragmentTexture(gBufferNormalTexture, index: 0) 111 | encoder.setFragmentTexture(gBufferModelPositionTexture, index: 1) 112 | //encoder.setCullMode(.Front) 113 | 114 | for node in lights { 115 | guard node.vertexCount > 0 else { continue } 116 | encoder.setVertexBuffer(node.vertexBuffer, offset: 0, index: 0) 117 | encoder.setVertexBuffer(node.uniformBuffer, offset: 0, index: 1) 118 | encoder.setFragmentBuffer(node.lightDataBuffer, offset: 0, index: 0) 119 | encoder.drawPrimitives(type: .triangle, vertexStart: 0, vertexCount: 12) 120 | } 121 | encoder.popDebugGroup() 122 | encoder.endEncoding() 123 | } 124 | 125 | func renderCompositeBuffer(box:HgSkyboxNode, commandBuffer:MTLCommandBuffer){ 126 | let renderEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: compositionRenderPassDescriptor)! 127 | renderEncoder.label = "composition" 128 | renderEncoder.setRenderPipelineState(compositionRenderPipeline) 129 | renderEncoder.setDepthStencilState(compositeDepthStencilState) 130 | renderEncoder.setVertexBuffer(quadVertexBuffer, offset: 0, index: 0) 131 | renderEncoder.setVertexBuffer(box.scene.uniformBuffer, offset: 0, index: 1) //just getting the light data 132 | renderEncoder.setFragmentTexture(gBufferAlbedoTexture, index: 0) 133 | renderEncoder.setFragmentTexture(lightBufferTexture, index: 1) 134 | renderEncoder.setFragmentTexture(gBufferNormalTexture, index: 2) 135 | renderEncoder.drawPrimitives(type: .triangle, vertexStart:0, vertexCount:6) 136 | renderEncoder.endEncoding() 137 | } 138 | 139 | func renderPostBuffer(commandBuffer:MTLCommandBuffer, renderPassDescriptor:MTLRenderPassDescriptor){ 140 | let renderEncoder2 = commandBuffer.makeRenderCommandEncoder(descriptor: renderPassDescriptor)! 141 | renderEncoder2.label = "post process" 142 | renderEncoder2.setRenderPipelineState(postRenderPipeline) 143 | renderEncoder2.setVertexBuffer(quadVertexBuffer, offset: 0, index: 0) 144 | renderEncoder2.setVertexBuffer(uniformBuffer, offset: 0, index:1) 145 | renderEncoder2.setFragmentTexture(compositionTexture, index: 0) 146 | renderEncoder2.drawPrimitives(type: .triangle, vertexStart:0, vertexCount:6) 147 | renderEncoder2.endEncoding() 148 | } 149 | 150 | lazy var uniformBuffer:MTLBuffer = { 151 | let uniformSize = 2 * MemoryLayout.size 152 | let buffer = HgRenderer.device.makeBuffer(length: uniformSize, options: [])! 153 | 154 | struct sizeStruct { 155 | let width:Float 156 | let height:Float 157 | } 158 | 159 | guard let v = self.view else {fatalError("did not set viewWidth and viewHeight for renderer")} 160 | 161 | let x = Float(v.frame.size.width) 162 | let y = Float(v.frame.size.height) 163 | //print("supplied \(x) and \(y)") 164 | 165 | var ss = sizeStruct(width: x, height: y) 166 | memcpy(buffer.contents(), &ss, MemoryLayout.size * 2) 167 | return buffer 168 | }() 169 | 170 | func render(texturedNodes:[HgNode], untexturedNodes:[HgNode], box:HgSkyboxNode, lights:[HgLightNode]){ 171 | 172 | guard let v = HgRenderer.sharedInstance.view else {print("could not get view"); return} 173 | //guard let renderPassDescriptor = v.currentRenderPassDescriptor else { print("could not get rpd");return } 174 | 175 | //dispatch_semaphore_wait(inflightSemaphore, DISPATCH_TIME_FOREVER) 176 | 177 | let commandBuffer = HgRenderer.commandQueue!.makeCommandBuffer()! 178 | 179 | // 1st pass (shadow depth texture pass) 180 | renderShadowBuffer(nodes: untexturedNodes) 181 | 182 | // 2nd pass (gbuffer) 183 | renderGBuffer(texturedNodes:texturedNodes, untexturedNodes:untexturedNodes, box:box, commandBuffer: commandBuffer) 184 | 185 | // 3rd pass (light buffer) 186 | renderLightBuffer(lights:lights, commandBuffer: commandBuffer) 187 | 188 | // 4th pass (composition) 189 | renderCompositeBuffer(box:box, commandBuffer: commandBuffer) 190 | 191 | //5th pass (post process) 192 | renderPostBuffer(commandBuffer: commandBuffer, renderPassDescriptor: viewRenderPassDescriptor) 193 | 194 | commandBuffer.present(v.currentDrawable!) 195 | commandBuffer.commit() 196 | 197 | } 198 | 199 | //MARK:- Textures 200 | fileprivate lazy var zBufferTexture: MTLTexture = { 201 | guard let v = self.view else {fatalError("did not set viewWidth and viewHeight for renderer")} 202 | let x = Int(v.frame.size.width) 203 | let y = Int(v.frame.size.height) 204 | let zbufferTextureDescriptor = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: MTLPixelFormat.depth32Float, width: x, height: y, mipmapped: false) 205 | zbufferTextureDescriptor.usage = [.renderTarget, .shaderRead] 206 | zbufferTextureDescriptor.storageMode = .private 207 | return HgRenderer.device.makeTexture(descriptor: zbufferTextureDescriptor)! 208 | }() 209 | 210 | fileprivate lazy var gBufferAlbedoTexture: MTLTexture = { 211 | guard let v = self.view else {fatalError("did not set viewWidth and viewHeight for renderer")} 212 | let x = Int(v.frame.size.width) 213 | let y = Int(v.frame.size.height) 214 | 215 | let descriptor = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: .rgba8Unorm, width: x, height: y, mipmapped: false) 216 | descriptor.sampleCount = 1 217 | descriptor.storageMode = .private 218 | descriptor.textureType = .type2D 219 | descriptor.usage = [.renderTarget, .shaderRead] 220 | 221 | return HgRenderer.device.makeTexture(descriptor: descriptor)! 222 | }() 223 | 224 | fileprivate lazy var gBufferNormalTexture: MTLTexture = { 225 | guard let v = self.view else {fatalError("did not set viewWidth and viewHeight for renderer")} 226 | let x = Int(v.frame.size.width) 227 | let y = Int(v.frame.size.height) 228 | 229 | let descriptor = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: .rgba16Float, width: x, height: y, mipmapped: false) 230 | descriptor.sampleCount = 1 231 | descriptor.storageMode = .private 232 | descriptor.textureType = .type2D 233 | descriptor.usage = [.renderTarget, .shaderRead] 234 | 235 | return HgRenderer.device.makeTexture(descriptor: descriptor)! 236 | }() 237 | 238 | fileprivate lazy var gBufferModelPositionTexture: MTLTexture = { 239 | guard let v = self.view else {fatalError("did not set viewWidth and viewHeight for renderer")} 240 | let x = Int(v.frame.size.width) 241 | let y = Int(v.frame.size.height) 242 | 243 | let descriptor = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: .rgba16Float, width: x, height: y, mipmapped: false) 244 | descriptor.sampleCount = 1 245 | descriptor.storageMode = .private 246 | descriptor.textureType = .type2D 247 | descriptor.usage = [.renderTarget, .shaderRead] 248 | 249 | return HgRenderer.device.makeTexture(descriptor: descriptor)! 250 | }() 251 | 252 | fileprivate lazy var lightBufferTexture: MTLTexture = { 253 | guard let v = self.view else {fatalError("did not set viewWidth and viewHeight for renderer")} 254 | let x = Int(v.frame.size.width) 255 | let y = Int(v.frame.size.height) 256 | 257 | let descriptor = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: .bgra8Unorm, width: x, height: y, mipmapped: false) 258 | descriptor.sampleCount = 1 259 | descriptor.storageMode = .private 260 | descriptor.textureType = .type2D 261 | descriptor.usage = [.renderTarget, .shaderRead] 262 | 263 | return HgRenderer.device.makeTexture(descriptor: descriptor)! 264 | }() 265 | 266 | fileprivate lazy var compositionTexture: MTLTexture = { 267 | guard let v = self.view else {fatalError("did not set viewWidth and viewHeight for renderer")} 268 | let x = Int(v.frame.size.width) 269 | let y = Int(v.frame.size.height) 270 | 271 | let descriptor = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: .bgra8Unorm, width: x, height: y, mipmapped: false) 272 | descriptor.sampleCount = 1 273 | descriptor.storageMode = .private 274 | descriptor.textureType = .type2D 275 | descriptor.usage = [.renderTarget, .shaderRead] 276 | 277 | return HgRenderer.device.makeTexture(descriptor: descriptor)! 278 | }() 279 | 280 | fileprivate lazy var gBufferDepthTexture: MTLTexture = { 281 | guard let v = self.view else {fatalError("did not set viewWidth and viewHeight for renderer")} 282 | let x = Int(v.frame.size.width) 283 | let y = Int(v.frame.size.height) 284 | 285 | let descriptor = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: .depth32Float, width: x, height: y, mipmapped: false) 286 | descriptor.sampleCount = 1 287 | descriptor.storageMode = .private 288 | descriptor.textureType = .type2D 289 | descriptor.usage = [.renderTarget, .shaderRead] 290 | 291 | return HgRenderer.device.makeTexture(descriptor: descriptor)! 292 | }() 293 | 294 | static func loadTexture(_ name:String) -> MTLTexture? { 295 | if let url = Bundle.main.url(forResource: name, withExtension: ".png"){ 296 | let loader = MTKTextureLoader(device: HgRenderer.device) 297 | 298 | do { 299 | let texture = try loader.newTexture(URL: url, options:nil) 300 | print("loaded texture \(name)") 301 | return texture 302 | } catch let error { 303 | print("Failed to load texture, error \(error)") 304 | 305 | } 306 | } 307 | return nil 308 | } 309 | 310 | //MARK: Depth and stencil states 311 | fileprivate lazy var shadowDepthStencilState:MTLDepthStencilState = { 312 | let desc = MTLDepthStencilDescriptor() 313 | desc.isDepthWriteEnabled = true 314 | desc.depthCompareFunction = .lessEqual 315 | return HgRenderer.device.makeDepthStencilState(descriptor: desc)! 316 | }() 317 | 318 | fileprivate lazy var gBufferDepthStencilState:MTLDepthStencilState = { 319 | let desc = MTLDepthStencilDescriptor() 320 | desc.isDepthWriteEnabled = true 321 | desc.depthCompareFunction = .lessEqual 322 | return HgRenderer.device.makeDepthStencilState(descriptor: desc)! 323 | }() 324 | 325 | fileprivate lazy var compositeDepthStencilState:MTLDepthStencilState = { 326 | let desc = MTLDepthStencilDescriptor() 327 | desc.isDepthWriteEnabled = false 328 | desc.depthCompareFunction = .always 329 | return HgRenderer.device.makeDepthStencilState(descriptor: desc)! 330 | }() 331 | 332 | 333 | //MARK: Render pass descriptors 334 | fileprivate lazy var shadowRenderPassDescriptor: MTLRenderPassDescriptor = { 335 | let descriptor = MTLRenderPassDescriptor() 336 | descriptor.depthAttachment.texture = HgRenderer.sharedInstance.zBufferTexture 337 | descriptor.depthAttachment.loadAction = .clear; 338 | descriptor.depthAttachment.storeAction = .store; 339 | descriptor.depthAttachment.clearDepth = 1.0 340 | return descriptor 341 | }() 342 | 343 | fileprivate lazy var gBufferRenderPassDescriptor: MTLRenderPassDescriptor = { 344 | let desc = MTLRenderPassDescriptor() 345 | let color = desc.colorAttachments[0] 346 | color?.clearColor = MTLClearColorMake(0,0,0,1) 347 | color?.texture = HgRenderer.sharedInstance.gBufferAlbedoTexture 348 | color?.loadAction = .clear 349 | color?.storeAction = .store 350 | let color2 = desc.colorAttachments[1] 351 | color2?.texture = HgRenderer.sharedInstance.gBufferNormalTexture 352 | color2?.loadAction = .clear 353 | color2?.storeAction = .store 354 | let color3 = desc.colorAttachments[2] 355 | color3?.texture = HgRenderer.sharedInstance.gBufferModelPositionTexture 356 | color3?.loadAction = .clear 357 | color3?.storeAction = .store 358 | 359 | let depth = desc.depthAttachment 360 | depth?.loadAction = .clear 361 | depth?.storeAction = .store 362 | depth?.texture = HgRenderer.sharedInstance.gBufferDepthTexture 363 | depth?.clearDepth = 1.0 364 | return desc 365 | }() 366 | 367 | fileprivate lazy var lightBufferRenderPassDescriptor: MTLRenderPassDescriptor = { 368 | let desc = MTLRenderPassDescriptor() 369 | let color = desc.colorAttachments[0] 370 | color?.clearColor = MTLClearColorMake(0,0,0,1) 371 | color?.texture = HgRenderer.sharedInstance.lightBufferTexture 372 | color?.loadAction = .clear 373 | color?.storeAction = .store 374 | return desc 375 | }() 376 | 377 | fileprivate lazy var compositionRenderPassDescriptor: MTLRenderPassDescriptor = { 378 | let desc = MTLRenderPassDescriptor() 379 | let color = desc.colorAttachments[0] 380 | color?.clearColor = MTLClearColorMake(0,0,0,1) 381 | color?.texture = HgRenderer.sharedInstance.compositionTexture 382 | color?.loadAction = .clear 383 | color?.storeAction = .store 384 | return desc 385 | }() 386 | 387 | fileprivate var viewRenderPassDescriptor: MTLRenderPassDescriptor{ 388 | //guard let v = HgRenderer.sharedInstance.view else {print("could not get view"); return} 389 | return HgRenderer.sharedInstance.view!.currentRenderPassDescriptor! 390 | } 391 | 392 | 393 | //MARK: Pipelines 394 | 395 | fileprivate static func makeRenderPipelineState(type:String, withDescriptor desc:MTLRenderPipelineDescriptor) -> MTLRenderPipelineState { 396 | var state:MTLRenderPipelineState 397 | do { 398 | try state = HgRenderer.device.makeRenderPipelineState(descriptor: desc) 399 | } catch let error { 400 | fatalError("Failed to create \(type) pipeline state, error \(error)") 401 | } 402 | return state 403 | } 404 | 405 | fileprivate lazy var skyboxRenderPipeline:MTLRenderPipelineState = { 406 | let desc = MTLRenderPipelineDescriptor() 407 | desc.colorAttachments[0].pixelFormat = .rgba8Unorm; 408 | desc.colorAttachments[1].pixelFormat = .rgba16Float; 409 | desc.colorAttachments[2].pixelFormat = .rgba16Float; 410 | desc.depthAttachmentPixelFormat = .depth32Float; 411 | desc.sampleCount = 1 412 | desc.label = "Skybox Render" 413 | desc.vertexFunction = HgRenderer.library.makeFunction(name: "skyboxVert") 414 | desc.fragmentFunction = HgRenderer.library.makeFunction(name: "skyboxFrag") 415 | 416 | return HgRenderer.makeRenderPipelineState(type: "skybox", withDescriptor: desc) 417 | }() 418 | 419 | fileprivate lazy var skyboxRenderPipelineUntextured:MTLRenderPipelineState = { 420 | let desc = MTLRenderPipelineDescriptor() 421 | desc.colorAttachments[0].pixelFormat = .rgba8Unorm; 422 | desc.colorAttachments[1].pixelFormat = .rgba16Float; 423 | desc.colorAttachments[2].pixelFormat = .rgba16Float; 424 | desc.depthAttachmentPixelFormat = .depth32Float; 425 | desc.sampleCount = 1 426 | desc.label = "Skybox Render" 427 | desc.vertexFunction = HgRenderer.library.makeFunction(name: "skyboxVert") 428 | desc.fragmentFunction = HgRenderer.library.makeFunction(name: "skyboxFragUntextured") 429 | 430 | return HgRenderer.makeRenderPipelineState(type: "skybox untextured", withDescriptor: desc) 431 | }() 432 | 433 | 434 | fileprivate lazy var gBufferRenderPipeline:MTLRenderPipelineState = { 435 | let desc = MTLRenderPipelineDescriptor() 436 | desc.colorAttachments[0].pixelFormat = .rgba8Unorm; 437 | desc.colorAttachments[1].pixelFormat = .rgba16Float; 438 | desc.colorAttachments[2].pixelFormat = .rgba16Float; 439 | desc.depthAttachmentPixelFormat = .depth32Float; 440 | desc.sampleCount = 1 441 | desc.label = "gBuffer Render" 442 | desc.vertexFunction = HgRenderer.library.makeFunction(name: "gBufferVert") 443 | desc.fragmentFunction = HgRenderer.library.makeFunction(name: "gBufferFrag") 444 | 445 | return HgRenderer.makeRenderPipelineState(type: "gBuffer", withDescriptor: desc) 446 | }() 447 | 448 | fileprivate lazy var lightBufferRenderPipeline:MTLRenderPipelineState = { 449 | let desc = MTLRenderPipelineDescriptor() 450 | 451 | let color = desc.colorAttachments[0] 452 | color?.isBlendingEnabled = true 453 | color?.rgbBlendOperation = .add 454 | color?.alphaBlendOperation = .add 455 | color?.pixelFormat = .bgra8Unorm 456 | color?.sourceRGBBlendFactor = .one 457 | color?.sourceAlphaBlendFactor = .one 458 | color?.destinationAlphaBlendFactor = .one 459 | color?.destinationRGBBlendFactor = .one 460 | 461 | desc.label = "light Pipeline" 462 | 463 | desc.vertexFunction = HgRenderer.library.makeFunction(name: "lightVert") 464 | desc.fragmentFunction = HgRenderer.library.makeFunction(name: "lightFrag") 465 | 466 | return HgRenderer.makeRenderPipelineState(type: "light", withDescriptor: desc) 467 | }() 468 | 469 | fileprivate lazy var compositionRenderPipeline:MTLRenderPipelineState = { 470 | let desc = MTLRenderPipelineDescriptor() 471 | desc.colorAttachments[0].pixelFormat = .bgra8Unorm; 472 | desc.label = "Composition Render" 473 | desc.vertexFunction = HgRenderer.library.makeFunction(name: "compositionVert") 474 | desc.fragmentFunction = HgRenderer.library.makeFunction(name: "compositionFrag") 475 | desc.sampleCount = 1 476 | 477 | return HgRenderer.makeRenderPipelineState(type: "composite", withDescriptor: desc) 478 | }() 479 | 480 | fileprivate lazy var postRenderPipeline:MTLRenderPipelineState = { 481 | let desc = MTLRenderPipelineDescriptor() 482 | desc.colorAttachments[0].pixelFormat = .bgra8Unorm; 483 | desc.depthAttachmentPixelFormat = .depth32Float_stencil8 484 | desc.stencilAttachmentPixelFormat = .depth32Float_stencil8 485 | 486 | desc.label = "Post Render" 487 | desc.vertexFunction = HgRenderer.library.makeFunction(name: "postVert") 488 | desc.fragmentFunction = HgRenderer.library.makeFunction(name: "postFrag") 489 | desc.sampleCount = 1 490 | 491 | return HgRenderer.makeRenderPipelineState(type: "post", withDescriptor: desc) 492 | }() 493 | 494 | fileprivate lazy var spriteRenderPipeline:MTLRenderPipelineState = { 495 | let desc = MTLRenderPipelineDescriptor() 496 | desc.label = "Fairy Render" 497 | desc.vertexFunction = HgRenderer.library.makeFunction(name: "fairyVert") 498 | desc.fragmentFunction = HgRenderer.library.makeFunction(name: "fairyFrag") 499 | 500 | return HgRenderer.makeRenderPipelineState(type: "sprite", withDescriptor: desc) 501 | }() 502 | 503 | fileprivate lazy var texturedGBufferRenderPipeline:MTLRenderPipelineState = { 504 | let desc = MTLRenderPipelineDescriptor() 505 | desc.colorAttachments[0].pixelFormat = .rgba8Unorm; 506 | desc.colorAttachments[1].pixelFormat = .rgba16Float; 507 | desc.colorAttachments[2].pixelFormat = .rgba16Float; 508 | desc.depthAttachmentPixelFormat = .depth32Float; 509 | desc.sampleCount = 1 510 | desc.label = "gBuffer Render" 511 | desc.vertexFunction = HgRenderer.library.makeFunction(name: "gBufferVert") 512 | desc.fragmentFunction = HgRenderer.library.makeFunction(name: "texturedGBufferFrag") 513 | 514 | return HgRenderer.makeRenderPipelineState(type: "texturedGBuffer", withDescriptor: desc) 515 | }() 516 | 517 | fileprivate lazy var shadowRenderPipeline:MTLRenderPipelineState = { 518 | let desc = MTLRenderPipelineDescriptor() 519 | desc.label = "Shadow Render Pipeleine" 520 | desc.vertexFunction = HgRenderer.library.makeFunction(name: "zOnly") 521 | desc.fragmentFunction = nil 522 | desc.depthAttachmentPixelFormat = HgRenderer.sharedInstance.zBufferTexture.pixelFormat 523 | 524 | return HgRenderer.makeRenderPipelineState(type: "shadow", withDescriptor: desc) 525 | }() 526 | 527 | 528 | 529 | } 530 | 531 | 532 | -------------------------------------------------------------------------------- /HgScene.swift: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // HgSceneNode.swift 4 | // mercury 5 | // 6 | // Created by Joshua Knapp on 2/20/15. 7 | // Copyright (c) 2015 Joshua Knapp. All rights reserved. 8 | // 9 | 10 | import GLKit 11 | import MetalKit 12 | import simd 13 | 14 | protocol HgViewController:class { } 15 | 16 | class HgScene: HgNode { 17 | 18 | fileprivate(set) var skybox = HgSkyboxNode(size:1000) 19 | 20 | var projectionMatrix = float4x4(1) 21 | var projectionMatrixIsDirty = true 22 | 23 | var sunPosition = float3(0,0.5,-1) 24 | //var lightPosition = float3(0,0.5,-1) 25 | 26 | override var scene:HgScene { get { return self } } // scene doesn't have a scene 27 | override var parent:HgNode? { get { return nil } set {} } // scene doesn't have a parent 28 | 29 | 30 | override var modelMatrixIsDirty: Bool{ 31 | didSet { 32 | 33 | for child in children { 34 | child.modelMatrixIsDirty = true 35 | } 36 | 37 | skybox.modelMatrixIsDirty = true 38 | } 39 | } 40 | 41 | weak var view:MTKView? 42 | 43 | var magnification:Float = 1 { didSet { modelMatrixIsDirty = true } } 44 | 45 | /// below this value shadows will not be shown 46 | var minMagnificationForShadows:Float = 0.5 47 | weak var controller:HgViewController? 48 | 49 | ///run is the place to load custom content into the scene graph 50 | func run(){ 51 | 52 | } 53 | 54 | func userSelection(){ 55 | 56 | } 57 | 58 | init(view:MTKView){ 59 | self.view = view 60 | super.init() 61 | skybox.parent = self 62 | } 63 | 64 | func render() { 65 | 66 | 67 | 68 | updateScene(1/60) 69 | super.updateNode(1/60) 70 | 71 | updateProjectionMatrix() 72 | 73 | skybox.updateNode(1/60) 74 | 75 | let (t, u, l) = flattenHeirarchy() 76 | HgRenderer.sharedInstance.render(texturedNodes:t, untexturedNodes:u, box:skybox, lights:l) 77 | 78 | 79 | } 80 | 81 | func updateScene(_ dt:TimeInterval) { 82 | modelMatrixIsDirty = true 83 | } 84 | 85 | func confirmAction(){ 86 | print("action confirmed") 87 | } 88 | 89 | func denyAction(){ 90 | print("action denied") 91 | } 92 | 93 | func updateProjectionMatrix(){ 94 | 95 | guard let view = view else { return } 96 | 97 | let w = Float(view.frame.size.width) 98 | let h = Float(view.frame.size.height) 99 | 100 | //let persp = float4x4(perspectiveWithFOVY: 140, aspect: 1, near:1, far: 0.01) 101 | 102 | projectionMatrix = float4x4(orthoWithLeft: -w / 2 / magnification, right: w / 2 / magnification, bottom: -h / 2 / magnification, top: h / 2 / magnification, nearZ: 1000, farZ: -1000) 103 | 104 | 105 | //projectionMatrix = float4x4(lookAtFromEyeX:0, eyeY:0, eyeZ:100, centerX:0, centerY:0, centerZ:0, upX:0, upY:1, upZ:0) 106 | 107 | //projectionMatrix = float4x4(perspectiveWithFOVY:80, aspect:1, near:5000, far:-5000) 108 | // projectionMatrix = persp * projectionMatrix 109 | 110 | projectionMatrixIsDirty = false 111 | } 112 | 113 | /* 114 | override func updateModelMatrix(){ 115 | 116 | let x = float4x4(XRotation: rotation.x) 117 | let y = float4x4(YRotation: rotation.y) 118 | let z = float4x4(ZRotation: rotation.z) 119 | let t = float4x4(translation: position) 120 | let s = float4x4(scale: scale) 121 | modelMatrix = x * y * z * t * s 122 | 123 | modelMatrixIsDirty = false 124 | 125 | } 126 | */ 127 | 128 | 129 | 130 | } 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /HgSkyboxNode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // File.swift 3 | // Mercury 4 | // 5 | // Created by Joshua Knapp on 12/24/15. 6 | // 7 | // 8 | 9 | import Foundation 10 | import simd 11 | import Metal 12 | import ModelIO 13 | import MetalKit 14 | 15 | class HgSkyboxNode:HgNode { 16 | 17 | //var tex:MTLTexture? 18 | 19 | 20 | init(size:Int) { 21 | 22 | super.init() 23 | 24 | let s = Float(1)//Float(size / 2) 25 | 26 | vertexData = Array(repeating: vertex(), count: 36) 27 | 28 | //top face 29 | vertexData[0].position = ( s, -s, 1) 30 | vertexData[1].position = ( -s, -s, 1) 31 | vertexData[2].position = ( -s, s, 1) 32 | vertexData[3].position = vertexData[2].position 33 | vertexData[4].position = ( s, s, 1) 34 | vertexData[5].position = vertexData[0].position 35 | 36 | for i in 0..<6 { 37 | vertexData[i].normal = (0,0,-1) 38 | vertexData[i].ambientColor = (0,1,1,1) 39 | vertexData[i].diffuseColor = (1,0,1,1) 40 | } 41 | 42 | //bottom face 43 | vertexData[6].position = ( s, s, -1) 44 | vertexData[7].position = ( -s, s, -1) 45 | vertexData[8].position = ( -s, -s, -1) 46 | vertexData[9].position = vertexData[8].position 47 | vertexData[10].position = ( s, -s, -1) 48 | vertexData[11].position = vertexData[6].position 49 | 50 | for i in 6..<12 { 51 | vertexData[i].normal = (0,0,1) 52 | vertexData[i].ambientColor = (0,1,1,1) 53 | vertexData[i].diffuseColor = (1,0,1,1) 54 | } 55 | 56 | //north face 57 | vertexData[12].position = ( s, s, 1) 58 | vertexData[13].position = ( -s, s, 1) 59 | vertexData[14].position = ( -s, s, -1) 60 | vertexData[15].position = vertexData[14].position 61 | vertexData[16].position = ( s, s, -1) 62 | vertexData[17].position = vertexData[12].position 63 | 64 | for i in 12..<18 { 65 | vertexData[i].normal = (0,-1,0) 66 | vertexData[i].ambientColor = (0,1,1,1) 67 | vertexData[i].diffuseColor = (1,0,1,1) 68 | } 69 | 70 | //south face 71 | vertexData[18].position = ( -s, -s, 1) 72 | vertexData[19].position = ( s, -s, 1) 73 | vertexData[20].position = ( s, -s, -1) 74 | vertexData[21].position = vertexData[20].position 75 | vertexData[22].position = ( -s, -s, -1) 76 | vertexData[23].position = vertexData[18].position 77 | 78 | for i in 18..<24 { 79 | vertexData[i].normal = (0,1,0) 80 | vertexData[i].ambientColor = (0,1,1,1) 81 | vertexData[i].diffuseColor = (1,0,1,1) 82 | } 83 | 84 | //east face 85 | vertexData[24].position = ( s, -s, 1) 86 | vertexData[25].position = ( s, s, 1) 87 | vertexData[26].position = ( s, s, -1) 88 | vertexData[27].position = vertexData[26].position 89 | vertexData[28].position = ( s, -s, -1) 90 | vertexData[29].position = vertexData[24].position 91 | 92 | for i in 24..<30 { 93 | vertexData[i].normal = (-1,0,0) 94 | vertexData[i].ambientColor = (0,1,1,1) 95 | vertexData[i].diffuseColor = (1,0,1,1) 96 | } 97 | 98 | //west face 99 | vertexData[30].position = ( -s, s, 1) 100 | vertexData[31].position = ( -s, -s, 1) 101 | vertexData[32].position = ( -s, -s, -1) 102 | vertexData[33].position = vertexData[32].position 103 | vertexData[34].position = ( -s, s, -1) 104 | vertexData[35].position = vertexData[30].position 105 | 106 | for i in 30..<36 { 107 | vertexData[i].normal = (1,0,0) 108 | vertexData[i].ambientColor = (0,1,1,1) 109 | vertexData[i].diffuseColor = (1,0,1,1) 110 | } 111 | 112 | vertexCount = 36 113 | 114 | //self.scale = float3(Float(size),Float(size),Float(size)) 115 | 116 | self.updateVertexBuffer() 117 | } 118 | 119 | override func updateModelMatrix(){ 120 | 121 | 122 | if let p = self.parent { 123 | //give a slight amount of parralax with skybox... this could potentially scroll off screen right now 124 | //self.position = float3(0, 0, -p.position.z) 125 | //...found this relationship empirically 126 | self.rotation = float3(p.rotation.x + Float(Float.pi / 2), p.rotation.z, p.rotation.y) 127 | } 128 | 129 | let x = float4x4(XRotation: rotation.x) 130 | let y = float4x4(YRotation: rotation.y) 131 | let z = float4x4(ZRotation: rotation.z) 132 | let t = float4x4(translation: position) 133 | let s = float4x4(scale: scale) 134 | let m = t * s * x * y * z 135 | 136 | modelMatrix = m 137 | modelMatrixIsDirty = false 138 | 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /IOSMercury/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // IOSMercury 4 | // 5 | // Created by Joshua Knapp on 12/4/15. 6 | // 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /IOSMercury/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /IOSMercury/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /IOSMercury/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /IOSMercury/BasicCar.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'BasicCar.blend' 2 | # Material Count: 3 3 | 4 | newmtl Material.001 5 | Ns 96.078431 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.640000 0.640000 0.640000 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.000000 11 | d 1.000000 12 | illum 2 13 | 14 | newmtl Material.002 15 | Ns 96.078431 16 | Ka 1.000000 1.000000 1.000000 17 | Kd 0.640000 0.640000 0.640000 18 | Ks 0.500000 0.500000 0.500000 19 | Ke 0.000000 0.000000 0.000000 20 | Ni 1.000000 21 | d 1.000000 22 | illum 2 23 | 24 | newmtl Material.004 25 | Ns 96.078431 26 | Ka 1.000000 1.000000 1.000000 27 | Kd 0.640000 0.640000 0.640000 28 | Ks 0.500000 0.500000 0.500000 29 | Ke 0.000000 0.000000 0.000000 30 | Ni 1.000000 31 | d 1.000000 32 | illum 2 33 | -------------------------------------------------------------------------------- /IOSMercury/BigHouse.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'BigHouse.blend' 2 | # Material Count: 1 3 | 4 | newmtl Material.001 5 | Ns 96.078431 6 | Ka 0.000000 0.000000 0.000000 7 | Kd 0.640000 0.640000 0.640000 8 | Ks 0.500000 0.500000 0.500000 9 | Ni 1.000000 10 | d 1.000000 11 | illum 2 12 | -------------------------------------------------------------------------------- /IOSMercury/BigHouse.obj: -------------------------------------------------------------------------------- 1 | # Blender v2.75 (sub 0) OBJ File: 'BigHouse.blend' 2 | # www.blender.org 3 | mtllib BigHouse.mtl 4 | o Cube 5 | v -3.368626 1.695846 -0.825034 6 | v -3.368626 2.081764 -0.825034 7 | v -2.982708 1.695846 -0.825033 8 | v -2.982708 2.081764 -0.825033 9 | v -3.368627 1.695846 -0.439116 10 | v -3.368627 2.081764 -0.439116 11 | v -2.982709 1.695846 -0.439116 12 | v -2.982709 2.081764 -0.439116 13 | v -3.412046 2.050842 -0.868454 14 | v -2.939288 2.050842 -0.868453 15 | v -2.939289 2.050842 -0.395695 16 | v -3.412047 2.050842 -0.395696 17 | v -3.412046 2.387519 -0.868454 18 | v -2.939288 2.387519 -0.868453 19 | v -2.939289 2.387519 -0.395695 20 | v -3.412047 2.387519 -0.395696 21 | v -3.360543 2.387519 -0.816951 22 | v -2.990792 2.387519 -0.816950 23 | v -2.990793 2.387519 -0.447199 24 | v -3.360543 2.387519 -0.447200 25 | v -3.360543 2.092364 -0.816951 26 | v -2.990792 2.092364 -0.816950 27 | v -2.990793 2.092364 -0.447199 28 | v -3.360543 2.092364 -0.447200 29 | v -0.999998 -0.040325 -1.000002 30 | v -0.999998 -0.040325 -1.000002 31 | v -0.999998 -0.040325 -1.000002 32 | v -0.999998 -0.040325 -1.000002 33 | v -0.999998 1.483531 -1.000002 34 | v 0.000002 -0.040325 -1.000000 35 | v -3.791638 -0.040325 -1.000008 36 | v -1.000000 -0.040325 -0.000002 37 | v -0.999998 1.483531 -1.000002 38 | v 0.000002 1.483531 -1.000000 39 | v 0.000002 -0.040325 -1.000000 40 | v 0.000000 -0.040325 0.000000 41 | v -3.791638 -0.040325 -1.000008 42 | v -1.000000 -0.040325 -0.000002 43 | v -3.791640 -0.040325 -0.000008 44 | v -2.516016 0.282630 -1.000005 45 | v -2.310673 0.282630 -1.000005 46 | v -1.325916 0.282630 -1.000003 47 | v -1.325916 0.965223 -1.000003 48 | v -3.500774 0.282630 -1.000008 49 | v -0.999998 1.483531 -1.000002 50 | v 0.000002 1.483531 -1.000000 51 | v 1.000002 1.483531 -0.999998 52 | v 1.000002 0.965223 -0.999998 53 | v 0.326284 0.965223 -0.999999 54 | v 0.326284 0.282630 -0.999999 55 | v 1.000002 0.282630 -0.999998 56 | v 1.000002 -0.040325 -0.999998 57 | v 1.000002 -0.040325 -0.999998 58 | v 1.000000 -0.040325 0.000002 59 | v -0.000002 -0.040325 1.000000 60 | v -1.000002 -0.040325 0.999998 61 | v -3.791638 1.483531 -1.000009 62 | v -1.000002 -0.040325 0.999998 63 | v -3.791642 -0.040325 0.999992 64 | v -3.791640 0.296634 -0.000008 65 | v -3.791638 0.296634 -0.484156 66 | v -3.791639 0.979228 -0.484156 67 | v -3.791640 0.979228 -0.000008 68 | v -3.791640 1.939016 -0.000009 69 | v -3.791638 1.483531 -1.000009 70 | v -3.500774 0.282630 -0.960521 71 | v -2.516016 0.282630 -0.960519 72 | v -2.516016 0.965223 -1.000006 73 | v -3.500774 0.965223 -1.000008 74 | v -2.310673 0.965223 -1.000005 75 | v -2.310673 0.282630 -0.960518 76 | v -1.325916 0.282630 -0.960516 77 | v -1.325916 0.965223 -0.960516 78 | v -0.999998 1.483531 -1.000002 79 | v 1.000002 1.483531 -0.999998 80 | v 1.000002 0.965223 -0.999998 81 | v 0.326283 0.965223 -0.960512 82 | v 1.000002 0.965223 -0.999998 83 | v 1.311041 0.965223 -0.999997 84 | v 1.311041 0.965223 -0.960510 85 | v 0.326283 0.282630 -0.960512 86 | v 1.311041 0.282630 -0.999997 87 | v 1.000002 0.282630 -0.999998 88 | v 1.000002 0.282630 -0.999998 89 | v 1.311041 0.282630 -0.960510 90 | v 1.000000 -0.040325 0.000002 91 | v 0.999998 -0.040325 1.000002 92 | v -0.000002 -0.040325 1.000000 93 | v -3.791642 -0.040325 0.999992 94 | v -3.791643 1.483531 0.999991 95 | v -3.791641 0.979228 0.500601 96 | v -3.791641 0.296634 0.500601 97 | v -2.516016 0.965223 -0.960519 98 | v -3.500774 0.965223 -0.960521 99 | v -2.310673 0.965223 -0.960518 100 | v 1.000002 -0.040325 -0.999998 101 | v 1.000002 1.483531 -0.999998 102 | v 1.000002 1.483531 -0.999998 103 | v 2.726278 1.483531 -0.999994 104 | v 2.501141 0.965223 -0.999995 105 | v 1.516384 0.965223 -0.999997 106 | v 1.516384 0.282630 -0.999997 107 | v 2.501141 0.282630 -0.999994 108 | v 2.726278 -0.040325 -0.999994 109 | v 1.000002 -0.040325 -0.999998 110 | v 0.999998 -0.040325 1.000002 111 | v 0.999998 -0.040325 1.000002 112 | v -1.000002 -0.040325 0.999998 113 | v -1.000002 -0.040325 0.999998 114 | v 2.726278 1.483531 -0.999994 115 | v 2.501141 0.965223 -0.960507 116 | v 1.516384 0.965223 -0.960510 117 | v 1.516384 0.282630 -0.960510 118 | v 2.501141 0.282630 -0.960507 119 | v 2.726278 -0.040325 -0.999994 120 | v 2.726276 -0.040325 0.000006 121 | v 2.726274 -0.040325 1.000006 122 | v 2.480500 -0.040325 1.000005 123 | v 2.480501 -0.040325 0.894300 124 | v 1.249036 -0.040325 0.894297 125 | v 1.249036 -0.040325 1.000003 126 | v 0.999998 -0.040325 1.000002 127 | v -0.000005 -0.040325 2.502374 128 | v -0.301714 -0.040325 2.502373 129 | v -0.301714 -0.040325 2.539414 130 | v -1.000005 -0.040325 2.539412 131 | v 0.999995 -0.040325 2.539416 132 | v 0.303760 -0.040325 2.539415 133 | v 0.303761 -0.040325 2.502374 134 | v -2.516021 0.282630 0.999995 135 | v -3.500778 0.282630 0.999992 136 | v -1.000003 1.483531 0.999997 137 | v -1.325920 0.965223 0.999997 138 | v -1.325920 0.282630 0.999997 139 | v -2.310678 0.282630 0.999995 140 | v -3.791643 1.483531 0.999991 141 | v 2.726276 1.970376 0.000006 142 | v 2.726276 0.979228 0.000006 143 | v 2.726277 0.979228 -0.484142 144 | v 2.726277 0.296634 -0.484142 145 | v 2.726276 0.296634 0.000006 146 | v 1.249036 -0.040325 1.000003 147 | v 2.726274 1.483531 1.000006 148 | v 2.726275 0.296634 0.500616 149 | v 2.726275 0.979228 0.500616 150 | v 2.726274 -0.040325 1.000006 151 | v 2.480501 0.965223 0.894300 152 | v 2.480500 -0.040325 1.000005 153 | v 2.480500 -0.040325 1.000005 154 | v 2.480500 0.965223 1.000005 155 | v 1.249036 0.965223 0.894297 156 | v 1.249036 0.965223 1.000003 157 | v 1.249036 -0.040325 1.000003 158 | v 0.999995 -0.040325 2.539416 159 | v -0.301714 0.847709 2.502373 160 | v 0.303761 0.847709 2.502374 161 | v -0.301714 0.847709 2.539414 162 | v -0.000006 0.847709 2.539414 163 | v -0.000006 1.964027 2.539414 164 | v -1.000006 1.483531 2.539412 165 | v 0.999994 1.483531 2.539417 166 | v 0.303760 0.847709 2.539415 167 | v -2.310678 0.965223 0.999995 168 | v -3.500778 0.965223 0.999992 169 | v -2.516021 0.965223 0.999994 170 | v -2.516021 0.282630 0.946480 171 | v -3.500778 0.282630 0.946477 172 | v -1.000005 -0.040325 2.539412 173 | v -1.000006 1.483531 2.539412 174 | v -1.325920 0.965223 0.946482 175 | v -1.325920 0.282630 0.946482 176 | v -2.310678 0.282630 0.946480 177 | v -1.000003 1.483531 0.999997 178 | v 2.647387 0.979228 -0.484142 179 | v 2.647384 0.979228 0.500615 180 | v 2.647387 0.296634 -0.484142 181 | v 2.647384 0.296634 0.500615 182 | v 2.726274 1.483531 1.000006 183 | v 0.999997 1.483531 1.000002 184 | v 0.999994 1.483531 2.539417 185 | v -2.516021 0.965223 0.946480 186 | v -2.310678 0.965223 0.946480 187 | v -3.500778 0.965223 0.946477 188 | v -1.000003 1.483531 0.999997 189 | v 0.999997 1.483531 1.000002 190 | v 0.999997 1.483531 1.000002 191 | v -1.000003 1.483531 0.999997 192 | v 0.999997 1.483531 1.000002 193 | v -0.000002 1.590579 1.000000 194 | v 0.044254 1.521507 1.018124 195 | v 0.000000 1.910402 0.000000 196 | v -1.045419 1.910402 -0.000002 197 | v -1.045417 1.445334 -1.045421 198 | v 0.000002 1.448997 -1.045419 199 | v -0.000002 1.910402 1.045419 200 | v -3.963853 1.910402 -0.000009 201 | v -3.963851 1.445334 -1.045428 202 | v 1.045419 1.910402 0.000002 203 | v -1.045417 1.677060 -1.045422 204 | v 0.000002 1.680723 -1.045419 205 | v -1.045421 1.445334 1.045417 206 | v 1.045417 1.445334 1.045421 207 | v -3.963851 1.677059 -1.045428 208 | v -3.963856 1.445334 1.045411 209 | v -3.963854 2.142128 -0.000009 210 | v 1.045422 1.445334 -1.045417 211 | v -0.000000 2.142128 -0.000000 212 | v 1.045421 1.677060 -1.045417 213 | v -0.000006 1.910402 2.654753 214 | v -1.045425 1.445334 2.654751 215 | v 1.045414 1.445334 2.654755 216 | v -1.045419 2.142128 -0.000003 217 | v -1.045422 1.677060 1.045416 218 | v -3.963856 1.677059 1.045410 219 | v 2.850104 1.445335 -1.045413 220 | v 2.850101 1.910403 0.000006 221 | v 2.850099 1.445335 1.045425 222 | v 2.850103 1.677060 -1.045413 223 | v -1.045425 1.677060 2.654750 224 | v -0.000006 2.142128 2.654753 225 | v 1.045417 1.677060 1.045422 226 | v 1.045413 1.677060 2.654755 227 | v 2.850101 2.142128 0.000006 228 | v 2.850099 1.677060 1.045426 229 | v 1.045419 2.142128 0.000002 230 | v -0.000003 2.142128 1.045419 231 | v -3.743135 0.979228 -0.484156 232 | v -3.743135 0.296634 -0.484156 233 | v -3.743137 0.296634 0.500601 234 | v -3.743137 0.979228 0.500601 235 | vt 0.016303 0.853803 236 | vt 0.146197 0.853803 237 | vt 0.146197 0.983697 238 | vt 0.016303 0.983697 239 | vt 0.081331 0.879942 240 | vt 0.081870 0.879902 241 | vt 0.081635 0.880191 242 | vt 0.081223 0.879599 243 | vt 0.083781 0.853908 244 | vt 0.084594 0.853813 245 | vt 0.097321 0.883094 246 | vt 0.096954 0.882882 247 | vt 0.049113 0.874760 248 | vt 0.048381 0.875561 249 | vt 0.079832 0.893306 250 | vt 0.079767 0.893141 251 | vt 0.103928 0.857051 252 | vt 0.092993 0.895765 253 | vt 0.045903 0.884447 254 | vt 0.059631 0.872952 255 | vt 0.062935 0.873146 256 | vt 0.076665 0.874111 257 | vt 0.077716 0.862457 258 | vt 0.050280 0.872556 259 | vt 0.084187 0.853861 260 | vt 0.125626 0.865699 261 | vt 0.119833 0.874858 262 | vt 0.107477 0.869260 263 | vt 0.103704 0.879892 264 | vt 0.112797 0.884044 265 | vt 0.110731 0.888073 266 | vt 0.110505 0.887887 267 | vt 0.105273 0.899790 268 | vt 0.089912 0.907083 269 | vt 0.078075 0.906244 270 | vt 0.037529 0.862015 271 | vt 0.039537 0.861563 272 | vt 0.077081 0.906321 273 | vt 0.042656 0.894408 274 | vt 0.041979 0.883196 275 | vt 0.044032 0.877818 276 | vt 0.037400 0.873219 277 | vt 0.033762 0.881368 278 | vt 0.018111 0.872902 279 | vt 0.050127 0.872628 280 | vt 0.058648 0.872043 281 | vt 0.054611 0.865223 282 | vt 0.048541 0.866328 283 | vt 0.061057 0.863570 284 | vt 0.062812 0.873143 285 | vt 0.076643 0.873519 286 | vt 0.077090 0.862962 287 | vt 0.126221 0.866193 288 | vt 0.126618 0.866523 289 | vt 0.119680 0.874671 290 | vt 0.108195 0.869839 291 | vt 0.119527 0.874484 292 | vt 0.123128 0.877654 293 | vt 0.122682 0.877416 294 | vt 0.103916 0.879568 295 | vt 0.117010 0.886551 296 | vt 0.112896 0.884222 297 | vt 0.112846 0.884133 298 | vt 0.117170 0.886268 299 | vt 0.110640 0.888076 300 | vt 0.105691 0.899284 301 | vt 0.099780 0.911041 302 | vt 0.090062 0.906537 303 | vt 0.080085 0.906435 304 | vt 0.077151 0.906986 305 | vt 0.042152 0.891595 306 | vt 0.017477 0.896609 307 | vt 0.029073 0.888383 308 | vt 0.039526 0.888928 309 | vt 0.055577 0.865549 310 | vt 0.048691 0.866881 311 | vt 0.929221 0.175629 312 | vt 0.929869 0.176998 313 | vt 0.928073 0.177122 314 | vt 0.927770 0.175910 315 | vt 0.061800 0.863622 316 | vt 0.933756 0.175084 317 | vt 0.933662 0.177309 318 | vt 0.930746 0.177230 319 | vt 0.930533 0.175223 320 | vt 0.110857 0.888038 321 | vt 0.126419 0.866358 322 | vt 0.943366 0.178131 323 | vt 0.942204 0.179997 324 | vt 0.939411 0.178584 325 | vt 0.940313 0.176534 326 | vt 0.145711 0.896438 327 | vt 0.136659 0.894848 328 | vt 0.126351 0.880651 329 | vt 0.119373 0.888275 330 | vt 0.129375 0.895966 331 | vt 0.128728 0.898255 332 | vt 0.100045 0.911288 333 | vt 0.098917 0.910879 334 | vt 0.136045 0.893460 335 | vt 0.126776 0.881453 336 | vt 0.119953 0.888028 337 | vt 0.129070 0.896794 338 | vt 0.146187 0.898411 339 | vt 0.129511 0.896704 340 | vt 0.125314 0.905489 341 | vt 0.119855 0.912153 342 | vt 0.118439 0.912132 343 | vt 0.118706 0.912376 344 | vt 0.104682 0.910686 345 | vt 0.103555 0.911992 346 | vt 0.100247 0.912643 347 | vt 0.088406 0.914068 348 | vt 0.086911 0.914312 349 | vt 0.086946 0.914214 350 | vt 0.084315 0.913792 351 | vt 0.091897 0.915574 352 | vt 0.089206 0.914631 353 | vt 0.088925 0.914541 354 | vt 0.053651 0.900434 355 | vt 0.040810 0.894673 356 | vt 0.073957 0.923637 357 | vt 0.069869 0.915640 358 | vt 0.071413 0.907902 359 | vt 0.057020 0.901688 360 | vt 0.016313 0.898846 361 | vt 0.946183 0.181513 362 | vt 0.944713 0.182215 363 | vt 0.942791 0.180368 364 | vt 0.944229 0.178982 365 | vt 0.146187 0.917502 366 | vt 0.133693 0.909711 367 | vt 0.138352 0.904117 368 | vt 0.133684 0.902420 369 | vt 0.128694 0.907166 370 | vt 0.103428 0.911901 371 | vt 0.129027 0.926086 372 | vt 0.125305 0.910975 373 | vt 0.130092 0.916129 374 | vt 0.120115 0.911748 375 | vt 0.118521 0.912186 376 | vt 0.119453 0.921533 377 | vt 0.118603 0.912240 378 | vt 0.121150 0.921400 379 | vt 0.060478 0.133802 380 | vt 0.067541 0.134653 381 | vt 0.067917 0.139265 382 | vt 0.060128 0.139087 383 | vt 0.102707 0.921305 384 | vt 0.103301 0.911810 385 | vt 0.103986 0.921179 386 | vt 0.091356 0.914440 387 | vt 0.085420 0.912809 388 | vt 0.051225 0.137295 389 | vt 0.051528 0.135628 390 | vt 0.052281 0.135505 391 | vt 0.052542 0.135743 392 | vt 0.052293 0.137477 393 | vt 0.086268 0.917728 394 | vt 0.086309 0.917621 395 | vt 0.087312 0.917913 396 | vt 0.086513 0.921777 397 | vt 0.083135 0.919874 398 | vt 0.090430 0.921249 399 | vt 0.088427 0.918129 400 | vt 0.088429 0.917983 401 | vt 0.050663 0.909375 402 | vt 0.030200 0.898012 403 | vt 0.048541 0.909057 404 | vt 0.052849 0.900575 405 | vt 0.040418 0.893593 406 | vt 0.083810 0.921216 407 | vt 0.068498 0.915743 408 | vt 0.071085 0.907412 409 | vt 0.057179 0.901616 410 | vt 0.074645 0.923994 411 | vt 0.137602 0.905208 412 | vt 0.130486 0.915030 413 | vt 0.132954 0.902711 414 | vt 0.125768 0.910778 415 | vt 0.127168 0.926861 416 | vt 0.097854 0.926467 417 | vt 0.089807 0.922046 418 | vt 0.047501 0.908856 419 | vt 0.052202 0.909921 420 | vt 0.032339 0.899250 421 | vt 0.924323 0.182733 422 | vt 0.926026 0.181541 423 | vt 0.928646 0.183012 424 | vt 0.927519 0.184758 425 | vt 0.076020 0.924680 426 | vt 0.928510 0.184982 427 | vt 0.929559 0.183232 428 | vt 0.932490 0.184454 429 | vt 0.931945 0.186209 430 | vt 0.075334 0.924350 431 | vt 0.945011 0.186059 432 | vt 0.944017 0.185163 433 | vt 0.945531 0.183463 434 | vt 0.946511 0.183989 435 | vt 0.096111 0.927050 436 | vt 0.094949 0.927439 437 | vt 0.095530 0.927244 438 | vt 0.085261 0.928886 439 | vt 0.085578 0.929618 440 | vt 0.923626 0.069467 441 | vt 0.930687 0.073262 442 | vt 0.925971 0.084500 443 | vt 0.916992 0.082764 444 | vt 0.043969 0.877950 445 | vt 0.036907 0.874155 446 | vt 0.030273 0.887451 447 | vt 0.039253 0.889188 448 | vt 0.932707 0.921484 449 | vt 0.927239 0.921484 450 | vt 0.927239 0.916016 451 | vt 0.932707 0.916016 452 | vt 0.896076 0.920324 453 | vt 0.895249 0.920324 454 | vt 0.895249 0.919497 455 | vt 0.896076 0.919497 456 | vt 0.901502 0.904304 457 | vt 0.914644 0.904304 458 | vt 0.914644 0.917447 459 | vt 0.901502 0.917447 460 | vn 0.000000 0.000000 -1.000000 461 | vn 1.000000 0.000000 0.000000 462 | vn -0.000000 0.000000 1.000000 463 | vn -1.000000 0.000000 -0.000000 464 | vn 0.000000 -1.000000 0.000000 465 | vn 0.000000 -0.814600 -0.580100 466 | vn -0.000000 -0.814600 0.580100 467 | vn 0.580100 -0.814600 0.000000 468 | vn -0.580100 -0.814600 -0.000000 469 | vn 0.000000 1.000000 0.000000 470 | vn 0.025500 -0.238400 -0.970800 471 | vn -0.029000 -0.271000 -0.962100 472 | vn 0.001600 -0.914300 0.405100 473 | vn 0.212200 -0.953900 -0.212200 474 | vn -0.000000 -0.913700 0.406500 475 | vn -0.001600 -0.914300 0.405100 476 | vn -0.212200 -0.953900 -0.212200 477 | vn 0.000000 -0.913700 -0.406500 478 | vn -0.003200 0.914900 -0.403800 479 | vn 0.406500 -0.913700 0.000000 480 | vn -0.406500 -0.913700 -0.000000 481 | vn 0.000000 0.913700 -0.406500 482 | vn 0.003200 0.914900 -0.403800 483 | vn -0.000000 0.913700 0.406500 484 | vn -0.406500 0.913700 -0.000000 485 | vn 0.406500 0.913700 0.000000 486 | usemtl Material.001 487 | s off 488 | f 2/1/1 4/2/1 3/3/1 1/4/1 489 | f 4/1/2 8/2/2 7/3/2 3/4/2 490 | f 8/1/3 6/2/3 5/3/3 7/4/3 491 | f 6/1/4 2/2/4 1/3/4 5/4/4 492 | f 1/1/5 3/2/5 7/3/5 5/4/5 493 | f 6/1/6 8/2/6 11/3/6 12/4/6 494 | f 11/1/2 10/2/2 14/3/2 15/4/2 495 | f 4/1/7 2/2/7 9/3/7 10/4/7 496 | f 2/1/8 6/2/8 12/3/8 9/4/8 497 | f 8/1/9 4/2/9 10/3/9 11/4/9 498 | f 13/1/10 16/2/10 20/3/10 17/4/10 499 | f 12/1/3 11/2/3 15/3/3 16/4/3 500 | f 10/1/1 9/2/1 13/3/1 14/4/1 501 | f 9/1/4 12/2/4 16/3/4 13/4/4 502 | f 20/1/1 19/2/1 23/3/1 24/4/1 503 | f 15/1/10 14/2/10 18/3/10 19/4/10 504 | f 16/1/10 15/2/10 19/3/10 20/4/10 505 | f 14/1/10 13/2/10 17/3/10 18/4/10 506 | f 24/1/10 23/2/10 22/3/10 21/4/10 507 | f 18/1/3 17/2/3 21/3/3 22/4/3 508 | f 17/1/2 20/2/2 24/3/2 21/4/2 509 | f 19/1/4 18/2/4 22/3/4 23/4/4 510 | f 26/5/3 27/6/3 28/7/3 25/8/3 511 | f 26/5/3 25/8/3 33/9/3 29/10/3 512 | f 27/6/3 26/5/3 35/11/3 30/12/3 513 | f 28/7/3 31/13/3 37/14/3 25/8/3 514 | f 27/6/3 32/15/3 38/16/3 28/7/3 515 | f 26/5/1 29/10/1 34/17/1 35/11/1 516 | f 36/18/5 32/15/5 27/6/5 30/12/5 517 | f 28/7/5 38/16/5 39/19/5 31/13/5 518 | f 40/20/1 41/21/1 42/22/1 43/23/1 33/9/1 25/8/1 37/14/1 44/24/1 519 | f 29/10/3 33/9/3 74/25/3 45/10/3 520 | f 34/17/3 29/10/3 45/10/3 46/17/3 521 | f 35/11/1 34/17/1 47/26/1 48/27/1 49/28/1 50/29/1 51/30/1 52/31/1 522 | f 30/12/3 35/11/3 52/31/3 53/32/3 523 | f 54/33/5 36/18/5 30/12/5 53/32/5 524 | f 55/34/5 56/35/5 32/15/5 36/18/5 525 | f 37/14/3 31/13/3 65/36/3 57/37/3 526 | f 38/16/5 58/38/5 59/39/5 39/19/5 527 | f 39/19/4 60/40/4 61/41/4 62/42/4 63/43/4 64/44/4 65/36/4 31/13/4 528 | f 32/15/3 56/35/3 58/38/3 38/16/3 529 | f 40/20/10 44/24/10 66/45/10 67/46/10 530 | f 40/20/1 68/47/1 69/48/1 44/24/1 37/14/1 57/37/1 33/9/1 43/23/1 70/49/1 41/21/1 531 | f 42/22/10 41/21/10 71/50/10 72/51/10 532 | f 43/23/4 42/22/4 72/51/4 73/52/4 533 | f 46/17/3 75/53/3 47/26/3 34/17/3 534 | f 48/27/3 47/26/3 98/54/3 76/55/3 535 | f 77/56/5 49/28/5 48/27/5 76/55/5 78/57/5 79/58/5 80/59/5 536 | f 50/29/2 49/28/2 77/56/2 81/60/2 537 | f 82/61/10 83/62/10 84/63/10 51/30/10 50/29/10 81/60/10 85/64/10 538 | f 52/31/3 51/30/3 84/63/3 539 | f 54/33/3 53/32/3 96/65/3 86/66/3 540 | f 87/67/5 55/34/5 36/18/5 54/33/5 541 | f 55/34/3 88/68/3 108/69/3 56/35/3 542 | f 59/39/3 58/38/3 109/70/3 89/71/3 543 | f 59/39/4 90/72/4 64/44/4 63/43/4 91/73/4 92/74/4 60/40/4 39/19/4 544 | f 68/47/4 40/20/4 67/46/4 93/75/4 545 | f 44/24/2 69/48/2 94/76/2 66/45/2 546 | f 93/77/1 67/78/1 66/79/1 94/80/1 547 | f 69/48/5 68/47/5 93/75/5 94/76/5 548 | f 33/9/3 57/37/3 65/36/3 74/25/3 549 | f 70/49/5 43/23/5 73/52/5 95/81/5 550 | f 41/21/2 70/49/2 95/81/2 71/50/2 551 | f 73/82/1 72/83/1 71/84/1 95/85/1 552 | f 53/32/3 52/31/3 105/86/3 96/65/3 553 | f 75/53/3 97/87/3 98/54/3 47/26/3 554 | f 80/88/1 85/89/1 81/90/1 77/91/1 555 | f 76/55/3 98/54/3 78/57/3 556 | f 78/57/1 98/54/1 99/92/1 100/93/1 101/94/1 102/95/1 82/61/1 79/58/1 557 | f 79/58/4 82/61/4 85/64/4 80/59/4 558 | f 82/61/1 102/95/1 103/96/1 100/93/1 99/92/1 104/97/1 105/86/1 83/62/1 559 | f 52/31/3 84/63/3 83/62/3 105/86/3 560 | f 86/66/3 106/98/3 87/67/3 54/33/3 561 | f 87/67/3 107/99/3 88/68/3 55/34/3 562 | f 101/94/5 100/93/5 111/100/5 112/101/5 563 | f 102/95/2 101/94/2 112/101/2 113/102/2 564 | f 103/96/10 102/95/10 113/102/10 114/103/10 565 | f 100/93/4 103/96/4 114/103/4 111/100/4 566 | f 110/104/2 115/105/2 104/97/2 99/92/2 567 | f 86/66/5 96/65/5 115/105/5 116/106/5 568 | f 106/98/5 86/66/5 116/106/5 117/107/5 118/108/5 119/109/5 120/110/5 121/111/5 569 | f 107/99/3 87/67/3 106/98/3 122/112/3 570 | f 108/69/5 88/68/5 123/113/5 124/114/5 125/115/5 126/116/5 571 | f 88/68/5 107/99/5 127/117/5 128/118/5 129/119/5 123/113/5 572 | f 109/70/3 58/38/3 56/35/3 108/69/3 573 | f 130/120/3 131/121/3 89/71/3 109/70/3 132/122/3 133/123/3 134/124/3 135/125/3 574 | f 136/126/3 90/72/3 59/39/3 89/71/3 575 | f 97/87/10 110/104/10 99/92/10 98/54/10 576 | f 111/127/1 114/128/1 113/129/1 112/130/1 577 | f 137/131/2 138/132/2 139/133/2 140/134/2 141/135/2 116/106/2 115/105/2 110/104/2 578 | f 115/105/3 96/65/3 105/86/3 104/97/3 579 | f 106/98/3 121/111/3 142/136/3 580 | f 143/137/2 117/107/2 116/106/2 141/135/2 144/138/2 145/139/2 138/132/2 137/131/2 581 | f 117/107/3 146/140/3 148/141/3 118/108/3 582 | f 147/142/4 119/109/4 118/108/4 148/141/4 149/143/4 150/144/4 583 | f 120/145/3 119/146/3 147/147/3 151/148/3 584 | f 152/149/2 153/150/2 142/136/2 121/111/2 120/110/2 151/151/2 585 | f 122/112/3 106/98/3 142/136/3 153/150/3 586 | f 122/112/3 154/152/3 127/117/3 107/99/3 587 | f 108/69/3 126/116/3 168/153/3 109/70/3 588 | f 155/154/3 124/155/3 123/156/3 129/157/3 156/158/3 589 | f 157/159/2 125/115/2 124/114/2 155/160/2 590 | f 158/161/3 159/162/3 160/163/3 126/116/3 125/115/3 157/159/3 591 | f 127/117/3 161/164/3 159/162/3 158/161/3 162/165/3 128/118/3 592 | f 156/166/4 129/119/4 128/118/4 162/165/4 593 | f 130/120/3 135/125/3 163/167/3 133/123/3 132/122/3 136/126/3 89/71/3 131/121/3 164/168/3 165/169/3 594 | f 131/121/10 130/120/10 166/170/10 167/171/10 595 | f 132/122/4 109/70/4 168/153/4 169/172/4 596 | f 134/124/4 133/123/4 170/173/4 171/174/4 597 | f 135/125/10 134/124/10 171/174/10 172/175/10 598 | f 132/122/5 173/176/5 90/72/5 136/126/5 599 | f 174/177/5 139/133/5 138/132/5 145/139/5 175/178/5 600 | f 140/134/3 139/133/3 174/177/3 176/179/3 601 | f 144/138/10 141/135/10 140/134/10 176/179/10 177/180/10 602 | f 178/181/2 146/140/2 117/107/2 143/137/2 603 | f 145/139/1 144/138/1 177/180/1 175/178/1 604 | f 150/144/5 152/149/5 151/151/5 147/142/5 605 | f 148/141/3 146/140/3 149/143/3 606 | f 179/182/3 122/112/3 153/150/3 152/149/3 150/144/3 149/143/3 146/140/3 178/181/3 607 | f 122/112/2 179/182/2 180/183/2 154/152/2 608 | f 162/165/5 158/161/5 157/159/5 155/160/5 156/166/5 609 | f 160/163/3 169/172/3 168/153/3 126/116/3 610 | f 161/164/1 127/117/1 154/152/1 180/183/1 611 | f 130/120/4 165/169/4 181/184/4 166/170/4 612 | f 163/167/2 135/125/2 172/175/2 182/185/2 613 | f 133/123/5 163/167/5 182/185/5 170/173/5 614 | f 164/168/2 131/121/2 167/171/2 183/186/2 615 | f 165/169/5 164/168/5 183/186/5 181/184/5 616 | f 183/187/3 167/188/3 166/189/3 181/190/3 617 | f 169/172/10 160/163/10 184/191/10 132/122/10 618 | f 182/192/3 172/193/3 171/194/3 170/195/3 619 | f 132/122/3 184/191/3 187/196/3 173/176/3 620 | f 175/197/2 177/198/2 176/199/2 174/200/2 621 | f 143/137/10 185/201/10 179/182/10 178/181/10 622 | f 180/183/3 179/182/3 186/202/3 161/164/3 623 | f 185/201/3 188/203/3 186/202/3 179/182/3 624 | f 189/204/11 190/205/11 187/196/11 184/191/11 625 | f 189/204/12 186/202/12 188/203/12 190/205/12 626 | f 227/206/4 228/207/4 229/208/4 230/209/4 627 | f 62/42/3 61/41/3 228/210/3 227/211/3 628 | f 91/73/5 63/43/5 62/42/5 227/211/5 230/212/5 629 | f 92/74/1 91/73/1 230/212/1 229/213/1 630 | f 228/210/10 61/41/10 60/40/10 92/74/10 229/213/10 631 | f 192/214/13 193/215/13 194/216/13 191/217/13 632 | f 191/1/14 195/2/14 201/3/14 192/4/14 633 | f 193/214/15 192/215/15 196/216/15 197/217/15 634 | f 191/214/16 194/215/16 206/216/16 198/217/16 635 | f 193/218/1 199/219/1 200/220/1 194/221/1 636 | f 195/214/17 191/215/17 198/216/17 202/217/17 637 | f 199/218/1 193/219/1 197/220/1 203/221/1 638 | f 192/214/18 201/215/18 204/216/18 196/217/18 639 | f 196/218/4 205/219/4 203/220/4 197/221/4 640 | f 207/218/19 200/219/19 199/220/19 641 | f 194/218/1 200/219/1 208/220/1 206/221/1 642 | f 201/222/20 195/223/20 209/224/20 210/225/20 643 | f 195/222/21 202/223/21 211/224/21 209/225/21 644 | f 212/218/22 199/219/22 203/220/22 205/221/22 645 | f 201/218/3 213/219/3 214/220/3 204/221/3 646 | f 204/218/4 214/219/4 205/220/4 196/221/4 647 | f 198/214/15 206/215/15 215/216/15 216/217/15 648 | f 202/214/18 198/215/18 216/216/18 217/217/18 649 | f 212/218/22 207/219/22 199/220/22 650 | f 208/218/23 200/219/23 207/220/23 651 | f 206/218/1 208/219/1 218/220/1 215/221/1 652 | f 213/218/4 201/219/4 210/220/4 219/221/4 653 | f 209/218/3 220/219/3 219/220/3 210/221/3 654 | f 202/218/2 221/219/2 222/220/2 211/221/2 655 | f 211/218/3 222/219/3 220/220/3 209/221/3 656 | f 213/218/24 212/219/24 205/220/24 214/221/24 657 | f 223/218/2 216/219/2 215/220/2 218/221/2 658 | f 221/218/3 202/219/3 217/220/3 224/221/3 659 | f 224/218/2 217/219/2 216/220/2 223/221/2 660 | f 207/218/24 212/219/24 213/220/24 661 | f 225/218/22 208/219/22 207/220/22 662 | f 208/218/22 225/219/22 223/220/22 218/221/22 663 | f 226/218/25 213/219/25 219/220/25 220/221/25 664 | f 221/218/26 226/219/26 220/220/26 222/221/26 665 | f 225/218/24 221/219/24 224/220/24 223/221/24 666 | f 226/218/25 207/219/25 213/220/25 667 | f 221/218/24 225/219/24 207/220/24 668 | f 226/218/26 221/219/26 207/220/26 669 | -------------------------------------------------------------------------------- /IOSMercury/HgIOSViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HgIOSViewController.swift 3 | // mercury 4 | // 5 | // Created by Joshua Knapp on 10/15/15. 6 | // Copyright © 2015 Joshua Knapp. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | 12 | import Foundation 13 | import MetalKit 14 | 15 | let MaxBuffers = 3 16 | 17 | class HgIOSViewController: UIViewController, MTKViewDelegate, HgViewController { 18 | 19 | let device: MTLDevice = MTLCreateSystemDefaultDevice()! 20 | 21 | let inflightSemaphore = dispatch_semaphore_create(MaxBuffers) 22 | var bufferIndex = 0 23 | 24 | var currentScene: HgScene! 25 | var mouseLoc:CGPoint = CGPoint(x: 0,y: 0) 26 | var touchesLoc:CGPoint = CGPoint(x:0, y:0) 27 | 28 | 29 | override func viewDidLoad() { 30 | 31 | super.viewDidLoad() 32 | 33 | // setup view properties 34 | let view = self.view as! MTKView 35 | view.delegate = self 36 | 37 | view.device = HgRenderer.device 38 | view.sampleCount = 1 39 | view.colorPixelFormat = MTLPixelFormat.BGRA8Unorm 40 | //view.acceptsTouchEvents = true 41 | 42 | HgRenderer.sharedInstance.view = view 43 | currentScene = HouseScene(view: view) 44 | currentScene.run() 45 | //currentScene.controller = self 46 | 47 | //gesture recognizers 48 | let magrec = UIPinchGestureRecognizer(target: self, action: Selector("magnify:")) 49 | view.addGestureRecognizer(magrec) 50 | 51 | let pan1rec = UIPanGestureRecognizer(target: self, action: Selector("pan2:")) 52 | pan1rec.maximumNumberOfTouches = 1 53 | view.addGestureRecognizer(pan1rec) 54 | 55 | let pan2rec = UIPanGestureRecognizer(target: self, action: Selector("pan:")) 56 | pan2rec.maximumNumberOfTouches = 2 57 | pan2rec.minimumNumberOfTouches = 2 58 | view.addGestureRecognizer(pan2rec) 59 | 60 | } 61 | 62 | //MARK: MTKViewDelegate Methods 63 | func drawInMTKView(view: MTKView) { 64 | if let cur = currentScene { 65 | cur.render() 66 | } 67 | } 68 | 69 | 70 | func mtkView(view: MTKView, drawableSizeWillChange size: CGSize) { 71 | 72 | } 73 | 74 | 75 | func magnify(recognizer:UIPinchGestureRecognizer) { 76 | let m = Float(recognizer.scale) 77 | recognizer.scale = 1 78 | currentScene.magnification *= m 79 | } 80 | 81 | func pan(recognizer:UIPanGestureRecognizer) { 82 | //print("pan1") 83 | let p = recognizer.translationInView(self.view) 84 | 85 | //if currentScene.rotation.x - dpy > -1 && currentScene.rotation.x - dpy < 1 86 | //{ 87 | currentScene.rotation = float3(currentScene.rotation.x + Float(p.y) / 100, currentScene.rotation.y, currentScene.rotation.z + Float(p.x) / 100) 88 | //} 89 | recognizer.setTranslation(CGPoint(x: 0,y: 0), inView: self.view) 90 | //print("current x rotation is \(currentScene.rotation.x)") 91 | 92 | 93 | } 94 | 95 | func pan2(recognizer:UIPanGestureRecognizer) { 96 | // print("pan2") 97 | let p = recognizer.translationInView(self.view) 98 | let dy = Float(p.y - touchesLoc.y) 99 | let dx = Float(p.x - touchesLoc.x) 100 | 101 | let cosr = cos( currentScene.rotation.z) 102 | let sinr = sin( currentScene.rotation.z) 103 | 104 | //print("Cosr is \(cosr)") 105 | //print("sinr is \(sinr)") 106 | 107 | let dify = -1 * cosr * dy - 1 * sinr * dx 108 | let difx = 1 * cosr * dx - 1 * sinr * dy 109 | 110 | 111 | 112 | //print("dx = \(dx)") 113 | //print("dy = \(dy)") 114 | currentScene.position = float3(currentScene.position.x - difx, currentScene.position.y - dify, currentScene.position.z) 115 | 116 | //touchesLoc = p 117 | recognizer.setTranslation(CGPoint(x: 0,y: 0), inView: self.view) 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /IOSMercury/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | metal 33 | 34 | UIStatusBarHidden 35 | 36 | UISupportedInterfaceOrientations 37 | 38 | UIInterfaceOrientationPortrait 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UISupportedInterfaceOrientations~ipad 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationPortraitUpsideDown 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Mercury.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /OSXMercury/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // OSXMercury 4 | // 5 | // Created by Joshua Knapp on 12/4/15. 6 | // Copyright (c) 2015 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | @NSApplicationMain 12 | class AppDelegate: NSObject, NSApplicationDelegate { 13 | 14 | @IBOutlet weak var window: NSWindow! 15 | 16 | func applicationDidFinishLaunching(_ aNotification: Notification) { 17 | 18 | } 19 | 20 | func applicationWillTerminate(_ aNotification: Notification) { 21 | 22 | } 23 | 24 | func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { 25 | return true; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /OSXMercury/HgOSXViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HgOSXViewController.swift 3 | // mercury 4 | // 5 | // Created by Joshua Knapp on 8/1/15. 6 | // Copyright © 2015 Joshua Knapp. All rights reserved. 7 | // 8 | 9 | 10 | import MetalKit 11 | 12 | class HgOSXViewController: NSViewController, MTKViewDelegate { 13 | 14 | //private let inflightSemaphore = dispatch_semaphore_create(MaxBuffers) 15 | 16 | fileprivate var bufferIndex = 0 17 | 18 | var currentScene: HgScene! 19 | 20 | var mouseLoc:NSPoint = NSPoint(x: 0,y: 0) 21 | var touchesLoc:NSPoint = NSPoint(x:0, y:0) 22 | var trackedTouch:NSTouch? 23 | 24 | 25 | override func viewDidLoad() { 26 | 27 | super.viewDidLoad() 28 | 29 | // setup view properties 30 | let view = self.view as! MTKView 31 | view.delegate = self 32 | 33 | view.device = HgRenderer.device 34 | view.sampleCount = 1 35 | view.colorPixelFormat = MTLPixelFormat.bgra8Unorm 36 | self.view.acceptsTouchEvents = true 37 | 38 | HgRenderer.sharedInstance.view = view 39 | currentScene = HouseScene(view: view) 40 | //currentScene = CubeScene(view: view) 41 | 42 | currentScene.run() 43 | } 44 | 45 | //MARK: MTKViewDelegate Methods 46 | func draw(in view: MTKView) { 47 | 48 | if let cur = currentScene { 49 | cur.render() 50 | } 51 | } 52 | 53 | func mtkView(_ view: MTKView, drawableSizeWillChange size: CGSize) { 54 | 55 | } 56 | 57 | override func touchesMoved(with event: NSEvent) { 58 | 59 | let touches = event.touches(matching: .moved, in: view) 60 | guard let touch = event.touches(matching: .moved, in: view).first else { return } 61 | 62 | switch touches.count { 63 | case 1: 64 | //print("1 touch moved") 65 | break 66 | 67 | case 2: //rotate scene 68 | 69 | let p = touch.normalizedPosition 70 | defer { touchesLoc = p } 71 | 72 | let dy = Float(p.y - touchesLoc.y) * 1 73 | let dx = Float(p.x - touchesLoc.x) * 1 74 | 75 | // FIXME: need to identify touches 76 | if dy > 0.1 || dx > 0.1 || dy < -0.1 || dx < -0.1 { touchesLoc = p;return } //eliminates flickering caused by different first touch selection 77 | 78 | 79 | currentScene.rotation = float3(currentScene.rotation.x - dy, currentScene.rotation.y, currentScene.rotation.z + dx) 80 | //print(currentScene.rotation) 81 | 82 | 83 | break 84 | 85 | 86 | default: 87 | break 88 | } 89 | } 90 | 91 | 92 | override func mouseDown(with theEvent: NSEvent) { 93 | mouseLoc = theEvent.locationInWindow 94 | } 95 | 96 | override func rightMouseDown(with theEvent: NSEvent) { 97 | currentScene.userSelection() 98 | } 99 | 100 | override func magnify(with event: NSEvent) { 101 | let m = Float(event.magnification) 102 | currentScene.magnification += m 103 | } 104 | 105 | //scene translation 106 | override func mouseDragged(with theEvent: NSEvent) { 107 | 108 | let p = theEvent.locationInWindow 109 | let dy = Float(p.y - mouseLoc.y) 110 | let dx = Float(p.x - mouseLoc.x) 111 | 112 | let cosr = abs(cos(currentScene.rotation.z)) 113 | let sinr = abs(sin(currentScene.rotation.z)) 114 | 115 | let dify = 1 / currentScene.magnification * (cosr * dy + sinr * dy) 116 | let difx = 1 / currentScene.magnification * (cosr * dx + sinr * dx) 117 | 118 | 119 | currentScene.position = float3(currentScene.position.x + difx, currentScene.position.y + dify, currentScene.position.z) 120 | 121 | mouseLoc = p 122 | 123 | } 124 | 125 | 126 | } 127 | 128 | -------------------------------------------------------------------------------- /OSXMercury/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | $(MACOSX_DEPLOYMENT_TARGET) 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mercury 2 | 3 | Deferred lighting with Metal on OSX and iOS 4 | 5 | ![Gif](http://i.giphy.com/7tNLLESHAf9AY.gif) 6 | -------------------------------------------------------------------------------- /Screen.Shot.2016-02-29.at.7.51.18.PM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sntwo/Mercury/d4d2c41c0847957481c6006f7d190907ab300136/Screen.Shot.2016-02-29.at.7.51.18.PM.png -------------------------------------------------------------------------------- /Screen.Shot.2016-02-29.at.7.52.07.PM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sntwo/Mercury/d4d2c41c0847957481c6006f7d190907ab300136/Screen.Shot.2016-02-29.at.7.52.07.PM.png -------------------------------------------------------------------------------- /Screen.Shot.2016-02-29.at.8.01.20.PM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sntwo/Mercury/d4d2c41c0847957481c6006f7d190907ab300136/Screen.Shot.2016-02-29.at.8.01.20.PM.png -------------------------------------------------------------------------------- /Shaders/Composition.metal: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | Composition shader 5 | 6 | 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | using namespace metal; 15 | 16 | struct VertexIn 17 | { 18 | packed_float2 position; 19 | packed_float2 texcoord; 20 | }; 21 | 22 | struct VertexOut { 23 | float4 position [[position]]; 24 | float2 texCoord [[user(texturecoord)]]; 25 | float3 lightPosition; 26 | }; 27 | 28 | struct Uniforms{ 29 | float4x4 modelMatrix; 30 | float4x4 projectionMatrix; 31 | float4x4 lightMatrix; //takes modelMatrix into light position for zBuffer writing 32 | float3x3 normalMatrix; 33 | float3 lightPosition; 34 | }; 35 | 36 | 37 | // Vertex shader function 38 | vertex VertexOut compositionVert(const device VertexIn* vertex_array [[ buffer(0) ]], 39 | const device Uniforms& uniforms [[ buffer(1) ]], 40 | unsigned int vid [[ vertex_id ]]) { 41 | 42 | VertexOut out; 43 | 44 | float4 tempPosition = float4((vertex_array[vid].position), 0.0, 1.0); 45 | out.position = tempPosition; 46 | out.texCoord = vertex_array[vid].texcoord; 47 | out.lightPosition = uniforms.lightPosition; 48 | 49 | return out; 50 | } 51 | 52 | // Fragment shader function 53 | 54 | fragment float4 compositionFrag(VertexOut in [[stage_in]], 55 | texture2d albedo [[ texture(0) ]], 56 | texture2d lightData [[ texture(1) ]], 57 | texture2d normals [[ texture(2) ]]) { 58 | 59 | constexpr sampler texSampler(min_filter::linear, mag_filter::linear); 60 | float4 light = lightData.sample(texSampler, in.texCoord); 61 | float3 diffuse = light.rgb; 62 | float3 n_s = normals.sample(texSampler, in.texCoord).rgb; 63 | float sun_diffuse = fmax(dot(n_s * 2.0 - 1.0, normalize(in.lightPosition)), 0.2); 64 | diffuse += float3(0.75) * sun_diffuse; 65 | diffuse *= albedo.sample(texSampler, in.texCoord).rgb; 66 | diffuse += diffuse; 67 | return float4(diffuse, 1.0); 68 | 69 | } 70 | 71 | //based on http://www.geeks3d.com/20110405/fxaa-fast-approximate-anti-aliasing-demo-glsl-opengl-test-radeon-geforce/3/ 72 | -------------------------------------------------------------------------------- /Shaders/GBuffer.metal: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | GBuffer shader 5 | 6 | 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | //#include "common.h" 15 | 16 | //using namespace AAPL; 17 | using namespace metal; 18 | 19 | struct VertexIn 20 | { 21 | packed_float3 position; 22 | packed_float3 normal; 23 | packed_float2 texcoord; 24 | packed_float4 ambientColor; 25 | packed_float4 diffuseColor; 26 | }; 27 | 28 | struct Uniforms{ 29 | float4x4 modelMatrix; 30 | float4x4 projectionMatrix; 31 | float4x4 lightMatrix; //takes modelMatrix into light position for zBuffer writing 32 | float3x3 normalMatrix; 33 | float3 lightPosition; 34 | }; 35 | 36 | 37 | struct VertexOut{ 38 | float4 position [[position]]; 39 | float4 color; 40 | float4 normal; 41 | float4 v_model; 42 | float2 uv; 43 | }; 44 | 45 | struct GBufferOut { 46 | float4 albedo [[color(0)]]; 47 | float4 normals [[color(1)]]; 48 | float4 positions [[color(2)]]; 49 | }; 50 | 51 | 52 | vertex VertexOut gBufferVert(const device VertexIn* vertex_array [[ buffer(0) ]], 53 | const device Uniforms& uniforms [[ buffer(1) ]], 54 | unsigned int vid [[ vertex_id ]]) { 55 | VertexOut out; 56 | VertexIn vin = vertex_array[vid]; 57 | 58 | float4 in_position = float4(vin.position, 1.0); 59 | out.position = uniforms.projectionMatrix * uniforms.modelMatrix * in_position; 60 | float3 normal = vin.normal; 61 | float3 eye_normal = normalize(uniforms.normalMatrix * normal); 62 | 63 | float3 lightPosition = float3(uniforms.modelMatrix * float4(uniforms.lightPosition, 0.0)); 64 | float n_dot_l = dot(eye_normal.rgb, normalize(lightPosition).rgb); 65 | n_dot_l = fmax(0.2, n_dot_l); 66 | 67 | out.color = float4(vin.ambientColor + vin.diffuseColor * n_dot_l); 68 | out.normal = float4(eye_normal, 0.0); 69 | out.v_model = uniforms.modelMatrix * in_position; 70 | out.uv = vin.texcoord; 71 | return out; 72 | } 73 | 74 | fragment GBufferOut gBufferFrag(VertexOut in [[stage_in]]) 75 | { 76 | float3 world_normal = in.normal.xyz; 77 | float scale = rsqrt(dot(world_normal, world_normal)) * 0.5; 78 | world_normal = world_normal * scale + 0.5; 79 | 80 | GBufferOut out; 81 | out.albedo = in.color; 82 | out.normals.xyz = world_normal; 83 | out.positions = in.v_model; 84 | return out; 85 | } 86 | 87 | fragment GBufferOut texturedGBufferFrag(VertexOut in [[stage_in]], texture2d texture [[texture(0)]]) 88 | { 89 | constexpr sampler s(coord::normalized, address::repeat,filter::linear); 90 | float4 color = texture.sample(s, in.uv); 91 | 92 | float3 world_normal = in.normal.xyz; 93 | float scale = rsqrt(dot(world_normal, world_normal)) * 0.5; 94 | world_normal = world_normal * scale + 0.5; 95 | 96 | GBufferOut out; 97 | out.albedo = float4(color.r * in.color.r, color.g * in.color.g, color.b * in.color.b, in.color.a); 98 | out.normals.xyz = world_normal; 99 | out.positions = in.v_model; 100 | return out; 101 | } 102 | -------------------------------------------------------------------------------- /Shaders/Light.metal: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace metal; 4 | 5 | struct Uniforms{ 6 | float4x4 modelMatrix; 7 | float4x4 projectionMatrix; 8 | float4x4 lightMatrix; //takes modelMatrix into light position for zBuffer writing 9 | float3x3 normalMatrix; 10 | float3 lightPosition; 11 | }; 12 | 13 | struct LightVertexIn{ 14 | float4 position; 15 | }; 16 | 17 | struct VertexIn 18 | { 19 | packed_float3 position; 20 | packed_float3 normal; 21 | packed_float2 texcoord; 22 | packed_float4 ambientColor; 23 | packed_float4 diffuseColor; 24 | }; 25 | 26 | struct LightVertexOutput{ 27 | float4 position [[position]]; 28 | float3 v_view; 29 | float2 distance; 30 | }; 31 | 32 | struct LightFragmentInput{ 33 | float4 view_light_position; 34 | float4 light_color_radius; 35 | float4 light_direction_coherance; 36 | float2 screen_size; 37 | }; 38 | 39 | 40 | vertex LightVertexOutput lightVert(device VertexIn* vertex_array [[ buffer(0) ]], 41 | constant Uniforms& uniforms [[ buffer(1) ]], 42 | uint vid [[ vertex_id] ]) 43 | 44 | { 45 | LightVertexOutput output; 46 | 47 | float4 tempPosition = float4(vertex_array[vid].position, 1.0); 48 | output.position = uniforms.projectionMatrix * uniforms.modelMatrix * tempPosition; 49 | output.distance = vertex_array[vid].texcoord; 50 | 51 | return output; 52 | } 53 | 54 | 55 | fragment float4 lightFrag(LightVertexOutput in [[stage_in]], 56 | constant LightFragmentInput *lightData [[buffer(0)]], 57 | texture2d normalsAndDepth [[ texture(0) ]], 58 | texture2d structurePosition [[ texture(1) ]]) 59 | { 60 | float2 txCoords = in.position.xy/lightData->screen_size; 61 | constexpr sampler texSampler; 62 | float4 gBuffers = normalsAndDepth.sample(texSampler, txCoords); 63 | float4 pos = structurePosition.sample(texSampler, txCoords); 64 | float3 normal = gBuffers.rgb * 2.0 - 1.0; 65 | float3 lightPosition = lightData->view_light_position.xyz; 66 | float3 lightVector = lightPosition - pos.xyz; 67 | float lightRadius = lightData->light_color_radius.w; 68 | 69 | float distance = length(lightVector); 70 | float diffuseIntensity = 1.0 - distance * 1.5 / lightRadius; 71 | 72 | float diffuseResponse = fmax(dot(normal, normalize(lightVector)), 0.0); 73 | 74 | float4 light = float4(0.0,0.0,0.0, 1.0); 75 | light.rgb = lightData->light_color_radius.xyz * diffuseIntensity * diffuseResponse; 76 | 77 | return light; 78 | } 79 | -------------------------------------------------------------------------------- /Shaders/Post.metal: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | using namespace metal; 7 | 8 | struct VertexIn 9 | { 10 | packed_float2 position; 11 | packed_float2 texcoord; 12 | }; 13 | 14 | struct VertexOut { 15 | float4 position [[position]]; 16 | float2 texCoord [[user(texturecoord)]]; 17 | float4 posPos; //used in FXAA 18 | float2 rcpFrame; 19 | }; 20 | 21 | struct Uniforms { 22 | float viewWidth; 23 | float viewHeight; 24 | }; 25 | 26 | // Vertex shader function 27 | vertex VertexOut postVert(const device VertexIn* vertex_array [[ buffer(0) ]], 28 | const device Uniforms& uniforms [[ buffer(1) ]], 29 | unsigned int vid [[ vertex_id ]]) { 30 | 31 | VertexOut out; 32 | 33 | float4 tempPosition = float4((vertex_array[vid].position), 0.0, 1.0); 34 | out.position = tempPosition; 35 | // 1 - is a cheap hack to fix a flip in the coords I can't figure out 36 | //out.texCoord = 1 - vertex_array[vid].texcoord; 37 | out.texCoord = vertex_array[vid].texcoord; 38 | 39 | 40 | #define FXAA_SUBPIX_SHIFT (0.0/4.0) 41 | //float2 rcpFrame = float2(1.0 / 782, 1.0 / 553); 42 | float2 rcpFrame = float2(1.0 / uniforms.viewWidth, 1.0 / uniforms.viewHeight); 43 | 44 | out.posPos.xy = out.texCoord; 45 | //out.posPos.xy = (tempPosition.xy * 0.5) + 0.5; 46 | out.posPos.zw = out.texCoord - (rcpFrame * (0.5) + FXAA_SUBPIX_SHIFT); 47 | out.rcpFrame = rcpFrame; 48 | return out; 49 | } 50 | 51 | // Fragment shader function 52 | 53 | fragment float4 postFrag(VertexOut in [[stage_in]], 54 | texture2d composition [[ texture(0) ]]) { 55 | 56 | constexpr sampler texSampler(min_filter::linear, mag_filter::linear); 57 | 58 | //pass through 59 | float2 rcpFrame = in.rcpFrame; 60 | //float2 rcpFrame = float2(1.0 / 782, 1.0 / 553); 61 | //float3 color = composition.sample(texSampler, in.texCoord).rgb; 62 | //return float4(color, 1.0); 63 | // 64 | 65 | 66 | // ... or ... 67 | //based on http://www.geeks3d.com/20110405/fxaa-fast-approximate-anti-aliasing-demo-glsl-opengl-test-radeon-geforce/3/ 68 | 69 | //--------------------------------------------------------- 70 | #define FXAA_REDUCE_MIN (1.0/128.0) 71 | #define FXAA_REDUCE_MUL (0.0/16.0) 72 | #define FXAA_SPAN_MAX 8.0 73 | //--------------------------------------------------------- 74 | float3 rgbNW = composition.sample(texSampler, in.posPos.zw).rgb; 75 | float3 rgbNE = composition.sample(texSampler, in.posPos.zw, int2(1, 0)).rgb; 76 | float3 rgbSW = composition.sample(texSampler, in.posPos.zw, int2(0, 1)).rgb; 77 | float3 rgbSE = composition.sample(texSampler, in.posPos.zw, int2(1, 1)).rgb; 78 | float3 rgbM = composition.sample(texSampler, in.posPos.xy).rgb; 79 | //--------------------------------------------------------- 80 | float3 luma = float3(0.299, 0.587, 0.114); 81 | float lumaNW = dot(rgbNW, luma); 82 | float lumaNE = dot(rgbNE, luma); 83 | float lumaSW = dot(rgbSW, luma); 84 | float lumaSE = dot(rgbSE, luma); 85 | float lumaM = dot(rgbM, luma); 86 | //--------------------------------------------------------- 87 | float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE))); 88 | float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE))); 89 | //--------------------------------------------------------- 90 | float2 dir; 91 | dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE)); 92 | dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE)); 93 | //--------------------------------------------------------- 94 | float dirReduce = max( 95 | (lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL), 96 | FXAA_REDUCE_MIN); 97 | float rcpDirMin = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce); 98 | dir = min(float2( FXAA_SPAN_MAX, FXAA_SPAN_MAX), 99 | max(float2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), 100 | dir * rcpDirMin)) * rcpFrame.xy; 101 | //-------------------------------------------------------- 102 | float3 rgbA = (1.0/2.0) * ( 103 | composition.sample(texSampler, in.posPos.xy + dir * (1.0/3.0 - 0.5)).xyz + 104 | composition.sample(texSampler, in.posPos.xy + dir * (2.0/3.0 - 0.5)).xyz); 105 | float3 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * ( 106 | composition.sample(texSampler, in.posPos.xy + dir * (0.0/3.0 - 0.5)).xyz + 107 | composition.sample(texSampler, in.posPos.xy + dir * (3.0/3.0 - 0.5)).xyz); 108 | float lumaB = dot(rgbB, luma); 109 | if((lumaB < lumaMin) || (lumaB > lumaMax)) return float4(rgbA , 1.0); 110 | 111 | return float4(rgbB, 1.0); 112 | 113 | } 114 | 115 | 116 | -------------------------------------------------------------------------------- /Shaders/Skybox.metal: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | Skybox shader 5 | 6 | 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | //#include "common.h" 15 | 16 | //using namespace AAPL; 17 | using namespace metal; 18 | 19 | struct VertexOut{ 20 | float4 position [[position]]; 21 | float4 color; 22 | float4 normal; 23 | float4 v_model; 24 | float3 texcoord; 25 | }; 26 | 27 | struct VertexIn 28 | { 29 | packed_float3 position; 30 | packed_float3 normal; 31 | packed_float2 texcoord; 32 | packed_float4 ambientColor; 33 | packed_float4 diffuseColor; 34 | }; 35 | 36 | 37 | struct Uniforms{ 38 | float4x4 modelMatrix; 39 | float4x4 projectionMatrix; 40 | float4x4 lightMatrix; //takes modelMatrix into light position for zBuffer writing 41 | float3x3 normalMatrix; 42 | float3 lightPosition; 43 | }; 44 | 45 | struct GBufferOut { 46 | float4 albedo [[color(0)]]; 47 | float4 normals [[color(1)]]; 48 | float4 positions [[color(2)]]; 49 | }; 50 | 51 | 52 | vertex VertexOut skyboxVert(constant VertexIn *vertexArray [[buffer(0)]], 53 | constant Uniforms &uniforms [[buffer(1)]], 54 | uint vid [[vertex_id]] ) 55 | { 56 | VertexOut out; 57 | VertexIn vin = vertexArray[vid]; 58 | out.texcoord = vin.position; 59 | 60 | float4 in_position = float4(vin.position, 1.0); 61 | 62 | in_position = 1.45 * uniforms.modelMatrix * in_position; 63 | 64 | //set the z value to 1.0 to make it always be the back object 65 | //see http://ogldev.atspace.co.uk/www/tutorial25/tutorial25.html 66 | out.position = float4(in_position.x, in_position.y, 1.0,1.0); 67 | out.color = vin.ambientColor; 68 | 69 | out.normal = float4(0,0,1,0); 70 | 71 | return out; 72 | 73 | } 74 | 75 | fragment GBufferOut skyboxFrag(VertexOut in [[stage_in]], 76 | texturecube skybox_texture [[texture(0)]]) 77 | 78 | { 79 | constexpr sampler linear_sampler(min_filter::linear, mag_filter::linear); 80 | float4 color = skybox_texture.sample(linear_sampler, in.texcoord); 81 | 82 | GBufferOut output; 83 | 84 | output.albedo = color; 85 | output.normals = float4(0,0,1, 1.0); 86 | output.positions = float4(-10000000,-10000000,-10000000,0); 87 | 88 | return output; 89 | } 90 | 91 | fragment GBufferOut skyboxFragUntextured(VertexOut in [[stage_in]], 92 | texturecube skybox_texture [[texture(0)]]) 93 | 94 | { 95 | //constexpr sampler linear_sampler(min_filter::linear, mag_filter::linear); 96 | //float4 color = skybox_texture.sample(linear_sampler, in.texcoord); 97 | 98 | GBufferOut output; 99 | 100 | output.albedo = in.color; 101 | output.normals = float4(0,0,1, 1.0); 102 | output.positions = float4(-10000000,-10000000,-10000000,0); 103 | 104 | return output; 105 | } 106 | -------------------------------------------------------------------------------- /Shaders/ZOnly.metal: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | zOnly shader 5 | 6 | 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | using namespace metal; 13 | 14 | struct Vertex 15 | { 16 | packed_float3 position; 17 | packed_float3 normal; 18 | packed_float3 texcoord; 19 | packed_float3 tangent; 20 | packed_float3 bitangent; 21 | }; 22 | 23 | struct VertexOutput 24 | { 25 | float4 position [[position]]; 26 | }; 27 | 28 | vertex VertexOutput zOnly(constant Vertex *pos_data [[buffer(0)]], 29 | constant float4x4 &mvp [[buffer(1)]], 30 | uint vid [[vertex_id]] ) 31 | { 32 | float4 tempPosition = float4(pos_data[vid].position, 1.0f); 33 | 34 | VertexOutput output; 35 | output.position = mvp * tempPosition; 36 | 37 | return output; 38 | } 39 | -------------------------------------------------------------------------------- /skybox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sntwo/Mercury/d4d2c41c0847957481c6006f7d190907ab300136/skybox.png --------------------------------------------------------------------------------