void OptimiseData::ParseMeshObj(csArray<csString>& libsNeeded, csArray<csString>& materialsNeeded, csString& mapInPath, csRef<iDocumentNode> meshobj) { csRef<iDocumentNodeIterator> meshobjs = meshobj->GetNodes("meshobj"); while(meshobjs->HasNext()) { ParseMeshObj(libsNeeded, materialsNeeded, mapInPath, meshobjs->Next()); } if(meshobj->GetNode("params")) { meshobj = meshobj->GetNode("params"); if(meshobj->GetNode("factory")) { bool found = false; for(size_t i=0; i<meshFactsOut.GetSize(); i++) { if(csString(meshFactsOut[i]->GetRoot()->GetNode("library")->GetNode("meshfact")->GetAttributeValue("name")).Compare(meshobj->GetNode("factory")->GetContentsValue())) { libsNeeded.PushSmart(meshobj->GetNode("factory")->GetContentsValue()); found = true; } } if(!found) { // Print error and mark data as incorrect. csFPrintf(stderr, "ERROR: Mesh object %s uses mesh factory %s but there is no factory data!\n", meshobj->GetAttributeValue("name"), meshobj->GetNode("factory")->GetContentsValue()); } } if(meshobj->GetNode("material")) { bool found = false; for(size_t i=0; i<materials.GetSize(); i++) { if(csString(materials[i]->GetAttributeValue("name")).Compare(meshobj->GetNode("material")->GetContentsValue())) { materialsNeeded.PushSmart(meshobj->GetNode("material")->GetContentsValue()); found = true; } } if(!found) { // Print error and mark data as incorrect. csFPrintf(stderr, "ERROR: Mesh object %s uses material %s but there is no such material declaration!\n", meshobj->GetAttributeValue("name"), meshobj->GetNode("material")->GetContentsValue()); } } } else if(meshobj->GetNode("paramsfile")) { csString paramsPath = mapInPath + "/" + meshobj->GetNode("paramsfile")->GetContentsValue(); csRef<iFile> file = vfs->Open(paramsPath, VFS_FILE_READ); csRef<iDocument> paramsDoc = docSys->CreateDocument(); paramsDoc->Parse(file); meshobj = paramsDoc->GetRoot()->GetNode("params"); if(meshobj->GetNode("factory")) { bool found = false; for(size_t i=0; i<meshFactsOut.GetSize(); i++) { if(csString(meshFactsOut[i]->GetRoot()->GetNode("library")->GetNode("meshfact")->GetAttributeValue("name")).Compare(meshobj->GetNode("factory")->GetContentsValue())) { libsNeeded.PushSmart(meshobj->GetNode("factory")->GetContentsValue()); found = true; } } if(!found) { // Print error and mark data as incorrect. csFPrintf(stderr, "ERROR: Mesh object %s uses mesh factory %s but there is no factory data!\n", meshobj->GetParent()->GetAttributeValue("name"), meshobj->GetNode("factory")->GetContentsValue()); } } if(meshobj->GetNode("material")) { bool found = false; for(size_t i=0; i<materials.GetSize(); i++) { if(csString(materials[i]->GetAttributeValue("name")).Compare(meshobj->GetNode("material")->GetContentsValue())) { materialsNeeded.PushSmart(meshobj->GetNode("material")->GetContentsValue()); found = true; } } if(!found) { // Print error and mark data as incorrect. csFPrintf(stderr, "ERROR: Mesh object %s uses material %s but there is no such material declaration!\n", meshobj->GetParent()->GetAttributeValue("name"), meshobj->GetNode("material")->GetContentsValue()); } } } }