expo-three: loadAsync not working with FBX [Android]
Hello! I’m trying to render a FBX file on Android but am running into an error. It renders an OBJ file fine on Android and the OBJ and FBX fine on iOS. I think the issue is related to #85 and #93 . Same issue as here. Is there any workaround? I’ve copied the offending error message below. Thanks.
Edit: I traced the issue to line 85 of loadModelsAsync.js, this promise always gets rejected on Android
return new Promise((res, rej) => loader.load(uri, res, onProgress, rej));
Edit 2: I’ve spent a few hours on this with no luck. GLView does not work with remote debugging which makes this especially difficult. Any suggestions appreciated.
NOTE: This works fine in IOS only having issue with Android.
Object {
"bubbles": false,
"cancelable": false,
"currentTarget": XMLHttpRequest {
"DONE": 4,
"HEADERS_RECEIVED": 2,
"LOADING": 3,
"OPENED": 1,
"UNSENT": 0,
"_aborted": false,
"_cachedResponse": undefined,
"_hasError": true,
"_headers": Object {},
"_incrementalEvents": true,
"_lowerCaseResponseHeaders": Object {},
"_method": "GET",
"_requestId": null,
"_response": "",
"_responseType": "arraybuffer",
"_sent": true,
"_subscriptions": Array [],
"_timedOut": false,
"_trackingName": "unknown",
"_url": "file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540anonymous%252Fthreedemo-3D-expo-2992d51a-3466-48b9-bd1f-6e46e749520c/ExponentAsset-9a80489e046f0d3e164a6f0955a8df98.fbx",
"readyState": 4,
"responseHeaders": undefined,
"status": 0,
"timeout": 0,
"upload": XMLHttpRequestEventTarget {
Symbol(listeners): Object {},
},
"withCredentials": true,
Symbol(listeners): Object {
"abort": Object {
"kind": 2,
"listener": [Function anonymous],
"next": null,
},
"error": Object {
"kind": 2,
"listener": [Function anonymous],
"next": null,
},
"load": Object {
"kind": 2,
"listener": [Function anonymous],
"next": null,
},
"progress": Object {
"kind": 2,
"listener": [Function anonymous],
"next": null,
},
},
},
"eventPhase": 2,
"isTrusted": false,
"target": XMLHttpRequest {
"DONE": 4,
"HEADERS_RECEIVED": 2,
"LOADING": 3,
"OPENED": 1,
"UNSENT": 0,
"_aborted": false,
"_cachedResponse": undefined,
"_hasError": true,
"_headers": Object {},
"_incrementalEvents": true,
"_lowerCaseResponseHeaders": Object {},
"_method": "GET",
"_requestId": null,
"_response": "",
"_responseType": "arraybuffer",
"_sent": true,
"_subscriptions": Array [],
"_timedOut": false,
"_trackingName": "unknown",
"_url": "file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540anonymous%252Fthreedemo-3D-expo-2992d51a-3466-48b9-bd1f-6e46e749520c/ExponentAsset-9a80489e046f0d3e164a6f0955a8df98.fbx",
"readyState": 4,
"responseHeaders": undefined,
"status": 0,
"timeout": 0,
"upload": XMLHttpRequestEventTarget {
Symbol(listeners): Object {},
},
"withCredentials": true,
Symbol(listeners): Object {
"abort": Object {
"kind": 2,
"listener": [Function anonymous],
"next": null,
},
"error": Object {
"kind": 2,
"listener": [Function anonymous],
"next": null,
},
"load": Object {
"kind": 2,
"listener": [Function anonymous],
"next": null,
},
"progress": Object {
"kind": 2,
"listener": [Function anonymous],
"next": null,
},
},
},
"timeStamp": 1575344131854,
"type": "error",
Symbol(stop_immediate_propagation_flag): false,
Symbol(canceled_flag): false,
Symbol(original_event): Object {
"type": "error",
},
}
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 17 (1 by maintainers)
After going through so many googling & github issues or even three.js forum (from 0 exp in 3d rendering few weeks back until today), I’m finally able to load these 3 types of models:
OBJ,FBX,GLTF - (.glb)in release mode for both android & ios using RN standalone app (barebone RN app with react-native-unimodules installed)To learn three.js, I created https://github.com/kyaroru/ShibaThree & https://github.com/kyaroru/ReactShibaThree and finally trying out on mobile app using
expo-three, but I face so many issues and seems to be unresolvable at first.Not until today! Argh! So I’m going to share my findings for the newbies out there who are just like me (this might not be an official solution but it just works)
My
package.jsondependencies:Using
expo-three, I tried few different ways to load models:eg. import
OBJLoaderorFBXLoaderorGLTFLoaderdirectly fromthreeAnd load using
The above works fine on iOS (even in release mode) but not on android release mode (the APK). Android will always get this issue https://github.com/expo/expo-three/issues/182
Then I tried with
loadObjAsync(), it works on Android release mode finally!But
.pngtextures was not loading properly, only.mtlworking if I try:Then, I tried to look for texture issues & I found this => https://github.com/expo/expo-three/issues/185#issuecomment-732161813 (What he explained just strike me in the head… hmmm)
So I renamed all my textures image file extension to prefix with ‘x’, and it became :
xpng,xjpeg,xjpg- thus it will bundle intorawfolder instead ofdrawablefolder when runningassembleReleaseTake note also we have to update
metro.config.js:Then I can finally load
OBJmodel in android release APK usingOBJ is down, how about FBX & GLTF? To know how things work, I look into
loadObjAsyncmethod insidenode_modules\expo-three\build\loaders\loadModelsAsync.jsI found out it was actually calling
loader.parse()method instead ofloader.load()So I attempted to do similar approach for FBX and GLTF models after referring to https://github.com/expo/expo-three/issues/151#issuecomment-593267436
First, install
base64-arraybufferusing npm/yarnThen. In wherever file that you wanted to load fbx or gltf model, add the following codes: (of course we can also fork
expo-threeand add these new methods - so the newbie don’t get stucked! )And that’s all! We can now load OBJ, FBX, GLTF models proudly inside Barebone RN app!
.glbis working for now because using.gltffile will require loading.binfile as well but I haven’t figure out how to load.binfile yet 😢)For more info, can refer to my gist:
or clone this example app that I created:
Programmer life is tough… 😉
Hi ! With expo-three 5.3.0 / expo-sdk 36 and react 16.9 I am only able to successfully load obj files. I tried the following extensions without success gltf, glb and dae. I am receiving the following message en try to load them in my android device: Event { “isTrusted”: false, }
Thanks Enzo
@kyaroru Thank you for your example. I checked your repo https://github.com/kyaroru/RNExpoThree Btw, could you please update your example using the latest expo sdk?
@enzopoeta I encourtered the same issue.
After checking source code, I find that expo use
localUriwhich usefile://protocal to fetch file, when I changed source code to useuriwhich usehttp://protocal , the error resolved.Here is the source code diff, hope this can temporary help you. Also wait for expo give us the final solution.
@kyaroru thank you for the example project!