[Solved] GLTFLoader DRACOLoader in nodejs

Hi again.

Very sorry.

I was loading glbs without DRACO compression, this was the reason that it worked:

I have modified the DRACOLoader.js just including the line:
const decoder = require('draco3dgltf').createDecoderModule();
after the line use strict at the beginning.

Let me attach my example: example.js

/* Instructions:
* Have node-v10.13.0-win-x64 installed
* set PATH=%PATH%;C:\Users\ua4192\Documents\Viewer3d\node-v10.13.0-win-x64
* node --max-old-space-size=32000  example.js  <input_file> <input_folder>
*                           <input_file> --> is a plain text with 1 filename (<filename>.glb) in each line
*                           <input_folder> --> is the folder where glb files are allocated.
* 
 * Example:
*            node --max-old-space-size=32000  Generate_CMS_Scene_toDeliver.js lista.txt c:\temp\

*/
// ---------------------------------------------------------------------------------------------------------
// - REQUIREMENTS:
// ---------------------------------------------------------------------------------------------------------
               var  start = Date.now();
               var  before = Date.now();
               var  fs = require("fs")
               global.THREE = require('three')
               //require('./node_modules/three/examples/js/libs/draco/draco_decoder.js');
               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();
               //THREE.DRACOLoader.setDecoderPath( './node_modules/three/examples/js/libs/draco/gltf/' );
               //THREE.DRACOLoader.setDecoderConfig({type: 'js'});
               
               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);
                              }
               }

COuld you tell me where is my mistake?

Many thanks in advanced.

1 Like