buildMaterials function
- required BuildInput buildInput,
- required BuildOutputBuilder buildOutput,
- List<
String> ? materials, - String bundleName = 'materials',
- String discoveryRoot = 'assets/',
- MaterialAssetMode assetMode = MaterialAssetMode.generatedTree,
Compiles .fmat custom-material files into a Flutter GPU shader bundle plus
a parameter-metadata sidecar, for use with ShaderMaterial /
PreprocessedMaterial at runtime.
Call this from a consuming app's hook/build.dart, alongside
buildScenes and buildShaderBundleJson:
import 'package:hooks/hooks.dart';
import 'package:flutter_scene/build_hooks.dart';
void main(List<String> args) {
build(args, (config, output) async {
await buildMaterials(
buildInput: config,
buildOutput: output,
materials: ['assets/toon.fmat'],
);
});
}
Each path in materials is resolved relative to the package root. If
materials is omitted, .fmat files under discoveryRoot (default
assets/, the same root buildScenes discovers .glb sources under) are
discovered automatically; set discoveryRoot to search a different
directory.
The bundle carries one fragment entry per material, named by the material's
name, alongside a combined parameter sidecar and an index. They are written
into the app's flutter_scene_generated/ directory, and loadFmatMaterial
resolves them by source path.
The generated shaders #include flutter_scene's framework GLSL; this hook
puts flutter_scene's shaders/ directory on impellerc's include path (via
buildShaderBundleJson's includeDirectories), so no framework files are
copied into the consumer's project.
Implementation
Future<void> buildMaterials({
required BuildInput buildInput,
required BuildOutputBuilder buildOutput,
List<String>? materials,
String bundleName = 'materials',
String discoveryRoot = 'assets/',
MaterialAssetMode assetMode = MaterialAssetMode.generatedTree,
}) => _buildMaterials(
buildInput: buildInput,
buildOutput: buildOutput,
materials: materials,
bundleName: bundleName,
discoveryRoot: discoveryRoot,
assetMode: assetMode,
);