I have two polygons and want to turn them into a triangle mesh, using java3d. But whatever I try results in some kind of error. What am I missing?
Here is some code I've tried:
final int n = points.length;
final int m = opoints.length;
final GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
final Point3d[] npoints = Arrays.copyOf(points, n + m);
System.arraycopy(opoints, 0, npoints, n, m);
gi.setCoordinates(npoints);
gi.setStripCounts(new int[] { n, m });
gi.convertToIndexedTriangles();
final IndexedTriangleArray it = (IndexedTriangleArray) gi.getIndexedGeometryArray();
final Point3d[] newPoints = new Point3d[it.getVertexCount()];
it.getCoordinates(0, newPoints);
// Exception in thread "main" java.lang.NullPointerException
// at javax.media.j3d.GeometryArrayRetained.getCoordinates(GeometryArrayRetained.java:5425)
// at javax.media.j3d.GeometryArray.getCoordinates(GeometryArray.java:3699)
final int[] nidxs = new int[it.getValidIndexCount()];
it.getCoordinateIndices(0, nidxs);