0.0.1-61ded11 • Published 1 year ago

@needle-tools/usd v0.0.1-61ded11

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

Needle USD

USD wasm runtime and three.js hydra delegate.
Developed & maintained by Needle
For commercial use please contact hi@needle.tools

Install

npm install @needle-tools/usd

Use with Needle Engine

import { get } from "svelte/store";
import { activeFiles } from "..";
import { addPluginForNeedleEngine } from "@needle-tools/usd/plugins";

export function addUsdPlugin() {
    return addPluginForNeedleEngine({
        // USD files to load (first file must be the main file)
        getFiles: () => { return get(activeFiles) as Array<File & { path: string }> }
    })
}

Use with other three.js based viewers

See full example in examples

// Load the USD module
const usd = await getUsdModule();
// Load a USD file to be rendered by threejs
const handle = await createThreeHydra({
    USD: usd,
    scene: ctx.scene,
    usdz: "http://localhost:8081/v1/public/89aa693/89aa693/ImageTrackingNeedleSample.usdz",
})
// Call handle.update(dt) in your threejs update loop 

Low Level

Import

import { getUsdModule } from '@needle-tools/usd';

Load the Module

getUsdModule({
  // We need to override where the initial module is loaded from, 
  // since after bundling we can't rely on paths anymore
  mainScriptUrlOrBlob: "/emHdBindings.js",
}).then(async (Usd: USD) => {
    // use Usd here
});

Load a file into the virtual file system

const blob = await fetch("test.usdz");
const arrayBuffer = await blob.arrayBuffer();
// Create a file in the virtual file system
Usd.FS_createDataFile("", "test.usdz", new Uint8Array(arrayBuffer), true, true, true);

Load file into USD

let driver = new Usd.HdWebSyncDriver(delegate, "test.usdz");
if (driver instanceof Promise) driver = await driver;

// This kicks off asynchronous tasks to look at everything that has changed – _SyncAll –
// which will then call into the delegate to create and update the scene graph.
driver.Draw();

Useful References

Uses Asyncify to handle async calls in emscripten.

A synchronous call in C that waits for an asynchronous operation in JS to complete. https://emscripten.org/docs/porting/asyncify.html

Contact ✒️

🌵 NeedleGithubTwitterDiscordForumYoutube

0.0.1-61ded11

1 year ago

0.0.1-48f6760

1 year ago

0.0.1-412624

1 year ago

0.0.1-alpha.4

1 year ago

0.0.1-alpha.3

1 year ago

0.0.1-alpha.2

1 year ago

0.0.1-alpha.1

1 year ago

0.0.1-alpha

1 year ago