/// <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) { 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; } } }
/// <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; } } } }