PyObject* KX_VertexProxy::PySetUV(PyObject* value) { MT_Point2 vec; if (!PyVecTo(value, vec)) return NULL; m_vertex->SetUV(vec); m_mesh->SetMeshModified(true); Py_RETURN_NONE; }
int KX_CharacterWrapper::pyattr_set_walk_dir(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { KX_CharacterWrapper* self = static_cast<KX_CharacterWrapper*>(self_v); MT_Vector3 dir; if (!PyVecTo(value, dir)) { PyErr_SetString(PyExc_TypeError, "KX_CharacterWrapper.walkDirection: expected a vector"); return PY_SET_ATTR_FAIL; } self->m_character->SetWalkDirection(dir); return PY_SET_ATTR_SUCCESS; }
PyObject *KX_VehicleWrapper::PyAddWheel(PyObject *args) { PyObject *pylistPos,*pylistDir,*pylistAxleDir; PyObject *wheelGameObject; float suspensionRestLength,wheelRadius; int hasSteering; if (PyArg_ParseTuple(args,"OOOOffi:addWheel",&wheelGameObject,&pylistPos,&pylistDir,&pylistAxleDir,&suspensionRestLength,&wheelRadius,&hasSteering)) { KX_GameObject *gameOb; if (!ConvertPythonToGameObject(wheelGameObject, &gameOb, false, "vehicle.addWheel(...): KX_VehicleWrapper (first argument)")) return NULL; if (gameOb->GetSGNode()) { PHY_IMotionState* motionState = new KX_MotionState(gameOb->GetSGNode()); /* TODO - no error checking here! - bad juju */ MT_Vector3 attachPos,attachDir,attachAxle; PyVecTo(pylistPos,attachPos); PyVecTo(pylistDir,attachDir); PyVecTo(pylistAxleDir,attachAxle); //someone reverse some conventions inside Bullet (axle winding) attachAxle = -attachAxle; printf("attempt for addWheel: suspensionRestLength%f wheelRadius %f, hasSteering:%d\n",suspensionRestLength,wheelRadius,hasSteering); m_vehicle->AddWheel(motionState,attachPos,attachDir,attachAxle,suspensionRestLength,wheelRadius,hasSteering); } } else { return NULL; } Py_RETURN_NONE; }
bool PyQuatTo(PyObject *pyval, MT_Quaternion &qrot) { if (!PyVecTo(pyval, qrot)) return false; /* annoying!, Blender/Mathutils have the W axis first! */ MT_Scalar w = qrot[0]; /* from python, this is actually the W */ qrot[0] = qrot[1]; qrot[1] = qrot[2]; qrot[2] = qrot[3]; qrot[3] = w; return true; }
int KX_LightObject::pyattr_set_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { KX_LightObject* self = static_cast<KX_LightObject*>(self_v); MT_Vector3 color; if (PyVecTo(value, color)) { self->m_lightobj->m_color[0] = color[0]; self->m_lightobj->m_color[1] = color[1]; self->m_lightobj->m_color[2] = color[2]; return PY_SET_ATTR_SUCCESS; } return PY_SET_ATTR_FAIL; }
int KX_VertexProxy::pyattr_set_UV(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v); if (PySequence_Check(value)) { MT_Point2 vec; if (PyVecTo(value, vec)) { self->m_vertex->SetUV(0, vec); self->m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } } return PY_SET_ATTR_FAIL; }
PyObject* KX_VertexProxy::PySetUV2(PyObject* args) { MT_Point2 vec; unsigned int unit= RAS_TexVert::SECOND_UV; PyObject* list= NULL; if (!PyArg_ParseTuple(args, "O|i:setUV2", &list, &unit)) return NULL; if (!PyVecTo(list, vec)) return NULL; m_vertex->SetFlag((m_vertex->getFlag()|RAS_TexVert::SECOND_UV)); m_vertex->SetUnit(unit); m_vertex->SetUV2(vec); m_mesh->SetMeshModified(true); Py_RETURN_NONE; }
PyObject *KX_VertexProxy::PySetRGBA(PyObject *value) { if (PyLong_Check(value)) { int rgba = PyLong_AsLong(value); m_vertex->SetRGBA(rgba); m_mesh->SetMeshModified(true); Py_RETURN_NONE; } else { MT_Vector4 vec; if (PyVecTo(value, vec)) { m_vertex->SetRGBA(vec); m_mesh->SetMeshModified(true); Py_RETURN_NONE; } } PyErr_SetString(PyExc_TypeError, "vert.setRGBA(value): KX_VertexProxy, expected a 4D vector or an int"); return NULL; }
int KX_VertexProxy::py_setattro(PyObject *attr, PyObject *pyvalue) { char *attr_str= _PyUnicode_AsString(attr); if (PySequence_Check(pyvalue)) { if (!strcmp(attr_str, "XYZ")) { MT_Point3 vec; if (PyVecTo(pyvalue, vec)) { m_vertex->SetXYZ(vec); m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } return PY_SET_ATTR_FAIL; } if (!strcmp(attr_str, "UV")) { MT_Point2 vec; if (PyVecTo(pyvalue, vec)) { m_vertex->SetUV(vec); m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } return PY_SET_ATTR_FAIL; } if (!strcmp(attr_str, "color") || !strcmp(attr_str, "colour")) { MT_Vector4 vec; if (PyVecTo(pyvalue, vec)) { m_vertex->SetRGBA(vec); m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } return PY_SET_ATTR_FAIL; } if (!strcmp(attr_str, "normal")) { MT_Vector3 vec; if (PyVecTo(pyvalue, vec)) { m_vertex->SetNormal(vec); m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } return PY_SET_ATTR_FAIL; } } if (PyFloat_Check(pyvalue)) { float val = PyFloat_AsDouble(pyvalue); // pos MT_Point3 pos(m_vertex->getXYZ()); if (!strcmp(attr_str, "x")) { pos.x() = val; m_vertex->SetXYZ(pos); m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } if (!strcmp(attr_str, "y")) { pos.y() = val; m_vertex->SetXYZ(pos); m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } if (!strcmp(attr_str, "z")) { pos.z() = val; m_vertex->SetXYZ(pos); m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } // uv MT_Point2 uv = m_vertex->getUV1(); if (!strcmp(attr_str, "u")) { uv[0] = val; m_vertex->SetUV(uv); m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } if (!strcmp(attr_str, "v")) { uv[1] = val; m_vertex->SetUV(uv); m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } // uv MT_Point2 uv2 = m_vertex->getUV2(); if (!strcmp(attr_str, "u2")) { uv[0] = val; m_vertex->SetUV2(uv); m_mesh->SetMeshModified(true); return 0; } if (!strcmp(attr_str, "v2")) { uv[1] = val; m_vertex->SetUV2(uv); m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } // col unsigned int icol = *((const unsigned int *)m_vertex->getRGBA()); unsigned char *cp = (unsigned char*) &icol; val *= 255.0; if (!strcmp(attr_str, "r")) { cp[0] = (unsigned char) val; m_vertex->SetRGBA(icol); m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } if (!strcmp(attr_str, "g")) { cp[1] = (unsigned char) val; m_vertex->SetRGBA(icol); m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } if (!strcmp(attr_str, "b")) { cp[2] = (unsigned char) val; m_vertex->SetRGBA(icol); m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } if (!strcmp(attr_str, "a")) { cp[3] = (unsigned char) val; m_vertex->SetRGBA(icol); m_mesh->SetMeshModified(true); return PY_SET_ATTR_SUCCESS; } } return CValue::py_setattro(attr, pyvalue); }