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

Transformed output path problem #139

Open
josemurillodev opened this issue Mar 18, 2022 · 0 comments
Open

Transformed output path problem #139

josemurillodev opened this issue Mar 18, 2022 · 0 comments

Comments

@josemurillodev
Copy link

josemurillodev commented Mar 18, 2022

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

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

1 participant