KHR_texture_transform.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Newtonsoft.Json;
  2. using Siccity.GLTFUtility.Converters;
  3. using UnityEngine;
  4. using UnityEngine.Scripting;
  5. namespace Siccity.GLTFUtility {
  6. /// <summary>
  7. /// KHR_texture_transform textureInfo extension
  8. /// glTF extension that enables shifting and scaling UV coordinates on a per-texture basis
  9. /// see: https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_transform/schema/KHR_texture_transform.textureInfo.schema.json
  10. /// </summary>
  11. [Preserve] public class KHR_texture_transform : GLTFMaterial.TextureInfo.IExtension {
  12. /// <summary>
  13. /// The offset of the UV coordinate origin as a factor of the texture dimensions.
  14. /// </summary>
  15. [JsonConverter(typeof(Vector2Converter))] public Vector2 offset = Vector2.zero;
  16. /// <summary>
  17. /// Rotate the UVs by this many radians counter-clockwise around the origin.
  18. /// </summary>
  19. public float rotation = 0.0f;
  20. /// <summary>
  21. /// The scale factor applied to the components of the UV coordinates.
  22. /// </summary>
  23. [JsonConverter(typeof(Vector2Converter))] public Vector2 scale = Vector2.one;
  24. /// <summary>
  25. /// Overrides the textureInfo texCoord value if supplied, and if this extension is supported.
  26. /// </summary>
  27. public int texCoord = 0;
  28. public void Apply(GLTFMaterial.TextureInfo texInfo, Material material, string textureSamplerName) {
  29. material.SetTextureOffset(textureSamplerName, offset);
  30. // TODO rotation
  31. material.SetTextureScale(textureSamplerName, scale);
  32. // TODO texCoord
  33. }
  34. }
  35. }