import Vertice from './MeshVertice' ; import Triangle from './Triangle' ; import Mesh from './Mesh' ; export default class Box extends Mesh { constructor ( public length , public width , public height ) { super ( ) ; this . buildTriangles ( ) ; } buildTriangles ( ) { this . vertices = [ ] ; this . triangles = [ ] ; var halfLength = this . length / 2 ; var halfHeight = this . height / 2 ; var halfWidth = this . width / 2 ; var vF1 = [ - halfLength , halfHeight , halfWidth ] ; var vF2 = [ - halfLength , - halfHeight , halfWidth ] ; var vF3 = [ halfLength , halfHeight , halfWidth ] ; var vF4 = [ halfLength , - halfHeight , halfWidth ] ; var vB1 = [ - halfLength , halfHeight , - halfWidth ] ; var vB2 = [ - halfLength , - halfHeight , - halfWidth ] ; var vB3 = [ halfLength , halfHeight , - halfWidth ] ; var vB4 = [ halfLength , - halfHeight , - halfWidth ] ; var index = 0 ; var pzResult = this . _buildPlane ( index , vF1 , vF2 , vF3 , vF4 , [ 0 , 0 , 1 ] ) ; this . vertices = this . vertices . concat ( pzResult . vertices ) ; this . triangles = this . triangles . concat ( pzResult . triangles ) ; index += 4 ; var pxResult = this . _buildPlane ( index , vF3 , vF4 , vB3 , vB4 , [ 1 , 0 , 0 ] ) ; this . vertices = this . vertices . concat ( pxResult . vertices ) ; this . triangles = this . triangles . concat ( pxResult . triangles ) ; index += 4 ; var nzResult = this . _buildPlane ( index , vB3 , vB4 , vB1 , vB2 , [ 0 , 0 , - 1 ] ) ; this . vertices = this . vertices . concat ( nzResult . vertices ) ; this . triangles = this . triangles . concat ( nzResult . triangles ) ; index += 4 ; var nxResult = this . _buildPlane ( index , vB1 , vB2 , vF1 , vF2 , [ - 1 , 0 , 0 ] ) ; this . vertices = this . vertices . concat ( nxResult . vertices ) ; this . triangles = this . triangles . concat ( nxResult . triangles ) ; index += 4 ; var pyResult = this . _buildPlane ( index , vB1 , vF1 , vB3 , vF3 , [ 0 , 1 , 0 ] ) ; this . vertices = this . vertices . concat ( pyResult . vertices ) ; this . triangles = this . triangles . concat ( pyResult . triangles ) ; index += 4 ; var nyResult = this . _buildPlane ( index , vF2 , vB2 , vF4 , vB4 , [ 0 , - 1 , 0 ] ) ; this . vertices = this . vertices . concat ( nyResult . vertices ) ; this . triangles = this . triangles . concat ( nyResult . triangles ) ; } _buildPlane ( startIndex , pLT , pLB , pRT , pRB , nortal ) { var result = { vertices : < Vertice [ ] > [ ] , triangles : < Triangle [ ] > [ ] } ; var v0 = new Vertice ( { i : startIndex , p : pLT , uv : [ 0 , 0 ] , n : nortal , c : null } ) ; var v1 = new Vertice ( { i : startIndex + 1 , p : pLB , uv : [ 0 , 1 ] , n : nortal , c : null } ) ; var v2 = new Vertice ( { i : startIndex + 2 , p : pRT , uv : [ 1 , 0 ] , n : nortal , c : null } ) ; var v3 = new Vertice ( { i : startIndex + 3 , p : pRB , uv : [ 1 , 1 ] , n : nortal , c : null } ) ; result . vertices = [ v0 , v1 , v2 , v3 ] ; var tri0 = new Triangle ( v0 , v1 , v2 ) ; var tri1 = new Triangle ( v2 , v1 , v3 ) ; result . triangles = [ tri0 , tri1 ] ; return result ; } } ;