void createBoxes(ISceneManager* smgr) { ISimpleMesh* boxMesh = IMeshManager::getInstance()->createCubeMesh("box1", boxSize, boxSize, boxSize); u32 boxNum = 300; #if defined(DEBUG) || defined(_DEBUG) boxNum = 100; #endif IInstanceCollectionNode* collection = smgr->addInstanceCollectionNode(boxMesh, nullptr, boxNum, sizeof(XMFLOAT4)); for (u32 i = 0; i < boxNum; i++) { addBoxInstance(smgr, boxMesh, collection); } collection->setMaterialName("multi_box_material"); collection->addShadow(1); }
bool EditorScene::PrepareAddingInstance(u32 collectionId) { SCollectionNodeInfo* collectionInfo = nullptr; for (u32 i = 0; i < mCollectionNodeInfos.size(); i++) { if (mCollectionNodeInfos[i].Id == collectionId) { collectionInfo = &mCollectionNodeInfos[i]; break; } } IInstanceCollectionNode* collectionNode = collectionInfo->CollectionNode; IInstanceNode* node = collectionNode->addInstance(false, XMFLOAT3(0, 0, 0)); node->setTag(MESH_NODE_TAG); node->addShadow(1); mAddedNode = node; return true; }
IInstanceCollectionNode* EditorScene::CreateCollectionNode(IModelMesh* mesh, int maxNum) { IInstanceCollectionNode* collectionNode = mSceneManager->addInstanceCollectionNode(mesh, nullptr, maxNum, 0); IMaterialManager* materialManager = IMaterialManager::getInstance(); IPipelineManager* pipelineManager = IPipelineManager::getInstance(); std::string prefix = "multi_"; for (u32 i = 0; i < mesh->getSubsetCount(); i++) { IMaterial* material = mesh->getMaterial(i); if (!material) continue; std::string multiMaterialName = prefix + material->getName(); IMaterial* multi_material = materialManager->get(multiMaterialName, false); if (!multi_material) { SMaterial material2(*material); material2.setName(multiMaterialName); for (u32 j = 0; j < EPU_COUNT; j++) { IPipeline* pipeline = material2.getPipeline(j); if (pipeline) { std::string pipeline_name2 = prefix + pipeline->getName(); IPipeline* pipeline2 = pipelineManager->get(pipeline_name2); material2.setPipeline(j, pipeline2); } } materialManager->add(material2); multi_material = materialManager->get(multiMaterialName, false); } collectionNode->setMaterial(i, multi_material); } collectionNode->addShadow(1); return collectionNode; }