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

Method InternReadFile

code/AssetLib/M3D/M3DImporter.cpp:136–201  ·  view source on GitHub ↗

------------------------------------------------------------------------------------------------ Model 3D import implementation

Source from the content-addressed store, hash-verified

134// ------------------------------------------------------------------------------------------------
135// Model 3D import implementation
136void M3DImporter::InternReadFile(const std::string &file, aiScene *pScene, IOSystem *pIOHandler) {
137 // Read file into memory
138 std::unique_ptr<IOStream> pStream(pIOHandler->Open(file, "rb"));
139 if (!pStream.get()) {
140 throw DeadlyImportError("Failed to open file ", file, ".");
141 }
142
143 // Get the file-size and validate it, throwing an exception when fails
144 size_t fileSize = pStream->FileSize();
145 if (fileSize < 8) {
146 throw DeadlyImportError("M3D-file ", file, " is too small.");
147 }
148 std::vector<unsigned char> buffer(fileSize);
149 if (fileSize != pStream->Read(buffer.data(), 1, fileSize)) {
150 throw DeadlyImportError("Failed to read the file ", file, ".");
151 }
152 // extra check for binary format's first 8 bytes. Not done for the ASCII variant
153 if (!memcmp(buffer.data(), "3DMO", 4) && memcmp(buffer.data() + 4, &fileSize, 4)) {
154 throw DeadlyImportError("Bad binary header in file ", file, ".");
155 }
156 // make sure there's a terminator zero character, as input must be ASCIIZ
157 if (!memcmp(buffer.data(), "3dmo", 4)) {
158 buffer.push_back(0);
159 }
160
161 // Get the path for external assets
162 std::string folderName("./");
163 std::string::size_type pos = file.find_last_of("\\/");
164 if (pos != std::string::npos) {
165 folderName = file.substr(0, pos);
166 if (!folderName.empty()) {
167 pIOHandler->PushDirectory(folderName);
168 }
169 }
170
171 //DefaultLogger::create("/dev/stderr", Logger::VERBOSE);
172 ASSIMP_LOG_DEBUG("M3D: loading ", file);
173
174 // let the C SDK do the hard work for us
175 M3DWrapper m3d(pIOHandler, buffer);
176
177 if (!m3d) {
178 throw DeadlyImportError("Unable to parse ", file, " as M3D.");
179 }
180
181 // create the root node
182 pScene->mRootNode = new aiNode;
183 pScene->mRootNode->mName = aiString(m3d.Name());
184 pScene->mRootNode->mTransformation = aiMatrix4x4();
185 pScene->mRootNode->mNumChildren = 0;
186 mScene = pScene;
187
188 ASSIMP_LOG_DEBUG("M3D: root node ", m3d.Name());
189
190 // now we just have to fill up the Assimp structures in pScene
191 importMaterials(m3d);
192 importTextures(m3d);
193 importBones(m3d, M3D_NOTDEFINED, pScene->mRootNode);

Callers

nothing calls this directly

Calls 14

DeadlyImportErrorFunction · 0.85
aiMatrix4x4Class · 0.85
aiStringClass · 0.50
OpenMethod · 0.45
getMethod · 0.45
FileSizeMethod · 0.45
ReadMethod · 0.45
dataMethod · 0.45
push_backMethod · 0.45
emptyMethod · 0.45
PushDirectoryMethod · 0.45
NameMethod · 0.45

Tested by

no test coverage detected