how can i project a camera onto a cube as a Texture in JMonkeyEngine3? would you mind helping me?
I try to do it by this piece of code but it dosent work:
private void addCamera() {
Camera c = new Camera(100, 100);
c.setViewPort(0, 1, 0, 1);
c.setLocation(Vector3f.ZERO);
ViewPort v = new ViewPort("c", c);
v.attachScene(rootNode);
FrameBuffer fb = v.getOutputFrameBuffer();
fb.setDepthBuffer(Format.Depth);
Texture2D niftytex = new Texture2D(1024, 768, Format.RGB8);
fb.setColorTexture(niftytex);
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
Geometry geom = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("m_ColorMap", niftytex);
/**
* Here comes the texture!
*/
geom.setMaterial(mat);
localRootNode.attachChild(geom);
}
If you use the TestRenderToTexture
example in the jme3-examples
project, you will achieve what you want. You can put the whole thing in a util class and just call it from your project (I've done that myself).