Two viewport with different object

Hi,

I want to create two view ports and (LEFT, RIGHT on screen), each having two different object.

Currently I am able to create two view ports having same object (in rootNode)

How to show two different object each view port…?

Kindly guide.

Perhaps this is a good start:

You can attach a different “root node”, with your objects to each viewport.

view_n.attachScene(rootNode);

‘rootNode’ doesn’t have to be the application’s root node.

1 Like

And you will then have to manage the new root node’s updates yourself.

Like in this demo:

let me try

I tried the same in my code. It shows following error

java.lang.IllegalStateException: Scene graph is not properly updated for rendering.
State was changed after rootNode.updateGeometricState() call.
Make sure you do not modify the scene from another thread!
Problem spatial name: VP Root

Complete Code that i wrote as follows:

import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;


    
public class TestMultiViews_two_obj extends SimpleApplication {

private Node vpRoot;

public static void main(String[] args) {
TestMultiViews_two_obj app = new TestMultiViews_two_obj();
app.start();
}

@Override
public void simpleInitApp() {
// create the geometry and attach it
Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
teaGeom.scale(1);

DirectionalLight dl = new DirectionalLight();
dl.setColor(ColorRGBA.White);
dl.setDirection(Vector3f.UNIT_XYZ.negate());

rootNode.addLight(dl);
rootNode.attachChild(teaGeom);


Spatial boxGeom = new Geometry("Box", new Box(.5f, .5f, .5f));
// load some default material
boxGeom.setMaterial(assetManager.loadMaterial("Interface/Logo/Logo.j3m"));
// attach box to display in primary viewport


// Setup first view
viewPort.setBackgroundColor(ColorRGBA.Blue);
cam.setViewPort(0, 0.5f, 0, 1f);
//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.setViewPort(0.5f, 1f, 0, 1f);
cam2.setLocation(new Vector3f(-0.10947256f, 1.5760219f, 4.81758f));
cam2.setRotation(new Quaternion(0.0010108891f, 0.99857414f, -0.04928594f, 0.020481428f));

vpRoot = new Node("VP Root");
vpRoot.attachChild(boxGeom);

ViewPort view2 = renderManager.createMainView("Right", cam2);
view2.setClearFlags(true, true, true);

//view2.attachScene(rootNode);
view2.attachScene(vpRoot);

}

public void update( float tpf ) {
if( vpRoot != null ) {
vpRoot.updateLogicalState(tpf);
}
}
    
    public void render( RenderManager rm ) {
if( vpRoot != null ) {
vpRoot.updateGeometricState();
}
    }
}

Plese guide

If you are getting that error than one of your scenes is not getting updated at the right time.

…you will have to put in logging or run through the debugger to see what the issue is.

Edit: note that my example was using an app state and yours is directly extending application and messing up a bunch of what the base class is already trying to do for you. DO NOT OVERRIDE update() or render() in an Application subclass unless you are a super JME expert who knows everything about the engine.

…but even better, make an app state and you can be safer.

Maybe your Node needs some updates?

See

@Override
    public void render(RenderManager rm) {
        super.render(rm);

        rootNode1.updateGeometricState();
        rootNode2.updateGeometricState();
    }

Hi pspeed, JaRe

Thank you. I will do