From aacdabaeb6a9126e5207d429080d084ee6c0582d Mon Sep 17 00:00:00 2001 From: Janine Liu Date: Thu, 15 Aug 2024 15:53:16 -0400 Subject: [PATCH] Add scale to matrix instead of translation --- .../CesiumRuntime/Private/CesiumGltfComponent.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Source/CesiumRuntime/Private/CesiumGltfComponent.cpp b/Source/CesiumRuntime/Private/CesiumGltfComponent.cpp index 2d8b29b49..f064a35cc 100644 --- a/Source/CesiumRuntime/Private/CesiumGltfComponent.cpp +++ b/Source/CesiumRuntime/Private/CesiumGltfComponent.cpp @@ -1937,9 +1937,8 @@ static void loadInstancingData( if (translationAccessor.status() == AccessorViewStatus::Valid) { for (int64_t i = 0; i < count; ++i) { glm::dvec3 translation(translationAccessor[i]); - instanceTransforms[i] = glm::translate( - instanceTransforms[i], - translation * CesiumPrimitiveData::positionScaleFactor); + instanceTransforms[i] = + glm::translate(instanceTransforms[i], translation); } } } else { @@ -1983,9 +1982,16 @@ static void loadInstancingData( UE_LOG(LogCesium, Warning, TEXT("Invalid accessor for instance scales")); } result.InstanceTransforms.resize(count); + + double scale = 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)); for (int64_t i = 0; i < count; ++i) { glm::dmat4 unrealMat = - yInvertMatrix * instanceTransforms[i] * yInvertMatrix; + scaleMatrix * yInvertMatrix * instanceTransforms[i] * yInvertMatrix; auto unrealFMatrix = VecMath::createMatrix(unrealMat); result.InstanceTransforms[i].SetFromMatrix(unrealFMatrix); }