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

@kineviz/three-buffer-vertex-data

v1.2.2

Published

an easy way to set vertex data on a BufferGeometry

Downloads

57

Readme

three-buffer-vertex-data

experimental

(demo) - (source)

Convenience functions for sending vertex data to an attribtue of a THREE.BufferGeometry.

This will flatten vertex data if necessary, attempt to re-use arrays where possible to minimize GC, and handle some compatibility issues across different versions of ThreeJS. It can handle dynamically growing and shrinking buffers.

The input is expected in simple arrays, and can be one of:

  • a nested array like [ [ x, y ], [ x, y ] ]
  • a flat array like [ x, y, z, x, y, z ]
  • a typed array like new Float32Array([ x, y ])

This is particularly useful in new versions of ThreeJS, where BufferGeometry is required for custom shader attributes.

Install

npm install three-buffer-vertex-data --save

Example

A simple example using snowden.

var buffer = require('three-buffer-vertex-data')

// grab a simplicial complex
var snowden = require('snowden')

// set up our geometry
var geometry = new THREE.BufferGeometry()
buffer.index(geometry, snowden.cells)
buffer.attr(geometry, 'position', snowden.positions)

// add to scene
var material = new THREE.MeshBasicMaterial()
var mesh = new THREE.Mesh(geometry, material)
scene.add(mesh)

The 'position', 'uv' and 'normal' attributes are built-in to ThreeJS and will work with common materials. Result:

See demo for a more complex example, which cycles various mesh primitives into the same vertex buffers.

Usage

NPM

The data passed is sent through flatten-vertex-data, and can be in the form of:

  • a nested array like [ [ x, y ], [ x, y ] ]
  • a flat array like [ x, y, z, x, y, z ]
  • a typed array like new Float32Array([ x, y ])

If the attribute exists, its underlying array will try to be re-used. Otherwise, a new typed array will be created from the optional dtype.

buffer.index(geometry, data, [itemSize], [dtype])

Sets the index attribute for the given buffer geometry, with your list of indices in data. The itemSize defaults to 1, and dtype string defaults to 'uint16'

buffer.attr(geometry, key, data, [itemSize], [dtype])

Sets a generic attribute on the given buffer geometry by the given key and vertex data. The itemSize defaults to 3, and dtype string defaults to 'float32'.

Gotchas

In r73, ThreeJS breaks when using wireframe and attempting to dynamically grow/shrink and add/remove attributes.

Also, ThreeJS typically expects indices and positions to exist. Things may break without these attributes set.

You will need THREE r82 or newer if you wish to dynamically grow and shrink vertex buffers.

License

MIT, see LICENSE.md for details.