From a7b41b3d7f972089da468f25931236241c566de7 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 9 Apr 2015 13:31:32 -0500 Subject: Font3D: count points in a separate loop This makes the subsequent logic easier to refactor. --- src/javax/media/j3d/Font3D.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/javax/media/j3d/Font3D.java b/src/javax/media/j3d/Font3D.java index 7dc3a44..e99a661 100644 --- a/src/javax/media/j3d/Font3D.java +++ b/src/javax/media/j3d/Font3D.java @@ -466,12 +466,14 @@ private static class IntVector { Point3f q1 = new Point3f(), q2 = new Point3f(), q3 = new Point3f(); Vector3f n1 = new Vector3f(), n2 = new Vector3f(); numPoints = 0; + 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. NormalGenerator ng = new NormalGenerator(); for (i = 0; i < islandCounts.length; i++) { contourCounts[0] = islandCounts[i].length; - numPoints += outVerts[i].length; GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY); gi.setCoordinates(outVerts[i]); gi.setStripCounts(islandCounts[i]); -- cgit v1.2.3 From b18ec8f76feee4a6100fd2586ccd0543e06937c1 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 9 Apr 2015 13:34:27 -0500 Subject: Font3D: tweak whitespace --- src/javax/media/j3d/Font3D.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/javax/media/j3d/Font3D.java b/src/javax/media/j3d/Font3D.java index e99a661..4df6a6c 100644 --- a/src/javax/media/j3d/Font3D.java +++ b/src/javax/media/j3d/Font3D.java @@ -461,7 +461,7 @@ private static class IntVector { int[] contourCounts = new int[1]; int currCoordIndex = 0, vertOffset = 0; - ArrayList triangData = new ArrayList(); + ArrayList triangData = new ArrayList(); Point3f q1 = new Point3f(), q2 = new Point3f(), q3 = new Point3f(); Vector3f n1 = new Vector3f(), n2 = new Vector3f(); -- cgit v1.2.3 From af0c5a2f9bdb2c79f132a2108bc42fbf9a569422 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 9 Apr 2015 13:35:15 -0500 Subject: Font3D: declare local variables when they are used This will ease subsequent refactoring. --- src/javax/media/j3d/Font3D.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/javax/media/j3d/Font3D.java b/src/javax/media/j3d/Font3D.java index 4df6a6c..b9011e8 100644 --- a/src/javax/media/j3d/Font3D.java +++ b/src/javax/media/j3d/Font3D.java @@ -460,7 +460,6 @@ private static class IntVector { vertices = null; int[] contourCounts = new int[1]; - int currCoordIndex = 0, vertOffset = 0; ArrayList triangData = new ArrayList(); Point3f q1 = new Point3f(), q2 = new Point3f(), q3 = new Point3f(); @@ -471,6 +470,7 @@ private static class IntVector { } //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; @@ -510,7 +510,7 @@ private static class IntVector { // last known non-degenerate normal Vector3f goodNormal = new Vector3f(); - + int currCoordIndex = 0; for (j=0;j < islandCounts.length;j++) { GeometryArray ga = triangData.get(j); vertOffset = ga.getVertexCount(); -- cgit v1.2.3 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(-) 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 From caec6bfe7cfdb3652e5f95c22870cf0e5057890b Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 9 Apr 2015 13:43:15 -0500 Subject: Add a service interface for external routines In particular, Font3D's triangulateGlyphs routine relies on the classes GeometryInfo and NormalGenerator of package com.sun.j3d.utils.geometry, which lives in the j3d-core-utils project, under a different license. This means that historically, j3d-core and j3d-core-utils were mutually dependent. We avoid the situation by using a service interface instead. --- src/javax/media/j3d/GeometryService.java | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/javax/media/j3d/GeometryService.java diff --git a/src/javax/media/j3d/GeometryService.java b/src/javax/media/j3d/GeometryService.java new file mode 100644 index 0000000..346087c --- /dev/null +++ b/src/javax/media/j3d/GeometryService.java @@ -0,0 +1,40 @@ + +package javax.media.j3d; + +import java.util.ArrayList; + +import javax.vecmath.Point3f; + +/** + * A service interface for certain geometric operations that are not available + * in core Java 3D. + *

+ * In particular, the {@code j3d-core-utils} project provides additional + * functionality under a different license, which is needed in some + * circumstances by core Java 3D. Thus, historically, these two projects have + * been co-dependent. This interface breaks the circular dependency by using + * Java's service discovery mechanism: if {@code j3d-core-utils} is present on + * the classpath, its {@code GeometryServiceImpl} will provide the functionality + * defined here. Or if not (i.e., no suitable {@code GeometryService} + * implementation can be discovered and instantiated}), then the Java3D core + * will fail as gracefully as possible. + *

+ * + * @see Font3D#triangulateGlyphs + */ +public interface GeometryService { + + /** + * Loops through each island, calling triangulator once per island. Combines + * triangle data for all islands together in one object. + * + * @param islandCounts TODO + * @param outVerts TODO + * @param contourCounts TODO + * @param triangData TODO + * @return total vertex count of the combined array + */ + int triangulateIslands(int[][] islandCounts, Point3f[][] outVerts, + int[] contourCounts, ArrayList triangData); + +} -- cgit v1.2.3 From 58c3498601ccf18aba61dce3d0082f329d0d95ea Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 9 Apr 2015 13:47:21 -0500 Subject: 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. --- src/javax/media/j3d/Font3D.java | 43 ++++++++++++++--------------------------- 1 file 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 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 gsLoader = + ServiceLoader.load(GeometryService.class); + + final Iterator 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) { -- cgit v1.2.3 From 623b5ddab831a0b364e6df3c068699d42f4583fb Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Tue, 6 Oct 2015 13:01:44 -0500 Subject: Include META-INF directory in j3dutils.jar This is needed so that its GeometryService implementation can be discovered at runtime. --- build.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.xml b/build.xml index 6f9b08e..4338a40 100644 --- a/build.xml +++ b/build.xml @@ -84,7 +84,7 @@ - + @@ -118,7 +118,7 @@ - + -- cgit v1.2.3