formatting

This commit is contained in:
Nick Fisher
2025-06-02 12:08:26 +08:00
parent 7141a01101
commit 5eb83a80b3

View File

@@ -63,7 +63,11 @@ class ThermionViewerFFI extends ThermionViewer {
focalLength = kFocalLength; focalLength = kFocalLength;
} }
await camera.setLensProjection( await camera.setLensProjection(
near: near, far: far, aspect: aspect, focalLength: focalLength); near: near,
far: far,
aspect: aspect,
focalLength: focalLength,
);
} }
} }
@@ -83,8 +87,9 @@ class ThermionViewerFFI extends ThermionViewer {
await view.setCamera(camera); await view.setCamera(camera);
animationManager = await withPointerCallback<TAnimationManager>((cb) => animationManager = await withPointerCallback<TAnimationManager>(
AnimationManager_createRenderThread(app.engine, scene.scene, cb)); (cb) => AnimationManager_createRenderThread(app.engine, scene.scene, cb),
);
RenderTicker_addAnimationManager(app.renderTicker, animationManager); RenderTicker_addAnimationManager(app.renderTicker, animationManager);
@@ -113,8 +118,14 @@ class ThermionViewerFFI extends ThermionViewer {
/// ///
@override @override
Future render() async { Future render() async {
await withVoidCallback((requestId, cb) => RenderTicker_renderRenderThread( await withVoidCallback(
app.renderTicker, 0.toBigInt, requestId, cb)); (requestId, cb) => RenderTicker_renderRenderThread(
app.renderTicker,
0.toBigInt,
requestId,
cb,
),
);
await FilamentApp.instance!.flush(); await FilamentApp.instance!.flush();
} }
@@ -213,8 +224,11 @@ class ThermionViewerFFI extends ThermionViewer {
/// ///
/// ///
@override @override
Future setBackgroundImagePosition(double x, double y, Future setBackgroundImagePosition(
{bool clamp = false}) async { double x,
double y, {
bool clamp = false,
}) async {
throw UnimplementedError(); throw UnimplementedError();
} }
@@ -227,7 +241,12 @@ class ThermionViewerFFI extends ThermionViewer {
skybox = await withPointerCallback<TSkybox>((cb) { skybox = await withPointerCallback<TSkybox>((cb) {
Engine_buildSkyboxRenderThread( Engine_buildSkyboxRenderThread(
app.engine, data.address, data.length, cb, nullptr); app.engine,
data.address,
data.length,
cb,
nullptr,
);
}); });
Scene_setSkybox(scene.scene, skybox!); Scene_setSkybox(scene.scene, skybox!);
} }
@@ -249,7 +268,13 @@ class ThermionViewerFFI extends ThermionViewer {
indirectLight = await withPointerCallback<TIndirectLight>((cb) { indirectLight = await withPointerCallback<TIndirectLight>((cb) {
Engine_buildIndirectLightRenderThread( Engine_buildIndirectLightRenderThread(
app.engine, data.address, data.length, intensity, cb, nullptr); app.engine,
data.address,
data.length,
intensity,
cb,
nullptr,
);
}); });
if (FILAMENT_WASM) { if (FILAMENT_WASM) {
//stackRestore(stackPtr); //stackRestore(stackPtr);
@@ -291,8 +316,14 @@ class ThermionViewerFFI extends ThermionViewer {
} }
if (skybox != null) { if (skybox != null) {
await withVoidCallback((requestId, cb) => await withVoidCallback(
Engine_destroySkyboxRenderThread(app.engine, skybox!, requestId, cb)); (requestId, cb) => Engine_destroySkyboxRenderThread(
app.engine,
skybox!,
requestId,
cb,
),
);
skybox = null; skybox = null;
} }
} }
@@ -304,9 +335,14 @@ class ThermionViewerFFI extends ThermionViewer {
Future removeIbl() async { Future removeIbl() async {
if (indirectLight != null) { if (indirectLight != null) {
Scene_setIndirectLight(scene.scene, nullptr); Scene_setIndirectLight(scene.scene, nullptr);
await withVoidCallback((requestId, cb) => await withVoidCallback(
Engine_destroyIndirectLightRenderThread( (requestId, cb) => Engine_destroyIndirectLightRenderThread(
app.engine, indirectLight!, requestId, cb)); app.engine,
indirectLight!,
requestId,
cb,
),
);
indirectLight = null; indirectLight = null;
} }
} }
@@ -354,12 +390,14 @@ class ThermionViewerFFI extends ThermionViewer {
/// ///
/// ///
@override @override
Future<ThermionAsset> loadGltf(String path, Future<ThermionAsset> loadGltf(
{bool addToScene = true, String path, {
bool addToScene = true,
int numInstances = 1, int numInstances = 1,
bool keepData = false, bool keepData = false,
String? resourceUri, String? resourceUri,
bool loadAsync = false}) async { bool loadAsync = false,
}) async {
final data = await FilamentApp.instance!.loadResource(path); final data = await FilamentApp.instance!.loadResource(path);
if (resourceUri == null) { if (resourceUri == null) {
var split = path.split("/"); var split = path.split("/");
@@ -370,34 +408,42 @@ class ThermionViewerFFI extends ThermionViewer {
resourceUri = "${resourceUri}/"; resourceUri = "${resourceUri}/";
} }
return loadGltfFromBuffer(data, return loadGltfFromBuffer(
data,
addToScene: addToScene, addToScene: addToScene,
numInstances: numInstances, numInstances: numInstances,
keepData: keepData, keepData: keepData,
resourceUri: resourceUri, resourceUri: resourceUri,
loadResourcesAsync: loadAsync); loadResourcesAsync: loadAsync,
);
} }
/// ///
/// ///
/// ///
@override @override
Future<ThermionAsset> loadGltfFromBuffer(Uint8List data, Future<ThermionAsset> loadGltfFromBuffer(
{bool addToScene = true, Uint8List data, {
bool addToScene = true,
int numInstances = 1, int numInstances = 1,
bool keepData = false, bool keepData = false,
int priority = 4, int priority = 4,
int layer = 0, int layer = 0,
bool loadResourcesAsync = false, bool loadResourcesAsync = false,
String? resourceUri}) async { String? resourceUri,
var asset = await FilamentApp.instance!.loadGltfFromBuffer( }) async {
data, animationManager, var asset =
await FilamentApp.instance!.loadGltfFromBuffer(
data,
animationManager,
numInstances: numInstances, numInstances: numInstances,
keepData: keepData, keepData: keepData,
priority: priority, priority: priority,
layer: layer, layer: layer,
loadResourcesAsync: loadResourcesAsync, loadResourcesAsync: loadResourcesAsync,
resourceUri: resourceUri) as FFIAsset; resourceUri: resourceUri,
)
as FFIAsset;
_assets.add(asset); _assets.add(asset);
if (addToScene) { if (addToScene) {
@@ -421,7 +467,6 @@ class ThermionViewerFFI extends ThermionViewer {
await FilamentApp.instance!.destroyAsset(asset.boundingBoxAsset!); await FilamentApp.instance!.destroyAsset(asset.boundingBoxAsset!);
} }
await FilamentApp.instance!.destroyAsset(asset); await FilamentApp.instance!.destroyAsset(asset);
} }
/// ///
@@ -476,7 +521,9 @@ class ThermionViewerFFI extends ThermionViewer {
/// ///
/// ///
Future setSoftShadowOptions( Future setSoftShadowOptions(
double penumbraScale, double penumbraRatioScale) async { double penumbraScale,
double penumbraRatioScale,
) async {
View_setSoftShadowOptions(view.view, penumbraScale, penumbraRatioScale); View_setSoftShadowOptions(view.view, penumbraScale, penumbraRatioScale);
} }
@@ -512,7 +559,11 @@ class ThermionViewerFFI extends ThermionViewer {
/// ///
@override @override
Future setLightPosition( Future setLightPosition(
ThermionEntity lightEntity, double x, double y, double z) async { ThermionEntity lightEntity,
double x,
double y,
double z,
) async {
LightManager_setPosition(app.lightManager, lightEntity, x, y, z); LightManager_setPosition(app.lightManager, lightEntity, x, y, z);
} }
@@ -521,10 +572,17 @@ class ThermionViewerFFI extends ThermionViewer {
/// ///
@override @override
Future setLightDirection( Future setLightDirection(
ThermionEntity lightEntity, Vector3 direction) async { ThermionEntity lightEntity,
Vector3 direction,
) async {
direction.normalize(); direction.normalize();
LightManager_setPosition( LightManager_setPosition(
app.lightManager, lightEntity, direction.x, direction.y, direction.z); app.lightManager,
lightEntity,
direction.x,
direction.y,
direction.z,
);
} }
/// ///
@@ -543,7 +601,8 @@ class ThermionViewerFFI extends ThermionViewer {
final result = RenderableManager_getAabb(app.renderableManager, entityId); final result = RenderableManager_getAabb(app.renderableManager, entityId);
return v64.Aabb3.centerAndHalfExtents( return v64.Aabb3.centerAndHalfExtents(
Vector3(result.centerX, result.centerY, result.centerZ), Vector3(result.centerX, result.centerY, result.centerZ),
Vector3(result.halfExtentX, result.halfExtentY, result.halfExtentZ)); Vector3(result.halfExtentX, result.halfExtentY, result.halfExtentZ),
);
} }
/// ///
@@ -676,8 +735,11 @@ class ThermionViewerFFI extends ThermionViewer {
@override @override
Future<GizmoAsset> getGizmo(GizmoType gizmoType) async { Future<GizmoAsset> getGizmo(GizmoType gizmoType) async {
if (_gizmos[gizmoType] == null) { if (_gizmos[gizmoType] == null) {
_gizmos[gizmoType] = await FilamentApp.instance! _gizmos[gizmoType] = await FilamentApp.instance!.createGizmo(
.createGizmo(view, animationManager, gizmoType); view,
animationManager,
gizmoType,
);
} }
return _gizmos[gizmoType]!; return _gizmos[gizmoType]!;
} }