public static odfBoneList ParseBoneList(BinaryReader reader, int formatType) { ObjectName name = new ObjectName(reader.ReadBytes(64)); ObjectID id = new ObjectID(reader.ReadBytes(4)); ObjectID frameId = new ObjectID(reader.ReadBytes(4)); ObjectID meshObjId = new ObjectID(reader.ReadBytes(4)); int numBones = reader.ReadInt32(); odfBoneList boneList = new odfBoneList(name, id, numBones); boneList.MeshFrameId = frameId; boneList.SubmeshId = meshObjId; if (formatType >= 10) { boneList.AlwaysZero4 = reader.ReadBytes(4); } for (int boneIdx = 0; boneIdx < numBones; boneIdx++) { id = new ObjectID(reader.ReadBytes(4)); odfBone bone = new odfBone(id); int numberIndices = reader.ReadInt32(); bone.AlwaysZero24perIndex = reader.ReadBytes(24 * numberIndices); bone.VertexIndexArray = reader.ReadInt32Array(numberIndices); bone.WeightArray = reader.ReadSingleArray(numberIndices); bone.Matrix = reader.ReadMatrix(); boneList.AddChild(bone); } return(boneList); }
public void CopyBone(int boneListIdx, int boneIdx) { odfBoneList boneList = Parser.EnvelopeSection[boneListIdx]; odfBone bone = boneList[boneIdx]; boneList.AddChild(bone.Clone()); }
public static void MergeBoneLists(odfMesh mesh, Dictionary <ObjectID, ObjectID> submeshIDtrans, odfParser parser) { foreach (odfSubmesh submesh in mesh) { ObjectID baseSubmeshId = submeshIDtrans[submesh.Id]; for (int i = 0; i < parser.EnvelopeSection.Count; i++) { odfBoneList boneList = parser.EnvelopeSection[i]; if (boneList.SubmeshId == baseSubmeshId) { Dictionary <int, int> boneDic = new Dictionary <int, int>(boneList.Count); for (int j = 0; j < boneList.Count; j++) { odfBone bone = boneList[j]; boneDic.Add((int)bone.FrameId, j); } for (int j = i + 1; j < parser.EnvelopeSection.Count; j++) { odfBoneList boneList2 = parser.EnvelopeSection[j]; if (boneList2.SubmeshId == submesh.Id) { foreach (odfBone bone in boneList2) { int boneIdx; if (boneDic.TryGetValue((int)bone.FrameId, out boneIdx)) { boneList.RemoveChild(boneIdx); boneList.InsertChild(boneIdx, bone); } else { boneList.AddChild(bone); boneDic.Add((int)bone.FrameId, boneDic.Count); } } parser.EnvelopeSection.RemoveChild(boneList2); } } break; } else { Report.ReportLog("wrong"); } } } }
public odfBoneList Clone() { odfBoneList boneList = new odfBoneList(Name, Id, Count); boneList.MeshFrameId = new ObjectID(MeshFrameId); boneList.SubmeshId = new ObjectID(SubmeshId); if (AlwaysZero4 != null) { boneList.AlwaysZero4 = (byte[])AlwaysZero4.Clone(); } foreach (odfBone bone in this) { odfBone newBone = bone.Clone(); boneList.AddChild(newBone); } return(boneList); }
public static odfBoneList CreateBoneList(ObjectID id, ObjectID meshFrameId, odfSubmesh submesh, List <ImportedBone> boneList, Matrix lMeshMatrixInv, odfFrame rootFrame) { if (boneList == null || boneList.Count == 0) { return(null); } Dictionary <byte, Tuple <byte, odfBone> > boneDic = new Dictionary <byte, Tuple <byte, odfBone> >(boneList.Count); Tuple <List <int>, List <float> >[] newBoneListComponents = new Tuple <List <int>, List <float> > [boneList.Count]; int boneframeNotFound = 0; for (int i = 0; i < submesh.NumVertices; i++) { odfVertex vert = submesh.VertexList[i]; for (int j = 0; j < vert.BoneIndices.Length; j++) { byte boneIdx = vert.BoneIndices[j]; if (boneIdx == 0xFF) { continue; } Tuple <byte, odfBone> boneDesc; odfBone newBone; if (!boneDic.TryGetValue(boneIdx, out boneDesc)) { odfFrame boneFrame = odf.FindFrame(boneList[boneIdx].Name, rootFrame); if (boneFrame == null) { boneframeNotFound++; continue; } newBone = new odfBone(boneFrame.Id); newBone.Matrix = boneList[boneIdx].Matrix; boneDesc = new Tuple <byte, odfBone>((byte)boneDic.Count, newBone); boneDic.Add(boneIdx, boneDesc); newBoneListComponents[boneDesc.Item1] = new Tuple <List <int>, List <float> >(new List <int>(200), new List <float>(200)); } else { newBone = boneDesc.Item2; } byte newBoneIdx = boneDesc.Item1; List <int> newBoneIdxList = newBoneListComponents[newBoneIdx].Item1; newBoneIdxList.Add(i); List <float> newBoneWeightList = newBoneListComponents[newBoneIdx].Item2; newBoneWeightList.Add(vert.Weights[j]); } } if (boneDic.Count == 0) { Report.ReportLog(submesh.ToString() + ": all bones dropped because of missing skeleton."); return(null); } odfBoneList newBoneList = new odfBoneList(new ObjectName(String.Empty, null), id, boneDic.Count); newBoneList.MeshFrameId = meshFrameId; newBoneList.SubmeshId = submesh.Id; newBoneList.AlwaysZero4 = new byte[4]; foreach (Tuple <byte, odfBone> boneDesc in boneDic.Values) { byte newBoneIdx = boneDesc.Item1; List <int> newBoneIdxList = newBoneListComponents[newBoneIdx].Item1; List <float> newBoneWeightList = newBoneListComponents[newBoneIdx].Item2; odfBone newBone = boneDesc.Item2; newBone.AlwaysZero24perIndex = new byte[24 * newBoneIdxList.Count]; newBone.VertexIndexArray = newBoneIdxList.ToArray(); newBone.WeightArray = newBoneWeightList.ToArray(); Matrix lMatrix = Matrix.Invert(newBone.Matrix); newBone.Matrix = Matrix.Invert(lMatrix * lMeshMatrixInv); newBoneList.AddChild(newBone); } if (boneframeNotFound > 0) { Report.ReportLog(submesh.ToString() + ": " + boneframeNotFound + " bone(s) because of missing boneframe(s) dropped."); } return(newBoneList); }