summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarvey Harrison <[email protected]>2019-01-04 13:53:06 -0800
committerHarvey Harrison <[email protected]>2019-01-04 13:53:06 -0800
commit97f5e215fe52b45fa395be97a27c5e54a794b2ff (patch)
treef6882125bdded14636c9897b695cb9a7aa4f0b22
parent665057b9cc5f8d71c9f8360e1046268393c6b5d7 (diff)
parent623b5ddab831a0b364e6df3c068699d42f4583fb (diff)
Merge GeometryService implementation
Signed-off-by: Harvey Harrison <[email protected]>
-rw-r--r--build.xml4
-rw-r--r--src/javax/media/j3d/Font3D.java45
-rw-r--r--src/javax/media/j3d/GeometryService.java40
3 files changed, 64 insertions, 25 deletions
diff --git a/build.xml b/build.xml
index 4c2f162..a57e6ef 100644
--- a/build.xml
+++ b/build.xml
@@ -88,7 +88,7 @@
<copy todir="${class.dir}">
<fileset dir="${src.dir}" includes="**/*.properties"/>
- <fileset dir="${j3dtools.src.dir}" includes="**/*.properties"/>
+ <fileset dir="${j3dtools.src.dir}" includes="META-INF/** **/*.properties"/>
</copy>
</target>
@@ -122,7 +122,7 @@
<attribute name="Extension-Name" value="javax.media.j3d"/>
<attribute name="Implementation-Vendor-Id" value="${build.impl.vendor.id}"/>
</manifest>
- <fileset dir="${class.dir}" includes="com/**/*"/>
+ <fileset dir="${class.dir}" includes="META-INF/** com/**/*"/>
</jar>
<zip destfile="${build.dir}/jars/j3dcore-src.zip">
diff --git a/src/javax/media/j3d/Font3D.java b/src/javax/media/j3d/Font3D.java
index 7dc3a44..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
@@ -460,29 +459,19 @@ private static class IntVector {
vertices = null;
int[] contourCounts = new int[1];
- int currCoordIndex = 0, vertOffset = 0;
- ArrayList<GeometryArray> triangData = new ArrayList<GeometryArray>();
+ ArrayList<GeometryArray> triangData = new ArrayList<GeometryArray>();
Point3f q1 = new Point3f(), q2 = new Point3f(), q3 = new Point3f();
Vector3f n1 = new Vector3f(), n2 = new Vector3f();
numPoints = 0;
- //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]);
- gi.setContourCounts(contourCounts);
- ng.generateNormals(gi);
-
- GeometryArray ga = gi.getGeometryArray(false, false, false);
- vertOffset += ga.getVertexCount();
-
- triangData.add(ga);
- }
+ for (i = 0; i < islandCounts.length; i++) {
+ numPoints += outVerts[i].length;
+ }
+
+ final GeometryService gs = newGeometryService();
+ int vertOffset =
+ 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)
@@ -508,7 +497,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();
@@ -957,6 +946,16 @@ private static class IntVector {
return geo;
}
+ 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) {
Vector3f v1 = new Vector3f();
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.
+ * <p>
+ * 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.
+ * </p>
+ *
+ * @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<GeometryArray> triangData);
+
+}