コード例 #1
0
ファイル: rayScene.cpp プロジェクト: nal3vm/RayTracer
void RayScene::ParseJoint(FILE* fp,int& cmndCtr,RayGroup* current){
	char paramName[BUF_SIZE];
	char keyword[BUF_SIZE];

	ParametrizedRayGroup *newNode;
	RayGroup *currNode;
	int i,idx=-1;
	
	currNode=current;
	if(!fscanf(fp," %s ",paramName)){ParseLineError(cmndCtr,"failed to read parameter name\n");}
	for(i=0;i<keyFileNum;i++){
		idx=keyFiles[i].index(paramName);
		if(idx>=0){break;}
	}
	newNode=keyData[i].getParametrizedRayGroup(idx);
	if(!newNode){ParseLineError(cmndCtr,"failed to link joint node to parameter\n");}
	strcpy(newNode->pName,paramName);
	currNode->addShape(newNode);
	currNode=newNode;
	
	while(fscanf(fp," #%s",keyword) == 1){
		cmndCtr++;
		if(strcmp(keyword,"group_begin") == 0){ParseGroup(fp,cmndCtr,currNode);}
		else if(strcmp(keyword,"joint_begin") == 0){ParseJoint(fp,cmndCtr,currNode);}
		else if(!strcmp(keyword,"joint_end")){return;}
		else if(!strcmp(keyword,"group_end")){ParseLineError(cmndCtr,"group_end within a joint\n");}
		else if(ParseShape(fp,keyword,cmndCtr,currNode)){;}
		else {fprintf(stderr,"Ignoring Command %d: No valid #directive...%s \n",cmndCtr,keyword);}
	}
	ParseLineError(cmndCtr,"no group_end\n");
}
コード例 #2
0
ファイル: scene.cpp プロジェクト: TomCN7/BurgerKing
void Scene::ParseJoint(FILE* fp,int& cmndCtr,Group* current,const char* fileName){
	char keyword[BUF_SIZE];
	char parameterName[BUF_SIZE];
	ParametrizedGroup *newNode;
	Group *currNode;
	int i;
	Parameter** tempArray;

	currNode=current;

	newNode=new ParametrizedGroup(fp,parameterName);
	if(newNode==NULL){
		ParseLineError(cmndCtr,fileName,
			"failed to allocate memory for ParametrizedGroup\n");
	}
	for(i=0;i<parameterNum;i++){
		if(strcmp(parameterName,parameters[i]->name)==0){break;}
	}
	if(i==parameterNum){
		parameterNum++;
		tempArray=new Parameter*[parameterNum];
		assert(tempArray);
		for(i=0;i<parameterNum-1;i++){tempArray[i]=parameters[i];}
		tempArray[parameterNum-1]=new Parameter();
		strcpy(tempArray[i]->name,parameterName);
		tempArray[i]->value=newNode->localTransform.defaultParameterValue();
		if(parameterNum>1){delete[] parameters;}
		parameters=tempArray;
		newNode->parameter=parameters[parameterNum-1];
	}
	else{newNode->parameter=parameters[i];}
	currNode->addShape(newNode);
	currNode=newNode;

	while(fscanf(fp," #%s",keyword) == 1){
		cmndCtr++;
		if(strcmp(keyword,"group_begin") == 0){
			ParseGroup(fp,cmndCtr,currNode,fileName);
		}
		else if(strcmp(keyword,"joint_begin") == 0){
			ParseJoint(fp,cmndCtr,currNode,fileName);
		}
    /* We check if we have come to the end of a scene-graph group and we
     * do the appropriate pointer manipulation, making sure that we are not
     * leaving a group we had not begun */
		else if(strcmp(keyword,"joint_end") == 0){return;}
		else if(strcmp(keyword,"group_end")==0){
			ParseLineError(cmndCtr,fileName,"group_end within a joint\n");
		}
		else if(ParseShape(fp,keyword,cmndCtr,currNode,fileName)){;}
		else {
			fprintf(stderr,
				"Ignoring Command %d: No valid #directive...%s \n",cmndCtr,
				keyword);
		}
	}
	ParseLineError(cmndCtr,fileName,"no group_end\n");
}
コード例 #3
0
ファイル: bodymeshldr.cpp プロジェクト: crystalspace/CS
  bool BodyMeshLoader::ParseBone (iDocumentNode* node, iLoaderContext* ldr_context,
				  CS::Animation::iBodySkeleton* skeleton)
  {
    // parse bone name
    const char* name = node->GetAttributeValue ("name");
    if (!name)
    {
      synldr->ReportError (msgid, node, "No name set for bone");
      return false;
    }

    CS::Animation::BoneID id = skeleton->GetSkeletonFactory ()->FindBone (name);
    if (id == CS::Animation::InvalidBoneID)
    {
      synldr->ReportError (msgid, node, "No bone with name %s in skeleton factory",
			   name);
      return false;
    }

    // create body bone
    CS::Animation::iBodyBone* bone = skeleton->CreateBodyBone (id);

    // parse child nodes
    csRef<iDocumentNodeIterator> it = node->GetNodes ();
    while (it->HasNext ())
    {
      csRef<iDocumentNode> child = it->Next ();
      if (child->GetType () != CS_NODE_ELEMENT) continue;
      const char* value = child->GetValue ();
      csStringID id = xmltokens.Request (value);
      switch (id)
      {
      case XMLTOKEN_PROPERTIES:
        if (!ParseProperties (child, bone))
          return false;
        break;

      case XMLTOKEN_COLLIDERS:
        if (!ParseColliders (child, ldr_context, bone))
          return false;
        break;

      case XMLTOKEN_JOINT:
        if (!ParseJoint (child, bone))
          return false;
        break;

      default:
        synldr->ReportBadToken (child);
        return false;
      }
    }

    return true;
  }
コード例 #4
0
ファイル: rayScene.cpp プロジェクト: nal3vm/RayTracer
void RayScene::ParseGroup(FILE* fp,int& cmndCtr,RayGroup* current){
	char keyword[BUF_SIZE];
	RayGroup *currNode,*newNode;
	currNode=current;
	newNode=new StaticRayGroup();
	if(!newNode || !((StaticRayGroup*)newNode)->read(fp)){ParseLineError(cmndCtr,"failed to allocate memory for StaticGroup\n");}
	currNode->addShape(newNode);
	currNode=newNode;
	
	while(fscanf(fp," #%s",keyword) == 1){
		cmndCtr++;
		if(!strcmp(keyword,"group_begin")){ParseGroup(fp,cmndCtr,currNode);}
		else if(!strcmp(keyword,"joint_begin")){ParseJoint(fp,cmndCtr,currNode);}
		
		/* We check if we have come to the end of a scene-graph group and we
		* do the appropriate pointer manipulation, making sure that we are not
		* leaving a group we had not begun */
		else if(!strcmp(keyword,"group_end")){return;}
		else if(!strcmp(keyword,"joint_end")){ParseLineError(cmndCtr,"joint_end within a group\n");}
		else if(ParseShape(fp,keyword,cmndCtr,currNode)){;}
		else {fprintf(stderr,"Ignoring Command %d: No valid #directive...%s \n",cmndCtr,keyword);}
	}
	ParseLineError(cmndCtr,"no group_end\n");
}
コード例 #5
0
/*
====================
idRenderModelMD5::LoadModel

used for initial loads, reloadModel, and reloading the data of purged models
Upon exit, the model will absolutely be valid, but possibly as a default model
====================
*/
void idRenderModelMD5::LoadModel()
{

	int			version;
	int			num;
	int			parentNum;
	idToken		token;
	idLexer		parser( LEXFL_ALLOWPATHNAMES | LEXFL_NOSTRINGESCAPECHARS );
	
	if( !purged )
	{
		PurgeModel();
	}
	purged = false;
	
	if( !parser.LoadFile( name ) )
	{
		MakeDefaultModel();
		return;
	}
	
	parser.ExpectTokenString( MD5_VERSION_STRING );
	version = parser.ParseInt();
	
	if( version != MD5_VERSION )
	{
		parser.Error( "Invalid version %d.  Should be version %d\n", version, MD5_VERSION );
	}
	
	//
	// skip commandline
	//
	parser.ExpectTokenString( "commandline" );
	parser.ReadToken( &token );
	
	// parse num joints
	parser.ExpectTokenString( "numJoints" );
	num  = parser.ParseInt();
	joints.SetGranularity( 1 );
	joints.SetNum( num );
	defaultPose.SetGranularity( 1 );
	defaultPose.SetNum( num );
	
	// parse num meshes
	parser.ExpectTokenString( "numMeshes" );
	num = parser.ParseInt();
	if( num < 0 )
	{
		parser.Error( "Invalid size: %d", num );
	}
	meshes.SetGranularity( 1 );
	meshes.SetNum( num );
	
	//
	// parse joints
	//
	parser.ExpectTokenString( "joints" );
	parser.ExpectTokenString( "{" );
	idJointMat* poseMat = ( idJointMat* )_alloca16( joints.Num() * sizeof( poseMat[0] ) );
	for( int i = 0; i < joints.Num(); i++ )
	{
		idMD5Joint* joint = &joints[i];
		idJointQuat*	 pose = &defaultPose[i];
		
		ParseJoint( parser, joint, pose );
		poseMat[ i ].SetRotation( pose->q.ToMat3() );
		poseMat[ i ].SetTranslation( pose->t );
		if( joint->parent )
		{
			parentNum = joint->parent - joints.Ptr();
			pose->q = ( poseMat[ i ].ToMat3() * poseMat[ parentNum ].ToMat3().Transpose() ).ToQuat();
			pose->t = ( poseMat[ i ].ToVec3() - poseMat[ parentNum ].ToVec3() ) * poseMat[ parentNum ].ToMat3().Transpose();
		}
	}
	parser.ExpectTokenString( "}" );
	
	//-----------------------------------------
	// create the inverse of the base pose joints to support tech6 style deformation
	// of base pose vertexes, normals, and tangents.
	//
	// vertex * joints * inverseJoints == vertex when joints is the base pose
	// When the joints are in another pose, it gives the animated vertex position
	//-----------------------------------------
	invertedDefaultPose.SetNum( SIMD_ROUND_JOINTS( joints.Num() ) );
	for( int i = 0; i < joints.Num(); i++ )
	{
		invertedDefaultPose[i] = poseMat[i];
		invertedDefaultPose[i].Invert();
	}
	SIMD_INIT_LAST_JOINT( invertedDefaultPose.Ptr(), joints.Num() );
	
	for( int i = 0; i < meshes.Num(); i++ )
	{
		parser.ExpectTokenString( "mesh" );
		meshes[i].ParseMesh( parser, defaultPose.Num(), poseMat );
	}
	
	// calculate the bounds of the model
	bounds.Clear();
	for( int i = 0; i < meshes.Num(); i++ )
	{
		idBounds meshBounds;
		meshes[i].CalculateBounds( poseMat, meshBounds );
		bounds.AddBounds( meshBounds );
	}
	
	// set the timestamp for reloadmodels
	fileSystem->ReadFile( name, NULL, &timeStamp );
	
	common->UpdateLevelLoadPacifier(true);
}
コード例 #6
0
/*
====================
idRenderModelMD5::LoadModel

used for initial loads, reloadModel, and reloading the data of purged models
Upon exit, the model will absolutely be valid, but possibly as a default model
====================
*/
void idRenderModelMD5::LoadModel() {
	int			version;
	int			i;
	int			num;
	int			parentNum;
	idToken		token;
	idLexer		parser( LEXFL_ALLOWPATHNAMES | LEXFL_NOSTRINGESCAPECHARS );
	idJointQuat	*pose;
	idMD5Joint	*joint;
	idJointMat *poseMat3;

	if ( !purged ) {
		PurgeModel();
	}
	purged = false;

	if ( !parser.LoadFile( name ) ) {
		MakeDefaultModel();
		return;
	}

	parser.ExpectTokenString( MD5_VERSION_STRING );
	version = parser.ParseInt();

	if ( version != MD5_VERSION ) {
		parser.Error( "Invalid version %d.  Should be version %d\n", version, MD5_VERSION );
	}

	//
	// skip commandline
	//
	parser.ExpectTokenString( "commandline" );
	parser.ReadToken( &token );

	// parse num joints
	parser.ExpectTokenString( "numJoints" );
	num  = parser.ParseInt();
	joints.SetGranularity( 1 );
	joints.SetNum( num );
	defaultPose.SetGranularity( 1 );
	defaultPose.SetNum( num );
	poseMat3 = ( idJointMat * )_alloca16( num * sizeof( *poseMat3 ) );

	// parse num meshes
	parser.ExpectTokenString( "numMeshes" );
	num = parser.ParseInt();
	if ( num < 0 ) {
		parser.Error( "Invalid size: %d", num );
	}
	meshes.SetGranularity( 1 );
	meshes.SetNum( num );

	//
	// parse joints
	//
	parser.ExpectTokenString( "joints" );
	parser.ExpectTokenString( "{" );
	pose = defaultPose.Ptr();
	joint = joints.Ptr();
	for( i = 0; i < joints.Num(); i++, joint++, pose++ ) {
		ParseJoint( parser, joint, pose );
		poseMat3[ i ].SetRotation( pose->q.ToMat3() );
		poseMat3[ i ].SetTranslation( pose->t );
		if ( joint->parent ) {
			parentNum = joint->parent - joints.Ptr();
			pose->q = ( poseMat3[ i ].ToMat3() * poseMat3[ parentNum ].ToMat3().Transpose() ).ToQuat();
			pose->t = ( poseMat3[ i ].ToVec3() - poseMat3[ parentNum ].ToVec3() ) * poseMat3[ parentNum ].ToMat3().Transpose();
		}
	}
	parser.ExpectTokenString( "}" );

	for( i = 0; i < meshes.Num(); i++ ) {
		parser.ExpectTokenString( "mesh" );
		meshes[ i ].ParseMesh( parser, defaultPose.Num(), poseMat3 );
	}

	//
	// calculate the bounds of the model
	//
	CalculateBounds( poseMat3 );

	// set the timestamp for reloadmodels
	fileSystem->ReadFile( name, NULL, &timeStamp );
}
コード例 #7
0
ファイル: rayScene.cpp プロジェクト: nal3vm/RayTracer
int RayScene::read(FILE* fp,int transformType){
	char keyword[BUF_SIZE];
	char keyFileName[BUF_SIZE];
	int cmndCtr=0;
	int backFlag=0, ambFlag=0;
	int indL=-1, indM=-1, indT=-1,indRF=-1,indV=-1,indK=-1;
	int temp;
	int inShapes=0;
	RayGroup* root;
	
	group=new StaticRayGroup();
	group->set(Matrix4D::IdentityMatrix());
	root=group;
	
	lightNum=-1;
	textureNum=-1;
	materialNum=-1;
	rayFileNum=-1;
	vertexNum=-1;
	keyFileNum=-1;
	keyFiles=NULL;
	keyData=NULL;
	lights=NULL;
	textures=NULL;
	materials=NULL;
	rayFiles=NULL;
	vertices=NULL;
	camera=NULL;
	
	
	while(fscanf(fp," #%s",keyword) == 1){
		cmndCtr++;
		
		//We try to read out the camera information. We make sure that we have
		//not begun describing the scene graph yet, and we ignore the camera if 
		//it is the second one specified.
		
		if(!strcmp(keyword,"camera")){
			if (inShapes!=0){
				ParseLineError(cmndCtr,"not a valid directive within a group\n");
			}
			if(camera){
				fprintf(stderr,"Parsing Line %d: Ignoring extra camera\n",cmndCtr);
			}
			else {
				camera=new RayCamera;
				if(!camera){
					ParseLineError(cmndCtr,"failed to allocate camera memory\n");
				}
				if(!camera->read(fp)){
					ParseLineError(cmndCtr,"failed to parse camera settings\n");
				}
			}
		}
		
		//Next we try to read out the environment information. Again, we make
		//sure that we have not begun describing the scene graph yet and we 
		//ignore all but the first background color and ambient color 
		//specifications.
		
		else if(!strcmp(keyword,"background")){
			if(inShapes){
				ParseLineError(cmndCtr,"not a valid directive within a group\n");
			}
			if(backFlag==1){
				fprintf(stderr,"Parsing Line %d: Ignoring extra background\n",cmndCtr);
			}
			else {
				backFlag=1;
				if(fscanf(fp," %lg %lg %lg",
					&(background[0]),&(background[1]),&(background[2])) != 3){
					ParseLineError(cmndCtr,"failed to parse background settings\n");
				}
			}
		}
		else if(!strcmp(keyword,"ambient")){
			if(inShapes){
				ParseLineError(cmndCtr,"not a valid directive within a group\n");
			}
			if(ambFlag==1){
				fprintf(stderr,"Parsing Line %d: Ignoring extra ambient\n",cmndCtr);
			}
			else {
				ambFlag=1;
				if(fscanf(fp," %lg %lg %lg",
					&(ambient[0]),&(ambient[1]),&(ambient[2])) != 3){
					ParseLineError(cmndCtr,"failed to parse ambient settings\n");
				}
			}
		}

		else if(!strcmp(keyword,"ambient")){
			if(inShapes){
				ParseLineError(cmndCtr,"not a valid directive within a group\n");
			}
			if(ambFlag==1){
				fprintf(stderr,"Parsing Line %d: Ignoring extra ambient\n",cmndCtr);
			}
			else {
				ambFlag=1;
				if(fscanf(fp," %lg %lg %lg",
					&(ambient[0]),&(ambient[1]),&(ambient[2])) != 3){
					ParseLineError(cmndCtr,"failed to parse ambient settings\n");
				}
			}
		}
		
		//Next we try read out the number of lights. We make sure that we have
		//not begun describing the scene graph, and we make sure that the number
		//of lights is only specified once. Once we have a "good" light number
		//we allocate memory for the lights 
		
		else if(!strcmp(keyword,"light_num")){
			if (inShapes!=0){
				ParseLineError(cmndCtr,"not a valid directive within a group\n");
			}
			if(lightNum>-1){
				ParseLineError(cmndCtr,"attempted to define light_num more than once\n");
			}
			else{
				if (fscanf(fp," %d", &(lightNum)) != 1){
					ParseLineError(cmndCtr,"failed to parse num_lights setting\n");
				}
				else{
					if(lightNum < 0){
						ParseLineError(cmndCtr,"you can't have negative number of lights\n");
					}
					else if(!lightNum){lights=NULL;}
					else {
						lights=new RayLight*[lightNum];
						if(!lights){
							ParseLineError(cmndCtr,"failed to allocate memory Lights\n");
						}
					}
				}
			}
		}
		
		//Next we try read out the number of textures. We make sure that we have
		//not begun describing the scene graph, and we make sure that the number
		//of textures is only specified once. Once we have a "good" texture number
		//we allocate memory for the textures.
		
		else if(!strcmp(keyword,"texture_num")){
			if(inShapes){
				ParseLineError(cmndCtr,"not a valid directive within a group\n");
			}
			if(textureNum>-1){
				ParseLineError(cmndCtr,"attempted to define texture_num more than once\n");
			}
			else{
				if(fscanf(fp," %d",&(textureNum)) != 1){
					ParseLineError(cmndCtr,"failed to parse num_textures setting\n");
				}
				else{
					if(textureNum < 0){
						ParseLineError(cmndCtr,"you can't have negative number of textures\n");
					}
					else if(!textureNum){textures=NULL;}
					else{
						textures=new RayTexture[textureNum];
						if(!textures){
							ParseLineError(cmndCtr,"failed to allocate memory for textures\n");
						}
					}
				}
			}
		}
		
		//Next we try read out the number of materials. We make sure that we have
		//not begun describing the scene graph, and we make sure that the number
		//of materials is only specified once. Once we have a "good" material
		//number we allocate memory for the materials.
		
		else if(!strcmp(keyword,"material_num")){
			if (inShapes){
				ParseLineError(cmndCtr,"not a valid directive within a group\n");
			}
			if(materialNum>-1){
				ParseLineError(cmndCtr,"attempted to define material_num more than once\n");
			}
			else{
				if(fscanf(fp," %d",&(materialNum)) != 1){
					ParseLineError(cmndCtr,"failed to parse num_materials setting\n");
				}
				else {
					if(materialNum < 0){
						ParseLineError(cmndCtr,"you can't have negative number of materials\n");
					}
					else{
						if(materialNum>0){
							materials=new RayMaterial[materialNum];
							if(!materials){
								ParseLineError(cmndCtr,"failed to allocate memory for materials\n");
							}
						}
						else{materials=NULL;}
					}
				}
			}
		}
		
		//Next we try read out the number of vertices. We make sure that we have
		//not begun describing the scene graph, and we make sure that the number
		//of vertices is only specified once. Once we have a "good" vertex
		//number we allocate memory for the vertices.
		
		else if(!strcmp(keyword,"vertex_num")){
			if (inShapes){
				ParseLineError(cmndCtr,"not a valid directive within a group\n");
			}
			if(vertexNum>-1){
				ParseLineError(cmndCtr,"attempted to define material_num more than once\n");
			}
			else{
				if(fscanf(fp," %d",&(vertexNum)) != 1){
					ParseLineError(cmndCtr,"failed to parse num_materials setting\n");
				}
				else {
					if(vertexNum < 0){
						ParseLineError(cmndCtr,"you can't have negative number of materials\n");
					}
					else{
						if(vertexNum>0){
							vertices=new RayVertex[vertexNum];
							if(!vertices){
								ParseLineError(cmndCtr,"failed to allocate memory for vertices\n");
							}
						}
						else{vertices=NULL;}
					}
				}
			}
		}
		
		//Next we try read out the number of ray files. We make sure that we have
		//not begun describing the scene graph, and we make sure that the number
		//of ray files is only specified once. Once we have a "good" ray file
		//number we allocate memory for the ray files.
		
		else if(!strcmp(keyword,"ray_file_num")){
			if (inShapes){ParseLineError(cmndCtr,"not a valid directive within a group\n");}
			if(rayFileNum>-1){ParseLineError(cmndCtr,"attempted to define ray_file_num more than once\n");}
			else{
				if(fscanf(fp," %d",&(rayFileNum)) != 1){ParseLineError(cmndCtr,"failed to parse ray_file_num setting\n");}
				else {
					if(rayFileNum<=0){rayFiles=NULL;}
					else{
						rayFiles=new RayFile[rayFileNum];
						if(!rayFiles){ParseLineError(cmndCtr,"failed to allocate memory for ray_files\n");}
					}
				}
			}
		}

		//Next we try read out the number of key-files. We make sure that we have
		//not begun describing the scene graph, and we make sure that the number
		//of key-files is only specified once. Once we have a "good" ray file
		//number we allocate memory for the ray files.
		
		else if(!strcmp(keyword,"key_file_num")){
			if (inShapes){ParseLineError(cmndCtr,"not a valid directive within a group\n");}
			if(keyFileNum>-1){ParseLineError(cmndCtr,"attempted to define key_file_num more than once\n");}
			else{
				if(fscanf(fp," %d",&(keyFileNum)) != 1){ParseLineError(cmndCtr,"failed to parse key_file_num setting\n");}
				else {
					if(keyFileNum<=0){
						keyFiles=NULL;
						keyData=NULL;
					}
					else{
						keyFiles=new RayKeyFile[keyFileNum];
						keyData=new RayKeyData[keyFileNum];
						if(!keyFiles || !keyData){ParseLineError(cmndCtr,"failed to allocate memory for key_files\n");}
					}
				}
			}
		}
		
		//Next we try read out the next textures. We make sure that we have
		//not begun describing the scene graph. We make sure that we are not
		//adding more textures then we promised and we make sure that all the
		//file I/O works as it should.
		
		else if(!strcmp(keyword,"texture")){
			if(inShapes){
				ParseLineError(cmndCtr,"not a valid directive within a group\n");
			}
			if(textureNum == -1){
				ParseLineError(cmndCtr,"attempted to define texture before texture_num\n");
			}
			indT++;
			if(indT == textureNum){
				ParseLineError(cmndCtr,"attempted to define more textures than declared\n");
			}
			if(!textures[indT].read(fp)){
				ParseLineError(cmndCtr,"failed to generate texture\n");
			}
			textures[indT].index=indT;
		}
		
		//Next we try read out the next material. We make sure that we have
		//not begun describing the scene graph. We make sure that we are not
		//adding more materials then we promised.
		
		else if(!strcmp(keyword,"material")){
			if(inShapes){
				ParseLineError(cmndCtr,"not a valid directive within a group\n");
			}
			if(materialNum==-1){
				ParseLineError(cmndCtr,"attempted to define materials before material_num\n");
			}
			indM++;
			if(indM == materialNum){
				ParseLineError(cmndCtr,"attempted to define more materials than declared\n");
			}
			else{
				if(!materials[indM].read(fp,temp)){
					ParseLineError(cmndCtr,"failed to parse material\n");
				}
				else{
					if(temp==-1){materials[indM].tex=NULL;}
					else{
						if(temp >= textureNum){
							ParseLineError(cmndCtr,
								"material specifies a texture out of texture_num bounds (make sure texture_num comes before material_num) \n");
						}
						materials[indM].tex=&(textures[temp]);
					}
					materials[indM].index=indM;
				}
			}
		}
		
		//Next we try read out the next vertex. We make sure that we have
		//not begun describing the scene graph. We make sure that we are not
		//adding more vertices then we promised.
		
		else if(!strcmp(keyword,"vertex")){
			if(inShapes){
				ParseLineError(cmndCtr,"not a valid directive within a group\n");
			}
			if(vertexNum==-1){
				ParseLineError(cmndCtr,"attempted to define vertices before vertex_num\n");
			}
			indV++;
			if(indV == vertexNum){
				ParseLineError(cmndCtr,"attempted to define more vertices than declared\n");
			}
			else{
				if(!vertices[indV].read(fp)){
					ParseLineError(cmndCtr,"failed to parse vertices\n");
				}
				else{vertices[indV].index=indV;}
			}
		}
		//Next we try to read out the next rayFile
		else if(!strcmp(keyword,"ray_file")){
			if(inShapes){ParseLineError(cmndCtr,"not a valid directive within a group\n");}
			if(rayFileNum==-1){ParseLineError(cmndCtr,"attempted to define ray_files before ray_file_num\n");}
			indRF++;
			if(indRF == rayFileNum){ParseLineError(cmndCtr,"attempted to define more ray_files than declared\n");}
			else{
				if(!rayFiles[indRF].read(fp,transformType)){ParseLineError(cmndCtr,"failed to parse ray_file\n");}
				rayFiles[indRF].index=indRF;
			}
		}
		
		//Next we try read out the next light. We make sure that we have
		//not begun describing the scene graph. We make sure that we are not
		//adding more materials then we promised.
		
		else if(!strcmp(keyword,"light_point") || !strcmp(keyword,"light_dir") || !strcmp(keyword,"light_spot")){
			if(inShapes){ParseLineError(cmndCtr,"not a valid directive within a group\n");}
			if(lightNum==-1){ParseLineError(cmndCtr,"attempted to define lights before light_num\n");}
			indL++;
			if(indL == lightNum){ParseLineError(cmndCtr,"attempted to define more lights than light_num\n");}
			else{
				if(!strcmp(keyword,"light_point")){lights[indL]=new RayPointLight;}
				else if(!strcmp(keyword,"light_dir")){lights[indL]=new RayDirectionalLight;}
				else if(!strcmp(keyword,"light_spot")){lights[indL]=new RaySpotLight;}
				if(!lights[indL]){ParseLineError(cmndCtr,"failed to allocate memory for light\n");}
				if(!lights[indL]->read(fp)){ParseLineError(cmndCtr,"failed to parse light\n");}
			}
		}

		//Next we try to read out the .key file. We make sure that we have not
		//begun describing the scene graph.
		else if(!strcmp(keyword,"key_file")){
			if(inShapes){ParseLineError(cmndCtr,"not a valid directive within a group\n");}
			if(keyFileNum==-1){ParseLineError(cmndCtr,"attempted to define key_files before key_file_num\n");}
			indK++;
			if(indK == keyFileNum){ParseLineError(cmndCtr,"attempted to define more key_files than key_file_num\n");}
			fscanf(fp," %s",keyFileName);
			if(!keyFiles[indK].read(keyFileName)){ParseLineError(cmndCtr,"failed to read in key_file\n");}
			if(!keyData[indK].set(keyFiles[indK],transformType)){ParseLineError(cmndCtr,"failed to set key file data\n");}
			keyData[indK].setCurrentValue(0);
		}
		
		//Next we try read out the scene graph information, obtaining the 
		//transform and either creating a new scene graph or adding a node
		//to the existing one.
		
		else if(!strcmp(keyword,"group_begin")){
			inShapes=1;
			ParseGroup(fp,cmndCtr,root);
		}
		else if(!strcmp(keyword,"joint_begin")){
			inShapes=1;
			ParseJoint(fp,cmndCtr,root);
		}
		
		//We check if we have come to the end of a scene-graph group. If we have
		//this is bad because we have not yet opened one
		
		else if(!strcmp(keyword,"group_end")){
			ParseLineError(cmndCtr,"closed more groups then began\n");
		}
		else if(!strcmp(keyword,"joint_end")){
			ParseLineError(cmndCtr,"closed more joints then began\n");
		}
		else if(ParseShape(fp,keyword,cmndCtr,root)){inShapes=1;}
		else{
			fprintf(stderr,
				"Ignoring Command %d: No valid #directive...%s \n",cmndCtr,
				keyword);
		}		
	}		
	if(indL<(lightNum-1)){ParseError("Couldn't find enough lights for light_num");}
	if(indM<(materialNum-1)){ParseError("Couldn't find enough materials for material_num");}
	if(indT<(textureNum-1)){ParseError("Couldn't find enough textures for texture_num");}
	if(indRF<(rayFileNum-1)){ParseError("Couldn't find enough ray_files for ray_file_num");}
	if(lightNum==-1){lightNum=0;}
	if(materialNum==-1){materialNum=0;}
	if(textureNum==-1){textureNum=0;}
	if(rayFileNum==-1){rayFileNum=0;}
	if(vertexNum==-1){vertexNum=0;}
	return 1;
}