void Entity::setMaterial(const std::string &name) { //setMaterial(name, 0); IMaterialMgr *pMatMgr = gEngModule->pMaterialMgr; MaterialHandle handle = pMatMgr->getHandle(name); IMaterial *pMat = 0; if (handle.isNull() == true) { IMaterial *pCreateMat = pMatMgr->create(name); if (pCreateMat != 0) { mMaterialHandle = pMatMgr->getHandle(name); pMat = pCreateMat; } } for (int i = 0; i < mSubRenderableVec.size(); ++i) { if (i == 0) { mSubRenderableVec[i]->setMaterial(mMaterialHandle); } else { SubMaterialVec subMaterialVec = pMat->getSubMaterialVec(); IMaterial *pSubMat = subMaterialVec[i - 1]; mSubRenderableVec[i]->setMaterial(pSubMat->getName()); } } }
void Entity::setMaterial(const std::string &name, const int index) { if (index >= mSubRenderableVec.size()) { Log::getInstance().logMsg("Material index error !"); return; } IMaterialMgr *pMatMgr = gEngModule->pMaterialMgr; MaterialHandle handle = pMatMgr->getHandle(name); if (handle.isNull() == true) { IMaterial *pCreateMat = pMatMgr->create(name); if (pCreateMat != 0) { mMaterialHandle = pMatMgr->getHandle(name); } } mSubRenderableVec[index]->setMaterial(name); }