forked from bartvdbraak/blender
BGE API cleanup: ReplaceMeshActuator mesh attributes now returns a KX_MeshProxy. Fix a bug in KX_MeshProxy where the Python type was not set right.
This commit is contained in:
parent
1e2f736d3a
commit
48e4a48340
@ -124,7 +124,7 @@ KX_MeshProxy::_getattr(const char *attr)
|
||||
|
||||
|
||||
KX_MeshProxy::KX_MeshProxy(RAS_MeshObject* mesh)
|
||||
: m_meshobj(mesh)
|
||||
: SCA_IObject(&Type), m_meshobj(mesh)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,7 @@ public:
|
||||
virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
|
||||
virtual const STR_String & GetText();
|
||||
virtual float GetNumber();
|
||||
virtual RAS_MeshObject* GetMesh() { return m_meshobj; }
|
||||
virtual STR_String GetName();
|
||||
virtual void SetName(STR_String name); // Set the name of the value
|
||||
virtual void ReplicaSetName(STR_String name);
|
||||
|
@ -36,6 +36,7 @@
|
||||
// Please look here for revision history.
|
||||
|
||||
#include "KX_SCA_ReplaceMeshActuator.h"
|
||||
#include "KX_MeshProxy.h"
|
||||
|
||||
#include "PyObjectPlus.h"
|
||||
|
||||
@ -115,7 +116,8 @@ PyObject* KX_SCA_ReplaceMeshActuator::pyattr_get_mesh(void *self, const struct K
|
||||
KX_SCA_ReplaceMeshActuator* actuator = static_cast<KX_SCA_ReplaceMeshActuator*>(self);
|
||||
if (!actuator->m_mesh)
|
||||
Py_RETURN_NONE;
|
||||
return PyString_FromString(const_cast<char *>(actuator->m_mesh->GetName().ReadPtr()));
|
||||
KX_MeshProxy* meshproxy = new KX_MeshProxy(actuator->m_mesh);
|
||||
return meshproxy;
|
||||
}
|
||||
|
||||
int KX_SCA_ReplaceMeshActuator::pyattr_set_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
||||
@ -123,18 +125,19 @@ int KX_SCA_ReplaceMeshActuator::pyattr_set_mesh(void *self, const struct KX_PYAT
|
||||
KX_SCA_ReplaceMeshActuator* actuator = static_cast<KX_SCA_ReplaceMeshActuator*>(self);
|
||||
if (value == Py_None) {
|
||||
actuator->m_mesh = NULL;
|
||||
} else {
|
||||
char* meshname = PyString_AsString(value);
|
||||
if (!meshname) {
|
||||
PyErr_SetString(PyExc_ValueError, "Expected the name of a mesh or None");
|
||||
return 1;
|
||||
}
|
||||
void* mesh = SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String(meshname));
|
||||
} else if (PyString_Check(value)) {
|
||||
void* mesh = SCA_ILogicBrick::m_sCurrentLogicManager->GetMeshByName(STR_String(PyString_AsString(value)));
|
||||
if (mesh==NULL) {
|
||||
PyErr_SetString(PyExc_ValueError, "The mesh name given does not exist");
|
||||
return 1;
|
||||
}
|
||||
actuator->m_mesh= (class RAS_MeshObject*)mesh;
|
||||
} else if PyObject_TypeCheck(value, &KX_MeshProxy::Type) {
|
||||
KX_MeshProxy* proxy = (KX_MeshProxy*)value;
|
||||
actuator->m_mesh= proxy->GetMesh();
|
||||
} else {
|
||||
PyErr_SetString(PyExc_ValueError, "Expected the name of a mesh, a mesh proxy or None");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -57,9 +57,9 @@ class KX_SCA_ReplaceMeshActuator(SCA_IActuator):
|
||||
C{ERROR: GameObject I{OBName} ReplaceMeshActuator I{ActuatorName} without object}
|
||||
|
||||
Properties:
|
||||
@ivar mesh: the name of the mesh that will replace the current one
|
||||
@ivar mesh: L{KX_MeshProxy} or the name of the mesh that will replace the current one
|
||||
Set to None to disable actuator
|
||||
@type mesh: string or None if no mesh is set
|
||||
@type mesh: L{KX_MeshProxy} or None if no mesh is set
|
||||
"""
|
||||
def setMesh(name):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user