PyObject *KX_MeshProxy::pyattr_get_materials(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_MeshProxy* self = static_cast<KX_MeshProxy*>(self_v); int tot= self->m_meshobj->NumMaterials(); int i; PyObject *materials = PyList_New( tot ); list<RAS_MeshMaterial>::iterator mit= self->m_meshobj->GetFirstMaterial(); for (i=0; i<tot; mit++, i++) { RAS_IPolyMaterial *polymat = mit->m_bucket->GetPolyMaterial(); /* Why do we need to check for RAS_BLENDERMAT if both are cast to a (PyObject *)? - Campbell */ if (polymat->GetFlag() & RAS_BLENDERMAT) { KX_BlenderMaterial *mat = static_cast<KX_BlenderMaterial*>(polymat); PyList_SET_ITEM(materials, i, mat->GetProxy()); } else { KX_PolygonMaterial *mat = static_cast<KX_PolygonMaterial*>(polymat); PyList_SET_ITEM(materials, i, mat->GetProxy()); } } return materials; }
void RAS_MeshObject::AddMeshUser(void *clientobj, SG_QList *head, RAS_Deformer* deformer) { list<RAS_MeshMaterial>::iterator it; list<RAS_MeshMaterial>::iterator mit; for (it = m_materials.begin();it!=m_materials.end();++it) { /* always copy from the base slot, which is never removed * since new objects can be created with the same mesh data */ if (deformer && !deformer->UseVertexArray()) { // HACK! // this deformer doesn't use vertex array => derive mesh // we must keep only the mesh slots that have unique material id // this is to match the derived mesh drawing function // Need a better solution in the future: scan the derive mesh and create vertex array RAS_IPolyMaterial* curmat = it->m_bucket->GetPolyMaterial(); if (curmat->GetFlag() & RAS_BLENDERGLSL) { for (mit = m_materials.begin(); mit != it; ++mit) { RAS_IPolyMaterial* mat = mit->m_bucket->GetPolyMaterial(); if ((mat->GetFlag() & RAS_BLENDERGLSL) && mat->GetMaterialIndex() == curmat->GetMaterialIndex()) // no need to convert current mesh slot break; } if (mit != it) continue; } } RAS_MeshSlot *ms = it->m_bucket->CopyMesh(it->m_baseslot); ms->m_clientObj = clientobj; ms->SetDeformer(deformer); it->m_slots.insert(clientobj, ms); head->QAddBack(ms); } }
// Texture object initialization int Texture_init (Texture *self, PyObject *args, PyObject *kwds) { // parameters - game object with video texture PyObject * obj = NULL; // material ID short matID = 0; // texture ID short texID = 0; // texture object with shared texture ID Texture * texObj = NULL; static const char *kwlist[] = {"gameObj", "materialID", "textureID", "textureObj", NULL}; // get parameters if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|hhO!", const_cast<char**>(kwlist), &obj, &matID, &texID, &TextureType, &texObj)) return -1; // if parameters are available if (obj != NULL) { // process polygon material or blender material try { // get pointer to texture image RAS_IPolyMaterial * mat = getMaterial(obj, matID); if (mat != NULL) { // is it blender material or polygon material if (mat->GetFlag() & RAS_BLENDERGLSL) { self->m_imgTexture = static_cast<KX_BlenderMaterial*>(mat)->getImage(texID); self->m_useMatTexture = false; } else if (mat->GetFlag() & RAS_BLENDERMAT) { // get blender material texture self->m_matTexture = static_cast<KX_BlenderMaterial*>(mat)->getTex(texID); self->m_useMatTexture = true; } else { // get texture pointer from polygon material MTFace * tface = static_cast<KX_PolygonMaterial*>(mat)->GetMTFace(); self->m_imgTexture = (Image*)tface->tpage; self->m_useMatTexture = false; } } // check if texture is available, if not, initialization failed if (self->m_imgTexture == NULL && self->m_matTexture == NULL) // throw exception if initialization failed THRWEXCP(MaterialNotAvail, S_OK); // if texture object is provided if (texObj != NULL) { // copy texture code self->m_actTex = texObj->m_actTex; self->m_mipmap = texObj->m_mipmap; if (texObj->m_source != NULL) Texture_setSource(self, reinterpret_cast<PyObject*>(texObj->m_source), NULL); } else // otherwise generate texture code glGenTextures(1, (GLuint*)&self->m_actTex); } catch (Exception & exp) { exp.report(); return -1; } } // initialization succeded return 0; }