MCPcopy Create free account
hub / github.com/ZDoom/Raze / Load

Method Load

source/common/models/models_obj.cpp:38–234  ·  view source on GitHub ↗

* Load an OBJ model * * @param fn The path to the model file * @param lumpnum The lump index in the wad collection * @param buffer The contents of the model file * @param length The size of the model file * @return Whether or not the model was parsed successfully */

Source from the content-addressed store, hash-verified

36 * @return Whether or not the model was parsed successfully
37 */
38bool FOBJModel::Load(const char* fn, int lumpnum, const char* buffer, int length)
39{
40 auto objName = fileSystem.GetFileFullPath(lumpnum);
41 FString objBuf(buffer, length);
42
43 // Do some replacements before we parse the OBJ string
44 {
45 // Ensure usemtl statements remain intact
46 TArray<FString> mtlUsages;
47 TArray<ptrdiff_t> mtlUsageIdxs;
48 ptrdiff_t bpos = 0, nlpos = 0, slashpos = 0;
49 while (1)
50 {
51 bpos = objBuf.IndexOf("\nusemtl", bpos);
52 if (bpos == -1) break;
53 slashpos = objBuf.IndexOf('/', bpos);
54 nlpos = objBuf.IndexOf('\n', ++bpos);
55 if (slashpos > nlpos || slashpos == -1)
56 {
57 continue;
58 }
59 if (nlpos == -1)
60 {
61 nlpos = objBuf.Len();
62 }
63 FString lineStr(objBuf.GetChars() + bpos, nlpos - bpos);
64 mtlUsages.Push(lineStr);
65 mtlUsageIdxs.Push(bpos);
66 }
67
68 // Replace forward slashes with percent signs so they aren't parsed as line comments
69 objBuf.ReplaceChars('/', *newSideSep);
70 char* wObjBuf = objBuf.LockBuffer();
71
72 // Substitute broken usemtl statements with old ones
73 for (size_t i = 0; i < mtlUsages.Size(); i++)
74 {
75 bpos = mtlUsageIdxs[i];
76 nlpos = objBuf.IndexOf('\n', bpos);
77 if (nlpos == -1)
78 {
79 nlpos = objBuf.Len();
80 }
81 memcpy(wObjBuf + bpos, mtlUsages[i].GetChars(), nlpos - bpos);
82 }
83
84 bpos = 0;
85 // Find each OBJ line comment, and convert each to a C-style line comment
86 while (1)
87 {
88 bpos = objBuf.IndexOf('#', bpos);
89 if (bpos == -1) break;
90 if (objBuf[(unsigned int)bpos + 1] == '\n')
91 {
92 wObjBuf[bpos] = ' ';
93 }
94 else
95 {

Callers

nothing calls this directly

Calls 15

FNullTextureIDClass · 0.85
LoadSkinFunction · 0.85
GetFileFullPathMethod · 0.80
LenMethod · 0.80
LockBufferMethod · 0.80
UnlockBufferMethod · 0.80
OpenStringMethod · 0.80
c_strMethod · 0.80
MustGetStringMethod · 0.80
ScriptMessageMethod · 0.80
IndexOfAnyMethod · 0.80
UnGetMethod · 0.80

Tested by

no test coverage detected