Search in sources :

Example 1 with CenterQuad

use of com.jme3.scene.CenterQuad in project jmonkeyengine by jMonkeyEngine.

the class VRGuiManager method getGuiQuad.

/**
	 * Create a GUI quad for the given camera.
	 * @param sourceCam the camera
	 * @return a GUI quad for the given camera.
	 */
private Spatial getGuiQuad(Camera sourceCam) {
    if (environment != null) {
        if (environment.getApplication() != null) {
            if (guiQuadNode == null) {
                Vector2f guiCanvasSize = getCanvasSize();
                Camera offCamera = sourceCam.clone();
                offCamera.setParallelProjection(true);
                offCamera.setLocation(Vector3f.ZERO);
                offCamera.lookAt(Vector3f.UNIT_Z, Vector3f.UNIT_Y);
                offView = environment.getApplication().getRenderManager().createPreView("GUI View", offCamera);
                offView.setClearFlags(true, true, true);
                offView.setBackgroundColor(ColorRGBA.BlackNoAlpha);
                // create offscreen framebuffer
                FrameBuffer offBuffer = new FrameBuffer((int) guiCanvasSize.x, (int) guiCanvasSize.y, 1);
                //setup framebuffer's texture
                guiTexture = new Texture2D((int) guiCanvasSize.x, (int) guiCanvasSize.y, Format.RGBA8);
                guiTexture.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
                guiTexture.setMagFilter(Texture.MagFilter.Bilinear);
                //setup framebuffer to use texture
                offBuffer.setDepthBuffer(Format.Depth);
                offBuffer.setColorTexture(guiTexture);
                //set viewport to render to offscreen framebuffer
                offView.setOutputFrameBuffer(offBuffer);
                // setup framebuffer's scene
                Iterator<Spatial> spatialIter = environment.getApplication().getGuiViewPort().getScenes().iterator();
                while (spatialIter.hasNext()) {
                    offView.attachScene(spatialIter.next());
                }
                if (useCurvedSurface) {
                    guiQuad = (Geometry) environment.getApplication().getAssetManager().loadModel("Common/Util/gui_mesh.j3o");
                } else {
                    guiQuad = new Geometry("guiQuad", new CenterQuad(1f, 1f));
                }
                Material mat = new Material(environment.getApplication().getAssetManager(), "Common/MatDefs/VR/GuiOverlay.j3md");
                mat.getAdditionalRenderState().setDepthTest(!overdraw);
                mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
                mat.getAdditionalRenderState().setDepthWrite(false);
                mat.setTexture("ColorMap", guiTexture);
                guiQuad.setQueueBucket(Bucket.Translucent);
                guiQuad.setMaterial(mat);
                guiQuadNode = new Node("gui-quad-node");
                guiQuadNode.setQueueBucket(Bucket.Translucent);
                guiQuadNode.attachChild(guiQuad);
            }
            return guiQuadNode;
        } else {
            throw new IllegalStateException("VR GUI manager underlying environment is not attached to any application.");
        }
    } else {
        throw new IllegalStateException("VR GUI manager is not attached to any environment.");
    }
}
Also used : Geometry(com.jme3.scene.Geometry) Texture2D(com.jme3.texture.Texture2D) Spatial(com.jme3.scene.Spatial) Vector2f(com.jme3.math.Vector2f) Node(com.jme3.scene.Node) Material(com.jme3.material.Material) Camera(com.jme3.renderer.Camera) FrameBuffer(com.jme3.texture.FrameBuffer) CenterQuad(com.jme3.scene.CenterQuad)

Aggregations

Material (com.jme3.material.Material)1 Vector2f (com.jme3.math.Vector2f)1 Camera (com.jme3.renderer.Camera)1 CenterQuad (com.jme3.scene.CenterQuad)1 Geometry (com.jme3.scene.Geometry)1 Node (com.jme3.scene.Node)1 Spatial (com.jme3.scene.Spatial)1 FrameBuffer (com.jme3.texture.FrameBuffer)1 Texture2D (com.jme3.texture.Texture2D)1