* AssetManager.loadAsset() with null key will throw exception
* Make use of try/finally paradigm for all loaders git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8183 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
0094d37e0f
commit
045e2a4317
engine/src
core-plugins/com/jme3
export/binary
font/plugins
material/plugins
scene/plugins
texture/plugins
desktop/com/jme3/asset
jogg/com/jme3/audio/plugins
ogre/com/jme3/scene/plugins/ogre
@ -125,13 +125,20 @@ public final class BinaryImporter implements JmeImporter {
|
|||||||
|
|
||||||
assetManager = info.getManager();
|
assetManager = info.getManager();
|
||||||
|
|
||||||
try{
|
InputStream is = null;
|
||||||
InputStream is = info.openStream();
|
try {
|
||||||
|
is = info.openStream();
|
||||||
Savable s = load(is);
|
Savable s = load(is);
|
||||||
is.close();
|
|
||||||
return s;
|
return s;
|
||||||
}catch (IOException ex){
|
} catch (IOException ex) {
|
||||||
logger.log(Level.SEVERE, "An error occured while loading jME binary object", ex);
|
logger.log(Level.SEVERE, "An error occured while loading jME binary object", ex);
|
||||||
|
} finally {
|
||||||
|
if (is != null){
|
||||||
|
try {
|
||||||
|
is.close();
|
||||||
|
} catch (IOException ex) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -38,27 +38,27 @@ import com.jme3.material.MaterialDef;
|
|||||||
import com.jme3.asset.AssetInfo;
|
import com.jme3.asset.AssetInfo;
|
||||||
import com.jme3.asset.AssetKey;
|
import com.jme3.asset.AssetKey;
|
||||||
import com.jme3.asset.AssetLoader;
|
import com.jme3.asset.AssetLoader;
|
||||||
|
import com.jme3.asset.AssetManager;
|
||||||
import com.jme3.asset.TextureKey;
|
import com.jme3.asset.TextureKey;
|
||||||
import com.jme3.material.RenderState.BlendMode;
|
import com.jme3.material.RenderState.BlendMode;
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.texture.Texture;
|
import com.jme3.texture.Texture;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
public class BitmapFontLoader implements AssetLoader {
|
public class BitmapFontLoader implements AssetLoader {
|
||||||
|
|
||||||
public Object load(AssetInfo info) throws IOException {
|
private BitmapFont load(AssetManager assetManager, String folder, InputStream in) throws IOException{
|
||||||
MaterialDef spriteMat =
|
MaterialDef spriteMat =
|
||||||
(MaterialDef) info.getManager().loadAsset(new AssetKey("Common/MatDefs/Misc/Unshaded.j3md"));
|
(MaterialDef) assetManager.loadAsset(new AssetKey("Common/MatDefs/Misc/Unshaded.j3md"));
|
||||||
|
|
||||||
BitmapCharacterSet charSet = new BitmapCharacterSet();
|
BitmapCharacterSet charSet = new BitmapCharacterSet();
|
||||||
Material[] matPages = null;
|
Material[] matPages = null;
|
||||||
BitmapFont font = new BitmapFont();
|
BitmapFont font = new BitmapFont();
|
||||||
|
|
||||||
String folder = info.getKey().getFolder();
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(info.openStream()));
|
|
||||||
String regex = "[\\s=]+";
|
String regex = "[\\s=]+";
|
||||||
|
|
||||||
font.setCharSet(charSet);
|
font.setCharSet(charSet);
|
||||||
@ -105,7 +105,7 @@ public class BitmapFontLoader implements AssetLoader {
|
|||||||
}
|
}
|
||||||
TextureKey key = new TextureKey(folder + file, true);
|
TextureKey key = new TextureKey(folder + file, true);
|
||||||
key.setGenerateMips(false);
|
key.setGenerateMips(false);
|
||||||
tex = info.getManager().loadTexture(key);
|
tex = assetManager.loadTexture(key);
|
||||||
tex.setMagFilter(Texture.MagFilter.Bilinear);
|
tex.setMagFilter(Texture.MagFilter.Bilinear);
|
||||||
tex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
|
tex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
|
||||||
}
|
}
|
||||||
@ -165,9 +165,20 @@ public class BitmapFontLoader implements AssetLoader {
|
|||||||
ch.addKerning(second, amount);
|
ch.addKerning(second, amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reader.close();
|
|
||||||
|
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object load(AssetInfo info) throws IOException {
|
||||||
|
InputStream in = null;
|
||||||
|
try {
|
||||||
|
in = info.openStream();
|
||||||
|
BitmapFont font = load(info.getManager(), info.getKey().getFolder(), in);
|
||||||
|
return font;
|
||||||
|
} finally {
|
||||||
|
if (in != null){
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -525,9 +525,10 @@ public class J3MLoader implements AssetLoader {
|
|||||||
key = info.getKey();
|
key = info.getKey();
|
||||||
loadFromRoot(BlockLanguageParser.parse(in));
|
loadFromRoot(BlockLanguageParser.parse(in));
|
||||||
} finally {
|
} finally {
|
||||||
if (in != null)
|
if (in != null){
|
||||||
in.close();
|
in.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (material != null){
|
if (material != null){
|
||||||
if (!(info.getKey() instanceof MaterialKey)){
|
if (!(info.getKey() instanceof MaterialKey)){
|
||||||
|
@ -254,16 +254,25 @@ public class MTLLoader implements AssetLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("empty-statement")
|
@SuppressWarnings("empty-statement")
|
||||||
public Object load(AssetInfo info){
|
public Object load(AssetInfo info) throws IOException{
|
||||||
|
reset();
|
||||||
|
|
||||||
this.assetManager = info.getManager();
|
this.assetManager = info.getManager();
|
||||||
folderName = info.getKey().getFolder();
|
folderName = info.getKey().getFolder();
|
||||||
|
matList = new MaterialList();
|
||||||
|
|
||||||
InputStream in = info.openStream();
|
InputStream in = null;
|
||||||
|
try {
|
||||||
|
in = info.openStream();
|
||||||
scan = new Scanner(in);
|
scan = new Scanner(in);
|
||||||
scan.useLocale(Locale.US);
|
scan.useLocale(Locale.US);
|
||||||
|
|
||||||
matList = new MaterialList();
|
|
||||||
while (readLine());
|
while (readLine());
|
||||||
|
} finally {
|
||||||
|
if (in != null){
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (matName != null){
|
if (matName != null){
|
||||||
// still have a material in the vars
|
// still have a material in the vars
|
||||||
@ -273,12 +282,8 @@ public class MTLLoader implements AssetLoader {
|
|||||||
|
|
||||||
MaterialList list = matList;
|
MaterialList list = matList;
|
||||||
|
|
||||||
reset();
|
|
||||||
|
|
||||||
try{
|
|
||||||
in.close();
|
|
||||||
}catch (IOException ex){
|
|
||||||
}
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -534,17 +534,12 @@ public final class OBJLoader implements AssetLoader {
|
|||||||
|
|
||||||
@SuppressWarnings("empty-statement")
|
@SuppressWarnings("empty-statement")
|
||||||
public Object load(AssetInfo info) throws IOException{
|
public Object load(AssetInfo info) throws IOException{
|
||||||
|
reset();
|
||||||
|
|
||||||
key = (ModelKey) info.getKey();
|
key = (ModelKey) info.getKey();
|
||||||
assetManager = info.getManager();
|
assetManager = info.getManager();
|
||||||
|
|
||||||
if (!(info.getKey() instanceof ModelKey))
|
|
||||||
throw new IllegalArgumentException("Model assets must be loaded using a ModelKey");
|
|
||||||
|
|
||||||
InputStream in = info.openStream();
|
|
||||||
scan = new Scanner(in);
|
|
||||||
scan.useLocale(Locale.US);
|
|
||||||
|
|
||||||
objName = key.getName();
|
objName = key.getName();
|
||||||
|
|
||||||
String folderName = key.getFolder();
|
String folderName = key.getFolder();
|
||||||
String ext = key.getExtension();
|
String ext = key.getExtension();
|
||||||
objName = objName.substring(0, objName.length() - ext.length() - 1);
|
objName = objName.substring(0, objName.length() - ext.length() - 1);
|
||||||
@ -554,7 +549,22 @@ public final class OBJLoader implements AssetLoader {
|
|||||||
|
|
||||||
objNode = new Node(objName + "-objnode");
|
objNode = new Node(objName + "-objnode");
|
||||||
|
|
||||||
|
if (!(info.getKey() instanceof ModelKey))
|
||||||
|
throw new IllegalArgumentException("Model assets must be loaded using a ModelKey");
|
||||||
|
|
||||||
|
InputStream in = null;
|
||||||
|
try {
|
||||||
|
in = info.openStream();
|
||||||
|
|
||||||
|
scan = new Scanner(in);
|
||||||
|
scan.useLocale(Locale.US);
|
||||||
|
|
||||||
while (readLine());
|
while (readLine());
|
||||||
|
} finally {
|
||||||
|
if (in != null){
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (matFaces.size() > 0){
|
if (matFaces.size() > 0){
|
||||||
for (Entry<String, ArrayList<Face>> entry : matFaces.entrySet()){
|
for (Entry<String, ArrayList<Face>> entry : matFaces.entrySet()){
|
||||||
@ -570,13 +580,6 @@ public final class OBJLoader implements AssetLoader {
|
|||||||
objNode.attachChild(geom);
|
objNode.attachChild(geom);
|
||||||
}
|
}
|
||||||
|
|
||||||
reset();
|
|
||||||
|
|
||||||
try{
|
|
||||||
in.close();
|
|
||||||
}catch (IOException ex){
|
|
||||||
}
|
|
||||||
|
|
||||||
if (objNode.getQuantity() == 1)
|
if (objNode.getQuantity() == 1)
|
||||||
// only 1 geometry, so no need to send node
|
// only 1 geometry, so no need to send node
|
||||||
return objNode.getChild(0);
|
return objNode.getChild(0);
|
||||||
|
@ -122,7 +122,9 @@ public class DDSLoader implements AssetLoader {
|
|||||||
throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");
|
throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");
|
||||||
}
|
}
|
||||||
|
|
||||||
InputStream stream = info.openStream();
|
InputStream stream = null;
|
||||||
|
try {
|
||||||
|
stream = info.openStream();
|
||||||
in = new LittleEndien(stream);
|
in = new LittleEndien(stream);
|
||||||
loadHeader();
|
loadHeader();
|
||||||
if (texture3D) {
|
if (texture3D) {
|
||||||
@ -131,8 +133,12 @@ public class DDSLoader implements AssetLoader {
|
|||||||
((TextureKey) info.getKey()).setTextureTypeHint(Type.CubeMap);
|
((TextureKey) info.getKey()).setTextureTypeHint(Type.CubeMap);
|
||||||
}
|
}
|
||||||
ArrayList<ByteBuffer> data = readData(((TextureKey) info.getKey()).isFlipY());
|
ArrayList<ByteBuffer> data = readData(((TextureKey) info.getKey()).isFlipY());
|
||||||
stream.close();
|
|
||||||
return new Image(pixelFormat, width, height, depth, data, sizes);
|
return new Image(pixelFormat, width, height, depth, data, sizes);
|
||||||
|
} finally {
|
||||||
|
if (stream != null){
|
||||||
|
stream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Image load(InputStream stream) throws IOException {
|
public Image load(InputStream stream) throws IOException {
|
||||||
|
@ -40,6 +40,7 @@ import com.jme3.texture.Image.Format;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class HDRLoader implements AssetLoader {
|
public class HDRLoader implements AssetLoader {
|
||||||
@ -58,7 +59,7 @@ public class HDRLoader implements AssetLoader {
|
|||||||
public HDRLoader(){
|
public HDRLoader(){
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void convertFloatToRGBE(byte[] rgbe, float red, float green, float blue){
|
public static void convertFloatToRGBE(byte[] rgbe, float red, float green, float blue){
|
||||||
double max = red;
|
double max = red;
|
||||||
if (green > max) max = green;
|
if (green > max) max = green;
|
||||||
if (blue > max) max = blue;
|
if (blue > max) max = blue;
|
||||||
@ -74,7 +75,7 @@ public class HDRLoader implements AssetLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void convertRGBEtoFloat(byte[] rgbe, float[] rgbf){
|
public static void convertRGBEtoFloat(byte[] rgbe, float[] rgbf){
|
||||||
int R = rgbe[0] & 0xFF,
|
int R = rgbe[0] & 0xFF,
|
||||||
G = rgbe[1] & 0xFF,
|
G = rgbe[1] & 0xFF,
|
||||||
B = rgbe[2] & 0xFF,
|
B = rgbe[2] & 0xFF,
|
||||||
@ -86,7 +87,7 @@ public class HDRLoader implements AssetLoader {
|
|||||||
rgbf[2] = B * e;
|
rgbf[2] = B * e;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void convertRGBEtoFloat2(byte[] rgbe, float[] rgbf){
|
public static void convertRGBEtoFloat2(byte[] rgbe, float[] rgbf){
|
||||||
int R = rgbe[0] & 0xFF,
|
int R = rgbe[0] & 0xFF,
|
||||||
G = rgbe[1] & 0xFF,
|
G = rgbe[1] & 0xFF,
|
||||||
B = rgbe[2] & 0xFF,
|
B = rgbe[2] & 0xFF,
|
||||||
@ -98,7 +99,7 @@ public class HDRLoader implements AssetLoader {
|
|||||||
rgbf[2] = (B / 256.0f) * e;
|
rgbf[2] = (B / 256.0f) * e;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final void convertRGBEtoFloat3(byte[] rgbe, float[] rgbf){
|
public static void convertRGBEtoFloat3(byte[] rgbe, float[] rgbf){
|
||||||
int R = rgbe[0] & 0xFF,
|
int R = rgbe[0] & 0xFF,
|
||||||
G = rgbe[1] & 0xFF,
|
G = rgbe[1] & 0xFF,
|
||||||
B = rgbe[2] & 0xFF,
|
B = rgbe[2] & 0xFF,
|
||||||
@ -126,7 +127,7 @@ public class HDRLoader implements AssetLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String readString(InputStream is) throws IOException{
|
private String readString(InputStream is) throws IOException{
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuilder sb = new StringBuilder();
|
||||||
while (true){
|
while (true){
|
||||||
int i = is.read();
|
int i = is.read();
|
||||||
if (i == 0x0a || i == -1) // new line or EOF
|
if (i == 0x0a || i == -1) // new line or EOF
|
||||||
@ -257,7 +258,7 @@ public class HDRLoader implements AssetLoader {
|
|||||||
// regular command
|
// regular command
|
||||||
int index = ln.indexOf("=");
|
int index = ln.indexOf("=");
|
||||||
if (index < 1){
|
if (index < 1){
|
||||||
logger.fine("Ignored string: "+ln);
|
logger.log(Level.FINE, "Ignored string: {0}", ln);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,7 +273,7 @@ public class HDRLoader implements AssetLoader {
|
|||||||
}else if (var.equals("gamma")){
|
}else if (var.equals("gamma")){
|
||||||
gamma = Float.parseFloat(value);
|
gamma = Float.parseFloat(value);
|
||||||
}else{
|
}else{
|
||||||
logger.warning("HDR Command ignored: "+ln);
|
logger.log(Level.WARNING, "HDR Command ignored: {0}", ln);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -314,10 +315,16 @@ public class HDRLoader implements AssetLoader {
|
|||||||
throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");
|
throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");
|
||||||
|
|
||||||
boolean flip = ((TextureKey) info.getKey()).isFlipY();
|
boolean flip = ((TextureKey) info.getKey()).isFlipY();
|
||||||
InputStream in = info.openStream();
|
InputStream in = null;
|
||||||
|
try {
|
||||||
|
in = info.openStream();
|
||||||
Image img = load(in, flip);
|
Image img = load(in, flip);
|
||||||
in.close();
|
|
||||||
return img;
|
return img;
|
||||||
|
} finally {
|
||||||
|
if (in != null){
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ package com.jme3.texture.plugins;
|
|||||||
|
|
||||||
import com.jme3.asset.AssetInfo;
|
import com.jme3.asset.AssetInfo;
|
||||||
import com.jme3.asset.AssetLoader;
|
import com.jme3.asset.AssetLoader;
|
||||||
import com.jme3.asset.AssetManager;
|
|
||||||
import com.jme3.asset.TextureKey;
|
import com.jme3.asset.TextureKey;
|
||||||
import com.jme3.texture.Image;
|
import com.jme3.texture.Image;
|
||||||
import com.jme3.texture.Image.Format;
|
import com.jme3.texture.Image.Format;
|
||||||
@ -50,7 +49,7 @@ public class PFMLoader implements AssetLoader {
|
|||||||
private static final Logger logger = Logger.getLogger(PFMLoader.class.getName());
|
private static final Logger logger = Logger.getLogger(PFMLoader.class.getName());
|
||||||
|
|
||||||
private String readString(InputStream is) throws IOException{
|
private String readString(InputStream is) throws IOException{
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuilder sb = new StringBuilder();
|
||||||
while (true){
|
while (true){
|
||||||
int i = is.read();
|
int i = is.read();
|
||||||
if (i == 0x0a || i == -1) // new line or EOF
|
if (i == 0x0a || i == -1) // new line or EOF
|
||||||
@ -74,11 +73,7 @@ public class PFMLoader implements AssetLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object load(AssetInfo info) throws IOException {
|
private Image load(InputStream in, boolean needYFlip) throws IOException{
|
||||||
if (!(info.getKey() instanceof TextureKey))
|
|
||||||
throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");
|
|
||||||
|
|
||||||
InputStream in = info.openStream();
|
|
||||||
Format format = null;
|
Format format = null;
|
||||||
|
|
||||||
String fmtStr = readString(in);
|
String fmtStr = readString(in);
|
||||||
@ -105,7 +100,6 @@ public class PFMLoader implements AssetLoader {
|
|||||||
float scale = Float.parseFloat(scaleStr);
|
float scale = Float.parseFloat(scaleStr);
|
||||||
ByteOrder order = scale < 0 ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN;
|
ByteOrder order = scale < 0 ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN;
|
||||||
boolean needEndienFlip = order != ByteOrder.nativeOrder();
|
boolean needEndienFlip = order != ByteOrder.nativeOrder();
|
||||||
boolean needYFlip = ((TextureKey)info.getKey()).isFlipY();
|
|
||||||
|
|
||||||
// make sure all unneccessary stuff gets deleted from heap
|
// make sure all unneccessary stuff gets deleted from heap
|
||||||
// before allocating large amount of memory
|
// before allocating large amount of memory
|
||||||
@ -139,4 +133,20 @@ public class PFMLoader implements AssetLoader {
|
|||||||
return new Image(format, width, height, imageData);
|
return new Image(format, width, height, imageData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object load(AssetInfo info) throws IOException {
|
||||||
|
if (!(info.getKey() instanceof TextureKey))
|
||||||
|
throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");
|
||||||
|
|
||||||
|
InputStream in = null;
|
||||||
|
try {
|
||||||
|
in = info.openStream();
|
||||||
|
return load(in, ((TextureKey)info.getKey()).isFlipY());
|
||||||
|
} finally {
|
||||||
|
if (in != null){
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -83,10 +83,16 @@ public final class TGALoader implements AssetLoader {
|
|||||||
throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");
|
throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey");
|
||||||
|
|
||||||
boolean flip = ((TextureKey)info.getKey()).isFlipY();
|
boolean flip = ((TextureKey)info.getKey()).isFlipY();
|
||||||
InputStream in = info.openStream();
|
InputStream in = null;
|
||||||
|
try {
|
||||||
|
in = info.openStream();
|
||||||
Image img = load(in, flip);
|
Image img = load(in, flip);
|
||||||
in.close();
|
|
||||||
return img;
|
return img;
|
||||||
|
} finally {
|
||||||
|
if (in != null){
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -199,6 +199,9 @@ public class DesktopAssetManager implements AssetManager {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public <T> T loadAsset(AssetKey<T> key){
|
public <T> T loadAsset(AssetKey<T> key){
|
||||||
|
if (key == null)
|
||||||
|
throw new IllegalArgumentException("key cannot be null");
|
||||||
|
|
||||||
if (eventListener != null)
|
if (eventListener != null)
|
||||||
eventListener.assetRequested(key);
|
eventListener.assetRequested(key);
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ import com.jme3.asset.AssetInfo;
|
|||||||
import com.jme3.audio.AudioBuffer;
|
import com.jme3.audio.AudioBuffer;
|
||||||
import com.jme3.audio.AudioStream;
|
import com.jme3.audio.AudioStream;
|
||||||
import com.jme3.asset.AssetLoader;
|
import com.jme3.asset.AssetLoader;
|
||||||
|
import com.jme3.audio.AudioData;
|
||||||
import com.jme3.audio.AudioKey;
|
import com.jme3.audio.AudioKey;
|
||||||
import com.jme3.util.BufferUtils;
|
import com.jme3.util.BufferUtils;
|
||||||
import de.jarnbjo.ogg.EndOfOggStreamException;
|
import de.jarnbjo.ogg.EndOfOggStreamException;
|
||||||
@ -197,16 +198,7 @@ public class OGGLoader implements AssetLoader {
|
|||||||
return new JOggInputStream(vorbisStream);
|
return new JOggInputStream(vorbisStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object load(AssetInfo info) throws IOException {
|
private AudioData load(InputStream in, boolean readStream, boolean streamCache) throws IOException{
|
||||||
if (!(info.getKey() instanceof AudioKey)){
|
|
||||||
throw new IllegalArgumentException("Audio assets must be loaded using an AudioKey");
|
|
||||||
}
|
|
||||||
|
|
||||||
AudioKey key = (AudioKey) info.getKey();
|
|
||||||
boolean readStream = key.isStream();
|
|
||||||
boolean streamCache = key.useStreamCache();
|
|
||||||
|
|
||||||
InputStream in = info.openStream();
|
|
||||||
if (readStream && streamCache){
|
if (readStream && streamCache){
|
||||||
oggStream = new CachedOggStream(in);
|
oggStream = new CachedOggStream(in);
|
||||||
}else{
|
}else{
|
||||||
@ -241,4 +233,25 @@ public class OGGLoader implements AssetLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object load(AssetInfo info) throws IOException {
|
||||||
|
if (!(info.getKey() instanceof AudioKey)){
|
||||||
|
throw new IllegalArgumentException("Audio assets must be loaded using an AudioKey");
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioKey key = (AudioKey) info.getKey();
|
||||||
|
boolean readStream = key.isStream();
|
||||||
|
boolean streamCache = key.useStreamCache();
|
||||||
|
|
||||||
|
InputStream in = null;
|
||||||
|
try {
|
||||||
|
in = info.openStream();
|
||||||
|
return load(in, readStream, streamCache);
|
||||||
|
} finally {
|
||||||
|
if (in != null){
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
package com.jme3.scene.plugins.ogre;
|
package com.jme3.scene.plugins.ogre;
|
||||||
|
|
||||||
import com.jme3.asset.AssetInfo;
|
import com.jme3.asset.AssetInfo;
|
||||||
|
import com.jme3.asset.AssetKey;
|
||||||
import com.jme3.asset.AssetLoader;
|
import com.jme3.asset.AssetLoader;
|
||||||
import com.jme3.asset.AssetManager;
|
import com.jme3.asset.AssetManager;
|
||||||
import com.jme3.asset.TextureKey;
|
import com.jme3.asset.TextureKey;
|
||||||
@ -56,7 +57,6 @@ import java.io.InputStream;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -426,20 +426,18 @@ public class MaterialLoader implements AssetLoader {
|
|||||||
return mat;
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object load(AssetInfo info) throws IOException {
|
private MaterialList load(AssetManager assetManager, AssetKey key, InputStream in) throws IOException{
|
||||||
folderName = info.getKey().getFolder();
|
folderName = key.getFolder();
|
||||||
assetManager = info.getManager();
|
this.assetManager = assetManager;
|
||||||
|
|
||||||
MaterialList list = null;
|
MaterialList list = null;
|
||||||
|
|
||||||
InputStream in = info.openStream();
|
|
||||||
List<Statement> statements = BlockLanguageParser.parse(in);
|
List<Statement> statements = BlockLanguageParser.parse(in);
|
||||||
|
|
||||||
for (Statement statement : statements){
|
for (Statement statement : statements){
|
||||||
if (statement.getLine().startsWith("import")){
|
if (statement.getLine().startsWith("import")){
|
||||||
MaterialExtensionSet matExts = null;
|
MaterialExtensionSet matExts = null;
|
||||||
if (info.getKey() instanceof OgreMaterialKey){
|
if (key instanceof OgreMaterialKey){
|
||||||
matExts = ((OgreMaterialKey)info.getKey()).getMaterialExtensionSet();
|
matExts = ((OgreMaterialKey)key).getMaterialExtensionSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matExts == null){
|
if (matExts == null){
|
||||||
@ -460,8 +458,18 @@ public class MaterialLoader implements AssetLoader {
|
|||||||
list.put(matName, mat);
|
list.put(matName, mat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object load(AssetInfo info) throws IOException {
|
||||||
|
InputStream in = null;
|
||||||
|
try {
|
||||||
|
in = info.openStream();
|
||||||
|
return load(info.getManager(), info.getKey(), in);
|
||||||
|
} finally {
|
||||||
|
if (in != null){
|
||||||
in.close();
|
in.close();
|
||||||
return list;
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ package com.jme3.scene.plugins.ogre;
|
|||||||
import com.jme3.animation.Animation;
|
import com.jme3.animation.Animation;
|
||||||
import com.jme3.scene.plugins.ogre.matext.OgreMaterialKey;
|
import com.jme3.scene.plugins.ogre.matext.OgreMaterialKey;
|
||||||
import com.jme3.animation.AnimControl;
|
import com.jme3.animation.AnimControl;
|
||||||
import com.jme3.animation.BoneAnimation;
|
|
||||||
import com.jme3.animation.SkeletonControl;
|
import com.jme3.animation.SkeletonControl;
|
||||||
import com.jme3.asset.AssetInfo;
|
import com.jme3.asset.AssetInfo;
|
||||||
import com.jme3.asset.AssetKey;
|
import com.jme3.asset.AssetKey;
|
||||||
@ -53,7 +52,6 @@ import com.jme3.scene.VertexBuffer;
|
|||||||
import com.jme3.scene.VertexBuffer.Format;
|
import com.jme3.scene.VertexBuffer.Format;
|
||||||
import com.jme3.scene.VertexBuffer.Type;
|
import com.jme3.scene.VertexBuffer.Type;
|
||||||
import com.jme3.scene.VertexBuffer.Usage;
|
import com.jme3.scene.VertexBuffer.Usage;
|
||||||
import com.jme3.system.JmeSystem;
|
|
||||||
import com.jme3.util.BufferUtils;
|
import com.jme3.util.BufferUtils;
|
||||||
import com.jme3.util.IntMap;
|
import com.jme3.util.IntMap;
|
||||||
import com.jme3.util.IntMap.Entry;
|
import com.jme3.util.IntMap.Entry;
|
||||||
@ -78,7 +76,6 @@ import org.xml.sax.InputSource;
|
|||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import org.xml.sax.XMLReader;
|
import org.xml.sax.XMLReader;
|
||||||
import org.xml.sax.helpers.DefaultHandler;
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
import org.xml.sax.helpers.XMLReaderFactory;
|
|
||||||
|
|
||||||
import static com.jme3.util.xml.SAXUtil.*;
|
import static com.jme3.util.xml.SAXUtil.*;
|
||||||
|
|
||||||
@ -813,13 +810,20 @@ public class MeshLoader extends DefaultHandler implements AssetLoader {
|
|||||||
// checking with JmeSystem.
|
// checking with JmeSystem.
|
||||||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||||
factory.setNamespaceAware(true);
|
factory.setNamespaceAware(true);
|
||||||
XMLReader xr = factory.newSAXParser().getXMLReader();
|
|
||||||
|
|
||||||
|
XMLReader xr = factory.newSAXParser().getXMLReader();
|
||||||
xr.setContentHandler(this);
|
xr.setContentHandler(this);
|
||||||
xr.setErrorHandler(this);
|
xr.setErrorHandler(this);
|
||||||
InputStreamReader r = new InputStreamReader(info.openStream());
|
|
||||||
|
InputStreamReader r = null;
|
||||||
|
try {
|
||||||
|
r = new InputStreamReader(info.openStream());
|
||||||
xr.parse(new InputSource(r));
|
xr.parse(new InputSource(r));
|
||||||
|
} finally {
|
||||||
|
if (r != null){
|
||||||
r.close();
|
r.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return compileModel();
|
return compileModel();
|
||||||
} catch (SAXException ex) {
|
} catch (SAXException ex) {
|
||||||
|
@ -380,9 +380,18 @@ public class SceneLoader extends DefaultHandler implements AssetLoader {
|
|||||||
|
|
||||||
xr.setContentHandler(this);
|
xr.setContentHandler(this);
|
||||||
xr.setErrorHandler(this);
|
xr.setErrorHandler(this);
|
||||||
InputStreamReader r = new InputStreamReader(info.openStream());
|
|
||||||
|
InputStreamReader r = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
r = new InputStreamReader(info.openStream());
|
||||||
xr.parse(new InputSource(r));
|
xr.parse(new InputSource(r));
|
||||||
|
} finally {
|
||||||
|
if (r != null){
|
||||||
r.close();
|
r.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}catch (SAXException ex){
|
}catch (SAXException ex){
|
||||||
IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
|
IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
|
||||||
|
@ -296,9 +296,14 @@ public class SkeletonLoader extends DefaultHandler implements AssetLoader {
|
|||||||
|
|
||||||
public Object load(AssetInfo info) throws IOException {
|
public Object load(AssetInfo info) throws IOException {
|
||||||
assetManager = info.getManager();
|
assetManager = info.getManager();
|
||||||
InputStream in = info.openStream();
|
InputStream in = null;
|
||||||
Object obj = load(in);
|
try {
|
||||||
|
in = info.openStream();
|
||||||
|
return load(in);
|
||||||
|
} finally {
|
||||||
|
if (in != null){
|
||||||
in.close();
|
in.close();
|
||||||
return obj;
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user