From 6173452b10842e2f244eea1b44ee1466642b95ce Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 9 Apr 2015 13:54:09 -0500 Subject: Add GeometryService implementation This code was migrated from java3d-core's Font3D class, in order to address hharrison/java3d-core#17. --- .../services/javax.media.j3d.GeometryService | 1 + .../j3d/utils/geometry/GeometryServiceImpl.java | 38 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/classes/share/META-INF/services/javax.media.j3d.GeometryService create mode 100644 src/classes/share/com/sun/j3d/utils/geometry/GeometryServiceImpl.java diff --git a/src/classes/share/META-INF/services/javax.media.j3d.GeometryService b/src/classes/share/META-INF/services/javax.media.j3d.GeometryService new file mode 100644 index 0000000..fc954bc --- /dev/null +++ b/src/classes/share/META-INF/services/javax.media.j3d.GeometryService @@ -0,0 +1 @@ +com.sun.j3d.utils.geometry.GeometryServiceImpl diff --git a/src/classes/share/com/sun/j3d/utils/geometry/GeometryServiceImpl.java b/src/classes/share/com/sun/j3d/utils/geometry/GeometryServiceImpl.java new file mode 100644 index 0000000..f3b0dff --- /dev/null +++ b/src/classes/share/com/sun/j3d/utils/geometry/GeometryServiceImpl.java @@ -0,0 +1,38 @@ + +package com.sun.j3d.utils.geometry; + +import java.util.ArrayList; + +import javax.media.j3d.GeometryArray; +import javax.media.j3d.GeometryService; +import javax.vecmath.Point3f; + +/** + * Default implementation of the {@link GeometryService} service interface. + */ +public class GeometryServiceImpl implements GeometryService { + + @Override + public int triangulateIslands(final int[][] islandCounts, + final Point3f[][] outVerts, final int[] contourCounts, + final ArrayList triangData) + { + int vertOffset = 0; + final NormalGenerator ng = new NormalGenerator(); + for (int i = 0; i < islandCounts.length; i++) { + contourCounts[0] = islandCounts[i].length; + final GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY); + gi.setCoordinates(outVerts[i]); + gi.setStripCounts(islandCounts[i]); + gi.setContourCounts(contourCounts); + ng.generateNormals(gi); + + final GeometryArray ga = gi.getGeometryArray(false, false, false); + vertOffset += ga.getVertexCount(); + + triangData.add(ga); + } + return vertOffset; + } + +} -- cgit v1.2.3