使用 Java 和 OpenGL 绘制 3D 树有哪些方法?

发布于 2024-07-06 09:10:33 字数 240 浏览 7 评论 0原文

我知道如何使用 JOGL 或 LWJGL 连接到 OpenGL 来绘制基本对象。 我想要的是能够为树木生成某种几何形状的东西,类似于 SpeedTree 著名的东西。 显然我不期望与 SpeedTree 具有相同的质量。

我希望这些树看起来不重复。 速度不是问题,我预计屏幕上一次不需要超过 100 棵树。

Java 中有免费的树图绘制库吗? 或者示例代码或演示? 我可以移植或学习其他语言的任何内容吗?

I know how to draw basic objects using JOGL or LWJGL to connect to OpenGL. What I would like is something that can generate some kind of geometry for trees, similar to what SpeedTree is famous for. Obviously I don't expect the same quality as SpeedTree.

I want the trees to not look repetitive. Speed is not a concern, I do not expect to need more than 100 trees on screen at one time.

Are there free tree-drawing libraries available in Java? Or sample code or demos?
Is there anything in other languages which I could port or learn from?

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

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

发布评论

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

评论(9

左秋 2024-07-13 09:10:33

方法有数千种。 更好的问题会以更有限的方式定义“最佳”。 我们所说的“最佳”是绘图速度(适用于数千或数百万棵树)吗? 最好的还是最好看的? ETC。

There are thousands of methods. A better question would define 'best' in a more confined way. Are we talking 'best' as in speed of drawing (suitable for thousands or millions of trees)? Best as in best-looking? etc.

娇柔作态 2024-07-13 09:10:33

2D 还是 3D?
在 2D 中,常见的方法是使用 L 系统。
我还尝试了面向对象的方法,定义树干、树枝、树叶的对象,所有这些都扩展一个抽象类并实现一个 Genotype 接口(以改变树的种类)。
不确定它是否有效(创建了很多对象,特别是如果我为树设置动画),但做起来很有趣。

2D or 3D?
In 2D, a common way is to use L-systems.
I also tried an OO approach, defining objects for trunk, branches, leaves, all extending an abstract class and implementing a Genotype interface (to vary the kind of trees).
Not sure if it is efficient (lot of objects created, particularly if I animate the tree) but interesting to do.

清晨说晚安 2024-07-13 09:10:33

以下是一些可能有用的资源:

Here are a couple resources that may be helpful:

  • gamedev thread on the subject - contains some useful advice/suggestions
  • ngPlant - an open-source procedural plant generation tool. It is not written in Java, but you may be able to find ideas in its algorithms.
半山落雨半山空 2024-07-13 09:10:33

如果您使用 eclipse/SWT,请尝试 Draw 2D。

If you are using eclipse/SWT, try Draw 2D.

层林尽染 2024-07-13 09:10:33

如果您真的想获得美观、速度快的树,可以使用商业 C++ 库 SpeedTree。 许多大型游戏都使用它(例如,GTA、上古卷轴)。

If you're serious about getting good-looking, fast trees, there's a commercial C++ library SpeedTree. Lots of big-time games use it (e.g., GTA, Elder Scrolls).

梦行七里 2024-07-13 09:10:33

OpenSceneGraph 和 SpeedTree 的组合对我来说很有效。

A combination of OpenSceneGraph and SpeedTree has worked for me.

孤星 2024-07-13 09:10:33

我知道有两个库可以在 java 中使用 OpenGL。

LWJGL(轻量级 Java 游戏库),在我看来,它是更好的一个,因为它简单且与使用 opengl 相似与c/c++。

JOGL 如果你想将 swing 组件与 opengl 混合使用,这可能是更好的选择,我从来没有使用过它,但几年前它被认为是非常有缺陷的,我不知道它是否从那时起就成熟了。

至于画树,有很多方法可以像其他海报所说的那样,你可能想要更具体一些。

编辑:我想我有点误解了这个问题,哦,好吧:/你可以加载树的 3D 模型并显示它。

I know of two libraries that enable the usage of OpenGl with java.

LWJGL (Light Weight Java Gaming Library), which imo is the better one due to its simplicity and its similarity to using opengl with c/c++.

JOGL If you want to mix swing components with opengl this may be the better choice, I've never used it but several years ago it was known to be pretty buggy, I don't know if its matured since then.

As for drawing trees, there are many ways to do so like the other poster said, you might want to be more specific.

edit: I guess I misunderstood the question a bit, oh well : / You can load in a 3d model of a tree and display that.

捶死心动 2024-07-13 09:10:33

http://www.codeplex.com/LTrees 有一些源代码。 虽然它是c++。

http://www.codeplex.com/LTrees has some source code on that. it's c++ though.

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