public InstancedSkinnedModelContent(ModelContent model, InstancedSkinningDataContent instancedSkinningInfo) { this.modelContent = model; this.instancedSkinningData = instancedSkinningInfo; }
/// <summary> /// The main Process method converts an intermediate format content pipeline /// NodeContent tree to a ModelContent object with embedded animation data. /// </summary> public override InstancedSkinnedModelContent Process(NodeContent input, ContentProcessorContext context) { ValidateMesh(input, context, null); // Find the skeleton. BoneContent skeleton = MeshHelper.FindSkeleton(input); if (skeleton == null) { throw new InvalidContentException("Input skeleton not found."); } //Bake the transforms so everything is in the same coordinate system FlattenTransforms(input, skeleton); // This is a helper function that wasn't in the SkinnedModelSample, // but was implemented here. Go through and remove meshes that don't have bone weights RemoveInvalidGeometry(input, context); // Read the bind pose and skeleton hierarchy data. IList <BoneContent> bones = MeshHelper.FlattenSkeleton(skeleton); // Collect bone information foreach (BoneContent bone in bones) { bindPose.Add(bone.Transform); inverseBindPose.Add(Matrix.Invert(bone.AbsoluteTransform)); skeletonHierarchy.Add(bones.IndexOf(bone.Parent as BoneContent)); } // We're going to keep a list of all the rows of animation matrices // We'll eventually turn this list into a texture List <Matrix[]> keyFrameMatrices = new List <Matrix[]>(); // Get a list of animation clips, and at the same time, populate our keyFrameMatrices list Dictionary <string, InstancedAnimationClip> animationClips; animationClips = ProcessAnimations(skeleton.Animations, bones, keyFrameMatrices); // Create a content object that will hold the animation texture data PixelBitmapContent <Vector4> animationContent = GetEncodedTexture(keyFrameMatrices, bones.Count); // Create a texture 2D content object, and populate it with our data TextureContent animationTexture = new Texture2DContent(); animationTexture.Faces[0].Add(animationContent); // We're going to create an instance of the original ModelProcessor, // with our minor material modification. The reason we do this is that // the ModelProcessor does the heavy lifting for us of doing some BoneWeight // stuff, and we don't want to reimplement that when ModelProcessor does // such a fine job! ModelProcessor processor = new ModifiedModelProcessor(); // Chain to the base ModelProcessor class so it can convert the model data. ModelContent model = processor.Process(input, context); InstancedSkinningDataContent data = new InstancedSkinningDataContent(animationClips, animationTexture); InstancedSkinnedModelContent instancedModel = new InstancedSkinnedModelContent(model, data); return(instancedModel); }