Exemple #1
0
void Animated::SetFromCharacterName(const std::string& chName)
{
  // Characters must be consistently named: chName.md2
  std::string file = "characters/" + chName + "/" + chName + ".md2";

//std::cout << "Loading character MD2: " << file << "\n";

  LoadMd2(file);
}
Exemple #2
0
model_t	*FindModel(const char *name)
{
	guard(R_FindModel);

	TString<64> Name2;
	Name2.filename(name);

#if 0
	// try to load md3 instead of md2
	//!! disable later
	char *ext = strrchr(Name2, '.');
	if (ext && !strcmp(ext, ".md2"))
	{
		ext[3] = '3';		// ".md2" -> ".md3"
		if (GFileSystem->FileExists(Name2))
			return FindModel(Name2);
		// md3 model with the same name is not found -- load md2
		ext[3] = '2';		// ".md3" -> ".md2"
	}
#endif

	model_t *m;
	// search already loaded models
	for (int i = 0; i < modelCount; i++)
	{
		m = modelsArray[i];
		if (!m) continue;				//?? should not happens
		if (Name2 == m->Name)
		{
			// found
			if (m->type == MODEL_UNKNOWN)
				return NULL;			// model name was cached to avoid file system lookup again
			return m;
		}
	}
	if (Name2[0] == '*')
		Com_DropError("R_FindModel: inline model \"%s\" was not found", *Name2);

	if (modelCount == MAX_GLMODELS)
	{
		appWPrintf("R_FindModel: MAX_GLMODELS\n");
		return NULL;
	}

	/*----- not found -- load model ------*/
	unsigned len;
	unsigned *file;
	if (!(file = (unsigned*) GFileSystem->LoadFile(Name2, &len)))
	{
		m = new model_t;
		m->Name = Name2;
		modelsArray[modelCount++] = m;
		Com_DPrintf("R_FindModel: not found: %s\n", *Name2);
		return NULL;	// file not found
	}

	switch (LittleLong(*file))
	{
	case MD2_IDENT:
		m = LoadMd2(Name2, (byte*)file, len);
		break;
	case MD3_IDENT:
		m = LoadMd3(Name2, (byte*)file, len);
		break;
	case SP2_IDENT:
		m = LoadSp2(Name2, (byte*)file, len);
		break;
	case BYTES4('/','/','S','P'):
		m = LoadSpr(Name2, (byte*)file, len);
		break;
	default:
		// no error here: simply ignore unknown model formats
		appWPrintf("R_FindModel: unknown ID 0x%X in %s", (unsigned)LittleLong(*file), name);
		m = NULL;
	}
	if (m) modelsArray[modelCount++] = m;

	delete file;
	return m;

	unguardf(("mdl=%s", name));
}