flix3dengine 0.1.0
flix3dengine: ^0.1.0 copied to clipboard
A Flutter game engine package with a C++20 runtime and Dart FFI.
Flix3DEngine #
Flix3DEngine is a Flutter/Dart package with a C++20 native gameplay runtime. The native macOS target includes a first playable vertical slice, Shard Run: a first-person maze game with an SDL3 desktop window/input loop, a Metal 3D renderer, collision, mouse/keyboard/gamepad input, gravity and jumping, collectible shards, and an exit objective. The shared runtime exposes the same simulation state and input through Dart FFI.
Milestone 01 adds native math, camera and directional-light scene components,
owned mesh/material resources, and a public Flix3DController /
Flix3DView. The Flutter view draws a live, orbitable mesh preview with
perspective projection and directional diffuse shading. It is not a GPU
renderer: the separate native macOS game uses Metal, but that backend is not
embedded in Flutter.
What works today #
- Dart engine lifecycle with validated updates and a native frame counter.
- Scene entity collection with stable IDs, transforms, add/update/remove, and optional camera and directional-light components, and Flutter notifications.
- C++
Vec2,Vec3,Vec4, quaternion,Matrix4, and transform math. - Native scene camera/light components and validated PBR material handles exposed by opaque C ABI handles.
Flix3DControllermodel loading, camera/light state, and native OBJ resource lifetime management.Flix3DViewrenders a generated cube or imported model as animated, perspective-projected triangles with an adjustable camera lens and directional light.Flix3DEngineBuilderfor composing engine state into Flutter widgets.- Native C++ first-person movement, camera yaw/pitch, collision against a grid-based level, jump/gravity, collectible state, completion, and reset.
- SDL3 desktop windowing, keyboard, relative mouse, gamepad input, fullscreen toggle, and high-density resize handling.
- C++ level geometry rendered with a Metal perspective camera and depth buffer.
- Native C++ engine source compiled and bundled for supported application targets by a Dart build hook, loaded automatically through Dart FFI.
- Separate CMake targets with implemented C++20 functionality for core logging, runtime lifecycle, native scenes/entities/transforms, mesh processing, materials, OBJ import, and gameplay. Native scene and OBJ APIs use opaque handles over the C ABI.
- Native OBJ import generates missing normals, planar UVs and tangents, triangulates polygon faces, and exposes mesh attributes and indices through Dart FFI. This native importer currently supports OBJ only.
- Explicit shared-library loading remains available when passing a path to
Flix3DNativeRuntime.open. Flix3DGameTouchControlsfor a virtual joystick, touch-look, and jump input on mobile-sized Flutter game surfaces.Flix3DModelImporterreads triangle meshes from OBJ, glTF 2.0, and GLB 2.0, including normals, PBR material factors, and glTF position morph deltas.Flix3DModelStudioprovides file import/export, searchable starter assets, an orbit/zoom mesh preview, material factor editing, and scene placement.- 34 original low-poly procedural starter assets span vehicles, buildings, infrastructure, characters, nature, interiors, road props, and environment.
- CMake-built C++ shared library and native macOS SDL3/Metal game.
- Flame is not a dependency; consumers can compose the package's Flutter widgets into a Flame app. Dedicated Flame and Flame 3D adapters are not implemented.
The native Metal renderer remains a separate macOS game target. The Flutter model viewport is a software-rendered triangle preview with painter ordering, not the native renderer or a general-purpose GPU renderer; it has no depth buffer or texture sampling. Model import and editing are an early, deliberately bounded slice: FBX/USD/USDZ, decoded texture images, skinning, animation playback, applied glTF node transforms, full PBR, HDR, shadow maps, general physics, audio, particles, multiplayer, and AI/navigation are not implemented. The starter assets are editable low-poly prototypes, not production-ready or photorealistic models. The building, vehicle, character, animation, terrain, particle, scene, and prefab editors remain future work. Windows, Linux, Vulkan, OpenGL/OpenGL ES, DirectX 12, WebGPU, and mobile native 3D rendering backends are not implemented. Native C++ model import currently supports OBJ; glTF/GLB parsing is implemented by the Dart importer.
The native C++ architecture is an incremental foundation, not a complete
engine: the currently implemented CMake modules are FlixCore, FlixRuntime,
FlixWorld, FlixMesh, FlixMaterial, FlixAssets, and FlixGameplay.
Native glTF/GLB, FBX/USD, renderer/RHI backends beyond the separate macOS game
renderer, job/memory/profiling systems, general physics and animation, and
native asynchronous asset loading are not implemented.
Model import and asset studio #
The package exports the importer and model data types from
package:flix3dengine/flix3dengine.dart. OBJ polygons are triangulated and
optional MTL files provide basic diffuse color, roughness, metallic, and texture
path metadata. glTF/GLB import reads indexed triangle geometry, FLOAT VEC3
positions/normals, PBR base-color/metallic/roughness factors, and position
morph-target deltas. A glTF JSON file can reference embedded data or external
buffers; the studio prompts for sidecar files when needed.
Imported texture files are not decoded or rendered. Skinning and animation clips, glTF scene/node transforms, cameras, and lights are not evaluated; available camera/light/animation counts and unsupported content are reported as metadata or import warnings. Sparse accessors and non-triangle primitives are rejected. FBX, USD, and USDZ are rejected with an explicit unsupported-format message. OBJ export includes mesh geometry only; it does not emit MTL files or texture payloads.
Add the editor to an app and optionally bind it to a scene:
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => Flix3DModelStudio(scene: engine.scene),
),
);
In the example app, open Asset Studio to search and filter the 34 bundled procedural blockouts, import models, orbit/zoom previews, edit material factors, and place assets into the supplied Dart scene by dragging from the browser or using the add button. Mesh thumbnails are generated from each model. The viewport has move/rotate/scale gizmo controls and configurable grid snapping. The preview uses flat triangle shading and painter-sorted depth; it is not a replacement for a depth-buffered PBR renderer. Asset-browser changes are currently in-memory and are not saved as project files.
Package structure #
lib/flix3dengine.dart: public package exports.lib/src/engine.dart: engine configuration, lifecycle, and scene ownership.lib/src/controller.dart: model, camera/light, and native resource controller.lib/src/scene.dart: immutable transforms/entities and mutable scene model.lib/src/modeling.dart: validated mesh/material data, OBJ/glTF/GLB importer, and OBJ geometry export.lib/src/model_library.dart: original procedural starter meshes.lib/src/widgets/model_studio.dart: asset browser, importer, material editor, and scene placement UI.lib/src/widgets/model_viewport.dart: interactive software mesh preview.lib/src/widgets/flix3d_view.dart: public controller-backed viewport widget.lib/src/widgets/engine_builder.dart: Flutter widget binding to engine state.lib/src/widgets/game_touch_controls.dart: touch joystick, camera look, jump, and mobile frame updates.docs/FEATURE_STATUS.md: implementation and verification matrix by feature and platform.ARCHITECTURE.md,DEVELOPMENT_STATUS.md,FEATURE_MATRIX.md, andPLATFORM_SUPPORT.md: milestone architecture, verified status, feature coverage, and platform/backend support.lib/src/native/: optional Dart FFI loader and non-FFI platform guard.hook/build.dart: cross-platform C++20 native-asset build hook.android_libcpp_shared: Android C++ standard-library asset bundled for native engine builds.Engine/Core/: C++ runtime lifecycle and logging.Engine/Platform/CAPI/: stable C ABI used by Dart FFI.Engine/Gameplay/: first-person maze simulation, collision, and objectives.Engine/Platform/MacOS/: SDL3 window and Metal playable game application.example/: Flutter package consumer example.tool/native_smoke.dart: end-to-end native FFI lifecycle check.tool/model_pipeline_smoke.dart: model format and starter-library smoke check.
Flutter example #
cd example
flutter pub get
flutter run -d chrome
The example provides a responsive scene hierarchy and transform inspector, engine lifecycle controls, entity creation/deletion, and an Asset Studio screen. Model previews draw the imported triangle geometry; scene transforms and material factors update the editor data directly.
Build the native runtime #
Flutter 3.38 or newer automatically builds and bundles the C++ FFI library using this package's Dart build hook. Install Flutter and the native C/C++ toolchain for your target platform; Android builds also need the Android NDK. The package's native library can be used without manually locating or packaging a shared library:
flutter pub get
The standalone macOS game is built separately and requires CMake 3.24+, a C++20 compiler, SDL3 3.2+, and Apple's Metal SDK. With Homebrew:
brew install sdl3
cmake -S . -B build/native -DCMAKE_BUILD_TYPE=Debug \
-DFLIX3D_BUILD_MACOS_APP=OFF -DBUILD_TESTING=ON
cmake --build build/native --target flix3d_native --parallel
On macOS, the default build also includes the native Metal game:
cmake --build build/native --parallel
open build/native/Flix3DEngine.app
Shard Run controls: WASD or arrow keys to move; click to capture the mouse
and move it to look; Space to jump; R to reset; F11 to toggle fullscreen;
Escape to release the mouse. A connected SDL-recognized gamepad uses the left
stick to move, the right stick to look, and its south button to jump. Collect
all three cyan shards and enter the gold exit.
Load the build-hook-bundled library directly:
import 'package:flix3dengine/flix3dengine.dart';
final native = Flix3DNativeRuntime.open();
final engine = Flix3DEngine(nativeRuntime: native);
engine.initialize();
engine.update(
1 / 60,
input: const Flix3DGameInput(forward: 1, jumpPressed: true),
);
final player = native.playerState;
print(
'Collected ${player.collected} / ${player.collectibleCount}; '
'height ${player.height}',
);
engine.dispose(); // Shuts down and releases the native handle.
To load a separately built native library instead, pass its path to
Flix3DNativeRuntime.open(path: ...). Web does not support this native FFI
runtime.
Verify #
flutter pub get
flutter analyze
flutter test
cmake -S . -B build/native -DCMAKE_BUILD_TYPE=Debug
cmake --build build/native --parallel
ctest --test-dir build/native --output-on-failure
dart run tool/model_pipeline_smoke.dart
Flame #
Flame is intentionally not included as a dependency. A Flame application can
own a Flix3DEngine controller and use Flix3DEngineBuilder or other Flutter
widgets to react to its state. A dedicated Flame bridge is not currently
implemented.
Android and iOS gameplay #
The Dart build hook builds and Flutter bundles the C++ gameplay library for
Android, iOS, macOS, Linux, and Windows using the selected platform toolchain.
The android_libcpp_shared dependency bundles Android's libc++_shared.so
alongside the C++ engine. Flix3DNativeRuntime.open() uses the package's
bundled native asset; consumers do not need to configure per-platform Gradle
or CocoaPods build rules.
Use the touch-control widget over a bounded, full-screen game surface. It owns the Flutter frame ticker while the engine is running:
final runtime = Flix3DNativeRuntime.open();
final engine = Flix3DEngine(nativeRuntime: runtime)..initialize();
Scaffold(
body: Flix3DGameTouchControls(
engine: engine,
child: const ColoredBox(
color: Color(0xFF18252C),
child: Center(child: Text('Your game surface')),
),
),
);
The widget sends joystick movement, right-side drag-look, and jump input to the native simulation. The child above is only a Flutter surface; this package does not yet render its 3D world inside Flutter on Android or iOS.
Native build hook #
hook/build.dart compiles the C++ core and C ABI for the operating system,
architecture, compiler, and build mode selected by the consuming application.
The Flutter/Dart SDK caches build-hook results and packages the resulting code
asset automatically. Web builds omit the native runtime; Windows, Linux, macOS,
Android, and iOS native libraries are built on demand when a corresponding
toolchain is selected.
dart run tool/native_smoke.dart exercises the default bundled-asset FFI path,
including player movement, collision, collectibles, jumping, and shutdown. The
standalone SDL3/Metal executable remains a separate CMake target.