public static int getCubemapFaceTexCoordFromVector(Vector3f texelVect, int mapSize, Vector2f store, FixSeamsMethod fixSeamsMethod) {

        float u = 0, v = 0, bias = 0;
        int face;
        float absX = abs(texelVect.x);
        float absY = abs(texelVect.y);
        float absZ = abs(texelVect.z);
        float max = Math.max(Math.max(absX, absY), absZ);
        if (max == absX) {
            face = texelVect.x > 0 ? 0 : 1;
        } else if (max == absY) {
            face = texelVect.y > 0 ? 2 : 3;
        } else {
            face = texelVect.z > 0 ? 4 : 5;
        }

        //compute vector depending on the face
        // Code from Nvtt : http://code.google.com/p/nvidia-texture-tools/source/browse/trunk/src/nvtt/CubeSurface.cpp
        switch (face) {
            case 0:
                //store.set(1f, -v, -u, 0);
                bias = 1f / texelVect.x;
                u = -texelVect.z;
                v = -texelVect.y;
                break;
            case 1:
                // store.set(-1f, -v, u, 0);
                bias = -1f / texelVect.x;
                u = texelVect.z;
                v = -texelVect.y;
                break;
            case 2:
                //store.set(u, 1f, v, 0);
                bias = 1f / texelVect.y;
                u = texelVect.x;
                v = texelVect.z;
                break;
            case 3:
                //store.set(u, -1f, -v, 0);
                bias = -1f / texelVect.y;
                u = texelVect.x;
                v = -texelVect.z;
                break;
            case 4:
                //store.set(u, -v, 1f, 0);
                bias = 1f / texelVect.z;
                u = texelVect.x;
                v = -texelVect.y;
                break;
            case 5:
                //store.set(-u, -v, -1.0f, 0);
                bias = -1f / texelVect.z;
                u = -texelVect.x;
                v = -texelVect.y;
                break;
        }
        u *= bias;
        v *= bias;

        if (fixSeamsMethod == FixSeamsMethod.Stretch) {
            /* Code from Nvtt : http://code.google.com/p/nvidia-texture-tools/source/browse/trunk/src/nvtt/CubeSurface.cpp
             * transform from [0..res - 1] to [-1 .. 1], match up edges exactly. */
            u = Math.round((u + 1.0f) * (mapSize - 1.0f) * 0.5f);
            v = Math.round((v + 1.0f) * (mapSize - 1.0f) * 0.5f);
        } else {
            //Done if any other fix method or no fix method is set
            /* transform from [0..res - 1] to [- (1 - 1 / res) .. (1 - 1 / res)]
             * (+ 0.5f is for texel center addressing) */
            u = Math.round((u + 1.0f) * mapSize * 0.5f - 0.5f);
            v = Math.round((v + 1.0f) * mapSize * 0.5f - 0.5f);

        }

        store.set(u, v);
        return face;
    }
Computes the texture coordinates and the face of the cube map from the
given vector

@param texelVect the vector to fetch texels from the cube map
@param fixSeamsMethod the method to fix the seams
@param mapSize the size of one face of the cube map
@param store a Vector2f where the texture coordinates will be stored
@return the face from which to fetch the texel
jme3-core/src/main/java/com/jme3/environment/util/EnvMapUtils.java