ShapeAnimationAsset.cpp
Engine/source/T3D/assets/ShapeAnimationAsset.cpp
Public Functions
ConsoleSetType(TypeShapeAnimationAssetPtr )
ConsoleType(ShapeAnimationAssetPtr , TypeShapeAnimationAssetPtr , ShapeAnimationAsset , ASSET_ID_FIELD_PREFIX )
DefineEngineMethod(ShapeAnimationAsset , 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>" )
Detailed Description
Public Functions
ConsoleSetType(TypeShapeAnimationAssetPtr )
ConsoleType(ShapeAnimationAssetPtr , TypeShapeAnimationAssetPtr , ShapeAnimationAsset , ASSET_ID_FIELD_PREFIX )
DefineEngineMethod(ShapeAnimationAsset , 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>" )
IMPLEMENT_CONOBJECT(ShapeAnimationAsset )
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_ANIMATION_ASSET_H 25#include "ShapeAnimationAsset.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 49//----------------------------------------------------------------------------- 50 51IMPLEMENT_CONOBJECT(ShapeAnimationAsset); 52 53ConsoleType(ShapeAnimationAssetPtr, TypeShapeAnimationAssetPtr, ShapeAnimationAsset, ASSET_ID_FIELD_PREFIX) 54 55//----------------------------------------------------------------------------- 56 57ConsoleGetType(TypeShapeAnimationAssetPtr) 58{ 59 // Fetch asset Id. 60 return (*((AssetPtr<ShapeAnimationAsset>*)dptr)).getAssetId(); 61} 62 63//----------------------------------------------------------------------------- 64 65ConsoleSetType(TypeShapeAnimationAssetPtr) 66{ 67 // Was a single argument specified? 68 if (argc == 1) 69 { 70 // Yes, so fetch field value. 71 const char* pFieldValue = argv[0]; 72 73 // Fetch asset pointer. 74 AssetPtr<ShapeAnimationAsset>* pAssetPtr = dynamic_cast<AssetPtr<ShapeAnimationAsset>*>((AssetPtrBase*)(dptr)); 75 76 // Is the asset pointer the correct type? 77 if (pAssetPtr == NULL) 78 { 79 // No, so fail. 80 //Con::warnf("(TypeShapeAnimationAssetPtr) - Failed to set asset Id '%d'.", pFieldValue); 81 return; 82 } 83 84 // Set asset. 85 pAssetPtr->setAssetId(pFieldValue); 86 87 return; 88 } 89 90 // Warn. 91 Con::warnf("(TypeShapeAnimationAssetPtr) - Cannot set multiple args to a single asset."); 92} 93 94//----------------------------------------------------------------------------- 95 96ShapeAnimationAsset::ShapeAnimationAsset() : 97 mIsEmbedded(false), mIsCyclical(true), mIsBlend(false), mBlendFrame(0), mStartFrame(0), mEndFrame(-1), mPadRotation(true), mPadTransforms(false) 98{ 99 mFileName = StringTable->EmptyString(); 100 mFilePath = StringTable->EmptyString(); 101 mAnimationName = StringTable->EmptyString(); 102 103 mBlendAnimAssetName = StringTable->EmptyString(); 104} 105 106//----------------------------------------------------------------------------- 107 108ShapeAnimationAsset::~ShapeAnimationAsset() 109{ 110} 111 112//----------------------------------------------------------------------------- 113 114void ShapeAnimationAsset::initPersistFields() 115{ 116 // Call parent. 117 Parent::initPersistFields(); 118 119 addProtectedField("animationFile", TypeAssetLooseFilePath, Offset(mFileName, ShapeAnimationAsset), 120 &setAnimationFile, &getAnimationFile, "Path to the file name containing the animation"); 121 122 addField("animationName", TypeString, Offset(mAnimationName, ShapeAnimationAsset), "Name of the animation"); 123 124 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"); 125 126 addField("isCyclic", TypeBool, Offset(mIsCyclical, ShapeAnimationAsset), "Is this animation looping?"); 127 128 addField("isBlend", TypeBool, Offset(mIsBlend, ShapeAnimationAsset), "Is this animation blended with another?"); 129 addField("blendRefAnimation", TypeString, Offset(mBlendAnimAssetName, ShapeAnimationAsset), "AssetID of the animation to reference for our blending"); 130 addField("blendFrame", TypeS32, Offset(mBlendFrame, ShapeAnimationAsset), "Which frame of the reference animation do we use for our blending"); 131 132 addField("startFrame", TypeS32, Offset(mStartFrame, ShapeAnimationAsset), "What frame does this animation clip start on"); 133 addField("endFrame", TypeS32, Offset(mEndFrame, ShapeAnimationAsset), "What fram does this animation clip end on"); 134 addField("padRotation", TypeBool, Offset(mPadRotation, ShapeAnimationAsset), "Are the rotation values padded"); 135 addField("padTransforms", TypeBool, Offset(mPadTransforms, ShapeAnimationAsset), "Are the transform values padded"); 136} 137 138//------------------------------------------------------------------------------ 139 140void ShapeAnimationAsset::copyTo(SimObject* object) 141{ 142 // Call to parent. 143 Parent::copyTo(object); 144} 145 146void ShapeAnimationAsset::initializeAsset(void) 147{ 148 if (!mIsEmbedded) 149 { 150 //If we're not embedded, we need to load in our initial shape and do some prepwork 151 mFilePath = expandAssetFilePath(mFileName); 152 153 mSourceShape = ResourceManager::get().load(mFilePath); 154 155 if (!mSourceShape->addSequence("ambient", "", mAnimationName, mStartFrame, mEndFrame, mPadRotation, mPadTransforms)) 156 { 157 Con::errorf("ShapeAnimationAsset::initializeAsset - Unable to do initial setup of the animation clip named %s for asset %s", mAnimationName, getAssetName()); 158 return; 159 } 160 161 S32 sequenceId = mSourceShape->findSequence(mAnimationName); 162 163 if(mIsCyclical) 164 mSourceShape->sequences[sequenceId].flags |= TSShape::Cyclic; 165 else 166 mSourceShape->sequences[sequenceId].flags &= (~(TSShape::Cyclic)); 167 } 168} 169 170void ShapeAnimationAsset::onAssetRefresh(void) 171{ 172 173} 174 175void ShapeAnimationAsset::setAnimationFile(const char* pAnimationFile) 176{ 177 // Sanity! 178 AssertFatal(pAnimationFile != NULL, "Cannot use a NULL animation file."); 179 180 // Fetch image file. 181 pAnimationFile = StringTable->insert(pAnimationFile); 182 183 // Ignore no change, 184 if (pAnimationFile == mFileName) 185 return; 186 187 // Update. 188 mFileName = StringTable->insert(pAnimationFile); 189 190 // Refresh the asset. 191 refreshAsset(); 192} 193 194S32 ShapeAnimationAsset::getAnimationCount() 195{ 196 if (mSourceShape == nullptr) 197 return 0; 198 199 return mSourceShape->sequences.size(); 200} 201 202DefineEngineMethod(ShapeAnimationAsset, getAnimationCount, S32, (), , 203 "Gets the number of animations for this shape asset.\n" 204 "@return Animation count.\n") 205{ 206 return object->getAnimationCount(); 207} 208