aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCurtis Rueden <[email protected]>2015-04-09 13:47:21 -0500
committerCurtis Rueden <[email protected]>2015-11-25 14:11:59 -0600
commit58c3498601ccf18aba61dce3d0082f329d0d95ea (patch)
tree6f6b47c342980ce2f5e6eeec68c8a954738352e6
parentcaec6bfe7cfdb3652e5f95c22870cf0e5057890b (diff)
Font3D: use the GeometryService as appropriate
This avoids a dependency on j3d-core-utils's com.sun.j3d.utils.geometry package. If j3d-core-utils is present on the classpath, it can provide the same backing implementation as before, but the option is now open to provide an alternative service implementation if desired. This addresses hharrison/java3d-core#17.
-rw-r--r--src/javax/media/j3d/Font3D.java43
1 files changed, 15 insertions, 28 deletions
diff --git a/src/javax/media/j3d/Font3D.java b/src/javax/media/j3d/Font3D.java
index 65566ea..0d7c631 100644
--- a/src/javax/media/j3d/Font3D.java
+++ b/src/javax/media/j3d/Font3D.java
@@ -37,14 +37,13 @@ import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.ServiceLoader;
import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;
-import com.sun.j3d.utils.geometry.GeometryInfo;
-import com.sun.j3d.utils.geometry.NormalGenerator;
-
/**
* The Font3D object is used to store extruded 2D glyphs. These
* 3D glyphs can then be used to construct Text3D NodeComponent
@@ -468,8 +467,11 @@ private static class IntVector {
for (i = 0; i < islandCounts.length; i++) {
numPoints += outVerts[i].length;
}
+
+ final GeometryService gs = newGeometryService();
int vertOffset =
- triangulateIslands(islandCounts, outVerts, contourCounts, triangData);
+ gs.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)
@@ -944,30 +946,15 @@ 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<GeometryArray> 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;
+ private GeometryService newGeometryService() {
+ final ServiceLoader<GeometryService> gsLoader =
+ ServiceLoader.load(GeometryService.class);
+
+ final Iterator<GeometryService> iter = gsLoader.iterator();
+ if (iter.hasNext()) return iter.next();
+
+ throw new IllegalStateException("No GeometryService implementation found. "
+ + "Please add j3d-core-utils to the classpath.");
}
static boolean getNormal(Point3f p1, Point3f p2, Point3f p3, Vector3f normal) {