Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

NeededCoordinateSpace.cs 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Linq;
  3. namespace UnityEditor.ShaderGraph.Internal
  4. {
  5. [Flags]
  6. public enum NeededCoordinateSpace
  7. {
  8. None = 0,
  9. Object = 1 << 0,
  10. View = 1 << 1,
  11. World = 1 << 2,
  12. Tangent = 1 << 3,
  13. AbsoluteWorld = 1 << 4,
  14. Screen = 1 << 5
  15. }
  16. public enum CoordinateSpace
  17. {
  18. Object,
  19. View,
  20. World,
  21. Tangent,
  22. AbsoluteWorld,
  23. Screen
  24. }
  25. public enum InterpolatorType
  26. {
  27. Normal,
  28. BiTangent,
  29. Tangent,
  30. ViewDirection,
  31. Position,
  32. PositionPredisplacement,
  33. }
  34. public static class CoordinateSpaceExtensions
  35. {
  36. static int s_SpaceCount = Enum.GetValues(typeof(CoordinateSpace)).Length;
  37. static int s_InterpolatorCount = Enum.GetValues(typeof(InterpolatorType)).Length;
  38. static string[] s_VariableNames = new string[s_SpaceCount * s_InterpolatorCount];
  39. public static string ToVariableName(this CoordinateSpace space, InterpolatorType type)
  40. {
  41. var index = (int)space + (int)type * s_SpaceCount;
  42. if (string.IsNullOrEmpty(s_VariableNames[index]))
  43. s_VariableNames[index] = string.Format("{0}Space{1}", space, type);
  44. return s_VariableNames[index];
  45. }
  46. public static NeededCoordinateSpace ToNeededCoordinateSpace(this CoordinateSpace space)
  47. {
  48. switch (space)
  49. {
  50. case CoordinateSpace.Object:
  51. return NeededCoordinateSpace.Object;
  52. case CoordinateSpace.View:
  53. return NeededCoordinateSpace.View;
  54. case CoordinateSpace.World:
  55. return NeededCoordinateSpace.World;
  56. case CoordinateSpace.Tangent:
  57. return NeededCoordinateSpace.Tangent;
  58. case CoordinateSpace.AbsoluteWorld:
  59. return NeededCoordinateSpace.AbsoluteWorld;
  60. case CoordinateSpace.Screen:
  61. return NeededCoordinateSpace.Screen;
  62. default:
  63. throw new ArgumentOutOfRangeException(nameof(space), space, null);
  64. }
  65. }
  66. public static CoordinateSpace ToCoordinateSpace(this NeededCoordinateSpace space)
  67. {
  68. switch (space)
  69. {
  70. case NeededCoordinateSpace.Object:
  71. return CoordinateSpace.Object;
  72. case NeededCoordinateSpace.View:
  73. return CoordinateSpace.View;
  74. case NeededCoordinateSpace.World:
  75. return CoordinateSpace.World;
  76. case NeededCoordinateSpace.Tangent:
  77. return CoordinateSpace.Tangent;
  78. case NeededCoordinateSpace.AbsoluteWorld:
  79. return CoordinateSpace.AbsoluteWorld;
  80. case NeededCoordinateSpace.Screen:
  81. return CoordinateSpace.Screen;
  82. default:
  83. throw new ArgumentOutOfRangeException(nameof(space), space, null);
  84. }
  85. }
  86. }
  87. }