CLI configuration not working? #854
-
Hi, I am new to glTF-Transform, and I would like to use it for a client project. The first thing I would like to do is a CLI tool that performs specific modifications of certain types of material, so I thought I'd use CLI configuration, i.e. extend the already functioning CLI. The docs page at https://gltf-transform.donmccurdy.com/cli.html says that I should provide a configuration mis file, which, in my case, is:
however, when I try to install the custom command
(of course using the right path):
I get error: Unknown command convertMaterials Am I doing something wrong? Thanks for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @robertoranon! You'll need to export a configuration definition, glTF Transform cannot detect new commands from the function declaration alone. Something like this should work: // Custom transform: convert materials
function convertMaterials(options) {
return (document) => {
for (const material of document.getRoot().listMaterials()) {
console.log(material);
}
};
}
export default {
onProgramReady: ({ program, io, Session }) => {
// Usage: https://caporal.io/
program
.command('convertMaterials', 'Convert materials')
.help('Lorem ipsum dolorem...')
.argument('<input>', 'Path to read glTF 2.0 (.glb, .gltf) model')
.argument('<output>', 'Path to write output')
.action(({ args, options, logger }) =>
Session.create(io, logger, args.input, args.output).transform(convertMaterials(options))
);
},
}; |
Beta Was this translation helpful? Give feedback.
-
@donmccurdy thanks, it works. For anyone coming to the same issue: after preparing the .mjs file as Don suggests, you need to call it as follows:
From the docs I somehow understood that I had to call a command to |
Beta Was this translation helpful? Give feedback.
Hi @robertoranon! You'll need to export a configuration definition, glTF Transform cannot detect new commands from the function declaration alone. Something like this should work: