The author introduces: Jiang Xue Wei Technological Partner of IT Company, Senior IT Lecturer, CSDN Community Expert, Invited Editor, Best-selling Book Author, National Patent Inventor; Published Book: Hand-to-Hand Teaching Framework 3D Game Engine. Electronic Industry Press and< Unity3D Detailed Explanation of Actual Core Technologies, Electronic Industry Press, etc.
CSDN Video Website: http://edu.csdn.net/lecturer/144
Readers have learned how to encrypt the model before. After understanding how to write the 3D encryption model, the code is compiled into an executable file. The compiled screenshots are as follows:
The compilation results in the following directories of executable files:
Next, we begin to modify the encryption mode. Developers can define the encryption mode of the model and the extended name of the model themselves. First, we find the C3BFile.cpp file, which has been implemented in the previous section. Here, we only show the reader the key functions of the modification, such as changing the extension name to x3b. The save saving function of the first modified class file is as follows:
bool save(Settings * const&settings, modeldata::Model *model) {
bool result = false;
json::BaseJSONWriter *jsonWriter = 0;
model->exportPart = settings->exportPart;
if(settings->outType == FILETYPE_ALL || settings->outType == FILETYPE_C3T)
{
std::stringout = settings->outFile;
int o = out.find_last_of(".");
out = out.substr(0, o+1) + "c3t";
std::ofstream myfile;
myfile.open (out.c_str(), std::ios::binary);
log->status(log::sExportToG3DJ, out.c_str());
jsonWriter = newjson::JSONWriter(myfile);
(*jsonWriter) << model;
delete jsonWriter;
result = true;
myfile.close();
}
if(settings->outType == FILETYPE_ALL || settings->outType == FILETYPE_C3B)
{
std::stringout = settings->outFile;
int o = out.find_last_of(".");
out = out.substr(0, o+1) + "x3b";
C3BFile file;
file.AddModel(model);
file.saveBinary(out);
log->status(log::sExportToG3DB, out.c_str());
}
log->status(log::sExportClose);
return result;
}
The saved file name needs to be changed to x3b. Another code to modify the extended file name defined in the extension function is as follows:
void setExtension(std::string&fn, constint&type) const { switch(type) { caseFILETYPE_FBX: returnsetExtension(fn, "fbx"); caseFILETYPE_G3DB: returnsetExtension(fn, "x3b"); caseFILETYPE_G3DJ: returnsetExtension(fn, "c3t"); default: returnsetExtension(fn, ""); } }
The format of the saved model file is x3b, so the format of the saved model file is x3b. Next, modify the encryption module and open the C3BFile.cpp file as follows:
bool C3BFile::saveBinary(const std::string& filepath) { _file = fopen(filepath.c_str(), "w+b"); // Document identification //char identifier[] = {'C','3','B','\0'}; unsigned char identifier[] = {8,52,67,19}; fwrite(identifier, 1, sizeof(identifier), _file); //Write version fwrite(GPB_VERSION, 1, sizeof(GPB_VERSION), _file); _refTable.writeBinary(_file); if(_models) { _models->writeBinary(_file); } _refTable.updateOffset(_file); fclose(_file); return true; }
The previous code has been commented out and modified to a custom encrypted string. The lines of code are as follows:
unsigned char identifier[] = {8,52,67,19};
The x3b model generated by the tool fbx-conv is as follows:
In this way, we can also encrypt the model ourselves.
Conclusion:
Encryption for the model has been completed, here is also to tell readers how to achieve encryption for the 3D model, but also to provide readers with a way of thinking, programmers can easily complete the encryption process. Model encryption is also handled in many ways, such as adding a field in the middle of the model or adding multiple matrix conversions in the model plug-in, etc.
Later, I will arrange and publish it as a manuscript. Please look forward to it.