realizeViews function

void realizeViews(
  1. SceneDocument document,
  2. Scene scene,
  3. Node root
)

Realizes document's serialized render views into scene's view list.

Call after realizing the node graph (the views' cameras are CameraComponent nodes in root, matched by their document ids) and adding root to scene. Views whose camera node or component is missing are skipped with a debug warning.

Implementation

void realizeViews(SceneDocument document, Scene scene, Node root) {
  for (final spec in document.views) {
    final node = _findNodeById(root, spec.cameraNode);
    if (node == null) {
      debugPrint(
        'fscene: skipping render view; camera node ${spec.cameraNode} '
        'was not found in the realized graph.',
      );
      continue;
    }
    final component = node.getComponents<CameraComponent>().firstOrNull;
    if (component == null) {
      debugPrint(
        'fscene: skipping render view; node ${spec.cameraNode} has no '
        'CameraComponent.',
      );
      continue;
    }
    scene.views.add(
      RenderView(
        camera: component.toCamera(),
        target: spec.target == null
            ? null
            : realizeRenderTexture(document, spec.target!),
        layerMask: spec.layerMask,
        order: spec.order,
        antiAliasingMode: spec.antiAliasingMode == null
            ? null
            : _enumByName(
                AntiAliasingMode.values,
                spec.antiAliasingMode!,
                AntiAliasingMode.auto,
              ),
        renderScale: spec.renderScale,
        filterQuality: spec.filterQuality == null
            ? null
            : _enumByName(
                ui.FilterQuality.values,
                spec.filterQuality!,
                ui.FilterQuality.medium,
              ),
      ),
    );
  }
}