MCPcopy Create free account
hub / github.com/assimp/assimp / InternReadFile

Method InternReadFile

code/AssetLib/Obj/ObjFileImporter.cpp:105–161  ·  view source on GitHub ↗

------------------------------------------------------------------------------------------------ Obj-file import implementation

Source from the content-addressed store, hash-verified

103// ------------------------------------------------------------------------------------------------
104// Obj-file import implementation
105void 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

Callers

nothing calls this directly

Calls 14

DeadlyImportErrorFunction · 0.85
GetModelMethod · 0.80
openMethod · 0.65
closeMethod · 0.65
CloseMethod · 0.45
OpenMethod · 0.45
FileSizeMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
PushDirectoryMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected