@@ -83,6 +83,7 @@ namespace {
83
83
using TMeshVector2 = FVector2f;
84
84
using TMeshVector3 = FVector3f;
85
85
using TMeshVector4 = FVector4f;
86
+ constexpr double scaleFactor = 1024.0 ;
86
87
} // namespace
87
88
88
89
static uint32_t nextMaterialId = 0 ;
@@ -1309,6 +1310,9 @@ static void loadPrimitive(
1309
1310
maxPosition = glm::dvec3 (max[0 ], max[1 ], max[2 ]);
1310
1311
}
1311
1312
1313
+ minPosition *= scaleFactor;
1314
+ maxPosition *= scaleFactor;
1315
+
1312
1316
primitiveResult.dimensions =
1313
1317
glm::vec3 (transform * glm::dvec4 (maxPosition - minPosition, 0 ));
1314
1318
@@ -1370,9 +1374,9 @@ static void loadPrimitive(
1370
1374
FStaticMeshBuildVertex& vertex = StaticMeshBuildVertices[i];
1371
1375
uint32 vertexIndex = indices[i];
1372
1376
const TMeshVector3& pos = positionView[vertexIndex];
1373
- vertex.Position .X = pos.X ;
1374
- vertex.Position .Y = -pos.Y ;
1375
- vertex.Position .Z = pos.Z ;
1377
+ vertex.Position .X = pos.X * scaleFactor ;
1378
+ vertex.Position .Y = -pos.Y * scaleFactor ;
1379
+ vertex.Position .Z = pos.Z * scaleFactor ;
1376
1380
vertex.UVs [0 ] = TMeshVector2 (0 .0f , 0 .0f );
1377
1381
vertex.UVs [2 ] = TMeshVector2 (0 .0f , 0 .0f );
1378
1382
RenderData->Bounds .SphereRadius = FMath::Max (
@@ -1384,9 +1388,9 @@ static void loadPrimitive(
1384
1388
for (int i = 0 ; i < StaticMeshBuildVertices.Num (); ++i) {
1385
1389
FStaticMeshBuildVertex& vertex = StaticMeshBuildVertices[i];
1386
1390
const TMeshVector3& pos = positionView[i];
1387
- vertex.Position .X = pos.X ;
1388
- vertex.Position .Y = -pos.Y ;
1389
- vertex.Position .Z = pos.Z ;
1391
+ vertex.Position .X = pos.X * scaleFactor ;
1392
+ vertex.Position .Y = -pos.Y * scaleFactor ;
1393
+ vertex.Position .Z = pos.Z * scaleFactor ;
1390
1394
vertex.UVs [0 ] = TMeshVector2 (0 .0f , 0 .0f );
1391
1395
vertex.UVs [2 ] = TMeshVector2 (0 .0f , 0 .0f );
1392
1396
RenderData->Bounds .SphereRadius = FMath::Max (
@@ -1669,7 +1673,14 @@ static void loadPrimitive(
1669
1673
primitiveResult.pMaterial = &material;
1670
1674
primitiveResult.pCollisionMesh = nullptr ;
1671
1675
1672
- primitiveResult.transform = transform * yInvertMatrix;
1676
+ double scale = 1.0 / scaleFactor;
1677
+ glm::dmat4 scaleMatrix = glm::dmat4 (
1678
+ glm::dvec4 (scale, 0.0 , 0.0 , 0.0 ),
1679
+ glm::dvec4 (0.0 , scale, 0.0 , 0.0 ),
1680
+ glm::dvec4 (0.0 , 0.0 , scale, 0.0 ),
1681
+ glm::dvec4 (0.0 , 0.0 , 0.0 , 1.0 ));
1682
+
1683
+ primitiveResult.transform = transform * yInvertMatrix * scaleMatrix;
1673
1684
1674
1685
if (primitive.mode != MeshPrimitive::Mode::POINTS &&
1675
1686
options.pMeshOptions ->pNodeOptions ->pModelOptions ->createPhysicsMeshes ) {
@@ -3834,6 +3845,14 @@ BuildChaosTriangleMeshes(
3834
3845
Chaos::TParticles<Chaos::FRealSingle, 3 > vertices;
3835
3846
vertices.AddParticles (vertexCount);
3836
3847
for (int32 i = 0 ; i < vertexCount; ++i) {
3848
+ // Scale up the collision meshes because Unreal has a degenerate triangle
3849
+ // epsilon test in `TriangleMeshImplicitObject.cpp` that is almost laughably
3850
+ // too eager. Perhaps it would be fine if our meshes actually used units of
3851
+ // centimeters like UE, but they usually use meters instead. UE considering
3852
+ // a triangle that is ~10cm on each side to be degenerate is... infuriating.
3853
+ //
3854
+ // We scale up the collision meshes by a power-of-two factor so that only
3855
+ // the exponent portion of the floating point number is affected.
3837
3856
vertices.X (i) = vertexData[i].Position ;
3838
3857
}
3839
3858
@@ -3849,13 +3868,15 @@ BuildChaosTriangleMeshes(
3849
3868
int32 vIndex1 = indices[index0];
3850
3869
int32 vIndex2 = indices[index0 + 2 ];
3851
3870
3852
- if (!isTriangleDegenerate (
3853
- vertices.X (vIndex0),
3854
- vertices.X (vIndex1),
3855
- vertices.X (vIndex2))) {
3856
- triangles.Add (Chaos::TVector<int32, 3 >(vIndex0, vIndex1, vIndex2));
3857
- faceRemap.Add (i);
3858
- }
3871
+ // if (!isTriangleDegenerate(
3872
+ // vertices.X(vIndex0),
3873
+ // vertices.X(vIndex1),
3874
+ // vertices.X(vIndex2))) {
3875
+ triangles.Add (Chaos::TVector<int32, 3 >(vIndex0, vIndex1, vIndex2));
3876
+ faceRemap.Add (i);
3877
+ // } else {
3878
+ // UE_LOG(LogCesium, Warning, TEXT("Degenerate"));
3879
+ // }
3859
3880
}
3860
3881
3861
3882
TUniquePtr<TArray<int32>> pFaceRemap = MakeUnique<TArray<int32>>(faceRemap);
0 commit comments