我现在正在做网格存储工作,即简单地将未索引的网格转换为索引的网格。工作原理如下:
GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
gi.setCoordinates(points);
gi.setStripCounts(strips);
gi.setContourCounts(contours);
gi.convertToIndexedTriangles();
IndexedGeometryArray ga = gi.getIndexedGeometryArray(true);
我想现在是读取和存储顶点和三角形信息的好时机,这些信息预计以[[xyz],[xyz],,,[xyz]]作为顶点
和[[abc],[abc],[abc],,,[abc]]作为三角形
的形式,而这个新顶点的数量应该比未索引的顶点少得多。
然而,我读的javadoc
越多,我就越困惑。看来从GeometryArray继承的方法getCooperatives()
会产生旧的顶点,而新方法getCooperativeIndices()
很难理解,就像getCooperativeIndices(0,indices)
一样。为什么是0?该索引中存储了什么?如果两者都错了,那么应该采用哪种方法呢?
谢谢!
最佳答案
几分钟后,我想出了这样的事情:
GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
gi.setCoordinates(points);
gi.setStripCounts(strips);
gi.setContourCounts(contours);
gi.convertToIndexedTriangles();
IndexedGeometryArray ga = gi.getIndexedGeometryArray(true);
double [] originalVertices = new double [ga.getVertexCount() * 3];
for(int i = 0; i < ga.getVertexCount(); i++ ){
double [] coord = new double [3];
ga.getCoordinate(i, coord);
for(int j = 0; j < 3; j++)
originalVertices[i*3+j] = coord[j];
}//next i
}//next
int[] triangles = new int[ga.getValidIndexCount()];
ga.getCoordinateIndices(0, triangles);
我不太明白为什么,但它确实有效,实际上效果很好。
关于java - 如何从 Java3D 中的 IndexedGeometryArray 读取顶点坐标和三角形索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34011496/