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

Method InternReadFile

code/AssetLib/AC/ACLoader.cpp:785–900  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

783// ------------------------------------------------------------------------------------------------
784// Imports the given file into the given scene structure.
785void AC3DImporter::InternReadFile(const std::string &pFile,
786 aiScene *pScene, IOSystem *pIOHandler) {
787 std::unique_ptr<IOStream> file(pIOHandler->Open(pFile, "rb"));
788
789 // Check whether we can read from the file
790 if (file == nullptr) {
791 throw DeadlyImportError("Failed to open AC3D file ", pFile, ".");
792 }
793
794 // allocate storage and copy the contents of the file to a memory buffer
795 std::vector<char> mBuffer2;
796 TextFileToBuffer(file.get(), mBuffer2);
797
798 mBuffer.data = &mBuffer2[0];
799 mBuffer.end = &mBuffer2[0] + mBuffer2.size();
800 mNumMeshes = 0;
801
802 mLightsCounter = mPolysCounter = mWorldsCounter = mGroupsCounter = 0;
803
804 if (::strncmp(mBuffer.data, "AC3D", 4)) {
805 throw DeadlyImportError("AC3D: No valid AC3D file, magic sequence not found");
806 }
807
808 // print the file format version to the console
809 unsigned int version = HexDigitToDecimal(mBuffer.data[4]);
810 char msg[3];
811 ASSIMP_itoa10(msg, 3, version);
812 ASSIMP_LOG_INFO("AC3D file format version: ", msg);
813
814 std::vector<Material> materials;
815 materials.reserve(5);
816
817 std::vector<Object> rootObjects;
818 rootObjects.reserve(5);
819
820 std::vector<aiLight *> lights;
821 mLights = &lights;
822
823 while (GetNextLine()) {
824 if (TokenMatch(mBuffer.data, "MATERIAL", 8)) {
825 materials.emplace_back();
826 Material &mat = materials.back();
827
828 // manually parse the material ... sscanf would use the buldin atof ...
829 // Format: (name) rgb %f %f %f amb %f %f %f emis %f %f %f spec %f %f %f shi %d trans %f
830
831 mBuffer.data = AcSkipToNextToken(mBuffer.data, mBuffer.end);
832 if ('\"' == *mBuffer.data) {
833 mBuffer.data = AcGetString(mBuffer.data, mBuffer.end, mat.name);
834 mBuffer.data = AcSkipToNextToken(mBuffer.data, mBuffer.end);
835 }
836
837 mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "rgb", 3, 3, &mat.rgb);
838 mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "amb", 3, 3, &mat.amb);
839 mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "emis", 4, 3, &mat.emis);
840 mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "spec", 4, 3, &mat.spec);
841 mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "shi", 3, 1, &mat.shin);
842 mBuffer.data = TAcCheckedLoadFloatArray(mBuffer.data, mBuffer.end, "trans", 5, 1, &mat.trans);

Callers

nothing calls this directly

Calls 15

DeadlyImportErrorFunction · 0.85
HexDigitToDecimalFunction · 0.85
ASSIMP_itoa10Function · 0.85
GetNextLineFunction · 0.85
TokenMatchFunction · 0.85
AcSkipToNextTokenFunction · 0.85
AcGetStringFunction · 0.85
TAcCheckedLoadFloatArrayFunction · 0.85
emplace_backMethod · 0.80
OpenMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected