Search in sources :

Example 31 with Environment

use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.

the class VRViewManagerOSVR method setupCamerasAndViews.

private void setupCamerasAndViews() {
    if (environment != null) {
        if (environment.getApplication() != null) {
            // get desired frustrum from original camera
            Camera origCam = environment.getCamera();
            float fFar = origCam.getFrustumFar();
            float fNear = origCam.getFrustumNear();
            // if we are using OSVR get the eye info here
            if (environment.getVRHardware() instanceof OSVR) {
                ((OSVR) environment.getVRHardware()).getEyeInfo();
            }
            // restore frustrum on distortion scene cam, if needed
            if (environment.isInstanceRendering()) {
                leftCamera = origCam;
            } else if (environment.compositorAllowed() == false) {
                origCam.setFrustumFar(100f);
                origCam.setFrustumNear(1f);
                leftCamera = origCam.clone();
                prepareCameraSize(origCam, 2f);
            } else {
                leftCamera = origCam.clone();
            }
            leftCamera.setFrustumPerspective(environment.getDefaultFOV(), environment.getDefaultAspect(), fNear, fFar);
            prepareCameraSize(leftCamera, 1f);
            if (environment.getVRHardware() != null)
                leftCamera.setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionLeftEye(leftCamera));
            if (!environment.isInstanceRendering()) {
                leftViewport = setupViewBuffers(leftCamera, LEFT_VIEW_NAME);
                rightCamera = leftCamera.clone();
                if (environment.getVRHardware() != null) {
                    rightCamera.setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(rightCamera));
                }
                rightViewport = setupViewBuffers(rightCamera, RIGHT_VIEW_NAME);
            } else {
                System.err.println("[VRViewManager] THIS CODE NEED CHANGES !!!");
                leftViewport = environment.getApplication().getViewPort();
                //leftViewport.attachScene(app.getRootNode());
                rightCamera = leftCamera.clone();
                if (environment.getVRHardware() != null) {
                    rightCamera.setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(rightCamera));
                }
                org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_CLIP_DISTANCE0);
                //FIXME: [jme-vr] Fix with JMonkey next release
                //RenderManager._VRInstancing_RightCamProjection = camRight.getViewProjectionMatrix();
                setupFinalFullTexture(environment.getApplication().getViewPort().getCamera());
            }
            // setup gui
            environment.getVRGUIManager().setupGui(leftCamera, rightCamera, leftViewport, rightViewport);
            if (environment.getVRHardware() != null) {
                // call these to cache the results internally
                environment.getVRHardware().getHMDMatrixPoseLeftEye();
                environment.getVRHardware().getHMDMatrixPoseRightEye();
            }
        } 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) Camera(com.jme3.renderer.Camera)

Example 32 with Environment

use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.

the class VRViewManagerOSVR 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 33 with Environment

use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.

the class VRViewManagerOSVR method update.

/**
     * Update the VR view manager. 
     * This method is called by the attached {@link VRApplication VR application} and should not be called manually.
     * @param tpf the time per frame.
     */
public void update(float tpf) {
    if (environment != null) {
        // grab the observer
        Object obs = environment.getObserver();
        Quaternion objRot;
        Vector3f objPos;
        if (obs instanceof Camera) {
            objRot = ((Camera) obs).getRotation();
            objPos = ((Camera) obs).getLocation();
        } else {
            objRot = ((Spatial) obs).getWorldRotation();
            objPos = ((Spatial) obs).getWorldTranslation();
        }
        // grab the hardware handle
        VRAPI dev = environment.getVRHardware();
        if (dev != null) {
            // update the HMD's position & orientation
            dev.updatePose();
            dev.getPositionAndOrientation(hmdPos, hmdRot);
            if (obs != null) {
                // update hmdPos based on obs rotation
                finalRotation.set(objRot);
                finalRotation.mult(hmdPos, hmdPos);
                finalRotation.multLocal(hmdRot);
            }
            finalizeCamera(dev.getHMDVectorPoseLeftEye(), objPos, leftCamera);
            finalizeCamera(dev.getHMDVectorPoseRightEye(), objPos, rightCamera);
        } else {
            leftCamera.setFrame(objPos, objRot);
            rightCamera.setFrame(objPos, objRot);
        }
        if (environment.hasTraditionalGUIOverlay()) {
            // update the mouse?
            environment.getVRMouseManager().update(tpf);
            // update GUI position?
            if (environment.getVRGUIManager().wantsReposition || environment.getVRGUIManager().getPositioningMode() != VRGUIPositioningMode.MANUAL) {
                environment.getVRGUIManager().positionGuiNow(tpf);
                environment.getVRGUIManager().updateGuiQuadGeometricState();
            }
        }
    } else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
    }
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) Camera(com.jme3.renderer.Camera) VRAPI(com.jme3.input.vr.VRAPI)

Example 34 with Environment

use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.

the class VRViewManagerOpenVR method setupVRScene.

/**
     * Replaces rootNode as the main cameras scene with the distortion mesh
     */
private void setupVRScene() {
    if (environment != null) {
        if (environment.getApplication() != null) {
            // no special scene to setup if we are doing instancing
            if (environment.isInstanceRendering()) {
                // distortion has to be done with compositor here... we want only one pass on our end!
                if (environment.getApplication().getContext().getSettings().isSwapBuffers()) {
                    setupMirrorBuffers(environment.getCamera(), dualEyeTex, true);
                }
                return;
            }
            leftEyeTexture = (Texture2D) getLeftViewport().getOutputFrameBuffer().getColorBuffer().getTexture();
            rightEyeTexture = (Texture2D) getRightViewport().getOutputFrameBuffer().getColorBuffer().getTexture();
            leftEyeDepth = (Texture2D) getLeftViewport().getOutputFrameBuffer().getDepthBuffer().getTexture();
            rightEyeDepth = (Texture2D) getRightViewport().getOutputFrameBuffer().getDepthBuffer().getTexture();
            // main viewport is either going to be a distortion scene or nothing
            // mirroring is handled by copying framebuffers
            Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator();
            while (spatialIter.hasNext()) {
                environment.getApplication().getViewPort().detachScene(spatialIter.next());
            }
            spatialIter = environment.getApplication().getGuiViewPort().getScenes().iterator();
            while (spatialIter.hasNext()) {
                environment.getApplication().getGuiViewPort().detachScene(spatialIter.next());
            }
            // only setup distortion scene if compositor isn't running (or using custom mesh distortion option)
            if (environment.getVRHardware().getCompositor() == null) {
                Node distortionScene = new Node();
                Material leftMat = new Material(environment.getApplication().getAssetManager(), "Common/MatDefs/VR/OpenVR.j3md");
                leftMat.setTexture("Texture", leftEyeTexture);
                Geometry leftEye = new Geometry("box", setupDistortionMesh(JOpenVRLibrary.EVREye.EVREye_Eye_Left, environment.getVRHardware()));
                leftEye.setMaterial(leftMat);
                distortionScene.attachChild(leftEye);
                Material rightMat = new Material(environment.getApplication().getAssetManager(), "Common/MatDefs/VR/OpenVR.j3md");
                rightMat.setTexture("Texture", rightEyeTexture);
                Geometry rightEye = new Geometry("box", setupDistortionMesh(JOpenVRLibrary.EVREye.EVREye_Eye_Right, environment.getVRHardware()));
                rightEye.setMaterial(rightMat);
                distortionScene.attachChild(rightEye);
                distortionScene.updateGeometricState();
                environment.getApplication().getViewPort().attachScene(distortionScene);
            //if( useCustomDistortion ) setupFinalFullTexture(app.getViewPort().getCamera());
            }
            if (environment.getApplication().getContext().getSettings().isSwapBuffers()) {
                setupMirrorBuffers(environment.getCamera(), leftEyeTexture, 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 : Geometry(com.jme3.scene.Geometry) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) Material(com.jme3.material.Material)

Example 35 with Environment

use of com.jme3.audio.Environment in project jmonkeyengine by jMonkeyEngine.

the class VRViewManagerOpenVR method setupCamerasAndViews.

private void setupCamerasAndViews() {
    if (environment != null) {
        // get desired frustrum from original camera
        Camera origCam = environment.getCamera();
        float fFar = origCam.getFrustumFar();
        float fNear = origCam.getFrustumNear();
        // restore frustrum on distortion scene cam, if needed
        if (environment.isInstanceRendering()) {
            leftCamera = origCam;
        } else if (environment.compositorAllowed() == false) {
            origCam.setFrustumFar(100f);
            origCam.setFrustumNear(1f);
            leftCamera = origCam.clone();
            prepareCameraSize(origCam, 2f);
        } else {
            leftCamera = origCam.clone();
        }
        getLeftCamera().setFrustumPerspective(environment.getDefaultFOV(), environment.getDefaultAspect(), fNear, fFar);
        prepareCameraSize(getLeftCamera(), 1f);
        if (environment.getVRHardware() != null) {
            getLeftCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionLeftEye(getLeftCamera()));
        }
        if (!environment.isInstanceRendering()) {
            leftViewport = setupViewBuffers(getLeftCamera(), LEFT_VIEW_NAME);
            rightCamera = getLeftCamera().clone();
            if (environment.getVRHardware() != null) {
                getRightCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(getRightCamera()));
            }
            rightViewport = setupViewBuffers(getRightCamera(), RIGHT_VIEW_NAME);
        } else {
            if (environment.getApplication() != null) {
                logger.severe("THIS CODE NEED CHANGES !!!");
                leftViewport = environment.getApplication().getViewPort();
                //leftViewport.attachScene(app.getRootNode());
                rightCamera = getLeftCamera().clone();
                if (environment.getVRHardware() != null) {
                    getRightCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(getRightCamera()));
                }
                org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_CLIP_DISTANCE0);
                //FIXME: [jme-vr] Fix with JMonkey next release
                //RenderManager._VRInstancing_RightCamProjection = camRight.getViewProjectionMatrix();
                setupFinalFullTexture(environment.getApplication().getViewPort().getCamera());
            } else {
                throw new IllegalStateException("This VR environment is not attached to any application.");
            }
        }
        // setup gui
        environment.getVRGUIManager().setupGui(getLeftCamera(), getRightCamera(), getLeftViewport(), getRightViewport());
        if (environment.getVRHardware() != null) {
            // call these to cache the results internally
            environment.getVRHardware().getHMDMatrixPoseLeftEye();
            environment.getVRHardware().getHMDMatrixPoseRightEye();
        }
    } else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
    }
}
Also used : Camera(com.jme3.renderer.Camera)

Aggregations

Camera (com.jme3.renderer.Camera)9 Vector2f (com.jme3.math.Vector2f)8 Vector3f (com.jme3.math.Vector3f)8 Spatial (com.jme3.scene.Spatial)7 VRAPI (com.jme3.input.vr.VRAPI)6 ViewPort (com.jme3.renderer.ViewPort)6 Texture2D (com.jme3.texture.Texture2D)6 Material (com.jme3.material.Material)5 Geometry (com.jme3.scene.Geometry)5 Node (com.jme3.scene.Node)5 FrameBuffer (com.jme3.texture.FrameBuffer)5 AudioNode (com.jme3.audio.AudioNode)4 OSVR (com.jme3.input.vr.OSVR)4 Quaternion (com.jme3.math.Quaternion)4 OpenVR (com.jme3.input.vr.OpenVR)3 ColorRGBA (com.jme3.math.ColorRGBA)3 FilterPostProcessor (com.jme3.post.FilterPostProcessor)3 Environment (com.jme3.audio.Environment)2 AmbientLight (com.jme3.light.AmbientLight)2 CartoonSSAO (com.jme3.post.CartoonSSAO)2