UNPKG

ts-game-engine

Version:

Simple WebGL game/render engine written in TypeScript

51 lines (50 loc) 2.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Mesh_1 = require("./Mesh"); const gl_matrix_1 = require("gl-matrix"); class CubeMesh extends Mesh_1.Mesh { constructor(scene) { super(scene); const vertexData = new Float32Array([ //Position Color Normal UV0 -0.5, +0.5, +0.5, 0, 1, 1, 1, +0, +0, +1, 0, 1, +0.5, +0.5, +0.5, 1, 1, 1, 1, +0, +0, +1, 1, 1, -0.5, -0.5, +0.5, 0, 0, 1, 1, +0, +0, +1, 0, 0, +0.5, -0.5, +0.5, 1, 0, 1, 1, +0, +0, +1, 1, 0, +0.5, +0.5, +0.5, 1, 1, 1, 1, +1, +0, +0, 0, 1, +0.5, +0.5, -0.5, 1, 1, 0, 1, +1, +0, +0, 1, 1, +0.5, -0.5, +0.5, 1, 0, 1, 1, +1, +0, +0, 0, 0, +0.5, -0.5, -0.5, 1, 0, 0, 1, +1, +0, +0, 1, 0, +0.5, +0.5, -0.5, 1, 1, 0, 1, +0, +0, -1, 0, 1, -0.5, +0.5, -0.5, 0, 1, 0, 1, +0, +0, -1, 1, 1, +0.5, -0.5, -0.5, 1, 0, 0, 1, +0, +0, -1, 0, 0, -0.5, -0.5, -0.5, 0, 0, 0, 1, +0, +0, -1, 1, 0, -0.5, +0.5, -0.5, 0, 1, 0, 1, -1, +0, +0, 0, 1, -0.5, +0.5, +0.5, 0, 1, 1, 1, -1, +0, +0, 1, 1, -0.5, -0.5, -0.5, 0, 0, 0, 1, -1, +0, +0, 0, 0, -0.5, -0.5, +0.5, 0, 0, 1, 1, -1, +0, +0, 1, 0, -0.5, +0.5, -0.5, 0, 1, 0, 1, +0, +1, +0, 0, 1, +0.5, +0.5, -0.5, 1, 1, 0, 1, +0, +1, +0, 1, 1, -0.5, +0.5, +0.5, 0, 1, 1, 1, +0, +1, +0, 0, 0, +0.5, +0.5, +0.5, 1, 1, 1, 1, +0, +1, +0, 1, 0, -0.5, -0.5, +0.5, 0, 0, 1, 1, +0, -1, +0, 0, 1, +0.5, -0.5, +0.5, 1, 0, 1, 1, +0, -1, +0, 1, 1, -0.5, -0.5, -0.5, 0, 0, 0, 1, +0, -1, +0, 0, 0, +0.5, -0.5, -0.5, 1, 0, 0, 1, +0, -1, +0, 1, 0 ]); const indexData = new Uint16Array([ 0, 2, 1, 1, 2, 3, 4, 6, 5, 5, 6, 7, 8, 10, 9, 9, 10, 11, 12, 14, 13, 13, 14, 15, 16, 18, 17, 17, 18, 19, 20, 22, 21, 21, 22, 23 // Bottom face ]); const vertexFormat = 1 /* Position */ | 2 /* Color */ | 4 /* Normal */ | 8 /* UV0 */; this.SetVertexData(vertexFormat, 4 /* Triangles */, 24, vertexData, false); this.SetIndexData(indexData); this.SetBounds(gl_matrix_1.vec3.fromValues(-0.5, -0.5, -0.5), gl_matrix_1.vec3.fromValues(0.5, 0.5, 0.5)); /*, { center: vec3.fromValues(0, 0, 0), radius: 0.707107 }*/ this.isLoaded = true; } } exports.CubeMesh = CubeMesh;