diff --git a/radiant/ui/surfaceinspector/SurfaceInspector.cpp b/radiant/ui/surfaceinspector/SurfaceInspector.cpp index b0d571f90b..e7fec1e469 100644 --- a/radiant/ui/surfaceinspector/SurfaceInspector.cpp +++ b/radiant/ui/surfaceinspector/SurfaceInspector.cpp @@ -627,17 +627,31 @@ void SurfaceInspector::fitTexture(Axis axis) if (repeatX > 0.0 && repeatY > 0.0) { - // User-specified fit values must always be >0, but we use -1 internally - // to signal not to fit on a particular axis. - GlobalCommandSystem().executeCommand("FitTexture", - (axis == Axis::Y ? -1 : repeatX), - (axis == Axis::X ? -1 : repeatY)); + GlobalCommandSystem().executeCommand("FitTexture", repeatX, repeatY); } else { // Invalid repeatX && repeatY values wxutil::Messagebox::ShowError(_("Both fit values must be > 0.")); + return; } + + // If only fitting on a single axis, propagate the scale factor for the + // fitted axis to the non-fitted axis, which should preserve the texture + // aspect ratio. + if (axis != Axis::BOTH) + { + GlobalSelectionSystem().foreachFace( + [&](IFace& face) { + ShiftScaleRotation texdef = face.getShiftScaleRotation(); + if (axis == Axis::X) + texdef.scale[1] = texdef.scale[0]; + else + texdef.scale[0] = texdef.scale[1]; + face.setShiftScaleRotation(texdef); + } + ); + } } void SurfaceInspector::onFit(Axis axis) diff --git a/radiantcore/brush/TextureProjection.cpp b/radiantcore/brush/TextureProjection.cpp index e38b0a1afe..fe7e9beeff 100644 --- a/radiantcore/brush/TextureProjection.cpp +++ b/radiantcore/brush/TextureProjection.cpp @@ -201,12 +201,8 @@ void TextureProjection::fitTexture(std::size_t width, std::size_t height, bounds.extents.z() = 1; // the bounds of a perfectly fitted texture transform - AABB perfect(Vector3(s_repeat > 0 ? s_repeat * 0.5 : bounds.origin.x(), - t_repeat > 0 ? t_repeat * 0.5 : bounds.origin.y(), - 0), - Vector3(s_repeat > 0 ? s_repeat * 0.5 : bounds.extents.x(), - t_repeat > 0 ? t_repeat * 0.5 : bounds.extents.y(), - 1)); + AABB perfect(Vector3(s_repeat * 0.5, t_repeat * 0.5, 0), + Vector3(s_repeat * 0.5, t_repeat * 0.5, 1)); // the difference between the current texture transform and the perfectly fitted transform Matrix4 diffMatrix = Matrix4::getTranslation(bounds.origin - perfect.origin);