build_hooks library
Build-hook helpers for flutter_scene.
Call these from your app's hook/build.dart at build time: buildScenes
converts glTF (.glb) source assets into flutter_scene's .fsceneb
package format (loaded by source path with loadScene), buildMaterials
compiles .fmat custom-material files into a Flutter GPU shader bundle
plus a parameter sidecar, and buildTextures cooks loose images into the
engine's compressed .fstex texture container. In DataAssets mode, the
outputs are registered with the Flutter asset bundle and can be loaded by
source path through loadScene / loadFmatMaterial / loadTexture.
import 'package:hooks/hooks.dart';
import 'package:flutter_scene/build_hooks.dart';
void main(List<String> args) {
build(args, (config, output) async {
buildScenes(
buildInput: config,
buildOutput: output,
assetMode: SceneAssetMode.dataAssetsRequired,
);
await buildMaterials(
buildInput: config,
buildOutput: output,
materials: ['materials/toon.fmat'],
);
});
}
Enums
- MaterialAssetMode
-
Controls how buildMaterials exposes generated
.fmatshader assets. - SceneAssetMode
-
Controls how buildScenes exposes generated
.fscenebassets. - TextureAssetMode
-
Controls how buildTextures exposes generated
.fstexassets. - TextureContent Assets and loading
- What a texture's pixels represent, which controls how mip levels are downsampled so the result is correct (color must average in linear light, normals must be averaged as vectors and renormalized).
Functions
-
buildMaterials(
{required BuildInput buildInput, required BuildOutputBuilder buildOutput, List< String> ? materials, String bundleName = 'materials', String discoveryRoot = 'assets/', MaterialAssetMode assetMode = MaterialAssetMode.legacyOnly}) → Future<void> -
Compiles
.fmatcustom-material files into a Flutter GPU shader bundle plus a parameter-metadata sidecar, for use withShaderMaterial/PreprocessedMaterialat runtime. -
buildScenes(
{required BuildInput buildInput, required BuildOutputBuilder buildOutput, List< String> ? inputFilePaths, String outputDirectory = 'build/scenes/', String discoveryRoot = 'assets/', SceneAssetMode assetMode = SceneAssetMode.legacyOnly, bool compressTextures = false}) → void -
Registers scene assets so an app loads them by source path with
loadScenewithout hand-editing the asset manifest. Discovers three source kinds underdiscoveryRoot:.glb(converted to.fsceneb), authored.fscene(compiled to.fsceneb, with referenced images embedded and prefab instances intact for runtime compose), and already-built.fsceneb(an editor'simported/assets, registered as-is). Generated outputs go underoutputDirectory(relative toBuildInput.packageRoot); a passthrough.fscenebis registered in place. -
buildTextures(
{required BuildInput buildInput, required BuildOutputBuilder buildOutput, required List< String> textures, Map<String, TextureContent> contents = const {}, String outputDirectory = 'build/textures/', TextureAssetMode assetMode = TextureAssetMode.legacyOnly}) → void -
Cooks loose image assets into the engine's compressed texture container and
registers them so an app loads them by source path with
loadTexture.