diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java index 8bd0a022b1..ac1faba8a2 100644 --- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java @@ -48,6 +48,7 @@ import com.jme3.util.IntMap; import com.jme3.util.mikktspace.MikktspaceTangentGenerator; import java.io.*; +import java.net.URLDecoder; import java.nio.Buffer; import java.nio.FloatBuffer; import java.util.*; @@ -589,11 +590,12 @@ protected byte[] getBytes(int bufferIndex, String uri, Integer bufferLength) thr data = Base64.getDecoder().decode(uri.substring(uri.indexOf(",") + 1)); } else { //external file let's load it - if (!uri.endsWith(".bin")) { - throw new AssetLoadException("Cannot load " + uri + ", a .bin extension is required."); + String decoded = decodeUri(uri); + if (!decoded.endsWith(".bin")) { + throw new AssetLoadException("Cannot load " + decoded + ", a .bin extension is required."); } - BinDataKey key = new BinDataKey(info.getKey().getFolder() + uri); + BinDataKey key = new BinDataKey(info.getKey().getFolder() + decoded); InputStream input = (InputStream) info.getManager().loadAsset(key); data = new byte[bufferLength]; DataInputStream dataStream = new DataInputStream(input); @@ -764,7 +766,8 @@ public Texture2D readImage(int sourceIndex, boolean flip) throws IOException { result = (Texture2D) info.getManager().loadAssetFromStream(key, new ByteArrayInputStream(data)); } else { //external file image - TextureKey key = new TextureKey(info.getKey().getFolder() + uri, flip); + String decoded = decodeUri(uri); + TextureKey key = new TextureKey(info.getKey().getFolder() + decoded, flip); Texture tex = info.getManager().loadTexture(key); result = (Texture2D) tex; } @@ -1186,6 +1189,14 @@ public Node getRootNode() { return rootNode; } + private String decodeUri(String uri) { + try { + return URLDecoder.decode(uri, "UTF-8"); + } catch (UnsupportedEncodingException e) { + return uri; //This would mean that UTF-8 is unsupported on the platform. + } + } + public static class WeightData { float value; short index; @@ -1417,4 +1428,3 @@ public SkinBuffers populate(Integer bufferViewIndex, int componentType, String t } } -