public void GetBoneMatrix(string name, out Matrix mat) { SkinningModelLibrary.SkinningData data = (SkinningModelLibrary.SkinningData)((object[])this.LODs[0].Tag)[0]; if (data == null) { mat = Matrix.Identity; Debug.Log("CUSTOMMODEL: Error, trying to get bone matrix for non-skinned model."); return; } Dictionary <string, int> dic = data.BoneNameToID; int id; bool result = dic.TryGetValue(name, out id); if (!result) { mat = Matrix.Identity; Debug.Log("CUSTOMMODEL: Given bone name not present in bone dictionary."); return; } if (MyObject.MyAnimator == null) { mat = data.BindPose[id]; } else { mat = MyObject.MyAnimator.GetWorldTransforms()[id]; } }
/// <summary> /// Loads animation clip from Model object, when we load just an animated skeleton from Animations folder /// </summary> /// <param name="model"></param> /// <param name="animation"></param> /// <param name="newName"></param> /// <returns></returns> public KeyValuePair <string, SkinningModelLibrary.AnimationClip> LoadAnimationFromModel(Model model, Model animation, string newName) { // need to extract AnimationClips from animation and save it into new SkinningData with the rest // of the data from original skinned Model. if ((model.Tag as object[])[0] == null || (animation.Tag as object[])[0] == null) { throw new InvalidOperationException("Either destination model or animation is not a skinned model"); } SkinningModelLibrary.SkinningData modelData = (model.Tag as object[])[0] as SkinningModelLibrary.SkinningData; SkinningModelLibrary.SkinningData animationData = (animation.Tag as object[])[0] as SkinningModelLibrary.SkinningData; if (modelData.SkeletonHierarchy.Count != animationData.SkeletonHierarchy.Count) { throw new InvalidOperationException("Model hierarchy is not the same as the animation's"); } return(new KeyValuePair <string, SkinningModelLibrary.AnimationClip>(newName, animationData.AnimationClips.Values.ElementAt(0))); }