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