Пример #1
0
MF_API bool MFAsset_ConvertModelAndAnimationFromFile(const char *pFilename, void **ppMesh, size_t *pMeshSize, void **ppAnimation, size_t *pAnimationSize, MFPlatform platform, size_t extraBytes)
{
	// should this request be forewarded to the file server, or should we do it locally?
	//... todo

	if(!MFIntAsset_ConvertModelAndAnimationFromFile(pFilename, ppMesh, pMeshSize, ppAnimation, pAnimationSize, platform, extraBytes))
		return false;

	if(ppMesh && *ppMesh)
	{
		MFFile *pFile = MFFileSystem_Open(MFStr("cache:%s.mdl", pFilename), MFOF_Write | MFOF_Binary);
		if(pFile)
		{
			MFFile_Write(pFile, *ppMesh, *pMeshSize, false);
			MFFile_Close(pFile);
		}
	}
	if(ppAnimation && *ppAnimation)
	{
		MFFile *pFile = MFFileSystem_Open(MFStr("cache:%s.anm", pFilename), MFOF_Write | MFOF_Binary);
		if(pFile)
		{
			MFFile_Write(pFile, *ppAnimation, *pAnimationSize, false);
			MFFile_Close(pFile);
		}
	}
	return true;
}
Пример #2
0
MF_API bool MFAsset_ConvertAssetFromFile(const char *pFilename, void **ppOutput, size_t *pSize, MFPlatform platform, size_t extraBytes)
{
	// should this request be forewarded to the file server, or should we do it locally?
	//... todo

	size_t size;
	if(!MFIntAsset_ConvertAssetFromFile(pFilename, ppOutput, &size, platform, extraBytes) || !*ppOutput)
		return false;

	if(pSize)
		*pSize = size;

	const char *pExt = MFString_GetFileExtension(pFilename);
	const char *pCacheExt = NULL;
	if(!MFString_CaseCmp(pExt, ".mfx"))
		pCacheExt = ".bfx";
	else if(!MFString_CaseCmp(pExt, ".fnt"))
		pCacheExt = ".fft";
	else if(!MFAsset_IsSoundFile(pExt))
		pCacheExt = ".snd";
	else if(!MFAsset_IsImageFile(pExt))
		pCacheExt = ".tex";
	else if(!MFAsset_IsGeometryFile(pExt))
		pCacheExt = ".mdl";
	else if(!MFAsset_IsShaderFile(pExt))
		pCacheExt = ".fsh";

	MFFile *pFile = MFFileSystem_Open(MFStr("cache:%s%s", pFilename, pCacheExt), MFOF_Write | MFOF_Binary);
	if(pFile)
	{
		MFFile_Write(pFile, *ppOutput, size, false);
		MFFile_Close(pFile);
	}
	return true;
}
Пример #3
0
MF_API size_t MFFileSystem_Save(const char *pFilename, const char *pBuffer, size_t size)
{
	MFDebug_Log(5, MFStr("Call: MFFileSystem_Save(\"%s\")", pFilename));

	size_t bytesWritten = 0;

	MFFile *hFile = MFFileSystem_Open(pFilename, MFOF_Write|MFOF_Truncate|MFOF_Binary|MFOF_CreateDirectory);
	if(hFile)
	{
		bytesWritten = MFFile_Write(hFile, pBuffer, size, false);

		MFFile_Close(hFile);
	}

	return bytesWritten;
}
Пример #4
0
MF_API bool MFAsset_ConvertShaderFromFile(const char *pFilename, void **ppOutput, size_t *pSize, MFPlatform platform, MFShaderType shaderType, MFShaderMacro *pMacros, MFRendererDrivers renderDriver, MFShaderLanguage language)
{
	// should this request be forewarded to the file server, or should we do it locally?
	//... todo

	if(!MFIntAsset_ConvertShaderFromFile(pFilename, ppOutput, pSize, platform, shaderType, pMacros, renderDriver, language))
		return false;

	MFFile *pFile = MFFileSystem_Open(MFStr("cache:%s.fsh", pFilename), MFOF_Write | MFOF_Binary);
	if(pFile)
	{
		MFFile_Write(pFile, *ppOutput, *pSize, false);
		MFFile_Close(pFile);
	}
	return true;
}
Пример #5
0
MF_API bool MFAsset_ConvertTextureFromFile(const char *pFilename, void **ppOutput, size_t *pSize, MFPlatform platform, uint32 flags, MFImageFormat targetFormat, size_t extraBytes)
{
	// should this request be forewarded to the file server, or should we do it locally?
	//... todo

	if(!MFIntAsset_ConvertTextureFromFile(pFilename, ppOutput, pSize, platform, flags, targetFormat, extraBytes))
		return false;

	MFFile *pFile = MFFileSystem_Open(MFStr("cache:%s.tex", pFilename), MFOF_Write | MFOF_Binary);
	if(pFile)
	{
		MFFile_Write(pFile, *ppOutput, *pSize, false);
		MFFile_Close(pFile);
	}
	return true;
}
Пример #6
0
uLong zwrite_file_func(voidpf opaque, voidpf stream, const void* buf, uLong size)
{
	return MFFile_Write((MFFile*)stream, buf, size, false);
}
Пример #7
0
MF_API size_t MFFile_StdWrite(const void *pBuffer, size_t size, size_t count, void* fileHandle)
{
	return MFFile_Write((MFFile*)fileHandle, pBuffer, size*count, false);
}
Пример #8
0
MF_API MFModel* MFModel_Create(const char *pFilename)
{
	const char* pOriginalFilename = pFilename;

	// see if it's already loaded
	MFModelPool::Iterator it = gModelBank.Get(pOriginalFilename);
	MFModelTemplate *pTemplate = it ? *it : NULL;

	if(!pTemplate)
	{
		char *pTemplateData = NULL;

		MFFile *hFile = MFFileSystem_Open(MFStr("%s.mdl", pFilename), MFOF_Read|MFOF_Binary);
		if(hFile)
		{
			int64 size = MFFile_GetSize(hFile);

			if(size > 0)
			{
				// allocate memory and load file
				pTemplateData = (char*)MFHeap_Alloc((size_t)size + MFString_Length(pFilename) + 1);
				MFFile_Read(hFile, pTemplateData, (size_t)size);
				MFFile_Close(hFile);

				MFString_Copy(&pTemplateData[size], pFilename);
				pFilename = &pTemplateData[size];
			}
		}
		else
		{
#if defined(ALLOW_LOAD_FROM_SOURCE_DATA)
			// try to load from source data
			const char * const pExt[] = { ".f3d", ".dae", ".x", ".ase", ".obj", ".md2", ".md3", ".me2", NULL };
			const char * const *ppExt = pExt;
			MFIntModel *pIM = NULL;
			while(!pIM && *ppExt)
			{
				MFString tempFilename = MFString::Format("%s%s", pFilename, *ppExt);
				pIM = MFIntModel_CreateFromFile(tempFilename.CStr());
				if(pIM)
				{
					pFilename = MFString_Copy((char*)MFHeap_Alloc(tempFilename.NumBytes()+1), tempFilename.CStr());
					break;
				}
				++ppExt;
			}

			if(pIM)
			{
				MFIntModel_Optimise(pIM);

				size_t size;
				MFIntModel_CreateRuntimeData(pIM, (void**)&pTemplateData, &size, MFSystem_GetCurrentPlatform());

				MFFile *pFile = MFFileSystem_Open(MFStr("cache:%s.mdl", pOriginalFilename), MFOF_Write | MFOF_Binary);
				if(pFile)
				{
					MFFile_Write(pFile, pTemplateData, size, false);
					MFFile_Close(pFile);
				}

				MFIntModel_Destroy(pIM);
			}
#endif
		}

		if(!pTemplateData)
			return NULL;

		// check ID string
		MFDebug_Assert(*(uint32*)pTemplateData == MFMAKEFOURCC('M', 'D', 'L', '2'), "Incorrect MFModel version.");

		// store filename for later reference
		pTemplate = (MFModelTemplate*)pTemplateData;
		pTemplate->pFilename = pFilename;

		gModelBank.Add(pOriginalFilename, pTemplate);

		MFModel_FixUp(pTemplate, true);

		MFModelDataChunk *pChunk = MFModel_GetDataChunk(pTemplate, MFChunkType_SubObjects);

		if(pChunk)
		{
			MFModelSubObject *pSubobjects = (MFModelSubObject*)pChunk->pData;

			for(int a=0; a<pChunk->count; a++)
			{
//				pSubobjects[a].pMaterial = MFMaterial_Create((char*)pSubobjects[a].pMaterial);

				for(int b=0; b<pSubobjects[a].numMeshChunks; b++)
				{
					MFModel_CreateMeshChunk(MFModel_GetMeshChunkInternal(pTemplate, a, b));
				}
			}
		}
	}

	MFModel *pModel;
	pModel = (MFModel*)MFHeap_Alloc(sizeof(MFModel));

	pModel->worldMatrix = MFMatrix::identity;
	pModel->modelColour = MFVector::one;
	pModel->pTemplate = pTemplate;
	pModel->pAnimation = NULL;

	++pTemplate->refCount;

	return pModel;
}