function layoutMeshUV(faces, verts, O) {

        var facesLength = faces.length;
        var gridSize = Math.ceil(Math.sqrt(facesLength));

        var maxima = findMeshMaxima(faces, verts);

        var xOffset = maxima.getXD();
        var yOffset = maxima.getYD();
        var zOffset = maxima.getZD();
        var boundingBoxTmp = Math.max(xOffset, yOffset, zOffset);
        var boundingBox = boundingBoxTmp + (boundingBoxTmp * O);

        var scaleFactor = (1 / (gridSize * boundingBox));
        var offset = boundingBox * scaleFactor;

        var scaleMat = mathFun.getScaleMatrix(scaleFactor);

        var faceVertexUvs = new Array(facesLength);
        var i;
        var bbs, xoffset, yoffset, uvs, max;

        var mapuv1 = function (uv) {
            uv[0] -= max.xMin * scaleFactor;
            uv[1] -= max.yMin * scaleFactor;
            return uv;
        };

        for (i = 0; i < facesLength; i++) {

            uvs = mathFun.flattenFace(faces[i], verts, faces[i].normal.toArray());
            max = getMaxima(uvs);
            uvs = mathFun.scaleFace(uvs, scaleMat);

            uvs.map(mapuv1);

            bbs = getMaxima(uvs);
            xoffset = (offset - bbs.xMax) / 2;
            yoffset = (offset - bbs.yMax) / 2;

            uvs.map(function (uv) {
                uv[0] += (i % gridSize) * offset + xoffset;
                uv[1] -= -Math.floor(i / gridSize) * offset - yoffset;
            });

            // TODO int8array?
            faceVertexUvs[i] = [
                [mathFun.clip(uvs[0][0], 0, 1), mathFun.clip(uvs[0][1], 0, 1)],
                [mathFun.clip(uvs[1][0], 0, 1), mathFun.clip(uvs[1][1], 0, 1)],
                [mathFun.clip(uvs[2][0], 0, 1), mathFun.clip(uvs[2][1], 0, 1)]
            ];
        }
        return faceVertexUvs;
    }
/**
     * This method calculates the uv map for a mesh. It is not optimized therefore there is
     * a lot waste of space
     * @param faces
     * @param verts
     * @param O
     * @returns {Array}
     */
This method calculates the uv map for a mesh. It is not optimized therefore there is
a lot waste of space
@param faces
@param verts
@param O
@returns {Array}
This method calculates the uv map for a mesh . It is not optimized therefore there is a lot waste of space @param faces @param verts @param O @returns { Array }
function layoutMeshUV(faces, verts, O) {
        var facesLength = faces.length;
        var gridSize = Math.ceil(Math.sqrt(facesLength));
        var maxima = findMeshMaxima(faces, verts);
        var xOffset = maxima.getXD();
        var yOffset = maxima.getYD();
        var zOffset = maxima.getZD();
        var boundingBoxTmp = Math.max(xOffset, yOffset, zOffset);
        var boundingBox = boundingBoxTmp + (boundingBoxTmp * O);
        var scaleFactor = (1 / (gridSize * boundingBox));
        var offset = boundingBox * scaleFactor;
        var scaleMat = mathFun.getScaleMatrix(scaleFactor);
        var faceVertexUvs = new Array(facesLength);
        var i;
        var bbs, xoffset, yoffset, uvs, max;
        var mapuv1 = function (uv) {
            uv[0] -= max.xMin * scaleFactor;
            uv[1] -= max.yMin * scaleFactor;
            return uv;
        };
        for (i = 0; i < facesLength; i++) {
            uvs = mathFun.flattenFace(faces[i], verts, faces[i].normal.toArray());
            max = getMaxima(uvs);
            uvs = mathFun.scaleFace(uvs, scaleMat);
            uvs.map(mapuv1);
            bbs = getMaxima(uvs);
            xoffset = (offset - bbs.xMax) / 2;
            yoffset = (offset - bbs.yMax) / 2;
            uvs.map(function (uv) {
                uv[0] += (i % gridSize) * offset + xoffset;
                uv[1] -= -Math.floor(i / gridSize) * offset - yoffset;
            });
            faceVertexUvs[i] = [
                [mathFun.clip(uvs[0][0], 0, 1), mathFun.clip(uvs[0][1], 0, 1)],
                [mathFun.clip(uvs[1][0], 0, 1), mathFun.clip(uvs[1][1], 0, 1)],
                [mathFun.clip(uvs[2][0], 0, 1), mathFun.clip(uvs[2][1], 0, 1)]
            ];
        }
        return faceVertexUvs;
    }
function layoutMeshUV ( faces , verts , O ) { var facesLength = faces . length ; var gridSize = Math . ceil ( Math . sqrt ( facesLength ) ) ; var maxima = findMeshMaxima ( faces , verts ) ; var xOffset = maxima . getXD ( ) ; var yOffset = maxima . getYD ( ) ; var zOffset = maxima . getZD ( ) ; var boundingBoxTmp = Math . max ( xOffset , yOffset , zOffset ) ; var boundingBox = boundingBoxTmp + ( boundingBoxTmp * O ) ; var scaleFactor = ( 1 / ( gridSize * boundingBox ) ) ; var offset = boundingBox * scaleFactor ; var scaleMat = mathFun . getScaleMatrix ( scaleFactor ) ; var faceVertexUvs = new Array ( facesLength ) ; var i ; var bbs , xoffset , yoffset , uvs , max ; var mapuv1 = function ( uv ) { uv [ 0 ] -= max . xMin * scaleFactor ; uv [ 1 ] -= max . yMin * scaleFactor ; return uv ; } ; for ( i = 0 ; i < facesLength ; i ++ ) { uvs = mathFun . flattenFace ( faces [ i ] , verts , faces [ i ] . normal . toArray ( ) ) ; max = getMaxima ( uvs ) ; uvs = mathFun . scaleFace ( uvs , scaleMat ) ; uvs . map ( mapuv1 ) ; bbs = getMaxima ( uvs ) ; xoffset = ( offset - bbs . xMax ) / 2 ; yoffset = ( offset - bbs . yMax ) / 2 ; uvs . map ( function ( uv ) { uv [ 0 ] += ( i % gridSize ) * offset + xoffset ; uv [ 1 ] -= - Math . floor ( i / gridSize ) * offset - yoffset ; } ) ; faceVertexUvs [ i ] = [ [ mathFun . clip ( uvs [ 0 ] [ 0 ] , 0 , 1 ) , mathFun . clip ( uvs [ 0 ] [ 1 ] , 0 , 1 ) ] , [ mathFun . clip ( uvs [ 1 ] [ 0 ] , 0 , 1 ) , mathFun . clip ( uvs [ 1 ] [ 1 ] , 0 , 1 ) ] , [ mathFun . clip ( uvs [ 2 ] [ 0 ] , 0 , 1 ) , mathFun . clip ( uvs [ 2 ] [ 1 ] , 0 , 1 ) ] ] ; } return faceVertexUvs ; }
This method calculates the uv map for a mesh.
This method calculates the uv map for a mesh .
// TODO int8array?