serializeStage function
Reads scene's stage render settings back into document's stage.
The reverse of realizeStage. An environment the realizer produced
recovers its source spec, and an fmat sky loaded through loadFmatSky
recovers its source path plus every parameter assigned through its typed
setters; a hand-built EnvironmentMap serializes as the studio default
and a custom ShaderSkySource is dropped, each with a warning.
Implementation
void serializeStage(Scene scene, SceneDocument document) {
final stage = document.stage;
stage.environmentIntensity = scene.environmentIntensity;
stage.exposure = scene.exposure;
stage.toneMapping = scene.toneMapping.name;
stage.antiAliasingMode = scene.antiAliasingMode.name;
stage.renderScale = scene.renderScale;
stage.filterQuality = scene.filterQuality.name;
final skyEnvironment = scene.skyEnvironment;
if (skyEnvironment == null) {
stage.skyEnvironment = null;
final environment = scene.environment;
var spec = environment == null ? null : _environmentSpec[environment];
if (spec == null && environment != null) {
// An environment the app loaded itself still recovers when it carries
// its asset-path stamp (EnvironmentMap.fromAssets).
final assetPath = environmentAssetPathOf(environment);
if (assetPath != null) spec = AssetEnvironment(AssetRef(assetPath));
}
if (spec != null) {
stage.environment = spec;
} else {
if (environment != null) {
debugPrint(
'fscene: the scene environment was not produced by realizeStage '
'or EnvironmentMap.fromAssets and cannot be recovered; serializing '
'the studio default',
);
}
stage.environment = const StudioEnvironment();
}
} else {
final source = _serializeSkySource(skyEnvironment.source);
stage.skyEnvironment = source == null
? null
: SkyEnvironmentSpec(
source,
refresh: skyEnvironment.refresh.name,
intervalSeconds: skyEnvironment.interval.inMicroseconds / 1e6,
faceResolution: skyEnvironment.faceResolution,
equirectWidth: skyEnvironment.equirectWidth,
);
}
final skybox = scene.skybox;
if (skybox == null) {
stage.skybox = null;
} else {
final source = _serializeSkySource(skybox.source);
stage.skybox = source == null
? null
: SkyboxSpec(source, intensity: skybox.intensity);
}
}