Skip to content

Commit

Permalink
Add scale to matrix instead of translation
Browse files Browse the repository at this point in the history
  • Loading branch information
j9liu committed Aug 15, 2024
1 parent 5130b8b commit aacdaba
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Source/CesiumRuntime/Private/CesiumGltfComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit aacdaba

Please sign in to comment.