Norse Polytheistic Mythology

    vdb-js
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.5 • Public • Published

    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

    Install

    npm i vdb-js

    DownloadsWeekly Downloads

    2

    Version

    0.0.5

    License

    MPL 2.0

    Unpacked Size

    167 kB

    Total Files

    74

    Last publish

    Collaborators

    • philippemorier
    • philippe.morier