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; } } }
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; } } } }