assetImporter.h 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  1. #pragma once
  2. #include "assets/assetPtr.h"
  3. #include "assets/assetManager.h"
  4. #include "module/moduleManager.h"
  5. #include "util/settings.h"
  6. #include "gui/controls/guiTreeViewCtrl.h"
  7. /// <summary>
  8. /// AssetImportConfig is a SimObject derived object intended to act as a container for all the necessary configuration data when running the Asset Importer.
  9. /// It dictates if and how any given asset type will be processed when running an import action. This is because the Asset Importer utilizes a lot of informed logic
  10. /// to try and automate as much of the import process as possible. In theory, you would run the import on a given file, and based on your config the importer will do
  11. /// everything from importing the designated file, as well as finding and importing any associated files such as images or materials, and prepping the objects at time
  12. /// of import to avoid as much manual post-processing as possible.
  13. /// </summary>
  14. class AssetImportConfig : public SimObject
  15. {
  16. typedef SimObject Parent;
  17. //General Settings
  18. public:
  19. /// <summary>
  20. /// Duplicate Asset Auto-Resolution Action. Options are None, AutoPrune, AutoRename
  21. /// </summary>
  22. String DuplicateAutoResolution;
  23. /// <summary>
  24. /// Indicates if warnings should be treated as errors.
  25. /// </summary>
  26. bool WarningsAsErrors;
  27. /// <summary>
  28. /// Indicates if importing should be prevented from completing if any errors are detected at all
  29. /// </summary>
  30. bool PreventImportWithErrors;
  31. /// <summary>
  32. /// Should the importer automatically prompt to find missing files if they are not detected automatically by the importer
  33. /// </summary>
  34. bool AutomaticallyPromptMissingFiles;
  35. //
  36. /// <summary>
  37. /// Should the importer add the folder name as a prefix to the assetName. Helps prevent name collisions.
  38. /// </summary>
  39. bool AddDirectoryPrefixToAssetName;
  40. //
  41. //
  42. //Mesh Settings
  43. /// <summary>
  44. /// Indicates if this config supports importing meshes
  45. /// </summary>
  46. bool ImportMesh;
  47. /// <summary>
  48. /// When importing a shape, this indicates if it should automatically add a standard suffix onto the name
  49. /// </summary>
  50. bool AlwaysAddShapeSuffix;
  51. /// <summary>
  52. /// If AlwaysAddShapeSuffix is on, this is the suffix to be added
  53. /// </summary>
  54. String AddedShapeSuffix;
  55. /// <summary>
  56. /// Indicates if this config should override the per-format sis files with the config's specific settings
  57. /// </summary>
  58. bool UseManualShapeConfigRules;
  59. /// <summary>
  60. /// Indicates if the up axis in the model file should be overridden
  61. /// </summary>
  62. bool DoUpAxisOverride;
  63. /// <summary>
  64. /// If overriding, what axis should be used as up. Options are X_AXIS, Y_AXIS, Z_AXIS
  65. /// </summary>
  66. String UpAxisOverride;
  67. /// <summary>
  68. /// Indicates if the scale in the model file should be overridden
  69. /// </summary>
  70. bool DoScaleOverride;
  71. /// <summary>
  72. /// If overriding, what scale should be used
  73. /// </summary>
  74. F32 ScaleOverride;
  75. /// <summary>
  76. /// Indicates if scale of nodes should be ignored
  77. /// </summary>
  78. bool IgnoreNodeScale;
  79. /// <summary>
  80. /// Indicates if the center of the model file should be automatically recentered
  81. /// </summary>
  82. bool AdjustCenter;
  83. /// <summary>
  84. /// Indicates if the floor height of the model file should be automatically zero'd
  85. /// </summary>
  86. bool AdjustFloor;
  87. /// <summary>
  88. /// Indicates if submeshes should be collapsed down into a single main mesh
  89. /// </summary>
  90. bool CollapseSubmeshes;
  91. /// <summary>
  92. /// Indicates what LOD mode the model file should utilize to process out LODs. Options are TrailingNumber, DetectDTS, SingleSize
  93. /// </summary>
  94. String LODType;
  95. //ImportAssetConfigSettingsList.addNewConfigSetting("TrailingNumber", "Trailing Number", "float", "", "2", "", "Mesh");
  96. /// <summary>
  97. /// A list of what nodes should be guaranteed to be imported if found in the model file. Separated by either , or ;
  98. /// </summary>
  99. String AlwaysImportedNodes;
  100. /// <summary>
  101. /// what lod value to use if all submeshes are set to the same detail level
  102. /// </summary>
  103. S32 singleDetailSize;
  104. /// <summary>
  105. /// A list of what nodes should be guaranteed to not be imported if found in the model file. Separated by either , or ;
  106. /// </summary>
  107. String AlwaysIgnoreNodes;
  108. /// <summary>
  109. /// A list of what mesh objects should be guaranteed to be imported if found in the model file. Separated by either , or ;
  110. /// </summary>
  111. String AlwaysImportMeshes;
  112. /// <summary>
  113. /// A list of what mesh objects should be guaranteed to not be imported if found in the model file. Separated by either , or ;
  114. /// </summary>
  115. String AlwaysIgnoreMeshes;
  116. //Assimp/Collada params
  117. /// <summary>
  118. /// Flag to indicate the shape loader should convert to a left-handed coordinate system
  119. /// </summary>
  120. bool convertLeftHanded;
  121. /// <summary>
  122. /// Should the shape loader calculate tangent space values
  123. /// </summary>
  124. bool calcTangentSpace;
  125. /// <summary>
  126. /// Should the shape loader automatically prune redundant/duplicate materials
  127. /// </summary>
  128. bool removeRedundantMats;
  129. /// <summary>
  130. /// Should the shape loader auto-generate UV Coordinates for the mesh.
  131. /// </summary>
  132. bool genUVCoords;
  133. /// <summary>
  134. /// Should the UV coordinates be transformed.
  135. /// </summary>
  136. bool TransformUVs;
  137. /// <summary>
  138. /// Should the UV coordinates be flipped
  139. /// </summary>
  140. bool flipUVCoords;
  141. /// <summary>
  142. /// Should the shape loader automatically look for instanced submeshes in the model file
  143. /// </summary>
  144. bool findInstances;
  145. /// <summary>
  146. /// Should the shape loader limit the bone weights
  147. /// </summary>
  148. bool limitBoneWeights;
  149. /// <summary>
  150. /// Should the shape loader automatically merge identical/duplicate verts
  151. /// </summary>
  152. bool JoinIdenticalVerts;
  153. /// <summary>
  154. /// Should the shape loader reverse the winding order of the mesh's face indicies
  155. /// </summary>
  156. bool reverseWindingOrder;
  157. /// <summary>
  158. /// Should the normals on the model be inverted
  159. /// </summary>
  160. bool invertNormals;
  161. //
  162. //
  163. //Materials
  164. /// <summary>
  165. /// Does this config allow for importing of materials
  166. /// </summary>
  167. bool ImportMaterials;
  168. /// <summary>
  169. /// When importing a material, should it automatically attempt to merge Roughness, AO and Metalness maps into a single, composited PBR Configuration map
  170. /// </summary>
  171. bool CreateORMConfig;
  172. /// <summary>
  173. /// When creating a material on import, this indicates if it should automatically add a standard suffix onto the name
  174. /// </summary>
  175. bool AlwaysAddMaterialSuffix;
  176. /// <summary>
  177. /// If AlwaysAddMaterialSuffix is on, this is the suffix to be added
  178. /// </summary>
  179. String AddedMaterialSuffix;
  180. /// <summary>
  181. /// When generating a material off of an importing image, should the importer force appending a diffusemap suffix onto the end to avoid potential naming confusion.
  182. /// e.g. MyCoolStuff.png is imported, generating MyCoolStuff material asset and MyCoolStuff_Diffuse image asset
  183. /// </summary>
  184. bool UseDiffuseSuffixOnOriginImage;
  185. /// <summary>
  186. /// Should the importer try and use existing material assets in the game directory if at all possible. (Not currently utilized)
  187. /// </summary>
  188. bool UseExistingMaterials;
  189. /// <summary>
  190. /// A list of material names that should not be imported. Separated by either , or ;
  191. /// </summary>
  192. String IgnoreMaterials;
  193. /// <summary>
  194. /// When processing a material asset, should the importer attempt to populate the various material maps on it by looking up common naming conventions for potentially relevent image files
  195. /// e.g. If MyCoolStuff_Diffuse.png is imported, generating MyCoolStuff material, it would also find MyCoolStuff_Normal and MyCoolStuff_PBR images and map them to the normal and ORMConfig maps respectively automatically
  196. /// </summary>
  197. bool PopulateMaterialMaps;
  198. //
  199. //Animations
  200. /// <summary>
  201. /// Does this config allow for importing Shape Animations
  202. /// </summary>
  203. bool ImportAnimations;
  204. /// <summary>
  205. /// When importing a shape file, should the animations within be separated out into unique files
  206. /// </summary>
  207. bool SeparateAnimations;
  208. /// <summary>
  209. /// If separating animations out from a source file, what prefix should be added to the names for grouping association
  210. /// </summary>
  211. String SeparateAnimationPrefix;
  212. /// <summary>
  213. /// Defines the animation timing for the given animation sequence. Options are FrameTime, Seconds, Milliseconds
  214. /// </summary>
  215. String animTiming;
  216. /// <summary>
  217. /// The FPS of the animation sequence
  218. /// </summary>
  219. F32 animFPS;
  220. /// <summary>
  221. /// When importing a shape animation, this indicates if it should automatically add a standard suffix onto the name
  222. /// </summary>
  223. bool AlwaysAddShapeAnimationSuffix;
  224. /// <summary>
  225. /// If AlwaysAddShapeAnimationSuffix is on, this is the suffix to be added
  226. /// </summary>
  227. String AddedShapeAnimationSuffix;
  228. //
  229. //Collision
  230. /// <summary>
  231. /// Does this configuration generate collision geometry when importing. (Not currently enabled)
  232. /// </summary>
  233. bool GenerateCollisions;
  234. /// <summary>
  235. /// What sort of collision geometry is generated. (Not currently enabled)
  236. /// </summary>
  237. String GenCollisionType;
  238. /// <summary>
  239. /// What prefix is added to the collision geometry generated. (Not currently enabled)
  240. /// </summary>
  241. String CollisionMeshPrefix;
  242. /// <summary>
  243. /// Does this configuration generate Line of Sight collision geometry. (Not currently enabled)
  244. /// </summary>
  245. bool GenerateLOSCollisions;
  246. /// <summary>
  247. /// What sort of Line of Sight collision geometry is generated. (Not currently enabled)
  248. /// </summary>
  249. String GenLOSCollisionType;
  250. /// <summary>
  251. /// What prefix is added to the Line of Sight collision geometry generated. (Not currently enabled)
  252. /// </summary>
  253. String LOSCollisionMeshPrefix;
  254. //
  255. //Images
  256. /// <summary>
  257. /// Does this configuration support importing images.
  258. /// </summary>
  259. bool importImages;
  260. /// <summary>
  261. /// When importing an image, this indicates if it should automatically add a standard suffix onto the name
  262. /// </summary>
  263. bool AlwaysAddImageSuffix;
  264. /// <summary>
  265. /// If AlwaysAddImageSuffix is on, this is the suffix to be added
  266. /// </summary>
  267. String AddedImageSuffix;
  268. /// <summary>
  269. /// What is the default ImageType images are imported as. Options are: N/A, Diffuse, Normal, Metalness, Roughness, AO, ORMConfig, GUI, Cubemap
  270. /// </summary>
  271. String ImageType;
  272. /// <summary>
  273. /// What type of suffixes are scanned to detect if an importing image is a diffuse map.
  274. /// e.g. _Albedo or _Color
  275. /// </summary>
  276. String DiffuseTypeSuffixes;
  277. /// <summary>
  278. /// What type of suffixes are scanned to detect if an importing image is a normal map.
  279. /// e.g. _Normal or _Norm
  280. /// </summary>
  281. String NormalTypeSuffixes;
  282. /// <summary>
  283. /// What type of suffixes are scanned to detect if an importing image is a metalness map.
  284. /// e.g. _Metalness or _Metal
  285. /// </summary>
  286. String MetalnessTypeSuffixes;
  287. /// <summary>
  288. /// What type of suffixes are scanned to detect if an importing image is a roughness map.
  289. /// e.g. _roughness or _rough
  290. /// </summary>
  291. String RoughnessTypeSuffixes;
  292. /// <summary>
  293. /// What type of suffixes are scanned to detect if an importing image is a smoothness map.
  294. /// e.g. _smoothness or _smooth
  295. /// </summary>
  296. String SmoothnessTypeSuffixes;
  297. /// <summary>
  298. /// What type of suffixes are scanned to detect if an importing image is a ambient occlusion map.
  299. /// e.g. _ambient or _ao
  300. /// </summary>
  301. String AOTypeSuffixes;
  302. /// <summary>
  303. /// What type of suffixes are scanned to detect if an importing image is a ORMConfig map.
  304. /// e.g. _Composite or _PBR
  305. /// </summary>
  306. String PBRTypeSuffixes;
  307. /// <summary>
  308. /// Indicates what filter mode images imported with this configuration utilizes. Options are Linear, Bilinear, Trilinear
  309. /// </summary>
  310. String TextureFilteringMode;
  311. /// <summary>
  312. /// Indicates if images imported with this configuration utilize mipmaps
  313. /// </summary>
  314. bool UseMips;
  315. /// <summary>
  316. /// Indicates if images imported with this configuration are in an HDR format
  317. /// </summary>
  318. bool IsHDR;
  319. /// <summary>
  320. /// Indicates what amount of scaling images imported with this configuration use
  321. /// </summary>
  322. F32 Scaling;
  323. /// <summary>
  324. /// Indicates if images imported with this configuration are compressed
  325. /// </summary>
  326. bool ImagesCompressed;
  327. /// <summary>
  328. /// Indicates if images imported with this configuration generate a parent material for it as well
  329. /// </summary>
  330. bool GenerateMaterialOnImport;
  331. //
  332. //Sounds
  333. /// <summary>
  334. /// Indicates if sounds are imported with this configuration
  335. /// </summary>
  336. bool importSounds;
  337. /// <summary>
  338. /// Indicates what amount the volume is adjusted on sounds imported with this configuration
  339. /// </summary>
  340. F32 VolumeAdjust;
  341. /// <summary>
  342. /// Indicates what amount the pitch is adjusted on sounds imported with this configuration
  343. /// </summary>
  344. F32 PitchAdjust;
  345. /// <summary>
  346. /// Indicates if sounds imported with this configuration are compressed
  347. /// </summary>
  348. bool SoundsCompressed;
  349. /// When importing an image, this indicates if it should automatically add a standard suffix onto the name
  350. /// </summary>
  351. bool AlwaysAddSoundSuffix;
  352. /// <summary>
  353. /// If AlwaysAddSoundSuffix is on, this is the suffix to be added
  354. /// </summary>
  355. String AddedSoundSuffix;
  356. public:
  357. AssetImportConfig();
  358. virtual ~AssetImportConfig();
  359. bool onAdd() override;
  360. void onRemove() override;
  361. /// Engine.
  362. static void initPersistFields();
  363. /// <summary>
  364. /// Loads a configuration from a Settings object
  365. /// @param configSettings, The Settings object to load from
  366. /// @param configName, The name of the configuration setting to load from the setting object
  367. /// </summary>
  368. void loadImportConfig(Settings* configSettings, String configName);
  369. void CopyTo(AssetImportConfig* target) const;
  370. /// Declare Console Object.
  371. DECLARE_CONOBJECT(AssetImportConfig);
  372. void loadSISFile(Torque::Path filePath);
  373. };
  374. /// <summary>
  375. /// AssetImportConfig is a SimObject derived object that represents and holds information for an importing asset. They are generated and processed by the AssetImporter
  376. /// </summary>
  377. class AssetImportObject : public SimObject
  378. {
  379. typedef SimObject Parent;
  380. public:
  381. /// <summary>
  382. /// What type is the importing asset
  383. /// </summary>
  384. String assetType;
  385. /// <summary>
  386. /// What is the source file path of the importing asset
  387. /// </summary>
  388. Torque::Path filePath;
  389. /// <summary>
  390. /// What is the source file path of the importing asset in string form
  391. /// </summary>
  392. StringTableEntry filePathString;
  393. /// <summary>
  394. /// What is the asset's name
  395. /// </summary>
  396. String assetName;
  397. /// <summary>
  398. /// What is the original, unmodified by processing, asset name
  399. /// </summary>
  400. String cleanAssetName;
  401. /// <summary>
  402. /// What is the name of the module this asset will be importing into
  403. /// </summary>
  404. String moduleName;
  405. /// <summary>
  406. /// What is the current status of this asset item in it's import process
  407. /// </summary>
  408. String status;
  409. /// <summary>
  410. /// If there is a warning or error status, what type is the condition for this asset item
  411. /// </summary>
  412. String statusType;
  413. /// <summary>
  414. /// What is the articulated information of the status of the asset. Contains the error or warning log data.
  415. /// </summary>
  416. String statusInfo;
  417. /// <summary>
  418. /// Is the asset item currently flagged as dirty
  419. /// </summary>
  420. bool dirty;
  421. enum
  422. {
  423. NotProcessed=0,
  424. Processed,
  425. Skipped,
  426. UseForDependencies,
  427. Error,
  428. Imported
  429. };
  430. /// <summary>
  431. /// Is this asset item marked to be skipped. If it is, it's usually due to being marked as deleted
  432. /// </summary>
  433. U32 importStatus;
  434. /// <summary>
  435. /// Is this specific asset item generated as part of the import process of another item
  436. /// </summary>
  437. bool generatedAsset;
  438. /// <summary>
  439. /// What, if any, importing asset item is this item's parent
  440. /// </summary>
  441. AssetImportObject* parentAssetItem;
  442. /// <summary>
  443. /// What, if any, importing asset item are children of this item
  444. /// </summary>
  445. Vector< AssetImportObject*> childAssetItems;
  446. /// <summary>
  447. /// What is the ultimate asset taml file path for this import item
  448. /// </summary>
  449. String tamlFilePath;
  450. //
  451. /// <summary>
  452. /// Specific to ImageAsset type
  453. /// What is the image asset's suffix type. Options are: Albedo, Normal, Roughness, AO, Metalness, ORMConfig
  454. /// </summary>
  455. String imageSuffixType;
  456. //
  457. /// <summary>
  458. /// Specific to ShapeAsset type
  459. /// Processed information about the shape file. Contains numbers and lists of meshes, materials and animations
  460. /// </summary>
  461. GuiTreeViewCtrl* shapeInfo;
  462. //
  463. /// <summary>
  464. /// A string that can hold a hint string to help the auto-import ensure the correct asset subtype is assigned.
  465. /// e.g. "GUI" would inform an image asset being imported that it should be flagged as a GUI image type
  466. /// </summary>
  467. String typeHint;
  468. public:
  469. AssetImportObject();
  470. virtual ~AssetImportObject();
  471. bool onAdd() override;
  472. void onRemove() override;
  473. /// Engine.
  474. static void initPersistFields();
  475. /// Declare Console Object.
  476. DECLARE_CONOBJECT(AssetImportObject);
  477. static bool _setFilePath(void* obj, const char* index, const char* data);
  478. void setFilePath(StringTableEntry pFilePath);
  479. bool operator == (const AssetImportObject& o) const
  480. {
  481. return o.getId() == this->getId();
  482. }
  483. bool canImport() {
  484. return (importStatus == AssetImportObject::Processed);
  485. }
  486. };
  487. /// <summary>
  488. /// AssetImporter is a SimObject derived object that processed and imports files and turns them into assets if they are of valid types.
  489. /// Utilizes an AssetImportConfig to inform the importing process's behavior.
  490. /// </summary>
  491. class AssetImporter : public SimObject
  492. {
  493. typedef SimObject Parent;
  494. /// <summary>
  495. /// The import configuration that is currently being utilized
  496. /// </summary>
  497. AssetImportConfig* activeImportConfig;
  498. /// <summary>
  499. /// A log of all the actions that have been performed by the importer
  500. /// </summary>
  501. Vector<String> activityLog;
  502. /// <summary>
  503. /// A list of AssetImportObjects that are to be imported
  504. /// </summary>
  505. Vector<AssetImportObject*> importingAssets;
  506. /// <summary>
  507. /// A list of file paths that are to be imported. These are only used for resetting purposes;
  508. /// </summary>
  509. Vector<Torque::Path> originalImportingFiles;
  510. /// <summary>
  511. /// The Id of the module the assets are to be imported into
  512. /// </summary>
  513. String targetModuleId;
  514. /// <summary>
  515. /// The path any imported assets are placed in as their destination
  516. /// </summary>
  517. String targetPath;
  518. /// <summary>
  519. /// Are there any issues with any of the current import asset items
  520. /// </summary>
  521. bool importIssues;
  522. /// <summary>
  523. /// Is this import action a reimport of an existing asset
  524. /// </summary>
  525. bool isReimport;
  526. /// <summary>
  527. /// Has the heirarchy of asset import items changed due to processing
  528. /// </summary>
  529. bool assetHeirarchyChanged;
  530. /// <summary>
  531. /// A string used for writing into the importLog
  532. /// </summary>
  533. char importLogBuffer[1024];
  534. /// <summary>
  535. /// only used for passing up the result of an import action for a script-side handled type
  536. /// </summary>
  537. String finalImportedAssetPath;
  538. bool mDumpLogs;
  539. public:
  540. AssetImporter();
  541. virtual ~AssetImporter();
  542. bool onAdd() override;
  543. void onRemove() override;
  544. /// Engine.
  545. static void initPersistFields();
  546. /// Declare Console Object.
  547. DECLARE_CONOBJECT(AssetImporter);
  548. /// <summary>
  549. /// Sets the target path for the assets being imported to be deposited into
  550. /// <para>@param pTargetPath, The filePath of the destination point assets are imported into</para>
  551. /// </summary>
  552. void setTargetPath(Torque::Path pTargetPath) { targetPath = pTargetPath; }
  553. /// <summary>
  554. /// Processes a file into an AssetImportObject and adds it to the session for importing
  555. /// <para>@param filePath, The filePath of the file to be imported in as an asset</para>
  556. /// <para>@return AssetImportObject that was created</para>
  557. /// </summary>
  558. AssetImportObject* addImportingFile(Torque::Path filePath);
  559. /// <summary>
  560. /// Adds an existing AssetImportObject to our import session. Generally this would be created in a script somewhere
  561. /// <para>@param assetItem, The asset item to be added to the import session</para>
  562. /// <para>@param parentItem (Optional), The asset item that will be the parent of the assetItem being added</para>
  563. /// </summary>
  564. void addImportingAssetItem(AssetImportObject* assetItem, AssetImportObject* parentItem);
  565. /// <summary>
  566. /// Adds an importing asset to the current session
  567. /// <para>@param assetType, Type of the asset being imported</para>
  568. /// <para>@param filePath, path of the file to be imported</para>
  569. /// <para>@param parentItem, AssetImportObject that the new item is a child of. null if no parent</para>
  570. /// <para>@param assetNameOverride, If not blank, will be the new item's assetName instead of being created off of the filePath</para>
  571. /// <para>@return AssetImportObject that was created</para>
  572. /// </summary>
  573. AssetImportObject* addImportingAsset(String assetType, Torque::Path filePath, AssetImportObject* parentItem, String assetNameOverride);
  574. /// <summary>
  575. /// Deletes the asset item from the import session. Affects the item's children as well
  576. /// <para>@param assetItem, asset item to be marked as deleted</para>
  577. /// </summary>
  578. void deleteImportingAsset(AssetImportObject* assetItem);
  579. /// <summary>
  580. /// Finds an asset item in the session if it exists, by name
  581. /// <para>@param assetName, Asset name to find</para>
  582. /// <para>@param assetItem, if null, will loop over and recurse the main import asset items, if a specific AssetImportObject is passed in, it will recurse it's children</para>
  583. /// <para>@return AssetImportObject that was found</para>
  584. /// </summary>
  585. AssetImportObject* findImportingAssetByName(String assetName, AssetImportObject* assetItem = nullptr);
  586. /// <summary>
  587. /// Finds the module associated with a given file path
  588. /// <para>@param filePath, File path to parse the the module from</para>
  589. /// <para>@return ModuleDefinition that was found</para>
  590. /// </summary>
  591. static ModuleDefinition* getModuleFromPath(Torque::Path filePath);
  592. /// <summary>
  593. /// Parses an asset's name to try and find if any of the import config's suffix lists match to it
  594. /// <para>@param assetName, Asset name to parse any image suffix out of</para>
  595. /// <para>@param suffixType, output, The suffix type that was matched to the asset name</para>
  596. /// <para>@return suffix that matched to the asset name</para>
  597. /// </summary>
  598. String parseImageSuffixes(String assetName, String* suffixType);
  599. /// <summary>
  600. /// Parses a file path to determine its asset type
  601. /// <para>@param filePath, File path to parse</para>
  602. /// <para>@return The asset type as a string</para>
  603. /// </summary>
  604. String getAssetTypeByFile(Torque::Path filePath);
  605. /// <summary>
  606. /// Resets the import session to a clean slate. This will clear all existing AssetImportObjects and the activity log
  607. /// and then re-process the original filePaths again.
  608. /// <para>@param hardClearSession, Defaults to false. If true, will also clear the original filePaths</para>
  609. /// </summary>
  610. void resetImportSession(bool hardClearSession = false);
  611. /// <summary>
  612. /// Get the number of lines in the activity log
  613. /// <para>@return Line count as S32</para>
  614. /// </summary>
  615. S32 getActivityLogLineCount();
  616. /// <summary>
  617. /// Gets the log line at a given index
  618. /// <para>@param line, line in the log to get</para>
  619. /// <para>@return The log line as a string</para>
  620. /// </summary>
  621. String getActivityLogLine(U32 line);
  622. /// <summary>
  623. /// Dumps the entire current activity log to the console.
  624. /// </summary>
  625. void dumpActivityLog();
  626. /// <summary>
  627. /// Gets the number of top-level asset items in the current import session(doesn't count children)
  628. /// <para>@return Number of children</para>
  629. /// </summary>
  630. S32 getAssetItemCount();
  631. /// <summary>
  632. /// Get the top-level asset item in the current import session at the requested index
  633. /// <para>@param index, The index of the item array to get</para>
  634. /// <para>@return The AssetImportObject at the index</para>
  635. /// </summary>
  636. AssetImportObject* getAssetItem(U32 index);
  637. /// <summary>
  638. /// Gets the number of child asset items of a given AssetImportObject
  639. /// <para>@param assetItem, The AssetImportObject to get the number of child items for</para>
  640. /// <para>@return Number of children</para>
  641. /// </summary>
  642. S32 getAssetItemChildCount(AssetImportObject* assetItem);
  643. /// <summary>
  644. /// Get the child asset item of a specific AssetImportObject at the requested index
  645. /// <para>@param assetItem, The AssetImportObject to get the number of child items for</para>
  646. /// <para>@param index, The index of the child item array to get</para>
  647. /// <para>@return The AssetImportObject at the index</para>
  648. /// </summary>
  649. AssetImportObject* getAssetItemChild(AssetImportObject* assetItem, U32 index);
  650. /// <summary>
  651. /// Process AssetImportObject's to prepare them for importing.
  652. /// <para>@param assetItem, If null, will loop over the top-level asset items list, if a specific item is provided, will process it's children</para>
  653. /// </summary>
  654. void processImportAssets(AssetImportObject* assetItem = nullptr);
  655. /// <summary>
  656. /// Process a specific AssetImportObject that is an ImageAsset type to prepare it for importing
  657. /// <para>@param assetItem, The AssetImportObject to process</para>
  658. /// </summary>
  659. void processImageAsset(AssetImportObject* assetItem);
  660. /// <summary>
  661. /// Process a specific AssetImportObject that is an MaterialAsset type to prepare it for importing
  662. /// <para>@param assetItem, The AssetImportObject to process</para>
  663. /// </summary>
  664. void processMaterialAsset(AssetImportObject* assetItem);
  665. /// <summary>
  666. /// Process a specific AssetImportObject that is an ShapeAnimationAsset type to prepare it for importing
  667. /// <para>@param assetItem, The AssetImportObject to process</para>
  668. /// </summary>
  669. void processShapeAsset(AssetImportObject* assetItem);
  670. /// <summary>
  671. /// Process a specific AssetImportObject that is an ShapeAsset type to prepare it for importing
  672. /// <para>@param assetItem, The AssetImportObject to process</para>
  673. /// </summary>
  674. void processShapeAnimationAsset(AssetImportObject* assetItem);
  675. /// <summary>
  676. /// Process a specific ShapeAsset AssetImportObject with a material id in order to parse and handle the materials listed in the shape file
  677. /// <para>@param assetItem, The AssetImportObject to process</para>
  678. /// <para>@param materialItemId, The materialItemId in the shapeInfo to process</para>
  679. /// </summary>
  680. void processShapeMaterialInfo(AssetImportObject* assetItem, S32 materialItemId);
  681. /// <summary>
  682. /// Process a specific AssetImportObject that is an SoundAsset type to prepare it for importing
  683. /// <para>@param assetItem, The AssetImportObject to process</para>
  684. /// </summary>
  685. void processSoundAsset(AssetImportObject* assetItem);
  686. /// <summary>
  687. /// Run through and validate assets for issues, such as name collisions
  688. /// </summary>
  689. bool validateAssets();
  690. /// <summary>
  691. /// Validate a specific asset item
  692. /// <para>@param assetItem, The AssetImportObject to validate</para>
  693. /// </summary>
  694. void validateAsset(AssetImportObject* assetItem);
  695. /// <summary>
  696. /// Reset the validation status of asset items
  697. /// <para>@param assetItem, If null, will loop over the top-level asset items list, if a specific item is provided, will reset it's children</para>
  698. /// </summary>
  699. void resetAssetValidationStatus(AssetImportObject* assetItem = nullptr);
  700. /// <summary>
  701. /// Checks asset items for any collisions in the current import session
  702. /// <para>@param assetItemToCheckFor, The asset to check for collisions with</para>
  703. /// <para>@param assetItem, if null, will loop over and recurse the main import asset items, if a specific AssetImportObject is passed in, it will recurse it's children</para>
  704. /// <para>@return If a collision was detected</para>
  705. /// </summary>
  706. bool checkAssetForCollision(AssetImportObject* assetItemToCheckFor, AssetImportObject* assetItem = nullptr);
  707. /// <summary>
  708. /// Attempts to automatically resolve import issues according to the import config settings
  709. /// <para>@param assetItem, The AssetImportObject to resolve</para>
  710. /// </summary>
  711. void resolveAssetItemIssues(AssetImportObject* assetItem);
  712. /// <summary>
  713. /// Runs the import process on a single file in-place. Intended primarily for autoimporting a loose file that's in the game directory.
  714. /// <para>@param filePath, The filePath of the file to be imported in as an asset</para>
  715. /// <para>@param typeHint, Optional. A string that provides a hint of the intended asset type. Such as an image being intended for GUI use.</para>
  716. /// <para>@return AssetId of the asset that was imported. If import failed, it will be empty.</para>
  717. /// </summary>
  718. StringTableEntry autoImportFile(Torque::Path filePath, String typeHint);
  719. /// <summary>
  720. /// Runs the import process in the current session
  721. /// <para>@param assetItem, if null, will loop over and recurse the main import asset items, if a specific AssetImportObject is passed in, it will recurse it's children</para>
  722. /// </summary>
  723. void importAssets(AssetImportObject* assetItem = nullptr);
  724. /// <summary>
  725. /// Runs the import processing on a specific ImageAsset item
  726. /// <para>@param assetItem, The asset item to import</para>
  727. /// <para>@return TAML File path of the new asset that was imported. If import failed, it will be empty.</para>
  728. /// </summary>
  729. Torque::Path importImageAsset(AssetImportObject* assetItem);
  730. /// <summary>
  731. /// Runs the import processing on a specific MaterialAsset item
  732. /// <para>@param assetItem, The asset item to import</para>
  733. /// <para>@return TAML File path of the new asset that was imported. If import failed, it will be empty.</para>
  734. /// </summary>
  735. Torque::Path importMaterialAsset(AssetImportObject* assetItem);
  736. /// <summary>
  737. /// Runs the import processing on a specific ShapeAsset item
  738. /// <para>@param assetItem, The asset item to import</para>
  739. /// <para>@return TAML File path of the new asset that was imported. If import failed, it will be empty.</para>
  740. /// </summary>
  741. Torque::Path importShapeAsset(AssetImportObject* assetItem);
  742. /// <summary>
  743. /// Runs the import processing on a specific SoundAsset item
  744. /// <para>@param assetItem, The asset item to import</para>
  745. /// <para>@return TAML File path of the new asset that was imported. If import failed, it will be empty.</para>
  746. /// </summary>
  747. Torque::Path importSoundAsset(AssetImportObject* assetItem);
  748. /// <summary>
  749. /// Runs the import processing on a specific ShapeAnimationAsset item
  750. /// <para>@param assetItem, The asset item to import</para>
  751. /// <para>@return TAML File path of the new asset that was imported. If import failed, it will be empty.</para>
  752. /// </summary>
  753. Torque::Path importShapeAnimationAsset(AssetImportObject* assetItem);
  754. /// <summary>
  755. /// Iterates over all the items in the current session and acquires them, which jumpstarts the loading/init'ng process on them, making the available for use immediately
  756. /// <para>@param assetItem, if null, will loop over and recurse the main import asset items, if a specific AssetImportObject is passed in, it will recurse it's children</para>
  757. /// </summary>
  758. void acquireAssets(AssetImportObject* assetItem = nullptr);
  759. //
  760. /// <summary>
  761. /// Gets the currently active import configuration
  762. /// <para>@return Current AssetImportConfig the importer is using</para>
  763. /// </summary>
  764. AssetImportConfig* getImportConfig() { return activeImportConfig; }
  765. void setImportConfig(AssetImportConfig* importConfig)
  766. {
  767. if (importConfig != nullptr)
  768. {
  769. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Loading import config: %s!", importConfig->getName());
  770. activityLog.push_back(importLogBuffer);
  771. activeImportConfig = importConfig;
  772. }
  773. }
  774. /// <summary>
  775. /// Resets the active import config to whatever the default is. Either a clean slate if one isn't defined
  776. /// or loading one if defined via the editor config
  777. /// </summary>
  778. void resetImportConfig();
  779. //
  780. static String getTrueFilename(const String& fileName);
  781. //
  782. /// <summary>
  783. /// </summary>
  784. static inline String findImagePath(const String &testPath)
  785. {
  786. String imagePath;
  787. if (Platform::isFile(testPath + String(".jpg")))
  788. imagePath = testPath + String(".jpg");
  789. else if (Platform::isFile(testPath + String(".png")))
  790. imagePath = testPath + String(".png");
  791. else if (Platform::isFile(testPath + String(".dds")))
  792. imagePath = testPath + String(".dds");
  793. else if (Platform::isFile(testPath + String(".tif")))
  794. imagePath = testPath + String(".tif");
  795. if(imagePath.isNotEmpty())
  796. //This ensures case-correct for the filename
  797. imagePath = getTrueFilename(imagePath);
  798. return imagePath;
  799. }
  800. //
  801. void setTargetModuleId(const String& moduleId) { targetModuleId = moduleId; }
  802. const String& getTargetModuleId() { return targetModuleId; }
  803. String getFolderPrefixedName(AssetImportObject* assetItem)
  804. {
  805. String renamedAssetName = assetItem->assetName;
  806. S32 dirIndex = assetItem->filePath.getDirectoryCount() - 1;
  807. while (dirIndex > -1)
  808. {
  809. renamedAssetName = assetItem->assetName;
  810. String owningFolder = assetItem->filePath.getDirectory(dirIndex);
  811. renamedAssetName = owningFolder + "_" + renamedAssetName;
  812. if (AssetDatabase.isDeclaredAsset(renamedAssetName))
  813. {
  814. dirIndex--;
  815. continue;
  816. }
  817. break;
  818. }
  819. return renamedAssetName;
  820. }
  821. };