Skip to content

Commit

Permalink
Remove FCesiumInstanceFeatures
Browse files Browse the repository at this point in the history
This collection duplicated all the functionality of
FCesiumPrimitiveFeatures, so just that instead.
  • Loading branch information
timoore committed Dec 2, 2024
1 parent fb497e0 commit f19130a
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 197 deletions.
8 changes: 3 additions & 5 deletions Source/CesiumRuntime/Private/CesiumFeatureIdSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "CesiumGltf/FeatureId.h"
#include "CesiumGltf/Model.h"
#include "CesiumGltfPrimitiveComponent.h"
#include "CesiumInstanceFeatures.h"

static FCesiumFeatureIdAttribute EmptyFeatureIDAttribute;
static FCesiumFeatureIdTexture EmptyFeatureIDTexture;
Expand Down Expand Up @@ -219,10 +218,9 @@ int64 UCesiumFeatureIdSetBlueprintLibrary::GetFeatureIDFromHit(
const auto* pInstancedComponent =
Cast<UCesiumGltfInstancedComponent>(Hit.Component);
if (IsValid(pInstancedComponent)) {
const FCesiumInstanceFeatures& instanceFeatures =
UCesiumInstanceFeaturesBlueprintLibrary::GetInstanceFeatures(
pInstancedComponent);
return UCesiumInstanceFeaturesBlueprintLibrary::GetFeatureIDFromInstance(
const FCesiumPrimitiveFeatures& instanceFeatures =
*pInstancedComponent->pInstanceFeatures;
return UCesiumPrimitiveFeaturesBlueprintLibrary::GetFeatureIDFromInstance(
instanceFeatures,
Hit.Item);
}
Expand Down
5 changes: 3 additions & 2 deletions Source/CesiumRuntime/Private/CesiumGltfComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,8 @@ static void loadInstancingData(
result.InstanceTransforms[i].SetFromMatrix(unrealFMatrix);
}
if (pInstanceFeatures) {
result.pInstanceFeatures = MakeShared<FCesiumInstanceFeatures>(model, node);
result.pInstanceFeatures =
MakeShared<FCesiumPrimitiveFeatures>(model, node);
}
}

Expand Down Expand Up @@ -2885,7 +2886,7 @@ static void loadPrimitiveGameThreadPart(
bool createNavCollision,
ACesium3DTileset* pTilesetActor,
const std::vector<FTransform>& instanceTransforms,
TSharedPtr<FCesiumInstanceFeatures> pInstanceFeatures) {
TSharedPtr<FCesiumPrimitiveFeatures> pInstanceFeatures) {
TRACE_CPUPROFILER_EVENT_SCOPE(Cesium::LoadPrimitive)

#if DEBUG_GLTF_ASSET_NAMES
Expand Down
4 changes: 2 additions & 2 deletions Source/CesiumRuntime/Private/CesiumGltfPrimitiveComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#pragma once

#include "Cesium3DTilesSelection/BoundingVolume.h"
#include "CesiumInstanceFeatures.h"
#include "CesiumPrimitive.h"
#include "CesiumPrimitiveFeatures.h"
#include "Components/InstancedStaticMeshComponent.h"
#include "Components/StaticMeshComponent.h"
#include "CoreMinimal.h"
Expand Down Expand Up @@ -63,7 +63,7 @@ class UCesiumGltfInstancedComponent : public UInstancedStaticMeshComponent,
CesiumPrimitiveData& getPrimitiveData() override;
const CesiumPrimitiveData& getPrimitiveData() const override;

TSharedPtr<FCesiumInstanceFeatures> pInstanceFeatures;
TSharedPtr<FCesiumPrimitiveFeatures> pInstanceFeatures;

private:
CesiumPrimitiveData _cesiumData;
Expand Down
81 changes: 0 additions & 81 deletions Source/CesiumRuntime/Private/CesiumInstanceFeatures.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ getInstancePropertyTableValues(
if (!IsValid(pInstancedComponent)) {
return std::nullopt;
}
const TSharedPtr<FCesiumInstanceFeatures> pInstanceFeatures =
const TSharedPtr<FCesiumPrimitiveFeatures> pInstanceFeatures =
pInstancedComponent->pInstanceFeatures;
if (!pInstanceFeatures) {
return std::nullopt;
}

const TArray<FCesiumFeatureIdSet>& featureIDSets =
UCesiumInstanceFeaturesBlueprintLibrary::GetFeatureIDSets(
UCesiumPrimitiveFeaturesBlueprintLibrary::GetFeatureIDSets(
*pInstanceFeatures);
if (FeatureIDSetIndex < 0 || FeatureIDSetIndex >= featureIDSets.Num()) {
return TMap<FString, FCesiumMetadataValue>();
Expand All @@ -192,7 +192,7 @@ getInstancePropertyTableValues(
const FCesiumPropertyTable& propertyTable =
propertyTables[propertyTableIndex];
int64 featureID =
UCesiumInstanceFeaturesBlueprintLibrary::GetFeatureIDFromInstance(
UCesiumPrimitiveFeaturesBlueprintLibrary::GetFeatureIDFromInstance(
*pInstanceFeatures,
Hit.Item,
FeatureIDSetIndex);
Expand Down
36 changes: 36 additions & 0 deletions Source/CesiumRuntime/Private/CesiumPrimitiveFeatures.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright 2020-2024 CesiumGS, Inc. and Contributors

#include "CesiumPrimitiveFeatures.h"
#include "CesiumGltf/ExtensionExtInstanceFeatures.h"
#include "CesiumGltf/ExtensionExtMeshFeatures.h"
#include "CesiumGltf/ExtensionExtMeshGpuInstancing.h"
#include "CesiumGltf/Model.h"
#include "CesiumGltfPrimitiveComponent.h"

Expand All @@ -26,6 +28,26 @@ FCesiumPrimitiveFeatures::FCesiumPrimitiveFeatures(
}
}

FCesiumPrimitiveFeatures::FCesiumPrimitiveFeatures(
const CesiumGltf::Model& Model,
const CesiumGltf::Node& Node)
: _vertexCount(0), _primitiveMode(-1) {
if (Node.mesh < 0 || Node.mesh >= Model.meshes.size()) {
return;
}
const auto* pInstancing =
Node.getExtension<CesiumGltf::ExtensionExtMeshGpuInstancing>();
if (!pInstancing) {
return;
}
if (const auto* pInstanceFeatures =
Node.getExtension<CesiumGltf::ExtensionExtInstanceFeatures>()) {
for (const auto& featureId : pInstanceFeatures->featureIds) {
_featureIdSets.Emplace(Model, Node, featureId);
}
}
}

const FCesiumPrimitiveFeatures&
UCesiumPrimitiveFeaturesBlueprintLibrary::GetPrimitiveFeatures(
const UPrimitiveComponent* component) {
Expand Down Expand Up @@ -98,6 +120,20 @@ int64 UCesiumPrimitiveFeaturesBlueprintLibrary::GetFeatureIDFromFace(
FaceIndex));
}

int64 UCesiumPrimitiveFeaturesBlueprintLibrary::GetFeatureIDFromInstance(
const FCesiumPrimitiveFeatures& InstanceFeatures,
int64 InstanceIndex,
int64 FeatureIDSetIndex) {
if (FeatureIDSetIndex < 0 ||
FeatureIDSetIndex >= InstanceFeatures._featureIdSets.Num()) {
return -1;
}
const auto& featureIDSet = InstanceFeatures._featureIdSets[FeatureIDSetIndex];
return UCesiumFeatureIdSetBlueprintLibrary::GetFeatureIDForInstance(
featureIDSet,
InstanceIndex);
}

int64 UCesiumPrimitiveFeaturesBlueprintLibrary::GetFeatureIDFromHit(
UPARAM(ref) const FCesiumPrimitiveFeatures& PrimitiveFeatures,
const FHitResult& Hit,
Expand Down
3 changes: 1 addition & 2 deletions Source/CesiumRuntime/Private/LoadGltfResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "CesiumCommon.h"
#include "CesiumEncodedFeaturesMetadata.h"
#include "CesiumInstanceFeatures.h"
#include "CesiumMetadataPrimitive.h"
#include "CesiumModelMetadata.h"
#include "CesiumPrimitiveFeatures.h"
Expand Down Expand Up @@ -200,7 +199,7 @@ struct LoadNodeResult {
* because there may be multiple primitives in the same mesh belonging to a
* single instance.
*/
TSharedPtr<FCesiumInstanceFeatures> pInstanceFeatures = nullptr;
TSharedPtr<FCesiumPrimitiveFeatures> pInstanceFeatures = nullptr;
};

/**
Expand Down
101 changes: 0 additions & 101 deletions Source/CesiumRuntime/Public/CesiumInstanceFeatures.h

This file was deleted.

30 changes: 29 additions & 1 deletion Source/CesiumRuntime/Public/CesiumPrimitiveFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ struct ExtensionExtMeshFeatures;

/**
* A Blueprint-accessible wrapper for a glTF Primitive's mesh features. It holds
* views of the feature ID sets associated with this primitive.
* views of the feature ID sets associated with this primitive. The collection
* of features in the EXT_instance_features is very similar to that in
* EXT_mesh_features, so FCesiumPrimitiveFeatures can be used to handle those
* features too.
*/
USTRUCT(BlueprintType)
struct CESIUMRUNTIME_API FCesiumPrimitiveFeatures {
Expand All @@ -41,9 +44,21 @@ struct CESIUMRUNTIME_API FCesiumPrimitiveFeatures {
const CesiumGltf::MeshPrimitive& Primitive,
const CesiumGltf::ExtensionExtMeshFeatures& Features);

/**
* Constructs an instance feature object.
*
* @param Model The model that contains the EXT_instance_features extension
* @param Node The node that stores EXT_instance_features
* extension
*/
FCesiumPrimitiveFeatures(
const CesiumGltf::Model& Model,
const CesiumGltf::Node& Node);

private:
TArray<FCesiumFeatureIdSet> _featureIdSets;
CesiumGltf::IndexAccessorType _indexAccessor;
// Vertex count = 0 and _primitiveMode = -1 indicates instance features
int64_t _vertexCount;
int32_t _primitiveMode;

Expand Down Expand Up @@ -132,6 +147,19 @@ class CESIUMRUNTIME_API UCesiumPrimitiveFeaturesBlueprintLibrary
int64 FaceIndex,
int64 FeatureIDSetIndex = 0);

/**
* Gets the feature ID associated with an instance at an index.
*
*/
UFUNCTION(
BlueprintCallable,
BlueprintPure,
Category = "Cesium|Primitive|Features")
static int64 GetFeatureIDFromInstance(
UPARAM(ref) const FCesiumPrimitiveFeatures& InstanceFeatures,
int64 InstanceIndex,
int64 FeatureIDSetIndex = 0);

/**
* Gets the feature ID from the given line trace hit, assuming it
* has hit a glTF primitive component containing this CesiumPrimitiveFeatures.
Expand Down

0 comments on commit f19130a

Please sign in to comment.