build/browser/index.js
// Subdivide a face to the required detail level.
Subdivide a face to the required detail level.
Subdivide a face to the required detail level .
function subdivide(face, detail, points, builder) {
                var cols = Math.pow(2, detail);
                var a = prepare(face.vertices[0].attributes[GraphicsProgramSymbols.ATTRIBUTE_POSITION], points);
                var b = prepare(face.vertices[1].attributes[GraphicsProgramSymbols.ATTRIBUTE_POSITION], points);
                var c = prepare(face.vertices[2].attributes[GraphicsProgramSymbols.ATTRIBUTE_POSITION], points);
                var v = [];
                for (var i = 0; i <= cols; i++) {
                    v[i] = [];
                    var aj = prepare(Vector3.copy(a).lerp(c, i / cols), points);
                    var bj = prepare(Vector3.copy(b).lerp(c, i / cols), points);
                    var rows = cols - i;
                    for (var j = 0; j <= rows; j++) {
                        if (j === 0 && i === cols) {
                            v[i][j] = aj;
                        }
                        else {
                            v[i][j] = prepare(Vector3.copy(aj).lerp(bj, j / rows), points);
                        }
                    }
                }
                for (var i = 0; i < cols; i++) {
                    for (var j = 0; j < 2 * (cols - i) - 1; j++) {
                        var k = Math.floor(j / 2);
                        if (j % 2 === 0) {
                            make(v[i][k + 1], v[i + 1][k], v[i][k], builder);
                        }
                        else {
                            make(v[i][k + 1], v[i + 1][k + 1], v[i + 1][k], builder);
                        }
                    }
                }
            }
function subdivide ( face , detail , points , builder ) { var cols = Math . pow ( 2 , detail ) ; var a = prepare ( face . vertices [ 0 ] . attributes [ GraphicsProgramSymbols . ATTRIBUTE_POSITION ] , points ) ; var b = prepare ( face . vertices [ 1 ] . attributes [ GraphicsProgramSymbols . ATTRIBUTE_POSITION ] , points ) ; var c = prepare ( face . vertices [ 2 ] . attributes [ GraphicsProgramSymbols . ATTRIBUTE_POSITION ] , points ) ; var v = [ ] ; for ( var i = 0 ; i <= cols ; i ++ ) { v [ i ] = [ ] ; var aj = prepare ( Vector3 . copy ( a ) . lerp ( c , i / cols ) , points ) ; var bj = prepare ( Vector3 . copy ( b ) . lerp ( c , i / cols ) , points ) ; var rows = cols - i ; for ( var j = 0 ; j <= rows ; j ++ ) { if ( j === 0 && i === cols ) { v [ i ] [ j ] = aj ; } else { v [ i ] [ j ] = prepare ( Vector3 . copy ( aj ) . lerp ( bj , j / rows ) , points ) ; } } } for ( var i = 0 ; i < cols ; i ++ ) { for ( var j = 0 ; j < 2 * ( cols - i ) - 1 ; j ++ ) { var k = Math . floor ( j / 2 ) ; if ( j % 2 === 0 ) { make ( v [ i ] [ k + 1 ] , v [ i + 1 ] [ k ] , v [ i ] [ k ] , builder ) ; } else { make ( v [ i ] [ k + 1 ] , v [ i + 1 ] [ k + 1 ] , v [ i + 1 ] [ k ] , builder ) ; } } } }
Subdivide a face to the required detail level.
Subdivide a face to the required detail level .
// Construct all of the vertices for this subdivision. // Construct all of the faces.