public virtual UWB_Material SetMaterial(ref UWB_Material m) { UWB_Material old = m_Material; m_Material = m; return(old); }
public UWB_Primitive() { mVisible = true; mVelocity = Vector3.Zero; mFlatColor = Color.Black; mShadingColor = Color.White; mFillMode = eFillMode.fmSolid; mShadeMode = eShadeMode.smGouraud; mPointSize = 2f; m_bBlendingEnabled = false; m_bLightingEnabled = true; m_Material = new UWB_Material(); }
public virtual void DrawMesh(bool bShowflatColor, Color MaterialColor, UWB_DrawHelper drawHelper) { UWB_XNAGraphicsDevice graphics = UWB_XNAGraphicsDevice.m_TheAPI; GraphicsDevice device = UWB_XNAGraphicsDevice.m_TheAPI.GraphicsDevice; UWB_XNAEffect effect = UWB_XNAGraphicsDevice.m_TheAPI.LightingEffect; SetupDrawAttributes(drawHelper); UWB_Material material = this.m_Material; //if (bShowflatColor && !m_bTexturingEnabled) //{ // material = new UWB_Material(Color.Gray.ToVector4(), // Color.Gray.ToVector4(), // Color.Gray.ToVector4(), // Color.White.ToVector4(), 1f); // material.Emissive = MaterialColor.ToVector4(); //} /* If texturing is enabled, there are two option... one is that * there has been a texture set for the mesh, and another is that * the mesh has a texture defined inside the mesh file. In the * second case, this only checks the FIRST mesh part and uses the * FIRST texture. */ Texture2D texture = null; if (this.m_bTexturingEnabled) { texture = UWB_XNAGraphicsDevice.m_TheAPI.RetrieveTexture(m_TexFileName); BasicEffect meshEffect = (mesh.Meshes[0].MeshParts[0].Effect as BasicEffect); Texture2D partTexture = meshEffect.Texture; // If there is no supplied texture then use the texture and material of the first mesh part if (texture == null && partTexture != null) { texture = partTexture; material.Ambient = new Vector4(meshEffect.AmbientLightColor, meshEffect.Alpha); material.Diffuse = new Vector4(meshEffect.DiffuseColor, meshEffect.Alpha); material.Emissive = new Vector4(meshEffect.EmissiveColor, meshEffect.Alpha); material.Specular = new Vector4(meshEffect.SpecularColor, meshEffect.Alpha); material.Power = meshEffect.SpecularPower; } } effect.Material = material; if (texture != null) { effect.Texture = texture; effect.TextureEnabled = true; } else { effect.Texture = texture; effect.TextureEnabled = false; } for (int m = 0; m < mesh.Meshes.Count; m++) { for (int part = 0; part < mesh.Meshes[m].MeshParts.Count; part++) { ModelMeshPart mp = mesh.Meshes[m].MeshParts[part]; device.Indices = mp.IndexBuffer; device.SetVertexBuffer(mp.VertexBuffer); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); device.DrawIndexedPrimitives(PrimitiveType.TriangleList, mp.VertexOffset, 0, mp.NumVertices, mp.StartIndex, mp.PrimitiveCount); } } } }
public virtual UWB_Material SetMaterial(ref UWB_Material m) { UWB_Material old = m_Material; m_Material = m; return old; }