public void Draw(GraphicsDevice graphicsDevice, Matrix view, Matrix projection) { graphicsDevice.RenderState.FogEnable = false; graphicsDevice.RenderState.AlphaBlendEnable = true; graphicsDevice.RenderState.AlphaTestEnable = true; graphicsDevice.RenderState.AlphaSourceBlend = Blend.SourceAlpha; graphicsDevice.RenderState.AlphaDestinationBlend = Blend.One; graphicsDevice.RenderState.AlphaBlendOperation = BlendFunction.Add; graphicsDevice.RenderState.BlendFunction = BlendFunction.Add; //graphicsDevice.RenderState.DepthBufferWriteEnable = false; //graphicsDevice.RenderState.CullMode = CullMode.CullClockwiseFace; //graphicsDevice.RenderState.FillMode = FillMode.Solid; graphicsDevice.VertexDeclaration = vertexDeclaration; Matrix WorldViewProj = world * view * projection; effect.Begin(); worldViewProjParam.SetValue(WorldViewProj); textureParam.SetValue(texture); if (worldParam != null) { worldParam.SetValue(world); } effect.CommitChanges(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); graphicsDevice.Indices = indexBuffer; graphicsDevice.Vertices[0].SetSource(vertexBuffer, 0, VertexPositionNormalTexture.SizeInBytes); graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertex.Length, 0, vertex.Length / 2); pass.End(); } effect.End(); //graphicsDevice.RenderState.DepthBufferWriteEnable = true; if (boundingBox != null) { boundingBox.Draw(graphicsDevice, world, view, projection); } }
/// <summary> /// Draw Mesh /// </summary> /// <param name="view">Camera view matrix</param> /// <param name="projection">Camera projection matrix</param> public virtual void Draw(GraphicsDevice graphicsDevice, Matrix view, Matrix projection) { graphicsDevice.RenderState.FogEnable = true; graphicsDevice.RenderState.DepthBufferEnable = true; graphicsDevice.RenderState.AlphaBlendEnable = false; graphicsDevice.RenderState.AlphaTestEnable = false; graphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace; graphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap; graphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap; graphicsDevice.SamplerStates[0].AddressW = TextureAddressMode.Wrap; if (model != null) { if (bHasAlpha) { graphicsDevice.RenderState.AlphaBlendEnable = true; graphicsDevice.RenderState.SourceBlend = Blend.One; graphicsDevice.RenderState.DestinationBlend = Blend.One; } if (effect != null) { #region Draw Model using Effect effect.Begin(); foreach (EffectPass pass in effect.Techniques[0].Passes) { pass.Begin(); Matrix WorldViewProj = world * view * projection; worldViewProjParam.SetValue(WorldViewProj); if (worldParam != null) { worldParam.SetValue(world); } textureParam.SetValue(texture); effect.CommitChanges(); DrawMesh(); pass.End(); } effect.End(); if (boundingBox != null) { boundingBox.Draw(graphicsDevice, world, view, projection); } #endregion } else { #region Draw Model using BasicEffect foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect basicEffect in mesh.Effects) { basicEffect.World = world; basicEffect.View = view; basicEffect.Projection = projection; basicEffect.TextureEnabled = true; basicEffect.Texture = texture; basicEffect.EnableDefaultLighting(); basicEffect.VertexColorEnabled = false; basicEffect.DiffuseColor = Vector3.One; basicEffect.CommitChanges(); } mesh.Draw(); } if (boundingBox != null) { boundingBox.Draw(graphicsDevice, world, view, projection); } #endregion } if (bHasAlpha) { graphicsDevice.RenderState.AlphaBlendEnable = false; } } }