【问题标题】:how can i project a camera onto a cube as a Texture in jMonkeyEngine 3?如何在 jMonkeyEngine 3 中将相机作为纹理投影到立方体上?
【发布时间】:2016-04-16 14:37:57
【问题描述】:

如何在 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)fb 为 NULL。 2)需要设置v.setOutputFrameBuffer() 3)材质参数为ColorMap,不带m_

标签: java camera jmonkeyengine


【解决方案1】:

如果您在jme3-examples 项目中使用TestRenderToTexture 示例,您将实现您想要的。您可以将整个内容放在一个 util 类中,然后从您的项目中调用它(我自己已经这样做了)。

【讨论】:

    猜你喜欢
    • 2019-06-03
    • 1970-01-01
    • 1970-01-01
    • 2015-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 1970-01-01
    相关资源
    最近更新 更多