Exemplo n.º 1
0
        /// <summary>
        /// Sets a specific effect to a model
        /// </summary>
        /// <param name="effect">The effect to apply to the model</param>
        /// <param name="CopyEffect">Wether or not we copy the effect</param>
        public void SetModelEffect(Effect effect, bool CopyEffect)
        {
            List <Texture2D> list = new List <Texture2D>();

            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)
                    {
                        string newName = mesh.Name.Split('_')[0];
                        if (_textures.ContainsKey(newName))
                        {
                            tag.Texture = _textures[newName];
                        }
                        else if (_textures.ContainsKey("ApplyAllMesh"))
                        {
                            tag.Texture = _textures["ApplyAllMesh"];
                        }

                        setEffectParameter(toSet, "BasicTexture", tag.Texture);
                        setEffectParameter(toSet, "TextureEnabled", true);
                        list.Add(tag.Texture);
                    }
                    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;
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Generate tags
 /// </summary>
 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;
             }
         }
     }
 }