buildMaterials function

Future<void> buildMaterials({
  1. required BuildInput buildInput,
  2. required BuildOutputBuilder buildOutput,
  3. List<String>? materials,
  4. String bundleName = 'materials',
  5. String discoveryRoot = 'assets/',
  6. MaterialAssetMode assetMode = MaterialAssetMode.generatedTree,
  7. bool? debugViews,
})

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.

debugViews compiles the surface debug views into the materials. It defaults to the app's flutter_scene_debug_views hook user-define (a hook cannot read flutter_scene's own debug_views), so set both. Without it the materials draw through the fallback debug shader while a view is active.

Implementation

Future<void> buildMaterials({
  required BuildInput buildInput,
  required BuildOutputBuilder buildOutput,
  List<String>? materials,
  String bundleName = 'materials',
  String discoveryRoot = 'assets/',
  MaterialAssetMode assetMode = MaterialAssetMode.generatedTree,
  bool? debugViews,
}) => _buildMaterials(
  buildInput: buildInput,
  buildOutput: buildOutput,
  materials: materials,
  bundleName: bundleName,
  discoveryRoot: discoveryRoot,
  assetMode: assetMode,
  debugViews: debugViews ?? HookOptions.of(buildInput).debugViews,
);