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

Method InternReadFile

code/AssetLib/OFF/OFFLoader.cpp:96–325  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

94// ------------------------------------------------------------------------------------------------
95// Imports the given file into the given scene structure.
96void OFFImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
97 std::unique_ptr<IOStream> file(pIOHandler->Open(pFile, "rb"));
98
99 // Check whether we can read from the file
100 if (file == nullptr) {
101 throw DeadlyImportError("Failed to open OFF file ", pFile, ".");
102 }
103
104 // allocate storage and copy the contents of the file to a memory buffer
105 std::vector<char> mBuffer2;
106 TextFileToBuffer(file.get(), mBuffer2);
107 const char *buffer = &mBuffer2[0];
108
109 // Proper OFF header parser. We only implement normal loading for now.
110 bool hasTexCoord = false, hasNormals = false, hasColors = false;
111 bool hasHomogenous = false, hasDimension = false;
112 unsigned int dimensions = 3;
113 const char *car = buffer;
114 const char *end = buffer + mBuffer2.size();
115 NextToken(&car, end);
116
117 if (car < end - 2 && car[0] == 'S' && car[1] == 'T') {
118 hasTexCoord = true;
119 car += 2;
120 }
121 if (car < end - 1 && car[0] == 'C') {
122 hasColors = true;
123 car++;
124 }
125 if (car < end - 1 && car[0] == 'N') {
126 hasNormals = true;
127 car++;
128 }
129 if (car < end - 1 && car[0] == '4') {
130 hasHomogenous = true;
131 car++;
132 }
133 if (car < end - 1 && car[0] == 'n') {
134 hasDimension = true;
135 car++;
136 }
137 if (car < end - 3 && car[0] == 'O' && car[1] == 'F' && car[2] == 'F') {
138 car += 3;
139 NextToken(&car, end);
140 } else {
141 // in case there is no OFF header (which is allowed by the
142 // specification...), then we might have unintentionally read an
143 // additional dimension from the primitive count fields
144 dimensions = 3;
145 hasHomogenous = false;
146 NextToken(&car, end);
147
148 // at this point the next token should be an integer number
149 if (car >= end - 1 || *car < '0' || *car > '9') {
150 throw DeadlyImportError("OFF: Header is invalid");
151 }
152 }
153 if (hasDimension) {

Callers

nothing calls this directly

Calls 11

DeadlyImportErrorFunction · 0.85
NextTokenFunction · 0.85
strtoul10Function · 0.85
GetNextLineFunction · 0.85
fast_atoreal_moveFunction · 0.85
SkipSpacesFunction · 0.50
OpenMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45
SetMethod · 0.45
AddPropertyMethod · 0.45

Tested by

no test coverage detected