Skip to content

Commit a04c802

Browse files
feat: allow custom loading manager to useTexture (#585)
* fix(deps):Update useTexture/index.ts fiexd TextureLoader use THREE.DefaultLoadingManager as default loading manager form: #432 * feat: Update src/composables/useTexture/index.ts remove the comment Co-authored-by: Alvaro Saburido <[email protected]> * feat: the documentation under docs/ to reflect 'allow custom loading manager to useTexture' --------- Co-authored-by: Alvaro Saburido <[email protected]>
1 parent 6232691 commit a04c802

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

docs/api/composables.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ Then you can bind the textures to the material.
148148
</template>
149149
```
150150

151+
`useTexture` by default takes the second argument 'manager' as LoadingManager. When omitted, it will automatically be added to `THREE.DefaultLoadingManager`. Of course, you can also add your own LoadingManager, like this:
152+
```ts
153+
const loadingManager = new LoadingManager()
154+
const texture = await useTexture({ map: 'path/to/texture.png' },loadingManager)
155+
```
156+
151157
Similar to above composable, the `useTexture` composable returns a promise, you can use it with `async/await` or `then/catch`. If you are using it on a component make sure you wrap it with a `Suspense` component.
152158

153159
## useSeek

src/composables/useTexture/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Texture } from 'three'
2-
import { LoadingManager, TextureLoader } from 'three'
1+
import type { Texture, LoadingManager } from 'three'
2+
import { TextureLoader } from 'three'
33
import { isArray } from '../../utils'
44

55
export interface PBRMaterialOptions {
@@ -114,9 +114,10 @@ export async function useTexture<TextureMap extends PBRUseTextureMap>(
114114

115115
export async function useTexture(
116116
paths: readonly [string] | string[] | PBRUseTextureMap,
117+
manager?: LoadingManager,
117118
): Promise<Texture | Texture[] | PBRTextureMaps> {
118-
const loadingManager = new LoadingManager()
119-
const textureLoader = new TextureLoader(loadingManager)
119+
120+
const textureLoader = new TextureLoader(manager)
120121

121122
/**
122123
* Load a texture.

0 commit comments

Comments
 (0)