Skip to content

Transformed output path problem #139

Open
@josemurillodev

Description

@josemurillodev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions