** more specific question ** How to read a 3d file (the type of data is not known) into memory to feed the following method .
i am simply trying to import a file (a 3d model.stl file) into memory and then pass it to the following method .
const aiScene* ReadFileFromMemory(
const void* pBuffer,
size_t pLength,
unsigned int pFlags,
const char* pHint = "");
but i don't know how to provide the following 2 arguments for the method mentioned above :
const void* pBuffer
size_t pLength
Can someone provide me with a block of code for this ? How can i use ifstream to read a file from memory (like "model.stl") , and then put it inside a buffer and pass it to the mentioned method
Tnx
ps . ReadFileFromMemory requires a pointer to the data. The data can be a char[], std::string, std::vector<uint8_t> or similar. Anything that holds raw data in contiguous memory and can provide a pointer to it
How to achieve this ?
===================== UPDATE ======================
Solution
string readFile(const string& fileName)
{
ifstream ifs(fileName.c_str(), ios::in | ios::binary | ios::ate);
ifstream::pos_type fileSize = ifs.tellg();
ifs.seekg(0, ios::beg);
vector<char> bytes(fileSize);
ifs.read(bytes.data(), fileSize);
return string(bytes.data(), fileSize);
}
and then take the buffer and it's length as the following :
std::string my_file = readFile("models/model_file.ext");
const char* pbuffer = my_file.data();
size_t plenght = my_file.length();