From a67d7b847a21150a2f19968ee7e2ed85513481da Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 9 Apr 2015 13:38:21 -0500 Subject: Font3D: refactor island triangulation logic This moves the logic into a dedicated private method, which will be subsequently externalized into a service interface. --- src/javax/media/j3d/Font3D.java | 44 +++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'src/javax/media') diff --git a/src/javax/media/j3d/Font3D.java b/src/javax/media/j3d/Font3D.java index b9011e8..65566ea 100644 --- a/src/javax/media/j3d/Font3D.java +++ b/src/javax/media/j3d/Font3D.java @@ -468,23 +468,8 @@ private static class IntVector { for (i = 0; i < islandCounts.length; i++) { numPoints += outVerts[i].length; } - //Now loop thru each island, calling triangulator once per island. - //Combine triangle data for all islands together in one object. - int vertOffset = 0; - NormalGenerator ng = new NormalGenerator(); - for (i = 0; i < islandCounts.length; i++) { - contourCounts[0] = islandCounts[i].length; - GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY); - gi.setCoordinates(outVerts[i]); - gi.setStripCounts(islandCounts[i]); - gi.setContourCounts(contourCounts); - ng.generateNormals(gi); - - GeometryArray ga = gi.getGeometryArray(false, false, false); - vertOffset += ga.getVertexCount(); - - triangData.add(ga); - } + int vertOffset = + triangulateIslands(islandCounts, outVerts, contourCounts, triangData); // Multiply by 2 since we create 2 faces of the font // Second term is for side-faces along depth of the font if (fontExtrusion == null) @@ -959,6 +944,31 @@ private static class IntVector { return geo; } + /** + * Loops through each island, calling triangulator once per island. Combines + * triangle data for all islands together in one object. + */ + private int triangulateIslands(final int[][] islandCounts, + final Point3f[][] outVerts, final int[] contourCounts, + final ArrayList triangData) + { + int vertOffset = 0; + NormalGenerator ng = new NormalGenerator(); + for (int i = 0; i < islandCounts.length; i++) { + contourCounts[0] = islandCounts[i].length; + GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY); + gi.setCoordinates(outVerts[i]); + gi.setStripCounts(islandCounts[i]); + gi.setContourCounts(contourCounts); + ng.generateNormals(gi); + + GeometryArray ga = gi.getGeometryArray(false, false, false); + vertOffset += ga.getVertexCount(); + + triangData.add(ga); + } + return vertOffset; + } static boolean getNormal(Point3f p1, Point3f p2, Point3f p3, Vector3f normal) { Vector3f v1 = new Vector3f(); -- cgit v1.2.3