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

Method InternReadFile

code/AssetLib/XGL/XGLLoader.cpp:96–167  ·  view source on GitHub ↗

------------------------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

94
95// ------------------------------------------------------------------------------------------------
96void XGLImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
97 clear();
98#ifndef ASSIMP_BUILD_NO_COMPRESSED_XGL
99 std::vector<char> uncompressed;
100#endif
101
102 m_scene = pScene;
103 std::shared_ptr<IOStream> stream(pIOHandler->Open(pFile, "rb"));
104
105 // check whether we can read from the file
106 if (stream == nullptr) {
107 throw DeadlyImportError("Failed to open XGL/ZGL file " + pFile);
108 }
109
110 // see if its compressed, if so uncompress it
111 if (GetExtension(pFile) == "zgl") {
112#ifdef ASSIMP_BUILD_NO_COMPRESSED_XGL
113 ThrowException("Cannot read ZGL file since Assimp was built without compression support");
114#else
115 std::unique_ptr<StreamReaderLE> raw_reader(new StreamReaderLE(stream));
116
117 Compression compression;
118 size_t total = 0l;
119 if (compression.open(Compression::Format::Binary, Compression::FlushMode::NoFlush, -Compression::MaxWBits)) {
120 // skip two extra bytes, zgl files do carry a crc16 upfront (I think)
121 raw_reader->IncPtr(2);
122 total = compression.decompress((unsigned char *)raw_reader->GetPtr(), raw_reader->GetRemainingSize(), uncompressed);
123 compression.close();
124 }
125 // replace the input stream with a memory stream
126 stream = std::make_shared<MemoryIOStream>(reinterpret_cast<uint8_t *>(uncompressed.data()), total);
127#endif
128 }
129
130 // parse the XML file
131 mXmlParser = new XmlParser;
132 if (!mXmlParser->parse(stream.get())) {
133 throw DeadlyImportError("XML parse error while loading XGL file ", pFile);
134 }
135
136 TempScope scope;
137 XmlNode *worldNode = mXmlParser->findNode("WORLD");
138 if (nullptr != worldNode) {
139 ReadWorld(*worldNode, scope);
140 }
141
142 std::vector<aiMesh *> &meshes = scope.meshes_linear;
143 std::vector<aiMaterial *> &materials = scope.materials_linear;
144 if (meshes.empty() || materials.empty()) {
145 ThrowException("failed to extract data from XGL file, no meshes loaded");
146 }
147
148 // copy meshes
149 m_scene->mNumMeshes = static_cast<unsigned int>(meshes.size());
150 m_scene->mMeshes = new aiMesh *[m_scene->mNumMeshes]();
151 std::copy(meshes.begin(), meshes.end(), m_scene->mMeshes);
152
153 // copy materials

Callers

nothing calls this directly

Calls 15

clearFunction · 0.85
DeadlyImportErrorFunction · 0.85
IncPtrMethod · 0.80
decompressMethod · 0.80
GetPtrMethod · 0.80
GetRemainingSizeMethod · 0.80
openMethod · 0.65
closeMethod · 0.65
OpenMethod · 0.45
dataMethod · 0.45
parseMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected