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