public override ModelContent Process(NodeContent input, ContentProcessorContext context) { CompileRegularExpressions(); context.Logger.LogMessage("Output Platform: {0}", context.TargetPlatform); maxScale_ = 0; maxOffset_ = 0; BoneContent skeleton = MeshHelper.FindSkeleton(input); FlattenTransforms(input, skeleton, context); SkinnedBone[] inverseBindPose = GetInverseBindPose(input, context, skeleton); context.Logger.LogMessage("Found {0} skinned bones in skeleton.", (inverseBindPose == null) ? 0 : inverseBindPose.Length); ModelContent output = base.Process(input, context); if (output.Tag == null) { output.Tag = new Dictionary <string, object>(); } if (FoundSkinning) { #if DEBUG StringBuilder strb = new StringBuilder(); #endif if (inverseBindPose == null) { throw new System.Exception("Could not find skeleton although there is skinned data."); } for (int i = 0; i != inverseBindPose.Length; ++i) { SkinnedBone sb = inverseBindPose[i]; int q = 0; sb.Index = -1; foreach (ModelBoneContent mbc in output.Bones) { if (mbc.Name == sb.Name) { sb.Index = mbc.Index; break; } ++q; } if (sb.Index == -1) { throw new System.ArgumentException( String.Format("Can't find the index for animated bone named {0}.", sb.Name)); } inverseBindPose[i] = sb; } ((Dictionary <string, object>)output.Tag).Add("InverseBindPose", inverseBindPose); } ((Dictionary <string, object>)output.Tag).Add("AnimationSet", BuildAnimationSet(input, ref output, context)); ((Dictionary <string, object>)output.Tag).Add("BoundsInfo", new BoundsInfo(maxScale_, maxOffset_)); return(output); }
protected virtual SkinnedBone[] GetInverseBindPose(NodeContent input, ContentProcessorContext context, BoneContent skeleton) { if (skeleton == null) { return(null); } IList <BoneContent> original = MeshHelper.FlattenSkeleton(skeleton); if (original.Count > maxNumBones_) { throw new System.ArgumentException(String.Format( "The animation processor found {0} bones in the skeleton; a maximum of {1} is allowed.", original.Count, maxNumBones_)); } List <SkinnedBone> inversePose = new List <SkinnedBone>(); foreach (BoneContent bc in original) { SkinnedBone sb = new SkinnedBone(); sb.Name = bc.Name; if (sb.Name == null) { throw new System.ArgumentNullException("Bone with null name found."); } sb.InverseBindTransform = Matrix.Invert(GetAbsoluteTransform(bc, null)); inversePose.Add(sb); } return(inversePose.ToArray()); }
private void LoadBone(SkinnedBone parentBone, ColladaBone colladaBone) { SkinnedBone bone = new SkinnedBone(); bone.num = skinnedModel.Bones.Count; skinnedModel.Bones.Add(bone); bone.parent = parentBone; if (parentBone != null) { parentBone.children.Add(bone); } bone.initialMatrix = colladaBone.initialMatrix; bone.invBoneSkinMatrix = colladaBone.invBoneSkinMatrix; bone.animationMatrices = colladaBone.animationMatrices; bone.finalMatrix = bone.GetMatrixRecursively(); for (int i = 0; i < colladaBone.children.Count; i++) { LoadBone(bone, colladaBone.children[i]); } }
protected virtual SkinnedBone[] GetInverseBindPose(NodeContent input, ContentProcessorContext context, BoneContent skeleton) { if (skeleton == null) return null; IList<BoneContent> original = MeshHelper.FlattenSkeleton(skeleton); if (original.Count > maxNumBones_) throw new System.ArgumentException(String.Format( "The animation processor found {0} bones in the skeleton; a maximum of {1} is allowed.", original.Count, maxNumBones_)); List<SkinnedBone> inversePose = new List<SkinnedBone>(); foreach (BoneContent bc in original) { SkinnedBone sb = new SkinnedBone(); sb.Name = bc.Name; if (sb.Name == null) throw new System.ArgumentNullException("Bone with null name found."); sb.InverseBindTransform = Matrix.Invert(GetAbsoluteTransform(bc, null)); inversePose.Add(sb); } return inversePose.ToArray(); }