public override void Draw(GameTime gameTime, Effect effect) { if (meshData != null) { if (meshData.Keys.Contains("SkinningData") && animationPlayer == null) { animationPlayer = new AnimationPlayer((SkinningData)meshData["SkinningData"]); if (!string.IsNullOrEmpty(AnimationClip)) animationPlayer.StartClip(animationPlayer.skinningDataValue.AnimationClips[AnimationClip]); } } if (animationPlayer != null) { bones = animationPlayer.GetSkinTransforms(); if (effect.Parameters["Bones"] != null) effect.Parameters["Bones"].SetValue(bones); if (effect.CurrentTechnique.Name == "ShadowMap") // Shadow Map { } else { if (effect.Parameters["vp"] != null) effect.Parameters["vp"].SetValue(Camera.View * Camera.Projection); if (effect.Parameters["v"] != null) effect.Parameters["v"].SetValue(Camera.View); if (effect.Parameters["p"] != null) effect.Parameters["p"].SetValue(Camera.Projection); } } base.Draw(gameTime, effect); }
protected override void LoadContent() { base.LoadContent(); thisMesh = AssetManager.GetAsset<Model>(mesh); meshData = (Dictionary<string, object>)thisMesh.Tag; transforms = new Matrix[thisMesh.Bones.Count]; thisMesh.CopyAbsoluteBoneTransformsTo(transforms); effect = AssetManager.GetAsset<Effect>("Shaders/Deferred/DeferredInstanceSkinnedShader"); //effect = AssetManager.GetAsset<Effect>("Shaders/Deferred/DeferredInstanceShader"); effect.CurrentTechnique = effect.Techniques["BasicTextureH"]; Dictionary<string, object> TagData = (Dictionary<string, object>)thisMesh.Tag; Dictionary<int, List<Vector3>> p = (Dictionary<int, List<Vector3>>)TagData["Vertices"]; Dictionary<int, List<Vector3>> n = (Dictionary<int, List<Vector3>>)TagData["Normals"]; Dictionary<int, List<Vector2>> t = (Dictionary<int, List<Vector2>>)TagData["TexCoords"]; Dictionary<int, List<Vector3>> tang = (Dictionary<int, List<Vector3>>)TagData["Tangents"]; Dictionary<int, List<Vector3>> bin = (Dictionary<int, List<Vector3>>)TagData["BiNormals"]; Dictionary<int, List<int>> i = (Dictionary<int, List<int>>)TagData["Inicies"]; Dictionary<int, List<Vector4>> bi = (Dictionary<int, List<Vector4>>)TagData["BlendIndex"]; Dictionary<int, List<Vector4>> bw = (Dictionary<int, List<Vector4>>)TagData["BlendWeight"]; animationPlayer = new AnimationPlayer((SkinningData)meshData["SkinningData"], AnimationOffSet); if (!string.IsNullOrEmpty(AnimationClip)) animationPlayer.StartClip(animationPlayer.skinningDataValue.AnimationClips[AnimationClip]); // Build Vert Elemets List<VertexPositionNormalTextureInstance> verts = new List<VertexPositionNormalTextureInstance>(); List<int> indx = new List<int>(); List<VertexPositionNormalTextureInstance> partVerts = new List<VertexPositionNormalTextureInstance>(); List<int> partIndx = new List<int>(); for (int d = 0; d < p.Count; d++) { partVerts.Clear(); partIndx.Clear(); for (int v = 0; v < p[d].Count; v++) { verts.Add(new VertexPositionNormalTextureInstance(p[d][v], n[d][v], tang[d][v], t[d][v], bi[d][v], bw[d][v])); indx.Add(i[d][v]); partVerts.Add(new VertexPositionNormalTextureInstance(p[d][v], n[d][v], tang[d][v], t[d][v], bi[d][v], bw[d][v])); partIndx.Add(i[d][v]); } partVertexBuffer.Add(new VertexBuffer(Game.GraphicsDevice, typeof(VertexPositionNormalTextureInstance), partVerts.Count, BufferUsage.WriteOnly)); partVertexBuffer[partVertexBuffer.Count-1].SetData(partVerts.ToArray()); partIndexBuffer.Add(new IndexBuffer(Game.GraphicsDevice, IndexElementSize.ThirtyTwoBits, partIndx.Count, BufferUsage.WriteOnly)); partIndexBuffer[partIndexBuffer.Count-1].SetData(partIndx.ToArray()); } vertCount = verts.Count; modelVertexBuffer = new VertexBuffer(Game.GraphicsDevice, typeof(VertexPositionNormalTextureInstance), vertCount, BufferUsage.WriteOnly); modelVertexBuffer.SetData(verts.ToArray()); indexBuffer = new IndexBuffer(Game.GraphicsDevice, IndexElementSize.ThirtyTwoBits, indx.Count, BufferUsage.WriteOnly); indexBuffer.SetData(indx.ToArray()); }