Java Code Examples for com.jme3.renderer.ViewPort#attachScene()
The following examples show how to use
com.jme3.renderer.ViewPort#attachScene() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VRGuiManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Set up the GUI. * @param leftcam the left eye camera. * @param rightcam the right eye camera. * @param left the left eye viewport. * @param right the right eye viewport. */ public void setupGui(Camera leftcam, Camera rightcam, ViewPort left, ViewPort right) { if (environment != null){ if( environment.hasTraditionalGUIOverlay() ) { camLeft = leftcam; camRight = rightcam; Spatial guiScene = getGuiQuad(camLeft); left.attachScene(guiScene); if( right != null ) right.attachScene(guiScene); setPositioningMode(posMode); } } else { throw new IllegalStateException("VR GUI manager is not attached to any environment."); } }
Example 2
Source File: OculusViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private ViewPort setupViewBuffers(Camera cam, String viewName) { // TODO this function is identical to that in VRViewManagerOpenVR; merge the two. if (environment != null) { if (environment.getApplication() != null) { 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()); } // The viewbuffer to render into will be set during prerender. 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."); } }
Example 3
Source File: LWJGLOpenVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private ViewPort setupMirrorBuffers(Camera cam, Texture2D 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(), 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."); } }
Example 4
Source File: LWJGLOpenVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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(Texture2D.MinFilter.BilinearNoMipMaps); offTex.setMagFilter(Texture2D.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."); } }
Example 5
Source File: OpenVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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."); } }
Example 6
Source File: OpenVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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."); } }
Example 7
Source File: OSVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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."); } }
Example 8
Source File: OSVRViewManager.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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."); } }
Example 9
Source File: SimpleWaterProcessor.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
protected void createPreViews() { reflectionCam = new Camera(renderWidth, renderHeight); refractionCam = new Camera(renderWidth, renderHeight); // create a pre-view. a view that is rendered before the main view reflectionView = new ViewPort("Reflection View", reflectionCam); reflectionView.setClearFlags(true, true, true); reflectionView.setBackgroundColor(ColorRGBA.Black); // create offscreen framebuffer reflectionBuffer = new FrameBuffer(renderWidth, renderHeight, 1); //setup framebuffer to use texture reflectionBuffer.setDepthBuffer(Format.Depth); reflectionBuffer.setColorTexture(reflectionTexture); //set viewport to render to offscreen framebuffer reflectionView.setOutputFrameBuffer(reflectionBuffer); reflectionView.addProcessor(new ReflectionProcessor(reflectionCam, reflectionBuffer, reflectionClipPlane)); // attach the scene to the viewport to be rendered reflectionView.attachScene(reflectionScene); // create a pre-view. a view that is rendered before the main view refractionView = new ViewPort("Refraction View", refractionCam); refractionView.setClearFlags(true, true, true); refractionView.setBackgroundColor(ColorRGBA.Black); // create offscreen framebuffer refractionBuffer = new FrameBuffer(renderWidth, renderHeight, 1); //setup framebuffer to use texture refractionBuffer.setDepthBuffer(Format.Depth); refractionBuffer.setColorTexture(refractionTexture); refractionBuffer.setDepthTexture(depthTexture); //set viewport to render to offscreen framebuffer refractionView.setOutputFrameBuffer(refractionBuffer); refractionView.addProcessor(new RefractionProcessor()); // attach the scene to the viewport to be rendered refractionView.attachScene(reflectionScene); }
Example 10
Source File: TestMultiViews.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void simpleInitApp() { // create the geometry and attach it Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj"); teaGeom.scale(3); DirectionalLight dl = new DirectionalLight(); dl.setColor(ColorRGBA.White); dl.setDirection(Vector3f.UNIT_XYZ.negate()); rootNode.addLight(dl); rootNode.attachChild(teaGeom); // Setup first view viewPort.setBackgroundColor(ColorRGBA.Blue); cam.setViewPort(.5f, 1f, 0f, 0.5f); cam.setLocation(new Vector3f(3.3212643f, 4.484704f, 4.2812433f)); cam.setRotation(new Quaternion(-0.07680723f, 0.92299235f, -0.2564353f, -0.27645364f)); // Setup second view Camera cam2 = cam.clone(); cam2.setViewPort(0f, 0.5f, 0f, 0.5f); cam2.setLocation(new Vector3f(-0.10947256f, 1.5760219f, 4.81758f)); cam2.setRotation(new Quaternion(0.0010108891f, 0.99857414f, -0.04928594f, 0.020481428f)); ViewPort view2 = renderManager.createMainView("Bottom Left", cam2); view2.setClearFlags(true, true, true); view2.attachScene(rootNode); // Setup third view Camera cam3 = cam.clone(); cam3.setViewPort(0f, .5f, .5f, 1f); cam3.setLocation(new Vector3f(0.2846221f, 6.4271426f, 0.23380789f)); cam3.setRotation(new Quaternion(0.004381671f, 0.72363687f, -0.69015175f, 0.0045953835f)); ViewPort view3 = renderManager.createMainView("Top Left", cam3); view3.setClearFlags(true, true, true); view3.attachScene(rootNode); // Setup fourth view Camera cam4 = cam.clone(); cam4.setViewPort(.5f, 1f, .5f, 1f); cam4.setLocation(new Vector3f(4.775564f, 1.4548365f, 0.11491505f)); cam4.setRotation(new Quaternion(0.02356979f, -0.74957186f, 0.026729556f, 0.66096294f)); ViewPort view4 = renderManager.createMainView("Top Right", cam4); view4.setClearFlags(true, true, true); view4.attachScene(rootNode); //test multiview for gui guiViewPort.getCamera().setViewPort(.5f, 1f, .5f, 1f); // Setup second gui view Camera guiCam2 = guiViewPort.getCamera().clone(); guiCam2.setViewPort(0f, 0.5f, 0f, 0.5f); ViewPort guiViewPort2 = renderManager.createPostView("Gui 2", guiCam2); guiViewPort2.setClearFlags(false, false, false); guiViewPort2.attachScene(guiViewPort.getScenes().get(0)); }
Example 11
Source File: TestMultiViews.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 4 votes |
public void simpleInitApp() { // create the geometry and attach it Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj"); teaGeom.scale(3); DirectionalLight dl = new DirectionalLight(); dl.setColor(ColorRGBA.White); dl.setDirection(Vector3f.UNIT_XYZ.negate()); rootNode.addLight(dl); rootNode.attachChild(teaGeom); // Setup first view viewPort.setBackgroundColor(ColorRGBA.Blue); cam.setViewPort(.5f, 1f, 0f, 0.5f); cam.setLocation(new Vector3f(3.3212643f, 4.484704f, 4.2812433f)); cam.setRotation(new Quaternion(-0.07680723f, 0.92299235f, -0.2564353f, -0.27645364f)); // Setup second view Camera cam2 = cam.clone(); cam2.setViewPort(0f, 0.5f, 0f, 0.5f); cam2.setLocation(new Vector3f(-0.10947256f, 1.5760219f, 4.81758f)); cam2.setRotation(new Quaternion(0.0010108891f, 0.99857414f, -0.04928594f, 0.020481428f)); ViewPort view2 = renderManager.createMainView("Bottom Left", cam2); view2.setClearFlags(true, true, true); view2.attachScene(rootNode); // Setup third view Camera cam3 = cam.clone(); cam3.setViewPort(0f, .5f, .5f, 1f); cam3.setLocation(new Vector3f(0.2846221f, 6.4271426f, 0.23380789f)); cam3.setRotation(new Quaternion(0.004381671f, 0.72363687f, -0.69015175f, 0.0045953835f)); ViewPort view3 = renderManager.createMainView("Top Left", cam3); view3.setClearFlags(true, true, true); view3.attachScene(rootNode); // Setup fourth view Camera cam4 = cam.clone(); cam4.setViewPort(.5f, 1f, .5f, 1f); cam4.setLocation(new Vector3f(4.775564f, 1.4548365f, 0.11491505f)); cam4.setRotation(new Quaternion(0.02356979f, -0.74957186f, 0.026729556f, 0.66096294f)); ViewPort view4 = renderManager.createMainView("Top Right", cam4); view4.setClearFlags(true, true, true); view4.attachScene(rootNode); //test multiview for gui guiViewPort.getCamera().setViewPort(.5f, 1f, .5f, 1f); // Setup second gui view Camera guiCam2 = guiViewPort.getCamera().clone(); guiCam2.setViewPort(0f, 0.5f, 0f, 0.5f); ViewPort guiViewPort2 = renderManager.createPostView("Gui 2", guiCam2); guiViewPort2.setClearFlags(false, false, false); guiViewPort2.attachScene(guiViewPort.getScenes().get(0)); }