Search in sources :

Example 1 with Environment

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

the class AbstractVRViewManager method syncScreenProcessing.

/**
     * Sets the two views to use the list of {@link SceneProcessor processors}.
     * @param sourceViewport the {@link ViewPort viewport} that contains the processors to use.
     */
public void syncScreenProcessing(ViewPort sourceViewport) {
    if (environment != null) {
        if (getRightViewport() == null) {
            return;
        }
        if (environment.getApplication() != null) {
            // setup post processing filters
            if (getRightPostProcessor() == null) {
                rightPostProcessor = new FilterPostProcessor(environment.getApplication().getAssetManager());
                leftPostProcessor = new FilterPostProcessor(environment.getApplication().getAssetManager());
            }
            // clear out all filters & processors, to start from scratch
            getRightPostProcessor().removeAllFilters();
            getLeftPostProcessor().removeAllFilters();
            getLeftViewport().clearProcessors();
            getRightViewport().clearProcessors();
            // if we have no processors to sync, don't add the FilterPostProcessor
            if (sourceViewport.getProcessors().isEmpty())
                return;
            // add post processors we just made, which are empty
            getLeftViewport().addProcessor(getLeftPostProcessor());
            getRightViewport().addProcessor(getRightPostProcessor());
            // add them to the left viewport processor & clone them to the right
            for (SceneProcessor sceneProcessor : sourceViewport.getProcessors()) {
                if (sceneProcessor instanceof FilterPostProcessor) {
                    for (Filter f : ((FilterPostProcessor) sceneProcessor).getFilterList()) {
                        if (f instanceof TranslucentBucketFilter) {
                            // just remove this filter, we will add it at the end manually
                            ((FilterPostProcessor) sceneProcessor).removeFilter(f);
                        } else {
                            getLeftPostProcessor().addFilter(f);
                            // clone to the right
                            Filter f2;
                            if (f instanceof FogFilter) {
                                f2 = FilterUtil.cloneFogFilter((FogFilter) f);
                            } else if (f instanceof CartoonSSAO) {
                                f2 = new CartoonSSAO((CartoonSSAO) f);
                            } else if (f instanceof SSAOFilter) {
                                f2 = FilterUtil.cloneSSAOFilter((SSAOFilter) f);
                            } else if (f instanceof DirectionalLightShadowFilter) {
                                f2 = FilterUtil.cloneDirectionalLightShadowFilter(environment.getApplication().getAssetManager(), (DirectionalLightShadowFilter) f);
                            } else {
                                // dof, bloom, lightscattering etc.
                                f2 = f;
                            }
                            getRightPostProcessor().addFilter(f2);
                        }
                    }
                } else if (sceneProcessor instanceof VRDirectionalLightShadowRenderer) {
                    // shadow processing
                    // TODO: make right shadow processor use same left shadow maps for performance
                    VRDirectionalLightShadowRenderer dlsr = (VRDirectionalLightShadowRenderer) sceneProcessor;
                    VRDirectionalLightShadowRenderer dlsrRight = dlsr.clone();
                    dlsrRight.setLight(dlsr.getLight());
                    getRightViewport().getProcessors().add(0, dlsrRight);
                    getLeftViewport().getProcessors().add(0, sceneProcessor);
                }
            }
            // make sure each has a translucent filter renderer
            getLeftPostProcessor().addFilter(new TranslucentBucketFilter());
            getRightPostProcessor().addFilter(new TranslucentBucketFilter());
        } else {
            throw new IllegalStateException("The 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 : SSAOFilter(com.jme3.post.ssao.SSAOFilter) TranslucentBucketFilter(com.jme3.post.filters.TranslucentBucketFilter) VRDirectionalLightShadowRenderer(com.jme3.shadow.VRDirectionalLightShadowRenderer) FogFilter(com.jme3.post.filters.FogFilter) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter) TranslucentBucketFilter(com.jme3.post.filters.TranslucentBucketFilter) Filter(com.jme3.post.Filter) SSAOFilter(com.jme3.post.ssao.SSAOFilter) FilterPostProcessor(com.jme3.post.FilterPostProcessor) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter) FogFilter(com.jme3.post.filters.FogFilter) SceneProcessor(com.jme3.post.SceneProcessor) CartoonSSAO(com.jme3.post.CartoonSSAO)

Example 2 with Environment

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

the class VRGuiManager method positionGuiNow.

/**
	 * Position the GUI without delay.
	 * @param tpf the time per frame.
	 */
protected void positionGuiNow(float tpf) {
    if (environment != null) {
        wantsReposition = false;
        if (environment.isInVR() == false) {
            return;
        }
        guiQuadNode.setLocalScale(guiDistance * guiScale * 4f, 4f * guiDistance * guiScale, 1f);
        switch(posMode) {
            case MANUAL:
            case AUTO_CAM_ALL_SKIP_PITCH:
            case AUTO_CAM_ALL:
                if (camLeft != null && camRight != null) {
                    // get middle point
                    temppos.set(camLeft.getLocation()).interpolateLocal(camRight.getLocation(), 0.5f);
                    positionTo(temppos, camLeft.getRotation(), tpf);
                }
                rotateScreenTo(camLeft.getRotation(), tpf);
                break;
            case AUTO_OBSERVER_POS_CAM_ROTATION:
                Object obs = environment.getObserver();
                if (obs != null) {
                    if (obs instanceof Camera) {
                        positionTo(((Camera) obs).getLocation(), camLeft.getRotation(), tpf);
                    } else {
                        positionTo(((Spatial) obs).getWorldTranslation(), camLeft.getRotation(), tpf);
                    }
                }
                rotateScreenTo(camLeft.getRotation(), tpf);
                break;
            case AUTO_OBSERVER_ALL:
            case AUTO_OBSERVER_ALL_CAMHEIGHT:
                obs = environment.getObserver();
                if (obs != null) {
                    Quaternion q;
                    if (obs instanceof Camera) {
                        q = ((Camera) obs).getRotation();
                        temppos.set(((Camera) obs).getLocation());
                    } else {
                        q = ((Spatial) obs).getWorldRotation();
                        temppos.set(((Spatial) obs).getWorldTranslation());
                    }
                    if (posMode == VRGUIPositioningMode.AUTO_OBSERVER_ALL_CAMHEIGHT) {
                        temppos.y = camLeft.getLocation().y;
                    }
                    positionTo(temppos, q, tpf);
                    rotateScreenTo(q, tpf);
                }
                break;
        }
    } else {
        throw new IllegalStateException("VR GUI manager is not attached to any environment.");
    }
}
Also used : Quaternion(com.jme3.math.Quaternion) Camera(com.jme3.renderer.Camera)

Example 3 with Environment

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

the class VRMouseManager method setImage.

/**
     * Set the image to use as mouse cursor. The given string describe an asset that the underlying application asset manager has to load.
     * @param texture the image to use as mouse cursor.
     */
public void setImage(String texture) {
    if (environment != null) {
        if (environment.getApplication() != null) {
            if (environment.isInVR() == false) {
                Texture tex = environment.getApplication().getAssetManager().loadTexture(texture);
                mouseImage.setTexture(environment.getApplication().getAssetManager(), (Texture2D) tex, true);
                ySize = tex.getImage().getHeight();
                mouseImage.setHeight(ySize);
                mouseImage.setWidth(tex.getImage().getWidth());
                mouseImage.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
                mouseImage.getMaterial().getAdditionalRenderState().setDepthWrite(false);
            } else {
                Texture tex = environment.getApplication().getAssetManager().loadTexture(texture);
                mouseImage.setTexture(environment.getApplication().getAssetManager(), (Texture2D) tex, true);
                ySize = tex.getImage().getHeight();
                mouseImage.setHeight(ySize);
                mouseImage.setWidth(tex.getImage().getWidth());
                mouseImage.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
                mouseImage.getMaterial().getAdditionalRenderState().setDepthWrite(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 : Texture(com.jme3.texture.Texture)

Example 4 with Environment

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

the class VRMouseManager method centerMouse.

/**
     * Center the mouse on the display.
     */
public void centerMouse() {
    if (environment != null) {
        if (environment.getApplication() != null) {
            // set mouse in center of the screen if newly added
            Vector2f size = environment.getVRGUIManager().getCanvasSize();
            MouseInput mi = environment.getApplication().getContext().getMouseInput();
            AppSettings as = environment.getApplication().getContext().getSettings();
            if (mi instanceof GlfwMouseInputVR)
                ((GlfwMouseInputVR) mi).setCursorPosition((int) (as.getWidth() / 2f), (int) (as.getHeight() / 2f));
            if (environment.isInVR()) {
                cursorPos.x = size.x / 2f;
                cursorPos.y = size.y / 2f;
                recentCenterCount = 2;
            }
        } 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 : GlfwMouseInputVR(com.jme3.input.lwjgl.GlfwMouseInputVR) AppSettings(com.jme3.system.AppSettings) Vector2f(com.jme3.math.Vector2f) MouseInput(com.jme3.input.MouseInput)

Example 5 with Environment

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

the class VRMouseManager method updateAnalogAsMouse.

/**
     * Update analog controller as it was a mouse controller.
     * @param inputIndex the index of the controller attached to the VR system.
     * @param mouseListener the JMonkey mouse listener to trigger.
     * @param mouseXName the mouseX identifier.
     * @param mouseYName the mouseY identifier
     * @param tpf the time per frame.
     */
public void updateAnalogAsMouse(int inputIndex, AnalogListener mouseListener, String mouseXName, String mouseYName, float tpf) {
    if (environment != null) {
        if (environment.getApplication() != null) {
            // got a tracked controller to use as the "mouse"
            if (environment.isInVR() == false || environment.getVRinput() == null || environment.getVRinput().isInputDeviceTracking(inputIndex) == false) {
                return;
            }
            Vector2f tpDelta;
            if (thumbstickMode) {
                tpDelta = environment.getVRinput().getAxis(inputIndex, VRInputType.ViveTrackpadAxis);
            } else {
                tpDelta = environment.getVRinput().getAxisDeltaSinceLastCall(inputIndex, VRInputType.ViveTrackpadAxis);
            }
            float Xamount = (float) Math.pow(Math.abs(tpDelta.x) * sensitivity, acceleration);
            float Yamount = (float) Math.pow(Math.abs(tpDelta.y) * sensitivity, acceleration);
            if (tpDelta.x < 0f) {
                Xamount = -Xamount;
            }
            if (tpDelta.y < 0f) {
                Yamount = -Yamount;
            }
            Xamount *= moveScale;
            Yamount *= moveScale;
            if (mouseListener != null) {
                if (tpDelta.x != 0f && mouseXName != null)
                    mouseListener.onAnalog(mouseXName, Xamount * 0.2f, tpf);
                if (tpDelta.y != 0f && mouseYName != null)
                    mouseListener.onAnalog(mouseYName, Yamount * 0.2f, tpf);
            }
            if (environment.getApplication().getInputManager().isCursorVisible()) {
                int index = (avgCounter + 1) % AVERAGE_AMNT;
                lastXmv[index] = Xamount * 133f;
                lastYmv[index] = Yamount * 133f;
                cursorPos.x -= avg(lastXmv);
                cursorPos.y -= avg(lastYmv);
                Vector2f maxsize = environment.getVRGUIManager().getCanvasSize();
                if (cursorPos.x > maxsize.x) {
                    cursorPos.x = maxsize.x;
                }
                if (cursorPos.x < 0f) {
                    cursorPos.x = 0f;
                }
                if (cursorPos.y > maxsize.y) {
                    cursorPos.y = maxsize.y;
                }
                if (cursorPos.y < 0f) {
                    cursorPos.y = 0f;
                }
            }
        } 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)

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