/// <summary> /// /// </summary> /// <param name="type"></param> /// <param name="vertices"></param> /// <param name="parent"></param> /// <returns></returns> private List <IOVertex> ConvertGXDLtoTriangleList(GXPrimitiveType type, List <SBHsdVertex> vertices, SBHsdBone parent) { var list = new List <IOVertex>(); foreach (var v in vertices) { var vertex = new IOVertex() { Position = new System.Numerics.Vector3(v.POS.X, v.POS.Y, v.POS.Z), Normal = new System.Numerics.Vector3(v.NRM.X, v.NRM.Y, v.NRM.Z), }; vertex.SetUV(v.UV0.X, v.UV0.Y, 0); for (int i = 0; i < 4; i++) { if (v.Weight[i] > 0) { vertex.Envelope.Weights.Add(new IOBoneWeight() { BoneName = "JOBJ_" + (int)v.Bone[i], Weight = v.Weight[i] }); } } if (parent != null) { vertex.Transform(TktoNumeric(parent.WorldTransform)); if (vertex.Envelope.Weights.Count == 0) { vertex.Envelope.Weights.Add(new IOBoneWeight() { BoneName = parent.Name, Weight = 1 }); } } if (v.Weight.X == 1) { vertex.Transform(TktoNumeric(Skeleton.Bones[(int)v.Bone.X].WorldTransform)); } list.Add(vertex); } if (type == GXPrimitiveType.TriangleStrip) { TriangleConvert.StripToList(list, out list); } if (type == GXPrimitiveType.Quads) { TriangleConvert.QuadToList(list, out list); } return(list); }
/// <summary> /// /// </summary> /// <returns></returns> private static IOVertex ParseVertex(string line, Dictionary <int, IOBone> idxToBones, out IOBone parentBone) { var args = Regex.Replace(line.Trim(), @"\s+", " ").Split(' '); IOVertex vertex = new IOVertex(); // parse parent index int parent = int.Parse(args[0]); // parse attributes vertex.Position = new System.Numerics.Vector3(float.Parse(args[1]), float.Parse(args[2]), float.Parse(args[3])); vertex.Normal = new System.Numerics.Vector3(float.Parse(args[4]), float.Parse(args[5]), float.Parse(args[6])); vertex.UVs.Add(new System.Numerics.Vector2(float.Parse(args[7]), float.Parse(args[8]))); // transform by parent so we can ignore it if (parent != -1) { vertex.Transform(idxToBones[parent].WorldTransform); parentBone = idxToBones[parent]; } else { parentBone = null; } // parse weights if (args.Length >= 10) { int links = int.Parse(args[9]); for (int i = 0; i < links; i++) { vertex.Envelope.Weights.Add(new IOBoneWeight() { BoneName = idxToBones[int.Parse(args[10 + i * 2])].Name, Weight = float.Parse(args[11 + i * 2]) }); } } return(vertex); }