UNPKG

ts-game-engine

Version:

Simple WebGL game/render engine written in TypeScript

85 lines (84 loc) 3.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Mesh_1 = require("./Mesh"); class WireBoxMesh extends Mesh_1.Mesh { constructor(scene, bounds, color) { super(scene); const vertexCount = 8; this.vertexData = new Float32Array(vertexCount * (Mesh_1.VERTEX_POSITION_SIZE + Mesh_1.VERTEX_COLOR_SIZE)); this.GenerateVertexData(bounds, color); const indexData = new Uint16Array([ 0, 1, 1, 3, 3, 2, 2, 0, 0, 4, 1, 5, 2, 6, 3, 7, 4, 5, 5, 7, 7, 6, 6, 4 ]); const vertexFormat = 1 /* Position */ | 2 /* Color */; this.SetVertexData(vertexFormat, 1 /* Lines */, vertexCount, this.vertexData, true); this.SetIndexData(indexData); this.isLoaded = true; } UpdateBounds(bounds, color) { this.GenerateVertexData(bounds, color); this.UpdateVertexData(this.vertexData); } GenerateVertexData(bounds, color) { let v = 0; this.vertexData[v++] = bounds.min[0]; this.vertexData[v++] = bounds.min[1]; this.vertexData[v++] = bounds.min[2]; this.vertexData[v++] = color[0]; this.vertexData[v++] = color[1]; this.vertexData[v++] = color[2]; this.vertexData[v++] = color[3]; this.vertexData[v++] = bounds.max[0]; this.vertexData[v++] = bounds.min[1]; this.vertexData[v++] = bounds.min[2]; this.vertexData[v++] = color[0]; this.vertexData[v++] = color[1]; this.vertexData[v++] = color[2]; this.vertexData[v++] = color[3]; this.vertexData[v++] = bounds.min[0]; this.vertexData[v++] = bounds.min[1]; this.vertexData[v++] = bounds.max[2]; this.vertexData[v++] = color[0]; this.vertexData[v++] = color[1]; this.vertexData[v++] = color[2]; this.vertexData[v++] = color[3]; this.vertexData[v++] = bounds.max[0]; this.vertexData[v++] = bounds.min[1]; this.vertexData[v++] = bounds.max[2]; this.vertexData[v++] = color[0]; this.vertexData[v++] = color[1]; this.vertexData[v++] = color[2]; this.vertexData[v++] = color[3]; this.vertexData[v++] = bounds.min[0]; this.vertexData[v++] = bounds.max[1]; this.vertexData[v++] = bounds.min[2]; this.vertexData[v++] = color[0]; this.vertexData[v++] = color[1]; this.vertexData[v++] = color[2]; this.vertexData[v++] = color[3]; this.vertexData[v++] = bounds.max[0]; this.vertexData[v++] = bounds.max[1]; this.vertexData[v++] = bounds.min[2]; this.vertexData[v++] = color[0]; this.vertexData[v++] = color[1]; this.vertexData[v++] = color[2]; this.vertexData[v++] = color[3]; this.vertexData[v++] = bounds.min[0]; this.vertexData[v++] = bounds.max[1]; this.vertexData[v++] = bounds.max[2]; this.vertexData[v++] = color[0]; this.vertexData[v++] = color[1]; this.vertexData[v++] = color[2]; this.vertexData[v++] = color[3]; this.vertexData[v++] = bounds.max[0]; this.vertexData[v++] = bounds.max[1]; this.vertexData[v++] = bounds.max[2]; this.vertexData[v++] = color[0]; this.vertexData[v++] = color[1]; this.vertexData[v++] = color[2]; this.vertexData[v++] = color[3]; } } exports.WireBoxMesh = WireBoxMesh;