G2Pavon / goldsrcmap

A Python library for creating, editing and writing GoldSrc .map files
https://github.com/G2Pavon/goldsrcmap/wiki
GNU General Public License v3.0
5 stars 0 forks source link

Improve Texture class #5

Open G2Pavon opened 8 months ago

G2Pavon commented 8 months ago
G2Pavon commented 8 months ago

Texture lock explained by Captain P:

One way to look at texture projection is that you have a texture plane, and you're projecting vertices onto that plane to get UV coordinates. Here is how I apply 'texture fit' when transforming a brush: https://github.com/pwitvoet/mess/blob/master/MESS/Macros/MappingExtensions.cs#L61 I first project a vertex onto the texture plane to get the original UV coordinates (not normalized, so texture size doesn't matter), then I transform the vertices and rotate/scale the UV axis, and then I project the same (now transformed) vertex again onto the now rotated and scaled texture plane to get new UV coordinates. I then use the difference between the old and new UV coordinates to update the UV offset.