I am trying to load the glb file using “require” in expo react-native app but its failing to load the file.
I have created metro.config.js file as documented in Expo with following content but still facing the issue.
const defaultAssetExts = require(“metro-config/src/defaults/defaults”)
.assetExts;
module.exports = {
resolver: {
assetExts: […defaultAssetExts, “glb”]
}
};
When I try to load the glb file using GLTFLoader, I get error Unhandled promise rejection
Code:
const loader = new GLTFLoader();
loader.load(
require(“./assets/my3dFile.glb”),
glb => {
console.log(“I am here”);
don =glb.scene;
scene.add(glb.scene);
},
xhr => {
console.log((xhr.loaded / xhr.total) * 100 + “% loaded”);
},
error => {
console.log(error);
}
);
Error:
[Unhandled promise rejection: TypeError: url.lastIndexOf is not a function. (In ‘url.lastIndexOf(’/‘)’, ‘url.lastIndexOf’ is undefined)]
-
node_modules/three/build/three.module.js:40347:17 in LoaderUtils.extractUrlBase
-
node_modules/three/examples/jsm/loaders/GLTFLoader.js:102:10 in Object.assign$argument_1.load
-
node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
-
node_modules/regenerator-runtime/runtime.js:274:30 in invoke
-
node_modules/regenerator-runtime/runtime.js:45:44 in tryCatch
-
node_modules/regenerator-runtime/runtime.js:135:28 in invoke
-
node_modules/regenerator-runtime/runtime.js:145:19 in PromiseImpl.resolve.then$argument_0
-
node_modules/promise/setimmediate/core.js:37:14 in tryCallOne
-
node_modules/promise/setimmediate/core.js:123:25 in setImmediate$argument_0
-
node_modules/react-native/Libraries/Core/Timers/JSTimers.js:146:14 in _callTimer
-
node_modules/react-native/Libraries/Core/Timers/JSTimers.js:194:17 in _callImmediatesPass
-
node_modules/react-native/Libraries/Core/Timers/JSTimers.js:458:30 in callImmediates
- [native code]:null in callImmediates
-
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:407:6 in __callImmediates
-
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:143:6 in __guard$argument_0
-
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:384:10 in __guard
-
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:142:17 in __guard$argument_0
-
[native code]:null in flushedQueue
-
[native code]:null in callFunctionReturnFlushedQueue
Package.josn
“dependencies”: {
“@react-native-community/masked-view”: “0.1.6”,
“@react-navigation/native”: “^5.6.1”,
“@react-navigation/stack”: “^5.6.2”,
“expo”: “~37.0.3”,
“expo-gl”: “~8.1.0”,
“expo-graphics”: “^1.1.0”,
“expo-three”: “^5.5.1”,
“react”: “~16.9.0”,
“react-dom”: “~16.9.0”,
“react-native”: “https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz”,
“react-native-gesture-handler”: “~1.6.0”,
“react-native-reanimated”: “~1.7.0”,
“react-native-safe-area-context”: “0.7.3”,
“react-native-screens”: “~2.2.0”,
“react-native-web”: “~0.11.7”,
“three”: “^0.117.1”
},
“devDependencies”: {
“babel-preset-expo”: “~8.1.0”,
“@babel/core”: “^7.8.6”
},
Can you please let me know where I am going wrong? Thanks for the help.