https://github.com/repalash/gltf-transform-generic-ext
GenericExtension class to easily create simple custom extensions for glTF-Transform
https://github.com/repalash/gltf-transform-generic-ext
gltf gltf-extensions gltf-transform webgi
Last synced: 2 months ago
JSON representation
GenericExtension class to easily create simple custom extensions for glTF-Transform
- Host: GitHub
- URL: https://github.com/repalash/gltf-transform-generic-ext
- Owner: repalash
- License: mit
- Created: 2023-05-29T18:01:04.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-05-29T18:01:41.000Z (about 3 years ago)
- Last Synced: 2025-09-22T10:03:51.227Z (9 months ago)
- Topics: gltf, gltf-extensions, gltf-transform, webgi
- Language: TypeScript
- Homepage: http://repalash.com/glTF-Transform-Generic-Ext/
- Size: 66.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Generic Extension for glTF-Transform
This is a generic extension for [glTF-Transform](https://gltf-transform.donmccurdy.com/), which can be used as a template for creating new extensions for glTF-Transform.
It can be used to automatically create extensions with arbitrary properties. It works by putting the properties in extras when reading the extension from the glTF and then restoring them when writing the glTF. With this, there is no need for defining fully typed extension classes and extension properties for simple custom extensions.
## Usage
```typescript
import {GenericExtension} from 'gltf-transform-generic-ext'
import {TextureChannel} from '@gltf-transform/core'
// Extension with no texture
class TriplanarMappingMaterialExtension extends GenericExtension {
public static readonly EXTENSION_NAME = 'WEBGI_materials_triplanar'
readonly extensionName = TriplanarMappingMaterialExtension.EXTENSION_NAME
}
// Extension with a texture using the R channel
class BumpMapMaterialExtension extends GenericExtension {
public static readonly EXTENSION_NAME = 'WEBGI_materials_bumpmap'
readonly extensionName = BumpMapMaterialExtension.EXTENSION_NAME
textureChannels: Record = {
bumpTexture: TextureChannel.R,
}
}
// Extension with a texture using the R, G and B channels
class LightMapMaterialExtension extends GenericExtension {
public static readonly EXTENSION_NAME = 'WEBGI_materials_lightmap'
readonly extensionName = LightMapMaterialExtension.EXTENSION_NAME
textureChannels: Record = {
lightMapTexture: TextureChannel.R | TextureChannel.G | TextureChannel.B,
}
}
// Extension with a texture using the G channel
class AlphaMapMaterialExtension extends GenericExtension {
public static readonly EXTENSION_NAME = 'WEBGI_materials_alphamap'
readonly extensionName = AlphaMapMaterialExtension.EXTENSION_NAME
textureChannels: Record = {
alphaTexture: TextureChannel.G,
}
}
```
## License
MIT
## References
Generated with [rollup-library-starter](https://github.com/repalash/rollup-library-starter)