assetImporter.cpp 143 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431
  1. #include "assetImporter.h"
  2. #include "assetImporter_ScriptBinding.h"
  3. #include "core/strings/findMatch.h"
  4. #include "ImageAsset.h"
  5. #include "ShapeAsset.h"
  6. #include "SoundAsset.h"
  7. #include "MaterialAsset.h"
  8. #include "ShapeAnimationAsset.h"
  9. #include "ts/collada/colladaUtils.h"
  10. #include "ts/collada/colladaAppNode.h"
  11. #include "ts/collada/colladaShapeLoader.h"
  12. #include "ts/assimp/assimpShapeLoader.h"
  13. #include "ts/tsShapeConstruct.h"
  14. #include "core/resourceManager.h"
  15. #include "materials/materialManager.h"
  16. #include "console/persistenceManager.h"
  17. ConsoleDocClass(AssetImportConfig,
  18. "@brief Defines properties for an AssetImprotConfig object.\n"
  19. "@AssetImportConfig is a SimObject derived object intended to act as a container for all the necessary configuration data when running the Asset Importer.\n"
  20. "@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\n"
  21. "@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\n"
  22. "@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\n"
  23. "@of import to avoid as much manual post-processing as possible.\n\n"
  24. "@ingroup Assets\n"
  25. );
  26. IMPLEMENT_CONOBJECT(AssetImportConfig);
  27. AssetImportConfig::AssetImportConfig() :
  28. DuplicateAutoResolution("AutoRename"),
  29. WarningsAsErrors(false),
  30. PreventImportWithErrors(true),
  31. AutomaticallyPromptMissingFiles(false),
  32. AddDirectoryPrefixToAssetName(false),
  33. ImportMesh(true),
  34. AlwaysAddShapeSuffix(false),
  35. AddedShapeSuffix("_shape"),
  36. UseManualShapeConfigRules(false),
  37. DoUpAxisOverride(false),
  38. UpAxisOverride("Z_AXIS"),
  39. DoScaleOverride(false),
  40. ScaleOverride(false),
  41. IgnoreNodeScale(false),
  42. AdjustCenter(false),
  43. AdjustFloor(false),
  44. CollapseSubmeshes(false),
  45. LODType("TrailingNumber"),
  46. AlwaysImportedNodes(""),
  47. AlwaysIgnoreNodes(""),
  48. AlwaysImportMeshes(""),
  49. AlwaysIgnoreMeshes(""),
  50. convertLeftHanded(false),
  51. calcTangentSpace(false),
  52. removeRedundantMats(false),
  53. genUVCoords(false),
  54. TransformUVs(false),
  55. flipUVCoords(false),
  56. findInstances(false),
  57. limitBoneWeights(false),
  58. JoinIdenticalVerts(false),
  59. reverseWindingOrder(false),
  60. invertNormals(false),
  61. ImportMaterials(true),
  62. AlwaysAddMaterialSuffix(true),
  63. AddedMaterialSuffix("_mat"),
  64. CreateORMConfig(true),
  65. UseDiffuseSuffixOnOriginImage(false),
  66. UseExistingMaterials(false),
  67. IgnoreMaterials(""),
  68. PopulateMaterialMaps(true),
  69. ImportAnimations(true),
  70. SeparateAnimations(false),
  71. SeparateAnimationPrefix(""),
  72. animTiming("FrameCount"),
  73. animFPS(false),
  74. GenerateCollisions(false),
  75. GenCollisionType(""),
  76. CollisionMeshPrefix(""),
  77. GenerateLOSCollisions(false),
  78. GenLOSCollisionType(""),
  79. LOSCollisionMeshPrefix(""),
  80. importImages(true),
  81. AlwaysAddImageSuffix(true),
  82. AddedImageSuffix("_image"),
  83. ImageType("GUI"),
  84. DiffuseTypeSuffixes("_ALBEDO,_DIFFUSE,_ALB,_DIF,_COLOR,_COL,_A,_C,-ALBEDO,-DIFFUSE,-ALB,-DIF,-COLOR,-COL,-A,-C"),
  85. NormalTypeSuffixes("_NORMAL,_NORM,_N,-NORMAL,-NORM,-N"),
  86. MetalnessTypeSuffixes("_METAL,_MET,_METALNESS,_METALLIC,_M,-METAL,-MET,-METALNESS,-METALLIC,-M"),
  87. RoughnessTypeSuffixes("_ROUGH,_ROUGHNESS,_R,-ROUGH,-ROUGHNESS,-R"),
  88. SmoothnessTypeSuffixes("_SMOOTH,_SMOOTHNESS,_S,-SMOOTH,-SMOOTHNESS,-S"),
  89. AOTypeSuffixes("_AO,_AMBIENT,_AMBIENTOCCLUSION,-AO,-AMBIENT,-AMBIENTOCCLUSION"),
  90. PBRTypeSuffixes("_COMP,_COMPOSITE,_PBR,-COMP,-COMPOSITE,-PBR,_ORM,-ORM"),
  91. TextureFilteringMode("Bilinear"),
  92. UseMips(true),
  93. IsHDR(false),
  94. Scaling(false),
  95. ImagesCompressed(false),
  96. GenerateMaterialOnImport(true),
  97. importSounds(true),
  98. VolumeAdjust(false),
  99. PitchAdjust(false),
  100. SoundsCompressed(false)
  101. {
  102. }
  103. AssetImportConfig::~AssetImportConfig()
  104. {
  105. }
  106. bool AssetImportConfig::onAdd()
  107. {
  108. if (!Parent::onAdd())
  109. return false;
  110. return true;
  111. }
  112. void AssetImportConfig::onRemove()
  113. {
  114. Parent::onRemove();
  115. }
  116. /// Engine.
  117. void AssetImportConfig::initPersistFields()
  118. {
  119. Parent::initPersistFields();
  120. addGroup("General");
  121. addField("DuplicateAutoResolution", TypeRealString, Offset(DuplicateAutoResolution, AssetImportConfig), "Duplicate Asset Auto-Resolution Action. Options are None, AutoPrune, AutoRename, FolderPrefix");
  122. addField("WarningsAsErrors", TypeBool, Offset(WarningsAsErrors, AssetImportConfig), "Indicates if warnings should be treated as errors");
  123. addField("PreventImportWithErrors", TypeBool, Offset(PreventImportWithErrors, AssetImportConfig), "Indicates if importing should be prevented from completing if any errors are detected at all");
  124. addField("AutomaticallyPromptMissingFiles", TypeBool, Offset(AutomaticallyPromptMissingFiles, AssetImportConfig), "Should the importer automatically prompt to find missing files if they are not detected automatically by the importer");
  125. addField("AddDirectoryPrefixToAssetName", TypeBool, Offset(AddDirectoryPrefixToAssetName, AssetImportConfig), "Should the importer add the folder name as a prefix to the assetName. Helps prevent name collisions.");
  126. endGroup("General");
  127. addGroup("Meshes");
  128. addField("ImportMesh", TypeBool, Offset(ImportMesh, AssetImportConfig), "Indicates if this config supports importing meshes");
  129. addField("AlwaysAddShapeSuffix", TypeBool, Offset(AlwaysAddShapeSuffix, AssetImportConfig), "When importing a shape, this indicates if it should automatically add a standard suffix onto the name");
  130. addField("AddedShapeSuffix", TypeString, Offset(AddedShapeSuffix, AssetImportConfig), " If AlwaysAddShapeSuffix is on, this is the suffix to be added");
  131. addField("UseManualShapeConfigRules", TypeBool, Offset(UseManualShapeConfigRules, AssetImportConfig), "Indicates if this config should override the per-format sis files with the config's specific settings");
  132. addField("DoUpAxisOverride", TypeBool, Offset(DoUpAxisOverride, AssetImportConfig), "Indicates if the up axis in the model file should be overridden");
  133. addField("UpAxisOverride", TypeRealString, Offset(UpAxisOverride, AssetImportConfig), "If overriding, what axis should be used as up. Options are X_AXIS, Y_AXIS, Z_AXIS");
  134. addField("DoScaleOverride", TypeBool, Offset(DoScaleOverride, AssetImportConfig), "Indicates if the scale in the model file should be overridden");
  135. addField("ScaleOverride", TypeF32, Offset(ScaleOverride, AssetImportConfig), "If overriding, what scale should be used");
  136. addField("IgnoreNodeScale", TypeBool, Offset(IgnoreNodeScale, AssetImportConfig), "Indicates if scale of nodes should be ignored");
  137. addField("AdjustCenter", TypeBool, Offset(AdjustCenter, AssetImportConfig), "Indicates if the center of the model file should be automatically recentered");
  138. addField("AdjustFloor", TypeBool, Offset(AdjustFloor, AssetImportConfig), "Indicates if the floor height of the model file should be automatically zero'd");
  139. addField("CollapseSubmeshes", TypeBool, Offset(CollapseSubmeshes, AssetImportConfig), "Indicates if submeshes should be collapsed down into a single main mesh");
  140. addField("LODType", TypeRealString, Offset(LODType, AssetImportConfig), "Indicates what LOD mode the model file should utilize to process out LODs. Options are TrailingNumber, DetectDTS, SingleSize");
  141. addField("AlwaysImportedNodes", TypeRealString, Offset(AlwaysImportedNodes, AssetImportConfig), " A list of what nodes should be guaranteed to be imported if found in the model file. Separated by either , or ;");
  142. addField("AlwaysIgnoreNodes", TypeRealString, Offset(AlwaysIgnoreNodes, AssetImportConfig), "A list of what nodes should be guaranteed to not be imported if found in the model file. Separated by either , or ;");
  143. addField("AlwaysImportMeshes", TypeRealString, Offset(AlwaysImportMeshes, AssetImportConfig), "A list of what mesh objects should be guaranteed to be imported if found in the model file. Separated by either , or ;");
  144. addField("AlwaysIgnoreMeshes", TypeRealString, Offset(AlwaysIgnoreMeshes, AssetImportConfig), "A list of what mesh objects should be guaranteed to not be imported if found in the model file. Separated by either , or ;");
  145. addField("convertLeftHanded", TypeBool, Offset(convertLeftHanded, AssetImportConfig), "Flag to indicate the shape loader should convert to a left-handed coordinate system");
  146. addField("calcTangentSpace", TypeBool, Offset(calcTangentSpace, AssetImportConfig), "Should the shape loader calculate tangent space values");
  147. addField("removeRedundantMats", TypeBool, Offset(removeRedundantMats, AssetImportConfig), "Should the shape loader automatically prune redundant/duplicate materials");
  148. addField("genUVCoords", TypeBool, Offset(genUVCoords, AssetImportConfig), "Should the shape loader auto-generate UV Coordinates for the mesh.");
  149. addField("TransformUVs", TypeBool, Offset(TransformUVs, AssetImportConfig), "Should the UV coordinates be transformed");
  150. addField("flipUVCoords", TypeBool, Offset(flipUVCoords, AssetImportConfig), "Should the UV coordinates be flipped");
  151. addField("findInstances", TypeBool, Offset(findInstances, AssetImportConfig), "Should the shape loader automatically look for instanced submeshes in the model file");
  152. addField("limitBoneWeights", TypeBool, Offset(limitBoneWeights, AssetImportConfig), "Should the shape loader limit the bone weights");
  153. addField("JoinIdenticalVerts", TypeBool, Offset(JoinIdenticalVerts, AssetImportConfig), "Should the shape loader automatically merge identical/duplicate verts");
  154. addField("reverseWindingOrder", TypeBool, Offset(reverseWindingOrder, AssetImportConfig), "Should the shape loader reverse the winding order of the mesh's face indicies");
  155. addField("invertNormals", TypeBool, Offset(invertNormals, AssetImportConfig), "Should the normals on the model be inverted");
  156. endGroup("Meshes");
  157. addGroup("Materials");
  158. addField("ImportMaterials", TypeBool, Offset(ImportMaterials, AssetImportConfig), "Does this config allow for importing of materials");
  159. addField("AlwaysAddMaterialSuffix", TypeBool, Offset(AlwaysAddMaterialSuffix, AssetImportConfig), "When importing a material, this indicates if it should automatically add a standard suffix onto the name");
  160. addField("AddedMaterialSuffix", TypeString, Offset(AddedMaterialSuffix, AssetImportConfig), " If AlwaysAddMaterialSuffix is on, this is the suffix to be added");
  161. addField("CreateORMConfig", TypeBool, Offset(PreventImportWithErrors, AssetImportConfig), "When importing a material, should it automatically attempt to merge Roughness, AO and Metalness maps into a single, composited PBR Configuration map");
  162. addField("UseDiffuseSuffixOnOriginImage", TypeBool, Offset(UseDiffuseSuffixOnOriginImage, AssetImportConfig), "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.\n e.g. MyCoolStuff.png is imported, generating MyCoolStuff material asset and MyCoolStuff_Diffuse image asset");
  163. addField("UseExistingMaterials", TypeBool, Offset(UseExistingMaterials, AssetImportConfig), "Should the importer try and use existing material assets in the game directory if at all possible. (Not currently utilized)");
  164. addField("IgnoreMaterials", TypeRealString, Offset(IgnoreMaterials, AssetImportConfig), "A list of material names that should not be imported. Separated by either , or ;");
  165. addField("PopulateMaterialMaps", TypeBool, Offset(PopulateMaterialMaps, AssetImportConfig), "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.\n 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");
  166. endGroup("Materials");
  167. addGroup("Animation");
  168. addField("ImportAnimations", TypeBool, Offset(ImportAnimations, AssetImportConfig), "Does this config allow for importing Shape Animations");
  169. addField("SeparateAnimations", TypeBool, Offset(SeparateAnimations, AssetImportConfig), "When importing a shape file, should the animations within be separated out into unique files");
  170. addField("SeparateAnimationPrefix", TypeRealString, Offset(SeparateAnimationPrefix, AssetImportConfig), "If separating animations out from a source file, what prefix should be added to the names for grouping association");
  171. addField("animTiming", TypeRealString, Offset(animTiming, AssetImportConfig), "Defines the animation timing for the given animation sequence. Options are FrameTime, Seconds, Milliseconds");
  172. addField("animFPS", TypeBool, Offset(animFPS, AssetImportConfig), "The FPS of the animation sequence");
  173. endGroup("Animation");
  174. addGroup("Collision");
  175. addField("GenerateCollisions", TypeBool, Offset(GenerateCollisions, AssetImportConfig), "Does this configuration generate collision geometry when importing. (Not currently enabled)");
  176. addField("GenCollisionType", TypeRealString, Offset(GenCollisionType, AssetImportConfig), "What sort of collision geometry is generated. (Not currently enabled)");
  177. addField("CollisionMeshPrefix", TypeRealString, Offset(CollisionMeshPrefix, AssetImportConfig), "What prefix is added to the collision geometry generated. (Not currently enabled)");
  178. addField("GenerateLOSCollisions", TypeBool, Offset(GenerateLOSCollisions, AssetImportConfig), "Does this configuration generate Line of Sight collision geometry. (Not currently enabled)");
  179. addField("GenLOSCollisionType", TypeRealString, Offset(GenLOSCollisionType, AssetImportConfig), "What sort of Line of Sight collision geometry is generated. (Not currently enabled)");
  180. addField("LOSCollisionMeshPrefix", TypeRealString, Offset(LOSCollisionMeshPrefix, AssetImportConfig), "What prefix is added to the Line of Sight collision geometry generated. (Not currently enabled)");
  181. endGroup("Collision");
  182. addGroup("Images");
  183. addField("importImages", TypeBool, Offset(importImages, AssetImportConfig), "Does this configuration support importing images.");
  184. addField("AlwaysAddImageSuffix", TypeBool, Offset(AlwaysAddImageSuffix, AssetImportConfig), "When importing an image, this indicates if it should automatically add a standard suffix onto the name");
  185. addField("AddedImageSuffix", TypeString, Offset(AddedImageSuffix, AssetImportConfig), " If AlwaysAddImageSuffix is on, this is the suffix to be added");
  186. addField("ImageType", TypeRealString, Offset(ImageType, AssetImportConfig), "What is the default ImageType images are imported as. Options are: N/A, Diffuse, Normal, Metalness, Roughness, AO, ORMConfig, GUI, Cubemap");
  187. addField("DiffuseTypeSuffixes", TypeRealString, Offset(DiffuseTypeSuffixes, AssetImportConfig), "What type of suffixes are scanned to detect if an importing image is a diffuse map. \n e.g. _Albedo or _Color");
  188. addField("NormalTypeSuffixes", TypeRealString, Offset(NormalTypeSuffixes, AssetImportConfig), "What type of suffixes are scanned to detect if an importing image is a normal map. \n e.g. _Normal or _Norm");
  189. addField("MetalnessTypeSuffixes", TypeRealString, Offset(MetalnessTypeSuffixes, AssetImportConfig), "What type of suffixes are scanned to detect if an importing image is a metalness map. \n e.g. _Metalness or _Metal");
  190. addField("RoughnessTypeSuffixes", TypeRealString, Offset(RoughnessTypeSuffixes, AssetImportConfig), "What type of suffixes are scanned to detect if an importing image is a roughness map.\n e.g. _roughness or _rough");
  191. addField("SmoothnessTypeSuffixes", TypeRealString, Offset(SmoothnessTypeSuffixes, AssetImportConfig), "What type of suffixes are scanned to detect if an importing image is a smoothness map. \n e.g. _smoothness or _smooth");
  192. addField("AOTypeSuffixes", TypeRealString, Offset(AOTypeSuffixes, AssetImportConfig), "What type of suffixes are scanned to detect if an importing image is a ambient occlusion map. \n e.g. _ambient or _ao");
  193. addField("PBRTypeSuffixes", TypeRealString, Offset(PBRTypeSuffixes, AssetImportConfig), "What type of suffixes are scanned to detect if an importing image is a ORMConfig map.\n e.g. _Composite or _PBR");
  194. addField("TextureFilteringMode", TypeRealString, Offset(TextureFilteringMode, AssetImportConfig), "Indicates what filter mode images imported with this configuration utilizes. Options are Linear, Bilinear, Trilinear");
  195. addField("UseMips", TypeBool, Offset(UseMips, AssetImportConfig), "Indicates if images imported with this configuration utilize mipmaps");
  196. addField("IsHDR", TypeBool, Offset(IsHDR, AssetImportConfig), "Indicates if images imported with this configuration are in an HDR format");
  197. addField("Scaling", TypeF32, Offset(Scaling, AssetImportConfig), "Indicates what amount of scaling images imported with this configuration use");
  198. addField("ImagesCompressed", TypeBool, Offset(ImagesCompressed, AssetImportConfig), "Indicates if images imported with this configuration are compressed");
  199. addField("GenerateMaterialOnImport", TypeBool, Offset(GenerateMaterialOnImport, AssetImportConfig), "Indicates if images imported with this configuration generate a parent material for it as well");
  200. endGroup("Images");
  201. addGroup("Sounds");
  202. addField("importSounds", TypeBool, Offset(importSounds, AssetImportConfig), "Indicates if sounds are imported with this configuration");
  203. addField("VolumeAdjust", TypeF32, Offset(VolumeAdjust, AssetImportConfig), "Indicates what amount the volume is adjusted on sounds imported with this configuration");
  204. addField("PitchAdjust", TypeF32, Offset(PitchAdjust, AssetImportConfig), "Indicates what amount the pitch is adjusted on sounds imported with this configuration");
  205. addField("SoundsCompressed", TypeBool, Offset(SoundsCompressed, AssetImportConfig), "Indicates if sounds imported with this configuration are compressed");
  206. endGroup("Sounds");
  207. }
  208. void AssetImportConfig::loadImportConfig(Settings* configSettings, String configName)
  209. {
  210. //General
  211. DuplicateAutoResolution = configSettings->value(String(configName + "/General/DuplicateAutoResolution").c_str());
  212. WarningsAsErrors = dAtob(configSettings->value(String(configName + "/General/WarningsAsErrors").c_str()));
  213. PreventImportWithErrors = dAtob(configSettings->value(String(configName + "/General/PreventImportWithErrors").c_str()));
  214. AutomaticallyPromptMissingFiles = dAtob(configSettings->value(String(configName + "/General/AutomaticallyPromptMissingFiles").c_str()));
  215. AddDirectoryPrefixToAssetName = dAtob(configSettings->value(String(configName + "/General/AddDirectoryPrefixToAssetName").c_str()));
  216. //Meshes
  217. ImportMesh = dAtob(configSettings->value(String(configName + "/Meshes/ImportMesh").c_str()));
  218. AlwaysAddShapeSuffix = dAtob(configSettings->value(String(configName + "/Meshes/AlwaysAddShapeSuffix").c_str()));
  219. AddedShapeSuffix = configSettings->value(String(configName + "/Meshes/AddedShapeSuffix").c_str());
  220. UseManualShapeConfigRules = dAtob(configSettings->value(String(configName + "/Meshes/UseManualShapeConfigRules").c_str()));
  221. DoUpAxisOverride = dAtob(configSettings->value(String(configName + "/Meshes/DoUpAxisOverride").c_str()));
  222. UpAxisOverride = configSettings->value(String(configName + "/Meshes/UpAxisOverride").c_str());
  223. DoScaleOverride = dAtob(configSettings->value(String(configName + "/Meshes/DoScaleOverride").c_str()));
  224. ScaleOverride = dAtof(configSettings->value(String(configName + "/Meshes/ScaleOverride").c_str()));
  225. IgnoreNodeScale = dAtob(configSettings->value(String(configName + "/Meshes/IgnoreNodeScale").c_str()));
  226. AdjustCenter = dAtob(configSettings->value(String(configName + "/Meshes/AdjustCenter").c_str()));
  227. AdjustFloor = dAtob(configSettings->value(String(configName + "/Meshes/AdjustFloor").c_str()));
  228. CollapseSubmeshes = dAtob(configSettings->value(String(configName + "/Meshes/CollapseSubmeshes").c_str()));
  229. LODType = configSettings->value(String(configName + "/Meshes/LODType").c_str());
  230. AlwaysImportedNodes = configSettings->value(String(configName + "/Meshes/AlwaysImportedNodes").c_str());
  231. AlwaysIgnoreNodes = configSettings->value(String(configName + "/Meshes/AlwaysIgnoreNodes").c_str());
  232. AlwaysImportMeshes = configSettings->value(String(configName + "/Meshes/AlwaysImportMeshes").c_str());
  233. AlwaysIgnoreMeshes = configSettings->value(String(configName + "/Meshes/AlwaysIgnoreMeshes").c_str());
  234. //Assimp/Collada
  235. convertLeftHanded = dAtob(configSettings->value(String(configName + "/Meshes/convertLeftHanded").c_str()));
  236. calcTangentSpace = dAtob(configSettings->value(String(configName + "/Meshes/calcTangentSpace").c_str()));
  237. removeRedundantMats = dAtob(configSettings->value(String(configName + "/Meshes/removeRedundantMats").c_str()));
  238. genUVCoords = dAtob(configSettings->value(String(configName + "/Meshes/genUVCoords").c_str()));
  239. TransformUVs = dAtob(configSettings->value(String(configName + "/Meshes/TransformUVs").c_str()));
  240. flipUVCoords = dAtob(configSettings->value(String(configName + "/Meshes/flipUVCoords").c_str()));
  241. findInstances = dAtob(configSettings->value(String(configName + "/Meshes/findInstances").c_str()));
  242. limitBoneWeights = dAtob(configSettings->value(String(configName + "/Meshes/limitBoneWeights").c_str()));
  243. JoinIdenticalVerts = dAtob(configSettings->value(String(configName + "/Meshes/JoinIdenticalVerts").c_str()));
  244. reverseWindingOrder = dAtob(configSettings->value(String(configName + "/Meshes/reverseWindingOrder").c_str()));
  245. invertNormals = dAtob(configSettings->value(String(configName + "/Meshes/invertNormals").c_str()));
  246. //Materials
  247. ImportMaterials = dAtob(configSettings->value(String(configName + "/Materials/ImportMaterials").c_str()));
  248. AlwaysAddMaterialSuffix = dAtob(configSettings->value(String(configName + "/Materials/AlwaysAddMaterialSuffix").c_str()));
  249. AddedMaterialSuffix = configSettings->value(String(configName + "/Materials/AddedMaterialSuffix").c_str());
  250. CreateORMConfig = dAtob(configSettings->value(String(configName + "/Materials/CreateORMConfig").c_str()));
  251. UseDiffuseSuffixOnOriginImage = dAtob(configSettings->value(String(configName + "/Materials/UseDiffuseSuffixOnOriginImage").c_str()));
  252. UseExistingMaterials = dAtob(configSettings->value(String(configName + "/Materials/UseExistingMaterials").c_str()));
  253. IgnoreMaterials = configSettings->value(String(configName + "/Materials/IgnoreMaterials").c_str());
  254. PopulateMaterialMaps = dAtob(configSettings->value(String(configName + "/Materials/PopulateMaterialMaps").c_str()));
  255. //Animations
  256. ImportAnimations = dAtob(configSettings->value(String(configName + "/Animations/ImportAnimations").c_str()));
  257. SeparateAnimations = dAtob(configSettings->value(String(configName + "/Animations/SeparateAnimations").c_str()));
  258. SeparateAnimationPrefix = configSettings->value(String(configName + "/Animations/SeparateAnimationPrefix").c_str());
  259. animTiming = configSettings->value(String(configName + "/Animations/animTiming").c_str());
  260. animFPS = dAtof(configSettings->value(String(configName + "/Animations/animFPS").c_str()));
  261. //Collisions
  262. GenerateCollisions = dAtob(configSettings->value(String(configName + "/Collision/GenerateCollisions").c_str()));
  263. GenCollisionType = configSettings->value(String(configName + "/Collision/GenCollisionType").c_str());
  264. CollisionMeshPrefix = configSettings->value(String(configName + "/Collision/CollisionMeshPrefix").c_str());
  265. GenerateLOSCollisions = dAtob(configSettings->value(String(configName + "/Collision/GenerateLOSCollisions").c_str()));
  266. GenLOSCollisionType = configSettings->value(String(configName + "/Collision/GenLOSCollisionType").c_str());
  267. LOSCollisionMeshPrefix = configSettings->value(String(configName + "/Collision/LOSCollisionMeshPrefix").c_str());
  268. //Images
  269. importImages = dAtob(configSettings->value(String(configName + "/Images/importImages").c_str()));
  270. AlwaysAddImageSuffix = dAtob(configSettings->value(String(configName + "/Images/AlwaysAddImageSuffix").c_str()));
  271. AddedImageSuffix = configSettings->value(String(configName + "/Images/AddedImageSuffix").c_str());
  272. ImageType = configSettings->value(String(configName + "/Images/ImageType").c_str());
  273. DiffuseTypeSuffixes = configSettings->value(String(configName + "/Images/DiffuseTypeSuffixes").c_str());
  274. NormalTypeSuffixes = configSettings->value(String(configName + "/Images/NormalTypeSuffixes").c_str());
  275. MetalnessTypeSuffixes = configSettings->value(String(configName + "/Images/MetalnessTypeSuffixes").c_str());
  276. RoughnessTypeSuffixes = configSettings->value(String(configName + "/Images/RoughnessTypeSuffixes").c_str());
  277. SmoothnessTypeSuffixes = configSettings->value(String(configName + "/Images/SmoothnessTypeSuffixes").c_str());
  278. AOTypeSuffixes = configSettings->value(String(configName + "/Images/AOTypeSuffixes").c_str());
  279. PBRTypeSuffixes = configSettings->value(String(configName + "/Images/PBRTypeSuffixes").c_str());
  280. TextureFilteringMode = configSettings->value(String(configName + "/Images/TextureFilteringMode").c_str());
  281. UseMips = dAtob(configSettings->value(String(configName + "/Images/UseMips").c_str()));
  282. IsHDR = dAtob(configSettings->value(String(configName + "/Images/IsHDR").c_str()));
  283. Scaling = dAtof(configSettings->value(String(configName + "/Images/Scaling").c_str()));
  284. ImagesCompressed = dAtob(configSettings->value(String(configName + "/Images/Compressed").c_str()));
  285. GenerateMaterialOnImport = dAtob(configSettings->value(String(configName + "/Images/GenerateMaterialOnImport").c_str()));
  286. //Sounds
  287. VolumeAdjust = dAtof(configSettings->value(String(configName + "/Sounds/VolumeAdjust").c_str()));
  288. PitchAdjust = dAtof(configSettings->value(String(configName + "/Sounds/PitchAdjust").c_str()));
  289. SoundsCompressed = dAtob(configSettings->value(String(configName + "/Sounds/Compressed").c_str()));
  290. }
  291. void AssetImportConfig::CopyTo(AssetImportConfig* target) const
  292. {
  293. target->DuplicateAutoResolution = DuplicateAutoResolution;
  294. target->WarningsAsErrors = WarningsAsErrors;
  295. target->PreventImportWithErrors = PreventImportWithErrors;
  296. target->AutomaticallyPromptMissingFiles = AutomaticallyPromptMissingFiles;
  297. target->AddDirectoryPrefixToAssetName = AddDirectoryPrefixToAssetName;
  298. //Meshes
  299. target->ImportMesh = ImportMesh;
  300. target->AlwaysAddShapeSuffix = AlwaysAddShapeSuffix;
  301. target->AddedShapeSuffix = AddedShapeSuffix;
  302. target->UseManualShapeConfigRules = UseManualShapeConfigRules;
  303. target->DoUpAxisOverride = DoUpAxisOverride;
  304. target->UpAxisOverride = UpAxisOverride;
  305. target->DoScaleOverride = DoScaleOverride;
  306. target->ScaleOverride = ScaleOverride;
  307. target->IgnoreNodeScale = IgnoreNodeScale;
  308. target->AdjustCenter = AdjustCenter;
  309. target->AdjustFloor = AdjustFloor;
  310. target->CollapseSubmeshes = CollapseSubmeshes;
  311. target->LODType = LODType;
  312. target->AlwaysImportedNodes = AlwaysImportedNodes;
  313. target->AlwaysIgnoreNodes = AlwaysIgnoreNodes;
  314. target->AlwaysImportMeshes = AlwaysImportMeshes;
  315. target->AlwaysIgnoreMeshes = AlwaysIgnoreMeshes;
  316. //Assimp/Collada
  317. target->convertLeftHanded = convertLeftHanded;
  318. target->calcTangentSpace = calcTangentSpace;
  319. target->removeRedundantMats = removeRedundantMats;
  320. target->genUVCoords = genUVCoords;
  321. target->TransformUVs = TransformUVs;
  322. target->flipUVCoords = flipUVCoords;
  323. target->findInstances = findInstances;
  324. target->limitBoneWeights = limitBoneWeights;
  325. target->JoinIdenticalVerts = JoinIdenticalVerts;
  326. target->reverseWindingOrder = reverseWindingOrder;
  327. target->invertNormals = invertNormals;
  328. //Materials
  329. target->ImportMaterials = ImportMaterials;
  330. target->AlwaysAddMaterialSuffix = AlwaysAddMaterialSuffix;
  331. target->AddedMaterialSuffix = AddedMaterialSuffix;
  332. target->CreateORMConfig = CreateORMConfig;
  333. target->UseDiffuseSuffixOnOriginImage = UseDiffuseSuffixOnOriginImage;
  334. target->UseExistingMaterials = UseExistingMaterials;
  335. target->IgnoreMaterials = IgnoreMaterials;
  336. target->PopulateMaterialMaps = PopulateMaterialMaps;
  337. //Animations
  338. target->ImportAnimations = ImportAnimations;
  339. target->SeparateAnimations = SeparateAnimations;
  340. target->SeparateAnimationPrefix = SeparateAnimationPrefix;
  341. target->animTiming = animTiming;
  342. target->animFPS = animFPS;
  343. //Collisions
  344. target->GenerateCollisions = GenerateCollisions;
  345. target->GenCollisionType = GenCollisionType;
  346. target->CollisionMeshPrefix = CollisionMeshPrefix;
  347. target->GenerateLOSCollisions = GenerateLOSCollisions;
  348. target->GenLOSCollisionType = GenLOSCollisionType;
  349. target->LOSCollisionMeshPrefix = LOSCollisionMeshPrefix;
  350. //Images
  351. target->importImages = importImages;
  352. target->AlwaysAddImageSuffix = AlwaysAddImageSuffix;
  353. target->AddedImageSuffix = AddedImageSuffix;
  354. target->ImageType = ImageType;
  355. target->DiffuseTypeSuffixes = DiffuseTypeSuffixes;
  356. target->NormalTypeSuffixes = NormalTypeSuffixes;
  357. target->MetalnessTypeSuffixes = MetalnessTypeSuffixes;
  358. target->RoughnessTypeSuffixes = RoughnessTypeSuffixes;
  359. target->SmoothnessTypeSuffixes = SmoothnessTypeSuffixes;
  360. target->AOTypeSuffixes = AOTypeSuffixes;
  361. target->PBRTypeSuffixes = PBRTypeSuffixes;
  362. target->TextureFilteringMode = TextureFilteringMode;
  363. target->UseMips = UseMips;
  364. target->IsHDR = IsHDR;
  365. target->Scaling = Scaling;
  366. target->ImagesCompressed = ImagesCompressed;
  367. target->GenerateMaterialOnImport = GenerateMaterialOnImport;
  368. //Sounds
  369. target->VolumeAdjust = VolumeAdjust;
  370. target->PitchAdjust = PitchAdjust;
  371. target->SoundsCompressed = SoundsCompressed;
  372. }
  373. ConsoleDocClass(AssetImportObject,
  374. "@brief Defines properties for an AssetImportObject object.\n"
  375. "@AssetImportObject is a SimObject derived object intended to act as a stand-in for the to-be imported objects.\n"
  376. "@It contains important info such as dependencies, if it's been processed, any error/status issues and the originating file\n"
  377. "@or if it's been programmatically generated as part of the import process.\n\n"
  378. "@ingroup Assets\n"
  379. );
  380. IMPLEMENT_CONOBJECT(AssetImportObject);
  381. AssetImportObject::AssetImportObject() :
  382. dirty(false),
  383. skip(false),
  384. processed(false),
  385. generatedAsset(false),
  386. parentAssetItem(nullptr),
  387. tamlFilePath(""),
  388. imageSuffixType(""),
  389. shapeInfo(nullptr),
  390. filePathString(StringTable->EmptyString())
  391. {
  392. }
  393. AssetImportObject::~AssetImportObject()
  394. {
  395. }
  396. bool AssetImportObject::onAdd()
  397. {
  398. if (!Parent::onAdd())
  399. return false;
  400. return true;
  401. }
  402. void AssetImportObject::onRemove()
  403. {
  404. Parent::onRemove();
  405. }
  406. void AssetImportObject::initPersistFields()
  407. {
  408. Parent::initPersistFields();
  409. addField("assetType", TypeRealString, Offset(assetType, AssetImportObject), "What type is the importing asset");
  410. addProtectedField("filePath", TypeFilename, Offset(filePathString, AssetImportObject), &_setFilePath, &defaultProtectedGetFn, "What is the source file path of the importing asset");
  411. addField("assetName", TypeRealString, Offset(assetName, AssetImportObject), "What is the asset's name");
  412. addField("cleanAssetName", TypeRealString, Offset(cleanAssetName, AssetImportObject), "What is the original, unmodified by processing, asset name");
  413. addField("status", TypeRealString, Offset(status, AssetImportObject), "What is the current status of this asset item in it's import process");
  414. addField("statusType", TypeRealString, Offset(statusType, AssetImportObject), "If there is a warning or error status, what type is the condition for this asset item");
  415. addField("statusInfo", TypeRealString, Offset(statusInfo, AssetImportObject), "What is the articulated information of the status of the asset. Contains the error or warning log data");
  416. addField("dirty", TypeBool, Offset(dirty, AssetImportObject), "Is the asset item currently flagged as dirty");
  417. addField("skip", TypeBool, Offset(skip, AssetImportObject), "Is this asset item marked to be skipped. If it is, it's usually due to being marked as deleted");
  418. addField("processed", TypeBool, Offset(processed, AssetImportObject), "Has the asset item been processed");
  419. addField("generatedAsset", TypeBool, Offset(generatedAsset, AssetImportObject), "Is this specific asset item generated as part of the import process of another item");
  420. addField("tamlFilePath", TypeRealString, Offset(tamlFilePath, AssetImportObject), "What is the ultimate asset taml file path for this import item");
  421. addField("imageType", TypeRealString, Offset(imageSuffixType, AssetImportObject), "Specific to ImageAsset type. What is the image asset's suffix type. Options are: Albedo, Normal, Roughness, AO, Metalness, ORMConfig");
  422. addField("shapeInfo", TYPEID< GuiTreeViewCtrl >(), Offset(shapeInfo, AssetImportObject), "Specific to ShapeAsset type. Processed information about the shape file. Contains numbers and lists of meshes, materials and animations");
  423. }
  424. bool AssetImportObject::_setFilePath(void* obj, const char* index, const char* data)
  425. {
  426. AssetImportObject* importObj = static_cast<AssetImportObject*>(obj);
  427. importObj->setFilePath(StringTable->insert(data));
  428. return false;
  429. }
  430. void AssetImportObject::setFilePath(StringTableEntry pFilePath)
  431. {
  432. filePathString = pFilePath;
  433. filePath = Torque::Path(pFilePath);
  434. }
  435. ConsoleDocClass(AssetImporter,
  436. "@brief Defines properties for an AssetImportObject object.\n"
  437. "@AssetImportObject is a SimObject derived object intended to act as a stand-in for the to-be imported objects.\n"
  438. "@It contains important info such as dependencies, if it's been processed, any error/status issues and the originating file\n"
  439. "@or if it's been programmatically generated as part of the import process.\n\n"
  440. "@ingroup Assets\n"
  441. );
  442. IMPLEMENT_CONOBJECT(AssetImporter);
  443. AssetImporter::AssetImporter() :
  444. importIssues(false),
  445. isReimport(false),
  446. assetHeirarchyChanged(false),
  447. importLogBuffer(""),
  448. activeImportConfig(nullptr)
  449. {
  450. }
  451. AssetImporter::~AssetImporter()
  452. {
  453. }
  454. bool AssetImporter::onAdd()
  455. {
  456. if (!Parent::onAdd())
  457. return false;
  458. return true;
  459. }
  460. void AssetImporter::onRemove()
  461. {
  462. Parent::onRemove();
  463. }
  464. void AssetImporter::initPersistFields()
  465. {
  466. Parent::initPersistFields();
  467. addField("targetModuleId", TypeRealString, Offset(targetModuleId, AssetImporter), "The Id of the module the assets are to be imported into");
  468. addField("finalImportedAssetPath", TypeRealString, Offset(finalImportedAssetPath, AssetImporter), "The Id of the module the assets are to be imported into");
  469. addField("targetPath", TypeRealString, Offset(targetPath, AssetImporter), "The path any imported assets are placed in as their destination");
  470. }
  471. //
  472. // Utility Functions
  473. //
  474. AssetImportObject* AssetImporter::addImportingFile(Torque::Path filePath)
  475. {
  476. String assetType = getAssetTypeByFile(filePath);
  477. if (assetType.isEmpty())
  478. {
  479. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Unable to import file %s because it is of an unrecognized/unsupported type.", filePath.getFullPath().c_str());
  480. activityLog.push_back(importLogBuffer);
  481. return nullptr;
  482. }
  483. AssetImportObject* newAssetItem = addImportingAsset(assetType, filePath, nullptr, "");
  484. originalImportingFiles.push_back(filePath);
  485. return newAssetItem;
  486. }
  487. void AssetImporter::addImportingAssetItem(AssetImportObject* assetItem, AssetImportObject* parentItem)
  488. {
  489. if (assetItem == nullptr)
  490. {
  491. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Cannot add a null AssetImportObject to import session!");
  492. activityLog.push_back(importLogBuffer);
  493. return;
  494. }
  495. if (parentItem != nullptr)
  496. {
  497. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Added Child Importing Asset to %s", parentItem->assetName.c_str());
  498. activityLog.push_back(importLogBuffer);
  499. parentItem->childAssetItems.push_back(assetItem);
  500. assetItem->parentAssetItem = parentItem;
  501. }
  502. else
  503. {
  504. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Added Importing Asset");
  505. activityLog.push_back(importLogBuffer);
  506. importingAssets.push_back(assetItem);
  507. }
  508. dSprintf(importLogBuffer, sizeof(importLogBuffer), " Asset Info: Name: %s | Type: %s", assetItem->assetName.c_str(), assetItem->assetType.c_str());
  509. activityLog.push_back(importLogBuffer);
  510. if (!assetItem->filePath.isEmpty())
  511. {
  512. dSprintf(importLogBuffer, sizeof(importLogBuffer), " File: %s", assetItem->filePath.getFullPath().c_str());
  513. activityLog.push_back(importLogBuffer);
  514. }
  515. }
  516. AssetImportObject* AssetImporter::addImportingAsset(String assetType, Torque::Path filePath, AssetImportObject* parentItem, String assetNameOverride)
  517. {
  518. String assetName;
  519. //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
  520. if (assetNameOverride.isNotEmpty())
  521. assetName = assetNameOverride;
  522. else
  523. assetName = filePath.getFileName();
  524. AssetImportObject* assetImportObj = new AssetImportObject();
  525. assetImportObj->registerObject();
  526. //sanitize
  527. assetName.replace(' ', '_');
  528. assetName.replace('~', '_');
  529. assetName.replace('`', '_');
  530. assetName.replace('-', '_');
  531. assetName.replace('*', '_');
  532. assetName.replace('-', '_');
  533. assetName.replace('+', '_');
  534. assetImportObj->assetType = assetType;
  535. assetImportObj->filePath = filePath;
  536. assetImportObj->filePathString = StringTable->insert(filePath.getFullPath().c_str());
  537. assetImportObj->assetName = assetName;
  538. assetImportObj->cleanAssetName = assetName;
  539. assetImportObj->moduleName = targetModuleId;
  540. assetImportObj->status = "";
  541. assetImportObj->statusType = "";
  542. assetImportObj->statusInfo = "";
  543. assetImportObj->dirty = false;
  544. assetImportObj->skip = false;
  545. assetImportObj->processed = false;
  546. assetImportObj->generatedAsset = false;
  547. if (parentItem != nullptr)
  548. {
  549. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Added Child Importing Asset to %s", parentItem->assetName.c_str());
  550. activityLog.push_back(importLogBuffer);
  551. parentItem->childAssetItems.push_back(assetImportObj);
  552. assetImportObj->parentAssetItem = parentItem;
  553. }
  554. else
  555. {
  556. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Added Importing Asset");
  557. activityLog.push_back(importLogBuffer);
  558. importingAssets.push_back(assetImportObj);
  559. }
  560. dSprintf(importLogBuffer, sizeof(importLogBuffer), " Asset Info: Name: %s | Type: %s", assetImportObj->assetName.c_str(), assetImportObj->assetType.c_str());
  561. activityLog.push_back(importLogBuffer);
  562. if (!filePath.isEmpty())
  563. {
  564. dSprintf(importLogBuffer, sizeof(importLogBuffer), " File: %s", filePath.getFullPath().c_str());
  565. activityLog.push_back(importLogBuffer);
  566. }
  567. return assetImportObj;
  568. }
  569. void AssetImporter::deleteImportingAsset(AssetImportObject* assetItem)
  570. {
  571. assetItem->skip = true;
  572. //log it
  573. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Deleting Importing Asset %s and all it's child items", assetItem->assetName.c_str());
  574. activityLog.push_back(importLogBuffer);
  575. }
  576. AssetImportObject* AssetImporter::findImportingAssetByName(String assetName, AssetImportObject* assetItem)
  577. {
  578. if (assetItem == nullptr)
  579. {
  580. for (U32 i = 0; i < importingAssets.size(); i++)
  581. {
  582. if (importingAssets[i]->cleanAssetName == assetName)
  583. {
  584. return importingAssets[i];
  585. }
  586. //If it wasn't a match, try recusing on the children(if any)
  587. AssetImportObject* retItem = findImportingAssetByName(assetName, importingAssets[i]);
  588. if (retItem != nullptr)
  589. return retItem;
  590. }
  591. }
  592. else
  593. {
  594. //this is the child recursing section
  595. for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
  596. {
  597. if (assetItem->childAssetItems[i]->cleanAssetName == assetName)
  598. {
  599. return assetItem->childAssetItems[i];
  600. }
  601. //If it wasn't a match, try recusing on the children(if any)
  602. AssetImportObject* retItem = findImportingAssetByName(assetName, assetItem->childAssetItems[i]);
  603. if (retItem != nullptr)
  604. return retItem;
  605. }
  606. }
  607. return nullptr;
  608. }
  609. ModuleDefinition* AssetImporter::getModuleFromPath(Torque::Path filePath)
  610. {
  611. // Use a relative path so modules on mounted file systems will be found.
  612. ModuleDefinition* moduleDef = ModuleDatabase.findModuleByFilePath(Platform::makeRelativePathName(filePath.getFullPath().c_str(), NULL));
  613. return moduleDef;
  614. }
  615. String AssetImporter::parseImageSuffixes(String assetName, String* suffixType)
  616. {
  617. //Here, we loop over our different suffix lists progressively.
  618. //This lets us walk through a list of suffixes in the Import Config, such as DiffuseTypeSuffixes
  619. //And then iterate over the delinated list of items within it to look for a match.
  620. //If we don't find a match, we then increment our list switch index and scan through the next list.
  621. U32 suffixTypeIdx = 0;
  622. while (suffixTypeIdx < 6)
  623. {
  624. String suffixList;
  625. switch (suffixTypeIdx)
  626. {
  627. case 0:
  628. suffixList = activeImportConfig->DiffuseTypeSuffixes;
  629. suffixType->insert(0, "Albedo", 10);
  630. break;
  631. case 1:
  632. suffixList = activeImportConfig->NormalTypeSuffixes;
  633. suffixType->insert(0, "Normal", 10);
  634. break;
  635. case 2:
  636. suffixList = activeImportConfig->RoughnessTypeSuffixes;
  637. suffixType->insert(0, "Roughness", 10);
  638. break;
  639. case 3:
  640. suffixList = activeImportConfig->AOTypeSuffixes;
  641. suffixType->insert(0, "AO", 10);
  642. break;
  643. case 4:
  644. suffixList = activeImportConfig->MetalnessTypeSuffixes;
  645. suffixType->insert(0, "Metalness", 10);
  646. break;
  647. case 5:
  648. suffixList = activeImportConfig->PBRTypeSuffixes;
  649. suffixType->insert(0, "ORMConfig", 10);
  650. break;
  651. default:
  652. suffixList = "";
  653. }
  654. suffixTypeIdx++;
  655. U32 suffixCount = StringUnit::getUnitCount(suffixList, ",;\t");
  656. for (U32 i = 0; i < suffixCount; i++)
  657. {
  658. String suffix = StringUnit::getUnit(suffixList, i, ",;\t");
  659. String searchSuffix = String("*") + suffix;
  660. if (FindMatch::isMatch(searchSuffix.c_str(), assetName.c_str(), false))
  661. {
  662. //We have a match, so indicate as such
  663. S32 pos = assetName.length();
  664. pos -= searchSuffix.length();
  665. suffix = assetName.substr(pos+1);
  666. return suffix;
  667. }
  668. }
  669. }
  670. suffixType->clear();
  671. return "";
  672. }
  673. String AssetImporter::getAssetTypeByFile(Torque::Path filePath)
  674. {
  675. String fileExt = String::ToLower(filePath.getExtension());
  676. String fileName = String::ToLower(filePath.getFileName());
  677. if (fileExt == String("dts") && fileName.endsWith("cached"))
  678. return "";
  679. if (fileExt == String("png") || fileExt == String("jpg") || fileExt == String("jpeg") || fileExt == String("dds"))
  680. return "ImageAsset";
  681. else if (fileExt == String("dae") || fileExt == String("fbx") || fileExt == String("blend") || fileExt == String("obj") || fileExt == String("dts") || fileExt == String("gltf") || fileExt == String("gltb"))
  682. return "ShapeAsset";
  683. else if (fileExt == String("dsq"))
  684. return "ShapeAnimationAsset";
  685. else if (fileExt == String("ogg") || fileExt == String("wav") || fileExt == String("mp3"))
  686. return "SoundAsset";
  687. else if (fileExt == String("zip"))
  688. return "Zip";
  689. else if (fileExt.isEmpty())
  690. return "Folder";
  691. return "";
  692. }
  693. String AssetImporter::getTrueFilename(const String& fileName)
  694. {
  695. Torque::Path pth(fileName);
  696. String pattern = pth.getFullPath() + "*";
  697. static const String sSlash("/");
  698. Vector<String> findFilesResults;
  699. String sPattern(Torque::Path::CleanSeparators(pattern));
  700. if (sPattern.isEmpty())
  701. {
  702. Con::errorf("findFirstFile() requires a search pattern");
  703. return "";
  704. }
  705. char scriptFilenameBuffer[1024];
  706. if (!Con::expandScriptFilename(scriptFilenameBuffer, sizeof(scriptFilenameBuffer), sPattern.c_str()))
  707. {
  708. Con::errorf("findFirstFile() given initial directory cannot be expanded: '%s'", pattern.c_str());
  709. return "";
  710. }
  711. sPattern = String::ToString(scriptFilenameBuffer);
  712. String::SizeType slashPos = sPattern.find('/', 0, String::Right);
  713. // if(slashPos == String::NPos)
  714. // {
  715. // Con::errorf("findFirstFile() missing search directory or expression: '%s'", sPattern.c_str());
  716. // return -1;
  717. // }
  718. // Build the initial search path
  719. Torque::Path givenPath(Torque::Path::CompressPath(sPattern));
  720. givenPath.setFileName("*");
  721. givenPath.setExtension("*");
  722. if (givenPath.getPath().length() > 0 && givenPath.getPath().find('*', 0, String::Right) == givenPath.getPath().length() - 1)
  723. {
  724. // Deal with legacy searches of the form '*/*.*'
  725. String suspectPath = givenPath.getPath();
  726. String::SizeType newLen = suspectPath.length() - 1;
  727. if (newLen > 0 && suspectPath.find('/', 0, String::Right) == suspectPath.length() - 2)
  728. {
  729. --newLen;
  730. }
  731. givenPath.setPath(suspectPath.substr(0, newLen));
  732. }
  733. Torque::FS::FileSystemRef fs = Torque::FS::GetFileSystem(givenPath);
  734. //Torque::Path path = fs->mapTo(givenPath);
  735. Torque::Path path = givenPath;
  736. // Make sure that we have a root so the correct file system can be determined when using zips
  737. if (givenPath.isRelative())
  738. path = Torque::Path::Join(Torque::FS::GetCwd(), '/', givenPath);
  739. path.setFileName(String::EmptyString);
  740. path.setExtension(String::EmptyString);
  741. if (!Torque::FS::IsDirectory(path))
  742. {
  743. Con::errorf("findFirstFile() invalid initial search directory: '%s'", path.getFullPath().c_str());
  744. return "";
  745. }
  746. // Build the search expression
  747. const String expression(slashPos != String::NPos ? sPattern.substr(slashPos + 1) : sPattern);
  748. if (expression.isEmpty())
  749. {
  750. Con::errorf("findFirstFile() requires a search expression: '%s'", sPattern.c_str());
  751. return "";
  752. }
  753. S32 results = Torque::FS::FindByPattern(path, expression, false, findFilesResults, false);
  754. if (givenPath.isRelative() && results > 0)
  755. {
  756. // Strip the CWD out of the returned paths
  757. // MakeRelativePath() returns incorrect results (it adds a leading ..) so doing this the dirty way
  758. const String cwd = Torque::FS::GetCwd().getFullPath();
  759. for (S32 i = 0; i < findFilesResults.size(); ++i)
  760. {
  761. String str = findFilesResults[i];
  762. if (str.compare(cwd, cwd.length(), String::NoCase) == 0)
  763. str = str.substr(cwd.length());
  764. findFilesResults[i] = str;
  765. }
  766. }
  767. for (U32 i = 0; i < findFilesResults.size(); i++)
  768. {
  769. if (!findFilesResults[i].compare(fileName, 0, String::NoCase|String::Left))
  770. return findFilesResults[i];
  771. }
  772. return "";
  773. }
  774. void AssetImporter::resetImportSession(bool hardClearSession)
  775. {
  776. importingAssets.clear();
  777. activityLog.clear();
  778. if (hardClearSession)
  779. {
  780. originalImportingFiles.clear();
  781. }
  782. else
  783. {
  784. Vector<Torque::Path> tempImportingFiles = originalImportingFiles;
  785. originalImportingFiles.clear();
  786. for (U32 i = 0; i < tempImportingFiles.size(); i++)
  787. {
  788. addImportingFile(tempImportingFiles[i]);
  789. }
  790. }
  791. }
  792. S32 AssetImporter::getActivityLogLineCount()
  793. {
  794. return activityLog.size();
  795. }
  796. String AssetImporter::getActivityLogLine(U32 line)
  797. {
  798. if (line >= activityLog.size())
  799. return "";
  800. return activityLog[line];
  801. }
  802. void AssetImporter::dumpActivityLog()
  803. {
  804. for (U32 i = 0; i < activityLog.size(); i++)
  805. {
  806. Con::printf(activityLog[i].c_str());
  807. }
  808. }
  809. S32 AssetImporter::getAssetItemCount()
  810. {
  811. return importingAssets.size();
  812. }
  813. AssetImportObject* AssetImporter::getAssetItem(U32 index)
  814. {
  815. if (index >= importingAssets.size())
  816. return nullptr;
  817. return importingAssets[index];
  818. }
  819. S32 AssetImporter::getAssetItemChildCount(AssetImportObject* assetItem)
  820. {
  821. return assetItem->childAssetItems.size();
  822. }
  823. AssetImportObject* AssetImporter::getAssetItemChild(AssetImportObject* assetItem, U32 index)
  824. {
  825. if (index >= assetItem->childAssetItems.size())
  826. return nullptr;
  827. return assetItem->childAssetItems[index];
  828. }
  829. //
  830. // Processing
  831. //
  832. // Helper struct for counting nodes, meshes and polygons down through the scene
  833. // hierarchy
  834. struct SceneStats
  835. {
  836. S32 numNodes;
  837. S32 numMeshes;
  838. S32 numPolygons;
  839. S32 numMaterials;
  840. S32 numLights;
  841. S32 numClips;
  842. SceneStats() : numNodes(0), numMeshes(0), numPolygons(0), numMaterials(0), numLights(0), numClips(0) { }
  843. };
  844. // Recurse through the <visual_scene> adding nodes and geometry to the GuiTreeView control
  845. static void processNode(GuiTreeViewCtrl* tree, domNode* node, S32 parentID, SceneStats& stats)
  846. {
  847. stats.numNodes++;
  848. S32 nodeID = tree->insertItem(parentID, _GetNameOrId(node), "node", "", 0, 0);
  849. // Update mesh and poly counts
  850. for (S32 i = 0; i < node->getContents().getCount(); i++)
  851. {
  852. domGeometry* geom = 0;
  853. const char* elemName = "";
  854. daeElement* child = node->getContents()[i];
  855. switch (child->getElementType())
  856. {
  857. case COLLADA_TYPE::INSTANCE_GEOMETRY:
  858. {
  859. domInstance_geometry* instgeom = daeSafeCast<domInstance_geometry>(child);
  860. if (instgeom)
  861. {
  862. geom = daeSafeCast<domGeometry>(instgeom->getUrl().getElement());
  863. elemName = _GetNameOrId(geom);
  864. }
  865. break;
  866. }
  867. case COLLADA_TYPE::INSTANCE_CONTROLLER:
  868. {
  869. domInstance_controller* instctrl = daeSafeCast<domInstance_controller>(child);
  870. if (instctrl)
  871. {
  872. domController* ctrl = daeSafeCast<domController>(instctrl->getUrl().getElement());
  873. elemName = _GetNameOrId(ctrl);
  874. if (ctrl && ctrl->getSkin())
  875. geom = daeSafeCast<domGeometry>(ctrl->getSkin()->getSource().getElement());
  876. else if (ctrl && ctrl->getMorph())
  877. geom = daeSafeCast<domGeometry>(ctrl->getMorph()->getSource().getElement());
  878. }
  879. break;
  880. }
  881. case COLLADA_TYPE::INSTANCE_LIGHT:
  882. stats.numLights++;
  883. tree->insertItem(nodeID, _GetNameOrId(node), "light", "", 0, 0);
  884. break;
  885. }
  886. if (geom && geom->getMesh())
  887. {
  888. const char* name = _GetNameOrId(node);
  889. if (dStrEqual(name, "null") || dStrEndsWith(name, "PIVOT"))
  890. name = _GetNameOrId(daeSafeCast<domNode>(node->getParent()));
  891. stats.numMeshes++;
  892. tree->insertItem(nodeID, name, "mesh", "", 0, 0);
  893. for (S32 j = 0; j < geom->getMesh()->getTriangles_array().getCount(); j++)
  894. stats.numPolygons += geom->getMesh()->getTriangles_array()[j]->getCount();
  895. for (S32 j = 0; j < geom->getMesh()->getTristrips_array().getCount(); j++)
  896. stats.numPolygons += geom->getMesh()->getTristrips_array()[j]->getCount();
  897. for (S32 j = 0; j < geom->getMesh()->getTrifans_array().getCount(); j++)
  898. stats.numPolygons += geom->getMesh()->getTrifans_array()[j]->getCount();
  899. for (S32 j = 0; j < geom->getMesh()->getPolygons_array().getCount(); j++)
  900. stats.numPolygons += geom->getMesh()->getPolygons_array()[j]->getCount();
  901. for (S32 j = 0; j < geom->getMesh()->getPolylist_array().getCount(); j++)
  902. stats.numPolygons += geom->getMesh()->getPolylist_array()[j]->getCount();
  903. }
  904. }
  905. // Recurse into child nodes
  906. for (S32 i = 0; i < node->getNode_array().getCount(); i++)
  907. processNode(tree, node->getNode_array()[i], nodeID, stats);
  908. for (S32 i = 0; i < node->getInstance_node_array().getCount(); i++)
  909. {
  910. domInstance_node* instnode = node->getInstance_node_array()[i];
  911. domNode* dNode = daeSafeCast<domNode>(instnode->getUrl().getElement());
  912. if (dNode)
  913. processNode(tree, dNode, nodeID, stats);
  914. }
  915. }
  916. static bool enumColladaForImport(const char* shapePath, GuiTreeViewCtrl* tree, bool loadCachedDts)
  917. {
  918. // Check if a cached DTS is available => no need to import the collada file
  919. // if we can load the DTS instead
  920. Torque::Path path(shapePath);
  921. if (loadCachedDts && ColladaShapeLoader::canLoadCachedDTS(path))
  922. return false;
  923. // Check if this is a Sketchup file (.kmz) and if so, mount the zip filesystem
  924. // and get the path to the DAE file.
  925. String mountPoint;
  926. Torque::Path daePath;
  927. bool isSketchup = ColladaShapeLoader::checkAndMountSketchup(path, mountPoint, daePath);
  928. // Load the Collada file into memory
  929. domCOLLADA* root = ColladaShapeLoader::getDomCOLLADA(daePath);
  930. if (!root)
  931. {
  932. TSShapeLoader::updateProgress(TSShapeLoader::Load_Complete, "Load complete");
  933. return false;
  934. }
  935. if (isSketchup)
  936. {
  937. // Unmount the zip if we mounted it
  938. Torque::FS::Unmount(mountPoint);
  939. }
  940. // Initialize tree
  941. tree->removeItem(0);
  942. S32 nodesID = tree->insertItem(0, "Shape", "", "", 0, 0);
  943. S32 matsID = tree->insertItem(0, "Materials", "", "", 0, 0);
  944. S32 animsID = tree->insertItem(0, "Animations", "", "", 0, 0);
  945. SceneStats stats;
  946. // Query DOM for shape summary details
  947. for (S32 i = 0; i < root->getLibrary_visual_scenes_array().getCount(); i++)
  948. {
  949. const domLibrary_visual_scenes* libScenes = root->getLibrary_visual_scenes_array()[i];
  950. for (S32 j = 0; j < libScenes->getVisual_scene_array().getCount(); j++)
  951. {
  952. const domVisual_scene* visualScene = libScenes->getVisual_scene_array()[j];
  953. for (S32 k = 0; k < visualScene->getNode_array().getCount(); k++)
  954. processNode(tree, visualScene->getNode_array()[k], nodesID, stats);
  955. }
  956. }
  957. // Get material count
  958. for (S32 i = 0; i < root->getLibrary_materials_array().getCount(); i++)
  959. {
  960. const domLibrary_materials* libraryMats = root->getLibrary_materials_array()[i];
  961. stats.numMaterials += libraryMats->getMaterial_array().getCount();
  962. for (S32 j = 0; j < libraryMats->getMaterial_array().getCount(); j++)
  963. {
  964. domMaterial* mat = libraryMats->getMaterial_array()[j];
  965. tree->insertItem(matsID, _GetNameOrId(mat), "", "", 0, 0);
  966. }
  967. }
  968. // Get images count
  969. for (S32 i = 0; i < root->getLibrary_images_array().getCount(); i++)
  970. {
  971. const domLibrary_images* libraryImages = root->getLibrary_images_array()[i];
  972. for (S32 j = 0; j < libraryImages->getImage_array().getCount(); j++)
  973. {
  974. domImage* img = libraryImages->getImage_array()[j];
  975. S32 materialID = tree->findItemByName(_GetNameOrId(img));
  976. if (materialID == 0)
  977. continue;
  978. tree->setItemValue(materialID, img->getInit_from()->getValue().str().c_str());
  979. }
  980. }
  981. // Get animation count
  982. for (S32 i = 0; i < root->getLibrary_animation_clips_array().getCount(); i++)
  983. {
  984. const domLibrary_animation_clips* libraryClips = root->getLibrary_animation_clips_array()[i];
  985. stats.numClips += libraryClips->getAnimation_clip_array().getCount();
  986. for (S32 j = 0; j < libraryClips->getAnimation_clip_array().getCount(); j++)
  987. {
  988. domAnimation_clip* clip = libraryClips->getAnimation_clip_array()[j];
  989. tree->insertItem(animsID, _GetNameOrId(clip), "animation", "", 0, 0);
  990. }
  991. }
  992. if (stats.numClips == 0)
  993. {
  994. // No clips => check if there are any animations (these will be added to a default clip)
  995. for (S32 i = 0; i < root->getLibrary_animations_array().getCount(); i++)
  996. {
  997. const domLibrary_animations* libraryAnims = root->getLibrary_animations_array()[i];
  998. if (libraryAnims->getAnimation_array().getCount())
  999. {
  1000. stats.numClips = 1;
  1001. tree->insertItem(animsID, "ambient", "animation", "", 0, 0);
  1002. break;
  1003. }
  1004. }
  1005. }
  1006. // Extract the global scale and up_axis from the top level <asset> element,
  1007. F32 unit = 1.0f;
  1008. domUpAxisType upAxis = UPAXISTYPE_Z_UP;
  1009. if (root->getAsset()) {
  1010. if (root->getAsset()->getUnit())
  1011. unit = root->getAsset()->getUnit()->getMeter();
  1012. if (root->getAsset()->getUp_axis())
  1013. upAxis = root->getAsset()->getUp_axis()->getValue();
  1014. }
  1015. TSShapeLoader::updateProgress(TSShapeLoader::Load_Complete, "Load complete");
  1016. // Store shape information in the tree control
  1017. tree->setDataField(StringTable->insert("_nodeCount"), 0, avar("%d", stats.numNodes));
  1018. tree->setDataField(StringTable->insert("_meshCount"), 0, avar("%d", stats.numMeshes));
  1019. tree->setDataField(StringTable->insert("_polygonCount"), 0, avar("%d", stats.numPolygons));
  1020. tree->setDataField(StringTable->insert("_materialCount"), 0, avar("%d", stats.numMaterials));
  1021. tree->setDataField(StringTable->insert("_lightCount"), 0, avar("%d", stats.numLights));
  1022. tree->setDataField(StringTable->insert("_animCount"), 0, avar("%d", stats.numClips));
  1023. tree->setDataField(StringTable->insert("_unit"), 0, avar("%g", unit));
  1024. if (upAxis == UPAXISTYPE_X_UP)
  1025. tree->setDataField(StringTable->insert("_upAxis"), 0, "X_AXIS");
  1026. else if (upAxis == UPAXISTYPE_Y_UP)
  1027. tree->setDataField(StringTable->insert("_upAxis"), 0, "Y_AXIS");
  1028. else
  1029. tree->setDataField(StringTable->insert("_upAxis"), 0, "Z_AXIS");
  1030. char shapesStr[16];
  1031. dSprintf(shapesStr, 16, "%i", stats.numMeshes);
  1032. char materialsStr[16];
  1033. dSprintf(materialsStr, 16, "%i", stats.numMaterials);
  1034. char animationsStr[16];
  1035. dSprintf(animationsStr, 16, "%i", stats.numClips);
  1036. tree->setItemValue(nodesID, StringTable->insert(shapesStr));
  1037. tree->setItemValue(matsID, StringTable->insert(materialsStr));
  1038. tree->setItemValue(animsID, StringTable->insert(animationsStr));
  1039. return true;
  1040. }
  1041. static bool enumDTSForImport(const char* shapePath, GuiTreeViewCtrl* tree)
  1042. {
  1043. // Check if a cached DTS is available => no need to import the collada file
  1044. // if we can load the DTS instead
  1045. Torque::Path path(shapePath);
  1046. Resource<TSShape> dtsShape = ResourceManager::get().load(shapePath);
  1047. if (!dtsShape)
  1048. return false;
  1049. // Initialize tree
  1050. tree->removeItem(0);
  1051. S32 nodesID = tree->insertItem(0, "Shape", "", "", 0, 0);
  1052. S32 matsID = tree->insertItem(0, "Materials", "", "", 0, 0);
  1053. S32 animsID = tree->insertItem(0, "Animations", "", "", 0, 0);
  1054. SceneStats stats;
  1055. // Query DOM for shape summary details
  1056. for (S32 i = 0; i < dtsShape->objects.size(); i++)
  1057. {
  1058. tree->insertItem(nodesID, dtsShape->names[dtsShape->objects[i].nameIndex], "", "", 0, 0);
  1059. stats.numMeshes++;
  1060. }
  1061. // Get material count
  1062. for (S32 i = 0; i < dtsShape->materialList->size(); i++)
  1063. {
  1064. S32 matId = tree->insertItem(matsID, dtsShape->materialList->getMaterialName(i).c_str(), "", "", 0, 0);
  1065. stats.numMaterials++;
  1066. GFXTextureObject* difTex = dtsShape->materialList->getDiffuseTexture(i);
  1067. if (difTex)
  1068. {
  1069. tree->insertItem(matId, difTex->getPath().c_str(), "", "", 0, 0);
  1070. }
  1071. }
  1072. // Get animation count
  1073. for (S32 i = 0; i < dtsShape->sequences.size(); i++)
  1074. {
  1075. tree->insertItem(animsID, dtsShape->names[dtsShape->sequences[i].nameIndex], "animation", "", 0, 0);
  1076. stats.numClips++;
  1077. }
  1078. /*if (stats.numClips == 0)
  1079. {
  1080. // No clips => check if there are any animations (these will be added to a default clip)
  1081. for (S32 i = 0; i < root->getLibrary_animations_array().getCount(); i++)
  1082. {
  1083. const domLibrary_animations* libraryAnims = root->getLibrary_animations_array()[i];
  1084. if (libraryAnims->getAnimation_array().getCount())
  1085. {
  1086. stats.numClips = 1;
  1087. tree->insertItem(animsID, "ambient", "animation", "", 0, 0);
  1088. break;
  1089. }
  1090. }
  1091. }*/
  1092. F32 unit = 1.0f;
  1093. // Store shape information in the tree control
  1094. tree->setDataField(StringTable->insert("_nodeCount"), 0, avar("%d", stats.numNodes));
  1095. tree->setDataField(StringTable->insert("_meshCount"), 0, avar("%d", stats.numMeshes));
  1096. tree->setDataField(StringTable->insert("_polygonCount"), 0, avar("%d", stats.numPolygons));
  1097. tree->setDataField(StringTable->insert("_materialCount"), 0, avar("%d", stats.numMaterials));
  1098. tree->setDataField(StringTable->insert("_lightCount"), 0, avar("%d", stats.numLights));
  1099. tree->setDataField(StringTable->insert("_animCount"), 0, avar("%d", stats.numClips));
  1100. tree->setDataField(StringTable->insert("_unit"), 0, avar("%g", unit));
  1101. tree->setDataField(StringTable->insert("_upAxis"), 0, "Z_AXIS");
  1102. char shapesStr[16];
  1103. dSprintf(shapesStr, 16, "%i", stats.numMeshes);
  1104. char materialsStr[16];
  1105. dSprintf(materialsStr, 16, "%i", stats.numMaterials);
  1106. char animationsStr[16];
  1107. dSprintf(animationsStr, 16, "%i", stats.numClips);
  1108. tree->setItemValue(nodesID, StringTable->insert(shapesStr));
  1109. tree->setItemValue(matsID, StringTable->insert(materialsStr));
  1110. tree->setItemValue(animsID, StringTable->insert(animationsStr));
  1111. return true;
  1112. }
  1113. void AssetImportConfig::loadSISFile(Torque::Path filePath)
  1114. {
  1115. String settingsFilePath = "Tools";
  1116. Settings* editorSettings;
  1117. //See if we can get our editor settings
  1118. if (Sim::findObject("EditorSettings", editorSettings))
  1119. {
  1120. settingsFilePath = editorSettings->value("defaultSettingsPath", "Tools");
  1121. }
  1122. String fileExtension = filePath.getExtension();
  1123. String settingsFile = settingsFilePath + "/" + fileExtension + ".sis";
  1124. FileObject* fileObj = new FileObject();
  1125. if (Platform::isFile(settingsFile))
  1126. {
  1127. if (!fileObj->readMemory(settingsFile.c_str()))
  1128. {
  1129. Con::errorf("AssetImporter::loadSISFile() - Error opening file to load settings: %s", settingsFile.c_str());
  1130. fileObj->deleteObject();
  1131. return;
  1132. }
  1133. }
  1134. else
  1135. {
  1136. return;
  1137. }
  1138. String headerLine = (const char*)fileObj->readLine();
  1139. if (headerLine.substr(0, 4).compare("SISV", 0U, String::NoCase) != 0)
  1140. return; //not a sis file?
  1141. while (!fileObj->isEOF())
  1142. {
  1143. const char* line = (const char*)fileObj->readLine();
  1144. String key = StringUnit::getUnit(line, 0, "\t");
  1145. String value = StringUnit::getUnit(line, 1, "\t");
  1146. if (key.compare("DoUpAxisOverride", 0U, String::NoCase) == 0)
  1147. DoUpAxisOverride = dAtob(value.c_str());
  1148. else if (key.compare("UpAxisOverride", 0U, String::NoCase) == 0)
  1149. UpAxisOverride = value.c_str();
  1150. else if (key.compare("DoScaleOverride", 0U, String::NoCase) == 0)
  1151. DoScaleOverride = dAtob(value.c_str());
  1152. else if (key.compare("ScaleOverride", 0U, String::NoCase) == 0)
  1153. ScaleOverride = dAtof(value.c_str());
  1154. else if (key.compare("IgnoreNodeScale", 0U, String::NoCase) == 0)
  1155. IgnoreNodeScale = dAtob(value.c_str());
  1156. else if (key.compare("AdjustCenter", 0U, String::NoCase) == 0)
  1157. AdjustCenter = dAtob(value.c_str());
  1158. else if (key.compare("AdjustFloor", 0U, String::NoCase) == 0)
  1159. AdjustFloor = dAtob(value.c_str());
  1160. else if (key.compare("CollapseSubmeshes", 0U, String::NoCase) == 0)
  1161. CollapseSubmeshes = dAtob(value.c_str());
  1162. else if (key.compare("LODType", 0U, String::NoCase) == 0)
  1163. LODType = value.c_str();
  1164. else if (key.compare("AlwaysImportedNodes", 0U, String::NoCase) == 0)
  1165. AlwaysImportedNodes = value.c_str();
  1166. else if (key.compare("AlwaysIgnoreNodes", 0U, String::NoCase) == 0)
  1167. AlwaysIgnoreNodes = value.c_str();
  1168. else if (key.compare("AlwaysImportMeshes", 0U, String::NoCase) == 0)
  1169. AlwaysImportMeshes = value.c_str();
  1170. else if (key.compare("AlwaysIgnoreMeshes", 0U, String::NoCase) == 0)
  1171. AlwaysIgnoreMeshes = value.c_str();
  1172. else if (key.compare("convertLeftHanded", 0U, String::NoCase) == 0)
  1173. convertLeftHanded = dAtob(value.c_str());
  1174. else if (key.compare("calcTangentSpace", 0U, String::NoCase) == 0)
  1175. calcTangentSpace = dAtob(value.c_str());
  1176. else if (key.compare("removeRedundantMats", 0U, String::NoCase) == 0)
  1177. removeRedundantMats = dAtob(value.c_str());
  1178. else if (key.compare("genUVCoords", 0U, String::NoCase) == 0)
  1179. genUVCoords = dAtob(value.c_str());
  1180. else if (key.compare("TransformUVs", 0U, String::NoCase) == 0)
  1181. TransformUVs = dAtob(value.c_str());
  1182. else if (key.compare("flipUVCoords", 0U, String::NoCase) == 0)
  1183. flipUVCoords = dAtob(value.c_str());
  1184. else if (key.compare("findInstances", 0U, String::NoCase) == 0)
  1185. findInstances = dAtob(value.c_str());
  1186. else if (key.compare("limitBoneWeights", 0U, String::NoCase) == 0)
  1187. limitBoneWeights = dAtob(value.c_str());
  1188. else if (key.compare("JoinIdenticalVerts", 0U, String::NoCase) == 0)
  1189. JoinIdenticalVerts = dAtob(value.c_str());
  1190. else if (key.compare("reverseWindingOrder", 0U, String::NoCase) == 0)
  1191. reverseWindingOrder = dAtob(value.c_str());
  1192. else if (key.compare("invertNormals", 0U, String::NoCase) == 0)
  1193. invertNormals = dAtob(value.c_str());
  1194. }
  1195. fileObj->close();
  1196. fileObj->deleteObject();
  1197. }
  1198. void AssetImporter::processImportAssets(AssetImportObject* assetItem)
  1199. {
  1200. if (assetItem == nullptr)
  1201. {
  1202. assetHeirarchyChanged = false;
  1203. for (U32 i = 0; i < importingAssets.size(); i++)
  1204. {
  1205. AssetImportObject* item = importingAssets[i];
  1206. if (item->skip)
  1207. continue;
  1208. if (!item->processed)
  1209. {
  1210. //Sanitize before modifying our asset name(suffix additions, etc)
  1211. if (item->assetName != item->cleanAssetName)
  1212. item->assetName = item->cleanAssetName;
  1213. //handle special pre-processing here for any types that need it
  1214. //process the asset items
  1215. if (item->assetType == String("ImageAsset"))
  1216. {
  1217. processImageAsset(item);
  1218. }
  1219. else if (item->assetType == String("ShapeAsset"))
  1220. {
  1221. processShapeAsset(item);
  1222. }
  1223. /*else if (item->assetType == String("SoundAsset"))
  1224. SoundAsset::prepareAssetForImport(this, item);*/
  1225. else if (item->assetType == String("MaterialAsset"))
  1226. {
  1227. processMaterialAsset(item);
  1228. }
  1229. /*else if (item->assetType == String("ShapeAnimationAsset"))
  1230. ShapeAnimationAsset::prepareAssetForImport(this, item);*/
  1231. else
  1232. {
  1233. String processCommand = "process";
  1234. processCommand += item->assetType;
  1235. if(isMethod(processCommand.c_str()))
  1236. Con::executef(this, processCommand.c_str(), item);
  1237. }
  1238. item->processed = true;
  1239. }
  1240. //try recusing on the children(if any)
  1241. processImportAssets(item);
  1242. }
  1243. }
  1244. else
  1245. {
  1246. //this is the child recursing section
  1247. for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
  1248. {
  1249. AssetImportObject* childItem = assetItem->childAssetItems[i];
  1250. if (childItem->skip)
  1251. continue;
  1252. if (!childItem->processed)
  1253. {
  1254. //Sanitize before modifying our asset name(suffix additions, etc)
  1255. //if (childItem->assetName != childItem->cleanAssetName)
  1256. // childItem->assetName = childItem->cleanAssetName;
  1257. //handle special pre-processing here for any types that need it
  1258. //process the asset items
  1259. if (childItem->assetType == String("ImageAsset"))
  1260. {
  1261. processImageAsset(childItem);
  1262. }
  1263. else if (childItem->assetType == String("ShapeAsset"))
  1264. {
  1265. processShapeAsset(childItem);
  1266. }
  1267. /*else if (item->assetType == String("SoundAsset"))
  1268. SoundAsset::prepareAssetForImport(this, item);*/
  1269. else if (childItem->assetType == String("MaterialAsset"))
  1270. {
  1271. processMaterialAsset(childItem);
  1272. }
  1273. /*else if (item->assetType == String("ShapeAnimationAsset"))
  1274. ShapeAnimationAsset::prepareAssetForImport(this, item);*/
  1275. else
  1276. {
  1277. String processCommand = "process";
  1278. processCommand += childItem->assetType;
  1279. if (isMethod(processCommand.c_str()))
  1280. Con::executef(this, processCommand.c_str(), childItem);
  1281. }
  1282. childItem->processed = true;
  1283. }
  1284. //try recusing on the children(if any)
  1285. processImportAssets(childItem);
  1286. }
  1287. }
  1288. //If our hierarchy changed, it's because we did so during processing
  1289. //so we'll loop back through again until everything has been processed
  1290. if (assetHeirarchyChanged)
  1291. processImportAssets();
  1292. }
  1293. void AssetImporter::processImageAsset(AssetImportObject* assetItem)
  1294. {
  1295. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Preparing Image for Import: %s", assetItem->assetName.c_str());
  1296. activityLog.push_back(importLogBuffer);
  1297. if ((activeImportConfig->GenerateMaterialOnImport && assetItem->parentAssetItem == nullptr)/* || assetItem->parentAssetItem != nullptr*/)
  1298. {
  1299. //find our suffix match, if any
  1300. String noSuffixName = assetItem->assetName;
  1301. String suffixType;
  1302. String suffix = parseImageSuffixes(assetItem->assetName, &suffixType);
  1303. if (suffix.isNotEmpty())
  1304. {
  1305. assetItem->imageSuffixType = suffixType;
  1306. S32 suffixPos =assetItem->assetName.find(suffix, 0, String::NoCase|String::Left);
  1307. noSuffixName = assetItem->assetName.substr(0, suffixPos);
  1308. }
  1309. //We try to automatically populate materials under the naming convention: materialName: Rock, image maps: Rock_Albedo, Rock_Normal, etc
  1310. AssetImportObject* materialAsset = findImportingAssetByName(noSuffixName);
  1311. if (materialAsset != nullptr && materialAsset->assetType != String("MaterialAsset"))
  1312. {
  1313. //We may have a situation where an asset matches the no-suffix name, but it's not a material asset. Ignore this
  1314. //asset item for now
  1315. materialAsset = nullptr;
  1316. }
  1317. //If we didn't find a matching material asset in our current items, we'll make one now
  1318. if (materialAsset == nullptr)
  1319. {
  1320. if (!assetItem->filePath.isEmpty())
  1321. {
  1322. materialAsset = addImportingAsset("MaterialAsset", assetItem->filePath, nullptr, noSuffixName);
  1323. }
  1324. }
  1325. //Not that, one way or another, we have the generated material asset, lets move on to associating our image with it
  1326. if (materialAsset != nullptr && materialAsset != assetItem->parentAssetItem)
  1327. {
  1328. if (assetItem->parentAssetItem != nullptr)
  1329. {
  1330. //If the image had an existing parent, it gets removed from that parent's child item list
  1331. assetItem->parentAssetItem->childAssetItems.remove(assetItem);
  1332. }
  1333. else
  1334. {
  1335. //If it didn't have one, we're going to pull it from the importingAssets list
  1336. importingAssets.remove(assetItem);
  1337. }
  1338. //Now we can add it to the correct material asset
  1339. materialAsset->childAssetItems.push_back(assetItem);
  1340. assetItem->parentAssetItem = materialAsset;
  1341. assetHeirarchyChanged = true;
  1342. }
  1343. //Now to do some cleverness. If we're generating a material, we can parse like assets being imported(similar filenames) but different suffixes
  1344. //If we find these, we'll just populate into the original's material
  1345. //if we need to append the diffuse suffix and indeed didn't find a suffix on the name, do that here
  1346. if (suffixType.isEmpty())
  1347. {
  1348. if (activeImportConfig->UseDiffuseSuffixOnOriginImage)
  1349. {
  1350. String diffuseToken = StringUnit::getUnit(activeImportConfig->DiffuseTypeSuffixes, 0, ",;\t");
  1351. assetItem->assetName = assetItem->assetName + diffuseToken;
  1352. assetItem->cleanAssetName = assetItem->assetName;
  1353. }
  1354. else
  1355. {
  1356. //We need to ensure that our image asset doesn't match the same name as the material asset, so if we're not trying to force the diffuse suffix
  1357. //we'll give it a generic one
  1358. if ((materialAsset && materialAsset->assetName.compare(assetItem->assetName) == 0) || activeImportConfig->AlwaysAddImageSuffix)
  1359. {
  1360. assetItem->assetName = assetItem->assetName + activeImportConfig->AddedImageSuffix;
  1361. assetItem->cleanAssetName = assetItem->assetName;
  1362. }
  1363. }
  1364. //Assume for abledo if it has no suffix matches
  1365. assetItem->imageSuffixType = "Albedo";
  1366. }
  1367. else
  1368. {
  1369. }
  1370. }
  1371. else
  1372. {
  1373. //If we're processing an unaffiliated image without generating materials for it, we can check some other bits
  1374. if (assetItem->parentAssetItem == nullptr)
  1375. {
  1376. if (assetItem->typeHint != String::EmptyString)
  1377. {
  1378. ImageAssetType type = ImageAsset::getImageTypeFromName(StringTable->insert(assetItem->typeHint.c_str()));
  1379. if (type == ImageAssetType::GUI)
  1380. {
  1381. }
  1382. }
  1383. }
  1384. }
  1385. if(assetItem->assetName == assetItem->cleanAssetName && activeImportConfig->AlwaysAddImageSuffix)
  1386. {
  1387. assetItem->assetName = assetItem->assetName + activeImportConfig->AddedImageSuffix;
  1388. assetItem->cleanAssetName = assetItem->assetName;
  1389. }
  1390. assetItem->processed = true;
  1391. }
  1392. void AssetImporter::processMaterialAsset(AssetImportObject* assetItem)
  1393. {
  1394. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Preparing Material for Import: %s", assetItem->assetName.c_str());
  1395. activityLog.push_back(importLogBuffer);
  1396. String filePath = assetItem->filePath.getFullPath();
  1397. String fileName = assetItem->filePath.getFileName();
  1398. String fileExt = assetItem->filePath.getExtension();
  1399. const char* assetName = assetItem->assetName.c_str();
  1400. assetItem->generatedAsset = true;
  1401. if (activeImportConfig->IgnoreMaterials.isNotEmpty())
  1402. {
  1403. U32 ignoredMatNameCount = StringUnit::getUnitCount(activeImportConfig->IgnoreMaterials, ",;\t");
  1404. for (U32 i = 0; i < ignoredMatNameCount; i++)
  1405. {
  1406. String ignoredName = StringUnit::getUnit(activeImportConfig->IgnoreMaterials, i, ",;\t");
  1407. if (FindMatch::isMatch(ignoredName.c_str(), assetName, false))
  1408. {
  1409. assetItem->skip = true;
  1410. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Material %s has been ignored due to it's name being listed in the IgnoreMaterials list in the Import Config.", assetItem->assetName.c_str());
  1411. activityLog.push_back(importLogBuffer);
  1412. return;
  1413. }
  1414. }
  1415. }
  1416. if (activeImportConfig->UseExistingMaterials)
  1417. {
  1418. //So if the material already exists, we should just use that. So first, let's find out if it already exists
  1419. //check to see if the definition for this already exists
  1420. StringTableEntry existingMatAsset = MaterialAsset::getAssetIdByMaterialName(StringTable->insert(assetName));
  1421. if (existingMatAsset != StringTable->EmptyString())
  1422. {
  1423. assetItem->skip = true;
  1424. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Material %s has been skipped because we already found an asset Id that uses that material definition. The found assetId is: %s", assetItem->assetName.c_str(), existingMatAsset);
  1425. activityLog.push_back(importLogBuffer);
  1426. return;
  1427. }
  1428. //If there was no existing assetId, then lets see if it already exists in a legacy file, like a materials.cs or materials.tscript
  1429. //If it does, we'll just make our asset point to that instead of a new file
  1430. Material* mat = MATMGR->getMaterialDefinitionByName(assetName);
  1431. if (!mat)
  1432. mat = MATMGR->getMaterialDefinitionByMapTo(assetName);
  1433. if (!mat && assetItem->assetName != assetItem->cleanAssetName)
  1434. {
  1435. mat = MATMGR->getMaterialDefinitionByName(assetItem->cleanAssetName);
  1436. if (!mat)
  1437. mat = MATMGR->getMaterialDefinitionByMapTo(assetItem->cleanAssetName);
  1438. }
  1439. if(mat)
  1440. {
  1441. //We found a match, so just modify our asset item's info to point against it. This will create the asset definition, but otherwise leave the material definition as-is.
  1442. assetItem->filePath = (Torque::Path)(mat->getFilename());
  1443. }
  1444. }
  1445. else
  1446. {
  1447. if (activeImportConfig->AlwaysAddMaterialSuffix) //we only opt to force on the suffix if we're not obligating using the original material defs
  1448. {
  1449. assetItem->assetName += activeImportConfig->AddedMaterialSuffix;
  1450. assetItem->cleanAssetName = assetItem->assetName;
  1451. }
  1452. if (activeImportConfig->PopulateMaterialMaps)
  1453. {
  1454. //If we're trying to populate the rest of our material maps, we need to go looking
  1455. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Attempting to Auto-Populate Material Maps");
  1456. activityLog.push_back(importLogBuffer);
  1457. AssetImportObject* matchedImageTypes[ImageAsset::ImageTypeCount] = { nullptr };
  1458. String materialImageNoSuffix;
  1459. for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
  1460. {
  1461. AssetImportObject* childAssetItem = assetItem->childAssetItems[i];
  1462. if (childAssetItem->skip || childAssetItem->assetType != String("ImageAsset"))
  1463. continue;
  1464. for (S32 t = 0; t < ImageAsset::ImageTypeCount; t++)
  1465. {
  1466. //If the imageType name and child asset image type match, check it off our list
  1467. if (!dStricmp(ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)t), childAssetItem->imageSuffixType.c_str()))
  1468. {
  1469. matchedImageTypes[t] = childAssetItem;
  1470. if (t == ImageAsset::ImageTypes::Albedo)
  1471. {
  1472. String sufType;
  1473. String suffix = parseImageSuffixes(childAssetItem->assetName, &sufType);
  1474. String imageAssetName = childAssetItem->assetName;
  1475. if (suffix.isEmpty())
  1476. materialImageNoSuffix = imageAssetName;
  1477. else
  1478. materialImageNoSuffix = imageAssetName.erase(imageAssetName.length() - suffix.length(), suffix.length());//cache this for later as we may need it for file association lookups
  1479. }
  1480. }
  1481. }
  1482. }
  1483. //Now that we've checked off any existingly matched image types, process through the unmatched to look for files that associate
  1484. for (S32 t = 0; t < ImageAsset::ImageTypeCount; t++)
  1485. {
  1486. //This type wasn't found, so try and find a match based on suffix
  1487. String suffixList;
  1488. switch (t)
  1489. {
  1490. case ImageAsset::Albedo:
  1491. suffixList = activeImportConfig->DiffuseTypeSuffixes;
  1492. break;
  1493. case ImageAsset::Normal:
  1494. suffixList = activeImportConfig->NormalTypeSuffixes;
  1495. break;
  1496. case ImageAsset::ORMConfig:
  1497. suffixList = activeImportConfig->PBRTypeSuffixes;
  1498. break;
  1499. case ImageAsset::Metalness:
  1500. suffixList = activeImportConfig->MetalnessTypeSuffixes;
  1501. break;
  1502. case ImageAsset::AO:
  1503. suffixList = activeImportConfig->AOTypeSuffixes;
  1504. break;
  1505. case ImageAsset::Roughness:
  1506. suffixList = activeImportConfig->RoughnessTypeSuffixes;
  1507. break;
  1508. //TODO: Glow map lookup too
  1509. }
  1510. if (!matchedImageTypes[t])
  1511. {
  1512. U32 suffixCount = StringUnit::getUnitCount(suffixList.c_str(), ",;\t");
  1513. for (U32 i = 0; i < suffixCount; i++)
  1514. {
  1515. //First, try checking based on the material's assetName for our patternbase
  1516. String testPath = assetItem->filePath.getRootAndPath();
  1517. testPath += "/" + assetItem->cleanAssetName + StringUnit::getUnit(suffixList.c_str(), i, ",;\t");
  1518. String imagePath = AssetImporter::findImagePath(testPath);
  1519. if (imagePath.isNotEmpty())
  1520. {
  1521. //got a match!
  1522. AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
  1523. newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)t);
  1524. matchedImageTypes[t] = newImageAssetObj;
  1525. break;
  1526. }
  1527. else
  1528. {
  1529. if (materialImageNoSuffix.isNotEmpty())
  1530. {
  1531. testPath = assetItem->filePath.getRootAndPath();
  1532. testPath += "/" + materialImageNoSuffix + StringUnit::getUnit(suffixList.c_str(), i, ",;\t");
  1533. imagePath = AssetImporter::findImagePath(testPath);
  1534. if (imagePath.isNotEmpty())
  1535. {
  1536. //got a match!
  1537. AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
  1538. newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType((ImageAsset::ImageTypes)t);
  1539. matchedImageTypes[t] = newImageAssetObj;
  1540. break;
  1541. }
  1542. }
  1543. }
  1544. }
  1545. //If we're the abledo slot and after all that we didn't find anything, it probably is a suffixless image
  1546. if (t == ImageAsset::Albedo && matchedImageTypes[t] == nullptr)
  1547. {
  1548. String testPath = assetItem->filePath.getRootAndPath() + "/" + assetItem->cleanAssetName;
  1549. String imagePath = AssetImporter::findImagePath(testPath);
  1550. if (imagePath.isNotEmpty())
  1551. {
  1552. //got a match!
  1553. AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
  1554. //In the event that the names match, we want to avoid duplications, so we'll go ahead and append a suffix onto our new image asset
  1555. if (newImageAssetObj->assetName == assetItem->assetName)
  1556. {
  1557. newImageAssetObj->assetName += StringUnit::getUnit(suffixList.c_str(), 0, ",;\t");
  1558. newImageAssetObj->cleanAssetName = newImageAssetObj->assetName;
  1559. }
  1560. newImageAssetObj->imageSuffixType = ImageAsset::getImageTypeNameFromType(ImageAsset::ImageTypes::Albedo);
  1561. matchedImageTypes[t] = newImageAssetObj;
  1562. }
  1563. }
  1564. }
  1565. else
  1566. {
  1567. //just a bit of cleanup and logical testing for matches
  1568. //in the event we KNOW what the type is, but we don't have a suffix, such as a found image on a material lookup
  1569. //that doesn't have a suffix, we assume it to be the albedo, so we'll just append the suffix to avoid collisions if
  1570. //the name already matches our material name, similar to above logic
  1571. if (matchedImageTypes[t]->assetName == assetItem->assetName)
  1572. {
  1573. matchedImageTypes[t]->assetName += StringUnit::getUnit(suffixList.c_str(), 0, ",;\t");
  1574. matchedImageTypes[t]->cleanAssetName = matchedImageTypes[t]->assetName;
  1575. }
  1576. }
  1577. }
  1578. /*for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
  1579. {
  1580. AssetImportObject* childAssetItem = assetItem->childAssetItems[i];
  1581. if (childAssetItem->skip || childAssetItem->processed || childAssetItem->assetType != String("ImageAsset"))
  1582. continue;
  1583. if (childAssetItem->imageSuffixType == String("Albedo"))
  1584. {
  1585. assetItem->diffuseImageAsset = % childAssetItem;
  1586. }
  1587. }*/
  1588. }
  1589. }
  1590. assetItem->processed = true;
  1591. }
  1592. void AssetImporter::processShapeAsset(AssetImportObject* assetItem)
  1593. {
  1594. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Preparing Shape for Import: %s", assetItem->assetName.c_str());
  1595. activityLog.push_back(importLogBuffer);
  1596. String filePath = assetItem->filePath.getFullPath();
  1597. String fileName = assetItem->filePath.getFileName();
  1598. String fileExt = assetItem->filePath.getExtension();
  1599. if (assetItem->shapeInfo == nullptr)
  1600. {
  1601. GuiTreeViewCtrl* shapeInfo = new GuiTreeViewCtrl();
  1602. shapeInfo->registerObject();
  1603. if (fileExt.compare("dae") == 0)
  1604. {
  1605. enumColladaForImport(filePath, shapeInfo, false);
  1606. }
  1607. else if (fileExt.compare("dts") == 0)
  1608. {
  1609. enumDTSForImport(filePath, shapeInfo);
  1610. }
  1611. else
  1612. {
  1613. // Check if a cached DTS is available => no need to import the source file
  1614. // if we can load the DTS instead
  1615. AssimpShapeLoader loader;
  1616. loader.fillGuiTreeView(filePath.c_str(), shapeInfo);
  1617. }
  1618. assetItem->shapeInfo = shapeInfo;
  1619. }
  1620. if (activeImportConfig->AlwaysAddShapeSuffix)
  1621. {
  1622. assetItem->assetName += activeImportConfig->AddedShapeSuffix;
  1623. assetItem->cleanAssetName = assetItem->assetName;
  1624. }
  1625. S32 meshCount = dAtoi(assetItem->shapeInfo->getDataField(StringTable->insert("_meshCount"), nullptr));
  1626. S32 shapeItem = assetItem->shapeInfo->findItemByName("Meshes");
  1627. S32 animCount = dAtoi(assetItem->shapeInfo->getDataField(StringTable->insert("_animCount"), nullptr));
  1628. S32 animItem = assetItem->shapeInfo->findItemByName("Animations");
  1629. S32 materialCount = dAtoi(assetItem->shapeInfo->getDataField(StringTable->insert("_materialCount"), nullptr));
  1630. S32 matItem = assetItem->shapeInfo->findItemByName("Materials");
  1631. dSprintf(importLogBuffer, sizeof(importLogBuffer), " Shape Info: Mesh Count: %i | Material Count: %i | Anim Count: %i", meshCount, animCount, materialCount);
  1632. activityLog.push_back(importLogBuffer);
  1633. AssetImportConfig* cachedConfig = new AssetImportConfig();;
  1634. cachedConfig->registerObject();
  1635. activeImportConfig->CopyTo(cachedConfig);
  1636. if (!activeImportConfig->UseManualShapeConfigRules)
  1637. {
  1638. //Try and load a sis file if it exists for this format
  1639. activeImportConfig->loadSISFile(assetItem->filePath);
  1640. }
  1641. if (activeImportConfig->ImportMesh && meshCount > 0)
  1642. {
  1643. }
  1644. if (activeImportConfig->ImportAnimations && animCount > 0)
  1645. {
  1646. //If we have animations but no meshes, then this is a pure animation file so we can swap the asset type here
  1647. if (meshCount == 0)
  1648. {
  1649. assetItem->assetType = "ShapeAnimationAsset";
  1650. }
  1651. }
  1652. if (activeImportConfig->ImportMaterials && materialCount > 0)
  1653. {
  1654. S32 materialId = assetItem->shapeInfo->getChildItem(matItem);
  1655. processShapeMaterialInfo(assetItem, materialId);
  1656. materialId = assetItem->shapeInfo->getNextSiblingItem(materialId);
  1657. while (materialId != 0)
  1658. {
  1659. processShapeMaterialInfo(assetItem, materialId);
  1660. materialId = assetItem->shapeInfo->getNextSiblingItem(materialId);
  1661. }
  1662. }
  1663. //restore the cached version just in case we loaded a sis file
  1664. cachedConfig->CopyTo(activeImportConfig);
  1665. cachedConfig->deleteObject();
  1666. assetItem->processed = true;
  1667. }
  1668. void AssetImporter::processShapeMaterialInfo(AssetImportObject* assetItem, S32 materialItemId)
  1669. {
  1670. String matName = assetItem->shapeInfo->getItemText(materialItemId);
  1671. String matAssetName = matName;
  1672. if (matName == assetItem->assetName)
  1673. {
  1674. //So apparently we managed to name the material the same as the shape. So we'll tweak the name
  1675. matAssetName += activeImportConfig->AddedMaterialSuffix;
  1676. }
  1677. //Do a check so we don't import materials that are on our ignore list
  1678. if (activeImportConfig->IgnoreMaterials.isNotEmpty())
  1679. {
  1680. U32 ignoredMatNamesCount = StringUnit::getUnitCount(activeImportConfig->IgnoreMaterials, ",;\t");
  1681. for (U32 i = 0; i < ignoredMatNamesCount; i++)
  1682. {
  1683. const char* ignoreMatName = StringUnit::getUnit(activeImportConfig->IgnoreMaterials, i, ",;\t");
  1684. if (FindMatch::isMatch(ignoreMatName, matName.c_str(), false))
  1685. {
  1686. //If we have a match to one of our ignore names, just bail out here and skip the material wholesale
  1687. return;
  1688. }
  1689. }
  1690. }
  1691. String materialItemValue = assetItem->shapeInfo->getItemValue(materialItemId);
  1692. AssetImportObject* matAssetItem = nullptr;
  1693. //If it happens to just be a color value instead of an image, we'll go ahead and skip doing any lookups
  1694. //TODO: properly map the 'texture' color to the material that gets created
  1695. if (materialItemValue.startsWith("Color:"))
  1696. {
  1697. matAssetItem = addImportingAsset("MaterialAsset", "", assetItem, matName);
  1698. }
  1699. else
  1700. {
  1701. Torque::Path filePath = materialItemValue;
  1702. String fullFilePath = filePath.getFullFileName().c_str();
  1703. String shapePathBase = assetItem->filePath.getRootAndPath();
  1704. if (fullFilePath.isNotEmpty())
  1705. {
  1706. if (!Platform::isFile(fullFilePath.c_str()))
  1707. {
  1708. //could be a stale path reference, such as if it was downloaded elsewhere. Trim to just the filename and see
  1709. //if we can find it there
  1710. //trim (not found) if needbe
  1711. fullFilePath = fullFilePath.replace(" (Not Found)", "");
  1712. fullFilePath = fullFilePath.replace(" (not found)", "");
  1713. String testFileName = shapePathBase + "/" + fullFilePath;
  1714. if (Platform::isFile(testFileName.c_str()))
  1715. {
  1716. filePath = testFileName;
  1717. }
  1718. else
  1719. {
  1720. //Hmm, didn't find it. It could be that the in-model filename could be different by virtue of
  1721. //image extension. Some files have source content files like psd's, but the mesh was exported to use
  1722. //a dds or png, etc
  1723. Torque::Path testFilePath = testFileName;
  1724. String imgFileName = AssetImporter::findImagePath(testFilePath.getPath() + "/" + testFilePath.getFileName());
  1725. if (imgFileName.isNotEmpty())
  1726. filePath = imgFileName;
  1727. }
  1728. }
  1729. matAssetItem = addImportingAsset("MaterialAsset", shapePathBase + "/", assetItem, matName);
  1730. AssetImportObject* imageAssetItem = addImportingAsset("ImageAsset", filePath, matAssetItem, "");
  1731. String suffixType;
  1732. String suffix = parseImageSuffixes(imageAssetItem->assetName, &suffixType);
  1733. if (suffix.isNotEmpty())
  1734. {
  1735. imageAssetItem->imageSuffixType = suffixType;
  1736. }
  1737. else
  1738. {
  1739. //we'll assume it's albedo
  1740. imageAssetItem->imageSuffixType = "Albedo";
  1741. }
  1742. }
  1743. else
  1744. {
  1745. matAssetItem = addImportingAsset("MaterialAsset", shapePathBase + "/" + matName, assetItem, matName);
  1746. }
  1747. }
  1748. //In the event we modified the asset name(such as appending _Mat to avoid naming conflicts) update the name here
  1749. //This preseves the 'clean asset name' which we can later use for lookups and the like as needed
  1750. if (matAssetItem && matAssetName != matName)
  1751. matAssetItem->assetName = matAssetName;
  1752. }
  1753. void AssetImporter::processSoundAsset(AssetImportObject* assetItem)
  1754. {
  1755. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Preparing Image for Import: %s", assetItem->assetName.c_str());
  1756. activityLog.push_back(importLogBuffer);
  1757. if ((activeImportConfig->GenerateMaterialOnImport && assetItem->parentAssetItem == nullptr)/* || assetItem->parentAssetItem != nullptr*/)
  1758. {
  1759. //find our suffix match, if any
  1760. String noSuffixName = assetItem->assetName;
  1761. String suffixType;
  1762. String suffix = parseImageSuffixes(assetItem->assetName, &suffixType);
  1763. if (suffix.isNotEmpty())
  1764. {
  1765. assetItem->imageSuffixType = suffixType;
  1766. S32 suffixPos = assetItem->assetName.find(suffix, 0, String::NoCase | String::Left);
  1767. noSuffixName = assetItem->assetName.substr(0, suffixPos);
  1768. }
  1769. //We try to automatically populate materials under the naming convention: materialName: Rock, image maps: Rock_Albedo, Rock_Normal, etc
  1770. AssetImportObject* materialAsset = findImportingAssetByName(noSuffixName);
  1771. if (materialAsset != nullptr && materialAsset->assetType != String("MaterialAsset"))
  1772. {
  1773. //We may have a situation where an asset matches the no-suffix name, but it's not a material asset. Ignore this
  1774. //asset item for now
  1775. materialAsset = nullptr;
  1776. }
  1777. //If we didn't find a matching material asset in our current items, we'll make one now
  1778. if (materialAsset == nullptr)
  1779. {
  1780. if (!assetItem->filePath.isEmpty())
  1781. {
  1782. materialAsset = addImportingAsset("MaterialAsset", assetItem->filePath, nullptr, noSuffixName);
  1783. }
  1784. }
  1785. //Not that, one way or another, we have the generated material asset, lets move on to associating our image with it
  1786. if (materialAsset != nullptr && materialAsset != assetItem->parentAssetItem)
  1787. {
  1788. if (assetItem->parentAssetItem != nullptr)
  1789. {
  1790. //If the image had an existing parent, it gets removed from that parent's child item list
  1791. assetItem->parentAssetItem->childAssetItems.remove(assetItem);
  1792. }
  1793. else
  1794. {
  1795. //If it didn't have one, we're going to pull it from the importingAssets list
  1796. importingAssets.remove(assetItem);
  1797. }
  1798. //Now we can add it to the correct material asset
  1799. materialAsset->childAssetItems.push_back(assetItem);
  1800. assetItem->parentAssetItem = materialAsset;
  1801. assetHeirarchyChanged = true;
  1802. }
  1803. //Now to do some cleverness. If we're generating a material, we can parse like assets being imported(similar filenames) but different suffixes
  1804. //If we find these, we'll just populate into the original's material
  1805. //if we need to append the diffuse suffix and indeed didn't find a suffix on the name, do that here
  1806. if (suffixType.isEmpty())
  1807. {
  1808. if (activeImportConfig->UseDiffuseSuffixOnOriginImage)
  1809. {
  1810. String diffuseToken = StringUnit::getUnit(activeImportConfig->DiffuseTypeSuffixes, 0, ",;\t");
  1811. assetItem->assetName = assetItem->assetName + diffuseToken;
  1812. assetItem->cleanAssetName = assetItem->assetName;
  1813. }
  1814. else
  1815. {
  1816. //We need to ensure that our image asset doesn't match the same name as the material asset, so if we're not trying to force the diffuse suffix
  1817. //we'll give it a generic one
  1818. if ((materialAsset && materialAsset->assetName.compare(assetItem->assetName) == 0) || activeImportConfig->AlwaysAddImageSuffix)
  1819. {
  1820. assetItem->assetName = assetItem->assetName + activeImportConfig->AddedImageSuffix;
  1821. assetItem->cleanAssetName = assetItem->assetName;
  1822. }
  1823. }
  1824. //Assume for abledo if it has no suffix matches
  1825. assetItem->imageSuffixType = "Albedo";
  1826. }
  1827. }
  1828. assetItem->processed = true;
  1829. }
  1830. //
  1831. // Validation
  1832. //
  1833. bool AssetImporter::validateAssets()
  1834. {
  1835. importIssues = false;
  1836. resetAssetValidationStatus();
  1837. for (U32 i = 0; i < importingAssets.size(); i++)
  1838. {
  1839. validateAsset(importingAssets[i]);
  1840. resolveAssetItemIssues(importingAssets[i]);
  1841. }
  1842. return importIssues;
  1843. }
  1844. void AssetImporter::validateAsset(AssetImportObject* assetItem)
  1845. {
  1846. if (assetItem->skip)
  1847. return;
  1848. bool hasCollision = checkAssetForCollision(assetItem);
  1849. if (hasCollision)
  1850. {
  1851. importIssues = true;
  1852. return;
  1853. }
  1854. if (!isReimport)
  1855. {
  1856. AssetQuery aQuery;
  1857. U32 numAssetsFound = AssetDatabase.findAllAssets(&aQuery);
  1858. bool hasCollision = false;
  1859. for (U32 i = 0; i < numAssetsFound; i++)
  1860. {
  1861. StringTableEntry assetId = aQuery.mAssetList[i];
  1862. ModuleDefinition* moduleDef = AssetDatabase.getAssetModuleDefinition(assetId);
  1863. if ((moduleDef == NULL) || moduleDef->getModuleId() != StringTable->insert(targetModuleId.c_str()))
  1864. continue;
  1865. StringTableEntry assetName = AssetDatabase.getAssetName(assetId);
  1866. if (assetName == StringTable->insert(assetItem->assetName.c_str()))
  1867. {
  1868. hasCollision = true;
  1869. assetItem->status = "Error";
  1870. assetItem->statusType = "DuplicateAsset";
  1871. assetItem->statusInfo = "Duplicate asset names found within the target module!\nAsset \"" + assetItem->assetName + "\" of type \"" + assetItem->assetType + "\" has a matching name.\nPlease rename it and try again!";
  1872. //log it
  1873. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Asset %s has an identically named asset in the target module.", assetItem->assetName.c_str());
  1874. activityLog.push_back(importLogBuffer);
  1875. break;
  1876. }
  1877. }
  1878. }
  1879. if (!assetItem->filePath.isEmpty() && !assetItem->generatedAsset && !Platform::isFile(assetItem->filePath.getFullPath().c_str()))
  1880. {
  1881. assetItem->status = "Error";
  1882. assetItem->statusType = "MissingFile";
  1883. assetItem->statusInfo = "Unable to find file to be imported with provided path: " + assetItem->filePath + "\n Please select a valid file.";
  1884. //log it
  1885. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Asset %s's file at %s was not found.", assetItem->assetName.c_str(), assetItem->filePath.getFullPath().c_str());
  1886. activityLog.push_back(importLogBuffer);
  1887. }
  1888. if (assetItem->status == String("Warning"))
  1889. {
  1890. if (activeImportConfig->WarningsAsErrors)
  1891. {
  1892. assetItem->status = "Error";
  1893. //log it
  1894. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Import configuration has treated an import warning as an error.", assetItem->assetName.c_str());
  1895. activityLog.push_back(importLogBuffer);
  1896. }
  1897. }
  1898. if (assetItem->status == String("Error"))
  1899. importIssues = true;
  1900. for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
  1901. {
  1902. validateAsset(assetItem->childAssetItems[i]);
  1903. resolveAssetItemIssues(assetItem->childAssetItems[i]);
  1904. }
  1905. return;
  1906. }
  1907. void AssetImporter::resetAssetValidationStatus(AssetImportObject* assetItem)
  1908. {
  1909. if (assetItem == nullptr)
  1910. {
  1911. for (U32 i = 0; i < importingAssets.size(); i++)
  1912. {
  1913. if (importingAssets[i]->skip)
  1914. continue;
  1915. importingAssets[i]->status = "";
  1916. importingAssets[i]->statusType = "";
  1917. importingAssets[i]->statusInfo = "";
  1918. //If it wasn't a match, try recusing on the children(if any)
  1919. resetAssetValidationStatus(importingAssets[i]);
  1920. }
  1921. }
  1922. else
  1923. {
  1924. //this is the child recursing section
  1925. for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
  1926. {
  1927. if (assetItem->childAssetItems[i]->skip)
  1928. continue;
  1929. assetItem->childAssetItems[i]->status = "";
  1930. assetItem->childAssetItems[i]->statusType = "";
  1931. assetItem->childAssetItems[i]->statusInfo = "";
  1932. //If it wasn't a match, try recusing on the children(if any)
  1933. resetAssetValidationStatus(assetItem->childAssetItems[i]);
  1934. }
  1935. }
  1936. }
  1937. bool AssetImporter::checkAssetForCollision(AssetImportObject* assetItemToCheck, AssetImportObject* assetItem)
  1938. {
  1939. bool results = false;
  1940. if (assetItem == nullptr)
  1941. {
  1942. for (U32 i = 0; i < importingAssets.size(); i++)
  1943. {
  1944. AssetImportObject* importingAsset = importingAssets[i];
  1945. if (importingAsset->skip)
  1946. continue;
  1947. if ((assetItemToCheck->assetName.compare(importingAsset->assetName) == 0) && (assetItemToCheck->getId() != importingAsset->getId()))
  1948. {
  1949. //we do have a collision, note the collsion and bail out
  1950. assetItemToCheck->status = "Warning";
  1951. assetItemToCheck->statusType = "DuplicateImportAsset";
  1952. assetItemToCheck->statusInfo = "Duplicate asset names found with importing assets!\nAsset \"" + importingAsset->assetName + "\" of the type \"" + importingAsset->assetType + "\" and \"" +
  1953. assetItemToCheck->assetName + "\" of the type \"" + assetItemToCheck->assetType + "\" have matching names.\nPlease rename one of them.";
  1954. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Warning! Asset %s, type %s has a naming collision with another importing asset: %s, type %s",
  1955. assetItemToCheck->assetName.c_str(), assetItemToCheck->assetType.c_str(),
  1956. importingAsset->assetName.c_str(), importingAsset->assetType.c_str());
  1957. activityLog.push_back(importLogBuffer);
  1958. return true;
  1959. }
  1960. //If it wasn't a match, try recusing on the children(if any)
  1961. results = checkAssetForCollision(assetItemToCheck, importingAsset);
  1962. if (results)
  1963. return results;
  1964. }
  1965. }
  1966. else
  1967. {
  1968. //this is the child recursing section
  1969. for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
  1970. {
  1971. AssetImportObject* childAsset = assetItem->childAssetItems[i];
  1972. if (childAsset->skip)
  1973. continue;
  1974. if ((assetItemToCheck->assetName.compare(childAsset->assetName) == 0) && (assetItemToCheck->getId() != childAsset->getId()))
  1975. {
  1976. //we do have a collision, note the collsion and bail out
  1977. assetItemToCheck->status = "Warning";
  1978. assetItemToCheck->statusType = "DuplicateImportAsset";
  1979. assetItemToCheck->statusInfo = "Duplicate asset names found with importing assets!\nAsset \"" + assetItem->assetName + "\" of the type \"" + assetItem->assetType + "\" and \"" +
  1980. assetItemToCheck->assetName + "\" of the type \"" + assetItemToCheck->assetType + "\" have matching names.\nPlease rename one of them.";
  1981. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Warning! Asset %s, type %s has a naming collision with another importing asset: %s, type %s",
  1982. assetItemToCheck->assetName.c_str(), assetItemToCheck->assetType.c_str(),
  1983. childAsset->assetName.c_str(), childAsset->assetType.c_str());
  1984. activityLog.push_back(importLogBuffer);
  1985. return true;
  1986. }
  1987. //If it wasn't a match, try recusing on the children(if any)
  1988. results = checkAssetForCollision(assetItemToCheck, childAsset);
  1989. if (results)
  1990. return results;
  1991. }
  1992. }
  1993. return results;
  1994. }
  1995. void AssetImporter::resolveAssetItemIssues(AssetImportObject* assetItem)
  1996. {
  1997. if (assetItem->statusType == String("DuplicateImportAsset") || assetItem->statusType == String("DuplicateAsset"))
  1998. {
  1999. String humanReadableReason = assetItem->statusType == String("DuplicateImportAsset") ? "Importing asset was duplicate of another importing asset" : "Importing asset was duplicate of an existing asset";
  2000. //get the config value for duplicateAutoResolution
  2001. if (activeImportConfig->DuplicateAutoResolution == String("AutoPrune"))
  2002. {
  2003. //delete the item
  2004. deleteImportingAsset(assetItem);
  2005. //log it's deletion
  2006. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Asset %s was autopruned due to %s as part of the Import Configuration", assetItem->assetName.c_str(), humanReadableReason.c_str());
  2007. activityLog.push_back(importLogBuffer);
  2008. importIssues = false;
  2009. }
  2010. else if (activeImportConfig->DuplicateAutoResolution == String("AutoRename"))
  2011. {
  2012. //Set trailing number
  2013. String renamedAssetName = assetItem->assetName;
  2014. renamedAssetName = Sim::getUniqueName(renamedAssetName.c_str());
  2015. //Log it's renaming
  2016. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Asset %s was renamed due to %s as part of the Import Configuration", assetItem->assetName.c_str(), humanReadableReason.c_str());
  2017. activityLog.push_back(importLogBuffer);
  2018. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Asset %s was renamed to %s", assetItem->assetName.c_str(), renamedAssetName.c_str());
  2019. activityLog.push_back(importLogBuffer);
  2020. assetItem->assetName = renamedAssetName;
  2021. //Whatever status we had prior is no longer relevent, so reset the status
  2022. resetAssetValidationStatus(assetItem);
  2023. importIssues = false;
  2024. }
  2025. else if (activeImportConfig->DuplicateAutoResolution == String("UseExisting"))
  2026. {
  2027. }
  2028. else if (activeImportConfig->DuplicateAutoResolution == String("FolderPrefix"))
  2029. {
  2030. String renamedAssetName = assetItem->assetName;
  2031. //Set trailing number
  2032. S32 dirIndex = assetItem->filePath.getDirectoryCount() - 1;
  2033. while (dirIndex > -1)
  2034. {
  2035. renamedAssetName = assetItem->assetName;
  2036. String owningFolder = assetItem->filePath.getDirectory(dirIndex);
  2037. renamedAssetName = owningFolder + "_" + renamedAssetName;
  2038. if (AssetDatabase.isDeclaredAsset(renamedAssetName))
  2039. {
  2040. dirIndex--;
  2041. continue;
  2042. }
  2043. break;
  2044. }
  2045. //Log it's renaming
  2046. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Asset %s was renamed due to %s as part of the Import Configuration", assetItem->assetName.c_str(), humanReadableReason.c_str());
  2047. activityLog.push_back(importLogBuffer);
  2048. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Asset %s was renamed to %s", assetItem->assetName.c_str(), renamedAssetName.c_str());
  2049. activityLog.push_back(importLogBuffer);
  2050. assetItem->assetName = renamedAssetName;
  2051. //Whatever status we had prior is no longer relevent, so reset the status
  2052. resetAssetValidationStatus(assetItem);
  2053. importIssues = false;
  2054. }
  2055. }
  2056. else if (assetItem->statusType == String("MissingFile"))
  2057. {
  2058. //Trigger callback to look?
  2059. }
  2060. }
  2061. void AssetImporter::resetImportConfig()
  2062. {
  2063. //use a default import config
  2064. if (activeImportConfig == nullptr)
  2065. {
  2066. activeImportConfig = new AssetImportConfig();
  2067. activeImportConfig->registerObject();
  2068. }
  2069. bool foundConfig = false;
  2070. Settings* editorSettings;
  2071. //See if we can get our editor settings
  2072. if (Sim::findObject("EditorSettings", editorSettings))
  2073. {
  2074. String defaultImportConfig = editorSettings->value("Assets/AssetImporDefaultConfig");
  2075. //If we found it, grab the import configs
  2076. Settings* importConfigs;
  2077. if (Sim::findObject("AssetImportSettings", importConfigs))
  2078. {
  2079. //Now load the editor setting-deigned config!
  2080. activeImportConfig->loadImportConfig(importConfigs, defaultImportConfig.c_str());
  2081. }
  2082. }
  2083. }
  2084. //
  2085. // Importing
  2086. //
  2087. StringTableEntry AssetImporter::autoImportFile(Torque::Path filePath, String typeHint)
  2088. {
  2089. //Just in case we're reusing the same importer object from another import session, nuke any existing files
  2090. resetImportSession(true);
  2091. String assetType = getAssetTypeByFile(filePath);
  2092. if (assetType == String("Folder") || assetType == String("Zip"))
  2093. {
  2094. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Unable to import file %s because it is a folder or zip.", filePath.getFullPath().c_str());
  2095. activityLog.push_back(importLogBuffer);
  2096. dumpActivityLog();
  2097. return StringTable->EmptyString();
  2098. }
  2099. if (assetType.isEmpty())
  2100. {
  2101. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Unable to import file %s because it is of an unrecognized/unsupported type.", filePath.getFullPath().c_str());
  2102. activityLog.push_back(importLogBuffer);
  2103. dumpActivityLog();
  2104. return StringTable->EmptyString();
  2105. }
  2106. //Find out if the filepath has an associated module to it. If we're importing in-place, it needs to be within a module's directory
  2107. ModuleDefinition* targetModuleDef = AssetImporter::getModuleFromPath(filePath);
  2108. if (targetModuleDef == nullptr)
  2109. {
  2110. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Unable to import file %s because it is not in a valid module folder.", filePath.getFullPath().c_str());
  2111. activityLog.push_back(importLogBuffer);
  2112. dumpActivityLog();
  2113. return StringTable->EmptyString();
  2114. }
  2115. else
  2116. {
  2117. targetModuleId = targetModuleDef->getModuleId();
  2118. }
  2119. //set our path
  2120. targetPath = filePath.getPath();
  2121. resetImportConfig();
  2122. AssetImportObject* assetItem = addImportingAsset(assetType, filePath, nullptr, "");
  2123. processImportAssets();
  2124. bool hasIssues = validateAssets();
  2125. if (hasIssues)
  2126. {
  2127. //log it
  2128. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Import process has failed due to issues discovered during validation!");
  2129. activityLog.push_back(importLogBuffer);
  2130. }
  2131. else
  2132. {
  2133. importAssets();
  2134. }
  2135. dumpActivityLog();
  2136. if (hasIssues)
  2137. {
  2138. return StringTable->EmptyString();
  2139. }
  2140. else
  2141. {
  2142. String assetId = targetModuleId + ":" + assetItem->assetName;
  2143. return StringTable->insert(assetId.c_str());
  2144. }
  2145. }
  2146. void AssetImporter::importAssets(AssetImportObject* assetItem)
  2147. {
  2148. ModuleDefinition* moduleDef = ModuleDatabase.findModule(targetModuleId.c_str(), 1);
  2149. if (moduleDef == nullptr)
  2150. {
  2151. dSprintf(importLogBuffer, sizeof(importLogBuffer), "AssetImporter::importAssets - Unable to find moduleId %s", targetModuleId.c_str());
  2152. activityLog.push_back(importLogBuffer);
  2153. return;
  2154. }
  2155. if (assetItem == nullptr)
  2156. {
  2157. for (U32 i = 0; i < importingAssets.size(); i++)
  2158. {
  2159. if (importingAssets[i]->skip)
  2160. continue;
  2161. Torque::Path assetPath;
  2162. if (importingAssets[i]->assetType == String("ImageAsset"))
  2163. {
  2164. assetPath = importImageAsset(importingAssets[i]);
  2165. }
  2166. else if (importingAssets[i]->assetType == String("ShapeAsset"))
  2167. {
  2168. assetPath = importShapeAsset(importingAssets[i]);
  2169. }
  2170. else if (importingAssets[i]->assetType == String("SoundAsset"))
  2171. {
  2172. assetPath = importSoundAsset(importingAssets[i]);
  2173. }
  2174. else if (importingAssets[i]->assetType == String("MaterialAsset"))
  2175. {
  2176. assetPath = importMaterialAsset(importingAssets[i]);
  2177. }
  2178. else
  2179. {
  2180. finalImportedAssetPath = String::EmptyString;
  2181. String processCommand = "import";
  2182. processCommand += importingAssets[i]->assetType;
  2183. if (isMethod(processCommand.c_str()))
  2184. {
  2185. Con::executef(this, processCommand.c_str(), importingAssets[i]);
  2186. assetPath = finalImportedAssetPath;
  2187. }
  2188. }
  2189. /*else if (importingAssets[i]->assetType == String("ShapeAnimationAsset"))
  2190. assetPath = ShapeAnimationAsset::importAsset(importingAssets[i]);*/
  2191. if (assetPath.isEmpty() && importingAssets[i]->assetType != String("MaterialAsset"))
  2192. {
  2193. dSprintf(importLogBuffer, sizeof(importLogBuffer), "AssetImporter::importAssets - Import attempt of %s failed, so skipping asset.", importingAssets[i]->assetName.c_str());
  2194. activityLog.push_back(importLogBuffer);
  2195. continue;
  2196. }
  2197. else
  2198. {
  2199. //If we got a valid filepath back from the import action, then we know we're good to go and we can go ahead and register the asset!
  2200. if (!isReimport)
  2201. {
  2202. bool registerSuccess = AssetDatabase.addDeclaredAsset(moduleDef, assetPath.getFullPath().c_str());
  2203. if (!registerSuccess)
  2204. {
  2205. dSprintf(importLogBuffer, sizeof(importLogBuffer), "AssetImporter::importAssets - Failed to successfully register new asset at path %s to moduleId %s", assetPath.getFullPath().c_str(), targetModuleId.c_str());
  2206. activityLog.push_back(importLogBuffer);
  2207. }
  2208. }
  2209. else
  2210. {
  2211. String assetId = importingAssets[i]->moduleName + ":" + importingAssets[i]->assetName;
  2212. bool refreshSuccess = AssetDatabase.refreshAsset(assetId.c_str());
  2213. if (!refreshSuccess)
  2214. {
  2215. dSprintf(importLogBuffer, sizeof(importLogBuffer), "AssetImporter::importAssets - Failed to refresh reimporting asset %s.", importingAssets[i]->assetName.c_str());
  2216. activityLog.push_back(importLogBuffer);
  2217. }
  2218. }
  2219. }
  2220. //recurse if needed
  2221. importAssets(importingAssets[i]);
  2222. }
  2223. }
  2224. else
  2225. {
  2226. //this is the child recursing section
  2227. for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
  2228. {
  2229. AssetImportObject* childItem = assetItem->childAssetItems[i];
  2230. if (childItem->skip)
  2231. continue;
  2232. Torque::Path assetPath;
  2233. if (childItem->assetType == String("ImageAsset"))
  2234. {
  2235. assetPath = importImageAsset(childItem);
  2236. }
  2237. else if (childItem->assetType == String("ShapeAsset"))
  2238. {
  2239. assetPath = importShapeAsset(childItem);
  2240. }
  2241. else if (childItem->assetType == String("SoundAsset"))
  2242. {
  2243. assetPath = importSoundAsset(childItem);
  2244. }
  2245. else if (childItem->assetType == String("MaterialAsset"))
  2246. {
  2247. assetPath = importMaterialAsset(childItem);
  2248. }
  2249. /*else if (childItem->assetType == String("ShapeAnimationAsset"))
  2250. assetPath = ShapeAnimationAsset::importAsset(childItem);*/
  2251. else
  2252. {
  2253. finalImportedAssetPath = String::EmptyString;
  2254. String processCommand = "import";
  2255. processCommand += childItem->assetType;
  2256. if (isMethod(processCommand.c_str()))
  2257. {
  2258. ConsoleValueRef importReturnVal = Con::executef(this, processCommand.c_str(), childItem);
  2259. assetPath = Torque::Path(importReturnVal.getStringValue());
  2260. }
  2261. }
  2262. if (assetPath.isEmpty() && childItem->assetType != String("MaterialAsset"))
  2263. {
  2264. dSprintf(importLogBuffer, sizeof(importLogBuffer), "AssetImporter::importAssets - Import attempt of %s failed, so skipping asset.", childItem->assetName.c_str());
  2265. activityLog.push_back(importLogBuffer);
  2266. continue;
  2267. }
  2268. else
  2269. {
  2270. //If we got a valid filepath back from the import action, then we know we're good to go and we can go ahead and register the asset!
  2271. if (!isReimport)
  2272. {
  2273. bool registerSuccess = AssetDatabase.addDeclaredAsset(moduleDef, assetPath.getFullPath().c_str());
  2274. if (!registerSuccess)
  2275. {
  2276. dSprintf(importLogBuffer, sizeof(importLogBuffer), "AssetImporter::importAssets - Failed to successfully register new asset at path %s to moduleId %s", assetPath.getFullPath().c_str(), targetModuleId.c_str());
  2277. activityLog.push_back(importLogBuffer);
  2278. }
  2279. }
  2280. else
  2281. {
  2282. String assetId = childItem->moduleName + ":" + childItem->assetName;
  2283. bool refreshSuccess = AssetDatabase.refreshAsset(assetId.c_str());
  2284. if (!refreshSuccess)
  2285. {
  2286. dSprintf(importLogBuffer, sizeof(importLogBuffer), "AssetImporter::importAssets - Failed to refresh reimporting asset %s.", childItem->assetName.c_str());
  2287. activityLog.push_back(importLogBuffer);
  2288. }
  2289. }
  2290. }
  2291. //recurse if needed
  2292. importAssets(childItem);
  2293. }
  2294. }
  2295. }
  2296. //
  2297. // Type-specific import logic
  2298. //
  2299. Torque::Path AssetImporter::importImageAsset(AssetImportObject* assetItem)
  2300. {
  2301. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Beginning importing of Image Asset: %s", assetItem->assetName.c_str());
  2302. activityLog.push_back(importLogBuffer);
  2303. ImageAsset* newAsset = new ImageAsset();
  2304. newAsset->registerObject();
  2305. StringTableEntry assetName = StringTable->insert(assetItem->assetName.c_str());
  2306. String imageFileName = assetItem->filePath.getFileName() + "." + assetItem->filePath.getExtension();
  2307. String assetPath = targetPath + "/" + imageFileName;
  2308. String tamlPath = targetPath + "/" + assetName + ".asset.taml";
  2309. String originalPath = assetItem->filePath.getFullPath().c_str();
  2310. char qualifiedFromFile[2048];
  2311. char qualifiedToFile[2048];
  2312. Platform::makeFullPathName(originalPath.c_str(), qualifiedFromFile, sizeof(qualifiedFromFile));
  2313. Platform::makeFullPathName(assetPath.c_str(), qualifiedToFile, sizeof(qualifiedToFile));
  2314. newAsset->setAssetName(assetName);
  2315. newAsset->setImageFileName(imageFileName.c_str());
  2316. //If it's not a re-import, check that the file isn't being in-place imported. If it isn't, store off the original
  2317. //file path for reimporting support later
  2318. if (!isReimport && String::compare(qualifiedFromFile, qualifiedToFile))
  2319. {
  2320. newAsset->setDataField(StringTable->insert("originalFilePath"), nullptr, qualifiedFromFile);
  2321. }
  2322. if (assetItem->typeHint != String::EmptyString)
  2323. {
  2324. newAsset->setImageType(ImageAsset::getImageTypeFromName(StringTable->insert(assetItem->typeHint.c_str())));
  2325. }
  2326. else
  2327. {
  2328. ImageAsset::ImageTypes imageType = ImageAsset::getImageTypeFromName(assetItem->imageSuffixType.c_str());
  2329. newAsset->setImageType(imageType);
  2330. }
  2331. Taml tamlWriter;
  2332. bool importSuccessful = tamlWriter.write(newAsset, tamlPath.c_str());
  2333. if (!importSuccessful)
  2334. {
  2335. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Unable to write asset taml file %s", tamlPath.c_str());
  2336. activityLog.push_back(importLogBuffer);
  2337. return "";
  2338. }
  2339. if (!isReimport)
  2340. {
  2341. bool isInPlace = !String::compare(qualifiedFromFile, qualifiedToFile);
  2342. if (!isInPlace && !dPathCopy(qualifiedFromFile, qualifiedToFile, !isReimport))
  2343. {
  2344. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Unable to copy file %s", assetItem->filePath.getFullPath().c_str());
  2345. activityLog.push_back(importLogBuffer);
  2346. return "";
  2347. }
  2348. }
  2349. return tamlPath;
  2350. }
  2351. Torque::Path AssetImporter::importMaterialAsset(AssetImportObject* assetItem)
  2352. {
  2353. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Beginning importing of Material Asset: %s", assetItem->assetName.c_str());
  2354. activityLog.push_back(importLogBuffer);
  2355. MaterialAsset* newAsset = new MaterialAsset();
  2356. newAsset->registerObject();
  2357. StringTableEntry assetName = StringTable->insert(assetItem->assetName.c_str());
  2358. String tamlPath = targetPath + "/" + assetName + ".asset.taml";
  2359. String scriptName = assetItem->assetName + "." TORQUE_SCRIPT_EXTENSION;
  2360. String scriptPath = targetPath + "/" + scriptName;
  2361. String originalPath = assetItem->filePath.getFullPath().c_str();
  2362. char qualifiedFromFile[2048];
  2363. Platform::makeFullPathName(originalPath.c_str(), qualifiedFromFile, sizeof(qualifiedFromFile));
  2364. newAsset->setAssetName(assetName);
  2365. newAsset->setScriptFile(scriptName.c_str());
  2366. newAsset->setDataField(StringTable->insert("originalFilePath"), nullptr, qualifiedFromFile);
  2367. newAsset->setDataField(StringTable->insert("materialDefinitionName"), nullptr, assetName);
  2368. //iterate through and write out the material maps dependencies
  2369. S32 dependencySlotId = 0;
  2370. for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
  2371. {
  2372. AssetImportObject* childItem = assetItem->childAssetItems[i];
  2373. if (childItem->skip || !childItem->processed || childItem->assetType.compare("ImageAsset") != 0)
  2374. continue;
  2375. char dependencyFieldName[64];
  2376. dSprintf(dependencyFieldName, 64, "imageMap%i", dependencySlotId);
  2377. char dependencyFieldDef[512];
  2378. dSprintf(dependencyFieldDef, 512, "%s=%s:%s", ASSET_ID_SIGNATURE, targetModuleId.c_str(), childItem->assetName.c_str());
  2379. newAsset->setDataField(StringTable->insert(dependencyFieldName), nullptr, dependencyFieldDef);
  2380. dependencySlotId++;
  2381. }
  2382. Taml tamlWriter;
  2383. bool importSuccessful = tamlWriter.write(newAsset, tamlPath.c_str());
  2384. if (!importSuccessful)
  2385. {
  2386. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Unable to write asset taml file %s", tamlPath.c_str());
  2387. activityLog.push_back(importLogBuffer);
  2388. return "";
  2389. }
  2390. //build the ORMConfig file if we're flagged to and have valid image maps
  2391. if (activeImportConfig->CreateORMConfig)
  2392. {
  2393. AssetImportObject* ormMap = nullptr;
  2394. AssetImportObject* roughnessMap = nullptr;
  2395. AssetImportObject* metalnessMap = nullptr;
  2396. AssetImportObject* aoMap = nullptr;
  2397. //We need to find any/all respective image maps for the given channels
  2398. for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
  2399. {
  2400. AssetImportObject* childItem = assetItem->childAssetItems[i];
  2401. if (childItem->skip || childItem->assetType.compare("ImageAsset") != 0)
  2402. continue;
  2403. if (childItem->imageSuffixType.compare("ORMConfig") == 0)
  2404. ormMap = childItem;
  2405. else if(childItem->imageSuffixType.compare("Roughness") == 0)
  2406. roughnessMap = childItem;
  2407. else if (childItem->imageSuffixType.compare("Metalness") == 0)
  2408. metalnessMap = childItem;
  2409. else if (childItem->imageSuffixType.compare("AO") == 0)
  2410. aoMap = childItem;
  2411. }
  2412. if (ormMap != nullptr && ormMap->generatedAsset)
  2413. {
  2414. if (roughnessMap != nullptr || metalnessMap != nullptr || aoMap != nullptr)
  2415. {
  2416. U32 channelKey[4] = { 0,1,2,3 };
  2417. GFX->getTextureManager()->saveCompositeTexture(aoMap->filePath.getFullPath(), roughnessMap->filePath.getFullPath(), metalnessMap->filePath.getFullPath(), "",
  2418. channelKey, ormMap->filePath.getFullPath(), &GFXTexturePersistentProfile);
  2419. }
  2420. }
  2421. }
  2422. FileObject* file = new FileObject();
  2423. file->registerObject();
  2424. if (activeImportConfig->UseExistingMaterials && Platform::isFile(qualifiedFromFile))
  2425. {
  2426. //Now write the script file containing our material out
  2427. //There's 2 ways to do this. If we're in-place importing an existing asset, we can see if the definition existed already, like in an old
  2428. //materials.tscript file. if it does, we can just find the object by name, and save it out to our new file
  2429. //If not, we'll just generate one
  2430. Material* existingMat = MATMGR->getMaterialDefinitionByName(assetName);
  2431. //It's also possible that, for legacy models, the material hooks in via the material's mapTo field, and the material name is something completely different
  2432. //So we'll check for that as well if we didn't find it by name up above
  2433. if (existingMat == nullptr)
  2434. existingMat = MATMGR->getMaterialDefinitionByMapTo(assetName);
  2435. if (existingMat == nullptr && assetItem->assetName != assetItem->cleanAssetName)
  2436. {
  2437. existingMat = MATMGR->getMaterialDefinitionByName(assetItem->cleanAssetName);
  2438. if (existingMat == nullptr)
  2439. existingMat = MATMGR->getMaterialDefinitionByMapTo(assetItem->cleanAssetName);
  2440. }
  2441. if (existingMat)
  2442. {
  2443. PersistenceManager* persistMgr;
  2444. if (Sim::findObject("ImageAssetValidator", persistMgr))
  2445. {
  2446. for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
  2447. {
  2448. AssetImportObject* childItem = assetItem->childAssetItems[i];
  2449. if (childItem->skip || !childItem->processed || childItem->assetType.compare("ImageAsset") != 0)
  2450. continue;
  2451. String path = childItem->filePath.getFullFileName();
  2452. String mapFieldName = "";
  2453. String assetFieldName = "";
  2454. ImageAsset::ImageTypes imageType = ImageAsset::getImageTypeFromName(childItem->imageSuffixType);
  2455. if (imageType == ImageAsset::ImageTypes::Albedo || childItem->imageSuffixType.isEmpty())
  2456. {
  2457. mapFieldName = "DiffuseMap";
  2458. }
  2459. else if (imageType == ImageAsset::ImageTypes::Normal)
  2460. {
  2461. mapFieldName = "NormalMap";
  2462. }
  2463. else if (imageType == ImageAsset::ImageTypes::ORMConfig)
  2464. {
  2465. mapFieldName = "ORMConfig";
  2466. }
  2467. else if (imageType == ImageAsset::ImageTypes::Metalness)
  2468. {
  2469. mapFieldName = "MetalnessMap";
  2470. }
  2471. else if (imageType == ImageAsset::ImageTypes::AO)
  2472. {
  2473. mapFieldName = "AOMap";
  2474. }
  2475. else if (imageType == ImageAsset::ImageTypes::Roughness)
  2476. {
  2477. mapFieldName = "RoughnessMap";
  2478. }
  2479. assetFieldName = mapFieldName + "Asset[0]";
  2480. mapFieldName += "[0]";
  2481. //If there's already an existing image map file on the material definition in this slot, don't override it
  2482. if (!path.isEmpty())
  2483. existingMat->writeField(mapFieldName.c_str(), path.c_str());
  2484. String targetAsset = targetModuleId + ":" + childItem->assetName;
  2485. existingMat->writeField(assetFieldName.c_str(), targetAsset.c_str());
  2486. }
  2487. persistMgr->setDirty(existingMat);
  2488. }
  2489. else
  2490. {
  2491. Con::errorf("ImageAssetValidator not found!");
  2492. }
  2493. }
  2494. else
  2495. {
  2496. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Failed to find original material definition %s!", assetName);
  2497. activityLog.push_back(importLogBuffer);
  2498. return tamlPath;
  2499. }
  2500. }
  2501. else if (file->openForWrite(scriptPath.c_str()))
  2502. {
  2503. file->writeLine((U8*)"//--- OBJECT WRITE BEGIN ---");
  2504. char lineBuffer[1024];
  2505. dSprintf(lineBuffer, 1024, "singleton Material(%s) {", assetName);
  2506. file->writeLine((U8*)lineBuffer);
  2507. dSprintf(lineBuffer, 1024, " mapTo=\"%s\";", assetName);
  2508. file->writeLine((U8*)lineBuffer);
  2509. bool hasRoughness = false;
  2510. for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
  2511. {
  2512. AssetImportObject* childItem = assetItem->childAssetItems[i];
  2513. if (childItem->skip || !childItem->processed || childItem->assetType.compare("ImageAsset") != 0)
  2514. continue;
  2515. String mapFieldName = "";
  2516. String assetFieldName = "";
  2517. ImageAsset::ImageTypes imageType = ImageAsset::getImageTypeFromName(childItem->imageSuffixType);
  2518. if (imageType == ImageAsset::ImageTypes::Albedo || childItem->imageSuffixType.isEmpty())
  2519. {
  2520. mapFieldName = "DiffuseMap";
  2521. }
  2522. else if (imageType == ImageAsset::ImageTypes::Normal)
  2523. {
  2524. mapFieldName = "NormalMap";
  2525. }
  2526. else if (imageType == ImageAsset::ImageTypes::ORMConfig)
  2527. {
  2528. mapFieldName = "ORMConfigMap";
  2529. }
  2530. else if (imageType == ImageAsset::ImageTypes::Metalness)
  2531. {
  2532. mapFieldName = "MetalnessMap";
  2533. }
  2534. else if (imageType == ImageAsset::ImageTypes::AO)
  2535. {
  2536. mapFieldName = "AOMap";
  2537. }
  2538. else if (imageType == ImageAsset::ImageTypes::Roughness)
  2539. {
  2540. mapFieldName = "RoughnessMap";
  2541. hasRoughness = true;
  2542. }
  2543. assetFieldName = mapFieldName + "Asset";
  2544. mapFieldName += "[0]";
  2545. //String path = childItem->filePath.getFullFileName();
  2546. //dSprintf(lineBuffer, 1024, " %s = \"%s\";", mapFieldName.c_str(), path.c_str());
  2547. //file->writeLine((U8*)lineBuffer);
  2548. dSprintf(lineBuffer, 1024, " %s = \"%s:%s\";", assetFieldName.c_str(), targetModuleId.c_str(), childItem->assetName.c_str());
  2549. file->writeLine((U8*)lineBuffer);
  2550. }
  2551. if (hasRoughness)
  2552. {
  2553. file->writeLine((U8*)" invertSmoothness = true;");
  2554. }
  2555. file->writeLine((U8*)"};");
  2556. file->writeLine((U8*)"//--- OBJECT WRITE END ---");
  2557. file->close();
  2558. }
  2559. else
  2560. {
  2561. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Unable to write asset script file %s", scriptPath.c_str());
  2562. activityLog.push_back(importLogBuffer);
  2563. return "";
  2564. }
  2565. return tamlPath;
  2566. }
  2567. Torque::Path AssetImporter::importShapeAsset(AssetImportObject* assetItem)
  2568. {
  2569. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Beginning importing of Shape Asset: %s", assetItem->assetName.c_str());
  2570. activityLog.push_back(importLogBuffer);
  2571. ShapeAsset* newAsset = new ShapeAsset();
  2572. newAsset->registerObject();
  2573. StringTableEntry assetName = StringTable->insert(assetItem->assetName.c_str());
  2574. String shapeFileName = assetItem->filePath.getFileName() + "." + assetItem->filePath.getExtension();
  2575. String constructorFileName = assetItem->filePath.getFileName() + "." TORQUE_SCRIPT_EXTENSION;
  2576. String assetPath = targetPath + "/" + shapeFileName;
  2577. String constructorPath = targetPath + "/" + constructorFileName;
  2578. String tamlPath = targetPath + "/" + assetName + ".asset.taml";
  2579. String originalPath = assetItem->filePath.getFullPath().c_str();
  2580. String originalConstructorPath = assetItem->filePath.getPath() + "/" + constructorFileName;
  2581. char qualifiedFromFile[2048];
  2582. char qualifiedToFile[2048];
  2583. char qualifiedFromCSFile[2048];
  2584. char qualifiedToCSFile[2048];
  2585. Platform::makeFullPathName(originalPath.c_str(), qualifiedFromFile, sizeof(qualifiedFromFile));
  2586. Platform::makeFullPathName(assetPath.c_str(), qualifiedToFile, sizeof(qualifiedToFile));
  2587. Platform::makeFullPathName(originalConstructorPath.c_str(), qualifiedFromCSFile, sizeof(qualifiedFromCSFile));
  2588. Platform::makeFullPathName(constructorPath.c_str(), qualifiedToCSFile, sizeof(qualifiedToCSFile));
  2589. newAsset->setAssetName(assetName);
  2590. newAsset->setShapeFile(shapeFileName.c_str());
  2591. newAsset->setShapeConstructorFile(constructorFileName.c_str());
  2592. AssetImportConfig* cachedConfig = new AssetImportConfig();
  2593. cachedConfig->registerObject();
  2594. activeImportConfig->CopyTo(cachedConfig);
  2595. if (!activeImportConfig->UseManualShapeConfigRules)
  2596. {
  2597. //Try and load a sis file if it exists for this format
  2598. activeImportConfig->loadSISFile(assetItem->filePath);
  2599. }
  2600. //If it's not a re-import, check that the file isn't being in-place imported. If it isn't, store off the original
  2601. //file path for reimporting support later
  2602. if (!isReimport && String::compare(qualifiedFromFile, qualifiedToFile))
  2603. {
  2604. newAsset->setDataField(StringTable->insert("originalFilePath"), nullptr, qualifiedFromFile);
  2605. }
  2606. //iterate through and write out the material maps dependencies
  2607. S32 dependencySlotId = 0;
  2608. for (U32 i = 0; i < assetItem->childAssetItems.size(); i++)
  2609. {
  2610. AssetImportObject* childItem = assetItem->childAssetItems[i];
  2611. if (childItem->skip || !childItem->processed)
  2612. continue;
  2613. if (childItem->assetType.compare("MaterialAsset") == 0)
  2614. {
  2615. char dependencyFieldName[64];
  2616. dSprintf(dependencyFieldName, 64, "materialSlot%i", dependencySlotId);
  2617. char dependencyFieldDef[512];
  2618. dSprintf(dependencyFieldDef, 512, "%s=%s:%s", ASSET_ID_SIGNATURE, targetModuleId.c_str(), childItem->assetName.c_str());
  2619. newAsset->setDataField(StringTable->insert(dependencyFieldName), nullptr, dependencyFieldDef);
  2620. dependencySlotId++;
  2621. }
  2622. else if (childItem->assetType.compare("ShapeAnimationAsset") == 0)
  2623. {
  2624. char dependencyFieldName[64];
  2625. dSprintf(dependencyFieldName, 64, "animationSequence%i", dependencySlotId);
  2626. char dependencyFieldDef[512];
  2627. dSprintf(dependencyFieldDef, 512, "%s=%s:%s", ASSET_ID_SIGNATURE, targetModuleId.c_str(), childItem->assetName.c_str());
  2628. newAsset->setDataField(StringTable->insert(dependencyFieldName), nullptr, dependencyFieldDef);
  2629. dependencySlotId++;
  2630. }
  2631. }
  2632. Taml tamlWriter;
  2633. bool importSuccessful = tamlWriter.write(newAsset, tamlPath.c_str());
  2634. if (!importSuccessful)
  2635. {
  2636. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Unable to write asset taml file %s", tamlPath.c_str());
  2637. activityLog.push_back(importLogBuffer);
  2638. return "";
  2639. }
  2640. bool makeNewConstructor = true;
  2641. if (!isReimport)
  2642. {
  2643. bool isInPlace = !String::compare(qualifiedFromFile, qualifiedToFile);
  2644. if (!isInPlace && !dPathCopy(qualifiedFromFile, qualifiedToFile, !isReimport))
  2645. {
  2646. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Unable to copy file %s", qualifiedFromFile);
  2647. activityLog.push_back(importLogBuffer);
  2648. return "";
  2649. }
  2650. if (!isInPlace)
  2651. {
  2652. if (Platform::isFile(qualifiedFromCSFile))
  2653. {
  2654. if (!dPathCopy(qualifiedFromCSFile, qualifiedToCSFile, !isReimport))
  2655. {
  2656. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Unable to copy file %s", qualifiedFromCSFile);
  2657. activityLog.push_back(importLogBuffer);
  2658. }
  2659. else
  2660. {
  2661. //We successfully copied the original constructor file, so no extra work required
  2662. makeNewConstructor = false;
  2663. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Successfully copied original TSShape Constructor file %s", qualifiedFromCSFile);
  2664. activityLog.push_back(importLogBuffer);
  2665. }
  2666. }
  2667. }
  2668. else
  2669. {
  2670. //We're doing an in-place import, so double check we've already got a constructor file in the expected spot
  2671. if (Platform::isFile(qualifiedFromCSFile))
  2672. {
  2673. //Yup, found it, we're good to go
  2674. makeNewConstructor = false;
  2675. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Existing TSShape Constructor file %s found", qualifiedFromCSFile);
  2676. activityLog.push_back(importLogBuffer);
  2677. }
  2678. else
  2679. {
  2680. //Didn't work, but it's possible it's using the old .cs extension when our extension variable is set to something else, so check that one as well just to be sure
  2681. Torque::Path constrFilePath = qualifiedFromCSFile;
  2682. constrFilePath.setExtension("cs");
  2683. if (Platform::isFile(constrFilePath.getFullPath().c_str()))
  2684. {
  2685. //Yup, found it, we're good to go
  2686. makeNewConstructor = false;
  2687. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Existing TSShape Constructor file %s found", constrFilePath.getFullPath().c_str());
  2688. activityLog.push_back(importLogBuffer);
  2689. }
  2690. }
  2691. }
  2692. }
  2693. if (makeNewConstructor)
  2694. {
  2695. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Beginning creation of new TSShapeConstructor file: %s", qualifiedToCSFile);
  2696. activityLog.push_back(importLogBuffer);
  2697. //find/create shape constructor
  2698. TSShapeConstructor* constructor = TSShapeConstructor::findShapeConstructorByFilename(Torque::Path(qualifiedToFile).getFullPath());
  2699. if (constructor == nullptr)
  2700. {
  2701. constructor = new TSShapeConstructor(StringTable->insert(qualifiedToFile));
  2702. String constructorName = assetItem->filePath.getFileName() + assetItem->filePath.getExtension().substr(0, 3);
  2703. constructorName.replace(" ", "_");
  2704. constructorName.replace("-", "_");
  2705. constructorName.replace(".", "_");
  2706. constructorName = Sim::getUniqueName(constructorName.c_str());
  2707. constructor->registerObject(constructorName.c_str());
  2708. }
  2709. //now we write the import config logic into the constructor itself to ensure we load like we wanted it to
  2710. String neverImportMats;
  2711. if (activeImportConfig->IgnoreMaterials.isNotEmpty())
  2712. {
  2713. U32 ignoredMatNamesCount = StringUnit::getUnitCount(activeImportConfig->IgnoreMaterials, ",;\t");
  2714. for (U32 i = 0; i < ignoredMatNamesCount; i++)
  2715. {
  2716. if (i == 0)
  2717. neverImportMats = StringUnit::getUnit(activeImportConfig->IgnoreMaterials, i, ",;\t");
  2718. else
  2719. neverImportMats += String("\t") + StringUnit::getUnit(activeImportConfig->IgnoreMaterials, i, ",;\t");
  2720. }
  2721. }
  2722. if (activeImportConfig->DoUpAxisOverride)
  2723. {
  2724. S32 upAxis = domUpAxisType::UPAXISTYPE_Z_UP;
  2725. if (activeImportConfig->UpAxisOverride.compare("X_AXIS") == 0)
  2726. {
  2727. upAxis = domUpAxisType::UPAXISTYPE_X_UP;
  2728. }
  2729. else if (activeImportConfig->UpAxisOverride.compare("Y_AXIS") == 0)
  2730. {
  2731. upAxis = domUpAxisType::UPAXISTYPE_Y_UP;
  2732. }
  2733. else if (activeImportConfig->UpAxisOverride.compare("Z_AXIS") == 0)
  2734. {
  2735. upAxis = domUpAxisType::UPAXISTYPE_Z_UP;
  2736. }
  2737. constructor->mOptions.upAxis = (domUpAxisType)upAxis;
  2738. }
  2739. if (activeImportConfig->DoScaleOverride)
  2740. constructor->mOptions.unit = activeImportConfig->ScaleOverride;
  2741. else
  2742. constructor->mOptions.unit = -1;
  2743. enum eAnimTimingType
  2744. {
  2745. FrameCount = 0,
  2746. Seconds = 1,
  2747. Milliseconds = 1000
  2748. };
  2749. S32 lodType = ColladaUtils::ImportOptions::eLodType::TrailingNumber;
  2750. if (activeImportConfig->LODType.compare("TrailingNumber") == 0)
  2751. lodType = ColladaUtils::ImportOptions::eLodType::TrailingNumber;
  2752. else if (activeImportConfig->LODType.compare("SingleSize") == 0)
  2753. lodType = ColladaUtils::ImportOptions::eLodType::SingleSize;
  2754. else if (activeImportConfig->LODType.compare("DetectDTS") == 0)
  2755. lodType = ColladaUtils::ImportOptions::eLodType::DetectDTS;
  2756. constructor->mOptions.lodType = (ColladaUtils::ImportOptions::eLodType)lodType;
  2757. constructor->mOptions.singleDetailSize = activeImportConfig->convertLeftHanded;
  2758. constructor->mOptions.alwaysImport = activeImportConfig->AlwaysImportedNodes;
  2759. constructor->mOptions.neverImport = activeImportConfig->AlwaysIgnoreNodes;
  2760. constructor->mOptions.alwaysImportMesh = activeImportConfig->AlwaysImportMeshes;
  2761. constructor->mOptions.neverImportMesh = activeImportConfig->AlwaysIgnoreMeshes;
  2762. constructor->mOptions.ignoreNodeScale = activeImportConfig->IgnoreNodeScale;
  2763. constructor->mOptions.adjustCenter = activeImportConfig->AdjustCenter;
  2764. constructor->mOptions.adjustFloor = activeImportConfig->AdjustFloor;
  2765. constructor->mOptions.convertLeftHanded = activeImportConfig->convertLeftHanded;
  2766. constructor->mOptions.calcTangentSpace = activeImportConfig->calcTangentSpace;
  2767. constructor->mOptions.genUVCoords = activeImportConfig->genUVCoords;
  2768. constructor->mOptions.flipUVCoords = activeImportConfig->flipUVCoords;
  2769. constructor->mOptions.findInstances = activeImportConfig->findInstances;
  2770. constructor->mOptions.limitBoneWeights = activeImportConfig->limitBoneWeights;
  2771. constructor->mOptions.joinIdenticalVerts = activeImportConfig->JoinIdenticalVerts;
  2772. constructor->mOptions.reverseWindingOrder = activeImportConfig->reverseWindingOrder;
  2773. constructor->mOptions.invertNormals = activeImportConfig->invertNormals;
  2774. constructor->mOptions.removeRedundantMats = activeImportConfig->removeRedundantMats;
  2775. S32 animTimingType;
  2776. if (activeImportConfig->animTiming.compare("FrameCount") == 0)
  2777. animTimingType = ColladaUtils::ImportOptions::eAnimTimingType::FrameCount;
  2778. else if (activeImportConfig->animTiming.compare("Seconds") == 0)
  2779. animTimingType = ColladaUtils::ImportOptions::eAnimTimingType::Seconds;
  2780. else// (activeImportConfig->animTiming.compare("Milliseconds") == 0)
  2781. animTimingType = ColladaUtils::ImportOptions::eAnimTimingType::Milliseconds;
  2782. constructor->mOptions.animTiming = (ColladaUtils::ImportOptions::eAnimTimingType)animTimingType;
  2783. constructor->mOptions.animFPS = activeImportConfig->animFPS;
  2784. constructor->mOptions.neverImportMat = neverImportMats;
  2785. PersistenceManager* constructorPersist = new PersistenceManager();
  2786. constructorPersist->registerObject();
  2787. constructorPersist->setDirty(constructor, qualifiedToCSFile);
  2788. if (!constructorPersist->saveDirtyObject(constructor))
  2789. {
  2790. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Failed to save shape constructor file to %s", constructorPath.c_str());
  2791. activityLog.push_back(importLogBuffer);
  2792. }
  2793. else
  2794. {
  2795. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Finished creating shape constructor file to %s", constructorPath.c_str());
  2796. activityLog.push_back(importLogBuffer);
  2797. }
  2798. constructorPersist->destroySelf();
  2799. }
  2800. //restore the cached version just in case we loaded a sis file
  2801. cachedConfig->CopyTo(activeImportConfig);
  2802. cachedConfig->deleteObject();
  2803. return tamlPath;
  2804. }
  2805. Torque::Path AssetImporter::importSoundAsset(AssetImportObject* assetItem)
  2806. {
  2807. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Beginning importing of Sound Asset: %s", assetItem->assetName.c_str());
  2808. activityLog.push_back(importLogBuffer);
  2809. SoundAsset* newAsset = new SoundAsset();
  2810. newAsset->registerObject();
  2811. StringTableEntry assetName = StringTable->insert(assetItem->assetName.c_str());
  2812. String imageFileName = assetItem->filePath.getFileName() + "." + assetItem->filePath.getExtension();
  2813. String assetPath = targetPath + "/" + imageFileName;
  2814. String tamlPath = targetPath + "/" + assetName + ".asset.taml";
  2815. String originalPath = assetItem->filePath.getFullPath().c_str();
  2816. char qualifiedFromFile[2048];
  2817. char qualifiedToFile[2048];
  2818. Platform::makeFullPathName(originalPath.c_str(), qualifiedFromFile, sizeof(qualifiedFromFile));
  2819. Platform::makeFullPathName(assetPath.c_str(), qualifiedToFile, sizeof(qualifiedToFile));
  2820. newAsset->setAssetName(assetName);
  2821. newAsset->setSoundFile(imageFileName.c_str());
  2822. //If it's not a re-import, check that the file isn't being in-place imported. If it isn't, store off the original
  2823. //file path for reimporting support later
  2824. if (!isReimport && String::compare(qualifiedFromFile, qualifiedToFile))
  2825. {
  2826. newAsset->setDataField(StringTable->insert("originalFilePath"), nullptr, qualifiedFromFile);
  2827. }
  2828. Taml tamlWriter;
  2829. bool importSuccessful = tamlWriter.write(newAsset, tamlPath.c_str());
  2830. if (!importSuccessful)
  2831. {
  2832. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Unable to write asset taml file %s", tamlPath.c_str());
  2833. activityLog.push_back(importLogBuffer);
  2834. return "";
  2835. }
  2836. if (!isReimport)
  2837. {
  2838. bool isInPlace = !String::compare(qualifiedFromFile, qualifiedToFile);
  2839. if (!isInPlace && !dPathCopy(qualifiedFromFile, qualifiedToFile, !isReimport))
  2840. {
  2841. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Unable to copy file %s", assetItem->filePath.getFullPath().c_str());
  2842. activityLog.push_back(importLogBuffer);
  2843. return "";
  2844. }
  2845. }
  2846. return tamlPath;
  2847. }
  2848. Torque::Path AssetImporter::importShapeAnimationAsset(AssetImportObject* assetItem)
  2849. {
  2850. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Beginning importing of Shape Animation Asset: %s", assetItem->assetName.c_str());
  2851. activityLog.push_back(importLogBuffer);
  2852. ShapeAnimationAsset* newAsset = new ShapeAnimationAsset();
  2853. newAsset->registerObject();
  2854. StringTableEntry assetName = StringTable->insert(assetItem->assetName.c_str());
  2855. String imageFileName = assetItem->filePath.getFileName() + "." + assetItem->filePath.getExtension();
  2856. String assetPath = targetPath + "/" + imageFileName;
  2857. String tamlPath = targetPath + "/" + assetName + ".asset.taml";
  2858. String originalPath = assetItem->filePath.getFullPath().c_str();
  2859. char qualifiedFromFile[2048];
  2860. char qualifiedToFile[2048];
  2861. Platform::makeFullPathName(originalPath.c_str(), qualifiedFromFile, sizeof(qualifiedFromFile));
  2862. Platform::makeFullPathName(assetPath.c_str(), qualifiedToFile, sizeof(qualifiedToFile));
  2863. newAsset->setAssetName(assetName);
  2864. newAsset->setAnimationFile(imageFileName.c_str());
  2865. //If it's not a re-import, check that the file isn't being in-place imported. If it isn't, store off the original
  2866. //file path for reimporting support later
  2867. if (!isReimport && String::compare(qualifiedFromFile, qualifiedToFile))
  2868. {
  2869. newAsset->setDataField(StringTable->insert("originalFilePath"), nullptr, qualifiedFromFile);
  2870. }
  2871. Taml tamlWriter;
  2872. bool importSuccessful = tamlWriter.write(newAsset, tamlPath.c_str());
  2873. if (!importSuccessful)
  2874. {
  2875. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Unable to write asset taml file %s", tamlPath.c_str());
  2876. activityLog.push_back(importLogBuffer);
  2877. return "";
  2878. }
  2879. if (!isReimport)
  2880. {
  2881. bool isInPlace = !String::compare(qualifiedFromFile, qualifiedToFile);
  2882. if (!isInPlace && !dPathCopy(qualifiedFromFile, qualifiedToFile, !isReimport))
  2883. {
  2884. dSprintf(importLogBuffer, sizeof(importLogBuffer), "Error! Unable to copy file %s", assetItem->filePath.getFullPath().c_str());
  2885. activityLog.push_back(importLogBuffer);
  2886. return "";
  2887. }
  2888. }
  2889. return tamlPath;
  2890. }