private void ReadBones(ContentReader input) { int numSkeletonBones = input.ReadInt32(); List <SkinnedModelBone> skinnedModelBoneList = new List <SkinnedModelBone>(numSkeletonBones); // Read all bones for (int i = 0; i < numSkeletonBones; i++) { input.ReadSharedResource <SkinnedModelBone>( delegate(SkinnedModelBone skinnedBone) { skinnedModelBoneList.Add(skinnedBone); }); } // Create the skeleton skeleton = new SkinnedModelBoneCollection(skinnedModelBoneList); }
private void ReadBones(ContentReader input) { int numSkeletonBones = input.ReadInt32(); List <SkinnedModelBone> skinnedModelBoneList = new List <SkinnedModelBone>(numSkeletonBones); // Read all bones for (int i = 0; i < numSkeletonBones; i++) { input.ReadSharedResource <SkinnedModelBone>( delegate(SkinnedModelBone skinnedBone) { skinnedModelBoneList.Add(skinnedBone); }); } // Create the skeleton skeleton = new SkinnedModelBoneCollection(skinnedModelBoneList); //foreach (SkinnedModelBoneContent bone in skeleton) //output.WriteSharedResource(bone); /* * /// * /// TODO I can optimize this using write shared resource for the skeleton * /// * string rootBoneName = input.ReadString(); * int numBones = input.ReadInt32(); * * SkinnedModelBone[] tempBonesArray = new SkinnedModelBone[numBones]; * Dictionary<string, SkinnedModelBone> boneDictionary = * new Dictionary<string, SkinnedModelBone>(); * * // Read all boneDictionary * for (int i = 0; i < numBones; i++) * { * string boneName = input.ReadString(); * Matrix boneTransform = input.ReadMatrix(); * Matrix boneAbsoluteTransform = input.ReadMatrix(); * Matrix boneBindPoseTransform = input.ReadMatrix(); * * SkinnedModelBone bone = * new SkinnedModelBone(boneName, boneTransform, boneAbsoluteTransform, * boneBindPoseTransform); * * tempBonesArray[i] = bone; * boneDictionary.Add(boneName, bone); * } * * // Read the boneDictionary parent and children * for (int i = 0; i < numBones; i++) * { * // Find parent bone * SkinnedModelBone parentBone = null; * string parentBoneName = input.ReadObject<string>(); * if (parentBoneName != null) * parentBone = boneDictionary[parentBoneName]; * * tempBonesArray[i].Parent = parentBone; * * // Find children * int numChildren = input.ReadInt32(); * List<SkinnedModelBone> childrenList = new List<SkinnedModelBone>(numChildren); * for (int j = 0; j < numChildren; j++) * { * string childName = input.ReadString(); * childrenList.Add(boneDictionary[childName]); * } * * tempBonesArray[i].Children = new SkinnedModelBoneCollection(childrenList); * } * * // Store everything * tempBonesArray = null; * * rootBone = boneDictionary[rootBoneName]; * this.boneDictionary = new SkinnedModelBoneDictionary(boneDictionary); * skinnedBones = new Matrix[numBones]; * * inverseBindPose = new Matrix[numBones]; * rootBone.GetHierarchyInverseBindPoseTransfom(ref inverseBindPose); */ }