Esempio n. 1
0
 // Generates the model's tags
 private void generateTags()
 {
     // Loop through each ModelMeshPart in each ModelMesh in the model
     foreach (ModelMesh mesh in Model.Meshes)
     {
         foreach (ModelMeshPart part in mesh.MeshParts)
         {
             // Check if the ModelMeshPart's effect is a BasicEffect
             if (part.Effect is BasicEffect)
             {
                 // Get the effect
                 BasicEffect effect = (BasicEffect)part.Effect;
                 // Create a new tag using the effects properties
                 MeshTag tag = new MeshTag(effect.DiffuseColor, effect.Texture, effect.SpecularPower);
                 // Update the part's tag to the newly created one
                 part.Tag = tag;
             }
         }
     }
 }
Esempio n. 2
0
        // Set the models effect
        public void SetModelEffect(Effect effect, bool CopyEffect)
        {
            // Loop through each ModelMeshPart in each ModelMesh of the model
            foreach (ModelMesh mesh in Model.Meshes)
            {
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    // Effect to set on the ModelMeshPart
                    Effect toSet = effect;

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

                    MeshTag tag = ((MeshTag)part.Tag);

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

                    // Set remaining parameters to ones in effect
                    setEffectParameter(toSet, "DiffuseColor", tag.Color);
                    setEffectParameter(toSet, "SpecularPower", tag.SpecularPower);

                    // Set the ModelMeshPart's effect to the newly created one
                    part.Effect = toSet;
                }
            }
        }