Refactoring: removing BlenderContext cleaning; reference to the instance of this class is lost instead after the loading is done.
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10875 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
f49992d15b
commit
7987f5edf0
@ -38,7 +38,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Stack;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.jme3.animation.Bone;
|
||||
import com.jme3.animation.Skeleton;
|
||||
@ -64,8 +63,6 @@ import com.jme3.scene.plugins.blender.meshes.MeshContext;
|
||||
* @author Marcin Roguski (Kaelthas)
|
||||
*/
|
||||
public class BlenderContext {
|
||||
private static final Logger LOGGER = Logger.getLogger(BlenderContext.class.getName());
|
||||
|
||||
/** The blender file version. */
|
||||
private int blenderVersion;
|
||||
/** The blender key. */
|
||||
@ -78,9 +75,10 @@ public class BlenderContext {
|
||||
private BlenderInputStream inputStream;
|
||||
/** The asset manager. */
|
||||
private AssetManager assetManager;
|
||||
/** The blocks read from the file. */
|
||||
protected List<FileBlockHeader> blocks;
|
||||
/**
|
||||
* A map containing the file block headers. The key is the old pointer
|
||||
* address.
|
||||
* A map containing the file block headers. The key is the old memory address.
|
||||
*/
|
||||
private Map<Long, FileBlockHeader> fileBlockHeadersByOma = new HashMap<Long, FileBlockHeader>();
|
||||
/** A map containing the file block headers. The key is the block code. */
|
||||
@ -613,26 +611,6 @@ public class BlenderContext {
|
||||
return markersMap == null ? null : markersMap.get(feature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all sotred resources and closes the blender input stream.
|
||||
*/
|
||||
public void dispose() {
|
||||
LOGGER.fine("Disposing blender context resources.");
|
||||
inputStream.forceClose();
|
||||
loadedFeatures.clear();
|
||||
loadedFeaturesByName.clear();
|
||||
parentStack.clear();
|
||||
constraints.clear();
|
||||
animData.clear();
|
||||
skeletons.clear();
|
||||
meshContexts.clear();
|
||||
boneContexts.clear();
|
||||
helpers.clear();
|
||||
fileBlockHeadersByOma.clear();
|
||||
fileBlockHeadersByCode.clear();
|
||||
markers.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* This enum defines what loaded data type user wants to retreive. It can be
|
||||
* either filled structure or already converted data.
|
||||
|
@ -139,10 +139,11 @@ public class BlenderLoader implements AssetLoader {
|
||||
loadingResults.addScene(this.toScene(sceneBlock.getStructure(blenderContext)));
|
||||
}
|
||||
|
||||
blenderContext.dispose();
|
||||
return loadingResults;
|
||||
} catch (BlenderFileException e) {
|
||||
throw new IOException(e.getLocalizedMessage(), e);
|
||||
} finally {
|
||||
this.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@ -267,4 +268,13 @@ public class BlenderLoader implements AssetLoader {
|
||||
blenderContext.setSceneStructure(sceneFileBlock.getStructure(blenderContext));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The internal data is only needed during loading so make it unreachable so that the GC can release
|
||||
* that memory (which can be quite large amount).
|
||||
*/
|
||||
protected void clear() {
|
||||
blenderContext = null;
|
||||
blocks = null;
|
||||
}
|
||||
}
|
||||
|
@ -69,11 +69,11 @@ public class BlenderModelLoader extends BlenderLoader {
|
||||
ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
|
||||
Object object = objectHelper.toObject(block.getStructure(blenderContext), blenderContext);
|
||||
if (object instanceof LightNode && (blenderKey.getFeaturesToLoad() & FeaturesToLoad.LIGHTS) != 0) {
|
||||
rootObjects.add((LightNode)object);
|
||||
rootObjects.add((LightNode) object);
|
||||
} else if (object instanceof Node && (blenderKey.getFeaturesToLoad() & FeaturesToLoad.OBJECTS) != 0) {
|
||||
LOGGER.log(Level.FINE, "{0}: {1}--> {2}", new Object[] { ((Node) object).getName(), ((Node) object).getLocalTranslation().toString(), ((Node) object).getParent() == null ? "null" : ((Node) object).getParent().getName() });
|
||||
if (((Node) object).getParent() == null) {
|
||||
rootObjects.add((Node)object);
|
||||
rootObjects.add((Node) object);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -83,20 +83,21 @@ public class BlenderModelLoader extends BlenderLoader {
|
||||
ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class);
|
||||
constraintHelper.bakeConstraints(blenderContext);
|
||||
|
||||
//attach the nodes to the root node at the very end so that the root objects have no parents during constraint applying
|
||||
// attach the nodes to the root node at the very end so that the root objects have no parents during constraint applying
|
||||
LOGGER.fine("Creating the root node of the model and applying loaded nodes of the scene to it.");
|
||||
Node modelRoot = new Node(blenderKey.getName());
|
||||
for(Node node : rootObjects) {
|
||||
if(node instanceof LightNode) {
|
||||
for (Node node : rootObjects) {
|
||||
if (node instanceof LightNode) {
|
||||
modelRoot.addLight(((LightNode) node).getLight());
|
||||
}
|
||||
modelRoot.attachChild(node);
|
||||
}
|
||||
|
||||
blenderContext.dispose();
|
||||
|
||||
return modelRoot;
|
||||
} catch (BlenderFileException e) {
|
||||
throw new IOException(e.getLocalizedMessage(), e);
|
||||
} finally {
|
||||
this.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ public class BlenderInputStream extends InputStream {
|
||||
this.readFileHeader();
|
||||
} catch (BlenderFileException e) {// the file might be packed, don't panic, try one more time ;)
|
||||
this.decompressFile();
|
||||
this.position = 0;
|
||||
position = 0;
|
||||
this.readFileHeader();
|
||||
}
|
||||
}
|
||||
@ -363,16 +363,9 @@ public class BlenderInputStream extends InputStream {
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
// this method is unimplemented because some loaders (ie. TGALoader) have flaws that close the stream given from the outside
|
||||
// this method is unimplemented because some loaders (ie. TGALoader) tend close the stream given from the outside
|
||||
// because the images can be stored directly in the blender file then this stream is properly positioned and given to the loader
|
||||
// to read the image file, that is why we do not want it to be closed before the reading is done
|
||||
// to properly close the stream use forceClose() method
|
||||
}
|
||||
|
||||
/**
|
||||
* This method should be used to close the stream because some loaders may close the stream while reading resources from it.
|
||||
*/
|
||||
public void forceClose() {
|
||||
cachedBuffer = null;
|
||||
// and anyway this stream is only a cached buffer, so it does not hold any open connection to anything
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user