TerrainMaterialAsset.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #pragma once
  23. #ifndef TERRAINMATERIALASSET_H
  24. #define TERRAINMATERIALASSET_H
  25. #ifndef _ASSET_BASE_H_
  26. #include "assets/assetBase.h"
  27. #endif
  28. #ifndef _ASSET_DEFINITION_H_
  29. #include "assets/assetDefinition.h"
  30. #endif
  31. #ifndef _STRINGUNIT_H_
  32. #include "string/stringUnit.h"
  33. #endif
  34. #ifndef _ASSET_FIELD_TYPES_H_
  35. #include "assets/assetFieldTypes.h"
  36. #endif
  37. #ifndef _GFXDEVICE_H_
  38. #include "gfx/gfxDevice.h"
  39. #endif
  40. #ifndef _GUI_INSPECTOR_TYPES_H_
  41. #include "gui/editor/guiInspectorTypes.h"
  42. #endif
  43. #ifndef _TERRMATERIAL_H_
  44. #include "terrain/terrMaterial.h"
  45. #endif
  46. #ifndef _MATERIALDEFINITION_H_
  47. #include "materials/materialDefinition.h"
  48. #endif
  49. //-----------------------------------------------------------------------------
  50. class TerrainMaterialAsset : public AssetBase
  51. {
  52. typedef AssetBase Parent;
  53. StringTableEntry mScriptFile;
  54. StringTableEntry mScriptPath;
  55. StringTableEntry mMatDefinitionName;
  56. SimObjectPtr<TerrainMaterial> mMaterialDefinition;
  57. SimObjectPtr<Material> mFXMaterialDefinition;
  58. public:
  59. static StringTableEntry smNoTerrainMaterialAssetFallback;
  60. enum TerrainMaterialAssetErrCode
  61. {
  62. ScriptLoaded = AssetErrCode::Extended,
  63. DefinitionAlreadyExists,
  64. EmbeddedDefinition,
  65. Extended
  66. };
  67. public:
  68. TerrainMaterialAsset();
  69. virtual ~TerrainMaterialAsset();
  70. /// Set up some global script interface stuff.
  71. static void consoleInit();
  72. /// Engine.
  73. static void initPersistFields();
  74. void copyTo(SimObject* object) override;
  75. U32 load() override;
  76. StringTableEntry getMaterialDefinitionName() { return mMatDefinitionName; }
  77. SimObjectPtr<TerrainMaterial> getMaterialDefinition() { return mMaterialDefinition; }
  78. SimObjectPtr<Material> getFXMaterialDefinition() { return mFXMaterialDefinition; }
  79. void setScriptFile(const char* pScriptFile);
  80. inline StringTableEntry getScriptFile(void) const { return mScriptFile; };
  81. inline StringTableEntry getScriptPath(void) const { return mScriptPath; };
  82. /// <summary>
  83. /// Looks for any assets that uses the provided Material Definition name.
  84. /// If none are found, attempts to auto-import the material definition if the
  85. /// material definition exists.
  86. /// </summary>
  87. /// <param name="matName">Material Definition name to look for</param>
  88. /// <returns>AssetId of matching asset.</returns>
  89. static StringTableEntry getAssetIdByMaterialName(StringTableEntry matName);
  90. static U32 getAssetById(StringTableEntry assetId, AssetPtr<TerrainMaterialAsset>* materialAsset);
  91. static SimObjectPtr<TerrainMaterial> findMaterialDefinitionByAssetId(StringTableEntry assetId);
  92. static U32 getAssetByMaterialName(StringTableEntry matName, AssetPtr<TerrainMaterialAsset>* matAsset);
  93. /// Declare Console Object.
  94. DECLARE_CONOBJECT(TerrainMaterialAsset);
  95. protected:
  96. void initializeAsset() override;
  97. void onAssetRefresh(void) override;
  98. static bool setScriptFile(void *obj, const char *index, const char *data)
  99. {
  100. static_cast<TerrainMaterialAsset*>(obj)->setScriptFile(data);
  101. return false;
  102. }
  103. static const char* getScriptFile(void* obj, const char* data) { return static_cast<TerrainMaterialAsset*>(obj)->getScriptFile(); }
  104. };
  105. DefineConsoleType(TypeTerrainMaterialAssetPtr, TerrainMaterialAsset)
  106. DefineConsoleType(TypeTerrainMaterialAssetId, String)
  107. #ifdef TORQUE_TOOLS
  108. //-----------------------------------------------------------------------------
  109. // TypeAssetId GuiInspectorField Class
  110. //-----------------------------------------------------------------------------
  111. class GuiInspectorTypeTerrainMaterialAssetPtr : public GuiInspectorTypeFileName
  112. {
  113. typedef GuiInspectorTypeFileName Parent;
  114. public:
  115. GuiBitmapButtonCtrl* mEditButton;
  116. DECLARE_CONOBJECT(GuiInspectorTypeTerrainMaterialAssetPtr);
  117. static void consoleInit();
  118. GuiControl* constructEditControl() override;
  119. bool updateRects() override;
  120. };
  121. class GuiInspectorTypeTerrainMaterialAssetId : public GuiInspectorTypeTerrainMaterialAssetPtr
  122. {
  123. typedef GuiInspectorTypeTerrainMaterialAssetPtr Parent;
  124. public:
  125. DECLARE_CONOBJECT(GuiInspectorTypeTerrainMaterialAssetId);
  126. static void consoleInit();
  127. };
  128. #endif
  129. #endif // _ASSET_BASE_H_