assetImport.tscript 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. function ImportAssetWindow::showDialog(%this)
  23. {
  24. //prep the import control
  25. Canvas.pushDialog(AssetImportCtrl);
  26. AssetImportCtrl.setHidden(false);
  27. ImportAssetWindow.allowAutoImport = true; //special-case override for if we want to force a manual import process
  28. ImportAssetWindow.assetHeirarchyChanged = false;
  29. %defaultConfig = EditorSettings.value("Assets/AssetImporDefaultConfig", "");
  30. if(%defaultConfig !$= "")
  31. {
  32. %defaultConfigIdx = ImportAssetConfigList.findText(%defaultConfig);
  33. ImportAssetConfigList.setSelected(%defaultConfigIdx);
  34. }
  35. else
  36. {
  37. ImportAssetConfigList.setSelected(0);
  38. }
  39. %this.dirty = false;
  40. }
  41. function ImportAssetWindow::Close(%this)
  42. {
  43. //Some cleanup
  44. ImportAssetWindow.importer.resetImportSession(true);
  45. //ImportAssetWindow.importingFilesArray.empty();
  46. %this.importTempDirHandler.deleteFolder("tools/assetBrowser/importTemp/*/");
  47. if(ImportAssetWindow.isAwake())
  48. ImportAssetWindow.refresh();
  49. //ImportAssetItems.empty();
  50. Canvas.popDialog();
  51. }
  52. //
  53. function ImportAssetWindow::onWake(%this)
  54. {
  55. //We've woken, meaning we're trying to import assets
  56. //Lets refresh our list
  57. if(!ImportAssetWindow.isVisible())
  58. return;
  59. AssetImportSettings.read();
  60. %this.reloadImportOptionConfigs();
  61. AssetImportCtrl-->NewAssetsTree.buildIconTable( ":tools/classIcons/TSStatic:tools/classIcons/TSStatic" @
  62. ":tools/classIcons/material:tools/classIcons/material"@
  63. ":tools/classIcons/GuiBitmapCtrl:tools/classIcons/GuiBitmapCtrl"@
  64. ":tools/classIcons/SFXEmitter:tools/classIcons/SFXEmitter"@
  65. ":tools/gui/images/iconWarn:tools/gui/images/iconWarn"@
  66. ":tools/gui/images/iconError:tools/gui/images/iconError");
  67. AssetImportTargetAddress.text = AssetBrowser.dirHandler.currentAddress;
  68. AssetImportTargetModule.text = AssetBrowser.dirHandler.getModuleFromAddress(AssetBrowser.dirHandler.currentAddress).ModuleId;
  69. ImportAssetConfigList.setSelected(0);
  70. %this.importer.targetPath = AssetImportTargetAddress.getText();
  71. %this.importer.targetModuleId = AssetImportTargetModule.getText();
  72. %this.refresh();
  73. toggleImportWindowVizBtn.setStateOn(EditorSettings.value("Assets/AutoImport"));
  74. }
  75. //
  76. //
  77. function isImageFormat(%fileExt)
  78. {
  79. if( (%fileExt $= ".png") || (%fileExt $= ".jpg") || (%fileExt $= ".bmp") || (%fileExt $= ".dds") || (%fileExt $= ".tif") || (%fileExt $= ".psd") || (%fileExt $= ".gif") || (%fileExt $= ".hdr"))
  80. return true;
  81. return false;
  82. }
  83. function isShapeFormat(%fileExt)
  84. {
  85. if( (%fileExt $= ".dae") ||
  86. (%fileExt $= ".dts") ||
  87. (%fileExt $= ".fbx") ||
  88. (%fileExt $= ".gltf") ||
  89. (%fileExt $= ".glb") ||
  90. (%fileExt $= ".obj") ||
  91. (%fileExt $= ".blend") ||
  92. (%fileExt $= ".dsq"))
  93. return true;
  94. return false;
  95. }
  96. function isSoundFormat(%fileExt)
  97. {
  98. if( (%fileExt $= ".ogg") || (%fileExt $= ".wav") || (%fileExt $= ".mp3"))
  99. return true;
  100. return false;
  101. }
  102. function getImageInfo(%file)
  103. {
  104. //we're going to populate a GuiTreeCtrl with info of the inbound image file
  105. }
  106. //This lets us go and look for a image at the importing directory as long as it matches the material name
  107. function findImageFile(%path, %materialName, %type)
  108. {
  109. if(isFile(%path @ "/" @ %materialName @ ".jpg"))
  110. return %path @ "/" @ %materialName @ ".jpg";
  111. else if(isFile(%path @ "/" @ %materialName @ ".png"))
  112. return %path @ "/" @ %materialName @ ".png";
  113. else if(isFile(%path @ "/" @ %materialName @ ".dds"))
  114. return %path @ "/" @ %materialName @ ".dds";
  115. else if(isFile(%path @ "/" @ %materialName @ ".tif"))
  116. return %path @ "/" @ %materialName @ ".tif";
  117. }
  118. function getAssetTypeByFilename(%filePath)
  119. {
  120. %fileExt = fileExt( %filePath );
  121. //add it to our array!
  122. if(isImageFormat(%fileExt))
  123. return "ImageAsset";
  124. else if( isShapeFormat(%fileExt))
  125. return "ShapeAsset";
  126. else if( isSoundFormat(%fileExt))
  127. return "SoundAsset";
  128. else if( %fileExt $= "." @ $TorqueScriptFileExtension || %fileExt $= "." @ $TorqueScriptFileExtension @ ".dso" )
  129. return "ScriptAsset";
  130. else if( %fileExt $= ".gui" || %fileExt $= ".gui.dso" )
  131. return "GUIAsset";
  132. else if (%fileExt $= ".zip")
  133. return "zip";
  134. else if( %fileExt $= "")
  135. return "folder";
  136. return "";
  137. }
  138. function AssetBrowser::onBeginDropFiles( %this )
  139. {
  140. if(!AssetBrowser.isAwake() || !AssetBrowser.isVisible())
  141. {
  142. if(GuiEditorIsActive())
  143. GuiEditor.onBeginDropFiles();
  144. else if(EditorIsActive())
  145. EWorldEditor.onBeginDropFiles();
  146. return;
  147. }
  148. error("% DragDrop - Beginning files dropping.");
  149. if(!ImportAssetWindow.isAwake())
  150. ImportAssetWindow.showDialog();
  151. }
  152. function AssetBrowser::onDropFile( %this, %filePath )
  153. {
  154. if(fileExt(%filePath) $= "")
  155. {
  156. //we're dealing with a folder, so we gotta parse through it
  157. %file = findFirstFile( %filePath @ "/*" );
  158. while( %file !$= "" )
  159. {
  160. %this.onDropFile(%file);
  161. %file = findNextFile( %filePath @ "/*" );
  162. }
  163. return;
  164. }
  165. if(!AssetBrowser.isAwake() || !AssetBrowser.isVisible())
  166. {
  167. if(GuiEditorIsActive())
  168. GuiEditor.onDropFile(%filePath);
  169. else if(EditorIsActive())
  170. EWorldEditor.onDropFile(%filePath);
  171. return;
  172. }
  173. ImportAssetWindow.importer.addImportingFile(%filePath);
  174. }
  175. function AssetBrowser::onDropZipFile(%this, %filePath)
  176. {
  177. if(!AssetBrowser.isAwake() || !AssetBrowser.isVisible())
  178. {
  179. if(GuiEditorIsActive())
  180. GuiEditor.onDropZipFile(%filePath);
  181. else if(EditorIsActive())
  182. EWorldEditor.onDropZipFile(%filePath);
  183. return;
  184. }
  185. %zip = new ZipObject();
  186. %zip.openArchive(%filePath);
  187. %count = %zip.getFileEntryCount();
  188. echo("Dropped in a zip file with" SPC %count SPC "files inside!");
  189. for (%i = 0; %i < %count; %i++)
  190. {
  191. %fileEntry = %zip.getFileEntry(%i);
  192. %fileFrom = getField(%fileEntry, 0);
  193. %fileTo = expandFilename("^tools/assetBrowser/importTemp/") @ %fileFrom;
  194. %zip.extractFile(%fileFrom, %fileTo);
  195. //exec(%fileTo);
  196. }
  197. %zip.delete();
  198. //Next, we loop over the files and import them
  199. }
  200. function AssetBrowser::onDropFolder(%this, %filePath)
  201. {
  202. if(!AssetBrowser.isAwake() || !AssetBrowser.isVisible())
  203. {
  204. if(GuiEditorIsActive())
  205. GuiEditor.onDropFolder(%filePath);
  206. else if(EditorIsActive())
  207. EWorldEditor.onDropFolder(%filePath);
  208. return;
  209. }
  210. %zip = new ZipObject();
  211. %zip.openArchive(%filePath);
  212. %count = %zip.getFileEntryCount();
  213. echo("Dropped in a zip file with" SPC %count SPC "files inside!");
  214. return;
  215. for (%i = 0; %i < %count; %i++)
  216. {
  217. %fileEntry = %zip.getFileEntry(%i);
  218. %fileFrom = getField(%fileEntry, 0);
  219. //First, we wanna scan to see if we have modules to contend with. If we do, we'll just plunk them in wholesale
  220. //and not process their contents.
  221. // TODO
  222. %fileExt = "";
  223. //If not modules, it's likely an art pack or other mixed files, so we'll import them as normal
  224. if( (%fileExt $= ".png") || (%fileExt $= ".jpg") || (%fileExt $= ".bmp") || (%fileExt $= ".dds") )
  225. %this.importAssetListArray.add("ImageAsset", %filePath);
  226. else if( (%fileExt $= ".dae") || (%fileExt $= ".dts"))
  227. %this.importAssetListArray.add("ShapeAsset", %filePath);
  228. else if( (%fileExt $= ".ogg") || (%fileExt $= ".wav") || (%fileExt $= ".mp3"))
  229. %this.importAssetListArray.add("SoundAsset", %filePath);
  230. else if( (%fileExt $= ".gui") || (%fileExt $= ".gui.dso"))
  231. %this.importAssetListArray.add("GUIAsset", %filePath);
  232. //else if( (%fileExt $= "." @ $TorqueScriptFileExtension) || (%fileExt $= ".dso"))
  233. // %this.importAssetListArray.add("Script", %filePath);
  234. else if( (%fileExt $= ".mis"))
  235. %this.importAssetListArray.add("LevelAsset", %filePath);
  236. // For now, if it's a .tscript file, we'll assume it's a behavior.
  237. if (fileExt(%fileFrom) !$= "." @ $TorqueScriptFileExtension)
  238. continue;
  239. %fileTo = expandFilename("^game/behaviors/") @ fileName(%fileFrom);
  240. %zip.extractFile(%fileFrom, %fileTo);
  241. exec(%fileTo);
  242. }
  243. }
  244. function AssetBrowser::onEndDropFiles( %this )
  245. {
  246. if(!AssetBrowser.isAwake() || !AssetBrowser.isVisible())
  247. {
  248. if(GuiEditorIsActive())
  249. GuiEditor.onEndDropFiles();
  250. else if(EditorIsActive())
  251. EWorldEditor.onEndDropFiles();
  252. return;
  253. }
  254. ImportAssetWindow.refresh();
  255. }
  256. //
  257. //
  258. //
  259. function AssetBrowser::reloadImportingFiles(%this)
  260. {
  261. //Effectively, we re-import the files we were trying to originally. We'd only usually do this in the event we change our import config
  262. %this.onBeginDropFiles();
  263. for(%i=0; %i < ImportAssetWindow.importingFilesArray.count(); %i++)
  264. {
  265. %this.onDropFile(ImportAssetWindow.importingFilesArray.getKey(%i));
  266. }
  267. %this.onEndDropFiles();
  268. }
  269. function AssetBrowser::addImportingAsset( %this, %assetType, %filePath, %parentAssetItem, %assetNameOverride )
  270. {
  271. //In some cases(usually generated assets on import, like materials) we'll want to specifically define the asset name instead of peeled from the filePath
  272. if(%assetNameOverride !$= "")
  273. %assetName = %assetNameOverride;
  274. else
  275. %assetName = fileBase(%filePath);
  276. //We don't get a file path at all if we're a generated entry, like materials
  277. //if we have a file path, though, then sanitize it
  278. if(%filePath !$= "")
  279. %filePath = filePath(%filePath) @ "/" @ fileBase(%filePath) @ fileExt(%filePath);
  280. %moduleName = AssetBrowser.SelectedModule;
  281. ImportAssetModuleList.text = %moduleName;
  282. %assetName = strreplace( %assetName, " ", "_" );
  283. //Add to our main list
  284. %assetItem = new AssetImportObject()
  285. {
  286. assetType = %assetType;
  287. filePath = %filePath;
  288. assetName = %assetName;
  289. cleanAssetName = %assetName;
  290. moduleName = %moduleName;
  291. dirty = true;
  292. parentAssetItem = %parentAssetItem;
  293. status = "";
  294. statusType = "";
  295. statusInfo = "";
  296. skip = false;
  297. processed = false;
  298. generatedAsset = false;
  299. };
  300. ImportAssetWindow.importer.addImportingAssetItem(%assetItem, %parentAssetItem);
  301. return %assetItem;
  302. }
  303. function ImportAssetWindow::reloadImportOptionConfigs(%this)
  304. {
  305. if(!isObject(ImportAssetWindow.importConfigsList))
  306. ImportAssetWindow.importConfigsList = new ArrayObject();
  307. else
  308. ImportAssetWindow.importConfigsList.empty();
  309. ImportAssetConfigList.clear();
  310. %xmlDoc = new SimXMLDocument();
  311. if(%xmlDoc.loadFile($AssetBrowser::importConfigsFile))
  312. {
  313. //StateMachine element
  314. if(!%xmlDoc.pushFirstChildElement("AssetImportSettings"))
  315. {
  316. error("Invalid Import Configs file");
  317. return;
  318. }
  319. //Config Groups
  320. %configCount = 0;
  321. %hasGroup = %xmlDoc.pushFirstChildElement("Group");
  322. while(%hasGroup)
  323. {
  324. %configName = %xmlDoc.attribute("name");
  325. ImportAssetWindow.importConfigsList.add(%configName);
  326. ImportAssetConfigList.add(%configName);
  327. %hasGroup = %xmlDoc.nextSiblingElement("Group");
  328. }
  329. %xmlDoc.popElement();
  330. }
  331. %xmlDoc.delete();
  332. %importConfigIdx = ImportAssetWindow.activeImportConfigIndex;
  333. if(%importConfigIdx $= "")
  334. %importConfigIdx = 0;
  335. //ImportAssetConfigList.setSelected(%importConfigIdx);
  336. }
  337. //
  338. function assetImportUpdatePath(%newPath)
  339. {
  340. AssetBrowser.navigateTo(%newPath);
  341. AssetImportTargetAddress.text = %newPath;
  342. AssetImportTargetModule.text = AssetBrowser.dirHandler.getModuleFromAddress(AssetBrowser.dirHandler.currentAddress).ModuleId;
  343. }
  344. function ImportAssetWindow::findImportingAssetByName(%this, %assetName, %assetItem)
  345. {
  346. if(!isObject(%assetItem))
  347. {
  348. for(%i=0; %i < ImportAssetItems.count(); %i++)
  349. {
  350. %assetItem = ImportAssetItems.getKey(%i);
  351. if(!isObject(%assetItem))
  352. return;
  353. if(isObject(%assetItem) && %assetItem.cleanAssetName $= %assetName)
  354. {
  355. return %assetItem;
  356. }
  357. %ret = %this.findImportingAssetByName(%assetName, %assetItem);
  358. if(%ret !$= "")
  359. return %ret;
  360. }
  361. }
  362. else
  363. {
  364. for(%i=0; %i < %assetItem.childAssetItems.count(); %i++)
  365. {
  366. %childAssetItem = %assetItem.childAssetItems.getKey(%i);
  367. if(!isObject(%childAssetItem))
  368. return;
  369. if(isObject(%childAssetItem) && %childAssetItem.cleanAssetName $= %assetName)
  370. {
  371. return %childAssetItem;
  372. }
  373. %ret = %this.findImportingAssetByName(%assetName, %childAssetItem);
  374. if(%ret !$= "")
  375. return %ret;
  376. }
  377. }
  378. return "";
  379. }
  380. function refreshImportAssetWindow()
  381. {
  382. ImportAssetWindow.refresh();
  383. }
  384. function ImportAssetWindow::refresh(%this)
  385. {
  386. if(!%this.dirty)
  387. {
  388. %this.dirty = true;
  389. %this.schedule(16, "doRefresh");
  390. }
  391. }
  392. function ImportAssetWindow::doRefresh(%this)
  393. {
  394. %this.ImportingAssets = 0;
  395. %this.FetchedAssets = 0;
  396. %this.prunedDuplicateAssets = 0;
  397. %this.autoRenamedAssets = 0;
  398. //Go through and process any newly, unprocessed assets
  399. ImportAssetWindow.importer.processImportingAssets();
  400. //%this.processImportAssets();
  401. ImportAssetWindow.hasImportIssues = ImportAssetWindow.importer.hasImportIssues();
  402. AssetImportCtrl-->NewAssetsTree.clear();
  403. AssetImportCtrl-->NewAssetsTree.insertItem(0, "Importing Assets");
  404. for(%i=0; %i < ImportAssetWindow.importer.getAssetItemCount(); %i++)
  405. {
  406. %assetItem = ImportAssetWindow.importer.getAssetItem(%i);
  407. %this.refreshAssetItem(%assetItem);
  408. }
  409. AssetImportCtrl-->NewAssetsTree.buildVisibleTree(true);
  410. %ImportActionSummary = "";
  411. if(%this.ImportingAssets != 0)
  412. {
  413. %ImportActionSummary = %ImportActionSummary SPC %this.ImportingAssets @ " Imported|";
  414. }
  415. if(%this.FetchedAssets != 0)
  416. {
  417. %ImportActionSummary = %ImportActionSummary SPC %this.FetchedAssets @ " Fetched|";
  418. }
  419. if(%this.prunedDuplicateAssets != 0)
  420. {
  421. %ImportActionSummary = %ImportActionSummary SPC %this.prunedDuplicateAssets @ " Duplicates Pruned|";
  422. }
  423. if(%this.autoRenamedAssets != 0)
  424. {
  425. %ImportActionSummary = %ImportActionSummary SPC %this.autoRenamedAssets @ " Automatically Renamed|";
  426. }
  427. if(%ImportActionSummary !$= "")
  428. warn(%ImportActionSummary);
  429. AssetImportSummarization.Text = %ImportActionSummary;
  430. //If we have a valid config file set and we've set to auto-import, and we have no
  431. //issues for importing, then go ahead and run the import immediately, don't
  432. //bother showing the window.
  433. //If any of these conditions fail, we'll display the import window so it can be handled
  434. //by the user
  435. if(ImportAssetWindow.importConfigsList.count() != 0
  436. && EditorSettings.value("Assets/AssetImporDefaultConfig") !$= ""
  437. && EditorSettings.value("Assets/AutoImport", false) == true
  438. && ImportAssetWindow.hasImportIssues() == false
  439. && AssetBrowser.isAssetReImport == false
  440. && ImportAssetWindow.allowAutoImport)
  441. {
  442. AssetImportCtrl.setHidden(true);
  443. ImportAssetWindow.visible = false;
  444. //Go ahead and check if we have any issues, and if not, run the import!
  445. ImportAssetWindow.importer.ImportAssets();
  446. ImportAssetWindow.importer.resetImportSession(true);
  447. }
  448. else
  449. {
  450. //we have assets to import, so go ahead and display the window for that now
  451. AssetImportCtrl.setHidden(false);
  452. ImportAssetWindow.visible = true;
  453. ImportAssetWindow.selectWindow();
  454. }
  455. if(ImportAssetWindow.hasImportIssues && getAssetImportConfigValue("General/PreventImportWithErrors", "0") == 1)
  456. {
  457. DoAssetImportButton.enabled = false;
  458. }
  459. else
  460. {
  461. DoAssetImportButton.enabled = true;
  462. }
  463. if(ImportAssetWindow.importConfigsList.count() == 0)
  464. {
  465. toolsMessageBoxOK( "Warning", "No base import config. Please create an import configuration set to simplify asset importing.");
  466. }
  467. %this.dirty = false;
  468. AssetBrowser.refresh();
  469. }
  470. function ImportAssetWindow::refreshAssetItem(%this, %assetItem, %parentTreeIdx)
  471. {
  472. if(!isObject(%assetItem) || %assetItem.skip)
  473. return;
  474. %assetType = %assetItem.assetType;
  475. %filePath = %assetItem.filePath;
  476. %assetName = %assetItem.assetName;
  477. //Once validated, attempt any fixes for issues
  478. ImportAssetWindow.importer.resolveAssetItemIssues(%assetItem);
  479. //create!
  480. %toolTip = "";
  481. if(%assetType $= "ShapeAsset" || %assetType $= "AnimationAsset" || %assetType $= "ImageAsset" || %assetType $= "SoundAsset")
  482. {
  483. if(%assetItem.status $= "Error")
  484. {
  485. %iconIdx = 11;
  486. }
  487. else if(%assetItem.status $= "Warning")
  488. {
  489. %iconIdx = 9;
  490. }
  491. %configCommand = "ImportAssetOptionsWindow.fixIssues(" @ %assetItem @ ");";
  492. if(%assetItem.statusType $= "DuplicateAsset" || %assetItem.statusType $= "DuplicateImportAsset")
  493. %assetName = %assetItem.assetName @ " <Duplicate Asset>";
  494. }
  495. else
  496. {
  497. if(%assetItem.status $= "Error")
  498. {
  499. %iconIdx = 11;
  500. }
  501. else if(%assetItem.status $= "Warning")
  502. {
  503. %iconIdx = 9;
  504. }
  505. if(%assetItem.statusType $= "DuplicateAsset" || %assetItem.statusType $= "DuplicateImportAsset")
  506. %assetName = %assetItem.assetName @ " <Duplicate Asset>";
  507. }
  508. %toolTip = %assetItem.statusInfo;
  509. if(%assetItem.status $= "")
  510. {
  511. if(%assetType $= "ShapeAsset")
  512. %iconIdx = 1;
  513. else if(%assetType $= "MaterialAsset")
  514. %iconIdx = 3;
  515. else if(%assetType $= "ImageAsset")
  516. %iconIdx = 5;
  517. else if(%assetType $= "SoundAsset")
  518. %iconIdx = 7;
  519. }
  520. if(%parentTreeIdx $= "")
  521. %parentTreeIdx = 1;
  522. %assetItem.treeIdx = AssetImportCtrl-->NewAssetsTree.insertItem(%parentTreeIdx, %assetName, %assetItem, "", %iconIdx, %iconIdx+1);
  523. for(%i=0; %i < ImportAssetWindow.importer.getAssetItemChildCount(%assetItem); %i++)
  524. {
  525. %childAssetItem = ImportAssetWindow.importer.getAssetItemChild(%assetItem, %i);
  526. %this.refreshAssetItem(%childAssetItem, %assetItem.treeIdx);
  527. }
  528. }
  529. //
  530. function NewAssetsViewTree::onSelect(%this, %itemId)
  531. {
  532. if(%itemId == 1)
  533. //can't select root
  534. return;
  535. %assetItem = %this.getItemValue(%itemId);
  536. AssetImportCtrl-->NewAssetsInspector.clearFields();
  537. AssetImportCtrl-->NewAssetsInspector.startGroup("General");
  538. AssetImportCtrl-->NewAssetsInspector.addField("assetName", "Asset Name", "string", "", %assetItem.assetName, "", %assetItem);
  539. AssetImportCtrl-->NewAssetsInspector.addField("assetType", "Asset Type", "string", "", %assetItem.assetType, "", %assetItem);
  540. if(!%assetItem.generatedAsset)
  541. AssetImportCtrl-->NewAssetsInspector.addField("filePath", "File Path", "fileName", "", %assetItem.filePath, "", %assetItem);
  542. //AssetImportCtrl-->NewAssetsInspector.addField("assetName", "Asset Name", "string", "", %assetItem.assetName, "", %assetItem);
  543. //AssetImportCtrl-->NewAssetsInspector.addField("assetName", "Asset Name", "string", "", %assetItem.assetName, "", %assetItem);
  544. AssetImportCtrl-->NewAssetsInspector.addField("status", "Status", "string", "", %assetItem.status, "", %assetItem);
  545. AssetImportCtrl-->NewAssetsInspector.addField("statusInfo", "Status Info", "string", "", %assetItem.statusInfo, "", %assetItem);
  546. AssetImportCtrl-->NewAssetsInspector.endGroup();
  547. AssetImportCtrl-->NewAssetsInspector.setFieldEnabled("assetType", false);
  548. if(AssetBrowser.isMethod("inspectImporting" @ %assetItem.assetType))
  549. {
  550. %command = "AssetBrowser.inspectImporting" @ %assetItem.assetType @ "(" @ %assetItem @ ");";
  551. eval(%command);
  552. }
  553. //AssetImportCtrl-->NewAssetsInspector.setFieldEnabled("status", false);
  554. /*moduleName = %moduleName;
  555. dirty = true;
  556. parentAssetItem = %parentAssetItem;
  557. status = "";
  558. statusType = "";
  559. statusInfo = "";
  560. skip = false;
  561. processed = false;
  562. generatedAsset = false;*/
  563. }
  564. function NewAssetsViewTree::onRightMouseDown(%this, %itemId)
  565. {
  566. ImportAssetActions.enableItem(1, true);
  567. if( %itemId != 1 && %itemId != -1)
  568. {
  569. %assetItem = %this.getItemValue(%itemId);
  570. if(%assetItem.assetType $= "MaterialAsset")
  571. {
  572. %contextPopup = ImportAssetMaterialMaps;
  573. for(%i=0; %i < 7; %i++)
  574. {
  575. %contextPopup.enableItem(%i, true);
  576. }
  577. if(isObject(%assetItem.diffuseImageAsset))
  578. %contextPopup.enableItem(0, false);
  579. if(isObject(%assetItem.normalImageAsset))
  580. %contextPopup.enableItem(1, false);
  581. if(isObject(%assetItem.compositeImageAsset))
  582. %contextPopup.enableItem(2, false);
  583. }
  584. else
  585. {
  586. %contextPopup = ImportAssetActions;
  587. }
  588. %contextPopup.showPopup(Canvas);
  589. %contextPopup.assetItem = %assetItem;
  590. %contextPopup.itemId = %itemId;
  591. }
  592. else
  593. {
  594. ImportAssetActions.showPopup(Canvas);
  595. }
  596. }
  597. function NewAssetsPanelInputs::onRightMouseDown(%this)
  598. {
  599. NewAssetsViewTree::onRightMouseDown(0, -1);
  600. }
  601. //
  602. function ImportAssetWindow::removeImportingAsset(%this)
  603. {
  604. %this.importer.deleteImportingAsset(ImportAssetActions.assetItem);
  605. }
  606. function ImportAssetWindow::addNewImportingAsset(%this, %filterType)
  607. {
  608. %filter = "Any Files (*.*)|*.*|";
  609. if(%filterType $= "Sound" || %filterType $= "")
  610. %filter = "Sound Files(*.wav, *.ogg)|*.wav;*.ogg|" @ %filter;
  611. if(%filterType $= "Image" || %filterType $= "")
  612. %filter = "Images Files(*.jpg,*.png,*.tga,*.bmp,*.dds)|*.jpg;*.png;*.tga;*.bmp;*.dds|" @ %filter;
  613. if(%filterType $= "Shape" || %filterType $= "")
  614. %filter = "Shape Files(*.dae, *.cached.dts)|*.dae;*.cached.dts|" @ %filter;
  615. //get our item depending on which action we're trying for
  616. if(ImportAssetActions.visible)
  617. %parentAssetItem = ImportAssetActions.assetItem;
  618. else if(ImportAssetMaterialMaps.visible)
  619. %parentAssetItem = ImportAssetMaterialMaps.assetItem;
  620. %defaultPath = filePath(%parentAssetItem.filePath) @ "/";
  621. %dlg = new OpenFileDialog()
  622. {
  623. Filters = %filter;
  624. DefaultFile = %defaultPath;
  625. ChangePath = false;
  626. MustExist = true;
  627. MultipleFiles = false;
  628. forceRelativePath = false;
  629. };
  630. if ( %dlg.Execute() )
  631. {
  632. %filePath = %dlg.FileName;
  633. }
  634. %dlg.delete();
  635. if(%filePath $= "")
  636. return "";
  637. //AssetBrowser.onDropFile( %path );
  638. %fileExt = fileExt( %filePath );
  639. %fileName = fileName(%filePath);
  640. if(%fileExt $= ".dts" && endsWith(%fileName, ".cached"))
  641. return "";
  642. //add it to our array!
  643. if(isImageFormat(%fileExt))
  644. %type = "ImageAsset";
  645. else if( isShapeFormat(%fileExt))
  646. %type = "ShapeAsset";
  647. else if( isSoundFormat(%fileExt))
  648. %type = "SoundAsset";
  649. else if( %fileExt $= "." @ $TorqueScriptFileExtension || %fileExt $= "." @ $TorqueScriptFileExtension @ ".dso" )
  650. %type = "ScriptAsset";
  651. else if( %fileExt $= ".gui" || %fileExt $= ".gui.dso" )
  652. %type = "GUIAsset";
  653. %newAssetItem = AssetBrowser.addImportingAsset(%type, %filePath, %parentAssetItem);
  654. //Used to keep tabs on what files we were trying to import, used mainly in the event of
  655. //adjusting configs and needing to completely reprocess the import
  656. //ensure we're not doubling-up on files by accident
  657. if(%this.importingFilesArray.getIndexFromKey(%filePath) == -1)
  658. %this.importingFilesArray.add(%filePath);
  659. AssetBrowser.onEndDropFiles();
  660. return %newAssetItem;
  661. }
  662. function ImportAssetWindow::addMaterialMap(%this, %map)
  663. {
  664. %newAssetItem = %this.addNewImportingAsset("Image");
  665. %newAssetItem.ImageType = %map;
  666. }
  667. //
  668. function ImportAssetWindow::ImportAssets(%this)
  669. {
  670. //get the selected module data
  671. if(%this.importer.targetModuleId $= "")
  672. {
  673. %moduleName = AssetImportTargetModule.getText();
  674. %module = ModuleDatabase.findModule(%moduleName, 1);
  675. if(!isObject(%module))
  676. {
  677. toolsMessageBoxOK( "Error!", "No module selected. You must select or create a module for the assets to be added to.");
  678. return;
  679. }
  680. displayEditorLoadingGui("Importing Assets...");
  681. %this.importer.targetModuleId = %moduleName;
  682. }
  683. %this.importer.targetPath = AssetImportTargetAddress.getText();
  684. %this.importer.importAssets();
  685. //force an update of any and all modules so we have an up-to-date asset list
  686. AssetBrowser.refresh();
  687. Canvas.popDialog(AssetImportCtrl);
  688. AssetBrowser.isAssetReImport = false;
  689. %this.importer.resetImportSession(true);
  690. hideEditorLoadingGui();
  691. //do the actual importing, now!
  692. /*%assetCount = ImportAssetItems.count();
  693. %this.doImportAssets();
  694. //force an update of any and all modules so we have an up-to-date asset list
  695. AssetBrowser.refresh();
  696. Canvas.popDialog(AssetImportCtrl);
  697. AssetBrowser.isAssetReImport = false;*/
  698. }
  699. function ImportAssetWindow::findMissingFile(%this, %assetItem)
  700. {
  701. if(%assetItem.assetType $= "ShapeAsset")
  702. %filters = "Shape Files(*.dae, *.cached.dts)|*.dae;*.cached.dts";
  703. else if(%assetItem.assetType $= "ImageAsset")
  704. %filters = "Images Files(*.jpg,*.png,*.tga,*.bmp,*.dds)|*.jpg;*.png;*.tga;*.bmp;*.dds";
  705. %dlg = new OpenFileDialog()
  706. {
  707. Filters = %filters;
  708. DefaultPath = $Pref::WorldEditor::LastPath;
  709. DefaultFile = "";
  710. ChangePath = true;
  711. OverwritePrompt = true;
  712. forceRelativePath = false;
  713. fileName="";
  714. //MultipleFiles = true;
  715. };
  716. %ret = %dlg.Execute();
  717. if ( %ret )
  718. {
  719. $Pref::WorldEditor::LastPath = filePath( %dlg.FileName );
  720. %fullPath = %dlg.FileName;//makeRelativePath( %dlg.FileName, getMainDotCSDir() );
  721. }
  722. %dlg.delete();
  723. if ( !%ret )
  724. return;
  725. %assetItem.filePath = %fullPath;
  726. %assetItem.assetName = fileBase(%assetItem.filePath);
  727. /*if(%assetItem.assetType $= "ImageAsset")
  728. {
  729. //See if we have anything important to update for our material parent(if we have one)
  730. %treeItem = ImportAssetTree.findItemByObjectId(%assetItem);
  731. %parentItem = ImportAssetTree.getParentItem(%treeItem);
  732. if(%parentItem != 0)
  733. {
  734. %parentAssetItem = ImportAssetTree.getItemObject(%parentItem);
  735. if(%parentAssetItem.assetType $= "MaterialAsset")
  736. {
  737. AssetBrowser.prepareImportMaterialAsset(%parentAssetItem);
  738. }
  739. }
  740. }*/
  741. ImportAssetWindow.refresh();
  742. }
  743. //
  744. //
  745. function ImportAssetWindow::toggleLogWindow()
  746. {
  747. if(AssetBrowserImportLog.isAwake())
  748. {
  749. Canvas.popDialog(AssetBrowserImportLog);
  750. return;
  751. }
  752. else
  753. {
  754. Canvas.pushDialog(AssetBrowserImportLog);
  755. }
  756. ImportLogTextList.clear();
  757. for(%i=0; %i < ImportAssetWindow.importer.getActivityLogLineCount(); %i++)
  758. {
  759. ImportLogTextList.addRow(%i,ImportAssetWindow.importer.getActivityLogLine(%i));
  760. }
  761. }
  762. //
  763. //
  764. function ImportAssetModuleList::onWake(%this)
  765. {
  766. %this.refresh();
  767. }
  768. function ImportAssetModuleList::refresh(%this)
  769. {
  770. %this.clear();
  771. //First, get our list of modules
  772. %moduleList = ModuleDatabase.findModules();
  773. %count = getWordCount(%moduleList);
  774. for(%i=0; %i < %count; %i++)
  775. {
  776. %moduleName = getWord(%moduleList, %i);
  777. %this.add(%moduleName.ModuleId, %i);
  778. }
  779. }
  780. //
  781. //
  782. function toggleImportWindowViz()
  783. {
  784. %value = EditorSettings.value("Assets/AutoImport");
  785. EditorSettings.setValue("Assets/AutoImport", !%value);
  786. }
  787. //