https://github.com/fralonra/wgs-player
WGS player for the Web
https://github.com/fralonra/wgs-player
canvas pixel-shader webgl2 wgs wgsl
Last synced: 6 months ago
JSON representation
WGS player for the Web
- Host: GitHub
- URL: https://github.com/fralonra/wgs-player
- Owner: fralonra
- License: mit
- Created: 2023-06-21T04:57:02.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-06-21T06:51:55.000Z (over 2 years ago)
- Last Synced: 2025-03-14T03:21:58.563Z (7 months ago)
- Topics: canvas, pixel-shader, webgl2, wgs, wgsl
- Language: TypeScript
- Homepage: https://fralonra.github.io/wgs-player/
- Size: 1.01 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wgs-player
[](https://www.npmjs.com/package/wgs-player)
`wgs-player` helps you to run [`wgs`](https://github.com/fralonra/wgs) file on Web.
It's built on top of [wgs-runtime-wgpu](https://www.npmjs.com/package/wgs-runtime-wgpu).
## Installation
```bash
npm install wgs-player
```## Usage
```javascript
import { createPlayer } from 'wgs-player'async function main() {
const canvas = document.getElementById('canvas')const player = await createPlayer({ canvas })
}main()
```## API
### createPlayer
`function createPlayer(options: PlayerOptions): Promise`
Create a new [`WgsPlayer`](#WgsPlayer) instance.
#### PlayerOptions
```typescript
interface PlayerOptions {
// Whether to automatically render the wgs once the instance is created.
// Default is true.
// If set to `false`, you can always manually invoke `play()` to trigger the rendering.
autoPLay?: boolean// The HTMLCanvasElement where the player will render wgs.
canvas: HTMLCanvasElement
}
```### WgsPlayer
The WgsPlayer instance.
#### runtime
_property_ Expose the `WebRuntime` from [wgs-runtime-wgpu](https://www.npmjs.com/package/wgs-runtime-wgpu).
#### destroy
`destroy(): void`
_method_ Destroy the instance manually. Will remove listeners associated with the `HTMLCanvasElement`.
#### loadFromBlob
`loadFromBlob(blob: Blob): Promise`
_method_ Load wgs data from a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
#### loadFromFile
`loadFromFile(file: File): Promise`
_method_ Load wgs data from a [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File).
#### loadFromUrl
`loadFromUrl(url: string, fetchOptions?: RequestInit): Promise`
_method_ Load wgs data from a url. `fetchOptions` will be passed down to Fetch API.
#### pause
`pause(): void`
_method_ Pause the runtime.
#### play
`play(): void`
_method_ Start the runtime manually. Used when `autoPlay` is set to `false`.
#### restart
`restart(): void`
_method_ Restart the runtime.
#### resume
`resume(): void`
_method_ Resume the runtime.