Skip to content

Commit

Permalink
Add missing header files, prevent material from generating withunsave…
Browse files Browse the repository at this point in the history
…d changes
  • Loading branch information
j9liu committed Aug 11, 2023
1 parent 21540ab commit 43d7499
Show file tree
Hide file tree
Showing 17 changed files with 191 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct FCesiumPropertyTable;
struct FCesiumPropertyTableProperty;
struct FCesiumPropertyTexture;
struct FCesiumPropertyTableDescription;
struct FCesiumPropertyTextureDescription;
struct FFeatureTextureDescription;
struct FCesiumModelMetadataDescription;
struct FCesiumPrimitiveFeaturesDescription;
Expand Down
4 changes: 4 additions & 0 deletions Source/CesiumRuntime/Private/CesiumEncodedMetadataUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

using namespace CesiumTextureUtility;

PRAGMA_DISABLE_DEPRECATION_WARNINGS

namespace CesiumEncodedMetadataUtility {

namespace {
Expand Down Expand Up @@ -800,3 +802,5 @@ FString createHlslSafeName(const FString& rawName) {
}

} // namespace CesiumEncodedMetadataUtility

PRAGMA_ENABLE_DEPRECATION_WARNINGS
55 changes: 38 additions & 17 deletions Source/CesiumRuntime/Private/CesiumFeaturesMetadataComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "CesiumGltfPrimitiveComponent.h"
#include "CesiumMetadataConversions.h"
#include "CesiumModelMetadata.h"
#include "CesiumRuntime.h"

#if WITH_EDITOR
#include "AssetRegistry/AssetData.h"
Expand Down Expand Up @@ -438,6 +439,7 @@ static void RemapUserConnections(
TMap<FString, TArray<FExpressionInput*>>& ConnectionRemap,
UMaterialFunction* GetFeatureIdsFromAttributeFunction,
UMaterialFunction* GetFeatureIdsFromTextureFunction) {

MaterialNodeClassification Classification;
ClassifyNodes(
Layer,
Expand Down Expand Up @@ -571,7 +573,7 @@ UMaterialExpressionMaterialFunctionCall* GenerateNodesForFeatureIdAttribute(
TextureCoordinateIndex->MaterialExpressionEditorY = NodeY;
AutoGeneratedNodes.Add(TextureCoordinateIndex);

NodeX += Incr;
NodeX += 2 * Incr;

UMaterialExpressionMaterialFunctionCall* GetFeatureIdsFromAttribute =
NewObject<UMaterialExpressionMaterialFunctionCall>(TargetMaterialLayer);
Expand Down Expand Up @@ -600,6 +602,8 @@ void GenerateNodesForPropertyTable(
int32 SectionLeft = NodeX;
int32 SectionTop = NodeY;

NodeX += 1.5 * Incr;

UMaterialExpressionCustom* GetPropertyValuesFunction =
NewObject<UMaterialExpressionCustom>(TargetMaterialLayer);
GetPropertyValuesFunction->Inputs.Reserve(PropertyTable.Properties.Num() + 2);
Expand All @@ -617,8 +621,6 @@ void GenerateNodesForPropertyTable(
FeatureIDInput.InputName = FName("FeatureID");
FeatureIDInput.Input.Expression = GetFeatureIdCall;

NodeX += Incr;

if (PropertyTable.Properties.Num()) {
const FCesiumPropertyTablePropertyDescription& property =
PropertyTable.Properties[0];
Expand All @@ -638,12 +640,18 @@ void GenerateNodesForPropertyTable(
}

NodeX = SectionLeft;
NodeY += Incr;

GetPropertyValuesFunction->AdditionalOutputs.Reserve(
PropertyTable.Properties.Num());
for (const FCesiumPropertyTablePropertyDescription& property :
PropertyTable.Properties) {
if (property.EncodingDetails.Conversion ==
ECesiumEncodedMetadataConversion::None) {
continue;
}

NodeY += Incr;

FString propertyName = createHlslSafeName(property.Name);

UMaterialExpressionTextureObjectParameter* PropertyData =
Expand Down Expand Up @@ -705,8 +713,6 @@ void GenerateNodesForPropertyTable(
GetPropertyValuesFunction->Code +=
propertyName + " = " + asComponentString + "(" + PropertyDataName +
".Load(int3(_czm_pixelX, _czm_pixelY, 0))." + swizzle + ");\n";

NodeY += Incr;
}

// Obligatory return code.
Expand Down Expand Up @@ -856,8 +862,8 @@ void GenerateMaterialNodes(

TSet<FString> GeneratedPropertyTableNames;

int32 SectionLeft = NodeX;
int32 GeneratedNodesWidth = 0;
int32 FeatureIdSectionLeft = NodeX;
int32 PropertyTableSectionLeft = FeatureIdSectionLeft + 3 * Incr;

for (const FCesiumFeatureIdSetDescription& featureIdSet :
pComponent->FeatureIdSets) {
Expand Down Expand Up @@ -897,7 +903,7 @@ void GenerateMaterialNodes(
});

if (pPropertyTable) {
NodeX += 4 * Incr;
NodeX = PropertyTableSectionLeft;

GenerateNodesForPropertyTable(
*pPropertyTable,
Expand All @@ -910,13 +916,14 @@ void GenerateMaterialNodes(
GeneratedPropertyTableNames.Add(pPropertyTable->Name);
}

GeneratedNodesWidth = std::max(NodeX, GeneratedNodesWidth);
NodeX = SectionLeft;
NodeY += Incr;
NodeX = FeatureIdSectionLeft;
NodeY += 2 * Incr;
}

NodeX += Incr;
NodeX = PropertyTableSectionLeft;

// Generate nodes for any property tables that aren't linked to a feature ID
// set.
for (const FCesiumPropertyTableDescription& propertyTable :
pComponent->PropertyTables) {
if (!GeneratedPropertyTableNames.Find(propertyTable.Name)) {
Expand All @@ -927,15 +934,14 @@ void GenerateMaterialNodes(
NodeX,
NodeY,
nullptr);
GeneratedNodesWidth = std::max(NodeX, GeneratedNodesWidth);
NodeX = SectionLeft;
NodeX = PropertyTableSectionLeft;
NodeY += Incr;
}
}

// GenerateNodesForPropertyTextures

NodeX = 0;
NodeX = FeatureIdSectionLeft;
NodeY = -2 * Incr;

UMaterialExpressionFunctionInput* InputMaterial = nullptr;
Expand Down Expand Up @@ -965,7 +971,7 @@ void GenerateMaterialNodes(
OneTimeGeneratedNodes.Add(InputMaterial);
}

NodeX += GeneratedNodesWidth + 2 * Incr;
NodeX += PropertyTableSectionLeft + 3 * Incr;

UMaterialExpressionSetMaterialAttributes* SetMaterialAttributes = nullptr;
#if ENGINE_MINOR_VERSION == 0
Expand Down Expand Up @@ -1045,6 +1051,21 @@ void UCesiumFeaturesMetadataComponent::GenerateMaterial() {

if (!GetFeatureIdsFromAttributeFunction ||
!GetFeatureIdsFromTextureFunction) {
UE_LOG(
LogCesium,
Error,
TEXT(
"Can't find the material functions necessary to generate material. Aborting."));
return;
}

if (this->TargetMaterialLayer &&
this->TargetMaterialLayer->GetPackage()->IsDirty()) {
UE_LOG(
LogCesium,
Error,
TEXT(
"Can't regenerate a material layer that has unsaved changes. Please save your changes and try again."));
return;
}

Expand Down
10 changes: 8 additions & 2 deletions Source/CesiumRuntime/Private/CesiumGltfComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,6 @@ static void SetPropertyTableParameterValues(
int32 index) {
for (const CesiumEncodedFeaturesMetadata::EncodedPropertyTableProperty&
encodedProperty : encodedPropertyTable.properties) {

pMaterial->SetTextureParameterValueByInfo(
FMaterialParameterInfo(
FName(CesiumEncodedFeaturesMetadata::
Expand Down Expand Up @@ -2454,7 +2453,14 @@ static void loadPrimitiveGameThreadPart(

PRAGMA_DISABLE_DEPRECATION_WARNINGS

pMesh->Metadata_DEPRECATED = std::move(loadResult.Metadata_DEPRECATED);
// Doing the above std::move operations invalidates the pointers in the
// FCesiumMetadataPrimitive constructed on the loadResult. It's a bit awkward,
// but we have to reconstruct the metadata primitive here.
pMesh->Metadata_DEPRECATED = FCesiumMetadataPrimitive{
pMesh->Features,
pMesh->Metadata,
pGltf->Metadata};

if (loadResult.EncodedMetadata_DEPRECATED) {
pMesh->EncodedMetadata_DEPRECATED =
std::move(loadResult.EncodedMetadata_DEPRECATED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class UCesiumGltfPrimitiveComponent : public UStaticMeshComponent {
* For backwards compatibility with the EXT_feature_metadata implementation.
*/
FCesiumMetadataPrimitive Metadata_DEPRECATED;

std::optional<CesiumEncodedMetadataUtility::EncodedMetadataPrimitive>
EncodedMetadata_DEPRECATED;
PRAGMA_ENABLE_DEPRECATION_WARNINGS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ UCesiumMetadataPickingBlueprintLibrary::GetMetadataValuesForFace(
int64 featureID =
UCesiumPrimitiveFeaturesBlueprintLibrary::GetFeatureIDFromFace(
features,
featureIDSet,
FaceIndex);
FaceIndex,
FeatureIDSetIndex);
if (featureID < 0) {
return TMap<FString, FCesiumMetadataValue>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
PRAGMA_DISABLE_DEPRECATION_WARNINGS

#include "CesiumMetadataUtilityBlueprintLibrary.h"
#include "CesiumFeatureIdAttribute.h"
#include "CesiumFeatureIdTexture.h"
#include "CesiumGltfComponent.h"
#include "CesiumGltfPrimitiveComponent.h"
Expand Down Expand Up @@ -51,8 +50,6 @@ UCesiumMetadataUtilityBlueprintLibrary::GetMetadataValuesForFace(
const FCesiumPrimitiveMetadata& primitiveMetadata = pGltfComponent->Metadata;

// For now, only considers the first feature ID set
// TODO: expand to arbitrary number of features once testing data is
// available
const FCesiumFeatureIdSet& featureIDSet = featureIDSets[0];
const int64 propertyTableIndex =
UCesiumFeatureIdSetBlueprintLibrary::GetPropertyTableIndex(featureIDSet);
Expand All @@ -69,8 +66,8 @@ UCesiumMetadataUtilityBlueprintLibrary::GetMetadataValuesForFace(
int64 featureID =
UCesiumPrimitiveFeaturesBlueprintLibrary::GetFeatureIDFromFace(
features,
featureIDSet,
FaceIndex);
FaceIndex,
0);
if (featureID < 0) {
return TMap<FString, FCesiumMetadataValue>();
}
Expand Down
11 changes: 8 additions & 3 deletions Source/CesiumRuntime/Private/CesiumPrimitiveFeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,15 @@ int64 UCesiumPrimitiveFeaturesBlueprintLibrary::GetFirstVertexFromFace(

int64 UCesiumPrimitiveFeaturesBlueprintLibrary::GetFeatureIDFromFace(
UPARAM(ref) const FCesiumPrimitiveFeatures& PrimitiveFeatures,
UPARAM(ref) const FCesiumFeatureIdSet& FeatureIDSet,
int64 FaceIndex) {
int64 FaceIndex,
int64 FeatureIDSetIndex) {
if (FeatureIDSetIndex < 0 ||
FeatureIDSetIndex > PrimitiveFeatures._featureIDSets.Num()) {
return -1;
}

return UCesiumFeatureIdSetBlueprintLibrary::GetFeatureIDForVertex(
FeatureIDSet,
PrimitiveFeatures._featureIDSets[FeatureIDSetIndex],
UCesiumPrimitiveFeaturesBlueprintLibrary::GetFirstVertexFromFace(
PrimitiveFeatures,
FaceIndex));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "CesiumSubLevelSwitcherComponent.h"
#include "CesiumRuntime.h"
#include "CesiumSubLevelComponent.h"
#include "Engine/LevelStreaming.h"
#include "Engine/World.h"
Expand Down
11 changes: 6 additions & 5 deletions Source/CesiumRuntime/Private/Tests/CesiumGltfSpecUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,22 @@ CesiumGltf::PropertyTableProperty& AddPropertyTablePropertyToModel(
const std::string& type,
const std::optional<std::string>& componentType,
const std::vector<T>& values) {
ExtensionModelExtStructuralMetadata* pExtension =
model.getExtension<ExtensionModelExtStructuralMetadata>();
CesiumGltf::ExtensionModelExtStructuralMetadata* pExtension =
model.getExtension<CesiumGltf::ExtensionModelExtStructuralMetadata>();
if (pExtension == nullptr) {
pExtension = &model.addExtension<ExtensionModelExtStructuralMetadata>();
pExtension =
&model.addExtension<CesiumGltf::ExtensionModelExtStructuralMetadata>();
}

if (!pExtension->schema) {
pExtension->schema.emplace();
}
Schema& schema = *pExtension->schema;
CesiumGltf::Schema& schema = *pExtension->schema;

const std::string& className = propertyTable.classProperty;
CesiumGltf::Class& theClass = schema.classes[className];

ClassProperty& classProperty = theClass.properties[propertyName];
CesiumGltf::ClassProperty& classProperty = theClass.properties[propertyName];
classProperty.type = type;
classProperty.componentType = componentType;

Expand Down
Loading

0 comments on commit 43d7499

Please sign in to comment.