Exemple #1
0
void Application::InitRenderer()
{
    m_Renderer->SetPointLightMaterial      (LoadMaterial("Silk/PointLight.mtrl"       ));
    m_Renderer->SetSpotLightMaterial       (LoadMaterial("Silk/SpotLight.mtrl"        ));
    m_Renderer->SetDirectionalLightMaterial(LoadMaterial("Silk/DirectionalLight.mtrl" ));
    m_Renderer->SetFinalPassMaterial       (LoadMaterial("Silk/FinalDeferredPass.mtrl"));
}
void DrawParticleSinks(R3Scene *scene)
{
  // Check if should draw particle sinks
  if (!show_particle_sources_and_sinks) return;

  // Setup
  GLboolean lighting = glIsEnabled(GL_LIGHTING);
  glEnable(GL_LIGHTING);

  // Define sink material
  static R3Material sink_material;
  if (sink_material.id != 33) {
    sink_material.ka.Reset(0.2,0.2,0.2,1);
    sink_material.kd.Reset(1,0,0,1);
    sink_material.ks.Reset(1,0,0,1);
    sink_material.kt.Reset(0,0,0,1);
    sink_material.emission.Reset(0,0,0,1);
    sink_material.shininess = 1;
    sink_material.indexofrefraction = 1;
    sink_material.texture = NULL;
    sink_material.texture_index = -1;
    sink_material.id = 33;
  }

  // Draw all particle sinks
  glEnable(GL_LIGHTING);
  LoadMaterial(&sink_material);
  for (int i = 0; i < scene->NParticleSinks(); i++) {
    R3ParticleSink *sink = scene->ParticleSink(i);
    DrawShape(sink->shape);
  }

  // Clean up
  if (!lighting) glDisable(GL_LIGHTING);
}
void DrawNode(R3Scene *scene, R3Node *node)
{
  // Push transformation onto stack
  glPushMatrix();
  LoadMatrix(&node->transformation);

  // Load material
  if (node->material) LoadMaterial(node->material);

  // Draw shape
  if (node->shape) DrawShape(node->shape);

  // Draw children nodes
  for (int i = 0; i < (int) node->children.size(); i++) 
    DrawNode(scene, node->children[i]);

  // Restore previous transformation
  glPopMatrix();

  // Show bounding box
  if (show_bboxes) {
    GLboolean lighting = glIsEnabled(GL_LIGHTING);
    glDisable(GL_LIGHTING);
    node->bbox.Outline();
    if (lighting) glEnable(GL_LIGHTING);
  }
}
//-----------------------------------------------------------------------------
// Returns the material
//-----------------------------------------------------------------------------
IMaterial* CMaterial::GetMaterial( bool bForceLoad )
{
	if ( bForceLoad )
		LoadMaterial();
		
	return m_pMaterial;
}
Exemple #5
0
HRESULT KModelSFXScreen::LoadMesh(LPSTR pFileName)
{
	wsprintf(m_szMeshFileName,"Screen SFX");

	m_dNumMaterial = 1;
	m_lpMaterial = new MATERIAL[m_dNumMaterial];
	ZeroMemory(m_lpMaterial,sizeof(MATERIAL)*m_dNumMaterial);
	
	DWORD Def_Option = MATERIAL_OPTION_ZBUFFER_TRUE|
		MATERIAL_OPTION_FILL_SOLID|
		MATERIAL_OPTION_SHADE_GOURAUD|
		MATERIAL_OPTION_CULL_CW|MATERIAL_OPTION_LIGHTING|
		MATERIAL_OPTION_SPECULARENABLE;
	
	for(DWORD i=0;i<m_dNumMaterial;i++)
	{
		m_lpMaterial[i].m_sMaterial9.Diffuse.r = 0.7f ;
		m_lpMaterial[i].m_sMaterial9.Diffuse.g = 0.7f ;
		m_lpMaterial[i].m_sMaterial9.Diffuse.b = 0.7f ;
		m_lpMaterial[i].m_sMaterial9.Diffuse.a = 1.0f ;
		m_lpMaterial[i].m_sMaterial9.Ambient = m_lpMaterial[i].m_sMaterial9.Diffuse;
		m_lpMaterial[i].m_sMaterial9.Specular = m_lpMaterial[i].m_sMaterial9.Diffuse;
		m_lpMaterial[i].m_sMaterial9.Power = 15;
		m_lpMaterial[i].m_dOption = Def_Option;
	}

	TCHAR Name[256];
	wsprintf(Name,"%s\\ScreenSFX.Mtl",g_Def_ModelDirectory);
	LoadMaterial(Name);

	//m_lpMaterial[0].m_dTextureIDs[0] = g_cGraphicsTool.m_BufferTextureID;
	return S_OK;
}
Exemple #6
0
HRESULT KModelBelt::LoadMesh(LPSTR pFileName)
{
	CreateVerticesBuffer();
	m_dNumMaterial = 1;
	m_lpMaterial = new MATERIAL[m_dNumMaterial];
	ZeroMemory(m_lpMaterial,sizeof(MATERIAL)*m_dNumMaterial);
	
	DWORD Def_Option = MATERIAL_OPTION_ZBUFFER_TRUE|
		MATERIAL_OPTION_FILL_SOLID|
		MATERIAL_OPTION_SHADE_GOURAUD|
		MATERIAL_OPTION_CULL_NONE|
		MATERIAL_OPTION_SPECULARENABLE;
	
	for(DWORD i=0;i<m_dNumMaterial;i++)
	{
		m_lpMaterial[i].m_sMaterial9.Diffuse.r = 0.7f ;
		m_lpMaterial[i].m_sMaterial9.Diffuse.g = 0.7f ;
		m_lpMaterial[i].m_sMaterial9.Diffuse.b = 0.7f ;
		m_lpMaterial[i].m_sMaterial9.Diffuse.a = 1.0f ;
		m_lpMaterial[i].m_sMaterial9.Ambient = m_lpMaterial[i].m_sMaterial9.Diffuse;
		m_lpMaterial[i].m_sMaterial9.Specular = m_lpMaterial[i].m_sMaterial9.Diffuse;
		m_lpMaterial[i].m_sMaterial9.Power = 15;
		m_lpMaterial[i].m_dOption = Def_Option;
	}

	TCHAR Name[256];
//	wsprintf(Name,"%s\\Blade.Mtl",g_Def_ModelDirectory);
	wsprintf(Name,"%s\\旗子.Mtl",g_Def_ModelDirectory);
	LoadMaterial(Name);
	
	wsprintf(m_szMeshFileName,"Sword Blade");
	return S_OK;
}
Exemple #7
0
void LoadScene(TiXmlElement *element)
{
    for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) {
        
        if ( COMPARE( child->Value(), "background" ) ) {
            Color c(1,1,1);
            ReadColor( child, c );
            background.SetColor(c);
            printf("Background %f %f %f\n",c.r,c.g,c.b);
            background.SetTexture( ReadTexture(child) );
        } else if ( COMPARE( child->Value(), "environment" ) ) {
            Color c(1,1,1);
            ReadColor( child, c );
            environment.SetColor(c);
            printf("Environment %f %f %f\n",c.r,c.g,c.b);
            environment.SetTexture( ReadTexture(child) );
        } else if ( COMPARE( child->Value(), "object" ) ) {
            LoadNode( &rootNode, child );
        } else if ( COMPARE( child->Value(), "material" ) ) {
            LoadMaterial( child );
        } else if ( COMPARE( child->Value(), "light" ) ) {
            LoadLight( child );
        }
    }
}
Exemple #8
0
csPtr<iMaterialWrapper> BgLoader::LoadMaterial(const char* name, bool* failed, bool wait)
{
    csRef<Material> material = materials.Get(mStringSet.Request(name), csRef<Material>());
    {
        if(!failed)
        {
          // Validation.
          csString msg;
          msg.Format("Invalid material reference '%s'", name);
          CS_ASSERT_MSG(msg.GetData(), material.IsValid());
        }
        else if(!material.IsValid())
        {
          *failed = true;
          return csPtr<iMaterialWrapper>(0);
        }
    }

    if(LoadMaterial(material, wait))
    {
        return csPtr<iMaterialWrapper>(material->mat);
    }

    return csPtr<iMaterialWrapper>(0);
}
Exemple #9
0
void CModel::Load( const char * szFile )
{
    CXMLElement * pModelXML = NULL;
    g_pXMLWrapper->LoadXML( szFile, &pModelXML );

    if ( !pModelXML )
        return;

    CXMLElement * pMeshXML = pModelXML->GetChild( "Mesh" );

    if ( pMeshXML )
    {
        CXMLAttr * pMeshAttr = pMeshXML->GetAttr( "File" );

        if ( pMeshAttr )
        {
            LoadObjects( pMeshAttr->GetValue() );
        }

        //----------------------------------------------------------------------
        // Tip: Читаем материалы
        //----------------------------------------------------------------------
        for ( uint n = 0; n < pMeshXML->GetNumChilds(); ++n )
        {
            LoadMaterial( pMeshXML->GetChild( n ) );
        }
    }

    //--------------------------------------------------------------------------
    //
    //--------------------------------------------------------------------------
    CXMLElement * pAnimXML = pModelXML->GetChild( "Animations" );

    if ( pAnimXML )
    {
        for ( uint n = 0; n < pAnimXML->GetNumChilds(); ++n )
        {
            CXMLElement * pCurAnimXML = pAnimXML->GetChild( n );

            CXMLAttr * pFileAttr = pCurAnimXML->GetAttr( "File" );
            CXMLAttr * pNameAttr = pCurAnimXML->GetAttr( "Name" );

            CAnim * pAnim = NEW CAnim;

            if ( pAnim->Load( pFileAttr->GetValue() ) )
            {
                pAnim->SetName( pNameAttr->GetValue() );
                AddAnim( pAnim );
                PlayAnim( "test_anim" );
                continue;
            }

            DEL( pAnim );
        }
    }

    DEL( pModelXML );
}
//----------------------------------------------------------------------------------------------
bool CFXMatManager::Load(const char *Path, m_material &OutMaterial)
{
	bool bResult = false;

	LoadMaterial(Path, &OutMaterial);
	bResult = true;

	return bResult;
}
Exemple #11
0
	void Model_IO::LoadMaterials(std::vector<Material>& materials, BinaryReader& reader, const achar* path)
	{
		int32_t materialCount = reader.Get<int32_t>();
		materials.resize(materialCount);

		for (int32_t i = 0; i < materialCount; i++)
		{
			LoadMaterial(materials[i], reader, path);
		}
	}
	//------------------------------------------------------------
	void PPC::LoadMaterials( tixmlel_traits::in element, bool replace )
	{
		string_traits::str childName;
		const TiXmlElement* childElement(0);
		while( XI::IterateChildElements( element, childElement ) )
		{
			childName = childElement->Value();
			if( childName == PK::MATERIAL )
				LoadMaterial( childElement, replace );
		}
	}
Exemple #13
0
bool BgLoader::LoadMeshFact(MeshFact* meshfact, bool wait)
{
    if(meshfact->useCount != 0)
    {
        ++meshfact->useCount;
        return true;
    }

    bool ready = true;
    for(size_t i=0; i<meshfact->materials.GetSize(); i++)
    {
        if(!meshfact->checked[i])
        {
            meshfact->checked[i] = LoadMaterial(meshfact->materials[i], wait);
            ready &= meshfact->checked[i];
        }
    }

    if(ready && !meshfact->status)
    {
        if(meshfact->data)
        {
            if(wait)
            {
                meshfact->status = tloader->LoadNodeWait(meshfact->path, meshfact->data);
            }
            else
            {
                meshfact->status = tloader->LoadNode(meshfact->path, meshfact->data);
                return false;
            }
        }
        else
        {
            if(wait)
            {
                meshfact->status = tloader->LoadMeshObjectFactoryWait(meshfact->path, meshfact->filename);
            }
            else
            {
                meshfact->status = tloader->LoadMeshObjectFactory(meshfact->path, meshfact->filename);
                return false;
            }
        }
    }

    if(meshfact->status && meshfact->status->IsFinished())
    {
        ++meshfact->useCount;
        return true;
    }

    return false;
}
void MaterialManager::Initialize()
{
	DIR *pDIR;
	struct dirent *entry;
	if( pDIR=opendir("./Data/Materials") ){
		while(entry = readdir(pDIR)){
			if( strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0 )
				LoadMaterial(string("./Data/Materials/") + entry->d_name);
		}
		closedir(pDIR);
	}
}
Exemple #15
0
void LoadScene(TiXmlElement *element)
{
    for ( TiXmlElement *child = element->FirstChildElement(); child!=NULL; child = child->NextSiblingElement() ) {
        
        if ( COMPARE( child->Value(), "object" ) ) {
            //cout<<"Object...................";
            LoadNode( &rootNode, child );
        } else if ( COMPARE( child->Value(), "material" ) ) {
            LoadMaterial( child );
        } else if ( COMPARE( child->Value(), "light" ) ) {
            LoadLight( child );
        }
    }
}
void GLMesh::Load(std::string filepath)
{
	const aiScene *scene = importer.ReadFile(filepath,
		aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_FindDegenerates);
	bool result = false;
	if (scene)
	{
		LoadScene(scene);
		LoadMaterial(scene, filepath);
	}
	else
	{
		std::cerr << "GLMesh import error " << filepath << std::endl;
	}
}
Exemple #17
0
void SceneBase::InitMaterials()
{
	const string MATERIAL_FILE_PATH = "SONs//Materials.son";

	StopWatch initTimer;
	initTimer.startTimer();

	std::cout << "Loading " << MATERIAL_FILE_PATH << "... ";

	matList = LoadMaterial(MATERIAL_FILE_PATH);
	// Push the default Material to the 
	Material temp;
	temp.name = "DefaultMaterial";
	matList.insert(std::pair<string, Material>(temp.name, temp));

	std::cout << "Loaded! (" << initTimer.getElapsedTime() << "s)" << std::endl;
}
    PMDDataDx9( const std::string &_file_name ) :
      Node(&PMDNoBoneManagerDx9::Instance()),
      m_FilePass(_file_name)
    {
        if(_file_name.empty()) return;

        PMDLoader::DATA *data = PMDLoader::Load(_file_name);
        if(!data) return;

        LoadMesh(data);
        LoadMaterial(data);
        delete[] data->vertex;
        delete[] data->face_vert_index;
        delete[] data->bone;
        delete[] data->material;
        delete data;
    };
Exemple #19
0
	void FbxUtil::LoadMesh(const SceneNode::Ptr &ntNode, FbxNode* fbxNode)
	{
		FbxMesh* fbxMesh = static_cast<FbxMesh*>(fbxNode->GetNodeAttribute());

		// first, we test if ther's already a mesh asset exits with this name.
		Mesh::Ptr mesh = EntityUtil::Instance()->FindEntity<Mesh>(fbxMesh->GetName());
		
		if (mesh == nullptr)
		{
			// if not, we read the mesh data.
			mesh = CreateMesh(fbxMesh);
			EntityUtil::Instance()->AddEntity(mesh);
		}

		// attach mesh component to node.
		ntNode->AddComponent(MeshRender::Create(nullptr, mesh));

		LoadMaterial(ntNode, fbxNode);
	}
Exemple #20
0
bool BgLoader::LoadMeshGen(MeshGen* meshgen)
{
    bool ready = true;
    for(size_t i=0; i<meshgen->meshfacts.GetSize(); i++)
    {
        if(!meshgen->mftchecked[i])
        {
            meshgen->mftchecked[i] = LoadMeshFact(meshgen->meshfacts[i]);
            ready &= meshgen->mftchecked[i];
        }
    }

    if(!ready)
      return false;

    for(size_t i=0; i<meshgen->materials.GetSize(); i++)
    {
        if(!meshgen->matchecked[i])
        {
            meshgen->matchecked[i] = LoadMaterial(meshgen->materials[i]);
            ready &= meshgen->matchecked[i];
        }
    }

    if(!ready || !LoadMesh(meshgen->object))
      return false;

    if(ready && !meshgen->status)
    {
        meshgen->status = tloader->LoadNode(vfs->GetCwd(), meshgen->data, 0, meshgen->sector->object);
        return false;
    }

    if(meshgen->status && meshgen->status->IsFinished())
    {
      meshgen->loading = false;
      return true;
    }

    return false;
}
HRESULT C3DLoaderMS3D::MergeMesh(C3DModel *Model, char* MeshName, int BoneID)
{		
	int i;

	// load a mesh
	bool Found = false;
	for(i=0; i<m_NumMeshes; i++)
	{
		if(stricmp(m_Meshes[i].m_Name, MeshName)==0)
		{
			C3DMesh* Mesh = new C3DMesh(Game);
			LoadMesh(Mesh, &m_Meshes[i], Model->m_NumMaterials, BoneID);
			Model->m_Meshes.Add(Mesh);

			Model->m_NumMeshes++;
			Found = true;
			break;
		}
	}
	if(!Found)
	{
		Game->LOG(0, "Error: Mesh '%s' not found in model '%s'", MeshName, m_Filename);
		return E_FAIL;
	}

	// load materials
	for(i=0; i<m_NumMaterials; i++)
	{
		C3DMaterial* Material = new C3DMaterial(Game);
		LoadMaterial(Material, &m_Materials[i]);
		Model->m_Materials.Add(Material);

		Model->m_NumMaterials++;
	}

	return S_OK;
}
Exemple #22
0
//
//  Load OBJ file
//
int LoadOBJ(const char* file)
{
   int k;
   int  Nv,Nn,Nt;  //  Number of vertex, normal and textures
   int  Mv,Mn,Mt;  //  Maximum vertex, normal and textures
   float* V;       //  Array of vertexes
   float* N;       //  Array of normals
   float* T;       //  Array if textures coordinates
   char*  line;    //  Line pointer
   char*  str;     //  String pointer

   //  Open file
   FILE* f = fopen(file,"r");
   if (!f) Fatal("Cannot open file %s\n",file);

   // Reset materials
   mtl = NULL;
   Nmtl = 0;

   //  Start new displaylist
   int list = glGenLists(1);
   glNewList(list,GL_COMPILE);
   //  Push attributes for textures
   glPushAttrib(GL_TEXTURE_BIT);

   //  Read vertexes and facets
   V  = N  = T  = NULL;
   Nv = Nn = Nt = 0;
   Mv = Mn = Mt = 0;
   while ((line = readline(f)))
   {
      //  Vertex coordinates (always 3)
      if (line[0]=='v' && line[1]==' ')
         readcoord(line+2,3,&V,&Nv,&Mv);
      //  Normal coordinates (always 3)
      else if (line[0]=='v' && line[1] == 'n')
         readcoord(line+2,3,&N,&Nn,&Mn);
      //  Texture coordinates (always 2)
      else if (line[0]=='v' && line[1] == 't')
         readcoord(line+2,2,&T,&Nt,&Mt);
      //  Read and draw facets
      else if (line[0]=='f')
      {
         line++;
         //  Read Vertex/Texture/Normal triplets
         glBegin(GL_POLYGON);
         while ((str = getword(&line)))
         {
            int Kv,Kt,Kn;
            //  Try Vertex/Texture/Normal triplet
            if (sscanf(str,"%d/%d/%d",&Kv,&Kt,&Kn)==3)
            {
               if (Kv<0 || Kv>Nv/3) Fatal("Vertex %d out of range 1-%d\n",Kv,Nv/3);
               if (Kn<0 || Kn>Nn/3) Fatal("Normal %d out of range 1-%d\n",Kn,Nn/3);
               if (Kt<0 || Kt>Nt/2) Fatal("Texture %d out of range 1-%d\n",Kt,Nt/2);
            }
            //  Try Vertex//Normal pairs
            else if (sscanf(str,"%d//%d",&Kv,&Kn)==2)
            {
               if (Kv<0 || Kv>Nv/3) Fatal("Vertex %d out of range 1-%d\n",Kv,Nv/3);
               if (Kn<0 || Kn>Nn/3) Fatal("Normal %d out of range 1-%d\n",Kn,Nn/3);
               Kt = 0;
            }
            //  Try Vertex index
            else if (sscanf(str,"%d",&Kv)==1)
            {
               if (Kv<0 || Kv>Nv/3) Fatal("Vertex %d out of range 1-%d\n",Kv,Nv/3);
               Kn = 0;
               Kt = 0;
            }
            //  This is an error
            else
               Fatal("Invalid facet %s\n",str);
            //  Draw vectors
            if (Kt) glTexCoord2fv(T+2*(Kt-1));
            if (Kn) glNormal3fv(N+3*(Kn-1));
            if (Kv) glVertex3fv(V+3*(Kv-1));
         }
         glEnd();
      }
      //  Use material
      else if ((str = readstr(line,"usemtl")))
         SetMaterial(str);
      //  Load materials
      else if ((str = readstr(line,"mtllib")))
         LoadMaterial(str);
      //  Skip this line
   }
   fclose(f);
   //  Pop attributes (textures)
   glPopAttrib();
   glEndList();

   //  Free materials
   for (k=0;k<Nmtl;k++)
      free(mtl[k].name);
   free(mtl);

   //  Free arrays
   free(V);
   free(T);
   free(N);

   return list;
}
HRESULT C3DLoaderMS3D::LoadModel(C3DModel *Model)
{		
	int i,j;

	// load meshes
	Model->m_NumMeshes = m_NumMeshes;

	for(i=0; i<m_NumMeshes; i++){
		C3DMesh* Mesh = new C3DMesh(Game);
		LoadMesh(Mesh, &m_Meshes[i], 0);
		Model->m_Meshes.Add(Mesh);
	}

	// load materials
	Model->m_NumMaterials = m_NumMaterials;
	
	for(i=0; i<m_NumMaterials; i++){
		C3DMaterial* Material = new C3DMaterial(Game);
		LoadMaterial(Material, &m_Materials[i]);
		Model->m_Materials.Add(Material);
	}


	// load joints
	int parent;

	Model->m_NumJoints = m_NumJoints;
	Model->m_Joints = new C3DJoint[m_NumJoints];

	// conversion matrix from right-handed to left-handed
	D3DXMATRIX convert;
	D3DXMatrixRotationYawPitchRoll(&convert, DegToRad(180), DegToRad(180), 0);

	for(i=0; i<m_NumJoints; i++){
		parent = -1;
		
		// find parent (if any)
		if(strlen(m_Joints[i].m_ParentName) > 0){
			for(j=0; j<m_NumJoints; j++){
				if(stricmp(m_Joints[j].m_Name, m_Joints[i].m_ParentName)== 0){
					parent = j;
					break;
				}
			}
			if(parent==-1) Game->LOG(0, "Warning: cannot find joint '%s' (model '%s')", m_Joints[i].m_ParentName, m_Filename);
		}
		Model->m_Joints[i].m_Parent = parent;

		// local rotation
		Model->m_Joints[i].m_LocalRotation.x =  m_Joints[i].m_Rotation[0];
		Model->m_Joints[i].m_LocalRotation.y =  m_Joints[i].m_Rotation[1];
		Model->m_Joints[i].m_LocalRotation.z =  m_Joints[i].m_Rotation[2];

		D3DXVec3TransformCoord(&Model->m_Joints[i].m_LocalRotation, &Model->m_Joints[i].m_LocalRotation, &convert);

		// local translation
		Model->m_Joints[i].m_LocalTranslation.x =  m_Joints[i].m_Translation[0];
		Model->m_Joints[i].m_LocalTranslation.y =  m_Joints[i].m_Translation[1];
		Model->m_Joints[i].m_LocalTranslation.z = -m_Joints[i].m_Translation[2];

		CBUtils::SetString(&Model->m_Joints[i].m_Name, m_Joints[i].m_Name);
	}

	// load anim info
	//Model->m_TotalTime = m_TotalTime;


	// load animations
	/*
	Model->m_NumAnimations = m_Animations.GetSize();
	if(Model->m_NumAnimations > 0)
		Model->m_Animations = new C3DSkelAnim[Model->m_NumAnimations];

	for(i=0; i<m_Animations.GetSize(); i++){
		C3DSkelAnim* anim = &Model->m_Animations[i];
		anim->SetName(m_Animations[i]->m_Name);
		anim->m_Looping = m_Animations[i]->m_Looping;

		anim->m_JointAnims = new C3DSkelAnim::C3DJointAnim[m_NumJoints];

		double StartTime = m_FrameTime * m_Animations[i]->m_StartFrame;
		double EndTime = m_FrameTime * m_Animations[i]->m_EndFrame;

		anim->m_TotalTime = EndTime - StartTime;

		int count;
		for(j=0; j<m_NumJoints; j++){
			//////////////////////////////////////////////////////////////////////////			
			// count valid translation keyframes
			for(k=0; k<m_Joints[j].m_NumTransKeyframes; k++){
				if(m_Joints[j].m_TranslationKeyframes[k].m_Time*1000.0f >= StartTime && m_Joints[j].m_TranslationKeyframes[k].m_Time*1000.0f <= EndTime)
					anim->m_JointAnims[j].m_NumTranslationKeyframes++;
			}
			// ...and load them
			if(anim->m_JointAnims[j].m_NumTranslationKeyframes > 0){
				anim->m_JointAnims[j].m_TranslationKeyframes = new C3DKeyframe[anim->m_JointAnims[j].m_NumTranslationKeyframes];
				count=0;
				for(k=0; k<m_Joints[j].m_NumTransKeyframes; k++){
					if(m_Joints[j].m_TranslationKeyframes[k].m_Time*1000.0f >= StartTime && m_Joints[j].m_TranslationKeyframes[k].m_Time*1000.0f <= EndTime){
						C3DKeyframe* Keyframe = &anim->m_JointAnims[j].m_TranslationKeyframes[count++];
						
						Keyframe->m_JointIndex = j;
						Keyframe->m_Time = m_Joints[j].m_TranslationKeyframes[k].m_Time*1000.0f - StartTime;
			
						Keyframe->m_Parameter.x =  m_Joints[j].m_TranslationKeyframes[k].m_Parameter[0];
						Keyframe->m_Parameter.y =  m_Joints[j].m_TranslationKeyframes[k].m_Parameter[1];
						Keyframe->m_Parameter.z = -m_Joints[j].m_TranslationKeyframes[k].m_Parameter[2];
					}
				}
			}

			//////////////////////////////////////////////////////////////////////////
			// count valid rotation keyframes
			for(k=0; k<m_Joints[j].m_NumRotKeyframes; k++){
				if(m_Joints[j].m_RotationKeyframes[k].m_Time*1000.0f >= StartTime && m_Joints[j].m_RotationKeyframes[k].m_Time*1000.0f <= EndTime)
					anim->m_JointAnims[j].m_NumRotationKeyframes++;
			}
			// ...and load them
			if(anim->m_JointAnims[j].m_NumRotationKeyframes > 0){
				anim->m_JointAnims[j].m_RotationKeyframes = new C3DKeyframe[anim->m_JointAnims[j].m_NumRotationKeyframes];
				count=0;
				for(k=0; k<m_Joints[j].m_NumRotKeyframes; k++){
					if(m_Joints[j].m_RotationKeyframes[k].m_Time*1000.0f >= StartTime && m_Joints[j].m_RotationKeyframes[k].m_Time*1000.0f <= EndTime){
						C3DKeyframe* Keyframe = &anim->m_JointAnims[j].m_RotationKeyframes[count++];
						
						Keyframe->m_JointIndex = j;
						Keyframe->m_Time = m_Joints[j].m_RotationKeyframes[k].m_Time*1000.0f - StartTime;
			
						Keyframe->m_Parameter.x = m_Joints[j].m_RotationKeyframes[k].m_Parameter[0];
						Keyframe->m_Parameter.y = m_Joints[j].m_RotationKeyframes[k].m_Parameter[1];
						Keyframe->m_Parameter.z = m_Joints[j].m_RotationKeyframes[k].m_Parameter[2];

						D3DXVec3TransformCoord(&Keyframe->m_Parameter, &Keyframe->m_Parameter, &convert);
					}
				}
			}
		}

	}
	*/

	return S_OK;
}
Exemple #24
0
bool Loader::loadFromModel(const char *fileName)
{
    printf("load %s begin\n",fileName);
    printf("parsing..\n");
    const aiScene* pScene = m_Importer.ReadFile(fileName,aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenSmoothNormals |aiProcess_CalcTangentSpace);
    this->m_pScene = (aiScene*)pScene;
    if(!m_pScene)
    {
        printf("parsing failure!\n");
        return false;
    }
    else
    {
        printf("parsing succes!\n");
        printf("extracting data to memory...\n");
        m_model = new CMC_ModelData();

        auto inverseTransform = pScene->mRootNode->mTransformation;
        inverseTransform = inverseTransform.Inverse();
        m_model->setGlobalInverseTransform (toQMatrix(inverseTransform));
        LoadMaterial(pScene,fileName);

        const aiVector3D Zero3D(0.0f, 0.0f, 0.0f);
        for(int i =0 ;i< pScene->mNumMeshes ;i++)
        {
            const aiMesh* the_mesh = pScene->mMeshes[i];
            auto mesh = new CMC_MeshData;
            m_model->addMesh(mesh);
            //set material
            mesh->setMaterialIndex (the_mesh->mMaterialIndex);
            for(int j =0; j<the_mesh->mNumVertices;j++)
            {
                const aiVector3D* pPos = &(the_mesh->mVertices[j]);
                const aiVector3D* pNormal = &(the_mesh->mNormals[j]);
                const aiVector3D* pTexCoord = the_mesh->HasTextureCoords(0) ? &(the_mesh->mTextureCoords[0][j]) : &Zero3D;
                const aiVector3D* pTangent = &(the_mesh->mTangents[i]);
                CMC_Vertex  vec;
                vec.setPos (QVector3D(pPos->x,pPos->y,pPos->z));
                vec.setNormal (QVector3D(pNormal->x,pNormal->y,pNormal->z));
                vec.setUV (QVector2D(pTexCoord->x,pTexCoord->y));
            if(pTangent)
            {
                 vec.setTangent (QVector3D(pTangent->x,pTangent->y,pTangent->z));
            }
            mesh->pushVertex (vec);
            }

            for (unsigned int k = 0 ; k < the_mesh->mNumFaces ; k++) {
                const aiFace& Face = the_mesh->mFaces[k];
                assert(Face.mNumIndices == 3);
                mesh->pushIndex (Face.mIndices[0]);
                mesh->pushIndex(Face.mIndices[1]);
                mesh->pushIndex(Face.mIndices[2]);
            }
            //load bones
            loadBoneList(the_mesh,mesh);
            //mesh->finish();
        }
        loadNodeHeirarchy(nullptr,m_pScene->mRootNode);
        loadAnimations ();
        printf("extracting finish..\n");
        return true;
    }
}
void XMLReader::LoadSceneFromFile(QFile &file, const QStringRef &local_path, Scene &scene, Integrator &integrator)
{
    if(file.open(QIODevice::ReadOnly))
    {
        QXmlStreamReader xml_reader;
        xml_reader.setDevice(&file);
        QMap<QString, QList<Geometry*>> material_to_geometry_map;
        while(!xml_reader.isEndDocument())
        {
            xml_reader.readNext();
            if(xml_reader.isStartElement())
            {
                //Get the tag name
                QString tag(xml_reader.name().toString());
                if(QString::compare(tag, QString("camera")) == 0)
                {
                    scene.SetCamera(LoadCamera(xml_reader));
                }
                else if(QString::compare(tag, QString("geometry")) == 0)
                {
                    Geometry* geometry = LoadGeometry(xml_reader, material_to_geometry_map, local_path);
                    if(geometry == NULL)
                    {
                        return;
                    }
                    scene.objects.append(geometry);
                }
                else if(QString::compare(tag, QString("material")) == 0)
                {
                    Material* material = LoadMaterial(xml_reader, local_path);
                    if(material == NULL)
                    {
                        return;
                    }
                    scene.materials.append(material);
                }
                else if(QString::compare(tag, QString("integrator")) == 0)
                {
                    integrator = LoadIntegrator(xml_reader);
                }
                else if(QString::compare(tag, QString("pixelSampler"), Qt::CaseInsensitive) == 0)
                {
                    PixelSampler* sampler = LoadPixelSampler(xml_reader);
                    if(sampler == NULL)
                    {
                        std::cout << "Did not properly load a pixel sampler!" << std::endl;
                        return;
                    }
                    if(scene.pixel_sampler != NULL)
                    {
                        delete scene.pixel_sampler;
                    }
                    scene.pixel_sampler = sampler;
                }
            }
        }
        //Associate the materials in the XML file with the geometries that use those materials.
        for(int i = 0; i < scene.materials.size(); i++)
        {
            QList<Geometry*> l = material_to_geometry_map.value(scene.materials[i]->name);
            for(int j = 0; j < l.size(); j++)
            {
                l[j]->SetMaterial(scene.materials[i]);
            }
        }

        //Copy emissive geometry from the list of objects to the list of lights
        QList<Geometry*> to_lights;
        for(Geometry *g : scene.objects)
        {
            g->create();
            if(g->material->emissive)
            {
                to_lights.append(g);
            }
        }
        for(Geometry *g : to_lights)
        {
            scene.lights.append(g);
        }
        file.close();
    }
}
Exemple #26
0
int Model::ReadAndSaveValues()
{
	int CurrentMaterial = 0 ;
	for (int i = 0; i < coords.size(); ++i)
	{
		if ( (*coords[i])[0] == '#')
			continue;
		else if ((*coords[i])[0] == 'v' && (*coords[i])[1] == ' ')//vertex
		{
			float x, y, z;
			sscanf_s(coords[i]->c_str(), "v %f %f %f", &x, &y, &z);
			vertex.push_back(new Vector3(x, y, z));
		}
		else if ((*coords[i])[0] == 'v' && (*coords[i])[1] == 'n' && ControlNormal)//normal
		{
			float x, y, z;
			sscanf_s(coords[i]->c_str(), "vn %f %f %f", &x, &y, &z);
			normals.push_back(new Vector3(x, y, z));
			IsNormal = true ;
		}
		else if ((*coords[i])[0] == 'f')//face
		{
			LoadFace(i, CurrentMaterial) ;
		}
		if(ControlMaterial)
		{
			if((*coords[i])[0] == 'u' && (*coords[i])[1] == 's' && (*coords[i])[2] == 'e') // search for material and make index equal to it 
			{
				char materialIndx[200] ;
				sscanf(coords[i]->c_str() , "usemtl %s" , materialIndx ) ;
				for(int j = 0 ; j < materials.size() ; ++j)
				{
					if(strcmp(materials[j]->name.c_str(), materialIndx) == 0 ) 
					{
						CurrentMaterial = j ;
						break ;
					}
				}
			}
			else if((*coords[i])[0] == 'm' && (*coords[i])[1] == 't' && (*coords[i])[2] == 'l' && (*coords[i])[3] == 'l') // load the materialfile
			{
				int Correct = LoadMaterial(i) ;
				if(Correct == -1) 
					return -1 ;
			}

		}
		if(ControlTexture)
			if((*coords[i])[0] == 'v' && (*coords[i])[0] == 't')
			{
				TexCoord* texloc = new TexCoord(0,0) ;
				scanf(coords[i]->c_str() , "vt %f %f" , &texloc->U , &texloc->V);
				texloc->V = 1- texloc->V ; // reverse it
				texcoordinates.push_back(texloc) ;
				IsTexture = true ;
				delete texloc ;
			}


			if(materials.size() == 0)
				IsMaterial = false ;
			else
				IsMaterial = true ;

	}
	return 0 ;
}
//-----------------------------------------------------------------------------
// Purpose: Loads this material's image from disk if it is not already loaded.
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CMaterial::Load( void )
{
	LoadMaterial();
	return true;
}
Exemple #28
0
HRESULT KModelWater::LoadMesh(LPSTR pFileName)
{
	HRESULT hr = S_OK;

	m_dwNumPoly_X = 63;     //长方形网格的长,网格数
	m_dwNumPoly_Z = 63;     //长方形网格的宽,网格数

	LPD3DXMESH pMesh = m_pWaterUp;
	LPD3DXMESH pDMesh = m_pWaterDn;

	DWORD m_dNumPloy     = m_dwNumPoly_X * m_dwNumPoly_Z;
	DWORD m_dNumFaces    = m_dNumPloy * 2;
	DWORD m_dNumVertices = (m_dwNumPoly_X+1)*(m_dwNumPoly_Z+1);

	SAFE_RELEASE(pMesh);	
	SAFE_RELEASE(pDMesh);
	WORD *pwIndices;

	//建立水面网格 
	if(FAILED(hr = g_pd3dDevice->CreateIndexBuffer(m_dNumFaces * 3 * sizeof(WORD), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 
		D3DFMT_INDEX16, D3DPOOL_DEFAULT, &m_pibIndices, NULL)))
	{
		return hr;
	}

	if (FAILED(hr = D3DXCreateMeshFVF(m_dNumFaces,m_dNumVertices,D3DXMESH_MANAGED|D3DXMESH_32BIT,
		D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_NORMAL|D3DFVF_TEX1,g_pd3dDevice,&pMesh)))
	{
		return hr;
	}	
	if (FAILED(hr = D3DXCreateMeshFVF(m_dNumFaces,m_dNumVertices,D3DXMESH_MANAGED|D3DXMESH_32BIT,
		D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_NORMAL|D3DFVF_TEX1,g_pd3dDevice,&pDMesh)))
	{
		return hr;
	}




	VFormat::FACES_NORMAL_TEXTURE1 * pVers = NULL;
	DWORD* pIndex = NULL;
	DWORD * pAttrib = NULL;	

	VFormat::FACES_NORMAL_TEXTURE1 * pDVers = NULL;
	DWORD* pDIndex = NULL;
	DWORD * pDAttrib = NULL;	
	if(FAILED(hr = m_pibIndices->Lock(0, m_dNumFaces *3 * sizeof(WORD), (void**) &pwIndices, D3DLOCK_DISCARD)))
		return E_FAIL;
	if (FAILED(pMesh->LockVertexBuffer(0,(void**)&pVers)))
		return E_FAIL;
	if (FAILED(pMesh->LockIndexBuffer (0,(void**)&pIndex)))
		return E_FAIL;
	if (FAILED(pMesh->LockAttributeBuffer(0,(DWORD**)&pAttrib)))
		return E_FAIL;

	if (FAILED(pDMesh->LockVertexBuffer(0,(void**)&pDVers)))
		return E_FAIL;
	if (FAILED(pDMesh->LockIndexBuffer (0,(void**)&pDIndex)))
		return E_FAIL;
	if (FAILED(pDMesh->LockAttributeBuffer(0,(DWORD**)&pDAttrib)))
		return E_FAIL;

	DWORD i = 0;
	float _X = 1.0f/m_dwNumPoly_X;
	float _Z = 1.0f/m_dwNumPoly_Z;

	float m_fPolyWidth  = 200;
	float m_fPolyHeight = 200;

	for(DWORD X =0;X<=m_dwNumPoly_X;X++)
	{
		for(DWORD Y =0;Y<=m_dwNumPoly_Z;Y++)
		{
			float PX = X * m_fPolyWidth;
			float PZ = Y * m_fPolyHeight;

			D3DXVECTOR2 Pos(PX,PZ);

			pVers[i].p = D3DXVECTOR3(PX,200,PZ);

			pVers[i].Normal = D3DXVECTOR3(0,1,0);

			pVers[i].tu1 = (X * _X);
			pVers[i].tv1 = (1 - Y *_Z);
			pDVers[i].p = D3DXVECTOR3(PX,0,PZ);
			pDVers[i].Normal = D3DXVECTOR3(0,1,0);
			pDVers[i].tu1 = (X * _X);
			pDVers[i].tv1 = (1 - Y *_Z);
			i++;
		}
	}

	DWORD  Weight = m_dwNumPoly_X + 1;

	for(X =0;X<m_dwNumPoly_X;X++)
	{
		for(DWORD Y =0;Y<m_dwNumPoly_Z;Y++)
		{
			DWORD PloyIndex = Y*m_dwNumPoly_X +X;

			DWORD PolyMaterialID = 0;

			DWORD Vertex_A = X    *Weight+ Y;
			DWORD Vertex_B = (X+1)*Weight+ Y;
			DWORD Vertex_C = (X+1)*Weight+(Y+1);
			DWORD Vertex_D = X    *Weight+(Y+1);

			DWORD Faces_A1 = (PloyIndex*2)*3;
			DWORD Faces_B1 = Faces_A1 + 1;
			DWORD Faces_C1 = Faces_B1 + 1;

			pIndex[Faces_A1] = Vertex_A;
			pIndex[Faces_B1] = Vertex_B;
			pIndex[Faces_C1] = Vertex_D;
			pAttrib[PloyIndex*2] = PolyMaterialID;
			pDIndex[Faces_A1] = Vertex_A;
			pDIndex[Faces_B1] = Vertex_B;
			pDIndex[Faces_C1] = Vertex_D;
			pDAttrib[PloyIndex*2] = PolyMaterialID;

			pwIndices[Faces_A1] = WORD(Vertex_A);
			pwIndices[Faces_B1] = WORD(Vertex_B);
			pwIndices[Faces_C1] = WORD(Vertex_D);

			DWORD Faces_A2 = (PloyIndex*2+1)*3;
			DWORD Faces_B2 = Faces_A2 + 1;
			DWORD Faces_C2 = Faces_B2 + 1;

			pIndex[Faces_A2] = Vertex_D;
			pIndex[Faces_B2] = Vertex_B;
			pIndex[Faces_C2] = Vertex_C;
			pAttrib[PloyIndex*2+1] = PolyMaterialID;
			pDIndex[Faces_A2] = Vertex_D;
			pDIndex[Faces_B2] = Vertex_B;
			pDIndex[Faces_C2] = Vertex_C;
			pDAttrib[PloyIndex*2+1] = PolyMaterialID;

			pwIndices[Faces_A2] = WORD(Vertex_D);
			pwIndices[Faces_B2] = WORD(Vertex_B);
			pwIndices[Faces_C2] = WORD(Vertex_C);

		}
	}	

	D3DXComputeBoundingBox((D3DXVECTOR3*)pVers,m_dNumVertices,sizeof(VFormat::FACES_NORMAL_TEXTURE1),
		&m_BBox_A,&m_BBox_B);
	D3DXComputeBoundingBox((D3DXVECTOR3*)pDVers,m_dNumVertices,sizeof(VFormat::FACES_NORMAL_TEXTURE1),
		&m_BBox_A,&m_BBox_B);

	if (FAILED(pMesh->UnlockVertexBuffer()))
		return E_FAIL;
	if (FAILED(pMesh->UnlockIndexBuffer()))
		return E_FAIL;
	if (FAILED(pMesh->UnlockAttributeBuffer()))
		return E_FAIL;

	if (FAILED(pDMesh->UnlockVertexBuffer()))
		return E_FAIL;
	if (FAILED(pDMesh->UnlockIndexBuffer()))
		return E_FAIL;
	if (FAILED(pDMesh->UnlockAttributeBuffer()))
		return E_FAIL;
	if (FAILED(m_pibIndices->Unlock()))
		return E_FAIL;
	m_pWaterUp = pMesh;		
	m_pWaterDn = pDMesh;	


	//水面网格的材质
	m_dNumMaterial = 1;
	m_lpMaterial = new MATERIAL[m_dNumMaterial];
	ZeroMemory(m_lpMaterial,sizeof(MATERIAL)*m_dNumMaterial);

	DWORD Def_Option = MATERIAL_OPTION_ZBUFFER_TRUE|
		MATERIAL_OPTION_FILL_SOLID|
		MATERIAL_OPTION_SHADE_GOURAUD|
		MATERIAL_OPTION_CULL_NONE|
		MATERIAL_OPTION_SPECULARENABLE;

	for(DWORD i=0;i<m_dNumMaterial;i++)
	{
		m_lpMaterial[i].m_sMaterial9.Diffuse.r = 0.7f ;
		m_lpMaterial[i].m_sMaterial9.Diffuse.g = 0.7f ;
		m_lpMaterial[i].m_sMaterial9.Diffuse.b = 0.7f ;
		m_lpMaterial[i].m_sMaterial9.Diffuse.a = 1.0f ;
		m_lpMaterial[i].m_sMaterial9.Ambient = m_lpMaterial[i].m_sMaterial9.Diffuse;
		m_lpMaterial[i].m_sMaterial9.Specular = m_lpMaterial[i].m_sMaterial9.Diffuse;
		m_lpMaterial[i].m_sMaterial9.Power = 15;
		m_lpMaterial[i].m_dOption = Def_Option;
	} 

	TCHAR Name[256];
	wsprintf(Name,"%s\\Water.Mtl",g_Def_ModelDirectory);
	LoadMaterial(Name);  


	//天空盒的纹理
	wsprintf(Name,"%s\\%s",g_Def_AppDirectory,"Textures\\LobbyCube.dds");
	if( FAILED( hr = D3DXCreateCubeTextureFromFile( g_pd3dDevice,Name, &m_pSkyCubeTex ) ) )
		return hr; 
	//水面的纹理
	wsprintf(Name,"%s\\%s",g_Def_AppDirectory,"Textures\\Water.bmp");
	if( FAILED( hr = D3DXCreateTextureFromFileEx(g_pd3dDevice, Name, D3DX_DEFAULT, D3DX_DEFAULT, 
		D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, 
		D3DX_DEFAULT, 0, NULL, NULL, &m_pWaterTex) ))
		return hr;
	/*
	// Effect
	wsprintf(Name,"%s\\%s",g_Def_AppDirectory,"water.fx");
	if(FAILED(hr = D3DXCreateEffectFromFile(g_pd3dDevice, Name, NULL, NULL, 0, NULL, &m_pEffect, NULL)))
	return hr;
	m_pEffect->OnResetDevice();
	m_pEffect->SetTexture("tFLR", m_pWaterTex);
	m_pEffect->SetTexture("tENV", m_pSkyCubeTex);
	*/

	//创建水面bump纹理
	if( FAILED( InitBumpMap() ) )
		return E_FAIL;
	//	m_pEffect->SetTexture("tBump", m_pBumpMapTexture);
	WSea.Initialize(m_dwNumPoly_X,m_dwNumPoly_Z);
	Water.Initialize(m_pWaterUp,m_dwNumPoly_X,m_dwNumPoly_Z);   //初始化水纹
	Water.Drop();                                               //产生水纹  
	Ripple.Initialize(m_pWaterUp,m_dwNumPoly_X,m_dwNumPoly_Z);  //初始化涟漪纹


	return S_OK;

}
ModelMaterial::ModelMaterial(Model& model, std::ifstream& inputFile)
    : mModel(model), mTextures()
{
    LoadMaterial(inputFile);
}
Exemple #30
0
bool ObjReader::LoadObj(char *szFileName)
{
	FILE *file = fopen(szFileName, "rb");

	ObjObject * obj = NULL;//模型

	char materialFile[MAX_PATH];
	char materialStr[MAX_PATH];
	char tempStr[MAX_PATH];
	char      buf[MAX_PATH];//存储读入信息
	
	Point3f position;//顶点信息
    Point3f texCoord;
    Point3f normal; 
    
    int posIndex;//三角形信息
	int texIndex;
	int norIndex;
	
	while(fscanf(file, "%s", buf) != EOF) 
	{
	  //读取数据
	  switch(buf[0]) 
	  {
	   case 'm'://材质库
	    for(int i=0;i<MAX_PATH;i++)materialFile[i] = 0;
		for(int i=0;i<MAX_PATH;i++)tempStr[i] = 0;
        fscanf(file,"%s",tempStr);
		for(int i=0;i<MAX_PATH;i++)
		{
         if(szFileName[i] =='.')
		 {
		  while(szFileName[i]!='\\'&&i>=0)i--;
          for(int j=0;j<=i;j++)
          materialFile[j] = szFileName[j];//路径
          for(int j=i+1;j<MAX_PATH;j++)
          materialFile[j] = tempStr[j-i-1];//文件名
		  break;
		 }

		}
		
		break;

	  case 'u'://材质信息
		for(int i=0;i<MAX_PATH;i++)materialStr[i] = 0;
		fscanf(file, "%s", materialStr);

		LoadMaterial(materialFile,materialStr,obj);//读取材质信息
		break;

	   case 'g'://物体
	   if(obj == NULL) 
	   {
		obj = new ObjObject;//构造新模型  
	    m_Object.push_back(obj);//存入物体
	   }
	   if(obj!=NULL && (int)obj->posIndices.size()>0)//构造新模型  
	   { 
		 obj = new ObjObject;//构造新模型 
		 m_Object.push_back(obj);
	   }
	   break;

	   case 'v':  //如果读取到 v,vt,vn 数据
		   
		 switch(buf[1]) 
	     {
		   case '\0':			//顶点坐标
			  fscanf(file, "%f %f %f", &position.X(),&position.Y(), &position.Z());  
			  Positions.push_back(position);//存储顶点信息
			  break;

		   case 't'://纹理坐标
              fscanf(file, "%f %f %f", &texCoord.X(),&texCoord.Y(), &texCoord.Z());  
			  TexCoords.push_back(texCoord);//存储纹理信息
			   break;
		   case 'n'://法线
              fscanf(file, "%f %f %f", &normal.X(),&normal.Y(), &normal.Z());  
			  Normals.push_back(normal);//存储法线信息
			  break;
		    
		  }
		 break;
		
		case 'f':	//如果读取到面数据			
		
		  fscanf(file, "%s", buf);
          //obj文件索引从1开始计数
		  if(sscanf(buf, "%d//%d", &posIndex, &norIndex)==2) //顶点,法线
		  {	
            obj->posIndices.push_back(posIndex-1);
			obj->norIndices.push_back(norIndex-1);

			fscanf(file, "%d//%d", &posIndex, &norIndex);
			obj->posIndices.push_back(posIndex-1);
			obj->norIndices.push_back(norIndex-1);

			fscanf(file, "%d//%d", &posIndex, &norIndex);
			obj->posIndices.push_back(posIndex-1);
			obj->norIndices.push_back(norIndex-1);
		   }
		  else if (sscanf(buf, "%d/%d/%d", &posIndex, &texIndex, &norIndex) == 3) //顶点 纹理 法线 
		  {
			obj->posIndices.push_back(posIndex-1);
			obj->texIndices.push_back(texIndex-1);
			obj->norIndices.push_back(norIndex-1);

			fscanf(file, "%d/%d/%d",  &posIndex, &texIndex, &norIndex);
			obj->posIndices.push_back(posIndex-1);
			obj->texIndices.push_back(texIndex-1);
			obj->norIndices.push_back(norIndex-1);

			fscanf(file, "%d/%d/%d",  &posIndex, &texIndex, &norIndex);	
			obj->posIndices.push_back(posIndex-1);
			obj->texIndices.push_back(texIndex-1);
			obj->norIndices.push_back(norIndex-1);
		  }
		  else if (sscanf(buf, "%d/%d", &posIndex, &texIndex) == 2) //顶点 纹理
		  {	
			obj->posIndices.push_back(posIndex-1);
			obj->texIndices.push_back(texIndex-1);

			fscanf(file, "%d/%d",&posIndex, &texIndex);
			obj->posIndices.push_back(posIndex-1);
			obj->texIndices.push_back(texIndex-1);
				
			fscanf(file, "%d/%d", &posIndex, &texIndex);	
			obj->posIndices.push_back(posIndex-1);
			obj->texIndices.push_back(texIndex-1);
		   } 
		   else  if(sscanf(buf, "%d", &posIndex) == 1) //顶点 
		   {
			obj->posIndices.push_back(posIndex-1);

			fscanf(file, "%d", &posIndex);
			obj->posIndices.push_back(posIndex-1);

			fscanf(file, "%d", &posIndex);
			obj->posIndices.push_back(posIndex-1); 
		   }
		  break;
	
		default:
		  fgets(buf, sizeof(buf), file);//读入一行
		  break;
		}   		
}
 fclose(file);//关闭文件
		
 return true;
}