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

Method InternReadFile

code/AssetLib/FBX/FBXImporter.cpp:126–189  ·  view source on GitHub ↗

------------------------------------------------------------------------------------------------ Imports the given file into the given scene structure.

Source from the content-addressed store, hash-verified

124// ------------------------------------------------------------------------------------------------
125// Imports the given file into the given scene structure.
126void FBXImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
127 auto streamCloser = [&](IOStream *pStream) {
128 pIOHandler->Close(pStream);
129 };
130 std::unique_ptr<IOStream, decltype(streamCloser)> stream(pIOHandler->Open(pFile, "rb"), streamCloser);
131 if (!stream) {
132 ThrowException("Could not open file for reading");
133 }
134
135 ASSIMP_LOG_DEBUG("Reading FBX file");
136
137 // read entire file into memory - no streaming for this, fbx
138 // files can grow large, but the assimp output data structure
139 // then becomes very large, too. Assimp doesn't support
140 // streaming for its output data structures so the net win with
141 // streaming input data would be very low.
142 std::vector<char> contents;
143 contents.resize(stream->FileSize() + 1);
144 stream->Read(&*contents.begin(), 1, contents.size() - 1);
145 contents[contents.size() - 1] = 0;
146 const char *const begin = &*contents.begin();
147
148 // broad-phase tokenized pass in which we identify the core
149 // syntax elements of FBX (brackets, commas, key:value mappings)
150 TokenList tokens;
151 Assimp::StackAllocator tempAllocator;
152 try {
153 bool is_binary = false;
154 if (!strncmp(begin, "Kaydara FBX Binary", 18)) {
155 is_binary = true;
156 TokenizeBinary(tokens, begin, contents.size(), tempAllocator);
157 } else {
158 Tokenize(tokens, begin, tempAllocator);
159 }
160
161 // use this information to construct a very rudimentary
162 // parse-tree representing the FBX scope structure
163 Parser parser(tokens, tempAllocator, is_binary);
164
165 // take the raw parse-tree and convert it to a FBX DOM
166 Document doc(parser, mSettings);
167
168 // convert the FBX DOM to aiScene
169 ConvertToAssimpScene(pScene, doc, mSettings.removeEmptyBones);
170
171 // size relative to cm
172 float size_relative_to_cm = doc.GlobalSettings().UnitScaleFactor();
173 if (size_relative_to_cm == 0.0) {
174 // BaseImporter later asserts that fileScale is non-zero.
175 ThrowException("The UnitScaleFactor must be non-zero");
176 }
177
178 // Set FBX file scale is relative to CM must be converted to M for
179 // assimp universal format (M)
180 SetFileScale(size_relative_to_cm * 0.01f);
181
182 // This collection does not own the memory for the tokens, but we need to call their d'tor
183 std::for_each(tokens.begin(), tokens.end(), Util::destructor_fun<Token>());

Callers

nothing calls this directly

Calls 12

TokenizeBinaryFunction · 0.85
TokenizeFunction · 0.85
ConvertToAssimpSceneFunction · 0.85
SetFileScaleFunction · 0.85
CloseMethod · 0.45
OpenMethod · 0.45
resizeMethod · 0.45
FileSizeMethod · 0.45
ReadMethod · 0.45
beginMethod · 0.45
sizeMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected