remove TMaterialKey struct and pass directly as function params

This commit is contained in:
Nick Fisher
2025-05-14 08:15:09 +08:00
parent d392daa2e6
commit 11ff6c9053
10 changed files with 1196 additions and 754 deletions

View File

@@ -887,11 +887,86 @@ external void Gizmo_unhighlight(
); );
@ffi.Native< @ffi.Native<
ffi.Pointer<TMaterialInstance> Function(ffi.Pointer<TMaterialProvider>, ffi.Pointer<TMaterialInstance> Function(
ffi.Pointer<TMaterialKey>)>(isLeaf: true) ffi.Pointer<TMaterialProvider>,
ffi.Bool,
ffi.Bool,
ffi.Bool,
ffi.Bool,
ffi.Bool,
ffi.Bool,
ffi.Bool,
ffi.Bool,
ffi.Int,
ffi.Bool,
ffi.Bool,
ffi.Uint8,
ffi.Bool,
ffi.Uint8,
ffi.Uint8,
ffi.Bool,
ffi.Uint8,
ffi.Bool,
ffi.Uint8,
ffi.Bool,
ffi.Uint8,
ffi.Bool,
ffi.Bool,
ffi.Bool,
ffi.Uint8,
ffi.Uint8,
ffi.Uint8,
ffi.Bool,
ffi.Uint8,
ffi.Bool,
ffi.Uint8,
ffi.Bool,
ffi.Uint8,
ffi.Bool,
ffi.Uint8,
ffi.Bool,
ffi.Bool,
ffi.Bool)>(isLeaf: true)
external ffi.Pointer<TMaterialInstance> MaterialProvider_createMaterialInstance( external ffi.Pointer<TMaterialInstance> MaterialProvider_createMaterialInstance(
ffi.Pointer<TMaterialProvider> provider, ffi.Pointer<TMaterialProvider> provider,
ffi.Pointer<TMaterialKey> key, bool doubleSided,
bool unlit,
bool hasVertexColors,
bool hasBaseColorTexture,
bool hasNormalTexture,
bool hasOcclusionTexture,
bool hasEmissiveTexture,
bool useSpecularGlossiness,
int alphaMode,
bool enableDiagnostics,
bool hasMetallicRoughnessTexture,
int metallicRoughnessUV,
bool hasSpecularGlossinessTexture,
int specularGlossinessUV,
int baseColorUV,
bool hasClearCoatTexture,
int clearCoatUV,
bool hasClearCoatRoughnessTexture,
int clearCoatRoughnessUV,
bool hasClearCoatNormalTexture,
int clearCoatNormalUV,
bool hasClearCoat,
bool hasTransmission,
bool hasTextureTransforms,
int emissiveUV,
int aoUV,
int normalUV,
bool hasTransmissionTexture,
int transmissionUV,
bool hasSheenColorTexture,
int sheenColorUV,
bool hasSheenRoughnessTexture,
int sheenRoughnessUV,
bool hasVolumeThicknessTexture,
int volumeThicknessUV,
bool hasSheen,
bool hasIOR,
bool hasVolume,
); );
@ffi.Native< @ffi.Native<
@@ -2121,14 +2196,88 @@ external void SceneAsset_createGeometryRenderThread(
@ffi.Native< @ffi.Native<
ffi.Void Function( ffi.Void Function(
ffi.Pointer<TMaterialProvider>, ffi.Pointer<TMaterialProvider>,
ffi.Pointer<TMaterialKey>, ffi.Bool,
ffi.Bool,
ffi.Bool,
ffi.Bool,
ffi.Bool,
ffi.Bool,
ffi.Bool,
ffi.Bool,
ffi.Int,
ffi.Bool,
ffi.Bool,
ffi.Uint8,
ffi.Bool,
ffi.Uint8,
ffi.Uint8,
ffi.Bool,
ffi.Uint8,
ffi.Bool,
ffi.Uint8,
ffi.Bool,
ffi.Uint8,
ffi.Bool,
ffi.Bool,
ffi.Bool,
ffi.Uint8,
ffi.Uint8,
ffi.Uint8,
ffi.Bool,
ffi.Uint8,
ffi.Bool,
ffi.Uint8,
ffi.Bool,
ffi.Uint8,
ffi.Bool,
ffi.Uint8,
ffi.Bool,
ffi.Bool,
ffi.Bool,
ffi.Pointer< ffi.Pointer<
ffi.NativeFunction< ffi.NativeFunction<
ffi.Void Function( ffi.Void Function(
ffi.Pointer<TMaterialInstance>)>>)>(isLeaf: true) ffi.Pointer<TMaterialInstance>)>>)>(isLeaf: true)
external void MaterialProvider_createMaterialInstanceRenderThread( external void MaterialProvider_createMaterialInstanceRenderThread(
ffi.Pointer<TMaterialProvider> tMaterialProvider, ffi.Pointer<TMaterialProvider> tMaterialProvider,
ffi.Pointer<TMaterialKey> tKey, bool doubleSided,
bool unlit,
bool hasVertexColors,
bool hasBaseColorTexture,
bool hasNormalTexture,
bool hasOcclusionTexture,
bool hasEmissiveTexture,
bool useSpecularGlossiness,
int alphaMode,
bool enableDiagnostics,
bool hasMetallicRoughnessTexture,
int metallicRoughnessUV,
bool hasSpecularGlossinessTexture,
int specularGlossinessUV,
int baseColorUV,
bool hasClearCoatTexture,
int clearCoatUV,
bool hasClearCoatRoughnessTexture,
int clearCoatRoughnessUV,
bool hasClearCoatNormalTexture,
int clearCoatNormalUV,
bool hasClearCoat,
bool hasTransmission,
bool hasTextureTransforms,
int emissiveUV,
int aoUV,
int normalUV,
bool hasTransmissionTexture,
int transmissionUV,
bool hasSheenColorTexture,
int sheenColorUV,
bool hasSheenRoughnessTexture,
int sheenRoughnessUV,
bool hasVolumeThicknessTexture,
int volumeThicknessUV,
bool hasSheen,
bool hasIOR,
bool hasVolume,
ffi.Pointer< ffi.Pointer<
ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TMaterialInstance>)>> ffi.NativeFunction<ffi.Void Function(ffi.Pointer<TMaterialInstance>)>>
callback, callback,
@@ -3323,134 +3472,6 @@ final class TFilamentAsset extends ffi.Opaque {}
final class TColorGrading extends ffi.Opaque {} final class TColorGrading extends ffi.Opaque {}
final class UnnamedStruct1 extends ffi.Struct {
@ffi.Bool()
external bool hasMetallicRoughnessTexture;
@ffi.Uint8()
external int metallicRoughnessUV;
}
final class UnnamedStruct2 extends ffi.Struct {
@ffi.Bool()
external bool hasSpecularGlossinessTexture;
@ffi.Uint8()
external int specularGlossinessUV;
}
final class UnnamedUnion1 extends ffi.Union {
external UnnamedStruct1 unnamed;
external UnnamedStruct2 unnamed$1;
}
final class TMaterialKey extends ffi.Struct {
@ffi.Bool()
external bool doubleSided;
@ffi.Bool()
external bool unlit;
@ffi.Bool()
external bool hasVertexColors;
@ffi.Bool()
external bool hasBaseColorTexture;
@ffi.Bool()
external bool hasNormalTexture;
@ffi.Bool()
external bool hasOcclusionTexture;
@ffi.Bool()
external bool hasEmissiveTexture;
@ffi.Bool()
external bool useSpecularGlossiness;
@ffi.Int()
external int alphaMode;
@ffi.Bool()
external bool enableDiagnostics;
external UnnamedUnion1 unnamed;
@ffi.Uint8()
external int baseColorUV;
@ffi.Bool()
external bool hasClearCoatTexture;
@ffi.Uint8()
external int clearCoatUV;
@ffi.Bool()
external bool hasClearCoatRoughnessTexture;
@ffi.Uint8()
external int clearCoatRoughnessUV;
@ffi.Bool()
external bool hasClearCoatNormalTexture;
@ffi.Uint8()
external int clearCoatNormalUV;
@ffi.Bool()
external bool hasClearCoat;
@ffi.Bool()
external bool hasTransmission;
@ffi.Bool()
external bool hasTextureTransforms;
@ffi.Uint8()
external int emissiveUV;
@ffi.Uint8()
external int aoUV;
@ffi.Uint8()
external int normalUV;
@ffi.Bool()
external bool hasTransmissionTexture;
@ffi.Uint8()
external int transmissionUV;
@ffi.Bool()
external bool hasSheenColorTexture;
@ffi.Uint8()
external int sheenColorUV;
@ffi.Bool()
external bool hasSheenRoughnessTexture;
@ffi.Uint8()
external int sheenRoughnessUV;
@ffi.Bool()
external bool hasVolumeThicknessTexture;
@ffi.Uint8()
external int volumeThicknessUV;
@ffi.Bool()
external bool hasSheen;
@ffi.Bool()
external bool hasIOR;
@ffi.Bool()
external bool hasVolume;
}
final class double3 extends ffi.Struct { final class double3 extends ffi.Struct {
@ffi.Double() @ffi.Double()
external double x; external double x;

View File

@@ -255,7 +255,7 @@ sealed class Struct extends NativeType {
Struct(this._address); Struct(this._address);
static create<T extends Struct>() { static create<T extends Struct>() {
switch (T) { switch (T) {
case double4x4: case double4x4:
final ptr = double4x4.stackAlloc(); final ptr = double4x4.stackAlloc();
final arr1 = final arr1 =
@@ -901,7 +901,44 @@ extension type NativeLibrary(JSObject _) implements JSObject {
); );
external Pointer<TMaterialInstance> _MaterialProvider_createMaterialInstance( external Pointer<TMaterialInstance> _MaterialProvider_createMaterialInstance(
Pointer<TMaterialProvider> provider, Pointer<TMaterialProvider> provider,
Pointer<TMaterialKey> key, bool doubleSided,
bool unlit,
bool hasVertexColors,
bool hasBaseColorTexture,
bool hasNormalTexture,
bool hasOcclusionTexture,
bool hasEmissiveTexture,
bool useSpecularGlossiness,
int alphaMode,
bool enableDiagnostics,
bool hasMetallicRoughnessTexture,
int metallicRoughnessUV,
bool hasSpecularGlossinessTexture,
int specularGlossinessUV,
int baseColorUV,
bool hasClearCoatTexture,
int clearCoatUV,
bool hasClearCoatRoughnessTexture,
int clearCoatRoughnessUV,
bool hasClearCoatNormalTexture,
int clearCoatNormalUV,
bool hasClearCoat,
bool hasTransmission,
bool hasTextureTransforms,
int emissiveUV,
int aoUV,
int normalUV,
bool hasTransmissionTexture,
int transmissionUV,
bool hasSheenColorTexture,
int sheenColorUV,
bool hasSheenRoughnessTexture,
int sheenRoughnessUV,
bool hasVolumeThicknessTexture,
int volumeThicknessUV,
bool hasSheen,
bool hasIOR,
bool hasVolume,
); );
external Pointer<TRenderTarget> _RenderTarget_create( external Pointer<TRenderTarget> _RenderTarget_create(
Pointer<TEngine> tEngine, Pointer<TEngine> tEngine,
@@ -1558,7 +1595,44 @@ extension type NativeLibrary(JSObject _) implements JSObject {
); );
external void _MaterialProvider_createMaterialInstanceRenderThread( external void _MaterialProvider_createMaterialInstanceRenderThread(
Pointer<TMaterialProvider> tMaterialProvider, Pointer<TMaterialProvider> tMaterialProvider,
Pointer<TMaterialKey> tKey, bool doubleSided,
bool unlit,
bool hasVertexColors,
bool hasBaseColorTexture,
bool hasNormalTexture,
bool hasOcclusionTexture,
bool hasEmissiveTexture,
bool useSpecularGlossiness,
int alphaMode,
bool enableDiagnostics,
bool hasMetallicRoughnessTexture,
int metallicRoughnessUV,
bool hasSpecularGlossinessTexture,
int specularGlossinessUV,
int baseColorUV,
bool hasClearCoatTexture,
int clearCoatUV,
bool hasClearCoatRoughnessTexture,
int clearCoatRoughnessUV,
bool hasClearCoatNormalTexture,
int clearCoatNormalUV,
bool hasClearCoat,
bool hasTransmission,
bool hasTextureTransforms,
int emissiveUV,
int aoUV,
int normalUV,
bool hasTransmissionTexture,
int transmissionUV,
bool hasSheenColorTexture,
int sheenColorUV,
bool hasSheenRoughnessTexture,
int sheenRoughnessUV,
bool hasVolumeThicknessTexture,
int volumeThicknessUV,
bool hasSheen,
bool hasIOR,
bool hasVolume,
Pointer<self.NativeFunction<void Function(PointerClass<TMaterialInstance>)>> Pointer<self.NativeFunction<void Function(PointerClass<TMaterialInstance>)>>
callback, callback,
); );
@@ -3143,10 +3217,85 @@ void Gizmo_unhighlight(
self.Pointer<TMaterialInstance> MaterialProvider_createMaterialInstance( self.Pointer<TMaterialInstance> MaterialProvider_createMaterialInstance(
self.Pointer<TMaterialProvider> provider, self.Pointer<TMaterialProvider> provider,
self.Pointer<TMaterialKey> key, bool doubleSided,
bool unlit,
bool hasVertexColors,
bool hasBaseColorTexture,
bool hasNormalTexture,
bool hasOcclusionTexture,
bool hasEmissiveTexture,
bool useSpecularGlossiness,
int alphaMode,
bool enableDiagnostics,
bool hasMetallicRoughnessTexture,
int metallicRoughnessUV,
bool hasSpecularGlossinessTexture,
int specularGlossinessUV,
int baseColorUV,
bool hasClearCoatTexture,
int clearCoatUV,
bool hasClearCoatRoughnessTexture,
int clearCoatRoughnessUV,
bool hasClearCoatNormalTexture,
int clearCoatNormalUV,
bool hasClearCoat,
bool hasTransmission,
bool hasTextureTransforms,
int emissiveUV,
int aoUV,
int normalUV,
bool hasTransmissionTexture,
int transmissionUV,
bool hasSheenColorTexture,
int sheenColorUV,
bool hasSheenRoughnessTexture,
int sheenRoughnessUV,
bool hasVolumeThicknessTexture,
int volumeThicknessUV,
bool hasSheen,
bool hasIOR,
bool hasVolume,
) { ) {
final result = _lib._MaterialProvider_createMaterialInstance( final result = _lib._MaterialProvider_createMaterialInstance(
provider.cast(), key.cast()); provider.cast(),
doubleSided,
unlit,
hasVertexColors,
hasBaseColorTexture,
hasNormalTexture,
hasOcclusionTexture,
hasEmissiveTexture,
useSpecularGlossiness,
alphaMode,
enableDiagnostics,
hasMetallicRoughnessTexture,
metallicRoughnessUV,
hasSpecularGlossinessTexture,
specularGlossinessUV,
baseColorUV,
hasClearCoatTexture,
clearCoatUV,
hasClearCoatRoughnessTexture,
clearCoatRoughnessUV,
hasClearCoatNormalTexture,
clearCoatNormalUV,
hasClearCoat,
hasTransmission,
hasTextureTransforms,
emissiveUV,
aoUV,
normalUV,
hasTransmissionTexture,
transmissionUV,
hasSheenColorTexture,
sheenColorUV,
hasSheenRoughnessTexture,
sheenRoughnessUV,
hasVolumeThicknessTexture,
volumeThicknessUV,
hasSheen,
hasIOR,
hasVolume);
return self.Pointer<TMaterialInstance>(result); return self.Pointer<TMaterialInstance>(result);
} }
@@ -4493,12 +4642,88 @@ void SceneAsset_createGeometryRenderThread(
void MaterialProvider_createMaterialInstanceRenderThread( void MaterialProvider_createMaterialInstanceRenderThread(
self.Pointer<TMaterialProvider> tMaterialProvider, self.Pointer<TMaterialProvider> tMaterialProvider,
self.Pointer<TMaterialKey> tKey, bool doubleSided,
bool unlit,
bool hasVertexColors,
bool hasBaseColorTexture,
bool hasNormalTexture,
bool hasOcclusionTexture,
bool hasEmissiveTexture,
bool useSpecularGlossiness,
int alphaMode,
bool enableDiagnostics,
bool hasMetallicRoughnessTexture,
int metallicRoughnessUV,
bool hasSpecularGlossinessTexture,
int specularGlossinessUV,
int baseColorUV,
bool hasClearCoatTexture,
int clearCoatUV,
bool hasClearCoatRoughnessTexture,
int clearCoatRoughnessUV,
bool hasClearCoatNormalTexture,
int clearCoatNormalUV,
bool hasClearCoat,
bool hasTransmission,
bool hasTextureTransforms,
int emissiveUV,
int aoUV,
int normalUV,
bool hasTransmissionTexture,
int transmissionUV,
bool hasSheenColorTexture,
int sheenColorUV,
bool hasSheenRoughnessTexture,
int sheenRoughnessUV,
bool hasVolumeThicknessTexture,
int volumeThicknessUV,
bool hasSheen,
bool hasIOR,
bool hasVolume,
self.Pointer<self.NativeFunction<void Function(Pointer<TMaterialInstance>)>> self.Pointer<self.NativeFunction<void Function(Pointer<TMaterialInstance>)>>
callback, callback,
) { ) {
final result = _lib._MaterialProvider_createMaterialInstanceRenderThread( final result = _lib._MaterialProvider_createMaterialInstanceRenderThread(
tMaterialProvider.cast(), tKey.cast(), callback.cast()); tMaterialProvider.cast(),
doubleSided,
unlit,
hasVertexColors,
hasBaseColorTexture,
hasNormalTexture,
hasOcclusionTexture,
hasEmissiveTexture,
useSpecularGlossiness,
alphaMode,
enableDiagnostics,
hasMetallicRoughnessTexture,
metallicRoughnessUV,
hasSpecularGlossinessTexture,
specularGlossinessUV,
baseColorUV,
hasClearCoatTexture,
clearCoatUV,
hasClearCoatRoughnessTexture,
clearCoatRoughnessUV,
hasClearCoatNormalTexture,
clearCoatNormalUV,
hasClearCoat,
hasTransmission,
hasTextureTransforms,
emissiveUV,
aoUV,
normalUV,
hasTransmissionTexture,
transmissionUV,
hasSheenColorTexture,
sheenColorUV,
hasSheenRoughnessTexture,
sheenRoughnessUV,
hasVolumeThicknessTexture,
volumeThicknessUV,
hasSheen,
hasIOR,
hasVolume,
callback.cast());
return result; return result;
} }
@@ -6415,22 +6640,6 @@ sealed class TGizmoAxis {
static const Z = 2; static const Z = 2;
} }
extension TMaterialKeyExt on Pointer<TMaterialKey> {
TMaterialKey toDart() {
return TMaterialKey(this);
}
void setFrom(TMaterialKey dartType) {}
}
final class TMaterialKey extends self.Struct {
TMaterialKey(super._address);
static Pointer<TMaterialKey> stackAlloc() {
return Pointer<TMaterialKey>(_lib._stackAlloc<TMaterialKey>(0));
}
}
extension TSkyboxExt on Pointer<TSkybox> { extension TSkyboxExt on Pointer<TSkybox> {
TSkybox toDart() { TSkybox toDart() {
return TSkybox(this); return TSkybox(this);

View File

@@ -1,6 +1,5 @@
import 'package:animation_tools_dart/animation_tools_dart.dart'; import 'package:animation_tools_dart/animation_tools_dart.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:thermion_dart/src/bindings/src/js_interop.dart';
import 'package:thermion_dart/src/utils/src/matrix.dart'; import 'package:thermion_dart/src/utils/src/matrix.dart';
import 'package:thermion_dart/src/filament/src/implementation/ffi_filament_app.dart'; import 'package:thermion_dart/src/filament/src/implementation/ffi_filament_app.dart';
import 'package:thermion_dart/src/filament/src/implementation/ffi_material.dart'; import 'package:thermion_dart/src/filament/src/implementation/ffi_material.dart';
@@ -224,33 +223,33 @@ class FFIAsset extends ThermionAsset {
.setStencilOpDepthStencilPass(StencilOperation.REPLACE); .setStencilOpDepthStencilPass(StencilOperation.REPLACE);
await sourceMaterialInstance.setStencilReferenceValue(1); await sourceMaterialInstance.setStencilReferenceValue(1);
throw Exception("TODO");
// final materialInstancePtr =
// await withPointerCallback<TMaterialInstance>((cb) {
final materialInstancePtr = // MaterialProvider_createMaterialInstanceRenderThread(
await withPointerCallback<TMaterialInstance>((cb) { // app.ubershaderMaterialProvider, , cb);
final key = Struct.create<TMaterialKey>(); // });
MaterialProvider_createMaterialInstanceRenderThread( // final highlightMaterialInstance =
app.ubershaderMaterialProvider, key.address, cb); // FFIMaterialInstance(materialInstancePtr, app);
}); // await highlightMaterialInstance
final highlightMaterialInstance = // .setStencilCompareFunction(SamplerCompareFunction.NE);
FFIMaterialInstance(materialInstancePtr, app); // await highlightMaterialInstance.setStencilReferenceValue(1);
await highlightMaterialInstance
.setStencilCompareFunction(SamplerCompareFunction.NE);
await highlightMaterialInstance.setStencilReferenceValue(1);
await highlightMaterialInstance.setDepthCullingEnabled(false); // await highlightMaterialInstance.setDepthCullingEnabled(false);
await highlightMaterialInstance.setParameterFloat4( // await highlightMaterialInstance.setParameterFloat4(
"baseColorFactor", r, g, b, 1.0); // "baseColorFactor", r, g, b, 1.0);
var highlightInstance = await this // var highlightInstance = await this
.createInstance(materialInstances: [highlightMaterialInstance]); // .createInstance(materialInstances: [highlightMaterialInstance]);
_highlight = highlightInstance; // _highlight = highlightInstance;
await highlightMaterialInstance.setStencilReferenceValue(1); // await highlightMaterialInstance.setStencilReferenceValue(1);
RenderableManager_setPriority(app.renderableManager, targetEntity, 0); // RenderableManager_setPriority(app.renderableManager, targetEntity, 0);
TransformManager_setParent( // TransformManager_setParent(
app.transformManager, _highlight!.entity, entity, false); // app.transformManager, _highlight!.entity, entity, false);
} }
var targetHighlightEntity = _highlight!.entity; var targetHighlightEntity = _highlight!.entity;
@@ -365,9 +364,47 @@ class FFIAsset extends ThermionAsset {
// Create unlit material instance for the wireframe // Create unlit material instance for the wireframe
final materialInstancePtr = final materialInstancePtr =
await withPointerCallback<TMaterialInstance>((cb) { await withPointerCallback<TMaterialInstance>((cb) {
final key = Struct.create<TMaterialKey>();
MaterialProvider_createMaterialInstanceRenderThread( MaterialProvider_createMaterialInstanceRenderThread(
app.ubershaderMaterialProvider, key.address, cb); app.ubershaderMaterialProvider,
false,
true,
false,
false,
false,
false,
false,
false,
0,
false,
false,
0,
false,
0,
0,
false,
0,
false,
0,
false,
0,
false,
false,
false,
0,
0,
0,
false,
0,
false,
0,
false,
0,
false,
0,
false,
false,
false,
cb);
}); });
final material = FFIMaterialInstance(materialInstancePtr, app); final material = FFIMaterialInstance(materialInstancePtr, app);

View File

@@ -247,8 +247,8 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
/// ///
/// ///
Future destroyAsset(covariant FFIAsset asset) async { Future destroyAsset(covariant FFIAsset asset) async {
await withVoidCallback( await withVoidCallback((requestId, cb) =>
(requestId, cb) => SceneAsset_destroyRenderThread(asset.asset, requestId, cb)); SceneAsset_destroyRenderThread(asset.asset, requestId, cb));
await asset.dispose(); await asset.dispose();
} }
@@ -414,6 +414,8 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
bool enableDiagnostics = false, bool enableDiagnostics = false,
bool hasMetallicRoughnessTexture = false, bool hasMetallicRoughnessTexture = false,
int metallicRoughnessUV = 0, int metallicRoughnessUV = 0,
bool hasSpecularGlossiness = false,
int specularGlossinessUV = 0,
int baseColorUV = 0, int baseColorUV = 0,
bool hasClearCoatTexture = false, bool hasClearCoatTexture = false,
int clearCoatUV = 0, int clearCoatUV = 0,
@@ -438,54 +440,48 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
bool hasSheen = false, bool hasSheen = false,
bool hasIOR = false, bool hasIOR = false,
bool hasVolume = false}) async { bool hasVolume = false}) async {
late Pointer stackPtr;
if (FILAMENT_WASM) {
//stackPtr = stackSave();
}
final key = Struct.create<TMaterialKey>();
key.doubleSided = doubleSided;
key.unlit = unlit;
key.hasVertexColors = hasVertexColors;
key.hasBaseColorTexture = hasBaseColorTexture;
key.hasNormalTexture = hasNormalTexture;
key.hasOcclusionTexture = hasOcclusionTexture;
key.hasEmissiveTexture = hasEmissiveTexture;
key.useSpecularGlossiness = useSpecularGlossiness;
key.alphaMode = alphaMode.index;
key.enableDiagnostics = enableDiagnostics;
key.unnamed.unnamed.hasMetallicRoughnessTexture =
hasMetallicRoughnessTexture;
key.unnamed.unnamed.metallicRoughnessUV = 0;
key.baseColorUV = baseColorUV;
key.hasClearCoatTexture = hasClearCoatTexture;
key.clearCoatUV = clearCoatUV;
key.hasClearCoatRoughnessTexture = hasClearCoatRoughnessTexture;
key.clearCoatRoughnessUV = clearCoatRoughnessUV;
key.hasClearCoatNormalTexture = hasClearCoatNormalTexture;
key.clearCoatNormalUV = clearCoatNormalUV;
key.hasClearCoat = hasClearCoat;
key.hasTransmission = hasTransmission;
key.hasTextureTransforms = hasTextureTransforms;
key.emissiveUV = emissiveUV;
key.aoUV = aoUV;
key.normalUV = normalUV;
key.hasTransmissionTexture = hasTransmissionTexture;
key.transmissionUV = transmissionUV;
key.hasSheenColorTexture = hasSheenColorTexture;
key.sheenColorUV = sheenColorUV;
key.hasSheenRoughnessTexture = hasSheenRoughnessTexture;
key.sheenRoughnessUV = sheenRoughnessUV;
key.hasVolumeThicknessTexture = hasVolumeThicknessTexture;
key.volumeThicknessUV = volumeThicknessUV;
key.hasSheen = hasSheen;
key.hasIOR = hasIOR;
key.hasVolume = hasVolume;
final materialInstance = await withPointerCallback<TMaterialInstance>((cb) { final materialInstance = await withPointerCallback<TMaterialInstance>((cb) {
MaterialProvider_createMaterialInstanceRenderThread( MaterialProvider_createMaterialInstanceRenderThread(
ubershaderMaterialProvider, key.address, cb); ubershaderMaterialProvider,
doubleSided,
unlit,
hasVertexColors,
hasBaseColorTexture,
hasNormalTexture,
hasOcclusionTexture,
hasEmissiveTexture,
useSpecularGlossiness,
alphaMode.index,
enableDiagnostics,
hasMetallicRoughnessTexture,
metallicRoughnessUV,
hasSpecularGlossiness,
specularGlossinessUV,
baseColorUV,
hasClearCoatTexture,
clearCoatUV,
hasClearCoatRoughnessTexture,
clearCoatRoughnessUV,
hasClearCoatNormalTexture,
clearCoatNormalUV,
hasClearCoat,
hasTransmission,
hasTextureTransforms,
emissiveUV,
aoUV,
normalUV,
hasTransmissionTexture,
transmissionUV,
hasSheenColorTexture,
sheenColorUV,
hasSheenRoughnessTexture,
sheenRoughnessUV,
hasVolumeThicknessTexture,
volumeThicknessUV,
hasSheen,
hasIOR,
hasVolume,
cb);
}); });
if (FILAMENT_WASM) { if (FILAMENT_WASM) {
@@ -549,10 +545,11 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
}); });
if (FILAMENT_SINGLE_THREADED) { if (FILAMENT_SINGLE_THREADED) {
await withVoidCallback((requestId, cb) => Engine_executeRenderThread(engine, requestId, cb));
} else {
await withVoidCallback( await withVoidCallback(
(requestId, cb) => Engine_flushAndWaitRenderThread(engine, requestId, cb)); (requestId, cb) => Engine_executeRenderThread(engine, requestId, cb));
} else {
await withVoidCallback((requestId, cb) =>
Engine_flushAndWaitRenderThread(engine, requestId, cb));
} }
} }
@@ -868,8 +865,9 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
SceneAsset_createFromFilamentAssetRenderThread(engine, SceneAsset_createFromFilamentAssetRenderThread(engine,
gltfAssetLoader, nameComponentManager, filamentAsset, cb)); gltfAssetLoader, nameComponentManager, filamentAsset, cb));
await withVoidCallback((requestId, cb) => GltfResourceLoader_destroyRenderThread( await withVoidCallback((requestId, cb) =>
engine, gltfResourceLoader, requestId, cb)); GltfResourceLoader_destroyRenderThread(
engine, gltfResourceLoader, requestId, cb));
return FFIAsset(asset, this, animationManager.cast<TAnimationManager>()); return FFIAsset(asset, this, animationManager.cast<TAnimationManager>());
} finally { } finally {
@@ -886,11 +884,12 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
Future destroyView(covariant FFIView view) async { Future destroyView(covariant FFIView view) async {
View_setColorGrading(view.view, nullptr); View_setColorGrading(view.view, nullptr);
for (final cg in view.colorGrading.entries) { for (final cg in view.colorGrading.entries) {
await withVoidCallback( await withVoidCallback((requestId, cb) =>
(requestId, cb) => Engine_destroyColorGradingRenderThread(engine, cg.value, requestId, cb)); Engine_destroyColorGradingRenderThread(
engine, cg.value, requestId, cb));
} }
await withVoidCallback( await withVoidCallback((requestId, cb) =>
(requestId, cb) => Engine_destroyViewRenderThread(engine, view.view, requestId, cb)); Engine_destroyViewRenderThread(engine, view.view, requestId, cb));
for (final swapchain in _swapChains.keys) { for (final swapchain in _swapChains.keys) {
if (_swapChains[swapchain]!.contains(view)) { if (_swapChains[swapchain]!.contains(view)) {
_swapChains[swapchain]!.remove(view); _swapChains[swapchain]!.remove(view);
@@ -901,8 +900,8 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
} }
Future destroyScene(covariant FFIScene scene) async { Future destroyScene(covariant FFIScene scene) async {
await withVoidCallback( await withVoidCallback((requestId, cb) =>
(requestId, cb) => Engine_destroySceneRenderThread(engine, scene.scene, requestId, cb)); Engine_destroySceneRenderThread(engine, scene.scene, requestId, cb));
} }
Future<Pointer<TColorGrading>> createColorGrading(ToneMapper mapper) async { Future<Pointer<TColorGrading>> createColorGrading(ToneMapper mapper) async {
@@ -1028,10 +1027,11 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
/// ///
Future flush() async { Future flush() async {
if (FILAMENT_SINGLE_THREADED) { if (FILAMENT_SINGLE_THREADED) {
await withVoidCallback((requestId, cb) => Engine_executeRenderThread(engine, requestId, cb));
} else {
await withVoidCallback( await withVoidCallback(
(requestId, cb) => Engine_flushAndWaitRenderThread(engine, requestId, cb)); (requestId, cb) => Engine_executeRenderThread(engine, requestId, cb));
} else {
await withVoidCallback((requestId, cb) =>
Engine_flushAndWaitRenderThread(engine, requestId, cb));
} }
} }

View File

@@ -1,6 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:thermion_dart/src/bindings/src/js_interop.dart';
import 'package:thermion_dart/src/filament/src/interface/scene.dart'; import 'package:thermion_dart/src/filament/src/interface/scene.dart';
import 'package:thermion_dart/src/filament/src/implementation/ffi_filament_app.dart'; import 'package:thermion_dart/src/filament/src/implementation/ffi_filament_app.dart';
import 'package:thermion_dart/src/filament/src/implementation/ffi_render_target.dart'; import 'package:thermion_dart/src/filament/src/implementation/ffi_render_target.dart';

View File

@@ -45,68 +45,6 @@ extern "C"
typedef struct TFilamentAsset TFilamentAsset; typedef struct TFilamentAsset TFilamentAsset;
typedef struct TColorGrading TColorGrading; typedef struct TColorGrading TColorGrading;
struct TMaterialKey {
bool doubleSided;
bool unlit;
bool hasVertexColors;
bool hasBaseColorTexture;
bool hasNormalTexture;
bool hasOcclusionTexture;
bool hasEmissiveTexture;
bool useSpecularGlossiness;
int alphaMode;
bool enableDiagnostics;
union {
#ifdef __cplusplus
struct {
bool hasMetallicRoughnessTexture;
uint8_t metallicRoughnessUV;
};
struct {
bool hasSpecularGlossinessTexture;
uint8_t specularGlossinessUV;
};
#else
struct {
bool hasMetallicRoughnessTexture;
uint8_t metallicRoughnessUV;
};
struct {
bool hasSpecularGlossinessTexture;
uint8_t specularGlossinessUV;
};
#endif
};
uint8_t baseColorUV;
// -- 32 bit boundary --
bool hasClearCoatTexture;
uint8_t clearCoatUV;
bool hasClearCoatRoughnessTexture;
uint8_t clearCoatRoughnessUV;
bool hasClearCoatNormalTexture;
uint8_t clearCoatNormalUV;
bool hasClearCoat;
bool hasTransmission;
bool hasTextureTransforms;
// -- 32 bit boundary --
uint8_t emissiveUV;
uint8_t aoUV;
uint8_t normalUV;
bool hasTransmissionTexture;
uint8_t transmissionUV;
// -- 32 bit boundary --
bool hasSheenColorTexture;
uint8_t sheenColorUV;
bool hasSheenRoughnessTexture;
uint8_t sheenRoughnessUV;
bool hasVolumeThicknessTexture;
uint8_t volumeThicknessUV ;
bool hasSheen;
bool hasIOR;
bool hasVolume;
} ;
typedef struct TMaterialKey TMaterialKey;
typedef struct { typedef struct {
double x; double x;
double y; double y;

View File

@@ -9,7 +9,47 @@ extern "C"
#endif #endif
// EMSCRIPTEN_KEEPALIVE TMaterialProvider *MaterialProvider_create(TEngine *tEngine, uint8_t* data, size_t length); // EMSCRIPTEN_KEEPALIVE TMaterialProvider *MaterialProvider_create(TEngine *tEngine, uint8_t* data, size_t length);
EMSCRIPTEN_KEEPALIVE TMaterialInstance *MaterialProvider_createMaterialInstance(TMaterialProvider *provider, TMaterialKey *key); EMSCRIPTEN_KEEPALIVE TMaterialInstance *MaterialProvider_createMaterialInstance(
TMaterialProvider *provider,
bool doubleSided,
bool unlit,
bool hasVertexColors,
bool hasBaseColorTexture,
bool hasNormalTexture,
bool hasOcclusionTexture,
bool hasEmissiveTexture,
bool useSpecularGlossiness,
int alphaMode,
bool enableDiagnostics,
bool hasMetallicRoughnessTexture,
uint8_t metallicRoughnessUV,
bool hasSpecularGlossinessTexture,
uint8_t specularGlossinessUV,
uint8_t baseColorUV,
bool hasClearCoatTexture,
uint8_t clearCoatUV,
bool hasClearCoatRoughnessTexture,
uint8_t clearCoatRoughnessUV,
bool hasClearCoatNormalTexture,
uint8_t clearCoatNormalUV,
bool hasClearCoat,
bool hasTransmission,
bool hasTextureTransforms,
uint8_t emissiveUV,
uint8_t aoUV,
uint8_t normalUV,
bool hasTransmissionTexture,
uint8_t transmissionUV,
bool hasSheenColorTexture,
uint8_t sheenColorUV,
bool hasSheenRoughnessTexture,
uint8_t sheenRoughnessUV,
bool hasVolumeThicknessTexture,
uint8_t volumeThicknessUV ,
bool hasSheen,
bool hasIOR,
bool hasVolume
);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -116,7 +116,47 @@ namespace thermion
int materialInstanceCount, int materialInstanceCount,
void (*callback)(TSceneAsset *) void (*callback)(TSceneAsset *)
); );
void MaterialProvider_createMaterialInstanceRenderThread(TMaterialProvider *tMaterialProvider, TMaterialKey *tKey, void (*callback)(TMaterialInstance *)); void MaterialProvider_createMaterialInstanceRenderThread(
TMaterialProvider *tMaterialProvider,
bool doubleSided,
bool unlit,
bool hasVertexColors,
bool hasBaseColorTexture,
bool hasNormalTexture,
bool hasOcclusionTexture,
bool hasEmissiveTexture,
bool useSpecularGlossiness,
int alphaMode,
bool enableDiagnostics,
bool hasMetallicRoughnessTexture,
uint8_t metallicRoughnessUV,
bool hasSpecularGlossinessTexture,
uint8_t specularGlossinessUV,
uint8_t baseColorUV,
bool hasClearCoatTexture,
uint8_t clearCoatUV,
bool hasClearCoatRoughnessTexture,
uint8_t clearCoatRoughnessUV,
bool hasClearCoatNormalTexture,
uint8_t clearCoatNormalUV,
bool hasClearCoat,
bool hasTransmission,
bool hasTextureTransforms,
uint8_t emissiveUV,
uint8_t aoUV,
uint8_t normalUV,
bool hasTransmissionTexture,
uint8_t transmissionUV,
bool hasSheenColorTexture,
uint8_t sheenColorUV,
bool hasSheenRoughnessTexture,
uint8_t sheenRoughnessUV,
bool hasVolumeThicknessTexture,
uint8_t volumeThicknessUV ,
bool hasSheen,
bool hasIOR,
bool hasVolume,
void (*callback)(TMaterialInstance *));
void AnimationManager_updateBoneMatricesRenderThread( void AnimationManager_updateBoneMatricesRenderThread(
TAnimationManager *tAnimationManager, TAnimationManager *tAnimationManager,

View File

@@ -20,41 +20,81 @@ namespace thermion
{ {
#endif #endif
EMSCRIPTEN_KEEPALIVE TMaterialInstance *MaterialProvider_createMaterialInstance(TMaterialProvider *tMaterialProvider, TMaterialKey *materialConfig) EMSCRIPTEN_KEEPALIVE TMaterialInstance *MaterialProvider_createMaterialInstance(
TMaterialProvider *tMaterialProvider,
bool doubleSided,
bool unlit,
bool hasVertexColors,
bool hasBaseColorTexture,
bool hasNormalTexture,
bool hasOcclusionTexture,
bool hasEmissiveTexture,
bool useSpecularGlossiness,
int alphaMode,
bool enableDiagnostics,
bool hasMetallicRoughnessTexture,
uint8_t metallicRoughnessUV,
bool hasSpecularGlossinessTexture,
uint8_t specularGlossinessUV,
uint8_t baseColorUV,
bool hasClearCoatTexture,
uint8_t clearCoatUV,
bool hasClearCoatRoughnessTexture,
uint8_t clearCoatRoughnessUV,
bool hasClearCoatNormalTexture,
uint8_t clearCoatNormalUV,
bool hasClearCoat,
bool hasTransmission,
bool hasTextureTransforms,
uint8_t emissiveUV,
uint8_t aoUV,
uint8_t normalUV,
bool hasTransmissionTexture,
uint8_t transmissionUV,
bool hasSheenColorTexture,
uint8_t sheenColorUV,
bool hasSheenRoughnessTexture,
uint8_t sheenRoughnessUV,
bool hasVolumeThicknessTexture,
uint8_t volumeThicknessUV ,
bool hasSheen,
bool hasIOR,
bool hasVolume)
{ {
gltfio::MaterialKey config; gltfio::MaterialKey config;
gltfio::UvMap uvMap; gltfio::UvMap uvMap;
memset(&config, 0, sizeof(gltfio::MaterialKey)); memset(&config, 0, sizeof(gltfio::MaterialKey));
// Set and log each field // Set and log each field
config.unlit = materialConfig->unlit; config.unlit = unlit;
config.doubleSided = materialConfig->doubleSided; config.doubleSided = doubleSided;
config.useSpecularGlossiness = materialConfig->useSpecularGlossiness; config.useSpecularGlossiness = useSpecularGlossiness;
config.alphaMode = static_cast<filament::gltfio::AlphaMode>(materialConfig->alphaMode); config.alphaMode = static_cast<filament::gltfio::AlphaMode>(alphaMode);
config.hasBaseColorTexture = materialConfig->hasBaseColorTexture; config.hasBaseColorTexture = hasBaseColorTexture;
config.hasClearCoat = materialConfig->hasClearCoat; config.hasClearCoat = hasClearCoat;
config.hasClearCoatNormalTexture = materialConfig->hasClearCoatNormalTexture; config.hasClearCoatNormalTexture = hasClearCoatNormalTexture;
config.hasClearCoatRoughnessTexture = materialConfig->hasClearCoatRoughnessTexture; config.hasClearCoatRoughnessTexture = hasClearCoatRoughnessTexture;
config.hasEmissiveTexture = materialConfig->hasEmissiveTexture; config.hasEmissiveTexture = hasEmissiveTexture;
config.hasIOR = materialConfig->hasIOR; config.hasIOR = hasIOR;
config.hasMetallicRoughnessTexture = materialConfig->hasMetallicRoughnessTexture; config.hasMetallicRoughnessTexture = hasMetallicRoughnessTexture;
config.hasNormalTexture = materialConfig->hasNormalTexture; config.hasNormalTexture = hasNormalTexture;
config.hasOcclusionTexture = materialConfig->hasOcclusionTexture; config.hasOcclusionTexture = hasOcclusionTexture;
config.hasSheen = materialConfig->hasSheen; config.hasSheen = hasSheen;
config.hasSheenColorTexture = materialConfig->hasSheenColorTexture; config.hasSheenColorTexture = hasSheenColorTexture;
config.hasSheenRoughnessTexture = materialConfig->hasSheenRoughnessTexture; config.hasSheenRoughnessTexture = hasSheenRoughnessTexture;
config.hasTextureTransforms = materialConfig->hasTextureTransforms; config.hasTextureTransforms = hasTextureTransforms;
config.hasTransmission = materialConfig->hasTransmission; config.hasTransmission = hasTransmission;
config.hasTransmissionTexture = materialConfig->hasTransmissionTexture; config.hasTransmissionTexture = hasTransmissionTexture;
config.hasVolume = materialConfig->hasVolume; config.hasVolume = hasVolume;
config.hasVolumeThicknessTexture = materialConfig->hasVolumeThicknessTexture; config.hasVolumeThicknessTexture = hasVolumeThicknessTexture;
config.baseColorUV = materialConfig->baseColorUV; config.baseColorUV = baseColorUV;
config.hasVertexColors = materialConfig->hasVertexColors; config.hasVertexColors = hasVertexColors;
auto *materialProvider = reinterpret_cast<gltfio::MaterialProvider *>(tMaterialProvider); auto *materialProvider = reinterpret_cast<gltfio::MaterialProvider *>(tMaterialProvider);
auto materialInstance = materialProvider->createMaterialInstance(&config, &uvMap); auto materialInstance = materialProvider->createMaterialInstance(&config, &uvMap);
return reinterpret_cast<TMaterialInstance *>(materialInstance); return reinterpret_cast<TMaterialInstance *>(materialInstance);
} }
#ifdef __cplusplus #ifdef __cplusplus
} }
} }