public void checkTimesConsistantcy() { if ((translations != null && times.length != translations.length) || (rotations != null && times.length != rotations.length) || (scales != null && times.length != scales.length)) { throw new AssetLoadException("Inconsistent animation sampling "); } }
new Object[]{name, ex.toString()});
new Object[]{name, ex.toString()});
public static void assertNotNull(Object o, String errorMessage) { if (o == null) { throw new AssetLoadException(errorMessage); } }
public static VertexBuffer.Format getVertexBufferFormat(int componentType) { switch (componentType) { case 5120: return VertexBuffer.Format.Byte; case 5121: return VertexBuffer.Format.UnsignedByte; case 5122: return VertexBuffer.Format.Short; case 5123: return VertexBuffer.Format.UnsignedShort; case 5125: return VertexBuffer.Format.UnsignedInt; case 5126: return VertexBuffer.Format.Float; default: throw new AssetLoadException("Illegal component type: " + componentType); } }
public static int getNumberOfComponents(String type) { switch (type) { case "SCALAR": return 1; case "VEC2": return 2; case "VEC3": return 3; case "VEC4": return 4; case "MAT2": return 4; case "MAT3": return 9; case "MAT4": return 16; default: throw new AssetLoadException("Illegal type: " + type); } }
public InputStream openStream(){ try{ return zipfile.getInputStream(entry); }catch (IOException ex){ throw new AssetLoadException("Failed to load zip entry: "+entry, ex); } } }
@Override public InputStream openStream() { try{ return new FileInputStream(file); }catch (FileNotFoundException ex){ // NOTE: Can still happen even if file.exists() is true, e.g. // permissions issue and similar throw new AssetLoadException("Failed to open file: " + file, ex); } } }
private VarType getVarType(Object value) { if (value instanceof Float) return VarType.Float; if (value instanceof Integer) return VarType.Int; if (value instanceof Boolean) return VarType.Boolean; if (value instanceof ColorRGBA) return VarType.Vector4; if (value instanceof Vector4f) return VarType.Vector4; if (value instanceof Vector3f) return VarType.Vector3; if (value instanceof Vector2f) return VarType.Vector2; if (value instanceof Matrix3f) return VarType.Matrix3; if (value instanceof Matrix4f) return VarType.Matrix4; if (value instanceof String) return VarType.Boolean; throw new AssetLoadException("Unsupported material parameter type : " + value.getClass().getSimpleName()); } }
public void setRootPath(String rootPath) { try{ zipfile = new ZipFile(new File(rootPath), ZipFile.OPEN_READ); }catch (IOException ex){ throw new AssetLoadException("Failed to open zip file: " + rootPath, ex); } }
public void setRootPath(String rootPath) { if (rootPath == null) throw new NullPointerException(); try { root = new File(rootPath).getCanonicalFile(); if (!root.isDirectory()){ throw new IllegalArgumentException("Given root path \"" + root + "\" is not a directory"); } } catch (IOException ex) { throw new AssetLoadException("Root path is invalid", ex); } }
@Override public InputStream openStream() { if (in != null){ // Reuse the already existing stream (only once) InputStream in2 = in; in = null; return in2; }else{ // Create a new stream for subsequent invocations. try { URLConnection conn = url.openConnection(); conn.setUseCaches(false); return conn.getInputStream(); } catch (IOException ex) { throw new AssetLoadException("Failed to read URL " + url, ex); } } } }
private void readShaderDefinition(Shader.ShaderType shaderType, String name, String... languages) { shaderNames.put(shaderType, name); if (langSize != 0 && langSize != languages.length) { throw new AssetLoadException("Technique " + technique.getName() + " must have the same number of languages for each shader type."); } langSize = languages.length; for (int i = 0; i < languages.length; i++) { if (i >= shaderLanguages.size()) { shaderLanguages.add(new EnumMap<Shader.ShaderType, String>(Shader.ShaderType.class)); } shaderLanguages.get(i).put(shaderType, languages[i]); } }
@Override public InputStream openStream() { if (in != null){ // Reuse the already existing stream (only once) InputStream in2 = in; in = null; return in2; }else{ // Create a new stream for subsequent invocations. android.content.res.Resources androidResources = JmeAndroidSystem.getView().getContext().getResources(); if (resourceId == 0) { try { return androidResources.getAssets().open(assetPath); } catch (IOException ex) { throw new AssetLoadException("Failed to open asset " + assetPath, ex); } } else { try { return androidResources.openRawResource(resourceId); } catch (Resources.NotFoundException ex) { throw new AssetLoadException("Failed to open asset " + assetPath, ex); } } } }
public AssetFileDescriptor openFileDescriptor() { android.content.res.Resources androidResources = JmeAndroidSystem.getView().getContext().getResources(); if (resourceId == 0) { try { return androidResources.getAssets().openFd(assetPath); } catch (IOException ex) { throw new AssetLoadException("Failed to open asset " + assetPath, ex); } } else { try { return androidResources.openRawResourceFd(resourceId); } catch (Resources.NotFoundException ex) { throw new AssetLoadException("Failed to open asset " + assetPath, ex); } } } }
private <T> T readExtras(String name, JsonElement el, T input) throws AssetLoadException { if (key == null) { return input; } ExtrasLoader loader; loader = key.getExtrasLoader(); if (loader == null) { return input; } JsonElement extras = el.getAsJsonObject().getAsJsonObject("extras"); if (extras == null) { return input; } try { return (T) loader.handleExtras(gltfLoader, name, el, extras, input); } catch (ClassCastException e) { throw new AssetLoadException("Extra loader " + loader.getClass().getName() + " for " + name + " is incompatible with type " + input.getClass(), e); } }
private <T> T readExtension(String name, JsonElement el, T input) throws AssetLoadException, IOException { JsonElement extensions = el.getAsJsonObject().getAsJsonObject("extensions"); if (extensions == null) { return input; } for (Map.Entry<String, JsonElement> ext : extensions.getAsJsonObject().entrySet()) { ExtensionLoader loader = null; if (key != null) { loader = key.getExtensionLoader(ext.getKey()); } if (loader == null) { loader = defaultExtensionLoaders.get(ext.getKey()); } if (loader == null) { logger.log(Level.WARNING, "Could not find loader for extension " + ext.getKey()); continue; } try { return (T) loader.handleExtension(gltfLoader, name, el, ext.getValue(), input); } catch (ClassCastException e) { throw new AssetLoadException("Extension loader " + loader.getClass().getName() + " for extension " + ext.getKey() + " is incompatible with type " + input.getClass(), e); } } return input; }
@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(); } }
public AssetInfo locate(AssetManager manager, AssetKey key) { String name = key.getName(); File file = new File(root, name); if (file.exists() && file.isFile()){ try { // Now, check asset name requirements String canonical = file.getCanonicalPath(); String absolute = file.getAbsolutePath(); if (!canonical.endsWith(absolute)){ throw new AssetNotFoundException("Asset name doesn't match requirements.\n"+ "\"" + canonical + "\" doesn't match \"" + absolute + "\""); } } catch (IOException ex) { throw new AssetLoadException("Failed to get file canonical path " + file, ex); } return new AssetInfoFile(manager, key, file); }else{ return null; } }
protected byte[] getBytes(int bufferIndex, String uri, Integer bufferLength) throws IOException { byte[] data; if (uri != null) { if (uri.startsWith("data:")) { //base 64 embed data data = DatatypeConverter.parseBase64Binary(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."); } BinDataKey key = new BinDataKey(info.getKey().getFolder() + uri); InputStream input = (InputStream) info.getManager().loadAsset(key); data = new byte[bufferLength]; DataInputStream dataStream = new DataInputStream(input); dataStream.readFully(data); dataStream.close(); } } else { //no URI this should not happen in a gltf file, only in glb files. throw new AssetLoadException("Buffer " + bufferIndex + " has no uri"); } return data; }