drawing model that does not use a texture

Mar 31, 2011 at 7:33 AM

Hi,

I am migrating a game from xna 3.1 to xna 4. Hence I changed to the dev version of xnanimation.

I have a model created in Blender, exported to fbx format. I had no problem drawing it with the old version of xnanimation.

But since in the new version the shader code was probably changed and since the model does not use a texture (consequently does not have an uv map),

I get following error: (in SkinnedModelMesh.cs line 66)

"The current vertex declaration does not include all the elements required by the current vertex shader. TextureCoordinate0 is missing."

The model is supposed to be colored depending on the player. Following code was working in xna 3.1 with the former version of xnanimation:

            Matrix[] boneTransforms = new Matrix[skinnedModel.Model.Bones.Count];
            skinnedModel.Model.CopyAbsoluteBoneTransformsTo(boneTransforms);         

            foreach (ModelMesh modelMesh in skinnedModel.Model.Meshes)
            {
                foreach (SkinnedModelBasicEffect effect in modelMesh.Effects)
                {
                    effect.World = boneTransforms[modelMesh.ParentBone.Index] *
                        Matrix.CreateTranslation(Position3D) *
                        Matrix.CreateTranslation(ModelOffset);
                    effect.View = cameraView;
                    effect.Projection = cameraProjection;

                    // Set the animated bones to the model
                    effect.Bones = animationController.SkinnedBoneTransforms;

                    // Configure material
                    if (effect.Material.SpecularPower > 100)
                    {
                        int colorIndex = (int)(effect.Material.SpecularPower - 101);
                        if (colorIndex == 0 || upgrades[colorIndex - 1] == null)
                        {
                            effect.Material.DiffuseColor = ObjectOwner.PlayerColor;
                        }
                        else
                        {
                            effect.Material.DiffuseColor = upgrades[colorIndex-1].UpgradeColor;
                        }
                    }

                }
                // Draw a model mesh
                modelMesh.Draw();
            }

/* sorry I didn't insert as code snippet, but it didn't work in my browser

now I'm trying to use following code:

            Matrix[] boneTransforms = new Matrix[skinnedModel.SkeletonBones.Count];
            skinnedModel.BoneTransforms.CopyTo(boneTransforms,0);
            skinnedModel.World = Matrix.CreateTranslation(Position3D) *
                       Matrix.CreateTranslation(ModelOffset);
            skinnedModel.View = cameraView;
            skinnedModel.Projection = cameraProjection;
            // Set the animated bones to the model
            skinnedModel.BoneTransforms = animationController.SkinnedBoneTransforms;
            foreach (SkinnedModelMesh modelMesh in skinnedModel.Meshes)
            {
                // Configure material
                if (modelMesh.Effect.Material.SpecularPower > 100)
                {
                    int colorIndex = (int)(modelMesh.Effect.Material.SpecularPower - 101);
                    if (colorIndex == 0 || upgrades[colorIndex - 1] == null)
                    {
                        modelMesh.Effect.Material.DiffuseColor = ObjectOwner.PlayerColor;
                    }
                    else
                    {
                        modelMesh.Effect.Material.DiffuseColor = upgrades[colorIndex - 1].UpgradeColor;
                    }
                }
                    modelMesh.Effect.NormalMapEnabled =false;
                    modelMesh.Effect.SpecularMapEnabled = false;
                    modelMesh.Effect.DiffuseMapEnabled = false;
                // Draw a model mesh
               // modelMesh.Draw();
            }
            //Draw Model
            skinnedModel.Draw();

I searched a long time through the internet, but didn't find any solution to it. I don't have the model source, so I can not create those coordinates.

I'd rather know: How do I draw this model with the new version of xnanimation?

Thanks in advance,

nomisge

Apr 10, 2011 at 4:46 PM

does somebody at least have a hint at where to look deeper into the xnanimation code to fix this behavior?

Or does anybody have a similiar problem?

Greetz,

nomisge