three-buffergeometry-sort

1.3.0 • Public • Published

three-buffergeometry-sort

I primarily made this so working with THREE.js BufferGeometry would be easier to work with. Some of this code is based on this StackOverflow post.

How to use

// Import this library
var BGSorter = require("three-buffergeometry-sort");

// Create your BufferGeometry with 'positions' attribute
this.points = new THREE.BufferGeometry();
this.points.addAttribute('position', positions);

// Initialize the sorter
var sorter = BGSorter();

function render() {
  // Sort positions in ascending order in terms of distance from camera every frame
  sorter.sort(this.points.attributes, cameraPosition);

  window.requestAnimationFrame(render);
}
window.requestAnimationFrame(render);

You can also make it sort every N frames

var sorter = BGSorter(5);

function render() {
  // Sort positions every 5 frames
  sorter.sort(this.points.attributes, cameraPosition);

  window.requestAnimationFrame(render);
}
window.requestAnimationFrame(render);

License

Mozilla Public License version 2

Package Sidebar

Install

npm i three-buffergeometry-sort

Weekly Downloads

3

Version

1.3.0

License

MPL-2.0

Last publish

Collaborators

  • frewsxcv