Giter Club home page Giter Club logo

pex-gui's Introduction

pex-gl

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

Create a RenderingContext (2d, webgl, webgl2, bitmaprenderer, webgpu) for use in PEX.

Installation

npm install pex-gl

Usage

import createRenderingContext, { FALLBACKS } from "pex-gl";

// Creates a webgl context filling the window
const context = createRenderingContext();

// Creates a webgl context from an existing canvas and keeps its size
const context = createRenderingContext({ canvas });

// Creates a webgl context on a new canvas with given width and height
const context = createRenderingContext({ width, height });

// Creates a new canvas of type "webgpu"
const context = createRenderingContext({ type: "webgpu" });

// Creates a new canvas of type "webgl" or fallback to experimental-webgl in case it fails
const context = createRenderingContext({ type: "webgl" });

// Disable fallbacks for "webgl2"
FALLBACKS.webgl2 = [];
// Creates a new canvas of type "webgl2" and return null in case it fails
const context = createRenderingContext({ type: "webgl2" });

API

Modules

pex-gl

Typedefs

PexGLOptions : object

Options for context creation. All optional.

pex-gl

pex-gl.FALLBACKS

Context fallbacks map

Kind: static constant of pex-gl

pex-gl.default([opts]) ⇒ RenderingContext

Creates a rendering context.

Kind: static method of pex-gl

Param Type Default
[opts] PexGLOptions {}

PexGLOptions : object

Options for context creation. All optional.

Kind: global typedef Properties

Name Type Default Description
[width] number window.innerWidth Request an initial canvas width.
[height] number window.innerHeight Request an initial canvas height.
[pixelRatio] boolean 1 Multiply canvas dimensions with a given ratio.
[fullscreen] boolean !opts.width && !opts.height Make the canvas fullscreen.
[type] "2d" | "bitmaprenderer" | "webgl" | "webgl2" | "webgpu" "webgl" A "contextType" for getContext.
[element] HTMLElement document.body Element to append the canvas to.
[...contextAttributes] CanvasRenderingContext2DSettings | WebGLContextAttributes {} Attributes to be passed to getContext.

License

MIT. See license file.

pex-gui's People

Contributors

dmnsgn avatar szymonkaliski avatar vorg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pex-gui's Issues

Implement dispose

  • Remove event listener
  • Dispose of any created canvas/context
  • Dispose of created textures

GUI clicks don't work on scaled canvas

1There are couple of interdependent causes to that:

  1. responsive: true overwrites scale on draw so i would propose that we default to false.
  2. this.getScaledActiveArea multiples activeArea by scale
  3. pixelRatio is not propagated from constructor to renderer

Currently i found two way to make gui render and be clickable

  • responsive: false, scale: canvas.width/canvas.clientWidth
  • responsive: true, pixelRatio set manually to canvas.width/canvas.clientWidth

So not sure if some of those things are bugs or i just don't know how to use them yet :)

Modular mouse and touch handling

Currently we depend on pex-sys/Window.addEventListener or manually calling gui.onMouseMove callbacks. It would be good to move to shared library between pex-sys,pex-gui and pex-cam.

Requirements:

  • works with mouse and touch (ideally using PointerEvents)
  • works in plask and borwser (can be via pex-gl.canvas)
  • has clear prioritisation (e.g. gui/GUI before cam/Arcball)
  • can cancel events or mark as handled (so Arcball doesn't move when i move the slider)
  • can filter events / record
  • allows implementing gestures
  • can map/filter/transform events (e.g. limit mouse movement to a viewport)

Ideal scenario:

  • create stream of events for a canvas
  • pass stream to a Logger
  • pass stream to GUI
  • pass stream to Arcball
  • on canvas.mousedown new event is added to the stream
  • Logger responds to a change, console.logs the event and leaves it in the stream
  • GUI responds to the change, if click is inside a slider the event is consumed, otherwise it's passed to the Arcball

Questions:

  • am i reinventing the wheel and try to compensate for lack of event bubbling that I would have for free when using HTML based GUI?

Add support for textures in addParam

Currently we need to use gui.addTexture2D(name, tex) instead of gui.addParam(name, obj, propName). This means tex can't be null and the gui will not update when the texture object is replaced with another one.

Use case: shadows maps of lights that initialize with shadowCasting off but then get it on.

Default responsive to false

I find it more intuitive that gui is controlled with scale. Current responsive:true often causes gui to scale. pixelRatio seems to do nothing? What's the correct way to use those 3 params?

“slider” GUIControl needs dirty = true to update

Hey Marcin, probably more of a documentation issue.

Was working off the audio.Audio example (https://github.com/vorg/pex-examples/blob/master/src/audio.Audio/main.js) and found that it was misleading as my variant only needed the progress slider and when everything else was stripped off, the slider stops updating.

Found that I needed to assign the slider, e.g.:

init: function() {
  …
  this.slider = this.gui.addParam('Progress', this, 'progress', { min: 0, max: 1}, this.onSeek.bind(this));
  …
}

And subsequently in the rendering cycle, declare that it is dirty:

draw: function() {
  …
  this.progress = this.audio.duration ? this.audio.currentTime / this.audio.duration : 0;
  this.slider.dirty = true;
  …
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.