gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 10:03:02 24 4
gpt4 key购买 nike

如何在 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 类中,然后从您的项目中调用它(我自己已经这样做了)。

关于java - 我如何将相机作为 jMonkeyEngine 3 中的纹理投影到立方体上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36665499/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com