Esempio n. 1
0
void MD5_ReadJoints(md5_bone_t* bones, ushort numBones)
{
	md5_bone_t* bone = 0;
	int i=0;
	
	LE_readToken(); // {
	
	bone = bones;
	for(i=0; i < numBones; i++,bone++)
	{
		
		
		LE_readToken();

		strcpy(bone->name, LE_getCurrentToken());
		
				
		bone->parent = LE_readReal();
		bone->position[0] = LE_readReal();
		bone->position[1] = LE_readReal();
		bone->position[2] = LE_readReal();
		bone->orientation[0] = LE_readReal();
		bone->orientation[1] = LE_readReal();
		bone->orientation[2] = LE_readReal();
		Quat_computeW (bone->orientation);
	}
	
	
	LE_readToken(); // }
}
Esempio n. 2
0
camera_frame_t* CAM_ReadFrameFromFile(void)
{
	camera_frame_t* frame ;
	matrix3x3_t rotMatrix;
	int i;
	
	frame = calloc(1,sizeof(camera_frame_t));
	
	
	LE_readToken(); //time
	frame->time = LE_readReal();
	
	frame->position[0] = LE_readReal();
	frame->position[1] = LE_readReal();
	frame->position[2] = LE_readReal();
	
	LE_readToken(); //q or m
	if (!strcmp("q", LE_getCurrentToken()))
	{
		for( i=0; i < 4 ; i++)
		frame->orientation[i]= LE_readReal();
	}
	else if (!strcmp("m", LE_getCurrentToken()))
	{
		for( i=0; i < 9 ; i++)
			rotMatrix[i] = LE_readReal();
		
		Quat_CreateFromMat3x3(rotMatrix,frame->orientation);
		
	}
	
	return frame;
}
Esempio n. 3
0
void CAM_StartPlaying(char* filename)
{
	uint i;	
	filehandle_t* file ;
	uchar isCP1 = 0;
	
	file = FS_OpenFile(filename, "rt");
	
	if (!file)
		return;
	
	isCP1 = (*file->ptrStart == 'c' && *(file->ptrStart+1) == 'p' && *(file->ptrStart+2) == '1') ;
	
	if (!isCP1)
	{
		printf("Camera path is not a valid file:");
		return;
	}
	
	LE_init(file);
	
	LE_readToken(); //CP1
	LE_readToken(); //num_frames
	
	
	
	camera.path.num_frames = LE_readReal();
	
	camera.path.frames = CAM_ReadFrameFromFile();
	camera.path.frames->next = 0;
	camera.path.currentFrame = camera.path.frames;
	
	for(i=1 ; i < camera.path.num_frames ; i++)
	{
		camera.path.currentFrame->next = CAM_ReadFrameFromFile();
		camera.path.currentFrame = camera.path.currentFrame->next;
		camera.path.currentFrame->next = 0;
	}
							  
	camera.playing = 1;
	camera.path.currentFrame = camera.path.frames;
	strcpy(camera.recordFilename, filename);
	simulationTime = camera.path.frames[0].time;
	
	FS_CloseFile(file);
}
Esempio n. 4
0
void dEngine_ReadConfig(void)
{
	filehandle_t* config;
	int currentSceneId=0;
	
    
    
	config = FS_OpenFile(CONFIG_PATH, "rt");
	FS_UploadToRAM(config);
	
	if (!config)
	{
		Log_Printf("Configuration file: data/config.cfg not found");
		exit(0);
	}
	
	//renderer.resolution = 1;

	LE_pushLexer();
	LE_init(config);
	
	while (LE_hasMoreData()) 
	{
		LE_readToken();

		if (!strcmp("scenes", LE_getCurrentToken()))
		{
			LE_readToken(); // {
			LE_readToken(); // numScenes
			while (LE_hasMoreData() && strcmp("}", LE_getCurrentToken()))
			{
				if (!strcmp("numScenes", LE_getCurrentToken()))
				{
					engine.numScenes = LE_readReal();
				}
				else 
				if (!strcmp("scene", LE_getCurrentToken()))
				{
					currentSceneId = LE_readReal();
					
					LE_readToken(); //The name of the scene, here only to help developer to keep track of config.cfg
					strReplace(LE_getCurrentToken(), '_', ' ');
					strcpy(engine.scenes[currentSceneId].name, LE_getCurrentToken());
					
					LE_readToken();
					strcpy(engine.scenes[currentSceneId].path, LE_getCurrentToken());
					
					Log_Printf("Read scene %d, name %s, path %s\n",currentSceneId,engine.scenes[currentSceneId].name,engine.scenes[currentSceneId].path);
					
					
				}
				
				LE_readToken();
				
			}
		}
		else if (!strcmp("fx", LE_getCurrentToken()))
		{
			LE_readToken(); //{
			while (LE_hasMoreData() && strcmp("}", LE_getCurrentToken()))
			{
				LE_readToken();
				
				if (!strcmp("impactTextureName", LE_getCurrentToken()))
				{
					LE_readToken();
	//			explosionTexture.path = calloc(strlen(LE_getCurrentToken())+1, sizeof(char));
					strcpy(explosionTexture.path, LE_getCurrentToken());
				}
				else 
				if (!strcmp("smokeTextureName", LE_getCurrentToken()))
				{
					LE_readToken();
	//				smokeTexture.path = calloc(strlen(LE_getCurrentToken())+1, sizeof(char));
					strcpy(smokeTexture.path, LE_getCurrentToken());
				}
				else 
				if (!strcmp("ghostTextureName", LE_getCurrentToken()))
				{
					LE_readToken();
	//				ghostTexture.path = calloc(strlen(LE_getCurrentToken())+1, sizeof(char));
					strcpy(ghostTexture.path, LE_getCurrentToken());
				}
			}
		}
		/*
		else if (!strcmp("video", LE_getCurrentToken()))
		{
			
			LE_readToken(); // {
			LE_readToken();
			while (strcmp("}", LE_getCurrentToken()))
			{
				if (!strcmp("record", LE_getCurrentToken()))
				{
					engine.recordVideo = LE_readReal();
				}
				LE_readToken();
			}
		}
		*/
		else if (!strcmp("players", LE_getCurrentToken()))
		{
			LE_readToken();	//{
			LE_readToken();
			while (LE_hasMoreData() && strcmp("}", LE_getCurrentToken()))
			{
				if (!strcmp("model1", LE_getCurrentToken()))
				{
					LE_readToken();
					strcpy(players[1].modelPath, LE_getCurrentToken());
				}
				else 
				if (!strcmp("model0", LE_getCurrentToken()))
				{
					LE_readToken();
					strcpy(players[0].modelPath, LE_getCurrentToken());
				}
				else 
					if (!strcmp("bulletTextureName", LE_getCurrentToken()))
				{
					LE_readToken();
//					bulletConfig.bulletTexture.path = calloc(strlen(LE_getCurrentToken())+1, sizeof(char));
					strcpy(bulletConfig.bulletTexture.path, LE_getCurrentToken());
				}
				else 
				if (!strcmp("ttl", LE_getCurrentToken()))
				{
					bulletConfig.ttl = LE_readReal();
				}
				else 
				if (!strcmp("heightRatio", LE_getCurrentToken()))
				{
					bulletConfig.heightRatio = LE_readReal();
				}
				else 
				if (!strcmp("widthRatio", LE_getCurrentToken()))
				{
					bulletConfig.widthRatio = LE_readReal();
				}
				else 
				if (!strcmp("screenSpaceXDeltaRatio", LE_getCurrentToken()))
				{
					bulletConfig.screenSpaceXDeltaRatio = LE_readReal();
				}
				else 
				if (!strcmp("screenSpaceYDeltaRatio", LE_getCurrentToken()))
				{
					bulletConfig.screenSpaceYDeltaRatio = LE_readReal();
				}
				else 
				if (!strcmp("flashHeightRatio", LE_getCurrentToken()))
				{
					bulletConfig.flashHeightRatio = LE_readReal();
				}
				else 
				if (!strcmp("flashWidthRatio", LE_getCurrentToken()))
				{
					bulletConfig.flashWidthRatio = LE_readReal();
				}
				else 
				if (!strcmp("flashScreenSpaceXDeltaRatio", LE_getCurrentToken()))
				{
					bulletConfig.flashScreenSpaceXDeltaRatio = LE_readReal();
				}
				else 
				if (!strcmp("flashScreenSpaceYDeltaRatio", LE_getCurrentToken()))
				{
					bulletConfig.flashScreenSpaceYDeltaRatio = LE_readReal();
				}
				
				LE_readToken();
			}
			
		}
		
	}
	
	
	LE_popLexer();
	FS_CloseFile(config);
	
	
}
Esempio n. 5
0
char OBJ_Load(char* filename,entity_t* entity)
{
	static vec3_t tmpVertices[DE_USHRT_MAX];
	ushort num_vertices=0;
	
	static vec2_t tmpTextureCoor[DE_USHRT_MAX];
	ushort num_textuCoor=0;
	
	int idata[9];	
	int i;
	
	ushort indiceOfCurrentVertex;
	
	filehandle_t* objFile ;
	
	obj_t* obj;
	
	
	
	
	objFile = FS_OpenFile(filename, "rt");
	
	if (!objFile)
	{
		printf("Could not Load OBJ: '%s'.\n",filename);
		return 0;
	}
	
	
		
	OBJ_InitVerticeCache();
	
	obj = (obj_t*)entity->model;
	obj->vertices = (obj_vertex_t*)calloc(DE_USHRT_MAX, sizeof(obj_vertex_t));
	obj->num_vertices = 0;
	obj->indices = (ushort*)calloc(DE_USHRT_MAX, sizeof(ushort));
	obj->num_indices = 0;
	
	LE_pushLexer();
	
	LE_init(objFile);
	
	while (LE_hasMoreData()) 
	{
		LE_readToken();
		
		if (!strcmp("v",LE_getCurrentToken()))
		{
			tmpVertices[num_vertices][0] = LE_readReal();
			tmpVertices[num_vertices][1] = LE_readReal();
			tmpVertices[num_vertices][2] = LE_readReal();
			num_vertices++;
			
		}
		else
		if (!strcmp("vt",LE_getCurrentToken()))
		{
			tmpTextureCoor[num_textuCoor][0] = LE_readReal();
			tmpTextureCoor[num_textuCoor][1] = 1- LE_readReal();
			num_textuCoor++;
		}
		else
		if (!strcmp("vn",LE_getCurrentToken()))
		{
			for(i=0;i<3;i++)
				LE_readReal();
			
			//Drop it (like it's hot)
		}
		else
		if (!strcmp("f",LE_getCurrentToken()))
		{
			LE_SetWhiteCharValue('/', 1);
			
			for(i=0;i<9;i++)
			{
				idata[i] = LE_readReal();
				idata[i]--;
			}
			
			#ifdef OBJ_FACE_CCW
			for(i=0;i<3;i++)//OBJ Standard: Couter-clockwise
			#else
			for(i=2;i>=0;i--) //Bugged expoter.
			#endif			
			{
				indiceOfCurrentVertex = GetCacheVertex(idata[3*i],tmpTextureCoor[idata[3*i+1]]);
				//indiceOfCurrentVertex = obj->num_indices;
				
				if (indiceOfCurrentVertex+1 > obj->num_vertices)
					obj->num_vertices = indiceOfCurrentVertex+1;
				
				vectorCopy (tmpVertices[idata[3*i]]		, obj->vertices[indiceOfCurrentVertex].position);
				//for(i=0;i<3;i++)
				//{
				//		printf("Vertices: %d, %d, %d.\n",obj->vertices[indiceOfCurrentVertex].position[0],obj->vertices[indiceOfCurrentVertex].position[1],obj->vertices[indiceOfCurrentVertex].position[2]);
				//}
				vector2Copy(tmpTextureCoor[idata[3*i+1]], obj->vertices[indiceOfCurrentVertex].textCoo);
				
				//printf("num_indices = %d, indice pointer=%d\n",obj->num_indices,indiceOfCurrentVertex);
				obj->indices[obj->num_indices++] = indiceOfCurrentVertex ;
				
			}
			
			LE_SetWhiteCharValue('/', 0);
		}
		else
		if (!strcmp("usemtl",LE_getCurrentToken()))
		{
			LE_readToken();
			entity->material = MATLIB_Get(LE_getCurrentToken());
			if (entity->material == 0)
				printf("************[OBJ Loader] Could not find material: '%s'\n",LE_getCurrentToken());
			
		}
	}
	
	
	LE_popLexer();
	
	FS_CloseFile(objFile);
	
	//Adjust size of vertices and indices
	obj->vertices = realloc(obj->vertices,obj->num_vertices  * sizeof(obj_vertex_t));
	obj->indices  = realloc(obj->indices ,obj->num_indices   * sizeof(ushort));
	
	//printf("Obj %s has %d vertices.\n",filename,obj->num_vertices);
	//printf("Obj %s has %d indices.\n",filename,obj->num_indices);
	
	OBJ_DestroyVerticeCache();
	
	//Generate lighting infos.
	OBJ_GenerateLightingInfo(obj);
	
	return 1;
}
Esempio n. 6
0
char MD5_LoadMesh(md5_mesh_t* mesh, const char* filename)
{
	filehandle_t* fhandle = 0;
	vertex_t* currentVertex = 0;
	ushort verticesCounter=0;
	int versionNumber = 0;
	int i;
	
	 
	
	fhandle = FS_OpenFile(filename, "rt");
	
	if (!fhandle)
	{
		return 0;
	}
	
	LE_pushLexer();
	LE_init(fhandle);
	
	
	mesh->memLocation = MD5_MEMLOC_RAM;
	
	//printf("[MD5_LoadEntity] Loading MD5 '%s' .\n",filename); 

	
	
	while (LE_hasMoreData()) 
	{
		LE_readToken();
		
		if(!strcmp("MD5Version", LE_getCurrentToken()))
		{
			versionNumber = LE_readReal();
			if (versionNumber != 10)
			{
				printf ("[MD5_Loader ERROR] : %s has a bad model version (%d)\n",filename,versionNumber);
				return 0;
			}
		}
		else
		if (!strcmp("numJoints", LE_getCurrentToken()))
		{
			mesh->numBones = LE_readReal();
			mesh->bones = (md5_bone_t*)calloc(mesh->numBones,sizeof(md5_bone_t));
			//printf("[MD5_LoadEntity] Found numJoints: %d.\n",mesh->numBones);
		}
		else
		if (!strcmp("mesh", LE_getCurrentToken()))
		{
			//printf("[MD5_LoadEntity] Found mesh.\n");
			MD5_ReadMesh(mesh);  
		}
		else
		if (!strcmp("numMeshes", LE_getCurrentToken()))
		{
			//printf("[MD5_LoadEntity] Found numMeshes.\n");
			if(LE_readReal() > 1)
			{
				printf("[MD5_Loader ERROR] %s has more than one mesh: Not supported.\n",filename);
				return 0;
			}
		}		   
		else
		if (!strcmp("joints", LE_getCurrentToken()))
		{
			//printf("[MD5_LoadEntity] Found joints.\n");
			MD5_ReadJoints(mesh->bones,mesh->numBones);
		}		   
		   
	}
	

	
	mesh->vertexArray = (vertex_t*)calloc(mesh->numVertices, sizeof(vertex_t));
	mesh->indices = (ushort*)calloc(mesh->numTriangles * 3,sizeof(ushort));
	
	//Write indices
	mesh->numIndices=0 ;
	for (i = 0  ; i < mesh->numTriangles; i++)
	{
		mesh->indices[mesh->numIndices++] = mesh->triangles[i].index[0];
		mesh->indices[mesh->numIndices++] = mesh->triangles[i].index[1];
		mesh->indices[mesh->numIndices++] = mesh->triangles[i].index[2];
	}
	
	//Write textureCoo
	//Set all textures coordinate once for all, this will never change
	currentVertex = mesh->vertexArray;
	for(verticesCounter=0 ; verticesCounter < mesh->numVertices ; verticesCounter++,currentVertex++)
	{
		currentVertex->text[0] = mesh->vertices[verticesCounter].st[0];
		currentVertex->text[1] = mesh->vertices[verticesCounter].st[1];
	}
	
	//printf("[MD5 Loader] %d vertices.\n",mesh->numVertices);
	//printf("[MD5 Loader] %d triangles.\n",mesh->numTriangles);
	//printf("[MD5 Loader] %d indices.\n",mesh->numIndices);
	
	
	
	MD5_GenerateSkin(mesh,mesh->bones);
	MD5_GenerateLightingInfo(mesh);
	MD5_GenerateSkin(mesh,mesh->bones);
	
	//Bounding box
	MD5_GenerateModelSpaceBBox(mesh);
	
	if (TRACE_BLOCK)
	{
	if (!strcmp(filename,"data/models/misc/FRA200L.obj.md5mesh"))
	{
		currentVertex = mesh->vertexArray;
		printf("Listing Vertices.\n");
		for (i=0; i < mesh->numVertices ; i++,currentVertex++) 
		{
			printf("vertex: %d/%hu  (norm: %hd , %hd , %hd ) (text: %hd , %hd ) (pos: %f , %f , %f )\n",
				   i,
				   mesh->numVertices-1,   
				   currentVertex->normal[0],
				   currentVertex->normal[1],
				   currentVertex->normal[2],
				   currentVertex->text[0],
				   currentVertex->text[1],
				   currentVertex->pos[0],
				   currentVertex->pos[1],
				   currentVertex->pos[2]	   
				   );
		}


		printf("Listing indices.\n");
		for(i=0;  i < mesh->numIndices ; i++)
		{
			printf("indice: %d/%hu, vertex: %hu   (norm: %hd , %hd , %hd ) (text: %hd , %hd ) (pos: %f , %f , %f )\n",
				   i,
				   mesh->numIndices-1,   
					mesh->indices[i],
				   mesh->vertexArray[mesh->indices[i]].normal[0],
				   mesh->vertexArray[mesh->indices[i]].normal[1],
				   mesh->vertexArray[mesh->indices[i]].normal[2],
				   mesh->vertexArray[mesh->indices[i]].text[0],
				   mesh->vertexArray[mesh->indices[i]].text[1],
				   mesh->vertexArray[mesh->indices[i]].pos[0],
				   mesh->vertexArray[mesh->indices[i]].pos[1],
				   mesh->vertexArray[mesh->indices[i]].pos[2]	 
				   );
		}
	}
	}

	FS_CloseFile(fhandle);
	LE_popLexer();
	
	
	//Cache mesh to speed up future loading.
	
	return 1;
}
Esempio n. 7
0
void MD5_ReadMesh(md5_mesh_t* mesh)
{
	int j ;
	md5_triangle_t* triangle;
	md5_vertex_t* vertex;
	md5_weight_t* weight;

	
	
	LE_readToken(); // {
	
	while (strcmp("}", LE_getCurrentToken())) 
	{
		LE_readToken();
		
		if (!strcmp("shader", LE_getCurrentToken()))
		{
			LE_readToken();
			cleanUpDoubleQuotes(LE_getCurrentToken());
			mesh->materialName = calloc(strlen(LE_getCurrentToken()+1), sizeof(char));
			strcpy(mesh->materialName, LE_getCurrentToken());
		}
		else
		if (!strcmp("numverts", LE_getCurrentToken()))
		{
		
			mesh->numVertices = LE_readReal();
			//printf("[MD5_ReadMesh] Found numverts: %d.\n",mesh->numVertices);
			mesh->vertices = (md5_vertex_t*)calloc(mesh->numVertices, sizeof(md5_vertex_t));
			vertex = mesh->vertices;
			for(j=0; j< mesh->numVertices ; j++,vertex++)
			{
				LE_readToken() ; //vert
				LE_readReal();	// id
				vertex->st[0] = LE_readReal() * 32767;
				vertex->st[1] = LE_readReal() * 32767;
				vertex->start = LE_readReal();
				vertex->count = LE_readReal();
				
				//printf("MD5 Read vertex: uv[%hu,%hu] st,count[%d,%d]\n",vertex->st[0],vertex->st[2],vertex->start,vertex->count);
				
			}
			
		}
		else
		if (!strcmp("numtris", LE_getCurrentToken()))
		{
			
			mesh->numTriangles = LE_readReal();
			//printf("[MD5_ReadMesh] Found numtris: %d.\n",mesh->numTriangles);
			
			mesh->triangles = (md5_triangle_t*)calloc(mesh->numTriangles, sizeof(md5_triangle_t));
			triangle = mesh->triangles;
			for(j=0; j< mesh->numTriangles ; j++,triangle++)
			{
				LE_readToken() ; //tri
				LE_readReal();	// id
				triangle->index[0] = LE_readReal();
				triangle->index[1] = LE_readReal();
				triangle->index[2] = LE_readReal();
				
				//printf("MD5 Read tri: [%hu,%hu,%hu]\n",triangle->index[0],triangle->index[1],triangle->index[2]);
			}
		}
		else
		if (!strcmp("numweights", LE_getCurrentToken()))
		{
			
			mesh->numWeights = LE_readReal();
			//printf("[MD5_ReadMesh] Found numweights: %d.\n",mesh->numWeights);
			
			mesh->weights = (md5_weight_t*)calloc(mesh->numWeights, sizeof(md5_weight_t));
			weight = mesh->weights;
			for(j=0;j<mesh->numWeights ; j++,weight++)
			{
				LE_readToken() ; //tri
				LE_readReal();	// id
				weight->boneId = LE_readReal();
				weight->bias = LE_readReal();
				weight->boneSpacePos[0] = LE_readReal();
				weight->boneSpacePos[1] = LE_readReal();
				weight->boneSpacePos[2] = LE_readReal();
				
				//printf("MD5 Read weight: Boneid[%d] f[%.2f]  boneSpace[%.2f,%.2f,%.2f]\n",weight->boneId,weight->bias,weight->boneSpacePos[0],weight->boneSpacePos[1],weight->boneSpacePos[2]);
			}
		}
		
	
	}
	
}