Răsfoiți Sursa

glTF: prevent direct loading of .bin files.

Nehon 8 ani în urmă
părinte
comite
21fbaf8f11

+ 12 - 0
jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/BinDataKey.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);
+    }
+}

+ 6 - 2
jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/BinLoader.java

@@ -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();
     }
 }

+ 2 - 1
jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java

@@ -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);
             }