| 41 | } |
| 42 | |
| 43 | IModelPtr ModelCache::getModel(const std::string& modelPath) |
| 44 | { |
| 45 | // Try to lookup the existing model |
| 46 | auto found = _modelMap.find(modelPath); |
| 47 | |
| 48 | if (_enabled && found != _modelMap.end()) |
| 49 | { |
| 50 | return found->second; |
| 51 | } |
| 52 | |
| 53 | // The model is not cached or the cache is disabled, load afresh |
| 54 | |
| 55 | // Get the extension of this model |
| 56 | std::string type = os::getExtension(modelPath); |
| 57 | |
| 58 | // Find a suitable model loader |
| 59 | IModelImporterPtr modelLoader = GlobalModelFormatManager().getImporter(type); |
| 60 | |
| 61 | IModelPtr model = modelLoader->loadModelFromPath(modelPath); |
| 62 | |
| 63 | if (model) |
| 64 | { |
| 65 | // Model successfully loaded, insert a reference into the map |
| 66 | _modelMap.emplace(modelPath, model); |
| 67 | } |
| 68 | |
| 69 | return model; |
| 70 | } |
| 71 | |
| 72 | scene::INodePtr ModelCache::getModelNodeForStaticResource(const std::string& resourcePath) |
| 73 | { |