------------------------------------------------------------------------------------------------ Imports the given file into the given scene structure.
| 783 | // ------------------------------------------------------------------------------------------------ |
| 784 | // Imports the given file into the given scene structure. |
| 785 | void 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); |
nothing calls this directly
no test coverage detected