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

时间:2016-04-16 14:37:57

标签: java camera jmonkeyengine

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

我尝试通过这段代码来完成它,但它起作用了:

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

}

1 个答案:

答案 0 :(得分:1)

如果您使用TestRenderToTexture项目中的jme3-examples示例,您将获得所需的内容。你可以把整个东西放在一个util类中,然后从你的项目中调用它(我自己也做过)。