args.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. let args_use: bool = false;
  2. let args_asset_path: string = "";
  3. let args_background: bool = false;
  4. let args_export_textures: bool = false;
  5. let args_export_textures_type: string = "";
  6. let args_export_textures_preset: string = "";
  7. let args_export_textures_path: string = "";
  8. let args_reimport_mesh: bool = false;
  9. let args_export_mesh: bool = false;
  10. let args_export_mesh_path: string = "";
  11. let args_export_material: bool = false;
  12. let args_export_material_path: string = "";
  13. function args_parse() {
  14. if (iron_get_arg_count() > 1) {
  15. args_use = true;
  16. let i: i32 = 0;
  17. while (i < iron_get_arg_count()) {
  18. // Process each arg
  19. let current_arg: string = iron_get_arg(i);
  20. if (path_is_project(current_arg)) {
  21. project_filepath = current_arg;
  22. }
  23. else if (current_arg == "--b" || current_arg == "--background") {
  24. args_background = true;
  25. }
  26. else if (path_is_texture(current_arg)) {
  27. args_asset_path = current_arg;
  28. }
  29. else if (current_arg == "--export-textures" && (i + 3) <= iron_get_arg_count()) {
  30. args_export_textures = true;
  31. ++i;
  32. args_export_textures_type = iron_get_arg(i);
  33. ++i;
  34. args_export_textures_preset = iron_get_arg(i);
  35. ++i;
  36. args_export_textures_path = iron_get_arg(i);
  37. }
  38. else if (current_arg == "--reload-mesh") {
  39. args_reimport_mesh = true;
  40. }
  41. else if (current_arg == "--export-mesh" && (i + 1) <= iron_get_arg_count()) {
  42. args_export_mesh = true;
  43. ++i;
  44. args_export_mesh_path = iron_get_arg(i);
  45. }
  46. else if (path_is_mesh(current_arg) || (i > 1 && !starts_with(current_arg, "-") && path_is_folder(current_arg))) {
  47. args_asset_path = current_arg;
  48. }
  49. else if (current_arg == "--export-material" && (i + 1) <= iron_get_arg_count()) {
  50. args_export_material = true;
  51. ++i;
  52. args_export_material_path = iron_get_arg(i);
  53. }
  54. ++i;
  55. }
  56. }
  57. }
  58. function args_run() {
  59. if (args_use) {
  60. sys_notify_on_init(function () {
  61. if (project_filepath != "") {
  62. import_arm_run_project(project_filepath);
  63. }
  64. else if (args_asset_path != "") {
  65. import_asset_run(args_asset_path, -1, -1, false);
  66. if (path_is_texture(args_asset_path)) {
  67. ui_base_show_2d_view(view_2d_type_t.ASSET);
  68. }
  69. }
  70. else if (args_reimport_mesh) {
  71. project_reimport_mesh();
  72. }
  73. if (args_export_textures) {
  74. if (args_export_textures_type == "png" ||
  75. args_export_textures_type == "jpg" ||
  76. args_export_textures_type == "exr16" ||
  77. args_export_textures_type == "exr32") {
  78. if (path_is_folder(args_export_textures_path)) {
  79. // Applying the correct format type from args
  80. if (args_export_textures_type == "png") {
  81. base_bits_handle.position = texture_bits_t.BITS8;
  82. context_raw.format_type = texture_ldr_format_t.PNG;
  83. }
  84. else if (args_export_textures_type == "jpg") {
  85. base_bits_handle.position = texture_bits_t.BITS8;
  86. context_raw.format_type = texture_ldr_format_t.JPG;
  87. }
  88. else if (args_export_textures_type == "exr16") {
  89. base_bits_handle.position = texture_bits_t.BITS16;
  90. }
  91. else if (args_export_textures_type == "exr32") {
  92. base_bits_handle.position = texture_bits_t.BITS32;
  93. }
  94. context_raw.layers_export = export_mode_t.VISIBLE;
  95. // Get export preset and apply the correct one from args
  96. box_export_files = file_read_directory(path_data() + path_sep + "export_presets");
  97. for (let i: i32 = 0; i < box_export_files.length; ++i) {
  98. let s: string = box_export_files[i];
  99. box_export_files[i] = substring(s, 0, s.length - 5); // Strip .json
  100. }
  101. let file: string = "export_presets/" + box_export_files[0] + ".json";
  102. for (let i: i32 = 0; i < box_export_files.length; ++i) {
  103. let f: string = box_export_files[i];
  104. if (f == args_export_textures_preset) {
  105. file = "export_presets/" + box_export_files[array_index_of(box_export_files, f)] + ".json";
  106. }
  107. }
  108. let blob: buffer_t = data_get_blob(file);
  109. box_export_preset = json_parse(sys_buffer_to_string(blob));
  110. data_delete_blob("export_presets/" + file);
  111. // Export queue
  112. sys_notify_on_init(function () {
  113. export_texture_run(args_export_textures_path);
  114. });
  115. }
  116. else {
  117. iron_log(tr("Invalid export directory"));
  118. }
  119. }
  120. else {
  121. iron_log(tr("Invalid texture type"));
  122. }
  123. }
  124. else if (args_export_mesh) {
  125. if (path_is_folder(args_export_mesh_path)) {
  126. let f: string = ui_files_filename;
  127. if (f == "") {
  128. f = tr("untitled");
  129. }
  130. export_mesh_run(args_export_mesh_path + path_sep + f, null, false);
  131. }
  132. else {
  133. iron_log(tr("Invalid export directory"));
  134. }
  135. }
  136. else if (args_export_material) {
  137. context_raw.write_icon_on_export = true;
  138. export_arm_run_material(args_export_material_path);
  139. }
  140. if (args_background) {
  141. iron_stop();
  142. }
  143. });
  144. }
  145. }