Code: Select all

```
public static IndexedFaceSet createSurface( int x, int y ) {
// generate the coordinates for the surface as a 2D array of 3-vectors
// QuadMeshFactory is the only factory which accepts such a data structure
// as the argument of its setVertexCoordinates() method!
double [][][] coords = new double [x][y][3];
for( int i=0; i<x; i++) {
double v = -.4 + .8*(i/(y-1.0));
for (int j = 0; j<y; ++j) {
double u = -.3 + .6*(j/(x-1.0));
coords[i][j][0] = 10*(u-v*v);
coords[i][j][1]= 10*u*v;
coords[i][j][2]= 10*(u*u-4*u*v*v);
}
}
// QuadMeshFactory knows how to build an IndexedFaceSet from a rectangular array
// of vectors.
QuadMeshFactory factory = new QuadMeshFactory();
factory.setVLineCount(x); // important: the v-direction is the left-most index
factory.setULineCount(y); // and the u-direction the next-left-most 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
factory.update();
// now swap x and y around
coords = new double [y][x][3];
for( int i=0; i<y; i++) {
double v = -.4 + .8*(i/(y-1.0));
for (int j = 0; j<x; ++j) {
double u = -.3 + .6*(j/(x-1.0));
coords[i][j][0] = 10*(u-v*v);
coords[i][j][1]= 10*u*v;
coords[i][j][2]= 10*(u*u-4*u*v*v);
}
}
factory.setVLineCount(y); // important: the v-direction is the left-most index
factory.setULineCount(x); // and the u-direction the next-left-most 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
factory.update(); // <--- CRASH ON THIS LINE
return factory.getIndexedFaceSet();
}
```

Code: Select all

```
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at de.jreality.scene.data.IntArrayStorage.copy(IntArrayStorage.java:104)
at de.jreality.scene.data.StorageModel$ArrayOf.copy(StorageModel.java:61
1)
at de.jreality.scene.data.StorageModel.copy(StorageModel.java:161)
at de.jreality.scene.data.DataItem.copyTo(DataItem.java:155)
at de.jreality.scene.Geometry.setAttrImpl(Geometry.java:164)
at de.jreality.scene.Geometry.setAttributes(Geometry.java:281)
at de.jreality.scene.Geometry.setAttributes(Geometry.java:343)
at de.jreality.geometry.AbstractGeometryFactory.updateNode(AbstractGeome
tryFactory.java:156)
at de.jreality.geometry.AbstractPointSetFactory$AttributeGenerator.updat
eArray(AbstractPointSetFactory.java:282)
at de.jreality.geometry.AbstractIndexedFaceSetFactory.updateImpl(Abstrac
tIndexedFaceSetFactory.java:557)
at de.jreality.geometry.AbstractQuadMeshFactory.updateImpl(AbstractQuadM
eshFactory.java:287)
at de.jreality.geometry.AbstractGeometryFactory$1.run(AbstractGeometryFa
ctory.java:107)
at de.jreality.scene.Scene.executeWriter(Scene.java:113)
at de.jreality.geometry.AbstractGeometryFactory.update(AbstractGeometryF
actory.java:103)
at de.jreality.tutorial.geom.QuadMeshExample.createSurface(QuadMeshExamp
le.java:71)
at de.jreality.tutorial.geom.QuadMeshExample.main(QuadMeshExample.java:7
8)
```