forked from pixijs/pixijs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
176 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './loadBasis'; | ||
export * from './loadDDS'; | ||
export * from './loadKTX'; | ||
export * from './loadSVG'; | ||
export * from './loadTexture'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import type { IBaseTextureOptions, Texture } from '@pixi/core'; | ||
import { BaseTexture, ExtensionType, SVGResource } from '@pixi/core'; | ||
import { settings } from '@pixi/settings'; | ||
import { getResolutionOfUrl } from '@pixi/utils'; | ||
import { extname } from '../../../utils'; | ||
import type { Loader } from '../../Loader'; | ||
import type { LoadAsset } from '../../types'; | ||
|
||
import type { LoaderParser } from '../LoaderParser'; | ||
import { loadTextures } from './loadTexture'; | ||
import { createTexture } from './utils/createTexture'; | ||
|
||
/** Loads SVG's into Textures */ | ||
export const loadSVG = { | ||
extension: ExtensionType.LoadParser, | ||
|
||
test(url: string): boolean | ||
{ | ||
return (extname(url).includes('.svg')); | ||
}, | ||
|
||
async testParse(data: string): Promise<boolean> | ||
{ | ||
return SVGResource.test(data); | ||
}, | ||
|
||
async parse(asset: string, data: LoadAsset<IBaseTextureOptions>, loader: Loader): Promise<Texture> | ||
{ | ||
const src = new SVGResource(asset, data?.data?.resourceOptions); | ||
|
||
const base = new BaseTexture(src, { | ||
resolution: getResolutionOfUrl(asset), | ||
...data?.data, | ||
}); | ||
|
||
base.resource.src = asset; | ||
|
||
const texture = createTexture(base, loader, asset); | ||
|
||
if (!data?.data?.resourceOptions?.autoLoad) | ||
{ | ||
await src.load(); | ||
} | ||
|
||
return texture; | ||
}, | ||
|
||
async load(url: string, _options: LoadAsset): Promise<string> | ||
{ | ||
const response = await settings.ADAPTER.fetch(url); | ||
|
||
return response.text(); | ||
}, | ||
|
||
unload: loadTextures.unload, | ||
|
||
} as LoaderParser<Texture | string, IBaseTextureOptions>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/assets/src/loader/parsers/textures/utils/checkExtension.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export function checkExtension(url: string, extension: string | string[]): boolean | ||
{ | ||
const tempURL = url.split('?')[0]; | ||
const extensionSplit = tempURL.split('.').pop(); | ||
|
||
if (Array.isArray(extension)) | ||
{ | ||
return extension.includes(extensionSplit.toLowerCase()); | ||
} | ||
|
||
return extensionSplit.toLowerCase() === extension; | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/assets/src/loader/parsers/textures/utils/createTexture.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { BaseTexture } from '@pixi/core'; | ||
import { Texture } from '@pixi/core'; | ||
import type { Loader } from '../../../Loader'; | ||
|
||
export function createTexture(base: BaseTexture, loader: Loader, url: string) | ||
{ | ||
const texture = new Texture(base); | ||
|
||
// make sure to nuke the promise if a texture is destroyed.. | ||
texture.baseTexture.on('dispose', () => | ||
{ | ||
delete loader.promiseCache[url]; | ||
}); | ||
|
||
return texture; | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.