From 88906ebeea0eccedf87d022f73a6e154b37d7634 Mon Sep 17 00:00:00 2001 From: Janine Liu Date: Fri, 20 Sep 2024 15:14:35 -0400 Subject: [PATCH] Fix material property parameter values --- CHANGES.md | 1 + .../Private/CesiumEncodedFeaturesMetadata.cpp | 382 ++++++++++++++++-- .../Private/CesiumEncodedFeaturesMetadata.h | 51 +++ .../CesiumFeaturesMetadataComponent.cpp | 20 +- .../Private/CesiumGltfComponent.cpp | 333 +-------------- 5 files changed, 402 insertions(+), 385 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c9ed9b681..be60ea1a6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ ##### Fixes :wrench: - Drastically reduced tile mesh memory usage in UE 5.3 and 5.4 by working around a bug that causes those engine versions to add more texture coordinate sets than necessary. +- Fixed a bug where the `scale`, `noData`, and `default` values of a property in `EXT_strutural_metadata` were not correctly passed to the tileset's material. ### v2.8.0 - 2024-09-02 diff --git a/Source/CesiumRuntime/Private/CesiumEncodedFeaturesMetadata.cpp b/Source/CesiumRuntime/Private/CesiumEncodedFeaturesMetadata.cpp index 872d35f0b..7396acc97 100644 --- a/Source/CesiumRuntime/Private/CesiumEncodedFeaturesMetadata.cpp +++ b/Source/CesiumRuntime/Private/CesiumEncodedFeaturesMetadata.cpp @@ -13,9 +13,11 @@ #include "CesiumPropertyTexture.h" #include "CesiumRuntime.h" #include "Containers/Map.h" +#include "Materials/MaterialInstanceDynamic.h" #include "PixelFormat.h" #include "TextureResource.h" #include "UnrealMetadataConversions.h" + #include #include #include @@ -161,6 +163,7 @@ std::optional encodeFeatureIdTexture( return result; } + } // namespace EncodedPrimitiveFeatures encodePrimitiveFeaturesAnyThreadPart( @@ -314,44 +317,6 @@ FString getMaterialNameForPropertyTextureProperty( namespace { -struct EncodedPixelFormat { - EPixelFormat format; - int32_t bytesPerChannel; - int32_t channels; -}; - -// TODO: consider picking better pixel formats when they are available for the -// current platform. -EncodedPixelFormat -getPixelFormat(FCesiumMetadataEncodingDetails encodingDetails) { - - switch (encodingDetails.ComponentType) { - case ECesiumEncodedMetadataComponentType::Uint8: - switch (encodingDetails.Type) { - case ECesiumEncodedMetadataType::Scalar: - return {EPixelFormat::PF_R8_UINT, 1, 1}; - case ECesiumEncodedMetadataType::Vec2: - case ECesiumEncodedMetadataType::Vec3: - case ECesiumEncodedMetadataType::Vec4: - return {EPixelFormat::PF_R8G8B8A8_UINT, 1, 4}; - default: - return {EPixelFormat::PF_Unknown, 0, 0}; - } - case ECesiumEncodedMetadataComponentType::Float: - switch (encodingDetails.Type) { - case ECesiumEncodedMetadataType::Scalar: - return {EPixelFormat::PF_R32_FLOAT, 4, 1}; - case ECesiumEncodedMetadataType::Vec2: - case ECesiumEncodedMetadataType::Vec3: - case ECesiumEncodedMetadataType::Vec4: - // Note this is ABGR - return {EPixelFormat::PF_A32B32G32R32F, 4, 4}; - } - default: - return {EPixelFormat::PF_Unknown, 0, 0}; - } -} - bool isValidPropertyTablePropertyDescription( const FCesiumPropertyTablePropertyDescription& propertyDescription, const FCesiumPropertyTableProperty& property) { @@ -517,7 +482,8 @@ EncodedPropertyTable encodePropertyTableAnyThreadPart( continue; } - EncodedPixelFormat encodedFormat = getPixelFormat(encodingDetails); + EncodedPixelFormat encodedFormat = + getPixelFormat(encodingDetails.Type, encodingDetails.ComponentType); if (encodedFormat.format == EPixelFormat::PF_Unknown) { UE_LOG( LogCesium, @@ -781,7 +747,7 @@ EncodedModelMetadata encodeModelMetadataAnyThreadPart( const TArray& propertyTables = UCesiumModelMetadataBlueprintLibrary::GetPropertyTables(metadata); result.propertyTables.Reserve(propertyTables.Num()); - for (const auto& propertyTable : propertyTables) { + for (const FCesiumPropertyTable& propertyTable : propertyTables) { const FString propertyTableName = getNameForPropertyTable(propertyTable); const FCesiumPropertyTableDescription* pExpectedPropertyTable = @@ -810,9 +776,8 @@ EncodedModelMetadata encodeModelMetadataAnyThreadPart( propertyTexturePropertyMap; propertyTexturePropertyMap.Reserve(propertyTextures.Num()); - for (const auto& propertyTexture : propertyTextures) { - const FString propertyTextureName = - getNameForPropertyTexture(propertyTexture); + for (const FCesiumPropertyTexture& propertyTexture : propertyTextures) { + FString propertyTextureName = getNameForPropertyTexture(propertyTexture); const FCesiumPropertyTextureDescription* pExpectedPropertyTexture = metadataDescription.PropertyTextures.FindByPredicate( @@ -937,4 +902,335 @@ FString createHlslSafeName(const FString& rawName) { return safeName; } +// TODO: consider picking better pixel formats when they are available for the +// current platform. +EncodedPixelFormat getPixelFormat( + ECesiumEncodedMetadataType Type, + ECesiumEncodedMetadataComponentType ComponentType) { + switch (ComponentType) { + case ECesiumEncodedMetadataComponentType::Uint8: + switch (Type) { + case ECesiumEncodedMetadataType::Scalar: + return {EPixelFormat::PF_R8_UINT, 1, 1}; + case ECesiumEncodedMetadataType::Vec2: + case ECesiumEncodedMetadataType::Vec3: + case ECesiumEncodedMetadataType::Vec4: + return {EPixelFormat::PF_R8G8B8A8_UINT, 1, 4}; + default: + return {EPixelFormat::PF_Unknown, 0, 0}; + } + case ECesiumEncodedMetadataComponentType::Float: + switch (Type) { + case ECesiumEncodedMetadataType::Scalar: + return {EPixelFormat::PF_R32_FLOAT, 4, 1}; + case ECesiumEncodedMetadataType::Vec2: + case ECesiumEncodedMetadataType::Vec3: + case ECesiumEncodedMetadataType::Vec4: + // Note this is ABGR + return {EPixelFormat::PF_A32B32G32R32F, 4, 4}; + } + default: + return {EPixelFormat::PF_Unknown, 0, 0}; + } +} + +bool isSupportedPropertyTextureProperty( + const FCesiumMetadataPropertyDetails& PropertyDetails) { + if (PropertyDetails.bIsArray && + PropertyDetails.Type != ECesiumMetadataType::Scalar) { + // Only scalar arrays are supported. + return false; + } + + uint32 byteSize = GetMetadataTypeByteSize( + PropertyDetails.Type, + PropertyDetails.ComponentType); + if (PropertyDetails.bIsArray) { + byteSize *= PropertyDetails.ArraySize; + } + + return byteSize > 0 && byteSize <= 4; +} + +void SetPropertyParameterValue( + UMaterialInstanceDynamic* pMaterial, + EMaterialParameterAssociation association, + int32 index, + const FString& name, + ECesiumEncodedMetadataType type, + const FCesiumMetadataValue& value, + float defaultValue) { + if (type == ECesiumEncodedMetadataType::Scalar) { + pMaterial->SetScalarParameterValueByInfo( + FMaterialParameterInfo(FName(name), association, index), + UCesiumMetadataValueBlueprintLibrary::GetFloat(value, defaultValue)); + } else if ( + type == ECesiumEncodedMetadataType::Vec2 || + type == ECesiumEncodedMetadataType::Vec3 || + type == ECesiumEncodedMetadataType::Vec4) { + FVector4 vector4Value = UCesiumMetadataValueBlueprintLibrary::GetVector4( + value, + FVector4(defaultValue, defaultValue, defaultValue, defaultValue)); + + pMaterial->SetVectorParameterValueByInfo( + FMaterialParameterInfo(FName(name), association, index), + FLinearColor( + static_cast(vector4Value.X), + static_cast(vector4Value.Y), + static_cast(vector4Value.Z), + static_cast(vector4Value.W))); + } +} + +void SetFeatureIdTextureParameterValues( + UMaterialInstanceDynamic* pMaterial, + EMaterialParameterAssociation association, + int32 index, + const FString& name, + const EncodedFeatureIdTexture& encodedFeatureIdTexture) { + pMaterial->SetTextureParameterValueByInfo( + FMaterialParameterInfo( + FName(name + MaterialTextureSuffix), + association, + index), + encodedFeatureIdTexture.pTexture->pTexture->getUnrealTexture()); + + size_t numChannels = encodedFeatureIdTexture.channels.size(); + pMaterial->SetScalarParameterValueByInfo( + FMaterialParameterInfo( + FName(name + MaterialNumChannelsSuffix), + association, + index), + static_cast(numChannels)); + + std::vector channelsAsFloats{0.0f, 0.0f, 0.0f, 0.0f}; + for (size_t i = 0; i < numChannels; i++) { + channelsAsFloats[i] = + static_cast(encodedFeatureIdTexture.channels[i]); + } + + FLinearColor channels{ + channelsAsFloats[0], + channelsAsFloats[1], + channelsAsFloats[2], + channelsAsFloats[3], + }; + + pMaterial->SetVectorParameterValueByInfo( + FMaterialParameterInfo( + FName(name + MaterialChannelsSuffix), + association, + index), + channels); + + if (!encodedFeatureIdTexture.textureTransform) { + return; + } + + glm::dvec2 scale = encodedFeatureIdTexture.textureTransform->scale(); + glm::dvec2 offset = encodedFeatureIdTexture.textureTransform->offset(); + + pMaterial->SetVectorParameterValueByInfo( + FMaterialParameterInfo( + FName(name + MaterialTextureScaleOffsetSuffix), + association, + index), + FLinearColor(scale[0], scale[1], offset[0], offset[1])); + + glm::dvec2 rotation = + encodedFeatureIdTexture.textureTransform->rotationSineCosine(); + pMaterial->SetVectorParameterValueByInfo( + FMaterialParameterInfo( + FName(name + MaterialTextureRotationSuffix), + association, + index), + FLinearColor(rotation[0], rotation[1], 0.0f, 1.0f)); +} + +void SetPropertyTableParameterValues( + UMaterialInstanceDynamic* pMaterial, + EMaterialParameterAssociation association, + int32 index, + const EncodedPropertyTable& encodedPropertyTable) { + for (const EncodedPropertyTableProperty& encodedProperty : + encodedPropertyTable.properties) { + FString fullPropertyName = getMaterialNameForPropertyTableProperty( + encodedPropertyTable.name, + encodedProperty.name); + + if (encodedProperty.pTexture) { + pMaterial->SetTextureParameterValueByInfo( + FMaterialParameterInfo(FName(fullPropertyName), association, index), + encodedProperty.pTexture->pTexture->getUnrealTexture()); + } + + if (!UCesiumMetadataValueBlueprintLibrary::IsEmpty( + encodedProperty.offset)) { + FString parameterName = fullPropertyName + MaterialPropertyOffsetSuffix; + SetPropertyParameterValue( + pMaterial, + association, + index, + parameterName, + encodedProperty.type, + encodedProperty.offset, + 0.0f); + } + + if (!UCesiumMetadataValueBlueprintLibrary::IsEmpty(encodedProperty.scale)) { + FString parameterName = fullPropertyName + MaterialPropertyScaleSuffix; + SetPropertyParameterValue( + pMaterial, + association, + index, + parameterName, + encodedProperty.type, + encodedProperty.scale, + 1.0f); + } + + if (!UCesiumMetadataValueBlueprintLibrary::IsEmpty( + encodedProperty.noData)) { + FString parameterName = fullPropertyName + MaterialPropertyNoDataSuffix; + SetPropertyParameterValue( + pMaterial, + association, + index, + parameterName, + encodedProperty.type, + encodedProperty.noData, + 0.0f); + } + + if (!UCesiumMetadataValueBlueprintLibrary::IsEmpty( + encodedProperty.defaultValue)) { + FString parameterName = + fullPropertyName + MaterialPropertyDefaultValueSuffix; + SetPropertyParameterValue( + pMaterial, + association, + index, + parameterName, + encodedProperty.type, + encodedProperty.defaultValue, + 0.0f); + + FString hasValueName = fullPropertyName + MaterialPropertyHasValueSuffix; + pMaterial->SetScalarParameterValueByInfo( + FMaterialParameterInfo(FName(hasValueName), association, index), + encodedProperty.pTexture ? 1.0 : 0.0); + } + } +} + +void SetPropertyTextureParameterValues( + UMaterialInstanceDynamic* pMaterial, + EMaterialParameterAssociation association, + int32 index, + const EncodedPropertyTexture& encodedPropertyTexture) { + for (const EncodedPropertyTextureProperty& encodedProperty : + encodedPropertyTexture.properties) { + FString fullPropertyName = getMaterialNameForPropertyTextureProperty( + encodedPropertyTexture.name, + encodedProperty.name); + + if (encodedProperty.pTexture) { + pMaterial->SetTextureParameterValueByInfo( + FMaterialParameterInfo(FName(fullPropertyName), association, index), + encodedProperty.pTexture->pTexture->getUnrealTexture()); + } + + pMaterial->SetVectorParameterValueByInfo( + FMaterialParameterInfo( + FName(fullPropertyName + MaterialChannelsSuffix), + association, + index), + FLinearColor( + encodedProperty.channels[0], + encodedProperty.channels[1], + encodedProperty.channels[2], + encodedProperty.channels[3])); + + if (!UCesiumMetadataValueBlueprintLibrary::IsEmpty( + encodedProperty.offset)) { + FString parameterName = fullPropertyName + MaterialPropertyOffsetSuffix; + SetPropertyParameterValue( + pMaterial, + association, + index, + parameterName, + encodedProperty.type, + encodedProperty.offset, + 0.0f); + } + + if (!UCesiumMetadataValueBlueprintLibrary::IsEmpty(encodedProperty.scale)) { + FString parameterName = fullPropertyName + MaterialPropertyScaleSuffix; + SetPropertyParameterValue( + pMaterial, + association, + index, + parameterName, + encodedProperty.type, + encodedProperty.scale, + 1.0f); + } + + if (!UCesiumMetadataValueBlueprintLibrary::IsEmpty( + encodedProperty.noData)) { + FString parameterName = fullPropertyName + MaterialPropertyNoDataSuffix; + SetPropertyParameterValue( + pMaterial, + association, + index, + parameterName, + encodedProperty.type, + encodedProperty.noData, + 0.0f); + } + + if (!UCesiumMetadataValueBlueprintLibrary::IsEmpty( + encodedProperty.defaultValue)) { + FString parameterName = + fullPropertyName + MaterialPropertyDefaultValueSuffix; + SetPropertyParameterValue( + pMaterial, + association, + index, + parameterName, + encodedProperty.type, + encodedProperty.defaultValue, + 0.0f); + + FString hasValueName = fullPropertyName + MaterialPropertyHasValueSuffix; + pMaterial->SetScalarParameterValueByInfo( + FMaterialParameterInfo(FName(hasValueName), association, index), + encodedProperty.pTexture ? 1.0 : 0.0); + } + + if (!encodedProperty.textureTransform) { + continue; + } + + glm::dvec2 scale = encodedProperty.textureTransform->scale(); + glm::dvec2 offset = encodedProperty.textureTransform->offset(); + + pMaterial->SetVectorParameterValueByInfo( + FMaterialParameterInfo( + FName(fullPropertyName + MaterialTextureScaleOffsetSuffix), + association, + index), + FLinearColor(scale[0], scale[1], offset[0], offset[1])); + + glm::dvec2 rotation = + encodedProperty.textureTransform->rotationSineCosine(); + pMaterial->SetVectorParameterValueByInfo( + FMaterialParameterInfo( + FName(fullPropertyName + MaterialTextureRotationSuffix), + association, + index), + FLinearColor(rotation[0], rotation[1], 0.0f, 1.0f)); + } +} + } // namespace CesiumEncodedFeaturesMetadata diff --git a/Source/CesiumRuntime/Private/CesiumEncodedFeaturesMetadata.h b/Source/CesiumRuntime/Private/CesiumEncodedFeaturesMetadata.h index a2a74bbeb..b1015f4bd 100644 --- a/Source/CesiumRuntime/Private/CesiumEncodedFeaturesMetadata.h +++ b/Source/CesiumRuntime/Private/CesiumEncodedFeaturesMetadata.h @@ -27,6 +27,10 @@ struct FCesiumModelMetadataDescription; struct FCesiumPrimitiveFeaturesDescription; struct FCesiumPrimitiveMetadataDescription; +struct FCesiumMetadataPropertyDetails; +class UMaterialInstanceDynamic; +enum EMaterialParameterAssociation; + /** * @brief Provides utility for encoding feature IDs from EXT_mesh_features and * metadata from EXT_structural_metadata. "Encoding" refers broadly to the @@ -499,6 +503,53 @@ void destroyEncodedModelMetadata(EncodedModelMetadata& encodedMetadata); #pragma endregion +#pragma region Utility + +struct EncodedPixelFormat { + EPixelFormat format; + int32_t bytesPerChannel; + int32_t channels; +}; + +// TODO: consider picking better pixel formats when they are available for the +// current platform. +EncodedPixelFormat getPixelFormat( + ECesiumEncodedMetadataType Type, + ECesiumEncodedMetadataComponentType ComponentType); + FString createHlslSafeName(const FString& rawName); +bool isSupportedPropertyTextureProperty( + const FCesiumMetadataPropertyDetails& PropertyDetails); + +void SetPropertyParameterValue( + UMaterialInstanceDynamic* pMaterial, + EMaterialParameterAssociation association, + int32 index, + const FString& name, + ECesiumEncodedMetadataType type, + const FCesiumMetadataValue& value, + float defaultValue); + +void SetFeatureIdTextureParameterValues( + UMaterialInstanceDynamic* pMaterial, + EMaterialParameterAssociation association, + int32 index, + const FString& name, + const EncodedFeatureIdTexture& encodedFeatureIdTexture); + +void SetPropertyTableParameterValues( + UMaterialInstanceDynamic* pMaterial, + EMaterialParameterAssociation association, + int32 index, + const EncodedPropertyTable& encodedPropertyTable); + +void SetPropertyTextureParameterValues( + UMaterialInstanceDynamic* pMaterial, + EMaterialParameterAssociation association, + int32 index, + const EncodedPropertyTexture& encodedPropertyTexture); + +#pragma endregion + } // namespace CesiumEncodedFeaturesMetadata diff --git a/Source/CesiumRuntime/Private/CesiumFeaturesMetadataComponent.cpp b/Source/CesiumRuntime/Private/CesiumFeaturesMetadataComponent.cpp index 9b0212cb2..55ba893e7 100644 --- a/Source/CesiumRuntime/Private/CesiumFeaturesMetadataComponent.cpp +++ b/Source/CesiumRuntime/Private/CesiumFeaturesMetadataComponent.cpp @@ -920,24 +920,6 @@ FString GetSwizzleForEncodedType(ECesiumEncodedMetadataType Type) { }; } -bool IsSupportedPropertyTextureProperty( - const FCesiumMetadataPropertyDetails& PropertyDetails) { - if (PropertyDetails.bIsArray && - PropertyDetails.Type != ECesiumMetadataType::Scalar) { - // Only scalar arrays are supported. - return false; - } - - uint32 byteSize = GetMetadataTypeByteSize( - PropertyDetails.Type, - PropertyDetails.ComponentType); - if (PropertyDetails.bIsArray) { - byteSize *= PropertyDetails.ArraySize; - } - - return byteSize > 0 && byteSize <= 4; -} - /** * @brief Generates code for assembling metadata values from a scalar property * texture property. @@ -2062,7 +2044,7 @@ void GenerateNodesForPropertyTexture( for (const FCesiumPropertyTexturePropertyDescription& Property : PropertyTexture.Properties) { - if (!IsSupportedPropertyTextureProperty(Property.PropertyDetails)) { + if (!isSupportedPropertyTextureProperty(Property.PropertyDetails)) { // Ignore properties that are unsupported, i.e., properties that require // more than four bytes to parse values from. This limitation is imposed // by cesium-native because only single-byte channels are supported. diff --git a/Source/CesiumRuntime/Private/CesiumGltfComponent.cpp b/Source/CesiumRuntime/Private/CesiumGltfComponent.cpp index 391aacadf..a99dd7720 100644 --- a/Source/CesiumRuntime/Private/CesiumGltfComponent.cpp +++ b/Source/CesiumRuntime/Private/CesiumGltfComponent.cpp @@ -2651,319 +2651,6 @@ void SetWaterParameterValues( loadResult.waterMaskScale)); } -static void SetFeatureIdTextureParameterValues( - const CesiumEncodedFeaturesMetadata::EncodedFeatureIdTexture& - encodedFeatureIdTexture, - const FString& name, - UMaterialInstanceDynamic* pMaterial, - EMaterialParameterAssociation association, - int32 index) { - pMaterial->SetTextureParameterValueByInfo( - FMaterialParameterInfo( - FName(name + CesiumEncodedFeaturesMetadata::MaterialTextureSuffix), - association, - index), - encodedFeatureIdTexture.pTexture->pTexture->getUnrealTexture()); - - size_t numChannels = encodedFeatureIdTexture.channels.size(); - pMaterial->SetScalarParameterValueByInfo( - FMaterialParameterInfo( - FName( - name + CesiumEncodedFeaturesMetadata::MaterialNumChannelsSuffix), - association, - index), - static_cast(numChannels)); - - std::vector channelsAsFloats{0.0f, 0.0f, 0.0f, 0.0f}; - for (size_t i = 0; i < numChannels; i++) { - channelsAsFloats[i] = - static_cast(encodedFeatureIdTexture.channels[i]); - } - - FLinearColor channels{ - channelsAsFloats[0], - channelsAsFloats[1], - channelsAsFloats[2], - channelsAsFloats[3], - }; - - pMaterial->SetVectorParameterValueByInfo( - FMaterialParameterInfo( - FName(name + CesiumEncodedFeaturesMetadata::MaterialChannelsSuffix), - association, - index), - channels); - - if (!encodedFeatureIdTexture.textureTransform) { - return; - } - - glm::dvec2 scale = encodedFeatureIdTexture.textureTransform->scale(); - glm::dvec2 offset = encodedFeatureIdTexture.textureTransform->offset(); - - pMaterial->SetVectorParameterValueByInfo( - FMaterialParameterInfo( - FName( - name + - CesiumEncodedFeaturesMetadata::MaterialTextureScaleOffsetSuffix), - association, - index), - FLinearColor(scale[0], scale[1], offset[0], offset[1])); - - glm::dvec2 rotation = - encodedFeatureIdTexture.textureTransform->rotationSineCosine(); - pMaterial->SetVectorParameterValueByInfo( - FMaterialParameterInfo( - FName( - name + - CesiumEncodedFeaturesMetadata::MaterialTextureRotationSuffix), - association, - index), - FLinearColor(rotation[0], rotation[1], 0.0f, 1.0f)); -} - -static void SetPropertyParameterValue( - const FString& name, - ECesiumEncodedMetadataType type, - const FCesiumMetadataValue& value, - const float defaultValue, - UMaterialInstanceDynamic* pMaterial, - EMaterialParameterAssociation association, - int32 index) { - if (type == ECesiumEncodedMetadataType::Scalar) { - pMaterial->SetScalarParameterValueByInfo( - FMaterialParameterInfo(FName(name), association, index), - UCesiumMetadataValueBlueprintLibrary::GetFloat(value, defaultValue)); - } else if ( - type == ECesiumEncodedMetadataType::Vec2 || - type == ECesiumEncodedMetadataType::Vec3 || - type == ECesiumEncodedMetadataType::Vec4) { - FVector4 vector4Value = UCesiumMetadataValueBlueprintLibrary::GetVector4( - value, - FVector4(defaultValue, defaultValue, defaultValue, defaultValue)); - - pMaterial->SetVectorParameterValueByInfo( - FMaterialParameterInfo(FName(name), association, index), - FLinearColor( - static_cast(vector4Value.X), - static_cast(vector4Value.Y), - static_cast(vector4Value.Z), - static_cast(vector4Value.W))); - } -} - -static void SetPropertyTableParameterValues( - const CesiumEncodedFeaturesMetadata::EncodedPropertyTable& - encodedPropertyTable, - UMaterialInstanceDynamic* pMaterial, - EMaterialParameterAssociation association, - int32 index) { - for (const CesiumEncodedFeaturesMetadata::EncodedPropertyTableProperty& - encodedProperty : encodedPropertyTable.properties) { - FString fullPropertyName = - CesiumEncodedFeaturesMetadata::getMaterialNameForPropertyTableProperty( - encodedPropertyTable.name, - encodedProperty.name); - - if (encodedProperty.pTexture) { - pMaterial->SetTextureParameterValueByInfo( - FMaterialParameterInfo(FName(fullPropertyName), association, index), - encodedProperty.pTexture->pTexture->getUnrealTexture()); - } - - if (!UCesiumMetadataValueBlueprintLibrary::IsEmpty( - encodedProperty.offset)) { - FString parameterName = - fullPropertyName + - CesiumEncodedFeaturesMetadata::MaterialPropertyOffsetSuffix; - SetPropertyParameterValue( - parameterName, - encodedProperty.type, - encodedProperty.offset, - 0.0f, - pMaterial, - association, - index); - } - - if (!UCesiumMetadataValueBlueprintLibrary::IsEmpty(encodedProperty.scale)) { - FString parameterName = - fullPropertyName + - CesiumEncodedFeaturesMetadata::MaterialPropertyScaleSuffix; - SetPropertyParameterValue( - parameterName, - encodedProperty.type, - encodedProperty.offset, - 1.0f, - pMaterial, - association, - index); - } - - if (!UCesiumMetadataValueBlueprintLibrary::IsEmpty( - encodedProperty.noData)) { - FString parameterName = - fullPropertyName + - CesiumEncodedFeaturesMetadata::MaterialPropertyNoDataSuffix; - SetPropertyParameterValue( - parameterName, - encodedProperty.type, - encodedProperty.offset, - 0.0f, - pMaterial, - association, - index); - } - - if (!UCesiumMetadataValueBlueprintLibrary::IsEmpty( - encodedProperty.defaultValue)) { - FString parameterName = - fullPropertyName + - CesiumEncodedFeaturesMetadata::MaterialPropertyDefaultValueSuffix; - SetPropertyParameterValue( - parameterName, - encodedProperty.type, - encodedProperty.offset, - 0.0f, - pMaterial, - association, - index); - - FString hasValueName = fullPropertyName = - CesiumEncodedFeaturesMetadata::MaterialPropertyHasValueSuffix; - pMaterial->SetScalarParameterValueByInfo( - FMaterialParameterInfo(FName(hasValueName), association, index), - encodedProperty.pTexture ? 1.0 : 0.0); - } - } -} - -static void SetPropertyTextureParameterValues( - const CesiumEncodedFeaturesMetadata::EncodedPropertyTexture& - encodedPropertyTexture, - UMaterialInstanceDynamic* pMaterial, - EMaterialParameterAssociation association, - int32 index) { - for (const CesiumEncodedFeaturesMetadata::EncodedPropertyTextureProperty& - encodedProperty : encodedPropertyTexture.properties) { - FString fullPropertyName = CesiumEncodedFeaturesMetadata:: - getMaterialNameForPropertyTextureProperty( - encodedPropertyTexture.name, - encodedProperty.name); - - if (encodedProperty.pTexture) { - pMaterial->SetTextureParameterValueByInfo( - FMaterialParameterInfo(FName(fullPropertyName), association, index), - encodedProperty.pTexture->pTexture->getUnrealTexture()); - } - - pMaterial->SetVectorParameterValueByInfo( - FMaterialParameterInfo( - FName( - fullPropertyName + - CesiumEncodedFeaturesMetadata::MaterialChannelsSuffix), - association, - index), - FLinearColor( - encodedProperty.channels[0], - encodedProperty.channels[1], - encodedProperty.channels[2], - encodedProperty.channels[3])); - - if (!UCesiumMetadataValueBlueprintLibrary::IsEmpty( - encodedProperty.offset)) { - FString parameterName = - fullPropertyName + - CesiumEncodedFeaturesMetadata::MaterialPropertyOffsetSuffix; - SetPropertyParameterValue( - parameterName, - encodedProperty.type, - encodedProperty.offset, - 0.0f, - pMaterial, - association, - index); - } - - if (!UCesiumMetadataValueBlueprintLibrary::IsEmpty(encodedProperty.scale)) { - FString parameterName = - fullPropertyName + - CesiumEncodedFeaturesMetadata::MaterialPropertyScaleSuffix; - SetPropertyParameterValue( - parameterName, - encodedProperty.type, - encodedProperty.offset, - 1.0f, - pMaterial, - association, - index); - } - - if (!UCesiumMetadataValueBlueprintLibrary::IsEmpty( - encodedProperty.noData)) { - FString parameterName = - fullPropertyName + - CesiumEncodedFeaturesMetadata::MaterialPropertyNoDataSuffix; - SetPropertyParameterValue( - parameterName, - encodedProperty.type, - encodedProperty.offset, - 0.0f, - pMaterial, - association, - index); - } - - if (!UCesiumMetadataValueBlueprintLibrary::IsEmpty( - encodedProperty.defaultValue)) { - FString parameterName = - fullPropertyName + - CesiumEncodedFeaturesMetadata::MaterialPropertyDefaultValueSuffix; - SetPropertyParameterValue( - parameterName, - encodedProperty.type, - encodedProperty.offset, - 0.0f, - pMaterial, - association, - index); - - FString hasValueName = fullPropertyName = - CesiumEncodedFeaturesMetadata::MaterialPropertyHasValueSuffix; - pMaterial->SetScalarParameterValueByInfo( - FMaterialParameterInfo(FName(hasValueName), association, index), - encodedProperty.pTexture ? 1.0 : 0.0); - } - - if (!encodedProperty.textureTransform) { - continue; - } - - glm::dvec2 scale = encodedProperty.textureTransform->scale(); - glm::dvec2 offset = encodedProperty.textureTransform->offset(); - - pMaterial->SetVectorParameterValueByInfo( - FMaterialParameterInfo( - FName( - fullPropertyName + CesiumEncodedFeaturesMetadata:: - MaterialTextureScaleOffsetSuffix), - association, - index), - FLinearColor(scale[0], scale[1], offset[0], offset[1])); - - glm::dvec2 rotation = - encodedProperty.textureTransform->rotationSineCosine(); - pMaterial->SetVectorParameterValueByInfo( - FMaterialParameterInfo( - FName( - fullPropertyName + - CesiumEncodedFeaturesMetadata::MaterialTextureRotationSuffix), - association, - index), - FLinearColor(rotation[0], rotation[1], 0.0f, 1.0f)); - } -} - static void SetFeaturesMetadataParameterValues( const CesiumGltf::Model& model, UCesiumGltfComponent& gltfComponent, @@ -3000,31 +2687,31 @@ static void SetFeaturesMetadataParameterValues( } if (encodedFeatureIdSet.texture) { - SetFeatureIdTextureParameterValues( - *encodedFeatureIdSet.texture, - SafeName, + CesiumEncodedFeaturesMetadata::SetFeatureIdTextureParameterValues( pMaterial, association, - index); + index, + SafeName, + *encodedFeatureIdSet.texture); } } for (const CesiumEncodedFeaturesMetadata::EncodedPropertyTexture& propertyTexture : gltfComponent.EncodedMetadata.propertyTextures) { - SetPropertyTextureParameterValues( - propertyTexture, + CesiumEncodedFeaturesMetadata::SetPropertyTextureParameterValues( pMaterial, association, - index); + index, + propertyTexture); } for (const CesiumEncodedFeaturesMetadata::EncodedPropertyTable& propertyTable : gltfComponent.EncodedMetadata.propertyTables) { - SetPropertyTableParameterValues( - propertyTable, + CesiumEncodedFeaturesMetadata::SetPropertyTableParameterValues( pMaterial, association, - index); + index, + propertyTable); } } }