Draco compression and node JS?

Alright I have tried https://www.npmjs.com/package/draco3dgltf and poured over [Solved] GLTFLoader DRACOLoader in nodejs from some while back.

I tried following the above question verbatim but ran into a “cant find ‘fs’ error” that sent me down another rabbit hole. I’m just trying to use draco compression with GLTF loader, in node.

I have the GLTF loader working well with

var loader = new THREE.GLTFLoader();
// const decoder = require('draco3dgltf').createDecoderModule();

// loader.setDRACOLoader(decoder);

//https://blackthread.io/gltf-converter/
loader.load(
  // resource URL
  string,
  // called when the resource is loaded
  function ( gltf ) {

But the commented out parts w draco obviously dont work. What was the consensus with using draco compression in node js?

Hi.

I guess you want to open a GLB Draco compressed file under nodejs, isn’t it?

Here one one example to load a list of GLB files:

// ---------------------------------------------------------------------------------------------------------
// - REQUIREMENTS:
// ---------------------------------------------------------------------------------------------------------
	var  start = Date.now();
	var  before = Date.now();
	var  fs = require("fs")
	require('jsdom-global')()
	global.DOMParser = window.DOMParser
	var DOMParser = window.DOMParser
	global.THREE = require('three')
	require('./node_modules/three/examples/js/loaders/DRACOLoader.js')
	require('./node_modules/three/examples/js/loaders/GLTFLoader.js')

// ---------------------------------------------------------------------------------------------------------
// - ARGUMENTS::
// ---------------------------------------------------------------------------------------------------------
	var listFile = process.argv[2]; // Plain text with filenames separated by lines (each line one filename)
	var inFolder = process.argv[3]; // Input folder where glb files are allocated
	before = Date.now();

// ---------------------------------------------------------------------------------------------------------
// - FUNCTIONS:
// ---------------------------------------------------------------------------------------------------------
function toArrayBuffer(buf) {
	var ab = new ArrayBuffer(buf.length);
	var view = new Uint8Array(ab);
	for (var i = 0; i < buf.length; ++i) {
		view[i] = buf[i];
	}
	return ab;
}

// ---------------------------------------------------------------------------------------------------------
// - GLOBAL VARIABLES::
// ---------------------------------------------------------------------------------------------------------
var fileArray = fs.readFileSync(listFile, 'utf8').toString().split("\n");
console.log(fileArray);
var glbLoader = new THREE.GLTFLoader();
glbLoader.setDRACOLoader( new THREE.DRACOLoader() );

for (var i=0; i<fileArray.length-1;i++) {
	var inFilename = inFolder + fileArray[i];
	console.log("opening file " + inFilename);
	if (fs.existsSync(inFilename)) {
		console.log("loading glb " + inFilename);
		var data = fs.readFileSync(inFilename);
		var arrayBuffer = toArrayBuffer(data);
		console.log(arrayBuffer);
		glbLoader.parse( arrayBuffer, '', function ( glb ) {
			console.log(glb.scene);
		}, function (event){
			console.log(event);
			console.log("loader failed");
		} );
	} else {
		console.log("File doesn't exist " + inFilename);
	}
}

Best regards