Blender V2.61 - r43446
|
00001 00004 // 00005 // Replace the mesh for this actuator's parent 00006 // 00007 // 00008 // ***** BEGIN GPL LICENSE BLOCK ***** 00009 // 00010 // This program is free software; you can redistribute it and/or 00011 // modify it under the terms of the GNU General Public License 00012 // as published by the Free Software Foundation; either version 2 00013 // of the License, or (at your option) any later version. 00014 // 00015 // This program is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU General Public License 00021 // along with this program; if not, write to the Free Software Foundation, 00022 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00023 // 00024 // The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00025 // All rights reserved. 00026 // 00027 // The Original Code is: all of this file. 00028 // 00029 // Contributor(s): none yet. 00030 // 00031 // ***** END GPL LICENSE BLOCK ***** 00032 00033 // 00034 // Previously existed as: 00035 00036 // \source\gameengine\GameLogic\SCA_ReplaceMeshActuator.cpp 00037 00038 // Please look here for revision history. 00039 00040 #include <stddef.h> 00041 00042 #include "KX_SCA_ReplaceMeshActuator.h" 00043 #include "KX_MeshProxy.h" 00044 00045 #include "PyObjectPlus.h" 00046 00047 #ifdef WITH_PYTHON 00048 00049 /* ------------------------------------------------------------------------- */ 00050 /* Python functions */ 00051 /* ------------------------------------------------------------------------- */ 00052 00053 /* Integration hooks ------------------------------------------------------- */ 00054 00055 PyTypeObject KX_SCA_ReplaceMeshActuator::Type = { 00056 PyVarObject_HEAD_INIT(NULL, 0) 00057 "KX_SCA_ReplaceMeshActuator", 00058 sizeof(PyObjectPlus_Proxy), 00059 0, 00060 py_base_dealloc, 00061 0, 00062 0, 00063 0, 00064 0, 00065 py_base_repr, 00066 0,0,0,0,0,0,0,0,0, 00067 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, 00068 0,0,0,0,0,0,0, 00069 Methods, 00070 0, 00071 0, 00072 &SCA_IActuator::Type, 00073 0,0,0,0,0,0, 00074 py_base_new 00075 }; 00076 00077 PyMethodDef KX_SCA_ReplaceMeshActuator::Methods[] = { 00078 KX_PYMETHODTABLE(KX_SCA_ReplaceMeshActuator, instantReplaceMesh), 00079 {NULL,NULL} //Sentinel 00080 }; 00081 00082 PyAttributeDef KX_SCA_ReplaceMeshActuator::Attributes[] = { 00083 KX_PYATTRIBUTE_RW_FUNCTION("mesh", KX_SCA_ReplaceMeshActuator, pyattr_get_mesh, pyattr_set_mesh), 00084 KX_PYATTRIBUTE_BOOL_RW ("useDisplayMesh", KX_SCA_ReplaceMeshActuator, m_use_gfx), 00085 KX_PYATTRIBUTE_BOOL_RW ("usePhysicsMesh", KX_SCA_ReplaceMeshActuator, m_use_phys), 00086 { NULL } //Sentinel 00087 }; 00088 00089 PyObject* KX_SCA_ReplaceMeshActuator::pyattr_get_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) 00090 { 00091 KX_SCA_ReplaceMeshActuator* actuator = static_cast<KX_SCA_ReplaceMeshActuator*>(self); 00092 if (!actuator->m_mesh) 00093 Py_RETURN_NONE; 00094 KX_MeshProxy* meshproxy = new KX_MeshProxy(actuator->m_mesh); 00095 return meshproxy->NewProxy(true); 00096 } 00097 00098 int KX_SCA_ReplaceMeshActuator::pyattr_set_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) 00099 { 00100 KX_SCA_ReplaceMeshActuator* actuator = static_cast<KX_SCA_ReplaceMeshActuator*>(self); 00101 RAS_MeshObject* new_mesh; 00102 00103 if (!ConvertPythonToMesh(value, &new_mesh, true, "actuator.mesh = value: KX_SCA_ReplaceMeshActuator")) 00104 return PY_SET_ATTR_FAIL; 00105 00106 actuator->m_mesh = new_mesh; 00107 return PY_SET_ATTR_SUCCESS; 00108 } 00109 00110 KX_PYMETHODDEF_DOC(KX_SCA_ReplaceMeshActuator, instantReplaceMesh, 00111 "instantReplaceMesh() : immediately replace mesh without delay\n") 00112 { 00113 InstantReplaceMesh(); 00114 Py_RETURN_NONE; 00115 } 00116 00117 #endif // WITH_PYTHON 00118 00119 /* ------------------------------------------------------------------------- */ 00120 /* Native functions */ 00121 /* ------------------------------------------------------------------------- */ 00122 00123 KX_SCA_ReplaceMeshActuator::KX_SCA_ReplaceMeshActuator(SCA_IObject *gameobj, 00124 class RAS_MeshObject *mesh, 00125 SCA_IScene* scene, 00126 bool use_gfx, 00127 bool use_phys) : 00128 00129 SCA_IActuator(gameobj, KX_ACT_REPLACE_MESH), 00130 m_mesh(mesh), 00131 m_scene(scene), 00132 m_use_gfx(use_gfx), 00133 m_use_phys(use_phys) 00134 { 00135 } /* End of constructor */ 00136 00137 00138 00139 KX_SCA_ReplaceMeshActuator::~KX_SCA_ReplaceMeshActuator() 00140 { 00141 // there's nothing to be done here, really.... 00142 } /* end of destructor */ 00143 00144 00145 00146 bool KX_SCA_ReplaceMeshActuator::Update() 00147 { 00148 // bool result = false; /*unused*/ 00149 bool bNegativeEvent = IsNegativeEvent(); 00150 RemoveAllEvents(); 00151 00152 if (bNegativeEvent) 00153 return false; // do nothing on negative events 00154 00155 if (m_mesh || m_use_phys) /* NULL mesh is ok if were updating physics */ 00156 m_scene->ReplaceMesh(GetParent(),m_mesh, m_use_gfx, m_use_phys); 00157 00158 return false; 00159 } 00160 00161 00162 00163 CValue* KX_SCA_ReplaceMeshActuator::GetReplica() 00164 { 00165 KX_SCA_ReplaceMeshActuator* replica = 00166 new KX_SCA_ReplaceMeshActuator(*this); 00167 00168 if (replica == NULL) 00169 return NULL; 00170 00171 replica->ProcessReplica(); 00172 00173 return replica; 00174 }; 00175 00176 void KX_SCA_ReplaceMeshActuator::InstantReplaceMesh() 00177 { 00178 if (m_mesh) m_scene->ReplaceMesh(GetParent(),m_mesh, m_use_gfx, m_use_phys); 00179 } 00180 00181 /* eof */