npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gpu-curtains

v0.10.0

Published

gpu-curtains is a 3D WebGPU rendering engine. It can be used as a standalone 3D engine, but also includes extra classes focused on mapping 3d objects to DOM elements; It allows users to synchronize values such as position, sizing, or scale between them.

Downloads

180

Readme

gpu-curtains

Website - Documentation - Examples


:warning: WIP


DOM 2 WebGPU rendering engine

gpu-curtains is a small, lightweight 3D WebGPU rendering engine library.

It can be used as a standalone 3D engine, but also includes extra classes designed to turn HTML elements into textured planes or meshes, allowing you to animate them via WGSL shaders.

The project was initially conceived as a WebGPU port of curtains.js. It turned out to be a complete rewrite of the library instead, but with a very similar API.

Usage

You can directly download the files and start using the ES6 modules:

ES modules

import { GPUCurtains } from 'path/to/dist/esm/index.mjs'

window.addEventListener('load', async () => {
  // set our main GPUCurtains instance
  // it will handle everything we need
  // a WebGPU device and a renderer with its scene,
  // requestAnimationFrame, resize and scroll events...
  const gpuCurtains = new GPUCurtains({
    container: '#canvas'
  })

  // set the GPU device
  // note this is asynchronous
  await gpuCurtains.setDevice()

  // now create some magic!
})

You can also use one of your favorite package manager:

npm

npm i gpu-curtains

yarn

yarn add gpu-curtains

Finally, you can load the library from a CDN. You should always target a specific version (append @x.x.x) rather than the latest one in order to avoid breaking changes.

import { ... } from 'https://esm.run/gpu-curtains'
// or
import { ... } from 'https://cdn.skypack.dev/gpu-curtains'
// or use another cdn...

UMD files

In a browser, you can use the UMD files located in the dist directory:

<script src="path/to/dist/gpu-curtains.umd.min.js"></script>

Or use a CDN:

<script src="https://cdn.jsdelivr.net/npm/gpu-curtains"></script>

Documentation and examples

Basic example

HTML

<body>
    <!-- div that will hold our WebGPU canvas -->
    <div id="canvas"></div>
</body>

CSS

body {
  position: relative;
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

#canvas {
  /* make the canvas wrapper fits the viewport */
  position: fixed;
  top: 0;
  right: 0;
  width: 100%;
  height: 100lvh;
}

Javascript

import { Curtains, Mesh } from 'gpu-curtains';

window.addEventListener('load', async () => {
  // set our main GPUCurtains instance
  // it will handle everything we need
  // a WebGPU device and a renderer with its scene,
  // requestAnimationFrame, resize and scroll events...
  const gpuCurtains = new GPUCurtains({
    container: '#canvas'
  })

  // set the GPU device
  // note this is asynchronous
  await gpuCurtains.setDevice()

  // create a cube mesh
  const mesh = new Mesh(gpuCurtains, {
    geometry: new BoxGeometry(),
  })
  
  // this callback is executed
  // before the scene actually updates the matrix stack
  mesh.onBeforeRender(() => {
    // make it rotate
    mesh.rotation.x += 0.01
    mesh.rotation.y += 0.02
  })
})

Limitations

gpu-curtains is a slowly evolving 3D engine and may lack some common features.

If you need a more robust 3D engine that could handle complex glTF or advanced lighting, shading or rendering mechanics, then you should probably go with another library like three.js or Babylon.js.

Contributing

Contribution are more than welcome! Please refer to the contribution guidelines.

Acknowledgements

Some parts of the code (mostly the math classes) have been ported or adapted from other existing open source libraries like three.js and glmatrix.

Some examples are also ported and/or inspired by other online open-source WebGL or WebGPU examples. In any case the source should always be credited in the code. If a credit is missing, feel free to reach out or make a PR.

The WebGPU samples, WebGPU fundamentals and WebGPU best practices were very helpful to help with the basic concepts of WebGPU. If you want to understand a bit more how it's working under the hood, do not hesitate to check those.

A big thanks to the members of the WebGPU matrix chan that were always super kinds and very helpful as well.

Changelog and roadmap

  • Releases
  • See the roadmap for details on the current work in progress and possible improvements.