-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
importing a .glb file fails if only local path is provided and not served through HTTP #165
Comments
Thanks @f4z3k4s for logging this issue, and thanks for the details about the workaround you found. This will be helpful in solving this issue. @CoPrez do we have another issue tracking local file load problems? If so, maybe we can combine the two, and if not, will you add details from your recent investigation to this issue? |
Thanks for the shout-out @ryantrem. I hadn't logged an issue for my prior investigations because it was actually an issue with how React-Native bundles assets from outside the project folder. Loading the files into Babylon was working as I expected. @f4z3k4s would you mind sharing a snippet of code on how you would expect the ImportMesh call to work inside the package? Are you talking about loading local assets like you would for an image? Like this: SceneLoader.ImportMeshAsync(
'',
require('/assets/3d/tesla-high.glb`),
'',
scene
); We don't currently support loading local assets by just using the |
Thanks for the quick response guys. I was thinking of something similar that you pasted. I just realised that So your proposal seems React-Native-y in my opinion, as it is really similar to how Inside the package you could handle this in several ways, the simplest being |
This enhancement would be great to have since having to install Edit:
|
@ninjz It seems from the uri you're doing it on iOS. As my project's scope covers only Android for now, I haven't tested the solution on iOS. You can try the below method just to check if it's working: import { Image } from 'react-native';
// rootUrl being something like /assets/your-asset.glb
const uri = Image.resolveAssetSource(rootUrl).uri;
SceneLoader.ImportMeshAsync(
'',
require(uri),
'',
scene
); |
@f4z3k4s Sorry for the delay. I just tested this on iOS and figured out how to get it working with the help of your method as a starting point. This is how I got this working on iOS: import { Image } from 'react-native';
// rootUrl being something like /assets/your-asset.glb
const file = require(rootUrl);
const uri = Image.resolveAssetSource(file).uri;
SceneLoader.ImportMeshAsync(
'',
uri,
'',
scene
); |
@ninjz Awesome, glad you could make it work. :) |
@ninjz this not work on android & ios release builds. |
Yeah shoot, I ran into this while testing and forgot to mention this as I haven't been working with the lib recently. Would love to know how others have overcome this issue. I believe the uri is still referencing the local file system causing the file to not be found. |
@f4z3k4s I just tried using Been trying all sort of things to get this working in release mode. Has there really been no one here that has gotten this running in release mode on iOS with a local file successfully? Edit: This is the local URI that is being outputted: |
@ninjz sorry I have no experience on iOS with this yet but the app I am working on has to support iOS shortly (couple weeks) so I will be urged to figure this out. I will share my findings if I'll have any and it will be relevant at that time. FYI, on Android, the project is bare RN app. For the first glance, your URI seems correct. |
For anyone else who might look at this issue in the future, see additional discussion here: https://forum.babylonjs.com/t/how-to-import-a-local-glb-file-in-babylonreactnative/18212 |
@ninjz I can confirm it is working on iOS in release mode as well with the above stated To summarise: I can confirm that the above stated |
Latest thoughts on this issue can be found here in the forum: https://forum.babylonjs.com/t/load-local-stl-file-from-assets-in-react-native/26245/8?u=ryantrem Here is a copy/paste of the relevant part: Another option yet would be to rely on the React Native method of embedding asset files in the app via import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';
const stlUri = resolveAssetSource(require('./SomeModel.stl')).uri;
SceneLoader.ImportMeshAsync('', stlUri); Whether you use expo-asset or the React Native libs directly, you will need to tell the metro bundler to bundle const defaultAssetExts = require("metro-config/src/defaults/defaults").assetExts;
...
module.exports = {
...
assetExts: [...defaultAssetExts, 'stl'],
}; It would be great if someone could validate these steps and document them here: BabylonReactNative/README.md at master · BabylonJS/BabylonReactNative (github.com) EDIT: As @f4z3k4s mentions, the above will have issues on Android in release builds. We probably need to dig deeper for this, and @f4z3k4s comment above is probably a good place to start: #165 (comment). |
@ryantrem Please note that |
Thanks @f4z3k4s, I forgot you called this out already earlier in this thread. I will update my comment above to include this extra info. |
For now, let's just document this for now. We will figure out how to do this properly later. |
From tests I did:
But I'm running into an issue with .json. require returns the loaded object and I can't get the uri back from it using Is there a way to actually get the URL from a JSON or should we put extra care in any loading method that needs to URL to a json to also accept a string? Instead of
|
Another solution with react-native-asset : https://forum.babylonjs.com/t/load-local-app-gltf-glb-mesh-in-babylon-react-native/30888/23 |
An example with react-native-fs here https://forum.babylonjs.com/t/using-webxrimagetracking-in-a-bundled-react-native-app/40337/17 |
Hi!
First of all, thanks for the great work for all maintainers.
I've just started using this library in my project for rendering
.glb
files.When the
.glb
file is served from a local static server,SceneLoader.ImportMeshAsync
and other similar methods used for importing assets, such asAppend
,AppendAsync
, etc.. work perfectly. However, when the file is not requested over HTTP, but rather the local path is provided to the above stated methods, the app just crashes without any easily traceable error (I wasn't looking so hard for the error, but it didn't appear in the terminal of the packager). Maybe it's my uneducatedness but from the documentation available here, I expected the import to work with just a local path.I was able to solve the issue by using
expo-asset
to load the.glb
file instead and provide a local uri, and then passing that local uri to Babylon, described in the below way:However, I'd expect the library to do something similar internally, making the user to be able to only provide a path to a local
.glb
file and it load it without issues. If this work is purposefully left for the user, it would be nice to have it stated in the main documentation, since I think it's quite a common use-case.The text was updated successfully, but these errors were encountered: