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

gl-geometry

v3.1.1

Published

A flexible wrapper for gl-vao and gl-buffer that you can use to set up renderable WebGL geometries from a variety of different formats.

Downloads

113

Readme

gl-geometry experimental

A flexible wrapper for gl-vao and gl-buffer that you can use to set up renderable WebGL geometries from a variety of different formats.

Usage

NPM

geom = createGeometry(gl)

Creates a new geometry attached to the WebGL canvas context gl.

geom.attr(name, values[, opt])

Define or update an attribute value, for example using a simplicial complex:

var createGeometry = require('gl-geometry')
var bunny = require('bunny')

var geom = createGeometry(gl)
  .attr('positions', bunny)

The following vertex formats are supported and will be normalized:

  • Arrays of arrays, e.g. [[0, 0, 0], [1, 0, 0], [1, 1, 0]].

  • Flat arrays, e.g. [0, 0, 0, 1, 0, 0, 1, 1, 0].

  • Typed arrays, preferably a Float32Array.

  • 1-dimensional ndarrays.

  • simplicial complexes, i.e. an object with a positions array and a cells array. The former is a list of unique vertices in the mesh (if you've used three.js, think THREE.Vector3), and the latter is an index mapping these vertices to faces (THREE.Face3) in the mesh. It looks something like this:

    {
      "positions": [
        [0.0, 0.0, 0.0],
        [1.5, 0.0, 0.0],
        [1.5, 1.5, 0.0],
        [0.0, 1.5, 0.0]
      ],
      "cells": [
        [0, 1, 2],
        [1, 2, 3]
      ]
    }

You can specify opt.size for the vertex size, defaults to 3.

You can update attribute values by calling attr again with the same name:

  • By default the entire contents of the associated gl-buffer are replaced by data; the buffer will be resized accordingly.

  • Alternatively, you can pass opt.offset to copy data into the current buffer at a specific offset (in bytes). In this case, the buffer cannot be resized.

geom.faces(values[, opt])

Pass a simplicial complex's cells property here in any of the above formats to use it as your index when drawing the geometry. For example:

var createGeometry = require('gl-geometry')
var bunny = require('bunny')

bunny.normals = normals.vertexNormals(
    bunny.cells
  , bunny.positions
)

var geom = createGeometry(gl)
  .attr('positions', bunny.positions)
  .attr('normals', bunny.normals)
  .faces(bunny.cells)

You can specify opt.size for the cell size, defaults to 3.

geom.bind([shader])

Binds the underlying VAO – this must be called before calling geom.draw. Optionally, you can pass in a gl-shader to automatically set up your attribute locations for you.

geom.draw(mode, start, stop)

Draws the geometry to the screen using the currently bound shader.

Optionally, you can pass in the drawing mode, which should be one of the following:

  • gl.POINTS
  • gl.LINES
  • gl.LINE_STRIP
  • gl.LINE_LOOP
  • gl.TRIANGLES
  • gl.TRIANGLE_STRIP
  • gl.TRIANGLE_FAN

The default value is gl.TRIANGLES. You're also able to pass in a start and stop range for the points you want to render, just the same as you would with gl.drawArrays or gl.drawElements.

geom.unbind()

Unbinds the underlying VAO. This must be done when you're finished drawing, unless you're binding to another gl-geometry or gl-vao instance.

geom.dispose()

Disposes the underlying element and array buffers, as well as the VAO.

See Also

License

MIT. See LICENSE.md for details.