I’m trying to draw 2 objects, the first with depth writing on, and the 2nd with depth writing off in JME3, but it seems that the objects are being drawn out of order or something.
The following code demonstrates my problem with two cubes, the red one in behind and the green one in front, but with depth writing disabled. The green shape shouldn’t be blocked from drawing by the red shape.
[java]package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
/**
- test
-
@author normenhansen
*/
public class Main extends SimpleApplication {
public static void main(String[] args) {
Main app = new Main();
app.setShowSettings(false);
app.start();
}
@Override
public void simpleInitApp() {
Box box = new Box(Vector3f.ZERO, 2f,2f,0.5f);
Spatial a = new Geometry("BigBoxBox", box );
Material c1 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
c1.setColor("Color", ColorRGBA.Red);
a.move(0.0f,0.0f,-1.2f);
a.setMaterial(c1);
rootNode.attachChild(a);
//and a smaller green one
Spatial b = new Geometry("SmallBox", box );
b.scale(1.0f,3.0f,1.0f);
Material c2 = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
c2.getAdditionalRenderState().setDepthWrite(false);
c2.setColor("Color", ColorRGBA.Green);
b.move(0.0f,0.0f,0.5f);
b.scale(0.5f);
b.setMaterial(c2);
rootNode.attachChild(b);
}
@Override
public void simpleUpdate(float tpf) {
//TODO: add update code
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
[/java]
Is spatial a being drawn after spatial b somehow? Is there any way to force ordering?