我如何在 jMonkeyEngine 3 中将相机作为纹理投影到立方体上?

how can i project a camera onto a cube as a Texture in jMonkeyEngine 3?

如何在 JMonkeyEngine 3 中将相机作为纹理投影到立方体上? 你介意帮我吗?

我尝试通过这段代码来实现,但它不起作用:

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);

}

如果你在jme3-examples项目中使用TestRenderToTexture的例子,你会达到你想要的。你可以把整个东西放在一个 util class 中,然后从你的项目中调用它(我自己做过)。