diff options
author | Julien Gouesse <[email protected]> | 2019-05-28 14:24:07 +0200 |
---|---|---|
committer | Julien Gouesse <[email protected]> | 2019-05-28 14:24:07 +0200 |
commit | 9e3d502e0501fe0b25d691ba5e44623189c4a829 (patch) | |
tree | 4a802c219782c141ebfdd60bfda6e41e4455dc16 /ardor3d-collada/src/main/java | |
parent | b5a570d97c3f68ad7720ad31c8e1adb55c44679c (diff) |
Replaces Guava's Multimap by Java Map in ardor3d-collada and removes Google Guava from the build scripts as it's no longer used in JogAmp's Ardor3D Continuation (issue #13)
Diffstat (limited to 'ardor3d-collada/src/main/java')
7 files changed, 177 insertions, 89 deletions
diff --git a/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaAnimUtils.java b/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaAnimUtils.java index c4c4365..fa5bdf8 100644 --- a/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaAnimUtils.java +++ b/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaAnimUtils.java @@ -65,8 +65,6 @@ import com.ardor3d.util.export.binary.BinaryExporter; import com.ardor3d.util.export.binary.BinaryImporter; import com.ardor3d.util.geom.BufferUtils; import com.ardor3d.util.geom.VertMap; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; /** * Methods for parsing Collada data related to animation, skinning and morphing. @@ -98,14 +96,16 @@ public class ColladaAnimUtils { * @see SkinData#SkinData(String) */ private String getSkinStoreName(final Element ic, final Element controller) { - final String controllerName = controller.getAttributeValue("name", (String) null) != null ? controller - .getAttributeValue("name", (String) null) : controller.getAttributeValue("id", (String) null); - final String instanceControllerName = ic.getAttributeValue("name", (String) null) != null ? ic - .getAttributeValue("name", (String) null) : ic.getAttributeValue("sid", (String) null); - final String storeName = (controllerName != null ? controllerName : "") - + (controllerName != null && instanceControllerName != null ? " : " : "") - + (instanceControllerName != null ? instanceControllerName : ""); - return storeName; + final String controllerName = controller.getAttributeValue("name", (String) null) != null + ? controller.getAttributeValue("name", (String) null) + : controller.getAttributeValue("id", (String) null); + final String instanceControllerName = ic.getAttributeValue("name", (String) null) != null + ? ic.getAttributeValue("name", (String) null) + : ic.getAttributeValue("sid", (String) null); + final String storeName = (controllerName != null ? controllerName : "") + + (controllerName != null && instanceControllerName != null ? " : " : "") + + (instanceControllerName != null ? instanceControllerName : ""); + return storeName; } /** @@ -152,8 +152,9 @@ public class ColladaAnimUtils { final Element controller = _colladaDOMUtil.findTargetWithId(instanceController.getAttributeValue("url")); if (controller == null) { - throw new ColladaException("Unable to find controller with id: " - + instanceController.getAttributeValue("url"), instanceController); + throw new ColladaException( + "Unable to find controller with id: " + instanceController.getAttributeValue("url"), + instanceController); } final Element skin = controller.getChild("skin"); @@ -180,14 +181,14 @@ public class ColladaAnimUtils { * @param skin * our <skin> element. */ - private void buildSkinMeshes(final Node ardorParentNode, final Element instanceController, - final Element controller, final Element skin) { + private void buildSkinMeshes(final Node ardorParentNode, final Element instanceController, final Element controller, + final Element skin) { final String skinSource = skin.getAttributeValue("source"); final Element skinNodeEL = _colladaDOMUtil.findTargetWithId(skinSource); if (skinNodeEL == null || !"geometry".equals(skinNodeEL.getName())) { - throw new ColladaException("Expected a mesh for skin source with url: " + skinSource + " got instead: " - + skinNodeEL, skin); + throw new ColladaException( + "Expected a mesh for skin source with url: " + skinSource + " got instead: " + skinNodeEL, skin); } final Element geometry = skinNodeEL; @@ -202,8 +203,8 @@ public class ColladaAnimUtils { // add as a possible root for when we need to locate a joint by name later. skeletonRoots.add(skroot); } else { - throw new ColladaException("Unable to find node with id: " + sk.getText() - + ", referenced from skeleton " + sk, sk); + throw new ColladaException( + "Unable to find node with id: " + sk.getText() + ", referenced from skeleton " + sk, sk); } } @@ -274,8 +275,8 @@ public class ColladaAnimUtils { if (paramType == ParamType.idref_param) { found = _colladaDOMUtil.findTargetWithId(name); } else { - found = (Element) _colladaDOMUtil.selectSingleNode(geometry, "/*//visual_scene//*[@sid='" - + name + "']"); + found = (Element) _colladaDOMUtil.selectSingleNode(geometry, + "/*//visual_scene//*[@sid='" + name + "']"); } // Last resorts (bad exporters) @@ -283,8 +284,8 @@ public class ColladaAnimUtils { found = _colladaDOMUtil.findTargetWithId(name); } if (found == null) { - found = (Element) _colladaDOMUtil.selectSingleNode(geometry, "/*//visual_scene//*[@name='" - + name + "']"); + found = (Element) _colladaDOMUtil.selectSingleNode(geometry, + "/*//visual_scene//*[@name='" + name + "']"); } if (found == null) { @@ -565,8 +566,9 @@ public class ColladaAnimUtils { private void addAttachments(final SkeletonPose skPose) { final Skeleton skeleton = skPose.getSkeleton(); for (final Joint joint : skeleton.getJoints()) { - if (_dataCache.getAttachmentPoints().containsKey(joint)) { - for (final AttachmentPoint point : _dataCache.getAttachmentPoints().get(joint)) { + final List<AttachmentPoint> attachmentPoints = _dataCache.getAttachmentPoints().get(joint); + if (attachmentPoints != null) { + for (final AttachmentPoint point : attachmentPoints) { point.setJointIndex(joint.getIndex()); skPose.addPoseListener(point); } @@ -593,8 +595,9 @@ public class ColladaAnimUtils { final Element skinNode = _colladaDOMUtil.findTargetWithId(skinSource); if (skinNode == null || !"geometry".equals(skinNode.getName())) { - throw new ColladaException("Expected a mesh for morph source with url: " + skinSource - + " (line number is referring morph)", morph); + throw new ColladaException( + "Expected a mesh for morph source with url: " + skinSource + " (line number is referring morph)", + morph); } final Element geometry = skinNode; @@ -630,12 +633,14 @@ public class ColladaAnimUtils { final AnimationItem animationItemRoot = new AnimationItem("Animation Root"); _colladaStorage.setAnimationItemRoot(animationItemRoot); - final Multimap<Element, TargetChannel> channelMap = ArrayListMultimap.create(); + final Map<Element, List<TargetChannel>> channelMap = new HashMap<>(); parseAnimations(channelMap, libraryAnimations, animationItemRoot); - for (final Element key : channelMap.keySet()) { - buildAnimations(key, channelMap.get(key)); + for (final Map.Entry<Element, List<TargetChannel>> channelMapEntry : channelMap.entrySet()) { + if (channelMapEntry.getValue() != null) { + buildAnimations(channelMapEntry.getKey(), channelMapEntry.getValue()); + } } } @@ -836,7 +841,7 @@ public class ColladaAnimUtils { * @param animationRoot * @param animationItemRoot */ - private void parseAnimations(final Multimap<Element, TargetChannel> channelMap, final Element animationRoot, + private void parseAnimations(final Map<Element, List<TargetChannel>> channelMap, final Element animationRoot, final AnimationItem animationItemRoot) { if (animationRoot.getChild("animation") != null) { Attribute nameAttribute = animationRoot.getAttribute("name"); @@ -880,8 +885,18 @@ public class ColladaAnimUtils { target.accessorIndexX = 3; } - channelMap.put(targetNode.getParentElement(), new TargetChannel(target, targetNode, source, - animationItemRoot)); + final TargetChannel targetChannel = new TargetChannel(target, targetNode, source, animationItemRoot); + channelMap.compute(targetNode.getParentElement(), + (final Element currentKey, final List<TargetChannel> oldValue) -> { + final List<TargetChannel> newValue; + if (oldValue == null) { + newValue = new ArrayList<>(); + } else { + newValue = oldValue; + } + newValue.add(targetChannel); + return newValue; + }); } } } @@ -1068,8 +1083,8 @@ public class ColladaAnimUtils { } else if (type == TransformElementType.Rotation) { if (array[3] != 0) { workingMat.setIdentity(); - final Matrix3 rotate = new Matrix3().fromAngleAxis(array[3] * MathUtils.DEG_TO_RAD, new Vector3( - array[0], array[1], array[2])); + final Matrix3 rotate = new Matrix3().fromAngleAxis(array[3] * MathUtils.DEG_TO_RAD, + new Vector3(array[0], array[1], array[2])); workingMat.set(rotate); finalMat.multiplyLocal(workingMat); } @@ -1182,7 +1197,7 @@ public class ColladaAnimUtils { return "Target [accessorType=" + accessorType + ", id=" + id + ", sids=" + sids + "]"; } return "Target [accessorType=" + accessorType + ", accessorIndexX=" + accessorIndexX + ", accessorIndexY=" - + accessorIndexY + ", id=" + id + ", sids=" + sids + "]"; + + accessorIndexY + ", id=" + id + ", sids=" + sids + "]"; } } } 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 eade09d..a329877 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 @@ -13,9 +13,9 @@ package com.ardor3d.extension.model.collada.jdom; import java.io.IOException; import java.nio.FloatBuffer; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.EnumSet; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; @@ -49,8 +49,6 @@ import com.ardor3d.util.resource.RelativeResourceLocator; import com.ardor3d.util.resource.ResourceLocator; import com.ardor3d.util.resource.ResourceLocatorTool; import com.ardor3d.util.resource.ResourceSource; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; /** * Main class for importing Collada files. @@ -290,13 +288,15 @@ public class ColladaImporter { } // copy across our mesh colors - only for objects with multiple channels - final Multimap<MeshData, FloatBuffer> colors = ArrayListMultimap.create(); - final Multimap<MeshData, FloatBuffer> temp = dataCache.getParsedVertexColors(); - for (final MeshData key : temp.keySet()) { + final Map<MeshData, List<FloatBuffer>> colors = new HashMap<>(); + final Map<MeshData, List<FloatBuffer>> temp = dataCache.getParsedVertexColors(); + for (final Map.Entry<MeshData, List<FloatBuffer>> tempEntry : temp.entrySet()) { + final MeshData key = tempEntry.getKey(); // only copy multiple channels since their data is lost - final Collection<FloatBuffer> val = temp.get(key); + final List<FloatBuffer> val = tempEntry.getValue(); if (val != null && val.size() > 1) { - colors.putAll(key, val); + // defensive copy, not sure that it's really necessary + colors.put(key, new ArrayList<>(val)); } } colladaStorage.setParsedVertexColors(colors); diff --git a/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaInputPipe.java b/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaInputPipe.java index ff99c48..ab15384 100644 --- a/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaInputPipe.java +++ b/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaInputPipe.java @@ -11,6 +11,7 @@ package com.ardor3d.extension.model.collada.jdom; import java.nio.FloatBuffer; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.logging.Level; @@ -194,16 +195,26 @@ public class ColladaInputPipe { case COLOR: _buffer = BufferUtils.createFloatBuffer(size); meshData.setColorCoords(new FloatBufferData(_buffer, _paramCount)); - cache.getParsedVertexColors().put(meshData, _buffer); + cache.getParsedVertexColors().compute(meshData, + (final MeshData currentKey, final List<FloatBuffer> oldValue) -> { + final List<FloatBuffer> newValue; + if (oldValue == null) { + newValue = new ArrayList<>(); + } else { + newValue = oldValue; + } + newValue.add(_buffer); + return newValue; + }); break; case TEXTANGENT: _buffer = BufferUtils.createFloatBuffer(size); meshData.setTangentCoords(new FloatBufferData(_buffer, _paramCount)); break; - // case TEXBINORMAL: - // _buffer = BufferUtils.createFloatBuffer(size); - // meshData.setTangentBuffer(_buffer); - // break; + // case TEXBINORMAL: + // _buffer = BufferUtils.createFloatBuffer(size); + // meshData.setTangentBuffer(_buffer); + // break; default: } } 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 4b9cc29..ec45945 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 @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at <http://www.ardor3d.com/LICENSE>. */ @@ -11,8 +11,10 @@ package com.ardor3d.extension.model.collada.jdom; import java.nio.FloatBuffer; +import java.util.ArrayList; import java.util.EnumSet; import java.util.LinkedList; +import java.util.List; import java.util.logging.Logger; import org.jdom2.Element; @@ -64,7 +66,7 @@ public class ColladaMeshUtils { /** * Builds geometry from an instance_geometry element. - * + * * @param instanceGeometry * @return our Spatial */ @@ -81,7 +83,7 @@ public class ColladaMeshUtils { * Builds a mesh from a Collada geometry element. Currently supported mesh types: mesh, polygons, polylist, * triangles, lines. Not supported yet: linestrips, trifans, tristrips. If no meshtype is found, a pointcloud is * built. - * + * * @param colladaGeometry * @return a Node containing all of the Ardor3D meshes we've parsed from this geometry element. */ @@ -217,7 +219,17 @@ public class ColladaMeshUtils { indices[i] = i; } final MeshVertPairs mvp = new MeshVertPairs(points, indices); - _dataCache.getVertMappings().put(colladaGeometry, mvp); + _dataCache.getVertMappings().compute(colladaGeometry, + (final Element currentKey, final List<MeshVertPairs> oldValue) -> { + final List<MeshVertPairs> newValue; + if (oldValue == null) { + newValue = new ArrayList<>(); + } else { + newValue = oldValue; + } + newValue.add(mvp); + return newValue; + }); if (_optimizeMeshes) { final VertMap map = _geometryTool.minimizeVerts(points, _optimizeSettings); @@ -263,11 +275,21 @@ public class ColladaMeshUtils { // Add to vert mapping final int[] indices = new int[numEntries]; final MeshVertPairs mvp = new MeshVertPairs(polyMesh, indices); - _dataCache.getVertMappings().put(colladaGeometry, mvp); + _dataCache.getVertMappings().compute(colladaGeometry, + (final Element currentKey, final List<MeshVertPairs> oldValue) -> { + final List<MeshVertPairs> newValue; + if (oldValue == null) { + newValue = new ArrayList<>(); + } else { + newValue = oldValue; + } + newValue.add(mvp); + return newValue; + }); // Prepare indices buffer - final IndexBufferData<?> meshIndices = BufferUtils.createIndexBufferData(numIndices, polyMesh.getMeshData() - .getVertexCount() - 1); + final IndexBufferData<?> meshIndices = BufferUtils.createIndexBufferData(numIndices, + polyMesh.getMeshData().getVertexCount() - 1); polyMesh.getMeshData().setIndices(meshIndices); // go through the polygon entries @@ -356,11 +378,21 @@ public class ColladaMeshUtils { // Add to vert mapping final int[] indices = new int[numEntries]; final MeshVertPairs mvp = new MeshVertPairs(polyMesh, indices); - _dataCache.getVertMappings().put(colladaGeometry, mvp); + _dataCache.getVertMappings().compute(colladaGeometry, + (final Element currentKey, final List<MeshVertPairs> oldValue) -> { + final List<MeshVertPairs> newValue; + if (oldValue == null) { + newValue = new ArrayList<>(); + } else { + newValue = oldValue; + } + newValue.add(mvp); + return newValue; + }); // Prepare indices buffer - final IndexBufferData<?> meshIndices = BufferUtils.createIndexBufferData(numIndices, polyMesh.getMeshData() - .getVertexCount() - 1); + final IndexBufferData<?> meshIndices = BufferUtils.createIndexBufferData(numIndices, + polyMesh.getMeshData().getVertexCount() - 1); polyMesh.getMeshData().setIndices(meshIndices); // go through the polygon entries @@ -444,7 +476,17 @@ public class ColladaMeshUtils { // Add to vert mapping final int[] indices = new int[numEntries]; final MeshVertPairs mvp = new MeshVertPairs(triMesh, indices); - _dataCache.getVertMappings().put(colladaGeometry, mvp); + _dataCache.getVertMappings().compute(colladaGeometry, + (final Element currentKey, final List<MeshVertPairs> oldValue) -> { + final List<MeshVertPairs> newValue; + if (oldValue == null) { + newValue = new ArrayList<>(); + } else { + newValue = oldValue; + } + newValue.add(mvp); + return newValue; + }); // go through the p entry // for each p, iterate using max offset @@ -495,7 +537,17 @@ public class ColladaMeshUtils { // Add to vert mapping final int[] indices = new int[numEntries]; final MeshVertPairs mvp = new MeshVertPairs(lineMesh, indices); - _dataCache.getVertMappings().put(colladaGeometry, mvp); + _dataCache.getVertMappings().compute(colladaGeometry, + (final Element currentKey, final List<MeshVertPairs> oldValue) -> { + final List<MeshVertPairs> newValue; + if (oldValue == null) { + newValue = new ArrayList<>(); + } else { + newValue = oldValue; + } + newValue.add(mvp); + return newValue; + }); // go through the p entry // for each p, iterate using max offset @@ -523,7 +575,7 @@ public class ColladaMeshUtils { /** * Extract our pipes from the given parent element. - * + * * @param inputsParent * @param pipesStore * the store for our pipes @@ -564,7 +616,7 @@ public class ColladaMeshUtils { /** * Push the values at the given indices of currentVal onto the buffers defined in pipes. - * + * * @param pipes * @param currentVal * @return the vertex index referenced in the given indices based on the pipes. Integer.MIN_VALUE is returned if no @@ -586,7 +638,7 @@ public class ColladaMeshUtils { /** * Extract name from xml element, some exporters don't support 'name' attribute, so we better use the material * instead of a generic name. - * + * * @param element * @return value from 'name' or 'material' attribute */ diff --git a/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaNodeUtils.java b/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaNodeUtils.java index fcf94c4..d8f167f 100644 --- a/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaNodeUtils.java +++ b/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/ColladaNodeUtils.java @@ -305,8 +305,8 @@ public class ColladaNodeUtils { final Node subNode = getNode(in, jointNode); if (subNode != null) { node.attachChild(subNode); - if (nodeType == NodeType.JOINT - && getNodeType(_colladaDOMUtil.findTargetWithId(in.getAttributeValue("url"))) == NodeType.NODE) { + if (nodeType == NodeType.JOINT && getNodeType( + _colladaDOMUtil.findTargetWithId(in.getAttributeValue("url"))) == NodeType.NODE) { // make attachment createJointAttachment(jointChildNode, node, subNode); } @@ -373,8 +373,8 @@ public class ColladaNodeUtils { } else if ("rotate".equals(transform.getName())) { if (array[3] != 0) { workingMat.setIdentity(); - final Matrix3 rotate = new Matrix3().fromAngleAxis(array[3] * MathUtils.DEG_TO_RAD, new Vector3( - array[0], array[1], array[2])); + final Matrix3 rotate = new Matrix3().fromAngleAxis(array[3] * MathUtils.DEG_TO_RAD, + new Vector3(array[0], array[1], array[2])); workingMat.set(rotate); finalMat.multiplyLocal(workingMat); } @@ -402,8 +402,12 @@ public class ColladaNodeUtils { } public void reattachAttachments(final Node scene) { - for (final AttachmentPoint point : _dataCache.getAttachmentPoints().values()) { - scene.attachChild(point.getAttachment()); + for (final List<AttachmentPoint> attachmentPoints : _dataCache.getAttachmentPoints().values()) { + if (attachmentPoints != null) { + for (final AttachmentPoint point : attachmentPoints) { + scene.attachChild(point.getAttachment()); + } + } } } } diff --git a/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/data/ColladaStorage.java b/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/data/ColladaStorage.java index bcbb457..d26eed5 100644 --- a/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/data/ColladaStorage.java +++ b/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/data/ColladaStorage.java @@ -26,7 +26,6 @@ import com.ardor3d.scenegraph.Node; import com.ardor3d.util.export.InputCapsule; import com.ardor3d.util.export.OutputCapsule; import com.ardor3d.util.export.Savable; -import com.google.common.collect.Multimap; /** * Data storage object meant to hold objects parsed from a Collada file that the user might want to directly access. @@ -42,7 +41,7 @@ public class ColladaStorage implements Savable { // List of parsed color buffers, useful if collada includes multiple color channels per meshdata object // Transient because the key is identity - meshdata. - private transient Multimap<MeshData, FloatBuffer> _parsedVertexColors; + private transient Map<MeshData, List<FloatBuffer>> _parsedVertexColors; // Map of parsed material information, useful for doing post-manipulation of model information. // Transient because the key is identity - mesh. @@ -106,14 +105,14 @@ public class ColladaStorage implements Savable { } /** - * @return a transient Multimap of MeshData -> List of parsed vertex colors. Only MeshData objects that had multiple + * @return a transient Map of MeshData -> List of parsed vertex colors. Only MeshData objects that had multiple * vertex colors parsed will show up in this map. */ - public Multimap<MeshData, FloatBuffer> getParsedVertexColors() { + public Map<MeshData, List<FloatBuffer>> getParsedVertexColors() { return _parsedVertexColors; } - public void setParsedVertexColors(final Multimap<MeshData, FloatBuffer> parsedVertexColors) { + public void setParsedVertexColors(final Map<MeshData, List<FloatBuffer>> parsedVertexColors) { _parsedVertexColors = parsedVertexColors; } diff --git a/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/data/DataCache.java b/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/data/DataCache.java index 39960ff..b4bbd37 100644 --- a/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/data/DataCache.java +++ b/ardor3d-collada/src/main/java/com/ardor3d/extension/model/collada/jdom/data/DataCache.java @@ -32,8 +32,6 @@ import com.ardor3d.scenegraph.Mesh; import com.ardor3d.scenegraph.MeshData; import com.ardor3d.scenegraph.Spatial; import com.ardor3d.util.geom.VertMap; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; /** * Performance cache and temp storage during parsing. @@ -53,9 +51,9 @@ public class DataCache { private final Map<Element, int[]> _intArrays; private final Map<Element, String[]> _stringArrays; - private final Multimap<Element, MeshVertPairs> _vertMappings; + private final Map<Element, List<MeshVertPairs>> _vertMappings; private final Map<Mesh, VertMap> _meshVertMap; - private final Multimap<MeshData, FloatBuffer> _parsedVertexColors; + private final Map<MeshData, List<FloatBuffer>> _parsedVertexColors; private final Map<String, MaterialInfo> _materialInfoMap; private final Map<Mesh, String> _meshMaterialMap; private final Map<Element, Spatial> _elementSpatialMapping; @@ -67,7 +65,7 @@ public class DataCache { private final Map<Skeleton, SkeletonPose> _skeletonPoseMapping; private final List<Skeleton> _skeletons; private final List<ControllerStore> _controllers; - private final Multimap<Joint, AttachmentPoint> _attachmentPoints = ArrayListMultimap.create(); + private final Map<Joint, List<AttachmentPoint>> _attachmentPoints = new HashMap<>(); public DataCache() { _boundMaterials = new HashMap<>(); @@ -77,17 +75,17 @@ public class DataCache { _xPathExpressions = new HashMap<>(); _pattern = Pattern.compile("\\s"); - _transformTypes = Collections.unmodifiableList(Arrays.asList(new String[] { "lookat", "matrix", "rotate", - "scale", "scew", "translate" })); + _transformTypes = Collections.unmodifiableList( + Arrays.asList(new String[] { "lookat", "matrix", "rotate", "scale", "scew", "translate" })); _floatArrays = new HashMap<>(); _doubleArrays = new HashMap<>(); _booleanArrays = new HashMap<>(); _intArrays = new HashMap<>(); _stringArrays = new HashMap<>(); - _vertMappings = ArrayListMultimap.create(); + _vertMappings = new HashMap<>(); _meshVertMap = new IdentityHashMap<>(); - _parsedVertexColors = ArrayListMultimap.create(); + _parsedVertexColors = new HashMap<>(); _materialInfoMap = new HashMap<>(); _meshMaterialMap = new IdentityHashMap<>(); @@ -167,7 +165,7 @@ public class DataCache { return _stringArrays; } - public Multimap<Element, MeshVertPairs> getVertMappings() { + public Map<Element, List<MeshVertPairs>> getVertMappings() { return _vertMappings; } @@ -175,7 +173,7 @@ public class DataCache { return _meshVertMap; } - public Multimap<MeshData, FloatBuffer> getParsedVertexColors() { + public Map<MeshData, List<FloatBuffer>> getParsedVertexColors() { return _parsedVertexColors; } @@ -232,10 +230,19 @@ public class DataCache { } public void addAttachmentPoint(final Joint joint, final AttachmentPoint attach) { - _attachmentPoints.put(joint, attach); - } - - public Multimap<Joint, AttachmentPoint> getAttachmentPoints() { + _attachmentPoints.compute(joint, (final Joint currentKey, final List<AttachmentPoint> oldValue) -> { + final List<AttachmentPoint> newValue; + if (oldValue == null) { + newValue = new ArrayList<>(); + } else { + newValue = oldValue; + } + newValue.add(attach); + return newValue; + }); + } + + public Map<Joint, List<AttachmentPoint>> getAttachmentPoints() { return _attachmentPoints; } } |