Ejemplo n.º 1
0
        public void SetModelEffect(Effect effect, bool copyEffect)
        {
            foreach (ModelMesh mesh in Model.Meshes)
            {
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    Effect toSet = effect;

                    // Copy the effect if necessary
                    if (copyEffect)
                    {
                        toSet = effect.Clone();
                    }

                    MeshTag tag = (MeshTag)part.Tag;

                    // if this ModelMeshPart has a texture, set it to the effect
                    if (tag.Texture != null)
                    {
                        SetEffectParameter(toSet, "BasicTexture", tag.Texture);
                        SetEffectParameter(toSet, "TextureEnabled", true);
                    }
                    else
                    {
                        SetEffectParameter(toSet, "TextureEnabled", false);
                    }

                    // Set our remaining parameters to the effect
                    SetEffectParameter(toSet, "diffuseColor", tag.Color);
                    SetEffectParameter(toSet, "SpecularPower", tag.SpecularPower);

                    part.Effect = toSet;
                }
            }
        }
Ejemplo n.º 2
0
 private void GenerateTags()
 {
     foreach (ModelMesh mesh in Model.Meshes)
     {
         foreach (ModelMeshPart part in mesh.MeshParts)
         {
             if (part.Effect is BasicEffect)
             {
                 BasicEffect effect = (BasicEffect)part.Effect;
                 MeshTag     tag    = new MeshTag(effect.DiffuseColor, effect.Texture, effect.SpecularPower);
                 part.Tag = tag;
             }
         }
     }
 }