Dear all,
I am having a little trouble over here with normal generation:
I am generating an n-faced mesh from one triangle and n-1 matrices so that the 1st triangle of the mesh is the original one and the i-th one is generated from the original one transformed with the affine transformation described by i-th matrix, 2 <= i <= n.
The mesh is optically (e.g. in wireframe mode) nice and no seams, but the problem is that both gouraud and flat shading look the same (that is, gouraud shading is faceted instead of being smooth). Yes, i have set crease angle to PI. The problem is IMHO some minimal (0.000001) differences in the coordinates introduced during the matrix multiplication.
Any ideas how to fix this? I have some ideas too, but the problem is that the time efficiency of the operation (the time is measured between the beginning of generating the mesh and displaying it on the screen) is very-very important, even 0.01 s matters. So answers like go through all the faces and if you find 5 vertices that differ only slightly, set all five of them to the average etc. are far from quick enough...
I can help you with NormalGenerator problems.
The vertices must be exactly the same for the geometry utilities. GeometryInfo.recomputeIndices will compute proper indices for your geometry, guaranteeing identical vertices will use the same index. This is the relevant code (from GeometryInfo.java):
/* * This routine will return an index list for any array of objects. */ int[] getListIndices(Object list[]) { // Create list of indices to return int indices[] = new int[list.length];
// Create hash table with initial capacity equal to the number // of components (assuming about half will be duplicates) HashMap table = new HashMap(list.length);
Integer idx; for (int i = 0 ; i < list.length ; i++) {
// Find index associated with this object idx = (Integer)table.get(list[i]);
if (idx == null) { // We haven't seen this object before indices[i] = i;
// Put into hash table and remember the index table.put(list[i], new Integer(i));
} else { // We've seen this object indices[i] = idx.intValue(); } }
return indices; } // End of getListIndices
As you can see, if two Point3f (or any other object) have the same hash value, they will get the same index. If you pull this code into your project, you can tweak this method to get what you need. All of the Vecmath classes have epsilonEquals, so you may be able to use that, but you'll need to replace the HashMap imlementation with something else. Perhaps use an ArrayList and use .contains(), then override the Point3f with a subclass that overrides .equals and calls .epsilonEquals. I'm sure you can figure something out.
-Paul
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".