Skip to content
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

useGLTF does not work in android emulator #1670

Closed
msmolnikau-d opened this issue Sep 29, 2023 · 1 comment
Closed

useGLTF does not work in android emulator #1670

msmolnikau-d opened this issue Sep 29, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@msmolnikau-d
Copy link

msmolnikau-d commented Sep 29, 2023

  • three version: 0.157.0
  • @react-three/fiber version: 8.14.3
  • @react-three/drei version: 9.86.1
  • node version: 20.3.0
  • yarn version: 1.22.11

Problem description:

useGLTF does not work in android emulator. Although, it is possible to load objects in expo for web, once the code is launched in emulator, it produces different sorts of errors. I have tried multiple ways (found in documentation and stackoverflow) of using the function.

My metro.config.js already has glb extension enabled:

module.exports = {
  resolver: {
    sourceExts: ['js', 'jsx', 'json', 'ts', 'tsx', 'cjs', 'mjs'],
    assetExts: ['glb', 'gltf', 'png', 'jpg'],
  },
}

The following code fragment (pine.glb is in assets folder, the code fragment is in root folder)

import { useGLTF } from "@react-three/drei/native";

export default function Pine(props) {
  const { nodes, materials } = useGLTF("./assets/pine.glb");
  // const { nodes, materials } = useGLTF("/assets/pine.glb"); also tried this
  // const { nodes, materials } = useGLTF("./pine.glb"); and this
  // const { nodes, materials } = useGLTF("/pine.glb"); and this
  console.log(nodes, materials);
}

throws

Error: Could not load ./assets/pine.glb: Call to function 'ExponentFileSystem.downloadAsync' has been rejected.
→ Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0

This fragment, works in web, but fails on Android:

import { useGLTF } from "@react-three/drei/native";
import model from "./assets/pine.glb";

export default function Pine(props) {
  const { nodes, materials } = useGLTF(model);
  console.log(nodes, materials);
}

the result is:

 ERROR  Error: Could not load 5: undefined

This error is located at:
    in Unknown
    in FiberProvider
    in CanvasWrapper (created by App)
    in Suspense (created by App)
    in App (created by withDevTools(App))
    in withDevTools(App)
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
    in main(RootComponent), js engine: hermes

Using other path for a model throws a standard error that file not found so I'm pretty sure that the path is correct

@msmolnikau-d msmolnikau-d added the bug Something isn't working label Sep 29, 2023
@CodyJasonBennett
Copy link
Member

This was fixed downstream in pmndrs/react-three-fiber#3036.

Note that we're waiting for fixes to upstream into react-native 0.74 to load embedded textures in GLB. Use gltfjsx and split up textures for now if you have to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants