in viewer, ensure onTextureUploadComplete callbacks are passed through to KTX1Bundle.createTexture
This commit is contained in:
@@ -44,13 +44,13 @@ class FFIKtx1Bundle extends Ktx1Bundle {
|
||||
return FFIKtx1Bundle(bundle);
|
||||
}
|
||||
|
||||
Future<Texture> createTexture() async {
|
||||
Future<Texture> createTexture({VoidCallback? onTextureUploadComplete, int? requestId}) async {
|
||||
final texturePtr = await withPointerCallback<TTexture>((cb) {
|
||||
Ktx1Reader_createTextureRenderThread(
|
||||
(FilamentApp.instance as FFIFilamentApp).engine,
|
||||
pointer,
|
||||
0,
|
||||
nullptr,
|
||||
requestId ?? 0,
|
||||
onTextureUploadComplete ?? nullptr,
|
||||
cb);
|
||||
});
|
||||
return FFITexture(FilamentApp.instance!.engine, texturePtr);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:thermion_dart/thermion_dart.dart';
|
||||
|
||||
abstract class Ktx1Bundle {
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
@@ -10,7 +9,8 @@ abstract class Ktx1Bundle {
|
||||
///
|
||||
///
|
||||
///
|
||||
Future<Texture> createTexture();
|
||||
Future<Texture> createTexture(
|
||||
{VoidCallback? onTextureUploadComplete, int? requestId});
|
||||
|
||||
///
|
||||
///
|
||||
|
||||
@@ -267,7 +267,7 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
withVoidCallback((requestId, onTextureUploadComplete) async {
|
||||
var bundle = await FFIKtx1Bundle.create(data);
|
||||
|
||||
_skyboxTexture = await bundle.createTexture() as FFITexture;
|
||||
_skyboxTexture = await bundle.createTexture(onTextureUploadComplete: onTextureUploadComplete, requestId: requestId) as FFITexture;
|
||||
|
||||
_skybox = await FilamentApp.instance!.buildSkybox(texture: _skyboxTexture)
|
||||
as FFISkybox;
|
||||
@@ -287,53 +287,61 @@ class ThermionViewerFFI extends ThermionViewer {
|
||||
///
|
||||
///
|
||||
@override
|
||||
Future loadIbl(String lightingPath, {double intensity = 30000, bool destroyExisting= true}) async {
|
||||
await removeIbl(destroy:destroyExisting);
|
||||
Future loadIbl(String lightingPath,
|
||||
{double intensity = 30000, bool destroyExisting = true}) async {
|
||||
await removeIbl(destroy: destroyExisting);
|
||||
|
||||
final completer = Completer();
|
||||
_iblTextureUploadComplete =
|
||||
withVoidCallback((requestId, onTextureUploadComplete) async {
|
||||
late Pointer stackPtr;
|
||||
if (FILAMENT_WASM) {
|
||||
//stackPtr = stackSave();
|
||||
}
|
||||
late Pointer stackPtr;
|
||||
if (FILAMENT_WASM) {
|
||||
//stackPtr = stackSave();
|
||||
}
|
||||
|
||||
var data = await FilamentApp.instance!.loadResource(lightingPath);
|
||||
var data = await FilamentApp.instance!.loadResource(lightingPath);
|
||||
|
||||
final bundle = await FFIKtx1Bundle.create(data);
|
||||
final bundle = await FFIKtx1Bundle.create(data);
|
||||
|
||||
final texture = await bundle.createTexture();
|
||||
final harmonics = bundle.getSphericalHarmonics();
|
||||
final texture = await bundle.createTexture(onTextureUploadComplete: onTextureUploadComplete, requestId: requestId);
|
||||
final harmonics = bundle.getSphericalHarmonics();
|
||||
|
||||
final ibl = await FFIIndirectLight.fromIrradianceHarmonics(
|
||||
harmonics,
|
||||
reflectionsTexture: texture,
|
||||
intensity: intensity,
|
||||
);
|
||||
final ibl = await FFIIndirectLight.fromIrradianceHarmonics(
|
||||
harmonics,
|
||||
reflectionsTexture: texture,
|
||||
intensity: intensity,
|
||||
);
|
||||
|
||||
await scene.setIndirectLight(ibl);
|
||||
await scene.setIndirectLight(ibl);
|
||||
|
||||
if (FILAMENT_WASM) {
|
||||
//stackRestore(stackPtr);
|
||||
data.free();
|
||||
}
|
||||
data.free();
|
||||
if (FILAMENT_WASM) {
|
||||
//stackRestore(stackPtr);
|
||||
data.free();
|
||||
}
|
||||
data.free();
|
||||
|
||||
completer.complete();
|
||||
}).then((_) {
|
||||
_iblTextureUploadComplete = null;
|
||||
});
|
||||
completer.complete();
|
||||
_logger.info("IBL texture upload complete");
|
||||
}).then((_) {
|
||||
_logger.info("IBL texture upload complete");
|
||||
_iblTextureUploadComplete = null;
|
||||
}).onError((err, st) {
|
||||
_logger.severe(err.toString());
|
||||
});
|
||||
await completer.future;
|
||||
}
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
Future loadIblFromTexture(Texture texture, { Texture? reflectionsTexture = null, double intensity = 30000, bool destroyExisting = true}) async {
|
||||
Future loadIblFromTexture(Texture texture,
|
||||
{Texture? reflectionsTexture = null,
|
||||
double intensity = 30000,
|
||||
bool destroyExisting = true}) async {
|
||||
await removeIbl(destroy: destroyExisting);
|
||||
|
||||
final ibl = await FFIIndirectLight.fromIrradianceTexture(texture,
|
||||
reflectionsTexture: reflectionsTexture, intensity: intensity);
|
||||
reflectionsTexture: reflectionsTexture, intensity: intensity);
|
||||
|
||||
await scene.setIndirectLight(ibl);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user