Control created out of SimpleApplication does not work

Hi,

I have got 1 SimpleApplication which handles 1 Canvas.

I need to alternate several scenes there.

So I have SceneManager and Scene instances in it.

Scene is class which contains fakeRootNode and all Spatials, Controls etc. associated with fakeRootNode.

I need all of this show in my SimpleApplication when needed.



fakeRootNode is attached as only child to cleared original rootNode in SimpleApplication.



At this state of things, Controls (TerrainLodControl and some my own Controls) doesn’t do anything. If I tested this scenes separately, directly defined in simpleInitApp() method, it worked well.



All Spatials displays all right.



What could be the problem?

You override update() instead of simpleUpdate()? Apart from that idea, all you say doesn’t happen without you showing some code :stuck_out_tongue:

Actually, I don’t override any of these methods.



Ok, I will try to post “some” code but this is great challenge to choose the right parts…sorry;)



Scene init:

[java]

//SKYBOX

Texture west, east, north, south, up, down;



west = ApplicationDImpl.getMonkeyApplication().getAssetManager().loadTexture(“Textures/skybox_side.png”);

east = ApplicationDImpl.getMonkeyApplication().getAssetManager().loadTexture(“Textures/skybox_side.png”);

north = ApplicationDImpl.getMonkeyApplication().getAssetManager().loadTexture(“Textures/skybox_side.png”);

south = ApplicationDImpl.getMonkeyApplication().getAssetManager().loadTexture(“Textures/skybox_side.png”);

up = ApplicationDImpl.getMonkeyApplication().getAssetManager().loadTexture(“Textures/skybox_up.png”);

down = ApplicationDImpl.getMonkeyApplication().getAssetManager().loadTexture(“Textures/skybox_down.png”);

Spatial sky = SkyFactory.createSky(ApplicationDImpl.getMonkeyApplication().getAssetManager(), west, east, north, south, up, down);

fakeRootNode.attachChild(sky);



//…many other Spatials attached to fakeRootNode…



//LOD Control

List<Camera> cameras = new ArrayList<Camera>();

cameras.add(ApplicationDImpl.getMonkeyApplication().getCamera());

ApplicationDImpl.getMonkeyApplication().getCamera().setLocation(new Vector3f((heightMap.getWidth()/2)*xMapScale, 1500f, heightMap.getHeight()*zMapScale));



//terrain is TerrainQuad

TerrainLodControl control = new TerrainLodControl(terrain, cameras);

terrain.addControl(control);

[/java]



set Scene to MonkeyApplication() which extends MonkeySimpleApplication which is “clone” of SimpleApplication. MonkeyApplication is like to extend SimpleApplication directly.



[java]

public void set()

{

ApplicationDImpl.getMonkeyApplication().getViewPort().clearScenes();

ApplicationDImpl.getMonkeyApplication().getGuiViewPort().clearScenes();

this.fakeRootNode.updateGeometricState();

this.fakeGuiNode.updateGeometricState();

ApplicationDImpl.getMonkeyApplication().getViewPort().attachScene(this.fakeRootNode);

ApplicationDImpl.getMonkeyApplication().getGuiViewPort().attachScene(this.fakeGuiNode);

}

[/java]

You replace the whole rootNode, simpleApplication only updates the preset rootNode, just attach your fakeRootNode to that instead of removing the rootNode.

1 Like

That’s it. Thanks :slight_smile: