Use an indexed line set factory
Source file: Cube02
JavaDoc: IndexedLineSet
JavaDoc: IndexedLineSetFactory
Now we'll add edges to the vertices created above which turns our geometry into an IndexedLineSet. This can be achieved by using the IndexedLineSetFactory, where we additionally specify edge indices. The edge indices are specified as an array of integers, one row per edge, and each entry in each row giving the index (0-based) into the array of vertices. We choose the indices such that we are going round the unit square in counter-clockwise direction.
An edge can have as few as 2 vertices, in which case it describes a single edge segment; edges with more entries describe connected curves consisting of a sequence of connected edge segments.
package de.jreality.tutorial; import de.jreality.geometry.IndexedLineSetFactory; public class Cube02 { public static void main(String[] args) { IndexedLineSetFactory ilsf = new IndexedLineSetFactory(); double [][] vertices = new double[][] { {0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0} }; int[][] edgeIndices = new int[][]{ {0, 1}, {1, 2}, {2, 3}, {3, 0} }; ilsf.setVertexCount( vertices.length ); ilsf.setVertexCoordinates( vertices ); ilsf.setLineCount(edgeIndices.length); ilsf.setEdgeIndices(edgeIndices); ilsf.update(); JRViewer.display(ilsf.getIndexedLineSet()); } }
Note that we are now calling ilsf.getIndexedLineSet() to produce geometry with our factory.
|