glTF: prevent direct loading of .bin files.

fix-456
Nehon 7 years ago
parent d606c30a52
commit 21fbaf8f11
  1. 12
      jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/BinDataKey.java
  2. 8
      jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/BinLoader.java
  3. 3
      jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java

@ -0,0 +1,12 @@
package com.jme3.scene.plugins.gltf;
import com.jme3.asset.AssetKey;
/**
* Created by Nehon on 09/09/2017.
*/
class BinDataKey extends AssetKey<Object> {
public BinDataKey(String name) {
super(name);
}
}

@ -1,7 +1,6 @@
package com.jme3.scene.plugins.gltf;
import com.jme3.asset.AssetInfo;
import com.jme3.asset.AssetLoader;
import com.jme3.asset.*;
import java.io.IOException;
@ -11,6 +10,11 @@ import java.io.IOException;
public class BinLoader implements AssetLoader {
@Override
public Object load(AssetInfo assetInfo) throws IOException {
if (!(assetInfo.getKey() instanceof BinDataKey)) {
throw new AssetLoadException(".bin files cannot be loaded directly, load the associated .gltf file");
}
return assetInfo.openStream();
}
}

@ -499,7 +499,8 @@ public class GltfLoader implements AssetLoader {
throw new AssetLoadException("Cannot load " + uri + ", a .bin extension is required.");
}
InputStream input = (InputStream) info.getManager().loadAsset(info.getKey().getFolder() + uri);
BinDataKey key = new BinDataKey(info.getKey().getFolder() + uri);
InputStream input = (InputStream) info.getManager().loadAsset(key);
data = new byte[bufferLength];
input.read(data);
}

Loading…
Cancel
Save