🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@nasedkinpv/opensubdiv-wasm

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nasedkinpv/opensubdiv-wasm

WebAssembly port of OpenSubdiv for Three.js - High-performance Catmull-Clark subdivision surfaces in the browser

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

@nasedkinpv/opensubdiv-wasm

WebAssembly port of Pixar's OpenSubdiv for browser and Node.js.

High-performance Catmull-Clark subdivision surfaces with Three.js integration.

Live Demo — WebGPU + HDR environment

Features

  • Catmull-Clark subdivision (levels 1-5)
  • Real-time animation via StencilTable caching
  • Zero-copy typed array access to WASM memory
  • Three.js BufferGeometry integration
  • Face-varying UV interpolation
  • Mixed quad/triangle mesh support

Bundle Size

FileSizeGzipped
opensubdiv.wasm163 KB60 KB
opensubdiv.mjs46 KB13 KB
Total209 KB72 KB

Installation

npm install @nasedkinpv/opensubdiv-wasm

Quick Start

Low-level WASM API

import OpenSubdiv from '@nasedkinpv/opensubdiv-wasm';

const module = await OpenSubdiv();

const positions = new Float32Array([
  -1, -1, 1,  1, -1, 1,  1, 1, 1,  -1, 1, 1,  // front
  -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1  // back
]);

const quadIndices = new Int32Array([
  0, 1, 2, 3,  // front
  5, 4, 7, 6,  // back
  4, 0, 3, 7,  // left
  1, 5, 6, 2,  // right
  3, 2, 6, 7,  // top
  4, 5, 1, 0   // bottom
]);

const mesh = new module.SubdivisionMesh();
mesh.initFromQuads(positions, quadIndices, 6, 2, module.BOUNDARY_EDGE_ONLY);

console.log('Vertices:', mesh.getVertexCount());
console.log('Triangles:', mesh.getTriangleCount());

const subdivided = mesh.getPositions();  // Float32Array
const normals = mesh.getNormals();       // Float32Array  
const indices = mesh.getIndices();       // Uint32Array

mesh.delete();  // Free WASM memory

Three.js Integration

import * as THREE from 'three';
import { SubdivisionSurface } from '@nasedkinpv/opensubdiv-wasm/threejs';

const surface = new SubdivisionSurface({ level: 2 });
await surface.init();

surface.initFromQuads(positions, quadIndices);
const geometry = surface.toBufferGeometry(THREE);

const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);

// Animation (fast path using cached stencils)
function animate() {
  modifyControlVertices(positions);
  surface.updatePositions(positions);
  surface.updateBufferGeometry(geometry);
}

surface.dispose();

API Reference

See THREEJS_USAGE.md for complete API documentation.

When loading the ESM build in a custom runtime or bundler, you can pass Emscripten module options such as locateFile() to control where opensubdiv.wasm is fetched from.

Performance

Benchmarked with 984 input vertices (quad mesh):

LevelOutput VertsTrianglesTimeThroughput
1~4K~8K~1.5ms~2,600 v/ms
2~16K~31K~5ms~3,000 v/ms
3~63K~126K~25ms~2,500 v/ms
4~251K~503K~120ms~2,100 v/ms
  • WASM init: ~17ms (one-time)
  • Level 2: Sweet spot for real-time (5ms for 16K verts)
  • Animation updates: Use pre-computed StencilTables, ~10-100x faster than re-subdivision

Building from Source

Requirements

# Homebrew (macOS)
brew install emscripten binaryen

# Or install via emsdk (cross-platform)
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk && ./emsdk install latest && ./emsdk activate latest

# Binaryen via npm is also supported
npm install -g binaryen

Build Commands

# Activate Emscripten if you installed it via emsdk
source /path/to/emsdk/emsdk_env.sh

# Full build (WASM + wasm-opt + TypeScript wrapper)
npm run build

# Quick build without wasm-opt (faster iteration)
npm run build:quick

# Run tests
npm test

Build Scripts

ScriptDescription
buildFull optimized build (WASM + wasm-opt + threejs)
build:quickSkip wasm-opt for faster iteration
build:wasmBuild CommonJS WASM module
build:wasm:esmBuild ES Module WASM module
build:wasm:optimizeRun wasm-opt -Oz on WASM binary
build:threejsCompile TypeScript wrapper

License

TOST-1.0 (Tomorrow Open Source Technology License - modified Apache 2.0)

Based on OpenSubdiv by Pixar Animation Studios.

Trademark Notice

This project is not affiliated with, endorsed by, or sponsored by Pixar Animation Studios, DreamWorks Animation, or any of their affiliates.

"OpenSubdiv", "Pixar", and "DreamWorks" are trademarks of their respective owners. Use of these names is solely for attribution purposes as required by the license.

Credits

See NOTICE.txt for full attribution.

Keywords

opensubdiv

FAQs

Package last updated on 09 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts