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

expand-vertex-data

v1.1.2

Published

Expand vertex, normal and uv indices into vertex normal and uv data that is ready for your array buffers

Downloads

50

Readme

expand-vertex-data npm version Build Status

Expand vertex, normal and uv indices into vertex normal and uv data that is ready for your WebGL element and array buffers

3d model file formats will typically encoded their position, normal and uv data across three separate position, normal and uv indices. This is great for maintaining a compact file, but poses a problem when you want to buffer your data onto the GPU.

WebGL supports one ELEMENT_ARRAY_BUFFER, so having three indexes for your vertex data is not an option.

expand-vertex-data makes your vertex data accessible using only one index (vertexPositionIndices) by creating new indices and duplicating data into those indices where necessary.

You only need to do this once, before creating your ARRAY_BUFFERs and ELEMENT_ARRAY_BUFFER.

You'll typically want to do this at runtime to save download time and disk space (at the one time expense of some CPU cycles).

In some cases you may wish to expand this data before runtime via a script to save CPU cycles (at the expense of persisting your larger expanded 3d model data to disk)

To Install

$ npm install --save expand-vertex-data

Usage

var fs = require('fs')

var colladaFile = fs.readFileSync('./some-collada-model.dae').toString()
var wavefrontFile = fs.readFileSync('./some-wavefront-model.obj').toString()

// Note, you can use a different parser, you'll just need to move your
// parsed data around to make sure that it conforms to `expand-vertex-data`'s
// expected format
var parsedCollada = require('collada-dae-parser')(colladaFile)
var parsedWavefront = require('wavefront-obj-parser')(wavefrontFile)

// Pass this data into your ELEMENT_ARRAY_BUFFER and ARRAY_BUFFERS
var expandedCollada = expandVertexData(parsedCollada)
var expandedWavefront = expandVertexData(parsedWavefront)

See something broken, confusing or ripe for improvement? Feel free to open an issue or PR!

API

expandVertexData(compressedVertexData, opts) -> expandedOutput

An object containing your model's vertex data. If you're using collada-dae-parser or wavefront-obj-parser you can pass their returned data right in.

If you're using your own parser, you're still all good. Just rename your parsed properties accordingly before passing them into expand-vertex-data

compressedVertexData.vertexPositionIndices

Required

Type: Array

compressedVertexData.vertexPositions

Required

type: Array

compressedVertexData.vertexNormalIndices

Optional

type: Array

compressedVertexData.vertexNormals

Optional

type: Array

compressedVertexData.vertexUVIndices

Optional

type: Array

compressedVertexData.vertexUVs

Optional

type: Array

compressedVertexData.vertexJointsAndWeights

Optional

type: Array

opts.facesToTriangles

Optional

type: Boolean

Use this when working with JSON that came from wavefront-obj-parser

Returned: expandedOutput

type: Object

In the Array lengths described below, n is the number of vertexPositionIndices that were returned after expansion

expandedOutput.positionIndices

type: Array[n]

Note that n will often times be more than the number of indices that you passed in. This is because more position indices will be created if your data needs to be expanded.

expandedOutput.positions

type: Array[n * 3]

expandedOutput.normals

type: Array[n * 3]

expandedOutput.uvs

type: Array[n * 2]

expandedOutput.jointInfuences

type: Array[n * 4]

There are four joint influences per vertex, even if there aren't four influencing joints. In cases where there is no joint there will be a weight of zero. This is because you need every joint to have the same number of weights when you vertex shader attributes.

expandedOutput.jointWeights

type: Array[n * 4]

An array of joint weights. A weight is a number between 0 - 1 that signifies how much the corresponding joint should affect the corresponding vertex.

There are four weights per vertex, even if there aren't four influencing joints. In cases where there is no joint there will be a weight of zero. This is because you need every joint to have the same number of weights when you vertex shader attributes.

TODO:

  • [ ] Support 3 weights per bone
  • [ ] Are we expanding as minimally as possible? Can our output be smaller?

To Test:

$ npm run test

See Also

License

MIT