From 813762c722d134831f1439c64c4933aaf55f7e9b Mon Sep 17 00:00:00 2001 From: Areloch Date: Fri, 7 Aug 2020 00:24:26 -0500 Subject: [PATCH] Separated ShapeAsset's fileName for the loose file name and the fully processed file path to avoid potential save-out problems Fixed autoAssetImport so it properly cleared any prior import session objects Added beginning and ending comment line signfiers to make import logging easier to spot in console Fixed variable used when doing the actual import on assets where it would use the top-level asset import objects and not the children array, causing a crash Fixed the Make Selected A Mesh logic to work with the creation of a new shapeAsset Added secondary handling to generate a prefab of the original selection for preservation purposes Added optional input for makeSelectedPrefab to not delete the original selection(useful for the preservational prefab mentioned above) Adjusted font color for NA text edit fields to make it more legible Changed the non-working reloadDatabase button in assetBrowser to instead open the Asset Editing editor settings page. --- Engine/source/T3D/assets/ShapeAsset.cpp | 12 ++-- Engine/source/T3D/assets/ShapeAsset.h | 9 ++- Engine/source/T3D/assets/assetImporter.cpp | 7 +- Engine/source/gui/worldEditor/worldEditor.cpp | 60 ++++++++++-------- Engine/source/gui/worldEditor/worldEditor.h | 4 +- .../tools/assetBrowser/guis/assetBrowser.gui | 8 +-- .../assetBrowser/scripts/assetBrowser.cs | 8 +-- .../tools/gui/images/stencilIcons/gear.png | Bin 0 -> 7111 bytes Templates/BaseGame/game/tools/settings.xml | 2 +- .../worldEditor/scripts/menuHandlers.ed.cs | 46 ++++++++++++-- 10 files changed, 106 insertions(+), 50 deletions(-) create mode 100644 Templates/BaseGame/game/tools/gui/images/stencilIcons/gear.png diff --git a/Engine/source/T3D/assets/ShapeAsset.cpp b/Engine/source/T3D/assets/ShapeAsset.cpp index f20239070..906a516a4 100644 --- a/Engine/source/T3D/assets/ShapeAsset.cpp +++ b/Engine/source/T3D/assets/ShapeAsset.cpp @@ -117,6 +117,8 @@ ShapeAsset::ShapeAsset() { mFileName = StringTable->EmptyString(); mConstructorFileName = StringTable->EmptyString(); + mFilePath = StringTable->EmptyString(); + mConstructorFilePath = StringTable->EmptyString(); } //----------------------------------------------------------------------------- @@ -163,10 +165,10 @@ void ShapeAsset::initializeAsset() ResourceManager::get().getChangedSignal().notify(this, &ShapeAsset::_onResourceChanged); //Ensure our path is expando'd if it isn't already - if (!Platform::isFullPath(mFileName)) - mFileName = getOwned() ? expandAssetFilePath(mFileName) : mFileName; + if (!Platform::isFullPath(mFilePath)) + mFilePath = getOwned() ? expandAssetFilePath(mFileName) : mFilePath; - mConstructorFileName = expandAssetFilePath(mConstructorFileName); + mConstructorFilePath = expandAssetFilePath(mConstructorFilePath); loadShape(); } @@ -258,7 +260,7 @@ bool ShapeAsset::loadShape() } } - mShape = ResourceManager::get().load(mFileName); + mShape = ResourceManager::get().load(mFilePath); if (!mShape) { @@ -439,7 +441,7 @@ void ShapeAsset::onAssetRefresh(void) // Update. if(!Platform::isFullPath(mFileName)) - mFileName = getOwned() ? expandAssetFilePath(mFileName) : mFileName; + mFilePath = getOwned() ? expandAssetFilePath(mFileName) : mFilePath; loadShape(); } diff --git a/Engine/source/T3D/assets/ShapeAsset.h b/Engine/source/T3D/assets/ShapeAsset.h index df2938105..a78dcddbb 100644 --- a/Engine/source/T3D/assets/ShapeAsset.h +++ b/Engine/source/T3D/assets/ShapeAsset.h @@ -64,6 +64,8 @@ class ShapeAsset : public AssetBase protected: StringTableEntry mFileName; StringTableEntry mConstructorFileName; + StringTableEntry mFilePath; + StringTableEntry mConstructorFilePath; Resource mShape; //Material assets we're dependent on and use @@ -96,9 +98,9 @@ public: Resource getShapeResource() { return mShape; } void SplitSequencePathAndName(String& srcPath, String& srcName); - StringTableEntry getShapeFilename() { return mFileName; } + StringTableEntry getShapeFilename() { return mFilePath; } - U32 getShapeFilenameHash() { return _StringTable::hashString(mFileName); } + U32 getShapeFilenameHash() { return _StringTable::hashString(mFilePath); } Vector> getMaterialAssets() { return mMaterialAssets; } @@ -128,6 +130,9 @@ public: void setShapeConstructorFile(const char* pScriptFile); inline StringTableEntry getShapeConstructorFile(void) const { return mConstructorFileName; }; + inline StringTableEntry getShapeFilePath(void) const { return mFilePath; }; + inline StringTableEntry getShapeConstructorFilePath(void) const { return mConstructorFilePath; }; + static bool getAssetByFilename(StringTableEntry fileName, AssetPtr* shapeAsset); static StringTableEntry getAssetIdByFilename(StringTableEntry fileName); static bool getAssetById(StringTableEntry assetId, AssetPtr* shapeAsset); diff --git a/Engine/source/T3D/assets/assetImporter.cpp b/Engine/source/T3D/assets/assetImporter.cpp index afc00ac8a..1b1f8c2b1 100644 --- a/Engine/source/T3D/assets/assetImporter.cpp +++ b/Engine/source/T3D/assets/assetImporter.cpp @@ -1833,6 +1833,9 @@ void AssetImporter::resolveAssetItemIssues(AssetImportObject* assetItem) // StringTableEntry AssetImporter::autoImportFile(Torque::Path filePath) { + //Just in case we're reusing the same importer object from another import session, nuke any existing files + resetImportSession(true); + String assetType = getAssetTypeByFile(filePath); if (assetType == String("Folder") || assetType == String("Zip")) @@ -1902,10 +1905,12 @@ StringTableEntry AssetImporter::autoImportFile(Torque::Path filePath) } #if TORQUE_DEBUG + Con::printf("/***************/"); for (U32 i = 0; i < activityLog.size(); i++) { Con::printf(activityLog[i].c_str()); } + Con::printf("/***************/"); #endif if (hasIssues) @@ -2045,7 +2050,7 @@ void AssetImporter::importAssets(AssetImportObject* assetItem) } } - if (assetPath.isEmpty() && importingAssets[i]->assetType != String("MaterialAsset")) + if (assetPath.isEmpty() && childItem->assetType != String("MaterialAsset")) { dSprintf(importLogBuffer, sizeof(importLogBuffer), "AssetImporter::importAssets - Import attempt of %s failed, so skipping asset.", childItem->assetName.c_str()); activityLog.push_back(importLogBuffer); diff --git a/Engine/source/gui/worldEditor/worldEditor.cpp b/Engine/source/gui/worldEditor/worldEditor.cpp index 84e4e309f..64b1512b4 100644 --- a/Engine/source/gui/worldEditor/worldEditor.cpp +++ b/Engine/source/gui/worldEditor/worldEditor.cpp @@ -3668,7 +3668,7 @@ DefineEngineMethod( WorldEditor, colladaExportSelection, void, ( const char* pat object->colladaExportSelection( path ); } -void WorldEditor::makeSelectionPrefab( const char *filename ) +void WorldEditor::makeSelectionPrefab( const char *filename, bool dontReplaceOriginals ) { if ( mSelected->size() == 0 ) { @@ -3761,25 +3761,28 @@ void WorldEditor::makeSelectionPrefab( const char *filename ) } // Save out .prefab file. - group->save( filename, false, "$ThisPrefab = " ); + group->save( filename, false, "$ThisPrefab = " ); - // Allocate Prefab object and add to level. - Prefab *fab = new Prefab(); - fab->setFile( filename ); - fabMat.inverse(); - fab->setTransform( fabMat ); - fab->registerObject(); - scene->addObject( fab ); + if (!dontReplaceOriginals) + { + // Allocate Prefab object and add to level. + Prefab* fab = new Prefab(); + fab->setFile(filename); + fabMat.inverse(); + fab->setTransform(fabMat); + fab->registerObject(); + scene->addObject(fab); - // Select it, mark level as dirty. - clearSelection(); - selectObject( fab ); - setDirty(); + // Select it, mark level as dirty. + clearSelection(); + selectObject(fab); + setDirty(); - // Delete original objects and temporary SimGroup. - group->deleteObject(); - for ( S32 i = 0; i < cleanup.size(); i++ ) - cleanup[i]->deleteObject(); + // Delete original objects and temporary SimGroup. + group->deleteObject(); + for (S32 i = 0; i < cleanup.size(); i++) + cleanup[i]->deleteObject(); + } } void WorldEditor::explodeSelectedPrefab() @@ -3827,19 +3830,19 @@ void WorldEditor::explodeSelectedPrefab() setDirty(); } -void WorldEditor::makeSelectionAMesh(const char *filename) +bool WorldEditor::makeSelectionAMesh(const char *filename) { if (mSelected->size() == 0) { Con::errorf("WorldEditor::makeSelectionAMesh - Nothing selected."); - return; + return false; } Scene* scene = Scene::getRootScene(); if (!scene) { Con::errorf("WorldEditor::makeSelectionAMesh - Could not find root Scene."); - return; + return false; } Vector< SimObject* > stack; @@ -3887,7 +3890,7 @@ void WorldEditor::makeSelectionAMesh(const char *filename) if (found.empty()) { Con::warnf("WorldEditor::makeSelectionPrefab - No valid objects selected."); - return; + return false; } // SimGroup we collect prefab objects into. @@ -3911,7 +3914,7 @@ void WorldEditor::makeSelectionAMesh(const char *filename) } if ( objectList.empty() ) - return; + return false; // Point3F centroid; @@ -3982,6 +3985,11 @@ void WorldEditor::makeSelectionAMesh(const char *filename) ColladaUtils::exportToCollada(filename, exportData); // + if (Platform::isFile(filename)) + return true; + else + return false; + // Allocate TSStatic object and add to level. TSStatic *ts = new TSStatic(); ts->setShapeFileName(StringTable->insert(filename)); @@ -4000,11 +4008,11 @@ void WorldEditor::makeSelectionAMesh(const char *filename) objectList[i]->deleteObject(); } -DefineEngineMethod( WorldEditor, makeSelectionPrefab, void, ( const char* filename ),, +DefineEngineMethod( WorldEditor, makeSelectionPrefab, void, ( const char* filename, bool dontDeleteOriginals ), (false), "Save selected objects to a .prefab file and replace them in the level with a Prefab object." "@param filename Prefab file to save the selected objects to.") { - object->makeSelectionPrefab( filename ); + object->makeSelectionPrefab( filename, dontDeleteOriginals); } DefineEngineMethod( WorldEditor, explodeSelectedPrefab, void, (),, @@ -4013,11 +4021,11 @@ DefineEngineMethod( WorldEditor, explodeSelectedPrefab, void, (),, object->explodeSelectedPrefab(); } -DefineEngineMethod(WorldEditor, makeSelectionAMesh, void, (const char* filename), , +DefineEngineMethod(WorldEditor, makeSelectionAMesh, bool, (const char* filename), , "Save selected objects to a .dae collada file and replace them in the level with a TSStatic object." "@param filename collada file to save the selected objects to.") { - object->makeSelectionAMesh(filename); + return object->makeSelectionAMesh(filename); } DefineEngineMethod( WorldEditor, mountRelative, void, ( SceneObject *objA, SceneObject *objB ),, diff --git a/Engine/source/gui/worldEditor/worldEditor.h b/Engine/source/gui/worldEditor/worldEditor.h index e903e024b..01c7d396c 100644 --- a/Engine/source/gui/worldEditor/worldEditor.h +++ b/Engine/source/gui/worldEditor/worldEditor.h @@ -114,10 +114,10 @@ class WorldEditor : public EditTSCtrl void colladaExportSelection( const String &path ); - void makeSelectionPrefab( const char *filename ); + void makeSelectionPrefab( const char *filename, bool dontReplaceOriginals = false); void explodeSelectedPrefab(); - void makeSelectionAMesh(const char *filename); + bool makeSelectionAMesh(const char *filename); // static SceneObject* getClientObj(SceneObject *); diff --git a/Templates/BaseGame/game/tools/assetBrowser/guis/assetBrowser.gui b/Templates/BaseGame/game/tools/assetBrowser/guis/assetBrowser.gui index 6b2c57a8e..40d772206 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/guis/assetBrowser.gui +++ b/Templates/BaseGame/game/tools/assetBrowser/guis/assetBrowser.gui @@ -310,7 +310,7 @@ }; new GuiIconButtonCtrl() { buttonMargin = "4 4"; - iconBitmap = "tools/gui/images/stencilIcons/return.png"; + iconBitmap = "tools/gui/images/stencilIcons/gear.png"; iconLocation = "Left"; sizeIconToButton = "1"; makeIconSquare = "1"; @@ -328,12 +328,12 @@ profile = "ToolsGuiDefaultProfile"; visible = "1"; active = "1"; - command = "AssetBrowser.refreshDatabases();"; + command = "AssetBrowser.openAssetSettings();"; tooltipProfile = "GuiToolTipProfile"; - tooltip = "Refresh Asset and Module databases."; + tooltip = "Edit the editor settings for Assets."; hovertime = "1000"; isContainer = "0"; - internalName = "refreshDatabasesButton"; + internalName = "editAssetSettingsButton"; canSave = "1"; canSaveDynamicFields = "0"; }; diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.cs index d4c30762a..381ccff65 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.cs @@ -1218,11 +1218,11 @@ function AssetBrowserFilterTree::onRightMouseDown(%this, %itemId) // // // -function AssetBrowser::refreshDatabases(%this) +function AssetBrowser::openAssetSettings(%this) { - //ModuleDatabase.scanModules( "data", false ); - //ModuleDatabase.unloadGroup( "Game" ); - //ModuleDatabase.LoadGroup( "Game" ); + ESettingsWindow.toggleEditorSettings(); + %assetEditIndex = ESettingsWindowList.findTextIndex("Asset Editing"); + ESettingsWindowList.setSelectedRow( %assetEditIndex ); } function AssetBrowser::showVisibiltyOptions(%this) diff --git a/Templates/BaseGame/game/tools/gui/images/stencilIcons/gear.png b/Templates/BaseGame/game/tools/gui/images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 15 255 59 58 57 255 50 49 48 255 - 77 77 77 255 + 120 120 120 255 43 43 43 255 72 70 68 255 178 175 172 255 diff --git a/Templates/BaseGame/game/tools/worldEditor/scripts/menuHandlers.ed.cs b/Templates/BaseGame/game/tools/worldEditor/scripts/menuHandlers.ed.cs index 7571a34c0..27e9ce4cb 100644 --- a/Templates/BaseGame/game/tools/worldEditor/scripts/menuHandlers.ed.cs +++ b/Templates/BaseGame/game/tools/worldEditor/scripts/menuHandlers.ed.cs @@ -573,10 +573,10 @@ function EditorExplodePrefab() EditorTree.buildVisibleTree( true ); } -function makeSelectedAMesh() +function makeSelectedAMesh(%assetId) { - - %dlg = new SaveFileDialog() + + /*%dlg = new SaveFileDialog() { Filters = "Collada file (*.dae)|*.dae|"; DefaultPath = $Pref::WorldEditor::LastPath; @@ -598,9 +598,45 @@ function makeSelectedAMesh() %dlg.delete(); if ( !%ret ) - return; + return;*/ + + %assetDef = AssetDatabase.acquireAsset(%assetId); - EWorldEditor.makeSelectionAMesh( %saveFile ); + %assetPath = AssetDatabase.getAssetPath(%assetId); + %filePath = %assetPath @ "/" @ %assetDef.AssetName @ ".dae"; + + %fileName = fileName(%filePath); + + %assetDef.fileName = %fileName; + %assetDef.saveAsset(); + + %success = EWorldEditor.makeSelectionAMesh( %filePath ); + + AssetDatabase.refreshAsset(%assetId); + + if(%success) + { + //ok, cool it worked, so clear out the old + //First, get our center of the currently selected objects + %selectionCenter = EWorldEditor.getSelectionCentroid(); + + //Next, for safety purposes(and convenience!) we'll make them a prefab aping off the filepath/name provided + //TODO: Make this an editor option + %prefabPath = %assetPath @ "/" @ %assetDef.AssetName @ ".prefab"; + EWorldEditor.makeSelectionPrefab(%prefabPath, true); + + //Next, nuke 'em + EditorMenuEditDelete(); + + //now make a new static + %newStatic = new TSStatic() + { + shapeAsset = %assetId; + position = %selectionCenter; + }; + + getRootScene().add(%newStatic); + } EditorTree.buildVisibleTree( true ); }