Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
EbodShojaei opened this issue Aug 22, 2023 · 1 comment

Comments

@EbodShojaei
Copy link

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;
@Brakebein
Copy link
Owner

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 ] )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants