pmndrs / drei

🥉 useful helpers for react-three-fiber
https://docs.pmnd.rs/drei
MIT License
8.36k stars 699 forks source link

useTexture does not work on react native with Expo #1809

Open itsyoboieltr opened 9 months ago

itsyoboieltr commented 9 months ago

Problem description:

I am trying to load a sprite, but it errors.

image

Relevant code:

import { useTexture } from '@react-three/drei/native';

export default function Test() {
  const sprite = useTexture(require('./sprite.png'));
  return <></>;
}

Suggested solution:

Maybe I am misusing it? but I would expect this to work.

divyansh4300 commented 7 months ago

Try wrapping the component with Canvas

import React from 'react';
import { Canvas } from 'react-three-fiber';
import { useTexture } from '@react-three/drei';

function Test() {
  const sprite = useTexture(require('./sprite.png'));
  return (
    <mesh>
      <planeBufferGeometry attach="geometry" args={[1, 1]} />
      <meshBasicMaterial attach="material" map={sprite} />
    </mesh>
  );
}

export default function App() {
  return (
    <Canvas>
      <Test />
    </Canvas>
  );
}
github-actions[bot] commented 2 days ago

Thank you for contributing! We’re marking this issue as stale as a gentle reminder to revisit it and give it the attention it needs to move forward.

Any activity, like adding an update or comment, will automatically remove the stale label so it stays on our radar.

Feel free to reach out on Discord if you need support or feedback from the community. This issue will close automatically soon if there’s no further activity. Thank you for understanding and for being part of the project!