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]); // 42Iterate 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); // 3Ray 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]); // 42Limitations
Currently, only the following hard-coded tree structure/hierarchy is supported:
InternalNode2.DIM= 256InternalNode1.DIM= 64LeafNode.DIM= 8
─ ─┌┬┬┬──────────┬┬┬┐─ ─
|||| RootNode ||||
─ ─└┴┴┴─────┬────┴┴┴┘─ ─
┌─────────┴─────────┐
▼ ▼
┌───────────────┐ ┌───────────────┐ ┌─ ─ ─
| InternalNode2 | | InternalNode2 | |
└───────┬───────┘ └───────┬───────┘ └─ ─ ─
┌─────────┴─────────┐ └─────────┐
▼ ▼ ▼
┌───────────────┐ ┌───────────────┐ ┌───────────────┐ ┌─ ─ ─
| InternalNode1 | | InternalNode1 | | InternalNode1 | |
└───────┬───────┘ └───────┬───────┘ └───────┬───────┘ └─ ─ ─
┌─────────┴────┐ ┌┴─────────────┐ └────────┐
▼ ▼ ▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌─ ─ ─
| LeafNode | | LeafNode | | LeafNode | | LeafNode | | LeafNode | |
└──────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘ └─ ─ ─OpenVDB
- Origianl repo
- High-level summary of the terminology and basic components
- Cookbook with code examples
- Original paper from Ken Museth: VDB: High-Resolution Sparse Volumes with Dynamic Topology
- Ken Museth explaining VDB: OpenVDB: An Open Source Data Structure and Toolkit for High-Resolution Volumes
- VDB on GPU: Fast Fluid Simulations with Sparse Volumes on the GPU
- Raytracing Sparse Volumes with NVIDIA® GVDB in DesignWorks
Publish
npm loginyarn nx build vdbcd ./dist/libs/vdbnpm publish