@ImporterClass.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /******************************************************************************/
  2. /******************************************************************************/
  3. class ImporterClass
  4. {
  5. enum MODE
  6. {
  7. UPDATE, // reload target from source file
  8. ANIM , // import animations only to target
  9. CLOTH , // import as cloth to target
  10. ADD , // add source to target
  11. };
  12. class Import
  13. {
  14. class MaterialEx : XMaterial
  15. {
  16. Material mtrl;
  17. Image base_0, base_1, detail, macro, reflection, light;
  18. UID base_0_id, base_1_id, detail_id, macro_id, reflection_id, light_id;
  19. void copyTo(EditMaterial &dest, C TimeStamp &time=TimeStamp().getUTC())C;
  20. void check(C Str &path, Str &tex);
  21. void process(C Str &path);
  22. public:
  23. MaterialEx();
  24. };
  25. class ImageEx : Image
  26. {
  27. bool cube;
  28. File raw;
  29. public:
  30. ImageEx();
  31. };
  32. int status; // -1=in progress, 0=fail, 1=ok
  33. bool has_loop, cancel, remember_result, has_color, has_alpha, ignore_anims;
  34. ELM_TYPE type;
  35. MODE mode;
  36. UID elm_id, parent_id;
  37. Str file, force_name;
  38. Mesh mesh;
  39. Skeleton skel;
  40. Memc<XAnimation> anims;
  41. Memc<MaterialEx> mtrls;
  42. Memc<int> part_mtrl_index;
  43. Memc<Str> bone_names;
  44. Memc<ImageEx> images;
  45. File raw;
  46. EditFont edit_font;
  47. Font font;
  48. Str code;
  49. Str nodeName(int i)C;
  50. Str nodeUID (int i)C; // unique string identifying a node !! needs to be the same as 'EditSkeleton.nodeUID' !!
  51. Import& set(C UID &elm_id, C UID &parent_id, C Str &file, MODE mode, ELM_TYPE type, C Str &force_name, bool remember_result);
  52. static bool ApplyVolume(ptr data, int size, flt vol);
  53. bool import(); // !! this is called on a secondary thread !!
  54. public:
  55. Import();
  56. };
  57. static void ImportDo(Import &import, ImporterClass &importer, int thread_index);
  58. class ImportElm
  59. {
  60. UID elm_id;
  61. bool remember_result;
  62. void set(C UID &elm_id, bool remember_result=false);
  63. };
  64. Memx<Import> imports ; // elements that are being imported right now, Memx due to const mem addr for processing on threads
  65. Memc<ImportElm> import_queue; // elements to import
  66. Map<UID, Edit::RELOAD_RESULT> import_results; // doesn't need to be thread-safe
  67. Memc<UID> texs; // this is a copy of 'Project.texs' that includes textures currently being imported in 'threads'
  68. Threads threads;
  69. SyncLock lock;
  70. Menu import_menu;
  71. Memc<Str> import_files;
  72. UID import_target;
  73. MODE import_mode;
  74. ~ImporterClass(); // delete threads before other members
  75. // get
  76. bool busy()C;
  77. // manage
  78. static void ImportFull (ImporterClass &ic); // import normally
  79. static void ImportReplace(ImporterClass &ic);
  80. static void ImportAnim (ImporterClass &ic);
  81. static void ImportCloth (ImporterClass &ic);
  82. static void ImportAdd (ImporterClass &ic);
  83. void create();
  84. // operations
  85. void stop();
  86. void importNew(C UID &elm_id, C UID &parent_id, C Str &file, MODE mode, ELM_TYPE type, C Str &force_name=S, bool remember_result=false);
  87. void importSpecialFile(C Str &file);
  88. void importSpecialDir(C Str &path);
  89. void importSpecial(MODE mode);
  90. void import(Elm &target, Memc<Str> &files, C Vec2 &screen_pos);
  91. bool includeTex(C UID &tex_id);
  92. void excludeTex(C UID &tex_id);
  93. void clearProj();
  94. void opened(Project &proj, ElmNode &node);
  95. Import* findImport(C UID &elm_id);
  96. ImportElm* findImportQueue(C UID &elm_id);
  97. bool inQueue(C UID &elm_id);
  98. void cancelImports(C MemPtr<UID> &sorted_elm_ids);
  99. void cancel(C MemPtr<UID> &elm_ids);
  100. void getResult(C MemPtr<UID> &elms, MemPtr<Edit::IDParam<Edit::RELOAD_RESULT> > results);
  101. void clearImportResults(C MemPtr<UID> &elm_ids);
  102. void forgetResult(C MemPtr<UID> &elm_ids);
  103. void reload(C MemPtr<UID> &elm_ids, bool remember_result);
  104. void investigate(Elm &elm);
  105. void investigate(ElmNode &node);
  106. void investigate(Memc<UID> &elm_ids);
  107. void processUpdate(Import &import);
  108. void processCloth(Import &import);
  109. void processAnim(Import &import);
  110. void processAdd(Import &import);
  111. // update
  112. void update();
  113. public:
  114. ImporterClass();
  115. };
  116. /******************************************************************************/
  117. /******************************************************************************/
  118. extern ImporterClass Importer;
  119. /******************************************************************************/