为什么我的离屏渲染 Canvas3D 不起作用?

发布于 2024-08-04 01:10:41 字数 776 浏览 9 评论 0原文

我一直在尝试使用 Java3D 1.5.2 使离屏渲染正常工作。在我的源代码中,我一直在尝试附加一个扩展的Canvas3D,它可以离屏渲染到 SimpleUniverse,但这样做会破坏渲染:

62.  // FOR SOME REASON THIS BREAKS RENDERING
63.  universe.getViewer().getView().addCanvas3D(canvas);

完整的源代码有点太大,无法粘贴到 StackOverflow 上,因此我通过 Pastie 通过 此处

第 63 行已被注释掉,并由普通 Canvas3D 进行屏幕渲染。它将渲染一个立方体并将其显示在 JFrame 中。但是,如果您删除注释,屏幕外渲染将导致屏幕上渲染不渲染。此外,离屏渲染将返回“大黑无”BufferedImage

我想知道如何使离屏渲染工作,即将旋转立方体的场景渲染到缓冲图像。我一直在查看 Java3D 提供的离屏渲染示例代码,他们也这样做(除了他们使用 Raster 对象将离屏缓冲区渲染回一个屏幕窗口)。

I've been trying to make off screen rendering to work, using Java3D 1.5.2. In my source code I've been trying to attach an extended Canvas3D that will do off-screen rendering to SimpleUniverse, but doing so will break the render:

62.  // FOR SOME REASON THIS BREAKS RENDERING
63.  universe.getViewer().getView().addCanvas3D(canvas);

The full source code is a bit too large to paste on StackOverflow so I made it available via Pastie over here.

Line 63 has been commented out and has the ordinary Canvas3D do on-screen rendering. It will render a cube and display this in a JFrame. However if you remove the comment the off-screen render will cause the on-screen one from not rendering. Also the off-screen rendering will return a "big black nothing" BufferedImage.

I'd like to know how to make the off screen rendering work, i.e. render the scene of a rotated cube to a buffered image. I've been looking at the Java3D provided example code for off-screen rendering and they do it as this as well (with the exception that they use the Raster object to render the off screen buffer back to an on-screen window).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍景流年 2024-08-11 01:10:41

Screen3D 的物理尺寸可能是错误的。该值应该是物理屏幕的大小(以米为单位)。您可以使用以下方法进行测试:

screen3D.setPhysicalScreenWidth(0.0254/90.0 * destWidth);
screen3D.setPhysicalScreenHeight(0.0254/90.0 * destHeight);

这些值来自 Screen3D javadoc 的顶部。有问题的行与上面的代码一起工作,至少对我来说:)

设置错误的物理尺寸也可能会改变渲染图像的纵横比。

It might be the physical dimension of the Screen3D that is wrong. The value is supposed to be size of the physical screen in meters. You can test with:

screen3D.setPhysicalScreenWidth(0.0254/90.0 * destWidth);
screen3D.setPhysicalScreenHeight(0.0254/90.0 * destHeight);

The values are from the top of the Screen3D javadoc. The problematic line worked together with the above code, at least for me :)

Setting the wrong physical dimension may also change the aspect ratio of the rendered image.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文