generate static method
Future<String>
generate(
- String root,
- String path, {
- NormalMapOptions options = const NormalMapOptions(),
Makes the normal map of the image at path (project-relative) under
root, beside it — <name>_normal.png, _2 and on when that is
taken — and gives its path.
Throws an ArgumentError for a path outside the project — absolute,
or climbing out with .. (a path read from a scene may) — or in a
package (packages/<name>/…, the package's own): nothing is written
there. The pixels are worked out off the UI's isolate.
Implementation
static Future<String> generate(
String root,
String path, {
NormalMapOptions options = const NormalMapOptions(),
}) async {
if (!ProjectFiles.isContained(path)) {
throw ArgumentError.value(
path,
'path',
'is outside the project: no normal map is made beside it',
);
}
if (PackageAssetPaths.isPackageKey(path)) {
throw ArgumentError.value(
path,
'path',
"is a package's: no normal map is made in it",
);
}
final picture = await Pixels.read('$root/$path');
final map = await compute(_make, (picture, options));
final dot = path.lastIndexOf('.');
final stem = dot <= path.lastIndexOf('/') ? path : path.substring(0, dot);
var n = 1;
String out() => '${stem}_normal${n == 1 ? '' : '_$n'}.png';
while (File('$root/${out()}').existsSync()) {
n++;
}
final made = out();
await map.writePng('$root/$made');
return made;
}