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

keyframe-resample

v0.1.0

Published

Resamples and optimizes keyframe data using WebAssembly

Downloads

16,628

Readme

keyframe-resample-wasm

Latest NPM release Build Status

Resamples and optimizes keyframe data using WebAssembly. Minzipped size is about 6-7 kb.

Installation

npm install --save keyframe-resample

Compatibility

The keyframe-resample module will load a WebAssembly binary as a static resource, as described in Web.Dev: Bundling non-JavaScript resources . This method in compatible with Node.js, most browsers, and applications compiled with a modern bundler. For older bundlers, a keyframe-resample/compat module is also available, loading the WebAssembly binary from an inline Data URI. The compatibility build is a couple kilobytes larger, and requires more time to process the WebAssembly binary.

API

import { ready, resample } from 'keyframe-resample'; // Node.js, browsers, and modern bundlers
import { ready, resample } from 'keyframe-resample/compat'; // Legacy bundlers

// wait for WASM to compile
await ready;

// keyframe times, in seconds
const srcTimes = new Float32Array([0, 0.1, 0.2, 0.3, 0.4]);

// keyframe values, N-dimensional vectors
const srcValues = new Float32Array([
    0, 0, 1,
    0, 0, 2,
    0, 0, 3,
    0, 0, 4,
    0, 0, 5,
]);

// resample keyframes, remove those unnecessary with interpolation.
const count = resample(srcTimes, srcValues, 'lerp');

// results are written to start of source array.
const dstTimes = srcTimes.slice(0, count); // → [0, 0.4]
const dstValues = srcValues.slice(0, count * 3); // → [0, 0, 1, 0, 0, 5]

In addition to the resample(...) function implemented in WebAssembly, a resampleDebug(...) function implemented in plain JavaScript is also exported. The WebAssembly implementation runs considerably faster.

Exports

| export | description | |--------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------| | | | | ready: Promise<void> | Promise resolving when WASM is initialized and module is ready for use. | | | | | resample( times: Float32Array, values: Float32Array, interp: 'step' | 'lerp' | 'slerp', tolerance = 1e4) | WebAssembly implementation of keyframe interpolation. | | | | | resampleDebug( times: Float32Array, values: Float32Array, interp: 'step' | 'lerp' | 'slerp', tolerance = 1e4) | JavaScript implementation of keyframe interpolation. |

Interpolation modes

| mode | description | |-----------|-------------------------------------------------------------| | 'step' | Step (also called discrete or constant) interpolation. | | 'lerp' | Linear, per-component interpolation. | | 'slerp' | Spherical linear interpolation, valid only for quaternions. |

Contributing

To build the project locally, run:

npm install
npm run dist

To test changes:

npm run test
npm run benchmark

Optimizations and bug fixes are welcome. Please consider filing an issue to discuss possible feature additions.

License

Licensed under Blue Oak Model License 1.0.0.