From 004afd4ae6e177ace4c896d0628de39ae5ab8eb7 Mon Sep 17 00:00:00 2001 From: Trevor Flynn Date: Sat, 29 Aug 2020 12:37:50 -0800 Subject: [PATCH 1/5] GltfLoader now decodes uri for files --- .../jme3/scene/plugins/gltf/GltfLoader.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) 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..624ccf4a0f 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,8 +48,11 @@ import com.jme3.util.IntMap; import com.jme3.util.mikktspace.MikktspaceTangentGenerator; import java.io.*; +import java.net.URI; +import java.net.URLDecoder; import java.nio.Buffer; import java.nio.FloatBuffer; +import java.nio.file.Paths; import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -589,11 +592,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 +768,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 +1191,14 @@ public Node getRootNode() { return rootNode; } + private String decodeUri(String uri) { + try { + return URLDecoder.decode(uri.replace("+", "%2B"), "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; From 25b31cbd834db74877d0721351a65a450a274eaa Mon Sep 17 00:00:00 2001 From: Trevor Flynn Date: Sat, 29 Aug 2020 13:46:44 -0800 Subject: [PATCH 2/5] Remove leftover imports --- .../gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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 624ccf4a0f..937e4132ca 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,11 +48,9 @@ import com.jme3.util.IntMap; import com.jme3.util.mikktspace.MikktspaceTangentGenerator; import java.io.*; -import java.net.URI; import java.net.URLDecoder; import java.nio.Buffer; import java.nio.FloatBuffer; -import java.nio.file.Paths; import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -439,7 +437,7 @@ public Geometry[] readMeshPrimitives(int meshIndex) throws IOException { targetNames.add(target.getAsString()); } } - + //Read morph targets JsonArray targets = meshObject.getAsJsonArray("targets"); if(targets != null){ @@ -459,7 +457,7 @@ public Geometry[] readMeshPrimitives(int meshIndex) throws IOException { mesh.addMorphTarget(morphTarget); } } - + //Read mesh extras mesh = customContentManager.readExtensionAndExtras("primitive", meshObject, mesh); @@ -1131,7 +1129,7 @@ private void setupControls() { // skinData.rootBoneTransformOffset.combineWithParent(skinData.parent.getWorldTransform()); // } // } - + if (skinData.animComposer != null && skinData.animComposer.getSpatial() == null) { spatial.addControl(skinData.animComposer); } From 95d6c5730d4b378313b800332ad9ffcb98ba31b0 Mon Sep 17 00:00:00 2001 From: Trevor Flynn Date: Sat, 29 Aug 2020 13:49:51 -0800 Subject: [PATCH 3/5] Fix IDEA auto formatting --- .../src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java | 1 - 1 file changed, 1 deletion(-) 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 937e4132ca..e52cc30b34 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 @@ -1428,4 +1428,3 @@ public SkinBuffers populate(Integer bufferViewIndex, int componentType, String t } } - From db530f8ae85e5f5d12fb85aa3e382cb72e182fd2 Mon Sep 17 00:00:00 2001 From: Trevor Flynn Date: Sat, 29 Aug 2020 13:52:35 -0800 Subject: [PATCH 4/5] Fix IDEA auto formatting again... --- .../gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 e52cc30b34..142d30cde9 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 @@ -437,7 +437,7 @@ public Geometry[] readMeshPrimitives(int meshIndex) throws IOException { targetNames.add(target.getAsString()); } } - + //Read morph targets JsonArray targets = meshObject.getAsJsonArray("targets"); if(targets != null){ @@ -457,7 +457,7 @@ public Geometry[] readMeshPrimitives(int meshIndex) throws IOException { mesh.addMorphTarget(morphTarget); } } - + //Read mesh extras mesh = customContentManager.readExtensionAndExtras("primitive", meshObject, mesh); @@ -1129,7 +1129,7 @@ private void setupControls() { // skinData.rootBoneTransformOffset.combineWithParent(skinData.parent.getWorldTransform()); // } // } - + if (skinData.animComposer != null && skinData.animComposer.getSpatial() == null) { spatial.addControl(skinData.animComposer); } From 1832daa54ee86510aaf37ec3ebe19204ae15c130 Mon Sep 17 00:00:00 2001 From: Trevor Flynn Date: Sat, 29 Aug 2020 14:44:23 -0800 Subject: [PATCH 5/5] Remove + escapeing --- .../src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 142d30cde9..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 @@ -1191,7 +1191,7 @@ public Node getRootNode() { private String decodeUri(String uri) { try { - return URLDecoder.decode(uri.replace("+", "%2B"), "UTF-8"); + return URLDecoder.decode(uri, "UTF-8"); } catch (UnsupportedEncodingException e) { return uri; //This would mean that UTF-8 is unsupported on the platform. }