aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaImporter.java18
-rw-r--r--ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaMeshUtils.java21
-rw-r--r--ardor3d-core/src/main/java/com/ardor3d/util/geom/GeometryTool.java14
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjGeometryStore.java17
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjImporter.java16
5 files changed, 68 insertions, 18 deletions
diff --git a/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaImporter.java b/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaImporter.java
index c813e5d..4464a0b 100644
--- a/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaImporter.java
+++ b/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaImporter.java
@@ -42,6 +42,7 @@ import com.ardor3d.extension.model.collada.jdom.data.DataCache;
import com.ardor3d.extension.model.collada.jdom.plugin.ColladaExtraPlugin;
import com.ardor3d.scenegraph.MeshData;
import com.ardor3d.scenegraph.Node;
+import com.ardor3d.util.geom.GeometryTool;
import com.ardor3d.util.geom.GeometryTool.MatchCondition;
import com.ardor3d.util.resource.RelativeResourceLocator;
import com.ardor3d.util.resource.ResourceLocator;
@@ -203,6 +204,21 @@ public class ColladaImporter {
* if the resource can not be loaded for some reason.
*/
public ColladaStorage load(final ResourceSource resource) throws IOException {
+ return load(resource, new GeometryTool());
+ }
+
+ /**
+ * Reads a Collada file from the given resource and returns it as a ColladaStorage object.
+ *
+ * @param resource
+ * the name of the resource to find.
+ * @param geometryTool
+ * the geometry tool used to minimize the vertex count.
+ * @return a ColladaStorage data object containing the Collada scene and other useful elements.
+ * @throws IOException
+ * if the resource can not be loaded for some reason.
+ */
+ public ColladaStorage load(final ResourceSource resource, final GeometryTool geometryTool) throws IOException {
final ColladaStorage colladaStorage = new ColladaStorage();
final DataCache dataCache = new DataCache();
if (_externalJointMapping != null) {
@@ -211,7 +227,7 @@ public class ColladaImporter {
final ColladaDOMUtil colladaDOMUtil = new ColladaDOMUtil(dataCache);
final ColladaMaterialUtils colladaMaterialUtils = new ColladaMaterialUtils(this, dataCache, colladaDOMUtil);
final ColladaMeshUtils colladaMeshUtils = new ColladaMeshUtils(dataCache, colladaDOMUtil, colladaMaterialUtils,
- _optimizeMeshes, _optimizeSettings);
+ _optimizeMeshes, _optimizeSettings, geometryTool);
final ColladaAnimUtils colladaAnimUtils = new ColladaAnimUtils(colladaStorage, dataCache, colladaDOMUtil,
colladaMeshUtils);
final ColladaNodeUtils colladaNodeUtils = new ColladaNodeUtils(dataCache, colladaDOMUtil, colladaMaterialUtils,
diff --git a/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaMeshUtils.java b/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaMeshUtils.java
index c04e854..4c40b0a 100644
--- a/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaMeshUtils.java
+++ b/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaMeshUtils.java
@@ -43,15 +43,23 @@ public class ColladaMeshUtils {
private final ColladaMaterialUtils _colladaMaterialUtils;
private final boolean _optimizeMeshes;
private final EnumSet<MatchCondition> _optimizeSettings;
+ private final GeometryTool _geometryTool;
public ColladaMeshUtils(final DataCache dataCache, final ColladaDOMUtil colladaDOMUtil,
final ColladaMaterialUtils colladaMaterialUtils, final boolean optimizeMeshes,
final EnumSet<MatchCondition> optimizeSettings) {
+ this(dataCache, colladaDOMUtil, colladaMaterialUtils, optimizeMeshes, optimizeSettings, new GeometryTool());
+ }
+
+ public ColladaMeshUtils(final DataCache dataCache, final ColladaDOMUtil colladaDOMUtil,
+ final ColladaMaterialUtils colladaMaterialUtils, final boolean optimizeMeshes,
+ final EnumSet<MatchCondition> optimizeSettings, final GeometryTool geometryTool) {
_dataCache = dataCache;
_colladaDOMUtil = colladaDOMUtil;
_colladaMaterialUtils = colladaMaterialUtils;
_optimizeMeshes = optimizeMeshes;
_optimizeSettings = EnumSet.copyOf(optimizeSettings);
+ _geometryTool = geometryTool;
}
/**
@@ -77,7 +85,6 @@ public class ColladaMeshUtils {
* @param colladaGeometry
* @return a Node containing all of the Ardor3D meshes we've parsed from this geometry element.
*/
- @SuppressWarnings("unchecked")
public Node buildMesh(final Element colladaGeometry) {
if (colladaGeometry.getChild("mesh") != null) {
final Element cMesh = colladaGeometry.getChild("mesh");
@@ -213,7 +220,7 @@ public class ColladaMeshUtils {
_dataCache.getVertMappings().put(colladaGeometry, mvp);
if (_optimizeMeshes) {
- final VertMap map = GeometryTool.minimizeVerts(points, _optimizeSettings);
+ final VertMap map = _geometryTool.minimizeVerts(points, _optimizeSettings);
_dataCache.setMeshVertMap(points, map);
}
@@ -224,7 +231,6 @@ public class ColladaMeshUtils {
return points;
}
- @SuppressWarnings("unchecked")
public Mesh buildMeshPolygons(final Element colladaGeometry, final Element polys) {
if (polys == null || polys.getChild("input") == null) {
return null;
@@ -309,7 +315,7 @@ public class ColladaMeshUtils {
}
if (_optimizeMeshes) {
- final VertMap map = GeometryTool.minimizeVerts(polyMesh, _optimizeSettings);
+ final VertMap map = _geometryTool.minimizeVerts(polyMesh, _optimizeSettings);
_dataCache.setMeshVertMap(polyMesh, map);
}
@@ -401,7 +407,7 @@ public class ColladaMeshUtils {
}
if (_optimizeMeshes) {
- final VertMap map = GeometryTool.minimizeVerts(polyMesh, _optimizeSettings);
+ final VertMap map = _geometryTool.minimizeVerts(polyMesh, _optimizeSettings);
_dataCache.setMeshVertMap(polyMesh, map);
}
@@ -455,7 +461,7 @@ public class ColladaMeshUtils {
}
if (_optimizeMeshes) {
- final VertMap map = GeometryTool.minimizeVerts(triMesh, _optimizeSettings);
+ final VertMap map = _geometryTool.minimizeVerts(triMesh, _optimizeSettings);
_dataCache.setMeshVertMap(triMesh, map);
}
@@ -506,7 +512,7 @@ public class ColladaMeshUtils {
}
if (_optimizeMeshes) {
- final VertMap map = GeometryTool.minimizeVerts(lineMesh, _optimizeSettings);
+ final VertMap map = _geometryTool.minimizeVerts(lineMesh, _optimizeSettings);
_dataCache.setMeshVertMap(lineMesh, map);
}
@@ -523,7 +529,6 @@ public class ColladaMeshUtils {
* the store for our pipes
* @return the max offset of our pipes.
*/
- @SuppressWarnings("unchecked")
private int extractPipes(final Element inputsParent, final LinkedList<ColladaInputPipe> pipesStore) {
int maxOffset = 0;
int texCount = 0;
diff --git a/ardor3d-core/src/main/java/com/ardor3d/util/geom/GeometryTool.java b/ardor3d-core/src/main/java/com/ardor3d/util/geom/GeometryTool.java
index 53d5b49..a9f4f3f 100644
--- a/ardor3d-core/src/main/java/com/ardor3d/util/geom/GeometryTool.java
+++ b/ardor3d-core/src/main/java/com/ardor3d/util/geom/GeometryTool.java
@@ -29,7 +29,7 @@ import com.google.common.collect.Maps;
* Note: Does not work with geometry using texcoords other than 2d coords. <br>
* TODO: Consider adding an option for "close enough" vertex matches... ie, smaller than X distance apart.<br>
*/
-public abstract class GeometryTool {
+public class GeometryTool {
private static final Logger logger = Logger.getLogger(GeometryTool.class.getName());
/**
@@ -46,6 +46,10 @@ public abstract class GeometryTool {
Group;
}
+ public GeometryTool() {
+ super();
+ }
+
/**
* Attempt to collapse duplicate vertex data in a given mesh. Vertices are considered duplicate if they occupy the
* same place in space and match the supplied conditions. All vertices in the mesh are considered part of the same
@@ -57,7 +61,7 @@ public abstract class GeometryTool {
* our match conditions.
* @return a mapping of old vertex positions to their new positions.
*/
- public static VertMap minimizeVerts(final Mesh mesh, final EnumSet<MatchCondition> conditions) {
+ public VertMap minimizeVerts(final Mesh mesh, final EnumSet<MatchCondition> conditions) {
final VertGroupData groupData = new VertGroupData();
groupData.setGroupConditions(VertGroupData.DEFAULT_GROUP, conditions);
return minimizeVerts(mesh, groupData);
@@ -73,7 +77,7 @@ public abstract class GeometryTool {
* grouping data for the vertices in this mesh.
* @return a mapping of old vertex positions to their new positions.
*/
- public static VertMap minimizeVerts(final Mesh mesh, final VertGroupData groupData) {
+ public VertMap minimizeVerts(final Mesh mesh, final VertGroupData groupData) {
final long start = System.currentTimeMillis();
int vertCount = -1;
@@ -205,7 +209,7 @@ public abstract class GeometryTool {
return result;
}
- private static Vector2[] getTexs(final Vector2[][] tex, final int i) {
+ private Vector2[] getTexs(final Vector2[][] tex, final int i) {
final Vector2[] res = new Vector2[tex.length];
for (int x = 0; x < tex.length; x++) {
if (tex[x] != null) {
@@ -215,7 +219,7 @@ public abstract class GeometryTool {
return res;
}
- public static void trimEmptyBranches(final Spatial spatial) {
+ public void trimEmptyBranches(final Spatial spatial) {
if (spatial instanceof Node) {
final Node node = (Node) spatial;
for (int i = node.getNumberOfChildren(); --i >= 0;) {
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjGeometryStore.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjGeometryStore.java
index e472bad..cac72f6 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjGeometryStore.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjGeometryStore.java
@@ -58,6 +58,17 @@ public class ObjGeometryStore {
private final Map<String, ObjMaterial> materialLibrary = Maps.newHashMap();
private final Map<Spatial, String> _materialMap = Maps.newHashMap();
+ private final GeometryTool _geometryTool;
+
+ public ObjGeometryStore() {
+ this(new GeometryTool());
+ }
+
+ public ObjGeometryStore(final GeometryTool geometryTool) {
+ super();
+ _geometryTool = geometryTool;
+ }
+
public Map<String, ObjMaterial> getMaterialLibrary() {
return materialLibrary;
}
@@ -188,7 +199,7 @@ public class ObjGeometryStore {
}
points.getMeshData().setIndices(indexBuffer);
- GeometryTool.minimizeVerts(points, EnumSet.noneOf(MatchCondition.class));
+ _geometryTool.minimizeVerts(points, EnumSet.noneOf(MatchCondition.class));
applyCurrentMaterial(points);
mapToGroups(points);
@@ -236,7 +247,7 @@ public class ObjGeometryStore {
}
line.getMeshData().setIndexLengths(lengths);
}
- GeometryTool.minimizeVerts(line, EnumSet.of(MatchCondition.UVs));
+ _geometryTool.minimizeVerts(line, EnumSet.of(MatchCondition.UVs));
applyCurrentMaterial(line);
mapToGroups(line);
@@ -315,7 +326,7 @@ public class ObjGeometryStore {
groupData.setVertGroups(vertGroups);
groupData.setGroupConditions(VertGroupData.DEFAULT_GROUP,
EnumSet.of(MatchCondition.Normal, MatchCondition.UVs));
- GeometryTool.minimizeVerts(mesh, groupData);
+ _geometryTool.minimizeVerts(mesh, groupData);
applyCurrentMaterial(mesh);
mapToGroups(mesh);
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjImporter.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjImporter.java
index e41cae6..f7b7c28 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjImporter.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjImporter.java
@@ -21,6 +21,7 @@ import com.ardor3d.image.TextureStoreFormat;
import com.ardor3d.math.MathUtils;
import com.ardor3d.math.Vector3;
import com.ardor3d.util.TextureManager;
+import com.ardor3d.util.geom.GeometryTool;
import com.ardor3d.util.resource.ResourceLocator;
import com.ardor3d.util.resource.ResourceLocatorTool;
import com.ardor3d.util.resource.ResourceSource;
@@ -130,8 +131,21 @@ public class ObjImporter {
* @return an ObjGeometryStore data object containing the scene and other useful elements.
*/
public ObjGeometryStore load(final ResourceSource resource) {
+ return load(resource, new GeometryTool());
+ }
+
+ /**
+ * Reads a Wavefront OBJ file from the given resource
+ *
+ * @param resource
+ * the name of the resource to find.
+ * @param geometryTool
+ * the geometry tool used to minimize the vertex count.
+ * @return an ObjGeometryStore data object containing the scene and other useful elements.
+ */
+ public ObjGeometryStore load(final ResourceSource resource, final GeometryTool geometryTool) {
try {
- final ObjGeometryStore store = new ObjGeometryStore();
+ final ObjGeometryStore store = new ObjGeometryStore(geometryTool);
long currentSmoothGroup = -1;
final BufferedReader reader = new BufferedReader(new InputStreamReader(resource.openStream()));