Skip to content

Commit

Permalink
feat: allow custom loading manager to useTexture (#585)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
hawk86104 and alvarosabu authored Apr 3, 2024
1 parent 6232691 commit a04c802
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 6 additions & 0 deletions docs/api/composables.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ Then you can bind the textures to the material.
</template>
```

`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:
```ts
const loadingManager = new LoadingManager()
const texture = await useTexture({ map: 'path/to/texture.png' },loadingManager)
```

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.

## useSeek
Expand Down
9 changes: 5 additions & 4 deletions src/composables/useTexture/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Texture } from 'three'
import { LoadingManager, TextureLoader } from 'three'
import type { Texture, LoadingManager } from 'three'
import { TextureLoader } from 'three'
import { isArray } from '../../utils'

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

export async function useTexture(
paths: readonly [string] | string[] | PBRUseTextureMap,
manager?: LoadingManager,
): Promise<Texture | Texture[] | PBRTextureMaps> {
const loadingManager = new LoadingManager()
const textureLoader = new TextureLoader(loadingManager)

const textureLoader = new TextureLoader(manager)

/**
* Load a texture.
Expand Down

0 comments on commit a04c802

Please sign in to comment.