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.Pointer<TMaterialInstance> Function(ffi.Pointer<TMaterialProvider>,
ffi.Pointer<TMaterialKey>)>(isLeaf: true)
ffi.Pointer<TMaterialInstance> Function(
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(
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<
@@ -2121,14 +2196,88 @@ external void SceneAsset_createGeometryRenderThread(
@ffi.Native<
ffi.Void Function(
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.NativeFunction<
ffi.Void Function(
ffi.Pointer<TMaterialInstance>)>>)>(isLeaf: true)
external void MaterialProvider_createMaterialInstanceRenderThread(
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.NativeFunction<ffi.Void Function(ffi.Pointer<TMaterialInstance>)>>
callback,
@@ -3323,134 +3472,6 @@ final class TFilamentAsset 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 {
@ffi.Double()
external double x;

View File

@@ -255,7 +255,7 @@ sealed class Struct extends NativeType {
Struct(this._address);
static create<T extends Struct>() {
switch (T) {
switch (T) {
case double4x4:
final ptr = double4x4.stackAlloc();
final arr1 =
@@ -901,7 +901,44 @@ extension type NativeLibrary(JSObject _) implements JSObject {
);
external Pointer<TMaterialInstance> _MaterialProvider_createMaterialInstance(
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(
Pointer<TEngine> tEngine,
@@ -1558,7 +1595,44 @@ extension type NativeLibrary(JSObject _) implements JSObject {
);
external void _MaterialProvider_createMaterialInstanceRenderThread(
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>)>>
callback,
);
@@ -3143,10 +3217,85 @@ void Gizmo_unhighlight(
self.Pointer<TMaterialInstance> MaterialProvider_createMaterialInstance(
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(
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);
}
@@ -4493,12 +4642,88 @@ void SceneAsset_createGeometryRenderThread(
void MaterialProvider_createMaterialInstanceRenderThread(
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>)>>
callback,
) {
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;
}
@@ -6415,22 +6640,6 @@ sealed class TGizmoAxis {
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> {
TSkybox toDart() {
return TSkybox(this);

View File

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

View File

@@ -247,8 +247,8 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
///
///
Future destroyAsset(covariant FFIAsset asset) async {
await withVoidCallback(
(requestId, cb) => SceneAsset_destroyRenderThread(asset.asset, requestId, cb));
await withVoidCallback((requestId, cb) =>
SceneAsset_destroyRenderThread(asset.asset, requestId, cb));
await asset.dispose();
}
@@ -414,6 +414,8 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
bool enableDiagnostics = false,
bool hasMetallicRoughnessTexture = false,
int metallicRoughnessUV = 0,
bool hasSpecularGlossiness = false,
int specularGlossinessUV = 0,
int baseColorUV = 0,
bool hasClearCoatTexture = false,
int clearCoatUV = 0,
@@ -438,54 +440,48 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
bool hasSheen = false,
bool hasIOR = false,
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) {
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) {
@@ -549,10 +545,11 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
});
if (FILAMENT_SINGLE_THREADED) {
await withVoidCallback((requestId, cb) => Engine_executeRenderThread(engine, requestId, cb));
} else {
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,
gltfAssetLoader, nameComponentManager, filamentAsset, cb));
await withVoidCallback((requestId, cb) => GltfResourceLoader_destroyRenderThread(
engine, gltfResourceLoader, requestId, cb));
await withVoidCallback((requestId, cb) =>
GltfResourceLoader_destroyRenderThread(
engine, gltfResourceLoader, requestId, cb));
return FFIAsset(asset, this, animationManager.cast<TAnimationManager>());
} finally {
@@ -886,11 +884,12 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
Future destroyView(covariant FFIView view) async {
View_setColorGrading(view.view, nullptr);
for (final cg in view.colorGrading.entries) {
await withVoidCallback(
(requestId, cb) => Engine_destroyColorGradingRenderThread(engine, cg.value, requestId, cb));
await withVoidCallback((requestId, cb) =>
Engine_destroyColorGradingRenderThread(
engine, cg.value, requestId, cb));
}
await withVoidCallback(
(requestId, cb) => Engine_destroyViewRenderThread(engine, view.view, requestId, cb));
await withVoidCallback((requestId, cb) =>
Engine_destroyViewRenderThread(engine, view.view, requestId, cb));
for (final swapchain in _swapChains.keys) {
if (_swapChains[swapchain]!.contains(view)) {
_swapChains[swapchain]!.remove(view);
@@ -901,8 +900,8 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
}
Future destroyScene(covariant FFIScene scene) async {
await withVoidCallback(
(requestId, cb) => Engine_destroySceneRenderThread(engine, scene.scene, requestId, cb));
await withVoidCallback((requestId, cb) =>
Engine_destroySceneRenderThread(engine, scene.scene, requestId, cb));
}
Future<Pointer<TColorGrading>> createColorGrading(ToneMapper mapper) async {
@@ -1028,10 +1027,11 @@ class FFIFilamentApp extends FilamentApp<Pointer> {
///
Future flush() async {
if (FILAMENT_SINGLE_THREADED) {
await withVoidCallback((requestId, cb) => Engine_executeRenderThread(engine, requestId, cb));
} else {
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 '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/implementation/ffi_filament_app.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 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 {
double x;
double y;

View File

@@ -9,7 +9,47 @@ extern "C"
#endif
// 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
}

View File

@@ -116,7 +116,47 @@ namespace thermion
int materialInstanceCount,
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(
TAnimationManager *tAnimationManager,

View File

@@ -20,41 +20,81 @@ namespace thermion
{
#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::UvMap uvMap;
memset(&config, 0, sizeof(gltfio::MaterialKey));
// Set and log each field
config.unlit = materialConfig->unlit;
config.doubleSided = materialConfig->doubleSided;
config.useSpecularGlossiness = materialConfig->useSpecularGlossiness;
config.alphaMode = static_cast<filament::gltfio::AlphaMode>(materialConfig->alphaMode);
config.hasBaseColorTexture = materialConfig->hasBaseColorTexture;
config.hasClearCoat = materialConfig->hasClearCoat;
config.hasClearCoatNormalTexture = materialConfig->hasClearCoatNormalTexture;
config.hasClearCoatRoughnessTexture = materialConfig->hasClearCoatRoughnessTexture;
config.hasEmissiveTexture = materialConfig->hasEmissiveTexture;
config.hasIOR = materialConfig->hasIOR;
config.hasMetallicRoughnessTexture = materialConfig->hasMetallicRoughnessTexture;
config.hasNormalTexture = materialConfig->hasNormalTexture;
config.hasOcclusionTexture = materialConfig->hasOcclusionTexture;
config.hasSheen = materialConfig->hasSheen;
config.hasSheenColorTexture = materialConfig->hasSheenColorTexture;
config.hasSheenRoughnessTexture = materialConfig->hasSheenRoughnessTexture;
config.hasTextureTransforms = materialConfig->hasTextureTransforms;
config.hasTransmission = materialConfig->hasTransmission;
config.hasTransmissionTexture = materialConfig->hasTransmissionTexture;
config.hasVolume = materialConfig->hasVolume;
config.hasVolumeThicknessTexture = materialConfig->hasVolumeThicknessTexture;
config.baseColorUV = materialConfig->baseColorUV;
config.hasVertexColors = materialConfig->hasVertexColors;
config.unlit = unlit;
config.doubleSided = doubleSided;
config.useSpecularGlossiness = useSpecularGlossiness;
config.alphaMode = static_cast<filament::gltfio::AlphaMode>(alphaMode);
config.hasBaseColorTexture = hasBaseColorTexture;
config.hasClearCoat = hasClearCoat;
config.hasClearCoatNormalTexture = hasClearCoatNormalTexture;
config.hasClearCoatRoughnessTexture = hasClearCoatRoughnessTexture;
config.hasEmissiveTexture = hasEmissiveTexture;
config.hasIOR = hasIOR;
config.hasMetallicRoughnessTexture = hasMetallicRoughnessTexture;
config.hasNormalTexture = hasNormalTexture;
config.hasOcclusionTexture = hasOcclusionTexture;
config.hasSheen = hasSheen;
config.hasSheenColorTexture = hasSheenColorTexture;
config.hasSheenRoughnessTexture = hasSheenRoughnessTexture;
config.hasTextureTransforms = hasTextureTransforms;
config.hasTransmission = hasTransmission;
config.hasTransmissionTexture = hasTransmissionTexture;
config.hasVolume = hasVolume;
config.hasVolumeThicknessTexture = hasVolumeThicknessTexture;
config.baseColorUV = baseColorUV;
config.hasVertexColors = hasVertexColors;
auto *materialProvider = reinterpret_cast<gltfio::MaterialProvider *>(tMaterialProvider);
auto materialInstance = materialProvider->createMaterialInstance(&config, &uvMap);
return reinterpret_cast<TMaterialInstance *>(materialInstance);
}
#ifdef __cplusplus
}
}