------------------------------------------------------------------------------------------------ Obj-file import implementation
| 103 | // ------------------------------------------------------------------------------------------------ |
| 104 | // Obj-file import implementation |
| 105 | void ObjFileImporter::InternReadFile(const std::string &file, aiScene *pScene, IOSystem *pIOHandler) { |
| 106 | if (m_pRootObject != nullptr) { |
| 107 | delete m_pRootObject; |
| 108 | m_pRootObject = nullptr; |
| 109 | } |
| 110 | |
| 111 | // Read file into memory |
| 112 | static constexpr char mode[] = "rb"; |
| 113 | auto streamCloser = [&](IOStream *pStream) { |
| 114 | pIOHandler->Close(pStream); |
| 115 | }; |
| 116 | std::unique_ptr<IOStream, decltype(streamCloser)> fileStream(pIOHandler->Open(file, mode), streamCloser); |
| 117 | if (!fileStream) { |
| 118 | throw DeadlyImportError("Failed to open file ", file, "."); |
| 119 | } |
| 120 | |
| 121 | // Get the file-size and validate it, throwing an exception when fails |
| 122 | size_t fileSize = fileStream->FileSize(); |
| 123 | if (fileSize < ObjMinSize) { |
| 124 | throw DeadlyImportError("OBJ-file is too small."); |
| 125 | } |
| 126 | |
| 127 | IOStreamBuffer<char> streamedBuffer; |
| 128 | streamedBuffer.open(fileStream.get()); |
| 129 | |
| 130 | // Allocate buffer and read file into it |
| 131 | //TextFileToBuffer( fileStream.get(),m_Buffer); |
| 132 | |
| 133 | // Get the model name |
| 134 | std::string modelName, folderName; |
| 135 | std::string::size_type pos = file.find_last_of("\\/"); |
| 136 | if (pos != std::string::npos) { |
| 137 | modelName = file.substr(pos + 1, file.size() - pos - 1); |
| 138 | folderName = file.substr(0, pos); |
| 139 | if (!folderName.empty()) { |
| 140 | pIOHandler->PushDirectory(folderName); |
| 141 | } |
| 142 | } else { |
| 143 | modelName = file; |
| 144 | } |
| 145 | |
| 146 | // parse the file into a temporary representation |
| 147 | ObjFileParser parser(streamedBuffer, modelName, pIOHandler, m_progress, file); |
| 148 | |
| 149 | // And create the proper return structures out of it |
| 150 | CreateDataFromImport(parser.GetModel(), pScene); |
| 151 | |
| 152 | streamedBuffer.close(); |
| 153 | |
| 154 | // Clean up allocated storage for the next import |
| 155 | m_Buffer.clear(); |
| 156 | |
| 157 | // Pop directory stack |
| 158 | if (pIOHandler->StackSize() > 0) { |
| 159 | pIOHandler->PopDirectory(); |
| 160 | } |
| 161 | } |
| 162 |
nothing calls this directly
no test coverage detected