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

Method Load

source/common/models/models_md3.cpp:131–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129//===========================================================================
130
131bool FMD3Model::Load(const char * path, int lumpnum, const char * buffer, int length)
132{
133 md3_header_t * hdr = (md3_header_t *)buffer;
134
135 auto numFrames = LittleLong(hdr->Num_Frames);
136 auto numSurfaces = LittleLong(hdr->Num_Surfaces);
137 hasSurfaces = numSurfaces > 1;
138
139 numTags = LittleLong(hdr->Num_Tags);
140
141 md3_frame_t * frm = (md3_frame_t*)(buffer + LittleLong(hdr->Ofs_Frames));
142
143 Frames.Resize(numFrames);
144 for (unsigned i = 0; i < numFrames; i++)
145 {
146 strncpy(Frames[i].Name, frm[i].Name, 15);
147 for (int j = 0; j < 3; j++) Frames[i].origin[j] = frm[i].localorigin[j];
148 }
149
150 md3_surface_t * surf = (md3_surface_t*)(buffer + LittleLong(hdr->Ofs_Surfaces));
151
152 Surfaces.Resize(numSurfaces);
153
154 for (unsigned i = 0; i < numSurfaces; i++)
155 {
156 MD3Surface * s = &Surfaces[i];
157 md3_surface_t * ss = surf;
158
159 surf = (md3_surface_t *)(((char*)surf) + LittleLong(surf->Ofs_End));
160
161 s->numSkins = LittleLong(ss->Num_Shaders);
162 s->numTriangles = LittleLong(ss->Num_Triangles);
163 s->numVertices = LittleLong(ss->Num_Verts);
164
165 // copy shaders (skins)
166 md3_shader_t * shader = (md3_shader_t*)(((char*)ss) + LittleLong(ss->Ofs_Shaders));
167 s->Skins.Resize(s->numSkins);
168
169 for (unsigned ii = 0; ii < s->numSkins; ii++)
170 {
171 // [BB] According to the MD3 spec, Name is supposed to include the full path.
172 // ... and since some tools seem to output backslashes, these need to be replaced with forward slashes to work.
173 FixPathSeperator(shader[ii].Name);
174 s->Skins[ii] = LoadSkin("", shader[ii].Name);
175 // [BB] Fall back and check if Name is relative.
176 if (!s->Skins[ii].isValid())
177 s->Skins[ii] = LoadSkin(path, shader[ii].Name);
178 }
179 }
180 mLumpNum = lumpnum;
181 return true;
182}
183
184//===========================================================================
185//

Callers

nothing calls this directly

Calls 5

LoadSkinFunction · 0.85
LittleLongFunction · 0.50
FixPathSeperatorFunction · 0.50
ResizeMethod · 0.45
isValidMethod · 0.45

Tested by

no test coverage detected