/// <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> /// <param name="semantic"></param> /// <param name="values"></param> /// <param name="vertex"></param> /// <param name="vertices"></param> private void ProcessInput(Input_Semantic semantic, string source, int set, IOVertex vertex, Vertices vertices, int index, SourceManager srcs, List <IOEnvelope> vertexEnvelopes) { var values = srcs.GetFloatValue(source, index); switch (semantic) { case Input_Semantic.VERTEX: // process per vertex input foreach (var vertInput in vertices.Input) { ProcessInput(vertInput.Semantic, vertInput.source, 0, vertex, vertices, index, srcs, vertexEnvelopes); } // load envelopes if availiable if (vertexEnvelopes != null && index < vertexEnvelopes.Count) { // copy bone weights var en = vertexEnvelopes[index]; for (int i = 0; i < en.Weights.Count; i++) { vertex.Envelope.Weights.Add(new IOBoneWeight() { BoneName = en.Weights[i].BoneName, Weight = en.Weights[i].Weight, BindMatrix = en.Weights[i].BindMatrix }); } // make the bind matrix as being used vertex.Envelope.UseBindMatrix = true; } break; case Input_Semantic.POSITION: vertex.Position = new Vector3( values.Length > 0 ? values[0] : 0, values.Length > 1 ? values[1] : 0, values.Length > 2 ? values[2] : 0); break; case Input_Semantic.NORMAL: vertex.Normal = new Vector3( values.Length > 0 ? values[0] : 0, values.Length > 1 ? values[1] : 0, values.Length > 2 ? values[2] : 0); break; case Input_Semantic.TANGENT: vertex.Tangent = new Vector3( values.Length > 0 ? values[0] : 0, values.Length > 1 ? values[1] : 0, values.Length > 2 ? values[2] : 0); break; case Input_Semantic.BINORMAL: vertex.Binormal = new Vector3( values.Length > 0 ? values[0] : 0, values.Length > 1 ? values[1] : 0, values.Length > 2 ? values[2] : 0); break; case Input_Semantic.TEXCOORD: vertex.SetUV( values.Length > 0 ? values[0] : 0, values.Length > 1 ? values[1] : 0, set); break; case Input_Semantic.COLOR: vertex.SetColor( values.Length > 0 ? values[0] : 0, values.Length > 1 ? values[1] : 0, values.Length > 2 ? values[2] : 0, values.Length > 3 ? values[3] : 0, set); break; } }