diff --git a/jme3-core/src/main/java/com/jme3/scene/AssetLinkNode.java b/jme3-core/src/main/java/com/jme3/scene/AssetLinkNode.java index d31997f5b..82711ac6b 100644 --- a/jme3-core/src/main/java/com/jme3/scene/AssetLinkNode.java +++ b/jme3-core/src/main/java/com/jme3/scene/AssetLinkNode.java @@ -31,16 +31,15 @@ */ package com.jme3.scene; -import com.jme3.asset.AssetInfo; import com.jme3.asset.AssetManager; import com.jme3.asset.ModelKey; import com.jme3.export.InputCapsule; import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; -import com.jme3.export.binary.BinaryImporter; -import com.jme3.util.clone.Cloner; import com.jme3.util.SafeArrayList; +import com.jme3.util.clone.Cloner; + import java.io.IOException; import java.util.*; import java.util.Map.Entry; @@ -164,25 +163,24 @@ public class AssetLinkNode extends Node { @Override public void read(JmeImporter e) throws IOException { super.read(e); - InputCapsule capsule = e.getCapsule(this); - BinaryImporter importer = BinaryImporter.getInstance(); - AssetManager loaderManager = e.getAssetManager(); + + final InputCapsule capsule = e.getCapsule(this); + final AssetManager assetManager = e.getAssetManager(); assetLoaderKeys = (ArrayList) capsule.readSavableArrayList("assetLoaderKeyList", new ArrayList()); - for (Iterator it = assetLoaderKeys.iterator(); it.hasNext();) { - ModelKey modelKey = it.next(); - AssetInfo info = loaderManager.locateAsset(modelKey); - Spatial child = null; - if (info != null) { - child = (Spatial) importer.load(info); - } + + for (final Iterator iterator = assetLoaderKeys.iterator(); iterator.hasNext(); ) { + + final ModelKey modelKey = iterator.next(); + final Spatial child = assetManager.loadAsset(modelKey); + if (child != null) { child.parent = this; children.add(child); assetChildren.put(modelKey, child); } else { - Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot locate {0} for asset link node {1}", - new Object[]{ modelKey, key }); + Logger.getLogger(this.getClass().getName()).log(Level.WARNING, + "Cannot locate {0} for asset link node {1}", new Object[]{modelKey, key}); } } } @@ -190,7 +188,7 @@ public class AssetLinkNode extends Node { @Override public void write(JmeExporter e) throws IOException { SafeArrayList childs = children; - children = new SafeArrayList(Spatial.class); + children = new SafeArrayList<>(Spatial.class); super.write(e); OutputCapsule capsule = e.getCapsule(this); capsule.writeSavableArrayList(assetLoaderKeys, "assetLoaderKeyList", null); diff --git a/jme3-core/src/main/resources/com/jme3/asset/General.cfg b/jme3-core/src/main/resources/com/jme3/asset/General.cfg index 016dcccf2..80b038ba6 100644 --- a/jme3-core/src/main/resources/com/jme3/asset/General.cfg +++ b/jme3-core/src/main/resources/com/jme3/asset/General.cfg @@ -12,8 +12,8 @@ LOADER com.jme3.texture.plugins.DDSLoader : dds LOADER com.jme3.texture.plugins.PFMLoader : pfm LOADER com.jme3.texture.plugins.HDRLoader : hdr LOADER com.jme3.texture.plugins.TGALoader : tga -LOADER com.jme3.export.binary.BinaryImporter : j3o -LOADER com.jme3.export.binary.BinaryImporter : j3f +LOADER com.jme3.export.binary.BinaryLoader : j3o +LOADER com.jme3.export.binary.BinaryLoader : j3f LOADER com.jme3.scene.plugins.OBJLoader : obj LOADER com.jme3.scene.plugins.MTLLoader : mtl LOADER com.jme3.scene.plugins.ogre.MeshLoader : meshxml, mesh.xml diff --git a/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryLoader.java b/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryLoader.java new file mode 100644 index 000000000..4f8d7e09a --- /dev/null +++ b/jme3-core/src/plugins/java/com/jme3/export/binary/BinaryLoader.java @@ -0,0 +1,41 @@ +package com.jme3.export.binary; + +import com.jme3.asset.AssetInfo; +import com.jme3.asset.AssetLoader; + +import java.io.IOException; +import java.util.ArrayDeque; +import java.util.Deque; + +/** + * The default loader to load binaries files. + * + * @author JavaSaBr + */ +public class BinaryLoader implements AssetLoader { + + /** + * The importers queue. + */ + private final Deque importers; + + public BinaryLoader() { + importers = new ArrayDeque<>(); + } + + @Override + public Object load(final AssetInfo assetInfo) throws IOException { + + BinaryImporter importer = importers.pollLast(); + + if (importer == null) { + importer = new BinaryImporter(); + } + + try { + return importer.load(assetInfo); + } finally { + importers.addLast(importer); + } + } +}