forked from BabylonJS/Babylon.js
-
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.
EXT_texture_avif implementation (BabylonJS#13370)
* EXT_texture_avif implementation * added avif to places where I forgot it
- Loading branch information
Showing
6 changed files
with
80 additions
and
0 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
58 changes: 58 additions & 0 deletions
58
packages/dev/loaders/src/glTF/2.0/Extensions/EXT_texture_avif.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,58 @@ | ||
import type { IGLTFLoaderExtension } from "../glTFLoaderExtension"; | ||
import { GLTFLoader, ArrayItem } from "../glTFLoader"; | ||
import type { ITexture } from "../glTFLoaderInterfaces"; | ||
import type { BaseTexture } from "core/Materials/Textures/baseTexture"; | ||
import type { Nullable } from "core/types"; | ||
import type { IEXTTextureAVIF } from "babylonjs-gltf2interface"; | ||
|
||
const NAME = "EXT_texture_avif"; | ||
|
||
/** | ||
* [glTF PR](https://github.com/KhronosGroup/glTF/pull/2235) | ||
* [Specification](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Vendor/EXT_texture_avif/README.md) | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export class EXT_texture_avif implements IGLTFLoaderExtension { | ||
/** The name of this extension. */ | ||
public readonly name = NAME; | ||
|
||
/** Defines whether this extension is enabled. */ | ||
public enabled: boolean; | ||
|
||
private _loader: GLTFLoader; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
constructor(loader: GLTFLoader) { | ||
this._loader = loader; | ||
this.enabled = loader.isExtensionUsed(NAME); | ||
} | ||
|
||
/** @internal */ | ||
public dispose() { | ||
(this._loader as any) = null; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public _loadTextureAsync(context: string, texture: ITexture, assign: (babylonTexture: BaseTexture) => void): Nullable<Promise<BaseTexture>> { | ||
return GLTFLoader.LoadExtensionAsync<IEXTTextureAVIF, BaseTexture>(context, texture, this.name, (extensionContext, extension) => { | ||
const sampler = texture.sampler == undefined ? GLTFLoader.DefaultSampler : ArrayItem.Get(`${context}/sampler`, this._loader.gltf.samplers, texture.sampler); | ||
const image = ArrayItem.Get(`${extensionContext}/source`, this._loader.gltf.images, extension.source); | ||
return this._loader._createTextureAsync( | ||
context, | ||
sampler, | ||
image, | ||
(babylonTexture) => { | ||
assign(babylonTexture); | ||
}, | ||
undefined, | ||
!texture._textureInfo.nonColorData | ||
); | ||
}); | ||
} | ||
} | ||
|
||
GLTFLoader.RegisterExtension(NAME, (loader) => new EXT_texture_avif(loader)); |
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