Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
j9liu committed Dec 20, 2024
1 parent 8db3e82 commit 3d26412
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
15 changes: 0 additions & 15 deletions Source/CesiumRuntime/Private/CesiumFeatureIdAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,6 @@ FCesiumFeatureIdAttribute::FCesiumFeatureIdAttribute(
_featureIdAccessor(),
_attributeIndex(FeatureIDAttribute),
_propertyTableName(PropertyTableName) {
const std::string attributeName =
"_FEATURE_ID_" + std::to_string(FeatureIDAttribute);

auto featureID = Primitive.attributes.find(attributeName);
if (featureID == Primitive.attributes.end()) {
return;
}

const CesiumGltf::Accessor* accessor =
Model.getSafe<CesiumGltf::Accessor>(&Model.accessors, featureID->second);
if (!accessor || accessor->type != CesiumGltf::Accessor::Type::SCALAR) {
this->_status = ECesiumFeatureIdAttributeStatus::ErrorInvalidAccessor;
return;
}

this->_featureIdAccessor = CesiumGltf::getFeatureIdAccessorView(
Model,
Primitive,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ bool UCesiumMetadataPickingBlueprintLibrary::FindUVFromHit(

namespace {
/*
* Returns std:nullopt if the component isnt an instanced static mesh or doesn't
* have instance feature ID data, which will allow
* GetPropertyTableValuesFromHit() to search for feature IDs in primitive
* Returns std:nullopt if the component isn't an instanced static mesh or
* if it doesn't have instance feature IDs. This will prompt
* GetPropertyTableValuesFromHit() to search for feature IDs in the primitive's
* attributes.
*/
std::optional<TMap<FString, FCesiumMetadataValue>>
Expand All @@ -167,7 +167,7 @@ getInstancePropertyTableValues(
if (!IsValid(pInstancedComponent)) {
return std::nullopt;
}
const TSharedPtr<FCesiumPrimitiveFeatures> pInstanceFeatures =
const TSharedPtr<FCesiumPrimitiveFeatures>& pInstanceFeatures =
pInstancedComponent->pInstanceFeatures;
if (!pInstanceFeatures) {
return std::nullopt;
Expand Down Expand Up @@ -210,25 +210,31 @@ UCesiumMetadataPickingBlueprintLibrary::GetPropertyTableValuesFromHit(
const FHitResult& Hit,
int64 FeatureIDSetIndex) {
const UCesiumGltfComponent* pModel = nullptr;

if (const auto* pPrimComponent = Cast<UPrimitiveComponent>(Hit.Component);
!IsValid(pPrimComponent)) {
return TMap<FString, FCesiumMetadataValue>();
} else {
pModel = Cast<UCesiumGltfComponent>(pPrimComponent->GetOuter());
if (!IsValid(pModel)) {
return TMap<FString, FCesiumMetadataValue>();
}
}
std::optional<TMap<FString, FCesiumMetadataValue>> instanceProperties =

if (!IsValid(pModel)) {
return TMap<FString, FCesiumMetadataValue>();
}

// Query for instance-level metadata first. (EXT_instance_features)
std::optional<TMap<FString, FCesiumMetadataValue>> maybeProperties =
getInstancePropertyTableValues(Hit, pModel, FeatureIDSetIndex);
if (instanceProperties) {
return *instanceProperties;
if (maybeProperties) {
return *maybeProperties;
}

const auto* pCesiumPrimitive = Cast<ICesiumPrimitive>(Hit.Component);
if (!pCesiumPrimitive) {
return TMap<FString, FCesiumMetadataValue>();
}

// Query for primitive-level metadata. (EXT_mesh_features)
const CesiumPrimitiveData& primData = pCesiumPrimitive->getPrimitiveData();
const FCesiumPrimitiveFeatures& features = primData.Features;
const TArray<FCesiumFeatureIdSet>& featureIDSets =
Expand Down
3 changes: 1 addition & 2 deletions Source/CesiumRuntime/Public/CesiumPrimitiveFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ class CESIUMRUNTIME_API UCesiumPrimitiveFeaturesBlueprintLibrary
int64 FeatureIDSetIndex = 0);

/**
* Gets the feature ID associated with an instance at an index.
*
* Gets the feature ID associated with the instance at the given index.
*/
UFUNCTION(
BlueprintCallable,
Expand Down

0 comments on commit 3d26412

Please sign in to comment.