im working on a specific use case where i need to load files from the iOS documents directory. in UrlRequest_Apple.mm its only implemented loading from the app bundle.
i started writing an implementation for loading from the documents directory using the documents:/// scheme but i think this implementation is a bit short sighted as there are also other directories that people might want to load from - NSDocumentDirectory, NSTemporaryDirectory, NSCachesDirectory, NSApplicationSupportDirectory
perhaps all these directory paths can be returned during initialization (as they don’t change during the app session) and then people can append their file path to the end. otherwise we can go with different schemes for each (documents:///temporary:/// etc). just wanted to put it out for discussion before putting a PR together.
I think that would be a nice feature that other users could benefit from. I’m pinging @bghgary so we can see if it makes sense as a Babylon Native feature.
This kind of file scheme is not portable. It might work well for iOS but at this level, it needs to work for all platforms. Is the final path an absolute path? If so, you should be able to use the file:/// scheme to do it.
hi @bghgary, the thing about iOS and OSX is that a user won’t know what the full file:/// path should be unless it queries the system.
for example this is a path to a gltf in the documents folder: /var/mobile/Containers/Data/Application/A1D2BB71-A60C-476E-A788-E47667A587B8/Documents/animation.gltf - the UUID in the path is set every time the app is installed.
the javascript code would need to query the iOS/OSX system to get the root of the documents folder and then append to it, to construct the full file path.
as far as i can see, this can be solved by providing some utility classes on the babylon javascript end which allows to query the system for these paths. or using the current schema approach and specifying app:/// or documents:/// etc.
another thing to consider is that these path options are different on Android, ie, Android has options for private and public document folders, so there’s more nuance across different platforms. so a utility class for getting the base paths should be very generic, something like getPathTo("documents") - passing a string key and under the hood there would be a platform specific implementation.
I can see some usefulness in providing functionality for this, but it will have to be platform specific. Windows also has its own set of known folders. I don’t know if Linux has something like this. Maybe you can contribute a plugin if you’re inclined.
For a short-term fix, maybe expose utility functions to JS via Node-API in your application so that you don’t have to worry about platforms you don’t care about?
hey @bghgary, yeah sure i’ll give it a crack.
can you point me to where something similar is done in BabylonNative, so i can use that as a guide for how i structure the code.