Access texture of model

Started by
-1 comments, last by football94 10 years, 5 months ago

Hi Guys

Ive been working with the toon shader sample from the microsoft xbox live website(link below) and wanted to apply the

effect to the skinning sample also from the website and wanted to know if there was a way to extract texture info

from a model without using the basiceffect

Thankyou

toon shader link

http://xbox.create.msdn.com/en-US/education/catalog/sample/nonrealistic_rendering

animated model link

http://xbox.create.msdn.com/en-US/education/catalog/sample/skinned_model

portion of code wanting to modify from this:


 foreach (BasicEffect oldEffect in mesh.Effects)

To this and still be able to access the texture of the animated model


 foreach (Effect oldEffect in mesh.Effects)

complete code


  static void ChangeEffectUsedByModel(Model model, Effect replacementEffect)
        {
            // Table mapping the original effects to our replacement versions.
            Dictionary<Effect, Effect> effectMapping = new Dictionary<Effect, Effect>();

            foreach (ModelMesh mesh in model.Meshes)
            {
                // Scan over all the effects currently on the mesh.
                foreach (BasicEffect oldEffect in mesh.Effects)
                {
                    // If we haven't already seen this effect...
                    if (!effectMapping.ContainsKey(oldEffect))
                    {
                        // Make a clone of our replacement effect. We can't just use
                        // it directly, because the same effect might need to be
                        // applied several times to different parts of the model using
                        // a different texture each time, so we need a fresh copy each
                        // time we want to set a different texture into it.
                        Effect newEffect = replacementEffect.Clone(
                                                    replacementEffect.GraphicsDevice);

                        // Copy across the texture from the original effect.
                        newEffect.Parameters["Texture"].SetValue(oldEffect.Texture);

                        newEffect.Parameters["TextureEnabled"].SetValue(
                                                            oldEffect.TextureEnabled);

                        effectMapping.Add(oldEffect, newEffect);
                    }
                }

                // Now that we've found all the effects in use on this mesh,
                // update it to use our new replacement versions.
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    meshPart.Effect = effectMapping[meshPart.Effect];
                }
            }
        }


This topic is closed to new replies.

Advertisement