00001
00002
00003
00004
00005
00006 #include "SCA_IActuator.h"
00007 #include "SCA_ReplaceMeshActuator.h"
00008 #include "SCA_IScene.h"
00009 #include <iostream>
00010
00011
00012
00013
00014
00015
00016
00017 PyTypeObject SCA_ReplaceMeshActuator::Type = {
00018 PyObject_HEAD_INIT(&PyType_Type)
00019 0,
00020 "SCA_ReplaceMeshActuator",
00021 sizeof(SCA_ReplaceMeshActuator),
00022 0,
00023 PyDestructor,
00024 0,
00025 __getattr,
00026 __setattr,
00027 0,
00028 __repr,
00029 0,
00030 0,
00031 0,
00032 0,
00033 0
00034 };
00035
00036 PyParentObject SCA_ReplaceMeshActuator::Parents[] = {
00037 &SCA_IActuator::Type,
00038 &SCA_ILogicBrick::Type,
00039 &CValue::Type,
00040 NULL
00041 };
00042 PyMethodDef SCA_ReplaceMeshActuator::Methods[] = {
00043 {"setMesh", (PyCFunction) SCA_ReplaceMeshActuator::sPySetMesh, METH_VARARGS, SetMesh_doc},
00044
00045 {NULL,NULL}
00046 };
00047
00048
00049 PyObject* SCA_ReplaceMeshActuator::_getattr(char* attr)
00050 {
00051 _getattr_up(SCA_IActuator);
00052 }
00053
00054
00055 char SCA_ReplaceMeshActuator::SetMesh_doc[] =
00056 "setMesh(name)\n"
00057 "\t- name: string\n"
00058 "\tSet the mesh that will be substituted for the current one.\n";
00059 PyObject* SCA_ReplaceMeshActuator::PySetMesh(PyObject* self,
00060 PyObject* args,
00061 PyObject* kwds) {
00062 char* meshname;
00063
00064 if (!PyArg_ParseTuple(args, "s", &meshname)) {
00065 return NULL;
00066 }
00067 void* mesh = SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(CCString(meshname));
00068
00069 if (m_mesh) {
00070 m_mesh= (class RAS_MeshObject*)mesh;
00071 Py_Return;
00072 }
00073
00074 return NULL;
00075 }
00076
00077
00078
00079
00080
00081 SCA_ReplaceMeshActuator::SCA_ReplaceMeshActuator(SCA_IObject *gameobj,
00082 class RAS_MeshObject *mesh,
00083 SCA_IScene* scene,
00084 PyTypeObject* T)
00085 : SCA_IActuator(gameobj, T),
00086 m_scene(scene),
00087 m_mesh(mesh)
00088 {
00089
00090 }
00091
00092 SCA_ReplaceMeshActuator::~SCA_ReplaceMeshActuator()
00093 {
00094
00095 }
00096
00097 bool SCA_ReplaceMeshActuator::Update(double curtime,double deltatime)
00098 {
00099 bool result = false;
00100 bool bNegativeEvent = IsNegativeEvent();
00101
00102 if (bNegativeEvent)
00103 return false;
00104
00105 if (m_mesh)
00106 m_scene->ReplaceMesh(GetParent(),m_mesh);
00107 else
00108 {
00109 cout << "\nSCA_ReplaceMeshActuator error: invalid mesh!";
00110 }
00111
00112
00113 return false;
00114 }
00115
00116