Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | import {MatrixIV} from '../mathf/matrixIV';
import {Vector} from '../mathf/vector';
export enum MeshTypes {
CUBE = 'cube',
}
/**
* @unstable
*/
export class Mesh {
public name: string;
public position: Vector;
public rotation: Vector;
public up: Vector;
public right: Vector;
public forward: Vector;
public vertices: Array<Vector>;
public basisMatrix: MatrixIV;
public color: string;
/**
* @param verticesCount The number of vertices this mesh should contain.
*/
constructor() {
this.name = '';
this.vertices = [];
this.position = Vector.ZERO;
this.rotation = Vector.ZERO;
this.up = Vector.ZERO;
this.right = Vector.ZERO;
this.forward = Vector.ZERO;
this.basisMatrix = MatrixIV.IDENTITY;
this.color = 'green';
}
// eslint-disable-next-line
size(width: number, height: number, depth: number) {
this.up = new Vector(0, width, 0);
this.right = new Vector(height, 0, 0);
this.forward = Vector.ONE.cross(this.up);
// Generate a basis matrix.
const basisMatrix = new MatrixIV();
basisMatrix.setVectorColumn(0, this.right);
basisMatrix.setVectorColumn(1, this.up);
basisMatrix.setVectorColumn(2, this.forward);
this.basisMatrix = basisMatrix;
}
}
/**
* Creates a CubeMesh.
*/
export class CubeMesh extends Mesh {
constructor() {
super();
this.name = MeshTypes.CUBE;
this.vertices = [
new Vector(-1, 1, 1),
new Vector(1, 1, 1),
new Vector(-1, -1, 1),
new Vector(-1, -1, -1),
new Vector(-1, 1, -1),
new Vector(1, 1, -1),
new Vector(1, -1, 1),
new Vector(1, -1, -1),
];
}
}
|