示例#1
0
文件: ZON.cpp 项目: exjam/r3e
	bool ZON::Load(const char* path){
		ScopedPointer<File> fh(FILE_SYS()->OpenFile(path, "rb"));
		if(!fh) return false;

		unsigned int blocks, type, offset;
		fh->Read(blocks);
		for(unsigned int i = 0; i < blocks; ++i){
			fh->Read(type);
			fh->Read(offset);
			long pos = fh->Position();
			switch(type){
				case TEXTURE_LIST:
					fh->Seek(offset);
					ReadTextureList(fh);
					break;
				case TILE_LIST:
					fh->Seek(offset);
					ReadTileList(fh);
					break;
			}

			fh->Seek(pos);
		}

		fh->Close();
		return true;
	}
示例#2
0
文件: ZMO.cpp 项目: exjam/r3e
	bool ZMO::Load(const char* path){
		ScopedPointer<File> fh(FILE_SYS()->OpenFile(path, "rb"));
		if(!fh) return false;

		char VersionHeader[8];
		fh->ReadData(VersionHeader, 8);
		if(strncmp(VersionHeader, "ZMO0002", 7)){
			LOG("Error: '%s' invalid version '%s'", path, VersionHeader);
			fh->Close();
			return false;
		}

		unsigned int channels;
		fh->Read(mFPS);
		fh->Read(mFrameCount);
		fh->Read(channels);

		mChannels.SetSize(channels);
		for(unsigned int i = 0; i < channels; ++i){
			Channel* chan = &mChannels[i];
			fh->Read(chan->mType);
			fh->Read(chan->mBoneID);
			if(chan->mType == CTYPE_POSITION) chan->mData = (char*)new Vector3[mFrameCount];
			else if(chan->mType == CTYPE_ROTATION) chan->mData = (char*)new Quaternion[mFrameCount];
		}

		for(unsigned int i = 0; i < mFrameCount; ++i){
			for(unsigned int j = 0; j < channels; ++j){
				Channel* chan = &mChannels[j];
				if(chan->mType == CTYPE_POSITION){
					Vector3* pos = (Vector3*)chan->mData;
					fh->Read(pos[i].x);
					fh->Read(pos[i].y);
					fh->Read(pos[i].z);
					pos[i] /= 100.0f;
				}else if(chan->mType == CTYPE_ROTATION){
					Quaternion* rot = (Quaternion*)chan->mData;
					fh->Read(rot[i].s);
					fh->Read(rot[i].x);
					fh->Read(rot[i].y);
					fh->Read(rot[i].z);
				}
			}
		}

		LOG("Loaded: '%s' C: %u F: %u", path, mChannels.Size(), mFrameCount);

		fh->Close();
		return true;
	}
示例#3
0
文件: TIL.cpp 项目: exjam/r3e
	bool TIL::Load(const char* path){
		ScopedPointer<File> fh(FILE_SYS()->OpenFile(path, "rb"));
		if(!fh) return false;

		fh->Read(mWidth);
		fh->Read(mHeight);
		for(int x = 0; x < mWidth; ++x){
			for(int y = 0; y < mHeight; ++y){
				fh->Read(mTileMap[x][y].mBrushNumber);
				fh->Read(mTileMap[x][y].mTileIndex);
				fh->Read(mTileMap[x][y].mTileSet);
				fh->Read(mTileMap[x][y].mTileNumber);
			}
		}

		fh->Close();

		return true;
	}
示例#4
0
文件: Texture.hpp 项目: Tycheo/r3e
	virtual bool Load(const char* pathV){
		static bool hasInitIL = false;
		if(!hasInitIL){
			ilInit();
			ilutRenderer(ILUT_OPENGL);
			hasInitIL = true;
		}

		String path = pathV;
		FILE_SYS()->GetFullPath(path);
		ILuint ilTex;
		ilGenImages(1, &ilTex);
		ilBindImage(ilTex);
		if(!ilLoadImage(path)) return false;
		mWidth = ilGetInteger(IL_IMAGE_WIDTH);
		mHeight = ilGetInteger(IL_IMAGE_HEIGHT);
		iluFlipImage();

		mTexID = ilutGLBindTexImage();
		ilDeleteImages(1, &ilTex);

		return true;
	}
示例#5
0
文件: ZSC.hpp 项目: DragoonX6/R3E
		bool Load(const char* path){
			ScopedPointer<File> fh(FILE_SYS()->OpenFile(path, "rb"));
			if(!fh) return false;
			short count, subCount;

			fh->Read(count);
			mMeshList.SetSize(count);
			for(short i = 0; i < count; ++i)
				mMeshList[i].mPath = fh->ReadTerminatedString();

			fh->Read(count);
			mMaterialList.SetSize(count);
			for(short i = 0; i < count; ++i){
				Material* mat = &mMaterialList[i];
				mat->SetTexture(fh->ReadTerminatedString());
				fh->Skip(2);
				fh->Read(mat->mIsAlpha);
				fh->Read(mat->mIs2Side);
				fh->Read(mat->mAlphaTest);
				fh->Read(subCount);
				mat->mAlphaRef = float(subCount) / 256.0f;
				mat->mZTest = fh->Read<short>() != 0;
				mat->mZWrite = fh->Read<short>() != 0;
				fh->Read(mat->mBlendType);
				fh->Read(mat->mSpecular);
				fh->Skip(18);
			}

			fh->Read(count);
			mEffectList.SetSize(count);
			for(short i = 0; i < count; ++i)
				mEffectList[i].mPath = fh->ReadTerminatedString();

			
			fh->Read(count);
			mModelList.SetSize(count);
			for(short i = 0; i < count; ++i){
				Model* model = &mModelList[i];
				fh->Skip(12);
				fh->Read(subCount);
				if(!subCount) continue;

				model->mPartList.SetSize(subCount);
				for(short j = 0; j < subCount; ++j){
					ModelPart* part = &model->mPartList[j];
					part->mBoneID = -1;
					part->mDummyID = -1;

					fh->Read(part->mMesh);
					fh->Read(part->mMaterial);
					
					int transFlags = TRANS_NONE;
					char flag, size;
					Vector3 translate, scale;
					Quaternion rotate;

					fh->Read(flag);
					while(flag){
						fh->Read(size);
						switch(flag){
							case PART_POSITION:
								fh->Read(translate);
								translate /= 100.0f;
								transFlags |= TRANS_TRANSLATE;
								break;
							case PART_ROTATION:
								fh->Read(rotate.s);
								fh->Read(rotate.x);
								fh->Read(rotate.y);
								fh->Read(rotate.z);
								transFlags |= TRANS_ROTATE;
								break;
							case PART_SCALE:
								fh->Read(scale);
								transFlags |= TRANS_SCALE;
								break;
							case PART_BONEINDEX:
								fh->Read(part->mBoneID);
								break;
							case PART_DUMMYINDEX:
								fh->Read(part->mDummyID);
								break;
							default:
								fh->Skip(size);
						};

						fh->Read(flag);
					}

					part->mTransform = Matrix4::IDENTITY;
					if(transFlags & TRANS_ROTATE) part->mTransform = Matrix4::CreateRotation(rotate);
					if(transFlags & TRANS_SCALE) part->mTransform *= Matrix4::CreateScaling(scale);
					if(transFlags & TRANS_TRANSLATE) part->mTransform *= Matrix4::CreateTranslation(translate);
				}

				fh->Read(subCount);
				model->mEffectList.SetSize(subCount);
				for(short j = 0; j < subCount; ++j){
					ModelEffect* effect = &model->mEffectList[j];
					fh->Read(effect->mEffect);
					fh->Read(effect->mType);

					int transFlags = TRANS_NONE;
					char flag, size;
					Vector3 translate, scale;
					Quaternion rotate;

					fh->Read(flag);
					while(flag){
						fh->Read(size);
						switch(flag){
							case EFFECT_POSITION:
								fh->Read(translate);
								transFlags |= TRANS_TRANSLATE;
								break;
							case EFFECT_ROTATION:
								fh->Read(rotate);
								transFlags |= TRANS_ROTATE;
								break;
							case EFFECT_SCALE:
								fh->Read(scale);
								transFlags |= TRANS_SCALE;
								break;
							default:
								fh->Skip(size);
						};

						fh->Read(flag);
					}

					effect->mTransform = Matrix4::IDENTITY;
					if(transFlags & TRANS_ROTATE) effect->mTransform = Matrix4::CreateRotation(rotate);
					if(transFlags & TRANS_SCALE) effect->mTransform = effect->mTransform * Matrix4::CreateScaling(scale);
					if(transFlags & TRANS_TRANSLATE) effect->mTransform = effect->mTransform * Matrix4::CreateTranslation(translate);
				}

				fh->Read(model->mBoundingBox);

				model->mBoundingBox.mMin /= 100.0f;
				model->mBoundingBox.mMax /= 100.0f;
			}

			LOG("Loaded: '%s' Me: %u Ma: %u E: %u Mo: %u", path, mMeshList.Size(), mMaterialList.Size(), mEffectList.Size(), mModelList.Size());

			fh->Close();
			return true;
		}
示例#6
0
文件: STL.cpp 项目: exjam/r3e
	bool STL::Load(const char* path){
		ScopedPointer<File> fh(FILE_SYS()->OpenFile(path, "rb"));
		if(!fh) return false;
		char strBuffer[512];
		unsigned char nullChar = 0;

		fh->ReadPascalString(strBuffer);
		if(strcmp(strBuffer, "NRST01") == 0){
			mType = STL_TEXT;
		}else if(strcmp(strBuffer, "ITST01") == 0){
			mType = STL_TEXT | STL_COMMENT;
		}else if(strcmp(strBuffer, "QEST01") == 0){
			mType = STL_TEXT | STL_COMMENT | STL_QUEST;
		}else{
			LOG("Error: '%s' invalid version '%s'", path, strBuffer);
			fh->Close();
			return false;
		}

		unsigned int entryCount;
		long offset1, offset2;

		fh->Read(entryCount);
		mEntries = new Entry[entryCount];

		for(unsigned int i = 0; i < entryCount; ++i){
			fh->ReadPascalString(strBuffer);
			fh->Skip(4);
			mStrIndex.Add(strBuffer, i);//fh->Read<unsigned int>());
		}

		fh->Skip(4 + 4);

		fh->Read(offset1);
		fh->Seek(offset1);

		//Method below is optimised for buffered file system
		//Also reduces memory allocations for increased speed
		for(unsigned int i = 0; i < entryCount; ++i){
			unsigned int len, totalLen = 0;
			fh->Read(offset2);
			offset1 = fh->Position();
			fh->Seek(offset2);

			Entry* entry = &mEntries[i];
			len = fh->ReadPascalStringLen();
			entry->mOffsets[0] = fh->Position() - offset2;
			fh->Skip(len);

			totalLen = entry->mOffsets[0] + len;
			if(mType & STL_COMMENT){
				len = fh->ReadPascalStringLen();
				fh->WriteData(&nullChar, 1, totalLen + offset2);
				entry->mOffsets[1] = fh->Position() - offset2;
				fh->Skip(len);
				totalLen = len + entry->mOffsets[1];
			}

			if(mType & STL_QUEST){
				len = fh->ReadPascalStringLen();
				fh->WriteData(&nullChar, 1, totalLen + offset2);
				entry->mOffsets[2] = fh->Position() - offset2;
				fh->Skip(len);
				totalLen = len + entry->mOffsets[2];

				len = fh->ReadPascalStringLen();
				fh->WriteData(&nullChar, 1, totalLen + offset2);
				entry->mOffsets[3] = fh->Position() - offset2;
				fh->Skip(len);
				fh->WriteData(&nullChar, 1);

				totalLen = len + entry->mOffsets[3];
			}

			entry->mData = new char[totalLen+1];
			fh->Seek(offset2);
			fh->ReadData(entry->mData, totalLen);
			entry->mData[totalLen] = 0;

			fh->Seek(offset1);
		}

		fh->Close();
		return true;
	}
示例#7
0
文件: ZMD.cpp 项目: exjam/r3e
	bool ZMD::Load(const char* path){
		ScopedPointer<File> fh(FILE_SYS()->OpenFile(path, "rb"));
		if(!fh) return false;

		char VersionHeader[7];
		fh->ReadData(VersionHeader, 7);
		if(strncmp(VersionHeader, "ZMD0003", 7) == 0){
			mVersion = 3;
		}else if(strncmp(VersionHeader, "ZMD0002", 7) == 0){
			mVersion = 2;
		}else{
			LOG("Error: '%s' invalid version '%s'", path, VersionHeader);
			fh->Close();
			return false;
		}

		unsigned int boneCount;
		fh->Read(boneCount);
		mBoneList.SetSize(boneCount);
		for(unsigned int i = 0; i < boneCount; ++i){
			Bone* bone = &mBoneList[i];
			bone->mDummy = false;
			fh->Read(bone->mParentID);
			bone->mName = fh->ReadTerminatedString();
			fh->Read(bone->mTranslate.x);
			fh->Read(bone->mTranslate.y);
			fh->Read(bone->mTranslate.z);

			fh->Read(bone->mRotate.s);
			fh->Read(bone->mRotate.x);
			fh->Read(bone->mRotate.y);
			fh->Read(bone->mRotate.z);
			bone->mTranslate /= 100.0f;

			bone->mTransform = Matrix4::CreateRotation(bone->mRotate);
			bone->mTransform *= Matrix4::CreateTranslation(bone->mTranslate);
		}

		fh->Read(boneCount);
		int offset = mBoneList.Size();
		mBoneList.SetSize(offset + boneCount);
		for(unsigned int i = 0; i < boneCount; ++i){
			Bone* bone = &mBoneList[i + offset];
			bone->mDummy = true;
			bone->mName = fh->ReadTerminatedString();
			fh->Read(bone->mParentID);
			fh->Read(bone->mTranslate);
			bone->mTranslate /= 100.0f;
			bone->mTransform = Matrix4::IDENTITY;
			if(mVersion == 3){
				bone->mTransform = Matrix4::CreateRotation(bone->mRotate);
				fh->Read(bone->mRotate.s);
				fh->Read(bone->mRotate.x);
				fh->Read(bone->mRotate.y);
				fh->Read(bone->mRotate.z);
			}

			bone->mTransform *= Matrix4::CreateTranslation(bone->mTranslate);
		}

		TransformChildren(0);

		LOG("Loaded: '%s' B: %u", path, mBoneList.Size());

		fh->Close();
		return true;
	}