Search in sources :

Example 11 with Application

use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.

the class VRViewManagerOSVR method setupViewBuffers.

private ViewPort setupViewBuffers(Camera cam, String viewName) {
    if (environment != null) {
        if (environment.getApplication() != null) {
            // create offscreen framebuffer
            FrameBuffer offBufferLeft = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
            //offBufferLeft.setSrgb(true);
            //setup framebuffer's texture
            Texture2D offTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
            offTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
            offTex.setMagFilter(Texture.MagFilter.Bilinear);
            //setup framebuffer to use texture
            offBufferLeft.setDepthBuffer(Image.Format.Depth);
            offBufferLeft.setColorTexture(offTex);
            ViewPort viewPort = environment.getApplication().getRenderManager().createPreView(viewName, cam);
            viewPort.setClearFlags(true, true, true);
            viewPort.setBackgroundColor(ColorRGBA.Black);
            Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator();
            while (spatialIter.hasNext()) {
                viewPort.attachScene(spatialIter.next());
            }
            //set viewport to render to offscreen framebuffer
            viewPort.setOutputFrameBuffer(offBufferLeft);
            return viewPort;
        } else {
            throw new IllegalStateException("This VR environment is not attached to any application.");
        }
    } else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
    }
}
Also used : Texture2D(com.jme3.texture.Texture2D) Spatial(com.jme3.scene.Spatial) ViewPort(com.jme3.renderer.ViewPort) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 12 with Application

use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.

the class VRViewManagerOSVR method initialize.

/**
     * Initialize the VR view manager.
     */
public void initialize() {
    logger.config("Initializing VR view manager.");
    if (environment != null) {
        initTextureSubmitStructs();
        setupCamerasAndViews();
        setupVRScene();
        moveScreenProcessingToEyes();
        if (environment.hasTraditionalGUIOverlay()) {
            environment.getVRMouseManager().initialize();
            // update the pose to position the gui correctly on start
            update(0f);
            environment.getVRGUIManager().positionGui();
        }
        if (environment.getApplication() != null) {
            // if we are OSVR, our primary mirror window needs to be the same size as the render manager's output...
            if (environment.getVRHardware() instanceof OSVR) {
                int origWidth = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getWidth();
                int origHeight = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode().getHeight();
                long window = ((LwjglWindow) environment.getApplication().getContext()).getWindowHandle();
                Vector2f windowSize = new Vector2f();
                ((OSVR) environment.getVRHardware()).getRenderSize(windowSize);
                windowSize.x = Math.max(windowSize.x * 2f, leftCamera.getWidth());
                org.lwjgl.glfw.GLFW.glfwSetWindowSize(window, (int) windowSize.x, (int) windowSize.y);
                environment.getApplication().getContext().getSettings().setResolution((int) windowSize.x, (int) windowSize.y);
                if (environment.getApplication().getRenderManager() != null) {
                    environment.getApplication().getRenderManager().notifyReshape((int) windowSize.x, (int) windowSize.y);
                }
                org.lwjgl.glfw.GLFW.glfwSetWindowPos(window, origWidth - (int) windowSize.x, 32);
                org.lwjgl.glfw.GLFW.glfwFocusWindow(window);
                org.lwjgl.glfw.GLFW.glfwSetCursorPos(window, origWidth / 2.0, origHeight / 2.0);
                logger.config("Initialized VR view manager [SUCCESS]");
            } else {
                throw new IllegalStateException("Underlying VR hardware should be " + OSVR.class.getSimpleName());
            }
        } else {
            throw new IllegalStateException("This VR environment is not attached to any application.");
        }
    } else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
    }
}
Also used : OSVR(com.jme3.input.vr.OSVR) Vector2f(com.jme3.math.Vector2f) LwjglWindow(com.jme3.system.lwjgl.LwjglWindow)

Example 13 with Application

use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.

the class VRViewManagerOpenVR method prepareCameraSize.

/**
     * Prepare the size of the given {@link Camera camera} to adapt it to the underlying rendering context.
     * @param cam the {@link Camera camera} to prepare.
     * @param xMult the camera width multiplier.
     */
private void prepareCameraSize(Camera cam, float xMult) {
    if (environment != null) {
        if (environment.getApplication() != null) {
            Vector2f size = new Vector2f();
            VRAPI vrhmd = environment.getVRHardware();
            if (vrhmd == null) {
                size.x = 1280f;
                size.y = 720f;
            } else {
                vrhmd.getRenderSize(size);
            }
            if (size.x < environment.getApplication().getContext().getSettings().getWidth()) {
                size.x = environment.getApplication().getContext().getSettings().getWidth();
            }
            if (size.y < environment.getApplication().getContext().getSettings().getHeight()) {
                size.y = environment.getApplication().getContext().getSettings().getHeight();
            }
            if (environment.isInstanceRendering()) {
                size.x *= 2f;
            }
            // other adjustments
            size.x *= xMult;
            size.x *= getResolutionMuliplier();
            size.y *= getResolutionMuliplier();
            if (cam.getWidth() != size.x || cam.getHeight() != size.y) {
                cam.resize((int) size.x, (int) size.y, false);
            }
        } else {
            throw new IllegalStateException("This VR environment is not attached to any application.");
        }
    } else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
    }
}
Also used : Vector2f(com.jme3.math.Vector2f) VRAPI(com.jme3.input.vr.VRAPI)

Example 14 with Application

use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.

the class VRViewManagerOpenVR method setupMirrorBuffers.

private ViewPort setupMirrorBuffers(Camera cam, Texture tex, boolean expand) {
    if (environment != null) {
        if (environment.getApplication() != null) {
            Camera clonecam = cam.clone();
            ViewPort viewPort = environment.getApplication().getRenderManager().createPostView("MirrorView", clonecam);
            clonecam.setParallelProjection(true);
            viewPort.setClearFlags(true, true, true);
            viewPort.setBackgroundColor(ColorRGBA.Black);
            Picture pic = new Picture("fullscene");
            pic.setLocalTranslation(-0.75f, -0.5f, 0f);
            if (expand) {
                pic.setLocalScale(3f, 1f, 1f);
            } else {
                pic.setLocalScale(1.5f, 1f, 1f);
            }
            pic.setQueueBucket(Bucket.Opaque);
            pic.setTexture(environment.getApplication().getAssetManager(), (Texture2D) tex, false);
            viewPort.attachScene(pic);
            viewPort.setOutputFrameBuffer(null);
            pic.updateGeometricState();
            return viewPort;
        } else {
            throw new IllegalStateException("This VR environment is not attached to any application.");
        }
    } else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
    }
}
Also used : Picture(com.jme3.ui.Picture) ViewPort(com.jme3.renderer.ViewPort) Camera(com.jme3.renderer.Camera)

Example 15 with Application

use of com.jme3.app.Application in project jmonkeyengine by jMonkeyEngine.

the class VRViewManagerOpenVR method setupViewBuffers.

private ViewPort setupViewBuffers(Camera cam, String viewName) {
    if (environment != null) {
        if (environment.getApplication() != null) {
            // create offscreen framebuffer
            FrameBuffer offBufferLeft = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
            //offBufferLeft.setSrgb(true);
            //setup framebuffer's texture
            Texture2D offTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
            offTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
            offTex.setMagFilter(Texture.MagFilter.Bilinear);
            //setup framebuffer to use texture
            offBufferLeft.setDepthBuffer(Image.Format.Depth);
            offBufferLeft.setColorTexture(offTex);
            ViewPort viewPort = environment.getApplication().getRenderManager().createPreView(viewName, cam);
            viewPort.setClearFlags(true, true, true);
            viewPort.setBackgroundColor(ColorRGBA.Black);
            Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator();
            while (spatialIter.hasNext()) {
                viewPort.attachScene(spatialIter.next());
            }
            //set viewport to render to offscreen framebuffer
            viewPort.setOutputFrameBuffer(offBufferLeft);
            return viewPort;
        } else {
            throw new IllegalStateException("This VR environment is not attached to any application.");
        }
    } else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
    }
}
Also used : Texture2D(com.jme3.texture.Texture2D) Spatial(com.jme3.scene.Spatial) ViewPort(com.jme3.renderer.ViewPort) FrameBuffer(com.jme3.texture.FrameBuffer)

Aggregations

AppSettings (com.jme3.system.AppSettings)11 Material (com.jme3.material.Material)10 Vector2f (com.jme3.math.Vector2f)8 ViewPort (com.jme3.renderer.ViewPort)8 Geometry (com.jme3.scene.Geometry)8 Camera (com.jme3.renderer.Camera)6 Spatial (com.jme3.scene.Spatial)6 Texture2D (com.jme3.texture.Texture2D)6 Node (com.jme3.scene.Node)5 FrameBuffer (com.jme3.texture.FrameBuffer)5 KeyTrigger (com.jme3.input.controls.KeyTrigger)4 InputManager (com.jme3.input.InputManager)3 OSVR (com.jme3.input.vr.OSVR)3 VRAPI (com.jme3.input.vr.VRAPI)3 Application (ca.uhn.hl7v2.app.Application)2 BitmapText (com.jme3.font.BitmapText)2 MouseInput (com.jme3.input.MouseInput)2 ActionListener (com.jme3.input.controls.ActionListener)2 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)2 Vector3f (com.jme3.math.Vector3f)2