Texturing a trimesh -- possible bug

suppose i have a trimesh, with unique 24 vertices, 44 triangles. That implies 132 vertex indecies to describe all triangles. The mesh is texture-mapped, so each triangle vertex would have u,v coords, 132 in total.



so, i've been trying to draw a trimesh with 24 vertecies, 132 vertex indexes and 132 texture coords, and the texture looks all messed up. The solution is to duplicate some of the vertex coords, so that there is 1 vertex for each vertex index/texture coord, (132 in total). Then, trimesh with 132 vertecies, 132 vertex indexes and 132 texture coords renders OK.



The question is, is this a bug in JME? Otherwise, what's the point of having vertex index array? you might as well drop it, and just have vertex coord array and texture coord array.


Since we use arrays, your indices make reference to a vert/uv/color via a single index reference.  Thus in jME you need to use the same number of each.  Index arrays are still useful to prevent unnecessary duplication of data though as long as you are not trying to reuse the same point in space with a different normal/uv/color.  (Consider all of our shapes for example, such as Box that uses 8 verts/uv/colors/normals for 12 triangles using 36 indices.)

thanks for your reply.



IMO, it's very common for one vertex to be shared by different polygons, and of course, UV/color would be different for each poly vertex, SO, it really would make sense to associate (UV, index) with (vertex). I think that's how rendering packages implement it – as part of my troubleshooting, i dumped mesh data into a .OBJ file and imported it into Blender & Maya.  The 24/132/132 configuration renders perfectly.


afaik, in those cases, the vertex information generally is duplicated by the rendering engine without you seeing it.

Yes, that is what is actually happening, and the same happens with normals and colors, if you want to have two normals or colors associated with one logical vertex, then you need to duplicate that vertex, and use the two indexes for each attribute. The point is that Maya/3DS obviously have algorithms to do this behind the scenes. It would be nice to have them in jME too, but they are not a priority.



Now, if you want to volunteer…