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-mesh

v0.1.0

Published

Static indexed mesh drawing for WebGL

Downloads

31

Readme

gl-mesh

WebGL class for rendering static indexed geometry

Example

Try this demo in your browser

var shell = require("gl-now")()
var createMesh = require("gl-mesh")
var simple2DShader = require("simple-2d-shader")

var mesh, shader

shell.on("gl-init", function() {
  shader = simple2DShader(shell.gl)
  mesh = createMesh(shell.gl,
      [[0, 1, 2],
       [2, 1, 3]],
      { "position": [[-1,-1],   [0, 1],    [0, 0],    [1, -1]],
        "color":    [[1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 1, 1]] })
})

shell.on("gl-render", function(t) {
  shader.bind()
  mesh.bind(shader)
  mesh.draw()
  mesh.unbind()
})

And here is what it should look like:

Install

Use npm to install it locally:

npm install gl-mesh

Then you can build/run the client using any tool that compiles CommonJS modules, for example browserify or beefy.

API

var createMesh = require("gl-mesh")

Constructor

var mesh = createMesh(gl, cells, attributes)

Creates a static mesh.

  • gl is a webgl context
  • cells is a list of representing indices into the geometry
  • attributes is an object of attributes to pass to the mesh

Each of these objects can be encoded as either an array-of-native-arrays or as a typed array using ndarrays. The first dimension in the shape is interepreted as the number of vertices in the attribute while the second dimension is interpreted as the size. For example, to pass in a packed array of 3d vertices in a typed array you could do:

var mesh = createMesh(gl, cells, { "positions": ndarray(position_data, [numVertices, 3]) })

The drawing mode for the mesh is determined by the shape of the cells according to the following rule:

  • cells.length == 0 : empty mesh
  • cells[0].length == 1 : gl.POINTS
  • cells[0].length == 2 : gl.LINES
  • cells[0].length == 3 : gl.TRIANGLES

You can also skip the cells parameter, in which case the resulting mesh is drawn as a point cloud.

Also you can pass a single object with a cells field. For example, here is the quickest way to create a Stanford bunny test mesh:

var bunnyMesh = createMesh(gl, require("bunny"))

Where the module comes from the bunny package

Returns A Mesh object

Methods

Each Mesh object has the following methods:

mesh.bind(shader)

Binds the mesh to the given shader updating attributes accordingly.

  • shader is an instance of a shader created using gl-shader

mesh.draw()

Draws an instance of the mesh once it is bound to a shader

mesh.unbind()

Unbinds the mesh releasing the current vertex attribute state

mesh.dispose()

Destroys the mesh and releases all of its associated resources

Credits

(c) 2013 Mikola Lysenko. MIT License