MCPcopy Create free account
hub / github.com/dhewm/dhewm3 / GetModel

Method GetModel

neo/renderer/ModelManager.cpp:255–347  ·  view source on GitHub ↗

================= idRenderModelManagerLocal::GetModel ================= */

Source from the content-addressed store, hash-verified

253=================
254*/
255idRenderModel *idRenderModelManagerLocal::GetModel( const char *modelName, bool createIfNotFound ) {
256 idStr canonical;
257 idStr extension;
258
259 if ( !modelName || !modelName[0] ) {
260 return NULL;
261 }
262
263 canonical = modelName;
264 canonical.ToLower();
265
266 // see if it is already present
267 int key = hash.GenerateKey( modelName, false );
268 for ( int i = hash.First( key ); i != -1; i = hash.Next( i ) ) {
269 idRenderModel *model = models[i];
270
271 if ( canonical.Icmp( model->Name() ) == 0 ) {
272 if ( !model->IsLoaded() ) {
273 // reload it if it was purged
274 model->LoadModel();
275 } else if ( insideLevelLoad && !model->IsLevelLoadReferenced() ) {
276 // we are reusing a model already in memory, but
277 // touch all the materials to make sure they stay
278 // in memory as well
279 model->TouchData();
280 }
281 model->SetLevelLoadReferenced( true );
282 return model;
283 }
284 }
285
286 // see if we can load it
287
288 // determine which subclass of idRenderModel to initialize
289
290 idRenderModel *model;
291
292 canonical.ExtractFileExtension( extension );
293
294 if ( ( extension.Icmp( "ase" ) == 0 ) || ( extension.Icmp( "lwo" ) == 0 ) || ( extension.Icmp( "flt" ) == 0 ) ) {
295 model = new idRenderModelStatic;
296 model->InitFromFile( modelName );
297 } else if ( extension.Icmp( "ma" ) == 0 ) {
298 model = new idRenderModelStatic;
299 model->InitFromFile( modelName );
300 } else if ( extension.Icmp( MD5_MESH_EXT ) == 0 ) {
301 model = new idRenderModelMD5;
302 model->InitFromFile( modelName );
303 } else if ( extension.Icmp( "md3" ) == 0 ) {
304 model = new idRenderModelMD3;
305 model->InitFromFile( modelName );
306 // DG: no idea why this needs special treatment, but otherwise
307 // idRenderModelMD3::InstantiateDynamicModel() is called all the time
308 if ( model->IsDefaultModel() ) {
309 delete model;
310 return NULL;
311 }
312 } else if ( extension.Icmp( "prt" ) == 0 ) {

Callers

nothing calls this directly

Calls 15

ToLowerMethod · 0.80
GenerateKeyMethod · 0.80
FirstMethod · 0.80
IsLevelLoadReferencedMethod · 0.80
ExtractFileExtensionMethod · 0.80
IsDefaultModelMethod · 0.80
InitEmptyMethod · 0.80
MakeDefaultModelMethod · 0.80
IcmpMethod · 0.60
NextMethod · 0.45
NameMethod · 0.45

Tested by

no test coverage detected