Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into vcpkg
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Aug 15, 2024
2 parents e727ba0 + c7066a5 commit c09e998
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 68 deletions.
9 changes: 7 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# Change Log

### ? - ?
### v2.7.1 - 2024-08-01

#### Fixes :wrench:
##### Fixes :wrench:

- Improved collision and line tracing against tilesets by working around an overly-aggressive degenerate triangle check in the Chaos physics engine.
- Fixed a bug that could cause a `bad_any_cast` exception when trying to access glTF extensions on non-Windows platforms. This commonly popped up when loading tilesets with metadata.
- Fixed a bug that caused the `GetInteger64` functions on `CesiumMetadataValue`, `CesiumPropertyArray`, and `CesiumPropertyTableProperty` to always return the default value on non-Windows platforms.
- Fixed issue with `UCesiumGlobeAnchorComponent::GetEllipsoid` that caused compilation errors on some machines.

In addition to the above, this release updates [cesium-native](https://github.com/CesiumGS/cesium-native) from v0.37.0 to v0.38.0. See the [changelog](https://github.com/CesiumGS/cesium-native/blob/main/CHANGES.md) for a complete list of changes in cesium-native.

### v2.7.0 - 2024-07-01

##### Additions :tada:
Expand Down
4 changes: 2 additions & 2 deletions CesiumForUnreal.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 61,
"VersionName": "2.7.0",
"Version": 62,
"VersionName": "2.7.1",
"FriendlyName": "Cesium for Unreal",
"Description": "Unlock the 3D geospatial ecosystem in Unreal Engine with real-world 3D content and a high accuracy full-scale WGS84 globe.",
"Category": "Geospatial",
Expand Down
44 changes: 19 additions & 25 deletions Source/CesiumRuntime/Private/CesiumGltfComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,9 @@ static void loadPrimitive(
maxPosition = glm::dvec3(max[0], max[1], max[2]);
}

minPosition *= CesiumPrimitiveData::positionScaleFactor;
maxPosition *= CesiumPrimitiveData::positionScaleFactor;

primitiveResult.dimensions =
glm::vec3(transform * glm::dvec4(maxPosition - minPosition, 0));

Expand Down Expand Up @@ -1370,9 +1373,9 @@ static void loadPrimitive(
FStaticMeshBuildVertex& vertex = StaticMeshBuildVertices[i];
uint32 vertexIndex = indices[i];
const TMeshVector3& pos = positionView[vertexIndex];
vertex.Position.X = pos.X;
vertex.Position.Y = -pos.Y;
vertex.Position.Z = pos.Z;
vertex.Position.X = pos.X * CesiumPrimitiveData::positionScaleFactor;
vertex.Position.Y = -pos.Y * CesiumPrimitiveData::positionScaleFactor;
vertex.Position.Z = pos.Z * CesiumPrimitiveData::positionScaleFactor;
vertex.UVs[0] = TMeshVector2(0.0f, 0.0f);
vertex.UVs[2] = TMeshVector2(0.0f, 0.0f);
RenderData->Bounds.SphereRadius = FMath::Max(
Expand All @@ -1384,9 +1387,9 @@ static void loadPrimitive(
for (int i = 0; i < StaticMeshBuildVertices.Num(); ++i) {
FStaticMeshBuildVertex& vertex = StaticMeshBuildVertices[i];
const TMeshVector3& pos = positionView[i];
vertex.Position.X = pos.X;
vertex.Position.Y = -pos.Y;
vertex.Position.Z = pos.Z;
vertex.Position.X = pos.X * CesiumPrimitiveData::positionScaleFactor;
vertex.Position.Y = -pos.Y * CesiumPrimitiveData::positionScaleFactor;
vertex.Position.Z = pos.Z * CesiumPrimitiveData::positionScaleFactor;
vertex.UVs[0] = TMeshVector2(0.0f, 0.0f);
vertex.UVs[2] = TMeshVector2(0.0f, 0.0f);
RenderData->Bounds.SphereRadius = FMath::Max(
Expand Down Expand Up @@ -1669,7 +1672,14 @@ static void loadPrimitive(
primitiveResult.pMaterial = &material;
primitiveResult.pCollisionMesh = nullptr;

primitiveResult.transform = transform * yInvertMatrix;
double scale = 1.0 / CesiumPrimitiveData::positionScaleFactor;
glm::dmat4 scaleMatrix = glm::dmat4(
glm::dvec4(scale, 0.0, 0.0, 0.0),
glm::dvec4(0.0, scale, 0.0, 0.0),
glm::dvec4(0.0, 0.0, scale, 0.0),
glm::dvec4(0.0, 0.0, 0.0, 1.0));

primitiveResult.transform = transform * yInvertMatrix * scaleMatrix;

if (primitive.mode != MeshPrimitive::Mode::POINTS &&
options.pMeshOptions->pNodeOptions->pModelOptions->createPhysicsMeshes) {
Expand Down Expand Up @@ -3810,17 +3820,6 @@ void UCesiumGltfComponent::UpdateFade(float fadePercentage, bool fadingIn) {
}
}

static bool isTriangleDegenerate(
const Chaos::FTriangleMeshImplicitObject::ParticleVecType& A,
const Chaos::FTriangleMeshImplicitObject::ParticleVecType& B,
const Chaos::FTriangleMeshImplicitObject::ParticleVecType& C) {
Chaos::FTriangleMeshImplicitObject::ParticleVecType AB = B - A;
Chaos::FTriangleMeshImplicitObject::ParticleVecType AC = C - A;
Chaos::FTriangleMeshImplicitObject::ParticleVecType Normal =
Chaos::FTriangleMeshImplicitObject::ParticleVecType::CrossProduct(AB, AC);
return (Normal.SafeNormalize() < 1.e-8f);
}

template <typename TIndex>
#if ENGINE_VERSION_5_4_OR_HIGHER
static Chaos::FTriangleMeshImplicitObjectPtr
Expand Down Expand Up @@ -3849,13 +3848,8 @@ BuildChaosTriangleMeshes(
int32 vIndex1 = indices[index0];
int32 vIndex2 = indices[index0 + 2];

if (!isTriangleDegenerate(
vertices.X(vIndex0),
vertices.X(vIndex1),
vertices.X(vIndex2))) {
triangles.Add(Chaos::TVector<int32, 3>(vIndex0, vIndex1, vIndex2));
faceRemap.Add(i);
}
triangles.Add(Chaos::TVector<int32, 3>(vIndex0, vIndex1, vIndex2));
faceRemap.Add(i);
}

TUniquePtr<TArray<int32>> pFaceRemap = MakeUnique<TArray<int32>>(faceRemap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ bool UCesiumMetadataPickingBlueprintLibrary::FindUVFromHit(
std::array<FVector, 3> Positions;
for (size_t i = 0; i < Positions.size(); i++) {
auto& Position = primData.PositionAccessor[VertexIndices[i]];
// The Y-component of glTF positions must be inverted
Positions[i] = FVector(Position[0], -Position[1], Position[2]);
// The Y-component of glTF positions must be inverted, and the positions
// must be scaled to match the UE meshes.
Positions[i] = FVector(Position[0], -Position[1], Position[2]) *
CesiumPrimitiveData::positionScaleFactor;
}

const FVector Location =
Expand Down
6 changes: 3 additions & 3 deletions Source/CesiumRuntime/Private/CesiumMetadataValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ int64 UCesiumMetadataValueBlueprintLibrary::GetInteger64(
int64 DefaultValue) {
return swl::visit(
[DefaultValue](auto value) -> int64 {
return CesiumGltf::MetadataConversions<int64, decltype(value)>::convert(
value)
.value_or(DefaultValue);
return CesiumGltf::MetadataConversions<int64_t, decltype(value)>::
convert(value)
.value_or(DefaultValue);
},
Value._value);
}
Expand Down
17 changes: 17 additions & 0 deletions Source/CesiumRuntime/Private/CesiumPrimitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ class CesiumPrimitiveData {

std::optional<Cesium3DTilesSelection::BoundingVolume> boundingVolume;

/**
* The factor by which the positions in the glTF primitive is scaled up when
* the Unreal mesh is populated.
*
* We scale up the meshes because Chaos has a degenerate triangle epsilon test
* in `TriangleMeshImplicitObject.cpp` that is almost laughably too eager.
* Perhaps it would be fine if our meshes actually used units of centimeters
* like UE, but they usually use meters instead. With a factor of 1.0, UE will
* consider a right triangle that is slightly less than ~10cm on each side to
* be degenerate.
*
* This value should be a power-of-two so the the scale affects only the
* exponent of coordinate values, not the mantissa, in order to reduce the
* chances of losing precision.
*/
static constexpr double positionScaleFactor = 1024.0;

void destroy();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ int64 UCesiumPropertyArrayBlueprintLibrary::GetInteger64(
return defaultValue;
}
auto value = v[index];
return CesiumGltf::MetadataConversions<int64, decltype(value)>::convert(
value)
.value_or(defaultValue);
return CesiumGltf::MetadataConversions<int64_t, decltype(value)>::
convert(value)
.value_or(defaultValue);
},
array._value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ int64 UCesiumPropertyTablePropertyBlueprintLibrary::GetInteger64(
auto maybeValue = v.get(FeatureID);
if (maybeValue) {
auto value = *maybeValue;
return CesiumGltf::MetadataConversions<int64, decltype(value)>::
return CesiumGltf::MetadataConversions<int64_t, decltype(value)>::
convert(value)
.value_or(DefaultValue);
}
Expand Down
10 changes: 6 additions & 4 deletions Source/CesiumRuntime/Private/Tests/CesiumFeatureIdSet.spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ void FCesiumFeatureIdSetSpec::Define() {
std::array<int64, 3> expected{3, 1, 0};

for (size_t i = 0; i < locations.size(); i++) {
Hit.Location = locations[i];
Hit.Location = locations[i] * CesiumPrimitiveData::positionScaleFactor;
TestEqual(
"FeatureIDFromHit",
UCesiumFeatureIdSetBlueprintLibrary::GetFeatureIDFromHit(
Expand Down Expand Up @@ -511,7 +511,7 @@ void FCesiumFeatureIdSetSpec::Define() {
std::array<int64, 3> expected{0, 3, 0};
for (size_t i = 0; i < locations.size(); i++) {
Hit.FaceIndex = faceIndices[i];
Hit.Location = locations[i];
Hit.Location = locations[i] * CesiumPrimitiveData::positionScaleFactor;
TestEqual(
"FeatureIDFromHit",
UCesiumFeatureIdSetBlueprintLibrary::GetFeatureIDFromHit(
Expand Down Expand Up @@ -542,7 +542,8 @@ void FCesiumFeatureIdSetSpec::Define() {
FHitResult Hit;
Hit.Component = pPrimitiveComponent;
Hit.FaceIndex = 0;
Hit.Location = FVector_NetQuantize(0, -1, 0);
Hit.Location = FVector_NetQuantize(0, -1, 0) *
CesiumPrimitiveData::positionScaleFactor;
TestEqual(
"FeatureIDFromHit",
UCesiumFeatureIdSetBlueprintLibrary::GetFeatureIDFromHit(
Expand All @@ -551,7 +552,8 @@ void FCesiumFeatureIdSetSpec::Define() {
0);

Hit.FaceIndex = 1;
Hit.Location = FVector_NetQuantize(0, -4, 0);
Hit.Location = FVector_NetQuantize(0, -4, 0) *
CesiumPrimitiveData::positionScaleFactor;
TestEqual(
"FeatureIDFromHit",
UCesiumFeatureIdSetBlueprintLibrary::GetFeatureIDFromHit(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ void FCesiumFeatureIdTextureSpec::Define() {
ECesiumFeatureIdTextureStatus::Valid);

FHitResult Hit;
Hit.Location = FVector_NetQuantize::Zero();
Hit.Location = FVector_NetQuantize::Zero() *
CesiumPrimitiveData::positionScaleFactor;
Hit.Component = pPrimitiveComponent;
Hit.FaceIndex = 0;

Expand Down Expand Up @@ -611,7 +612,8 @@ void FCesiumFeatureIdTextureSpec::Define() {
ECesiumFeatureIdTextureStatus::Valid);

FHitResult Hit;
Hit.Location = FVector_NetQuantize(0, -1, 0);
Hit.Location = FVector_NetQuantize(0, -1, 0) *
CesiumPrimitiveData::positionScaleFactor;
Hit.FaceIndex = 0;
Hit.Component = nullptr;

Expand Down Expand Up @@ -671,7 +673,8 @@ void FCesiumFeatureIdTextureSpec::Define() {
ECesiumFeatureIdTextureStatus::Valid);

FHitResult Hit;
Hit.Location = FVector_NetQuantize(0, -1, 0);
Hit.Location = FVector_NetQuantize(0, -1, 0) *
CesiumPrimitiveData::positionScaleFactor;
Hit.FaceIndex = 0;
Hit.Component = pPrimitiveComponent;

Expand Down Expand Up @@ -741,7 +744,7 @@ void FCesiumFeatureIdTextureSpec::Define() {
std::array<int64, 3> expected{3, 1, 0};

for (size_t i = 0; i < locations.size(); i++) {
Hit.Location = locations[i];
Hit.Location = locations[i] * CesiumPrimitiveData::positionScaleFactor;
int64 featureID =
UCesiumFeatureIdTextureBlueprintLibrary::GetFeatureIDFromHit(
featureIDTexture,
Expand Down Expand Up @@ -808,7 +811,7 @@ void FCesiumFeatureIdTextureSpec::Define() {
std::array<int64, 3> expected{3, 1, 0};

for (size_t i = 0; i < locations.size(); i++) {
Hit.Location = locations[i];
Hit.Location = locations[i] * CesiumPrimitiveData::positionScaleFactor;
int64 featureID =
UCesiumFeatureIdTextureBlueprintLibrary::GetFeatureIDFromHit(
featureIDTexture,
Expand Down Expand Up @@ -901,7 +904,7 @@ void FCesiumFeatureIdTextureSpec::Define() {
std::array<int64, 3> expected{3, 1, 2};

for (size_t i = 0; i < locations.size(); i++) {
Hit.Location = locations[i];
Hit.Location = locations[i] * CesiumPrimitiveData::positionScaleFactor;
int64 featureID =
UCesiumFeatureIdTextureBlueprintLibrary::GetFeatureIDFromHit(
featureIDTexture,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ void FCesiumMetadataPickingSpec::Define() {

It("returns false if hit has no valid component", [this]() {
FHitResult Hit;
Hit.Location = FVector_NetQuantize(0, -1, 0);
Hit.Location = FVector_NetQuantize(0, -1, 0) *
CesiumPrimitiveData::positionScaleFactor;
Hit.FaceIndex = 0;
Hit.Component = nullptr;

Expand All @@ -98,7 +99,8 @@ void FCesiumMetadataPickingSpec::Define() {

It("returns false if specified texcoord set does not exist", [this]() {
FHitResult Hit;
Hit.Location = FVector_NetQuantize(0, -1, 0);
Hit.Location = FVector_NetQuantize(0, -1, 0) *
CesiumPrimitiveData::positionScaleFactor;
Hit.FaceIndex = 0;
Hit.Component = pPrimitiveComponent;

Expand All @@ -110,7 +112,8 @@ void FCesiumMetadataPickingSpec::Define() {

It("gets hit for primitive without indices", [this]() {
FHitResult Hit;
Hit.Location = FVector_NetQuantize(0, -1, 0);
Hit.Location = FVector_NetQuantize(0, -1, 0) *
CesiumPrimitiveData::positionScaleFactor;
Hit.FaceIndex = 0;
Hit.Component = pPrimitiveComponent;

Expand All @@ -121,7 +124,8 @@ void FCesiumMetadataPickingSpec::Define() {
TestTrue("UV at point (X)", FMath::IsNearlyEqual(UV[0], 0.0));
TestTrue("UV at point (Y)", FMath::IsNearlyEqual(UV[1], 1.0));

Hit.Location = FVector_NetQuantize(0, -0.5, 0);
Hit.Location = FVector_NetQuantize(0, -0.5, 0) *
CesiumPrimitiveData::positionScaleFactor;
TestTrue(
"found hit",
UCesiumMetadataPickingBlueprintLibrary::FindUVFromHit(Hit, 0, UV));
Expand All @@ -133,7 +137,8 @@ void FCesiumMetadataPickingSpec::Define() {
FMath::IsNearlyEqual(UV[1], 0.5));

Hit.FaceIndex = 1;
Hit.Location = FVector_NetQuantize(0, -4, 0);
Hit.Location = FVector_NetQuantize(0, -4, 0) *
CesiumPrimitiveData::positionScaleFactor;
TestTrue(
"found hit",
UCesiumMetadataPickingBlueprintLibrary::FindUVFromHit(Hit, 0, UV));
Expand All @@ -156,7 +161,8 @@ void FCesiumMetadataPickingSpec::Define() {
static_cast<int32_t>(model.accessors.size() - 1));

FHitResult Hit;
Hit.Location = FVector_NetQuantize(0, -4, 0);
Hit.Location = FVector_NetQuantize(0, -4, 0) *
CesiumPrimitiveData::positionScaleFactor;
Hit.FaceIndex = 0;
Hit.Component = pPrimitiveComponent;

Expand All @@ -168,7 +174,8 @@ void FCesiumMetadataPickingSpec::Define() {
TestTrue("UV at point (X)", FMath::IsNearlyEqual(UV[0], 0.0));
TestTrue("UV at point (Y)", FMath::IsNearlyEqual(UV[1], 1.0));

Hit.Location = FVector_NetQuantize(0, -3.5, 0);
Hit.Location = FVector_NetQuantize(0, -3.5, 0) *
CesiumPrimitiveData::positionScaleFactor;
TestTrue(
"found hit",
UCesiumMetadataPickingBlueprintLibrary::FindUVFromHit(Hit, 0, UV));
Expand All @@ -180,7 +187,8 @@ void FCesiumMetadataPickingSpec::Define() {
FMath::IsNearlyEqual(UV[1], 0.5));

Hit.FaceIndex = 1;
Hit.Location = FVector_NetQuantize(0, -1, 0);
Hit.Location = FVector_NetQuantize(0, -1, 0) *
CesiumPrimitiveData::positionScaleFactor;
TestTrue(
"found hit",
UCesiumMetadataPickingBlueprintLibrary::FindUVFromHit(Hit, 0, UV));
Expand Down Expand Up @@ -778,7 +786,8 @@ void FCesiumMetadataPickingSpec::Define() {
FVector2D(vec2Values[0][0], vec2Values[0][1])};

for (size_t i = 0; i < locations.size(); i++) {
Hit.Location = locations[i];
Hit.Location =
locations[i] * CesiumPrimitiveData::positionScaleFactor;

const auto values = UCesiumMetadataPickingBlueprintLibrary::
GetPropertyTextureValuesFromHit(Hit);
Expand Down Expand Up @@ -861,7 +870,7 @@ void FCesiumMetadataPickingSpec::Define() {
newScalarValues[2],
newScalarValues[0]};
for (size_t i = 0; i < locations.size(); i++) {
Hit.Location = locations[i];
Hit.Location = locations[i] * CesiumPrimitiveData::positionScaleFactor;

const auto values = UCesiumMetadataPickingBlueprintLibrary::
GetPropertyTextureValuesFromHit(Hit, 1);
Expand Down
Loading

0 comments on commit c09e998

Please sign in to comment.