pmndrs / gltfjsx

🎮 Turns GLTFs into JSX components
https://gltf.pmnd.rs
MIT License
4.71k stars 310 forks source link

Transformed output path problem #139

Open josemurillodev opened 2 years ago

josemurillodev commented 2 years ago

I have this process inside my models directory to convert my fbx to glb and then to jsx:

const convert = require('fbx2gltf');
const path = require('path');
const gltfjsx = require('gltfjsx/src/gltfjsx');

const assetsPath = __dirname;

const modelName = 'planet';
const modelExt = '.fbx';

const inFile = path.join(assetsPath, `${modelName}${modelExt}`);
const outFile = path.join(assetsPath, `${modelName}.glb`);
const outJsx = path.join(assetsPath, `${modelName}.js`);

const jsxOptions = {
  transform: true,
  root: assetsPath,
};

convert(inFile, outFile).then(
  destPath => {
    console.log(destPath);
    gltfjsx(outFile, outJsx, jsxOptions)
      .then((e) => { console.log(e); })
      .catch((e) => { console.log(e); });
  },
  error => {
    console.log(error);
  }
);

Everything works fine except for the transformed glb, this file is processed in the root directory, I updated these lines in gltfjsx.js file and then I get the expected results:

if (options.transform) {
          const { name } = path.parse(file)
          // Here
          const fileDir = path.dirname(file)
          const transformOut = path.join(fileDir, name + '-transformed.glb')
          if (options.setLog) options.setLog((state) => [...state, 'transforming ' + transformOut])
          await transform(file, transformOut, {})
          file = transformOut
}

Note: My script to run the process npm run models

  "scripts": {
    "prod": "webpack --config webpack.prod.js",
    "models": "node ./src/app/assets/models/process-models.js"
  },

Let me know if I'm doing something wrong or if I can create a pull request with those changes