1
0
Эх сурвалжийг харах

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 <alvaro.saburido@gmail.com>

* feat: the documentation under docs/ to reflect 'allow custom loading manager to useTexture'

---------

Co-authored-by: Alvaro Saburido <alvaro.saburido@gmail.com>
地虎降天龙.hawk 1 жил өмнө
parent
commit
a04c802220

+ 6 - 0
docs/api/composables.md

@@ -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

+ 5 - 4
src/composables/useTexture/index.ts

@@ -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 {
@@ -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.