Torque3D Documentation / _generateds / TerrainMaterialAsset.cpp

TerrainMaterialAsset.cpp

Engine/source/T3D/assets/TerrainMaterialAsset.cpp

More...

Public Functions

ConsoleDocClass(GuiInspectorTypeTerrainMaterialAssetPtr , "@brief Inspector field type <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/class/classmaterial/">Material</a> Asset <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Objects\n\n</a>" "Editor use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" "@internal" )
ConsoleSetType(TypeTerrainMaterialAssetPtr )
ConsoleType(TerrainMaterialAssetPtr , TypeTerrainMaterialAssetPtr , TerrainMaterialAsset , ASSET_ID_FIELD_PREFIX )
DefineEngineMethod(GuiInspectorTypeTerrainMaterialAssetPtr , setMaterialAsset , void , (String assetId) , ("") , "Gets <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> particular shape animation asset <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">shape.\n</a>" "@param animation asset <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">index.\n</a>" "@return Shape Animation <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Asset.\n</a>" )
DefineEngineMethod(TerrainMaterialAsset , compileShader , void , () , "Compiles the material's generated shader, <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> any. Not yet <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">implemented\n</a>" )

Detailed Description

Public Functions

ConsoleDocClass(GuiInspectorTypeTerrainMaterialAssetPtr , "@brief Inspector field type <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/class/classmaterial/">Material</a> Asset <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Objects\n\n</a>" "Editor use <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">only.\n\n</a>" "@internal" )

ConsoleSetType(TypeTerrainMaterialAssetPtr )

ConsoleType(TerrainMaterialAssetPtr , TypeTerrainMaterialAssetPtr , TerrainMaterialAsset , ASSET_ID_FIELD_PREFIX )

DefineEngineMethod(GuiInspectorTypeTerrainMaterialAssetPtr , setMaterialAsset , void , (String assetId) , ("") , "Gets <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> particular shape animation asset <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> this <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">shape.\n</a>" "@param animation asset <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">index.\n</a>" "@return Shape Animation <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Asset.\n</a>" )

DefineEngineMethod(TerrainMaterialAsset , compileShader , void , () , "Compiles the material's generated shader, <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> any. Not yet <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">implemented\n</a>" )

IMPLEMENT_CONOBJECT(GuiInspectorTypeTerrainMaterialAssetPtr )

IMPLEMENT_CONOBJECT(TerrainMaterialAsset )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2013 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef TERRAINMATERIALASSET_H
 25#include "TerrainMaterialAsset.h"
 26#endif
 27
 28#ifndef _ASSET_MANAGER_H_
 29#include "assets/assetManager.h"
 30#endif
 31
 32#ifndef _CONSOLETYPES_H_
 33#include "console/consoleTypes.h"
 34#endif
 35
 36#ifndef _TAML_
 37#include "persistence/taml/taml.h"
 38#endif
 39
 40#ifndef _ASSET_PTR_H_
 41#include "assets/assetPtr.h"
 42#endif
 43
 44//-----------------------------------------------------------------------------
 45
 46IMPLEMENT_CONOBJECT(TerrainMaterialAsset);
 47
 48ConsoleType(TerrainMaterialAssetPtr, TypeTerrainMaterialAssetPtr, TerrainMaterialAsset, ASSET_ID_FIELD_PREFIX)
 49
 50//-----------------------------------------------------------------------------
 51
 52ConsoleGetType(TypeTerrainMaterialAssetPtr)
 53{
 54   // Fetch asset Id.
 55   return (*((AssetPtr<TerrainMaterialAsset>*)dptr)).getAssetId();
 56}
 57
 58//-----------------------------------------------------------------------------
 59
 60ConsoleSetType(TypeTerrainMaterialAssetPtr)
 61{
 62   // Was a single argument specified?
 63   if (argc == 1)
 64   {
 65      // Yes, so fetch field value.
 66      const char* pFieldValue = argv[0];
 67
 68      // Fetch asset pointer.
 69      AssetPtr<TerrainMaterialAsset>* pAssetPtr = dynamic_cast<AssetPtr<TerrainMaterialAsset>*>((AssetPtrBase*)(dptr));
 70
 71      // Is the asset pointer the correct type?
 72      if (pAssetPtr == NULL)
 73      {
 74         // No, so fail.
 75         //Con::warnf("(TypeMaterialAssetPtr) - Failed to set asset Id '%d'.", pFieldValue);
 76         return;
 77      }
 78
 79      // Set asset.
 80      pAssetPtr->setAssetId(pFieldValue);
 81
 82      return;
 83   }
 84
 85   // Warn.
 86   Con::warnf("(TypeTerrainMaterialAssetPtr) - Cannot set multiple args to a single asset.");
 87}
 88
 89//-----------------------------------------------------------------------------
 90
 91TerrainMaterialAsset::TerrainMaterialAsset()
 92{
 93   mScriptFile = StringTable->EmptyString();
 94   mScriptPath = StringTable->EmptyString();
 95   mMatDefinitionName = StringTable->EmptyString();
 96}
 97
 98//-----------------------------------------------------------------------------
 99
100TerrainMaterialAsset::~TerrainMaterialAsset()
101{
102}
103
104//-----------------------------------------------------------------------------
105
106void TerrainMaterialAsset::initPersistFields()
107{
108   // Call parent.
109   Parent::initPersistFields();
110
111   //addField("shaderGraph", TypeRealString, Offset(mShaderGraphFile, TerrainMaterialAsset), "");
112   addProtectedField("scriptFile", TypeAssetLooseFilePath, Offset(mScriptFile, TerrainMaterialAsset),
113      &setScriptFile, &getScriptFile, "Path to the file containing the material definition.");
114
115   addField("materialDefinitionName", TypeString, Offset(mMatDefinitionName, TerrainMaterialAsset), "Name of the material definition this asset is for.");
116}
117
118void TerrainMaterialAsset::initializeAsset()
119{
120   // Call parent.
121   Parent::initializeAsset();
122
123   compileShader();
124
125   mScriptPath = expandAssetFilePath(mScriptFile);
126
127   if (Platform::isFile(mScriptPath))
128      Con::executeFile(mScriptPath, false, false);
129}
130
131void TerrainMaterialAsset::onAssetRefresh()
132{
133   mScriptPath = expandAssetFilePath(mScriptFile);
134
135   if (Platform::isFile(mScriptPath))
136      Con::executeFile(mScriptPath, false, false);
137
138   if (mMatDefinitionName != StringTable->EmptyString())
139   {
140      TerrainMaterial* matDef;
141      if (!Sim::findObject(mMatDefinitionName, matDef))
142      {
143         Con::errorf("TerrainMaterialAsset: Unable to find the Material %s", mMatDefinitionName);
144         return;
145      }
146
147      //matDef->reload();
148   }
149}
150
151void TerrainMaterialAsset::setScriptFile(const char* pScriptFile)
152{
153   // Sanity!
154   AssertFatal(pScriptFile != NULL, "Cannot use a NULL script file.");
155
156   // Fetch image file.
157   pScriptFile = StringTable->insert(pScriptFile);
158
159   // Update.
160   mScriptFile = pScriptFile;
161
162   // Refresh the asset.
163   refreshAsset();
164}
165
166//------------------------------------------------------------------------------
167
168void TerrainMaterialAsset::compileShader()
169{
170}
171
172void TerrainMaterialAsset::copyTo(SimObject* object)
173{
174   // Call to parent.
175   Parent::copyTo(object);
176}
177
178DefineEngineMethod(TerrainMaterialAsset, compileShader, void, (), , "Compiles the material's generated shader, if any. Not yet implemented\n")
179{
180   object->compileShader();
181}
182
183//-----------------------------------------------------------------------------
184// GuiInspectorTypeAssetId
185//-----------------------------------------------------------------------------
186
187IMPLEMENT_CONOBJECT(GuiInspectorTypeTerrainMaterialAssetPtr);
188
189ConsoleDocClass(GuiInspectorTypeTerrainMaterialAssetPtr,
190   "@brief Inspector field type for Material Asset Objects\n\n"
191   "Editor use only.\n\n"
192   "@internal"
193);
194
195void GuiInspectorTypeTerrainMaterialAssetPtr::consoleInit()
196{
197   Parent::consoleInit();
198
199   ConsoleBaseType::getType(TypeTerrainMaterialAssetPtr)->setInspectorFieldType("GuiInspectorTypeTerrainMaterialAssetPtr");
200}
201
202GuiControl* GuiInspectorTypeTerrainMaterialAssetPtr::constructEditControl()
203{
204   // Create base filename edit controls
205   mUseHeightOverride = true;
206   mHeightOverride = 100;
207
208   mMatEdContainer = new GuiControl();
209   mMatEdContainer->registerObject();
210
211   addObject(mMatEdContainer);
212
213   // Create "Open in ShapeEditor" button
214   mMatPreviewButton = new GuiBitmapButtonCtrl();
215
216   const char* matAssetId = getData();
217
218   TerrainMaterialAsset* matAsset = AssetDatabase.acquireAsset< TerrainMaterialAsset>(matAssetId);
219
220   TerrainMaterial* materialDef = nullptr;
221
222   char bitmapName[512] = "tools/worldEditor/images/toolbar/shape-editor";
223
224   /*if (!Sim::findObject(matAsset->getMaterialDefinitionName(), materialDef))
225   {
226      Con::errorf("GuiInspectorTypeTerrainMaterialAssetPtr::constructEditControl() - unable to find material in asset");
227   }
228   else
229   {
230      mMatPreviewButton->setBitmap(materialDef->mDiffuseMapFilename[0]);
231   }*/
232
233   mMatPreviewButton->setPosition(0, 0);
234   mMatPreviewButton->setExtent(100,100);
235
236   // Change filespec
237   char szBuffer[512];
238   dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"TerrainMaterialAsset\", \"AssetBrowser.changeAsset\", %d, %s);",
239      mInspector->getComponentGroupTargetId(), mCaption);
240   mMatPreviewButton->setField("Command", szBuffer);
241
242   mMatPreviewButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
243   mMatPreviewButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
244   mMatPreviewButton->setDataField(StringTable->insert("hovertime"), NULL, "1000");
245
246   StringBuilder strbld;
247   strbld.append(matAsset->getMaterialDefinitionName());
248   strbld.append("\n");
249   strbld.append("Open this file in the Material Editor");
250
251   mMatPreviewButton->setDataField(StringTable->insert("tooltip"), NULL, strbld.data());
252
253   _registerEditControl(mMatPreviewButton);
254   //mMatPreviewButton->registerObject();
255   mMatEdContainer->addObject(mMatPreviewButton);
256
257   mMatAssetIdTxt = new GuiTextEditCtrl();
258   mMatAssetIdTxt->registerObject();
259   mMatAssetIdTxt->setActive(false);
260
261   mMatAssetIdTxt->setText(matAssetId);
262
263   mMatAssetIdTxt->setBounds(100, 0, 150, 18);
264   mMatEdContainer->addObject(mMatAssetIdTxt);
265
266   return mMatEdContainer;
267}
268
269bool GuiInspectorTypeTerrainMaterialAssetPtr::updateRects()
270{
271   S32 dividerPos, dividerMargin;
272   mInspector->getDivider(dividerPos, dividerMargin);
273   Point2I fieldExtent = getExtent();
274   Point2I fieldPos = getPosition();
275
276   mCaptionRect.set(0, 0, fieldExtent.x - dividerPos - dividerMargin, fieldExtent.y);
277   mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin - 34, fieldExtent.y);
278
279   bool resized = mEdit->resize(mEditCtrlRect.point, mEditCtrlRect.extent);
280
281   if (mMatEdContainer != nullptr)
282   {
283      mMatPreviewButton->resize(mEditCtrlRect.point, mEditCtrlRect.extent);
284   }
285
286   if (mMatPreviewButton != nullptr)
287   {
288      mMatPreviewButton->resize(Point2I::Zero, Point2I(100, 100));
289   }
290
291   if (mMatAssetIdTxt != nullptr)
292   {
293      mMatAssetIdTxt->resize(Point2I(100, 0), Point2I(mEditCtrlRect.extent.x - 100, 18));
294   }
295
296   return resized;
297}
298
299void GuiInspectorTypeTerrainMaterialAssetPtr::setMaterialAsset(String assetId)
300{
301   mTargetObject->setDataField(mCaption, "", assetId);
302
303   //force a refresh
304   SimObject* obj = mInspector->getInspectObject();
305   mInspector->inspectObject(obj);
306}
307
308DefineEngineMethod(GuiInspectorTypeTerrainMaterialAssetPtr, setMaterialAsset, void, (String assetId), (""),
309   "Gets a particular shape animation asset for this shape.\n"
310   "@param animation asset index.\n"
311   "@return Shape Animation Asset.\n")
312{
313   if (assetId == String::EmptyString)
314      return;
315
316   return object->setMaterialAsset(assetId);
317}
318