Пример #1
0
//simple hacked together load function, assumes file exists and mesh is initialized to default
void WarlockeryModelLoader::LoadWarlockeryModelFileToMesh(const std::string& fileName, Mesh* mesh, bool useCommonFilePath){
	const std::string WarlockeryModelExt = ".c23";
	std::string fullModelPath = fileName + WarlockeryModelExt;

	if (useCommonFilePath)
		fullModelPath = COMMON_MODEL_FILE_PATH + fileName + "/" + fileName + WarlockeryModelExt;

	BinaryFileParser WarlockeryModelParser = BinaryFileParser(fullModelPath);

	m_fileHeader.ReadFileHeader(WarlockeryModelParser);

	if (VerifyWarlockeryModelFile(&m_fileHeader)){
		//read num vertices
		//mesh = new Mesh();
		mesh->m_numVerticesToDraw = WarlockeryModelParser.ReadNextUInt();
		
		//read to vertex 3Ds
		Vertex3Ds meshVerts;
		meshVerts.clear();
		meshVerts.reserve(mesh->m_numVerticesToDraw * sizeof(Vertex3D));

		for (unsigned int i = 0; i < mesh->m_numVerticesToDraw; i++){
			meshVerts.push_back(WarlockeryModelParser.ReadNextVertex3D());
		}

		mesh->CopyMeshVertexData(meshVerts);

		//bind indices
		mesh->m_numIndicesToDraw = WarlockeryModelParser.ReadNextUInt();

		//DEBUG temporarily test lighting with vertex arrays
		mesh->m_numIndicesToDraw = 0;

		std::vector<unsigned int> meshIndices;
		meshIndices.clear();
		meshIndices.reserve(mesh->m_numIndicesToDraw * sizeof(unsigned int));

	

		if (mesh->m_numIndicesToDraw > 0){
			for (unsigned int i = 0; i < mesh->m_numIndicesToDraw; i++){
				meshIndices.push_back(WarlockeryModelParser.ReadNextUInt());
			}

			mesh->CopyMeshIndexData(meshIndices);
		}
		else{
			mesh->m_numIndicesToDraw = 0;
		}

	

	}
}