Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Valve 220 texture lock fix #1458

Merged
merged 8 commits into from
Oct 2, 2016

Conversation

ericwa
Copy link
Collaborator

@ericwa ericwa commented Oct 2, 2016

  • Fix for Texture lock broken in Valve 220 format #1454 . I reverted 36e49c4 and now I just bail out at the beginning of ParallelTexCoordSystem::doTransform if lockTexture is false. Texture lock OFF and ON both seem to work now.
  • Tests for texture lock. The testTextureLock_Parallel fails without the fix to ParallelTexCoordSystem.
  • There are no tests yet for the case when texture lock is off There is a basic test of "texture lock off" now. It only tests the case when a face has reset texture alignment before being transfomed.

@ericwa
Copy link
Collaborator Author

ericwa commented Oct 2, 2016

Hm.. just noticed a problem, rotating a brush with texture lock OFF stretches the texture. So I guess ParallelTexCoordSystem::doTransform needs to do some more work if lockTexture is false.

Reduce excessive number of translation test cases in checkTextureLockWithTranslationAnd90DegreeRotations because it was slow
@ericwa
Copy link
Collaborator Author

ericwa commented Oct 2, 2016

All of my tests pass except for the ones testing ParallelTexCoordSystem with texture lock off.

I'm not sure how to fix ParallelTexCoordSystem::doTransform for the case when texture lock is off and the user does a rotation. That's a somewhat niche use case though; everything else seems to be working.

@kduske
Copy link
Collaborator

kduske commented Oct 2, 2016

What is the problem? Why is rotation special?

@ericwa
Copy link
Collaborator Author

ericwa commented Oct 2, 2016

The problem looks like this: https://www.dropbox.com/s/50ayw9lqn1i8mgk/rotate.mov?dl=0
I guess rotation is special because, with translation, you can get away with leaving the texture axes alone. If you don't touch the texture axes, but rotate a face 90 degrees, you get the stretched look seen in the video.

@kduske
Copy link
Collaborator

kduske commented Oct 2, 2016

Is it not possible to compensate for the rotation? It sounds like you need to apply rotation to the texture axes in that case, essentially behaving as if texture lock was in, but undoing the translation?

@kduske
Copy link
Collaborator

kduske commented Oct 2, 2016

Thanks for the video. I think it makes sense that the texture coordinate system must be rotated even if texture lock is off. So that would mean that texture lock only applies to translation and nothing else in Valve 220.

Do you know how other editors handle this?

@ericwa
Copy link
Collaborator Author

ericwa commented Oct 2, 2016

I just checked Sledge, it does what you said: "texture lock off" only applies to translation. Rotation always gets texture lock.

Here is Sledge's texture lock code:
https://github.com/LogicAndTrick/sledge/blob/master/Sledge.DataStructures/MapObjects/Face.cs#L405

I'll see if I can get "texture lock off" only for translation to work.

@kduske
Copy link
Collaborator

kduske commented Oct 2, 2016

Remember that you can very easily separate the translational component from a transformation matrix, as it is stored independently from the rest in the fourth column (or the fourth row?). That way, you can separate them (there should be methods for that already) and apply only the non-translational part to the texture axes.

You may also have to update the stupid angle value somehow. It represents by how much a texture coordinate system has been rotated away from its default position. It's solely used by the UI and it's utterly stupid.

@kduske
Copy link
Collaborator

kduske commented Oct 2, 2016

See methods translationMatrix(const Mat<T,S,S>&) and stripTranslation(const Mat<T,S,S>&) in Mat.h.

…compensate for the translation part of the transformation. Still compensate for the rotation.
@ericwa
Copy link
Collaborator Author

ericwa commented Oct 2, 2016

Ok, using stripTranslation seems to work. The stretching when rotating is fixed.

Only remaining concern I have is, will removing the attribs.xScale() == 0.0f || attribs.yScale() == 0.0f check cause problems? is that just there to avoid an assertion failure later in the method?

… used, which could lead to tests incorrectly passing because the tests were making translations of integer units.
@kduske
Copy link
Collaborator

kduske commented Oct 2, 2016

Those checks are important, because there is a bug elsewhere that sometimes produces 0 scaling factors, which then cause all sorts of havoc.

@ericwa
Copy link
Collaborator Author

ericwa commented Oct 2, 2016

Ok, I just restored those checks. I'm assuming there is no need to update the texture axes in that case, since the texture alignment is going to be nonsense anyway?

@kduske
Copy link
Collaborator

kduske commented Oct 2, 2016

Yes. I think I should add assertions to the setters of those attributes to catch the bug earlier.

Copy link
Collaborator

@kduske kduske left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge and make the requested changes myself. Thanks for your help!

@@ -102,18 +102,14 @@ namespace TrenchBroom {
m_yAxis = rot * m_yAxis;
}

void ParallelTexCoordSystem::doTransform(const Plane3& oldBoundary, const Mat4x4& transformation, BrushFaceAttributes& attribs, bool lockTexture, const Vec3& oldInvariant) {
void ParallelTexCoordSystem::doTransform(const Plane3& oldBoundary, const Mat4x4& origTransformation, BrushFaceAttributes& attribs, bool lockTexture, const Vec3& oldInvariant) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use abbreviated variable names. Also I think it's better to keep translation as the variable name and use a different name below.

return;

// when texture lock is off, don't compensate for the translation part of the transformation
const Mat4x4 transformation = lockTexture ? origTransformation : stripTranslation(origTransformation);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to use a name like actualTransformation or effectiveTransformationhere.

checkTextureLockOffWithTranslation(origFace);
}

TEST(BrushFaceTest, testTextureLock_Paraxial) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the test cases, looks like it was more work than the actual changes ;-)

return false;
}
return true;
}

TEST(TestUtilsTest, testTexCoordsEqual) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good man ;-)

@kduske kduske merged commit 73e6876 into TrenchBroom:release/v2.0.0 Oct 2, 2016
@ericwa
Copy link
Collaborator Author

ericwa commented Oct 2, 2016

Happy to help!

The tests should be useful if any changes / bug fixes need to be made to the texture lock code in the future. They seem to be fairly thorough, e.g. they'll fail if some of the "magic" bits of ParaxialTexCoordSystem are commented out, like this thing

@kduske
Copy link
Collaborator

kduske commented Oct 2, 2016

Yeah, that "magic" stuff is annoying. I wish I understood it better and that the algorithm was easier, but at some point I just gave up and declared it good enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants