Skip to content
This repository was archived by the owner on Feb 1, 2026. It is now read-only.

Commit fd7a82f

Browse files
committed
refactor(Atlas.ts): replace useLoader with TextureLoader for improved texture handling
- Removed the use of `useLoader` from `@Tresjs/core` and implemented a direct instantiation of `TextureLoader` from Three.js for loading textures. This change enhances clarity and performance by simplifying the texture loading process. - Updated the promise handling for texture loading to ensure proper resolution and rejection, improving error handling. - Adjusted the way texture dimensions are accessed to streamline the code and enhance maintainability.
1 parent fa47c12 commit fd7a82f

File tree

1 file changed

+15
-8
lines changed
  • src/core/abstractions/AnimatedSprite

1 file changed

+15
-8
lines changed

src/core/abstractions/AnimatedSprite/Atlas.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,36 @@
1-
import { logError, useLoader } from '@tresjs/core'
1+
import { logError } from '@tresjs/core'
22
import { type Texture, TextureLoader } from 'three'
3-
import type { LoaderProto } from '@tresjs/core'
43
import { expand } from './AtlasAnimationDefinitionParser'
54
import { getNumbersFromEnd, stripUnderscoresNumbersFromEnd } from './StringOps'
65

76
export async function getTextureAndAtlasAsync(
87
imagePathOrImageData: string,
98
atlasPathOrAtlasish: string | Atlasish,
109
): Promise<[Texture | Texture[], Atlas]> {
11-
const texturePromise: Promise<Texture | Texture[]> = useLoader<Texture>(
12-
TextureLoader as LoaderProto<Texture>,
13-
imagePathOrImageData,
14-
)
10+
// Use plain Three.js TextureLoader for loading the texture
11+
const loader = new TextureLoader()
12+
const texturePromise = new Promise<Texture>((resolve, reject) => {
13+
loader.load(
14+
imagePathOrImageData,
15+
resolve,
16+
undefined,
17+
reject,
18+
)
19+
})
20+
1521
const atlasishPromise: Promise<Atlasish>
1622
= typeof atlasPathOrAtlasish !== 'string'
1723
? new Promise(resolve => resolve(atlasPathOrAtlasish as Atlasish))
1824
: fetch(atlasPathOrAtlasish)
1925
.then(response => response.json())
2026
.catch(e => logError(`Cientos Atlas - ${e}`))
27+
2128
return Promise.all([texturePromise, atlasishPromise]).then(
2229
([texture, atlasish]) => {
2330
const atlas = getAtlas(
2431
atlasish,
25-
(texture as Texture).image.width,
26-
(texture as Texture).image.height,
32+
texture.image.width,
33+
texture.image.height,
2734
)
2835
return [texture, atlas]
2936
},

0 commit comments

Comments
 (0)