This is a convenience library to support processing of Khronos glTF files. It is inspired by Fabrice Robinet's glTF-parser.js but provides some convenience functionality and is available as NPM package.
$ npm install gltf-walker
- Callbacks for all components in order of dependencies textures
- Resolves named references in JSON to real object references in JavaScript
- Buffers: Creates ArrayBuffer objects from data URLs
- Shaders: Creates strings from data URLs
- Resolve relative URIs (optional)
var walker = require("gltf-walker");
var json = JSON.parse(/* glTF file here */);
// Callbacks for all components, called in order of dependencies
walker(json, {
buffers: function (buffer, id) {
console.log(buffer._buffer); // Only set if buffer is defined as data URL
console.log(buffer._uri); // Only set if buffer is not a data URL and baseURL is defined
},
materials: function (material, id) {
},
images: function (image, id) {
},
...
default: function (desc, id) {
// Callback for all categories that do not have a dedicated callback
}
}, {
// Optional user context object.
// Available as 'this' in callbacks
context: null,
// The library will resolve relative
// URLs, if this (optional) base URL is defined
baseURL: null
});
- Fetch external resources (optional)
MIT License (MIT)