使用 Java3D 同时显示多边形线和纹理
我有一个使用纹理(POLYGON_FILL)成功渲染的 3D 网格。我还想做的是以编程方式同时绘制不同颜色的线(POLYGON_LINE PolygonAttribute),以显示三角形的边缘。它看起来就像您在 3D 建模程序或某些此类应用程序中看到的那样 - 带有说明面部边缘的线轮廓的面部纹理。
这是通过 API 轻松完成的事情还是需要一定的创造力?我想我可以改变纹理坐标,使纹理稍微低于多边形的边缘(但我认为如果面边缘上的间隙变化很大,它看起来会不一致),但是我正在使用 TexCoordGeneration 而不是确定从哪里开始做类似的事情。
基本上,这将用于一种基本但高度定制的 3D 建模应用程序,因此在用户操作 3D 几何体方面会发生许多不太常见的操作。
I have a 3d mesh being rendered successfully with textures (POLYGON_FILL). What I'd like to do is also programatically draw lines (POLYGON_LINE PolygonAttribute) of a different color at the same time, to display the edges of the triangles. It would look something like you might see in a 3d modeling program or some such application--face textures with wire outlines illustrating the face edges.
Is this something easily done through the API or will it take some amount of creativity? I guess I could alter the texture coords so that the texture falls slightly short of the polygon's edges (but I think it'd look inconsistent if the gap on the face edges varied widely), however I'm using TexCoordGeneration and I'm not sure where to start in doing something like that.
Basically this is going to be for a sort of basic but highly customized 3d modeller app, so there's a lot of less common operations going on regarding user manipulation of the 3d geometry.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对 OpenGL 更熟悉,所以不幸的是这个答案只是一个理论课。我不认为这是 Java3D 的“内置”功能(如果是的话,任何人都可以随时纠正我)。您需要执行多个渲染过程才能完成它。从我刚刚对这个主题所做的一点搜索来看,Java3D 似乎对这类事情没有太多支持。您可能想考虑使用 OpenGL 等较低级别的 API,特别是考虑到您说它是“高度定制的 3d 建模应用程序”。您将能够更好地控制如何将内容绘制到屏幕上。
话虽这么说。这是一个高层次答案的尝试。您希望显示所有线条,还是仅显示未隐藏在其他多边形后面的线条?
仅渲染未隐藏线
对于每个帧,您需要:
POLYGON_LINE
再次渲染网格。深度缓冲区根据多边形与观察者的距离来确定是否应该绘制像素。 Java3D 的默认深度测试,根据 javadoc 是
LESS_OR_EQUAL
,因此这应该会导致在纹理顶部绘制线条。渲染所有线
这与上面相同,但您需要清除两个渲染通道之间的深度缓冲区。
I am more familiar with OpenGL so unfortunately this answer is only a theory lesson. I would not imagine this is a 'built-in' feature of Java3D (anyone feel free to correct me if it is). You need to do multiple rendering passes to accomplish it. From the little bit of searching I have just done on the topic, it does not look like Java3D has much support for that kind of thing. You may want to look at using a lower level API like OpenGL, especially considering you said it was a 'highly customized 3d modeller app'. You will get a lot more control over how things are drawn to the screen.
That being said. Here is an attempt at a high level answer. Do you want all the lines to show up, or only the lines that are not hidden behind other polygons?
Only Render Unhidden Lines
For each frame, you need to:
POLYGON_FILL
.POLYGON_LINE
.The depth buffer determines whether a pixel should be drawn or not based on the distance of the polygon from the viewer. The default depth test for Java3D, according to the javadoc, is
LESS_OR_EQUAL
so this should result in the lines being drawn on top of the textures.Render All Lines
This is the same as above, but you need to clear the depth buffer in between the two rendering passes.