implement TSkybox and use setColor method to set the background color, rather than the image

This commit is contained in:
Nick Fisher
2025-06-18 13:01:25 +08:00
parent df393b075b
commit 42f9538040
11 changed files with 177 additions and 30 deletions

View File

@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:thermion_dart/src/filament/src/implementation/ffi_camera.dart';
import 'package:thermion_dart/src/filament/src/implementation/ffi_skybox.dart';
import 'package:thermion_dart/src/filament/src/interface/scene.dart';
import 'package:thermion_dart/src/filament/src/implementation/ffi_asset.dart';
import 'package:thermion_dart/src/filament/src/implementation/ffi_gizmo.dart';
@@ -10,6 +11,7 @@ import 'package:thermion_dart/src/filament/src/implementation/ffi_scene.dart';
import 'package:thermion_dart/src/filament/src/implementation/ffi_swapchain.dart';
import 'package:thermion_dart/src/filament/src/implementation/ffi_texture.dart';
import 'package:thermion_dart/src/filament/src/implementation/ffi_view.dart';
import 'package:thermion_dart/src/filament/src/interface/skybox.dart';
import 'package:thermion_dart/src/utils/src/matrix.dart';
import 'package:thermion_dart/thermion_dart.dart';
import 'package:logging/logging.dart';
@@ -1207,5 +1209,17 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
Vector3(bb.halfExtentX, bb.halfExtentY, bb.halfExtentZ));
}
/// Builds an (empty) [Skybox] instance. This will not be attached to any scene until
/// [setSkybox] is called.
///
Future<Skybox> buildSkybox({Texture? texture = null}) async {
final ptr = await withPointerCallback<TSkybox>((cb) {
Engine_buildSkyboxRenderThread(
engine,
(texture as FFITexture?)?.pointer ?? nullptr,
cb,
);
});
return FFISkybox(ptr);
}
}

View File

@@ -1,6 +1,8 @@
import 'package:thermion_dart/src/filament/src/implementation/ffi_asset.dart';
import 'package:thermion_dart/src/filament/src/implementation/ffi_indirect_light.dart';
import 'package:thermion_dart/src/filament/src/implementation/ffi_skybox.dart';
import 'package:thermion_dart/src/filament/src/interface/scene.dart';
import 'package:thermion_dart/src/filament/src/interface/skybox.dart';
import 'package:thermion_dart/thermion_dart.dart';
import 'package:logging/logging.dart';
@@ -153,4 +155,11 @@ class FFIScene extends Scene {
Future<IndirectLight?> getIndirectLight() async {
return _indirectLight;
}
///
///
///
Future setSkybox(Skybox skybox) async {
Scene_setSkybox(scene, (skybox as FFISkybox).pointer);
}
}

View File

@@ -0,0 +1,26 @@
import 'package:thermion_dart/src/filament/src/implementation/ffi_filament_app.dart';
import 'package:thermion_dart/src/filament/src/interface/skybox.dart';
import 'package:thermion_dart/thermion_dart.dart';
class FFISkybox extends Skybox {
final Pointer<TSkybox> pointer;
FFISkybox(this.pointer);
@override
Future setColor(double r, double g, double b, double a) async {
Skybox_setColor(pointer, r, g, b, a);
}
@override
Future destroy() async {
await withVoidCallback(
(requestId, cb) => Engine_destroySkyboxRenderThread(
(FilamentApp.instance as FFIFilamentApp).engine,
pointer,
requestId,
cb,
),
);
}
}

View File

@@ -1,4 +1,5 @@
import 'package:thermion_dart/src/filament/src/interface/scene.dart';
import 'package:thermion_dart/src/filament/src/interface/skybox.dart';
import 'package:thermion_dart/thermion_dart.dart';
class FilamentConfig<T, U> {
@@ -344,19 +345,23 @@ abstract class FilamentApp<T> {
Future<Matrix4> getWorldTransform(ThermionEntity entity);
/// Sets the render priority for [entity].
/// [priority] should be be between 0 and 7, with 0 meaning highest priority
/// [priority] should be be between 0 and 7, with 0 meaning highest priority
/// (rendered first) and 7 meaning lowest priority (rendered last).
///
Future setPriority(ThermionEntity entity, int priority);
/// Gets the number of primitives for [entity] (which is assumed to be
/// Gets the number of primitives for [entity] (which is assumed to be
/// have a renderable component attached)
///
Future<int> getPrimitiveCount(ThermionEntity entity);
/// Gets the bounding box for [entity] (which is assumed to be
/// Gets the bounding box for [entity] (which is assumed to be
/// have a renderable component attached).
///
Future<Aabb3> getBoundingBox(ThermionEntity entity);
/// Builds a [Skybox] instance. This will not be attached to any scene until
/// [setSkybox] is called.
///
Future<Skybox> buildSkybox({Texture? texture = null});
}

View File

@@ -1,3 +1,4 @@
import 'package:thermion_dart/src/filament/src/interface/skybox.dart';
import 'package:thermion_dart/thermion_dart.dart';
abstract class Scene {
@@ -49,4 +50,11 @@ abstract class Scene {
Future<IndirectLight?> getIndirectLight() {
throw UnimplementedError();
}
///
///
///
Future setSkybox(Skybox skybox) {
throw UnimplementedError();
}
}

View File

@@ -0,0 +1,11 @@
abstract class Skybox {
///
///
///
Future setColor(double r, double g, double b, double a);
///
///
///
Future destroy();
}