An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# wgs-player

[![npm version](https://img.shields.io/npm/v/wgs-player.svg)](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.