Пример #1
0
bool JSpline::Load(const char *filename, float xscale, float yscale)
{
	JFileSystem *fileSystem = JFileSystem::GetInstance();

	if (fileSystem == NULL) return false;
	if (!fileSystem->OpenFile(filename)) return false;

	int size = fileSystem->GetFileSize();
	char *xmlBuffer = new char[size];
	fileSystem->ReadFile(xmlBuffer, size);

	TiXmlDocument doc;
	doc.Parse(xmlBuffer);

	mCount = 0;

	mMidPoints.clear();
	mPixels.clear();


	TiXmlNode* node = 0;
	//TiXmlElement* todoElement = 0;
	TiXmlElement* element;

	node = doc.RootElement();

	float xx, yy;

	for(element = node->FirstChildElement(); element; element = element->NextSiblingElement())
	{
		xx = 0.0f;
		yy = 0.0f;
		element->QueryFloatAttribute("x", &xx);
		element->QueryFloatAttribute("y", &yy);

		Point pt(xx*xscale, yy*yscale);
		AddControlPoint(pt);
		
	}

	fileSystem->CloseFile();
	delete[] xmlBuffer;

	return true;
}
Пример #2
0
bool JResourceManager::LoadResource(const string& resourceName)
{
	string path = /*mResourceRoot + */resourceName;

//	TiXmlDocument doc(path.c_str());
//	
//	if (!doc.LoadFile()) return false;
	
	JGE *engine = JGE::GetInstance();
	if (engine == NULL) return false;

	JFileSystem *fileSystem = JFileSystem::GetInstance();
	if (fileSystem == NULL) return false;

	if (!fileSystem->OpenFile(path.c_str())) return false;

	int size = fileSystem->GetFileSize();
	char *xmlBuffer = new char[size];
	fileSystem->ReadFile(xmlBuffer, size);

	TiXmlDocument doc;
	doc.Parse(xmlBuffer);

	TiXmlNode* resource = 0;
	TiXmlNode* node = 0;
	TiXmlElement* element = 0;

	resource = doc.FirstChild("resource"); 
	if (resource)
	{
		element = resource->ToElement();
		printf("---- Loading %s:%s\n", element->Value(), element->Attribute("name"));

		for (node = resource->FirstChild(); node; node = node->NextSibling())
		{
			element = node->ToElement();
			if (element != NULL)
			{
				if (strcmp(element->Value(), "texture")==0)
				{
					CreateTexture(element->Attribute("name"));
				}
				else if (strcmp(element->Value(), "quad")==0)
				{
					string quadName = element->Attribute("name");
					string textureName = element->Attribute("texture");
					float x = 0.0f;
					float y = 0.0f;
					float width = 16.0f;
					float height = 16.0f;
					float value;
					float hotspotX = 0.0f;
					float hotspotY = 0.0f;
					
					if (element->QueryFloatAttribute("x", &value) == TIXML_SUCCESS)
						x = value;
					
					if (element->QueryFloatAttribute("y", &value) == TIXML_SUCCESS)
						y = value;

					if (element->QueryFloatAttribute("width", &value) == TIXML_SUCCESS)
						width = value;

					if (element->QueryFloatAttribute("height", &value) == TIXML_SUCCESS)
						height = value;

					if (element->QueryFloatAttribute("w", &value) == TIXML_SUCCESS)
						width = value;

					if (element->QueryFloatAttribute("h", &value) == TIXML_SUCCESS)
						height = value;

					if (element->QueryFloatAttribute("hotspot.x", &value) == TIXML_SUCCESS)
						hotspotX = value;
					else
						hotspotX = width/2;

					if (element->QueryFloatAttribute("hotspot.y", &value) == TIXML_SUCCESS)
						hotspotY = value;
					else
						hotspotY = height/2;

// 					if (element->QueryFloatAttribute("regx", &value) == TIXML_SUCCESS)
// 						hotspotX = width/2;
// 
// 					if (element->QueryFloatAttribute("regy", &value) == TIXML_SUCCESS)
// 						hotspotY = height/2;
				
					int id = CreateQuad(quadName, textureName, x, y, width, height);
					if (id != INVALID_ID)
					{
						GetQuad(id)->SetHotSpot(hotspotX, hotspotY);
					}
				}
				else if (strcmp(element->Value(), "font")==0)
				{
				}
				else if (strcmp(element->Value(), "music")==0)
				{
					LoadMusic(element->Attribute("name"));
				}
				else if (strcmp(element->Value(), "sample")==0)
				{
					LoadSample(element->Attribute("name"));
				}
// 				else if (strcmp(element->Value(), "effect")==0)
// 				{
// 					RegisterParticleEffect(element->Attribute("name"));
// 				}
// 				else if (strcmp(element->Value(), "motion_emitter")==0)
// 				{
// 					RegisterMotionEmitter(element->Attribute("name"));
// 				}
			}
		}
		
	}
	
	fileSystem->CloseFile();
	delete[] xmlBuffer;
//	JGERelease();

	return true;
}
Пример #3
0
bool JGBKFont::Init(const char* engFileName, const char* chnFileName, int fontsize, bool smallEnglishFont)
{
	mSmallEnglishFont = smallEnglishFont;
	mFontSize = fontsize;

	mCacheImageWidth = 256;
	mCacheImageHeight = 256;

	mBytesPerRow = (mFontSize+7)/8;
	mBytesPerChar = mBytesPerRow*mFontSize;

	mCol = mCacheImageWidth/mFontSize;
	mRow = mCacheImageHeight/mFontSize;
	mCacheSize = mCol*mRow;

	mSprites = new JQuad*[mCacheSize];
	mGBCode = new int[mCacheSize];

#if defined (WIN32) || defined (LINUX)
	mCharBuffer = new DWORD[mFontSize*mFontSize];
#endif

	mTexture = mRenderer->CreateTexture(mCacheImageWidth, mCacheImageHeight, true);

	int index = 0;
	for (int y=0;y<mRow;y++)
	{
		for (int x=0;x<mCol;x++)
		{
			mGBCode[index] = -1;

			mSprites[index] = new JQuad(mTexture, 
                                        static_cast<float>(x*mFontSize),
                                        static_cast<float>(y*mFontSize),
                                        static_cast<float>(mFontSize),
                                        static_cast<float>(mFontSize));
			mSprites[index]->SetHotSpot(static_cast<float>(mFontSize/2), static_cast<float>(mFontSize/2));

			index++;
		}
	}

	int size;

	JFileSystem *fileSys = JFileSystem::GetInstance();
	if (!fileSys->OpenFile(engFileName))
		return false;

	size = fileSys->GetFileSize();
	mEngFont = new BYTE[size];

	fileSys->ReadFile(mEngFont, size);
	fileSys->CloseFile();


	if (!fileSys->OpenFile(chnFileName))
		return false;

	size = fileSys->GetFileSize();

	mChnFont = new BYTE[size];

	fileSys->ReadFile(mChnFont, size);
	fileSys->CloseFile();

	return true;
}
Пример #4
0
bool JParticleEffect::Load(const char* filename)
{
	mX = 0.0f;
	mY = 0.0f;

	mEmitterCount = 0;


	JFileSystem *fileSystem = JFileSystem::GetInstance();
	if (fileSystem == NULL) return false;

	if (!fileSystem->OpenFile(filename)) return false;

	int size = fileSystem->GetFileSize();
	char *xmlBuffer = new char[size];
	fileSystem->ReadFile(xmlBuffer, size);

	TiXmlDocument doc;
	
	doc.Parse(xmlBuffer);

	
	TiXmlNode* effect = 0;
	TiXmlNode* emitter = 0;
	TiXmlNode* param = 0;
	TiXmlNode* key = 0;
	
	TiXmlElement* element = 0;

	float keyTime;
	float value;
	float baseValue;
	int int_value;
// 	
// 	enum ParticleField
// 	{
// 		FIELD_SPEED,
// 		FIELD_SIZE,
// 		FIELD_ROTATION,
// 		FIELD_ALPHA,
// 		FIELD_RED,
// 		FIELD_GREEN,
// 		FIELD_BLUE,
// 		FIELD_COUNT
// 	};

	char* lifeValues[] =
	{
		"speed",
		"size",
		"rotation",
		"alpha",
		"red",
		"green",
		"blue",
		"radial_accel",
		"tangential_accel",
		"gravity"
	};

	char* typeNames[] =
	{
		"POINT",
		"AREA",
		"HORIZONTAL",
		"VERTICAL",
		"CIRCLE"
	};

	char* modeNames[] =
	{
		"REPEAT",
		"ONCE",
		"NTIMES",
		"CONTINUOUS"
	};

	int i;
	
	//////////////////////////////////////////////////////////////////////////
	// One effect per file only, well, we may extend it later to permit 
	// multiple effect definitions:
	//
	// for (effect = doc.FirstChild("effect"); effect; effect  = effect->NextSibling())
	// 
	//////////////////////////////////////////////////////////////////////////

	effect = doc.FirstChild("effect"); 
	if (effect)
	{
		element = effect->ToElement();
		printf("%s:%s\n", element->Value(), element->Attribute("name"));


		for (emitter = effect->FirstChild("emitter"); emitter && mEmitterCount < MAX_EMITTER; emitter = emitter->NextSibling())
		{

			mParticleEmitters[mEmitterCount] = new JParticleEmitter(this);
			element = emitter->ToElement();

			if (element->QueryFloatAttribute("life", &value) == TIXML_SUCCESS)
				mParticleEmitters[mEmitterCount]->mLife = value;

			for (param = emitter->FirstChild(); param; param = param->NextSibling())
			{
				element = param->ToElement();
				
				if (strcmp(element->Attribute("name"), "settings")==0)
				{
					
					if (strcmp(element->Attribute("blend"), "NORMAL")==0)
						mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
					else if (strcmp(element->Attribute("blend"), "ADDITIVE")==0)
						mParticleEmitters[mEmitterCount]->SetBlending(BLEND_SRC_ALPHA, BLEND_ONE);
					
					for (i=0;i<sizeof(modeNames)/sizeof(char*);i++)
					{
						if (strcmp(element->Attribute("mode"), modeNames[i])==0)
						{
							mParticleEmitters[mEmitterCount]->mEmitterMode = i;
							#if defined (_DEBUG)
								printf("emitter mode:%s\n", modeNames[i]);
							#endif
							break;
						}
					}
					for (i=0;i<sizeof(typeNames)/sizeof(char*);i++)
					{
						if (strcmp(element->Attribute("type"), typeNames[i])==0)
						{
							mParticleEmitters[mEmitterCount]->mType = i;
							#if defined (_DEBUG)
								printf("emitter type:%s\n", typeNames[i]);
							#endif
							break;
						}
					}

					string quadName = element->Attribute("image");
					JQuad* quad = mResourceManager->GetQuad(quadName);
					if (quad != NULL)
						mParticleEmitters[mEmitterCount]->SetQuad(quad);
					
// 					if (element->QueryIntAttribute("image", &int_value) == TIXML_SUCCESS)
// 					{
// 						mParticleEmitters[mEmitterCount]->mQuadIndex = int_value;
// 
// 					}
					if (element->QueryIntAttribute("width", &int_value) == TIXML_SUCCESS)
					{
						mParticleEmitters[mEmitterCount]->mWidth = int_value;

					}
					if (element->QueryIntAttribute("height", &int_value) == TIXML_SUCCESS)
					{
						mParticleEmitters[mEmitterCount]->mHeight = int_value;

					}

					if (element->QueryIntAttribute("id", &int_value) == TIXML_SUCCESS)
					{
						mParticleEmitters[mEmitterCount]->mId = int_value;

					}

					if (element->QueryIntAttribute("repeat_count", &int_value) == TIXML_SUCCESS)
					{
						mParticleEmitters[mEmitterCount]->mRepeatTimes = int_value;

					}
				}
				else if (strcmp(element->Attribute("name"), "quantity")==0)
				{
					for (key = param->FirstChild(); key; key = key->NextSibling())
					{
						element = key->ToElement();

						if (element->QueryFloatAttribute("timeslice", &keyTime) == TIXML_SUCCESS &&
							element->QueryFloatAttribute("value", &value) == TIXML_SUCCESS)
						{
							mParticleEmitters[mEmitterCount]->mQuantity.AddKey(keyTime, value);
						}
						
					}
				}
				else if (strcmp(element->Attribute("name"), "lifex")==0)
				{
					if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
						element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
					{
						mParticleEmitters[mEmitterCount]->mLifeBase = baseValue;
						mParticleEmitters[mEmitterCount]->mLifeMax= value;	
					}
				}
				else if (strcmp(element->Attribute("name"), "anglex")==0)
				{
					if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
						element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
					{
						mParticleEmitters[mEmitterCount]->mAngleBase = baseValue*DEG2RAD;
						mParticleEmitters[mEmitterCount]->mAngleMax= value*DEG2RAD;	
					}
				}
				else if (strcmp(element->Attribute("name"), "speedx")==0)
				{
					if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
						element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
					{
						mParticleEmitters[mEmitterCount]->mSpeedBase = baseValue;
						mParticleEmitters[mEmitterCount]->mSpeedMax= value;	
					}
				}
				else if (strcmp(element->Attribute("name"), "sizex")==0)
				{
					if (element->QueryFloatAttribute("base", &baseValue) == TIXML_SUCCESS &&
						element->QueryFloatAttribute("max", &value) == TIXML_SUCCESS)
					{
						mParticleEmitters[mEmitterCount]->mSizeBase = baseValue;
						mParticleEmitters[mEmitterCount]->mSizeMax= value;	
					}
				}
				else 
				{
					for (int i=0;i<FIELD_COUNT;i++)
					{
						if (strcmp(element->Attribute("name"), lifeValues[i])==0)
						{
							for (key = param->FirstChild(); key; key = key->NextSibling())
							{
								element = key->ToElement();

								if (element->QueryFloatAttribute("lifeslice", &keyTime) == TIXML_SUCCESS &&
									element->QueryFloatAttribute("value", &value) == TIXML_SUCCESS)
								{
									if (i==FIELD_ROTATION)
										value *= DEG2RAD;
									
									mParticleEmitters[mEmitterCount]->mData[i].AddKey(keyTime, value);
								}

							}
							break;
						}
					}

				}


			}

			mEmitterCount++;
		}
	}

	fileSystem->CloseFile();
	delete[] xmlBuffer;

	return true;
}
Пример #5
0
bool JOBJModel::Load(const char *modelName, const char *textureName)
{

	JFileSystem* fileSys = JFileSystem::GetInstance();
	if (!fileSys->OpenFile(modelName))
		return false;

	int size = fileSys->GetFileSize();
	char *buffer = new char[size];

	fileSys->ReadFile(buffer, size);
	fileSys->CloseFile();

	Vector3D vert;

	vector<Face> faceList;
	vector<Vector3D> normalList;
	vector<Vector3D> texList;
	vector<Vector3D> vertList;

	normalList.reserve(32);
	texList.reserve(32);
	vertList.reserve(32);
	faceList.reserve(32);

	int filePtr = 0;

	char tmpLine[256];
	char s1[256];
	
	int count;

    while (filePtr < size)
    {
		filePtr = ReadLine(tmpLine, buffer, filePtr, size);
        {

			if ((tmpLine[0] == '#') || (strlen(tmpLine)  < 3))
			{
			}
			else if (tmpLine[0] == 'v')
			{
				count = sscanf(tmpLine, "%s  %f %f %f", s1, &vert.x, &vert.y, &vert.z);

				if (count == 4)
				{
					if (strcmp(s1, "vn") == 0)
						normalList.push_back(vert);
					else if (strcmp(s1, "vt") == 0)
						texList.push_back(vert);
					else if (strcmp(s1, "v") == 0)
						vertList.push_back(vert);
				}
				else if (count == 3)
				{
					if (strcmp(s1, "vt") == 0)
						texList.push_back(vert);
				}
	             
			}
			else if (tmpLine[0] == 'f')
			{
				Face face;
				face.mVertCount = 0;

				char *p = strchr(tmpLine, ' ');
				char *pNext = p;

				int vertIdx, texIdx, norIdx;
				
				while (p != NULL)
				{
					while (((*p) == ' ') || ((*p) == '\n') || ((*p) == '\t'))
						++p;
					strcpy(s1, p);
					count = sscanf(s1, "%d/%d/%d", &vertIdx, &texIdx, &norIdx);
					if (count == 3)
					{
						if (face.mVertCount < 4)
						{
							face.mVertIdx[face.mVertCount] = vertIdx - 1;
							face.mTexIdx[face.mVertCount] = texIdx - 1;
							face.mNormalIdx[face.mVertCount] = norIdx - 1;
							face.mVertCount++;
						}
					}
					else if (count == 2)
					{
						if (face.mVertCount < 4)
						{
							face.mVertIdx[face.mVertCount] = vertIdx - 1;
							face.mTexIdx[face.mVertCount] = texIdx - 1;
							face.mNormalIdx[face.mVertCount] = 0;
							face.mVertCount++;
						}
					}
					else if (count == 1)
					{
						if (face.mVertCount < 4)
						{
							face.mVertIdx[face.mVertCount] = vertIdx - 1;
							face.mTexIdx[face.mVertCount] = 0;
							face.mNormalIdx[face.mVertCount] = 0;
							face.mVertCount++;
						}
					}
					
					pNext = strchr(p, ' ');
					p = pNext;
				}
			
				if (face.mVertCount == 3)		// we do triangles only ;)
					faceList.push_back(face);
			}
			else if (tmpLine[0] == 'g')
			{
				
			}
			else if (tmpLine[0] == 'u')
			{
			}

		}
	}

	mPolycount = faceList.size();
	mPolygons = new Vertex3D[mPolycount*3];

	int idx = 0;
	for (int i=0;i<mPolycount;i++)
	{
		
		for (int j=0;j<3;j++)
		{
			mPolygons[idx].u = texList[faceList[i].mTexIdx[j]].x;
			mPolygons[idx].v = 1.0f-texList[faceList[i].mTexIdx[j]].y;
			mPolygons[idx].x = vertList[faceList[i].mVertIdx[j]].x;
			mPolygons[idx].y = vertList[faceList[i].mVertIdx[j]].y;
			mPolygons[idx].z = vertList[faceList[i].mVertIdx[j]].z;
			idx++;
		}
		
		/*
		mPolygons[idx].u = texList[faceList[i].mTexIdx[0]].x;
		mPolygons[idx].v = 1.0-texList[faceList[i].mTexIdx[0]].y;
		mPolygons[idx].x = vertList[faceList[i].mVertIdx[0]].x;
		mPolygons[idx].y = vertList[faceList[i].mVertIdx[0]].y;
		mPolygons[idx].z = vertList[faceList[i].mVertIdx[0]].z;
		idx++;
		mPolygons[idx].u = texList[faceList[i].mTexIdx[1]].x;
		mPolygons[idx].v = 1.0-texList[faceList[i].mTexIdx[1]].y;
		mPolygons[idx].x = vertList[faceList[i].mVertIdx[1]].x;
		mPolygons[idx].y = vertList[faceList[i].mVertIdx[1]].y;
		mPolygons[idx].z = vertList[faceList[i].mVertIdx[1]].z;
		idx++;
		mPolygons[idx].u = texList[faceList[i].mTexIdx[2]].x;
		mPolygons[idx].v = 1.0-texList[faceList[i].mTexIdx[2]].y;
		mPolygons[idx].x = vertList[faceList[i].mVertIdx[2]].x;
		mPolygons[idx].y = vertList[faceList[i].mVertIdx[2]].y;
		mPolygons[idx].z = vertList[faceList[i].mVertIdx[2]].z;
		idx++;
		*/
	}
   

	if (textureName != NULL)
		mTexture = JRenderer::GetInstance()->LoadTexture(textureName);

    return true;

}
Пример #6
0
bool JAnimator::Load(const char* scriptFile)
{

    JFileSystem *fileSystem = JFileSystem::GetInstance();
    if (fileSystem == NULL) return false;

    if (!fileSystem->OpenFile(scriptFile)) return false;

    int size = fileSystem->GetFileSize();
    char *xmlBuffer = new char[size];
    fileSystem->ReadFile(xmlBuffer, size);

    TiXmlDocument doc;
    doc.Parse(xmlBuffer);

    TiXmlNode* script = 0;
    TiXmlNode* frame = 0;
    TiXmlNode* obj = 0;
    TiXmlNode* param = 0;
    TiXmlElement* element = 0;

    float defaultTime = 0.033f;

    script = doc.FirstChild("script");
    if (script)
    {
        element = script->ToElement();
        printf("---- Loading %s:%s\n", element->Value(), element->Attribute("name"));

        char *type[] =
        {
            "ANIMATION_TYPE_LOOPING",
            "ANIMATION_TYPE_ONCE_AND_STAY",
            "ANIMATION_TYPE_ONCE_AND_BACK",
            "ANIMATION_TYPE_ONCE_AND_GONE",
            "ANIMATION_TYPE_PINGPONG"
        };

        const char* aniType = element->Attribute("type");
        for (int i=0; i<5; i++)
            if (strcmp(type[i], aniType)==0)
            {
                SetAnimationType(i);
                break;
            }

        float fps;
        if (element->QueryFloatAttribute("framerate", &fps) != TIXML_SUCCESS)
            fps = 30.0f;

        defaultTime = 1/fps;

        for (frame = script->FirstChild("frame"); frame; frame = frame->NextSibling())
        {
            JAnimatorFrame *aniFrame = new JAnimatorFrame(this);

            float duration;
            element = frame->ToElement();
            if (element->QueryFloatAttribute("time", &duration) != TIXML_SUCCESS)
                duration = defaultTime;
            aniFrame->SetFrameTime(duration);

            for (obj = frame->FirstChild(); obj; obj = obj->NextSibling())
            {
                for (param = obj->FirstChild(); param; param = param->NextSibling())
                {

                    element = param->ToElement();
                    if (element != NULL)
                    {
                        if (strcmp(element->Value(), "settings")==0)
                        {
                            const char* quadName = element->Attribute("quad");
                            JQuad* quad = mResource->GetQuad(quadName);

                            float x, y;
                            float vsize, hsize;
                            float angle;
                            int a, r, g, b;
                            int value;
                            bool flipped = false;

                            if (element->QueryFloatAttribute("x", &x) != TIXML_SUCCESS)
                                x = 0.0f;

                            if (element->QueryFloatAttribute("y", &y) != TIXML_SUCCESS)
                                y = 0.0f;

                            if (element->QueryFloatAttribute("hsize", &hsize) != TIXML_SUCCESS)
                                hsize = 1.0f;

                            if (element->QueryFloatAttribute("vsize", &vsize) != TIXML_SUCCESS)
                                vsize = 1.0f;

                            if (element->QueryFloatAttribute("rotation", &angle) != TIXML_SUCCESS)
                                angle = 0.0f;

                            if (element->QueryIntAttribute("a", &a) != TIXML_SUCCESS)
                                a = 255;

                            if (element->QueryIntAttribute("r", &r) != TIXML_SUCCESS)
                                r = 255;

                            if (element->QueryIntAttribute("g", &g) != TIXML_SUCCESS)
                                g = 255;

                            if (element->QueryIntAttribute("b", &b) != TIXML_SUCCESS)
                                b = 255;

                            if (element->QueryIntAttribute("flip", &value) == TIXML_SUCCESS)
                                flipped = (value==1);


                            JAnimatorObject *object = new JAnimatorObject();
                            object->SetQuad(quad);
                            object->SetPosition(x, y);
                            object->SetHScale(hsize);
                            object->SetVScale(vsize);
                            object->SetRotation(angle);
                            object->SetColor(ARGB(a,r,g,b));
                            object->SetFlip(flipped);

                            aniFrame->AddObject(object);

                        }
                    }
                }

            }

            mFrames.push_back(aniFrame);
        }

    }

    fileSystem->CloseFile();
    delete[] xmlBuffer;

    return true;

}
Пример #7
0
//-------------------------------------------------------------------------------------------------
// loads MD2 model
bool JMD2Model::Load(char *filename, char *textureName)
{

	//FILE *filePtr;						// file pointer
	int fileLen;						// length of model file
    char *buffer;						// file buffer
		
	modelHeader_t *modelHeader;			// model header

	stIndex_t *stPtr;					// texture data
    frame_t *frame;						// frame data
	Vector3D *pointListPtr;				// index variable
    mesh_t *triIndex, *bufIndexPtr;		// index variables
    int i, j;							// index variables

	// open the model file

	JFileSystem* fileSystem = JFileSystem::GetInstance();
	if (!fileSystem->OpenFile(filename))
		return false;
	//filePtr = fopen(filename, "rb");
	//if (filePtr == NULL)
	//	return false;

	// find length of file
    //fseek(filePtr, 0, SEEK_END);
    //fileLen = ftell(filePtr);
    //fseek(filePtr, 0, SEEK_SET);

	fileLen = fileSystem->GetFileSize();
	
    // read entire file into buffer
    buffer = (char*)malloc(fileLen + 1);
    //fread(buffer, sizeof(char), fileLen, filePtr);
	fileSystem->ReadFile(buffer, fileLen);
	fileSystem->CloseFile();

	// extract model file header from buffer
    modelHeader = (modelHeader_t*)buffer;

	// allocate memory for model data
   	mModel = (modelData_t*)malloc(sizeof(modelData_t));
	if (mModel == NULL)
		return false;

	// allocate memory for all vertices used in model, including animations
    mModel->pointList = (Vector3D *)malloc(sizeof(Vector3D)*modelHeader->numXYZ * modelHeader->numFrames);

	// store vital model data
    mModel->numPoints = modelHeader->numXYZ;
    mModel->numFrames = modelHeader->numFrames;
	mModel->frameSize = modelHeader->framesize;

    // loop number of frames in model file
    for(j = 0; j < modelHeader->numFrames; j++)
    {
       // offset to the points in this frame
       frame = (frame_t*)&buffer[modelHeader->offsetFrames + modelHeader->framesize * j];

	   // calculate the point positions based on frame details
       pointListPtr = (Vector3D *)&mModel->pointList[modelHeader->numXYZ * j];
       for(i = 0; i < modelHeader->numXYZ; i++)
       {
          pointListPtr[i].x = frame->scale[0] * frame->fp[i].v[0] + frame->translate[0];
          pointListPtr[i].y = frame->scale[1] * frame->fp[i].v[1] + frame->translate[1];
          pointListPtr[i].z = frame->scale[2] * frame->fp[i].v[2] + frame->translate[2];
       }
    }
			 
	JTexture *tex = mRenderer->LoadTexture(textureName);
	if (tex)
		mModel->modelTex = tex;
	else
	{
		free(mModel);
		mModel = NULL;
		
		free(buffer);
		return false;
	}

	float texWidth = (float)tex->mWidth;
	float texHeight = (float)tex->mHeight;


    // allocate memory for the model texture coordinates
    mModel->st = (texCoord_t*)malloc(sizeof(texCoord_t)*modelHeader->numST);

	// store number of texture coordinates
    mModel->numST = modelHeader->numST;

	// set texture pointer to texture coordinate offset
    stPtr = (stIndex_t*)&buffer[modelHeader->offsetST];

	// calculate and store the texture coordinates for the model
    for (i = 0; i < modelHeader->numST; i++)
    {
		mModel->st[i].s = (float)stPtr[i].s / texWidth;
        mModel->st[i].t = (float)stPtr[i].t / texHeight;
    }

	// allocate an index of triangles
	triIndex = (mesh_t*)malloc(sizeof(mesh_t) * modelHeader->numTris);

	// set total number of triangles
	mModel->numTriangles = modelHeader->numTris;
	mModel->triIndex = triIndex;
	
	// point to triangle indexes in buffer
	bufIndexPtr = (mesh_t*)&buffer[modelHeader->offsetTris];

	// create a mesh (triangle) list
	for (j = 0; j < mModel->numFrames; j++)		
	{
		// for all triangles in each frame
		for(i = 0; i < modelHeader->numTris; i++)
		{
		   triIndex[i].meshIndex[0] = bufIndexPtr[i].meshIndex[0];
		   triIndex[i].meshIndex[1] = bufIndexPtr[i].meshIndex[1];
		   triIndex[i].meshIndex[2] = bufIndexPtr[i].meshIndex[2];
		   triIndex[i].stIndex[0] = bufIndexPtr[i].stIndex[0];
		   triIndex[i].stIndex[1] = bufIndexPtr[i].stIndex[1];
		   triIndex[i].stIndex[2] = bufIndexPtr[i].stIndex[2];
		}
	}

	// close file and free memory
	//fclose(filePtr);
    free(buffer);

	mModel->currentFrame = 0;
	mModel->nextFrame = 1;
	mModel->interpol = 0.0;

	CheckNextState();

    return true;
}