fixed asset linked node to reuse shared data between loaded models. (#739)

* fixed asset linked node to reuse shared data between loaded models.
* updated implementation of binary loader.
empirephoenix-patch-1
Alexandr Brui 7 years ago committed by Kirill Vainer
parent 94e828f92e
commit 556e3de1c0
  1. 30
      jme3-core/src/main/java/com/jme3/scene/AssetLinkNode.java
  2. 4
      jme3-core/src/main/resources/com/jme3/asset/General.cfg
  3. 41
      jme3-core/src/plugins/java/com/jme3/export/binary/BinaryLoader.java

@ -31,16 +31,15 @@
*/ */
package com.jme3.scene; package com.jme3.scene;
import com.jme3.asset.AssetInfo;
import com.jme3.asset.AssetManager; import com.jme3.asset.AssetManager;
import com.jme3.asset.ModelKey; import com.jme3.asset.ModelKey;
import com.jme3.export.InputCapsule; import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter; import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter; import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule; 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.SafeArrayList;
import com.jme3.util.clone.Cloner;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -164,25 +163,24 @@ public class AssetLinkNode extends Node {
@Override @Override
public void read(JmeImporter e) throws IOException { public void read(JmeImporter e) throws IOException {
super.read(e); super.read(e);
InputCapsule capsule = e.getCapsule(this);
BinaryImporter importer = BinaryImporter.getInstance(); final InputCapsule capsule = e.getCapsule(this);
AssetManager loaderManager = e.getAssetManager(); final AssetManager assetManager = e.getAssetManager();
assetLoaderKeys = (ArrayList<ModelKey>) capsule.readSavableArrayList("assetLoaderKeyList", new ArrayList<ModelKey>()); assetLoaderKeys = (ArrayList<ModelKey>) capsule.readSavableArrayList("assetLoaderKeyList", new ArrayList<ModelKey>());
for (Iterator<ModelKey> it = assetLoaderKeys.iterator(); it.hasNext();) {
ModelKey modelKey = it.next(); for (final Iterator<ModelKey> iterator = assetLoaderKeys.iterator(); iterator.hasNext(); ) {
AssetInfo info = loaderManager.locateAsset(modelKey);
Spatial child = null; final ModelKey modelKey = iterator.next();
if (info != null) { final Spatial child = assetManager.loadAsset(modelKey);
child = (Spatial) importer.load(info);
}
if (child != null) { if (child != null) {
child.parent = this; child.parent = this;
children.add(child); children.add(child);
assetChildren.put(modelKey, child); assetChildren.put(modelKey, child);
} else { } else {
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot locate {0} for asset link node {1}", Logger.getLogger(this.getClass().getName()).log(Level.WARNING,
new Object[]{ modelKey, key }); "Cannot locate {0} for asset link node {1}", new Object[]{modelKey, key});
} }
} }
} }
@ -190,7 +188,7 @@ public class AssetLinkNode extends Node {
@Override @Override
public void write(JmeExporter e) throws IOException { public void write(JmeExporter e) throws IOException {
SafeArrayList<Spatial> childs = children; SafeArrayList<Spatial> childs = children;
children = new SafeArrayList<Spatial>(Spatial.class); children = new SafeArrayList<>(Spatial.class);
super.write(e); super.write(e);
OutputCapsule capsule = e.getCapsule(this); OutputCapsule capsule = e.getCapsule(this);
capsule.writeSavableArrayList(assetLoaderKeys, "assetLoaderKeyList", null); capsule.writeSavableArrayList(assetLoaderKeys, "assetLoaderKeyList", null);

@ -12,8 +12,8 @@ LOADER com.jme3.texture.plugins.DDSLoader : dds
LOADER com.jme3.texture.plugins.PFMLoader : pfm LOADER com.jme3.texture.plugins.PFMLoader : pfm
LOADER com.jme3.texture.plugins.HDRLoader : hdr LOADER com.jme3.texture.plugins.HDRLoader : hdr
LOADER com.jme3.texture.plugins.TGALoader : tga LOADER com.jme3.texture.plugins.TGALoader : tga
LOADER com.jme3.export.binary.BinaryImporter : j3o LOADER com.jme3.export.binary.BinaryLoader : j3o
LOADER com.jme3.export.binary.BinaryImporter : j3f LOADER com.jme3.export.binary.BinaryLoader : j3f
LOADER com.jme3.scene.plugins.OBJLoader : obj LOADER com.jme3.scene.plugins.OBJLoader : obj
LOADER com.jme3.scene.plugins.MTLLoader : mtl LOADER com.jme3.scene.plugins.MTLLoader : mtl
LOADER com.jme3.scene.plugins.ogre.MeshLoader : meshxml, mesh.xml LOADER com.jme3.scene.plugins.ogre.MeshLoader : meshxml, mesh.xml

@ -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<BinaryImporter> 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);
}
}
}
Loading…
Cancel
Save