@Override
    public void bakeEnvironment(Spatial scene, Vector3f position, float frustumNear, float frustumFar, Predicate<Geometry> filter) {
        FrameBuffer envbakers[] = new FrameBuffer[6];
        for (int i = 0; i < 6; i++) {
            envbakers[i] = new FrameBuffer(envMap.getImage().getWidth(), envMap.getImage().getHeight(), 1);
            envbakers[i].setDepthTarget(FrameBufferTarget.newTarget(depthFormat));
            envbakers[i].setSrgb(false);
            envbakers[i].addColorTarget(FrameBufferTarget.newTarget(envMap).face(TextureCubeMap.Face.values()[i]));
        }

        if (isTexturePulling()) {
            startPulling();
        }

        for (int i = 0; i < 6; i++) {
            FrameBuffer envbaker = envbakers[i];

            ViewPort viewPort = new ViewPort("EnvBaker", updateAndGetInternalCamera(i, envbaker.getWidth(), envbaker.getHeight(), position, frustumNear, frustumFar));
            viewPort.setClearFlags(true, true, true);
            viewPort.setBackgroundColor(ColorRGBA.Pink);

            viewPort.setOutputFrameBuffer(envbaker);
            viewPort.clearScenes();
            viewPort.attachScene(scene);

            scene.updateLogicalState(0);
            scene.updateGeometricState();

            Predicate<Geometry> ofilter = renderManager.getRenderFilter();

            renderManager.setRenderFilter(filter);
            renderManager.renderViewPort(viewPort, 0.16f);
            renderManager.setRenderFilter(ofilter);

            if (isTexturePulling()) {
                pull(envbaker, envMap, i);
            }

        }

        if (isTexturePulling()) {
            endPulling(envMap);
        }

        envMap.getImage().clearUpdateNeeded();

        for (int i = 0; i < 6; i++) {
            envbakers[i].dispose();
        }
    }
Updates the internal camera to face the given cubemap face
and return it.

@param faceId
           the id of the face (0-5)
@param w
           width of the camera
@param h
           height of the camera
@param position
           position of the camera
@param frustumNear
           near frustum
@param frustumFar
           far frustum
@return The updated camera
jme3-core/src/main/java/com/jme3/environment/baker/GenericEnvBaker.java