使用obj2gltf遍历目录转换obj文件

const obj2gltf = require('obj2gltf');
// import obj2gltf from "obj2gltf";
const fs = require('fs');
const path = require('path');
fs.readdir(path.resolve('./Data'),(err, files)=>{
    console.log(arguments)
    if (!err) {
        files.forEach((file)=>{
            if (file.includes('Tile')) {
                fs.stat(path.join('Data',`${file}`), (err, stats)=>{
                    if (stats.isDirectory()) {
                        obj2gltf(path.join('Data',`${file}`,`${file}.obj`))
                            .then(function(gltf) {
                                const data = Buffer.from(JSON.stringify(gltf));
                                fs.writeFileSync(path.join('Data',`${file}`,`${file}.gltf`), data);
                            });
                    }
                });
            }
        });
    }
});

你可能感兴趣的:(javascript,threejs,gltf,3D)