MCPcopy Index your code
hub / github.com/stemkoski/stemkoski.github.com / subdivide

Function subdivide

MathBox/mathbox-bundle.js:32995–33059  ·  view source on GitHub ↗
( face, detail )

Source from the content-addressed store, hash-verified

32993 // Analytically subdivide a face to the required detail level.
32994
32995 function subdivide( face, detail ) {
32996
32997 var cols = Math.pow(2, detail);
32998 var a = prepare( that.vertices[ face.a ] );
32999 var b = prepare( that.vertices[ face.b ] );
33000 var c = prepare( that.vertices[ face.c ] );
33001 var v = [];
33002
33003 // Construct all of the vertices for this subdivision.
33004
33005 for ( var i = 0 ; i <= cols; i ++ ) {
33006
33007 v[ i ] = [];
33008
33009 var aj = prepare( a.clone().lerp( c, i / cols ) );
33010 var bj = prepare( b.clone().lerp( c, i / cols ) );
33011 var rows = cols - i;
33012
33013 for ( var j = 0; j <= rows; j ++) {
33014
33015 if ( j == 0 && i == cols ) {
33016
33017 v[ i ][ j ] = aj;
33018
33019 } else {
33020
33021 v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
33022
33023 }
33024
33025 }
33026
33027 }
33028
33029 // Construct all of the faces.
33030
33031 for ( var i = 0; i < cols ; i ++ ) {
33032
33033 for ( var j = 0; j < 2 * (cols - i) - 1; j ++ ) {
33034
33035 var k = Math.floor( j / 2 );
33036
33037 if ( j % 2 == 0 ) {
33038
33039 make(
33040 v[ i ][ k + 1],
33041 v[ i + 1 ][ k ],
33042 v[ i ][ k ]
33043 );
33044
33045 } else {
33046
33047 make(
33048 v[ i ][ k + 1 ],
33049 v[ i + 1][ k + 1],
33050 v[ i + 1 ][ k ]
33051 );
33052

Callers 1

mathbox-bundle.jsFile · 0.70

Calls 2

prepareFunction · 0.70
makeFunction · 0.70

Tested by

no test coverage detected