Brakebein/node-three-gltf

TypeError: Cannot read properties of undefined (reading 'extensions')

EbodShojaei opened this issue · 1 comments

Hi there. I tried to replicate your example. My draco-compressed gltf file was not processed and console.logs were not generated. Was there something missing?

Error log:

TypeError: Cannot read properties of undefined (reading 'extensions')
    at GLTFTextureBasisUExtension.loadTexture (file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:792:25)
    at file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:1634:80
    at GLTFParser._invokeOne (file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:1590:28)
    at GLTFParser.getDependency (file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:1634:39)
    at GLTFParser.assignTexture (file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:1825:21)
    at GLTFMaterialsSpecularExtension.extendMaterialParams (file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:776:33)
    at file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:1948:56
    at GLTFParser._invokeAll (file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:1601:28)
    at GLTFParser.loadMaterial (file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:1947:43)
    at file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:1631:81
file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:792
        if (!textureDef.extensions || !textureDef.extensions[this.name]) {
                        ^

TypeError: Cannot read properties of undefined (reading 'extensions')
    at GLTFTextureBasisUExtension.loadTexture (file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:792:25)
    at file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:1634:80
    at GLTFParser._invokeOne (file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:1590:28)
    at GLTFParser.getDependency (file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:1634:39)
    at GLTFParser.assignTexture (file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:1825:21)
    at GLTFMaterialsSpecularExtension.extendMaterialParams (file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:776:33)
    at file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:1948:56
    at GLTFParser._invokeAll (file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:1601:28)
    at GLTFParser.loadMaterial (file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:1947:43)
    at file:///C:/Users/Node-Three-GLTF-Test/node_modules/node-three-gltf/build/index.js:1631:81

Node.js v18.14.0

index.js:

// Import Express, set up the homepage route, and use only ES modules
import express from 'express';
import loadModel from './src/js/loadModel.js';

const app = express();
const port = 3000;

app.get('/', async (req, res) => {
    const fileData = await loadModel();
    console.log('What is this?', fileData);
}
);

app.listen(port, () => {
    console.log(`Example app listening at http://localhost:${port}`);
}
);

/js/loadModel.js:

import { DRACOLoader, GLTFLoader, loadGltf } from 'node-three-gltf';
import fs from 'fs';

const loadModel = async () => {
    const filePath = './src/assets/dracoModel.gltf';

    if (!fs.existsSync(filePath)) {
        console.log('File not found');
        return;
    };
    
    // init GLTFLoader and pass a path to a local file or a url to a web resource
    const loader = new GLTFLoader();
    loader.setDRACOLoader(new DRACOLoader());

    loader.load(filePath, gltf => {
        console.log(gltf.scene.children);
    });

    // there is also a small utility function that instantiates GLTFLoader and DRACOLoader
    // and returns a Promise with the loaded content
    const gltf = await loadGltf(filePath);
    console.log(gltf.scene.children);
};

export default loadModel;

Have you tried your file with the original (frontend) GLTFLoader of three.js? Considering the line where error is thrown, it looks like that your gltf file has some wrong texture indices.

const textureDef = json.textures[ textureIndex ];

if ( ! textureDef.extensions || ! textureDef.extensions[ this.name ] )