ShapeAsset.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  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. #ifndef _SHAPE_ASSET_H_
  23. #include "ShapeAsset.h"
  24. #endif
  25. #ifndef _ASSET_MANAGER_H_
  26. #include "assets/assetManager.h"
  27. #endif
  28. #ifndef _CONSOLETYPES_H_
  29. #include "console/consoleTypes.h"
  30. #endif
  31. #ifndef _TAML_
  32. #include "persistence/taml/taml.h"
  33. #endif
  34. #ifndef _ASSET_PTR_H_
  35. #include "assets/assetPtr.h"
  36. #endif
  37. #include "core/resourceManager.h"
  38. // Debug Profiling.
  39. #include "platform/profiler.h"
  40. #include "T3D/assets/assetImporter.h"
  41. #ifdef TORQUE_TOOLS
  42. #include "ts/tsLastDetail.h"
  43. #endif
  44. #include "util/imposterCapture.h"
  45. StringTableEntry ShapeAsset::smNoShapeAssetFallback = NULL;
  46. //-----------------------------------------------------------------------------
  47. IMPLEMENT_CONOBJECT(ShapeAsset);
  48. ConsoleType(assetIdString, TypeShapeAssetPtr, String, ASSET_ID_FIELD_PREFIX)
  49. ConsoleGetType(TypeShapeAssetPtr)
  50. {
  51. // Fetch asset Id.
  52. //return *((StringTableEntry*)dptr);
  53. return (*((AssetPtr<ShapeAsset>*)dptr)).getAssetId();
  54. }
  55. ConsoleSetType(TypeShapeAssetPtr)
  56. {
  57. // Was a single argument specified?
  58. if (argc == 1)
  59. {
  60. // Yes, so fetch field value.
  61. const char* pFieldValue = argv[0];
  62. // Fetch asset Id.
  63. StringTableEntry* assetId = (StringTableEntry*)(dptr);
  64. // Update asset value.
  65. *assetId = StringTable->insert(pFieldValue);
  66. return;
  67. }
  68. // Warn.
  69. Con::warnf("(TypeAssetId) - Cannot set multiple args to a single asset.");
  70. }
  71. //-----------------------------------------------------------------------------
  72. ConsoleType(assetIdString, TypeShapeAssetId, const char*, ASSET_ID_FIELD_PREFIX)
  73. ConsoleGetType(TypeShapeAssetId)
  74. {
  75. // Fetch asset Id.
  76. return *((const char**)(dptr));
  77. }
  78. ConsoleSetType(TypeShapeAssetId)
  79. {
  80. // Was a single argument specified?
  81. if (argc == 1)
  82. {
  83. // Yes, so fetch field value.
  84. *((const char**)dptr) = StringTable->insert(argv[0]);
  85. return;
  86. }
  87. // Warn.
  88. Con::warnf("(TypeAssetId) - Cannot set multiple args to a single asset.");
  89. }
  90. //-----------------------------------------------------------------------------
  91. const String ShapeAsset::mErrCodeStrings[] =
  92. {
  93. "TooManyVerts",
  94. "TooManyBones",
  95. "MissingAnimatons",
  96. "UnKnown"
  97. };
  98. //-----------------------------------------------------------------------------
  99. ShapeAsset::ShapeAsset()
  100. {
  101. mFileName = StringTable->EmptyString();
  102. mConstructorFileName = StringTable->EmptyString();
  103. mFilePath = StringTable->EmptyString();
  104. mConstructorFilePath = StringTable->EmptyString();
  105. mDiffuseImposterFileName = StringTable->EmptyString();
  106. mDiffuseImposterPath = StringTable->EmptyString();
  107. mNormalImposterFileName = StringTable->EmptyString();
  108. mNormalImposterPath = StringTable->EmptyString();
  109. mLoadedState = AssetErrCode::NotLoaded;
  110. }
  111. //-----------------------------------------------------------------------------
  112. ShapeAsset::~ShapeAsset()
  113. {
  114. }
  115. //-----------------------------------------------------------------------------
  116. void ShapeAsset::consoleInit()
  117. {
  118. Parent::consoleInit();
  119. Con::addVariable("$Core::NoShapeAssetFallback", TypeString, &smNoShapeAssetFallback,
  120. "The assetId of the shape to display when the requested shape asset is missing.\n"
  121. "@ingroup GFX\n");
  122. smNoShapeAssetFallback = StringTable->insert(Con::getVariable("$Core::NoShapeAssetFallback"));
  123. }
  124. //-----------------------------------------------------------------------------
  125. void ShapeAsset::initPersistFields()
  126. {
  127. // Call parent.
  128. Parent::initPersistFields();
  129. addProtectedField("fileName", TypeAssetLooseFilePath, Offset(mFileName, ShapeAsset),
  130. &setShapeFile, &getShapeFile, "Path to the shape file we want to render");
  131. addProtectedField("constuctorFileName", TypeAssetLooseFilePath, Offset(mConstructorFileName, ShapeAsset),
  132. &setShapeConstructorFile, &getShapeConstructorFile, "Path to the shape file we want to render");
  133. addProtectedField("diffuseImposterFileName", TypeAssetLooseFilePath, Offset(mDiffuseImposterFileName, ShapeAsset),
  134. &setDiffuseImposterFile, &getDiffuseImposterFile, "Path to the diffuse imposter file we want to render");
  135. addProtectedField("normalImposterFileName", TypeAssetLooseFilePath, Offset(mNormalImposterFileName, ShapeAsset),
  136. &setNormalImposterFile, &getNormalImposterFile, "Path to the normal imposter file we want to render");
  137. }
  138. void ShapeAsset::setDataField(StringTableEntry slotName, StringTableEntry array, StringTableEntry value)
  139. {
  140. Parent::setDataField(slotName, array, value);
  141. //Now, if it's a material slot of some fashion, set it up
  142. StringTableEntry matSlotName = StringTable->insert("materialAsset");
  143. if (String(slotName).startsWith(matSlotName))
  144. {
  145. StringTableEntry matId = StringTable->insert(value);
  146. mMaterialAssetIds.push_back(matId);
  147. }
  148. }
  149. void ShapeAsset::initializeAsset()
  150. {
  151. // Call parent.
  152. Parent::initializeAsset();
  153. if (mFileName == StringTable->EmptyString())
  154. return;
  155. ResourceManager::get().getChangedSignal().notify(this, &ShapeAsset::_onResourceChanged);
  156. //Ensure our path is expando'd if it isn't already
  157. mFilePath = getOwned() ? expandAssetFilePath(mFileName) : mFilePath;
  158. mConstructorFilePath = getOwned() ? expandAssetFilePath(mConstructorFilePath) : mConstructorFilePath;
  159. mDiffuseImposterPath = getOwned() ? expandAssetFilePath(mDiffuseImposterFileName) : mDiffuseImposterFileName;
  160. if (mDiffuseImposterPath == StringTable->EmptyString())
  161. {
  162. String diffusePath = String(mFilePath) + "_imposter.dds";
  163. mDiffuseImposterPath = StringTable->insert(diffusePath.c_str());
  164. }
  165. mNormalImposterPath = getOwned() ? expandAssetFilePath(mNormalImposterFileName) : mNormalImposterFileName;
  166. if (mNormalImposterPath == StringTable->EmptyString())
  167. {
  168. String normalPath = String(mFilePath) + "_imposter_normals.dds";
  169. mNormalImposterPath = StringTable->insert(normalPath.c_str());
  170. }
  171. loadShape();
  172. }
  173. void ShapeAsset::setShapeFile(const char* pShapeFile)
  174. {
  175. // Sanity!
  176. AssertFatal(pShapeFile != NULL, "Cannot use a NULL shape file.");
  177. // Fetch image file.
  178. pShapeFile = StringTable->insert(pShapeFile, true);
  179. // Ignore no change,
  180. if (pShapeFile == mFileName)
  181. return;
  182. mFileName = getOwned() ? expandAssetFilePath(pShapeFile) : pShapeFile;
  183. // Refresh the asset.
  184. refreshAsset();
  185. }
  186. void ShapeAsset::setShapeConstructorFile(const char* pShapeConstructorFile)
  187. {
  188. // Sanity!
  189. AssertFatal(pShapeConstructorFile != NULL, "Cannot use a NULL shape constructor file.");
  190. // Fetch image file.
  191. pShapeConstructorFile = StringTable->insert(pShapeConstructorFile, true);
  192. // Ignore no change,
  193. if (pShapeConstructorFile == mConstructorFileName)
  194. return;
  195. mConstructorFileName = getOwned() ? expandAssetFilePath(pShapeConstructorFile) : pShapeConstructorFile;
  196. // Refresh the asset.
  197. refreshAsset();
  198. }
  199. void ShapeAsset::setDiffuseImposterFile(const char* pImageFile)
  200. {
  201. // Sanity!
  202. AssertFatal(pImageFile != NULL, "Cannot use a NULL image file.");
  203. // Fetch image file.
  204. pImageFile = StringTable->insert(pImageFile, true);
  205. // Ignore no change,
  206. if (pImageFile == mDiffuseImposterFileName)
  207. return;
  208. mDiffuseImposterFileName = getOwned() ? expandAssetFilePath(pImageFile) : pImageFile;
  209. // Refresh the asset.
  210. refreshAsset();
  211. }
  212. void ShapeAsset::setNormalImposterFile(const char* pImageFile)
  213. {
  214. // Sanity!
  215. AssertFatal(pImageFile != NULL, "Cannot use a NULL image file.");
  216. // Fetch image file.
  217. pImageFile = StringTable->insert(pImageFile, true);
  218. // Ignore no change,
  219. if (pImageFile == mNormalImposterFileName)
  220. return;
  221. mNormalImposterFileName = getOwned() ? expandAssetFilePath(pImageFile) : pImageFile;
  222. // Refresh the asset.
  223. refreshAsset();
  224. }
  225. void ShapeAsset::_onResourceChanged(const Torque::Path &path)
  226. {
  227. if (path != Torque::Path(mFilePath) )
  228. return;
  229. refreshAsset();
  230. loadShape();
  231. }
  232. bool ShapeAsset::loadShape()
  233. {
  234. mMaterialAssets.clear();
  235. mMaterialAssetIds.clear();
  236. //First, load any material, animation, etc assets we may be referencing in our asset
  237. // Find any asset dependencies.
  238. AssetManager::typeAssetDependsOnHash::Iterator assetDependenciesItr = mpOwningAssetManager->getDependedOnAssets()->find(mpAssetDefinition->mAssetId);
  239. // Does the asset have any dependencies?
  240. if (assetDependenciesItr != mpOwningAssetManager->getDependedOnAssets()->end())
  241. {
  242. // Iterate all dependencies.
  243. while (assetDependenciesItr != mpOwningAssetManager->getDependedOnAssets()->end() && assetDependenciesItr->key == mpAssetDefinition->mAssetId)
  244. {
  245. StringTableEntry assetType = mpOwningAssetManager->getAssetType(assetDependenciesItr->value);
  246. if (assetType == StringTable->insert("MaterialAsset"))
  247. {
  248. mMaterialAssetIds.push_front(assetDependenciesItr->value);
  249. //Force the asset to become initialized if it hasn't been already
  250. AssetPtr<MaterialAsset> matAsset = assetDependenciesItr->value;
  251. mMaterialAssets.push_front(matAsset);
  252. }
  253. else if (assetType == StringTable->insert("ShapeAnimationAsset"))
  254. {
  255. mAnimationAssetIds.push_back(assetDependenciesItr->value);
  256. //Force the asset to become initialized if it hasn't been already
  257. AssetPtr<ShapeAnimationAsset> animAsset = assetDependenciesItr->value;
  258. mAnimationAssets.push_back(animAsset);
  259. }
  260. // Next dependency.
  261. assetDependenciesItr++;
  262. }
  263. }
  264. mShape = ResourceManager::get().load(mFilePath);
  265. if (!mShape)
  266. {
  267. Con::errorf("ShapeAsset::loadShape : failed to load shape file %s (%s)!", getAssetName(), mFilePath);
  268. mLoadedState = BadFileReference;
  269. return false; //if it failed to load, bail out
  270. }
  271. mShape->setupBillboardDetails(mFilePath, mDiffuseImposterPath, mNormalImposterPath);
  272. //If they exist, grab our imposters here and bind them to our shapeAsset
  273. bool hasBlends = false;
  274. //Now that we've successfully loaded our shape and have any materials and animations loaded
  275. //we need to set up the animations we're using on our shape
  276. for (S32 i = mAnimationAssets.size()-1; i >= 0; --i)
  277. {
  278. String srcName = mAnimationAssets[i]->getAnimationName();
  279. String srcPath(mAnimationAssets[i]->getAnimationFilename());
  280. //SplitSequencePathAndName(srcPath, srcName);
  281. if (!mShape->addSequence(srcPath, srcName, srcName,
  282. mAnimationAssets[i]->getStartFrame(), mAnimationAssets[i]->getEndFrame(), mAnimationAssets[i]->getPadRotation(), mAnimationAssets[i]->getPadTransforms()))
  283. {
  284. mLoadedState = MissingAnimatons;
  285. return false;
  286. }
  287. if (mAnimationAssets[i]->isBlend())
  288. hasBlends = true;
  289. }
  290. //if any of our animations are blends, set those up now
  291. if (hasBlends)
  292. {
  293. for (U32 i=0; i < mAnimationAssets.size(); ++i)
  294. {
  295. if (mAnimationAssets[i]->isBlend() && mAnimationAssets[i]->getBlendAnimationName() != StringTable->EmptyString())
  296. {
  297. //gotta do a bit of logic here.
  298. //First, we need to make sure the anim asset we depend on for our blend is loaded
  299. AssetPtr<ShapeAnimationAsset> blendAnimAsset = mAnimationAssets[i]->getBlendAnimationName();
  300. if (blendAnimAsset.isNull())
  301. {
  302. Con::errorf("ShapeAsset::initializeAsset - Unable to acquire reference animation asset %s for asset %s to blend!", mAnimationAssets[i]->getBlendAnimationName(), mAnimationAssets[i]->getAssetName());
  303. {
  304. mLoadedState = MissingAnimatons;
  305. return false;
  306. }
  307. }
  308. String refAnimName = blendAnimAsset->getAnimationName();
  309. if (!mShape->setSequenceBlend(mAnimationAssets[i]->getAnimationName(), true, blendAnimAsset->getAnimationName(), mAnimationAssets[i]->getBlendFrame()))
  310. {
  311. Con::errorf("ShapeAnimationAsset::initializeAsset - Unable to set animation clip %s for asset %s to blend!", mAnimationAssets[i]->getAnimationName(), mAnimationAssets[i]->getAssetName());
  312. {
  313. mLoadedState = MissingAnimatons;
  314. return false;
  315. }
  316. }
  317. }
  318. }
  319. }
  320. mChangeSignal.trigger();
  321. mLoadedState = Ok;
  322. return true;
  323. }
  324. //------------------------------------------------------------------------------
  325. //Utility function to 'fill out' bindings and resources with a matching asset if one exists
  326. U32 ShapeAsset::getAssetByFilename(StringTableEntry fileName, AssetPtr<ShapeAsset>* shapeAsset)
  327. {
  328. AssetQuery query;
  329. S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, fileName);
  330. if (foundAssetcount == 0)
  331. {
  332. //Didn't work, so have us fall back to a placeholder asset
  333. shapeAsset->setAssetId(ShapeAsset::smNoShapeAssetFallback);
  334. if (shapeAsset->isNull())
  335. {
  336. //Well that's bad, loading the fallback failed.
  337. Con::warnf("ShapeAsset::getAssetByFilename - Finding of asset associated with file %s failed with no fallback asset", fileName);
  338. return AssetErrCode::Failed;
  339. }
  340. //handle noshape not being loaded itself
  341. if ((*shapeAsset)->mLoadedState == BadFileReference)
  342. {
  343. Con::warnf("ShapeAsset::getAssetByFilename - Finding of associated with file %s failed, and fallback asset reported error of Bad File Reference.", fileName);
  344. return AssetErrCode::BadFileReference;
  345. }
  346. Con::warnf("ShapeAsset::getAssetByFilename - Finding of associated with file %s failed, utilizing fallback asset", fileName);
  347. (*shapeAsset)->mLoadedState = AssetErrCode::UsingFallback;
  348. return AssetErrCode::UsingFallback;
  349. }
  350. else
  351. {
  352. //acquire and bind the asset, and return it out
  353. shapeAsset->setAssetId(query.mAssetList[0]);
  354. return (*shapeAsset)->mLoadedState;
  355. }
  356. }
  357. StringTableEntry ShapeAsset::getAssetIdByFilename(StringTableEntry fileName)
  358. {
  359. if (fileName == StringTable->EmptyString())
  360. return StringTable->EmptyString();
  361. StringTableEntry shapeAssetId = ShapeAsset::smNoShapeAssetFallback;
  362. AssetQuery query;
  363. S32 foundAssetcount = AssetDatabase.findAssetLooseFile(&query, fileName);
  364. if (foundAssetcount != 0)
  365. {
  366. //acquire and bind the asset, and return it out
  367. shapeAssetId = query.mAssetList[0];
  368. }
  369. return shapeAssetId;
  370. }
  371. U32 ShapeAsset::getAssetById(StringTableEntry assetId, AssetPtr<ShapeAsset>* shapeAsset)
  372. {
  373. (*shapeAsset) = assetId;
  374. if (shapeAsset->notNull())
  375. {
  376. return (*shapeAsset)->mLoadedState;
  377. }
  378. else
  379. {
  380. //Didn't work, so have us fall back to a placeholder asset
  381. shapeAsset->setAssetId(ShapeAsset::smNoShapeAssetFallback);
  382. if (shapeAsset->isNull())
  383. {
  384. //Well that's bad, loading the fallback failed.
  385. Con::warnf("ShapeAsset::getAssetById - Finding of asset with id %s failed with no fallback asset", assetId);
  386. return AssetErrCode::Failed;
  387. }
  388. //handle noshape not being loaded itself
  389. if ((*shapeAsset)->mLoadedState == BadFileReference)
  390. {
  391. Con::warnf("ShapeAsset::getAssetById - Finding of asset with id %s failed, and fallback asset reported error of Bad File Reference.", assetId);
  392. return AssetErrCode::BadFileReference;
  393. }
  394. Con::warnf("ShapeAsset::getAssetById - Finding of asset with id %s failed, utilizing fallback asset", assetId);
  395. (*shapeAsset)->mLoadedState = AssetErrCode::UsingFallback;
  396. return AssetErrCode::UsingFallback;
  397. }
  398. }
  399. //------------------------------------------------------------------------------
  400. void ShapeAsset::copyTo(SimObject* object)
  401. {
  402. // Call to parent.
  403. Parent::copyTo(object);
  404. }
  405. void ShapeAsset::onAssetRefresh(void)
  406. {
  407. if (mFileName == StringTable->EmptyString())
  408. return;
  409. // Update.
  410. if(!Platform::isFullPath(mFileName))
  411. mFilePath = getOwned() ? expandAssetFilePath(mFileName) : mFilePath;
  412. loadShape();
  413. }
  414. void ShapeAsset::SplitSequencePathAndName(String& srcPath, String& srcName)
  415. {
  416. srcName = "";
  417. // Determine if there is a sequence name at the end of the source string, and
  418. // if so, split the filename from the sequence name
  419. S32 split = srcPath.find(' ', 0, String::Right);
  420. S32 split2 = srcPath.find('\t', 0, String::Right);
  421. if ((split == String::NPos) || (split2 > split))
  422. split = split2;
  423. if (split != String::NPos)
  424. {
  425. split2 = split + 1;
  426. while ((srcPath[split2] != '\0') && dIsspace(srcPath[split2]))
  427. split2++;
  428. // now 'split' is at the end of the path, and 'split2' is at the start of the sequence name
  429. srcName = srcPath.substr(split2);
  430. srcPath = srcPath.erase(split, srcPath.length() - split);
  431. }
  432. }
  433. ShapeAnimationAsset* ShapeAsset::getAnimation(S32 index)
  434. {
  435. if (index < mAnimationAssets.size())
  436. {
  437. return mAnimationAssets[index];
  438. }
  439. return nullptr;
  440. }
  441. #ifdef TORQUE_TOOLS
  442. const char* ShapeAsset::generateCachedPreviewImage(S32 resolution)
  443. {
  444. if (!mShape)
  445. return "";
  446. TSLastDetail* dt = new TSLastDetail(mShape,
  447. mFilePath,
  448. 1,
  449. 0,
  450. 0,
  451. false,
  452. 0,
  453. resolution);
  454. dt->update();
  455. delete dt;
  456. return mFilePath;
  457. }
  458. #endif
  459. DefineEngineMethod(ShapeAsset, getMaterialCount, S32, (), ,
  460. "Gets the number of materials for this shape asset.\n"
  461. "@return Material count.\n")
  462. {
  463. return object->getMaterialCount();
  464. }
  465. DefineEngineMethod(ShapeAsset, getAnimationCount, S32, (), ,
  466. "Gets the number of animations for this shape asset.\n"
  467. "@return Animation count.\n")
  468. {
  469. return object->getAnimationCount();
  470. }
  471. DefineEngineMethod(ShapeAsset, getAnimation, ShapeAnimationAsset*, (S32 index), (0),
  472. "Gets a particular shape animation asset for this shape.\n"
  473. "@param animation asset index.\n"
  474. "@return Shape Animation Asset.\n")
  475. {
  476. return object->getAnimation(index);
  477. }
  478. DefineEngineMethod(ShapeAsset, getShapeFile, const char*, (), ,
  479. "Gets the shape's file path\n"
  480. "@return The filename of the shape file")
  481. {
  482. return object->getShapeFilePath();
  483. }
  484. DefineEngineMethod(ShapeAsset, getShapeConstructorFilePath, const char*, (), ,
  485. "Gets the shape's constructor file.\n"
  486. "@return The filename of the shape constructor file")
  487. {
  488. return object->getShapeConstructorFilePath();
  489. }
  490. DefineEngineMethod(ShapeAsset, getStatusString, String, (), , "get status string")\
  491. {
  492. return ShapeAsset::getAssetErrstrn(object->getStatus());
  493. }
  494. #ifdef TORQUE_TOOLS
  495. DefineEngineMethod(ShapeAsset, generateCachedPreviewImage, const char*, (S32 resolution), (256), "")
  496. {
  497. return object->generateCachedPreviewImage(resolution);
  498. }
  499. DefineEngineStaticMethod(ShapeAsset, getAssetIdByFilename, const char*, (const char* filePath), (""),
  500. "Queries the Asset Database to see if any asset exists that is associated with the provided file path.\n"
  501. "@return The AssetId of the associated asset, if any.")
  502. {
  503. return ShapeAsset::getAssetIdByFilename(StringTable->insert(filePath));
  504. }
  505. #endif
  506. //-----------------------------------------------------------------------------
  507. // GuiInspectorTypeAssetId
  508. //-----------------------------------------------------------------------------
  509. #ifdef TORQUE_TOOLS
  510. IMPLEMENT_CONOBJECT(GuiInspectorTypeShapeAssetPtr);
  511. ConsoleDocClass(GuiInspectorTypeShapeAssetPtr,
  512. "@brief Inspector field type for Shapes\n\n"
  513. "Editor use only.\n\n"
  514. "@internal"
  515. );
  516. void GuiInspectorTypeShapeAssetPtr::consoleInit()
  517. {
  518. Parent::consoleInit();
  519. ConsoleBaseType::getType(TypeShapeAssetPtr)->setInspectorFieldType("GuiInspectorTypeShapeAssetPtr");
  520. }
  521. GuiControl* GuiInspectorTypeShapeAssetPtr::constructEditControl()
  522. {
  523. // Create base filename edit controls
  524. GuiControl *retCtrl = Parent::constructEditControl();
  525. if (retCtrl == NULL)
  526. return retCtrl;
  527. // Change filespec
  528. char szBuffer[512];
  529. dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"ShapeAsset\", \"AssetBrowser.changeAsset\", %s, %s);",
  530. mInspector->getIdString(), mCaption);
  531. mBrowseButton->setField("Command", szBuffer);
  532. setDataField(StringTable->insert("targetObject"), NULL, mInspector->getInspectObject()->getIdString());
  533. // Create "Open in ShapeEditor" button
  534. mShapeEdButton = new GuiBitmapButtonCtrl();
  535. dSprintf(szBuffer, sizeof(szBuffer), "ShapeEditorPlugin.openShapeAssetId(%d.getText());", retCtrl->getId());
  536. mShapeEdButton->setField("Command", szBuffer);
  537. char bitmapName[512] = "ToolsModule:shape_editor_n_image";
  538. mShapeEdButton->setBitmap(StringTable->insert(bitmapName));
  539. mShapeEdButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
  540. mShapeEdButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
  541. mShapeEdButton->setDataField(StringTable->insert("hovertime"), NULL, "1000");
  542. mShapeEdButton->setDataField(StringTable->insert("tooltip"), NULL, "Open this file in the Shape Editor");
  543. mShapeEdButton->registerObject();
  544. addObject(mShapeEdButton);
  545. return retCtrl;
  546. }
  547. bool GuiInspectorTypeShapeAssetPtr::updateRects()
  548. {
  549. S32 dividerPos, dividerMargin;
  550. mInspector->getDivider(dividerPos, dividerMargin);
  551. Point2I fieldExtent = getExtent();
  552. Point2I fieldPos = getPosition();
  553. mCaptionRect.set(0, 0, fieldExtent.x - dividerPos - dividerMargin, fieldExtent.y);
  554. mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin - 34, fieldExtent.y);
  555. bool resized = mEdit->resize(mEditCtrlRect.point, mEditCtrlRect.extent);
  556. if (mBrowseButton != NULL)
  557. {
  558. mBrowseRect.set(fieldExtent.x - 32, 2, 14, fieldExtent.y - 4);
  559. resized |= mBrowseButton->resize(mBrowseRect.point, mBrowseRect.extent);
  560. }
  561. if (mShapeEdButton != NULL)
  562. {
  563. RectI shapeEdRect(fieldExtent.x - 16, 2, 14, fieldExtent.y - 4);
  564. resized |= mShapeEdButton->resize(shapeEdRect.point, shapeEdRect.extent);
  565. }
  566. return resized;
  567. }
  568. IMPLEMENT_CONOBJECT(GuiInspectorTypeShapeAssetId);
  569. ConsoleDocClass(GuiInspectorTypeShapeAssetId,
  570. "@brief Inspector field type for Shapes\n\n"
  571. "Editor use only.\n\n"
  572. "@internal"
  573. );
  574. void GuiInspectorTypeShapeAssetId::consoleInit()
  575. {
  576. Parent::consoleInit();
  577. ConsoleBaseType::getType(TypeShapeAssetId)->setInspectorFieldType("GuiInspectorTypeShapeAssetId");
  578. }
  579. #endif