Skip to content

Commit

Permalink
Stylistic changes after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
timoore committed Nov 28, 2024
1 parent 999d8e5 commit 4f5e3ea
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 30 deletions.
1 change: 0 additions & 1 deletion Source/CesiumRuntime/Private/CesiumFeatureIdAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "CesiumFeatureIdAttribute.h"
#include <CesiumGltf/Accessor.h>
#include <CesiumGltf/ExtensionExtMeshGpuInstancing.h>
#include <CesiumGltf/Model.h>

FCesiumFeatureIdAttribute::FCesiumFeatureIdAttribute(
Expand Down
27 changes: 14 additions & 13 deletions Source/CesiumRuntime/Private/CesiumFeatureIdSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ FCesiumFeatureIdSet::FCesiumFeatureIdSet(
if (pMetadata && _propertyTableIndex >= 0) {
size_t index = static_cast<size_t>(_propertyTableIndex);
if (index < pMetadata->propertyTables.size()) {
const CesiumGltf::PropertyTable& propertyTable = pMetadata->propertyTables[index];
const CesiumGltf::PropertyTable& propertyTable =
pMetadata->propertyTables[index];
std::string name = propertyTable.name.value_or("");
propertyTableName = FString(name.c_str());
}
Expand Down Expand Up @@ -217,6 +218,18 @@ int64 UCesiumFeatureIdSetBlueprintLibrary::GetFeatureIDForInstance(
int64 UCesiumFeatureIdSetBlueprintLibrary::GetFeatureIDFromHit(
UPARAM(ref) const FCesiumFeatureIdSet& FeatureIDSet,
const FHitResult& Hit) {
// FeatureIDs from instanced geometry take precedence.
const auto* pInstancedComponent =
Cast<UCesiumGltfInstancedComponent>(Hit.Component);
if (IsValid(pInstancedComponent)) {
const FCesiumInstanceFeatures& instanceFeatures =
UCesiumInstanceFeaturesBlueprintLibrary::GetInstanceFeatures(
pInstancedComponent);
return UCesiumInstanceFeaturesBlueprintLibrary::GetFeatureIDFromInstance(
instanceFeatures,
Hit.Item);
}

if (FeatureIDSet._featureIDSetType == ECesiumFeatureIdSetType::Texture) {
FCesiumFeatureIdTexture texture =
std::get<FCesiumFeatureIdTexture>(FeatureIDSet._featureID);
Expand All @@ -225,18 +238,6 @@ int64 UCesiumFeatureIdSetBlueprintLibrary::GetFeatureIDFromHit(
Hit);
}

{
const auto* pInstancedComponent =
Cast<UCesiumGltfInstancedComponent>(Hit.Component);
if (IsValid(pInstancedComponent)) {
const FCesiumInstanceFeatures& instanceFeatures =
UCesiumInstanceFeaturesBlueprintLibrary::GetInstanceFeatures(
pInstancedComponent);
return UCesiumInstanceFeaturesBlueprintLibrary::GetFeatureIDFromInstance(
instanceFeatures,
Hit.Item);
}
}
// Find the first vertex of the face.
const UCesiumGltfPrimitiveComponent* pGltfComponent =
Cast<UCesiumGltfPrimitiveComponent>(Hit.Component);
Expand Down
4 changes: 3 additions & 1 deletion Source/CesiumRuntime/Private/LoadGltfResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ struct LoadNodeResult {
*/
std::vector<FTransform> InstanceTransforms;
/**
* Instance features
* Features from EXT_instance_features. A pointer is used for shared ownership
* because there may be multiple primitives in the same mesh belonging to a
* single instance.
*/
TSharedPtr<FCesiumInstanceFeatures> pInstanceFeatures = nullptr;
};
Expand Down
5 changes: 3 additions & 2 deletions Source/CesiumRuntime/Public/CesiumFeatureIdAttribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ struct CESIUMRUNTIME_API FCesiumFeatureIdAttribute {
const FString& PropertyTableName);

/**
* @brief Constructs a feature ID attribute instance from instance metadata.
* @brief Constructs a feature ID attribute instance from
* EXT_instance_features data.
*
* @param Model The model.
* @param Node The "mesh node" containing the feature ID attribute.
* @param Node The node containing the feature ID attribute.
* @param FeatureIDAttribute The attribute index specified by the FeatureId.
* @param PropertyTableName The name of the property table this attribute
* corresponds to, if one exists, for backwards compatibility.
Expand Down
13 changes: 8 additions & 5 deletions Source/CesiumRuntime/Public/CesiumFeatureIdSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ enum class ECesiumFeatureIdSetType : uint8 {
/**
* @brief A blueprint-accessible wrapper for a feature ID set from a glTF
* primitive. A feature ID can be defined as a per-vertex attribute, as a
* feature texture, or implicitly via vertex ID. These can be used with the
* corresponding {@link FCesiumPropertyTable} to access per-vertex metadata.
* feature texture, implicitly via vertex ID, or associated with glTF
* instances. These can be used with the corresponding {@link
* FCesiumPropertyTable} to access the metadata.
*/
USTRUCT(BlueprintType)
struct CESIUMRUNTIME_API FCesiumFeatureIdSet {
Expand Down Expand Up @@ -189,12 +190,14 @@ class CESIUMRUNTIME_API UCesiumFeatureIdSetBlueprintLibrary
int64 VertexIndex);

/**
* Gets the feature ID associated with a given instance. The feature ID can be
* used with a FCesiumPropertyTable to retrieve the corresponding metadata.
* Gets the feature ID associated with a given instance in glTF models using
* the EXT_mesh_gpu_instancing and EXT_instance_features extensions. The
* feature ID can be used with a FCesiumPropertyTable to retrieve the
* corresponding metadata.
*
* This returns -1 if the given instance is out-of-bounds, if the feature ID
* set is not for instances, or if the feature ID set is invalid (e.g., it
* contains an invalid feature ID texture).
* contains an invalid feature ID attribute).
*/
UFUNCTION(
BlueprintCallable,
Expand Down
17 changes: 9 additions & 8 deletions Source/CesiumRuntime/Public/CesiumInstanceFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ struct CESIUMRUNTIME_API FCesiumInstanceFeatures {

public:
/**
* Constructs an empty primitive features instance.
* Constructs an empty instance features object.
*/
FCesiumInstanceFeatures() : _instanceCount(0) {}

/**
* Constructs an instance feature.
* Constructs an instance feature object.
*
* @param Model The model that contains the EXT_instance_features extension
* @param Node The node that stores instance data
* @param Node The node that stores EXT_instance_features
* extension
*/
FCesiumInstanceFeatures(
Expand All @@ -52,8 +52,9 @@ class CESIUMRUNTIME_API UCesiumInstanceFeaturesBlueprintLibrary

public:
/**
* Gets the instance features of a glTF primitive component. If component is
* not a Cesium glTF primitive component, the returned features are empty.
* Gets the instance features of an instanced glTF primitive component. If
* component is not an instanced Cesium glTF component, the returned features
* are empty.
*/
UFUNCTION(
BlueprintCallable,
Expand All @@ -63,8 +64,8 @@ class CESIUMRUNTIME_API UCesiumInstanceFeaturesBlueprintLibrary
GetInstanceFeatures(const UPrimitiveComponent* component);

/**
* Gets all the feature ID sets that are associated with the
* primitive.
* Gets all the feature ID sets that are associated with the features
* associated with an instanced primitive.
*/
UFUNCTION(
BlueprintCallable,
Expand All @@ -86,7 +87,7 @@ class CESIUMRUNTIME_API UCesiumInstanceFeaturesBlueprintLibrary
ECesiumFeatureIdSetType Type);

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

0 comments on commit 4f5e3ea

Please sign in to comment.