voxel_scene 0.1.0-dev
voxel_scene: ^0.1.0-dev copied to clipboard
flutter_scene renderer for voxel_engine: one scene node per chunk, the terrain material and its shaders.
voxel_scene #
Draws voxel_engine worlds with flutter_scene:
one scene node per chunk, a terrain material with its own shaders, a day
and night sky, block models and the selection outline.
Status: 0.1.0-dev, the first release. The API can still change.
Features #
VoxelChunkView: aChunkMeshSinkthat turns each mesh into a scene node.TerrainMaterial: the terrain shader (lit, fogged, shadowed).MirroredCamera: the camera that showsvoxel_engine's winding the right way round.DayNightSky,SelectionOutline,VoxelModelMesh,RigPart,NodeBody.
Install #
dependencies:
voxel_scene: ^0.1.0-dev
Dart SDK ^3.13.0.
-
macOS for now. Turn Flutter GPU on in
macos/Runner/Info.plist:<key>FLTEnableFlutterGPU</key> <true/> -
flutter_sceneis pinned to0.23.0: the terrain material uses its private GPU layer. -
The shaders ship compiled in
assets/shaders/. After a Flutter upgrade or a shader edit, rebuild them withdart tool/build_shaders.dart.
Usage #
-
Load the resources before the first frame.
WidgetsFlutterBinding.ensureInitialized(); await Scene.initializeStaticResources(); await TerrainMaterial.loadLibrary(); // before the first TerrainMaterial -
Put a chunk view in a scene.
final scene = Scene(); final view = VoxelChunkView(); scene.add(view.root); -
Stream
voxel_enginechunks into it. The view is the streamer's sink.final streamer = ChunkStreamer(table: table, sink: view, loadRadius: 6)..jobs = pool; streamer.updateAround(ChunkStreamer.chunkOfXZ(0, 0)); -
Show it with a
MirroredCamera, callingstreamer.update()every tick.SceneView(scene, cameraBuilder: (elapsed) => MirroredCamera(position: eye, target: target), onTick: (elapsed, dt) => streamer.update()); -
Shadows: give the
SunLightshadowCasterFaces: MirroredCamera.shadowCasterFaces.
Example #
cd example
flutter run -d macos
example/lib/main.dart draws sine hills with a lake
and lamps under a sun with shadows, from a camera that circles them.