Created
January 3, 2018 15:03
-
-
Save anden3/abb8c76f1b397e03ff913cb59a84b04f to your computer and use it in GitHub Desktop.
CreateHouse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function createHouse() { | |
| const vertices = [ | |
| // Front side wall. | |
| [-10, -5, 10], [10, -5, 10], [-10, 5, 10], | |
| [10, -5, 10], [10, 5, 10], [-10, 5, 10], | |
| // Front side roof. | |
| [-10, 5, 10], [10, 5, 10], [0, 15, 10], | |
| // Left side wall. | |
| [-10, -5, -10], [-10, -5, 10], [-10, 5, -10], | |
| [-10, -5, 10], [-10, 5, 10], [-10, 5, -10], | |
| // Left side roof. | |
| [-10, 5, -10], [-10, 5, 10], [0, 15, -10], | |
| [-10, 5, 10], [0, 15, 10], [0, 15, -10], | |
| // Back side wall. | |
| [10, -5, -10], [-10, -5, -10], [10, 5, -10], | |
| [-10, -5, -10], [-10, 5, -10], [10, 5, -10], | |
| // Back side roof. | |
| [10, 5, -10], [-10, 5, -10], [0, 15, -10], | |
| // Right side wall. | |
| [10, -5, 10], [10, -5, -10], [10, 5, 10], | |
| [10, -5, -10], [10, 5, -10], [10, 5, 10], | |
| // Right side roof. | |
| [10, 5, 10], [10, 5, -10], [0, 15, 10], | |
| [10, 5, -10], [0, 15, -10], [0, 15, 10], | |
| // Floor | |
| [-10, -5, -10], [10, -5, -10], [-10, -5, 10], | |
| [10, -5, -10], [10, -5, 10], [-10, -5, 10] | |
| ]; | |
| const cornerColors = new Map([ | |
| ["-10,-5,10", [1, 0, 0, 1]], | |
| ["10,-5,10", [0, 1, 0, 1]], | |
| ["-10,5,10", [0, 0, 1, 1]], | |
| ["10,5,10", [1, 1, 0, 1]], | |
| ["0,15,10", [0, 1, 1, 1]], | |
| ["-10,-5,-10", [1, 0, 1, 1]], | |
| ["-10,5,-10", [1, 1, 1, 1]], | |
| ["0,15,-10", [0.5, 0.5, 0, 1]], | |
| ["10,-5,-10", [0, 0.5, 0.5, 1]], | |
| ["10,5,-10", [0.5, 0, 0.5, 1]] | |
| ]); | |
| let data = []; | |
| for (let vertex of vertices) { | |
| data.extend(vertex); | |
| data.extend(cornerColors.get(vertex.toString())); | |
| } | |
| const vertexBuffer = gl.createBuffer(); | |
| shared.house.vertexArray = gl.createVertexArray(); | |
| shared.house.vertexCount = uploadData( | |
| shared.house.vertexArray, | |
| vertexBuffer, data, [3, 4] | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment