Disabling loading all assets by default. Now unlinked assets or those being on inactive layers will not be loaded if they are not requested to.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8042 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Kae..pl 13 years ago
parent b3a37f93b7
commit daa86cfec7
  1. 69
      engine/src/blender/com/jme3/asset/BlenderKey.java
  2. 4
      engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java

@ -88,6 +88,8 @@ public class BlenderKey extends ModelKey {
* This variable is a bitwise flag of FeatureToLoad interface values; By default everything is being loaded. * This variable is a bitwise flag of FeatureToLoad interface values; By default everything is being loaded.
*/ */
protected int featuresToLoad = FeaturesToLoad.ALL; protected int featuresToLoad = FeaturesToLoad.ALL;
/** This variable determines if assets that are not linked to the objects should be loaded. */
protected boolean loadUnlinkedAssets;
/** The root path for all the assets. */ /** The root path for all the assets. */
protected String assetRootPath; protected String assetRootPath;
/** This variable indicate if Y axis is UP axis. If not then Z is up. By default set to true. */ /** This variable indicate if Y axis is UP axis. If not then Z is up. By default set to true. */
@ -113,8 +115,7 @@ public class BlenderKey extends ModelKey {
/** /**
* Constructor used by serialization mechanisms. * Constructor used by serialization mechanisms.
*/ */
public BlenderKey() { public BlenderKey() {}
}
/** /**
* Constructor. Creates a key for the given file name. * Constructor. Creates a key for the given file name.
@ -155,7 +156,7 @@ public class BlenderKey extends ModelKey {
objectAnimations = new HashMap<String, int[]>(); objectAnimations = new HashMap<String, int[]>();
animations.put(objectName, objectAnimations); animations.put(objectName, objectAnimations);
} }
objectAnimations.put(name, new int[]{start, stop}); objectAnimations.put(name, new int[] { start, stop });
} }
/** /**
@ -273,7 +274,8 @@ public class BlenderKey extends ModelKey {
/** /**
* This method sets layers to be loaded. * This method sets layers to be loaded.
* @param layersToLoad layers to be loaded * @param layersToLoad
* layers to be loaded
*/ */
public void setLayersToLoad(int layersToLoad) { public void setLayersToLoad(int layersToLoad) {
this.layersToLoad = layersToLoad; this.layersToLoad = layersToLoad;
@ -331,6 +333,29 @@ public class BlenderKey extends ModelKey {
return featuresToLoad; return featuresToLoad;
} }
/**
* This method determines if unlinked assets should be loaded.
* If not then only objects on selected layers will be loaded and their assets if required.
* If yes then all assets will be loaded even if they are on inactive layers or are not linked
* to anything.
* @return <b>true</b> if unlinked assets should be loaded and <b>false</b> otherwise
*/
public boolean isLoadUnlinkedAssets() {
return loadUnlinkedAssets;
}
/**
* This method sets if unlinked assets should be loaded.
* If not then only objects on selected layers will be loaded and their assets if required.
* If yes then all assets will be loaded even if they are on inactive layers or are not linked
* to anything.
* @param loadUnlinkedAssets
* <b>true</b> if unlinked assets should be loaded and <b>false</b> otherwise
*/
public void setLoadUnlinkedAssets(boolean loadUnlinkedAssets) {
this.loadUnlinkedAssets = loadUnlinkedAssets;
}
/** /**
* This method creates an object where loading results will be stores. Only those features will be allowed to store * This method creates an object where loading results will be stores. Only those features will be allowed to store
* that were specified by features-to-load flag. * that were specified by features-to-load flag.
@ -399,7 +424,7 @@ public class BlenderKey extends ModelKey {
public void write(JmeExporter e) throws IOException { public void write(JmeExporter e) throws IOException {
super.write(e); super.write(e);
OutputCapsule oc = e.getCapsule(this); OutputCapsule oc = e.getCapsule(this);
//saving animations // saving animations
oc.write(animations == null ? 0 : animations.size(), "anim-size", 0); oc.write(animations == null ? 0 : animations.size(), "anim-size", 0);
if (animations != null) { if (animations != null) {
int objectCounter = 0; int objectCounter = 0;
@ -414,9 +439,13 @@ public class BlenderKey extends ModelKey {
++objectCounter; ++objectCounter;
} }
} }
//saving the rest of the data // saving the rest of the data
oc.write(fps, "fps", DEFAULT_FPS); oc.write(fps, "fps", DEFAULT_FPS);
oc.write(generatedTextureWidth, "generated-texture-width", 20);
oc.write(generatedTextureHeight, "generated-texture-height", 20);
oc.write(generatedTextureDepth, "generated-texture-depth", 20);
oc.write(featuresToLoad, "features-to-load", FeaturesToLoad.ALL); oc.write(featuresToLoad, "features-to-load", FeaturesToLoad.ALL);
oc.write(loadUnlinkedAssets, "load-unlinked-assets", false);
oc.write(assetRootPath, "asset-root-path", null); oc.write(assetRootPath, "asset-root-path", null);
oc.write(fixUpAxis, "fix-up-axis", true); oc.write(fixUpAxis, "fix-up-axis", true);
oc.write(usedWorld, "used-world", null); oc.write(usedWorld, "used-world", null);
@ -429,7 +458,7 @@ public class BlenderKey extends ModelKey {
public void read(JmeImporter e) throws IOException { public void read(JmeImporter e) throws IOException {
super.read(e); super.read(e);
InputCapsule ic = e.getCapsule(this); InputCapsule ic = e.getCapsule(this);
//reading animations // reading animations
int animSize = ic.readInt("anim-size", 0); int animSize = ic.readInt("anim-size", 0);
if (animSize > 0) { if (animSize > 0) {
if (animations == null) { if (animations == null) {
@ -450,9 +479,13 @@ public class BlenderKey extends ModelKey {
} }
} }
//reading the rest of the data // reading the rest of the data
fps = ic.readInt("fps", DEFAULT_FPS); fps = ic.readInt("fps", DEFAULT_FPS);
generatedTextureWidth = ic.readInt("generated-texture-width", 20);
generatedTextureHeight = ic.readInt("generated-texture-height", 20);
generatedTextureDepth = ic.readInt("generated-texture-depth", 20);
featuresToLoad = ic.readInt("features-to-load", FeaturesToLoad.ALL); featuresToLoad = ic.readInt("features-to-load", FeaturesToLoad.ALL);
loadUnlinkedAssets = ic.readBoolean("load-unlinked-assets", false);
assetRootPath = ic.readString("asset-root-path", null); assetRootPath = ic.readString("asset-root-path", null);
fixUpAxis = ic.readBoolean("fix-up-axis", true); fixUpAxis = ic.readBoolean("fix-up-axis", true);
usedWorld = ic.readString("used-world", null); usedWorld = ic.readString("used-world", null);
@ -472,9 +505,11 @@ public class BlenderKey extends ModelKey {
result = prime * result + featuresToLoad; result = prime * result + featuresToLoad;
result = prime * result + (fixUpAxis ? 1231 : 1237); result = prime * result + (fixUpAxis ? 1231 : 1237);
result = prime * result + fps; result = prime * result + fps;
result = prime * result + generatedTextureDepth;
result = prime * result + generatedTextureHeight; result = prime * result + generatedTextureHeight;
result = prime * result + generatedTextureWidth; result = prime * result + generatedTextureWidth;
result = prime * result + layersToLoad; result = prime * result + layersToLoad;
result = prime * result + (loadUnlinkedAssets ? 1231 : 1237);
result = prime * result + (usedWorld == null ? 0 : usedWorld.hashCode()); result = prime * result + (usedWorld == null ? 0 : usedWorld.hashCode());
return result; return result;
} }
@ -524,6 +559,9 @@ public class BlenderKey extends ModelKey {
if (fps != other.fps) { if (fps != other.fps) {
return false; return false;
} }
if (generatedTextureDepth != other.generatedTextureDepth) {
return false;
}
if (generatedTextureHeight != other.generatedTextureHeight) { if (generatedTextureHeight != other.generatedTextureHeight) {
return false; return false;
} }
@ -533,6 +571,9 @@ public class BlenderKey extends ModelKey {
if (layersToLoad != other.layersToLoad) { if (layersToLoad != other.layersToLoad) {
return false; return false;
} }
if (loadUnlinkedAssets != other.loadUnlinkedAssets) {
return false;
}
if (usedWorld == null) { if (usedWorld == null) {
if (other.usedWorld != null) { if (other.usedWorld != null) {
return false; return false;
@ -751,12 +792,10 @@ public class BlenderKey extends ModelKey {
} }
@Override @Override
public void updateModelBound() { public void updateModelBound() {}
}
@Override @Override
public void setModelBound(BoundingVolume modelBound) { public void setModelBound(BoundingVolume modelBound) {}
}
@Override @Override
public int getVertexCount() { public int getVertexCount() {
@ -774,12 +813,10 @@ public class BlenderKey extends ModelKey {
} }
@Override @Override
public void depthFirstTraversal(SceneGraphVisitor visitor) { public void depthFirstTraversal(SceneGraphVisitor visitor) {}
}
@Override @Override
protected void breadthFirstTraversal(SceneGraphVisitor visitor, Queue<Spatial> queue) { protected void breadthFirstTraversal(SceneGraphVisitor visitor, Queue<Spatial> queue) {}
}
} }
/** /**

@ -153,7 +153,7 @@ public class BlenderLoader implements AssetLoader {
} }
break; break;
case FileBlockHeader.BLOCK_MA00://Material case FileBlockHeader.BLOCK_MA00://Material
if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.MATERIALS) != 0) { if (blenderKey.isLoadUnlinkedAssets() && (blenderKey.getFeaturesToLoad() & FeaturesToLoad.MATERIALS) != 0) {
loadingResults.addMaterial(converter.toMaterial(block.getStructure(dataRepository))); loadingResults.addMaterial(converter.toMaterial(block.getStructure(dataRepository)));
} }
break; break;
@ -163,7 +163,7 @@ public class BlenderLoader implements AssetLoader {
} }
break; break;
case FileBlockHeader.BLOCK_WO00://World case FileBlockHeader.BLOCK_WO00://World
if (worldData == null) {//onlu one world data is used if (blenderKey.isLoadUnlinkedAssets() && worldData == null) {//onlu one world data is used
Structure worldStructure = block.getStructure(dataRepository); Structure worldStructure = block.getStructure(dataRepository);
String worldName = worldStructure.getName(); String worldName = worldStructure.getName();
if (blenderKey.getUsedWorld() == null || blenderKey.getUsedWorld().equals(worldName)) { if (blenderKey.getUsedWorld() == null || blenderKey.getUsedWorld().equals(worldName)) {

Loading…
Cancel
Save