locked
how to know the xfile has effect instance parameter RRS feed

  • 問題

  • I want to write a ModelVieer. Now it can view the moedel with BasicEffect.
    But now I want to let the ModelViewer also can view the model with effect instance and parameter(that made the model in 3ds max with DirectX Shader Materal and export model to XFile include shader parameter).
    I want my ModelViewer can judge the xfile wether use the effect instance or use basic effect? But I do not know that how to achieve this goal.

    There is my code about rendering basic effect and effect instance(light map):

    public void Draw(Matrix world, Camera camera)
    
    {
    
    	//Set transfroms
    
    	Matrix[] transforms = new Matrix[m_model.Bones.Count];
    
    	m_model.CopyAbsoluteBoneTransformsTo(transforms);
    
    
    
    	if (bEffectInstance==false)
    
    	{
    
    		//BasicEffect
    
    		
    
    		//Loop through meshes and their effects 
    
    		foreach (ModelMesh mesh in m_model.Meshes)
    
    		{
    
    			foreach (BasicEffect effect in mesh.Effects)
    
    			{
    
    				//Set BasicEffect information
    
    				effect.EnableDefaultLighting();
    
    				effect.Projection = camera.projection;
    
    				effect.View = camera.view;
    
    
    
    				//effect.World = GetWorld() * mesh.ParentBone.Transform; //<==XNA 3.0 learning //error
    
    				effect.World = transforms[mesh.ParentBone.Index] * world;//reference D:\&#25105;&#30340;&#32178;&#31449;\project\WindowsGame3D.zip<==error
    
    
    
    				//
    
    				effect.PreferPerPixelLighting = true;
    
    				effect.SpecularPower = 16;
    
    			}
    
    			//Draw
    
    			mesh.Draw();
    
    		}
    
    	}
    
    	else
    
    	{
    
    		//light map code
    
    		
    
    		//Loop through meshes and their effects 
    
    		foreach (ModelMesh mesh in m_model.Meshes)
    
    		{
    
    			//Effect
    
    			foreach (Effect effect in mesh.Effects)
    
    			{
    
    				//Set BasicEffect information
    
    				effect.CurrentTechnique = effect.Techniques["Technique1"];
    
    				effect.Begin();
    
    				effect.Parameters["World"].SetValue(world * transforms[mesh.ParentBone.Index]);
    
    				effect.Parameters["View"].SetValue(camera.view);
    
    				effect.Parameters["Projection"].SetValue(camera.projection);
    
    				effect.End();
    
    			}
    
    			//Draw
    
    			mesh.Draw();
    
    		}
    
    	}
    
    
    
    }
    
    
    
    

    2009年10月7日 下午 05:02