flutter_scene README

The project's README from github.com/bdero/flutter_scene. As one markdown file: README.md.

Flutter Scene

Flutter Scene

A complete 3D game engine for Flutter, built on Flutter GPU

Rendering, physics, audio, animation, a scene editor with an MCP server, and a full asset pipeline, on every platform Flutter runs on, web included. Built and maintained by the author of Flutter GPU.

Covered by Argos Visual Testing

Website · Docs · Examples App · Games · FAQ

Physically based rendering of the glTF DamagedHelmet sample with image-based lighting in Flutter Scene

Dashsurfers, an endless runner game built with Flutter Scene

The Flutter Scene Editor, driven by a coding agent over MCP

At a glance

Built with Scene

Why Scene exists

Scene began its life inside the Flutter Engine, as a C++ module for Impeller with a declarative widget interface exposed through a 3D API in the Flutter SDK. Flutter GPU was built initially to set this project free, providing the low-level GPU access needed to develop Scene outside the engine, as an ordinary ecosystem of Dart packages.

That origin shapes the project's philosophy. Scene is a full 3D game engine and toolkit that makes Flutter GPU practical to build on, spanning rendering, physics, audio, editor tooling, and asset support across every target Flutter runs on. And the relationship flows both ways by design. Scene's cross-backend render tests are where Flutter GPU regressions get caught, so Impeller and Flutter GPU get better because Scene exists.

The goal has always been to pave the way for advanced graphics in Flutter. In line with the goals set out in Flutter GPU's original design doc, Scene aims to de-fracture, unite, and elevate Flutter's graphics ecosystem, so that building incredible 3D experiences with Flutter and Dart no longer requires engine forks, complicated external renderer integrations, or giving up platforms to get advanced features.

Scene is built by the author of Flutter GPU, a former core Flutter engine team member who spent four years on Flutter, most of it building Impeller.

Getting started

flutter pub add flutter_scene
dart run flutter_scene:init

init sets up the asset pipeline, which is the recommended way to use Scene. Drop sources under assets/, load them by their source path, and render:

final level = await loadScene('assets/level.glb');
scene.add(level);
// ...
SceneView(scene, cameraBuilder: (elapsed) => PerspectiveCamera(...));

The same code runs on web, and the engine's shaders are compiled for you during the build by flutter_scene's own build hook. Rendering goes through Flutter GPU, which is off by default, so enable it once per platform (below). The web needs nothing.

Impeller, which Flutter GPU builds on, is the default renderer on every native platform as of 3.47, so there is nothing to do for it.

Coding agents

This package ships a set of agent skills so a coding assistant writes idiomatic Scene instead of guessing: correct usage and traps, the run-settle-capture verification loop, copy-paste look presets, procedural content, and performance. dart run flutter_scene:init offers to install them, and dart run flutter_scene:skills installs, updates, or checks them on their own without touching your build hook. Upgrading Scene can carry newer revisions; dart run flutter_scene:skills --check reports whether any are available.

Enable Flutter GPU

While developing, pass the flags on the command line:

flutter run --enable-flutter-gpu

To turn it on permanently, for every run and for the app you ship, edit the platform file:

Platform File Add
iOS ios/Runner/Info.plist <key>FLTEnableFlutterGPU</key><true/>
Android android/app/src/main/AndroidManifest.xml, in <application> <meta-data android:name="io.flutter.embedding.android.EnableFlutterGPU" android:value="true" />
macOS macos/Runner/Info.plist <key>FLTEnableFlutterGPU</key><true/>
Web nothing

Windows and Linux set it on the DartProject their runner builds. This needs Flutter 3.47.1.

// linux/runner/my_application.cc
g_autoptr(FlDartProject) project = fl_dart_project_new();
fl_dart_project_set_enable_flutter_gpu(project, TRUE);
// windows/runner/main.cpp
flutter::DartProject project(L"data");
project.set_enable_flutter_gpu(true);

On 3.47.0 there is no such setting, so desktop takes the command-line flags per run, and release builds compile the engine's environment switches out, meaning a shipped Windows or Linux release needs 3.47.1.

A scene with no assets

The built-in geometry needs no asset pipeline, so a cube renders straight after flutter pub add flutter_scene:

import 'package:flutter/material.dart';
import 'package:flutter_scene/scene.dart';
import 'package:vector_math/vector_math.dart' as vm;

void main() => runApp(const MaterialApp(home: CubeView()));

class CubeView extends StatefulWidget {
  const CubeView({super.key});

  @override
  State<CubeView> createState() => _CubeViewState();
}

class _CubeViewState extends State<CubeView> {
  final Scene scene = Scene();
  bool ready = false;

  @override
  void initState() {
    super.initState();
    // Geometry and materials touch the shader bundle, so build them once the
    // engine's static resources are up.
    Scene.initializeStaticResources().then((_) {
      scene.add(
        Node(
          mesh: Mesh(
            CuboidGeometry(vm.Vector3(1, 1, 1)),
            PhysicallyBasedMaterial(),
          ),
        ),
      );
      if (mounted) setState(() => ready = true);
    });
  }

  @override
  Widget build(BuildContext context) {
    if (!ready) return const SizedBox.expand();
    return SceneView(
      scene,
      camera: PerspectiveCamera(position: vm.Vector3(2, 2, -4)),
    );
  }
}

The scene's default studio environment lights it, so there is nothing else to set up.

Moving a node

Every Node carries a transform relative to its parent. Read and write it one component at a time, or as a whole matrix through node.localTransform.

node.position = vm.Vector3(0, 1, 0);
node.rotation = vm.Quaternion.axisAngle(vm.Vector3(0, 1, 0), 0.5);
node.scale = vm.Vector3.all(2);
node.position += vm.Vector3(0, 0.1, 0);

Each getter returns a copy, so node.position.y = 1 moves nothing. Assign the value back instead. Debug builds throw on an edit that cannot reach the node, whether it is to a returned copy or to localTransform in place.

Built-in geometry

Every class below builds vertex data for you and drops into a Mesh the same way CuboidGeometry does above.

The asset pipeline

init writes a hook/build.dart that converts your assets at build time, creates flutter_scene_generated/ with a .gitignore for its outputs, and adds that one directory to flutter.assets in your pubspec.yaml. It is safe to run again, and it will not overwrite a hook/build.dart you wrote yourself. It prints a block to paste into your existing build() callback instead.

The hook it writes discovers .glb and .fscene models, .fmat materials, and loose images under assets/, and converts each one:

// hook/build.dart
import 'package:flutter_scene/build_hooks.dart';
import 'package:hooks/hooks.dart';

void main(List<String> args) async {
  await build(args, (input, output) async {
    buildScenes(buildInput: input, buildOutput: output);
    await buildMaterials(buildInput: input, buildOutput: output);
  });
}

The one line it adds to your pubspec.yaml:

flutter:
  assets:
    - flutter_scene_generated/

Upgrading from an earlier version, run it again. Generated assets now go into that directory on every Flutter release, so re-running init migrates the hook it wrote and adds the pubspec entry. A hook still asking for a removed asset mode fails the build and names its replacement.

From then on, drop sources under assets/ and load them by source path:

final level = await loadScene('assets/level.glb');
final toon = await loadFmatMaterial('assets/toon.fmat');
final ground = await loadTexture('assets/ground.png');

A .glb has to be parsed and unpacked into GPU-ready form every time the app loads it. The pipeline does that work once, at build time, into the .fsceneb format the engine reads directly, so loading a model at runtime costs far less. Prefer it for anything that ships with your app. It is also how .fmat custom materials and block-compressed textures with full mip chains reach you, and editing any source reconverts just that source and hot reloads it.

Loose images cook to the engine's own .fstex by default. For a smaller download, cook color textures to standard ETC1S KTX2 instead, several times smaller at some cost in quality:

buildTextures(
  buildInput: input,
  buildOutput: output,
  textures: ['assets/ground.png', 'assets/ground_normal.png'],
  encoding: const TextureEncoding.etc1s(quality: 128),
  // Normal maps keep more detail in the default encoding.
  encodings: {'assets/ground_normal.png': TextureEncoding.universal},
);

Keep your sources in version control. The generated directory holds compiled output tied to the Flutter engine that built it, which is why the hook manages its .gitignore for you.

For a model that only exists once the app is running, because you download it or the user supplies it, import the .glb directly with Node.fromGlbAsset('assets/model.glb'). That needs no hook, and it parses the glTF on every load, so prefer the pipeline whenever the model ships with you.

Where to go next

fscene.dev carries the full documentation. Your first scene renders something on screen from here, and the guides cover each subsystem in depth with live demos, including assets and loading, materials, lighting and environment, animation, and cameras. The API reference documents every public symbol.

Requirements

Flutter Scene is pre-1.0 and evolving quickly. Minor releases can carry breaking changes, and every change is documented in the CHANGELOG.

Features

Rendering

Materials and shaders

Assets and animation

App integration

Ecosystem

A 3D platformer game running on Flutter Scene

Depth of field and bloom post-processing on a glTF model

Rigid-body physics through flutter_scene_rapier

Instanced rendering of thousands of animated meshes

A custom sky material written in GLSL through the .fmat format

Skinned, animated glTF characters cloned across a scene

3D Gaussian splatting rendered as a scene node

Dashmap, a streaming 3D world map built on Flutter Scene

FAQ

Q: What platforms does this package support?

On native platforms flutter_scene runs anywhere Impeller does. On the web it runs on a built-in WebGL2 backend.

Every native platform needs Flutter GPU turned on. Impeller, which it builds on, is already the default everywhere. Enable Flutter GPU has the file and the key for each.

On the web, no flags are needed; it works under both the CanvasKit and Skwasm renderers.

Platform Status
iOS 🟢 Supported
Android 🟢 Supported
Web 🟢 Supported
MacOS 🟢 Supported
Windows 🟢 Supported (3.47.1 to ship a release)
Linux 🟢 Supported (3.47.1 to ship a release)
Custom embedders 🟢 Supported

Q: How does web support work?

Impeller and Flutter GPU aren't available on the web, so flutter_scene ships a built-in WebGL2 backend (a drop-in for flutter_gpu) and renders through it there. It works under both the CanvasKit and Skwasm web renderers, with no extra flags or configuration.

Sponsors

Scene's development is funded by its sponsors, listed in full at fscene.dev/sponsors. Anyone can sponsor through GitHub Sponsors, from $5 a month. Company tiers are at fscene.dev/sponsors.

Silver

Primio

Infrastructure

To sponsor Scene, write to [email protected].

Repository

This repository is a pub workspace containing the engine, its companion packages, and the example apps:

Path Description
packages/flutter_scene The 3D engine, including the glTF importer, the .fscene format, and the web (WebGL2) backend. Published to pub.dev as flutter_scene.
packages/flutter_scene_rapier Rapier physics backend, shipping prebuilt native binaries and a wasm module. Published to pub.dev as flutter_scene_rapier.
packages/flutter_scene_box3d box3d physics backend. Published to pub.dev as flutter_scene_box3d.
packages/flutter_scene_soloud SoLoud audio backend. Published to pub.dev as flutter_scene_soloud.
packages/flutter_scene_fmod FMOD Studio audio backend. Published to pub.dev as flutter_scene_fmod.
packages/flutter_scene_net Multiplayer on dashwire, binding replicated state to scene nodes with interpolated transforms and in-app hosting. Published to pub.dev as flutter_scene_net.
packages/flutter_scene_input Rebindable input actions for keyboard, mouse, gamepads, and pointer lock, with contexts, rebinding, and scene drivers. Published to pub.dev as flutter_scene_input.
packages/scene The engine-agnostic .fscene document core and the physics contract the backends implement. Published to pub.dev as scene.
packages/flutter_scene_codegen Static extraction and code generation for annotated components. A development-time tool, not published.
packages/flutter_scene_editor_core, packages/flutter_scene_editor, packages/flutter_scene_mcp The Flutter Scene Editor stack (headless command core, Flutter UI, and MCP tool surface). Shipped as the desktop app under apps/, not as pub.dev libraries. In active development.
apps/flutter_scene_editor_app The standalone Flutter Scene Editor desktop app.
examples/flutter_app Runnable example app with 43 feature examples.

The remaining examples/ folders are dev-only test harnesses (the web-backend smoke test, deterministic smoke renders, and a CPU stress bench).

To run the example app from a fresh clone:

flutter pub get                                             # resolves the workspace

cd examples/flutter_app
flutter create . --platforms=macos,ios,android,linux,windows,web  # generate gitignored platform stubs
flutter run --enable-flutter-gpu                              # native; add `-d <device>` if needed
flutter run -d chrome                                         # web

Pass --dart-define=FLUTTER_SCENE_PROFILE=true to print 120-frame render graph, culling, encoding, instance packing, binding, byte, draw, and instance summaries. Multiple active RenderViews share the counters.

flutter_scene (bdero/flutter_scene)

Searching Database…

这是什么?Flutter Scene 是一个面向 Flutter 的完整实时 3D 游戏引擎,涵盖基于物理的渲染、物理、音频、动画、场景编辑器和完整的资产管线,可在 Flutter 支持的所有平台上运行,包括 Web。
这是一个添加到现有 Flutter 应用中的库,还是自带应用的独立引擎?它是添加到你自己的应用中的 Dart/Flutter 软件包,构建在 Flutter GPU 之上的普通 Dart 包生态,而不是一个单独的独立引擎;它也附带了一个桌面场景编辑器作为配套工具。
怎么把它添加到 Flutter 项目中?运行「flutter pub add flutterscene」即可零配置渲染内置几何体,或运行「dart run flutterscene:init」接入构建期资产管线,由它替你转换 assets/ 下的模型。
渲染能正常工作之前需要开启什么吗?需要。在除 Web 之外的每个原生平台上,你都必须通过编辑平台文件(Info.plist、AndroidManifest.xml 或桌面端 DartProject)来一次性启用 Flutter GPU,并且需要 Flutter 3.47 或更新版本(已发布的 Windows/Linux 版本要求 3.47.1)。
这个 API 现在稳定到可以依赖它构建了吗?还不能完全算——Flutter Scene 尚未到 1.0,演进很快,小版本发布也可能引入破坏性变更,不过每次变更都记录在 CHANGELOG 中。
它实际能在哪些平台上运行?iOS、Android、macOS、Windows、Linux 和 Web——原生平台通过 Impeller/Flutter GPU 渲染,Web 则使用内置的 WebGL2 后端。
MCP 服务器和代理技能集成是做什么的?桌面场景编辑器提供一个 MCP 服务器用于代理驱动的编辑,该软件包还可以安装代理技能(通过 flutterscene:init 或 flutterscene:skills),让编程助手写出正确的 Scene 代码,包括「运行-稳定-捕获」验证循环和性能预设。
可以导入哪些资产格式?它可以导入 glTF(.glb/.gltf)、自有的 .fscene 场景文档、.fmat GLSL 自定义材质、KTX2 压缩纹理以及 HDR/EXR 环境贴图,并在构建时将它们转换为加载迅速的 .fsceneb 和 .fstex 格式。
作者为什么构建一个单独的引擎,而不是扩展 Flutter 的引擎?Scene 由创建 Flutter GPU 的前 Flutter 引擎团队成员构建,目标是把高级 3D 工作从引擎分支中解放出来,移入普通的 Dart 包生态;Scene 的跨后端测试也有助于发现 Flutter GPU 的回归问题。
它开箱即含物理和音频功能吗?是的——物理通过 Rapier 或 box3d 后端提供,空间音频通过 SoLoud 或 FMOD 提供,并通过 dashwire 支持多人游戏。
Creator
bdero
Size
24.7 MB
Stars
964
Age
2y
Commits · 90 Days