public void XfbinClose(int xfbinNo) { BoneIDs.Clear(); BoneNames.Clear(); bones1Label.Text = "No bones loaded"; if (xfbinNo == 1) { mesh1Box.Items.Clear(); xfbin1Box.Text = ""; mesh1IndexLabel.Text = ""; group1Label.Text = ""; groups1Label.Text = ""; mat1Label.Text = ""; formatByte1Label.Text = ""; meshCount1 = 0; if (xfbin1Open) { file1Bytes.Clear(); meshList1.Clear(); xfbin1Groups.Clear(); groupsBox.Items.Clear(); } xfbin1Open = false; } else if (xfbinNo == 2) { mesh2Box.Items.Clear(); xfbin2Box.Text = ""; mesh2IndexLabel.Text = ""; group2Label.Text = ""; groups2Label.Text = ""; mat2Label.Text = ""; formatByte2Label.Text = ""; meshCount2 = 0; if (xfbin2Open) { file2Bytes.Clear(); meshList2.Clear(); xfbin2Groups.Clear(); } xfbin2Open = false; nudOpen = false; } }
//-------------------------------------------------------------- #region Methods //-------------------------------------------------------------- /// <summary> /// Initializes the skeleton. /// </summary> /// <param name="boneParents">The bone parents.</param> /// <param name="boneNames">The bone names.</param> /// <param name="bindPosesRelative">The bind poses.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="boneParents"/>, <paramref name="boneNames"/> or /// <paramref name="bindPosesRelative"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException"> /// Either the given lists are empty, have different length, or the /// <paramref name="boneParents"/> are invalid (parent bones must come be before their child /// bones). /// </exception> internal void Initialize(IList <int> boneParents, IList <string> boneNames, IList <SrtTransform> bindPosesRelative) { if (boneParents == null) { throw new ArgumentNullException("boneParents"); } if (boneNames == null) { throw new ArgumentNullException("boneNames"); } if (bindPosesRelative == null) { throw new ArgumentNullException("bindPosesRelative"); } var numberOfBones = boneParents.Count; if (numberOfBones == 0) { throw new ArgumentException("boneParents list must not be empty."); } if (boneNames.Count == 0) { throw new ArgumentException("boneNames list must not be empty."); } if (bindPosesRelative.Count == 0) { throw new ArgumentException("bindPosesRelative list must not be empty."); } if (numberOfBones != boneNames.Count || numberOfBones != bindPosesRelative.Count) { throw new ArgumentException("The lists must have the same number of elements."); } // Check if bone parents come before children. This ordering also forbids cycles. for (int index = 0; index < numberOfBones; index++) { var parentIndex = boneParents[index]; if (parentIndex >= index) { throw new ArgumentException("Invalid boneParents list. Parent bones must have a lower index than child bones."); } } // Build list of bone nodes. Bones = new Bone[numberOfBones]; var children = new List <int>(); for (int index = 0; index < numberOfBones; index++) { Bone bone = new Bone(); // Set parent index. int parentIndex = boneParents[index]; if (parentIndex < -1) { parentIndex = -1; } bone.Parent = parentIndex; // Create array of child indices. children.Clear(); for (int childIndex = index + 1; childIndex < numberOfBones; childIndex++) { if (boneParents[childIndex] == index) { children.Add(childIndex); } } if (children.Count > 0) { bone.Children = children.ToArray(); } Bones[index] = bone; } // Initialize bone name/index dictionary. if (BoneNames == null) { BoneNames = new Dictionary <string, int>(numberOfBones); } else { BoneNames.Clear(); } for (int index = 0; index < numberOfBones; index++) { var name = boneNames[index]; if (name != null) { BoneNames[name] = index; } } // Copy relative bind poses. if (BindPosesRelative == null) { BindPosesRelative = new SrtTransform[numberOfBones]; } for (int index = 0; index < numberOfBones; index++) { BindPosesRelative[index] = bindPosesRelative[index]; } // Initialize absolute bind poses (inverse). if (BindPosesAbsoluteInverse == null) { BindPosesAbsoluteInverse = new SrtTransform[numberOfBones]; } // First store the non-inverted BindTransforms in model space. BindPosesAbsoluteInverse[0] = BindPosesRelative[0]; for (int index = 1; index < numberOfBones; index++) { var parentIndex = Bones[index].Parent; //BindPosesAbsoluteInverse[index] = BindPosesAbsoluteInverse[parentIndex] * BindPosesRelative[index]; SrtTransform.Multiply(ref BindPosesAbsoluteInverse[parentIndex], ref BindPosesRelative[index], out BindPosesAbsoluteInverse[index]); } // Invert matrices. for (int index = 0; index < numberOfBones; index++) { BindPosesAbsoluteInverse[index].Invert(); } }