Path.hx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package arm.util;
  2. using StringTools;
  3. class Path {
  4. public static function toRelative(from:String, to:String):String {
  5. from = haxe.io.Path.normalize(from);
  6. to = haxe.io.Path.normalize(to);
  7. var a = from.split("/");
  8. var b = to.split("/");
  9. while (a[0] == b[0]) {
  10. a.shift();
  11. b.shift();
  12. if (a.length == 0 || b.length == 0) break;
  13. }
  14. var base = "";
  15. for (i in 0...a.length - 1) base += "../";
  16. base += b.join("/");
  17. return haxe.io.Path.normalize(base);
  18. }
  19. public static function baseDir(path:String):String {
  20. path = haxe.io.Path.normalize(path);
  21. var base = path.substr(0, path.lastIndexOf("/") + 1);
  22. #if krom_windows
  23. base = base.substr(0, 2) + "\\" + base.substr(3);
  24. #end
  25. return base;
  26. }
  27. public static function checkMeshFormat(path:String):Bool {
  28. var p = path.toLowerCase();
  29. return p.endsWith(".obj") ||
  30. p.endsWith(".fbx") ||
  31. p.endsWith(".blend");
  32. }
  33. public static function checkTextureFormat(path:String):Bool {
  34. var p = path.toLowerCase();
  35. return p.endsWith(".jpg") ||
  36. p.endsWith(".png") ||
  37. p.endsWith(".tga") ||
  38. p.endsWith(".hdr");
  39. }
  40. public static function checkFontFormat(path:String):Bool {
  41. var p = path.toLowerCase();
  42. return p.endsWith(".ttf");
  43. }
  44. public static function checkProjectFormat(path:String):Bool {
  45. var p = path.toLowerCase();
  46. return p.endsWith(".arm");
  47. }
  48. public static function checkBaseTex(p:String):Bool {
  49. return p.endsWith("_albedo") ||
  50. p.endsWith("_alb") ||
  51. p.endsWith("_basecol") ||
  52. p.endsWith("_basecolor") ||
  53. p.endsWith("_diffuse") ||
  54. p.endsWith("_diff") ||
  55. p.endsWith("_base") ||
  56. p.endsWith("_bc") ||
  57. p.endsWith("_d") ||
  58. p.endsWith("_color") ||
  59. p.endsWith("_col");
  60. }
  61. public static function checkOpacTex(p:String):Bool {
  62. return p.endsWith("_opac") ||
  63. p.endsWith("_alpha") ||
  64. p.endsWith("_opacity");
  65. }
  66. public static function checkNorTex(p:String):Bool {
  67. return p.endsWith("_normal") ||
  68. p.endsWith("_nor") ||
  69. p.endsWith("_n") ||
  70. p.endsWith("_nrm");
  71. }
  72. public static function checkOccTex(p:String):Bool {
  73. return p.endsWith("_ao") ||
  74. p.endsWith("_occlusion") ||
  75. p.endsWith("_o") ||
  76. p.endsWith("_occ");
  77. }
  78. public static function checkRoughTex(p:String):Bool {
  79. return p.endsWith("_roughness") ||
  80. p.endsWith("_roug") ||
  81. p.endsWith("_r") ||
  82. p.endsWith("_rough") ||
  83. p.endsWith("_rgh");
  84. }
  85. public static function checkMetTex(p:String):Bool {
  86. return p.endsWith("_metallic") ||
  87. p.endsWith("_metal") ||
  88. p.endsWith("_metalness") ||
  89. p.endsWith("_m") ||
  90. p.endsWith("_met");
  91. }
  92. public static function checkDispTex(p:String):Bool {
  93. return p.endsWith("_displacement") ||
  94. p.endsWith("_height") ||
  95. p.endsWith("_h") ||
  96. p.endsWith("_disp");
  97. }
  98. }