00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "MeshComponent.h"
00018 #include "../../core/GameManager.h"
00019
00020
00021
00022
00023 MeshComponent::MeshComponent(Entity *parent)
00024 : SceneComponent(parent, true)
00025 {
00026
00027 ISceneManager *pSceneMgr = GameManager::Instance()->getSceneManager();
00028
00029
00030 mMeshSN = pSceneMgr->addMeshSceneNode(0, 0, parent->getID(), parent->getPosition(),
00031 vector3df(0, 0, 0), vector3df(1.0f, 1.0f, 1.0f), true);
00032 mSceneNode = mMeshSN;
00033
00034
00035 mTriSelector = pSceneMgr->createTriangleSelectorFromBoundingBox(mMeshSN);
00036 mMetaSelector = pSceneMgr->createMetaTriangleSelector();
00037 }
00038
00039
00040 MeshComponent::MeshComponent(Entity *parent, const std::string &fileName,
00041 const vector3df &rotation, const vector3df &scale)
00042 : SceneComponent(parent, true)
00043 {
00044
00045 ISceneManager *pSceneMgr = GameManager::Instance()->getSceneManager();
00046
00047
00048 mMeshSN = pSceneMgr->addMeshSceneNode(pSceneMgr->getMesh(fileName.c_str()), 0,
00049 parent->getID(), parent->getPosition(), rotation, scale,
00050 true);
00051 mSceneNode = mMeshSN;
00052
00053
00054 mTriSelector = pSceneMgr->createTriangleSelectorFromBoundingBox(mMeshSN);
00055 mMetaSelector = pSceneMgr->createMetaTriangleSelector();
00056 }
00057
00058
00059 MeshComponent::MeshComponent(Entity *parent, IMesh *mesh, const vector3df &rotation,
00060 const vector3df &scale)
00061 : SceneComponent(parent, true)
00062 {
00063
00064 ISceneManager *pSceneMgr = GameManager::Instance()->getSceneManager();
00065
00066
00067 mMeshSN = pSceneMgr->addMeshSceneNode(mesh, 0, parent->getID(), parent->getPosition(), rotation,
00068 scale, true);
00069 mSceneNode = mMeshSN;
00070
00071
00072 mTriSelector = pSceneMgr->createTriangleSelectorFromBoundingBox(mMeshSN);
00073 mMetaSelector = pSceneMgr->createMetaTriangleSelector();
00074 }
00075
00076
00077 MeshComponent::~MeshComponent()
00078 {
00079 mMeshSN->remove();
00080 mSceneNode = NULL;
00081 }
00082
00083
00084 MeshComponent* MeshComponent::refFactory(Entity *parent)
00085 {
00086 return new MeshComponent(parent);
00087 }
00088
00089
00090 MeshComponent* MeshComponent::refFactory(Entity *parent, const std::string &fileName,
00091 const vector3df &rotation, const vector3df &scale)
00092 {
00093 return new MeshComponent(parent, fileName, rotation, scale);
00094 }
00095
00096
00097 IMeshSceneNode* MeshComponent::getMeshSceneNode()
00098 {
00099 return mMeshSN;
00100 }
00101
00102
00103 IMesh* MeshComponent::getMesh()
00104 {
00105 return mMeshSN->getMesh();
00106 }
00107
00108
00109 void MeshComponent::setMesh(const std::string &fileName)
00110 {
00111 IMesh *mesh = GameManager::Instance()->getSceneManager()->getMesh(fileName.c_str());
00112 if(mesh)
00113 mMeshSN->setMesh(mesh);
00114 }
00115
00116
00117 void MeshComponent::setMesh(IMesh *mesh)
00118 {
00119 mMeshSN->setMesh(mesh);
00120 }
00121
00122
00123
00124 void bindMeshComponent(asIScriptEngine *engine)
00125 {
00126
00127 int r;
00128
00129
00130 r = engine->RegisterObjectType("MeshComponent", sizeof(MeshComponent), asOBJ_REF); assert(r >= 0);
00131
00132
00133 bindSceneComponentBase<MeshComponent>(engine, "MeshComponent");
00134
00135
00136 r = engine->RegisterObjectBehaviour("MeshComponent", asBEHAVE_FACTORY, "MeshComponent@ f(Entity @)",
00137 asFUNCTIONPR(MeshComponent::refFactory, (Entity*), MeshComponent*), asCALL_CDECL); assert(r >= 0);
00138 r = engine->RegisterObjectBehaviour("MeshComponent", asBEHAVE_FACTORY, "MeshComponent@ f(Entity @, const string&, " \
00139 "const vector3df &in, const vector3df &in)",
00140 asFUNCTIONPR(MeshComponent::refFactory, (Entity*, const std::string&, const vector3df&,
00141 const vector3df&), MeshComponent*), asCALL_CDECL); assert(r >= 0);
00142
00143
00144 r = engine->RegisterObjectMethod("MeshComponent", "void setMesh(const string&)",
00145 asMETHODPR(MeshComponent, setMesh, (const std::string&), void), asCALL_THISCALL); assert(r >= 0);
00146 }
00147
00148