expo / expo-three

Utilities for using THREE.js on Expo
MIT License
711 stars 87 forks source link

texture based on file:// url won't load #297

Open earonesty opened 11 months ago

earonesty commented 11 months ago

followed this documentation:

https://github.com/expo/expo-three#loading-assets

texture based on remote image won't load:

Call to function 'ExponentFileSystem.downloadAsync' has been rejected.
→ Caused by: java.lang.IllegalArgumentException: Expected URL scheme 'http' or 'https' but was 'file'
    at construct (native)
    at apply (native)
    at _construct (http://10.24.121.64:8081/node_modules%5Cexpo%5CAppEntry.bundle//&platform=android&dev=true&hot=false&lazy=true:4486:28)
    at Wrapper (http://10.24.121.64:8081/node_modules%5Cexpo%5CAppEntry.bundle//&platform=android&dev=true&hot=false&lazy=true:4448:25)
    at construct (native)
    at _createSuperInternal (http://10.24.121.64:8081/node_modules%5Cexpo%5CAppEntry.bundle//&platform=android&dev=true&hot=false&lazy=true:125092:322)
    at call (native)
    at CodedError (http://10.24.121.64:8081/node_modules%5Cexpo%5CAppEntry.bundle//&platform=android&dev=true&hot=false&lazy=true:125105:26)

i believe this has already been fixed in dependent libs, so you just have to update deps

louix commented 7 months ago

Try passing textureLoader.load the asset instead of asset.localUri

markrickert commented 3 months ago

I had this problem today with the latest expo-asset.

Try this:

class LocalIconMesh extends Mesh {
  constructor() {
    super();
    this.geometry = new BoxGeometry(1, 1, 1);
    const loader = new TextureLoader();
    Asset.loadAsync(require('../assets/icon.png')).then(([{ localUri }]) => {
      try {
        loader.load(localUri, (texture) => {
          this.material = new MeshBasicMaterial({ map: texture });
        });
      } catch (error) {
        console.error(error);
      }
    });
  }
}
orange4glace commented 2 months ago

@markrickert Thanks for your work. BTW, I think your code is for loading texture from its own package. How can I load a texture from FileSystem? (ex: pick an image from gallery)

markrickert commented 2 days ago

Hi @orange4glace, sorry for the late reply. I just added an example in my updated fork. Everything is up to date in my implementation with three 0.166.0 and expo sdk 51.

I added a demo of how to use local file paths via an image picker to the "bouncing balls" demo of my fork. You can check it out here: https://github.com/expo/expo-three/pull/301/commits/e9f0a1d6504f737d703647dd6dec1dc64b562af8

33DEA067-EE35-42B8-8F07-23C77BB7BB75-99740-000649283FF60264