Draw spatial as a GUI element

Continuing the discussion from Ignore some of ancestor's transformations:

Hi all,

I’m trying to draw some spatials as GUI elements and I haven’t found the best solution yet.

The GUI element, that I will call “instrument” is rotated/translated to “follow” a spatial. Its material is an unshaded color. It is on a special Node with its own lighting (ambient only)

Here is the story board :slight_smile: The instrument sticked to a model, nothing special.

Now in the transluscent bucket. This is exactly what I want to achieve, but I lose the FXAA and Bloom filters.

Now in the transparent bucket, with :

g.getMaterial().getAdditionalRenderState().setDepthTest(false);
g.getMaterial().getAdditionalRenderState().setDepthWrite(false);

I get back my filters : FXAA and Bloom, but the instrument is also cover with the shadow filter. Plus I have a z-buffer issue between the instrument parts.

I’ve tried to use the TranslucentBucketFilter, adding it to the FilterPostProcessors after the shadow filters and before the bloom/FXAA, after reading the render bucket wiki page. This has not changed anything.

I can’t see any perfect solution to implement this feature perfectly, however it seems to be a classic thing. I would be glad to get explanations, advice and exemples if you have !

Thanks in advance.

Ben

I kind of think maybe you want a separate viewport with its own FXAA and Bloom. These are essentially HUD effects and it might look weird to have them bloom with the scene anyway.

…then it’s just a matter of rendering them in 2D and setting them to the coordinates after running through the getScreenCoordinates() call on Camera.

Okay I give it a try. I’ve done this :

	Camera c = app.getCamera().clone();
	c.setViewPort(0, 1f, 0, 1f);
	ViewPort viewPort2 = app.getRenderManager().createMainView("test", c);
	viewPort2.attachScene(myInstrumentnode);

And this produce an exception :

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: PlanarStanceInstrumentState view
	at com.jme3.scene.Spatial.checkCulling(Spatial.java:260)
	at com.jme3.renderer.RenderManager.renderSubScene(RenderManager.java:647)
	at com.jme3.renderer.RenderManager.renderScene(RenderManager.java:640)
	at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:974)
	at com.jme3.renderer.RenderManager.render(RenderManager.java:1029)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:252)
	at com.jme3.system.lwjgl.LwjglOffscreenBuffer.runLoop(LwjglOffscreenBuffer.java:125)
	at com.jme3.system.lwjgl.LwjglOffscreenBuffer.run(LwjglOffscreenBuffer.java:151)
	at java.lang.Thread.run(Unknown Source)

I’ve controlled every call of the myInstrumentNode, adding some Thread.currentThread() at each. It’s always done in the jMonkey LWJGL thread.

Do you know what can lead to such exception?

Another question : how will I draw the second view port above the main one? By turning some transparency on?

Thanx !

When you manage your own viewport, you have to manage your own viewport. This includes calling the update methods at the appropriate times since there is no way that JME can do that for you.

The default viewports get updated by default. There are 10 or 12 threads on this subject though I’m not sure the best search terms.

Basically, you have to call updateLogicalState() and updateGeometricState() once per frame. The best place is generally in an app state’s update() and render() methods respectively,.

I’d try writing my own postprocessor and special material for such utility geometry but don’t know if it will really work - I have similar task deep in my own ToDo list but had no chance to verify assumptions using real code.