From 0ffb99e7d471b9910327efa1b5f07bd63a44058b Mon Sep 17 00:00:00 2001 From: Marc Chapman Date: Tue, 12 Feb 2019 03:14:01 +0000 Subject: [PATCH 1/5] Adds the capability to add a small offset to the Z value of items being told to snap to terrain --- Engine/source/gui/worldEditor/worldEditor.cpp | 20 +++++++++++++++++++ Engine/source/gui/worldEditor/worldEditor.h | 2 ++ .../worldEditor/scripts/editorPrefs.ed.cs | 10 ++++++++++ 3 files changed, 32 insertions(+) diff --git a/Engine/source/gui/worldEditor/worldEditor.cpp b/Engine/source/gui/worldEditor/worldEditor.cpp index 27c9dc473e..c0cd7a241d 100644 --- a/Engine/source/gui/worldEditor/worldEditor.cpp +++ b/Engine/source/gui/worldEditor/worldEditor.cpp @@ -816,6 +816,21 @@ void WorldEditor::terrainSnapSelection(Selection* sel, U8 modifier, Point3F gizm { mStuckToGround = true; + const F32 OffsetZValueMin = 0.01f; + + if (mTerrainSnapOffsetZ) + { + if (mOffsetZValue == 0.0f) + { + ri.point.z += OffsetZValueMin; + } + else + { + ri.point.z += mOffsetZValue; + } + + } + sel->offset(ri.point - centroid, (!mUseGroupCenter && mGridSnap) ? mGridPlaneSize : 0.f); if(mTerrainSnapAlignment != AlignNone) @@ -1795,6 +1810,9 @@ WorldEditor::WorldEditor() mStickToGround = false; mStuckToGround = false; mTerrainSnapAlignment = AlignNone; + mTerrainSnapOffsetZ = false; + mOffsetZValue = 0.0f; + mDropAtBounds = false; mDropBelowCameraOffset = 15.0f; mDropAtScreenCenterScalar = 1.0f; @@ -2788,6 +2806,8 @@ void WorldEditor::initPersistFields() addField( "isDirty", TypeBool, Offset(mIsDirty, WorldEditor) ); addField( "stickToGround", TypeBool, Offset(mStickToGround, WorldEditor) ); + addField("TerrainSnapOffsetZ", TypeBool, Offset(mTerrainSnapOffsetZ, WorldEditor)); + addField("OffsetZValue", TypeF32, Offset(mOffsetZValue, WorldEditor)); //addField("sameScaleAllAxis", TypeBool, Offset(mSameScaleAllAxis, WorldEditor)); addField( "toggleIgnoreList", TypeBool, Offset(mToggleIgnoreList, WorldEditor) ); diff --git a/Engine/source/gui/worldEditor/worldEditor.h b/Engine/source/gui/worldEditor/worldEditor.h index 5bdd8f0f29..d52ecd6999 100644 --- a/Engine/source/gui/worldEditor/worldEditor.h +++ b/Engine/source/gui/worldEditor/worldEditor.h @@ -358,6 +358,8 @@ class WorldEditor : public EditTSCtrl bool mStickToGround; bool mStuckToGround; ///< Selection is stuck to the ground AlignmentType mTerrainSnapAlignment; ///< How does the stickied object align to the terrain + bool mTerrainSnapOffsetZ; ///< Allows the use of an offset to avoid z-fighting with flat objects on a flat terrain. + F32 mOffsetZValue; ///< Value of the Z offset (note: this shouldnt be changed once set) bool mSoftSnap; ///< Allow soft snapping all of the time bool mSoftSnapActivated; ///< Soft snap has been activated by the user and allowed by the current rules diff --git a/Templates/Full/game/tools/worldEditor/scripts/editorPrefs.ed.cs b/Templates/Full/game/tools/worldEditor/scripts/editorPrefs.ed.cs index 876ae120a0..7d35628fdf 100644 --- a/Templates/Full/game/tools/worldEditor/scripts/editorPrefs.ed.cs +++ b/Templates/Full/game/tools/worldEditor/scripts/editorPrefs.ed.cs @@ -60,6 +60,9 @@ EditorSettings.beginGroup( "Tools" ); EditorSettings.setDefaultValue( "snapGround", "0" ); +EditorSettings.setDefaultValue( "TerrainSnapOffsetZ", "0" ); +EditorSettings.setDefaultValue( "OffsetZValue", "0.01" ); + EditorSettings.setDefaultValue( "snapSoft", "0" ); EditorSettings.setDefaultValue( "snapSoftSize", "2.0" ); EditorSettings.setDefaultValue( "boundingBoxCollision", "0" ); @@ -215,6 +218,10 @@ function setDefault( %name, %value ) EditorSettings.beginGroup( "Tools" ); EWorldEditor.stickToGround = EditorSettings.value("snapGround"); //$pref::WorldEditor::snapGround; + EWorldEditor.TerrainSnapOffsetZ = EditorSettings.value("TerrainSnapOffsetZ"); //$pref::WorldEditor::TerrainSnapOffsetZ; + EWorldEditor.OffsetZValue = EditorSettings.value("OffsetZValue"); //$pref::WorldEditor::OffsetZValue; + + EWorldEditor.setSoftSnap( EditorSettings.value("snapSoft") ); //$pref::WorldEditor::snapSoft EWorldEditor.setSoftSnapSize( EditorSettings.value("snapSoftSize") ); //$pref::WorldEditor::snapSoftSize EWorldEditor.boundingBoxCollision = EditorSettings.value("boundingBoxCollision"); //$pref::WorldEditor::boundingBoxCollision; @@ -310,6 +317,9 @@ function setDefault( %name, %value ) EditorSettings.beginGroup( "Tools" ); EditorSettings.setValue( "snapGround", EWorldEditor.stickToGround ); //$Pref::WorldEditor::snapGround + EditorSettings.setValue( "TerrainSnapOffsetZ", EWorldEditor.TerrainSnapOffsetZ ); //$pref::WorldEditor::TerrainSnapOffsetZ; + EditorSettings.setValue( "OffsetZValue", EWorldEditor.OffsetZValue ); //$pref::WorldEditor::OffsetZValue; + EditorSettings.setValue( "snapSoft", EWorldEditor.getSoftSnap() ); //$Pref::WorldEditor::snapSoft EditorSettings.setValue( "snapSoftSize", EWorldEditor.getSoftSnapSize() ); //$Pref::WorldEditor::snapSoftSize EditorSettings.setValue( "boundingBoxCollision", EWorldEditor.boundingBoxCollision ); //$Pref::WorldEditor::boundingBoxCollision From 138ab8a8bf2e6addf0a9b95c0614f495cef1b6dc Mon Sep 17 00:00:00 2001 From: Areloch Date: Sat, 23 Feb 2019 18:01:14 -0600 Subject: [PATCH 2/5] Tweaks some handling of guiTreeViewObj so you don't necessarily have to delete an object if you delete the tree item, as well as the ability to look up the object id via tree item. Also removes spam in the event that an item on the tree is more of a data representation rather than literal object. --- .../source/gui/controls/guiTreeViewCtrl.cpp | 32 ++++++++++++++++--- Engine/source/gui/controls/guiTreeViewCtrl.h | 1 + 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Engine/source/gui/controls/guiTreeViewCtrl.cpp b/Engine/source/gui/controls/guiTreeViewCtrl.cpp index 3e815b1a5b..f9ad7e4113 100644 --- a/Engine/source/gui/controls/guiTreeViewCtrl.cpp +++ b/Engine/source/gui/controls/guiTreeViewCtrl.cpp @@ -390,7 +390,6 @@ void GuiTreeViewCtrl::Item::setObject(SimObject *obj) { if(!mState.test(InspectorData)) { - Con::errorf("Tried to set the object for item %d, which is not InspectorData!", mId); return; } @@ -409,7 +408,6 @@ SimObject *GuiTreeViewCtrl::Item::getObject() { if(!mState.test(InspectorData)) { - Con::errorf("Tried to get the object for item %d, which is not InspectorData!", mId); return NULL; } @@ -5101,12 +5099,13 @@ DefineEngineMethod( GuiTreeViewCtrl, editItem, bool, ( S32 itemId, const char* n return(object->editItem(itemId, newText, newValue)); } -DefineEngineMethod( GuiTreeViewCtrl, removeItem, bool, (S32 itemId), , +DefineEngineMethod( GuiTreeViewCtrl, removeItem, bool, (S32 itemId, bool deleteObjects), (0, true), "Remove an item from the tree with the given id.\n\n" "@param itemId TreeItemID of item to remove.\n" + "@param deleteObjects Whether the object on the item is deleted when the item is.\n" "@return True if successful, false if not.") { - return(object->removeItem(itemId)); + return(object->removeItem(itemId, deleteObjects)); } DefineEngineMethod( GuiTreeViewCtrl, removeAllChildren, void, (S32 itemId), , @@ -5335,6 +5334,31 @@ DefineEngineMethod( GuiTreeViewCtrl, findItemByObjectId, S32, (S32 objectId), , return(object->findItemByObjectId(objectId)); } +//------------------------------------------------------------------------------ +S32 GuiTreeViewCtrl::getItemObject(S32 itemId) +{ + GuiTreeViewCtrl::Item* item = getItem(itemId); + if (!item) + { + return 0; + } + + SimObject* pObj = item->getObject(); + if (pObj) + return pObj->getId(); + + return 0; +} + +//------------------------------------------------------------------------------ +DefineEngineMethod(GuiTreeViewCtrl, getItemObject, S32, (S32 itemId), , + "Gets the object for a particular item.\n\n" + "@param itemId Item id you want the object id for." + "@return Object Id for the given tree item ID.") +{ + return(object->getItemObject(itemId)); +} + //------------------------------------------------------------------------------ bool GuiTreeViewCtrl::scrollVisibleByObjectId(S32 objID) { diff --git a/Engine/source/gui/controls/guiTreeViewCtrl.h b/Engine/source/gui/controls/guiTreeViewCtrl.h index 686e3ea615..17b9aed040 100644 --- a/Engine/source/gui/controls/guiTreeViewCtrl.h +++ b/Engine/source/gui/controls/guiTreeViewCtrl.h @@ -554,6 +554,7 @@ class GuiTreeViewCtrl : public GuiArrayCtrl S32 findItemByName(const char *name); S32 findItemByValue(const char *name); S32 findItemByObjectId(S32 iObjId); + S32 getItemObject(S32 itemId); void sortTree( bool caseSensitive, bool traverseHierarchy, bool parentsFirst ); From 0c1288f86cb1572f7d87b5ebc2547a359ab78f0a Mon Sep 17 00:00:00 2001 From: Areloch Date: Sat, 23 Feb 2019 22:04:17 -0600 Subject: [PATCH 3/5] Adds a filter for materials to never import when importing a shape --- Engine/source/ts/collada/colladaUtils.h | 8 +- Engine/source/ts/tsShapeConstruct.cpp | 8 ++ .../game/tools/gui/colladaImport.ed.gui | 81 ++++++++++++++++--- 3 files changed, 81 insertions(+), 16 deletions(-) diff --git a/Engine/source/ts/collada/colladaUtils.h b/Engine/source/ts/collada/colladaUtils.h index 144a62c7b6..c1414a59e8 100644 --- a/Engine/source/ts/collada/colladaUtils.h +++ b/Engine/source/ts/collada/colladaUtils.h @@ -90,6 +90,7 @@ namespace ColladaUtils String neverImport; // List of node names (with wildcards) to ignore on loading String alwaysImportMesh; // List of mesh names (with wildcards) to import, even if in the neverImportMesh list String neverImportMesh; // List of mesh names (with wildcards) to ignore on loading + String neverImportMat; // List of material names (with wildcards) to ignore on loading bool ignoreNodeScale; // Ignore elements in s bool adjustCenter; // Translate model so origin is at the center bool adjustFloor; // Translate model so origin is at the bottom @@ -109,9 +110,10 @@ namespace ColladaUtils singleDetailSize = 2; matNamePrefix = ""; alwaysImport = ""; - neverImport = ""; + neverImport = String(Con::getVariable("$TSShapeConstructor::neverImport")); alwaysImportMesh = ""; - neverImportMesh = ""; + neverImportMesh = String(Con::getVariable("$TSShapeConstructor::neverImportMesh")); + neverImportMat = String(Con::getVariable("$TSShapeConstructor::neverImportMat")); ignoreNodeScale = false; adjustCenter = false; adjustFloor = false; @@ -632,7 +634,7 @@ template class ColladaPrimitive : public BasePrimitive /// Most primitives can use these common implementations const char* getElementName() { return primitive->getElementName(); } - const char* getMaterial() { return primitive->getMaterial(); } + const char* getMaterial() { return (FindMatch::isMatchMultipleExprs(ColladaUtils::getOptions().neverImportMat, primitive->getMaterial(), false)) ? NULL : primitive->getMaterial(); } const domInputLocalOffset_Array& getInputs() { return primitive->getInput_array(); } S32 getStride() const { return stride; } diff --git a/Engine/source/ts/tsShapeConstruct.cpp b/Engine/source/ts/tsShapeConstruct.cpp index c778028959..7a76296a8a 100644 --- a/Engine/source/ts/tsShapeConstruct.cpp +++ b/Engine/source/ts/tsShapeConstruct.cpp @@ -144,6 +144,7 @@ TSShapeConstructor::TSShapeConstructor() mOptions.neverImport = String(Con::getVariable("$TSShapeConstructor::neverImport")); mOptions.alwaysImportMesh = ""; mOptions.neverImportMesh = String(Con::getVariable("$TSShapeConstructor::neverImportMesh")); + mOptions.neverImportMat = String(Con::getVariable("$TSShapeConstructor::neverImportMat")); mOptions.ignoreNodeScale = false; mOptions.adjustCenter = false; mOptions.adjustFloor = false; @@ -266,6 +267,13 @@ void TSShapeConstructor::initPersistFields() "not be imported (unless it matches the alwaysImportMesh list.\n" "@see alwaysImportMesh" ); + addField("neverImportMat", TypeRealString, Offset(mOptions.neverImportMat, TSShapeConstructor), + "TAB separated patterns of materials to ignore on loading. No effect for DTS files.\n" + "Torque allows unwanted materials in COLLADA (.dae) files to to be ignored " + "during import. This field contains a TAB separated list of patterns to " + "match material names. Any material that matches one of the patterns in the list will " + "not be imported"); + addField( "ignoreNodeScale", TypeBool, Offset(mOptions.ignoreNodeScale, TSShapeConstructor), "Ignore elements inside COLLADA s. No effect for DTS files.\n" "This field is a workaround for certain exporters that generate bad node " diff --git a/Templates/BaseGame/game/tools/gui/colladaImport.ed.gui b/Templates/BaseGame/game/tools/gui/colladaImport.ed.gui index 30838c76d5..2acab99765 100644 --- a/Templates/BaseGame/game/tools/gui/colladaImport.ed.gui +++ b/Templates/BaseGame/game/tools/gui/colladaImport.ed.gui @@ -35,7 +35,7 @@ HorizSizing = "center"; VertSizing = "center"; position = "254 136"; - Extent = "516 447"; + Extent = "516 477"; MinExtent = "8 8"; canSave = "1"; Visible = "1"; @@ -51,7 +51,7 @@ HorizSizing = "width"; VertSizing = "height"; position = "8 24"; - Extent = "238 417"; + Extent = "238 437"; MinExtent = "8 2"; canSave = "1"; Visible = "1"; @@ -127,7 +127,7 @@ HorizSizing = "width"; VertSizing = "height"; position = "254 24"; - Extent = "254 417"; + Extent = "254 437"; MinExtent = "8 2"; canSave = "1"; Visible = "1"; @@ -426,7 +426,7 @@ HorizSizing = "right"; VertSizing = "bottom"; position = "0 68"; - Extent = "254 153"; + Extent = "254 173"; MinExtent = "8 8"; canSave = "1"; Visible = "1"; @@ -763,13 +763,63 @@ internalName = "neverImportMesh"; canSaveDynamicFields = "0"; }; + new GuiTextCtrl() { + text = "Ignore Materials"; + maxLength = "1024"; + Margin = "0 0 0 0"; + Padding = "0 0 0 0"; + AnchorTop = "1"; + AnchorBottom = "0"; + AnchorLeft = "1"; + AnchorRight = "0"; + isContainer = "0"; + Profile = "ToolsGuiTextRightProfile"; + HorizSizing = "right"; + VertSizing = "bottom"; + position = "13 150"; + Extent = "72 16"; + MinExtent = "8 2"; + canSave = "1"; + Visible = "1"; + tooltipprofile = "ToolsGuiToolTipProfile"; + hovertime = "1000"; + canSaveDynamicFields = "0"; + }; + new GuiTextEditCtrl() { + historySize = "0"; + password = "0"; + tabComplete = "0"; + sinkAllKeyEvents = "0"; + passwordMask = "*"; + maxLength = "1024"; + Margin = "0 0 0 0"; + Padding = "0 0 0 0"; + AnchorTop = "1"; + AnchorBottom = "0"; + AnchorLeft = "1"; + AnchorRight = "0"; + isContainer = "0"; + Profile = "ToolsGuiTextEditProfile"; + HorizSizing = "right"; + VertSizing = "bottom"; + position = "97 150"; + Extent = "148 18"; + MinExtent = "8 2"; + canSave = "1"; + Visible = "1"; + AltCommand = "ColladaImportTreeView.refresh(\"nodes\");"; + tooltipprofile = "ToolsGuiToolTipProfile"; + hovertime = "1000"; + internalName = "neverImportMat"; + canSaveDynamicFields = "0"; + }; }; new GuiBitmapBorderCtrl() { isContainer = "1"; Profile = "ToolsGuiGroupBorderProfile"; HorizSizing = "right"; VertSizing = "bottom"; - position = "0 226"; + position = "0 246"; Extent = "254 105"; MinExtent = "8 8"; canSave = "1"; @@ -966,7 +1016,7 @@ Profile = "ToolsGuiGroupBorderProfile"; HorizSizing = "right"; VertSizing = "bottom"; - position = "0 338"; + position = "0 358"; Extent = "254 24"; MinExtent = "8 8"; canSave = "1"; @@ -1006,7 +1056,7 @@ Profile = "ToolsGuiButtonProfile"; HorizSizing = "right"; VertSizing = "bottom"; - position = "11 368"; + position = "11 388"; Extent = "86 22"; MinExtent = "8 2"; canSave = "1"; @@ -1025,7 +1075,7 @@ Profile = "ToolsGuiButtonProfile"; HorizSizing = "right"; VertSizing = "bottom"; - position = "11 395"; + position = "11 415"; Extent = "86 22"; MinExtent = "8 2"; canSave = "1"; @@ -1044,7 +1094,7 @@ Profile = "ToolsGuiButtonProfile"; HorizSizing = "right"; VertSizing = "bottom"; - position = "159 368"; + position = "159 388"; Extent = "86 22"; MinExtent = "8 2"; canSave = "1"; @@ -1064,7 +1114,7 @@ Profile = "ToolsGuiButtonProfile"; HorizSizing = "right"; VertSizing = "bottom"; - position = "159 395"; + position = "159 415"; Extent = "86 22"; MinExtent = "8 2"; canSave = "1"; @@ -1276,6 +1326,7 @@ function ColladaImportDlg::showDialog(%this, %shapePath, %cmd) %this-->neverImport.setText(strreplace(%this.constructor.neverImport, "\t", ";")); %this-->alwaysImportMesh.setText(strreplace(%this.constructor.alwaysImportMesh, "\t", ";")); %this-->neverImportMesh.setText(strreplace(%this.constructor.neverImportMesh, "\t", ";")); + %this-->neverImportMat.setText(strreplace(%this.constructor.neverImportMat, "\t", ";")); %this-->ignoreNodeScale.setStateOn(%this.constructor.ignoreNodeScale); %this-->adjustCenter.setStateOn(%this.constructor.adjustCenter); %this-->adjustFloor.setStateOn(%this.constructor.adjustFloor); @@ -1285,13 +1336,14 @@ function ColladaImportDlg::showDialog(%this, %shapePath, %cmd) else { // Default settings - %this-->lodType.setText("DetectDTS"); + %this-->lodType.setText("TrailingNumber"); %this-->singleDetailSize.setText("2"); %this-->materialPrefix.setText(""); %this-->alwaysImport.setText(""); - %this-->neverImport.setText(""); + %this-->neverImport.setText($TSShapeConstructor::neverImport); %this-->alwaysImportMesh.setText(""); - %this-->neverImportMesh.setText(""); + %this-->neverImportMesh.setText($TSShapeConstructor::neverImportMesh); + %this-->neverImportMat.setText($TSShapeConstructor::neverImportMat); %this-->ignoreNodeScale.setStateOn(0); %this-->adjustCenter.setStateOn(0); %this-->adjustFloor.setStateOn(0); @@ -1418,6 +1470,7 @@ function ColladaImportTreeView::refresh(%this, %what) %this._neverImport = strreplace(ColladaImportDlg-->neverImport.getText(), ";", "\t"); %this._alwaysImportMesh = strreplace(ColladaImportDlg-->alwaysImportMesh.getText(), ";", "\t"); %this._neverImportMesh = strreplace(ColladaImportDlg-->neverImportMesh.getText(), ";", "\t"); + %this._neverImportMat = strreplace(ColladaImportDlg-->neverImportMat.getText(), ";", "\t"); %this.refreshNode(%this.getChild(%shapeRoot)); } @@ -1527,6 +1580,7 @@ function ColladaImportDlg::onOK(%this) (%this-->neverImport.getText() !$= "") || (%this-->alwaysImportMesh.getText() !$= "") || (%this-->neverImportMesh.getText() !$= "") || + (%this-->neverImportMat.getText() !$= "") || (%this-->ignoreNodeScale.getValue() != 0) || (%this-->adjustCenter.getValue() != 0) || (%this-->adjustFloor.getValue() != 0) || @@ -1560,6 +1614,7 @@ function ColladaImportDlg::onOK(%this) %this.constructor.neverImport = strreplace(%this-->neverImport.getText(), ";", "\t"); %this.constructor.alwaysImportMesh = strreplace(%this-->alwaysImportMesh.getText(), ";", "\t"); %this.constructor.neverImportMesh = strreplace(%this-->neverImportMesh.getText(), ";", "\t"); + %this.constructor.neverImportMat = strreplace(%this-->neverImportMat.getText(), ";", "\t"); %this.constructor.ignoreNodeScale = %this-->ignoreNodeScale.getValue(); %this.constructor.adjustCenter = %this-->adjustCenter.getValue(); %this.constructor.adjustFloor = %this-->adjustFloor.getValue(); From 442208203560ec5e86f6ab07a71b52de260cbda4 Mon Sep 17 00:00:00 2001 From: Areloch Date: Sat, 4 May 2019 11:49:42 -0500 Subject: [PATCH 4/5] Expands/Cleans up a lot of the asset functionality, including management, file association, and creation/importing --- Engine/source/T3D/assets/ComponentAsset.cpp | 28 +- Engine/source/T3D/assets/ComponentAsset.h | 6 + Engine/source/T3D/assets/CppAsset.cpp | 167 +++ Engine/source/T3D/assets/CppAsset.h | 81 ++ Engine/source/T3D/assets/GUIAsset.cpp | 73 +- Engine/source/T3D/assets/GUIAsset.h | 14 +- Engine/source/T3D/assets/GameObjectAsset.cpp | 175 ++- Engine/source/T3D/assets/GameObjectAsset.h | 22 +- Engine/source/T3D/assets/ImageAsset.cpp | 25 +- Engine/source/T3D/assets/ImageAsset.h | 6 +- Engine/source/T3D/assets/LevelAsset.cpp | 60 +- Engine/source/T3D/assets/LevelAsset.h | 15 +- Engine/source/T3D/assets/MaterialAsset.cpp | 139 +- Engine/source/T3D/assets/MaterialAsset.h | 26 +- Engine/source/T3D/assets/PostEffectAsset.cpp | 33 +- Engine/source/T3D/assets/PostEffectAsset.h | 9 +- Engine/source/T3D/assets/ScriptAsset.cpp | 48 +- Engine/source/T3D/assets/ScriptAsset.h | 14 +- .../source/T3D/assets/ShapeAnimationAsset.cpp | 44 +- .../source/T3D/assets/ShapeAnimationAsset.h | 8 + Engine/source/T3D/assets/ShapeAsset.cpp | 44 +- Engine/source/T3D/assets/ShapeAsset.h | 26 +- Engine/source/T3D/assets/SoundAsset.cpp | 26 +- Engine/source/T3D/assets/SoundAsset.h | 8 +- .../source/T3D/assets/stateMachineAsset.cpp | 27 +- Engine/source/T3D/assets/stateMachineAsset.h | 8 +- Engine/source/T3D/entity.cpp | 6 +- Engine/source/T3D/entity.h | 3 + Engine/source/assets/assetBase.cpp | 4 + .../game/data/ui/scripts/chooseLevelDlg.cs | 2 +- .../game/tools/assetBrowser/art/cppIcon.png | Bin 0 -> 4894 bytes .../tools/assetBrowser/assetImportConfigs.xml | 22 +- .../tools/assetBrowser/guis/assetBrowser.gui | 51 +- .../tools/assetBrowser/guis/assetImport.gui | 32 +- .../tools/assetBrowser/guis/selectModule.gui | 2 +- .../BaseGame/game/tools/assetBrowser/main.cs | 17 + .../assetBrowser/scripts/addModuleWindow.cs | 12 + .../assetBrowser/scripts/assetBrowser.cs | 528 ++++--- .../tools/assetBrowser/scripts/assetImport.cs | 1274 ++++++++++------- .../assetBrowser/scripts/assetImportConfig.cs | 59 +- .../scripts/assetTypes/assetTypeExample.cs | 53 + .../scripts/assetTypes/component.cs | 141 ++ .../assetBrowser/scripts/assetTypes/cpp.cs | 143 ++ .../scripts/assetTypes/gameObject.cs | 242 ++++ .../assetBrowser/scripts/assetTypes/gui.cs | 83 ++ .../assetBrowser/scripts/assetTypes/image.cs | 163 +++ .../assetBrowser/scripts/assetTypes/level.cs | 62 + .../scripts/assetTypes/material.cs | 468 ++++++ .../scripts/assetTypes/particle.cs | 0 .../assetBrowser/scripts/assetTypes/postFX.cs | 51 + .../assetBrowser/scripts/assetTypes/script.cs | 89 ++ .../assetBrowser/scripts/assetTypes/shape.cs | 266 ++++ .../scripts/assetTypes/shapeAnimation.cs | 55 + .../assetBrowser/scripts/assetTypes/sound.cs | 12 + .../scripts/assetTypes/stateMachine.cs | 173 +++ .../tools/assetBrowser/scripts/editAsset.cs | 298 +--- .../assetBrowser/scripts/gameObjectCreator.cs | 5 +- .../tools/assetBrowser/scripts/newAsset.cs | 433 +----- .../tools/assetBrowser/scripts/popupMenus.cs | 129 +- .../assetBrowser/scripts/selectModule.cs | 15 +- .../scripts/templateFiles/CppModuleFile.cpp | 18 + .../templateFiles/CppStaticClassFile.cpp | 15 + .../templateFiles/CppStaticClassFile.h | 17 + .../game/tools/classIcons/ActiveScene.png | Bin 0 -> 805 bytes .../BaseGame/game/tools/classIcons/Scene.png | Bin 0 -> 762 bytes .../BaseGame/game/tools/gui/profiles.ed.cs | 24 + .../scripts/materialEditor.ed.cs | 6 +- .../BaseGame/game/tools/shapeEditor/main.cs | 5 +- .../shapeEditor/scripts/shapeEditor.ed.cs | 2 +- .../scripts/shapeEditorActions.ed.cs | 16 +- .../tools/worldEditor/scripts/EditorGui.ed.cs | 4 +- .../worldEditor/scripts/menuHandlers.ed.cs | 170 +-- .../tools/worldEditor/scripts/menus.ed.cs | 4 +- 73 files changed, 4449 insertions(+), 1857 deletions(-) create mode 100644 Engine/source/T3D/assets/CppAsset.cpp create mode 100644 Engine/source/T3D/assets/CppAsset.h create mode 100644 Templates/BaseGame/game/tools/assetBrowser/art/cppIcon.png create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/assetTypeExample.cs create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/component.cs create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/cpp.cs create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/gameObject.cs create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/gui.cs create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.cs create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/level.cs create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.cs create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/particle.cs create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/postFX.cs create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/script.cs create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.cs create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shapeAnimation.cs create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/sound.cs create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/stateMachine.cs create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/templateFiles/CppModuleFile.cpp create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/templateFiles/CppStaticClassFile.cpp create mode 100644 Templates/BaseGame/game/tools/assetBrowser/scripts/templateFiles/CppStaticClassFile.h create mode 100644 Templates/BaseGame/game/tools/classIcons/ActiveScene.png create mode 100644 Templates/BaseGame/game/tools/classIcons/Scene.png diff --git a/Engine/source/T3D/assets/ComponentAsset.cpp b/Engine/source/T3D/assets/ComponentAsset.cpp index 83045832ee..324ec495fb 100644 --- a/Engine/source/T3D/assets/ComponentAsset.cpp +++ b/Engine/source/T3D/assets/ComponentAsset.cpp @@ -124,7 +124,8 @@ void ComponentAsset::initPersistFields() addField("componentType", TypeString, Offset(mComponentType, ComponentAsset), "The category of the component for organizing in the editor."); addField("description", TypeString, Offset(mDescription, ComponentAsset), "Simple description of the component."); - addField("scriptFile", TypeString, Offset(mScriptFile, ComponentAsset), "A script file with additional scripted functionality for this component."); + addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, ComponentAsset), + &setScriptFile, &getScriptFile, "A script file with additional scripted functionality for this component."); } //------------------------------------------------------------------------------ @@ -137,12 +138,35 @@ void ComponentAsset::copyTo(SimObject* object) void ComponentAsset::initializeAsset() { + mScriptFile = expandAssetFilePath(mScriptFile); + if(Platform::isFile(mScriptFile)) Con::executeFile(mScriptFile, false, false); } void ComponentAsset::onAssetRefresh() { + mScriptFile = expandAssetFilePath(mScriptFile); + if (Platform::isFile(mScriptFile)) Con::executeFile(mScriptFile, false, false); -} \ No newline at end of file +} + +void ComponentAsset::setScriptFile(const char* pScriptFile) +{ + // Sanity! + AssertFatal(pScriptFile != NULL, "Cannot use a NULL script file."); + + // Fetch image file. + pScriptFile = StringTable->insert(pScriptFile); + + // Ignore no change, + if (pScriptFile == mScriptFile) + return; + + // Update. + mScriptFile = getOwned() ? expandAssetFilePath(pScriptFile) : StringTable->insert(pScriptFile); + + // Refresh the asset. + refreshAsset(); +} diff --git a/Engine/source/T3D/assets/ComponentAsset.h b/Engine/source/T3D/assets/ComponentAsset.h index 9d803970bb..ded5e8ce09 100644 --- a/Engine/source/T3D/assets/ComponentAsset.h +++ b/Engine/source/T3D/assets/ComponentAsset.h @@ -77,9 +77,15 @@ class ComponentAsset : public AssetBase AssetDefinition* getAssetDefinition() { return mpAssetDefinition; } + void setScriptFile(const char* pScriptFile); + inline StringTableEntry getScriptFile(void) const { return mScriptFile; }; + protected: virtual void initializeAsset(void); virtual void onAssetRefresh(void); + + static bool setScriptFile(void *obj, const char *index, const char *data) { static_cast(obj)->setScriptFile(data); return false; } + static const char* getScriptFile(void* obj, const char* data) { return static_cast(obj)->getScriptFile(); } }; DefineConsoleType(TypeComponentAssetPtr, ComponentAsset) diff --git a/Engine/source/T3D/assets/CppAsset.cpp b/Engine/source/T3D/assets/CppAsset.cpp new file mode 100644 index 0000000000..91ab0a8aef --- /dev/null +++ b/Engine/source/T3D/assets/CppAsset.cpp @@ -0,0 +1,167 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- +#ifndef CPP_ASSET_H +#include "CppAsset.h" +#endif + +#ifndef _ASSET_MANAGER_H_ +#include "assets/assetManager.h" +#endif + +#ifndef _CONSOLETYPES_H_ +#include "console/consoleTypes.h" +#endif + +#ifndef _TAML_ +#include "persistence/taml/taml.h" +#endif + +#ifndef _ASSET_PTR_H_ +#include "assets/assetPtr.h" +#endif + +// Debug Profiling. +#include "platform/profiler.h" + +//----------------------------------------------------------------------------- + +IMPLEMENT_CONOBJECT(CppAsset); + +ConsoleType(CppAssetPtr, TypeCppAssetPtr, CppAsset, ASSET_ID_FIELD_PREFIX) + +//----------------------------------------------------------------------------- + +ConsoleGetType(TypeCppAssetPtr) +{ + // Fetch asset Id. + return (*((AssetPtr*)dptr)).getAssetId(); +} + +//----------------------------------------------------------------------------- + +ConsoleSetType(TypeCppAssetPtr) +{ + // Was a single argument specified? + if (argc == 1) + { + // Yes, so fetch field value. + const char* pFieldValue = argv[0]; + + // Fetch asset pointer. + AssetPtr* pAssetPtr = dynamic_cast*>((AssetPtrBase*)(dptr)); + + // Is the asset pointer the correct type? + if (pAssetPtr == NULL) + { + // No, so fail. + //Con::warnf("(TypeCppAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); + return; + } + + // Set asset. + pAssetPtr->setAssetId(pFieldValue); + + return; + } + + // Warn. + Con::warnf("(TypeCppAssetPtr) - Cannot set multiple args to a single asset."); +} + +//----------------------------------------------------------------------------- + +CppAsset::CppAsset() : AssetBase() +{ + mCodeFile = StringTable->EmptyString(); + mHeaderFile = StringTable->EmptyString(); +} + +//----------------------------------------------------------------------------- + +CppAsset::~CppAsset() +{ + // If the asset manager does not own the asset then we own the + // asset definition so delete it. + if (!getOwned()) + delete mpAssetDefinition; +} + +//----------------------------------------------------------------------------- + +void CppAsset::initPersistFields() +{ + // Call parent. + Parent::initPersistFields(); + + addProtectedField("codeFile", TypeAssetLooseFilePath, Offset(mCodeFile, CppAsset), + &setCppFile, &getCppFile, "Path to the cpp file."); + + addProtectedField("headerFile", TypeAssetLooseFilePath, Offset(mHeaderFile, CppAsset), + &setHeaderFile, &getHeaderFile, "Path to the h file."); + +} + +//------------------------------------------------------------------------------ + +void CppAsset::copyTo(SimObject* object) +{ + // Call to parent. + Parent::copyTo(object); +} + +void CppAsset::setCppFile(const char* pCppFile) +{ + // Sanity! + AssertFatal(pCppFile != NULL, "Cannot use a NULL code file."); + + // Fetch image file. + pCppFile = StringTable->insert(pCppFile); + + // Ignore no change, + if (pCppFile == mCodeFile) + return; + + // Update. + mCodeFile = getOwned() ? expandAssetFilePath(pCppFile) : StringTable->insert(pCppFile); + + // Refresh the asset. + refreshAsset(); +} + +void CppAsset::setHeaderFile(const char* pHeaderFile) +{ + // Sanity! + AssertFatal(pHeaderFile != NULL, "Cannot use a NULL header file."); + + // Fetch image file. + pHeaderFile = StringTable->insert(pHeaderFile); + + // Ignore no change, + if (pHeaderFile == mHeaderFile) + return; + + // Update. + mHeaderFile = getOwned() ? expandAssetFilePath(pHeaderFile) : StringTable->insert(pHeaderFile); + + // Refresh the asset. + refreshAsset(); +} diff --git a/Engine/source/T3D/assets/CppAsset.h b/Engine/source/T3D/assets/CppAsset.h new file mode 100644 index 0000000000..46afc79589 --- /dev/null +++ b/Engine/source/T3D/assets/CppAsset.h @@ -0,0 +1,81 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2013 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- +#ifndef CPP_ASSET_H +#define CPP_ASSET_H +#pragma once + +#ifndef _ASSET_BASE_H_ +#include "assets/assetBase.h" +#endif + +#ifndef _ASSET_DEFINITION_H_ +#include "assets/assetDefinition.h" +#endif + +#ifndef _STRINGUNIT_H_ +#include "string/stringUnit.h" +#endif + +#ifndef _ASSET_FIELD_TYPES_H_ +#include "assets/assetFieldTypes.h" +#endif + +//----------------------------------------------------------------------------- +class CppAsset : public AssetBase +{ + typedef AssetBase Parent; + + StringTableEntry mCodeFile; + StringTableEntry mHeaderFile; + +public: + CppAsset(); + virtual ~CppAsset(); + + /// Engine. + static void initPersistFields(); + virtual void copyTo(SimObject* object); + + /// Declare Console Object. + DECLARE_CONOBJECT(CppAsset); + + void setCppFile(const char* pCppFile); + inline StringTableEntry getCppFile(void) const { return mCodeFile; }; + + void setHeaderFile(const char* pHeaderFile); + inline StringTableEntry getHeaderFile(void) const { return mHeaderFile; }; + +protected: + virtual void initializeAsset(void) {}; + virtual void onAssetRefresh(void) {}; + + static bool setCppFile(void *obj, const char *index, const char *data) { static_cast(obj)->setCppFile(data); return false; } + static const char* getCppFile(void* obj, const char* data) { return static_cast(obj)->getCppFile(); } + + static bool setHeaderFile(void *obj, const char *index, const char *data) { static_cast(obj)->setHeaderFile(data); return false; } + static const char* getHeaderFile(void* obj, const char* data) { return static_cast(obj)->getHeaderFile(); } +}; + +DefineConsoleType(TypeCppAssetPtr, CppAsset) + +#endif // _ASSET_BASE_H_ + diff --git a/Engine/source/T3D/assets/GUIAsset.cpp b/Engine/source/T3D/assets/GUIAsset.cpp index a011b56e30..ce638f9b81 100644 --- a/Engine/source/T3D/assets/GUIAsset.cpp +++ b/Engine/source/T3D/assets/GUIAsset.cpp @@ -92,8 +92,8 @@ ConsoleSetType(TypeGUIAssetPtr) GUIAsset::GUIAsset() { - mScriptFilePath = StringTable->EmptyString(); - mGUIFilePath = StringTable->EmptyString(); + mScriptFile = StringTable->EmptyString(); + mGUIFile = StringTable->EmptyString(); } //----------------------------------------------------------------------------- @@ -113,8 +113,11 @@ void GUIAsset::initPersistFields() // Call parent. Parent::initPersistFields(); - addField("scriptFilePath", TypeString, Offset(mScriptFilePath, GUIAsset), "Path to the script file for the gui"); - addField("GUIFilePath", TypeString, Offset(mGUIFilePath, GUIAsset), "Path to the gui file"); + addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, GUIAsset), + &setScriptFile, &getScriptFile, "Path to the script file for the gui"); + + addProtectedField("GUIFile", TypeAssetLooseFilePath, Offset(mGUIFile, GUIAsset), + &setScriptFile, &getScriptFile, "Path to the gui file"); } //------------------------------------------------------------------------------ @@ -127,20 +130,66 @@ void GUIAsset::copyTo(SimObject* object) void GUIAsset::initializeAsset() { - if (Platform::isFile(mGUIFilePath)) - Con::executeFile(mGUIFilePath, false, false); + mGUIFile = expandAssetFilePath(mGUIFile); + + if (Platform::isFile(mGUIFile)) + Con::executeFile(mGUIFile, false, false); + + mScriptFile = expandAssetFilePath(mScriptFile); - if (Platform::isFile(mScriptFilePath)) - Con::executeFile(mScriptFilePath, false, false); + if (Platform::isFile(mScriptFile)) + Con::executeFile(mScriptFile, false, false); } void GUIAsset::onAssetRefresh() { - if (Platform::isFile(mGUIFilePath)) - Con::executeFile(mGUIFilePath, false, false); + mGUIFile = expandAssetFilePath(mGUIFile); + + if (Platform::isFile(mGUIFile)) + Con::executeFile(mGUIFile, false, false); + + mScriptFile = expandAssetFilePath(mScriptFile); + + if (Platform::isFile(mScriptFile)) + Con::executeFile(mScriptFile, false, false); +} + +void GUIAsset::setGUIFile(const char* pScriptFile) +{ + // Sanity! + AssertFatal(pScriptFile != NULL, "Cannot use a NULL gui file."); + + // Fetch image file. + pScriptFile = StringTable->insert(pScriptFile); + + // Ignore no change, + if (pScriptFile == mGUIFile) + return; + + // Update. + mGUIFile = getOwned() ? expandAssetFilePath(pScriptFile) : StringTable->insert(pScriptFile); + + // Refresh the asset. + refreshAsset(); +} + +void GUIAsset::setScriptFile(const char* pScriptFile) +{ + // Sanity! + AssertFatal(pScriptFile != NULL, "Cannot use a NULL script file."); + + // Fetch image file. + pScriptFile = StringTable->insert(pScriptFile); + + // Ignore no change, + if (pScriptFile == mScriptFile) + return; + + // Update. + mScriptFile = getOwned() ? expandAssetFilePath(pScriptFile) : StringTable->insert(pScriptFile); - if (Platform::isFile(mScriptFilePath)) - Con::executeFile(mScriptFilePath, false, false); + // Refresh the asset. + refreshAsset(); } //----------------------------------------------------------------------------- diff --git a/Engine/source/T3D/assets/GUIAsset.h b/Engine/source/T3D/assets/GUIAsset.h index 5668f9afd3..7ba4e221c6 100644 --- a/Engine/source/T3D/assets/GUIAsset.h +++ b/Engine/source/T3D/assets/GUIAsset.h @@ -46,8 +46,8 @@ class GUIAsset : public AssetBase { typedef AssetBase Parent; - StringTableEntry mScriptFilePath; - StringTableEntry mGUIFilePath; + StringTableEntry mScriptFile; + StringTableEntry mGUIFile; public: GUIAsset(); @@ -60,9 +60,19 @@ class GUIAsset : public AssetBase /// Declare Console Object. DECLARE_CONOBJECT(GUIAsset); + void setGUIFile(const char* pScriptFile); + inline StringTableEntry getGUIFile(void) const { return mGUIFile; }; + void setScriptFile(const char* pScriptFile); + inline StringTableEntry getScriptFile(void) const { return mScriptFile; }; + protected: virtual void initializeAsset(void); virtual void onAssetRefresh(void); + + static bool setGUIFile(void *obj, const char *index, const char *data) { static_cast(obj)->setGUIFile(data); return false; } + static const char* getGUIFile(void* obj, const char* data) { return static_cast(obj)->getGUIFile(); } + static bool setScriptFile(void *obj, const char *index, const char *data) { static_cast(obj)->setScriptFile(data); return false; } + static const char* getScriptFile(void* obj, const char* data) { return static_cast(obj)->getScriptFile(); } }; DefineConsoleType(TypeGUIAssetPtr, GUIAsset) diff --git a/Engine/source/T3D/assets/GameObjectAsset.cpp b/Engine/source/T3D/assets/GameObjectAsset.cpp index 45b33b086f..c49588b8ec 100644 --- a/Engine/source/T3D/assets/GameObjectAsset.cpp +++ b/Engine/source/T3D/assets/GameObjectAsset.cpp @@ -92,9 +92,9 @@ ConsoleSetType(TypeGameObjectAssetPtr) GameObjectAsset::GameObjectAsset() { - mGameObjectName = StringTable->lookup(""); - mScriptFilePath = StringTable->lookup(""); - mTAMLFilePath = StringTable->lookup(""); + mGameObjectName = StringTable->EmptyString(); + mScriptFile = StringTable->EmptyString(); + mTAMLFile = StringTable->EmptyString(); } //----------------------------------------------------------------------------- @@ -115,8 +115,11 @@ void GameObjectAsset::initPersistFields() Parent::initPersistFields(); addField("gameObjectName", TypeString, Offset(mGameObjectName, GameObjectAsset), "Name of the game object. Defines the created object's class."); - addField("scriptFilePath", TypeString, Offset(mScriptFilePath, GameObjectAsset), "Path to the script file for the GameObject's script code."); - addField("TAMLFilePath", TypeString, Offset(mTAMLFilePath, GameObjectAsset), "Path to the taml file for the GameObject's heirarchy."); + + addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, GameObjectAsset), + &setScriptFile, &getScriptFile, "Path to the script file for the GameObject's script code."); + addProtectedField("TAMLFile", TypeAssetLooseFilePath, Offset(mTAMLFile, GameObjectAsset), + &setTAMLFile, &getTAMLFile, "Path to the taml file for the GameObject's heirarchy."); } //------------------------------------------------------------------------------ @@ -129,14 +132,98 @@ void GameObjectAsset::copyTo(SimObject* object) void GameObjectAsset::initializeAsset() { - if (Platform::isFile(mScriptFilePath)) - Con::executeFile(mScriptFilePath, false, false); + //Ensure we have an expanded filepath + mScriptFile = expandAssetFilePath(mScriptFile); + + if (Platform::isFile(mScriptFile)) + Con::executeFile(mScriptFile, false, false); } void GameObjectAsset::onAssetRefresh() { - if (Platform::isFile(mScriptFilePath)) - Con::executeFile(mScriptFilePath, false, false); + //Ensure we have an expanded filepath + mScriptFile = expandAssetFilePath(mScriptFile); + + if (Platform::isFile(mScriptFile)) + Con::executeFile(mScriptFile, false, false); +} + +void GameObjectAsset::setScriptFile(const char* pScriptFile) +{ + // Sanity! + AssertFatal(pScriptFile != NULL, "Cannot use a NULL script file."); + + // Fetch image file. + pScriptFile = StringTable->insert(pScriptFile); + + // Ignore no change, + if (pScriptFile == mScriptFile) + return; + + // Update. + mScriptFile = getOwned() ? expandAssetFilePath(pScriptFile) : StringTable->insert(pScriptFile); + + // Refresh the asset. + refreshAsset(); +} + + +void GameObjectAsset::setTAMLFile(const char* pTAMLFile) +{ + // Sanity! + AssertFatal(pTAMLFile != NULL, "Cannot use a NULL TAML file."); + + // Fetch image file. + pTAMLFile = StringTable->insert(pTAMLFile); + + // Ignore no change, + if (pTAMLFile == mScriptFile) + return; + + // Update. + mTAMLFile = getOwned() ? expandAssetFilePath(pTAMLFile) : StringTable->insert(pTAMLFile); + + // Refresh the asset. + refreshAsset(); +} + + +const char* GameObjectAsset::create() +{ + if (!Platform::isFile(mTAMLFile)) + return ""; + + // Set the format mode. + Taml taml; + + // Yes, so set it. + taml.setFormatMode(Taml::getFormatModeEnum("xml")); + + // Turn-off auto-formatting. + taml.setAutoFormat(false); + + // Read object. + SimObject* pSimObject = taml.read(mTAMLFile); + + // Did we find the object? + if (pSimObject == NULL) + { + // No, so warn. + Con::warnf("GameObjectAsset::create() - Could not read object from file '%s'.", mTAMLFile); + return ""; + } + + //Flag it so we know where it came from + pSimObject->setDataField("GameObject", nullptr, getAssetId()); + + return pSimObject->getIdString(); +} + +DefineEngineMethod(GameObjectAsset, createObject, const char*, (),, + "Creates an instance of the given GameObject given the asset definition.\n" + "@return The GameObject entity created from the asset.") +{ + return object->create(); } //----------------------------------------------------------------------------- @@ -160,35 +247,50 @@ void GuiInspectorTypeGameObjectAssetPtr::consoleInit() GuiControl* GuiInspectorTypeGameObjectAssetPtr::constructEditControl() { - // Create base filename edit controls - GuiControl *retCtrl = Parent::constructEditControl(); - if (retCtrl == NULL) - return retCtrl; + // Create "Open in ShapeEditor" button + mGameObjectEditButton = new GuiButtonCtrl(); // Change filespec char szBuffer[512]; - dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"GameObjectAsset\", \"AssetBrowser.changeAsset\", %d, %s);", - mInspector->getComponentGroupTargetId(), mCaption); - mBrowseButton->setField("Command", szBuffer); + dSprintf(szBuffer, sizeof(szBuffer), "%d.onClick(%s);", this->getId(), mCaption); + mGameObjectEditButton->setField("Command", szBuffer); - // Create "Open in ShapeEditor" button - mSMEdButton = new GuiBitmapButtonCtrl(); + mGameObjectEditButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile"); + mGameObjectEditButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile"); + mGameObjectEditButton->setDataField(StringTable->insert("hovertime"), NULL, "1000"); - dSprintf(szBuffer, sizeof(szBuffer), "echo(\"Game Object Editor not implemented yet!\");", retCtrl->getId()); - mSMEdButton->setField("Command", szBuffer); + const char* assetId = getData(); - char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor"; - mSMEdButton->setBitmap(bitmapName); + if (assetId == "") + { + mGameObjectEditButton->setText("Create Game Object"); - mSMEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile"); - mSMEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile"); - mSMEdButton->setDataField(StringTable->insert("hovertime"), NULL, "1000"); - mSMEdButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this file in the State Machine Editor"); + mGameObjectEditButton->setDataField(StringTable->insert("tooltip"), NULL, "Convert this object into a reusable Game Object asset."); + } + else + { + GameObjectAsset* goAsset = AssetDatabase.acquireAsset< GameObjectAsset>(assetId); - mSMEdButton->registerObject(); - addObject(mSMEdButton); + if (goAsset) + { + mGameObjectEditButton->setText("Edit Game Object"); + + mGameObjectEditButton->setDataField(StringTable->insert("tooltip"), NULL, "Edit this object instance or Game Object asset."); + } + else + { + mGameObjectEditButton->setText("Create Game Object"); + + mGameObjectEditButton->setDataField(StringTable->insert("tooltip"), NULL, "Convert this object into a reusable Game Object asset."); + } + } - return retCtrl; + //mGameObjectEditButton->registerObject(); + _registerEditControl(mGameObjectEditButton); + + addObject(mGameObjectEditButton); + + return mGameObjectEditButton; } bool GuiInspectorTypeGameObjectAssetPtr::updateRects() @@ -199,20 +301,13 @@ bool GuiInspectorTypeGameObjectAssetPtr::updateRects() Point2I fieldPos = getPosition(); mCaptionRect.set(0, 0, fieldExtent.x - dividerPos - dividerMargin, fieldExtent.y); - mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin - 34, fieldExtent.y); + mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin, fieldExtent.y); bool resized = mEdit->resize(mEditCtrlRect.point, mEditCtrlRect.extent); - if (mBrowseButton != NULL) - { - mBrowseRect.set(fieldExtent.x - 32, 2, 14, fieldExtent.y - 4); - resized |= mBrowseButton->resize(mBrowseRect.point, mBrowseRect.extent); - } - - if (mSMEdButton != NULL) + if (mGameObjectEditButton != NULL) { - RectI shapeEdRect(fieldExtent.x - 16, 2, 14, fieldExtent.y - 4); - resized |= mSMEdButton->resize(shapeEdRect.point, shapeEdRect.extent); + resized |= mGameObjectEditButton->resize(mEditCtrlRect.point, mEditCtrlRect.extent); } return resized; -} \ No newline at end of file +} diff --git a/Engine/source/T3D/assets/GameObjectAsset.h b/Engine/source/T3D/assets/GameObjectAsset.h index 954a113006..90c666ecce 100644 --- a/Engine/source/T3D/assets/GameObjectAsset.h +++ b/Engine/source/T3D/assets/GameObjectAsset.h @@ -48,8 +48,8 @@ class GameObjectAsset : public AssetBase typedef AssetBase Parent; StringTableEntry mGameObjectName; - StringTableEntry mScriptFilePath; - StringTableEntry mTAMLFilePath; + StringTableEntry mScriptFile; + StringTableEntry mTAMLFile; public: GameObjectAsset(); @@ -59,12 +59,24 @@ class GameObjectAsset : public AssetBase static void initPersistFields(); virtual void copyTo(SimObject* object); + const char* create(); + /// Declare Console Object. DECLARE_CONOBJECT(GameObjectAsset); + void setScriptFile(const char* pScriptFile); + inline StringTableEntry getScriptFile(void) const { return mScriptFile; }; + void setTAMLFile(const char* pScriptFile); + inline StringTableEntry getTAMLFile(void) const { return mTAMLFile; }; + protected: virtual void initializeAsset(void); virtual void onAssetRefresh(void); + + static bool setScriptFile(void *obj, const char *index, const char *data) { static_cast(obj)->setScriptFile(data); return false; } + static const char* getScriptFile(void* obj, const char* data) { return static_cast(obj)->getScriptFile(); } + static bool setTAMLFile(void *obj, const char *index, const char *data) { static_cast(obj)->setTAMLFile(data); return false; } + static const char* getTAMLFile(void* obj, const char* data) { return static_cast(obj)->getTAMLFile(); } }; DefineConsoleType(TypeGameObjectAssetPtr, GameObjectAsset) @@ -73,12 +85,12 @@ DefineConsoleType(TypeGameObjectAssetPtr, GameObjectAsset) //----------------------------------------------------------------------------- // TypeAssetId GuiInspectorField Class //----------------------------------------------------------------------------- -class GuiInspectorTypeGameObjectAssetPtr : public GuiInspectorTypeFileName +class GuiInspectorTypeGameObjectAssetPtr : public GuiInspectorField { - typedef GuiInspectorTypeFileName Parent; + typedef GuiInspectorField Parent; public: - GuiBitmapButtonCtrl *mSMEdButton; + GuiButtonCtrl *mGameObjectEditButton; DECLARE_CONOBJECT(GuiInspectorTypeGameObjectAssetPtr); static void consoleInit(); diff --git a/Engine/source/T3D/assets/ImageAsset.cpp b/Engine/source/T3D/assets/ImageAsset.cpp index ff4c3ac702..56530b53b6 100644 --- a/Engine/source/T3D/assets/ImageAsset.cpp +++ b/Engine/source/T3D/assets/ImageAsset.cpp @@ -108,7 +108,9 @@ void ImageAsset::initPersistFields() // Call parent. Parent::initPersistFields(); - addField("imageFile", TypeString, Offset(mImageFileName, ImageAsset), "Path to the image file."); + addProtectedField("imageFile", TypeAssetLooseFilePath, Offset(mImageFileName, ImageAsset), + &setImageFileName, &getImageFileName, "Path to the image file."); + addField("useMips", TypeBool, Offset(mUseMips, ImageAsset), "Should the image use mips? (Currently unused)."); addField("isHDRImage", TypeBool, Offset(mIsHDRImage, ImageAsset), "Is the image in an HDR format? (Currently unused)"); } @@ -153,4 +155,23 @@ void ImageAsset::initializeAsset() void ImageAsset::onAssetRefresh() { loadImage(); -} \ No newline at end of file +} + +void ImageAsset::setImageFileName(const char* pScriptFile) +{ + // Sanity! + AssertFatal(pScriptFile != NULL, "Cannot use a NULL image file."); + + // Fetch image file. + pScriptFile = StringTable->insert(pScriptFile); + + // Ignore no change, + if (pScriptFile == mImageFileName) + return; + + // Update. + mImageFileName = getOwned() ? expandAssetFilePath(pScriptFile) : StringTable->insert(pScriptFile); + + // Refresh the asset. + refreshAsset(); +} diff --git a/Engine/source/T3D/assets/ImageAsset.h b/Engine/source/T3D/assets/ImageAsset.h index f5b52db072..5a3d7f9af1 100644 --- a/Engine/source/T3D/assets/ImageAsset.h +++ b/Engine/source/T3D/assets/ImageAsset.h @@ -66,7 +66,8 @@ class ImageAsset : public AssetBase /// Declare Console Object. DECLARE_CONOBJECT(ImageAsset); - StringTableEntry getImageFileName() { return mImageFileName; } + void setImageFileName(const char* pScriptFile); + inline StringTableEntry getImageFileName(void) const { return mImageFileName; }; bool isValid() { return mIsValidImage; } @@ -76,6 +77,9 @@ class ImageAsset : public AssetBase virtual void initializeAsset(void); virtual void onAssetRefresh(void); + static bool setImageFileName(void *obj, const char *index, const char *data) { static_cast(obj)->setImageFileName(data); return false; } + static const char* getImageFileName(void* obj, const char* data) { return static_cast(obj)->getImageFileName(); } + void loadImage(); }; diff --git a/Engine/source/T3D/assets/LevelAsset.cpp b/Engine/source/T3D/assets/LevelAsset.cpp index 34084924ac..ab0102bee2 100644 --- a/Engine/source/T3D/assets/LevelAsset.cpp +++ b/Engine/source/T3D/assets/LevelAsset.cpp @@ -92,6 +92,7 @@ ConsoleSetType(TypeLevelAssetPtr) LevelAsset::LevelAsset() : AssetBase(), mIsSubLevel(false) { + mLevelName = StringTable->EmptyString(); mLevelFile = StringTable->EmptyString(); mPreviewImage = StringTable->EmptyString(); @@ -115,8 +116,11 @@ void LevelAsset::initPersistFields() // Call parent. Parent::initPersistFields(); - addField("LevelFile", TypeString, Offset(mLevelFile, LevelAsset), "Path to the actual level file."); - addField("PreviewImage", TypeString, Offset(mPreviewImage, LevelAsset), "Path to the image used for selection preview."); + addProtectedField("LevelFile", TypeAssetLooseFilePath, Offset(mLevelFile, LevelAsset), + &setLevelFile, &getLevelFile, "Path to the actual level file."); + addField("LevelName", TypeString, Offset(mLevelName, LevelAsset), "Human-friendly name for the level."); + addProtectedField("PreviewImage", TypeAssetLooseFilePath, Offset(mPreviewImage, LevelAsset), + &setPreviewImageFile, &getPreviewImageFile, "Path to the image used for selection preview."); } //------------------------------------------------------------------------------ @@ -125,4 +129,54 @@ void LevelAsset::copyTo(SimObject* object) { // Call to parent. Parent::copyTo(object); -} \ No newline at end of file +} + +// +void LevelAsset::initializeAsset() +{ + // Call parent. + Parent::initializeAsset(); + + // Ensure the image-file is expanded. + mPreviewImage = expandAssetFilePath(mPreviewImage); + mLevelFile = expandAssetFilePath(mLevelFile); +} + +// +void LevelAsset::setLevelFile(const char* pLevelFile) +{ + // Sanity! + AssertFatal(pLevelFile != NULL, "Cannot use a NULL level file."); + + // Fetch image file. + pLevelFile = StringTable->insert(pLevelFile); + + // Ignore no change, + if (pLevelFile == mLevelFile) + return; + + // Update. + mLevelFile = getOwned() ? expandAssetFilePath(pLevelFile) : StringTable->insert(pLevelFile); + + // Refresh the asset. + refreshAsset(); +} + +void LevelAsset::setImageFile(const char* pImageFile) +{ + // Sanity! + AssertFatal(pImageFile != NULL, "Cannot use a NULL image file."); + + // Fetch image file. + pImageFile = StringTable->insert(pImageFile); + + // Ignore no change, + if (pImageFile == mPreviewImage) + return; + + // Update. + mPreviewImage = getOwned() ? expandAssetFilePath(pImageFile) : StringTable->insert(pImageFile); + + // Refresh the asset. + refreshAsset(); +} diff --git a/Engine/source/T3D/assets/LevelAsset.h b/Engine/source/T3D/assets/LevelAsset.h index 3fc58c1834..b8f222a478 100644 --- a/Engine/source/T3D/assets/LevelAsset.h +++ b/Engine/source/T3D/assets/LevelAsset.h @@ -44,6 +44,7 @@ class LevelAsset : public AssetBase { typedef AssetBase Parent; + StringTableEntry mLevelName; StringTableEntry mLevelFile; StringTableEntry mPreviewImage; @@ -61,8 +62,20 @@ class LevelAsset : public AssetBase /// Declare Console Object. DECLARE_CONOBJECT(LevelAsset); + void setLevelFile(const char* pImageFile); + inline StringTableEntry getLevelFile(void) const { return mLevelFile; }; + void setImageFile(const char* pImageFile); + inline StringTableEntry getImageFile(void) const { return mPreviewImage; }; + + SimObjectId load(); + protected: - virtual void initializeAsset(void) {} + static bool setLevelFile(void *obj, const char *index, const char *data) { static_cast(obj)->setLevelFile(data); return false; } + static const char* getLevelFile(void* obj, const char* data) { return static_cast(obj)->getLevelFile(); } + static bool setPreviewImageFile(void *obj, const char *index, const char *data) { static_cast(obj)->setImageFile(data); return false; } + static const char* getPreviewImageFile(void* obj, const char* data) { return static_cast(obj)->getImageFile(); } + + virtual void initializeAsset(void); virtual void onAssetRefresh(void) {} }; diff --git a/Engine/source/T3D/assets/MaterialAsset.cpp b/Engine/source/T3D/assets/MaterialAsset.cpp index 6cf3561a1f..5637d1effc 100644 --- a/Engine/source/T3D/assets/MaterialAsset.cpp +++ b/Engine/source/T3D/assets/MaterialAsset.cpp @@ -98,10 +98,6 @@ MaterialAsset::MaterialAsset() MaterialAsset::~MaterialAsset() { - // If the asset manager does not own the asset then we own the - // asset definition so delete it. - if (!getOwned()) - delete mpAssetDefinition; } //----------------------------------------------------------------------------- @@ -112,7 +108,9 @@ void MaterialAsset::initPersistFields() Parent::initPersistFields(); //addField("shaderGraph", TypeRealString, Offset(mShaderGraphFile, MaterialAsset), ""); - addField("scriptFile", TypeRealString, Offset(mScriptFile, MaterialAsset), "Path to the file containing the material definition."); + addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, MaterialAsset), + &setScriptFile, &getScriptFile, "Path to the file containing the material definition."); + addField("materialDefinitionName", TypeRealString, Offset(mMatDefinitionName, MaterialAsset), "Name of the material definition this asset is for."); } @@ -132,12 +130,12 @@ void MaterialAsset::onAssetRefresh() if (Platform::isFile(mScriptFile)) Con::executeFile(mScriptFile, false, false); - if (!mMatDefinitionName.isEmpty()) + if (mMatDefinitionName != StringTable->EmptyString()) { Material* matDef; - if (!Sim::findObject(mMatDefinitionName.c_str(), matDef)) + if (!Sim::findObject(mMatDefinitionName, matDef)) { - Con::errorf("MaterialAsset: Unable to find the Material %s", mMatDefinitionName.c_str()); + Con::errorf("MaterialAsset: Unable to find the Material %s", mMatDefinitionName); return; } @@ -145,6 +143,25 @@ void MaterialAsset::onAssetRefresh() } } +void MaterialAsset::setScriptFile(const char* pScriptFile) +{ + // Sanity! + AssertFatal(pScriptFile != NULL, "Cannot use a NULL script file."); + + // Fetch image file. + pScriptFile = StringTable->insert(pScriptFile); + + // Ignore no change, + if (pScriptFile == mScriptFile) + return; + + // Update. + mScriptFile = getOwned() ? expandAssetFilePath(pScriptFile) : StringTable->insert(pScriptFile); + + // Refresh the asset. + refreshAsset(); +} + //------------------------------------------------------------------------------ void MaterialAsset::compileShader() @@ -184,34 +201,68 @@ void GuiInspectorTypeMaterialAssetPtr::consoleInit() GuiControl* GuiInspectorTypeMaterialAssetPtr::constructEditControl() { // Create base filename edit controls - GuiControl *retCtrl = Parent::constructEditControl(); - if (retCtrl == NULL) - return retCtrl; + mUseHeightOverride = true; + mHeightOverride = 100; + + mMatEdContainer = new GuiControl(); + mMatEdContainer->registerObject(); + + addObject(mMatEdContainer); + + // Create "Open in ShapeEditor" button + mMatPreviewButton = new GuiBitmapButtonCtrl(); + + const char* matAssetId = getData(); + + MaterialAsset* matAsset = AssetDatabase.acquireAsset< MaterialAsset>(matAssetId); + + Material* materialDef = nullptr; + + char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor"; + + if (!Sim::findObject(matAsset->getMaterialDefinitionName(), materialDef)) + { + Con::errorf("GuiInspectorTypeMaterialAssetPtr::constructEditControl() - unable to find material in asset"); + } + else + { + mMatPreviewButton->setBitmap(materialDef->mDiffuseMapFilename[0]); + } + + mMatPreviewButton->setPosition(0, 0); + mMatPreviewButton->setExtent(100,100); // Change filespec char szBuffer[512]; dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"MaterialAsset\", \"AssetBrowser.changeAsset\", %d, %s);", mInspector->getComponentGroupTargetId(), mCaption); - mBrowseButton->setField("Command", szBuffer); + mMatPreviewButton->setField("Command", szBuffer); - // Create "Open in ShapeEditor" button - mSMEdButton = new GuiBitmapButtonCtrl(); + mMatPreviewButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile"); + mMatPreviewButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile"); + mMatPreviewButton->setDataField(StringTable->insert("hovertime"), NULL, "1000"); - dSprintf(szBuffer, sizeof(szBuffer), "echo(\"Game Object Editor not implemented yet!\");", retCtrl->getId()); - mSMEdButton->setField("Command", szBuffer); + StringBuilder strbld; + strbld.append(matAsset->getMaterialDefinitionName()); + strbld.append("\n"); + strbld.append("Open this file in the Material Editor"); - char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor"; - mSMEdButton->setBitmap(bitmapName); + mMatPreviewButton->setDataField(StringTable->insert("tooltip"), NULL, strbld.data()); + + _registerEditControl(mMatPreviewButton); + //mMatPreviewButton->registerObject(); + mMatEdContainer->addObject(mMatPreviewButton); - mSMEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile"); - mSMEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile"); - mSMEdButton->setDataField(StringTable->insert("hovertime"), NULL, "1000"); - mSMEdButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this file in the Material Editor"); + mMatAssetIdTxt = new GuiTextEditCtrl(); + mMatAssetIdTxt->registerObject(); + mMatAssetIdTxt->setActive(false); - mSMEdButton->registerObject(); - addObject(mSMEdButton); + mMatAssetIdTxt->setText(matAssetId); - return retCtrl; + mMatAssetIdTxt->setBounds(100, 0, 150, 18); + mMatEdContainer->addObject(mMatAssetIdTxt); + + return mMatEdContainer; } bool GuiInspectorTypeMaterialAssetPtr::updateRects() @@ -225,17 +276,41 @@ bool GuiInspectorTypeMaterialAssetPtr::updateRects() mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin - 34, fieldExtent.y); bool resized = mEdit->resize(mEditCtrlRect.point, mEditCtrlRect.extent); - if (mBrowseButton != NULL) + + if (mMatEdContainer != nullptr) + { + mMatPreviewButton->resize(mEditCtrlRect.point, mEditCtrlRect.extent); + } + + if (mMatPreviewButton != nullptr) { - mBrowseRect.set(fieldExtent.x - 32, 2, 14, fieldExtent.y - 4); - resized |= mBrowseButton->resize(mBrowseRect.point, mBrowseRect.extent); + mMatPreviewButton->resize(Point2I::Zero, Point2I(100, 100)); } - if (mSMEdButton != NULL) + if (mMatAssetIdTxt != nullptr) { - RectI shapeEdRect(fieldExtent.x - 16, 2, 14, fieldExtent.y - 4); - resized |= mSMEdButton->resize(shapeEdRect.point, shapeEdRect.extent); + mMatAssetIdTxt->resize(Point2I(100, 0), Point2I(mEditCtrlRect.extent.x - 100, 18)); } return resized; -} \ No newline at end of file +} + +void GuiInspectorTypeMaterialAssetPtr::setMaterialAsset(String assetId) +{ + mTargetObject->setDataField(mCaption, "", assetId); + + //force a refresh + SimObject* obj = mInspector->getInspectObject(); + mInspector->inspectObject(obj); +} + +DefineEngineMethod(GuiInspectorTypeMaterialAssetPtr, setMaterialAsset, void, (String assetId), (""), + "Gets a particular shape animation asset for this shape.\n" + "@param animation asset index.\n" + "@return Shape Animation Asset.\n") +{ + if (assetId == String::EmptyString) + return; + + return object->setMaterialAsset(assetId); +} diff --git a/Engine/source/T3D/assets/MaterialAsset.h b/Engine/source/T3D/assets/MaterialAsset.h index 2cb9f15b14..df6a135fbf 100644 --- a/Engine/source/T3D/assets/MaterialAsset.h +++ b/Engine/source/T3D/assets/MaterialAsset.h @@ -57,7 +57,7 @@ class MaterialAsset : public AssetBase String mShaderGraphFile; String mScriptFile; - String mMatDefinitionName; + StringTableEntry mMatDefinitionName; public: MaterialAsset(); @@ -67,15 +67,22 @@ class MaterialAsset : public AssetBase static void initPersistFields(); virtual void copyTo(SimObject* object); - virtual void initializeAsset(); - virtual void onAssetRefresh(void); - void compileShader(); - String getMaterialDefinitionName() { return mMatDefinitionName; } + StringTableEntry getMaterialDefinitionName() { return mMatDefinitionName; } + + void setScriptFile(const char* pScriptFile); + inline StringTableEntry getScriptFile(void) const { return mScriptFile; }; /// Declare Console Object. DECLARE_CONOBJECT(MaterialAsset); + +protected: + virtual void initializeAsset(); + virtual void onAssetRefresh(void); + + static bool setScriptFile(void *obj, const char *index, const char *data) { static_cast(obj)->setScriptFile(data); return false; } + static const char* getScriptFile(void* obj, const char* data) { return static_cast(obj)->getScriptFile(); } }; DefineConsoleType(TypeMaterialAssetPtr, MaterialAsset) @@ -83,18 +90,21 @@ DefineConsoleType(TypeMaterialAssetPtr, MaterialAsset) //----------------------------------------------------------------------------- // TypeAssetId GuiInspectorField Class //----------------------------------------------------------------------------- -class GuiInspectorTypeMaterialAssetPtr : public GuiInspectorTypeFileName +class GuiInspectorTypeMaterialAssetPtr : public GuiInspectorField { - typedef GuiInspectorTypeFileName Parent; + typedef GuiInspectorField Parent; public: - GuiBitmapButtonCtrl *mSMEdButton; + GuiControl* mMatEdContainer; + GuiBitmapButtonCtrl *mMatPreviewButton; + GuiTextEditCtrl *mMatAssetIdTxt; DECLARE_CONOBJECT(GuiInspectorTypeMaterialAssetPtr); static void consoleInit(); virtual GuiControl* constructEditControl(); virtual bool updateRects(); + void setMaterialAsset(String assetId); }; #endif // _ASSET_BASE_H_ diff --git a/Engine/source/T3D/assets/PostEffectAsset.cpp b/Engine/source/T3D/assets/PostEffectAsset.cpp index 4eb67a6a30..57dcb381da 100644 --- a/Engine/source/T3D/assets/PostEffectAsset.cpp +++ b/Engine/source/T3D/assets/PostEffectAsset.cpp @@ -112,7 +112,8 @@ void PostEffectAsset::initPersistFields() // Call parent. Parent::initPersistFields(); - addField("scriptFile", TypeString, Offset(mScriptFile, PostEffectAsset), "Path to the script file."); + addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, PostEffectAsset), + &setScriptFile, &getScriptFile, "Path to the script file."); } //------------------------------------------------------------------------------ @@ -125,5 +126,31 @@ void PostEffectAsset::copyTo(SimObject* object) void PostEffectAsset::initializeAsset() { - //mPostEffect = new PostEffect(); -} \ No newline at end of file + if (Platform::isFile(mScriptFile)) + Con::executeFile(mScriptFile, false, false); +} + +void PostEffectAsset::onAssetRefresh() +{ + if (Platform::isFile(mScriptFile)) + Con::executeFile(mScriptFile, false, false); +} + +void PostEffectAsset::setScriptFile(const char* pScriptFile) +{ + // Sanity! + AssertFatal(pScriptFile != NULL, "Cannot use a NULL script file."); + + // Fetch image file. + pScriptFile = StringTable->insert(pScriptFile); + + // Ignore no change, + if (pScriptFile == mScriptFile) + return; + + // Update. + mScriptFile = getOwned() ? expandAssetFilePath(pScriptFile) : StringTable->insert(pScriptFile); + + // Refresh the asset. + refreshAsset(); +} diff --git a/Engine/source/T3D/assets/PostEffectAsset.h b/Engine/source/T3D/assets/PostEffectAsset.h index 381fa15769..4597d33905 100644 --- a/Engine/source/T3D/assets/PostEffectAsset.h +++ b/Engine/source/T3D/assets/PostEffectAsset.h @@ -56,13 +56,18 @@ class PostEffectAsset : public AssetBase static void initPersistFields(); virtual void copyTo(SimObject* object); - virtual void initializeAsset(); + void setScriptFile(const char* pScriptFile); + inline StringTableEntry getScriptFile(void) const { return mScriptFile; }; /// Declare Console Object. DECLARE_CONOBJECT(PostEffectAsset); protected: - virtual void onAssetRefresh(void) {} + virtual void initializeAsset(); + virtual void onAssetRefresh(void); + + static bool setScriptFile(void *obj, const char *index, const char *data) { static_cast(obj)->setScriptFile(data); return false; } + static const char* getScriptFile(void* obj, const char* data) { return static_cast(obj)->getScriptFile(); } }; DefineConsoleType(TypePostEffectAssetPtr, PostEffectAsset) diff --git a/Engine/source/T3D/assets/ScriptAsset.cpp b/Engine/source/T3D/assets/ScriptAsset.cpp index 10c3be7772..d4968aa3f7 100644 --- a/Engine/source/T3D/assets/ScriptAsset.cpp +++ b/Engine/source/T3D/assets/ScriptAsset.cpp @@ -91,7 +91,7 @@ ConsoleSetType(TypeScriptAssetPtr) ScriptAsset::ScriptAsset() : AssetBase(), mIsServerSide(true) { - mScriptFilePath = StringTable->EmptyString(); + mScriptFile = StringTable->EmptyString(); } //----------------------------------------------------------------------------- @@ -111,9 +111,8 @@ void ScriptAsset::initPersistFields() // Call parent. Parent::initPersistFields(); - addField("scriptFilePath", TypeString, Offset(mScriptFilePath, ScriptAsset), "Path to the script file."); - addField("isServerSide", TypeBool, Offset(mIsServerSide, ScriptAsset), "Is this script file to be run on the server side?"); - + addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, ScriptAsset), + &setScriptFile, &getScriptFile, "Path to the script file."); } //------------------------------------------------------------------------------ @@ -124,14 +123,41 @@ void ScriptAsset::copyTo(SimObject* object) Parent::copyTo(object); } -void ScriptAsset::initializeAsset() +void ScriptAsset::setScriptFile(const char* pScriptFile) +{ + // Sanity! + AssertFatal(pScriptFile != NULL, "Cannot use a NULL script file."); + + // Fetch image file. + pScriptFile = StringTable->insert(pScriptFile); + + // Ignore no change, + if (pScriptFile == mScriptFile) + return; + + // Update. + mScriptFile = getOwned() ? expandAssetFilePath(pScriptFile) : StringTable->insert(pScriptFile); + + // Refresh the asset. + refreshAsset(); +} + +bool ScriptAsset::execScript() { - if (Platform::isFile(mScriptFilePath)) - Con::executeFile(mScriptFilePath, false, false); + if (Platform::isFile(mScriptFile)) + { + return Con::executeFile(mScriptFile, false, false); + } + else + { + Con::errorf("ScriptAsset:execScript() - Script asset must have a valid file to exec"); + return false; + } } -void ScriptAsset::onAssetRefresh() +DefineEngineMethod(ScriptAsset, execScript, bool, (), , + "Executes the script file.\n" + "@return The bool result of calling exec") { - if (Platform::isFile(mScriptFilePath)) - Con::executeFile(mScriptFilePath, false, false); -} \ No newline at end of file + return object->execScript(); +} diff --git a/Engine/source/T3D/assets/ScriptAsset.h b/Engine/source/T3D/assets/ScriptAsset.h index 8c12f2b88e..39eccdf957 100644 --- a/Engine/source/T3D/assets/ScriptAsset.h +++ b/Engine/source/T3D/assets/ScriptAsset.h @@ -44,7 +44,7 @@ class ScriptAsset : public AssetBase { typedef AssetBase Parent; - StringTableEntry mScriptFilePath; + StringTableEntry mScriptFile; bool mIsServerSide; public: @@ -58,9 +58,17 @@ class ScriptAsset : public AssetBase /// Declare Console Object. DECLARE_CONOBJECT(ScriptAsset); + void setScriptFile(const char* pScriptFile); + inline StringTableEntry getScriptFile(void) const { return mScriptFile; }; + + bool execScript(); + protected: - virtual void initializeAsset(void); - virtual void onAssetRefresh(void); + virtual void initializeAsset(void) {} + virtual void onAssetRefresh(void) {} + + static bool setScriptFile(void *obj, const char *index, const char *data) { static_cast(obj)->setScriptFile(data); return false; } + static const char* getScriptFile(void* obj, const char* data) { return static_cast(obj)->getScriptFile(); } }; DefineConsoleType(TypeScriptAssetPtr, ScriptAsset) diff --git a/Engine/source/T3D/assets/ShapeAnimationAsset.cpp b/Engine/source/T3D/assets/ShapeAnimationAsset.cpp index 4c2b0283ea..f433577077 100644 --- a/Engine/source/T3D/assets/ShapeAnimationAsset.cpp +++ b/Engine/source/T3D/assets/ShapeAnimationAsset.cpp @@ -105,10 +105,6 @@ ShapeAnimationAsset::ShapeAnimationAsset() : ShapeAnimationAsset::~ShapeAnimationAsset() { - // If the asset manager does not own the asset then we own the - // asset definition so delete it. - if (!getOwned()) - delete mpAssetDefinition; } //----------------------------------------------------------------------------- @@ -118,7 +114,9 @@ void ShapeAnimationAsset::initPersistFields() // Call parent. Parent::initPersistFields(); - addField("animationFile", TypeFilename, Offset(mFileName, ShapeAnimationAsset), "Path to the file name containing the animation"); + addProtectedField("animationFile", TypeAssetLooseFilePath, Offset(mFileName, ShapeAnimationAsset), + &setAnimationFile, &getAnimationFile, "Path to the file name containing the animation"); + addField("animationName", TypeString, Offset(mAnimationName, ShapeAnimationAsset), "Name of the animation"); addField("isEmbedded", TypeBool, Offset(mIsEmbedded, ShapeAnimationAsset), "If true, this animation asset just referrs to an embedded animation of a regular shape mesh. If false, it is a self-contained animation file"); @@ -172,4 +170,38 @@ void ShapeAnimationAsset::initializeAsset(void) void ShapeAnimationAsset::onAssetRefresh(void) { -} \ No newline at end of file +} + +void ShapeAnimationAsset::setAnimationFile(const char* pAnimationFile) +{ + // Sanity! + AssertFatal(pAnimationFile != NULL, "Cannot use a NULL animation file."); + + // Fetch image file. + pAnimationFile = StringTable->insert(pAnimationFile); + + // Ignore no change, + if (pAnimationFile == mFileName) + return; + + // Update. + mFileName = getOwned() ? expandAssetFilePath(pAnimationFile) : StringTable->insert(pAnimationFile); + + // Refresh the asset. + refreshAsset(); +} + +S32 ShapeAnimationAsset::getAnimationCount() +{ + if (mSourceShape == nullptr) + return 0; + + return mSourceShape->sequences.size(); +} + +DefineEngineMethod(ShapeAnimationAsset, getAnimationCount, S32, (), , + "Gets the number of animations for this shape asset.\n" + "@return Animation count.\n") +{ + return object->getAnimationCount(); +} diff --git a/Engine/source/T3D/assets/ShapeAnimationAsset.h b/Engine/source/T3D/assets/ShapeAnimationAsset.h index 0b7bf17903..3f8b77667c 100644 --- a/Engine/source/T3D/assets/ShapeAnimationAsset.h +++ b/Engine/source/T3D/assets/ShapeAnimationAsset.h @@ -78,6 +78,9 @@ class ShapeAnimationAsset : public AssetBase static void initPersistFields(); virtual void copyTo(SimObject* object); + void setAnimationFile(const char* pScriptFile); + inline StringTableEntry getAnimationFile(void) const { return mFileName; }; + /// Declare Console Object. DECLARE_CONOBJECT(ShapeAnimationAsset); @@ -85,6 +88,9 @@ class ShapeAnimationAsset : public AssetBase virtual void initializeAsset(void); virtual void onAssetRefresh(void); + static bool setAnimationFile(void *obj, const char *index, const char *data) { static_cast(obj)->setAnimationFile(data); return false; } + static const char* getAnimationFile(void* obj, const char* data) { return static_cast(obj)->getAnimationFile(); } + public: StringTableEntry getAnimationFilename() { return mFileName; } StringTableEntry getAnimationName() { return mAnimationName; } @@ -101,6 +107,8 @@ class ShapeAnimationAsset : public AssetBase bool isBlend() { return mIsBlend; } S32 getBlendFrame() { return mBlendFrame; } + + S32 getAnimationCount(); }; DefineConsoleType(TypeShapeAnimationAssetPtr, ShapeAnimationAsset) diff --git a/Engine/source/T3D/assets/ShapeAsset.cpp b/Engine/source/T3D/assets/ShapeAsset.cpp index 2bce369ea2..1766dea7c2 100644 --- a/Engine/source/T3D/assets/ShapeAsset.cpp +++ b/Engine/source/T3D/assets/ShapeAsset.cpp @@ -92,10 +92,6 @@ ShapeAsset::ShapeAsset() ShapeAsset::~ShapeAsset() { - // If the asset manager does not own the asset then we own the - // asset definition so delete it. - if (!getOwned()) - delete mpAssetDefinition; } //----------------------------------------------------------------------------- @@ -105,7 +101,8 @@ void ShapeAsset::initPersistFields() // Call parent. Parent::initPersistFields(); - addField("fileName", TypeFilename, Offset(mFileName, ShapeAsset), "Path to the shape file we want to render"); + addProtectedField("fileName", TypeAssetLooseFilePath, Offset(mFileName, ShapeAsset), + &setShapeFile, &getShapeFile, "Path to the shape file we want to render"); } void ShapeAsset::setDataField(StringTableEntry slotName, const char *array, const char *value) @@ -127,7 +124,36 @@ void ShapeAsset::initializeAsset() // Call parent. Parent::initializeAsset(); - if (dStrcmp(mFileName, "") == 0) + if (mFileName == StringTable->EmptyString()) + return; + + ResourceManager::get().getChangedSignal().notify(this, &ShapeAsset::_onResourceChanged); + + loadShape(); +} + +void ShapeAsset::setShapeFile(const char* pShapeFile) +{ + // Sanity! + AssertFatal(pShapeFile != NULL, "Cannot use a NULL shape file."); + + // Fetch image file. + pShapeFile = StringTable->insert(pShapeFile); + + // Ignore no change, + if (pShapeFile == mFileName) + return; + + // Update. + mFileName = getOwned() ? expandAssetFilePath(pShapeFile) : StringTable->insert(pShapeFile); + + // Refresh the asset. + refreshAsset(); +} + +void ShapeAsset::_onResourceChanged(const Torque::Path &path) +{ + if (path != Torque::Path(mFileName) ) return; loadShape(); @@ -152,12 +178,12 @@ bool ShapeAsset::loadShape() if (assetType == StringTable->insert("MaterialAsset")) { - mMaterialAssetIds.push_back(assetDependenciesItr->value); + mMaterialAssetIds.push_front(assetDependenciesItr->value); //Force the asset to become initialized if it hasn't been already AssetPtr matAsset = assetDependenciesItr->value; - mMaterialAssets.push_back(matAsset); + mMaterialAssets.push_front(matAsset); } else if (assetType == StringTable->insert("ShapeAnimationAsset")) { @@ -227,6 +253,8 @@ bool ShapeAsset::loadShape() } } + onShapeChanged.trigger(this); + return true; } diff --git a/Engine/source/T3D/assets/ShapeAsset.h b/Engine/source/T3D/assets/ShapeAsset.h index 45fca7e86a..e8800c1cf2 100644 --- a/Engine/source/T3D/assets/ShapeAsset.h +++ b/Engine/source/T3D/assets/ShapeAsset.h @@ -95,16 +95,40 @@ class ShapeAsset : public AssetBase Resource getShapeResource() { return mShape; } void SplitSequencePathAndName(String& srcPath, String& srcName); - String getShapeFilename() { return mFileName; } + StringTableEntry getShapeFilename() { return mFileName; } U32 getShapeFilenameHash() { return _StringTable::hashString(mFileName); } + Vector> getMaterialAssets() { return mMaterialAssets; } + + inline AssetPtr getMaterialAsset(U32 matId) + { + if(matId >= mMaterialAssets.size()) + return nullptr; + else + return mMaterialAssets[matId]; + } + + void clearMaterialAssets() { mMaterialAssets.clear(); } + + void addMaterialAssets(AssetPtr matPtr) { mMaterialAssets.push_back(matPtr); } + S32 getMaterialCount() { return mMaterialAssets.size(); } S32 getAnimationCount() { return mAnimationAssets.size(); } ShapeAnimationAsset* getAnimation(S32 index); + void _onResourceChanged(const Torque::Path &path); + + Signal< void(ShapeAsset*) > onShapeChanged; + + void setShapeFile(const char* pScriptFile); + inline StringTableEntry getShapeFile(void) const { return mFileName; }; + protected: virtual void onAssetRefresh(void); + + static bool setShapeFile(void *obj, const char *index, const char *data) { static_cast(obj)->setShapeFile(data); return false; } + static const char* getShapeFile(void* obj, const char* data) { return static_cast(obj)->getShapeFile(); } }; DefineConsoleType(TypeShapeAssetPtr, S32) diff --git a/Engine/source/T3D/assets/SoundAsset.cpp b/Engine/source/T3D/assets/SoundAsset.cpp index f2978aa387..9563f5d8aa 100644 --- a/Engine/source/T3D/assets/SoundAsset.cpp +++ b/Engine/source/T3D/assets/SoundAsset.cpp @@ -92,7 +92,7 @@ ConsoleSetType(TypeSoundAssetPtr) SoundAsset::SoundAsset() { - mSoundFilePath = StringTable->EmptyString(); + mSoundFile = StringTable->EmptyString(); mPitchAdjust = 0; mVolumeAdjust = 0; @@ -117,7 +117,8 @@ void SoundAsset::initPersistFields() // Call parent. Parent::initPersistFields(); - addField("soundFilePath", TypeFilename, Offset(mSoundFilePath, SoundAsset), "Path to the sound file."); + addProtectedField("soundFile", TypeAssetLooseFilePath, Offset(mSoundFile, SoundAsset), + &setSoundFile, &getSoundFile, "Path to the sound file."); addField("pitchAdjust", TypeF32, Offset(mPitchAdjust, SoundAsset), "Adjustment of the pitch value"); addField("volumeAdjust", TypeF32, Offset(mVolumeAdjust, SoundAsset), "Adjustment to the volume."); @@ -138,4 +139,23 @@ void SoundAsset::initializeAsset(void) void SoundAsset::onAssetRefresh(void) { -} \ No newline at end of file +} + +void SoundAsset::setSoundFile(const char* pSoundFile) +{ + // Sanity! + AssertFatal(pSoundFile != NULL, "Cannot use a NULL shape file."); + + // Fetch image file. + pSoundFile = StringTable->insert(pSoundFile); + + // Ignore no change, + if (pSoundFile == mSoundFile) + return; + + // Update. + mSoundFile = getOwned() ? expandAssetFilePath(pSoundFile) : StringTable->insert(pSoundFile); + + // Refresh the asset. + refreshAsset(); +} diff --git a/Engine/source/T3D/assets/SoundAsset.h b/Engine/source/T3D/assets/SoundAsset.h index bfe5828237..4e9bdf8d60 100644 --- a/Engine/source/T3D/assets/SoundAsset.h +++ b/Engine/source/T3D/assets/SoundAsset.h @@ -47,7 +47,7 @@ class SoundAsset : public AssetBase typedef AssetBase Parent; protected: - StringTableEntry mSoundFilePath; + StringTableEntry mSoundFile; F32 mPitchAdjust; F32 mVolumeAdjust; @@ -62,11 +62,15 @@ class SoundAsset : public AssetBase /// Declare Console Object. DECLARE_CONOBJECT(SoundAsset); - StringTableEntry getSoundFilePath() { return mSoundFilePath; } + void setSoundFile(const char* pScriptFile); + inline StringTableEntry getSoundFile(void) const { return mSoundFile; }; protected: virtual void initializeAsset(void); virtual void onAssetRefresh(void); + + static bool setSoundFile(void *obj, const char *index, const char *data) { static_cast(obj)->setSoundFile(data); return false; } + static const char* getSoundFile(void* obj, const char* data) { return static_cast(obj)->getSoundFile(); } }; DefineConsoleType(TypeSoundAssetPtr, SoundAsset) diff --git a/Engine/source/T3D/assets/stateMachineAsset.cpp b/Engine/source/T3D/assets/stateMachineAsset.cpp index 99ba956a48..44ca7f40d8 100644 --- a/Engine/source/T3D/assets/stateMachineAsset.cpp +++ b/Engine/source/T3D/assets/stateMachineAsset.cpp @@ -92,7 +92,7 @@ ConsoleSetType(TypeStateMachineAssetPtr) StateMachineAsset::StateMachineAsset() { - mStateMachineFileName = StringTable->EmptyString(); + mStateMachineFile = StringTable->EmptyString(); } //----------------------------------------------------------------------------- @@ -112,7 +112,8 @@ void StateMachineAsset::initPersistFields() // Call parent. Parent::initPersistFields(); - addField("stateMachineFile", TypeString, Offset(mStateMachineFileName, StateMachineAsset), "Path to the state machine file."); + addProtectedField("stateMachineFile", TypeAssetLooseFilePath, Offset(mStateMachineFile, StateMachineAsset), + &setStateMachineFile, &getStateMachineFile, "Path to the state machine file."); } //------------------------------------------------------------------------------ @@ -123,9 +124,29 @@ void StateMachineAsset::copyTo(SimObject* object) Parent::copyTo(object); } +void StateMachineAsset::setStateMachineFile(const char* pStateMachineFile) +{ + // Sanity! + AssertFatal(pStateMachineFile != NULL, "Cannot use a NULL state machine file."); + + // Fetch image file. + pStateMachineFile = StringTable->insert(pStateMachineFile); + + // Ignore no change, + if (pStateMachineFile == mStateMachineFile) + return; + + // Update. + mStateMachineFile = getOwned() ? expandAssetFilePath(pStateMachineFile) : StringTable->insert(pStateMachineFile); + + // Refresh the asset. + refreshAsset(); +} + + DefineEngineMethod(StateMachineAsset, notifyAssetChanged, void, (),,"") { - ResourceManager::get().getChangedSignal().trigger(object->getStateMachineFileName()); + ResourceManager::get().getChangedSignal().trigger(object->getStateMachineFile()); } //----------------------------------------------------------------------------- diff --git a/Engine/source/T3D/assets/stateMachineAsset.h b/Engine/source/T3D/assets/stateMachineAsset.h index 6452a6e6f0..8cb40bfcc0 100644 --- a/Engine/source/T3D/assets/stateMachineAsset.h +++ b/Engine/source/T3D/assets/stateMachineAsset.h @@ -46,7 +46,7 @@ class StateMachineAsset : public AssetBase { typedef AssetBase Parent; - StringTableEntry mStateMachineFileName; + StringTableEntry mStateMachineFile; public: StateMachineAsset(); @@ -59,11 +59,15 @@ class StateMachineAsset : public AssetBase /// Declare Console Object. DECLARE_CONOBJECT(StateMachineAsset); - StringTableEntry getStateMachineFileName() { return mStateMachineFileName; } + void setStateMachineFile(const char* pStateMachineFile); + inline StringTableEntry getStateMachineFile(void) const { return mStateMachineFile; }; protected: virtual void initializeAsset(void) {} virtual void onAssetRefresh(void) {} + + static bool setStateMachineFile(void *obj, const char *index, const char *data) { static_cast(obj)->setStateMachineFile(data); return false; } + static const char* getStateMachineFile(void* obj, const char* data) { return static_cast(obj)->getStateMachineFile(); } }; DefineConsoleType(TypeStateMachineAssetPtr, StateMachineAsset) diff --git a/Engine/source/T3D/entity.cpp b/Engine/source/T3D/entity.cpp index bb8f7becf7..e5ed603996 100644 --- a/Engine/source/T3D/entity.cpp +++ b/Engine/source/T3D/entity.cpp @@ -124,6 +124,7 @@ Entity::Entity() mGameObjectAssetId = StringTable->insert(""); + mDirtyGameObject = false; } Entity::~Entity() @@ -156,8 +157,11 @@ void Entity::initPersistFields() endGroup("Misc"); addGroup("GameObject"); - addProtectedField("gameObjectName", TypeGameObjectAssetPtr, Offset(mGameObjectAsset, Entity), &_setGameObject, &defaultProtectedGetFn, + addProtectedField("GameObject", TypeGameObjectAssetPtr, Offset(mGameObjectAsset, Entity), &_setGameObject, &defaultProtectedGetFn, "The asset Id used for the game object this entity is based on."); + + addField("dirtyGameObject", TypeBool, Offset(mDirtyGameObject, Entity), "If this entity is a GameObject, it flags if this instance delinates from the template.", + AbstractClassRep::FieldFlags::FIELD_HideInInspectors); endGroup("GameObject"); } diff --git a/Engine/source/T3D/entity.h b/Engine/source/T3D/entity.h index b7e325ce59..2e3f93df40 100644 --- a/Engine/source/T3D/entity.h +++ b/Engine/source/T3D/entity.h @@ -85,6 +85,9 @@ class Entity : public GameBase StringTableEntry mGameObjectAssetId; AssetPtr mGameObjectAsset; + //Marked if this entity is a GameObject and deliniates from the parent GO asset + bool mDirtyGameObject; + ContainerQueryInfo containerInfo; bool mInitialized; diff --git a/Engine/source/assets/assetBase.cpp b/Engine/source/assets/assetBase.cpp index 39cd4115f3..e1bc9bf7a3 100644 --- a/Engine/source/assets/assetBase.cpp +++ b/Engine/source/assets/assetBase.cpp @@ -60,6 +60,10 @@ mAssetInitialized(false) { // Generate an asset definition. mpAssetDefinition = new AssetDefinition(); + + mInternalName = StringTable->EmptyString(); + mClassName = StringTable->EmptyString(); + mSuperClassName = StringTable->EmptyString(); } //----------------------------------------------------------------------------- diff --git a/Templates/BaseGame/game/data/ui/scripts/chooseLevelDlg.cs b/Templates/BaseGame/game/data/ui/scripts/chooseLevelDlg.cs index af260c27d4..ef34e329df 100644 --- a/Templates/BaseGame/game/data/ui/scripts/chooseLevelDlg.cs +++ b/Templates/BaseGame/game/data/ui/scripts/chooseLevelDlg.cs @@ -243,7 +243,7 @@ %LevelInfoObject.delete(); }*/ - %levelName = %levelAsset.friendlyName; + %levelName = %levelAsset.LevelName; %levelDesc = %levelAsset.description; %levelPreview = %levelAsset.levelPreviewImage; diff --git a/Templates/BaseGame/game/tools/assetBrowser/art/cppIcon.png b/Templates/BaseGame/game/tools/assetBrowser/art/cppIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..8b027957b0fbe3594c73d1abfc84390b48ee152a GIT binary patch literal 4894 zcmeHLXIN9&*4}|Aj*0?`=m3EWeyAW#N`%k`VE}20AS%tFg&ul9Aja{k6d@{NL`)DJ zR6xR@gkE$=L1`i#q?iaKR3j=al6#`}d7K~KJIr(cem~B$&slrzwch>iwb$P3q#SXu z65sgaMgV}gjkSdn03y(<2-vV5YCgnuEkn(EZ(A!1sC@~ly>MMa(Ay8;)+eI?*tAXf zz`(8BJ0YQ1w2i%`7;E!(G4ZX%>DE<{NIuZ{MD!s{XsBOUH1r9;p-8`9qWydov4PP6 zidHuEM|?H>!~l@`)yCo{=eU8Hq4>+UvGGrNX#ZG$tiR^mKn+iRr0u6v`z<;DJTf5l z&`HrLu(6;pYww*hsfVz?-#T$`7WLkBF0w4}OnW|=c$=)rSZf&P` zMD8QsRAaF7z2!8BcW)f<0bK!Us1m%KDV zm5g{M;7yDdcE|muE5FccXS6V77T>cT1emFQ8aatve~VglPi?p_!Lzm$tEJI`tqU+^ zc8>K|CPnU_z4>E$%>#zdV^3-X6vt_Sika!y5_g4$!3O>EGMO8%+g%G>*n`K|JgUwE zR?qXRHw$`0bOFrl39g_{XBZWZtM#K#a+-Xlcsh=*6Kt|)kNov(dueT!CpgEXb;1lw)Ya-XqQ|uX^>x;{%HSxqmq=R z!-)}m3qHN6n{Ub|3vg3vWbMVx( zfoP?Kgrp>oK|Z%Q$*{d^oT-Uq{SbNH3*4k97HASnYok;Q{m0dpT3&cyCDL7g$0)wKU? zj$1WeBFA;6cJl_+*83!BG`th+LR2?9z&3yz6(f`Km)-O|rMT-5pEO;Hct{_n*Xy~i z-YMR#*(_fDxq0?2vWo~9UH4AXY*Y1t5m~SPaNe(8{5i5*nyiD-4l%E36ffT?V&X&G zYXf5hu?)*dKi}?7IY^8(SH>#?3k%vUI}OBe74o>>U=HpwcQTRxtdl@@ZQG*WKT%~& zBnYDc`C&^rUlPA;TN1dmtIzY@6L+yY`K$f~OrpML?Hw6`XukKf@#2W>GTl^(bvj<3 zf_i_1Kbg6}T+Ox_M3{jxitO>QY;Hc3yO;k9hc7n_F zxo?Qs1DzYies1~-xhHDsxF0JVGiXy=1X?On-8AEcGpf=^f;?eJY&Jb%NNOi!_F6lo zLCa95l{CLpoN~2t_TB2uG~Zl}$U8=|uJW&C6pZ4vUQi23A`)Ofri435a9wy55;Sv2 zCzE&o-c~EW?3TMXQWrT*R~NJPC?se4VF4TtnqBG;3T~aR^8{C4xVvM0&$e_0H;3&P z=%FNuh)N_*D~Vwu0xeB$#mC~5p$p{uJ@p?s$`NG;DnigY&c(E%Ekg>qyA1rTV34h; zA;G1#!B<_c8e~zDSQ(BO~~4D3%@p@sp42T zbXIHtQeiP}loYUcmmD4_KHtc-YYe`q8V2Bsz`884n%8>rk&E~iGjN3ito7;*Y(L(5 zCY(qKoYtPm^Is27QWG=R#(Bw?&>R_F!2xW=7hc5Yi4CAuahCN zzZ!~qUX-S8fI@Zir^j{SaJ*fg zmu-_>9S?BYeZS!FMHkJBm-Jtm(mDuD|C;d-jr3XHckpW;^F{hdKjx4=MmXQys9{=h zQu~7NBvj;D0e@M~Cu$?1;Xu793lNV1-3a(;+k}5CcZOkBO*BX$tq zetF3C?vfG^X`{+OXPbD*^WQonJlgSJ*Sf<=o1r##vG?Q7$+!bM#=Vz4Wqamurk zdO*LtYQGkQw=|5jGc3+tg_I$CJXGt8?;&ly9r-F0v3D7(F&&6~Un2Ktsb|{RTm&X= z=tYReaA_n725qTplT+wRw@xkWIiGXy%40X-B6D-lj?8dB%A1&?D0!ZhsI0gUp2gTh z<^1F4QbWG?lbw6gi?#<^6Y=y@TOxV?XazNycB|*f_bt30fO+lSRMc9Be zshLxBu4HyPO$8bPW%~Tn8`6Hvr;vo`dcL? zG&g&DP#QCYxxaxRu8?xcUqxm+Y-H%n$;~Ps*!UrNk5UYi95*+*bk$*S2FADVQ+jcf zP@#}eR*(Sa(9Q2FV7%IY7DVUTQoS@ zJ!6I}l$&OnDWY#XcllKkr9ZhcqMLCr?wJd(&1FiN?O}=s0e-nZ8tj1b@P3Z=z$@jZaed{-)EhG+jc8R%r`vruTd@4++(zmAjk7mSY*~X4Yvg zLO|)Mc(vTuG8Li2^28W&PRT;(49C6eDLDP6mZWsCC~I--&;qkU<>$?!!i?%aNsasb zMuCx#i!<`isl}K%eU6JY#0mNc({M9eo+L2MI!u4S%wT$S`tZ8biBJf%KgLyK9W&@& z8FJ}^4}Mm5+Bc{m0m{l1+FNPTVsmK=;vuP9H;0`%F4I}i6U1}e*2v?%QRbZvoUD2W z3(zwW8J#G!pjlaE(8`(h3P^%ndSvk}&V-JhS4soIU`w9(FL=fgWAwe_q5$O?qYSk*uhuGg?(1 zGvg*dH|eE7jMZqZ5iv2+ksi6dGxe-dlp*<1%RqpTsOVoP5+zf+l7kbD(_Kh)SMAZB z*K>V>>ZL}qO}1g}(i!r{d?J2xdMvyOH*7F2u;ZV?o}J$Jfsqg08%c8+S^cjKmN3R1 z0_+#hc`P3hVTBH9iltq2XX-SdQQj_Y`p{YO_87Ox zbR|J0E43f3DQNGZjMmaB&YZ4@#b zE%z@QZ)&Ieh}_;(zuvmJP*5T>L&w=kL#gZpOFG=av&h43g9P~fpYeI?zgD4Zs^I=q zLXx}v;h)Sage@G?)cKOcmuvA^soN{zl7t| literal 0 HcmV?d00001 diff --git a/Templates/BaseGame/game/tools/assetBrowser/assetImportConfigs.xml b/Templates/BaseGame/game/tools/assetBrowser/assetImportConfigs.xml index a442ab0a83..72050b04f7 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/assetImportConfigs.xml +++ b/Templates/BaseGame/game/tools/assetBrowser/assetImportConfigs.xml @@ -1,18 +1,34 @@ - + - + - + + + + + + + + + + + + + + + + + diff --git a/Templates/BaseGame/game/tools/assetBrowser/guis/assetBrowser.gui b/Templates/BaseGame/game/tools/assetBrowser/guis/assetBrowser.gui index fd06f75617..48f049782e 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/guis/assetBrowser.gui +++ b/Templates/BaseGame/game/tools/assetBrowser/guis/assetBrowser.gui @@ -13,15 +13,15 @@ isContainer = "1"; canSave = "1"; canSaveDynamicFields = "1"; - AddNewArtAssetPopup = "18801"; - AddNewAssetPopup = "18802"; - AddNewScriptAssetPopup = "18800"; + AddNewArtAssetPopup = "18222"; + AddNewAssetPopup = "18223"; + AddNewScriptAssetPopup = "18221"; + coreModulesFilter = "0"; currentPreviewPage = "0"; enabled = "1"; - importAssetFinalListArray = "20465"; - importAssetNewListArray = "20463"; - importAssetUnprocessedListArray = "20464"; + isReImportingAsset = "0"; totalPages = "1"; + treeFilterMode = "list"; new GuiWindowCtrl(AssetBrowser_addFilterWindow) { text = "Create New Tag"; @@ -400,33 +400,7 @@ canSaveDynamicFields = "0"; }; new GuiBitmapButtonCtrl() { - bitmap = "tools/gui/images/iconNew.png"; - bitmapMode = "Stretched"; - autoFitExtents = "0"; - useModifiers = "0"; - useStates = "1"; - masked = "0"; - groupNum = "-1"; - buttonType = "PushButton"; - useMouseEvents = "0"; - position = "113 1"; - extent = "15 15"; - minExtent = "8 2"; - horizSizing = "right"; - vertSizing = "bottom"; - profile = "GuiDefaultProfile"; - visible = "1"; - active = "1"; - command = "AssetBrowser.viewTagsFilter();"; - tooltipProfile = "GuiToolTipProfile"; - tooltip = "Show assets grouped and filtered via tags."; - hovertime = "1000"; - isContainer = "0"; - canSave = "1"; - canSaveDynamicFields = "0"; - }; - new GuiBitmapButtonCtrl() { - bitmap = "tools/gui/images/iconList.png"; + bitmap = "tools/gui/images/visible"; bitmapMode = "Stretched"; autoFitExtents = "0"; useModifiers = "0"; @@ -435,15 +409,15 @@ groupNum = "-1"; buttonType = "PushButton"; useMouseEvents = "0"; - position = "130 1"; - extent = "15 15"; + position = "128 -1"; + extent = "18 19"; minExtent = "8 2"; horizSizing = "right"; vertSizing = "bottom"; profile = "GuiDefaultProfile"; visible = "1"; active = "1"; - command = "AssetBrowser.viewListFilter();"; + command = "AssetBrowser.showFilterPopup();"; tooltipProfile = "GuiToolTipProfile"; tooltip = "Views assets via module-oriented list tree."; hovertime = "1000"; @@ -526,7 +500,7 @@ canRenameObjects = "1"; renameInternal = "0"; position = "1 1"; - extent = "145 294"; + extent = "145 252"; minExtent = "8 2"; horizSizing = "right"; vertSizing = "bottom"; @@ -897,13 +871,14 @@ horizSizing = "left"; vertSizing = "top"; profile = "ToolsGuiButtonProfile"; - visible = "1"; + visible = "0"; active = "1"; command = "AssetBrowser.selectAsset( AssetBrowser.selectedAsset );"; tooltipProfile = "GuiToolTipProfile"; hovertime = "1000"; isContainer = "0"; internalName = "SelectButton"; + hidden = "1"; canSave = "1"; canSaveDynamicFields = "0"; }; diff --git a/Templates/BaseGame/game/tools/assetBrowser/guis/assetImport.gui b/Templates/BaseGame/game/tools/assetBrowser/guis/assetImport.gui index 199ad91b89..f337c946f9 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/guis/assetImport.gui +++ b/Templates/BaseGame/game/tools/assetBrowser/guis/assetImport.gui @@ -30,7 +30,7 @@ anchorBottom = "0"; anchorLeft = "1"; anchorRight = "0"; - position = "633 358"; + position = "339 179"; extent = "346 409"; minExtent = "48 92"; horizSizing = "center"; @@ -138,7 +138,7 @@ anchorBottom = "0"; anchorLeft = "1"; anchorRight = "0"; - position = "562 251"; + position = "324 132"; extent = "376 503"; minExtent = "48 92"; horizSizing = "center"; @@ -296,8 +296,8 @@ anchorBottom = "0"; anchorLeft = "1"; anchorRight = "0"; - position = "536 205"; - extent = "368 502"; + position = "140 98"; + extent = "733 502"; minExtent = "48 92"; horizSizing = "center"; vertSizing = "center"; @@ -315,7 +315,7 @@ groupNum = "-1"; buttonType = "PushButton"; useMouseEvents = "0"; - position = "224 470"; + position = "589 470"; extent = "64 22"; minExtent = "8 2"; horizSizing = "left"; @@ -335,7 +335,7 @@ groupNum = "-1"; buttonType = "PushButton"; useMouseEvents = "0"; - position = "292 470"; + position = "657 470"; extent = "64 22"; minExtent = "8 2"; horizSizing = "left"; @@ -343,7 +343,7 @@ profile = "ToolsGuiButtonProfile"; visible = "1"; active = "1"; - command = "Canvas.popDialog();"; + command = "ImportAssetWindow.close();"; tooltipProfile = "ToolsGuiToolTipProfile"; hovertime = "1000"; isContainer = "0"; @@ -364,7 +364,7 @@ minExtent = "8 2"; horizSizing = "right"; vertSizing = "bottom"; - profile = "GuiTextProfile"; + profile = "GuiDefaultProfile"; visible = "1"; active = "1"; tooltipProfile = "GuiToolTipProfile"; @@ -387,7 +387,7 @@ anchorLeft = "1"; anchorRight = "0"; position = "134 27"; - extent = "204 22"; + extent = "569 22"; minExtent = "8 2"; horizSizing = "width"; vertSizing = "bottom"; @@ -410,7 +410,7 @@ groupNum = "-1"; buttonType = "PushButton"; useMouseEvents = "0"; - position = "342 27"; + position = "707 27"; extent = "22 22"; minExtent = "8 2"; horizSizing = "left"; @@ -463,7 +463,7 @@ anchorLeft = "1"; anchorRight = "0"; position = "126 53"; - extent = "175 22"; + extent = "540 22"; minExtent = "8 2"; horizSizing = "width"; vertSizing = "bottom"; @@ -486,7 +486,7 @@ groupNum = "-1"; buttonType = "PushButton"; useMouseEvents = "0"; - position = "305 53"; + position = "670 53"; extent = "15 22"; minExtent = "8 2"; horizSizing = "left"; @@ -512,7 +512,7 @@ groupNum = "-1"; buttonType = "PushButton"; useMouseEvents = "0"; - position = "325 53"; + position = "690 53"; extent = "15 22"; minExtent = "8 2"; horizSizing = "left"; @@ -538,7 +538,7 @@ groupNum = "-1"; buttonType = "PushButton"; useMouseEvents = "0"; - position = "346 53"; + position = "711 53"; extent = "15 22"; minExtent = "8 2"; horizSizing = "left"; @@ -570,7 +570,7 @@ anchorLeft = "1"; anchorRight = "0"; position = "9 82"; - extent = "348 381"; + extent = "713 381"; minExtent = "8 2"; horizSizing = "width"; vertSizing = "height"; @@ -594,7 +594,7 @@ changeChildSizeToFit = "0"; changeChildPosition = "1"; position = "1 1"; - extent = "345 20"; + extent = "710 20"; minExtent = "16 16"; horizSizing = "width"; vertSizing = "bottom"; diff --git a/Templates/BaseGame/game/tools/assetBrowser/guis/selectModule.gui b/Templates/BaseGame/game/tools/assetBrowser/guis/selectModule.gui index a1c4293ab0..7ee77dbc0e 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/guis/selectModule.gui +++ b/Templates/BaseGame/game/tools/assetBrowser/guis/selectModule.gui @@ -112,7 +112,7 @@ profile = "ToolsGuiButtonProfile"; visible = "1"; active = "1"; - command = "Canvas.popDialog(AssetBrowser_SelectModule);"; + command = "AssetBrowser_SelectModule.moduleSelected();"; tooltipProfile = "ToolsGuiToolTipProfile"; hovertime = "1000"; isContainer = "0"; diff --git a/Templates/BaseGame/game/tools/assetBrowser/main.cs b/Templates/BaseGame/game/tools/assetBrowser/main.cs index 32ae4682fb..c5272e44ad 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/main.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/main.cs @@ -38,6 +38,7 @@ function initializeAssetBrowser() exec("./guis/assetImport.gui"); exec("./guis/selectModule.gui"); exec("./guis/editModule.gui"); + exec("./guis/importTemplateModules.gui"); exec("./scripts/assetBrowser.cs"); exec("./scripts/popupMenus.cs"); @@ -48,7 +49,23 @@ function initializeAssetBrowser() exec("./scripts/newAsset.cs"); exec("./scripts/editAsset.cs"); exec("./scripts/editModule.cs"); + exec("./scripts/selectModule.cs"); + //Processing for the different asset types + exec("./scripts/assetTypes/component.cs"); + exec("./scripts/assetTypes/cpp.cs"); + exec("./scripts/assetTypes/gameObject.cs"); + exec("./scripts/assetTypes/gui.cs"); + exec("./scripts/assetTypes/image.cs"); + exec("./scripts/assetTypes/level.cs"); + exec("./scripts/assetTypes/material.cs"); + exec("./scripts/assetTypes/postFX.cs"); + exec("./scripts/assetTypes/script.cs"); + exec("./scripts/assetTypes/shape.cs"); + exec("./scripts/assetTypes/shapeAnimation.cs"); + exec("./scripts/assetTypes/sound.cs"); + exec("./scripts/assetTypes/stateMachine.cs"); + exec("./scripts/fieldTypes.cs"); new ScriptObject( AssetBrowserPlugin ) diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/addModuleWindow.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/addModuleWindow.cs index 784ed7d639..036b3bee6f 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/addModuleWindow.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/addModuleWindow.cs @@ -57,6 +57,18 @@ Extension = "asset.taml"; Recurse = true; }; + + //Autoload the usual suspects + new AutoloadAssets() + { + AssetType = "ComponentAsset"; + Recurse = true; + }; + new AutoloadAssets() + { + AssetType = "GUIAsset"; + Recurse = true; + }; }; TAMLWrite(%newModule, %moduleDefinitionFilePath); diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.cs index 0979f219e1..fd6f852783 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetBrowser.cs @@ -1,4 +1,3 @@ - new SimGroup(AssetBrowserPreviewCache); //AssetBrowser.addToolbarButton @@ -34,14 +33,84 @@ // function AssetBrowser::onAdd(%this) { - %this.isReImportingAsset = false; } function AssetBrowser::onWake(%this) { - %this.importAssetNewListArray = new ArrayObject(); + // manage preview array + if(!isObject(AssetPreviewArray)) + new ArrayObject(AssetPreviewArray); + + if(!isObject(ImportAssetTree)) + new GuiTreeViewCtrl(ImportAssetTree); + + %this.importingFilesArray = new ArrayObject(); %this.importAssetUnprocessedListArray = new ArrayObject(); %this.importAssetFinalListArray = new ArrayObject(); + + %this.isReImportingAsset = false; + %this.coreModulesFilter = false; + %this.onlyShowModulesWithAssets = false; + %this.treeFilterMode = "list"; + + //First, build our our list of active modules + %modulesList = ModuleDatabase.findModules(true); + + %nonDefaultModuleCount = 0; + + for(%i=0; %i < getWordCount(%modulesList); %i++) + { + %moduleName = getWord(%modulesList, %i).ModuleId; + + %moduleGroup = getWord(%modulesList, %i).Group; + if((%moduleGroup $= "Core" || %moduleGroup $= "Tools") && !%this.coreModulesFilter) + continue; + + %nonDefaultModuleCount++; + } + + if(%nonDefaultModuleCount == 0) + { + MessageBoxYesNo( "Import Template Content?", + "You have no modules or content. Do you want to import a module from the template content?", + "AssetBrowser.ImportTemplateModules();", "" ); + } +} + +//Filters +function AssetBrowser::showFilterPopup(%this) +{ + BrowserVisibilityPopup.showPopup(Canvas); +} + +function AssetBrowser::viewCoreModulesFilter(%this) +{ + %this.coreModulesFilter = !%this.coreModulesFilter; + + BrowserVisibilityPopup.checkItem(0,%this.coreModulesFilter); + + AssetBrowser.loadFilters(); +} + +function AssetBrowser::viewPopulatedModulesFilter(%this) +{ + %this.onlyShowModulesWithAssets = !%this.onlyShowModulesWithAssets; + + BrowserVisibilityPopup.checkItem(1,%this.onlyShowModulesWithAssets); + + AssetBrowser.loadFilters(); +} + +function AssetBrowser::viewListFilter(%this) +{ + %this.treeFilterMode = "list"; + AssetBrowser.loadFilters(); +} + +function AssetBrowser::viewTagsFilter(%this) +{ + %this.treeFilterMode = "tags"; + AssetBrowser.loadFilters(); } //Drag-Drop functionality @@ -113,6 +182,11 @@ function AssetBrowser::buildPreviewArray( %this, %asset, %moduleName ) { + if(!isObject(%this.previewData)) + { + %this.previewData = new ScriptObject(); + } + %assetDesc = AssetDatabase.acquireAsset(%asset); %assetName = AssetDatabase.getAssetName(%asset); %previewImage = "core/art/warnmat"; @@ -142,8 +216,20 @@ %tooltip = %assetName; + %doubleClickCommand = "AssetBrowser.editAsset( "@%assetDesc@" );"; + if(%assetType $= "ShapeAsset") { + %this.previewData.assetName = %assetDesc.assetName; + %this.previewData.assetPath = %assetDesc.scriptFile; + %this.previewData.doubleClickCommand = %doubleClickCommand; + + %this.previewData.previewImage = "tools/assetBrowser/art/componentIcon"; + + %this.previewData.assetFriendlyName = %assetDesc.friendlyName; + %this.previewData.assetDesc = %assetDesc.description; + %this.previewData.tooltip = %assetDesc.friendlyName @ "\n" @ %assetDesc; + %previewButton = new GuiObjectView() { className = "AssetPreviewControl"; @@ -218,111 +304,21 @@ } else { - if(%assetType $= "ComponentAsset") - { - %assetPath = "data/" @ %moduleName @ "/components/" @ %assetName @ ".cs"; - %doubleClickCommand = "EditorOpenFileInTorsion( "@%assetPath@", 0 );"; - - %previewImage = "tools/assetBrowser/art/componentIcon"; - - %assetFriendlyName = %assetDesc.friendlyName; - %assetDesc = %assetDesc.description; - %tooltip = %assetFriendlyName @ "\n" @ %assetDesc; - } - else if(%assetType $= "GameObjectAsset") - { - %assetPath = "data/" @ %moduleName @ "/gameObjects/" @ %assetName @ ".cs"; - %doubleClickCommand = "EditorOpenFileInTorsion( "@%assetPath@", 0 );"; - - %previewImage = "tools/assetBrowser/art/gameObjectIcon"; - - %tooltip = %assetDesc.gameObjectName; - } - else if(%assetType $= "ImageAsset") - { - //nab the image and use it for the preview - %assetQuery = new AssetQuery(); - %numAssetsFound = AssetDatabase.findAllAssets(%assetQuery); - - for( %i=0; %i < %numAssetsFound; %i++) - { - %assetId = %assetQuery.getAsset(%i); - %name = AssetDatabase.getAssetName(%assetId); - - if(%name $= %assetName) - { - %asset = AssetDatabase.acquireAsset(%assetId); - %previewImage = %asset.imageFile; - break; - } - } - } - else if(%assetType $= "StateMachineAsset") - { - %previewImage = "tools/assetBrowser/art/stateMachineIcon"; - } - else if(%assetType $= "SoundAsset") - { - %previewImage = "tools/assetBrowser/art/soundIcon"; - } - else if(%assetType $= "LevelAsset") - { - %previewImage = "tools/assetBrowser/art/levelIcon"; - } - else if(%assetType $= "PostEffectAsset") - { - %previewImage = "tools/assetBrowser/art/postEffectIcon"; - } - else if(%assetType $= "GUIAsset") - { - %previewImage = "tools/assetBrowser/art/guiIcon"; - } - else if(%assetType $= "ScriptAsset") - { - if(%assetDesc.isServerSide) - %previewImage = "tools/assetBrowser/art/serverScriptIcon"; - else - %previewImage = "tools/assetBrowser/art/clientScriptIcon"; - } - else if(%assetType $= "MaterialAsset") - { - %previewImage = ""; - //nab the image and use it for the preview - %assetQuery = new AssetQuery(); - %numAssetsFound = AssetDatabase.findAllAssets(%assetQuery); - - for( %i=0; %i < %numAssetsFound; %i++) - { - %assetId = %assetQuery.getAsset(%i); - %name = AssetDatabase.getAssetName(%assetId); - - if(%name $= %assetName) - { - %asset = AssetDatabase.acquireAsset(%assetId); - %previewImage = %asset.materialDefinitionName.diffuseMap[0]; - break; - } - } - - if(%previewImage $= "") - %previewImage = "tools/assetBrowser/art/materialIcon"; - } - if(%assetType $= "ShapeAnimationAsset") - { - %previewImage = "tools/assetBrowser/art/animationIcon"; - } + //Build out the preview + %buildCommand = %this @ ".build" @ %assetType @ "Preview(" @ %assetDesc @ "," @ %this.previewData @ ");"; + eval(%buildCommand); %previewButton = new GuiBitmapButtonCtrl() { className = "AssetPreviewControl"; - internalName = %assetName; + internalName = %this.previewData.assetName; HorizSizing = "right"; VertSizing = "bottom"; profile = "ToolsGuiButtonProfile"; position = "10 4"; extent = %previewSize; buttonType = "PushButton"; - bitmap = %previewImage; + bitmap = %this.previewData.previewImage; Command = ""; text = ""; useStates = false; @@ -345,7 +341,7 @@ %previewBorder = new GuiButtonCtrl(){ class = "AssetPreviewButton"; - internalName = %assetName@"Border"; + internalName = %this.previewData.assetName@"Border"; HorizSizing = "right"; VertSizing = "bottom"; profile = "ToolsGuiThumbHighlightButtonProfile"; @@ -353,21 +349,21 @@ class = "AssetPreviewButton"; extent = %previewSize.x + %previewBounds SPC %previewSize.y + 24; Variable = ""; buttonType = "radioButton"; - tooltip = %tooltip; + tooltip = %this.previewData.tooltip; Command = "AssetBrowser.updateSelection( $ThisControl.getParent().assetName, $ThisControl.getParent().moduleName );"; - altCommand = %doubleClickCommand; + altCommand = %this.previewData.doubleClickCommand; groupNum = "0"; useMouseEvents = true; text = ""; - icon = %previewImage; + icon = %this.previewData.previewImage; }; %previewNameCtrl = new GuiTextEditCtrl(){ position = 0 SPC %previewSize.y + %previewBounds - 16; profile = ToolsGuiTextEditCenterProfile; extent = %previewSize.x + %previewBounds SPC 16; - text = %assetName; - originalAssetName = %assetName; //special internal field used in renaming assets + text = %this.previewData.assetName; + originalAssetName = %this.previewData.assetName; //special internal field used in renaming assets internalName = "AssetNameLabel"; class = "AssetNameField"; active = false; @@ -381,32 +377,7 @@ class = "AssetNameField"; AssetBrowser-->materialSelection.add(%container); // add to the array object for reference later - AssetPreviewArray.add( %previewButton, %previewImage ); -} - -function AssetBrowser::loadImages( %this, %materialNum ) -{ - // this will save us from spinning our wheels in case we don't exist - /*if( !AssetBrowser.visible ) - return; - - // this schedule is here to dynamically load images - %previewButton = AssetPreviewArray.getKey(%materialNum); - %previewImage = AssetPreviewArray.getValue(%materialNum); - - if(%previewButton.getClassName() !$= "GuiObjectView") - { - %previewButton.setBitmap(%previewImage); - %previewButton.setText(""); - } - - %materialNum++; - - /*if( %materialNum < AssetPreviewArray.count() ) - { - %tempSchedule = %this.schedule(64, "loadImages", %materialNum); - MatEdScheduleArray.add( %tempSchedule, %materialNum ); - }*/ + AssetPreviewArray.add( %previewButton, %this.previewData.previewImage ); } function AssetBrowser::loadFilters( %this ) @@ -417,62 +388,91 @@ class = "AssetNameField"; AssetBrowser-->filterTree.insertItem(0, "Assets"); - //First, build our our list of active modules - %modulesList = ModuleDatabase.findModules(true); + AssetPreviewArray.empty(); - for(%i=0; %i < getWordCount(%modulesList); %i++) + if(%this.treeFilterMode $= "list") { - %moduleName = getWord(%modulesList, %i).ModuleId; + //First, build our our list of active modules + %modulesList = ModuleDatabase.findModules(true); - %moduleItemId = AssetBrowser-->filterTree.findItemByName(%moduleName); - - if(%moduleItemId == 0) - %moduleItemId = AssetBrowser-->filterTree.insertItem(1, %moduleName, "", "", 1, 1); - } + for(%i=0; %i < getWordCount(%modulesList); %i++) + { + %moduleName = getWord(%modulesList, %i).ModuleId; + + %moduleGroup = getWord(%modulesList, %i).Group; + if((%moduleGroup $= "Core" || %moduleGroup $= "Tools") && !%this.coreModulesFilter) + continue; + + %moduleItemId = AssetBrowser-->filterTree.findItemByName(%moduleName); + + if(%moduleItemId == 0) + %moduleItemId = AssetBrowser-->filterTree.insertItem(1, %moduleName, "", "", 1, 1); + } - //Next, go through and list the asset categories - %assetQuery = new AssetQuery(); - %numAssetsFound = AssetDatabase.findAllAssets(%assetQuery); - - for( %i=0; %i < %numAssetsFound; %i++) + //Next, go through and list the asset categories + %assetQuery = new AssetQuery(); + %numAssetsFound = AssetDatabase.findAllAssets(%assetQuery); + + for( %i=0; %i < %numAssetsFound; %i++) + { + %assetId = %assetQuery.getAsset(%i); + + //first, get the asset's module, as our major categories + %module = AssetDatabase.getAssetModule(%assetId); + + %moduleName = %module.moduleId; + + %moduleGroup = %module.Group; + if((%moduleGroup $= "Core" || %moduleGroup $= "Tools") && !%this.coreModulesFilter) + continue; + + //first, see if this module Module is listed already + %moduleItemId = AssetBrowser-->filterTree.findItemByName(%moduleName); + + if(%moduleItemId == 0) + %moduleItemId = AssetBrowser-->filterTree.insertItem(1, %moduleName, "", "", 1, 1); + + %assetType = AssetDatabase.getAssetCategory(%assetId); + + if(%assetType $= "") + { + %assetType = AssetDatabase.getAssetType(%assetId); + if(%assetType $= "") + %assetType = "Misc"; + } + + if(AssetBrowser.assetTypeFilter !$= "" && AssetBrowser.assetTypeFilter !$= %assetType) + continue; + + %assetTypeId = AssetBrowser-->filterTree.findChildItemByName(%moduleItemId, %assetType); + + if(%assetTypeId == 0) + %assetTypeId = AssetBrowser-->filterTree.insertItem(%moduleItemId, %assetType); + } + + AssetBrowser-->filterTree.buildVisibleTree(true); + } + else if(%this.treeFilterMode $= "tags") { - %assetId = %assetQuery.getAsset(%i); - - //first, get the asset's module, as our major categories - %module = AssetDatabase.getAssetModule(%assetId); - - %moduleName = %module.moduleId; - - //These are core, native-level components, so we're not going to be messing with this module at all, skip it - if(%moduleName $= "CoreComponentsModule") - continue; - - //first, see if this module Module is listed already - %moduleItemId = AssetBrowser-->filterTree.findItemByName(%moduleName); - - if(%moduleItemId == 0) - %moduleItemId = AssetBrowser-->filterTree.insertItem(1, %moduleName, "", "", 1, 1); - - %assetType = AssetDatabase.getAssetCategory(%assetId); - - if(%assetType $= "") - { - %assetType = AssetDatabase.getAssetType(%assetId); - if(%assetType $= "") - %assetType = "Misc"; - } - - if(AssetBrowser.assetTypeFilter !$= "" && AssetBrowser.assetTypeFilter !$= %assetType) - continue; - - %assetTypeId = AssetBrowser-->filterTree.findChildItemByName(%moduleItemId, %assetType); - - if(%assetTypeId == 0) - %assetTypeId = AssetBrowser-->filterTree.insertItem(%moduleItemId, %assetType); + } - - AssetBrowser-->filterTree.buildVisibleTree(true); + %this.collapseTree(); + + //Remove any modules that have no assets if we have that filter on + if(%this.onlyShowModulesWithAssets) + { + for(%i=0; %i < getWordCount(%modulesList); %i++) + { + %moduleName = getWord(%modulesList, %i).ModuleId; + + %moduleItemId = AssetBrowser-->filterTree.findItemByName(%moduleName); + + if(AssetBrowser-->filterTree.isParentItem(%moduleItemId) == false) + AssetBrowser-->filterTree.removeItem(%moduleItemId); + } + } + //special handling for selections if(AssetBrowser.newModuleId !$= "") { @@ -484,6 +484,8 @@ class = "AssetNameField"; %selectedItem = AssetBrowser-->filterTree.getSelectedItem(); AssetBrowser-->filterTree.scrollVisibleByObjectId(%selectedItem); + + AssetBrowser-->filterTree.buildVisibleTree(); } // create category and update current material if there is one @@ -563,6 +565,26 @@ class = "AssetNameField"; %this.prevSelectedMaterialHL = %asset; } +function AssetBrowser::collapseTree(%this) +{ + %modulesList = ModuleDatabase.findModules(true); + + for(%i=0; %i < getWordCount(%modulesList); %i++) + { + %moduleName = getWord(%modulesList, %i).ModuleId; + + %moduleGroup = getWord(%modulesList, %i).Group; + if((%moduleGroup $= "Core" || %moduleGroup $= "Tools") && !%this.coreModulesFilter) + continue; + + %moduleItemId = AssetBrowser-->filterTree.findItemByName(%moduleName); + + AssetBrowser-->filterTree.expandItem(%moduleItemId, false); + } + + AssetBrowser-->filterTree.expandItem(1, true); +} + // //needs to be deleted with the persistence manager and needs to be blanked out of the matmanager //also need to update instances... i guess which is the tricky part.... @@ -709,6 +731,9 @@ class = "AssetNameField"; %cmd = %this.fieldTargetObject @ "." @ %this.fieldTargetName @ "=\"" @ %this.selectedAsset @ "\";"; echo("Changing asset via the " @ %cmd @ " command"); eval(%cmd); + + //Flag us as dirty for editing purposes + EWorldEditor.setSceneAsDirty(); } function AssetBrowser::reImportAsset(%this) @@ -722,8 +747,34 @@ class = "AssetNameField"; AssetBrowser.isAssetReImport = true; AssetBrowser.reImportingAssetId = EditAssetPopup.assetId; + %reimportingPath = %assetDef.originalFilePath; + + //first, double-check we have an originating file. if we don't then we need to basically go out looking for it + if(!isFile(%assetDef.originalFilePath)) + { + //if(%assetType $= "ImageAsset") + // %filters = ""; + + %dlg = new OpenFileDialog() + { + Filters = "(All Files (*.*)|*.*|"; + DefaultFile = %currentFile; + ChangePath = false; + MustExist = true; + MultipleFiles = false; + forceRelativePath = false; + }; + + if ( %dlg.Execute() ) + { + %reimportingPath = %dlg.FileName; + } + + %dlg.delete(); + } + AssetBrowser.onBeginDropFiles(); - AssetBrowser.onDropFile(%assetDef.originalFilePath); + AssetBrowser.onDropFile(%reimportingPath); AssetBrowser.onEndDropFiles(); %module = AssetDatabase.getAssetModule(EditAssetPopup.assetId); @@ -745,7 +796,7 @@ class = "AssetNameField"; EditAssetPopup.enableItem(7, true); //Is it an editable type? - if(%assetType $= "ImageAsset" || %assetType $= "GameObjectAsset" || %assetType $= "SoundAsset") + if(%assetType $= "ImageAsset" /*|| %assetType $= "GameObjectAsset"*/ || %assetType $= "CppAsset" || %assetType $= "SoundAsset") { EditAssetPopup.enableItem(0, false); } @@ -758,7 +809,10 @@ class = "AssetNameField"; EditAssetPopup.enableItem(7, false); } - EditAssetPopup.showPopup(Canvas); + if(%assetType $= "LevelAsset") + EditLevelAssetPopup.showPopup(Canvas); + else + EditAssetPopup.showPopup(Canvas); } function AssetListPanel::onRightMouseDown(%this) @@ -802,10 +856,6 @@ class = "AssetNameField"; // we have to empty out the list; so when we create new schedules, these dont linger MatEdScheduleArray.empty(); - - // manage preview array - if(!isObject(AssetPreviewArray)) - new ArrayObject(AssetPreviewArray); // we have to empty out the list; so when we create new guicontrols, these dont linger AssetPreviewArray.empty(); @@ -876,8 +926,6 @@ class = "AssetNameField"; for(%i=0; %i < %assetArray.count(); %i++) AssetBrowser.buildPreviewArray( %assetArray.getValue(%i), %assetArray.getKey(%i) ); - - AssetBrowser.loadImages( 0 ); } function AssetBrowserFilterTree::onRightMouseDown(%this, %itemId) @@ -909,9 +957,9 @@ class = "AssetNameField"; //Canvas.popDialog(AssetBrowser_newComponentAsset); //AssetBrowser_newComponentAsset-->AssetBrowserModuleList.setText(AssetBrowser.selectedModule); } - else + else if(%this.getItemText(%itemId) $= "ScriptAsset") { - + EditAssetCategoryPopup.showPopup(Canvas); } } } @@ -1131,45 +1179,35 @@ class = "AssetPreviewControlType_AssetDrop"; if(%assetType $= "ImageAsset") { - echo("DROPPED AN IMAGE ON THE EDITOR WINDOW!"); + echo("WorldEditor::onControlDropped - dropped an ImageAsset onto the editor window. Todo: Implement dropping image/material into scene"); } else if(%assetType $= "ShapeAsset") { echo("DROPPED A SHAPE ON THE EDITOR WINDOW!"); - %newEntity = new Entity() - { - position = %pos; - - new MeshComponent() - { - MeshAsset = %module @ ":" @ %asset; - }; - - //new CollisionComponent(){}; - }; + %staticShapeObjDef = AssetDatabase.acquireAsset("Core_GameObjects:StaticShapeObject"); + + %newEntity = %staticShapeObjDef.createObject(); - MissionGroup.add(%newEntity); + %newEntity.position = %pos; + %newEntity-->MeshComponent.MeshAsset = %module @ ":" @ %asset; + + getScene(0).add(%newEntity); EWorldEditor.clearSelection(); EWorldEditor.selectObject(%newEntity); } else if(%assetType $= "MaterialAsset") { - echo("DROPPED A MATERIAL ON THE EDITOR WINDOW!"); + echo("WorldEditor::onControlDropped - dropped an MaterialAsset onto the editor window. Todo: Implement dropping image/material into scene"); } else if(%assetType $= "GameObjectAsset") { - echo("DROPPED A GAME OBJECT ON THE EDITOR WINDOW!"); - - %GO = spawnGameObject(%asset, true); + echo("WorldEditor::onControlDropped - dropped an GameObjectAsset onto the editor window."); - %pos = EWCreatorWindow.getCreateObjectPosition(); //LocalClientConnection.camera.position; + %goAssetDef = AssetDatabase.acquireAsset(%module @ ":" @%asset); - %GO.position = %pos; - - EWorldEditor.clearSelection(); - EWorldEditor.selectObject(%GO); + AssetBrowser.dragAndDropGameObjectAsset(%goAssetDef, EWorldEditor); } else if(%assetType $= "ComponentAsset") { @@ -1185,7 +1223,7 @@ class = "AssetPreviewControlType_AssetDrop"; else eval("$tmpVar = new " @ %assetDef.componentClass @ "() {}; %newEntity.add($tmpVar);"); - MissionGroup.add(%newEntity); + getScene(0).add(%newEntity); EWorldEditor.clearSelection(); EWorldEditor.selectObject(%newEntity); @@ -1198,7 +1236,7 @@ class = "AssetPreviewControlType_AssetDrop"; class = %asset; }; - MissionGroup.add(%newEntity); + getScene(0).add(%newEntity); EWorldEditor.clearSelection(); EWorldEditor.selectObject(%newEntity); @@ -1207,68 +1245,6 @@ class = %asset; EWorldEditor.isDirty = true; } -function GuiInspectorTypeShapeAssetPtr::onControlDropped( %this, %payload, %position ) -{ - Canvas.popDialog(EditorDragAndDropLayer); - - // Make sure this is a color swatch drag operation. - if( !%payload.parentGroup.isInNamespaceHierarchy( "AssetPreviewControlType_AssetDrop" ) ) - return; - - %assetType = %payload.dragSourceControl.parentGroup.assetType; - - if(%assetType $= "ShapeAsset") - { - echo("DROPPED A SHAPE ON A SHAPE ASSET COMPONENT FIELD!"); - - %module = %payload.dragSourceControl.parentGroup.moduleName; - %asset = %payload.dragSourceControl.parentGroup.assetName; - - %targetComponent = %this.ComponentOwner; - %targetComponent.MeshAsset = %module @ ":" @ %asset; - - //Inspector.refresh(); - } - - EWorldEditor.isDirty= true; -} - -function GuiInspectorTypeImageAssetPtr::onControlDropped( %this, %payload, %position ) -{ - Canvas.popDialog(EditorDragAndDropLayer); - - // Make sure this is a color swatch drag operation. - if( !%payload.parentGroup.isInNamespaceHierarchy( "AssetPreviewControlType_AssetDrop" ) ) - return; - - %assetType = %payload.dragSourceControl.parentGroup.assetType; - - if(%assetType $= "ImageAsset") - { - echo("DROPPED A IMAGE ON AN IMAGE ASSET COMPONENT FIELD!"); - } - - EWorldEditor.isDirty = true; -} - -function GuiInspectorTypeMaterialAssetPtr::onControlDropped( %this, %payload, %position ) -{ - Canvas.popDialog(EditorDragAndDropLayer); - - // Make sure this is a color swatch drag operation. - if( !%payload.parentGroup.isInNamespaceHierarchy( "AssetPreviewControlType_AssetDrop" ) ) - return; - - %assetType = %payload.dragSourceControl.parentGroup.assetType; - - if(%assetType $= "MaterialAsset") - { - echo("DROPPED A MATERIAL ON A MATERIAL ASSET COMPONENT FIELD!"); - } - - EWorldEditor.isDirty = true; -} - function AssetBrowserFilterTree::onControlDropped( %this, %payload, %position ) { Canvas.popDialog(EditorDragAndDropLayer); diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImport.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImport.cs index 8732ac8a55..1d23574b9d 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImport.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImport.cs @@ -68,9 +68,11 @@ function findImageFile(%path, %materialName, %type) function AssetBrowser::onBeginDropFiles( %this ) { error("% DragDrop - Beginning files dropping."); - %this.importAssetNewListArray.empty(); %this.importAssetUnprocessedListArray.empty(); %this.importAssetFinalListArray.empty(); + + ImportAssetTree.clear(); + AssetBrowser.unprocessedAssetsCount = 0; } function AssetBrowser::onDropFile( %this, %filePath ) @@ -86,8 +88,18 @@ function findImageFile(%path, %materialName, %type) %this.addImportingAsset("Model", %filePath); else if( isSoundFormat(%fileExt)) %this.addImportingAsset("Sound", %filePath); + else if( %fileExt $= ".cs" || %fileExt $= ".cs.dso" ) + %this.addImportingAsset("Script", %filePath); + else if( %fileExt $= ".gui" || %fileExt $= ".gui.dso" ) + %this.addImportingAsset("GUI", %filePath); else if (%fileExt $= ".zip") %this.onDropZipFile(%filePath); + + //Used to keep tabs on what files we were trying to import, used mainly in the event of + //adjusting configs and needing to completely reprocess the import + //ensure we're not doubling-up on files by accident + if(%this.importingFilesArray.getIndexFromKey(%filePath) == -1) + %this.importingFilesArray.add(%filePath); } function AssetBrowser::onDropZipFile(%this, %filePath) @@ -276,10 +288,65 @@ function findImageFile(%path, %materialName, %type) // // -function AssetBrowser::addImportingAsset( %this, %assetType, %filePath, %parentAssetItem ) +function AssetBrowser::reloadImportingFiles(%this) +{ + //Effectively, we re-import the files we were trying to originally. We'd only usually do this in the event we change our import config + %this.onBeginDropFiles(); + + for(%i=0; %i < %this.importingFilesArray.count(); %i++) + { + %this.onDropFile(%this.importingFilesArray.getKey(%i)); + } + + %this.onEndDropFiles(); +} + +function AssetBrowser::ImportTemplateModules(%this) +{ + //AssetBrowser_ImportModule + Canvas.pushDialog(AssetBrowser_ImportModuleTemplate); + AssetBrowser_ImportModuleTemplateWindow.visible = true; + + AssetBrowser_ImportModuleTemplateList.clear(); + + //ModuleDatabase.scanModules("../../../../../../Templates/Modules/"); + + %pattern = "../../../../../../Templates/Modules//*//*.module"; + %file = findFirstFile( %pattern ); + + while( %file !$= "" ) + { + echo("FOUND A TEMPLATE MODULE! " @ %file); + %file = findNextFile( %pattern ); + } + + /*%moduleCheckbox = new GuiCheckBoxCtrl() + { + text = "Testadoo"; + moduleId = ""; + }; + + AssetBrowser_ImportModuleTemplateList.addRow("0", "Testaroooooo"); + AssetBrowser_ImportModuleTemplateList.addRow("1", "Testadoooooo");*/ +} + +function AssetBrowser_ImportModuleTemplateList::onSelect(%this, %selectedRowIdx, %text) { - %assetName = fileBase(%filePath); - %filePath = filePath(%filePath) @ "/" @ fileBase(%filePath) @ fileExt(%filePath); //sanitize the file path + echo("Selected row: " @ %selectedRowIdx @ " " @ %text); +} + +function AssetBrowser::addImportingAsset( %this, %assetType, %filePath, %parentAssetItem, %assetNameOverride ) +{ + //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 + if(%assetNameOverride !$= "") + %assetName = %assetNameOverride; + else + %assetName = fileBase(%filePath); + + //We don't get a file path at all if we're a generated entry, like materials + //if we have a file path, though, then sanitize it + if(%filePath !$= "") + %filePath = filePath(%filePath) @ "/" @ fileBase(%filePath) @ fileExt(%filePath); %moduleName = AssetBrowser.SelectedModule; ImportAssetModuleList.text = %moduleName; @@ -290,6 +357,7 @@ function findImageFile(%path, %materialName, %type) assetType = %assetType; filePath = %filePath; assetName = %assetName; + cleanAssetName = %assetName; moduleName = %moduleName; dirty = true; parentAssetItem = %parentAssetItem; @@ -297,8 +365,9 @@ function findImageFile(%path, %materialName, %type) statusType = ""; statusInfo = ""; skip = false; + processed = false; }; - + //little bit of interception here if(%assetItem.assetType $= "Model") { @@ -306,7 +375,7 @@ function findImageFile(%path, %materialName, %type) if(%fileExt $= ".dae") { %shapeInfo = new GuiTreeViewCtrl(); - enumColladaForImport(%assetItem.filePath, %shapeInfo); + enumColladaForImport(%assetItem.filePath, %shapeInfo, false); } else { @@ -340,26 +409,37 @@ function findImageFile(%path, %materialName, %type) if(%parentAssetItem $= "") { - %assetItem.parentDepth = 0; - %this.importAssetNewListArray.add(%assetItem); - %this.importAssetUnprocessedListArray.add(%assetItem); + ImportAssetTree.insertObject(0, %assetItem); + + //%assetItem.parentDepth = 0; + //%this.importAssetNewListArray.add(%assetItem); + //%this.importAssetUnprocessedListArray.add(%assetItem); } else { - %assetItem.parentDepth = %parentAssetItem.parentDepth + 1; - %parentIndex = %this.importAssetUnprocessedListArray.getIndexFromKey(%parentAssetItem); + %parentid = ImportAssetTree.findItemByObjectId(%parentAssetItem); + ImportAssetTree.insertObject(%parentid, %assetItem); - %parentAssetItem.dependencies = %parentAssetItem.dependencies SPC %assetItem; - trim(%parentAssetItem.dependencies); + //%assetItem.parentDepth = %parentAssetItem.parentDepth + 1; + //%parentIndex = %this.importAssetUnprocessedListArray.getIndexFromKey(%parentAssetItem); - %this.importAssetUnprocessedListArray.insert(%assetItem, "", %parentIndex + 1); + //%parentAssetItem.dependencies = %parentAssetItem.dependencies SPC %assetItem; + //trim(%parentAssetItem.dependencies); + + //%this.importAssetUnprocessedListArray.insert(%assetItem, "", %parentIndex + 1); } + %this.unprocessedAssetsCount++; + return %assetItem; } -// -function ImportAssetButton::onClick(%this) +function AssetBrowser::importLegacyGame(%this) +{ + +} + +function AssetBrowser::importNewAssetFile(%this) { %dlg = new OpenFileDialog() { @@ -368,6 +448,7 @@ function findImageFile(%path, %materialName, %type) DefaultFile = ""; ChangePath = false; OverwritePrompt = true; + forceRelativePath = false; //MultipleFiles = true; }; @@ -376,7 +457,7 @@ function findImageFile(%path, %materialName, %type) if ( %ret ) { $Pref::WorldEditor::LastPath = filePath( %dlg.FileName ); - %fullPath = makeRelativePath( %dlg.FileName, getMainDotCSDir() ); + %fullPath = %dlg.FileName; %file = fileBase( %fullPath ); } @@ -385,22 +466,15 @@ function findImageFile(%path, %materialName, %type) if ( !%ret ) return; - AssetBrowser.importAssetListArray.empty(); - - %fileExt = fileExt( %fullPath ); - //add it to our array! - if( (%fileExt $= ".png") || (%fileExt $= ".jpg") || (%fileExt $= ".bmp") || (%fileExt $= ".dds") ) - AssetBrowser.importAssetListArray.add("Image", %fullPath); - else if( (%fileExt $= ".dae") || (%fileExt $= ".dts")) - AssetBrowser.importAssetListArray.add("Model", %fullPath); - else if( (%fileExt $= ".ogg") || (%fileExt $= ".wav") || (%fileExt $= ".mp3")) - AssetBrowser.importAssetListArray.add("Sound", %fullPath); - else if (%fileExt $= ".zip") - AssetBrowser.onDropZipFile(%fullPath); - - ImportAssetConfigWindow.visible = true; - ImportAssetConfigWindow.refresh(); - ImportAssetConfigWindow.selectWindow(); + AssetBrowser.onBeginDropFiles(); + AssetBrowser.onDropFile(%fullPath); + AssetBrowser.onEndDropFiles(); +} + +// +function ImportAssetButton::onClick(%this) +{ + ImportAssetsPopup.showPopup(Canvas); } // @@ -455,6 +529,7 @@ function findImageFile(%path, %materialName, %type) %xmlDoc.pushFirstChildElement("Materials"); %configObj.ImportMaterials = %xmlDoc.attribute("ImportMaterials"); + %configObj.IgnoreMaterials = %xmlDoc.attribute("IgnoreMaterials"); %configObj.CreateComposites = %xmlDoc.attribute("CreateComposites"); %configObj.UseDiffuseSuffixOnOriginImg = %xmlDoc.attribute("UseDiffuseSuffixOnOriginImg"); %configObj.UseExistingMaterials = %xmlDoc.attribute("UseExistingMaterials"); @@ -515,13 +590,21 @@ function findImageFile(%path, %materialName, %type) ImportAssetConfigList.add(%configObj.Name); } - ImportAssetConfigList.setSelected(0); + %importConfigIdx = ImportAssetWindow.activeImportConfigIndex; + if(%importConfigIdx $= "") + %importConfigIdx = 0; + + ImportAssetConfigList.setSelected(%importConfigIdx); } function ImportAssetWindow::setImportOptions(%this, %optionsObj) { //Todo, editor + load from files for preconfigs + //General + %optionsObj.treatWarningsAsErrors = false; + %optionsObj.ignoreDuplicateAssets = false; + //Meshes %optionsObj.ImportMesh = true; %optionsObj.UpAxisOverride = "Z_AXIS"; @@ -577,93 +660,79 @@ function findImageFile(%path, %materialName, %type) } // -function ImportAssetWindow::processNewImportAssets(%this) +function ImportAssetWindow::processNewImportAssets(%this, %id) { - %unprocessedCount = AssetBrowser.importAssetUnprocessedListArray.count(); - while(AssetBrowser.importAssetUnprocessedListArray.count() > 0) + while(%id > 0) { - %assetItem = AssetBrowser.importAssetUnprocessedListArray.getKey(0); - - %assetConfigObj = ImportAssetWindow.activeImportConfig.clone(); - %assetConfigObj.assetIndex = %i; - %assetConfigObj.assetName = %assetItem.assetName; - %assetItem.importConfig = %assetConfigObj; + %assetItem = ImportAssetTree.getItemObject(%id); - if(%assetItem.assetType $= "Model") + if(%assetItem.processed == false) { - %fileExt = fileExt(%assetItem.filePath); - if(%fileExt $= ".dae") - { - %shapeInfo = new GuiTreeViewCtrl(); - enumColladaForImport(%assetItem.filePath, %shapeInfo); - } - else - { - %shapeInfo = GetShapeInfo(%assetItem.filePath); - } - - %assetItem.shapeInfo = %shapeInfo; - - %shapeItem = %assetItem.shapeInfo.findItemByName("Shape"); - %shapeCount = %assetItem.shapeInfo.getItemValue(%shapeItem); + %assetConfigObj = ImportAssetWindow.activeImportConfig.clone(); + %assetConfigObj.assetIndex = %i; + + //sanetize before modifying our asset name(suffix additions, etc) + if(%assetItem.assetName !$= %assetItem.cleanAssetName) + %assetItem.assetName = %assetItem.cleanAssetName; + + %assetConfigObj.assetName = %assetItem.assetName; - if(%assetConfigObj.ImportMesh == 1 && %shapeCount > 0) + if(%assetItem.assetType $= "Model") { + %fileExt = fileExt(%assetItem.filePath); + if(%fileExt $= ".dae") + { + %shapeInfo = new GuiTreeViewCtrl(); + enumColladaForImport(%assetItem.filePath, %shapeInfo, false); + } + else + { + %shapeInfo = GetShapeInfo(%assetItem.filePath); + } - } - - %animItem = %assetItem.shapeInfo.findItemByName("Animations"); - %animCount = %assetItem.shapeInfo.getItemValue(%animItem); + %assetItem.shapeInfo = %shapeInfo; - if(%assetConfigObj.ImportAnimations == 1 && %animCount > 0) - { - %animationItem = %assetItem.shapeInfo.getChild(%animItem); + %shapeItem = %assetItem.shapeInfo.findItemByName("Shape"); + %shapeCount = %assetItem.shapeInfo.getItemValue(%shapeItem); - %animName = %assetItem.shapeInfo.getItemText(%animationItem); - //%animName = %assetItem.shapeInfo.getItemValue(%animationItem); + if(%assetConfigObj.ImportMesh == 1 && %shapeCount > 0) + { + + } - AssetBrowser.addImportingAsset("Animation", %animName, %assetItem); + %animItem = %assetItem.shapeInfo.findItemByName("Animations"); + %animCount = %assetItem.shapeInfo.getItemValue(%animItem); - %animationItem = %assetItem.shapeInfo.getNextSibling(%animationItem); - while(%animationItem != 0) + if(%assetConfigObj.ImportAnimations == 1 && %animCount > 0) { + %animationItem = %assetItem.shapeInfo.getChild(%animItem); + %animName = %assetItem.shapeInfo.getItemText(%animationItem); //%animName = %assetItem.shapeInfo.getItemValue(%animationItem); AssetBrowser.addImportingAsset("Animation", %animName, %assetItem); + + %animationItem = %assetItem.shapeInfo.getNextSibling(%animationItem); + while(%animationItem != 0) + { + %animName = %assetItem.shapeInfo.getItemText(%animationItem); + //%animName = %assetItem.shapeInfo.getItemValue(%animationItem); - %animationItem = %shapeInfo.getNextSibling(%animationItem); + AssetBrowser.addImportingAsset("Animation", %animName, %assetItem); + + %animationItem = %shapeInfo.getNextSibling(%animationItem); + } } - } - - %matItem = %assetItem.shapeInfo.findItemByName("Materials"); - %matCount = %assetItem.shapeInfo.getItemValue(%matItem); - - if(%assetConfigObj.importMaterials == 1 && %matCount > 0) - { - %materialItem = %assetItem.shapeInfo.getChild(%matItem); - %matName = %assetItem.shapeInfo.getItemText(%materialItem); - - %filePath = %assetItem.shapeInfo.getItemValue(%materialItem); - if(%filePath !$= "") - { - AssetBrowser.addImportingAsset("Material", %filePath, %assetItem); - } - else - { - //we need to try and find our material, since the shapeInfo wasn't able to find it automatically - %filePath = findImageFile(filePath(%assetItem.filePath), %matName); - if(%filePath !$= "") - AssetBrowser.addImportingAsset("Material", %filePath, %assetItem); - else - AssetBrowser.addImportingAsset("Material", %matName, %assetItem); - } + %matItem = %assetItem.shapeInfo.findItemByName("Materials"); + %matCount = %assetItem.shapeInfo.getItemValue(%matItem); - %materialItem = %assetItem.shapeInfo.getNextSibling(%materialItem); - while(%materialItem != 0) + if(%assetConfigObj.importMaterials == 1 && %matCount > 0) { + %materialItem = %assetItem.shapeInfo.getChild(%matItem); + %matName = %assetItem.shapeInfo.getItemText(%materialItem); + %filePath = %assetItem.shapeInfo.getItemValue(%materialItem); if(%filePath !$= "") { @@ -678,343 +747,532 @@ function findImageFile(%path, %materialName, %type) else AssetBrowser.addImportingAsset("Material", %matName, %assetItem); } - - %materialItem = %shapeInfo.getNextSibling(%materialItem); - } - } - } - else if(%assetItem.assetType $= "Animation") - { - //if we don't have our own file, that means we're gunna be using our parent shape's file so reference that - if(!isFile(%assetItem.filePath)) - { - %assetItem.filePath = %assetItem.parentAssetItem.filePath; - } - } - else if(%assetItem.assetType $= "Material") - { - //Iterate over to find appropriate images for - - //Fetch just the fileBase name - %fileDir = filePath(%assetItem.filePath); - %filename = fileBase(%assetItem.filePath); - %fileExt = fileExt(%assetItem.filePath); - - if(%assetItem.importConfig.PopulateMaterialMaps == 1) - { - if(%assetItem.diffuseImageAsset $= "") - { - //First, load our diffuse map, as set to the material in the shape - %diffuseAsset = AssetBrowser.addImportingAsset("Image", %fileDir @ "/" @ %filename @ %fileExt, %assetItem); - %assetItem.diffuseImageAsset = %diffuseAsset; - if(%assetItem.importConfig.UseDiffuseSuffixOnOriginImg == 1) - { - %diffuseToken = getToken(%assetItem.importConfig.DiffuseTypeSuffixes, ",", 0); - %diffuseAsset.AssetName = %diffuseAsset.AssetName @ %diffuseToken; - } - } - - if(%assetItem.normalImageAsset $= "") - { - //Now, iterate over our comma-delimited suffixes to see if we have any matches. We'll use the first match in each case, if any. - //First, normal map - %listCount = getTokenCount(%assetItem.importConfig.NormalTypeSuffixes, ","); - - %foundFile = 0; - for(%i=0; %i < %listCount; %i++) - { - %entryText = getToken(%assetItem.importConfig.NormalTypeSuffixes, ",", %i); - - %targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt; - %foundFile = isFile(%targetFilePath); - - if(%foundFile) - { - %normalAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %assetItem); - %assetItem.normalImageAsset = %normalAsset; - break; - } - } - } - if(%assetItem.specularImageAsset $= "") - { - //Specular - %listCount = getTokenCount(%assetItem.importConfig.SpecularTypeSuffixes, ","); - - %foundFile = 0; - for(%i=0; %i < %listCount; %i++) - { - %entryText = getToken(%assetItem.importConfig.SpecularTypeSuffixes, ",", %i); - - %targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt; - %foundFile = isFile(%targetFilePath); - - if(%foundFile) - { - %specularAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %assetItem); - %assetItem.specularImageAsset = %specularAsset; - break; - } - } - } - - if(%assetItem.metalImageAsset $= "") - { - //Metal - %listCount = getTokenCount(%assetItem.importConfig.MetalnessTypeSuffixes, ","); - - %foundFile = 0; - for(%i=0; %i < %listCount; %i++) + %materialItem = %assetItem.shapeInfo.getNextSibling(%materialItem); + while(%materialItem != 0) { - %entryText = getToken(%assetItem.importConfig.MetalnessTypeSuffixes, ",", %i); - - %targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt; - %foundFile = isFile(%targetFilePath); - - if(%foundFile) - { - %metalAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %assetItem); - %assetItem.metalImageAsset = %metalAsset; - break; - } - } - } - - if(%assetItem.roughnessImageAsset $= "") - { - //Roughness - %listCount = getTokenCount(%assetItem.importConfig.RoughnessTypeSuffixes, ","); - - %foundFile = 0; - for(%i=0; %i < %listCount; %i++) - { - %entryText = getToken(%assetItem.importConfig.RoughnessTypeSuffixes, ",", %i); - - %targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt; - %foundFile = isFile(%targetFilePath); - - if(%foundFile) - { - %roughnessAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %assetItem); - %assetItem.roughnessImageAsset = %roughnessAsset; - break; - } - } - } - - if(%assetItem.smoothnessImageAsset $= "") - { - //Smoothness - %listCount = getTokenCount(%assetItem.importConfig.SmoothnessTypeSuffixes, ","); - - %foundFile = 0; - for(%i=0; %i < %listCount; %i++) - { - %entryText = getToken(%assetItem.importConfig.SmoothnessTypeSuffixes, ",", %i); - - %targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt; - %foundFile = isFile(%targetFilePath); - - if(%foundFile) - { - %smoothnessAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %assetItem); - %assetItem.SmoothnessImageAsset = %smoothnessAsset; - break; - } - } - } - - if(%assetItem.AOImageAsset $= "") - { - //AO - %listCount = getTokenCount(%assetItem.importConfig.AOTypeSuffixes, ","); - - %foundFile = 0; - for(%i=0; %i < %listCount; %i++) - { - %entryText = getToken(%assetItem.importConfig.AOTypeSuffixes, ",", %i); - - %targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt; - %foundFile = isFile(%targetFilePath); - - if(%foundFile) + %matName = %assetItem.shapeInfo.getItemText(%materialItem); + %filePath = %assetItem.shapeInfo.getItemValue(%materialItem); + if(%filePath !$= "") { - %AOAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %assetItem); - %assetItem.AOImageAsset = %AOAsset; - break; + AssetBrowser.addImportingAsset("Material", %filePath, %assetItem); } - } - } - - if(%assetItem.compositeImageAsset $= "") - { - //Composite - %listCount = getTokenCount(%assetItem.importConfig.CompositeTypeSuffixes, ","); - - %foundFile = 0; - for(%i=0; %i < %listCount; %i++) - { - %entryText = getToken(%assetItem.importConfig.CompositeTypeSuffixes, ",", %i); - - %targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt; - %foundFile = isFile(%targetFilePath); - - if(%foundFile) + else { - %compositeAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %assetItem); - %assetItem.compositeImageAsset = %compositeAsset; - break; + //we need to try and find our material, since the shapeInfo wasn't able to find it automatically + %filePath = findImageFile(filePath(%assetItem.filePath), %matName); + if(%filePath !$= "") + AssetBrowser.addImportingAsset("Material", %filePath, %assetItem); + else + AssetBrowser.addImportingAsset("Material", %matName, %assetItem); } + + %materialItem = %shapeInfo.getNextSibling(%materialItem); } } } - } - else if(%assetItem.assetType $= "Image") - { - if(%assetConfigObj.GenerateMaterialOnImport == 1 && %assetItem.parentAssetItem $= "") + else if(%assetItem.assetType $= "Animation") { - %filePath = %assetItem.filePath; - if(%filePath !$= "") - %materialAsset = AssetBrowser.addImportingAsset("Material", %filePath, %assetItem); - - %materialAsset.diffuseImageAsset = %assetItem; - - if(%assetConfigObj.UseDiffuseSuffixOnOriginImg == 1) + //if we don't have our own file, that means we're gunna be using our parent shape's file so reference that + if(!isFile(%assetItem.filePath)) { - %diffuseToken = getToken(%assetItem.importConfig.DiffuseTypeSuffixes, ",", 0); - %assetItem.AssetName = %assetItem.AssetName @ %diffuseToken; + %assetItem.filePath = %assetItem.parentAssetItem.filePath; } } + else if(%assetItem.assetType $= "Material") + { + AssetBrowser.prepareImportMaterialAsset(%assetItem); + } + else if(%assetItem.assetType $= "Image") + { + AssetBrowser.prepareImportImageAsset(%assetItem); + } + + %assetItem.processed = true; } - AssetBrowser.importAssetUnprocessedListArray.erase(0); + //AssetBrowser.importAssetUnprocessedListArray.erase(0); //Been processed, so add it to our final list - AssetBrowser.importAssetFinalListArray.add(%assetItem); + //AssetBrowser.importAssetFinalListArray.add(%assetItem); + + if(ImportAssetTree.isParentItem(%id)) + { + %childItem = ImportAssetTree.getChild(%id); + + //recurse! + %this.processNewImportAssets(%childItem); + } + + %id = ImportAssetTree.getNextSibling(%id); } } -function ImportAssetWindow::refresh(%this) +function ImportAssetWindow::findImportingAssetByName(%this, %assetName) { - ImportingAssetList.clear(); + %id = ImportAssetTree.getFirstRootItem(); + return %this._findImportingAssetByName(%id, %assetName); +} + +function ImportAssetWindow::_findImportingAssetByName(%this, %id, %assetName) +{ + while(%id > 0) + { + %assetItem = ImportAssetTree.getItemObject(%id); + + if(%assetItem.cleanAssetName $= %assetName) + { + return %asset; + } + + if(ImportAssetTree.isParentItem(%id)) + { + %childItem = ImportAssetTree.getChild(%id); + + //recurse! + %ret = %this._findImportingAssetByName(%childItem, %assetName); + if(%ret != 0) + return %ret; + } + + %id = ImportAssetTree.getNextSibling(%id); + } + + return 0; +} + +function ImportAssetWindow::parseImageSuffixes(%this, %assetItem) +{ + //diffuse + %suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.DiffuseTypeSuffixes, ",;"); + for(%sfx = 0; %sfx < %suffixCount; %sfx++) + { + %suffixToken = getToken(ImportAssetWindow.activeImportConfig.DiffuseTypeSuffixes, ",;", %sfx); + if(strIsMatchExpr("*"@%suffixToken, %assetItem.AssetName)) + { + %assetItem.imageSuffixType = %suffixToken; + return "diffuse"; + } + } + + //normal + %suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.NormalTypeSuffixes, ",;"); + for(%sfx = 0; %sfx < %suffixCount; %sfx++) + { + %suffixToken = getToken(ImportAssetWindow.activeImportConfig.NormalTypeSuffixes, ",;", %sfx); + if(strIsMatchExpr("*"@%suffixToken, %assetItem.AssetName)) + { + %assetItem.imageSuffixType = %suffixToken; + return "normal"; + } + } + + //roughness + %suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.RoughnessTypeSuffixes, ",;"); + for(%sfx = 0; %sfx < %suffixCount; %sfx++) + { + %suffixToken = getToken(ImportAssetWindow.activeImportConfig.RoughnessTypeSuffixes, ",;", %sfx); + if(strIsMatchExpr("*"@%suffixToken, %assetItem.AssetName)) + { + %assetItem.imageSuffixType = %suffixToken; + return "roughness"; + } + } + + //Ambient Occlusion + %suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.AOTypeSuffixes, ",;"); + for(%sfx = 0; %sfx < %suffixCount; %sfx++) + { + %suffixToken = getToken(ImportAssetWindow.activeImportConfig.AOTypeSuffixes, ",;", %sfx); + if(strIsMatchExpr("*"@%suffixToken, %assetItem.AssetName)) + { + %assetItem.imageSuffixType = %suffixToken; + return "AO"; + } + } + + //metalness + %suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.MetalnessTypeSuffixes, ",;"); + for(%sfx = 0; %sfx < %suffixCount; %sfx++) + { + %suffixToken = getToken(ImportAssetWindow.activeImportConfig.MetalnessTypeSuffixes, ",;", %sfx); + if(strIsMatchExpr("*"@%suffixToken, %assetItem.AssetName)) + { + %assetItem.imageSuffixType = %suffixToken; + return "metalness"; + } + } + + //composite + %suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.CompositeTypeSuffixes, ",;"); + for(%sfx = 0; %sfx < %suffixCount; %sfx++) + { + %suffixToken = getToken(ImportAssetWindow.activeImportConfig.CompositeTypeSuffixes, ",;", %sfx); + if(strIsMatchExpr("*"@%suffixToken, %assetItem.AssetName)) + { + %assetItem.imageSuffixType = %suffixToken; + return "composite"; + } + } + + //specular + %suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.SpecularTypeSuffixes, ",;"); + for(%sfx = 0; %sfx < %suffixCount; %sfx++) + { + %suffixToken = getToken(ImportAssetWindow.activeImportConfig.SpecularTypeSuffixes, ",;", %sfx); + if(strIsMatchExpr("*"@%suffixToken, %assetItem.AssetName)) + { + %assetItem.imageSuffixType = %suffixToken; + return "specular"; + } + } + + return ""; +} + +function ImportAssetWindow::parseImagePathSuffixes(%this, %filePath) +{ + //diffuse + %suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.DiffuseTypeSuffixes, ","); + for(%sfx = 0; %sfx < %suffixCount; %sfx++) + { + %suffixToken = getToken(ImportAssetWindow.activeImportConfig.DiffuseTypeSuffixes, ",", %sfx); + if(strIsMatchExpr("*"@%suffixToken, %filePath)) + { + return "diffuse"; + } + } + + //normal + %suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.NormalTypeSuffixes, ","); + for(%sfx = 0; %sfx < %suffixCount; %sfx++) + { + %suffixToken = getToken(ImportAssetWindow.activeImportConfig.NormalTypeSuffixes, ",", %sfx); + if(strIsMatchExpr("*"@%suffixToken, %filePath)) + { + return "normal"; + } + } + + //roughness + %suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.RoughnessTypeSuffixes, ","); + for(%sfx = 0; %sfx < %suffixCount; %sfx++) + { + %suffixToken = getToken(ImportAssetWindow.activeImportConfig.RoughnessTypeSuffixes, ",", %sfx); + if(strIsMatchExpr("*"@%suffixToken, %filePath)) + { + return "roughness"; + } + } + + //Ambient Occlusion + %suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.AOTypeSuffixes, ","); + for(%sfx = 0; %sfx < %suffixCount; %sfx++) + { + %suffixToken = getToken(ImportAssetWindow.activeImportConfig.AOTypeSuffixes, ",", %sfx); + if(strIsMatchExpr("*"@%suffixToken, %filePath)) + { + return "AO"; + } + } + + //metalness + %suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.MetalnessTypeSuffixes, ","); + for(%sfx = 0; %sfx < %suffixCount; %sfx++) + { + %suffixToken = getToken(ImportAssetWindow.activeImportConfig.MetalnessTypeSuffixes, ",", %sfx); + if(strIsMatchExpr("*"@%suffixToken, %filePath)) + { + return "metalness"; + } + } + + //composite + %suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.CompositeTypeSuffixes, ","); + for(%sfx = 0; %sfx < %suffixCount; %sfx++) + { + %suffixToken = getToken(ImportAssetWindow.activeImportConfig.CompositeTypeSuffixes, ",", %sfx); + if(strIsMatchExpr("*"@%suffixToken, %filePath)) + { + return "composite"; + } + } + + //specular + %suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.SpecularTypeSuffixes, ","); + for(%sfx = 0; %sfx < %suffixCount; %sfx++) + { + %suffixToken = getToken(ImportAssetWindow.activeImportConfig.SpecularTypeSuffixes, ",", %sfx); + if(strIsMatchExpr("*"@%suffixToken, %filePath)) + { + return "specular"; + } + } + + return ""; +} + +function refreshImportAssetWindow() +{ + ImportAssetWindow.refresh(); +} + +function ImportAssetWindow::refresh(%this) +{ //Go through and process any newly, unprocessed assets - %this.processNewImportAssets(); + %id = ImportAssetTree.getFirstRootItem(); + + %this.processNewImportAssets(%id); + + %this.indentCount = 0; + + ImportingAssetList.clear(); if(AssetBrowser.importAssetUnprocessedListArray.count() == 0) { //We've processed them all, prep the assets for actual importing //Initial set of assets - %assetCount = AssetBrowser.importAssetFinalListArray.count(); + %id = ImportAssetTree.getFirstRootItem(); + + //recurse! + %this.refreshChildItem(%id); + } + else + { + //Continue processing + %this.refresh(); + } +} + +function ImportAssetWindow::refreshChildItem(%this, %id) +{ + while (%id > 0) + { + %assetItem = ImportAssetTree.getItemObject(%id); - for(%i=0; %i < %assetCount; %i++) + if(%assetItem.skip) { - %assetItem = AssetBrowser.importAssetFinalListArray.getKey(%i); - %assetType = %assetItem.assetType; - %filePath = %assetItem.filePath; - %assetName = %assetItem.assetName; - - //validate - %this.validateAsset(%assetItem); - - //Once validated, attempt any fixes for issues - %this.resolveIssue(%assetItem); - - //Make sure we size correctly - ImportingAssetList.extent.x = ImportingAssetList.getParent().extent.x - 15; - - //create! - %width = mRound(mRound(ImportingAssetList.extent.x) / 2); - %height = 20; - %indent = %assetItem.parentDepth * 16; - %toolTip = ""; - - %iconPath = "tools/gui/images/iconInformation"; - %configCommand = "ImportAssetOptionsWindow.editImportSettings(" @ %assetItem @ ");"; + %id = ImportAssetTree.getNextSibling(%id); + continue; + } + + %assetType = %assetItem.assetType; + %filePath = %assetItem.filePath; + %assetName = %assetItem.assetName; + + //validate + %this.validateAsset(%assetItem); + + //Once validated, attempt any fixes for issues + %this.resolveIssue(%assetItem); + + //Make sure we size correctly + ImportingAssetList.extent.x = ImportingAssetList.getParent().extent.x - 15; + + //create! + %width = mRound(mRound(ImportingAssetList.extent.x) / 2); + %height = 20; + %indent = %this.indentCount * 16; + %toolTip = ""; + + %iconPath = "tools/gui/images/iconInformation"; + %configCommand = "ImportAssetOptionsWindow.editImportSettings(" @ %assetItem @ ");"; + + if(%assetType $= "Model" || %assetType $= "Animation" || %assetType $= "Image" || %assetType $= "Sound") + { + /*if(%assetItem.status $= "Error") + { + %iconPath = "tools/gui/images/iconError"; + %configCommand = "ImportAssetOptionsWindow.findMissingFile(" @ %assetItem @ ");"; + } + else*/ + if(%assetItem.status $= "Warning") + { + %iconPath = "tools/gui/images/iconWarn"; + %configCommand = "ImportAssetOptionsWindow.fixIssues(" @ %assetItem @ ");"; + + if(%assetItem.statusType $= "DuplicateAsset" || %assetItem.statusType $= "DuplicateImportAsset") + %assetName = %assetItem.assetName @ " "; + } - if(%assetType $= "Model" || %assetType $= "Animation" || %assetType $= "Image" || %assetType $= "Sound") + %toolTip = %assetItem.statusInfo; + } + else + { + if(%assetItem.status $= "Error") { - if(%assetItem.status $= "Error") - { - %iconPath = "tools/gui/images/iconError"; - %configCommand = "ImportAssetOptionsWindow.findMissingFile(" @ %assetItem @ ");"; - } - else if(%assetItem.status $= "Warning") - { - %iconPath = "tools/gui/images/iconWarn"; - %configCommand = "ImportAssetOptionsWindow.fixIssues(" @ %assetItem @ ");"; - - if(%assetItem.statusType $= "DuplicateAsset" || %assetItem.statusType $= "DuplicateImportAsset") - %assetName = %assetItem.assetName @ " "; - } + %iconPath = "tools/gui/images/iconError"; + %configCommand = "";//"ImportAssetOptionsWindow.findMissingFile(" @ %assetItem @ ");"; + } + else if(%assetItem.status $= "Warning") + { + %iconPath = "tools/gui/images/iconWarn"; + %configCommand = "";//"ImportAssetOptionsWindow.fixIssues(" @ %assetItem @ ");"; - %toolTip = %assetItem.statusInfo; + if(%assetItem.statusType $= "DuplicateAsset" || %assetItem.statusType $= "DuplicateImportAsset") + %assetName = %assetItem.assetName @ " "; } - else + } + + %inputCellPos = %indent; + %inputCellWidth = (ImportingAssetList.extent.x * 0.3) - %indent; + + %filePathBtnPos = %inputCellPos + %inputCellWidth - %height; + + %assetNameCellPos = %inputCellPos + %inputCellWidth; + %assetNameCellWidth = ImportingAssetList.extent.x * 0.3; + + %assetTypeCellPos = %assetNameCellPos + %assetNameCellWidth; + %assetTypeCellWidth = ImportingAssetList.extent.x * 0.3; + + %configBtnPos = %assetTypeCellPos + %assetTypeCellWidth - (%height * 2); + %configBtnWidth = %height; + + %delBtnPos = %assetTypeCellPos + %assetTypeCellWidth - %height; + %delBtnWidth = %height; + + %inputField = %filePath; + + //Check if it's a generated type, like materials + %inputPathProfile = ToolsGuiTextEditProfile; + %generatedField = false; + if(%assetType $= "Material") + { + %inputField = "(Generated)"; + %generatedField = true; + } + else + { + //nope, so check that it's a valid file path. If not, flag it as such + if(%assetItem.status $= "Error") { - if(%assetItem.status $= "Error") + if(!isFile(%filePath)) { - %iconPath = "tools/gui/images/iconError"; - %configCommand = "";//"ImportAssetOptionsWindow.findMissingFile(" @ %assetItem @ ");"; - } - else if(%assetItem.status $= "Warning") - { - %iconPath = "tools/gui/images/iconWarn"; - %configCommand = "";//"ImportAssetOptionsWindow.fixIssues(" @ %assetItem @ ");"; - - if(%assetItem.statusType $= "DuplicateAsset" || %assetItem.statusType $= "DuplicateImportAsset") - %assetName = %assetItem.assetName @ " "; + %inputField = "File not found!"; + %inputPathProfile = ToolsGuiTextEditErrorProfile; } } + } + + %importEntry = new GuiControl() + { + position = "0 0"; + extent = ImportingAssetList.extent.x SPC %height; + horzSizing = "width"; + vertSizing = "bottom"; - %importEntry = new GuiControl() + new GuiTextEditCtrl() { - position = "0 0"; - extent = ImportingAssetList.extent.x SPC %height; - - new GuiTextCtrl() - { - Text = %assetName; - position = %indent SPC "0"; - extent = %width - %indent SPC %height; - internalName = "AssetName"; - }; - - new GuiTextCtrl() - { - Text = %assetType; - position = %width SPC "0"; - extent = %width - %height - %height SPC %height; - internalName = "AssetType"; - }; - - new GuiBitmapButtonCtrl() - { - position = ImportingAssetList.extent.x - %height - %height SPC "0"; - extent = %height SPC %height; - command = %configCommand; - bitmap = %iconPath; - tooltip = %toolTip; - }; - new GuiBitmapButtonCtrl() - { - position = ImportingAssetList.extent.x - %height SPC "0"; - extent = %height SPC %height; - command = "ImportAssetOptionsWindow.deleteImportingAsset(" @ %assetItem @ ");"; - bitmap = "tools/gui/images/iconDelete"; - }; + Text = %inputField; + position = %inputCellPos SPC "0"; + extent = %inputCellWidth SPC %height; + internalName = "InputPath"; + active = false; + profile = %inputPathProfile; + horzSizing = "width"; + vertSizing = "bottom"; + }; + + new GuiButtonCtrl() + { + position = %filePathBtnPos SPC "0"; + extent = %height SPC %height; + command = "ImportAssetOptionsWindow.findMissingFile(" @ %assetItem @ ");"; + text = "..."; + internalName = "InputPathButton"; + tooltip = %toolTip; + visible = !%generatedField; + horzSizing = "width"; + vertSizing = "bottom"; + }; + + new GuiTextEditCtrl() + { + Text = %assetName; + position = %assetNameCellPos SPC "0"; + extent = %assetNameCellWidth SPC %height; + internalName = "AssetName"; + horzSizing = "width"; + vertSizing = "bottom"; + }; + + new GuiTextEditCtrl() + { + Text = %assetType; + position = %assetTypeCellPos SPC "0"; + extent = %assetTypeCellWidth SPC %height; + active = false; + internalName = "AssetType"; + horzSizing = "width"; + vertSizing = "bottom"; }; - ImportingAssetList.add(%importEntry); + new GuiBitmapButtonCtrl() + { + position = %configBtnPos SPC "0"; + extent = %height SPC %height; + command = "ImportAssetWindow.importResolution(" @ %assetItem @ ");"; + bitmap = %iconPath; + tooltip = %toolTip; + horzSizing = "width"; + vertSizing = "bottom"; + }; + new GuiBitmapButtonCtrl() + { + position = %delBtnPos SPC "0"; + extent = %height SPC %height; + command = "ImportAssetOptionsWindow.deleteImportingAsset(" @ %assetItem @ ");"; + bitmap = "tools/gui/images/iconDelete"; + horzSizing = "width"; + vertSizing = "bottom"; + }; + }; + + ImportingAssetList.add(%importEntry); + + if(ImportAssetTree.isParentItem(%id)) + { + %this.indentCount++; + + %childItem = ImportAssetTree.getChild(%id); + + //recurse! + %this.refreshChildItem(%childItem); } + + %id = ImportAssetTree.getNextSibling(%id); + } + + %this.indentCount--; +} +// + +function ImportAssetWindow::importResolution(%this, %assetItem) +{ + if(%assetItem.status !$= "Error" && %assetItem.status !$= "Warning") + { + //If nothing's wrong, we just edit it + ImportAssetOptionsWindow.editImportSettings(%assetItem); + return; } else { - //Continue processing - %this.refresh(); + ImportAssetResolutionsPopup.assetItem = %assetItem; + if(%assetItem.statusType $= "DuplicateAsset" || %assetItem.statusType $= "DuplicateImportAsset") + { + ImportAssetResolutionsPopup.enableItem(3, false); //Rename + ImportAssetResolutionsPopup.enableItem(5, false); //Find Missing + } + else if(%assetItem.statusType $= "MissingFile") + { + ImportAssetResolutionsPopup.enableItem(0, false); //Use Orig + ImportAssetResolutionsPopup.enableItem(1, false); //Use Dupe + ImportAssetResolutionsPopup.enableItem(3, false); //Rename + } } + + ImportAssetResolutionsPopup.showPopup(Canvas); } -// function ImportAssetWindow::validateAssets(%this) { @@ -1099,7 +1357,8 @@ function findImageFile(%path, %materialName, %type) } } - if(!isFile(%assetItemA.filePath)) + //Check if we were given a file path(so not generated) but somehow isn't a valid file + if(%assetItemA.filePath !$= "" && !isFile(%assetItemA.filePath)) { %hasIssues = true; %assetItemA.status = "error"; @@ -1133,17 +1392,29 @@ function findImageFile(%path, %materialName, %type) return; } - /*if(!%this.validateAssets()) - { - //Force a refresh, as some things may have changed, such as errors and failure info! - refresh(); - - return; - }*/ + %id = ImportAssetTree.getFirstRootItem(); - for(%i=0; %i < %assetCount; %i++) + %this.doImportAssets(%id); + + //force an update of any and all modules so we have an up-to-date asset list + AssetBrowser.loadFilters(); + AssetBrowser.refreshPreviews(); + Canvas.popDialog(AssetImportCtrl); + AssetBrowser.isAssetReImport = false; +} + +function ImportAssetWindow::doImportAssets(%this, %id) +{ + while(%id > 0) { - %assetItem = AssetBrowser.importAssetFinalListArray.getKey(%i); + %assetItem = ImportAssetTree.getItemObject(%id); + + if(%assetItem.skip) + { + %id = ImportAssetTree.getNextSibling(%id); + continue; + } + %assetType = %assetItem.AssetType; %filePath = %assetItem.filePath; %assetName = %assetItem.assetName; @@ -1152,78 +1423,11 @@ function findImageFile(%path, %materialName, %type) if(%assetType $= "Image") { - %assetPath = "data/" @ %moduleName @ "/Images"; - %assetFullPath = %assetPath @ "/" @ fileName(%filePath); - - %newAsset = new ImageAsset() - { - assetName = %assetName; - versionId = 1; - imageFile = %assetFullPath; - originalFilePath = %filePath; - }; - - %assetImportSuccessful = TAMLWrite(%newAsset, %assetPath @ "/" @ %assetName @ ".asset.taml"); - - //and copy the file into the relevent directory - %doOverwrite = !AssetBrowser.isAssetReImport; - if(!pathCopy(%filePath, %assetFullPath, %doOverwrite)) - { - error("Unable to import asset: " @ %filePath); - } + AssetBrowser.importImageAsset(%assetItem); } else if(%assetType $= "Model") { - %assetPath = "data/" @ %moduleName @ "/Shapes"; - %assetFullPath = %assetPath @ "/" @ fileName(%filePath); - - %newAsset = new ShapeAsset() - { - assetName = %assetName; - versionId = 1; - fileName = %assetFullPath; - originalFilePath = %filePath; - isNewShape = true; - }; - - %dependencyCount = getWordCount(%assetItem.dependencies); - for(%d=0; %d < %dependencyCount; %d++) - { - %dependencyAssetItem = getWord(%assetItem.dependencies, %d); - - %depAssetType = %dependencyAssetItem.assetType; - if(%depAssetType $= "Material") - { - %matSet = "%newAsset.materialSlot"@%d@"=\"@Asset="@%moduleName@":"@%dependencyAssetItem.assetName@"\";"; - eval(%matSet); - } - if(%depAssetType $= "Animation") - { - %matSet = "%newAsset.animationSequence"@%d@"=\"@Asset="@%moduleName@":"@%dependencyAssetItem.assetName@"\";"; - eval(%matSet); - } - } - - %assetImportSuccessful = TAMLWrite(%newAsset, %assetPath @ "/" @ %assetName @ ".asset.taml"); - - //and copy the file into the relevent directory - %doOverwrite = !AssetBrowser.isAssetReImport; - if(!pathCopy(%filePath, %assetFullPath, %doOverwrite)) - { - error("Unable to import asset: " @ %filePath); - } - - //now, force-load the file if it's collada - %fileExt = fileExt(%assetFullPath); - if(isSupportedFormat(getSubStr(%fileExt,1))) - { - %tempShape = new TSStatic() - { - shapeName = %assetFullPath; - }; - - %tempShape.delete(); - } + AssetBrowser.importShapeAsset(%assetItem); } else if(%assetType $= "Animation") { @@ -1277,92 +1481,52 @@ function findImageFile(%path, %materialName, %type) } else if(%assetType $= "Material") { - %assetPath = "data/" @ %moduleName @ "/materials"; - %tamlpath = %assetPath @ "/" @ %assetName @ ".asset.taml"; - %sgfPath = %assetPath @ "/" @ %assetName @ ".sgf"; - %scriptPath = %assetPath @ "/" @ %assetName @ ".cs"; + AssetBrowser.importMaterialAsset(%assetItem); + } + else if(%assetType $= "Script") + { + %assetPath = "data/" @ %moduleName @ "/Scripts"; + %assetFullPath = %assetPath @ "/" @ fileName(%filePath); - %newAsset = new MaterialAsset() + %newAsset = new ScriptAsset() { assetName = %assetName; versionId = 1; - shaderGraph = %sgfPath; - scriptFile = %scriptPath; + scriptFilePath = %assetFullPath; + isServerSide = true; originalFilePath = %filePath; - materialDefinitionName = %assetName; }; - %dependencyCount = getWordCount(%assetItem.dependencies); - for(%d=0; %d < %dependencyCount; %d++) + %assetImportSuccessful = TAMLWrite(%newAsset, %assetPath @ "/" @ %assetName @ ".asset.taml"); + + //and copy the file into the relevent directory + %doOverwrite = !AssetBrowser.isAssetReImport; + if(!pathCopy(%filePath, %assetFullPath, %doOverwrite)) { - %dependencyAssetItem = getWord(%assetItem.dependencies, %d); - - %depAssetType = %dependencyAssetItem.assetType; - if(%depAssetType $= "Image") - { - %matSet = "%newAsset.imageMap"@%d@"=\"@Asset="@%moduleName@":"@%dependencyAssetItem.assetName@"\";"; - eval(%matSet); - } + error("Unable to import asset: " @ %filePath); } + } + else if(%assetType $= "GUI") + { + %assetPath = "data/" @ %moduleName @ "/GUIs"; + %assetFullPath = %assetPath @ "/" @ fileName(%filePath); + + %newAsset = new GUIAsset() + { + assetName = %assetName; + versionId = 1; + GUIFilePath = %assetFullPath; + scriptFilePath = ""; + originalFilePath = %filePath; + }; - %assetImportSuccessful = TamlWrite(%newAsset, %tamlpath); + %assetImportSuccessful = TAMLWrite(%newAsset, %assetPath @ "/" @ %assetName @ ".asset.taml"); - %file = new FileObject(); - - if(%file.openForWrite(%scriptPath)) + //and copy the file into the relevent directory + %doOverwrite = !AssetBrowser.isAssetReImport; + if(!pathCopy(%filePath, %assetFullPath, %doOverwrite)) { - %file.writeline("//--- OBJECT WRITE BEGIN ---"); - %file.writeline("singleton Material(" @ %assetName @ ") {"); - - //TODO: pass along the shape's target material for this just to be sure - %file.writeLine(" mapTo = \"" @ %assetName @ "\";"); - - if(%assetItem.diffuseImageAsset !$= "") - { - %diffuseAssetPath = "data/" @ %moduleName @ "/Images/" @ fileName(%assetItem.diffuseImageAsset.filePath); - %file.writeline(" DiffuseMap[0] = \"" @ %diffuseAssetPath @"\";"); - %file.writeline(" DiffuseMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.diffuseImageAsset.assetName @"\";"); - } - if(%assetItem.normalImageAsset) - { - %normalAssetPath = "data/" @ %moduleName @ "/Images/" @ fileName(%assetItem.normalImageAsset.filePath); - %file.writeline(" NormalMap[0] = \"" @ %normalAssetPath @"\";"); - %file.writeline(" NormalMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.normalImageAsset.assetName @"\";"); - } - /*if(%assetItem.specularImageAsset) - { - %file.writeline(" SpecularMap[0] = \"" @ %assetItem.specularImageAsset.filePath @"\";"); - %file.writeline(" SpecularMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.specularImageAsset.assetName @"\";"); - }*/ - if(%assetItem.roughnessImageAsset) - { - %file.writeline(" RoughMap[0] = \"" @ %assetItem.roughnessImageAsset.filePath @"\";"); - %file.writeline(" RoughMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.roughnessImageAsset.assetName @"\";"); - } - if(%assetItem.smoothnessImageAsset) - { - %file.writeline(" SmoothnessMap[0] = \"" @ %assetItem.smoothnessImageAsset.filePath @"\";"); - %file.writeline(" SmoothnessMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.smoothnessImageAsset.assetName @"\";"); - } - if(%assetItem.metalnessImageAsset) - { - %file.writeline(" MetalMap[0] = \"" @ %assetItem.metalnessImageAsset.filePath @"\";"); - %file.writeline(" MetalMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.metalnessImageAsset.assetName @"\";"); - } - if(%assetItem.AOImageAsset) - { - %file.writeline(" AOMap[0] = \"" @ %assetItem.AOImageAsset.filePath @"\";"); - %file.writeline(" AOMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.AOImageAsset.assetName @"\";"); - } - if(%assetItem.compositeImageAsset) - { - %file.writeline(" CompositeMap[0] = \"" @ %assetItem.compositeImageAsset.filePath @"\";"); - %file.writeline(" CompositeMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.compositeImageAsset.assetName @"\";"); - } - %file.writeline("};"); - %file.writeline("//--- OBJECT WRITE END ---"); - - %file.close(); + error("Unable to import asset: " @ %filePath); } } @@ -1375,15 +1539,26 @@ function findImageFile(%path, %materialName, %type) else AssetDatabase.refreshAsset(%assetId); } + + if(ImportAssetTree.isParentItem(%id)) + { + %childItem = ImportAssetTree.getChild(%id); + + //recurse! + %this.doImportAssets(%childItem); + } + + %id = ImportAssetTree.getNextSibling(%id); } - - //force an update of any and all modules so we have an up-to-date asset list - AssetBrowser.loadFilters(); - AssetBrowser.refreshPreviews(); - Canvas.popDialog(AssetImportCtrl); - AssetBrowser.isAssetReImport = false; } +function ImportAssetWindow::Close(%this) +{ + //Some cleanup + AssetBrowser.importingFilesArray.clear(); + + Canvas.popDialog(); +} // function ImportAssetWindow::validateAsset(%this, %assetItem) { @@ -1472,7 +1647,8 @@ function findImageFile(%path, %materialName, %type) %assetQuery.delete(); } - if(!isFile(%assetItem.filePath)) + //Check if we were given a file path(so not generated) but somehow isn't a valid file + if(%assetItem.filePath !$= "" && !isFile(%assetItem.filePath)) { %hasIssues = true; %assetItem.status = "error"; diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImportConfig.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImportConfig.cs index bdd4c28515..aa9d96377b 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImportConfig.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImportConfig.cs @@ -8,7 +8,9 @@ ImportAssetWindow.activeImportConfigIndex = %id; ImportAssetWindow.activeImportConfig = ImportAssetWindow.importConfigsList.getKey(%id); - ImportAssetWindow.refresh(); + //ImportAssetWindow.refresh(); + + AssetBrowser.reloadImportingFiles(); } function ImportAssetOptionsWindow::findMissingFile(%this, %assetItem) @@ -26,6 +28,7 @@ ChangePath = true; OverwritePrompt = true; forceRelativePath = false; + fileName=""; //MultipleFiles = true; }; @@ -43,6 +46,23 @@ return; %assetItem.filePath = %fullPath; + %assetItem.assetName = fileBase(%assetItem.filePath); + + if(%assetItem.assetType $= "Image") + { + //See if we have anything important to update for our material parent(if we have one) + %treeItem = ImportAssetTree.findItemByObjectId(%assetItem); + %parentItem = ImportAssetTree.getParentItem(%treeItem); + + if(%parentItem != 0) + { + %parentAssetItem = ImportAssetTree.getItemObject(%parentItem); + if(%parentAssetItem.assetType $= "Material") + { + AssetBrowser.prepareImportMaterialAsset(%parentAssetItem); + } + } + } ImportAssetWindow.refresh(); } @@ -128,6 +148,7 @@ ImportOptionsList.addField("PopulateMaterialMaps", "Populate Material Maps", "bool", "", "1", "", %optionsObj); ImportOptionsList.addField("UseDiffuseSuffixOnOriginImg", "Use Diffuse Suffix for Origin Image", "bool", "", "1", "", %optionsObj); ImportOptionsList.addField("UseExistingMaterials", "Use Existing Materials", "bool", "", "1", "", %optionsObj); + ImportOptionsList.addField("IgnoreMaterials", "Ignore Importing Materials that fit these naming convention.", "command", "", "1", "", %optionsObj); ImportOptionsList.endGroup(); } else if(%assetType $= "Sound") @@ -145,35 +166,13 @@ function ImportAssetOptionsWindow::deleteImportingAsset(%this, %assetItem) { - %assetIndex = AssetBrowser.importAssetNewListArray.getIndexFromKey(%assetItem); - AssetBrowser.importAssetNewListArray.erase(%assetIndex); + %item = ImportAssetTree.findItemByObjectId(%assetItem); - //check if we have any child assets and remove them as well - for(%i=0; %i < AssetBrowser.importAssetNewListArray.count(); %i++) - { - %asset = AssetBrowser.importAssetNewListArray.getKey(%i); - if(%asset.ParentAssetItem == %assetItem) - { - AssetBrowser.importAssetNewListArray.erase(%i); - %i--; - } - } - - %assetIndex = AssetBrowser.importAssetFinalListArray.getIndexFromKey(%assetItem); - AssetBrowser.importAssetFinalListArray.erase(%assetIndex); - - //check if we have any child assets and remove them as well - for(%i=0; %i < AssetBrowser.importAssetFinalListArray.count(); %i++) - { - %asset = AssetBrowser.importAssetFinalListArray.getKey(%i); - if(%asset.ParentAssetItem == %assetItem) - { - AssetBrowser.importAssetFinalListArray.erase(%i); - %i--; - } - } - - ImportAssetWindow.refresh(); + ImportAssetTree.removeAllChildren(%item); + ImportAssetTree.removeItem(%item); + + schedule(10, 0, "refreshImportAssetWindow"); + //ImportAssetWindow.refresh(); ImportAssetOptionsWindow.setVisible(0); } @@ -302,6 +301,7 @@ //Materials %optionsObj.ImportMaterials = true; + %optionsObj.IgnoreMaterials = ""; %optionsObj.CreateComposites = true; %optionsObj.UseDiffuseSuffixOnOriginImg = true; %optionsObj.UseExistingMaterials = true; @@ -398,6 +398,7 @@ %xmlDoc.pushNewElement("Materials"); %xmlDoc.setAttribute("ImportMaterials", %configObj.ImportMaterials); + %xmlDoc.setAttribute("IgnoreMaterials", %configObj.IgnoreMaterials); %xmlDoc.setAttribute("CreateComposites", %configObj.CreateComposites); %xmlDoc.setAttribute("UseDiffuseSuffixOnOriginImg", %configObj.UseDiffuseSuffixOnOriginImg); %xmlDoc.setAttribute("UseExistingMaterials", %configObj.UseExistingMaterials); diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/assetTypeExample.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/assetTypeExample.cs new file mode 100644 index 0000000000..3cbdcd6cbf --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/assetTypeExample.cs @@ -0,0 +1,53 @@ +function AssetBrowser::create_Asset(%this) +{ +} + +function AssetBrowser::edit_Asset(%this, %assetDef) +{ +} + +function AssetBrowser::duplicate_Asset(%this, %assetDef, %targetModule) +{ +} + +function AssetBrowser::import_Asset(%this, %assetDef) +{ +} + +function AssetBrowser::dragAndDrop_Asset(%this, %assetDef, %dropTarget) +{ + if(!isObject(%dropTarget)) + return; +} + +function AssetBrowser::rename_Asset(%this, %assetDef, %newAssetId, %originalName, %newName) +{ +} + +function AssetBrowser::delete_Asset(%this, %assetDef) +{ +} + +function AssetBrowser::build_AssetPreview(%this, %assetDef, %previewData) +{ + %previewData.assetName = %assetDef.assetName; + %previewData.assetPath = ""; + %previewData.doubleClickCommand = ""; + + %previewData.previewImage = "tools/assetBrowser/art/gameObjectIcon"; + + %previewData.assetFriendlyName = %assetDef.gameObjectName; + %previewData.assetDesc = %assetDef.description; + %previewData.tooltip = %assetDef.gameObjectName; +} + +function GuiInspectorType_AssetPtr::onClick( %this, %fieldName ) +{ + //Get our data + %obj = %this.getInspector().getInspectObject(0); +} + +function GuiInspectorType_AssetPtr::onControlDropped( %this, %payload, %position ) +{ + +} \ No newline at end of file diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/component.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/component.cs new file mode 100644 index 0000000000..ff643f9ad7 --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/component.cs @@ -0,0 +1,141 @@ +function AssetBrowser::createComponentAsset(%this) +{ + %moduleName = AssetBrowser.newAssetSettings.moduleName; + %modulePath = "data/" @ %moduleName; + + %assetName = AssetBrowser.newAssetSettings.assetName; + + %tamlpath = %modulePath @ "/components/" @ %assetName @ ".asset.taml"; + %scriptPath = %modulePath @ "/components/" @ %assetName @ ".cs"; + + %asset = new ComponentAsset() + { + AssetName = %assetName; + versionId = 1; + componentName = %assetName; + componentClass = AssetBrowser.newAssetSettings.parentClass; + friendlyName = AssetBrowser.newAssetSettings.friendlyName; + componentType = AssetBrowser.newAssetSettings.componentGroup; + description = AssetBrowser.newAssetSettings.description; + scriptFile = %assetName @ ".cs"; + }; + + TamlWrite(%asset, %tamlpath); + + %file = new FileObject(); + + if(%file.openForWrite(%scriptPath)) + { + //TODO: enable ability to auto-embed a header for copyright or whatnot + %file.writeline("//onAdd is called when the component is created and then added to it's owner entity.\n"); + %file.writeline("//You would also add any script-defined component fields via addComponentField().\n"); + %file.writeline("function " @ %assetName @ "::onAdd(%this)\n{\n\n}\n"); + %file.writeline("//onAdd is called when the component is removed and deleted from it's owner entity."); + %file.writeline("function " @ %assetName @ "::onRemove(%this)\n{\n\n}\n"); + %file.writeline("//onClientConnect is called any time a new client connects to the server."); + %file.writeline("function " @ %assetName @ "::onClientConnect(%this, %client)\n{\n\n}\n"); + %file.writeline("//onClientDisconnect is called any time a client disconnects from the server."); + %file.writeline("function " @ %assetName @ "::onClientDisonnect(%this, %client)\n{\n\n}\n"); + %file.writeline("//update is called when the component does an update tick.\n"); + %file.writeline("function " @ %assetName @ "::Update(%this)\n{\n\n}\n"); + + %file.close(); + } + + Canvas.popDialog(AssetBrowser_newComponentAsset); + + %moduleDef = ModuleDatabase.findModule(%moduleName, 1); + AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath); + + AssetBrowser.loadFilters(); + + %treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName); + %smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "ComponentAsset"); + + AssetBrowserFilterTree.onSelect(%smItem); + + return %tamlpath; +} + +function AssetBrowser::editComponentAsset(%this, %assetDef) +{ + %scriptFile = %assetDef.scriptFile; + + EditorOpenFileInTorsion(makeFullPath(%scriptFile), 0); +} + +function AssetBrowser::duplicateComponentAsset(%this, %assetId) +{ + +} + +function AssetBrowser::renameGameObjectAsset(%this, %assetDef, %newAssetId, %originalName, %newName) +{ + %assetPath = AssetDatabase.getAssetFilePath(%newAssetId); + + //rename the file to match + %path = filePath(%assetPath); + + %oldScriptFilePath = %assetDef.scriptFile; + %scriptFilePath = filePath(%assetDef.scriptFile); + %scriptExt = fileExt(%assetDef.scriptFile); + + %newScriptFileName = %scriptFilePath @ "/" @ %newName @ %scriptExt; + %newAssetFile = %path @ "/" @ %newName @ ".asset.taml"; + + %assetDef.componentName = %newName; + %assetDef.scriptFile = %newScriptFileName; + + TamlWrite(%assetDef, %newAssetFile); + fileDelete(%assetPath); + + pathCopy(%oldScriptFilePath, %newScriptFileName); + fileDelete(%oldScriptFilePath); + + //Go through our scriptfile and replace the old namespace with the new + %editedFileContents = ""; + + %file = new FileObject(); + if ( %file.openForRead( %newScriptFileName ) ) + { + while ( !%file.isEOF() ) + { + %line = %file.readLine(); + %line = trim( %line ); + + %editedFileContents = %editedFileContents @ strreplace(%line, %originalAssetName, %newName) @ "\n"; + } + + %file.close(); + } + + if(%editedFileContents !$= "") + { + %file.openForWrite(%newScriptFileName); + + %file.writeline(%editedFileContents); + + %file.close(); + } + + exec(%newScriptFileName); +} + +//not used +function AssetBrowser::importComponentAsset(%this, %assetId) +{ + +} + +function AssetBrowser::buildComponentAssetPreview(%this, %assetDef, %previewData) +{ + %previewData.assetName = %assetDef.assetName; + %previewData.assetPath = %assetDef.scriptFile; + %previewData.doubleClickCommand = "EditorOpenFileInTorsion( "@%previewData.assetPath@", 0 );"; + + %previewData.previewImage = "tools/assetBrowser/art/componentIcon"; + + %previewData.assetFriendlyName = %assetDef.friendlyName; + %previewData.assetDesc = %assetDef.description; + %previewData.tooltip = %assetDef.friendlyName @ "\n" @ %assetDef; +} \ No newline at end of file diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/cpp.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/cpp.cs new file mode 100644 index 0000000000..3ce87b6722 --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/cpp.cs @@ -0,0 +1,143 @@ +function AssetBrowser::createCppAsset(%this) +{ + %moduleName = AssetBrowser.newAssetSettings.moduleName; + %modulePath = "data/" @ %moduleName; + + %assetName = AssetBrowser.newAssetSettings.assetName; + + %tamlpath = %modulePath @ "/source/" @ %assetName @ ".asset.taml"; + %codePath = %modulePath @ "/source/" @ %assetName @ ".cpp"; + %headerPath = %modulePath @ "/source/" @ %assetName @ ".h"; + + //Do the work here + %assetType = AssetBrowser.newAssetSettings.assetType; + + /*if(%assetType $= "CppStaticClassAsset" + || %assetType $= "CppRegularClassAsset" + || %assetType $= "CppGameObjectAsset" + || %assetType $= "CppComponentAsset" + || %assetType $= "CppScriptClass") + { + + }*/ + + %asset = new CppAsset() + { + AssetName = %assetName; + versionId = 1; + codeFile = %codePath; + headerFile = %headerPath; + }; + + TamlWrite(%asset, %tamlpath); + + %moduleDef = ModuleDatabase.findModule(%moduleName, 1); + AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath); + + AssetBrowser.loadFilters(); + + %treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName); + %smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "CppAsset"); + + AssetBrowserFilterTree.onSelect(%smItem); + + %templateFilesPath = "tools/assetBrowser/scripts/templateFiles/"; + + %file = new FileObject(); + %templateFile = new FileObject(); + + if(%assetType $= "CppStaticClassAsset") + { + %cppTemplateCodeFilePath = %templateFilesPath @ "CppStaticClassFile.cpp"; + %cppTemplateHeaderFilePath = %templateFilesPath @ "CppStaticClassFile.h"; + } + + if(%file.openForWrite(%codePath) && %templateFile.openForRead(%cppTemplateCodeFilePath)) + { + while( !%templateFile.isEOF() ) + { + %line = %templateFile.readline(); + %line = strreplace( %line, "@", %assetName ); + + %file.writeline(%line); + echo(%line); + } + + %file.close(); + %templateFile.close(); + } + else + { + %file.close(); + %templateFile.close(); + + warnf("CreateNewCppAsset - Something went wrong and we couldn't write the C++ code file!"); + } + + if(%file.openForWrite(%headerPath) && %templateFile.openForRead(%cppTemplateHeaderFilePath)) + { + while( !%templateFile.isEOF() ) + { + %line = %templateFile.readline(); + %line = strreplace( %line, "@", %assetName ); + + %file.writeline(%line); + echo(%line); + } + + %file.close(); + %templateFile.close(); + } + else + { + %file.close(); + %templateFile.close(); + + warnf("CreateNewCppAsset - Something went wrong and we couldn't write the C++ header file!"); + } + + //Last, check that we have a C++ Module definition. If not, make one so anything important can be initialized on startup there + %cppModuleFilePath = %modulePath @ "/source/" @ %moduleName @ ".cpp"; + if(!isFile(%cppModuleFilePath)) + { + %file = new FileObject(); + %templateFile = new FileObject(); + + if(%file.openForWrite(%cppModuleFilePath) && %templateFile.openForRead(%templateFilesPath @ "CppModuleFile.cpp")) + { + while( !%templateFile.isEOF() ) + { + %line = %templateFile.readline(); + %line = strreplace( %line, "@", %moduleName ); + + %file.writeline(%line); + echo(%line); + } + + %file.close(); + %templateFile.close(); + } + else + { + %file.close(); + %templateFile.close(); + + warnf("CreateNewCppAsset - Something went wrong and we couldn't write the C++ module file!"); + } + } + + return %tamlpath; +} + +function AssetBrowser::buildCppAssetPreview(%this, %assetDef, %previewData) +{ + %previewData.assetName = %assetDef.assetName; + %previewData.assetPath = %assetDef.codeFilePath; + %previewData.doubleClickCommand = "echo(\"Not yet implemented to edit C++ files from the editor\");";//"EditorOpenFileInTorsion( "@%previewData.assetPath@", 0 );"; + + %previewData.previewImage = "tools/assetBrowser/art/cppIcon"; + + %previewData.assetFriendlyName = %assetDef.assetName; + %previewData.assetDesc = %assetDef.description; + %previewData.tooltip = %assetDef.assetName; +} \ No newline at end of file diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/gameObject.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/gameObject.cs new file mode 100644 index 0000000000..b119079290 --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/gameObject.cs @@ -0,0 +1,242 @@ +function AssetBrowser::createGameObjectAsset(%this) +{ + GameObjectCreatorObjectName.text = ""; + + %activeSelection = EWorldEditor.getActiveSelection(); + if( %activeSelection.getCount() == 0 ) + return; + + GameObjectCreator.selectedEntity = %activeSelection.getObject( 0 ); + + Canvas.pushDialog(GameObjectCreator); +} + +function AssetBrowser::editGameObjectAsset(%this, %assetDef) +{ + //We have no dedicated GO editor for now, so just defer to the script editing aspect + %this.editGameObjectAssetScript(%assetDef); +} + +function AssetBrowser::editGameObjectAssetScript(%this, %assetDef) +{ + %scriptFile = %assetDef.scriptFile; + + EditorOpenFileInTorsion(makeFullPath(%scriptFile), 0); +} + +function AssetBrowser::applyInstanceToGameObject(%this, %assetDef) +{ + %obj = EditGameObjectAssetPopup.object; + + //TODO add proper validation against the original GO asset + %obj.dirtyGameObject = true; + + TamlWrite(%obj, %assetDef.TAMLFilePath); +} + +function AssetBrowser::duplicateGameObjectAsset(%this, %assetDef, %targetModule) +{ + //Check if we have a target module, if not we need to select one + if(%targetModule $= "") + { + error("AssetBrowser::duplicateGameObjectAsset - No target module selected!"); + return; + } + + %assetId = %assetDef.getAssetId(); + %assetName = AssetDatabase.getAssetName(%assetId); + + //First step, copy the files + %modulePath = "data/" @ %targetModule @ "/gameObjects/"; + + if(!isDirectory(%modulePath)) + createPath(%modulePath); + + %assetFile = AssetDatabase.getAssetFilePath(%assetId); + %scriptFile = %assetDef.scriptFile; + %gameObjectFile = %assetDef.TAMLFile; + + echo("AssetBrowser::duplicateGameObjectAsset - duplicating! " @ %assetId @ " to " @ %targetModule); + + %tamlPath = %modulePath @ fileName(%assetFile); + + pathCopy(%assetFile, %tamlPath); + pathCopy(%scriptFile, %modulePath @ fileName(%scriptFile)); + pathCopy(%gameObjectFile, %modulePath @ fileName(%gameObjectFile)); + + echo("AssetBrowser::duplicateGameObjectAsset - duplicated!"); + + //Register the asset + %moduleDef = ModuleDatabase.findModule(%targetModule, 1); + + AssetDatabase.addDeclaredAsset(%moduleDef, %tamlPath); + + //Refresh the browser + AssetBrowser.loadFilters(); + + //Ensure our context is set + %treeItemId = AssetBrowserFilterTree.findItemByName(%targetModule); + %smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "GameObjectAsset"); + + AssetBrowserFilterTree.selectItem(%smItem); + + //Rename it for convenience + AssetBrowser.performRenameAsset(%assetName, "New" @ %assetName); + + //Expand and refresh the target module + AssetBrowserFilterTree.expandItem(%treeItemId,true); + + AssetBrowserFilterTree.buildVisibleTree(); +} + +//not used +function AssetBrowser::importGameObjectAsset(%this, %assetId) +{ + +} + +function AssetBrowser::dragAndDropGameObjectAsset(%this, %assetDef, %dropTarget) +{ + if(!isObject(%dropTarget)) + return; + + if(%dropTarget.getId() == EWorldEditor.getId()) + { + if(isObject(%assetDef)) + { + %gameObject = %assetDef.createObject(); + + getScene(0).add(%gameObject); + + %pos = EWCreatorWindow.getCreateObjectPosition(); //LocalClientConnection.camera.position; + + %gameObject.position = %pos; + + EWorldEditor.clearSelection(); + EWorldEditor.selectObject(%gameObject); + } + else + { + error("WorldEditor::onControlDropped - unable to create GameObject"); + } + } +} + +function AssetBrowser::renameGameObjectAsset(%this, %assetDef, %newAssetId, %originalName, %newName) +{ + %oldScriptFilePath = %assetDef.scriptFile; + %scriptFilePath = filePath(%assetDef.scriptFile); + %scriptExt = fileExt(%assetDef.scriptFile); + + %oldGOFilePath = %assetDef.TAMLFile; + + %filepath = AssetDatabase.getAssetFilePath(%assetDef.getAssetId()); + %path = makeRelativePath(filePath(%filepath)); + + %newScriptFileName = %path @ "/" @ %newName @ %scriptExt; + %newAssetFile = %path @ "/" @ %newName @ ".asset.taml"; + %newGOFile = %path @ "/" @ %newName @ ".taml"; + + %assetDef.gameObjectName = %newName; + %assetDef.scriptFile = %newScriptFileName; + %assetDef.TAMLFile = %newGOFile; + + TamlWrite(%assetDef, %newAssetFile); + fileDelete(%filepath); + + //Quick check, if we duplicated the asset to a new module, the old path may not line up so we'll want to update that to be relevent + if(filePath(%oldScriptFilePath) !$= %path) + { + %oldFileBase = fileName(%oldScriptFilePath); + %oldScriptFilePath = %path @ "/" @ %oldFileBase; + } + + %scriptFileCopySuccess = pathCopy(%oldScriptFilePath, %newScriptFileName); + fileDelete(%oldScriptFilePath); + + if(!%scriptFileCopySuccess) + error("AssetBrowser::renameGameObjectAsset - unable to copy scriptFile"); + + if(filePath(%oldGOFilePath) !$= %path) + { + %oldFileBase = fileName(%oldGOFilePath); + %oldGOFilePath = %path @ "/" @ %oldFileBase; + } + + %goFileCopySuccess = pathCopy(%oldGOFilePath, %newGOFile); + fileDelete(%oldGOFilePath); + + if(!%scriptFileCopySuccess) + error("AssetBrowser::renameGameObjectAsset - unable to copy gameObject"); + + //Go through our scriptfile and replace the old namespace with the new + %editedFileContents = ""; + + %file = new FileObject(); + if ( %file.openForRead( %newScriptFileName ) ) + { + while ( !%file.isEOF() ) + { + %line = %file.readLine(); + %line = trim( %line ); + + %editedFileContents = %editedFileContents @ strreplace(%line, %originalName, %newName) @ "\n"; + } + + %file.close(); + } + + if(%editedFileContents !$= "") + { + %file.openForWrite(%newScriptFileName); + + %file.writeline(%editedFileContents); + + %file.close(); + } + + exec(%newScriptFileName); + + %gameObj = TAMLRead(%newGOFile); + + %gameObj.className = %newName; + %gameObj.GameObject = %assetDef.getAssetId(); + + TAMLWrite(%gameObj, %newGOFile); +} + +function AssetBrowser::buildGameObjectAssetPreview(%this, %assetDef, %previewData) +{ + %previewData.assetName = %assetDef.assetName; + %previewData.assetPath = %assetDef.scriptFile; + %previewData.doubleClickCommand = "EditorOpenFileInTorsion( "@%previewData.assetPath@", 0 );"; + + %previewData.previewImage = "tools/assetBrowser/art/gameObjectIcon"; + + %previewData.assetFriendlyName = %assetDef.gameObjectName; + %previewData.assetDesc = %assetDef.description; + %previewData.tooltip = %assetDef.gameObjectName; +} + +function GuiInspectorTypeGameObjectAssetPtr::onClick( %this, %fieldName ) +{ + //Get our data + %obj = %this.getInspector().getInspectObject(0); + + EditGameObjectAssetPopup.object = %obj; + + %assetId = %obj.getFieldValue(%fieldName); + + if(%assetId !$= "") + { + EditGameObjectAssetPopup.assetId = %assetId; + + + EditGameObjectAssetPopup.showPopup(Canvas); + } + else + { + //We've gotta be trying to create a GameObject, so kick that off + AssetBrowser.createGameObjectAsset(); + } +} \ No newline at end of file diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/gui.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/gui.cs new file mode 100644 index 0000000000..22fa291857 --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/gui.cs @@ -0,0 +1,83 @@ +function AssetBrowser::createGUIAsset(%this) +{ + %moduleName = AssetBrowser.newAssetSettings.moduleName; + %modulePath = "data/" @ %moduleName; + + %assetName = AssetBrowser.newAssetSettings.assetName; + + %tamlpath = %modulePath @ "/GUIs/" @ %assetName @ ".asset.taml"; + %guipath = %modulePath @ "/GUIs/" @ %assetName @ ".gui"; + %scriptPath = %modulePath @ "/GUIs/" @ %assetName @ ".cs"; + + %asset = new GUIAsset() + { + AssetName = %assetName; + versionId = 1; + scriptFile = %assetName @ ".cs"; + guiFile = %assetName @ ".gui"; + }; + + TamlWrite(%asset, %tamlpath); + + %file = new FileObject(); + + if(%file.openForWrite(%guipath)) + { + %file.writeline("//--- OBJECT WRITE BEGIN ---"); + %file.writeline("%guiContent = new GuiControl(" @ %assetName @ ") {"); + %file.writeline(" position = \"0 0\";"); + %file.writeline(" extent = \"100 100\";"); + %file.writeline("};"); + %file.writeline("//--- OBJECT WRITE END ---"); + + %file.close(); + } + + if(%file.openForWrite(%scriptPath)) + { + %file.writeline("function " @ %assetName @ "::onWake(%this)\n{\n\n}\n"); + %file.writeline("function " @ %assetName @ "::onSleep(%this)\n{\n\n}\n"); + + %file.close(); + } + + //load the gui + exec(%guipath); + exec(%scriptPath); + + %moduleDef = ModuleDatabase.findModule(%moduleName, 1); + AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath); + + AssetBrowser.loadFilters(); + + %treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName); + %smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "GUIs"); + + AssetBrowserFilterTree.onSelect(%smItem); + + return %tamlpath; +} + +function AssetBrowser::editGUIAsset(%this, %assetDef) +{ + if(!isObject(%assetDef.assetName)) + { + exec(%assetDef.GUIFilePath); + exec(%assetDef.mScriptFilePath); + } + + GuiEditContent(%assetDef.assetName); +} + +function AssetBrowser::buildGUIAssetPreview(%this, %assetDef, %previewData) +{ + %previewData.assetName = %assetDef.assetName; + %previewData.assetPath = %assetDef.GUIFilePath; + %previewData.doubleClickCommand = ""; + + %previewData.previewImage = "tools/assetBrowser/art/guiIcon"; + + %previewData.assetFriendlyName = %assetDef.assetName; + %previewData.assetDesc = %assetDef.description; + %previewData.tooltip = %assetDef.assetName; +} \ No newline at end of file diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.cs new file mode 100644 index 0000000000..4270711d58 --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/image.cs @@ -0,0 +1,163 @@ +function AssetBrowser::prepareImportImageAsset(%this, %assetItem) +{ + if(ImportAssetWindow.activeImportConfig.GenerateMaterialOnImport == 1 && %assetItem.parentAssetItem $= "") + { + //First, see if this already has a suffix of some sort based on our import config logic. Many content pipeline tools like substance automatically appends them + %foundSuffixType = ImportAssetWindow.parseImageSuffixes(%assetItem); + + if(%foundSuffixType $= "") + { + %noSuffixName = %assetItem.AssetName; + } + else + { + %suffixPos = strpos(strlwr(%assetItem.AssetName), strlwr(%assetItem.imageSuffixType), 0); + %noSuffixName = getSubStr(%assetItem.AssetName, 0, %suffixPos); + } + + //Check if our material already exists + //First, lets double-check that we don't already have an + %materialAsset = AssetBrowser.doesAssetItemAlreadyExist(%noSuffixName); + if(%materialAsset == 0) + { + %filePath = %assetItem.filePath; + if(%filePath !$= "") + %materialAsset = AssetBrowser.addImportingAsset("Material", "", "", %noSuffixName); + } + + if(isObject(%materialAsset)) + { + //Establish parentage + %itemId = ImportAssetTree.findItemByObjectId(%assetItem); + %materialItemId = ImportAssetTree.findItemByObjectId(%materialAsset); + + %assetItem.parentId = %materialItemId; + + ImportAssetTree.reparentItem(%itemId, %materialItemId); + + ImportAssetTree.buildVisibleTree(true); + } + + //Lets do some cleverness here. If we're generating a material we can parse like assets being imported(similar file names) but different suffixes + //if we find these, we'll just populate into the original's material + + //If we need to append the diffuse suffix and indeed didn't find a suffix on the name, do that here + if(ImportAssetWindow.activeImportConfig.UseDiffuseSuffixOnOriginImg == 1) + { + if(%foundSuffixType $= "") + { + %diffuseToken = getToken(ImportAssetWindow.activeImportConfig.DiffuseTypeSuffixes, ",", 0); + %assetItem.AssetName = %assetItem.AssetName @ %diffuseToken; + + if(ImportAssetWindow.activeImportConfig.PopulateMaterialMaps == 1) + %materialAsset.diffuseImageAsset = %assetItem; + } + else if(%foundSuffixType !$= "") + { + //otherwise, if we have some sort of suffix, we'll want to figure out if we've already got an existing material, and should append to it + + if(ImportAssetWindow.activeImportConfig.PopulateMaterialMaps == 1) + { + if(%foundSuffixType $= "diffuse") + %materialAsset.diffuseImageAsset = %assetItem; + else if(%foundSuffixType $= "normal") + %materialAsset.normalImageAsset = %assetItem; + else if(%foundSuffixType $= "metalness") + %materialAsset.metalnessImageAsset = %assetItem; + else if(%foundSuffixType $= "roughness") + %materialAsset.roughnessImageAsset = %assetItem; + else if(%foundSuffixType $= "specular") + %materialAsset.specularImageAsset = %assetItem; + else if(%foundSuffixType $= "AO") + %materialAsset.AOImageAsset = %assetItem; + else if(%foundSuffixType $= "composite") + %materialAsset.compositeImageAsset = %assetItem; + } + } + } + else + { + //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 + //we'll give it a generic one + if(%materialAsset.assetName $= %assetItem.assetName) + { + %assetItem.AssetName = %assetItem.AssetName @ "_image"; + } + } + + %assetItem.processed = true; + } +} + +function AssetBrowser::importImageAsset(%this, %assetItem) +{ + %moduleName = ImportAssetModuleList.getText(); + + %assetType = %assetItem.AssetType; + %filePath = %assetItem.filePath; + %assetName = %assetItem.assetName; + %assetImportSuccessful = false; + %assetId = %moduleName@":"@%assetName; + + %assetPath = "data/" @ %moduleName @ "/Images"; + %assetFullPath = %assetPath @ "/" @ fileName(%filePath); + + %newAsset = new ImageAsset() + { + assetName = %assetName; + versionId = 1; + imageFile = fileName(%filePath); + originalFilePath = %filePath; + }; + + %assetImportSuccessful = TAMLWrite(%newAsset, %assetPath @ "/" @ %assetName @ ".asset.taml"); + + //and copy the file into the relevent directory + %doOverwrite = !AssetBrowser.isAssetReImport; + if(!pathCopy(%filePath, %assetFullPath, %doOverwrite)) + { + error("Unable to import asset: " @ %filePath); + return; + } + + %moduleDef = ModuleDatabase.findModule(%moduleName,1); + + if(!AssetBrowser.isAssetReImport) + AssetDatabase.addDeclaredAsset(%moduleDef, %assetPath @ "/" @ %assetName @ ".asset.taml"); + else + AssetDatabase.refreshAsset(%assetId); +} + +function AssetBrowser::buildImageAssetPreview(%this, %assetDef, %previewData) +{ + %previewData.assetName = %assetDef.assetName; + %previewData.assetPath = %assetDef.scriptFile; + //%previewData.doubleClickCommand = "EditorOpenFileInTorsion( "@%previewData.assetPath@", 0 );"; + + if(isFile(%assetDef.imageFile)) + %previewData.previewImage = %assetDef.imageFile; + else + %previewData.previewImage = "core/rendering/images/unavailable"; + + %previewData.assetFriendlyName = %assetDef.assetName; + %previewData.assetDesc = %assetDef.description; + %previewData.tooltip = %assetDef.friendlyName @ "\n" @ %assetDef; +} + +function GuiInspectorTypeImageAssetPtr::onControlDropped( %this, %payload, %position ) +{ + Canvas.popDialog(EditorDragAndDropLayer); + + // Make sure this is a color swatch drag operation. + if( !%payload.parentGroup.isInNamespaceHierarchy( "AssetPreviewControlType_AssetDrop" ) ) + return; + + %assetType = %payload.dragSourceControl.parentGroup.assetType; + + if(%assetType $= "ImageAsset") + { + echo("DROPPED A IMAGE ON AN IMAGE ASSET COMPONENT FIELD!"); + } + + EWorldEditor.isDirty = true; +} \ No newline at end of file diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/level.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/level.cs new file mode 100644 index 0000000000..ba8b92b5a0 --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/level.cs @@ -0,0 +1,62 @@ +function AssetBrowser::createLevelAsset(%this) +{ + %moduleName = AssetBrowser.newAssetSettings.moduleName; + %modulePath = "data/" @ %moduleName; + + %assetName = AssetBrowser.newAssetSettings.assetName; + + %tamlpath = %modulePath @ "/levels/" @ %assetName @ ".asset.taml"; + %levelPath = %modulePath @ "/levels/" @ %assetName @ ".mis"; + + %asset = new LevelAsset() + { + AssetName = %assetName; + versionId = 1; + LevelFile = %assetName @ ".mis"; + LevelName = AssetBrowser.newAssetSettings.levelName; + AssetDescription = AssetBrowser.newAssetSettings.description; + PreviewImage = AssetBrowser.newAssetSettings.levelPreviewImage; + }; + + TamlWrite(%asset, %tamlpath); + + if(!pathCopy("tools/levels/BlankRoom.mis", %levelPath, false)) + { + echo("Unable to copy template level file!"); + } + + %moduleDef = ModuleDatabase.findModule(%moduleName, 1); + AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath); + + AssetBrowser.loadFilters(); + + %treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName); + %smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "Levels"); + + AssetBrowserFilterTree.onSelect(%smItem); + + return %tamlpath; +} + +function AssetBrowser::editLevelAsset(%this, %assetDef) +{ + schedule( 1, 0, "EditorOpenMission", %assetDef); +} + +function AssetBrowser::buildLevelAssetPreview(%this, %assetDef, %previewData) +{ + %previewData.assetName = %assetDef.assetName; + %previewData.assetPath = %assetDef.levelFile; + %previewData.doubleClickCommand = "schedule( 1, 0, \"EditorOpenMission\", "@%assetDef@");"; + + %levelPreviewImage = %assetDesc.PreviewImage; + + if(isFile(%levelPreviewImage)) + %previewData.previewImage = %levelPreviewImage; + else + %previewData.previewImage = "tools/assetBrowser/art/levelIcon"; + + %previewData.assetFriendlyName = %assetDef.assetName; + %previewData.assetDesc = %assetDef.description; + %previewData.tooltip = %assetDef.assetName; +} \ No newline at end of file diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.cs new file mode 100644 index 0000000000..3f0f64b3d4 --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/material.cs @@ -0,0 +1,468 @@ +function AssetBrowser::createMaterialAsset(%this) +{ + %assetName = AssetBrowser.newAssetSettings.assetName; + + %moduleName = AssetBrowser.newAssetSettings.moduleName; + %modulePath = "data/" @ %moduleName; + + %tamlpath = %modulePath @ "/materials/" @ %assetName @ ".asset.taml"; + %sgfPath = %modulePath @ "/materials/" @ %assetName @ ".sgf"; + + %asset = new MaterialAsset() + { + AssetName = %assetName; + versionId = 1; + shaderData = ""; + shaderGraph = %sgfPath; + }; + + TamlWrite(%asset, %tamlpath); + + %moduleDef = ModuleDatabase.findModule(%moduleName, 1); + AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath); + + AssetBrowser.loadFilters(); + + %treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName); + %smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "Materials"); + + AssetBrowserFilterTree.onSelect(%smItem); + + return %tamlpath; +} + +function AssetBrowser::editMaterialAsset(%this, %assetDef) +{ + //if(EditorSettings.materialEditMode $= "MaterialEditor") + //{ + %assetDef.materialDefinitionName.reload(); + + EditorGui.setEditor(MaterialEditorPlugin); + + MaterialEditorGui.currentMaterial = %assetDef.materialDefinitionName; + MaterialEditorGui.setActiveMaterial( %assetDef.materialDefinitionName ); + + AssetBrowser.hideDialog(); + /*} + else + { + Canvas.pushDialog(ShaderEditor); + ShaderEditorGraph.loadGraph(%assetDef.shaderGraph); + $ShaderGen::targetShaderFile = filePath(%assetDef.shaderGraph) @"/"@fileBase(%assetDef.shaderGraph); + //} */ +} + +function AssetBrowser::prepareImportMaterialAsset(%this, %assetItem) +{ + //Iterate over to find appropriate images for + + //Fetch just the fileBase name + %fileDir = filePath(%assetItem.filePath); + %fileName = fileBase(%assetItem.filePath); + %fileExt = fileExt(%assetItem.filePath); + + //Check if we need to filter this material out or not + if(ImportAssetWindow.activeImportConfig.IgnoreMaterials !$= "") + { + %ignoredMatNamesCount = getTokenCount(ImportAssetWindow.activeImportConfig.IgnoreMaterials, ",;"); + for(%i=0; %i < %ignoredMatNamesCount; %i++) + { + %ignoreName = getToken(ImportAssetWindow.activeImportConfig.IgnoreMaterials, ".;", %i); + + if(strIsMatchExpr(%ignoreName, %fileName)) + { + //We fit the bill, ignore this material and skip it + %assetItem.skip = true; + return; + } + } + } + + if(ImportAssetWindow.activeImportConfig.PopulateMaterialMaps == 1) + { + %materialItemId = ImportAssetTree.findItemByObjectId(%assetItem); + + if(%assetItem.diffuseImageAsset $= "") + { + //First, load our diffuse map, as set to the material in the shape + //We're going to presume(for now) that the specifically-mentioned file for a given material is the diffuse/albedo + %diffuseImagePath = %fileDir @ "/" @ %filename @ %fileExt; + + %diffuseImageSuffix = ImportAssetWindow.parseImagePathSuffixes(%diffuseImagePath); + + + + if(ImportAssetWindow.activeImportConfig.UseDiffuseSuffixOnOriginImg == 1 && %diffuseImageSuffix $= "") + { + %diffuseToken = getToken(ImportAssetWindow.activeImportConfig.DiffuseTypeSuffixes, ",;", 0); + + %diffuseAsset = AssetBrowser.addImportingAsset("Image", %diffuseImagePath, %materialItemId, %filename @ %diffuseToken); + } + else + { + %diffuseAsset = AssetBrowser.addImportingAsset("Image", %diffuseImagePath, %materialItemId); + } + + %assetItem.diffuseImageAsset = %diffuseAsset; + } + + //Now, iterate over our comma-delimited suffixes to see if we have any matches. We'll use the first match in each case, if any. + if(%assetItem.normalImageAsset $= "") + { + //First, normal map + %targetFilePath = %this.findMaterialMapFileWSuffix(%fileDir, %fileName, %fileExt, ImportAssetWindow.activeImportConfig.NormalTypeSuffixes); + + if(%targetFilePath $= "") + { + //Didn't find it for the presumed file path, so lets angle it from the diffuse map's texture name, if it has one + if(isObject(%assetItem.diffuseImageAsset)) + { + if(isFile(%assetItem.diffuseImageAsset.filePath)) + { + %diffFileDir = filePath(%assetItem.diffuseImageAsset.filePath); + %diffFileName = fileBase(%assetItem.diffuseImageAsset.filePath); + %diffFileExt = fileExt(%assetItem.diffuseImageAsset.filePath); + + %suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.DiffuseTypeSuffixes, ",;"); + for(%sfx = 0; %sfx < %suffixCount; %sfx++) + { + %suffixToken = getToken(ImportAssetWindow.activeImportConfig.DiffuseTypeSuffixes, ",;", %sfx); + if(strIsMatchExpr("*"@%suffixToken, %diffFileName)) + { + %diffFileName = strreplace(%diffFileName, %suffixToken, ""); + break; + } + } + + %targetFilePath = %this.findMaterialMapFileWSuffix(%diffFileDir, %diffFileName, %diffFileExt, ImportAssetWindow.activeImportConfig.NormalTypeSuffixes); + } + } + } + + if(%targetFilePath !$= "") + { + %normalAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %materialItemId); + %assetItem.normalImageAsset = %normalAsset; + } + } + if(%assetItem.specularImageAsset $= "") + { + //Specular + %listCount = getTokenCount(ImportAssetWindow.activeImportConfig.SpecularTypeSuffixes, ",;"); + + %foundFile = 0; + for(%i=0; %i < %listCount; %i++) + { + %entryText = getToken(ImportAssetWindow.activeImportConfig.SpecularTypeSuffixes, ",;", %i); + + %targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt; + %foundFile = isFile(%targetFilePath); + + if(%foundFile) + { + %specularAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %materialItemId); + %assetItem.specularImageAsset = %specularAsset; + break; + } + } + } + + if(%assetItem.metalImageAsset $= "") + { + //Metal + %listCount = getTokenCount(ImportAssetWindow.activeImportConfig.MetalnessTypeSuffixes, ",;"); + + %foundFile = 0; + for(%i=0; %i < %listCount; %i++) + { + %entryText = getToken(ImportAssetWindow.activeImportConfig.MetalnessTypeSuffixes, ",;", %i); + + %targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt; + %foundFile = isFile(%targetFilePath); + + if(%foundFile) + { + %metalAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %materialItemId); + %assetItem.metalImageAsset = %metalAsset; + break; + } + } + } + + if(%assetItem.roughnessImageAsset $= "") + { + //Roughness + %listCount = getTokenCount(ImportAssetWindow.activeImportConfig.RoughnessTypeSuffixes, ",;"); + + %foundFile = 0; + for(%i=0; %i < %listCount; %i++) + { + %entryText = getToken(ImportAssetWindow.activeImportConfig.RoughnessTypeSuffixes, ",;", %i); + + %targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt; + %foundFile = isFile(%targetFilePath); + + if(%foundFile) + { + %roughnessAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %materialItemId); + %assetItem.roughnessImageAsset = %roughnessAsset; + break; + } + } + } + + if(%assetItem.smoothnessImageAsset $= "") + { + //Smoothness + %listCount = getTokenCount(ImportAssetWindow.activeImportConfig.SmoothnessTypeSuffixes, ",;"); + + %foundFile = 0; + for(%i=0; %i < %listCount; %i++) + { + %entryText = getToken(ImportAssetWindow.activeImportConfig.SmoothnessTypeSuffixes, ",;", %i); + + %targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt; + %foundFile = isFile(%targetFilePath); + + if(%foundFile) + { + %smoothnessAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %materialItemId); + %assetItem.SmoothnessImageAsset = %smoothnessAsset; + break; + } + } + } + + if(%assetItem.AOImageAsset $= "") + { + //AO + %listCount = getTokenCount(ImportAssetWindow.activeImportConfig.AOTypeSuffixes, ",;"); + + %foundFile = 0; + for(%i=0; %i < %listCount; %i++) + { + %entryText = getToken(ImportAssetWindow.activeImportConfig.AOTypeSuffixes, ",;", %i); + + %targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt; + %foundFile = isFile(%targetFilePath); + + if(%foundFile) + { + %AOAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %materialItemId); + %assetItem.AOImageAsset = %AOAsset; + break; + } + } + } + + if(%assetItem.compositeImageAsset $= "") + { + //Composite + %listCount = getTokenCount(ImportAssetWindow.activeImportConfig.CompositeTypeSuffixes, ",;"); + + %foundFile = 0; + for(%i=0; %i < %listCount; %i++) + { + %entryText = getToken(ImportAssetWindow.activeImportConfig.CompositeTypeSuffixes, ",;", %i); + + %targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt; + %foundFile = isFile(%targetFilePath); + + if(%foundFile) + { + %compositeAsset = AssetBrowser.addImportingAsset("Image", %targetFilePath, %materialItemId); + %assetItem.compositeImageAsset = %compositeAsset; + break; + } + } + } + } +} + +function AssetBrowser::findMaterialMapFileWSuffix(%this, %fileDir, %filename, %fileExt, %suffixList) +{ + //Now, iterate over our comma-delimited suffixes to see if we have any matches. We'll use the first match in each case, if any. + //First, normal map + %listCount = getTokenCount(%suffixList, ",;"); + + %foundFile = 0; + for(%i=0; %i < %listCount; %i++) + { + %entryText = getToken(%suffixList, ",;", %i); + + %targetFilePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt; + %foundFile = isFile(%targetFilePath); + + if(%foundFile) + { + return %targetFilePath; + break; + } + } + + return ""; +} + +function AssetBrowser::importMaterialAsset(%this, %assetItem) +{ + %moduleName = ImportAssetModuleList.getText(); + + %assetType = %assetItem.AssetType; + %filePath = %assetItem.filePath; + %assetName = %assetItem.assetName; + %assetImportSuccessful = false; + %assetId = %moduleName@":"@%assetName; + + %assetPath = "data/" @ %moduleName @ "/materials"; + %tamlpath = %assetPath @ "/" @ %assetName @ ".asset.taml"; + %sgfPath = %assetPath @ "/" @ %assetName @ ".sgf"; + %scriptPath = %assetPath @ "/" @ %assetName @ ".cs"; + + %newAsset = new MaterialAsset() + { + assetName = %assetName; + versionId = 1; + shaderGraph = %sgfPath; + scriptFile = %scriptPath; + originalFilePath = %filePath; + materialDefinitionName = %assetName; + }; + + //check dependencies + %importItem = ImportAssetTree.findItemByObjectId(%assetItem); + if(ImportAssetTree.isParentItem(%importItem)) + { + %imageSlot = 0; + %childId = ImportAssetTree.getChild(%importItem); + while(%childId > 0) + { + %dependencyAssetItem = ImportAssetTree.getItemObject(%childId); + + %depAssetType = %dependencyAssetItem.assetType; + if(%depAssetType $= "Image") + { + %matSet = "%newAsset.imageMap"@%imageSlot@"=\"@Asset="@%moduleName@":"@%dependencyAssetItem.assetName@"\";"; + eval(%matSet); + } + + %childId = ImportAssetTree.getNextSibling(%childId); + %imageSlot++; + } + } + + %assetImportSuccessful = TamlWrite(%newAsset, %tamlpath); + + %file = new FileObject(); + + if(%file.openForWrite(%scriptPath)) + { + %file.writeline("//--- OBJECT WRITE BEGIN ---"); + %file.writeline("singleton Material(" @ %assetName @ ") {"); + + //TODO: pass along the shape's target material for this just to be sure + %file.writeLine(" mapTo = \"" @ %assetName @ "\";"); + + if(%assetItem.diffuseImageAsset !$= "") + { + %diffuseAssetPath = "data/" @ %moduleName @ "/Images/" @ fileName(%assetItem.diffuseImageAsset.filePath); + %file.writeline(" DiffuseMap[0] = \"" @ %diffuseAssetPath @"\";"); + %file.writeline(" DiffuseMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.diffuseImageAsset.assetName @"\";"); + } + if(%assetItem.normalImageAsset) + { + %normalAssetPath = "data/" @ %moduleName @ "/Images/" @ fileName(%assetItem.normalImageAsset.filePath); + %file.writeline(" NormalMap[0] = \"" @ %normalAssetPath @"\";"); + %file.writeline(" NormalMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.normalImageAsset.assetName @"\";"); + } + /*if(%assetItem.specularImageAsset) + { + %file.writeline(" SpecularMap[0] = \"" @ %assetItem.specularImageAsset.filePath @"\";"); + %file.writeline(" SpecularMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.specularImageAsset.assetName @"\";"); + }*/ + if(%assetItem.roughnessImageAsset) + { + %file.writeline(" RoughMap[0] = \"" @ %assetItem.roughnessImageAsset.filePath @"\";"); + %file.writeline(" RoughMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.roughnessImageAsset.assetName @"\";"); + } + if(%assetItem.smoothnessImageAsset) + { + %file.writeline(" SmoothnessMap[0] = \"" @ %assetItem.smoothnessImageAsset.filePath @"\";"); + %file.writeline(" SmoothnessMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.smoothnessImageAsset.assetName @"\";"); + } + if(%assetItem.metalnessImageAsset) + { + %file.writeline(" MetalMap[0] = \"" @ %assetItem.metalnessImageAsset.filePath @"\";"); + %file.writeline(" MetalMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.metalnessImageAsset.assetName @"\";"); + } + if(%assetItem.AOImageAsset) + { + %file.writeline(" AOMap[0] = \"" @ %assetItem.AOImageAsset.filePath @"\";"); + %file.writeline(" AOMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.AOImageAsset.assetName @"\";"); + } + if(%assetItem.compositeImageAsset) + { + %file.writeline(" CompositeMap[0] = \"" @ %assetItem.compositeImageAsset.filePath @"\";"); + %file.writeline(" CompositeMapAsset[0] = \"" @ %moduleName @ ":" @ %assetItem.compositeImageAsset.assetName @"\";"); + } + %file.writeline("};"); + %file.writeline("//--- OBJECT WRITE END ---"); + + %file.close(); + } + + %moduleDef = ModuleDatabase.findModule(%moduleName,1); + + if(!AssetBrowser.isAssetReImport) + AssetDatabase.addDeclaredAsset(%moduleDef, %assetPath @ "/" @ %assetName @ ".asset.taml"); + else + AssetDatabase.refreshAsset(%assetId); +} + +function AssetBrowser::buildMaterialAssetPreview(%this, %assetDef, %previewData) +{ + %previewData.assetName = %assetDef.materialDefinitionName; + %previewData.assetPath = %assetDef.scriptFile; + + //Lotta prepwork + %previewData.doubleClickCommand = %assetDef@".materialDefinitionName.reload(); " + @ "$Tools::materialEditorList = \"\";" + @ "EWorldEditor.clearSelection();" + @ "MaterialEditorGui.currentObject = 0;" + @ "MaterialEditorGui.currentMode = \"asset\";" + @ "MaterialEditorGui.currentMaterial = "@%assetDef@".materialDefinitionName;" + @ "MaterialEditorGui.setActiveMaterial( "@%assetDef@".materialDefinitionName );" + @ "EditorGui.setEditor(MaterialEditorPlugin); " + @ "AssetBrowser.hideDialog();"; + + if(isFile(%assetDef.materialDefinitionName.diffuseMap[0])) + %previewData.previewImage = %assetDef.materialDefinitionName.diffuseMap[0]; + else + %previewData.previewImage = "tools/assetBrowser/art/materialIcon"; + + %previewData.assetFriendlyName = %assetDef.assetName; + %previewData.assetDesc = %assetDef.description; + %previewData.tooltip = %assetDef.friendlyName @ "\n" @ %assetDef; +} + +function GuiInspectorTypeMaterialAssetPtr::onControlDropped( %this, %payload, %position ) +{ + Canvas.popDialog(EditorDragAndDropLayer); + + // Make sure this is a color swatch drag operation. + if( !%payload.parentGroup.isInNamespaceHierarchy( "AssetPreviewControlType_AssetDrop" ) ) + return; + + %assetType = %payload.dragSourceControl.parentGroup.assetType; + %module = %payload.dragSourceControl.parentGroup.moduleName; + %assetName = %payload.dragSourceControl.parentGroup.assetName; + + if(%assetType $= "MaterialAsset") + { + echo("DROPPED A MATERIAL ON A MATERIAL ASSET COMPONENT FIELD!"); + //%assetDef = AssetDatabase.acquireAsset(%module @ ":" @ %assetName); + + %this.setMaterialAsset(%module @ ":" @ %assetName); + } + + EWorldEditor.isDirty = true; +} diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/particle.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/particle.cs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/postFX.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/postFX.cs new file mode 100644 index 0000000000..7eb23bd34e --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/postFX.cs @@ -0,0 +1,51 @@ +function AssetBrowser::createPostEffectAsset(%this) +{ + %moduleName = AssetBrowser.newAssetSettings.moduleName; + %modulePath = "data/" @ %moduleName; + + %assetName = AssetBrowser.newAssetSettings.assetName; + + %tamlpath = %modulePath @ "/postFXs/" @ %assetName @ ".asset.taml"; + %scriptPath = %modulePath @ "/postFXs/" @ %assetName @ ".cs"; + + %asset = new PostEffectAsset() + { + AssetName = %assetName; + versionId = 1; + scriptFile = %assetName @ ".cs"; + }; + + TamlWrite(%asset, %tamlpath); + + %moduleDef = ModuleDatabase.findModule(%moduleName, 1); + AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath); + + AssetBrowser.loadFilters(); + + %treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName); + %smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "PostEffectAsset"); + + AssetBrowserFilterTree.onSelect(%smItem); + + %file = new FileObject(); + + if(%file.openForWrite(%scriptPath)) + { + %file.close(); + } + + return %tamlpath; +} + +function AssetBrowser::buildPostEffectAssetPreview(%this, %assetDef, %previewData) +{ + %previewData.assetName = %assetDef.assetName; + %previewData.assetPath = %assetDef.scriptFilePath; + %previewData.doubleClickCommand = ""; + + %previewData.previewImage = "tools/assetBrowser/art/postEffectIcon"; + + %previewData.assetFriendlyName = %assetDef.assetName; + %previewData.assetDesc = %assetDef.description; + %previewData.tooltip = %assetDef.assetName; +} \ No newline at end of file diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/script.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/script.cs new file mode 100644 index 0000000000..a11373a201 --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/script.cs @@ -0,0 +1,89 @@ +function AssetBrowser::createScriptAsset(%this) +{ + %moduleName = AssetBrowser.newAssetSettings.moduleName; + %modulePath = "data/" @ %moduleName; + + %assetName = AssetBrowser.newAssetSettings.assetName; + + %tamlpath = %modulePath @ "/scripts/" @ %assetName @ ".asset.taml"; + %scriptPath = %modulePath @ "/scripts/" @ %assetName @ ".cs"; + + %asset = new ScriptAsset() + { + AssetName = %assetName; + versionId = 1; + scriptFile = %assetName @ ".cs"; + }; + + TamlWrite(%asset, %tamlpath); + + %moduleDef = ModuleDatabase.findModule(%moduleName, 1); + AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath); + + AssetBrowser.loadFilters(); + + %treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName); + %smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "ScriptAsset"); + + AssetBrowserFilterTree.onSelect(%smItem); + + %file = new FileObject(); + + if(%file.openForWrite(%scriptPath)) + { + %file.close(); + } + + return %tamlpath; +} + +function AssetBrowser::editScriptAsset(%this, %assetDef) +{ + %scriptFile = %assetDef.scriptFile; + + EditorOpenFileInTorsion(makeFullPath(%scriptFile), 0); +} + +function AssetBrowser::duplicateScriptAsset(%this, %assetDef, %targetModule) +{ +} + +function AssetBrowser::importScriptAsset(%this, %assetId) +{ +} + +function AssetBrowser::dragAndDropScriptAsset(%this, %assetDef, %dropTarget) +{ + if(!isObject(%dropTarget)) + return; +} + +function AssetBrowser::renameScriptAsset(%this, %assetDef, %originalName, %newName) +{ +} + +function AssetBrowser::deleteScriptAsset(%this, %assetDef) +{ +} + +function AssetBrowser::buildScriptAssetPreview(%this, %assetDef, %previewData) +{ + %previewData.assetName = %assetDef.assetName; + %previewData.assetPath = %assetDef.scriptFile; + %previewData.doubleClickCommand = "EditorOpenFileInTorsion( \""@%previewData.assetPath@"\", 0 );"; + + if(%assetDef.isServerSide) + %previewData.previewImage = "tools/assetBrowser/art/serverScriptIcon"; + else + %previewData.previewImage = "tools/assetBrowser/art/clientScriptIcon"; + + %previewData.assetFriendlyName = %assetDef.assetName; + %previewData.assetDesc = %assetDef.description; + %previewData.tooltip = %assetDef.assetName; +} + +function GuiInspectorTypeScriptAssetPtr::onClick( %this, %fieldName ) +{ + //Get our data + %obj = %this.getInspector().getInspectObject(0); +} \ No newline at end of file diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.cs new file mode 100644 index 0000000000..c3d7ad0934 --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shape.cs @@ -0,0 +1,266 @@ +function AssetBrowser::createShapeAsset(%this) +{ + %moduleName = AssetBrowser.newAssetSettings.moduleName; + %modulePath = "data/" @ %moduleName; + + %assetName = AssetBrowser.newAssetSettings.assetName; + + %tamlpath = %modulePath @ "/shapes/" @ %assetName @ ".asset.taml"; + %shapeFilePath = %modulePath @ "/shapes/" @ %assetName @ ".dae"; + + %asset = new ShapeAsset() + { + AssetName = %assetName; + versionId = 1; + friendlyName = AssetBrowser.newAssetSettings.friendlyName; + description = AssetBrowser.newAssetSettings.description; + fileName = %assetName @ ".dae"; + }; + + TamlWrite(%asset, %tamlpath); + + Canvas.popDialog(AssetBrowser_newComponentAsset); + + %moduleDef = ModuleDatabase.findModule(%moduleName, 1); + AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath); + + AssetBrowser.loadFilters(); + + %treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName); + %smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "ShapeAsset"); + + AssetBrowserFilterTree.onSelect(%smItem); + + return %tamlpath; +} + +function AssetBrowser::editShapeAsset(%this, %assetDef) +{ + %this.hideDialog(); + ShapeEditorPlugin.openShapeAsset(%assetDef); +} + +function AssetBrowser::prepareImportShapeAsset(%this, %assetItem) +{ + %fileExt = fileExt(%assetItem.filePath); + if(%fileExt $= ".dae") + { + %shapeInfo = new GuiTreeViewCtrl(); + enumColladaForImport(%assetItem.filePath, %shapeInfo, false); + } + else + { + %shapeInfo = GetShapeInfo(%assetItem.filePath); + } + + %assetItem.shapeInfo = %shapeInfo; + + %shapeItem = %assetItem.shapeInfo.findItemByName("Shape"); + %shapeCount = %assetItem.shapeInfo.getItemValue(%shapeItem); + + %shapeId = ImportAssetTree.findItemByObjectId(%assetItem); + + if(ImportAssetWindow.activeImportConfig.ImportMesh == 1 && %shapeCount > 0) + { + + } + + %animItem = %assetItem.shapeInfo.findItemByName("Animations"); + %animCount = %assetItem.shapeInfo.getItemValue(%animItem); + + if(ImportAssetWindow.activeImportConfig.ImportAnimations == 1 && %animCount > 0) + { + /*%animationItem = %assetItem.shapeInfo.getChild(%animItem); + + %animName = %assetItem.shapeInfo.getItemText(%animationItem); + + AssetBrowser.addImportingAsset("Animation", %animName, %shapeId); + + %animationItem = %assetItem.shapeInfo.getNextSibling(%animationItem); + while(%animationItem != 0) + { + %animName = %assetItem.shapeInfo.getItemText(%animationItem); + //%animName = %assetItem.shapeInfo.getItemValue(%animationItem); + + AssetBrowser.addImportingAsset("Animation", %animName, %shapeId); + + %animationItem = %shapeInfo.getNextSibling(%animationItem); + }*/ + } + + %matItem = %assetItem.shapeInfo.findItemByName("Materials"); + %matCount = %assetItem.shapeInfo.getItemValue(%matItem); + + if(ImportAssetWindow.activeImportConfig.importMaterials == 1 && %matCount > 0) + { + + + %materialItem = %assetItem.shapeInfo.getChild(%matItem); + + %matName = %assetItem.shapeInfo.getItemText(%materialItem); + + %filePath = %assetItem.shapeInfo.getItemValue(%materialItem); + if(%filePath !$= "") + { + AssetBrowser.addImportingAsset("Material", %filePath, %shapeId); + } + else + { + //we need to try and find our material, since the shapeInfo wasn't able to find it automatically + %filePath = findImageFile(filePath(%assetItem.filePath), %matName); + if(%filePath !$= "") + AssetBrowser.addImportingAsset("Material", %filePath, %shapeId); + else + AssetBrowser.addImportingAsset("Material", %matName, %shapeId); + } + + %materialItem = %assetItem.shapeInfo.getNextSibling(%materialItem); + while(%materialItem != 0) + { + %matName = %assetItem.shapeInfo.getItemText(%materialItem); + %filePath = %assetItem.shapeInfo.getItemValue(%materialItem); + if(%filePath !$= "") + { + AssetBrowser.addImportingAsset("Material", %filePath, %shapeId); + } + else + { + //we need to try and find our material, since the shapeInfo wasn't able to find it automatically + %filePath = findImageFile(filePath(%assetItem.filePath), %matName); + if(%filePath !$= "") + AssetBrowser.addImportingAsset("Material", %filePath, %shapeId); + else + AssetBrowser.addImportingAsset("Material", %matName, %shapeId); + } + + %materialItem = %shapeInfo.getNextSibling(%materialItem); + } + } +} + +function AssetBrowser::importShapeAsset(%this, %assetItem) +{ + %moduleName = ImportAssetModuleList.getText(); + + %assetType = %assetItem.AssetType; + %filePath = %assetItem.filePath; + %assetName = %assetItem.assetName; + %assetImportSuccessful = false; + %assetId = %moduleName@":"@%assetName; + + %assetPath = "data/" @ %moduleName @ "/Shapes"; + %assetFullPath = %assetPath @ "/" @ fileName(%filePath); + + %newAsset = new ShapeAsset() + { + assetName = %assetName; + versionId = 1; + fileName = fileName(%filePath); + originalFilePath = %filePath; + isNewShape = true; + }; + + //check dependencies + %importItem = ImportAssetTree.findItemByObjectId(%assetItem); + if(ImportAssetTree.isParentItem(%importItem)) + { + %matSlotId = 0; + %childId = ImportAssetTree.getChild(%importItem); + while(%childId > 0) + { + %dependencyAssetItem = ImportAssetTree.getItemObject(%childId); + + %depAssetType = %dependencyAssetItem.assetType; + if(%depAssetType $= "Material") + { + %matSet = "%newAsset.materialSlot"@%matSlotId@"=\"@Asset="@%moduleName@":"@%dependencyAssetItem.assetName@"\";"; + eval(%matSet); + } + if(%depAssetType $= "Animation") + { + %matSet = "%newAsset.animationSequence"@%matSlotId@"=\"@Asset="@%moduleName@":"@%dependencyAssetItem.assetName@"\";"; + eval(%matSet); + } + + %childId = ImportAssetTree.getNextSibling(%childId); + %matSlotId++; + } + } + + %assetImportSuccessful = TAMLWrite(%newAsset, %assetPath @ "/" @ %assetName @ ".asset.taml"); + + //and copy the file into the relevent directory + %doOverwrite = !AssetBrowser.isAssetReImport; + if(!pathCopy(%filePath, %assetFullPath, %doOverwrite)) + { + error("Unable to import asset: " @ %filePath); + } + + %constructor = ShapeEditor.findConstructor( %assetFullPath ); + + if(!isObject(%constructor)) + %constructor = ShapeEditor.createConstructor(%assetFullPath); + + //We'll update any relevent bits to the ShapeConstructor here + $TSShapeConstructor::neverImportMat = ""; + + if(ImportAssetWindow.activeImportConfig.IgnoreMaterials !$= "") + { + %ignoredMatNamesCount = getTokenCount(ImportAssetWindow.activeImportConfig.IgnoreMaterials, ",;"); + for(%i=0; %i < %ignoredMatNamesCount; %i++) + { + if(%i==0) + $TSShapeConstructor::neverImportMat = getToken(ImportAssetWindow.activeImportConfig.IgnoreMaterials, ",;", %i); + else + $TSShapeConstructor::neverImportMat = $TSShapeConstructor::neverImportMat TAB getToken(ImportAssetWindow.activeImportConfig.IgnoreMaterials, ",;", %i); + } + } + + %constructor.neverImportMat = $TSShapeConstructor::neverImportMat; + ShapeEditor.saveConstructor( %constructor ); + + //now, force-load the file if it's collada + %fileExt = fileExt(%assetFullPath); + if(isSupportedFormat(getSubStr(%fileExt,1))) + { + %tempShape = new TSStatic() + { + shapeName = %assetFullPath; + }; + + %tempShape.delete(); + } + + %moduleDef = ModuleDatabase.findModule(%moduleName,1); + + if(!AssetBrowser.isAssetReImport) + AssetDatabase.addDeclaredAsset(%moduleDef, %assetPath @ "/" @ %assetName @ ".asset.taml"); + else + AssetDatabase.refreshAsset(%assetId); +} + +function GuiInspectorTypeShapeAssetPtr::onControlDropped( %this, %payload, %position ) +{ + Canvas.popDialog(EditorDragAndDropLayer); + + // Make sure this is a color swatch drag operation. + if( !%payload.parentGroup.isInNamespaceHierarchy( "AssetPreviewControlType_AssetDrop" ) ) + return; + + %assetType = %payload.dragSourceControl.parentGroup.assetType; + + if(%assetType $= "ShapeAsset") + { + echo("DROPPED A SHAPE ON A SHAPE ASSET COMPONENT FIELD!"); + + %module = %payload.dragSourceControl.parentGroup.moduleName; + %asset = %payload.dragSourceControl.parentGroup.assetName; + + %targetComponent = %this.ComponentOwner; + %targetComponent.MeshAsset = %module @ ":" @ %asset; + + //Inspector.refresh(); + } + + EWorldEditor.isDirty= true; +} \ No newline at end of file diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shapeAnimation.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shapeAnimation.cs new file mode 100644 index 0000000000..1f418876bf --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/shapeAnimation.cs @@ -0,0 +1,55 @@ +function AssetBrowser::createShapeAnimationAsset(%this) +{ + %dlg = new OpenFileDialog() + { + Filters = "Animation Files(*.dae, *.cached.dts)|*.dae;*.cached.dts"; + DefaultPath = $Pref::WorldEditor::LastPath; + DefaultFile = ""; + ChangePath = false; + OverwritePrompt = true; + forceRelativePath = false; + //MultipleFiles = true; + }; + + %ret = %dlg.Execute(); + + if ( %ret ) + { + $Pref::WorldEditor::LastPath = filePath( %dlg.FileName ); + %fullPath = %dlg.FileName; + } + + %dlg.delete(); + + if ( !%ret ) + return; +} + +function AssetBrowser::editShapeAnimationAsset(%this, %assetDef) +{ + %this.hideDialog(); + ShapeEditorPlugin.openShapeAsset(%assetDef); +} + +function AssetBrowser::buildShapeAnimationAssetPreview(%this, %assetDef, %previewData) +{ + %previewData.assetName = %assetDef.animationName; + %previewData.assetPath = %assetDef.scriptFile; + + //Lotta prepwork + /*%previewData.doubleClickCommand = %assetDef@".materialDefinitionName.reload(); " + @ "$Tools::materialEditorList = \"\";" + @ "EWorldEditor.clearSelection();" + @ "MaterialEditorGui.currentObject = 0;" + @ "MaterialEditorGui.currentMode = \"asset\";" + @ "MaterialEditorGui.currentMaterial = "@%assetDef@".materialDefinitionName;" + @ "MaterialEditorGui.setActiveMaterial( "@%assetDef@".materialDefinitionName );" + @ "EditorGui.setEditor(MaterialEditorPlugin); " + @ "AssetBrowser.hideDialog();";*/ + + %previewData.previewImage = "tools/assetBrowser/art/animationIcon"; + + %previewData.assetFriendlyName = %assetDef.assetName; + %previewData.assetDesc = %assetDef.description; + %previewData.tooltip = %assetDef.friendlyName @ "\n" @ %assetDef; +} \ No newline at end of file diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/sound.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/sound.cs new file mode 100644 index 0000000000..7d3739cd5a --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/sound.cs @@ -0,0 +1,12 @@ +function AssetBrowser::buildSoundAssetPreview(%this, %assetDef, %previewData) +{ + %previewData.assetName = %assetDef.assetName; + %previewData.assetPath = %assetDef.soundFilePath; + //%previewData.doubleClickCommand = "EditorOpenFileInTorsion( "@%previewData.assetPath@", 0 );"; + + %previewData.previewImage = "tools/assetBrowser/art/soundIcon"; + + %previewData.assetFriendlyName = %assetDef.assetName; + %previewData.assetDesc = %assetDef.description; + %previewData.tooltip = %assetDef.assetName; +} \ No newline at end of file diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/stateMachine.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/stateMachine.cs new file mode 100644 index 0000000000..58ffbfecb0 --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetTypes/stateMachine.cs @@ -0,0 +1,173 @@ +function AssetBrowser::createStateMachineAsset(%this) +{ + %assetName = AssetBrowser.newAssetSettings.assetName; + %moduleName = AssetBrowser.selectedModule; + + %assetQuery = new AssetQuery(); + + %matchingAssetCount = AssetDatabase.findAssetName(%assetQuery, %assetName); + + %i=1; + while(%matchingAssetCount > 0) + { + %newAssetName = %assetName @ %i; + %i++; + + %matchingAssetCount = AssetDatabase.findAssetName(%assetQuery, %newAssetName); + } + + %assetName = %newAssetName; + + %assetQuery.delete(); + + %tamlpath = "data/" @ %moduleName @ "/stateMachines/" @ %assetName @ ".asset.taml"; + %smFilePath = "data/" @ %moduleName @ "/stateMachines/" @ %assetName @ ".xml"; + + %asset = new StateMachineAsset() + { + AssetName = %assetName; + versionId = 1; + stateMachineFile = %assetName @ ".xml"; + }; + + %xmlDoc = new SimXMLDocument(); + %xmlDoc.saveFile(%smFilePath); + %xmlDoc.delete(); + + TamlWrite(%asset, %tamlpath); + + //Now write our XML file + %xmlFile = new FileObject(); + %xmlFile.openForWrite(%smFilePath); + %xmlFile.writeLine(""); + %xmlFile.writeLine(""); + %xmlFile.close(); + + %moduleDef = ModuleDatabase.findModule(%moduleName, 1); + AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath); + + AssetBrowser.loadFilters(); + + %treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName); + %smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "StateMachines"); + + AssetBrowserFilterTree.onSelect(%smItem); + + return %tamlpath; +} + +function AssetBrowser::editStateMachineAsset(%this, %assetDef) +{ + eval("AssetBrowser.tempAsset = new " @ %assetDef.getClassName() @ "();"); + AssetBrowser.tempAsset.assignFieldsFrom(%assetDef); + + SMAssetEditInspector.inspect(AssetBrowser.tempAsset); + AssetBrowser_editAsset.editedAssetId = EditAssetPopup.assetId; + AssetBrowser_editAsset.editedAsset = AssetBrowser.tempAsset; + + //remove some of the groups we don't need: + for(%i=0; %i < SMAssetEditInspector.getCount(); %i++) + { + %caption = SMAssetEditInspector.getObject(%i).caption; + + if(%caption $= "Ungrouped" || %caption $= "Object" || %caption $= "Editing" + || %caption $= "Persistence" || %caption $= "Dynamic Fields") + { + SMAssetEditInspector.remove(SMAssetEditInspector.getObject(%i)); + %i--; + } + } + + Canvas.pushDialog(StateMachineEditor); + StateMachineEditor.loadStateMachineAsset(EditAssetPopup.assetId); + StateMachineEditor-->Window.text = "State Machine Editor ("@EditAssetPopup.assetId@")"; +} + +function AssetBrowser::duplicateStateMachineAsset(%this, %assetDef) +{ + //Check if we have a target module, if not we need to select one + if(%targetModule $= "") + { + error("AssetBrowser::duplicateStateMachineAsset - No target module selected!"); + return; + } + + %assetId = %assetDef.getAssetId(); + %assetName = AssetDatabase.getAssetName(%assetId); + + //First step, copy the files + %modulePath = "data/" @ %targetModule @ "/stateMachines/"; + + if(!isDirectory(%modulePath)) + createPath(%modulePath); + + %assetFile = AssetDatabase.getAssetFilePath(%assetId); + %stateMachineFile = %assetDef.stateMachineFile; + + echo("AssetBrowser::duplicateGameObjectAsset - duplicating! " @ %assetId @ " to " @ %targetModule); + + %tamlPath = %modulePath @ fileName(%assetFile); + + pathCopy(%assetFile, %tamlPath); + pathCopy(%stateMachineFile, %modulePath @ fileName(%stateMachineFile)); + + echo("AssetBrowser::duplicateStateMachineAsset - duplicated!"); + + //Register the asset + %moduleDef = ModuleDatabase.findModule(%targetModule, 1); + + AssetDatabase.addDeclaredAsset(%moduleDef, %tamlPath); + + //Refresh the browser + AssetBrowser.loadFilters(); + + //Ensure our context is set + %treeItemId = AssetBrowserFilterTree.findItemByName(%targetModule); + %smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "StateMachineAsset"); + + AssetBrowserFilterTree.selectItem(%smItem); + + //Rename it for convenience + AssetBrowser.performRenameAsset(%assetName, "New" @ %assetName); + + //Expand and refresh the target module + AssetBrowserFilterTree.expandItem(%treeItemId,true); + + AssetBrowserFilterTree.buildVisibleTree(); +} + +function AssetBrowser::renameGameObjectAsset(%this, %assetDef, %newAssetId, %originalName, %newName) +{ + %assetPath = AssetDatabase.getAssetFilePath(%newAssetId); + + //rename the file to match + %path = filePath(%assetPath); + + %oldScriptFilePath = %assetDef.stateMachineFile; + %scriptFilePath = filePath(%assetDef.stateMachineFile); + %scriptExt = fileExt(%assetDef.stateMachineFile); + + %newScriptFileName = %scriptFilePath @ "/" @ %newName @ %scriptExt; + %newAssetFile = %path @ "/" @ %newName @ ".asset.taml"; + + %assetDef.stateMachineFile = %newScriptFileName; + + TamlWrite(%assetDef, %newAssetFile); + fileDelete(%assetPath); + + pathCopy(%oldScriptFilePath, %newScriptFileName); + fileDelete(%oldScriptFilePath); +} + +function AssetBrowser::buildStateMachineAssetPreview(%this, %assetDef, %previewData) +{ + %previewData.assetName = %assetDef.assetName; + %previewData.assetPath = %assetDef.scriptFile; + %previewData.doubleClickCommand = "AssetBrowser.editStateMachineAsset( "@%assetDef@" );"; + + %previewData.previewImage = "tools/assetBrowser/art/stateMachineIcon"; + + %previewData.assetFriendlyName = %assetDef.friendlyName; + %previewData.assetDesc = %assetDef.description; + %previewData.tooltip = %assetDef.friendlyName @ "\n" @ %assetDef; +} \ No newline at end of file diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/editAsset.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/editAsset.cs index bc80f89775..b207f0c7a7 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/editAsset.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/editAsset.cs @@ -8,103 +8,26 @@ Canvas.popDialog(AssetBrowser_editAsset); } -function AssetBrowser::editAsset(%this) +function AssetBrowser::editAsset(%this, %assetDef) { //Find out what type it is - %assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId); - %assetType = %assetDef.getClassName(); - - if(%assetType $= "MaterialAsset") - { - //if(EditorSettings.materialEditMode $= "MaterialEditor") - //{ - %assetDef.materialDefinitionName.reload(); - - EditorGui.setEditor(MaterialEditorPlugin); - - MaterialEditorGui.currentMaterial = %assetDef.materialDefinitionName; - MaterialEditorGui.setActiveMaterial( %assetDef.materialDefinitionName ); - - AssetBrowser.hideDialog(); - /*} - else - { - Canvas.pushDialog(ShaderEditor); - ShaderEditorGraph.loadGraph(%assetDef.shaderGraph); - $ShaderGen::targetShaderFile = filePath(%assetDef.shaderGraph) @"/"@fileBase(%assetDef.shaderGraph); - }*/ - } - else if(%assetType $= "StateMachineAsset") - { - eval("AssetBrowser.tempAsset = new " @ %assetDef.getClassName() @ "();"); - AssetBrowser.tempAsset.assignFieldsFrom(%assetDef); - - SMAssetEditInspector.inspect(AssetBrowser.tempAsset); - AssetBrowser_editAsset.editedAssetId = EditAssetPopup.assetId; - AssetBrowser_editAsset.editedAsset = AssetBrowser.tempAsset; - - //remove some of the groups we don't need: - for(%i=0; %i < SMAssetEditInspector.getCount(); %i++) - { - %caption = SMAssetEditInspector.getObject(%i).caption; - - if(%caption $= "Ungrouped" || %caption $= "Object" || %caption $= "Editing" - || %caption $= "Persistence" || %caption $= "Dynamic Fields") - { - SMAssetEditInspector.remove(SMAssetEditInspector.getObject(%i)); - %i--; - } - } - - Canvas.pushDialog(StateMachineEditor); - StateMachineEditor.loadStateMachineAsset(EditAssetPopup.assetId); - StateMachineEditor-->Window.text = "State Machine Editor ("@EditAssetPopup.assetId@")"; - } - else if(%assetType $= "ComponentAsset") - { - %assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId); - %scriptFile = %assetDef.scriptFile; - - EditorOpenFileInTorsion(makeFullPath(%scriptFile), 0); - } - else if(%assetType $= "GameObjectAsset") - { + //If the passed-in definition param is blank, then we're likely called via a popup + if(%assetDef $= "") %assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId); - %scriptFile = %assetDef.scriptFilePath; - EditorOpenFileInTorsion(makeFullPath(%scriptFile), 0); - } - else if(%assetType $= "ScriptAsset") - { - %assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId); - %scriptFile = %assetDef.scriptFilePath; - - EditorOpenFileInTorsion(makeFullPath(%scriptFile), 0); - } - else if(%assetType $= "ShapeAsset") - { - %this.hideDialog(); - ShapeEditorPlugin.openShapeAsset(EditAssetPopup.assetId); - } - else if(%assetType $= "ShapeAnimationAsset") - { - %this.hideDialog(); - ShapeEditorPlugin.openShapeAsset(EditAssetPopup.assetId); - } - else if(%assetType $= "LevelAsset") - { - schedule( 1, 0, "EditorOpenMission", %assetDef.LevelFile); - } - else if(%assetType $= "GUIAsset") - { - if(!isObject(%assetDef.assetName)) - { - exec(%assetDef.GUIFilePath); - exec(%assetDef.mScriptFilePath); - } + %assetType = %assetDef.getClassName(); + + //Build out the edit command + %buildCommand = %this @ ".edit" @ %assetType @ "(" @ %assetDef @ ");"; + eval(%buildCommand); +} + +function AssetBrowser::appendSubLevel(%this) +{ + %assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId); + %assetType = %assetDef.getClassName(); - GuiEditContent(%assetDef.assetName); - } + schedule( 1, 0, "EditorOpenSceneAppend", %assetDef); } function AssetBrowser::editAssetInfo(%this) @@ -164,20 +87,24 @@ AssetBrowser.selectedAssetPreview-->AssetNameLabel.setFirstResponder(); } -function AssetNameField::onReturn(%this) +function AssetBrowser::performRenameAsset(%this, %originalAssetName, %newName) { //if the name is different to the asset's original name, rename it! - %newName = %this.getText(); - if(%this.originalAssetName !$= %this.getText()) + if(%originalAssetName !$= %newName) { %moduleName = AssetBrowser.selectedModule; //do a rename! - %success = AssetDatabase.renameDeclaredAsset(%moduleName @ ":" @ %this.originalAssetName, %moduleName @ ":" @ %this.getText()); + %success = AssetDatabase.renameDeclaredAsset(%moduleName @ ":" @ %originalAssetName, %moduleName @ ":" @ %newName); + + if(%success) + echo("AssetBrowser - renaming of asset " @ %moduleName @ ":" @ %originalAssetName @ " to " @ %moduleName @ ":" @ %newName @ " was a success."); + else + echo("AssetBrowser - renaming of asset " @ %moduleName @ ":" @ %originalAssetName @ " to " @ %moduleName @ ":" @ %newName @ " was a failure."); if(%success) { - %newAssetId = %moduleName @ ":" @ %this.getText(); + %newAssetId = %moduleName @ ":" @ %newName; %assetPath = AssetDatabase.getAssetFilePath(%newAssetId); //Rename any associated files as well @@ -187,160 +114,44 @@ //rename the file to match %path = filePath(%assetPath); - if(%assetType $= "ComponentAsset") - { - %oldScriptFilePath = %assetDef.scriptFile; - %scriptFilePath = filePath(%assetDef.scriptFile); - %scriptExt = fileExt(%assetDef.scriptFile); - - %newScriptFileName = %scriptFilePath @ "/" @ %newName @ %scriptExt; - %newAssetFile = %path @ "/" @ %this.getText() @ ".asset.taml"; - - %assetDef.componentName = %newName; - %assetDef.scriptFile = %newScriptFileName; - - TamlWrite(%assetDef, %newAssetFile); - fileDelete(%assetPath); - - pathCopy(%oldScriptFilePath, %newScriptFileName); - fileDelete(%oldScriptFilePath); - - //Go through our scriptfile and replace the old namespace with the new - %editedFileContents = ""; - - %file = new FileObject(); - if ( %file.openForRead( %newScriptFileName ) ) - { - while ( !%file.isEOF() ) - { - %line = %file.readLine(); - %line = trim( %line ); - - %editedFileContents = %editedFileContents @ strreplace(%line, %this.originalAssetName, %newName) @ "\n"; - } - - %file.close(); - } - - if(%editedFileContents !$= "") - { - %file.openForWrite(%newScriptFileName); - - %file.writeline(%editedFileContents); - - %file.close(); - } - - exec(%newScriptFileName); - } - else if(%assetType $= "StateMachineAsset") - { - %oldScriptFilePath = %assetDef.stateMachineFile; - %scriptFilePath = filePath(%assetDef.stateMachineFile); - %scriptExt = fileExt(%assetDef.stateMachineFile); - - %newScriptFileName = %scriptFilePath @ "/" @ %newName @ %scriptExt; - %newAssetFile = %path @ "/" @ %this.getText() @ ".asset.taml"; - - %assetDef.stateMachineFile = %newScriptFileName; - - TamlWrite(%assetDef, %newAssetFile); - fileDelete(%assetPath); - - pathCopy(%oldScriptFilePath, %newScriptFileName); - fileDelete(%oldScriptFilePath); - } - else if(%assetType $= "GameObjectAsset") - { - %oldScriptFilePath = %assetDef.scriptFilePath; - %scriptFilePath = filePath(%assetDef.scriptFilePath); - %scriptExt = fileExt(%assetDef.scriptFilePath); - - %oldGOFilePath = %assetDef.TAMLFilePath; - - %newScriptFileName = %scriptFilePath @ "/" @ %newName @ %scriptExt; - %newAssetFile = %path @ "/" @ %this.getText() @ ".asset.taml"; - %newGOFile = %path @ "/" @ %this.getText() @ ".taml"; - - %assetDef.gameObjectName = %newName; - %assetDef.scriptFilePath = %newScriptFileName; - %assetDef.TAMLFilePath = %newGOFile; - - TamlWrite(%assetDef, %newAssetFile); - fileDelete(%assetPath); - - pathCopy(%oldScriptFilePath, %newScriptFileName); - fileDelete(%oldScriptFilePath); - - pathCopy(%oldGOFilePath, %newGOFile); - fileDelete(%oldGOFilePath); - - //Go through our scriptfile and replace the old namespace with the new - %editedFileContents = ""; - - %file = new FileObject(); - if ( %file.openForRead( %newScriptFileName ) ) - { - while ( !%file.isEOF() ) - { - %line = %file.readLine(); - %line = trim( %line ); - - %editedFileContents = %editedFileContents @ strreplace(%line, %this.originalAssetName, %newName) @ "\n"; - } - - %file.close(); - } - - if(%editedFileContents !$= "") - { - %file.openForWrite(%newScriptFileName); - - %file.writeline(%editedFileContents); - - %file.close(); - } - - exec(%newScriptFileName); - - //Rename in the TAML file as well - %file = new FileObject(); - if ( %file.openForRead( %newGOFile ) ) - { - while ( !%file.isEOF() ) - { - %line = %file.readLine(); - %line = trim( %line ); - - %editedFileContents = %editedFileContents @ strreplace(%line, %this.originalAssetName, %newName) @ "\n"; - } - - %file.close(); - } - - if(%editedFileContents !$= "") - { - %file.openForWrite(%newGOFile); - - %file.writeline(%editedFileContents); - - %file.close(); - } - } + //Do the rename command + %buildCommand = %this @ ".rename" @ %assetType @ "(" @ %assetDef @ "," @ %newAssetId @ ");"; + eval(%buildCommand); } } + //Make sure everything is refreshed + AssetBrowser.loadFilters(); +} + +function AssetNameField::onReturn(%this) +{ %this.clearFirstResponder(); %this.setActive(false); + + AssetBrowser.performRenameAsset(%this.originalAssetName, %this.getText()); } //------------------------------------------------------------ -function AssetBrowser::duplicateAsset(%this) +function AssetBrowser::duplicateAsset(%this, %targetModule) { + if(%targetModule $= "") + { + //we need a module to duplicate to first + Canvas.pushDialog(AssetBrowser_selectModule); + AssetBrowser_selectModule.callback = "AssetBrowser.duplicateAsset"; + return; + } + %assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId); + %assetType = AssetDatabase.getAssetType(EditAssetPopup.assetId); - %this.setupCreateNewAsset(%assetDef.getClassName(), AssetBrowser.selectedModule); + //this acts as a redirect based on asset type and will enact the appropriate function + //so for a GameObjectAsset, it'll become %this.duplicateGameObjectAsset(%assetDef, %targetModule); + //and call to the tools/assetBrowser/scripts/assetTypes/gameObject.cs file for implementation + if(%this.isMethod("duplicate"@%assetType)) + eval(%this @ ".duplicate"@%assetType@"("@%assetDef@","@%targetModule@");"); } function AssetBrowser::deleteAsset(%this) @@ -358,8 +169,15 @@ %currentSelectedItem = AssetBrowserFilterTree.getSelectedItem(); %currentItemParent = AssetBrowserFilterTree.getParentItem(%currentSelectedItem); - AssetDatabase.deleteAsset(EditAssetPopup.assetId, false); + %assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId); + %assetType = AssetDatabase.getAssetType(EditAssetPopup.assetId); + //Do any cleanup required given the type + if(%this.isMethod("delete"@%assetType)) + eval(%this @ ".delete"@%assetType@"("@%assetDef@");"); + + AssetDatabase.deleteAsset(EditAssetPopup.assetId, false); + %this.loadFilters(); if(!AssetBrowserFilterTree.selectItem(%currentSelectedItem)) diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/gameObjectCreator.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/gameObjectCreator.cs index a2c526251b..230167daf8 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/gameObjectCreator.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/gameObjectCreator.cs @@ -39,8 +39,7 @@ //also, exec any components that may exist //find all GameObjectAssets %assetQuery = new AssetQuery(); - if(!AssetDatabase.findAssetType(%assetQuery, "GameObjectAsset")) - return; //if we didn't find ANY, just exit + AssetDatabase.findAssetType(%assetQuery, "GameObjectAsset"); %count = %assetQuery.getCount(); @@ -69,7 +68,7 @@ //get the selected module data %moduleName = GameObjectModuleList.getText(); - %selectedEntity.gameObjectAsset = %moduleName @ ":" @ %className; + %selectedEntity.gameObject = %moduleName @ ":" @ %className; %path = "data/" @ %moduleName @ "/gameObjects/"; diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/newAsset.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/newAsset.cs index ee351a1921..1486b420a1 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/newAsset.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/newAsset.cs @@ -71,16 +71,18 @@ AssetBrowser_addModuleWindow.selectWindow(); } -function AssetBrowser::setupCreateNewAsset(%this, %assetType, %moduleName) +function AssetBrowser::setupCreateNewAsset(%this, %assetType, %moduleName, %callback) { Canvas.pushDialog(AssetBrowser_newAsset); AssetBrowser_newAssetWindow.text = "New" SPC %assetType SPC "Asset"; - NewAssetPropertiesInspector.clear(); + NewAssetPropertiesInspector.clearFields(); NewAssetModuleList.setText(%moduleName); + AssetBrowser_newAsset.callbackFunc = %callback; + //get rid of the old one if we had one. if(isObject(%this.newAssetSettings)) %this.newAssetSettings.delete(); @@ -96,7 +98,7 @@ NewAssetPropertiesInspector.addField("assetName", "New Asset Name", "String", "Name of the new asset", "New" @ %shortAssetTypeName, "", %this.newAssetSettings); //NewAssetPropertiesInspector.addField("AssetType", "New Asset Type", "List", "Type of the new asset", %assetType, "Component,Image,Material,Shape,Sound,State Machine", %newAssetSettings); - NewAssetPropertiesInspector.addField("friendlyName", "Friendly Name", "String", "Human-readable name of new asset", "", "", %this.newAssetSettings); + //NewAssetPropertiesInspector.addField("friendlyName", "Friendly Name", "String", "Human-readable name of new asset", "", "", %this.newAssetSettings); NewAssetPropertiesInspector.addField("description", "Description", "Command", "Description of the new asset", "", "", %this.newAssetSettings); NewAssetPropertiesInspector.endGroup(); @@ -112,7 +114,8 @@ else if(%assetType $= "LevelAsset") { NewAssetPropertiesInspector.startGroup("Level"); - NewAssetPropertiesInspector.addField("levelPreviewImage", "LevePreviewImage", "Image", "Preview Image for the level", "", "", %this.newAssetSettings); + NewAssetPropertiesInspector.addField("levelName", "Level Name", "String", "Human-readable name of new level", "", "", %this.newAssetSettings); + NewAssetPropertiesInspector.addField("levelPreviewImage", "Level Preview Image", "Image", "Preview Image for the level", "", "", %this.newAssetSettings); NewAssetPropertiesInspector.endGroup(); } else if(%assetType $= "ScriptAsset") @@ -121,6 +124,13 @@ NewAssetPropertiesInspector.addField("isServerScript", "Is Server Script", "bool", "Is this script used on the server?", "1", "", %this.newAssetSettings); NewAssetPropertiesInspector.endGroup(); } + //Special case, we only do this via internal means like baking + /*else if(%assetType $= "ShapeAsset") + { + NewAssetPropertiesInspector.startGroup("Shape"); + NewAssetPropertiesInspector.addField("isServerScript", "Is Server Script", "bool", "Is this script used on the server?", "1", "", %this.newAssetSettings); + NewAssetPropertiesInspector.endGroup(); + }*/ /*else if(%assetType $= "ShapeAnimationAsset") { NewAssetPropertiesInspector.startGroup("Animation"); @@ -134,30 +144,6 @@ NewAssetPropertiesInspector.addField("padTransforms", "Pad Transforms", "bool", "Source file this animation will pull from", "0", "", %this.newAssetSettings); NewAssetPropertiesInspector.endGroup(); }*/ - - return; - - if(%moduleName $= "") - { - Canvas.pushDialog(AssetBrowser_selectModule); - } - else - { - AssetBrowser.SelectedModule = %moduleName; - - if(%assetType $= "MaterialAsset") - { - createNewMaterialAsset("NewMaterial", %moduleName); - } - else if(%assetType $= "StateMachineAsset") - { - createNewStateMachineAsset("NewStateMachine", %moduleName); - } - else if(%assetType $= "ScriptAsset") - { - createNewScriptAsset("NewScriptAsset", %moduleName); - } - } } //We do a quick validation that mandatory fields are filled in before passing along to the asset-type specific function @@ -189,36 +175,7 @@ function CreateNewAsset() return; } - if(%assetType $= "ComponentAsset") - { - //Canvas.popDialog(AssetBrowser_newComponentAsset); - //AssetBrowser_newComponentAsset-->AssetBrowserModuleList.setText(AssetBrowser.selectedModule); - %assetFilePath = createNewComponentAsset(%assetName, %path); - } - else if(%assetType $= "MaterialAsset") - { - %assetFilePath = createNewMaterialAsset(); - } - else if(%assetType $= "StateMachineAsset") - { - %assetFilePath = createNewStateMachineAsset(); - } - else if(%assetType $= "GUIAsset") - { - %assetFilePath = createNewGUIAsset(); - } - else if(%assetType $= "LevelAsset") - { - %assetFilePath = createNewLevelAsset(); - } - else if(%assetType $= "ScriptAsset") - { - %assetFilePath = createNewScriptAsset(); - } - else if(%assetType $= "ShapeAnimationAsset") - { - %assetFilePath = createShapeAnimationAsset(); - } + %assetFilePath = eval(AssetBrowser @ ".create"@%assetType@"();"); Canvas.popDialog(AssetBrowser_newAsset); @@ -227,356 +184,12 @@ function CreateNewAsset() AssetDatabase.addDeclaredAsset(%moduleDef, %assetFilePath); AssetBrowser.loadFilters(); -} - -function createNewComponentAsset() -{ - %moduleName = AssetBrowser.newAssetSettings.moduleName; - %modulePath = "data/" @ %moduleName; - - %assetName = AssetBrowser.newAssetSettings.assetName; - - %tamlpath = %modulePath @ "/components/" @ %assetName @ ".asset.taml"; - %scriptPath = %modulePath @ "/components/" @ %assetName @ ".cs"; - - %asset = new ComponentAsset() - { - AssetName = %assetName; - versionId = 1; - componentName = %assetName; - componentClass = AssetBrowser.newAssetSettings.parentClass; - friendlyName = AssetBrowser.newAssetSettings.friendlyName; - componentType = AssetBrowser.newAssetSettings.componentGroup; - description = AssetBrowser.newAssetSettings.description; - scriptFile = %scriptPath; - }; - - TamlWrite(%asset, %tamlpath); - - %file = new FileObject(); - if(%file.openForWrite(%scriptPath)) + if(AssetBrowser_newAsset.callbackFunc !$= "") { - //TODO: enable ability to auto-embed a header for copyright or whatnot - %file.writeline("//onAdd is called when the component is created and then added to it's owner entity.\n"); - %file.writeline("//You would also add any script-defined component fields via addComponentField().\n"); - %file.writeline("function " @ %assetName @ "::onAdd(%this)\n{\n\n}\n"); - %file.writeline("//onAdd is called when the component is removed and deleted from it's owner entity."); - %file.writeline("function " @ %assetName @ "::onRemove(%this)\n{\n\n}\n"); - %file.writeline("//onClientConnect is called any time a new client connects to the server."); - %file.writeline("function " @ %assetName @ "::onClientConnect(%this, %client)\n{\n\n}\n"); - %file.writeline("//onClientDisconnect is called any time a client disconnects from the server."); - %file.writeline("function " @ %assetName @ "::onClientDisonnect(%this, %client)\n{\n\n}\n"); - %file.writeline("//update is called when the component does an update tick.\n"); - %file.writeline("function " @ %assetName @ "::Update(%this)\n{\n\n}\n"); - - %file.close(); + %callbackCommand = "" @ AssetBrowser_newAsset.callbackFunc @ "(\"" @ %moduleName @ ":" @ %assetName @ "\");"; + eval(%callbackCommand); } - - Canvas.popDialog(AssetBrowser_newComponentAsset); - - %moduleDef = ModuleDatabase.findModule(%moduleName, 1); - AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath); - - AssetBrowser.loadFilters(); - - %treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName); - %smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "Components"); - - AssetBrowserFilterTree.onSelect(%smItem); - - return %tamlpath; -} - -function createNewMaterialAsset() -{ - %assetName = AssetBrowser.newAssetSettings.assetName; - - %moduleName = AssetBrowser.newAssetSettings.moduleName; - %modulePath = "data/" @ %moduleName; - - %tamlpath = %modulePath @ "/materials/" @ %assetName @ ".asset.taml"; - %sgfPath = %modulePath @ "/materials/" @ %assetName @ ".sgf"; - - %asset = new MaterialAsset() - { - AssetName = %assetName; - versionId = 1; - shaderData = ""; - shaderGraph = %sgfPath; - }; - - TamlWrite(%asset, %tamlpath); - - %moduleDef = ModuleDatabase.findModule(%moduleName, 1); - AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath); - - AssetBrowser.loadFilters(); - - %treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName); - %smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "Materials"); - - AssetBrowserFilterTree.onSelect(%smItem); - - return %tamlpath; -} - -function createNewScriptAsset() -{ - %moduleName = AssetBrowser.newAssetSettings.moduleName; - %modulePath = "data/" @ %moduleName; - - %assetName = AssetBrowser.newAssetSettings.assetName; - - %tamlpath = %modulePath @ "/scripts/" @ %assetName @ ".asset.taml"; - %scriptPath = %modulePath @ "/scripts/" @ %assetName @ ".cs"; - - %asset = new ScriptAsset() - { - AssetName = %assetName; - versionId = 1; - scriptFilePath = %scriptPath; - }; - - TamlWrite(%asset, %tamlpath); - - %moduleDef = ModuleDatabase.findModule(%moduleName, 1); - AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath); - - AssetBrowser.loadFilters(); - - %treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName); - %smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "Scripts"); - - AssetBrowserFilterTree.onSelect(%smItem); - - %file = new FileObject(); - - if(%file.openForWrite(%scriptPath)) - { - %file.close(); - } - - return %tamlpath; -} - -function createNewStateMachineAsset() -{ - %assetName = AssetBrowser.newAssetSettings.assetName; - - %assetQuery = new AssetQuery(); - - %matchingAssetCount = AssetDatabase.findAssetName(%assetQuery, %assetName); - - %i=1; - while(%matchingAssetCount > 0) - { - %newAssetName = %assetName @ %i; - %i++; - - %matchingAssetCount = AssetDatabase.findAssetName(%assetQuery, %newAssetName); - } - - %assetName = %newAssetName; - - %assetQuery.delete(); - - %tamlpath = "data/" @ %moduleName @ "/stateMachines/" @ %assetName @ ".asset.taml"; - %smFilePath = "data/" @ %moduleName @ "/stateMachines/" @ %assetName @ ".xml"; - - %asset = new StateMachineAsset() - { - AssetName = %assetName; - versionId = 1; - stateMachineFile = %smFilePath; - }; - - %xmlDoc = new SimXMLDocument(); - %xmlDoc.saveFile(%smFilePath); - %xmlDoc.delete(); - - TamlWrite(%asset, %tamlpath); - - //Now write our XML file - %xmlFile = new FileObject(); - %xmlFile.openForWrite(%smFilePath); - %xmlFile.writeLine(""); - %xmlFile.writeLine(""); - %xmlFile.close(); - - %moduleDef = ModuleDatabase.findModule(%moduleName, 1); - AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath); - - AssetBrowser.loadFilters(); - - %treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName); - %smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "StateMachines"); - - AssetBrowserFilterTree.onSelect(%smItem); - - return %tamlpath; -} - -function createNewGUIAsset() -{ - %moduleName = AssetBrowser.newAssetSettings.moduleName; - %modulePath = "data/" @ %moduleName; - - %assetName = AssetBrowser.newAssetSettings.assetName; - - %tamlpath = %modulePath @ "/GUIs/" @ %assetName @ ".asset.taml"; - %guipath = %modulePath @ "/GUIs/" @ %assetName @ ".gui"; - %scriptPath = %modulePath @ "/GUIs/" @ %assetName @ ".cs"; - - %asset = new GUIAsset() - { - AssetName = %assetName; - versionId = 1; - scriptFilePath = %scriptPath; - guiFilePath = %guipath; - }; - - TamlWrite(%asset, %tamlpath); - - %file = new FileObject(); - - if(%file.openForWrite(%guipath)) - { - %file.writeline("//--- OBJECT WRITE BEGIN ---"); - %file.writeline("%guiContent = new GuiControl(" @ %assetName @ ") {"); - %file.writeline(" position = \"0 0\";"); - %file.writeline(" extent = \"100 100\";"); - %file.writeline("};"); - %file.writeline("//--- OBJECT WRITE END ---"); - - %file.close(); - } - - if(%file.openForWrite(%scriptPath)) - { - %file.writeline("function " @ %assetName @ "::onWake(%this)\n{\n\n}\n"); - %file.writeline("function " @ %assetName @ "::onSleep(%this)\n{\n\n}\n"); - - %file.close(); - } - - //load the gui - exec(%guipath); - exec(%scriptPath); - - %moduleDef = ModuleDatabase.findModule(%moduleName, 1); - AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath); - - AssetBrowser.loadFilters(); - - %treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName); - %smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "GUIs"); - - AssetBrowserFilterTree.onSelect(%smItem); - - return %tamlpath; -} - -function createNewLevelAsset() -{ - %moduleName = AssetBrowser.newAssetSettings.moduleName; - %modulePath = "data/" @ %moduleName; - - %assetName = AssetBrowser.newAssetSettings.assetName; - - %tamlpath = %modulePath @ "/levels/" @ %assetName @ ".asset.taml"; - %levelPath = %modulePath @ "/levels/" @ %assetName @ ".mis"; - - %asset = new LevelAsset() - { - AssetName = %assetName; - versionId = 1; - LevelFile = %levelPath; - LevelDescription = AssetBrowser.newAssetSettings.levelDescription; - PreviewImage = AssetBrowser.newAssetSettings.levelPreviewImage; - }; - - TamlWrite(%asset, %tamlpath); - - if(!pathCopy("tools/levels/BlankRoom.mis", %levelPath, false)) - { - echo("Unable to copy template level file!"); - } - - %moduleDef = ModuleDatabase.findModule(%moduleName, 1); - AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath); - - AssetBrowser.loadFilters(); - - %treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName); - %smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "Levels"); - - AssetBrowserFilterTree.onSelect(%smItem); - - return %tamlpath; -} - -function createNewShapeAnimationAsset() -{ - %dlg = new OpenFileDialog() - { - Filters = "Animation Files(*.dae, *.cached.dts)|*.dae;*.cached.dts"; - DefaultPath = $Pref::WorldEditor::LastPath; - DefaultFile = ""; - ChangePath = false; - OverwritePrompt = true; - forceRelativePath = false; - //MultipleFiles = true; - }; - - %ret = %dlg.Execute(); - - if ( %ret ) - { - $Pref::WorldEditor::LastPath = filePath( %dlg.FileName ); - %fullPath = %dlg.FileName; - } - - %dlg.delete(); - - if ( !%ret ) - return; - - /*%moduleName = AssetBrowser.newAssetSettings.moduleName; - %modulePath = "data/" @ %moduleName; - - %assetName = AssetBrowser.newAssetSettings.assetName; - - %tamlpath = %modulePath @ "/levels/" @ %assetName @ ".asset.taml"; - %levelPath = %modulePath @ "/levels/" @ %assetName @ ".mis"; - - %asset = new ShapeAnimationAsset() - { - AssetName = %assetName; - versionId = 1; - LevelFile = %levelPath; - LevelDescription = AssetBrowser.newAssetSettings.levelDescription; - PreviewImage = AssetBrowser.newAssetSettings.levelPreviewImage; - }; - - TamlWrite(%asset, %tamlpath); - - if(!pathCopy("tools/levels/BlankRoom.mis", %levelPath, false)) - { - echo("Unable to copy template level file!"); - } - - %moduleDef = ModuleDatabase.findModule(%moduleName, 1); - AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath); - - AssetBrowser.loadFilters(); - - %treeItemId = AssetBrowserFilterTree.findItemByName(%moduleName); - %smItem = AssetBrowserFilterTree.findChildItemByName(%treeItemId, "Levels"); - - AssetBrowserFilterTree.onSelect(%smItem); - - return %tamlpath;*/ } function ParentComponentList::onWake(%this) @@ -651,13 +264,5 @@ function createNewShapeAnimationAsset() //---------------------------------------------------------- function EWorldEditor::createGameObject( %this ) { - GameObjectCreatorObjectName.text = ""; - - %activeSelection = %this.getActiveSelection(); - if( %activeSelection.getCount() == 0 ) - return; - - GameObjectCreator.selectedEntity = %activeSelection.getObject( 0 ); - - Canvas.pushDialog(GameObjectCreator); + AssetBrowser.createGameObjectAsset(); } \ No newline at end of file diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/popupMenus.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/popupMenus.cs index 12f422485f..63e9858fa5 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/popupMenus.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/popupMenus.cs @@ -37,6 +37,31 @@ class = "EditorWorldMenu"; }; } + if( !isObject( EditLevelAssetPopup ) ) + { + new PopupMenu( EditLevelAssetPopup ) + { + superClass = "MenuBuilder"; + class = "EditorWorldMenu"; + //isPopup = true; + + item[ 0 ] = "Edit Level" TAB "" TAB "AssetBrowser.editAsset();"; + item[ 1 ] = "Append as Sublevel" TAB "" TAB "AssetBrowser.appendSublevel();"; + item[ 2 ] = "Rename Asset" TAB "" TAB "AssetBrowser.renameAsset();"; + item[ 3 ] = "Refresh Asset" TAB "" TAB "AssetBrowser.refreshAsset();"; + item[ 4 ] = "Asset Properties" TAB "" TAB "AssetBrowser.editAssetInfo();"; + item[ 5 ] = "-"; + Item[ 6 ] = "Duplicate Asset" TAB "" TAB "AssetBrowser.duplicateAsset();"; + item[ 7 ] = "-"; + item[ 8 ] = "Re-Import Asset" TAB "" TAB "AssetBrowser.reImportAsset();"; + item[ 9 ] = "-"; + item[ 10 ] = "Delete Asset" TAB "" TAB "AssetBrowser.deleteAsset();"; + + jumpFileName = ""; + jumpLineNumber = ""; + }; + } + if( !isObject( AddNewComponentAssetPopup ) ) { new PopupMenu( AddNewComponentAssetPopup ) @@ -92,6 +117,25 @@ class = "EditorWorldMenu"; item[ 12 ] = "Create Particle Effect" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"ParticleEffectAsset\", AssetBrowser.selectedModule);";//"AssetBrowser.createNewParticleEffectAsset(\"NewParticleEffect\", AssetBrowser.selectedModule);"; }; } + + if( !isObject( AddNewCppAssetPopup ) ) + { + %this.AddNewCppAssetPopup = new PopupMenu( AddNewCppAssetPopup ) + { + superClass = "MenuBuilder"; + class = "EditorWorldMenu"; + //isPopup = true; + + /*item[ 0 ] = "Create Static Class" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"CppStaticClassAsset\", AssetBrowser.selectedModule);"; + item[ 1 ] = "Create Regular Class" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"CppRegularClassAsset\", AssetBrowser.selectedModule);"; + item[ 2 ] = "Create GameObject Class" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"CppGameObjectAsset\", AssetBrowser.selectedModule);"; + item[ 3 ] = "Create Component Class" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"CppComponentAsset\", AssetBrowser.selectedModule);"; + item[ 4 ] = "Create Script Class" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"CppScriptClass\", AssetBrowser.selectedModule);";*/ + + item[ 0 ] = "Create C++ Class" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"CppAsset\", AssetBrowser.selectedModule);"; + }; + //%this.AddNewScriptAssetPopup.insertSubMenu(0, "Create Component", AddNewComponentAssetPopup); + } if( !isObject( AddNewAssetPopup ) ) { @@ -105,6 +149,9 @@ class = "EditorWorldMenu"; item[2] = "Create Art Asset" TAB AddNewArtAssetPopup; item[3] = "-"; item[4] = "Create Level" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"LevelAsset\", AssetBrowser.selectedModule);";//"AssetBrowser.createNewLevelAsset(\"NewLevel\", AssetBrowser.selectedModule);"; + item[5] = "-"; + item[6] = "Create C++ Asset" TAB AddNewCppAssetPopup; + }; } @@ -130,11 +177,89 @@ class = "EditorWorldMenu"; //Some assets are not yet ready/implemented, so disable their creation here AddNewArtAssetPopup.enableItem(3, false); //shape AddNewArtAssetPopup.enableItem(4, false); //shape animation - AddNewArtAssetPopup.enableItem(8, false); //post effect AddNewArtAssetPopup.enableItem(10, false); //sound asset AddNewArtAssetPopup.enableItem(12, false); //particle effect - AddNewScriptAssetPopup.enableItem(2, false); //state machine + if( !isObject( EditAssetCategoryPopup ) ) + { + new PopupMenu( EditAssetCategoryPopup ) + { + superClass = "MenuBuilder"; + class = "EditorWorldMenu"; + //isPopup = true; + + item[ 0 ] = "Toggle Autoloading of Script Assets" TAB "" TAB "AssetBrowser.toggleAutoloadAsset(\"Script\");"; + }; + } + + //Browser visibility menu + if( !isObject( BrowserVisibilityPopup ) ) + { + new PopupMenu( BrowserVisibilityPopup ) + { + superClass = "MenuBuilder"; + class = "EditorWorldMenu"; + //isPopup = true; + + item[ 0 ] = "Toggle Show Core Modules" TAB "" TAB "AssetBrowser.viewCoreModulesFilter();"; + item[ 1 ] = "Toggle Only Show Modules with Assets" TAB "" TAB "AssetBrowser.viewPopulatedModulesFilter();"; + Item[ 2 ] = "-"; + item[ 3 ] = "Show Assets as list" TAB "" TAB "AssetBrowser.viewListFilter();"; + Item[ 4 ] = "Show Assets with tags" TAB "" TAB "AssetBrowser.viewTagsFilter();"; + }; + } + + //Import Legacy menus + if( !isObject( ImportAssetsPopup ) ) + { + new PopupMenu( ImportAssetsPopup ) + { + superClass = "MenuBuilder"; + class = "EditorWorldMenu"; + + item[ 0 ] = "Import Legacy Game" TAB "" TAB "AssetBrowser.importLegacyGame();"; + Item[ 1 ] = "-"; + item[ 2 ] = "Import new assets" TAB "" TAB "AssetBrowser.importNewAssetFile();"; + }; + } + + if( !isObject( EditGameObjectAssetPopup ) ) + { + new PopupMenu( EditGameObjectAssetPopup ) + { + superClass = "MenuBuilder"; + class = "EditorWorldMenu"; + //isPopup = true; + + item[ 0 ] = "Open GameObject Editor" TAB "" TAB "echo(\"Not yet implemented.\");"; + item[ 1 ] = "Edit GameObject Script" TAB "" TAB "AssetBrowser.editGameObjectAssetScript(AssetDatabase.acquireAsset(EditGameObjectAssetPopup.assetId));"; + item[ 2 ] = "-"; + item[ 3 ] = "Apply Instance to GameObject" TAB "" TAB "AssetBrowser.applyInstanceToGameObject(AssetDatabase.acquireAsset(EditGameObjectAssetPopup.assetId));"; + item[ 4 ] = "Reset Instance to GameObject" TAB "" TAB "echo(\"Not yet implemented.\");"; + item[ 5 ] = "-"; + item[ 6 ] = "Create Child GameObject" TAB "" TAB "echo(\"Not yet implemented.\");"; + }; + } + + //Asset Import Resolution menus + if( !isObject( ImportAssetResolutionsPopup ) ) + { + %this.ImportAssetResolutionsPopup = new PopupMenu( ImportAssetResolutionsPopup ) + { + superClass = "MenuBuilder"; + class = "EditorWorldMenu"; + + item[0] = "Use original Asset for duplicates" TAB "" TAB ""; + item[1] = "Override duplicate with new Asset" TAB "" TAB ""; + item[2] = "-"; + item[3] = "Rename Asset" TAB "" TAB ""; + item[4] = "-"; + item[5] = "Find missing file" TAB "" TAB "ImportAssetWindow.findMissingFile(ImportAssetResolutionsPopup.assetItem);"; + item[6] = "-"; + item[7] = "Edit Asset properties" TAB "" TAB ""; + + }; + } } function AddNewScriptAssetPopupMenu::onSelectItem(%this, %id, %text) diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/selectModule.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/selectModule.cs index 3c2c7c1ea3..4b34f45519 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/selectModule.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/selectModule.cs @@ -1,8 +1,21 @@ -function AssetBrowser_selectModule::onWake(%this) +function AssetBrowser_SelectModule::onWake(%this) { AssetBrowser_SelectModuleWindow-->ModuleList.refresh(); } +function AssetBrowser_SelectModule::moduleSelected(%this) +{ + Canvas.popDialog(AssetBrowser_SelectModule); + + %module = AssetBrowser_SelectModuleWindow-->ModuleList.getText(); + echo("Module Selected: " @ %module); + + if(%this.callback !$= "") + eval(%this.callback @ "(" @ %module @ ");"); + else + error("AssetBrowser_SelectModule - Invalid callback"); +} + function SelectModule_NewAssetModuleBtn::onClick(%this) { Canvas.pushDialog(AssetBrowser_AddModule); diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/templateFiles/CppModuleFile.cpp b/Templates/BaseGame/game/tools/assetBrowser/scripts/templateFiles/CppModuleFile.cpp new file mode 100644 index 0000000000..63d51b7763 --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/templateFiles/CppModuleFile.cpp @@ -0,0 +1,18 @@ +#include "core/module.h" +#include "console/engineAPI.h" + +MODULE_BEGIN(@_Module) + +MODULE_INIT_AFTER(Sim) +MODULE_SHUTDOWN_BEFORE(Sim) + +MODULE_INIT +{ + // Setup anything needed when the engine initializes here +} +MODULE_SHUTDOWN +{ + // Cleanup anything that was initialized before here +} +MODULE_END; + diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/templateFiles/CppStaticClassFile.cpp b/Templates/BaseGame/game/tools/assetBrowser/scripts/templateFiles/CppStaticClassFile.cpp new file mode 100644 index 0000000000..a6918bbaeb --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/templateFiles/CppStaticClassFile.cpp @@ -0,0 +1,15 @@ +#include "@.h" + +IMPLEMENT_STATIC_CLASS(@, , "Functions for maintaing a list of banned users."); + +@* @::smInstance; + +@::@() +{ + smInstance = this; +} + +DefineEngineStaticMethod(@, doSomething, void, (), , "") +{ + //@::instance()->doSomething(); +} \ No newline at end of file diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/templateFiles/CppStaticClassFile.h b/Templates/BaseGame/game/tools/assetBrowser/scripts/templateFiles/CppStaticClassFile.h new file mode 100644 index 0000000000..4fbf17e7d7 --- /dev/null +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/templateFiles/CppStaticClassFile.h @@ -0,0 +1,17 @@ +#pragma once + +#include "console/engineAPI.h" + +class @ +{ + DECLARE_STATIC_CLASS(@); +private: + +protected: + static @* smInstance; + +public: + @(); + + static @* instance() { return smInstance; } +}; \ No newline at end of file diff --git a/Templates/BaseGame/game/tools/classIcons/ActiveScene.png b/Templates/BaseGame/game/tools/classIcons/ActiveScene.png new file mode 100644 index 0000000000000000000000000000000000000000..01981f9658cc5e985340eb696e4bced33cb335b1 GIT binary patch literal 805 zcmV+=1KRwFP)4#W=m}s&CE-X5J5$eVHYZr(4@d9GJ5JI zeCnZyB7(>$yVyha&=tCFSX4@smy9&5*fr1YdUnsA(?hjn7b2RMfthc9Gyjhn!9SQj z2NM%;Ah4p+O@NN*-#uK`Rv`ggEWhd_SnZ^e#T7M0Gl*v!=w1W8y5#*u~Gql`W+G==$-StK!gjKCNtO{vG?h58+xriA% zHu5k1-U05vaoK_%&B+g0Yo`!3aYiBW?P!I1fS23Ec+smQ#VfYpyLrWg?U!}_=F=xwSzojcqtS@TWW;PT@$}6z4!0gbhxOu5mzPmB jy&9bpe>qSu|7%|W?Q0JtGRuW@00000NkvXXu0mjfM=5Z* literal 0 HcmV?d00001 diff --git a/Templates/BaseGame/game/tools/classIcons/Scene.png b/Templates/BaseGame/game/tools/classIcons/Scene.png new file mode 100644 index 0000000000000000000000000000000000000000..cb6621f2ac14dfbe53ca8025c95232ce82c53920 GIT binary patch literal 762 zcmV7Yn0J7H$9l0*6UN zK~y-)rITAolW`QlfBz}ES;j{e1*WYPVp5W(kXAF5?50qLNmmrhf)QE}6hwwEJ%vvN zMOk1sNGocX5)t_z)daf{gvGjCYvzJBVKpGonFRIb0snz~t-FTvgFrNgt4 z5QgPvfN7`(X-I4`3DZz5F-P%j{82j>{N-Slsa2#FS9z+i|KpgnSL&7 zmT!yaWe;*Rfq*xSfdM~{KAdOB>=B(j|6vC*A{&VaZAFS(R|GLM6 zC-HuE0}x^u3wf%XU~GhpwrM>XIp#I_xrdp@bw7i)`GZqt;VqVmccRtGaVrR)xJAiOA61#)k zLj_t~obcv3apDg_ z90MG@)J&qXv9D||IWu#p&fh@PkWKUU<}U!SWVsgB$gs4RXRaa`97ETGF-Y5;3*3L^ z!R6cq5eSWqv9q*}=@X_QBeDfRWNcsH6=476oX7Rdlr(CKwqdnevDvI7*=#&|{e)vT sPN1Mx{OJQ7Tj$rHIP;fB_4B{-70yKrJ!b!_`2YX_07*qoM6N<$f)wCX6951J literal 0 HcmV?d00001 diff --git a/Templates/BaseGame/game/tools/gui/profiles.ed.cs b/Templates/BaseGame/game/tools/gui/profiles.ed.cs index a1b120e0d6..1b598b0953 100644 --- a/Templates/BaseGame/game/tools/gui/profiles.ed.cs +++ b/Templates/BaseGame/game/tools/gui/profiles.ed.cs @@ -287,6 +287,30 @@ function execEditorProfilesCS() category = "Tools"; }; +if( !isObject( ToolsGuiTextEditErrorProfile ) ) +new GuiControlProfile( ToolsGuiTextEditErrorProfile ) +{ + opaque = true; + bitmap = "./images/textEditFrame"; + hasBitmapArray = true; + border = -2; // fix to display textEdit img + //borderWidth = "1"; // fix to display textEdit img + //borderColor = "100 100 100"; + fillColor = "242 241 240 0"; + fillColorHL = "255 255 255"; + fontColor = "0 0 0"; + fontColorHL = "255 0 0"; + fontColorSEL = "98 100 137"; + fontColorNA = "200 200 200"; + textOffset = "4 2"; + autoSizeWidth = false; + autoSizeHeight = true; + justify = "left"; + tab = true; + canKeyFocus = true; + category = "Tools"; +}; + if( !isObject( ToolsGuiTextEditCenterProfile ) ) new GuiControlProfile (ToolsGuiTextEditCenterProfile) { diff --git a/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.cs b/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.cs index 30c5dac261..74869ebb44 100644 --- a/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.cs +++ b/Templates/BaseGame/game/tools/materialEditor/scripts/materialEditor.ed.cs @@ -137,6 +137,8 @@ singleton ShaderData( materialEd_justAlphaShader ) if( MaterialEditorGui.currentMode $= "Mesh" ) MaterialEditorGui.prepareActiveObject( true ); + else if( MaterialEditorGui.currentMode $= "asset" ) + MaterialEditorGui.prepareActiveMaterial( MaterialEditorGui.currentMaterial, true ); else MaterialEditorGui.prepareActiveMaterial( "", true ); @@ -288,7 +290,9 @@ singleton ShaderData( materialEd_justAlphaShader ) } else { - MaterialEditorGui.currentMode = "Material"; + if(MaterialEditorGui.currentMode !$= "asset") + MaterialEditorGui.currentMode = "Material"; + MatEdMaterialMode.setVisible(1); EWorldEditor.clearSelection(); } diff --git a/Templates/BaseGame/game/tools/shapeEditor/main.cs b/Templates/BaseGame/game/tools/shapeEditor/main.cs index 40b6af6e0c..fa845d06cb 100644 --- a/Templates/BaseGame/game/tools/shapeEditor/main.cs +++ b/Templates/BaseGame/game/tools/shapeEditor/main.cs @@ -145,10 +145,9 @@ function SetToggleButtonValue(%ctrl, %value) } } -function ShapeEditorPlugin::openShapeAsset(%this, %assetId) +function ShapeEditorPlugin::openShapeAsset(%this, %assetDef) { - %this.selectedAssetId = %assetId; - %this.selectedAssetDef = AssetDatabase.acquireAsset(%assetId); + %this.selectedAssetDef = %assetDef; %this.open(%this.selectedAssetDef.fileName); } diff --git a/Templates/BaseGame/game/tools/shapeEditor/scripts/shapeEditor.ed.cs b/Templates/BaseGame/game/tools/shapeEditor/scripts/shapeEditor.ed.cs index b9551c9833..9ccc0d8ee1 100644 --- a/Templates/BaseGame/game/tools/shapeEditor/scripts/shapeEditor.ed.cs +++ b/Templates/BaseGame/game/tools/shapeEditor/scripts/shapeEditor.ed.cs @@ -613,7 +613,7 @@ function strcapitalise( %str ) ShapeEdThreadWindow.onAddThread(); // add thread 0 //Now, fetch any animation assets if we're utilizing a shape asset - if(ShapeEditorPlugin.selectedAssetId !$= "") + if(ShapeEditorPlugin.selectedAssetDef !$= "") { %animationAssetCount = ShapeEditorPlugin.selectedAssetDef.getAnimationCount(); diff --git a/Templates/BaseGame/game/tools/shapeEditor/scripts/shapeEditorActions.ed.cs b/Templates/BaseGame/game/tools/shapeEditor/scripts/shapeEditorActions.ed.cs index 15bd4cc9b6..1f6b173609 100644 --- a/Templates/BaseGame/game/tools/shapeEditor/scripts/shapeEditorActions.ed.cs +++ b/Templates/BaseGame/game/tools/shapeEditor/scripts/shapeEditorActions.ed.cs @@ -319,7 +319,7 @@ function onAddAnimationAssetShapeEditor(%selectedAnimation) function ActionAddSequence::doit( %this ) { - if(ShapeEditorPlugin.selectedAssetId $= "") + if(ShapeEditorPlugin.selectedAssetDef $= "") { // If adding this sequence from an existing sequence, make a backup copy of // the existing sequence first, so we can edit the start/end frames later @@ -346,8 +346,20 @@ function onAddAnimationAssetShapeEditor(%selectedAnimation) %assetDef = AssetDatabase.acquireAsset(%this.seqName); %moduleName = getWord(getToken(%this.seqName, ":", 0),0); + //If we have or ambient, we'll want to ignore them for our idx values when embedding animation dependencies to our shape asset + %idxOffset = 0; + + if(ShapeEdSequenceList.findTextIndex("\t\t\t\t") != -1) + %idxOffset++; + + if(ShapeEdSequenceList.findTextIndex("ambient\t\t\t\t") != -1) + %idxOffset++; + //TODO, properly ignore and ambient entries for our idx values, but only if they're there! - %idx = ShapeEdSequenceList.rowCount() - 2; + %idx = ShapeEdSequenceList.rowCount() - %idxOffset; + + //We adjust due to the list "header" row as well + %idx -= 1; %animSet = "ShapeEditorPlugin.selectedAssetDef.animationSequence"@%idx@"=\"@Asset="@%moduleName@":"@%assetDef.assetName@"\";"; eval(%animSet); diff --git a/Templates/BaseGame/game/tools/worldEditor/scripts/EditorGui.ed.cs b/Templates/BaseGame/game/tools/worldEditor/scripts/EditorGui.ed.cs index 8cc951a991..4a1f114c36 100644 --- a/Templates/BaseGame/game/tools/worldEditor/scripts/EditorGui.ed.cs +++ b/Templates/BaseGame/game/tools/worldEditor/scripts/EditorGui.ed.cs @@ -1596,6 +1596,8 @@ function VisibilityDropdownToggle() { %popup.item[ 0 ] = "Delete" TAB "" TAB "EditorMenuEditDelete();"; %popup.item[ 1 ] = "Group" TAB "" TAB "EWorldEditor.addSimGroup( true );"; + %popup.item[ 2 ] = "-"; + %popup.item[ 1 ] = "Make select a Sub-Level" TAB "" TAB "MakeSelectionASublevel();"; } else { @@ -1726,7 +1728,7 @@ function VisibilityDropdownToggle() if( %obj.name $= "CameraBookmarks" ) return EWorldEditor.areAllSelectedObjectsOfType( "CameraBookmark" ); else - return ( %obj.getClassName() $= "SimGroup" ); + return ( %obj.getClassName() $= "SimGroup" || %obj.isMemberOfClass("Scene")); } function EditorTree::onBeginReparenting( %this ) diff --git a/Templates/BaseGame/game/tools/worldEditor/scripts/menuHandlers.ed.cs b/Templates/BaseGame/game/tools/worldEditor/scripts/menuHandlers.ed.cs index 0f9f388527..7ba48d1d69 100644 --- a/Templates/BaseGame/game/tools/worldEditor/scripts/menuHandlers.ed.cs +++ b/Templates/BaseGame/game/tools/worldEditor/scripts/menuHandlers.ed.cs @@ -237,7 +237,7 @@ function EditorNewLevel( %file ) function EditorSaveMissionMenu() { if(EditorGui.saveAs) - EditorSaveMissionAs(); + AssetBrowser.setupCreateNewAsset("LevelAsset", AssetBrowser.selectedModule, "EditorSaveMissionAs"); else EditorSaveMission(); } @@ -299,123 +299,32 @@ function EditorSaveMission() return true; } -function EditorSaveMissionAs( %missionName ) +function EditorSaveMissionAs( %levelAsset ) { // If we didn't get passed a new mission name then // prompt the user for one. - if ( %missionName $= "" ) - { - %dlg = new SaveFileDialog() - { - Filters = $Pref::WorldEditor::FileSpec; - DefaultPath = EditorSettings.value("LevelInformation/levelsDirectory"); - ChangePath = false; - OverwritePrompt = true; - }; - - %ret = %dlg.Execute(); - if(%ret) - { - // Immediately override/set the levelsDirectory - EditorSettings.setValue( "LevelInformation/levelsDirectory", collapseFilename(filePath( %dlg.FileName )) ); - - %missionName = %dlg.FileName; - } + if ( %levelAsset $= "" ) + return; - %dlg.delete(); + %levelAssetDef = AssetDatabase.acquireAsset(%levelAsset); + %assetType = AssetDatabase.getAssetType(%levelAsset); - if(! %ret) - return; + if(%assetType !$= "LevelAsset") + { + error("Somehow tried to save a non-level asset as a level? " @ %levelAsset); + return; } + %missionName = %levelAssetDef.LevelFile; + if( fileExt( %missionName ) !$= ".mis" ) %missionName = %missionName @ ".mis"; - - EWorldEditor.isDirty = true; - %saveMissionFile = $Server::MissionFile; - - $Server::MissionFile = %missionName; - - %copyTerrainsFailed = false; - - // Rename all the terrain files. Save all previous names so we can - // reset them if saving fails. - %newMissionName = fileBase(%missionName); - %oldMissionName = fileBase(%saveMissionFile); - - initContainerTypeSearch( $TypeMasks::TerrainObjectType ); - %savedTerrNames = new ScriptObject(); - for( %i = 0;; %i ++ ) - { - %terrainObject = containerSearchNext(); - if( !%terrainObject ) - break; - - %savedTerrNames.array[ %i ] = %terrainObject.terrainFile; - - %terrainFilePath = makeRelativePath( filePath( %terrainObject.terrainFile ), getMainDotCsDir() ); - %terrainFileName = fileName( %terrainObject.terrainFile ); - - // Workaround to have terrains created in an unsaved "New Level..." mission - // moved to the correct place. - - if( EditorGui.saveAs && %terrainFilePath $= "tools/art/terrains" ) - %terrainFilePath = "art/terrains"; - - // Try and follow the existing naming convention. - // If we can't, use systematic terrain file names. - if( strstr( %terrainFileName, %oldMissionName ) >= 0 ) - %terrainFileName = strreplace( %terrainFileName, %oldMissionName, %newMissionName ); - else - %terrainFileName = %newMissionName @ "_" @ %i @ ".ter"; - - %newTerrainFile = %terrainFilePath @ "/" @ %terrainFileName; - - if (!isWriteableFileName(%newTerrainFile)) - { - if (MessageBox("Error", "Terrain file \""@ %newTerrainFile @ "\" is read-only. Continue?", "Ok", "Stop") == $MROk) - continue; - else - { - %copyTerrainsFailed = true; - break; - } - } - if( !%terrainObject.save( %newTerrainFile ) ) - { - error( "Failed to save '" @ %newTerrainFile @ "'" ); - %copyTerrainsFailed = true; - break; - } - - %terrainObject.terrainFile = %newTerrainFile; - } - - ETerrainEditor.isDirty = false; - - // Save the mission. - if(%copyTerrainsFailed || !EditorSaveMission()) - { - // It failed, so restore the mission and terrain filenames. - - $Server::MissionFile = %saveMissionFile; - - initContainerTypeSearch( $TypeMasks::TerrainObjectType ); - for( %i = 0;; %i ++ ) - { - %terrainObject = containerSearchNext(); - if( !%terrainObject ) - break; - - %terrainObject.terrainFile = %savedTerrNames.array[ %i ]; - } - } - - %savedTerrNames.delete(); + //Make sure we have a selected module so we can create our module + Canvas.pushDialog(AssetBrowser_selectModule); } -function EditorOpenMission(%filename) +function EditorOpenMission(%levelAsset) { if( EditorIsDirty()) { @@ -428,28 +337,31 @@ function EditorOpenMission(%filename) } } - if(%filename $= "") + if(%levelAsset $= "") { - %dlg = new OpenFileDialog() + AssetBrowser.showDialog("LevelAsset", "EditorOpenMission", "", "", ""); + return; + } + else + { + //If we got the actual assetdef, just roll with it + if(isObject(%levelAsset)) { - Filters = $Pref::WorldEditor::FileSpec; - DefaultPath = EditorSettings.value("LevelInformation/levelsDirectory"); - ChangePath = false; - MustExist = true; - }; - - %ret = %dlg.Execute(); - if(%ret) + %assetDef = %levelAsset; + } + else { - // Immediately override/set the levelsDirectory - EditorSettings.setValue( "LevelInformation/levelsDirectory", collapseFilename(filePath( %dlg.FileName )) ); - %filename = %dlg.FileName; + //parse it out if its + %assetDef = AssetDatabase.acquireAsset(%levelAsset); } - %dlg.delete(); + %filename = %assetDef.levelFile; - if(! %ret) + if(%filename $= "") + { + error("Selected Level Asset doesn't have a valid levelFile path!"); return; + } } // close the current editor, it will get cleaned up by MissionCleanup @@ -498,6 +410,22 @@ function EditorOpenSceneAppend(%levelAsset) } } +function MakeSelectionASublevel() +{ + /*%size = EWorldEditor.getSelectionSize(); + if ( %size == 0 ) + return; + + //Make a new Scene object + + for(%i=0; %i < %size; %i++) + { + + } + %a = EWorldEditor.getSelectedObject(0); + %b = EWorldEditor.getSelectedObject(1);*/ +} + function EditorExportToCollada() { diff --git a/Templates/BaseGame/game/tools/worldEditor/scripts/menus.ed.cs b/Templates/BaseGame/game/tools/worldEditor/scripts/menus.ed.cs index 57338ba1f0..bb5f9cf4d4 100644 --- a/Templates/BaseGame/game/tools/worldEditor/scripts/menus.ed.cs +++ b/Templates/BaseGame/game/tools/worldEditor/scripts/menus.ed.cs @@ -132,7 +132,7 @@ class = "EditorFileMenu"; %fileMenu.appendItem("New Level" TAB "" TAB "schedule( 1, 0, \"EditorNewLevel\" );"); %fileMenu.appendItem("Open Level..." TAB %cmdCtrl SPC "O" TAB "schedule( 1, 0, \"EditorOpenMission\" );"); %fileMenu.appendItem("Save Level" TAB %cmdCtrl SPC "S" TAB "EditorSaveMissionMenu();"); - %fileMenu.appendItem("Save Level As..." TAB "" TAB "EditorSaveMissionAs();"); + %fileMenu.appendItem("Save Level As..." TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"LevelAsset\", AssetBrowser.selectedModule, \"EditorSaveMissionAs\");"); %fileMenu.appendItem("-"); if( $platform $= "windows" ) @@ -339,7 +339,7 @@ class = "EditorUtilitiesMenu"; item[0] = "Network Graph" TAB "n" TAB "toggleNetGraph();"; item[1] = "Profiler" TAB "ctrl F2" TAB "showMetrics(true);"; item[2] = "Torque SimView" TAB "" TAB "tree();"; - item[3] = "Make Selected a Mesh" TAB "" TAB "makeSelectedAMesh();"; + item[3] = "Make Selected a Mesh" TAB "" TAB "AssetBrowser.setupCreateNewAsset(\"ShapeAsset\", AssetBrowser.selectedModule, \"makeSelectedAMesh\");"; }; %this.menuBar.insert(%toolsMenu); From b4623dc55899e4c83378f526820fbb22351d6322 Mon Sep 17 00:00:00 2001 From: Areloch Date: Sat, 18 May 2019 02:26:37 -0500 Subject: [PATCH 5/5] Cleanup of some of the loose file stuff, and ensures GameObjectAssets can be created properly. --- Engine/source/T3D/assets/GameObjectAsset.cpp | 18 +++++++++++++----- Engine/source/T3D/assets/MaterialAsset.cpp | 6 +++--- Engine/source/T3D/assets/MaterialAsset.h | 2 +- Engine/source/T3D/assets/ShapeAsset.cpp | 16 +++++++++++++--- Engine/source/assets/assetManager.cpp | 11 ++++++++++- Engine/source/console/simObject.h | 3 +++ .../core/components/Core_Components.module | 5 +++++ .../components/game/controlObject.asset.taml | 5 ++--- .../tools/assetBrowser/scripts/assetImport.cs | 5 ++++- 9 files changed, 54 insertions(+), 17 deletions(-) diff --git a/Engine/source/T3D/assets/GameObjectAsset.cpp b/Engine/source/T3D/assets/GameObjectAsset.cpp index c49588b8ec..9d56326945 100644 --- a/Engine/source/T3D/assets/GameObjectAsset.cpp +++ b/Engine/source/T3D/assets/GameObjectAsset.cpp @@ -40,6 +40,8 @@ #include "assets/assetPtr.h" #endif +#include "T3D/entity.h" + // Debug Profiling. #include "platform/profiler.h" @@ -133,10 +135,14 @@ void GameObjectAsset::copyTo(SimObject* object) void GameObjectAsset::initializeAsset() { //Ensure we have an expanded filepath - mScriptFile = expandAssetFilePath(mScriptFile); + if (!Platform::isFullPath(mScriptFile)) + mScriptFile = getOwned() ? expandAssetFilePath(mScriptFile) : mScriptFile; if (Platform::isFile(mScriptFile)) Con::executeFile(mScriptFile, false, false); + + if (!Platform::isFullPath(mTAMLFile)) + mTAMLFile = getOwned() ? expandAssetFilePath(mTAMLFile) : mTAMLFile; } void GameObjectAsset::onAssetRefresh() @@ -146,6 +152,8 @@ void GameObjectAsset::onAssetRefresh() if (Platform::isFile(mScriptFile)) Con::executeFile(mScriptFile, false, false); + + mTAMLFile = expandAssetFilePath(mTAMLFile); } void GameObjectAsset::setScriptFile(const char* pScriptFile) @@ -161,7 +169,7 @@ void GameObjectAsset::setScriptFile(const char* pScriptFile) return; // Update. - mScriptFile = getOwned() ? expandAssetFilePath(pScriptFile) : StringTable->insert(pScriptFile); + mScriptFile = getOwned() ? expandAssetFilePath(pScriptFile) : pScriptFile; // Refresh the asset. refreshAsset(); @@ -177,11 +185,11 @@ void GameObjectAsset::setTAMLFile(const char* pTAMLFile) pTAMLFile = StringTable->insert(pTAMLFile); // Ignore no change, - if (pTAMLFile == mScriptFile) + if (pTAMLFile == mTAMLFile) return; // Update. - mTAMLFile = getOwned() ? expandAssetFilePath(pTAMLFile) : StringTable->insert(pTAMLFile); + mTAMLFile = getOwned() ? expandAssetFilePath(pTAMLFile) : pTAMLFile; // Refresh the asset. refreshAsset(); @@ -214,7 +222,7 @@ const char* GameObjectAsset::create() } //Flag it so we know where it came from - pSimObject->setDataField("GameObject", nullptr, getAssetId()); + pSimObject->setDataField(StringTable->insert("GameObject"), nullptr, getAssetId()); return pSimObject->getIdString(); } diff --git a/Engine/source/T3D/assets/MaterialAsset.cpp b/Engine/source/T3D/assets/MaterialAsset.cpp index 5637d1effc..cace59c497 100644 --- a/Engine/source/T3D/assets/MaterialAsset.cpp +++ b/Engine/source/T3D/assets/MaterialAsset.cpp @@ -90,8 +90,8 @@ ConsoleSetType(TypeMaterialAssetPtr) MaterialAsset::MaterialAsset() { mShaderGraphFile = ""; - mScriptFile = ""; - mMatDefinitionName = ""; + mScriptFile = StringTable->EmptyString(); + mMatDefinitionName = StringTable->EmptyString(); } //----------------------------------------------------------------------------- @@ -111,7 +111,7 @@ void MaterialAsset::initPersistFields() addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, MaterialAsset), &setScriptFile, &getScriptFile, "Path to the file containing the material definition."); - addField("materialDefinitionName", TypeRealString, Offset(mMatDefinitionName, MaterialAsset), "Name of the material definition this asset is for."); + addField("materialDefinitionName", TypeString, Offset(mMatDefinitionName, MaterialAsset), "Name of the material definition this asset is for."); } void MaterialAsset::initializeAsset() diff --git a/Engine/source/T3D/assets/MaterialAsset.h b/Engine/source/T3D/assets/MaterialAsset.h index df6a135fbf..4ace9586ff 100644 --- a/Engine/source/T3D/assets/MaterialAsset.h +++ b/Engine/source/T3D/assets/MaterialAsset.h @@ -56,7 +56,7 @@ class MaterialAsset : public AssetBase typedef AssetBase Parent; String mShaderGraphFile; - String mScriptFile; + StringTableEntry mScriptFile; StringTableEntry mMatDefinitionName; public: diff --git a/Engine/source/T3D/assets/ShapeAsset.cpp b/Engine/source/T3D/assets/ShapeAsset.cpp index 1766dea7c2..d999c19e60 100644 --- a/Engine/source/T3D/assets/ShapeAsset.cpp +++ b/Engine/source/T3D/assets/ShapeAsset.cpp @@ -86,6 +86,7 @@ ConsoleSetType(TypeShapeAssetPtr) ShapeAsset::ShapeAsset() { + mFileName = StringTable->EmptyString(); } //----------------------------------------------------------------------------- @@ -129,6 +130,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; + loadShape(); } @@ -144,8 +149,7 @@ void ShapeAsset::setShapeFile(const char* pShapeFile) if (pShapeFile == mFileName) return; - // Update. - mFileName = getOwned() ? expandAssetFilePath(pShapeFile) : StringTable->insert(pShapeFile); + mFileName = pShapeFile; // Refresh the asset. refreshAsset(); @@ -156,6 +160,8 @@ void ShapeAsset::_onResourceChanged(const Torque::Path &path) if (path != Torque::Path(mFileName) ) return; + refreshAsset(); + loadShape(); } @@ -268,9 +274,13 @@ void ShapeAsset::copyTo(SimObject* object) void ShapeAsset::onAssetRefresh(void) { - if (dStrcmp(mFileName, "") == 0) + if (mFileName == StringTable->EmptyString()) return; + // Update. + if(!Platform::isFullPath(mFileName)) + mFileName = getOwned() ? expandAssetFilePath(mFileName) : mFileName; + loadShape(); } diff --git a/Engine/source/assets/assetManager.cpp b/Engine/source/assets/assetManager.cpp index 2018dd57cb..a2a51803f3 100644 --- a/Engine/source/assets/assetManager.cpp +++ b/Engine/source/assets/assetManager.cpp @@ -70,6 +70,9 @@ #ifndef MATERIALASSET_H #include "T3D/assets/MaterialAsset.h" #endif +#ifndef GAME_OBJECT_ASSET_H +#include "T3D/assets/GameObjectAsset.h" +#endif // Script bindings. #include "assetManager_ScriptBinding.h" @@ -272,10 +275,16 @@ bool AssetManager::loadModuleAutoLoadAssets(ModuleDefinition* pModuleDefinition) { assetBase = mTaml.read(assetDef->mAssetBaseFilePath); } + else if (assetDef->mAssetType == StringTable->insert("GameObjectAsset")) + { + assetBase = mTaml.read(assetDef->mAssetBaseFilePath); + } //load the asset now if valid if (assetBase) - addPrivateAsset(assetBase); + { + assetBase->setOwned(this, assetDef); + } } } } diff --git a/Engine/source/console/simObject.h b/Engine/source/console/simObject.h index 92850cb719..39201966c2 100644 --- a/Engine/source/console/simObject.h +++ b/Engine/source/console/simObject.h @@ -748,6 +748,9 @@ class SimObject: public ConsoleObject, public TamlCallbacks /// Performs a safe delayed delete of the object using a sim event. void safeDeleteObject(); + /// Special-case deletion behaviors, largely intended for cleanup in particular cases where it wouldn't happen automatically(like cleanup of associated files) + virtual void handleDeleteAction() {} + /// @} /// @name Accessors diff --git a/Templates/BaseGame/game/core/components/Core_Components.module b/Templates/BaseGame/game/core/components/Core_Components.module index 2c98b8091a..473e1303c6 100644 --- a/Templates/BaseGame/game/core/components/Core_Components.module +++ b/Templates/BaseGame/game/core/components/Core_Components.module @@ -11,4 +11,9 @@ canSaveDynamicFields="true" Extension="asset.taml" Recurse="true" /> + \ No newline at end of file diff --git a/Templates/BaseGame/game/core/components/components/game/controlObject.asset.taml b/Templates/BaseGame/game/core/components/components/game/controlObject.asset.taml index 7efa2d3a2e..bb21efb679 100644 --- a/Templates/BaseGame/game/core/components/components/game/controlObject.asset.taml +++ b/Templates/BaseGame/game/core/components/components/game/controlObject.asset.taml @@ -3,8 +3,7 @@ canSaveDynamicFields="true" AssetName="ControlObjectComponentAsset" componentName="ControlObjectComponent" - componentClass="Component" + componentClass="ControlObjectComponent" friendlyName="Control Object" componentType="Game" - description="Allows the component owner to be controlled by a client." - scriptFile="core/components/components/game/controlObject.cs" /> + description="Allows the component owner to be controlled by a client." /> diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImport.cs b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImport.cs index 1d23574b9d..8ff07e4925 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImport.cs +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/assetImport.cs @@ -71,6 +71,9 @@ function findImageFile(%path, %materialName, %type) %this.importAssetUnprocessedListArray.empty(); %this.importAssetFinalListArray.empty(); + //prep the import control + Canvas.pushDialog(AssetImportCtrl); + AssetImportCtrl.setHidden(true); ImportAssetTree.clear(); AssetBrowser.unprocessedAssetsCount = 0; } @@ -270,7 +273,7 @@ function findImageFile(%path, %materialName, %type) return; //we have assets to import, so go ahead and display the window for that now - Canvas.pushDialog(AssetImportCtrl); + AssetImportCtrl.setHidden(false); ImportAssetWindow.visible = true; //ImportAssetWindow.validateAssets(); ImportAssetWindow.refresh();