importGltf function
void
importGltf(})
Takes an input model (glTF file) and
Implementation
void importGltf(String inputGltfFilePath, String outputModelFilePath,
{String? workingDirectory}) {
final packageRoot = findImporterPackageRoot();
final importer = findBuiltExecutable('importer', packageRoot);
// Parse the paths via Uri.file/Uri.directory and use resolveUri to resolve
// the paths relative to the working directory. Using raw strings doesn't
// bode well with Windows paths.
final inputGltfFilePathUri = Uri.file(inputGltfFilePath);
final outputModelFilePathUri = Uri.file(outputModelFilePath);
final workingDirectoryUri =
Uri.directory(workingDirectory ?? packageRoot.toFilePath());
inputGltfFilePath =
workingDirectoryUri.resolveUri(inputGltfFilePathUri).toFilePath();
outputModelFilePath =
workingDirectoryUri.resolveUri(outputModelFilePathUri).toFilePath();
//throw Exception('root $packageRoot input $inputGltfFilePath output $outputModelFilePath');
final importerResult = Process.runSync(
importer.toFilePath(),
[
inputGltfFilePath,
outputModelFilePath,
],
workingDirectory: workingDirectory);
if (importerResult.exitCode != 0) {
throw Exception(
'Failed to run importer: ${importerResult.stderr}\n${importerResult.stdout}');
}
}