Use a quad mesh factory
Source file: QuadMeshExample
JavaDoc: QuadMeshFactory
A quad mesh is a special case an of an IndexedFaceSet in which the faces are derived from the vertices of a rectangular array of vertices located in 3space. We can think of this as a rectangle in (u,v) parameter space, which is mapped into 3dimensional space. In the tutorial example the first step is to generate these vertices and store them in an array of type double[][][]
, which I'll refer to as a 3layer array (to distinguish it from a 3dimensional (x,y,z) point). In this case the surface is a socalled swallowtail which arises in the analysis of singularities.
double [][][] coords = new double [N][N][3]; for( int i=0; i<N; i++) { double v = .4 + .8*(i/(N1.0)); for (int j = 0; j<N; ++j) { double u = .3 + .6*(j/(N1.0)); coords[i][j][0] = 10*(uv*v); coords[i][j][1]= 10*u*v; coords[i][j][2]= 10*(u*u4*u*v*v); } }
Here's how to construct the quad mesh from this data:
QuadMeshFactory factory = new QuadMeshFactory(); factory.setVLineCount(20); // important: the vdirection is the leftmost index factory.setULineCount(20); // and the udirection the nextleftmost index factory.setClosedInUDirection(false); factory.setClosedInVDirection(false); factory.setVertexCoordinates(coords); factory.setGenerateFaceNormals(true); factory.setGenerateTextureCoordinates(true); factory.setGenerateEdgesFromFaces(true); factory.setEdgeFromQuadMesh(true); // generate "long" edges: one for each u, v parameter curve
Note that the factory accepts the 3layer array as argument to the setVertexCoordinates() method, in contrast to the IndexedFaceSetFactory. This is because the (u,v) parameters are builtin to the factory and it therefore knows how to interpret the 3 layers of the array as (v, u, [xyz]) information.
The method call factory.setEdgeFromQuadMesh(true) (in conjunction with the call etGenerateEdgesFromFaces(true)), has the effect that the edge information which is generated is structured as a set of curves, one for each constant u or v value. The default, inherited from IndexedFaceSetFactory would be to generate a longer list of edges, each consisting of a single line segment. The code presented here allows one later to invoke for example the method IndexedFaceSetUtility.extractEdge(double[][] curve, int which)
to extract a complete u or v parameter curve of the surface.
