JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q24548F
  • License MPL 2.0

JavaScript implementation of OpenVDB.

Package Exports

  • vdb-js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (vdb-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

vdb-js

JavaScript implementation of OpenVDB.

The idea is to keep the code as close as possible to the original source.

Usage

JavaScript

Set/get voxel (with cached access)

let vdb = require('vdb-js');

let grid = new vdb.Grid(-1);
let accessor = grid.getAccessor();

accessor.setValueOn([0, 0, 0], 42);
accessor.getValue([0, 0, 0]); // 42

Iterate over active voxels

accessor.setValueOn([2, 1, 0], 42);
accessor.setValueOn([845, 64, 242], 42);
accessor.setValueOn([1000, 200000, 4000], 42);

let counter = 0;
for (const voxel of grid.beginVoxelOn()) {
  counter++;
  console.log(voxel.value); // 42
}

console.log(counter); // 3

Ray intersection

let eye = new vdb.Vec3(0, -1, 0);
let direction = new vdb.Vec3(0, 1, 0);
let ray = new vdb.Ray(eye, direction);

let intersector = new vdb.VolumeRayIntersector(grid);

if (intersector.setIndexRay(ray)) {
  console.log('Ray intersects!');
}

let start = [0, -10, 0];
let end = [0, 10, 0];
let timeSpanRef = new vdb.TimeSpan(start, end);

intersector.marchUntilEnd(timeSpanRef);

console.log('first hit of active tile/leaf:', timeSpanRef.t0);
console.log('first hit of inactive tile or exit point of BBOX for leaf nodes:', timeSpanRef.t1);

TypeScript

import { Grid } from 'vdb-js';

const grid = new Grid(-1);
const accessor = grid.getAccessor();

accessor.setValueOn([0, 0, 0], 42);
accessor.getValue([0, 0, 0]); // 42

Limitations

Currently, only the following hard-coded tree structure/hierarchy is supported:

  • InternalNode2.DIM = 256
  • InternalNode1.DIM = 64
  • LeafNode.DIM = 8
                        ─ ─┌┬┬┬──────────┬┬┬┐─ ─
                           |||| RootNode ||||
                        ─ ─└┴┴┴─────┬────┴┴┴┘─ ─
                          ┌─────────┴─────────┐
                          ▼                   ▼
                  ┌───────────────┐   ┌───────────────┐   ┌─ ─ ─
                  | InternalNode2 |   | InternalNode2 |   |
                  └───────┬───────┘   └───────┬───────┘   └─ ─ ─
                ┌─────────┴─────────┐         └─────────┐
                ▼                   ▼                   ▼
        ┌───────────────┐   ┌───────────────┐   ┌───────────────┐   ┌─ ─ ─
        | InternalNode1 |   | InternalNode1 |   | InternalNode1 |   |
        └───────┬───────┘   └───────┬───────┘   └───────┬───────┘   └─ ─ ─
      ┌─────────┴────┐             ┌┴─────────────┐     └────────┐
      ▼              ▼             ▼              ▼              ▼
┌──────────┐   ┌──────────┐   ┌──────────┐   ┌──────────┐   ┌──────────┐   ┌─ ─ ─
| LeafNode |   | LeafNode |   | LeafNode |   | LeafNode |   | LeafNode |   |
└──────────┘   └──────────┘   └──────────┘   └──────────┘   └──────────┘   └─ ─ ─

OpenVDB

Publish

  1. npm login
  2. yarn nx build vdb
  3. cd ./dist/libs/vdb
  4. npm publish