public static void CreateSimpleSkinFromLegacy(CreateSimpleSkinFromLegacy opts) { StaticObject staticObject = StaticObject.ReadSCO(opts.StaticObjectPath); WGTFile weightFile = new WGTFile(opts.WeightFilePath); SimpleSkin simpleSkin = new SimpleSkin(staticObject, weightFile); simpleSkin.Write(opts.SimpleSkinPath); }
public SKNFile(WGTFile Weights, SCOFile Model) { this.Submeshes.Add(new SKNSubmesh(Model.Name, 0, (uint)Model.Vertices.Count, 0, (uint)Model.Faces.Count * 3)); foreach (Vector3 Vertex in Model.Vertices) { this.Vertices.Add(new SKNVertex(Vertex)); } for (int i = 0; i < this.Vertices.Count; i++) { this.Vertices[i].SetWeight(Weights.Weights[i].Indices, Weights.Weights[i].Weights); } for (int i = 0; i < Model.Faces.Count; i++) { for (int j = 0; j < 3; j++) { this.Vertices[Model.Faces[i].Indices[j]].SetUV(Model.Faces[i].UV[j]); } for (int j = 0; j < 3; j++) { this.Indices.Add(Model.Faces[i].Indices[j]); } } for (int i = 0; i < Indices.Count; i += 3) { Vector3 cp = Vector3.Cross( Vertices[Indices[i + 1]].Position - Vertices[Indices[i]].Position, Vertices[Indices[i + 2]].Position - Vertices[Indices[i]].Position); Vertices[Indices[i]].SetNormal(Vertices[Indices[i]].Normal + cp); Vertices[Indices[i + 1]].SetNormal(Vertices[Indices[i + 1]].Normal + cp); Vertices[Indices[i + 2]].SetNormal(Vertices[Indices[i + 2]].Normal + cp); } foreach (SKNVertex Vertex in Vertices) { float s = Vertex.Normal.X + Vertex.Normal.Y + Vertex.Normal.Z; Vertex.SetNormal(new Vector3( Vertex.Normal.X / s, Vertex.Normal.Y / s, Vertex.Normal.Z / s ) ); } }
public SimpleSkin(StaticObject staticObject, WGTFile weightFile) { List <uint> staticObjectIndices = staticObject.GetIndices(); List <StaticObjectVertex> staticObjectVertices = staticObject.GetVertices(); int currentVertexOffset = 0; foreach (StaticObjectSubmesh submesh in staticObject.Submeshes) { // Build vertices List <SimpleSkinVertex> vertices = new(staticObjectVertices.Count); for (int i = 0; i < submesh.Vertices.Count; i++) { StaticObjectVertex vertex = submesh.Vertices[i]; WGTWeight weightData = weightFile.Weights[i + currentVertexOffset]; vertices.Add(new SimpleSkinVertex(vertex.Position, weightData.BoneIndices, weightData.Weights, Vector3.Zero, vertex.UV)); } this.Submeshes.Add(new SimpleSkinSubmesh(submesh.Name, submesh.Indices.Select(x => (ushort)x).ToList(), vertices)); currentVertexOffset += submesh.Vertices.Count; } }
/// <summary> /// Converts <paramref name="weights"/> and <paramref name="model"/> to an <see cref="SKNFile"/> /// </summary> /// <param name="weights">The <see cref="WGTFile"/> to be used for weights</param> /// <param name="model">The <see cref="SCOFile"/> to be used for model data</param> /// <returns>An <see cref="SKNFile"/> converted from <paramref name="weights"/> and <paramref name="model"/></returns> public static SKNFile ConvertLegacyModel(WGTFile weights, SCOFile model) { return(new SKNFile(weights, model)); }
/// <summary> /// Initializes a new <see cref="SKNFile"/> from legacy files /// </summary> /// <param name="weightsFile">Weights of this <see cref="SKNFile"/></param> /// <param name="modelFile">Model Data of this <see cref="SKNFile"/></param> public SKNFile(WGTFile weightsFile, SCOFile modelFile) { List <Vector3> vertices = new List <Vector3>(); List <Vector4Byte> boneIndices = new List <Vector4Byte>(); List <Vector4> weights = new List <Vector4>(); List <Vector2> uvs = new List <Vector2>(); List <uint> indices = new List <uint>(); foreach (WGTWeight weight in weightsFile.Weights) { boneIndices.Add(weight.BoneIndices); weights.Add(weight.Weights); } foreach (KeyValuePair <string, List <SCOFace> > material in modelFile.Materials) { foreach (SCOFace face in material.Value) { indices.AddRange(face.Indices); for (int i = 0; i < 3; i++) { vertices.Add(modelFile.Vertices[(int)face.Indices[i]]); uvs.Add(face.UVs[i]); } } } //Calculates smooth normals for the mesh List <Vector3> normals = new List <Vector3>(new Vector3[vertices.Count]); for (int i = 0; i < indices.Count; i += 3) { uint a = indices[i]; uint b = indices[i + 1]; uint c = indices[i + 2]; Vector3 edgeA = vertices[(int)a] - vertices[(int)b]; Vector3 edgeB = vertices[(int)c] - vertices[(int)b]; Vector3 normal = Vector3.Cross(edgeA, edgeB); normals[(int)a] = normal; normals[(int)b] = normal; normals[(int)c] = normal; } //Normalizes normals for (int j = 0; j < normals.Count; j++) { Vector3 normalNormalize = normals[j]; float sum = normalNormalize.X + normalNormalize.Y + normalNormalize.Z; normals[j] = new Vector3(normalNormalize.X / sum, normalNormalize.Y / sum, normalNormalize.Z / sum); } //Creates SKNVertex list from componets List <SKNVertex> sknVertices = new List <SKNVertex>(); for (int i = 0; i < vertices.Count; i++) { sknVertices.Add(new SKNVertex(vertices[i], boneIndices[i], weights[i], normals[i], uvs[i])); } //Creates Submeshes based on the Materials in the SCO File int indexOffset = 0; foreach (KeyValuePair <string, List <SCOFace> > material in modelFile.Materials) { this.Submeshes.Add(new SKNSubmesh(material.Key, indices.GetRange(indexOffset, material.Value.Count).Cast <ushort>().ToList(), sknVertices.GetRange(indexOffset, material.Value.Count), this)); } }
public static SKNFile ConvertLegacyModel(WGTFile Weights, SCOFile Model) { return(new SKNFile(Weights, Model)); }