refactoring
This commit is contained in:
@@ -219,5 +219,18 @@ abstract class FilamentApp<T> {
|
|||||||
Future setParent(ThermionEntity child, ThermionEntity? parent,
|
Future setParent(ThermionEntity child, ThermionEntity? parent,
|
||||||
{bool preserveScaling});
|
{bool preserveScaling});
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
Future<MaterialInstance> createImageMaterialInstance();
|
Future<MaterialInstance> createImageMaterialInstance();
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
Future<Uint8List> capture(covariant View view);
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
Future setClearColor(double r, double g, double b, double a);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,41 +14,54 @@ class BackgroundImage extends ThermionAsset {
|
|||||||
|
|
||||||
ThermionEntity get entity => asset.entity;
|
ThermionEntity get entity => asset.entity;
|
||||||
|
|
||||||
Texture? _backgroundImageTexture;
|
Texture? texture;
|
||||||
|
|
||||||
FFITextureSampler? _imageSampler;
|
FFITextureSampler? sampler;
|
||||||
|
|
||||||
|
final MaterialInstance mi;
|
||||||
|
|
||||||
final FFIScene scene;
|
final FFIScene scene;
|
||||||
|
|
||||||
BackgroundImage._(
|
BackgroundImage._(
|
||||||
this.asset, this.scene, this._backgroundImageTexture, this._imageSampler);
|
this.asset, this.scene, this.texture, this.sampler, this.mi);
|
||||||
|
|
||||||
Future destroy() async {
|
Future destroy() async {
|
||||||
Scene_removeEntity(scene.scene, entity);
|
Scene_removeEntity(scene.scene, entity);
|
||||||
await _backgroundImageTexture!.dispose();
|
|
||||||
await _imageSampler!.dispose();
|
await texture!.dispose();
|
||||||
|
await sampler!.dispose();
|
||||||
|
await mi.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<BackgroundImage> create(
|
static Future<BackgroundImage> create(
|
||||||
ThermionViewer viewer, FFIScene scene, Uint8List imageData) async {
|
ThermionViewer viewer, FFIScene scene) async {
|
||||||
final image = await FilamentApp.instance!.decodeImage(imageData);
|
|
||||||
var backgroundImageTexture = await FilamentApp.instance!
|
|
||||||
.createTexture(await image.getWidth(), await image.getHeight());
|
|
||||||
|
|
||||||
var imageSampler =
|
|
||||||
await FilamentApp.instance!.createTextureSampler() as FFITextureSampler;
|
|
||||||
|
|
||||||
var imageMaterialInstance =
|
var imageMaterialInstance =
|
||||||
await FilamentApp.instance!.createImageMaterialInstance();
|
await FilamentApp.instance!.createImageMaterialInstance();
|
||||||
|
|
||||||
await imageMaterialInstance.setParameterTexture(
|
|
||||||
"image", backgroundImageTexture as FFITexture, imageSampler);
|
|
||||||
var backgroundImage =
|
var backgroundImage =
|
||||||
await viewer.createGeometry(GeometryHelper.fullscreenQuad());
|
await viewer.createGeometry(GeometryHelper.fullscreenQuad());
|
||||||
backgroundImage.setMaterialInstanceAt(imageMaterialInstance);
|
backgroundImage.setMaterialInstanceAt(imageMaterialInstance);
|
||||||
await scene.add(backgroundImage as FFIAsset);
|
await scene.add(backgroundImage as FFIAsset);
|
||||||
return BackgroundImage._(
|
return BackgroundImage._(
|
||||||
backgroundImage, scene, backgroundImageTexture, imageSampler);
|
backgroundImage, scene, null, null, imageMaterialInstance);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future setBackgroundColor(double r, double g, double b, double a) async {
|
||||||
|
await mi.setParameterFloat4("backgroundColor", r, g, b, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future setImage(Uint8List imageData) async {
|
||||||
|
final image = await FilamentApp.instance!.decodeImage(imageData);
|
||||||
|
|
||||||
|
texture ??= await FilamentApp.instance!
|
||||||
|
.createTexture(await image.getWidth(), await image.getHeight());
|
||||||
|
|
||||||
|
sampler ??=
|
||||||
|
await FilamentApp.instance!.createTextureSampler() as FFITextureSampler;
|
||||||
|
|
||||||
|
await mi.setParameterTexture(
|
||||||
|
"image", texture as FFITexture, sampler as FFITextureSampler);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -263,7 +276,7 @@ class BackgroundImage extends ThermionAsset {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future setTransform(Matrix4 transform, { ThermionEntity? entity }) {
|
Future setTransform(Matrix4 transform, {ThermionEntity? entity}) {
|
||||||
// TODO: implement setTransform
|
// TODO: implement setTransform
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -541,10 +541,52 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
|
|||||||
///
|
///
|
||||||
@override
|
@override
|
||||||
Future<MaterialInstance> createImageMaterialInstance() async {
|
Future<MaterialInstance> createImageMaterialInstance() async {
|
||||||
_imageMaterial ??= FFIMaterial(Material_createImageMaterial(engine),
|
if (_imageMaterial == null) {
|
||||||
FilamentApp.instance! as FFIFilamentApp);
|
var ptr = await withPointerCallback<TMaterial>(
|
||||||
|
(cb) => Material_createImageMaterialRenderThread(engine, cb));
|
||||||
|
_imageMaterial =
|
||||||
|
FFIMaterial(ptr, FilamentApp.instance! as FFIFilamentApp);
|
||||||
|
}
|
||||||
var instance =
|
var instance =
|
||||||
await _imageMaterial!.createInstance() as FFIMaterialInstance;
|
await _imageMaterial!.createInstance() as FFIMaterialInstance;
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
Future<Uint8List> capture(covariant FFIView view) async {
|
||||||
|
final viewport = await view.getViewport();
|
||||||
|
final swapChain = _viewMappings[view];
|
||||||
|
final out = Uint8List(viewport.width * viewport.height * 4);
|
||||||
|
|
||||||
|
await withBoolCallback((cb) {
|
||||||
|
Renderer_beginFrameRenderThread(renderer, swapChain!.swapChain, 0, cb);
|
||||||
|
});
|
||||||
|
await withVoidCallback((cb) {
|
||||||
|
Renderer_readPixelsRenderThread(
|
||||||
|
renderer,
|
||||||
|
view.view,
|
||||||
|
view.renderTarget?.renderTarget ?? nullptr,
|
||||||
|
TPixelDataFormat.PIXELDATAFORMAT_RGBA,
|
||||||
|
TPixelDataType.PIXELDATATYPE_UBYTE,
|
||||||
|
out.address,
|
||||||
|
cb,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
await withVoidCallback((cb) {
|
||||||
|
Renderer_endFrameRenderThread(renderer, cb);
|
||||||
|
});
|
||||||
|
await withVoidCallback((cb) {
|
||||||
|
Engine_flushAndWaitRenderThead(engine, cb);
|
||||||
|
});
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
Future setClearColor(double r, double g, double b, double a) async {
|
||||||
|
Renderer_setClearOptions(renderer, r, g, b, a, 0, true, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1907,6 +1907,19 @@ external void Material_createInstanceRenderThread(
|
|||||||
onComplete,
|
onComplete,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ffi.Native<
|
||||||
|
ffi.Void Function(
|
||||||
|
ffi.Pointer<TEngine>,
|
||||||
|
ffi.Pointer<
|
||||||
|
ffi
|
||||||
|
.NativeFunction<ffi.Void Function(ffi.Pointer<TMaterial>)>>)>(
|
||||||
|
isLeaf: true)
|
||||||
|
external void Material_createImageMaterialRenderThread(
|
||||||
|
ffi.Pointer<TEngine> tEngine,
|
||||||
|
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TMaterial>)>>
|
||||||
|
onComplete,
|
||||||
|
);
|
||||||
|
|
||||||
@ffi.Native<
|
@ffi.Native<
|
||||||
ffi.Void Function(
|
ffi.Void Function(
|
||||||
ffi.Pointer<TView>, ffi.Pointer<TEngine>, ffi.UnsignedInt)>(
|
ffi.Pointer<TView>, ffi.Pointer<TEngine>, ffi.UnsignedInt)>(
|
||||||
@@ -1952,280 +1965,38 @@ external FilamentRenderCallback make_render_callback_fn_pointer(
|
|||||||
);
|
);
|
||||||
|
|
||||||
@ffi.Native<
|
@ffi.Native<
|
||||||
ffi.Void Function(
|
ffi.Void Function(ffi.Pointer<TSceneAsset>,
|
||||||
ffi.Pointer<TSceneManager>,
|
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
||||||
ffi.Pointer<TMaterial>,
|
external void SceneAsset_destroyRenderThread(
|
||||||
ffi.Pointer<
|
ffi.Pointer<TSceneAsset> tSceneAsset,
|
||||||
ffi
|
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> onComplete,
|
||||||
.NativeFunction<ffi.Void Function(ffi.Pointer<TSceneAsset>)>>)>(
|
|
||||||
isLeaf: true)
|
|
||||||
external void SceneManager_createGridRenderThread(
|
|
||||||
ffi.Pointer<TSceneManager> tSceneManager,
|
|
||||||
ffi.Pointer<TMaterial> tMaterial,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TSceneAsset>)>>
|
|
||||||
callback,
|
|
||||||
);
|
|
||||||
|
|
||||||
@ffi.Native<
|
|
||||||
ffi.Pointer<TGizmo> Function(
|
|
||||||
ffi.Pointer<TSceneManager>,
|
|
||||||
ffi.Pointer<TView>,
|
|
||||||
ffi.Pointer<TScene>,
|
|
||||||
ffi.UnsignedInt,
|
|
||||||
ffi.Pointer<
|
|
||||||
ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TGizmo>)>>)>(
|
|
||||||
symbol: "SceneManager_createGizmoRenderThread", isLeaf: true)
|
|
||||||
external ffi.Pointer<TGizmo> _SceneManager_createGizmoRenderThread(
|
|
||||||
ffi.Pointer<TSceneManager> tSceneManager,
|
|
||||||
ffi.Pointer<TView> tView,
|
|
||||||
ffi.Pointer<TScene> tScene,
|
|
||||||
int tGizmoType,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TGizmo>)>>
|
|
||||||
onComplete,
|
|
||||||
);
|
|
||||||
|
|
||||||
ffi.Pointer<TGizmo> SceneManager_createGizmoRenderThread(
|
|
||||||
ffi.Pointer<TSceneManager> tSceneManager,
|
|
||||||
ffi.Pointer<TView> tView,
|
|
||||||
ffi.Pointer<TScene> tScene,
|
|
||||||
TGizmoType tGizmoType,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TGizmo>)>>
|
|
||||||
onComplete,
|
|
||||||
) =>
|
|
||||||
_SceneManager_createGizmoRenderThread(
|
|
||||||
tSceneManager,
|
|
||||||
tView,
|
|
||||||
tScene,
|
|
||||||
tGizmoType.value,
|
|
||||||
onComplete,
|
|
||||||
);
|
|
||||||
|
|
||||||
@ffi.Native<
|
|
||||||
ffi.Void Function(
|
|
||||||
ffi.Pointer<TSceneManager>,
|
|
||||||
ffi.Pointer<ffi.Float>,
|
|
||||||
ffi.Int,
|
|
||||||
ffi.Pointer<ffi.Float>,
|
|
||||||
ffi.Int,
|
|
||||||
ffi.Pointer<ffi.Float>,
|
|
||||||
ffi.Int,
|
|
||||||
ffi.Pointer<ffi.Uint16>,
|
|
||||||
ffi.Int,
|
|
||||||
ffi.Int,
|
|
||||||
ffi.Pointer<ffi.Pointer<TMaterialInstance>>,
|
|
||||||
ffi.Int,
|
|
||||||
ffi.Bool,
|
|
||||||
ffi.Pointer<
|
|
||||||
ffi
|
|
||||||
.NativeFunction<ffi.Void Function(ffi.Pointer<TSceneAsset>)>>)>(
|
|
||||||
isLeaf: true)
|
|
||||||
external void SceneManager_createGeometryRenderThread(
|
|
||||||
ffi.Pointer<TSceneManager> sceneManager,
|
|
||||||
ffi.Pointer<ffi.Float> vertices,
|
|
||||||
int numVertices,
|
|
||||||
ffi.Pointer<ffi.Float> normals,
|
|
||||||
int numNormals,
|
|
||||||
ffi.Pointer<ffi.Float> uvs,
|
|
||||||
int numUvs,
|
|
||||||
ffi.Pointer<ffi.Uint16> indices,
|
|
||||||
int numIndices,
|
|
||||||
int primitiveType,
|
|
||||||
ffi.Pointer<ffi.Pointer<TMaterialInstance>> materialInstances,
|
|
||||||
int materialInstanceCount,
|
|
||||||
bool keepData,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TSceneAsset>)>>
|
|
||||||
callback,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
@ffi.Native<
|
@ffi.Native<
|
||||||
ffi.Void Function(
|
ffi.Void Function(
|
||||||
ffi.Pointer<TSceneManager>,
|
ffi.Pointer<TGltfAssetLoader>,
|
||||||
|
ffi.Pointer<TGltfResourceLoader>,
|
||||||
|
ffi.Pointer<TEngine>,
|
||||||
|
ffi.Pointer<TNameComponentManager>,
|
||||||
ffi.Pointer<ffi.Uint8>,
|
ffi.Pointer<ffi.Uint8>,
|
||||||
ffi.Size,
|
ffi.Size,
|
||||||
ffi.Int,
|
ffi.Size,
|
||||||
ffi.Bool,
|
|
||||||
ffi.Int,
|
|
||||||
ffi.Int,
|
|
||||||
ffi.Bool,
|
|
||||||
ffi.Pointer<
|
ffi.Pointer<
|
||||||
ffi
|
ffi
|
||||||
.NativeFunction<ffi.Void Function(ffi.Pointer<TSceneAsset>)>>)>(
|
.NativeFunction<ffi.Void Function(ffi.Pointer<TSceneAsset>)>>)>(
|
||||||
isLeaf: true)
|
isLeaf: true)
|
||||||
external void SceneManager_loadGlbFromBufferRenderThread(
|
external void SceneAsset_loadGlbRenderThread(
|
||||||
ffi.Pointer<TSceneManager> sceneManager,
|
ffi.Pointer<TGltfAssetLoader> tAssetLoader,
|
||||||
|
ffi.Pointer<TGltfResourceLoader> tResourceLoader,
|
||||||
|
ffi.Pointer<TEngine> tEngine,
|
||||||
|
ffi.Pointer<TNameComponentManager> tNameComponentManager,
|
||||||
ffi.Pointer<ffi.Uint8> data,
|
ffi.Pointer<ffi.Uint8> data,
|
||||||
int length,
|
int length,
|
||||||
int numInstances,
|
int numInstances,
|
||||||
bool keepData,
|
|
||||||
int priority,
|
|
||||||
int layer,
|
|
||||||
bool loadResourcesAsync,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TSceneAsset>)>>
|
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TSceneAsset>)>>
|
||||||
callback,
|
callback,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ffi.Native<
|
|
||||||
ffi.Void Function(
|
|
||||||
ffi.Pointer<TSceneManager>,
|
|
||||||
ffi.Pointer<
|
|
||||||
ffi.NativeFunction<
|
|
||||||
ffi.Void Function(
|
|
||||||
ffi.Pointer<TMaterialInstance>)>>)>(isLeaf: true)
|
|
||||||
external void SceneManager_createUnlitMaterialInstanceRenderThread(
|
|
||||||
ffi.Pointer<TSceneManager> sceneManager,
|
|
||||||
ffi.Pointer<
|
|
||||||
ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TMaterialInstance>)>>
|
|
||||||
callback,
|
|
||||||
);
|
|
||||||
|
|
||||||
@ffi.Native<
|
|
||||||
ffi.Void Function(
|
|
||||||
ffi.Pointer<TSceneManager>,
|
|
||||||
ffi.Pointer<
|
|
||||||
ffi.NativeFunction<
|
|
||||||
ffi.Void Function(
|
|
||||||
ffi.Pointer<TMaterialInstance>)>>)>(isLeaf: true)
|
|
||||||
external void SceneManager_createUnlitFixedSizeMaterialInstanceRenderThread(
|
|
||||||
ffi.Pointer<TSceneManager> sceneManager,
|
|
||||||
ffi.Pointer<
|
|
||||||
ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TMaterialInstance>)>>
|
|
||||||
callback,
|
|
||||||
);
|
|
||||||
|
|
||||||
@ffi.Native<
|
|
||||||
ffi.Void Function(
|
|
||||||
ffi.Pointer<TSceneManager>,
|
|
||||||
ffi.Pointer<ffi.Char>,
|
|
||||||
ffi.Int,
|
|
||||||
ffi.Bool,
|
|
||||||
ffi.Pointer<
|
|
||||||
ffi
|
|
||||||
.NativeFunction<ffi.Void Function(ffi.Pointer<TSceneAsset>)>>)>(
|
|
||||||
isLeaf: true)
|
|
||||||
external void SceneManager_loadGlbRenderThread(
|
|
||||||
ffi.Pointer<TSceneManager> sceneManager,
|
|
||||||
ffi.Pointer<ffi.Char> assetPath,
|
|
||||||
int numInstances,
|
|
||||||
bool keepData,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TSceneAsset>)>>
|
|
||||||
callback,
|
|
||||||
);
|
|
||||||
|
|
||||||
@ffi.Native<
|
|
||||||
ffi.Void Function(
|
|
||||||
ffi.Pointer<TSceneManager>,
|
|
||||||
ffi.Pointer<ffi.Char>,
|
|
||||||
ffi.Pointer<ffi.Char>,
|
|
||||||
ffi.Bool,
|
|
||||||
ffi.Pointer<
|
|
||||||
ffi
|
|
||||||
.NativeFunction<ffi.Void Function(ffi.Pointer<TSceneAsset>)>>)>(
|
|
||||||
isLeaf: true)
|
|
||||||
external void SceneManager_loadGltfRenderThread(
|
|
||||||
ffi.Pointer<TSceneManager> sceneManager,
|
|
||||||
ffi.Pointer<ffi.Char> assetPath,
|
|
||||||
ffi.Pointer<ffi.Char> relativePath,
|
|
||||||
bool keepData,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TSceneAsset>)>>
|
|
||||||
callback,
|
|
||||||
);
|
|
||||||
|
|
||||||
@ffi.Native<
|
|
||||||
ffi.Void Function(ffi.Pointer<TSceneManager>,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
|
||||||
external void SceneManager_destroyAllRenderThread(
|
|
||||||
ffi.Pointer<TSceneManager> tSceneManager,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
|
|
||||||
);
|
|
||||||
|
|
||||||
@ffi.Native<
|
|
||||||
ffi.Void Function(ffi.Pointer<TSceneManager>, ffi.Pointer<TSceneAsset>,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
|
||||||
external void SceneManager_destroyAssetRenderThread(
|
|
||||||
ffi.Pointer<TSceneManager> tSceneManager,
|
|
||||||
ffi.Pointer<TSceneAsset> sceneAsset,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
|
|
||||||
);
|
|
||||||
|
|
||||||
@ffi.Native<
|
|
||||||
ffi.Void Function(ffi.Pointer<TSceneManager>,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
|
||||||
external void SceneManager_destroyAssetsRenderThread(
|
|
||||||
ffi.Pointer<TSceneManager> tSceneManager,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
|
|
||||||
);
|
|
||||||
|
|
||||||
@ffi.Native<
|
|
||||||
ffi.Void Function(ffi.Pointer<TSceneManager>,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
|
||||||
external void SceneManager_destroyLightsRenderThread(
|
|
||||||
ffi.Pointer<TSceneManager> tSceneManager,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
|
|
||||||
);
|
|
||||||
|
|
||||||
@ffi.Native<
|
|
||||||
ffi.Void Function(
|
|
||||||
ffi.Pointer<TSceneManager>,
|
|
||||||
ffi.Uint8,
|
|
||||||
ffi.Float,
|
|
||||||
ffi.Float,
|
|
||||||
ffi.Float,
|
|
||||||
ffi.Float,
|
|
||||||
ffi.Float,
|
|
||||||
ffi.Float,
|
|
||||||
ffi.Float,
|
|
||||||
ffi.Float,
|
|
||||||
ffi.Float,
|
|
||||||
ffi.Float,
|
|
||||||
ffi.Float,
|
|
||||||
ffi.Float,
|
|
||||||
ffi.Float,
|
|
||||||
ffi.Float,
|
|
||||||
ffi.Bool,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>>)>(
|
|
||||||
isLeaf: true)
|
|
||||||
external void SceneManager_addLightRenderThread(
|
|
||||||
ffi.Pointer<TSceneManager> tSceneManager,
|
|
||||||
int type,
|
|
||||||
double colour,
|
|
||||||
double intensity,
|
|
||||||
double posX,
|
|
||||||
double posY,
|
|
||||||
double posZ,
|
|
||||||
double dirX,
|
|
||||||
double dirY,
|
|
||||||
double dirZ,
|
|
||||||
double falloffRadius,
|
|
||||||
double spotLightConeInner,
|
|
||||||
double spotLightConeOuter,
|
|
||||||
double sunAngularRadius,
|
|
||||||
double sunHaloSize,
|
|
||||||
double sunHaloFallof,
|
|
||||||
bool shadows,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(EntityId)>> callback,
|
|
||||||
);
|
|
||||||
|
|
||||||
@ffi.Native<
|
|
||||||
ffi.Void Function(ffi.Pointer<TSceneManager>, EntityId,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>>)>(isLeaf: true)
|
|
||||||
external void SceneManager_removeLightRenderThread(
|
|
||||||
ffi.Pointer<TSceneManager> tSceneManager,
|
|
||||||
int entityId,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function()>> callback,
|
|
||||||
);
|
|
||||||
|
|
||||||
@ffi.Native<
|
|
||||||
ffi.Void Function(
|
|
||||||
ffi.Pointer<TSceneManager>,
|
|
||||||
ffi.Pointer<
|
|
||||||
ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TCamera>)>>)>(
|
|
||||||
isLeaf: true)
|
|
||||||
external void SceneManager_createCameraRenderThread(
|
|
||||||
ffi.Pointer<TSceneManager> tSceneManager,
|
|
||||||
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TCamera>)>>
|
|
||||||
callback,
|
|
||||||
);
|
|
||||||
|
|
||||||
@ffi.Native<
|
@ffi.Native<
|
||||||
ffi.Void Function(
|
ffi.Void Function(
|
||||||
ffi.Pointer<TSceneAsset>,
|
ffi.Pointer<TSceneAsset>,
|
||||||
|
|||||||
@@ -129,7 +129,8 @@ class ThermionViewerFFI extends ThermionViewer {
|
|||||||
///
|
///
|
||||||
@override
|
@override
|
||||||
Future render() async {
|
Future render() async {
|
||||||
await withVoidCallback((cb) => RenderTicker_renderRenderThread(app.renderTicker, 0, cb));
|
await withVoidCallback(
|
||||||
|
(cb) => RenderTicker_renderRenderThread(app.renderTicker, 0, cb));
|
||||||
}
|
}
|
||||||
|
|
||||||
double _msPerFrame = 1000.0 / 60.0;
|
double _msPerFrame = 1000.0 / 60.0;
|
||||||
@@ -191,7 +192,8 @@ class ThermionViewerFFI extends ThermionViewer {
|
|||||||
@override
|
@override
|
||||||
Future setBackgroundImage(String path, {bool fillHeight = false}) async {
|
Future setBackgroundImage(String path, {bool fillHeight = false}) async {
|
||||||
final imageData = await loadAsset(path);
|
final imageData = await loadAsset(path);
|
||||||
_backgroundImage = await BackgroundImage.create(this, scene, imageData);
|
_backgroundImage ??= await BackgroundImage.create(this, scene);
|
||||||
|
await _backgroundImage!.setImage(imageData);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -199,7 +201,13 @@ class ThermionViewerFFI extends ThermionViewer {
|
|||||||
///
|
///
|
||||||
@override
|
@override
|
||||||
Future setBackgroundColor(double r, double g, double b, double a) async {
|
Future setBackgroundColor(double r, double g, double b, double a) async {
|
||||||
throw UnimplementedError();
|
// we don't want to use the Renderer clearColor, because this only applies
|
||||||
|
// to clearing the swapchain. Even if this Viewer is rendered into the
|
||||||
|
// swapchain, we don't necessarily (?) want to set the clear color,
|
||||||
|
// because that will affect other views.
|
||||||
|
// We therefore use the background image as the color;
|
||||||
|
_backgroundImage ??= await BackgroundImage.create(this, scene);
|
||||||
|
await _backgroundImage!.setBackgroundColor(r, g, b, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -318,8 +326,8 @@ class ThermionViewerFFI extends ThermionViewer {
|
|||||||
///
|
///
|
||||||
@override
|
@override
|
||||||
Future<ThermionEntity> addDirectLight(DirectLight directLight) async {
|
Future<ThermionEntity> addDirectLight(DirectLight directLight) async {
|
||||||
var entity = LightManager_createLight(app.engine,
|
var entity = LightManager_createLight(app.engine, app.lightManager,
|
||||||
app.lightManager, TLightType.values[directLight.type.index]);
|
TLightType.values[directLight.type.index]);
|
||||||
if (entity == FILAMENT_ASSET_ERROR) {
|
if (entity == FILAMENT_ASSET_ERROR) {
|
||||||
throw Exception("Failed to add light to scene");
|
throw Exception("Failed to add light to scene");
|
||||||
}
|
}
|
||||||
@@ -391,14 +399,16 @@ class ThermionViewerFFI extends ThermionViewer {
|
|||||||
int priority = 4,
|
int priority = 4,
|
||||||
int layer = 0,
|
int layer = 0,
|
||||||
bool loadResourcesAsync = false}) async {
|
bool loadResourcesAsync = false}) async {
|
||||||
var asset = SceneAsset_loadGlb(
|
var asset = await withPointerCallback<TSceneAsset>((cb) =>
|
||||||
app.gltfAssetLoader,
|
SceneAsset_loadGlbRenderThread(
|
||||||
app.gltfResourceLoader,
|
app.gltfAssetLoader,
|
||||||
app.engine,
|
app.gltfResourceLoader,
|
||||||
app.nameComponentManager,
|
app.engine,
|
||||||
data.address,
|
app.nameComponentManager,
|
||||||
data.length,
|
data.address,
|
||||||
numInstances);
|
data.length,
|
||||||
|
numInstances,
|
||||||
|
cb));
|
||||||
|
|
||||||
if (asset == nullptr) {
|
if (asset == nullptr) {
|
||||||
throw Exception("An error occurred loading the asset");
|
throw Exception("An error occurred loading the asset");
|
||||||
@@ -440,7 +450,9 @@ class ThermionViewerFFI extends ThermionViewer {
|
|||||||
@override
|
@override
|
||||||
Future destroyAsset(covariant FFIAsset asset) async {
|
Future destroyAsset(covariant FFIAsset asset) async {
|
||||||
await scene.remove(asset);
|
await scene.remove(asset);
|
||||||
SceneAsset_destroy(asset.asset);
|
|
||||||
|
await withVoidCallback((cb) => SceneAsset_destroyRenderThread(asset.asset, cb));
|
||||||
|
|
||||||
// if (asset.boundingBoxAsset != null) {
|
// if (asset.boundingBoxAsset != null) {
|
||||||
// await asset.setBoundingBoxVisibility(false);
|
// await asset.setBoundingBoxVisibility(false);
|
||||||
// await withVoidCallback((callback) =>
|
// await withVoidCallback((callback) =>
|
||||||
@@ -466,7 +478,7 @@ class ThermionViewerFFI extends ThermionViewer {
|
|||||||
///
|
///
|
||||||
@override
|
@override
|
||||||
Future setToneMapping(ToneMapper mapper) async {
|
Future setToneMapping(ToneMapper mapper) async {
|
||||||
view.setToneMapper(mapper);
|
await view.setToneMapper(mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -774,4 +786,5 @@ class ThermionViewerFFI extends ThermionViewer {
|
|||||||
// gizmoEntities.toSet()
|
// gizmoEntities.toSet()
|
||||||
// ..add(SceneAsset_getEntity(gizmo.cast<TSceneAsset>())));
|
// ..add(SceneAsset_getEntity(gizmo.cast<TSceneAsset>())));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ namespace thermion
|
|||||||
void (*onComplete)());
|
void (*onComplete)());
|
||||||
|
|
||||||
EMSCRIPTEN_KEEPALIVE void Material_createInstanceRenderThread(TMaterial *tMaterial, void (*onComplete)(TMaterialInstance *));
|
EMSCRIPTEN_KEEPALIVE void Material_createInstanceRenderThread(TMaterial *tMaterial, void (*onComplete)(TMaterialInstance *));
|
||||||
|
EMSCRIPTEN_KEEPALIVE void Material_createImageMaterialRenderThread(TEngine *tEngine, void (*onComplete)(TMaterial *));
|
||||||
|
|
||||||
EMSCRIPTEN_KEEPALIVE void View_setToneMappingRenderThread(TView *tView, TEngine *tEngine, TToneMapping toneMapping);
|
EMSCRIPTEN_KEEPALIVE void View_setToneMappingRenderThread(TView *tView, TEngine *tEngine, TToneMapping toneMapping);
|
||||||
EMSCRIPTEN_KEEPALIVE void View_setBloomRenderThread(TView *tView, bool enabled, double strength);
|
EMSCRIPTEN_KEEPALIVE void View_setBloomRenderThread(TView *tView, bool enabled, double strength);
|
||||||
@@ -82,60 +83,17 @@ namespace thermion
|
|||||||
|
|
||||||
FilamentRenderCallback make_render_callback_fn_pointer(FilamentRenderCallback);
|
FilamentRenderCallback make_render_callback_fn_pointer(FilamentRenderCallback);
|
||||||
|
|
||||||
EMSCRIPTEN_KEEPALIVE void SceneManager_createGridRenderThread(TSceneManager *tSceneManager, TMaterial *tMaterial, void (*callback)(TSceneAsset *));
|
EMSCRIPTEN_KEEPALIVE void SceneAsset_destroyRenderThread(TSceneAsset *tSceneAsset, void (*onComplete)());
|
||||||
|
EMSCRIPTEN_KEEPALIVE void SceneAsset_loadGlbRenderThread(
|
||||||
EMSCRIPTEN_KEEPALIVE TGizmo *SceneManager_createGizmoRenderThread(
|
TGltfAssetLoader *tAssetLoader,
|
||||||
TSceneManager *tSceneManager,
|
TGltfResourceLoader *tResourceLoader,
|
||||||
TView *tView,
|
TEngine *tEngine,
|
||||||
TScene *tScene,
|
TNameComponentManager *tNameComponentManager,
|
||||||
TGizmoType tGizmoType,
|
uint8_t *data,
|
||||||
void (*onComplete)(TGizmo *));
|
size_t length,
|
||||||
|
size_t numInstances,
|
||||||
EMSCRIPTEN_KEEPALIVE void SceneManager_createGeometryRenderThread(
|
void (*callback)(TSceneAsset *)
|
||||||
TSceneManager *sceneManager,
|
);
|
||||||
float *vertices,
|
|
||||||
int numVertices,
|
|
||||||
float *normals,
|
|
||||||
int numNormals,
|
|
||||||
float *uvs,
|
|
||||||
int numUvs,
|
|
||||||
uint16_t *indices,
|
|
||||||
int numIndices,
|
|
||||||
int primitiveType,
|
|
||||||
TMaterialInstance **materialInstances,
|
|
||||||
int materialInstanceCount,
|
|
||||||
bool keepData,
|
|
||||||
void (*callback)(TSceneAsset *));
|
|
||||||
EMSCRIPTEN_KEEPALIVE void SceneManager_loadGlbFromBufferRenderThread(TSceneManager *sceneManager, const uint8_t *const data, size_t length, int numInstances, bool keepData, int priority, int layer, bool loadResourcesAsync, void (*callback)(TSceneAsset *));
|
|
||||||
EMSCRIPTEN_KEEPALIVE void SceneManager_createUnlitMaterialInstanceRenderThread(TSceneManager *sceneManager, void (*callback)(TMaterialInstance *));
|
|
||||||
EMSCRIPTEN_KEEPALIVE void SceneManager_createUnlitFixedSizeMaterialInstanceRenderThread(TSceneManager *sceneManager, void (*callback)(TMaterialInstance *));
|
|
||||||
EMSCRIPTEN_KEEPALIVE void SceneManager_loadGlbRenderThread(TSceneManager *sceneManager, const char *assetPath, int numInstances, bool keepData, void (*callback)(TSceneAsset *));
|
|
||||||
EMSCRIPTEN_KEEPALIVE void SceneManager_loadGltfRenderThread(TSceneManager *sceneManager, const char *assetPath, const char *relativePath, bool keepData, void (*callback)(TSceneAsset *));
|
|
||||||
EMSCRIPTEN_KEEPALIVE void SceneManager_destroyAllRenderThread(TSceneManager *tSceneManager, void (*callback)());
|
|
||||||
EMSCRIPTEN_KEEPALIVE void SceneManager_destroyAssetRenderThread(TSceneManager *tSceneManager, TSceneAsset *sceneAsset, void (*callback)());
|
|
||||||
EMSCRIPTEN_KEEPALIVE void SceneManager_destroyAssetsRenderThread(TSceneManager *tSceneManager, void (*callback)());
|
|
||||||
EMSCRIPTEN_KEEPALIVE void SceneManager_destroyLightsRenderThread(TSceneManager *tSceneManager, void (*callback)());
|
|
||||||
EMSCRIPTEN_KEEPALIVE void SceneManager_addLightRenderThread(
|
|
||||||
TSceneManager *tSceneManager,
|
|
||||||
uint8_t type,
|
|
||||||
float colour,
|
|
||||||
float intensity,
|
|
||||||
float posX,
|
|
||||||
float posY,
|
|
||||||
float posZ,
|
|
||||||
float dirX,
|
|
||||||
float dirY,
|
|
||||||
float dirZ,
|
|
||||||
float falloffRadius,
|
|
||||||
float spotLightConeInner,
|
|
||||||
float spotLightConeOuter,
|
|
||||||
float sunAngularRadius,
|
|
||||||
float sunHaloSize,
|
|
||||||
float sunHaloFallof,
|
|
||||||
bool shadows,
|
|
||||||
void (*callback)(EntityId));
|
|
||||||
EMSCRIPTEN_KEEPALIVE void SceneManager_removeLightRenderThread(TSceneManager *tSceneManager, EntityId entityId, void (*callback)());
|
|
||||||
EMSCRIPTEN_KEEPALIVE void SceneManager_createCameraRenderThread(TSceneManager *tSceneManager, void (*callback)(TCamera *));
|
|
||||||
EMSCRIPTEN_KEEPALIVE void SceneAsset_createInstanceRenderThread(TSceneAsset *asset, TMaterialInstance **tMaterialInstances, int materialInstanceCount, void (*callback)(TSceneAsset *));
|
EMSCRIPTEN_KEEPALIVE void SceneAsset_createInstanceRenderThread(TSceneAsset *asset, TMaterialInstance **tMaterialInstances, int materialInstanceCount, void (*callback)(TSceneAsset *));
|
||||||
EMSCRIPTEN_KEEPALIVE void SceneAsset_createGeometryRenderThread(
|
EMSCRIPTEN_KEEPALIVE void SceneAsset_createGeometryRenderThread(
|
||||||
TEngine *tEngine,
|
TEngine *tEngine,
|
||||||
|
|||||||
@@ -319,6 +319,16 @@ extern "C"
|
|||||||
auto fut = _rl->add_task(lambda);
|
auto fut = _rl->add_task(lambda);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EMSCRIPTEN_KEEPALIVE void Material_createImageMaterialRenderThread(TEngine *tEngine, void (*onComplete)(TMaterial *)) {
|
||||||
|
std::packaged_task<void()> lambda(
|
||||||
|
[=]() mutable
|
||||||
|
{
|
||||||
|
auto *instance = Material_createImageMaterial(tEngine);
|
||||||
|
onComplete(instance);
|
||||||
|
});
|
||||||
|
auto fut = _rl->add_task(lambda);
|
||||||
|
}
|
||||||
|
|
||||||
EMSCRIPTEN_KEEPALIVE void Material_createInstanceRenderThread(TMaterial *tMaterial, void (*onComplete)(TMaterialInstance *))
|
EMSCRIPTEN_KEEPALIVE void Material_createInstanceRenderThread(TMaterial *tMaterial, void (*onComplete)(TMaterialInstance *))
|
||||||
{
|
{
|
||||||
std::packaged_task<void()> lambda(
|
std::packaged_task<void()> lambda(
|
||||||
@@ -330,6 +340,34 @@ extern "C"
|
|||||||
auto fut = _rl->add_task(lambda);
|
auto fut = _rl->add_task(lambda);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EMSCRIPTEN_KEEPALIVE void SceneAsset_destroyRenderThread(TSceneAsset *tSceneAsset, void (*onComplete)()) {
|
||||||
|
std::packaged_task<void()> lambda(
|
||||||
|
[=]() mutable
|
||||||
|
{
|
||||||
|
SceneAsset_destroy(tSceneAsset);
|
||||||
|
onComplete();
|
||||||
|
});
|
||||||
|
auto fut = _rl->add_task(lambda);
|
||||||
|
}
|
||||||
|
|
||||||
|
EMSCRIPTEN_KEEPALIVE void SceneAsset_loadGlbRenderThread(
|
||||||
|
TGltfAssetLoader *tAssetLoader,
|
||||||
|
TGltfResourceLoader *tResourceLoader,
|
||||||
|
TEngine *tEngine,
|
||||||
|
TNameComponentManager *tNameComponentManager,
|
||||||
|
uint8_t *data,
|
||||||
|
size_t length,
|
||||||
|
size_t numInstances,
|
||||||
|
void (*callback)(TSceneAsset *)
|
||||||
|
) {
|
||||||
|
std::packaged_task<void()> lambda(
|
||||||
|
[=]
|
||||||
|
{
|
||||||
|
auto sceneAsset = SceneAsset_loadGlb(tAssetLoader, tResourceLoader, tEngine, tNameComponentManager, data, length, numInstances);
|
||||||
|
callback(sceneAsset);
|
||||||
|
});
|
||||||
|
auto fut = _rl->add_task(lambda);
|
||||||
|
}
|
||||||
|
|
||||||
EMSCRIPTEN_KEEPALIVE void SceneAsset_createGeometryRenderThread(
|
EMSCRIPTEN_KEEPALIVE void SceneAsset_createGeometryRenderThread(
|
||||||
TEngine *tEngine,
|
TEngine *tEngine,
|
||||||
|
|||||||
Reference in New Issue
Block a user