Display polygon lines and texture at the same time w/Java3D
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 ba开发者_高级运维sic but highly customized 3d modeller app, so there's a lot of less common operations going on regarding user manipulation of the 3d geometry.
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:
- Render the mesh with
POLYGON_FILL
. - Without clearing the depth buffer, render the mesh again with
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.
精彩评论