void CRenderList::refresh() { m_draw.clear(); m_drawAlpha.clear(); m_drawStatic.clear(); m_drawTransparency.clear(); u32 size = (u32)m_list.size(); m_drawAlpha.reserve(size); m_drawStatic.reserve(size); m_drawTransparency.reserve(size); for (std::vector<SNodeList>::iterator iter = m_list.begin(); iter < m_list.end(); ++iter) { CNode* node = (*iter)._node; switch (node->getNodeType()) { case ENodeType::eShape: case ENodeType::eMesh: case ENodeType::eBillboard: case ENodeType::eParticleSystem: { f32 priority = 0.0f; CMesh* mesh = static_cast<CMesh*>(node); const MaterialPtr& material = mesh->getMaterial(); if (material->getTransparency() < 1.0f) { if (m_camera) { priority = (node->getAbsPosition() - m_camera->getAbsPosition()).length(); } else { priority = node->getAbsPosition().z; } node->setPriority(priority); if (checkDistance(node, priority)) { m_drawTransparency.push_back((*iter)); } } else if (mesh->getRenderTechique()->getRenderPass((*iter)._passIndex)->getRenderState()->isBlend()) { if (m_camera) { priority = (node->getAbsPosition() - m_camera->getAbsPosition()).length(); } else { priority = node->getAbsPosition().z; } node->setPriority(priority); if (checkDistance(node, priority)) { m_drawAlpha.push_back((*iter)); } } else { if (checkDistance(node, priority)) { m_drawStatic.push_back((*iter)); } } } break; case ENodeType::eCamera: { /*node->setPriority(k_maxPriority); if (static_cast<CCamera*>(node)->isActive()) { m_update.push_back(node); }*/ } break; case ENodeType::eSkyBox: { node->setPriority(k_maxPriority); m_drawStatic.push_back((*iter)); } break; case ENodeType::eLight: case ENodeType::eFog: { node->setPriority(-k_maxPriority); } break; case ENodeType::eText: { node->setPriority(0.0f); CText* text = static_cast<CText*>(node); const MaterialPtr& material = text->getMaterial(); if (material->getTransparency() < 1.0f) { m_drawTransparency.push_back((*iter)); } else if (text->getRenderTechique()->getRenderPass((*iter)._passIndex)->getRenderState()->isBlend()) { m_drawAlpha.push_back((*iter)); } else { m_drawStatic.push_back((*iter)); } } break; case ENodeType::eModel: default: break; } } m_drawStatic.shrink_to_fit(); m_draw.insert(m_draw.begin(), m_drawStatic.begin(), m_drawStatic.end()); if (!m_drawTransparency.empty()) { m_drawTransparency.shrink_to_fit(); std::sort(m_drawTransparency.begin(), m_drawTransparency.end(), [](const SNodeList& node0, const SNodeList& node1) -> bool { return (node0._node->getPriority() > node1._node->getPriority()); }); m_drawAlpha.insert(m_drawAlpha.end(), m_drawTransparency.begin(), m_drawTransparency.end()); } if (!m_drawAlpha.empty()) { m_drawAlpha.shrink_to_fit(); std::sort(m_drawAlpha.begin(), m_drawAlpha.end(), [](const SNodeList& node0, const SNodeList& node1) -> bool { return (node0._node->getPriority() > node1._node->getPriority()); }); m_draw.insert(m_draw.end(), m_drawAlpha.begin(), m_drawAlpha.end()); } }
void CResourceManager::loadChildren(const std::string &filename) { string ext = CFile::getExtension(filename); if(ext == "shape") { // need to get texture inside the shape NL3D::registerSerial3d(); CShapeStream ss; NLMISC::CIFile i(CPath::lookup(filename, false).c_str()); i.serial(ss); i.close(); CMesh *m = (CMesh*)ss.getShapePointer(); uint nbm = m->getNbMaterial(); for(uint i = 0; i < nbm; i++) { CMaterial &mat = m->getMaterial(i); for(uint j = 0; j < IDRV_MAT_MAXTEXTURES; j++) { ITexture *t = mat.getTexture(j); if(t) { CTextureFile *tf = dynamic_cast<CTextureFile *>(t); if(tf) { get(tf->getFileName()); } else { CTextureMultiFile *tmf = dynamic_cast<CTextureMultiFile *>(t); if(tmf) { for(uint t = 0; t < tmf->getNumFileName(); t++) get(tmf->getFileName(t)); } } } } } } else if(ext == "ps") { // need to get texture inside the shape NL3D::registerSerial3d(); string fn = CFile::getFilename(filename); CShapeBank *bank = new CShapeBank; string shapeCache("mtptShapeCache"); bank->addShapeCache(shapeCache); bank->setShapeCacheSize(shapeCache,1024*1024); std::vector<std::string> filelist; filelist.push_back(filename); CDriverUser *drv = (CDriverUser *)(&C3DTask::getInstance().driver()); bank->preLoadShapes(shapeCache,filelist,string("*.ps"),NULL,true,drv->getDriver()); bool b = bank->isShapeWaiting(); IShape *is = bank->getShape(fn); //bank->load(filename) CParticleSystemShape *ps = (CParticleSystemShape *)is; uint numTexture = ps->getNumCachedTextures(); nlinfo("loadchildren(%s) : num texture = %d",filename.c_str(),numTexture); for(uint i=0;i<numTexture;i++) { ITexture *tex = ps->getCachedTexture(i); CTextureFile *utex = (CTextureFile *)tex; nlinfo("loadchildren(%s) : texture = %s",filename.c_str(),utex->getFileName().c_str()); get(utex->getFileName()); } bank->reset(); delete bank; } }