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

@@ -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
}
}