-
Notifications
You must be signed in to change notification settings - Fork 717
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
Loading multiple textures with useTexture #176
Comments
yes it should work like that. useLoader does for sure. could you look into it and fix it? maybe the types are off. |
Checked it out, and I believe the typing is slightly off. It looks like the conditional type would always evaluate to string. I can throw up a quick PR. This fix worked fine for me. Current: Fixed for me: |
@drcmda when using Type 'Texture' must have a '[Symbol.iterator]()' method that returns an iterator. For this code: const [matcap1, matcap2] = useLoader(TextureLoader, ['matcap-1.png', 'matcap-2.png']) Using @Code47X's TS example in |
@joshuaellis Not sure if this helps you at all, but when I was messing with source code for |
Kind of helps me, I was under the impression the Types were implied through the generics, hopefully @drcmda can offer some insight. |
I was also under the assumption that the types were implied initially. Checking out the source, it seems the return type and the input type check if the generic extends an array. It looks like when
|
The solution will be: export function useTexture<T extends string | string[]>(url: T): T extends any[] ? Texture[] : Texture {
return useLoader(TextureLoader, url)
} assuming pmndrs/react-three-fiber#917 is approved. Could change depending on that PR. |
@joshuaellis I saw your pr (pmndrs/react-three-fiber#930) to fix Are you planning on fixing the typing for the |
@Code47X thank you, but I must honest, it was @stephencorwin who really came up with the plan with the conditionals & your suggestion too for handling the string correctly, I just put the two together. I hope to finish #223 this evening, so keep an eye out for the issue being closed, I think the PR is nearly there tbh. |
fixed in #231 |
I'm using the useTexture hook to load in a collection of textures. Currently I've been loading each texture individually like so, which seems to work fine:
I've checked out the useTexture examples, and TypeScript shows it can return an array of textures, but I'm not quite following the syntax. It seems like useTexture will only accept a single string as an argument. TS won't accept an array of strings as an argument. I've tried pointing it to the folder containing the textures, but no luck.
From Example:
const [texture1, texture2] = useTexture([texture1, texture2])
Just trying to figure out if there is a better way to load all the textures, or if using useTexture individually for each is the correct way. Thanks.
The text was updated successfully, but these errors were encountered: