// Load the given model from the VFS path IModelPtr PicoModelLoader::loadModelFromPath(const std::string& name) { // Open an ArchiveFile to load ArchiveFilePtr file = GlobalFileSystem().openFile(name); if (file == NULL) { rError() << "Failed to load model " << name << std::endl; return IModelPtr(); } // Determine the file extension (ASE or LWO) to pass down to the PicoModel std::string fName = file->getName(); boost::algorithm::to_lower(fName); std::string fExt = fName.substr(fName.size() - 3, 3); picoModel_t* model = PicoModuleLoadModelStream( _module, &file->getInputStream(), picoInputStreamReam, file->size(), 0 ); // greebo: Check if the model load was successful if (model == NULL || model->numSurfaces == 0) { // Model is either NULL or has no surfaces, this must've failed return IModelPtr(); } RenderablePicoModelPtr modelObj( new RenderablePicoModel(model, fExt) ); // Set the filename modelObj->setFilename(os::getFilename(file->getName())); modelObj->setModelPath(name); PicoFreeModel(model); return modelObj; }
model::IModelPtr MD5ModelLoader::loadModelFromPath(const std::string& name) { // Open an ArchiveFile to load ArchiveFilePtr file = GlobalFileSystem().openFile(name); if (file != NULL) { // Construct a new MD5Model container MD5ModelPtr model(new MD5Model); // Store the VFS path in this model model->setModelPath(name); // Set the filename this model was loaded from model->setFilename(os::getFilename(file->getName())); // greebo: Get the Inputstream from the given file BinaryToTextInputStream<InputStream> inputStream(file->getInputStream()); // Construct a Tokeniser object and start reading the file try { std::istream is(&inputStream); parser::BasicDefTokeniser<std::istream> tokeniser(is); // Invoke the parser routine (might throw) model->parseFromTokens(tokeniser); } catch (parser::ParseException& e) { rError() << "[md5model] Parse failure. Exception was:" << std::endl << e.what() << std::endl; // Return an empty model on error return model::IModelPtr(); } // Load was successful, return the model return model; } else { rError() << "Failed to load model " << name << std::endl; return model::IModelPtr(); // delete the model } }