Skip to content

Commit

Permalink
Get property texture picking to work
Browse files Browse the repository at this point in the history
  • Loading branch information
j9liu committed Oct 16, 2023
1 parent d2fd168 commit f9d5edd
Show file tree
Hide file tree
Showing 14 changed files with 318 additions and 179 deletions.
3 changes: 1 addition & 2 deletions Config/Engine.ini
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ RunningThreadedRequestLimit=100
# EXT_feature_metadata -> EXT_structural_metadata changes

# Deprecate the old type enum. Unfortunately, there's no way to redirect it to a CesiumMetadataValueType struct.
+EnumRedirects=(OldName="ECesiumMetadataTrueType", NewName="ECesiumMetadataTrueType_DEPRECATED", ValueChanges=
(("None","None_DEPRECATED"),("Int8","Int8_DEPRECATED"),("Uint8","Uint8_DEPRECATED"),("Int16","Int16_DEPRECATED"),("Uint16","Uint16_DEPRECATED"),("Int32","Int32_DEPRECATED"),("Uint32","Uint32_DEPRECATED"),("Int64","Int64_DEPRECATED"),("Uint64","Uint64_DEPRECATED"),("Float32","Float32_DEPRECATED"),("Float64","Float64_DEPRECATED"),("Boolean","Boolean_DEPRECATED"),("Enum","Enum_DEPRECATED"),("String","String_DEPRECATED"),("Array","Array_DEPRECATED")))
+EnumRedirects=(OldName="ECesiumMetadataTrueType", NewName="ECesiumMetadataTrueType_DEPRECATED", ValueChanges=(("None","None_DEPRECATED"),("Int8","Int8_DEPRECATED"),("Uint8","Uint8_DEPRECATED"),("Int16","Int16_DEPRECATED"),("Uint16","Uint16_DEPRECATED"),("Int32","Int32_DEPRECATED"),("Uint32","Uint32_DEPRECATED"),("Int64","Int64_DEPRECATED"),("Uint64","Uint64_DEPRECATED"),("Float32","Float32_DEPRECATED"),("Float64","Float64_DEPRECATED"),("Boolean","Boolean_DEPRECATED"),("Enum","Enum_DEPRECATED"),("String","String_DEPRECATED"),("Array","Array_DEPRECATED")))

+StructRedirects=(OldName="CesiumMetadataGenericValue", NewName="CesiumMetadataValue")
+ClassRedirects=(OldName="CesiumMetadataGenericValueBlueprintLibrary", NewName="CesiumMetadataValueBlueprintLibrary")
Expand Down
53 changes: 53 additions & 0 deletions Source/CesiumRuntime/Private/CesiumFeatureIdSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "CesiumGltf/ExtensionModelExtStructuralMetadata.h"
#include "CesiumGltf/FeatureId.h"
#include "CesiumGltf/Model.h"
#include "CesiumGltfPrimitiveComponent.h"

using namespace CesiumGltf;

Expand Down Expand Up @@ -135,3 +136,55 @@ int64 UCesiumFeatureIdSetBlueprintLibrary::GetFeatureIDForVertex(

return -1;
}

int64 UCesiumFeatureIdSetBlueprintLibrary::GetFeatureIDFromHit(
UPARAM(ref) const FCesiumFeatureIdSet& FeatureIDSet,
const FHitResult& Hit) {
if (FeatureIDSet._featureIDSetType == ECesiumFeatureIdSetType::Texture) {
FCesiumFeatureIdTexture texture =
std::get<FCesiumFeatureIdTexture>(FeatureIDSet._featureID);
return UCesiumFeatureIdTextureBlueprintLibrary::GetFeatureIDFromHit(
texture,
Hit);
}

// Find the first vertex of the face.
const UCesiumGltfPrimitiveComponent* pGltfComponent =
Cast<UCesiumGltfPrimitiveComponent>(Hit.Component);
if (!IsValid(pGltfComponent)) {
return false;
}

if (!pGltfComponent->GetStaticMesh() ||
!pGltfComponent->GetStaticMesh()->GetRenderData()) {
return false;
}

auto& LODResources =
pGltfComponent->GetStaticMesh()->GetRenderData()->LODResources[0];
auto PositionBuffer = LODResources.VertexBuffers.PositionVertexBuffer;

auto faceIndices = std::visit(
CesiumFaceVertexIndicesFromAccessor{
Hit.FaceIndex,
static_cast<int64_t>(PositionBuffer.GetNumVertices())},
pGltfComponent->IndexAccessor);

int64 VertexIndex = faceIndices[0];

if (FeatureIDSet._featureIDSetType == ECesiumFeatureIdSetType::Attribute) {
FCesiumFeatureIdAttribute attribute =
std::get<FCesiumFeatureIdAttribute>(FeatureIDSet._featureID);
return UCesiumFeatureIdAttributeBlueprintLibrary::GetFeatureIDForVertex(
attribute,
VertexIndex);
}

if (FeatureIDSet._featureIDSetType == ECesiumFeatureIdSetType::Implicit) {
return (VertexIndex >= 0 && VertexIndex < FeatureIDSet._featureCount)
? VertexIndex
: -1;
}

return -1;
}
4 changes: 2 additions & 2 deletions Source/CesiumRuntime/Private/CesiumFeatureIdTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ int64 UCesiumFeatureIdTextureBlueprintLibrary::GetUnrealUVChannel(
return -1;
}

auto textureCoordinateIndexIt = pPrimitive->glTFToUnrealTexCoordMap.find(
auto textureCoordinateIndexIt = pPrimitive->GltfToUnrealTexCoordMap.find(
UCesiumFeatureIdTextureBlueprintLibrary::GetGltfTextureCoordinateSetIndex(
FeatureIDTexture));
if (textureCoordinateIndexIt == pPrimitive->glTFToUnrealTexCoordMap.end()) {
if (textureCoordinateIndexIt == pPrimitive->GltfToUnrealTexCoordMap.end()) {
return -1;
}

Expand Down
Loading

0 comments on commit f9d5edd

Please sign in to comment.