Hello fiddling with BUI. Here I can just add geometry to a BGeomView but in order to make it look right I have to add it(geometry) to the root node as well. This had the disadvantage that the geometry is rendered in my scene as well as in my BgeomView window.
How do I handle this… Should I create my own scene for each BGeomWindow complete with cam etc?
Middy
I never tried out BUI myself but have You made sure culling is not enabled for the BUI - node ?
what does "look right" mean?
i'll give this a look when i get home.
edit: i got home
there's no need to add/render something twice unless you want to. the spatial you pass to the BGeomView has to be fully set up (lights and stuff - it doesn't "inherit" render states from the root node where you add the GUI). don't forget to call updateRenderState() when you change render states for the spatial you provide - the geometric state is updated by BUI. here's a very simple test for the geom view:
import java.io.InputStream;
import java.io.InputStreamReader;
import com.jme.app.SimpleGame;
import com.jme.input.MouseInput;
import com.jme.light.DirectionalLight;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.LightState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jmex.bui.BComponent;
import com.jmex.bui.BDecoratedWindow;
import com.jmex.bui.BGeomView;
import com.jmex.bui.BStyleSheet;
import com.jmex.bui.BWindow;
import com.jmex.bui.PolledRootNode;
import com.jmex.bui.background.TintedBackground;
import com.jmex.bui.layout.BorderLayout;
public class GeometryViewTest extends SimpleGame {
private Box box;
private long lastRotation = 0;
@Override
protected void simpleInitGame() {
display.getRenderer().setBackgroundColor(ColorRGBA.orange);
MouseInput.get().setCursorVisible(true);
PolledRootNode guiRoot = new PolledRootNode(this.timer, this.input);
BStyleSheet style = null;
try {
InputStream stin = getClass().getClassLoader()
.getResourceAsStream("rsrc/style.bss");
style = new BStyleSheet(new InputStreamReader(stin),
new BStyleSheet.DefaultResourceProvider());
}
catch (Exception e) {
e.printStackTrace(System.err);
System.exit(-1);
}
DirectionalLight light = new DirectionalLight();
light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
light.setDirection(new Vector3f(1, -1, 0));
light.setEnabled(true);
LightState ls = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
ls.setEnabled(true);
ls.attach(light);
box = new Box("box", new Vector3f(), 2, 2, 2);
Quaternion quat45 = new Quaternion();
quat45.fromAngleAxis(0.7854f, new Vector3f(1, 1, 1));
box.setLocalRotation(quat45);
ZBufferState zBufferState = DisplaySystem.getDisplaySystem().getRenderer()
.createZBufferState();
zBufferState.setEnabled(true);
zBufferState.setFunction(ZBufferState.CF_LESS);
Node n = new Node("blah");
n.setRenderState(ls);
n.setRenderState(zBufferState);
n.attachChild(box);
n.updateRenderState();
BGeomView view = new BGeomView();
view.setGeometry(n);
BWindow window = new BDecoratedWindow(style, null);
window.setLayoutManager(new BorderLayout());
window.setSize(400, 300);
window.center();
window.add(view, BorderLayout.CENTER);
guiRoot.addWindow(window);
window.setBackground(BComponent.DEFAULT, new TintedBackground(new ColorRGBA(0, 0, 1, 0.7f)));
rootNode.attachChild(guiRoot);
}
@Override
protected void simpleUpdate() {
if (timer.getTime() - lastRotation > 10) {
Vector3f axis = new Vector3f(1, -1, 0);
float currentAngle = box.getLocalRotation().toAngleAxis(axis) * FastMath.RAD_TO_DEG;
currentAngle += 1;
if (currentAngle >= 360) {
currentAngle = 1;
}
currentAngle *= FastMath.DEG_TO_RAD;
box.setLocalRotation(box.getLocalRotation().fromAngleAxis(currentAngle, axis));
lastRotation = timer.getTime();
}
}
public static void main(String[] args) {
GeometryViewTest test = new GeometryViewTest();
test.start();
}
}
if you wonder what that setBackground does and why i call it after adding to the guiRoot: it's to override the default BUI window style (in case you didn't change it already) which is transparent.
hth