00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "AnimatedMeshComponent.h"
00018 #include "../../core/GameManager.h"
00019
00020
00021
00022
00023 AnimatedMeshComponent::AnimatedMeshComponent(Entity *parent)
00024 : SceneComponent(parent, true)
00025 {
00026
00027 ISceneManager *pSceneMgr = GameManager::Instance()->getSceneManager();
00028
00029
00030 mAnimatedMeshSN = pSceneMgr->addAnimatedMeshSceneNode(0, 0, parent->getID(),
00031 parent->getPosition(), vector3df(0, 0, 0),
00032 vector3df(1.0f, 1.0f, 1.0f), true);
00033 mSceneNode = mAnimatedMeshSN;
00034 mShadowVolumeSN = NULL;
00035
00036
00037 mTriSelector = pSceneMgr->createTriangleSelectorFromBoundingBox(mAnimatedMeshSN);
00038 mMetaSelector = pSceneMgr->createMetaTriangleSelector();
00039 }
00040
00041
00042 AnimatedMeshComponent::AnimatedMeshComponent(Entity *parent, const std::string &fileName,
00043 const vector3df &rotation, const vector3df &scale)
00044 : SceneComponent(parent, true)
00045 {
00046
00047 ISceneManager *pSceneMgr = GameManager::Instance()->getSceneManager();
00048
00049
00050 mAnimatedMeshSN = pSceneMgr->addAnimatedMeshSceneNode(pSceneMgr->getMesh(fileName.c_str()), 0,
00051 parent->getID(), parent->getPosition(),
00052 rotation, scale, true);
00053 mSceneNode = mAnimatedMeshSN;
00054 mShadowVolumeSN = NULL;
00055
00056
00057 mTriSelector = pSceneMgr->createTriangleSelectorFromBoundingBox(mAnimatedMeshSN);
00058 mMetaSelector = pSceneMgr->createMetaTriangleSelector();
00059 }
00060
00061
00062 AnimatedMeshComponent::AnimatedMeshComponent(Entity *parent, IAnimatedMesh *mesh,
00063 const vector3df &rotation, const vector3df &scale)
00064 : SceneComponent(parent, true)
00065 {
00066 ISceneManager *pSceneMgr = GameManager::Instance()->getSceneManager();
00067
00068 mAnimatedMeshSN = pSceneMgr->addAnimatedMeshSceneNode(mesh, 0, parent->getID(),
00069 parent->getPosition(), rotation, scale,
00070 true);
00071 mSceneNode = mAnimatedMeshSN;
00072
00073
00074 mTriSelector = pSceneMgr->createTriangleSelectorFromBoundingBox(mAnimatedMeshSN);
00075 mMetaSelector = pSceneMgr->createMetaTriangleSelector();
00076 }
00077
00078
00079 AnimatedMeshComponent::~AnimatedMeshComponent()
00080 {
00081 mAnimatedMeshSN->remove();
00082 mSceneNode = NULL;
00083 }
00084
00085
00086 AnimatedMeshComponent* AnimatedMeshComponent::refFactory(Entity *parent)
00087 {
00088 return new AnimatedMeshComponent(parent);
00089 }
00090
00091
00092 AnimatedMeshComponent* AnimatedMeshComponent::refFactory(Entity *parent, const std::string &fileName,
00093 const vector3df &rotation,
00094 const vector3df &scale)
00095 {
00096 return new AnimatedMeshComponent(parent, fileName, rotation, scale);
00097 }
00098
00099
00100 IAnimatedMeshSceneNode* AnimatedMeshComponent::getAnimatedMeshSceneNode()
00101 {
00102 return mAnimatedMeshSN;
00103 }
00104
00105
00106 void AnimatedMeshComponent::animate()
00107 {
00108 mAnimatedMeshSN->animateJoints();
00109 }
00110
00111
00112 s32 AnimatedMeshComponent::getEndFrame() const
00113 {
00114 return mAnimatedMeshSN->getEndFrame();
00115 }
00116
00117
00118 f32 AnimatedMeshComponent::getFrame() const
00119 {
00120 return mAnimatedMeshSN->getFrameNr();
00121 }
00122
00123
00124 IMesh* AnimatedMeshComponent::getMesh()
00125 {
00126 return mAnimatedMeshSN->getMesh();
00127 }
00128
00129
00130 IShadowVolumeSceneNode* AnimatedMeshComponent::getShadowVolumeSceneNode()
00131 {
00132 return mShadowVolumeSN;
00133 }
00134
00135
00136 s32 AnimatedMeshComponent::getStartFrame() const
00137 {
00138 return mAnimatedMeshSN->getStartFrame();
00139 }
00140
00141
00142 void AnimatedMeshComponent::setAnimationSpeed(f32 speed)
00143 {
00144 mAnimatedMeshSN->setAnimationSpeed(speed);
00145 }
00146
00147
00148 void AnimatedMeshComponent::setCurrentFrame(f32 frame)
00149 {
00150 mAnimatedMeshSN->setCurrentFrame(frame);
00151 }
00152
00153
00154 void AnimatedMeshComponent::setFrameLoop(s32 start, s32 end)
00155 {
00156 mAnimatedMeshSN->setFrameLoop(start, end);
00157 }
00158
00159
00160 void AnimatedMeshComponent::setLoopMode(bool value)
00161 {
00162 mAnimatedMeshSN->setLoopMode(value);
00163 }
00164
00165
00166 void AnimatedMeshComponent::setMD2Animation(const std::string &animationName)
00167 {
00168 mAnimatedMeshSN->setMD2Animation(animationName.c_str());
00169 }
00170
00171
00172 void AnimatedMeshComponent::setMD2Animation(EMD2_ANIMATION_TYPE anim)
00173 {
00174 mAnimatedMeshSN->setMD2Animation(anim);
00175 }
00176
00177
00178 void AnimatedMeshComponent::setMesh(const std::string &fileName)
00179 {
00180 IAnimatedMesh *mesh = GameManager::Instance()->getSceneManager()->getMesh(fileName.c_str());
00181 if(mesh)
00182 mAnimatedMeshSN->setMesh(mesh);
00183 }
00184
00185
00186 void AnimatedMeshComponent::setMesh(IAnimatedMesh *mesh)
00187 {
00188 mAnimatedMeshSN->setMesh(mesh);
00189 }
00190
00191
00192 void AnimatedMeshComponent::setShadowVolumeSceneNode(const std::string &fileName, bool zfailmethod,
00193 f32 infinity)
00194 {
00195 if(!mShadowVolumeSN)
00196 {
00197 IMesh *mesh = GameManager::Instance()->getSceneManager()->getMesh(fileName.c_str());
00198 if(mesh)
00199 mShadowVolumeSN = mAnimatedMeshSN->addShadowVolumeSceneNode(mesh, pParent->getID(),
00200 zfailmethod, infinity);
00201 }
00202 }
00203
00204
00205 void AnimatedMeshComponent::setShadowVolumeSceneNode(IMesh *mesh, bool zfailmethod, f32 infinity)
00206 {
00207 if(!mShadowVolumeSN)
00208 {
00209 mShadowVolumeSN = mAnimatedMeshSN->addShadowVolumeSceneNode(mesh, pParent->getID(),
00210 zfailmethod, infinity);
00211 }
00212 }
00213
00214
00215 void AnimatedMeshComponent::setTransitionTime(f32 time)
00216 {
00217 mAnimatedMeshSN->setTransitionTime(time);
00218 }
00219
00220
00221
00222 void bindAnimatedMeshComponent(asIScriptEngine *engine)
00223 {
00224
00225 int r;
00226
00227
00228 r = engine->RegisterObjectType("AnimatedMeshComponent", sizeof(AnimatedMeshComponent), asOBJ_REF); assert(r >= 0);
00229
00230
00231 bindSceneComponentBase<AnimatedMeshComponent>(engine, "AnimatedMeshComponent");
00232
00233
00234 r = engine->RegisterObjectBehaviour("AnimatedMeshComponent", asBEHAVE_FACTORY, "AnimatedMeshComponent@ f(Entity @)",
00235 asFUNCTIONPR(AnimatedMeshComponent::refFactory, (Entity*), AnimatedMeshComponent*),
00236 asCALL_CDECL); assert(r >= 0);
00237 r = engine->RegisterObjectBehaviour("AnimatedMeshComponent", asBEHAVE_FACTORY, "AnimatedMeshComponent@ f(Entity @, " \
00238 "const string &, const vector3df &in, const vector3df &in)",
00239 asFUNCTIONPR(AnimatedMeshComponent::refFactory, (Entity*, const std::string&,
00240 const vector3df&, const vector3df&), AnimatedMeshComponent*), asCALL_CDECL);
00241 assert(r >= 0);
00242
00243
00244 r = engine->RegisterObjectMethod("AnimatedMeshComponent", "void animate()",
00245 asMETHOD(AnimatedMeshComponent, animate), asCALL_THISCALL); assert(r >= 0);
00246
00247 r = engine->RegisterObjectMethod("AnimatedMeshComponent", "s32 getEndFrame()",
00248 asMETHOD(AnimatedMeshComponent, getEndFrame), asCALL_THISCALL); assert(r >= 0);
00249 r = engine->RegisterObjectMethod("AnimatedMeshComponent", "f32 getFrame()",
00250 asMETHOD(AnimatedMeshComponent, getFrame), asCALL_THISCALL); assert(r >= 0);
00251 r = engine->RegisterObjectMethod("AnimatedMeshComponent", "s32 getStartFrame()",
00252 asMETHOD(AnimatedMeshComponent, getStartFrame), asCALL_THISCALL); assert(r >= 0);
00253
00254 r = engine->RegisterObjectMethod("AnimatedMeshComponent", "void setAnimationSpeed(f32)",
00255 asMETHOD(AnimatedMeshComponent, setAnimationSpeed), asCALL_THISCALL); assert(r >= 0);
00256 r = engine->RegisterObjectMethod("AnimatedMeshComponent", "void setCurrentFrame(f32)",
00257 asMETHOD(AnimatedMeshComponent, setCurrentFrame), asCALL_THISCALL); assert(r >= 0);
00258 r = engine->RegisterObjectMethod("AnimatedMeshComponent", "void setFrameLoop(s32, s32)",
00259 asMETHOD(AnimatedMeshComponent, setFrameLoop), asCALL_THISCALL); assert(r >= 0);
00260 r = engine->RegisterObjectMethod("AnimatedMeshComponent", "void setLoopMode(bool)",
00261 asMETHOD(AnimatedMeshComponent, setLoopMode), asCALL_THISCALL); assert(r >= 0);
00262 r = engine->RegisterObjectMethod("AnimatedMeshComponent", "void setMD2Animation(const string &)",
00263 asMETHODPR(AnimatedMeshComponent, setMD2Animation, (const std::string&), void),
00264 asCALL_THISCALL); assert(r >= 0);
00265 r = engine->RegisterObjectMethod("AnimatedMeshComponent", "void setMesh(const string &)",
00266 asMETHODPR(AnimatedMeshComponent, setMesh, (const std::string&), void),
00267 asCALL_THISCALL); assert(r >= 0);
00268 r = engine->RegisterObjectMethod("AnimatedMeshComponent", "void setShadowVolumeSceneNode(const string &fileName, " \
00269 "bool, f32)", asMETHODPR(AnimatedMeshComponent, setShadowVolumeSceneNode,
00270 (const std::string&, bool, f32), void), asCALL_THISCALL); assert(r >= 0);
00271 r = engine->RegisterObjectMethod("AnimatedMeshComponent", "void setTransitionTime(f32)",
00272 asMETHOD(AnimatedMeshComponent, setTransitionTime), asCALL_THISCALL); assert(r >= 0);
00273 }
00274
00275